@prisma/cli-engine 0.0.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.
- package/LICENSE +158 -0
- package/README.md +11 -0
- package/dist/engine-DXE014TZ.js +1703 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.js +200 -0
- package/dist/protocol-C1JQcGl9.js +106 -0
- package/dist/protocol-DGUfR-Ni.d.ts +117 -0
- package/dist/protocol.d.ts +2 -0
- package/dist/protocol.js +2 -0
- package/dist/run-summary-CPpYAYtS.d.ts +787 -0
- package/dist/testing.d.ts +67 -0
- package/dist/testing.js +96 -0
- package/package.json +60 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { $ as positional, A as Block, B as Severity, C as LoadedConfig, D as CommandContext, E as Runtime, F as PresentedResult, G as defineConfigSection, H as StreamMeta, I as TreeNode, J as Char, K as Args, L as Ui, M as Outcome, N as PRESENTED, O as Credentials, P as Presentations, Q as flag, R as ManagementApiClient, S as InputStream, T as PRISMA_CONFIG_VERSION, U as ConfigSection, V as StreamEvent, W as SectionValidation, X as FlagSpec, Y as CommandArgs, Z as PositionalSpec, _ as SessionCommandDefinition, a as defineCommandFamily, b as defineSessionCommand, c as CommandHandler, d as CompletedEnvelope, f as ErroredEnvelope, g as ServerCommandDefinition, h as NeedsSpec, i as MountedTree, j as Format, k as PromptSurface, l as CommandHelp, m as HelpSpec, n as RunSummary, o as AnyCommand, p as Handler, q as ArgsSpec, r as CommandFamily, s as CommandDefinition, t as EngineCommandSnapshot, u as CommandNeeds, v as defineCommand, w as OutputStream, x as HostProcess, y as defineServerCommand, z as EngineEvent } from "./run-summary-CPpYAYtS.js";
|
|
2
|
+
|
|
3
|
+
//#region src/cli.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The observation hooks a bin may attach to a run. Deliberately
|
|
6
|
+
* narrower than the engine's internal hook set (whose other members
|
|
7
|
+
* are test seams reachable only through the ./testing harness).
|
|
8
|
+
*/
|
|
9
|
+
interface CliRunHooks {
|
|
10
|
+
/** Fired exactly once per run, after settlement, for runs that
|
|
11
|
+
* reached a mounted command. Never fired for --help/--version.
|
|
12
|
+
* Errors thrown by the hook are swallowed. */
|
|
13
|
+
readonly onSettled?: (summary: RunSummary) => void;
|
|
14
|
+
}
|
|
15
|
+
interface Cli {
|
|
16
|
+
/**
|
|
17
|
+
* Parse, execute, render, return the exit code. Never touches
|
|
18
|
+
* process globals — it exits only through the runtime's exit proxy
|
|
19
|
+
* (second-signal force exit) and writes only to the provided streams.
|
|
20
|
+
* `hooks` is the bin's observation seam (telemetry).
|
|
21
|
+
*/
|
|
22
|
+
run(argv: readonly string[], runtime: Runtime, hooks?: CliRunHooks): Promise<number>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Shell-side construction. Group help is declared with the mount.
|
|
26
|
+
* Collisions, unknown groups, reserved-flag violations, grammar
|
|
27
|
+
* violations, and foreign-section references fail construction (build
|
|
28
|
+
* time, not run time).
|
|
29
|
+
*/
|
|
30
|
+
declare function createCli(spec: {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly version: string;
|
|
33
|
+
readonly commandFamilies: readonly CommandFamily[];
|
|
34
|
+
readonly groups: Readonly<Record<string, {
|
|
35
|
+
readonly brief: string;
|
|
36
|
+
readonly description?: string;
|
|
37
|
+
}>>;
|
|
38
|
+
readonly commands: MountedTree;
|
|
39
|
+
}): Cli;
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/config-loader.d.ts
|
|
42
|
+
/**
|
|
43
|
+
* Attaches the version marker to a prisma.config.ts export. Top-level
|
|
44
|
+
* keys are the config sections. Never throws — bad section values are
|
|
45
|
+
* the section validator's problem, not defineConfig's.
|
|
46
|
+
*/
|
|
47
|
+
declare function defineConfig<T extends Record<string, unknown>>(config: T): T & {
|
|
48
|
+
readonly $prismaConfig: number;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The real-disk loader behind Runtime.config: reads prisma.config.ts
|
|
52
|
+
* from cwd (cwd only — no walking up) and produces LoadedConfig. The
|
|
53
|
+
* bin builds Runtime.config with this; tests hand in fixtures.
|
|
54
|
+
*/
|
|
55
|
+
declare function loadConfig(cwd: string): Promise<LoadedConfig>;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { type AnyCommand, type Args, type ArgsSpec, type Block, type Char, type Cli, type CliRunHooks, type CommandArgs, type CommandContext, type CommandDefinition, type CommandFamily, type CommandHandler, type CommandHelp, type CommandNeeds, type CompletedEnvelope, type ConfigSection, type Credentials, type EngineCommandSnapshot, type EngineEvent, type ErroredEnvelope, type FlagSpec, type Format, type Handler, type HelpSpec, type HostProcess, type InputStream, type LoadedConfig, type ManagementApiClient, type MountedTree, type NeedsSpec, type Outcome, type OutputStream, PRESENTED, PRISMA_CONFIG_VERSION, type PositionalSpec, type Presentations, type PresentedResult, type PromptSurface, type RunSummary, type Runtime, type SectionValidation, type ServerCommandDefinition, type SessionCommandDefinition, type Severity, type StreamEvent, type StreamMeta, type TreeNode, type Ui, createCli, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, flag, loadConfig, positional };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { i as positional, n as PRESENTED, r as flag, t as buildEngine } from "./engine-DXE014TZ.js";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
//#region src/cli.ts
|
|
6
|
+
/**
|
|
7
|
+
* Shell-side construction. Group help is declared with the mount.
|
|
8
|
+
* Collisions, unknown groups, reserved-flag violations, grammar
|
|
9
|
+
* violations, and foreign-section references fail construction (build
|
|
10
|
+
* time, not run time).
|
|
11
|
+
*/
|
|
12
|
+
function createCli(spec) {
|
|
13
|
+
const engine = buildEngine(spec);
|
|
14
|
+
return { run: (argv, runtime, hooks) => engine.execute(argv, runtime, { onSettled: hooks?.onSettled }) };
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/command-family.ts
|
|
18
|
+
function defineCommandFamily(spec) {
|
|
19
|
+
return Object.freeze({
|
|
20
|
+
configSection: spec.configSection,
|
|
21
|
+
commands: spec.commands,
|
|
22
|
+
docsBaseUrl: spec.docsBaseUrl
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/commands.ts
|
|
27
|
+
function normalizeHelp(spec) {
|
|
28
|
+
return Object.freeze({
|
|
29
|
+
summary: spec.summary,
|
|
30
|
+
description: spec.description,
|
|
31
|
+
examples: spec.examples ?? []
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function normalizeArgs(spec) {
|
|
35
|
+
return Object.freeze({
|
|
36
|
+
flags: spec?.flags ?? {},
|
|
37
|
+
positionals: spec?.positionals ?? {}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function normalizeNeeds(spec) {
|
|
41
|
+
return Object.freeze({
|
|
42
|
+
config: spec?.config,
|
|
43
|
+
credentials: spec?.credentials === true,
|
|
44
|
+
dependencies: spec?.dependencies ?? [],
|
|
45
|
+
interaction: spec?.interaction === true
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function defineCommand(def) {
|
|
49
|
+
return Object.freeze({
|
|
50
|
+
kind: "result-command",
|
|
51
|
+
help: normalizeHelp(def.help),
|
|
52
|
+
args: normalizeArgs(def.args),
|
|
53
|
+
needs: normalizeNeeds(def.needs),
|
|
54
|
+
exitCodes: def.exitCodes ?? {},
|
|
55
|
+
handler: def.handler
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function defineSessionCommand(def) {
|
|
59
|
+
return Object.freeze({
|
|
60
|
+
kind: "session-command",
|
|
61
|
+
help: normalizeHelp(def.help),
|
|
62
|
+
args: normalizeArgs(def.args),
|
|
63
|
+
needs: normalizeNeeds(def.needs),
|
|
64
|
+
handler: def.handler
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function defineServerCommand(def) {
|
|
68
|
+
return Object.freeze({
|
|
69
|
+
kind: "server-command",
|
|
70
|
+
help: normalizeHelp(def.help),
|
|
71
|
+
args: normalizeArgs(def.args),
|
|
72
|
+
needs: normalizeNeeds(def.needs),
|
|
73
|
+
handler: def.handler
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/runtime.ts
|
|
78
|
+
/**
|
|
79
|
+
* The config contract version defineConfig writes as the structural
|
|
80
|
+
* `$prismaConfig` marker; the loader checks it before interpreting
|
|
81
|
+
* anything.
|
|
82
|
+
*/
|
|
83
|
+
const PRISMA_CONFIG_VERSION = 1;
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/config-loader.ts
|
|
86
|
+
/**
|
|
87
|
+
* The minimal prisma.config.ts loader behind Runtime.config:
|
|
88
|
+
* discover the file in cwd (cwd only — no walking up), evaluate it,
|
|
89
|
+
* check the defineConfig version marker, and produce LoadedConfig.
|
|
90
|
+
*
|
|
91
|
+
* Absence is not an error: section validators own absence, so a missing
|
|
92
|
+
* file is an empty LoadedConfig. An evaluated file WITHOUT the marker (a
|
|
93
|
+
* classic Prisma 7 config, which uses the same filename) fails early
|
|
94
|
+
* with one typed diagnostic — the loader never partially interprets an
|
|
95
|
+
* unmarked file, and never guesses.
|
|
96
|
+
*/
|
|
97
|
+
const CONFIG_FILE_NAME = "prisma.config.ts";
|
|
98
|
+
const MARKER_KEY = "$prismaConfig";
|
|
99
|
+
/**
|
|
100
|
+
* Attaches the version marker to a prisma.config.ts export. Top-level
|
|
101
|
+
* keys are the config sections. Never throws — bad section values are
|
|
102
|
+
* the section validator's problem, not defineConfig's.
|
|
103
|
+
*/
|
|
104
|
+
function defineConfig(config) {
|
|
105
|
+
return Object.freeze({
|
|
106
|
+
...config,
|
|
107
|
+
$prismaConfig: 1
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function hasVersionMarker(value) {
|
|
111
|
+
return typeof value === "object" && value !== null && typeof value[MARKER_KEY] === "number";
|
|
112
|
+
}
|
|
113
|
+
function fileLevelConfig(diagnostic) {
|
|
114
|
+
return {
|
|
115
|
+
sections: {},
|
|
116
|
+
diagnostics: [{
|
|
117
|
+
section: null,
|
|
118
|
+
diagnostic
|
|
119
|
+
}]
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function missingMarkerDiagnostic(path) {
|
|
123
|
+
return {
|
|
124
|
+
code: "CLI.CONFIG_MISSING_MARKER",
|
|
125
|
+
severity: "error",
|
|
126
|
+
summary: "This prisma.config.ts was not written for this version of the Prisma CLI, so it cannot be used.",
|
|
127
|
+
why: "Configs for this CLI are created with defineConfig, which records a version marker on the exported object. This file's default export has no marker — it is most likely a Prisma 7 config, which uses the same filename — and the CLI stops rather than misread it.",
|
|
128
|
+
nextActions: [{
|
|
129
|
+
kind: "user-choice",
|
|
130
|
+
label: "Migrate the file: wrap the exported object in defineConfig from @prisma/cli-engine and export the result as the default export."
|
|
131
|
+
}],
|
|
132
|
+
where: { path }
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function firstLine(text) {
|
|
136
|
+
const newline = text.indexOf("\n");
|
|
137
|
+
return (newline === -1 ? text : text.slice(0, newline)).trim();
|
|
138
|
+
}
|
|
139
|
+
function unsupportedVersionDiagnostic(path, found) {
|
|
140
|
+
return {
|
|
141
|
+
code: "CLI.CONFIG_INVALID",
|
|
142
|
+
severity: "error",
|
|
143
|
+
summary: `prisma.config.ts declares config version ${found}, but this CLI supports only version 1.`,
|
|
144
|
+
nextActions: [{
|
|
145
|
+
kind: "user-choice",
|
|
146
|
+
label: "Regenerate the config with a defineConfig matching this CLI, or update the CLI to a version that supports the declared config version."
|
|
147
|
+
}],
|
|
148
|
+
where: { path }
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function unreadableDiagnostic(path, cause) {
|
|
152
|
+
return {
|
|
153
|
+
code: "CLI.CONFIG_UNREADABLE",
|
|
154
|
+
severity: "error",
|
|
155
|
+
summary: `prisma.config.ts could not be evaluated: ${firstLine(cause instanceof Error ? cause.message : String(cause))}`,
|
|
156
|
+
nextActions: [{
|
|
157
|
+
kind: "user-choice",
|
|
158
|
+
label: "Fix the error in the file, then run the command again."
|
|
159
|
+
}],
|
|
160
|
+
where: { path }
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The real-disk loader behind Runtime.config: reads prisma.config.ts
|
|
165
|
+
* from cwd (cwd only — no walking up) and produces LoadedConfig. The
|
|
166
|
+
* bin builds Runtime.config with this; tests hand in fixtures.
|
|
167
|
+
*/
|
|
168
|
+
async function loadConfig(cwd) {
|
|
169
|
+
const path = join(cwd, CONFIG_FILE_NAME);
|
|
170
|
+
if (!existsSync(path)) return {
|
|
171
|
+
sections: {},
|
|
172
|
+
diagnostics: []
|
|
173
|
+
};
|
|
174
|
+
let loaded;
|
|
175
|
+
try {
|
|
176
|
+
loaded = await import(pathToFileURL(path).href);
|
|
177
|
+
} catch (cause) {
|
|
178
|
+
return fileLevelConfig(unreadableDiagnostic(path, cause));
|
|
179
|
+
}
|
|
180
|
+
const exported = loaded.default;
|
|
181
|
+
if (!hasVersionMarker(exported)) return fileLevelConfig(missingMarkerDiagnostic(path));
|
|
182
|
+
const version = exported[MARKER_KEY];
|
|
183
|
+
if (version !== 1) return fileLevelConfig(unsupportedVersionDiagnostic(path, version));
|
|
184
|
+
const sections = {};
|
|
185
|
+
for (const [key, value] of Object.entries(exported)) if (key !== MARKER_KEY) sections[key] = value;
|
|
186
|
+
return {
|
|
187
|
+
sections,
|
|
188
|
+
diagnostics: []
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/config-section.ts
|
|
193
|
+
function defineConfigSection(spec) {
|
|
194
|
+
return Object.freeze({
|
|
195
|
+
name: spec.name,
|
|
196
|
+
validate: spec.validate
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
export { PRESENTED, PRISMA_CONFIG_VERSION, createCli, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, flag, loadConfig, positional };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//#region src/protocol.ts
|
|
2
|
+
function ifDefined(key, value) {
|
|
3
|
+
return value !== void 0 ? { [key]: value } : {};
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Structured CLI error carrying everything an error envelope needs.
|
|
7
|
+
* `code` is a dotted `NAMESPACE.SUBCODE` string; the namespace prefix is
|
|
8
|
+
* the error's category.
|
|
9
|
+
*/
|
|
10
|
+
var CliStructuredError = class extends Error {
|
|
11
|
+
code;
|
|
12
|
+
severity;
|
|
13
|
+
why;
|
|
14
|
+
nextActions;
|
|
15
|
+
where;
|
|
16
|
+
meta;
|
|
17
|
+
docsUrl;
|
|
18
|
+
constructor(code, summary, options) {
|
|
19
|
+
super(summary, options?.cause !== void 0 ? { cause: options.cause } : void 0);
|
|
20
|
+
this.name = "CliStructuredError";
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.severity = options?.severity ?? "error";
|
|
23
|
+
this.why = options?.why;
|
|
24
|
+
this.nextActions = options?.nextActions ?? [];
|
|
25
|
+
this.where = options?.where ? {
|
|
26
|
+
...ifDefined("path", options.where.path),
|
|
27
|
+
...ifDefined("line", options.where.line)
|
|
28
|
+
} : void 0;
|
|
29
|
+
this.meta = options?.meta;
|
|
30
|
+
this.docsUrl = options?.docsUrl;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Converts this error to an error envelope for output formatting.
|
|
34
|
+
*/
|
|
35
|
+
toEnvelope() {
|
|
36
|
+
return {
|
|
37
|
+
ok: false,
|
|
38
|
+
code: this.code,
|
|
39
|
+
severity: this.severity,
|
|
40
|
+
summary: this.message,
|
|
41
|
+
...ifDefined("why", this.why),
|
|
42
|
+
nextActions: this.nextActions,
|
|
43
|
+
...ifDefined("where", this.where),
|
|
44
|
+
...ifDefined("meta", this.meta),
|
|
45
|
+
...ifDefined("docsUrl", this.docsUrl)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Duck-typed guard that works across module boundaries where
|
|
50
|
+
* instanceof may fail.
|
|
51
|
+
*/
|
|
52
|
+
static is(error) {
|
|
53
|
+
if (!(error instanceof Error)) return false;
|
|
54
|
+
const candidate = error;
|
|
55
|
+
return candidate.name === "CliStructuredError" && typeof candidate.code === "string" && typeof candidate.toEnvelope === "function";
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var OkImpl = class {
|
|
59
|
+
ok = true;
|
|
60
|
+
value;
|
|
61
|
+
constructor(value) {
|
|
62
|
+
this.value = value;
|
|
63
|
+
Object.freeze(this);
|
|
64
|
+
}
|
|
65
|
+
assertOk() {
|
|
66
|
+
return this.value;
|
|
67
|
+
}
|
|
68
|
+
assertNotOk() {
|
|
69
|
+
throw new Error("Expected NotOk result but got Ok");
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var NotOkImpl = class {
|
|
73
|
+
ok = false;
|
|
74
|
+
failure;
|
|
75
|
+
constructor(failure) {
|
|
76
|
+
this.failure = failure;
|
|
77
|
+
Object.freeze(this);
|
|
78
|
+
}
|
|
79
|
+
assertOk() {
|
|
80
|
+
throw new Error("Expected Ok result but got NotOk");
|
|
81
|
+
}
|
|
82
|
+
assertNotOk() {
|
|
83
|
+
return this.failure;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Creates a successful result.
|
|
88
|
+
*/
|
|
89
|
+
function ok(value) {
|
|
90
|
+
return new OkImpl(value);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Creates an unsuccessful result.
|
|
94
|
+
*/
|
|
95
|
+
function notOk(failure) {
|
|
96
|
+
return new NotOkImpl(failure);
|
|
97
|
+
}
|
|
98
|
+
const OK_VOID = new OkImpl(void 0);
|
|
99
|
+
/**
|
|
100
|
+
* Returns the singleton successful void result.
|
|
101
|
+
*/
|
|
102
|
+
function okVoid() {
|
|
103
|
+
return OK_VOID;
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
export { okVoid as i, notOk as n, ok as r, CliStructuredError as t };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
//#region src/protocol.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The protocol types — the shapes that cross package and process
|
|
4
|
+
* boundaries. Types-only consumers import `@prisma/cli-engine/protocol`
|
|
5
|
+
* and drag no engine code.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A recorded finding: pure data, never thrown, no stack. Field-for-field
|
|
9
|
+
* the error envelope minus `ok`; the two shapes never diverge.
|
|
10
|
+
* `nextActions` is always present (empty when there are none); the
|
|
11
|
+
* remaining optional fields are wire fields whose absence is data.
|
|
12
|
+
*/
|
|
13
|
+
interface Diagnostic {
|
|
14
|
+
readonly code: `${string}.${string}`;
|
|
15
|
+
readonly severity: "error" | "warn" | "info";
|
|
16
|
+
readonly summary: string;
|
|
17
|
+
readonly why?: string;
|
|
18
|
+
readonly nextActions: readonly NextAction[];
|
|
19
|
+
readonly where?: {
|
|
20
|
+
readonly path?: string;
|
|
21
|
+
readonly line?: number;
|
|
22
|
+
};
|
|
23
|
+
readonly meta?: Record<string, unknown>;
|
|
24
|
+
readonly docsUrl?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The typed agent-facing follow-up action.
|
|
28
|
+
*/
|
|
29
|
+
interface NextAction {
|
|
30
|
+
readonly kind: "run-command" | "user-choice" | "edit-file" | "done";
|
|
31
|
+
readonly label: string;
|
|
32
|
+
readonly command?: string;
|
|
33
|
+
readonly commands?: readonly string[];
|
|
34
|
+
readonly reason?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The serialized form of a CliStructuredError.
|
|
38
|
+
*/
|
|
39
|
+
type CliErrorEnvelope = {
|
|
40
|
+
readonly ok: false;
|
|
41
|
+
} & Diagnostic;
|
|
42
|
+
/**
|
|
43
|
+
* Structured CLI error carrying everything an error envelope needs.
|
|
44
|
+
* `code` is a dotted `NAMESPACE.SUBCODE` string; the namespace prefix is
|
|
45
|
+
* the error's category.
|
|
46
|
+
*/
|
|
47
|
+
declare class CliStructuredError extends Error {
|
|
48
|
+
readonly code: `${string}.${string}`;
|
|
49
|
+
readonly severity: Diagnostic["severity"];
|
|
50
|
+
readonly why: string | undefined;
|
|
51
|
+
readonly nextActions: readonly NextAction[];
|
|
52
|
+
readonly where: {
|
|
53
|
+
readonly path?: string;
|
|
54
|
+
readonly line?: number;
|
|
55
|
+
} | undefined;
|
|
56
|
+
readonly meta: Record<string, unknown> | undefined;
|
|
57
|
+
readonly docsUrl: string | undefined;
|
|
58
|
+
constructor(code: `${string}.${string}`, summary: string, options?: {
|
|
59
|
+
readonly severity?: Diagnostic["severity"];
|
|
60
|
+
readonly why?: string;
|
|
61
|
+
readonly nextActions?: readonly NextAction[];
|
|
62
|
+
readonly where?: {
|
|
63
|
+
readonly path?: string;
|
|
64
|
+
readonly line?: number;
|
|
65
|
+
};
|
|
66
|
+
readonly meta?: Record<string, unknown>;
|
|
67
|
+
readonly docsUrl?: string;
|
|
68
|
+
readonly cause?: unknown;
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* Converts this error to an error envelope for output formatting.
|
|
72
|
+
*/
|
|
73
|
+
toEnvelope(): CliErrorEnvelope;
|
|
74
|
+
/**
|
|
75
|
+
* Duck-typed guard that works across module boundaries where
|
|
76
|
+
* instanceof may fail.
|
|
77
|
+
*/
|
|
78
|
+
static is(error: unknown): error is CliStructuredError;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A successful result containing a value.
|
|
82
|
+
*/
|
|
83
|
+
interface Ok<T> {
|
|
84
|
+
readonly ok: true;
|
|
85
|
+
readonly value: T;
|
|
86
|
+
assertOk(): T;
|
|
87
|
+
assertNotOk(): never;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* An unsuccessful result containing failure details.
|
|
91
|
+
*/
|
|
92
|
+
interface NotOk<F> {
|
|
93
|
+
readonly ok: false;
|
|
94
|
+
readonly failure: F;
|
|
95
|
+
assertOk(): never;
|
|
96
|
+
assertNotOk(): F;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A discriminated union representing either success (Ok) or failure
|
|
100
|
+
* (NotOk). The standard way to return expected failures as values
|
|
101
|
+
* rather than throwing.
|
|
102
|
+
*/
|
|
103
|
+
type Result<T, F> = Ok<T> | NotOk<F>;
|
|
104
|
+
/**
|
|
105
|
+
* Creates a successful result.
|
|
106
|
+
*/
|
|
107
|
+
declare function ok<T>(value: T): Ok<T>;
|
|
108
|
+
/**
|
|
109
|
+
* Creates an unsuccessful result.
|
|
110
|
+
*/
|
|
111
|
+
declare function notOk<F>(failure: F): NotOk<F>;
|
|
112
|
+
/**
|
|
113
|
+
* Returns the singleton successful void result.
|
|
114
|
+
*/
|
|
115
|
+
declare function okVoid(): Ok<void>;
|
|
116
|
+
//#endregion
|
|
117
|
+
export { NotOk as a, notOk as c, NextAction as i, ok as l, CliStructuredError as n, Ok as o, Diagnostic as r, Result as s, CliErrorEnvelope as t, okVoid as u };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as NotOk, c as notOk, i as NextAction, l as ok, n as CliStructuredError, o as Ok, r as Diagnostic, s as Result, t as CliErrorEnvelope, u as okVoid } from "./protocol-DGUfR-Ni.js";
|
|
2
|
+
export { type CliErrorEnvelope, CliStructuredError, type Diagnostic, type NextAction, type NotOk, type Ok, type Result, notOk, ok, okVoid };
|
package/dist/protocol.js
ADDED