@prisma/cli-engine 0.0.8 → 8.0.0-rc.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/dist/index.d.ts +54 -3
- package/dist/index.js +165 -3
- package/dist/{protocol-C1JQcGl9.js → protocol-D1CRNkhv.js} +25 -4
- package/dist/{protocol-CpZLdxML.d.ts → protocol-YjqPCCOG.d.ts} +23 -3
- package/dist/protocol.d.ts +2 -2
- package/dist/protocol.js +2 -2
- package/dist/{run-summary-CVHIRjTS.d.ts → report-B7M-sp7P.d.ts} +204 -65
- package/dist/testing.d.ts +29 -2
- package/dist/testing.js +46 -23
- package/dist/{token-claims-_AF7BYbq.js → token-claims-Cwrz7N2O.js} +966 -138
- package/package.json +10 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { n as CliStructuredError } from "./protocol-
|
|
1
|
+
import { $ as PRESENTED, A as EngineCommandSnapshot, At as FlagSpec, B as OpenUrlRequest, C as HostProcess, Ct as ConfigSection, D as PRISMA_CONFIG_VERSION, Dt as ArgsSpec, E as OutputStream, Et as Args, F as PackageManagerRunner, G as SpawnChild, H as ChildResult, I as PackageOperations, J as SpawnedChild, K as SpawnOptions, L as BrowserWaitRequest, M as PackageManagerId, Mt as flag, N as PackageManagerRunRequest, Nt as positional, O as Runtime, Ot as Char, P as PackageManagerRunResult, Q as Outcome, R as CommandContext, S as defineSessionCommand, St as TokenStorage, T as LoadedConfig, Tt as defineConfigSection, U as ChildStatusSettlement, V as PromptSurface, W as ExitWithChildStatusOptions, X as Block, Y as exitWithChildStatus, Z as Format, _ as ServerCommandDefinition, _t as SERVICE_TOKEN_ENV_VAR, a as RedirectSpec, at as Tone, b as defineCommand, bt as ManagementApiClient, c as CommandDefinition, ct as EngineEvent, d as CommandNeeds, dt as StreamMeta, et as Presentations, f as CompletedEnvelope, ft as ActiveCredential, g as NeedsSpec, gt as CredentialOrigin, h as HelpSpec, ht as CredentialManager, i as MountedTree, it as Text, j as RunSummary, jt as PositionalSpec, k as TelemetryPayload, kt as CommandArgs, l as CommandHandler, lt as Severity, m as Handler, mt as CredentialIdentity, n as CommandFamily, nt as Span, o as defineCommandFamily, ot as TreeNode, p as ErroredEnvelope, pt as Credential, q as SpawnRequest, r as CommandRedirect, rt as Status, s as AnyCommand, st as Ui, t as TelemetryDeclaration, tt as PresentedResult, u as CommandHelp, ut as StreamEvent, v as SessionCommandDefinition, vt as Session, w as InputStream, wt as SectionValidation, x as defineServerCommand, xt as ManagementApiClientConfig, y as SpawnDeclarations, yt as StoredSessions, z as OpenUrlOutcome } from "./report-B7M-sp7P.js";
|
|
2
|
+
import { n as CliStructuredError } from "./protocol-YjqPCCOG.js";
|
|
3
3
|
|
|
4
4
|
//#region src/cli.d.ts
|
|
5
5
|
/**
|
|
@@ -37,6 +37,15 @@ declare function createCli(spec: {
|
|
|
37
37
|
readonly description?: string;
|
|
38
38
|
}>>;
|
|
39
39
|
readonly commands: MountedTree;
|
|
40
|
+
/**
|
|
41
|
+
* Declaring this, together with a `Runtime.spawnTelemetry` seam,
|
|
42
|
+
* turns telemetry on: the engine reads the user's preference,
|
|
43
|
+
* discloses on the first enabled run, mints the shared installation
|
|
44
|
+
* id, and hands one payload per run to the seam. Both halves are
|
|
45
|
+
* required — with either one missing the CLI reports nothing, and
|
|
46
|
+
* reads no config, prints no disclosure and mints no id.
|
|
47
|
+
*/
|
|
48
|
+
readonly telemetry?: TelemetryDeclaration;
|
|
40
49
|
}): Cli;
|
|
41
50
|
//#endregion
|
|
42
51
|
//#region src/config-loader.d.ts
|
|
@@ -116,6 +125,48 @@ declare class EnvironmentCredentialManager implements CredentialManager {
|
|
|
116
125
|
activeAccessToken(): Promise<string | null>;
|
|
117
126
|
}
|
|
118
127
|
//#endregion
|
|
128
|
+
//#region src/telemetry/gating.d.ts
|
|
129
|
+
/**
|
|
130
|
+
* Why telemetry resolved the way it did. Total: every resolution carries
|
|
131
|
+
* a reason, enabled or not, so `telemetry status` projects its copy from
|
|
132
|
+
* the resolution instead of re-deriving the decision.
|
|
133
|
+
*/
|
|
134
|
+
type TelemetryDisabledReason = "ci" | "env-opt-out" | "stored-opt-out";
|
|
135
|
+
type TelemetryEnabledReason = "stored-opt-in" | "default-on";
|
|
136
|
+
type TelemetryStatusReason = TelemetryDisabledReason | TelemetryEnabledReason;
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/telemetry/commands.d.ts
|
|
139
|
+
interface TelemetryStatus {
|
|
140
|
+
readonly enabled: boolean;
|
|
141
|
+
readonly reason: TelemetryStatusReason;
|
|
142
|
+
readonly configPath: string;
|
|
143
|
+
readonly installationIdStored: boolean;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The three commands with the group help text that belongs to them,
|
|
147
|
+
* ready to spread into `createCli`. `docsUrl` is the same URL the
|
|
148
|
+
* telemetry declaration names; the group description points users at it
|
|
149
|
+
* for what is collected and why.
|
|
150
|
+
*
|
|
151
|
+
* ```ts
|
|
152
|
+
* const telemetry = telemetryCommandGroup({ docsUrl: DOCS_URL });
|
|
153
|
+
* createCli({
|
|
154
|
+
* commands: { ...telemetry.commands, ...ownCommands },
|
|
155
|
+
* groups: { ...telemetry.groups, ...ownGroups },
|
|
156
|
+
* telemetry: { docsUrl: DOCS_URL },
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
declare function telemetryCommandGroup(options: {
|
|
161
|
+
readonly docsUrl: string;
|
|
162
|
+
}): {
|
|
163
|
+
readonly commands: MountedTree;
|
|
164
|
+
readonly groups: Readonly<Record<string, {
|
|
165
|
+
readonly brief: string;
|
|
166
|
+
readonly description?: string;
|
|
167
|
+
}>>;
|
|
168
|
+
};
|
|
169
|
+
//#endregion
|
|
119
170
|
//#region src/token-claims.d.ts
|
|
120
171
|
/**
|
|
121
172
|
* The workspace a credential names. One derivation, because a token
|
|
@@ -135,4 +186,4 @@ declare function claimedExpiresAt(token: string): Date | undefined;
|
|
|
135
186
|
*/
|
|
136
187
|
declare function claimedIdentity(token: string): CredentialIdentity | undefined;
|
|
137
188
|
//#endregion
|
|
138
|
-
export { type ActiveCredential, type AnyCommand, type Args, type ArgsSpec, type Block, type BrowserWaitRequest, type Char, type ChildResult, type ChildStatusSettlement, type Cli, type CliRunHooks, type CommandArgs, type CommandContext, type CommandDefinition, type CommandFamily, type CommandHandler, type CommandHelp, type CommandNeeds, type CommandRedirect, type CompletedEnvelope, type ConfigSection, type Credential, type CredentialIdentity, type CredentialManager, type CredentialOrigin, type CredentialsRequiredReason, type EngineCommandSnapshot, type EngineEvent, EnvironmentCredentialManager, type ErroredEnvelope, type ExitWithChildStatusOptions, type FlagSpec, type Format, type Handler, type HelpSpec, type HostProcess, type InputStream, type LoadedConfig, type ManagementApiClient, type ManagementApiClientConfig, type MountedTree, type NeedsSpec, type OpenUrlOutcome, type OpenUrlRequest, type Outcome, type OutputStream, PRESENTED, PRISMA_CONFIG_VERSION, type PositionalSpec, type Presentations, type PresentedResult, type PromptSurface, type RedirectSpec, type RunSummary, type Runtime, SERVICE_TOKEN_ENV_VAR, type SectionValidation, type ServerCommandDefinition, type Session, type SessionCommandDefinition, type Severity, type Span, type SpawnChild, type SpawnDeclarations, type SpawnOptions, type SpawnRequest, type SpawnedChild, type Status, type StoredSessions, type StreamEvent, type StreamMeta, type Text, type TokenStorage, type Tone, type TreeNode, type Ui, authServiceError, claimedExpiresAt, claimedIdentity, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional };
|
|
189
|
+
export { type ActiveCredential, type AnyCommand, type Args, type ArgsSpec, type Block, type BrowserWaitRequest, type Char, type ChildResult, type ChildStatusSettlement, type Cli, type CliRunHooks, type CommandArgs, type CommandContext, type CommandDefinition, type CommandFamily, type CommandHandler, type CommandHelp, type CommandNeeds, type CommandRedirect, type CompletedEnvelope, type ConfigSection, type Credential, type CredentialIdentity, type CredentialManager, type CredentialOrigin, type CredentialsRequiredReason, type EngineCommandSnapshot, type EngineEvent, EnvironmentCredentialManager, type ErroredEnvelope, type ExitWithChildStatusOptions, type FlagSpec, type Format, type Handler, type HelpSpec, type HostProcess, type InputStream, type LoadedConfig, type ManagementApiClient, type ManagementApiClientConfig, type MountedTree, type NeedsSpec, type OpenUrlOutcome, type OpenUrlRequest, type Outcome, type OutputStream, PRESENTED, PRISMA_CONFIG_VERSION, type PackageManagerId, type PackageManagerRunRequest, type PackageManagerRunResult, type PackageManagerRunner, type PackageOperations, type PositionalSpec, type Presentations, type PresentedResult, type PromptSurface, type RedirectSpec, type RunSummary, type Runtime, SERVICE_TOKEN_ENV_VAR, type SectionValidation, type ServerCommandDefinition, type Session, type SessionCommandDefinition, type Severity, type Span, type SpawnChild, type SpawnDeclarations, type SpawnOptions, type SpawnRequest, type SpawnedChild, type Status, type StoredSessions, type StreamEvent, type StreamMeta, type TelemetryDeclaration, type TelemetryPayload, type TelemetryStatus, type TelemetryStatusReason, type Text, type TokenStorage, type Tone, type TreeNode, type Ui, authServiceError, claimedExpiresAt, claimedIdentity, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional, telemetryCommandGroup };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as PRESENTED, b as
|
|
2
|
-
import { t as CliStructuredError } from "./protocol-
|
|
1
|
+
import { C as flag, S as exitWithChildStatus, _ as PRESENTED, b as writeUserConfig, c as PRISMA_CONFIG_VERSION, d as authServiceError, f as credentialRejectedError, g as noSessionForWorkspaceError, h as emptyServiceTokenError, i as buildEngine, l as SERVICE_TOKEN_ENV_VAR, m as credentialsRequiredError, n as claimedIdentity, o as defineConfig, p as credentialWorkspaceMismatchError, r as credentialWorkspaceId, s as loadConfig, t as claimedExpiresAt, u as WORKSPACE_ID_ENV_VAR, v as readUserConfig, w as positional, x as resolveGating, y as userConfigPath } from "./token-claims-Cwrz7N2O.js";
|
|
2
|
+
import { i as ok, r as notOk, t as CliStructuredError } from "./protocol-D1CRNkhv.js";
|
|
3
3
|
//#region src/cli.ts
|
|
4
4
|
/**
|
|
5
5
|
* Shell-side construction. Group help is declared with the mount.
|
|
@@ -66,6 +66,7 @@ function defineCommand(def) {
|
|
|
66
66
|
exitCodes: def.exitCodes ?? {},
|
|
67
67
|
managesCredentials: def.managesCredentials ?? false,
|
|
68
68
|
maySpawn: def.maySpawn ?? false,
|
|
69
|
+
installsPackages: def.installsPackages ?? false,
|
|
69
70
|
handler: def.handler
|
|
70
71
|
});
|
|
71
72
|
}
|
|
@@ -209,4 +210,165 @@ var EnvironmentCredentialManager = class {
|
|
|
209
210
|
}
|
|
210
211
|
};
|
|
211
212
|
//#endregion
|
|
212
|
-
|
|
213
|
+
//#region src/telemetry/commands.ts
|
|
214
|
+
/**
|
|
215
|
+
* The environment names no config directory, so there is no preference
|
|
216
|
+
* to read or write. Unreachable in production — `runtime.env` is
|
|
217
|
+
* `process.env`, where `HOME` (or `USERPROFILE`) is always set.
|
|
218
|
+
*/
|
|
219
|
+
function preferenceUnavailableError() {
|
|
220
|
+
return new CliStructuredError("CLI.TELEMETRY_PREFERENCE_UNAVAILABLE", "Cannot tell where your telemetry preference is stored.", { why: "The environment sets none of XDG_CONFIG_HOME, HOME, APPDATA or USERPROFILE, so the user-level config directory cannot be resolved." });
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Resolves the same decision the reporting path uses and projects it
|
|
224
|
+
* into a user-facing status. Pure read: never mints, never writes. The
|
|
225
|
+
* `installationId` value itself is never surfaced — only its presence —
|
|
226
|
+
* so `status` discloses nothing identifying.
|
|
227
|
+
*/
|
|
228
|
+
function resolveTelemetryStatus(inputs) {
|
|
229
|
+
const config = readUserConfig(inputs.env);
|
|
230
|
+
const installationId = config.installationId;
|
|
231
|
+
const gating = resolveGating({
|
|
232
|
+
env: inputs.env,
|
|
233
|
+
config,
|
|
234
|
+
inCI: inputs.inCI
|
|
235
|
+
});
|
|
236
|
+
return {
|
|
237
|
+
enabled: gating.enabled,
|
|
238
|
+
reason: gating.reason,
|
|
239
|
+
configPath: inputs.configPath,
|
|
240
|
+
installationIdStored: typeof installationId === "string" && installationId.length > 0
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const REASON_EXPLANATION = {
|
|
244
|
+
ci: "CI environment detected — telemetry is hard-disabled.",
|
|
245
|
+
"env-opt-out": "an environment opt-out is set (DO_NOT_TRACK / PRISMA_DISABLE_TELEMETRY).",
|
|
246
|
+
"stored-opt-out": "\"enableTelemetry\": false is stored in your config.",
|
|
247
|
+
"stored-opt-in": "\"enableTelemetry\": true is stored in your config.",
|
|
248
|
+
"default-on": "no explicit choice is stored, so the opt-out default applies."
|
|
249
|
+
};
|
|
250
|
+
function statusSummaryLine(status) {
|
|
251
|
+
return `Telemetry is ${status.enabled ? "enabled" : "disabled"}: ${REASON_EXPLANATION[status.reason]}`;
|
|
252
|
+
}
|
|
253
|
+
function formatTelemetryStatusLines(status) {
|
|
254
|
+
return [
|
|
255
|
+
statusSummaryLine(status),
|
|
256
|
+
`Config file: ${status.configPath}`,
|
|
257
|
+
`Installation ID: ${status.installationIdStored ? "stored" : "not stored"}`
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
function statusPresentations(status) {
|
|
261
|
+
return {
|
|
262
|
+
human: () => [{
|
|
263
|
+
kind: "summary",
|
|
264
|
+
status: "info",
|
|
265
|
+
text: statusSummaryLine(status)
|
|
266
|
+
}, {
|
|
267
|
+
kind: "fields",
|
|
268
|
+
rows: [{
|
|
269
|
+
label: "Config file",
|
|
270
|
+
value: status.configPath
|
|
271
|
+
}, {
|
|
272
|
+
label: "Installation ID",
|
|
273
|
+
value: status.installationIdStored ? "stored" : "not stored"
|
|
274
|
+
}]
|
|
275
|
+
}],
|
|
276
|
+
stdout: () => [...formatTelemetryStatusLines(status)],
|
|
277
|
+
json: () => status
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/** One confirmation line, echoed on stdout, with the stored decision as
|
|
281
|
+
* the json result. */
|
|
282
|
+
function consentPresentations(line, json) {
|
|
283
|
+
return {
|
|
284
|
+
human: () => [{
|
|
285
|
+
kind: "summary",
|
|
286
|
+
status: "ok",
|
|
287
|
+
text: line
|
|
288
|
+
}],
|
|
289
|
+
stdout: () => [line],
|
|
290
|
+
json: () => json
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
const telemetryStatusCommand = defineCommand({
|
|
294
|
+
help: {
|
|
295
|
+
summary: "Show whether anonymous CLI telemetry is enabled and why",
|
|
296
|
+
description: "Reports whether telemetry is currently enabled or disabled and the reason\n(default-on, stored opt-out, environment opt-out, or CI), the path to your\nuser-level config file, and whether an installation ID has been stored.\nRead-only: never sends an event, never mints an ID, never writes anything.",
|
|
297
|
+
examples: ["telemetry status", "telemetry status --json"]
|
|
298
|
+
},
|
|
299
|
+
handler: async (_args, ctx) => {
|
|
300
|
+
const configPath = userConfigPath(ctx.env);
|
|
301
|
+
if (configPath === void 0) return notOk(preferenceUnavailableError());
|
|
302
|
+
const status = resolveTelemetryStatus({
|
|
303
|
+
env: ctx.env,
|
|
304
|
+
inCI: ctx.isCI,
|
|
305
|
+
configPath
|
|
306
|
+
});
|
|
307
|
+
return ok(ctx.present({ data: status }, statusPresentations(status)));
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
const telemetryEnableCommand = defineCommand({
|
|
311
|
+
help: {
|
|
312
|
+
summary: "Enable anonymous CLI telemetry",
|
|
313
|
+
description: "Stores \"enableTelemetry\": true in your user-level config and mints an\ninstallation ID if one is not already stored.",
|
|
314
|
+
examples: ["telemetry enable"]
|
|
315
|
+
},
|
|
316
|
+
handler: async (_args, ctx) => {
|
|
317
|
+
const configPath = userConfigPath(ctx.env);
|
|
318
|
+
if (configPath === void 0) return notOk(preferenceUnavailableError());
|
|
319
|
+
writeUserConfig(ctx.env, { enableTelemetry: true });
|
|
320
|
+
const decision = {
|
|
321
|
+
enableTelemetry: true,
|
|
322
|
+
configPath
|
|
323
|
+
};
|
|
324
|
+
return ok(ctx.present({ data: decision }, consentPresentations(`Telemetry enabled. Preference stored in ${configPath}.`, decision)));
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
const telemetryDisableCommand = defineCommand({
|
|
328
|
+
help: {
|
|
329
|
+
summary: "Disable anonymous CLI telemetry",
|
|
330
|
+
description: "Stores \"enableTelemetry\": false in your user-level config. No installation\nID is minted and no event is sent.",
|
|
331
|
+
examples: ["telemetry disable"]
|
|
332
|
+
},
|
|
333
|
+
handler: async (_args, ctx) => {
|
|
334
|
+
const configPath = userConfigPath(ctx.env);
|
|
335
|
+
if (configPath === void 0) return notOk(preferenceUnavailableError());
|
|
336
|
+
writeUserConfig(ctx.env, { enableTelemetry: false });
|
|
337
|
+
const decision = {
|
|
338
|
+
enableTelemetry: false,
|
|
339
|
+
configPath
|
|
340
|
+
};
|
|
341
|
+
return ok(ctx.present({ data: decision }, consentPresentations(`Telemetry disabled. Preference stored in ${configPath}.`, decision)));
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
/**
|
|
345
|
+
* The three commands with the group help text that belongs to them,
|
|
346
|
+
* ready to spread into `createCli`. `docsUrl` is the same URL the
|
|
347
|
+
* telemetry declaration names; the group description points users at it
|
|
348
|
+
* for what is collected and why.
|
|
349
|
+
*
|
|
350
|
+
* ```ts
|
|
351
|
+
* const telemetry = telemetryCommandGroup({ docsUrl: DOCS_URL });
|
|
352
|
+
* createCli({
|
|
353
|
+
* commands: { ...telemetry.commands, ...ownCommands },
|
|
354
|
+
* groups: { ...telemetry.groups, ...ownGroups },
|
|
355
|
+
* telemetry: { docsUrl: DOCS_URL },
|
|
356
|
+
* });
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
function telemetryCommandGroup(options) {
|
|
360
|
+
return {
|
|
361
|
+
commands: {
|
|
362
|
+
"telemetry status": telemetryStatusCommand,
|
|
363
|
+
"telemetry enable": telemetryEnableCommand,
|
|
364
|
+
"telemetry disable": telemetryDisableCommand
|
|
365
|
+
},
|
|
366
|
+
groups: { telemetry: {
|
|
367
|
+
brief: "Inspect and change anonymous CLI telemetry",
|
|
368
|
+
description: `Show telemetry status, or enable / disable anonymous CLI usage data.
|
|
369
|
+
Telemetry is on by default (opt-out); see ${options.docsUrl}\nfor what is collected and why.`
|
|
370
|
+
} }
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
//#endregion
|
|
374
|
+
export { EnvironmentCredentialManager, PRESENTED, PRISMA_CONFIG_VERSION, SERVICE_TOKEN_ENV_VAR, authServiceError, claimedExpiresAt, claimedIdentity, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional, telemetryCommandGroup };
|
|
@@ -2,16 +2,26 @@
|
|
|
2
2
|
function ifDefined(key, value) {
|
|
3
3
|
return value !== void 0 ? { [key]: value } : {};
|
|
4
4
|
}
|
|
5
|
+
/** The mark a structured error carries so it can be recognized without
|
|
6
|
+
* its prototype. A registry symbol resolves to one symbol across every
|
|
7
|
+
* copy of this package in an install, so an error built by another copy
|
|
8
|
+
* carries the same key this one looks for. */
|
|
9
|
+
const STRUCTURED_ERROR = Symbol.for("@prisma/cli-engine.structuredError");
|
|
5
10
|
/**
|
|
6
11
|
* Structured CLI error carrying everything an error envelope needs.
|
|
7
12
|
* `code` is a dotted `NAMESPACE.SUBCODE` string; the namespace prefix is
|
|
8
13
|
* the error's category.
|
|
9
14
|
*/
|
|
10
15
|
var CliStructuredError = class extends Error {
|
|
16
|
+
[STRUCTURED_ERROR] = true;
|
|
11
17
|
code;
|
|
12
18
|
severity;
|
|
13
19
|
why;
|
|
14
20
|
nextActions;
|
|
21
|
+
/** Accompanying findings when the failure had several. This error is
|
|
22
|
+
* the primary one; these are reported alongside it, so a command can
|
|
23
|
+
* fail with everything it found instead of only the first thing. */
|
|
24
|
+
diagnostics;
|
|
15
25
|
where;
|
|
16
26
|
meta;
|
|
17
27
|
docsUrl;
|
|
@@ -22,6 +32,7 @@ var CliStructuredError = class extends Error {
|
|
|
22
32
|
this.severity = options?.severity ?? "error";
|
|
23
33
|
this.why = options?.why;
|
|
24
34
|
this.nextActions = options?.nextActions ?? [];
|
|
35
|
+
this.diagnostics = options?.diagnostics ?? [];
|
|
25
36
|
this.where = options?.where ? {
|
|
26
37
|
...ifDefined("path", options.where.path),
|
|
27
38
|
...ifDefined("line", options.where.line)
|
|
@@ -46,12 +57,22 @@ var CliStructuredError = class extends Error {
|
|
|
46
57
|
};
|
|
47
58
|
}
|
|
48
59
|
/**
|
|
49
|
-
*
|
|
50
|
-
* instanceof
|
|
60
|
+
* Recognizes a structured error across module boundaries, where
|
|
61
|
+
* instanceof fails because each copy of this package has its own
|
|
62
|
+
* class. The brand answers it outright. The duck-typed check behind
|
|
63
|
+
* it is the fallback for an error from a copy old enough to predate
|
|
64
|
+
* the brand: rejecting those would turn a real failure into an
|
|
65
|
+
* engine-bug report, so it has to keep working.
|
|
66
|
+
*
|
|
67
|
+
* Neither branch asks what the value's prototype is. Nothing in
|
|
68
|
+
* settlement needs an Error — it reads `code` and `nextActions` and
|
|
69
|
+
* calls `toEnvelope` — so a prototype chain, which is local to the
|
|
70
|
+
* copy that made it, is not the thing worth checking.
|
|
51
71
|
*/
|
|
52
72
|
static is(error) {
|
|
53
|
-
if (
|
|
73
|
+
if (typeof error !== "object" || error === null) return false;
|
|
54
74
|
const candidate = error;
|
|
75
|
+
if (candidate[STRUCTURED_ERROR] === true) return true;
|
|
55
76
|
return candidate.name === "CliStructuredError" && typeof candidate.code === "string" && typeof candidate.toEnvelope === "function";
|
|
56
77
|
}
|
|
57
78
|
};
|
|
@@ -103,4 +124,4 @@ function okVoid() {
|
|
|
103
124
|
return OK_VOID;
|
|
104
125
|
}
|
|
105
126
|
//#endregion
|
|
106
|
-
export { okVoid as i,
|
|
127
|
+
export { okVoid as a, ok as i, STRUCTURED_ERROR as n, notOk as r, CliStructuredError as t };
|
|
@@ -43,16 +43,26 @@ interface NextAction {
|
|
|
43
43
|
type CliErrorEnvelope = {
|
|
44
44
|
readonly ok: false;
|
|
45
45
|
} & Diagnostic;
|
|
46
|
+
/** The mark a structured error carries so it can be recognized without
|
|
47
|
+
* its prototype. A registry symbol resolves to one symbol across every
|
|
48
|
+
* copy of this package in an install, so an error built by another copy
|
|
49
|
+
* carries the same key this one looks for. */
|
|
50
|
+
declare const STRUCTURED_ERROR: unique symbol;
|
|
46
51
|
/**
|
|
47
52
|
* Structured CLI error carrying everything an error envelope needs.
|
|
48
53
|
* `code` is a dotted `NAMESPACE.SUBCODE` string; the namespace prefix is
|
|
49
54
|
* the error's category.
|
|
50
55
|
*/
|
|
51
56
|
declare class CliStructuredError extends Error {
|
|
57
|
+
readonly [STRUCTURED_ERROR]: true;
|
|
52
58
|
readonly code: `${string}.${string}`;
|
|
53
59
|
readonly severity: Diagnostic["severity"];
|
|
54
60
|
readonly why: string | undefined;
|
|
55
61
|
readonly nextActions: readonly NextAction[];
|
|
62
|
+
/** Accompanying findings when the failure had several. This error is
|
|
63
|
+
* the primary one; these are reported alongside it, so a command can
|
|
64
|
+
* fail with everything it found instead of only the first thing. */
|
|
65
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
56
66
|
readonly where: {
|
|
57
67
|
readonly path?: string;
|
|
58
68
|
readonly line?: number;
|
|
@@ -63,6 +73,7 @@ declare class CliStructuredError extends Error {
|
|
|
63
73
|
readonly severity?: Diagnostic["severity"];
|
|
64
74
|
readonly why?: string;
|
|
65
75
|
readonly nextActions?: readonly NextAction[];
|
|
76
|
+
readonly diagnostics?: readonly Diagnostic[];
|
|
66
77
|
readonly where?: {
|
|
67
78
|
readonly path?: string;
|
|
68
79
|
readonly line?: number;
|
|
@@ -76,8 +87,17 @@ declare class CliStructuredError extends Error {
|
|
|
76
87
|
*/
|
|
77
88
|
toEnvelope(): CliErrorEnvelope;
|
|
78
89
|
/**
|
|
79
|
-
*
|
|
80
|
-
* instanceof
|
|
90
|
+
* Recognizes a structured error across module boundaries, where
|
|
91
|
+
* instanceof fails because each copy of this package has its own
|
|
92
|
+
* class. The brand answers it outright. The duck-typed check behind
|
|
93
|
+
* it is the fallback for an error from a copy old enough to predate
|
|
94
|
+
* the brand: rejecting those would turn a real failure into an
|
|
95
|
+
* engine-bug report, so it has to keep working.
|
|
96
|
+
*
|
|
97
|
+
* Neither branch asks what the value's prototype is. Nothing in
|
|
98
|
+
* settlement needs an Error — it reads `code` and `nextActions` and
|
|
99
|
+
* calls `toEnvelope` — so a prototype chain, which is local to the
|
|
100
|
+
* copy that made it, is not the thing worth checking.
|
|
81
101
|
*/
|
|
82
102
|
static is(error: unknown): error is CliStructuredError;
|
|
83
103
|
}
|
|
@@ -118,4 +138,4 @@ declare function notOk<F>(failure: F): NotOk<F>;
|
|
|
118
138
|
*/
|
|
119
139
|
declare function okVoid(): Ok<void>;
|
|
120
140
|
//#endregion
|
|
121
|
-
export { NotOk as a,
|
|
141
|
+
export { NotOk as a, STRUCTURED_ERROR as c, okVoid as d, NextAction as i, notOk as l, CliStructuredError as n, Ok as o, Diagnostic as r, Result as s, CliErrorEnvelope as t, ok as u };
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as NotOk, c as
|
|
2
|
-
export { type CliErrorEnvelope, CliStructuredError, type Diagnostic, type NextAction, type NotOk, type Ok, type Result, notOk, ok, okVoid };
|
|
1
|
+
import { a as NotOk, c as STRUCTURED_ERROR, d as okVoid, i as NextAction, l as notOk, n as CliStructuredError, o as Ok, r as Diagnostic, s as Result, t as CliErrorEnvelope, u as ok } from "./protocol-YjqPCCOG.js";
|
|
2
|
+
export { type CliErrorEnvelope, CliStructuredError, type Diagnostic, type NextAction, type NotOk, type Ok, type Result, STRUCTURED_ERROR, notOk, ok, okVoid };
|
package/dist/protocol.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { CliStructuredError, notOk, ok, okVoid };
|
|
1
|
+
import { a as okVoid, i as ok, n as STRUCTURED_ERROR, r as notOk, t as CliStructuredError } from "./protocol-D1CRNkhv.js";
|
|
2
|
+
export { CliStructuredError, STRUCTURED_ERROR, notOk, ok, okVoid };
|