@nodetool-ai/cli-common 0.0.0-stage → 0.8.9-beta.2
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.
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/child-exit.d.ts +2 -0
- package/dist/child-exit.d.ts.map +1 -0
- package/dist/child-exit.js +2 -0
- package/dist/child-exit.js.map +1 -0
- package/dist/command-errors.d.ts +2 -0
- package/dist/command-errors.d.ts.map +1 -0
- package/dist/command-errors.js +2 -0
- package/dist/command-errors.js.map +1 -0
- package/dist/commands/debug-summary-output.d.ts +22 -0
- package/dist/commands/debug-summary-output.d.ts.map +1 -0
- package/dist/commands/debug-summary-output.js +28 -0
- package/dist/commands/debug-summary-output.js.map +1 -0
- package/dist/commands/output.d.ts +2 -0
- package/dist/commands/output.d.ts.map +1 -0
- package/dist/commands/output.js +2 -0
- package/dist/commands/output.js.map +1 -0
- package/dist/commands/validation-output.d.ts +25 -0
- package/dist/commands/validation-output.d.ts.map +1 -0
- package/dist/commands/validation-output.js +29 -0
- package/dist/commands/validation-output.js.map +1 -0
- package/dist/commands/version-commands.d.ts +91 -0
- package/dist/commands/version-commands.d.ts.map +1 -0
- package/dist/commands/version-commands.js +222 -0
- package/dist/commands/version-commands.js.map +1 -0
- package/dist/debug-bundle.d.ts +12 -0
- package/dist/debug-bundle.d.ts.map +1 -0
- package/dist/debug-bundle.js +21 -0
- package/dist/debug-bundle.js.map +1 -0
- package/dist/document-json.d.ts +11 -0
- package/dist/document-json.d.ts.map +1 -0
- package/dist/document-json.js +27 -0
- package/dist/document-json.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/interaction-script.d.ts +40 -0
- package/dist/interaction-script.d.ts.map +1 -0
- package/dist/interaction-script.js +104 -0
- package/dist/interaction-script.js.map +1 -0
- package/dist/numeric-options.d.ts +22 -0
- package/dist/numeric-options.d.ts.map +1 -0
- package/dist/numeric-options.js +45 -0
- package/dist/numeric-options.js.map +1 -0
- package/dist/optional-node-root.d.ts +10 -0
- package/dist/optional-node-root.d.ts.map +1 -0
- package/dist/optional-node-root.js +26 -0
- package/dist/optional-node-root.js.map +1 -0
- package/dist/package-assets.d.ts +8 -0
- package/dist/package-assets.d.ts.map +1 -0
- package/dist/package-assets.js +21 -0
- package/dist/package-assets.js.map +1 -0
- package/dist/predicates.d.ts +6 -0
- package/dist/predicates.d.ts.map +1 -0
- package/dist/predicates.js +6 -0
- package/dist/predicates.js.map +1 -0
- package/dist/rpc-client.d.ts +4 -0
- package/dist/rpc-client.d.ts.map +1 -0
- package/dist/rpc-client.js +15 -0
- package/dist/rpc-client.js.map +1 -0
- package/dist/runtime-env.d.ts +4 -0
- package/dist/runtime-env.d.ts.map +1 -0
- package/dist/runtime-env.js +31 -0
- package/dist/runtime-env.js.map +1 -0
- package/dist/telemetry.d.ts +38 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +158 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/trimHyphens.d.ts +3 -0
- package/dist/trimHyphens.d.ts.map +1 -0
- package/dist/trimHyphens.js +13 -0
- package/dist/trimHyphens.js.map +1 -0
- package/package.json +55 -4
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2026-10-31T10:34:18.078Z
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"child-exit.d.ts","sourceRoot":"","sources":["../src/child-exit.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"child-exit.js","sourceRoot":"","sources":["../src/child-exit.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-errors.d.ts","sourceRoot":"","sources":["../src/command-errors.ts"],"names":[],"mappings":"AAAA,cAAc,0CAA0C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-errors.js","sourceRoot":"","sources":["../src/command-errors.ts"],"names":[],"mappings":"AAAA,cAAc,0CAA0C,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The console summary printed after a timeline, sketch or JS-script debug run.
|
|
3
|
+
* Only the document-specific line and the bundle's document file differ.
|
|
4
|
+
*/
|
|
5
|
+
interface DebugSummaryReport {
|
|
6
|
+
verdict: {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
headline: string;
|
|
9
|
+
issues: string[];
|
|
10
|
+
warnings?: string[];
|
|
11
|
+
};
|
|
12
|
+
interactions: {
|
|
13
|
+
ok: boolean;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
export declare function printDebugSummary(report: DebugSummaryReport, bundleDir: string, doc: {
|
|
17
|
+
label: string;
|
|
18
|
+
meta: string;
|
|
19
|
+
file: string;
|
|
20
|
+
}): void;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=debug-summary-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-summary-output.d.ts","sourceRoot":"","sources":["../../src/commands/debug-summary-output.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,UAAU,kBAAkB;IAC1B,OAAO,EAAE;QACP,EAAE,EAAE,OAAO,CAAC;QACZ,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IACF,YAAY,EAAE;QAAE,EAAE,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;CACjC;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,kBAAkB,EAC1B,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjD,IAAI,CAwBN"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The console summary printed after a timeline, sketch or JS-script debug run.
|
|
3
|
+
* Only the document-specific line and the bundle's document file differ.
|
|
4
|
+
*/
|
|
5
|
+
export function printDebugSummary(report, bundleDir, doc) {
|
|
6
|
+
const column = Math.max(doc.label.length, "session".length) + 1;
|
|
7
|
+
const row = (label, text) => ` ${`${label}:`.padEnd(column)} ${text}`;
|
|
8
|
+
const mark = report.verdict.ok ? "✅" : "❌";
|
|
9
|
+
console.log(`\n${mark} ${report.verdict.headline}`);
|
|
10
|
+
console.log(row(doc.label, doc.meta));
|
|
11
|
+
const failed = report.interactions.filter((i) => !i.ok).length;
|
|
12
|
+
if (report.interactions.length > 0) {
|
|
13
|
+
console.log(row("session", `${report.interactions.length} step(s), ${failed} failed`));
|
|
14
|
+
}
|
|
15
|
+
if (report.verdict.issues.length > 0) {
|
|
16
|
+
console.log("\nIssues:");
|
|
17
|
+
for (const issue of report.verdict.issues)
|
|
18
|
+
console.log(` - ${issue}`);
|
|
19
|
+
}
|
|
20
|
+
if (report.verdict.warnings && report.verdict.warnings.length > 0) {
|
|
21
|
+
console.log("\nWarnings:");
|
|
22
|
+
for (const warning of report.verdict.warnings)
|
|
23
|
+
console.log(` - ${warning}`);
|
|
24
|
+
}
|
|
25
|
+
console.log(`\nDebug bundle: ${bundleDir}`);
|
|
26
|
+
console.log(` report.md / report.json · ${doc.file}`);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=debug-summary-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-summary-output.js","sourceRoot":"","sources":["../../src/commands/debug-summary-output.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,MAAM,UAAU,iBAAiB,CAC/B,MAA0B,EAC1B,SAAiB,EACjB,GAAkD;IAElD,MAAM,MAAM,G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AC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClE,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC3B,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ;YAC3C,OAAO,CAAC,GAAG,CAAC,OAAO,OAAO,EAAE,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,mBAAmB,SAAS,EAAE,CAAC,CAAC;IAC5C,OAAO,CAAC,GAAG,CAAC,+BAA+B,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/commands/output.ts"],"names":[],"mappings":"AAAA,cAAc,2CAA2C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/commands/output.ts"],"names":[],"mappings":"AAAA,cAAc,2CAA2C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One rendering of a document validation, shared by the timeline, sketch and
|
|
3
|
+
* JS-script commands. A restored document is checked and reported exactly the
|
|
4
|
+
* way a validated one is, and all three read the same on screen.
|
|
5
|
+
*/
|
|
6
|
+
export interface ValidationIssueLike {
|
|
7
|
+
severity: string;
|
|
8
|
+
message: string;
|
|
9
|
+
code: string;
|
|
10
|
+
path?: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface ValidationLike<I extends ValidationIssueLike> {
|
|
13
|
+
ok: boolean;
|
|
14
|
+
errors: I[];
|
|
15
|
+
warnings: I[];
|
|
16
|
+
}
|
|
17
|
+
/** `[path]` when the issue carries one, nothing otherwise. */
|
|
18
|
+
export declare function issueLocation(issue: ValidationIssueLike): string;
|
|
19
|
+
/**
|
|
20
|
+
* Headline, then one line per issue — errors before warnings. `where` names the
|
|
21
|
+
* part of the document an issue points at; per-document renderers pass the
|
|
22
|
+
* locator their issue type carries and fall back to `issueLocation`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function renderValidation<I extends ValidationIssueLike>(validation: ValidationLike<I>, where?: (issue: I) => string): string[];
|
|
25
|
+
//# sourceMappingURL=validation-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-output.d.ts","sourceRoot":"","sources":["../../src/commands/validation-output.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,mBAAmB;IAC3D,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,CAAC,EAAE,CAAC;IACZ,QAAQ,EAAE,CAAC,EAAE,CAAC;CACf;AAED,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,mBAAmB,EAC5D,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,EAC7B,KAAK,GAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAsB,GAC1C,MAAM,EAAE,CAaV"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One rendering of a document validation, shared by the timeline, sketch and
|
|
3
|
+
* JS-script commands. A restored document is checked and reported exactly the
|
|
4
|
+
* way a validated one is, and all three read the same on screen.
|
|
5
|
+
*/
|
|
6
|
+
/** `[path]` when the issue carries one, nothing otherwise. */
|
|
7
|
+
export function issueLocation(issue) {
|
|
8
|
+
return issue.path != null ? ` [${issue.path}]` : "";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Headline, then one line per issue — errors before warnings. `where` names the
|
|
12
|
+
* part of the document an issue points at; per-document renderers pass the
|
|
13
|
+
* locator their issue type carries and fall back to `issueLocation`.
|
|
14
|
+
*/
|
|
15
|
+
export function renderValidation(validation, where = issueLocation) {
|
|
16
|
+
const errors = validation.errors.length;
|
|
17
|
+
const warnings = validation.warnings.length;
|
|
18
|
+
const mark = validation.ok ? (warnings ? "⚠️" : "✅") : "❌";
|
|
19
|
+
const lines = ["", `${mark} ${errors} error(s), ${warnings} warning(s)`];
|
|
20
|
+
if (errors + warnings === 0)
|
|
21
|
+
return lines;
|
|
22
|
+
lines.push("");
|
|
23
|
+
for (const issue of [...validation.errors, ...validation.warnings]) {
|
|
24
|
+
const tag = issue.severity === "error" ? "error" : "warn ";
|
|
25
|
+
lines.push(` ${tag} ${issue.message}${where(issue)} (${issue.code})`);
|
|
26
|
+
}
|
|
27
|
+
return lines;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=validation-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-output.js","sourceRoot":"","sources":["../../src/commands/validation-output.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAeH,8DAA8D;AAC9D,MAAM,UAAU,aAAa,CAAC,KAA0B;IACtD,OAAO,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AACtD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAA6B,EAC7B,KAAK,GAAyB,aAAa;IAE3C,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC;IACxC,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC5C,MAAM,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAC3D,MAAM,KAAK,GAAG,CAAC,EAAE,EAAE,GAAG,IAAI,IAAI,MAAM,cAAc,QAAQ,aAAa,CAAC,CAAC;IACzE,IAAI,MAAM,GAAG,QAAQ,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAE1C,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnE,MAAM,GAAG,GAAG,KAAK,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;QAC3D,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<document> versions list|show|create|restore|delete` — one registration for
|
|
3
|
+
* every document type that keeps immutable snapshots (timeline sequences,
|
|
4
|
+
* image documents, JS scripts).
|
|
5
|
+
*
|
|
6
|
+
* Each type keeps its own row shapes, table columns and messages in a
|
|
7
|
+
* `VersionCommandSpec`; the command wiring, the CAS-guarded restore order
|
|
8
|
+
* (snapshot the pre-restore state, write, re-validate) and the exit codes are
|
|
9
|
+
* written once here. `restore` mirrors the tRPC routers: an old document is
|
|
10
|
+
* restored against today's schema, so a restore whose document no longer
|
|
11
|
+
* validates exits non-zero.
|
|
12
|
+
*/
|
|
13
|
+
import type { Command } from "commander";
|
|
14
|
+
import type { JsonValue } from "../document-json.js";
|
|
15
|
+
export type { JsonValue };
|
|
16
|
+
/** The model calls these commands make — the whole database seam. */
|
|
17
|
+
export interface VersionStore<Doc, Row> {
|
|
18
|
+
load: (id: string) => Promise<Doc | null>;
|
|
19
|
+
listVersions: (documentId: string, opts: {
|
|
20
|
+
limit?: number;
|
|
21
|
+
saveType?: string;
|
|
22
|
+
}) => Promise<Row[]>;
|
|
23
|
+
findVersion: (documentId: string, version: number) => Promise<Row | null>;
|
|
24
|
+
snapshot: (doc: Doc, opts: {
|
|
25
|
+
saveType: "manual" | "restore";
|
|
26
|
+
name?: string | null;
|
|
27
|
+
}) => Promise<Row>;
|
|
28
|
+
/**
|
|
29
|
+
* Write a version's document and settings back onto the parent document,
|
|
30
|
+
* compare-and-swap on the `updated_at` it was loaded with. Resolves to null
|
|
31
|
+
* when someone else wrote first.
|
|
32
|
+
*/
|
|
33
|
+
restore: (doc: Doc, version: Row) => Promise<Doc | null>;
|
|
34
|
+
deleteVersion: (documentId: string, version: number) => Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
interface Validation {
|
|
37
|
+
ok: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** Everything one document type contributes to the shared commands. */
|
|
40
|
+
export interface VersionCommandSpec<Doc, Row, Item, V extends Validation, Counts, Meta> {
|
|
41
|
+
/** Argument placeholder, e.g. `timeline_id`. */
|
|
42
|
+
idArg: string;
|
|
43
|
+
/** The key naming the parent document in `--json` output, e.g. `timelineId`. */
|
|
44
|
+
idKey: string;
|
|
45
|
+
/** Descriptions, verbatim — these are the documented CLI surface. */
|
|
46
|
+
descriptions: {
|
|
47
|
+
group: string;
|
|
48
|
+
list: string;
|
|
49
|
+
show: string;
|
|
50
|
+
create: string;
|
|
51
|
+
restore: string;
|
|
52
|
+
delete: string;
|
|
53
|
+
restoreJson: string;
|
|
54
|
+
};
|
|
55
|
+
notFoundDocument: (id: string) => string;
|
|
56
|
+
notFoundVersion: (id: string, version: number) => string;
|
|
57
|
+
/** Thrown when the CAS restore loses the race. */
|
|
58
|
+
conflict: string;
|
|
59
|
+
confirmDelete: (id: string, version: number) => string;
|
|
60
|
+
deleted: (id: string, version: number) => string;
|
|
61
|
+
toItem: (row: Row) => Item;
|
|
62
|
+
/** The table columns, for `list` and for `show`'s header row. */
|
|
63
|
+
tableRow: (item: Item) => Record<string, unknown>;
|
|
64
|
+
counts: (document: JsonValue | undefined) => Counts;
|
|
65
|
+
/** The line `show` prints under the table. */
|
|
66
|
+
showSummary: (counts: Counts, item: Item) => string;
|
|
67
|
+
/** The line `restore` prints on success. */
|
|
68
|
+
restoreSummary: (id: string, version: number, counts: Counts, row: Row) => string;
|
|
69
|
+
/** Extra `--json` keys describing the document after a restore. */
|
|
70
|
+
restoreJsonExtra: (doc: Doc) => Record<string, unknown>;
|
|
71
|
+
/** The render settings the validator needs, read off the version row. */
|
|
72
|
+
validateMeta: (row: Row) => Meta;
|
|
73
|
+
renderValidation: (validation: V) => string[];
|
|
74
|
+
}
|
|
75
|
+
/** Injected with lazy defaults so registration stays light and actions unit-test. */
|
|
76
|
+
export interface VersionCommandDeps<Doc, Row, V extends Validation, Meta> {
|
|
77
|
+
store?: () => Promise<VersionStore<Doc, Row>>;
|
|
78
|
+
validate?: (document: unknown, meta: Meta) => Promise<V> | V;
|
|
79
|
+
confirmDelete?: (message: string, force?: boolean) => Promise<boolean>;
|
|
80
|
+
}
|
|
81
|
+
/** A version is a positive integer; anything else names itself in the error. */
|
|
82
|
+
export declare function parseVersionNumber(raw: string): number;
|
|
83
|
+
/** Parse a stored document without throwing — an unreadable one is a finding. */
|
|
84
|
+
export declare function parseVersionDocument(raw: unknown): JsonValue;
|
|
85
|
+
/** Count an array-valued field, or 0 for anything else. */
|
|
86
|
+
export declare function countArray(value: unknown): number;
|
|
87
|
+
export declare function registerVersionCommands<Doc, Row, Item, V extends Validation, Counts, Meta>(parent: Command, spec: VersionCommandSpec<Doc, Row, Item, V, Counts, Meta>, deps: VersionCommandDeps<Doc, Row, V, Meta>, defaults: {
|
|
88
|
+
store: () => Promise<VersionStore<Doc, Row>>;
|
|
89
|
+
validate: (document: unknown, meta: Meta) => Promise<V> | V;
|
|
90
|
+
}): void;
|
|
91
|
+
//# sourceMappingURL=version-commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-commands.d.ts","sourceRoot":"","sources":["../../src/commands/version-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,YAAY,EAAE,SAAS,EAAE,CAAC;AAE1B,qEAAqE;AACrE,MAAM,WAAW,YAAY,CAAC,GAAG,EAAE,GAAG;IACpC,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;IAC1C,YAAY,EAAE,CACZ,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,KACxC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACpB,WAAW,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;IAC1E,QAAQ,EAAE,CACR,GAAG,EAAE,GAAG,EACR,IAAI,EAAE;QAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,KAC3D,OAAO,CAAC,GAAG,CAAC,CAAC;IAClB;;;;OAIG;IACH,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;IACzD,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE;AAED,UAAU,UAAU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AC,EAAE,MAAM,EAAE,IAAI,CAAC,EACzD,IAAI,EAAE,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,EAC3C,QAAQ,EAAE;IACR,KAAK,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC7C,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAC7D,GACA,IAAI,CAyON"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { printCommandError } from "../command-errors.js";
|
|
2
|
+
import { asJson, confirm, printTable } from "./output.js";
|
|
3
|
+
import { numericOptionParser } from "../numeric-options.js";
|
|
4
|
+
import { isString } from "../predicates.js";
|
|
5
|
+
/** A version is a positive integer; anything else names itself in the error. */
|
|
6
|
+
export function parseVersionNumber(raw) {
|
|
7
|
+
const value = Number(raw.trim());
|
|
8
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
9
|
+
throw new Error(`version must be a positive integer (got "${raw}")`);
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
/** Parse a stored document without throwing — an unreadable one is a finding. */
|
|
14
|
+
export function parseVersionDocument(raw) {
|
|
15
|
+
// SAFETY: a Postgres json column arrives already decoded; either way the
|
|
16
|
+
// stored document is JSON.
|
|
17
|
+
if (!isString(raw))
|
|
18
|
+
return raw;
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(raw);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return raw;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Count an array-valued field, or 0 for anything else. */
|
|
27
|
+
export function countArray(value) {
|
|
28
|
+
return Array.isArray(value) ? value.length : 0;
|
|
29
|
+
}
|
|
30
|
+
export function registerVersionCommands(parent, spec, deps, defaults) {
|
|
31
|
+
const openStore = deps.store ?? defaults.store;
|
|
32
|
+
const validate = deps.validate ?? defaults.validate;
|
|
33
|
+
const confirmDelete = deps.confirmDelete ??
|
|
34
|
+
((message, force) => confirm(message, { force }));
|
|
35
|
+
const id = `<${spec.idArg}>`;
|
|
36
|
+
async function requireDocument(store, documentId) {
|
|
37
|
+
const doc = await store.load(documentId);
|
|
38
|
+
if (!doc)
|
|
39
|
+
throw new Error(spec.notFoundDocument(documentId));
|
|
40
|
+
return doc;
|
|
41
|
+
}
|
|
42
|
+
async function requireVersion(store, documentId, version) {
|
|
43
|
+
const row = await store.findVersion(documentId, version);
|
|
44
|
+
if (!row)
|
|
45
|
+
throw new Error(spec.notFoundVersion(documentId, version));
|
|
46
|
+
return row;
|
|
47
|
+
}
|
|
48
|
+
const versions = parent
|
|
49
|
+
.command("versions")
|
|
50
|
+
.description(spec.descriptions.group);
|
|
51
|
+
versions
|
|
52
|
+
.command(`list ${id}`)
|
|
53
|
+
.description(spec.descriptions.list)
|
|
54
|
+
.option("--save-type <type>", "Only manual, autosave or restore snapshots")
|
|
55
|
+
.option("--limit <n>", "Maximum versions to list (default 100)", numericOptionParser("--limit", { integer: true, min: 1 }))
|
|
56
|
+
.option("--json", "Print the versions as JSON")
|
|
57
|
+
.action(async (documentId, opts) => {
|
|
58
|
+
try {
|
|
59
|
+
const store = await openStore();
|
|
60
|
+
await requireDocument(store, documentId);
|
|
61
|
+
const query = {};
|
|
62
|
+
if (opts.limit !== undefined) {
|
|
63
|
+
query.limit = opts.limit;
|
|
64
|
+
}
|
|
65
|
+
if (opts.saveType) {
|
|
66
|
+
query.saveType = opts.saveType;
|
|
67
|
+
}
|
|
68
|
+
const rows = await store.listVersions(documentId, query);
|
|
69
|
+
const items = rows.map(spec.toItem);
|
|
70
|
+
if (opts.json) {
|
|
71
|
+
asJson({ [spec.idKey]: documentId, versions: items });
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
printTable(items.map(spec.tableRow));
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
process.exit(printCommandError(e, opts.json));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
versions
|
|
81
|
+
.command(`show ${id} <version>`)
|
|
82
|
+
.description(spec.descriptions.show)
|
|
83
|
+
.option("--json", "Print the metadata and the full document as JSON")
|
|
84
|
+
.action(async (documentId, version, opts) => {
|
|
85
|
+
try {
|
|
86
|
+
const number = parseVersionNumber(version);
|
|
87
|
+
const store = await openStore();
|
|
88
|
+
await requireDocument(store, documentId);
|
|
89
|
+
const row = await requireVersion(store, documentId, number);
|
|
90
|
+
const item = spec.toItem(row);
|
|
91
|
+
const document = parseVersionDocument(row.document);
|
|
92
|
+
if (opts.json) {
|
|
93
|
+
asJson({ ...item, document });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
printTable([spec.tableRow(item)]);
|
|
97
|
+
console.log(spec.showSummary(spec.counts(document), item));
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
process.exit(printCommandError(e, opts.json));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
versions
|
|
104
|
+
.command(`create ${id}`)
|
|
105
|
+
.description(spec.descriptions.create)
|
|
106
|
+
.option("--name <name>", "Label for the snapshot")
|
|
107
|
+
.option("--json", "Print the created version as JSON")
|
|
108
|
+
.action(async (documentId, opts) => {
|
|
109
|
+
try {
|
|
110
|
+
const store = await openStore();
|
|
111
|
+
const doc = await requireDocument(store, documentId);
|
|
112
|
+
const row = await store.snapshot(doc, {
|
|
113
|
+
saveType: "manual",
|
|
114
|
+
name: opts.name ?? null
|
|
115
|
+
});
|
|
116
|
+
const item = spec.toItem(row);
|
|
117
|
+
if (opts.json) {
|
|
118
|
+
asJson(item);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
console.log(`✅ Snapshot saved as v${item.version}${item.name ? ` (${String(item.name)})` : ""}`);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
process.exit(printCommandError(e, opts.json));
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
versions
|
|
128
|
+
.command(`restore ${id} <version>`)
|
|
129
|
+
.description(spec.descriptions.restore)
|
|
130
|
+
.option("--json", spec.descriptions.restoreJson)
|
|
131
|
+
.action(async (documentId, version, opts) => {
|
|
132
|
+
// The verdict leaves the try block in a variable: `process.exit` throws
|
|
133
|
+
// under test, and an exit inside the try would be caught here as a
|
|
134
|
+
// command failure.
|
|
135
|
+
let restoredOk = false;
|
|
136
|
+
try {
|
|
137
|
+
const number = parseVersionNumber(version);
|
|
138
|
+
const store = await openStore();
|
|
139
|
+
const doc = await requireDocument(store, documentId);
|
|
140
|
+
const target = await requireVersion(store, documentId, number);
|
|
141
|
+
// Snapshot what is about to be overwritten first, so the restore is
|
|
142
|
+
// itself undoable — same order the tRPC router uses.
|
|
143
|
+
const backup = await store.snapshot(doc, {
|
|
144
|
+
saveType: "restore",
|
|
145
|
+
name: `Before restore to v${number}`
|
|
146
|
+
});
|
|
147
|
+
const updated = await store.restore(doc, target);
|
|
148
|
+
if (!updated)
|
|
149
|
+
throw new Error(spec.conflict);
|
|
150
|
+
const document = parseVersionDocument(target.document);
|
|
151
|
+
const validation = await validate(document, spec.validateMeta(target));
|
|
152
|
+
if (opts.json) {
|
|
153
|
+
asJson({
|
|
154
|
+
[spec.idKey]: documentId,
|
|
155
|
+
restored: spec.toItem(target),
|
|
156
|
+
snapshot: spec.toItem(backup),
|
|
157
|
+
...spec.restoreJsonExtra(updated),
|
|
158
|
+
validation
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
console.log(spec.restoreSummary(documentId, number, spec.counts(document), target));
|
|
163
|
+
const meta = backup;
|
|
164
|
+
console.log(` pre-restore state saved as v${meta.version} (${meta.save_type})`);
|
|
165
|
+
console.log(spec.renderValidation(validation).join("\n"));
|
|
166
|
+
}
|
|
167
|
+
restoredOk = validation.ok;
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
process.exit(printCommandError(e, opts.json));
|
|
171
|
+
}
|
|
172
|
+
process.exit(restoredOk ? 0 : 1);
|
|
173
|
+
});
|
|
174
|
+
versions
|
|
175
|
+
.command(`delete ${id} <version>`)
|
|
176
|
+
.description(spec.descriptions.delete)
|
|
177
|
+
.option("-y, --yes", "Skip the confirmation prompt")
|
|
178
|
+
.option("--json", "Print the result as JSON")
|
|
179
|
+
.action(async (documentId, version, opts) => {
|
|
180
|
+
let aborted = false;
|
|
181
|
+
try {
|
|
182
|
+
const number = parseVersionNumber(version);
|
|
183
|
+
const store = await openStore();
|
|
184
|
+
await requireDocument(store, documentId);
|
|
185
|
+
await requireVersion(store, documentId, number);
|
|
186
|
+
const ok = await confirmDelete(spec.confirmDelete(documentId, number), opts.yes);
|
|
187
|
+
if (!ok) {
|
|
188
|
+
aborted = true;
|
|
189
|
+
if (opts.json) {
|
|
190
|
+
asJson({
|
|
191
|
+
[spec.idKey]: documentId,
|
|
192
|
+
version: number,
|
|
193
|
+
deleted: false,
|
|
194
|
+
aborted: true
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
console.error("Aborted.");
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
await store.deleteVersion(documentId, number);
|
|
203
|
+
if (opts.json) {
|
|
204
|
+
asJson({
|
|
205
|
+
[spec.idKey]: documentId,
|
|
206
|
+
version: number,
|
|
207
|
+
deleted: true
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
console.log(spec.deleted(documentId, number));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
process.exit(printCommandError(e, opts.json));
|
|
217
|
+
}
|
|
218
|
+
if (aborted)
|
|
219
|
+
process.exit(1);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=version-commands.js.map
|
|
@@ -0,0 +1 @@
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AI,CAAC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,EACtC,IAAI,CAAC,GAAG,CACT,CAAC;YACF,IAAI,CAAC,EAAE,EAAE,CAAC;gBACR,OAAO,GAAG,IAAI,CAAC;gBACf,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;oBACd,MAAM,CAAC;wBACL,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU;wBACxB,OAAO,EAAE,MAAM;wBACf,OAAO,EAAE,KAAK;wBACd,OAAO,EAAE,IAAI;qBACd,CAAC,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,CAAC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;gBAC9C,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;oBACd,MAAM,CAAC;wBACL,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,UAAU;wBACxB,OAAO,EAAE,MAAM;wBACf,OAAO,EAAE,IAAI;qBACd,CAAC,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;gBAChD,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,OAAO;YAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC,CACF,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Default `nodetool-debug/<kind>-<slug>-<timestamp>` bundle directory. */
|
|
2
|
+
export declare function defaultDebugOutDir(kind: string, ref: string): string;
|
|
3
|
+
/** Write `<kind>.json`, `report.json` and `report.md` into the bundle directory. */
|
|
4
|
+
export declare function writeDebugBundle(args: {
|
|
5
|
+
kind: string;
|
|
6
|
+
ref: string;
|
|
7
|
+
outDir?: string;
|
|
8
|
+
raw: unknown;
|
|
9
|
+
report: unknown;
|
|
10
|
+
reportMarkdown: string;
|
|
11
|
+
}): Promise<string>;
|
|
12
|
+
//# sourceMappingURL=debug-bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-bundle.d.ts","sourceRoot":"","sources":["../src/debug-bundle.ts"],"names":[],"mappings":"AAIA,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAKpE;AAED,oFAAoF;AACpF,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiBlB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { trimHyphens } from "./trimHyphens.js";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
/** Default `nodetool-debug/<kind>-<slug>-<timestamp>` bundle directory. */
|
|
5
|
+
export function defaultDebugOutDir(kind, ref) {
|
|
6
|
+
const slug = trimHyphens(ref.replace(/[^a-zA-Z0-9_-]+/g, "-")).slice(0, 40) || kind;
|
|
7
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
8
|
+
return resolve(`nodetool-debug/${kind}-${slug}-${stamp}`);
|
|
9
|
+
}
|
|
10
|
+
/** Write `<kind>.json`, `report.json` and `report.md` into the bundle directory. */
|
|
11
|
+
export async function writeDebugBundle(args) {
|
|
12
|
+
const bundleDir = args.outDir
|
|
13
|
+
? resolve(args.outDir)
|
|
14
|
+
: defaultDebugOutDir(args.kind, args.ref);
|
|
15
|
+
await mkdir(bundleDir, { recursive: true });
|
|
16
|
+
await writeFile(join(bundleDir, `${args.kind}.json`), JSON.stringify(args.raw, null, 2), "utf8");
|
|
17
|
+
await writeFile(join(bundleDir, "report.json"), JSON.stringify(args.report, null, 2), "utf8");
|
|
18
|
+
await writeFile(join(bundleDir, "report.md"), args.reportMarkdown, "utf8");
|
|
19
|
+
return bundleDir;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=debug-bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug-bundle.js","sourceRoot":"","sources":["../src/debug-bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,2EAA2E;AAC3E,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,GAAW;IAC1D,MAAM,IAAI,GACR,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC;IACzE,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC7D,OAAO,OAAO,CAAC,kBAAkB,IAAI,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED,oFAAoF;AACpF,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAOtC;IACC,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM;QAC3B,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;QACtB,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,MAAM,SAAS,CACb,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,IAAI,OAAO,CAAC,EACpC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,EACjC,MAAM,CACP,CAAC;IACF,MAAM,SAAS,CACb,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,EAC9B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EACpC,MAAM,CACP,CAAC;IACF,MAAM,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IAC3E,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** A decoded JSON document, before anything validates its shape. */
|
|
2
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
3
|
+
[key: string]: JsonValue;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The document a target carries, unwrapping a `document` field (string or
|
|
7
|
+
* object) when there is one. Never throws — an unreadable document is a
|
|
8
|
+
* validation finding, not a crash.
|
|
9
|
+
*/
|
|
10
|
+
export declare function documentOf(raw: unknown): JsonValue;
|
|
11
|
+
//# sourceMappingURL=document-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-json.d.ts","sourceRoot":"","sources":["../src/document-json.ts"],"names":[],"mappings":"AAGA,oEAAoE;AACpE,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEjC;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,CAelD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Decoded JSON and the `document` unwrapping shared by the debug targets. */
|
|
2
|
+
import { isRecord, isString } from "./predicates.js";
|
|
3
|
+
/**
|
|
4
|
+
* The document a target carries, unwrapping a `document` field (string or
|
|
5
|
+
* object) when there is one. Never throws — an unreadable document is a
|
|
6
|
+
* validation finding, not a crash.
|
|
7
|
+
*/
|
|
8
|
+
export function documentOf(raw) {
|
|
9
|
+
// SAFETY: a target is read from a JSON file or a json column, so every
|
|
10
|
+
// branch below carries decoded JSON.
|
|
11
|
+
if (!isRecord(raw))
|
|
12
|
+
return raw;
|
|
13
|
+
const inner = raw.document;
|
|
14
|
+
if (isString(inner)) {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(inner);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return inner;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// SAFETY: same JSON provenance as the branch above.
|
|
23
|
+
if (inner !== undefined)
|
|
24
|
+
return inner;
|
|
25
|
+
return raw;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=document-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-json.js","sourceRoot":"","sources":["../src/document-json.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAWrD;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAY;IACrC,uEAAuE;IACvE,qCAAqC;IACrC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,GAAgB,CAAC;IAC5C,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,CAAC;IAC3B,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,oDAAoD;IACpD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAkB,CAAC;IACnD,OAAO,GAAgB,CAAC;AAC1B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC"}
|