Skip to content

Commit

Permalink
Merge pull request #660 from nats-io/linter
Browse files Browse the repository at this point in the history
[LINTER] fixed linter and deprecation warnings
  • Loading branch information
aricart committed Mar 11, 2024
2 parents 779f01c + d9fc79b commit 608e3c1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 47 deletions.
18 changes: 6 additions & 12 deletions examples/nats-pub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
credsAuthenticator,
headers,
MsgHdrs,
StringCodec,
} from "../src/mod.ts";
import { delay } from "../nats-base-client/util.ts";

Expand All @@ -32,9 +31,10 @@ const argv = parse(

const copts = { servers: argv.s } as ConnectionOptions;
const subject = String(argv._[0]);
const payload = argv._[1] || "";
const count = (argv.c == -1 ? Number.MAX_SAFE_INTEGER : argv.c) || 1;
const interval = argv.i || 0;
const payload = (argv._[1] || "") as string;
const count =
((argv.c == -1 ? Number.MAX_SAFE_INTEGER : argv.c) || 1) as number;
const interval = (argv.i || 0) as number;

if (argv.debug) {
copts.debug = true;
Expand All @@ -49,11 +49,7 @@ if (argv.h || argv.help || !subject) {
}

if (argv.creds) {
const f = await Deno.open(argv.creds, { read: true });
// FIXME: this needs to be changed when deno releases 2.0
// deno-lint-ignore no-deprecated-deno-api
const data = await Deno.readAll(f);
Deno.close(f.rid);
const data = await Deno.readFile(argv.creds);
copts.authenticator = credsAuthenticator(data);
}

Expand All @@ -75,10 +71,8 @@ if (argv.headers) {
pubopts.headers = hdrs;
}

const sc = StringCodec();

for (let i = 1; i <= count; i++) {
nc.publish(subject, sc.encode(String(payload)), pubopts);
nc.publish(subject, payload, pubopts);
console.log(`[${i}] ${subject}: ${payload}`);
if (interval) {
await delay(interval);
Expand Down
21 changes: 8 additions & 13 deletions examples/nats-rep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
ConnectionOptions,
credsAuthenticator,
headers,
StringCodec,
} from "../src/mod.ts";

const argv = parse(
Expand All @@ -29,27 +28,21 @@ const argv = parse(

const opts = { servers: argv.s } as ConnectionOptions;
const subject = argv._[0] ? String(argv._[0]) : "";
const sc = StringCodec();
const ps = argv._[1] || "";
const payload = sc.encode(String(ps));
const payload = (argv._[1] || "") as string;

if (argv.debug) {
opts.debug = true;
}

if (argv.h || argv.help || !subject || (argv._[1] && argv.q)) {
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 f = await Deno.open(argv.creds, { read: true });
// FIXME: this needs to be changed when deno releases 2.0
// deno-lint-ignore no-deprecated-deno-api
const data = await Deno.readAll(f);
Deno.close(f.rid);
const data = await Deno.readFile(argv.creds);
opts.authenticator = credsAuthenticator(data);
}

Expand All @@ -63,15 +56,17 @@ nc.closed()
});

const hdrs = argv.headers ? headers() : undefined;
const sub = nc.subscribe(subject, { queue: argv.q });
console.info(`${argv.q !== "" ? "queue " : ""}listening to ${subject}`);

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.data}`);
console.log(`[${sub.getProcessed()}]: ${m.reply}: ${m.string()}`);
} else {
console.log(`[${sub.getProcessed()}]: ignored - no reply subject`);
}
Expand Down
13 changes: 5 additions & 8 deletions examples/nats-req.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ const argv = parse(
const opts = { servers: argv.s } as ConnectionOptions;
const subject = String(argv._[0]);
const payload = String(argv._[1]) || "";
const count = (argv.c == -1 ? Number.MAX_SAFE_INTEGER : argv.c) || 1;
const interval = argv.i;
const count =
((argv.c == -1 ? Number.MAX_SAFE_INTEGER : argv.c) || 1) as number;
const interval = (argv.i || 0) as number;

if (argv.debug) {
opts.debug = true;
Expand All @@ -49,11 +50,7 @@ if (argv.h || argv.help || !subject) {
}

if (argv.creds) {
const f = await Deno.open(argv.creds, { read: true });
// FIXME: this needs to be changed when deno releases 2.0
// deno-lint-ignore no-deprecated-deno-api
const data = await Deno.readAll(f);
Deno.close(f.rid);
const data = await Deno.readFile(argv.creds);
opts.authenticator = credsAuthenticator(data);
}

Expand All @@ -67,7 +64,7 @@ nc.closed()
});

for (let i = 1; i <= count; i++) {
await nc.request(subject, sc.encode(payload), { timeout: argv.t })
await nc.request(subject, sc.encode(payload), { timeout: argv.t as number })
.then((m) => {
console.log(`[${i}]: ${sc.decode(m.data)}`);
if (argv.headers && m.headers) {
Expand Down
8 changes: 2 additions & 6 deletions examples/nats-sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ if (argv.debug) {
}

if (argv.creds) {
const f = await Deno.open(argv.creds, { read: true });
// FIXME: this needs to be changed when deno releases 2.0
// deno-lint-ignore no-deprecated-deno-api
const data = await Deno.readAll(f);
Deno.close(f.rid);
const data = await Deno.readFile(argv.creds);
opts.authenticator = credsAuthenticator(data);
}

Expand All @@ -58,7 +54,7 @@ nc.closed()
});

const sc = StringCodec();
const sub = nc.subscribe(subject, { queue: argv.q });
const sub = nc.subscribe(subject, { queue: argv.q as string });
console.info(`${argv.q !== "" ? "queue " : ""}listening to ${subject}`);
for await (const m of sub) {
console.log(`[${sub.getProcessed()}]: ${m.subject}: ${sc.decode(m.data)}`);
Expand Down
1 change: 0 additions & 1 deletion jetstream/jsmconsumer_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ export class ConsumerAPIImpl extends BaseApiClient implements ConsumerAPI {
until: Date,
): Promise<{ paused: boolean; pause_until: string; pause_remaining: Nanos }> {
const subj = `${this.prefix}.CONSUMER.PAUSE.${stream}.${name}`;
let payload = undefined;
const opts = {
pause_until: until.toISOString(),
};
Expand Down
11 changes: 5 additions & 6 deletions jetstream/tests/objectstore_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,16 +704,15 @@ Deno.test("objectstore - sanitize", async () => {
const info = await os.status({
subjects_filter: ">",
});
const subjects = info.streamInfo.state?.subjects || {};
assertEquals(
info.streamInfo.state
?.subjects![`$O.test.M.${Base64UrlPaddedCodec.encode("has.dots.here")}`],
subjects[`$O.test.M.${Base64UrlPaddedCodec.encode("has.dots.here")}`],
1,
);
assertEquals(
info.streamInfo.state
.subjects![
`$O.test.M.${Base64UrlPaddedCodec.encode("the spaces are here")}`
],
subjects[
`$O.test.M.${Base64UrlPaddedCodec.encode("the spaces are here")}`
],
1,
);

Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export class NatsServer implements PortInfo {

const routes: string[] = [];
configs.forEach((conf) => {
let { port, cluster, config } = conf;
let { cluster, config } = conf;

// jetstream defaults
const { jetstream } = jsopts();
Expand Down

0 comments on commit 608e3c1

Please sign in to comment.