Skip to content

Commit 118dbdd

Browse files
authored
Merge pull request #687 from nats-io/move-nanos
[CHANGE] moved `nanos()` and `millis()` to nats-base-client as they are referenced by the base library
2 parents a4d0f29 + bf4aba9 commit 118dbdd

27 files changed

+72
-68
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
deno-version: ${{ matrix.deno-version }}
3131

3232
- name: Set NATS Server Version
33-
run: echo "NATS_VERSION=v2.10.12" >> $GITHUB_ENV
33+
run: echo "NATS_VERSION=v2.10.14" >> $GITHUB_ENV
3434

3535
# this here because dns seems to be wedged on gha
3636
# - name: Add hosts to /etc/hosts

jetstream/consumer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ import {
1616
backoff,
1717
deferred,
1818
delay,
19+
nanos,
1920
Timeout,
2021
timeout,
2122
} from "../nats-base-client/util.ts";
2223
import { ConsumerAPI, ConsumerAPIImpl } from "./jsmconsumer_api.ts";
2324
import { nuid } from "../nats-base-client/nuid.ts";
24-
import { isHeartbeatMsg, nanos } from "./jsutil.ts";
25+
import { isHeartbeatMsg } from "./jsutil.ts";
2526
import { QueuedIteratorImpl } from "../nats-base-client/queued_iterator.ts";
2627
import {
2728
createInbox,

jetstream/internal_mod.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 The NATS Authors
2+
* Copyright 2023-2024 The NATS Authors
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -12,13 +12,7 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
export {
16-
checkJsError,
17-
isFlowControlMsg,
18-
isHeartbeatMsg,
19-
millis,
20-
nanos,
21-
} from "./jsutil.ts";
15+
export { checkJsError, isFlowControlMsg, isHeartbeatMsg } from "./jsutil.ts";
2216

2317
export {
2418
AdvisoryKind,

jetstream/jsapi_types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 The NATS Authors
2+
* Copyright 2023-2024 The NATS Authors
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -14,7 +14,8 @@
1414
*/
1515

1616
import { ApiError, Nanos } from "../nats-base-client/core.ts";
17-
import { nanos } from "./jsutil.ts";
17+
18+
import { nanos } from "../nats-base-client/util.ts";
1819

1920
export interface ApiPaged {
2021
total: number;

jetstream/jsclient.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import {
2121
isHeartbeatMsg,
2222
isTerminal409,
2323
Js409Errors,
24-
millis,
25-
nanos,
2624
newJsErrorMsg,
2725
validateDurableName,
2826
validateStreamName,
@@ -39,7 +37,13 @@ import {
3937
IngestionFilterFnResult,
4038
QueuedIteratorImpl,
4139
} from "../nats-base-client/queued_iterator.ts";
42-
import { delay, Timeout, timeout } from "../nats-base-client/util.ts";
40+
import {
41+
delay,
42+
millis,
43+
nanos,
44+
Timeout,
45+
timeout,
46+
} from "../nats-base-client/util.ts";
4347
import { headers } from "../nats-base-client/headers.ts";
4448
import { Bucket } from "./kv.ts";
4549
import { Feature } from "../nats-base-client/semver.ts";

jetstream/jsmsg.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 The NATS Authors
2+
* Copyright 2021-2024 The NATS Authors
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -17,10 +17,10 @@ import { JSONCodec, StringCodec } from "../nats-base-client/codec.ts";
1717
import { MsgImpl } from "../nats-base-client/msg.ts";
1818
import { ProtocolHandler } from "../nats-base-client/protocol.ts";
1919
import { RequestOne } from "../nats-base-client/request.ts";
20-
import { nanos } from "./jsutil.ts";
2120
import { Msg, MsgHdrs, RequestOptions } from "../nats-base-client/core.ts";
2221
import { DeliveryInfo, PullOptions } from "./jsapi_types.ts";
2322
import { deferred } from "../nats-base-client/mod.ts";
23+
import { nanos } from "../nats-base-client/util.ts";
2424

2525
export const ACK = Uint8Array.of(43, 65, 67, 75);
2626
const NAK = Uint8Array.of(45, 78, 65, 75);

jetstream/jsutil.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 The NATS Authors
2+
* Copyright 2021-2024 The NATS Authors
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -19,7 +19,6 @@ import { MsgImpl } from "../nats-base-client/msg.ts";
1919
import {
2020
ErrorCode,
2121
Msg,
22-
Nanos,
2322
NatsError,
2423
Publisher,
2524
} from "../nats-base-client/core.ts";
@@ -89,22 +88,6 @@ export function validName(name = ""): string {
8988
return "";
9089
}
9190

92-
/**
93-
* Converts the specified millis into Nanos
94-
* @param millis
95-
*/
96-
export function nanos(millis: number): Nanos {
97-
return millis * 1000000;
98-
}
99-
100-
/**
101-
* Convert the specified Nanos into millis
102-
* @param ns
103-
*/
104-
export function millis(ns: Nanos) {
105-
return Math.floor(ns / 1000000);
106-
}
107-
10891
/**
10992
* Returns true if the message is a flow control message
11093
* @param msg

jetstream/kv.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
Payload,
2222
QueuedIterator,
2323
} from "../nats-base-client/core.ts";
24-
import { millis, nanos } from "./jsutil.ts";
2524
import { QueuedIteratorImpl } from "../nats-base-client/queued_iterator.ts";
2625
import { headers } from "../nats-base-client/headers.ts";
2726
import {
@@ -47,7 +46,7 @@ import {
4746
StoredMsg,
4847
} from "./types.ts";
4948
import { compare, Feature, parseSemVer } from "../nats-base-client/semver.ts";
50-
import { deferred } from "../nats-base-client/util.ts";
49+
import { deferred, millis, nanos } from "../nats-base-client/util.ts";
5150
import { Empty } from "../nats-base-client/encoders.ts";
5251
import {
5352
AckPolicy,

jetstream/mod.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 The NATS Authors
2+
* Copyright 2023-2024 The NATS Authors
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -16,8 +16,6 @@ export {
1616
checkJsError,
1717
isFlowControlMsg,
1818
isHeartbeatMsg,
19-
millis,
20-
nanos,
2119
} from "./internal_mod.ts";
2220

2321
export {

jetstream/tests/consume_test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ import {
2828
} from "https://deno.land/[email protected]/assert/mod.ts";
2929
import { initStream } from "./jstest_util.ts";
3030
import { AckPolicy, DeliverPolicy } from "../jsapi_types.ts";
31-
import { deadline, deferred, delay } from "../../nats-base-client/util.ts";
32-
import { nanos } from "../jsutil.ts";
31+
import {
32+
deadline,
33+
deferred,
34+
delay,
35+
nanos,
36+
} from "../../nats-base-client/util.ts";
3337
import {
3438
ConsumerEvents,
3539
ConsumerStatus,

jetstream/tests/consumers_test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2023 The NATS Authors
2+
* Copyright 2022-2024 The NATS Authors
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -19,13 +19,12 @@ import {
1919
assertRejects,
2020
assertStringIncludes,
2121
} from "https://deno.land/[email protected]/assert/mod.ts";
22-
import { deferred } from "../../nats-base-client/mod.ts";
22+
import { deferred, nanos } from "../../nats-base-client/mod.ts";
2323
import {
2424
AckPolicy,
2525
Consumer,
2626
ConsumerMessages,
2727
DeliverPolicy,
28-
nanos,
2928
PullOptions,
3029
} from "../mod.ts";
3130
import { NatsServer } from "../../tests/helpers/launcher.ts";

jetstream/tests/fetch_test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ import {
2727
} from "https://deno.land/[email protected]/assert/mod.ts";
2828
import { Empty } from "../../nats-base-client/encoders.ts";
2929
import { StringCodec } from "../../nats-base-client/codec.ts";
30-
import { delay } from "../../nats-base-client/util.ts";
31-
import { nanos } from "../jsutil.ts";
30+
import { delay, nanos } from "../../nats-base-client/util.ts";
3231
import { NatsConnectionImpl } from "../../nats-base-client/nats.ts";
3332
import { syncIterator } from "../../nats-base-client/core.ts";
3433
import { PullConsumerMessagesImpl } from "../consumer.ts";

jetstream/tests/jetream409_test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2023 The NATS Authors
2+
* Copyright 2022-2024 The NATS Authors
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -13,9 +13,10 @@
1313
* limitations under the License.
1414
*/
1515

16-
import { Js409Errors, nanos, setMaxWaitingToFail } from "../jsutil.ts";
16+
import { Js409Errors, setMaxWaitingToFail } from "../jsutil.ts";
1717
import {
1818
deferred,
19+
nanos,
1920
NatsError,
2021
StringCodec,
2122
} from "../../nats-base-client/mod.ts";

jetstream/tests/jetstream_pullconsumer_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ import {
3838
fail,
3939
} from "https://deno.land/[email protected]/assert/mod.ts";
4040
import { Empty } from "../../nats-base-client/encoders.ts";
41-
import { checkJsError, nanos } from "../jsutil.ts";
41+
import { checkJsError } from "../jsutil.ts";
4242
import { JSONCodec, StringCodec } from "../../nats-base-client/codec.ts";
4343
import {
4444
consumerOpts,
4545
ConsumerOptsBuilderImpl,
4646
JetStreamSubscriptionInfoable,
4747
PubAck,
4848
} from "../types.ts";
49-
import { deferred, delay } from "../../nats-base-client/util.ts";
49+
import { deferred, delay, nanos } from "../../nats-base-client/util.ts";
5050
import {
5151
DebugEvents,
5252
ErrorCode,

jetstream/tests/jetstream_pushconsumer_test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,11 @@ import {
5555
} from "../jsapi_types.ts";
5656
import { JSONCodec, StringCodec } from "../../nats-base-client/codec.ts";
5757
import { Empty } from "../../nats-base-client/encoders.ts";
58-
import { deferred, delay } from "../../nats-base-client/util.ts";
58+
import { deferred, delay, nanos } from "../../nats-base-client/util.ts";
5959
import { nuid } from "../../nats-base-client/nuid.ts";
6060
import { JsMsg } from "../jsmsg.ts";
6161
import { connect } from "../../src/connect.ts";
62-
import {
63-
isFlowControlMsg,
64-
isHeartbeatMsg,
65-
Js409Errors,
66-
nanos,
67-
} from "../jsutil.ts";
62+
import { isFlowControlMsg, isHeartbeatMsg, Js409Errors } from "../jsutil.ts";
6863
import { JetStreamSubscriptionImpl } from "../jsclient.ts";
6964

7065
Deno.test("jetstream - ephemeral push", async () => {

jetstream/tests/jetstream_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
JsHeaders,
2424
JsMsg,
2525
JsMsgCallback,
26-
nanos,
2726
PubAck,
2827
RepublishHeaders,
2928
RetentionPolicy,
@@ -41,6 +40,7 @@ import {
4140
ErrorCode,
4241
headers,
4342
JSONCodec,
43+
nanos,
4444
NatsError,
4545
nuid,
4646
StringCodec,

jetstream/tests/jsm_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
headers,
3131
JSONCodec,
3232
jwtAuthenticator,
33+
nanos,
3334
NatsConnection,
3435
NatsError,
3536
nkeys,
@@ -43,7 +44,6 @@ import {
4344
ConsumerInfo,
4445
DiscardPolicy,
4546
Lister,
46-
nanos,
4747
PubAck,
4848
RetentionPolicy,
4949
StorageType,

jetstream/tests/jsmsg_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import {
2323
createInbox,
2424
Empty,
2525
Msg,
26+
nanos,
2627
StorageType,
2728
StringCodec,
2829
} from "../../src/mod.ts";
29-
import { nanos } from "../jsutil.ts";
3030
import { JsMsgImpl, parseInfo, toJsMsg } from "../jsmsg.ts";
3131
import {
3232
cleanup,

jetstream/tests/kv_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
deferred,
2020
delay,
2121
Empty,
22+
nanos,
2223
NatsConnection,
2324
NatsConnectionImpl,
2425
nuid,
@@ -34,7 +35,6 @@ import {
3435
KV,
3536
KvEntry,
3637
KvOptions,
37-
nanos,
3838
StorageType,
3939
} from "../mod.ts";
4040

jetstream/tests/next_test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ import {
2424
assertEquals,
2525
assertRejects,
2626
} from "https://deno.land/[email protected]/assert/mod.ts";
27-
import { nanos } from "../jsutil.ts";
2827
import { NatsConnectionImpl } from "../../nats-base-client/nats.ts";
29-
import { delay } from "../../nats-base-client/util.ts";
28+
import { delay, nanos } from "../../nats-base-client/util.ts";
3029

3130
Deno.test("next - basics", async () => {
3231
const { ns, nc } = await setup(jetstreamServerConf());
@@ -161,6 +160,7 @@ Deno.test("next - deleted consumer", async () => {
161160
const js = nc.jetstream();
162161
const c = await js.consumers.get("A", "a");
163162

163+
(nc as NatsConnectionImpl).options.debug = true;
164164
const exited = assertRejects(
165165
() => {
166166
return c.next({ expires: 4000 });
@@ -191,7 +191,9 @@ Deno.test("next - stream not found", async () => {
191191
const js = nc.jetstream();
192192
const c = await js.consumers.get("A", "a");
193193

194+
(nc as NatsConnectionImpl).options.debug = true;
194195
await jsm.streams.delete("A");
196+
await delay(1000);
195197

196198
await assertRejects(
197199
() => {

jetstream/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ import {
5858
import { JsMsg } from "./jsmsg.ts";
5959
import { BaseApiClient } from "./jsbaseclient_api.ts";
6060
import { ConsumerAPI } from "./jsmconsumer_api.ts";
61-
import { nanos, validateDurableName } from "./jsutil.ts";
61+
import { validateDurableName } from "./jsutil.ts";
6262
import { Lister } from "./jslister.ts";
63+
import { nanos } from "../nats-base-client/util.ts";
6364

6465
/**
6566
* The response returned by the JetStream server when a message is added to a stream.

nats-base-client/internal_mod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export {
1515
deferred,
1616
delay,
1717
extend,
18+
millis,
19+
nanos,
1820
render,
1921
timeout,
2022
} from "./util.ts";

nats-base-client/mod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export {
1717
jwtAuthenticator,
1818
Match,
1919
Metric,
20+
millis,
2021
MsgHdrsImpl,
22+
nanos,
2123
NatsError,
2224
nkeyAuthenticator,
2325
nkeys,

0 commit comments

Comments
 (0)