keri-ts 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import * as dntShim from "../../_dnt.shims.js";
2
+ import { spawnSync } from "node:child_process";
2
3
  import { AppError } from "../../core/errors.js";
3
4
  function readAllStdinSync() {
4
5
  const chunks = [];
@@ -21,16 +22,15 @@ function readAllStdinSync() {
21
22
  }
22
23
  return output;
23
24
  }
24
- function buildAnnotateArgs(options) {
25
+ function buildDenoAnnotateArgs(options) {
25
26
  const args = [
26
27
  "run",
27
28
  "--allow-read",
28
29
  "--allow-write",
29
30
  "packages/cesr/src/annotate/cli-deno.ts",
31
+ "--in",
32
+ options.inPath,
30
33
  ];
31
- if (options.inPath) {
32
- args.push("--in", options.inPath);
33
- }
34
34
  if (options.outPath) {
35
35
  args.push("--out", options.outPath);
36
36
  }
@@ -42,6 +42,60 @@ function buildAnnotateArgs(options) {
42
42
  }
43
43
  return args;
44
44
  }
45
+ function buildNodeAnnotateArgs(options) {
46
+ const nodeScript = [
47
+ "import { annotate } from 'cesr-ts';",
48
+ "import fs from 'node:fs';",
49
+ "const [inPath, outPath, qb2, pretty] = process.argv.slice(1);",
50
+ "const input = fs.readFileSync(inPath);",
51
+ "const output = qb2 === '1'",
52
+ " ? annotate(new Uint8Array(input), { domainHint: 'bny', pretty: pretty === '1' })",
53
+ " : annotate(input.toString('utf8'), { domainHint: 'txt', pretty: pretty === '1' });",
54
+ "if (outPath) {",
55
+ " fs.writeFileSync(outPath, output, 'utf8');",
56
+ "} else {",
57
+ " process.stdout.write(output + '\\n');",
58
+ "}",
59
+ ].join("\n");
60
+ return [
61
+ "--input-type=module",
62
+ "--eval",
63
+ nodeScript,
64
+ options.inPath,
65
+ options.outPath ?? "",
66
+ options.qb2 ? "1" : "0",
67
+ options.pretty ? "1" : "0",
68
+ ];
69
+ }
70
+ function forwardChildOutput(output) {
71
+ if (output.stdout.length > 0) {
72
+ dntShim.Deno.stdout.writeSync(output.stdout);
73
+ }
74
+ if (output.stderr.length > 0) {
75
+ dntShim.Deno.stderr.writeSync(output.stderr);
76
+ }
77
+ }
78
+ function runDenoAnnotator(options) {
79
+ const child = new dntShim.Deno.Command(dntShim.Deno.execPath(), {
80
+ args: buildDenoAnnotateArgs(options),
81
+ stdout: "piped",
82
+ stderr: "piped",
83
+ });
84
+ return child.outputSync();
85
+ }
86
+ function runNodeAnnotator(options) {
87
+ const maybeProcess = dntShim.dntGlobalThis;
88
+ const executable = maybeProcess.process?.execPath || "node";
89
+ const output = spawnSync(executable, buildNodeAnnotateArgs(options), {
90
+ stdio: "pipe",
91
+ });
92
+ return {
93
+ success: output.status === 0,
94
+ code: output.status ?? 1,
95
+ stdout: output.stdout ? new Uint8Array(output.stdout) : new Uint8Array(),
96
+ stderr: output.stderr ? new Uint8Array(output.stderr) : new Uint8Array(),
97
+ };
98
+ }
45
99
  // deno-lint-ignore require-yield
46
100
  export function* annotateCommand(args) {
47
101
  const options = {
@@ -57,18 +111,21 @@ export function* annotateCommand(args) {
57
111
  options.inPath = tempInPath;
58
112
  }
59
113
  try {
60
- const child = new dntShim.Deno.Command(dntShim.Deno.execPath(), {
61
- args: buildAnnotateArgs(options),
62
- stdout: "piped",
63
- stderr: "piped",
64
- });
65
- const output = child.outputSync();
66
- if (output.stdout.length > 0) {
67
- dntShim.Deno.stdout.writeSync(output.stdout);
114
+ let output;
115
+ try {
116
+ output = runDenoAnnotator(options);
68
117
  }
69
- if (output.stderr.length > 0) {
70
- dntShim.Deno.stderr.writeSync(output.stderr);
118
+ catch (error) {
119
+ const isDenoMissing = error instanceof Error &&
120
+ (error.message.includes("not found: deno") ||
121
+ (typeof error.code === "string" &&
122
+ error.code === "ENOENT"));
123
+ if (!isDenoMissing) {
124
+ throw error;
125
+ }
126
+ output = runNodeAnnotator(options);
71
127
  }
128
+ forwardChildOutput(output);
72
129
  if (!output.success) {
73
130
  throw new AppError(`annotate command failed with exit code ${output.code}`);
74
131
  }
@@ -79,7 +136,7 @@ export function* annotateCommand(args) {
79
136
  dntShim.Deno.removeSync(tempInPath);
80
137
  }
81
138
  catch {
82
- // no-op cleanup best effort
139
+ // best-effort cleanup
83
140
  }
84
141
  }
85
142
  }
@@ -2,7 +2,7 @@
2
2
  * Generated by scripts/generate_versions.ts.
3
3
  * Do not edit by hand.
4
4
  */
5
- export const PACKAGE_VERSION = "0.2.0";
5
+ export const PACKAGE_VERSION = "0.2.1";
6
6
  export const BUILD_METADATA = "";
7
7
  export const DISPLAY_VERSION = BUILD_METADATA
8
8
  ? `${PACKAGE_VERSION}+${BUILD_METADATA}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keri-ts",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "KERI TypeScript package with database primitives and CLI runtime",
5
5
  "homepage": "https://github.com/kentbull/keri-ts",
6
6
  "repository": {
@@ -48,7 +48,8 @@
48
48
  "commander": "^10.0.1",
49
49
  "effection": "^3.6.0",
50
50
  "lmdb": "^3.4.4",
51
- "@deno/shim-deno": "~0.18.0"
51
+ "@deno/shim-deno": "~0.18.0",
52
+ "cesr-ts": ">=0.2.0 <0.3.0"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@types/node": "^20.9.0"
@@ -1 +1 @@
1
- {"version":3,"file":"annotate.d.ts","sourceRoot":"","sources":["../../../src/app/cli/annotate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AA6D3C,wBAAiB,eAAe,CAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,SAAS,CAAC,IAAI,CAAC,CA4CjB"}
1
+ {"version":3,"file":"annotate.d.ts","sourceRoot":"","sources":["../../../src/app/cli/annotate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAkI3C,wBAAiB,eAAe,CAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,SAAS,CAAC,IAAI,CAAC,CA+CjB"}
@@ -2,7 +2,7 @@
2
2
  * Generated by scripts/generate_versions.ts.
3
3
  * Do not edit by hand.
4
4
  */
5
- export declare const PACKAGE_VERSION = "0.2.0";
5
+ export declare const PACKAGE_VERSION = "0.2.1";
6
6
  export declare const BUILD_METADATA = "";
7
7
  export declare const DISPLAY_VERSION: string;
8
8
  //# sourceMappingURL=version.d.ts.map