Skip to content

Commit

Permalink
Kv and cleanup (#198)
Browse files Browse the repository at this point in the history
- [fix] removed internal imports on 'mod.ts' from within the lib
- [feat] removed encoded entry, lib will only export byte array-oriented kv, moved kv types to types, and exported them from the internal_mod
- [wip] added a tool to generate mod files, and simplify the update of public types/functions
- [change] renamed KV related types with `Kv`Prefixes
- [change] KV internal consumer creation now sets `idle_heartbeat` as it is now required by servers on main when `flow_control` is on.
  • Loading branch information
aricart authored Sep 17, 2021
1 parent d791cd9 commit c560da3
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 686 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
deno-version: ${{ matrix.deno-version }}

- name: Set NATS Server Version
run: echo "NATS_VERSION=v2.4.0" >> $GITHUB_ENV
run: echo "NATS_VERSION=v2.5.0" >> $GITHUB_ENV

- name: Get nats-server
run: |
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build test
.PHONY: build test bundle

build: test

Expand All @@ -13,3 +13,6 @@ cover:

clean:
rm -rf ./coverage

bundle:
deno bundle --log-level info --unstable src/mod.ts ./nats.js
144 changes: 144 additions & 0 deletions bin/exports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { parse } from "https://deno.land/std@0.103.0/flags/mod.ts";
import {
basename,
extname,
join,
resolve,
} from "https://deno.land/std@0.103.0/path/mod.ts";

const argv = parse(
Deno.args,
{},
);

// resolve the specified directories to fq
const dirs = (argv._ as string[]).map((n) => {
return resolve(n);
});

if (!dirs.length || argv.h || argv.help || dirs.length > 1) {
console.log(
`deno run --allow-all exports dir`,
);
Deno.exit(1);
}

// collect a list of all the files
const files: string[] = [];
for (const d of dirs) {
for await (const fn of Deno.readDir(d)) {
const n = basename(fn.name);
if (n === "mod.ts" || n === "internal_mod.ts") {
continue;
}
const ext = extname(fn.name);
if (ext === ".ts" || ext === ".js") {
files.push(join(d, fn.name));
}
}
}

type Export = {
fn: string;
all: boolean;
classes: string[];
enums: string[];
functions: string[];
interfaces: string[];
types: string[];
vars: string[];
};

type Exports = Export[];
const exports: Exports = [];

for (const fn of files) {
const data = await Deno.readFile(fn);
const txt = new TextDecoder().decode(data);
const matches = txt.matchAll(
/export\s+(\*|function|class|type|interface|enum|const|var)\s+(\w+)/g,
);
if (!matches) {
continue;
}
const e = {
fn: fn,
all: false,
classes: [],
enums: [],
functions: [],
interfaces: [],
types: [],
vars: [],
} as Export;
exports.push(e);

for (const m of matches) {
switch (m[1]) {
case "*":
e.all = true;
break;
case "function":
e.functions.push(m[2]);
break;
case "type":
e.types.push(m[2]);
break;
case "interface":
e.interfaces.push(m[2]);
break;
case "enum":
e.enums.push(m[2]);
break;
case "class":
e.classes.push(m[2]);
break;
case "const":
case "var":
e.vars.push(m[2]);
break;
default:
// ignore
}
}
}

exports.sort((e1, e2) => {
const a = e1.fn;
const b = e2.fn;
return a < b ? -1 : (a > b ? 1 : 0);
});

const ordered = exports.filter((e) => {
return basename(e.fn) !== "types.ts";
}) || [];

const types = exports.find((e) => {
return basename(e.fn) === "types.ts";
});
if (types) {
ordered.unshift(types);
}

for (const e of ordered) {
e.fn = `./${basename(e.fn)}`;
const types = [];
const other = [];
types.push(...e.types);
types.push(...e.interfaces);

other.push(...e.enums);
other.push(...e.classes);
other.push(...e.functions);
other.push(...e.vars);

if (types.length) {
console.log(`export type { ${types.join(", ")} } from "${e.fn}"`);
}
if (e.all) {
console.log(`export * from "${e.fn}"`);
}
if (other.length) {
console.log(`export { ${other.join(", ")} } from "${e.fn}"`);
}
}
2 changes: 1 addition & 1 deletion nats-base-client/authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/
import { nkeys } from "./nkeys.ts";
import type { ConnectionOptions } from "./types.ts";
import { ErrorCode, NatsError } from "./mod.ts";
import { TD, TE } from "./encoders.ts";
import { ErrorCode, NatsError } from "./error.ts";

export type NoAuth = void;

Expand Down
132 changes: 0 additions & 132 deletions nats-base-client/ekv.ts

This file was deleted.

Loading

0 comments on commit c560da3

Please sign in to comment.