Skip to content

Commit

Permalink
chore(transport-node): normalize use of require/import in the module,…
Browse files Browse the repository at this point in the history
… and reference node libs with `node:`

internal(core): changed delay to resolve to a boolean to true unless canceled
  • Loading branch information
aricart committed Sep 7, 2024
1 parent 80d6bdc commit f22acec
Show file tree
Hide file tree
Showing 32 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion core/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nats-io/nats-core",
"version": "3.0.0-26",
"version": "3.0.0-27",
"exports": {
".": "./src/mod.ts",
"./internal": "./src/internal_mod.ts"
Expand Down
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nats-io/nats-core",
"version": "3.0.0-26",
"version": "3.0.0-27",
"files": [
"lib/",
"LICENSE",
Expand Down
7 changes: 4 additions & 3 deletions core/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,20 @@ export function timeout<T>(ms: number, asyncTraces = true): Timeout<T> {
return Object.assign(p, methods) as Timeout<T>;
}

export interface Delay extends Promise<void>, Cancelable {
export interface Delay extends Promise<boolean>, Cancelable {
cancel: () => void;
}

export function delay(ms = 0): Delay {
let methods;
const p = new Promise<void>((resolve) => {
const p = new Promise<boolean>((resolve) => {
const timer = setTimeout(() => {
resolve();
resolve(true);
}, ms);
const cancel = (): void => {
if (timer) {
clearTimeout(timer);
resolve(false);
}
};
methods = { cancel };
Expand Down
2 changes: 1 addition & 1 deletion core/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// This file is generated - do not edit
export const version = "3.0.0-26";
export const version = "3.0.0-27";
2 changes: 1 addition & 1 deletion jetstream/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"test": "deno test -A --parallel --reload --quiet tests/ --import-map=import_map.json"
},
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26"
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27"
}
}
2 changes: 1 addition & 1 deletion jetstream/examples/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import { createConsumer, fill, initStream } from "../tests/jstest_util.ts";
import type { NatsConnection } from "jsr:@nats-io/[email protected]17";
import type { NatsConnection } from "jsr:@nats-io/[email protected]26";
import { nuid } from "jsr:@nats-io/[email protected]";

export async function setupStreamAndConsumer(
Expand Down
4 changes: 2 additions & 2 deletions jetstream/import_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"imports": {
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
"@nats-io/nuid": "jsr:@nats-io/[email protected]",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-26/internal",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-27/internal",
"test_helpers": "../test_helpers/mod.ts",
"@std/io": "jsr:@std/[email protected]"
}
Expand Down
2 changes: 1 addition & 1 deletion jetstream/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"description": "jetstream library - this library implements all the base functionality for NATS JetStream for javascript clients",
"dependencies": {
"@nats-io/nats-core": "~3.0.0-26"
"@nats-io/nats-core": "~3.0.0-27"
},
"devDependencies": {
"@types/node": "^22.0.0",
Expand Down
2 changes: 1 addition & 1 deletion kv/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test": "deno test -A --parallel --reload --quiet tests/ --import-map=import_map.json"
},
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/jetstream": "jsr:@nats-io/jetstream@~3.0.0-10"
}
}
4 changes: 2 additions & 2 deletions kv/import_map.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-26/internal",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-27/internal",
"@nats-io/jetstream": "jsr:@nats-io/jetstream@~3.0.0-10",
"@nats-io/jetstream/internal": "jsr:@nats-io/jetstream@~3.0.0-10/internal",
"test_helpers": "../test_helpers/mod.ts",
Expand Down
2 changes: 1 addition & 1 deletion kv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"description": "kv library - this library implements all the base functionality for NATS KV javascript clients",
"dependencies": {
"@nats-io/jetstream": "~3.0.0-10",
"@nats-io/nats-core": "~3.0.0-26"
"@nats-io/nats-core": "~3.0.0-27"
},
"devDependencies": {
"@types/node": "^22.0.0",
Expand Down
2 changes: 1 addition & 1 deletion obj/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test": "deno test -A --parallel --reload --quiet tests/ --import-map=import_map.json"
},
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/jetstream": "jsr:@nats-io/jetstream@~3.0.0-10"
}
}
4 changes: 2 additions & 2 deletions obj/import_map.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-26/internal",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-27/internal",
"@nats-io/jetstream": "jsr:@nats-io/jetstream@~3.0.0-10",
"@nats-io/jetstream/internal": "jsr:@nats-io/jetstream@~3.0.0-10/internal",
"test_helpers": "../test_helpers/mod.ts",
Expand Down
2 changes: 1 addition & 1 deletion obj/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"description": "obj library - this library implements all the base functionality for NATS objectstore for javascript clients",
"dependencies": {
"@nats-io/jetstream": "~3.0.0-10",
"@nats-io/nats-core": "~3.0.0-26"
"@nats-io/nats-core": "~3.0.0-27"
},
"devDependencies": {
"@types/node": "^22.0.0",
Expand Down
10 changes: 0 additions & 10 deletions package.json

This file was deleted.

2 changes: 1 addition & 1 deletion services/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"test": "deno test -A --parallel --reload --quiet tests/ --import-map=import_map.json"
},
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26"
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27"
}
}
4 changes: 2 additions & 2 deletions services/import_map.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"imports": {
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-26/internal",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/nats-core/internal": "jsr:@nats-io/nats-core@~3.0.0-27/internal",
"test_helpers": "../test_helpers/mod.ts",
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
"@nats-io/nuid": "jsr:@nats-io/[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"description": "services library - this library implements all the base functionality for NATS services for javascript clients",
"dependencies": {
"@nats-io/nats-core": "~3.0.0-26"
"@nats-io/nats-core": "~3.0.0-27"
},
"devDependencies": {
"@types/node": "^22.0.0",
Expand Down
2 changes: 1 addition & 1 deletion transport-deno/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"imports": {
"@std/io": "jsr:@std/[email protected]",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-26",
"@nats-io/nats-core": "jsr:@nats-io/nats-core@~3.0.0-27",
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
"@nats-io/nuid": "jsr:@nats-io/[email protected]"
}
Expand Down
1 change: 1 addition & 0 deletions transport-node/examples/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const parse = require("minimist");
const { Nuid, connect } = require("../index");
const { Bench, Metric } = require("../lib/nats-base-client/bench");
const { process } = require("node:process");

const defaults = {
s: "127.0.0.1:4222",
Expand Down
1 change: 1 addition & 0 deletions transport-node/examples/nats-events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node

const { process } = require("node:process");
const parse = require("minimist");
const { connect } = require("../index");

Expand Down
3 changes: 2 additions & 1 deletion transport-node/examples/nats-pub.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const { connect, StringCodec, headers, credsAuthenticator } = require(
"../index",
);
const { delay } = require("./util");
const fs = require("fs");
const fs = require("node:fs");
const { process } = require("node:process");

const argv = parse(
process.argv.slice(2),
Expand Down
3 changes: 2 additions & 1 deletion transport-node/examples/nats-rep.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const parse = require("minimist");
const { connect, StringCodec, headers, credsAuthenticator } = require(
"../index",
);
const fs = require("fs");
const fs = require("node:fs");
const { process } = require("node:process");

const argv = parse(
process.argv.slice(2),
Expand Down
3 changes: 2 additions & 1 deletion transport-node/examples/nats-req.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const { connect, StringCodec, headers, credsAuthenticator } = require(
"../index",
);
const { delay } = require("./util");
const fs = require("fs");
const fs = require("node:fs");
const { process } = require("node:process");

const argv = parse(
process.argv.slice(2),
Expand Down
3 changes: 2 additions & 1 deletion transport-node/examples/nats-sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const parse = require("minimist");
const { connect, StringCodec, credsAuthenticator } = require("../index");
const fs = require("fs");
const fs = require("node:fs");
const { process } = require("node:process");

const argv = parse(
process.argv.slice(2),
Expand Down
4 changes: 2 additions & 2 deletions transport-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions transport-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nats-io/transport-node",
"version": "3.0.0-11",
"version": "3.0.0-12",
"description": "Node.js client for NATS, a lightweight, high-performance cloud native messaging system",
"keywords": [
"nats",
Expand Down Expand Up @@ -54,7 +54,7 @@
"node": ">= 18.0.0"
},
"dependencies": {
"@nats-io/nats-core": "~3.0.0-26",
"@nats-io/nats-core": "~3.0.0-27",
"@nats-io/nkeys": "^1.2.0-4",
"@nats-io/nuid": "^2.0.1-2"
},
Expand Down
13 changes: 7 additions & 6 deletions transport-node/src/node_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import {
} from "./nats-base-client";

import type { ConnectionOptions } from "./nats-base-client";
import { createConnection, Socket } from "net";
import { connect as tlsConnect, TlsOptions, TLSSocket } from "tls";
const { resolve } = require("path");
const { readFile, existsSync } = require("fs");
const dns = require("dns");
const { version } = require("./version");
import { createConnection, Socket } from "node:net";
import { connect as tlsConnect, TlsOptions, TLSSocket } from "node:tls";
import { resolve } from "node:path";
import { existsSync, readFile } from "node:fs";
import dns from "node:dns";
import { Buffer } from "node:buffer";
import { version } from "./version";
export const VERSION = version;
const LANG = "nats.js";

Expand Down
2 changes: 1 addition & 1 deletion transport-node/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// This file is generated - do not edit
export const version = "3.0.0-11";
export const version = "3.0.0-12";
12 changes: 6 additions & 6 deletions transport-node/tests/helpers/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const path = require("path");
const http = require("http");
const path = require("node:path");
const http = require("node:http");
const process = require("node:process");
const { spawn } = require("node:child_process");
const fs = require("node:fs");
const os = require("node:os");
const { check } = require("./delay");
const {
deferred,
Expand All @@ -22,10 +26,6 @@ const {
nuid,
} = require("@nats-io/nats-core/internal");

const { spawn } = require("child_process");

const fs = require("fs");
const os = require("os");
const { Lock } = require("./lock");

const ServerSignals = new Map();
Expand Down
3 changes: 2 additions & 1 deletion transport-node/tests/noiptls_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const {
"../index",
);

const { resolve, join } = require("path");
const process = require("node:process");
const { resolve, join } = require("node:path");
const { Lock } = require("./helpers/lock");
const { NatsServer } = require("./helpers/launcher");

Expand Down
5 changes: 3 additions & 2 deletions transport-node/tests/tls_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ const {
} = require(
"../index",
);
const { resolve, join } = require("path");
const { readFileSync } = require("fs");
const process = require("node:process");
const { resolve, join } = require("node:path");
const { readFileSync } = require("node:fs");
const { Lock } = require("./helpers/lock");
const { NatsServer } = require("./helpers/launcher");
const { buildAuthenticator, extend, Connect } = require(
Expand Down

0 comments on commit f22acec

Please sign in to comment.