Files
Alberto RicartandGitHub 74b528ed6d refactor: bump dependencies (#355)
* refactor: replace `parse` with `parseArgs` and update dependencies in examples and configurations

- Migrated from `@std/flags` to `@std/cli` across various scripts.
- Updated related imports, arguments parsing logic, and versioned dependencies.

Signed-off-by: Alberto Ricart <[email protected]>

* chore(deps): bump `@types/node` to ^25.0.0 across all packages

Signed-off-by: Alberto Ricart <[email protected]>

* chore(release): bump all packages to version 3.3.0

Signed-off-by: Alberto Ricart <[email protected]>

* chore(workflows): update Deno to 2.6.x, Node to 25.x in CI configurations

Signed-off-by: Alberto Ricart <[email protected]>

* fix(node_transport): specify `Uint8Array` type for `frame` argument in `socket.on("data")` listener

v25, the inferred type changed to string | NonSharedBuffer

Signed-off-by: Alberto Ricart <[email protected]>

* chore(workflows): update GitHub Actions to use latest versions of `checkout`, `setup-node`, and `setup-deno`

Signed-off-by: Alberto Ricart <[email protected]>

---------

Signed-off-by: Alberto Ricart <[email protected]>
2025-12-16 15:29:55 -06:00

74 lines
1.7 KiB
TypeScript
Executable File

#!/usr/bin/env deno run --allow-all --unstable
import { parseArgs } from "@std/cli";
import {
connect,
type ConnectionOptions,
credsAuthenticator,
headers,
} from "@nats-io/transport-deno";
const argv = parseArgs(
Deno.args,
{
alias: {
"s": ["server"],
"q": ["queue"],
"e": ["echo"],
"f": ["creds"],
},
default: {
s: "127.0.0.1:4222",
q: "",
},
boolean: ["echo", "headers", "debug"],
string: ["server", "queue", "creds"],
},
);
const opts = { servers: argv.s } as ConnectionOptions;
const subject = argv._[0] ? String(argv._[0]) : "";
const payload = (argv._[1] || "") as string;
if (argv.debug) {
opts.debug = true;
}
if (argv.h || argv.help || !subject) {
console.log(
"Usage: nats-rep [-s server] [--creds=/path/file.creds] [-q queue] [--headers] [-e echo_payload] subject [payload]",
);
Deno.exit(1);
}
if (argv.creds) {
const data = await Deno.readFile(argv.creds);
opts.authenticator = credsAuthenticator(data);
}
const nc = await connect(opts);
console.info(`connected ${nc.getServer()}`);
nc.closed()
.then((err) => {
if (err) {
console.error(`closed with an error: ${err.message}`);
}
});
const hdrs = argv.headers ? headers() : undefined;
const queue = argv.q as string;
const sub = nc.subscribe(subject, { queue });
console.info(`${queue !== "" ? "queue " : ""}listening to ${subject}`);
for await (const m of sub) {
if (hdrs) {
hdrs.set("sequence", sub.getProcessed().toString());
hdrs.set("time", Date.now().toString());
}
if (m.respond(argv.e ? m.data : payload, { headers: hdrs })) {
console.log(`[${sub.getProcessed()}]: ${m.reply}: ${m.string()}`);
} else {
console.log(`[${sub.getProcessed()}]: ignored - no reply subject`);
}
}