@prisma/cli-engine 0.0.5 → 0.0.7
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 +2 -2
- package/dist/index.js +16 -2
- package/dist/{run-summary-CLpl1gmC.d.ts → run-summary-DQx6CRvB.d.ts} +73 -14
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/{token-claims-Bpb1vA2N.js → token-claims-DZ3p13Qu.js} +192 -49
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as StreamEvent, A as BrowserWaitRequest, B as SpawnRequest, C as defineSessionCommand, D as OutputStream, E as LoadedConfig, F as ChildResult, G as Outcome, H as exitWithChildStatus, I as ChildStatusSettlement, J as PresentedResult, K as PRESENTED, L as ExitWithChildStatusOptions, M as OpenUrlOutcome, N as OpenUrlRequest, O as PRISMA_CONFIG_VERSION, P as PromptSurface, Q as Severity, R as SpawnChild, S as defineServerCommand, St as positional, T as InputStream, U as Block, V as SpawnedChild, W as Format, X as Ui, Y as TreeNode, Z as EngineEvent, _ as NeedsSpec, _t as Char, a as MountedTree, at as CredentialOrigin, b as SpawnDeclarations, bt as PositionalSpec, c as AnyCommand, ct as StoredSessions, d as CommandHelp, dt as TokenStorage, et as StreamMeta, f as CommandNeeds, ft as ConfigSection, g as HelpSpec, gt as ArgsSpec, h as Handler, ht as Args, i as CommandRedirect, it as CredentialManager, j as CommandContext, k as Runtime, l as CommandDefinition, lt as ManagementApiClient, m as ErroredEnvelope, mt as defineConfigSection, n as RunSummary, nt as Credential, o as RedirectSpec, ot as SERVICE_TOKEN_ENV_VAR, p as CompletedEnvelope, pt as SectionValidation, q as Presentations, r as CommandFamily, rt as CredentialIdentity, s as defineCommandFamily, st as Session, t as EngineCommandSnapshot, tt as ActiveCredential, u as CommandHandler, ut as ManagementApiClientConfig, v as ServerCommandDefinition, vt as CommandArgs, w as HostProcess, x as defineCommand, xt as flag, y as SessionCommandDefinition, yt as FlagSpec, z as SpawnOptions } from "./run-summary-DQx6CRvB.js";
|
|
2
2
|
import { n as CliStructuredError } from "./protocol-CpZLdxML.js";
|
|
3
3
|
|
|
4
4
|
//#region src/cli.d.ts
|
|
@@ -135,4 +135,4 @@ declare function claimedExpiresAt(token: string): Date | undefined;
|
|
|
135
135
|
*/
|
|
136
136
|
declare function claimedIdentity(token: string): CredentialIdentity | undefined;
|
|
137
137
|
//#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 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 RunSummary, type Runtime, SERVICE_TOKEN_ENV_VAR, type SectionValidation, type ServerCommandDefinition, type Session, type SessionCommandDefinition, type Severity, type SpawnChild, type SpawnDeclarations, type SpawnOptions, type SpawnRequest, type SpawnedChild, type StoredSessions, type StreamEvent, type StreamMeta, type TokenStorage, type TreeNode, type Ui, authServiceError, claimedExpiresAt, claimedIdentity, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional };
|
|
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 SpawnChild, type SpawnDeclarations, type SpawnOptions, type SpawnRequest, type SpawnedChild, type StoredSessions, type StreamEvent, type StreamMeta, type TokenStorage, type TreeNode, type Ui, authServiceError, claimedExpiresAt, claimedIdentity, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfig, defineConfigSection, defineServerCommand, defineSessionCommand, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as PRESENTED, b as positional, 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 exitWithChildStatus, y as flag } from "./token-claims-
|
|
1
|
+
import { _ as PRESENTED, b as positional, 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 exitWithChildStatus, y as flag } from "./token-claims-DZ3p13Qu.js";
|
|
2
2
|
import { t as CliStructuredError } from "./protocol-C1JQcGl9.js";
|
|
3
3
|
//#region src/cli.ts
|
|
4
4
|
/**
|
|
@@ -13,11 +13,25 @@ function createCli(spec) {
|
|
|
13
13
|
}
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/command-family.ts
|
|
16
|
+
/** A path is segments separated by whitespace, so the separator's shape
|
|
17
|
+
* carries no meaning and one form reaches the table and every lookup. */
|
|
18
|
+
function normalizePath(from) {
|
|
19
|
+
return from.trim().replace(/\s+/g, " ");
|
|
20
|
+
}
|
|
21
|
+
function normalizeRedirect(spec) {
|
|
22
|
+
return Object.freeze({
|
|
23
|
+
from: normalizePath(spec.from),
|
|
24
|
+
flag: spec.flag,
|
|
25
|
+
replacement: spec.replacement,
|
|
26
|
+
reason: spec.reason
|
|
27
|
+
});
|
|
28
|
+
}
|
|
16
29
|
function defineCommandFamily(spec) {
|
|
17
30
|
return Object.freeze({
|
|
18
31
|
configSection: spec.configSection,
|
|
19
32
|
commands: spec.commands,
|
|
20
|
-
docsBaseUrl: spec.docsBaseUrl
|
|
33
|
+
docsBaseUrl: spec.docsBaseUrl,
|
|
34
|
+
redirects: (spec.redirects ?? []).map(normalizeRedirect)
|
|
21
35
|
});
|
|
22
36
|
}
|
|
23
37
|
//#endregion
|
|
@@ -489,8 +489,9 @@ interface SpawnRequest {
|
|
|
489
489
|
readonly env: Readonly<Record<string, string | undefined>>;
|
|
490
490
|
}
|
|
491
491
|
/** How a child ended. A signal-killed child carries `signal` and a null
|
|
492
|
-
* `exitCode
|
|
493
|
-
*
|
|
492
|
+
* `exitCode`, and is an abort rather than a failure: exitWithChildStatus
|
|
493
|
+
* settles it as one, and a handler that reads the result itself branches
|
|
494
|
+
* on `signal` before `exitCode`. */
|
|
494
495
|
interface ChildResult {
|
|
495
496
|
readonly exitCode: number | null;
|
|
496
497
|
readonly signal: string | null;
|
|
@@ -524,25 +525,34 @@ declare const CHILD_STATUS: unique symbol;
|
|
|
524
525
|
* The sanctioned settlement outcome for "exit with the child's status
|
|
525
526
|
* verbatim": no envelope, the same settlement bypass server commands
|
|
526
527
|
* use. Built exclusively by exitWithChildStatus, and only settled by a
|
|
527
|
-
* command that declares maySpawn
|
|
528
|
-
*
|
|
529
|
-
*
|
|
528
|
+
* command that declares maySpawn. It carries no exit code, because the
|
|
529
|
+
* code is not the handler's to state: the engine reads it off its own
|
|
530
|
+
* record of the child. `nextActions` render to stderr before the
|
|
531
|
+
* process exits with the child's code.
|
|
530
532
|
*/
|
|
531
533
|
interface ChildStatusSettlement {
|
|
532
534
|
readonly [CHILD_STATUS]: true;
|
|
533
|
-
readonly exitCode: number;
|
|
534
535
|
readonly nextActions: readonly NextAction[];
|
|
535
536
|
}
|
|
536
537
|
interface ExitWithChildStatusOptions {
|
|
537
538
|
/** Engine-styled guidance printed to stderr before the exit — a
|
|
538
|
-
* failed converge's reproduce hint. The envelope stays absent
|
|
539
|
+
* failed converge's reproduce hint. The envelope stays absent, and
|
|
540
|
+
* a signal-killed child drops these entirely: the user stopped the
|
|
541
|
+
* run, so there is nothing to reproduce. */
|
|
539
542
|
readonly nextActions?: readonly NextAction[];
|
|
540
543
|
}
|
|
541
|
-
/**
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
|
|
544
|
+
/**
|
|
545
|
+
* Settles the run with the status of the child the run spawned — the
|
|
546
|
+
* one `ctx.lastChild()` reports. The handler names no child and no
|
|
547
|
+
* code: this is how a real child's status reaches the exit code, not
|
|
548
|
+
* how a handler picks one, so a run that spawned nothing is a
|
|
549
|
+
* construction error at settlement.
|
|
550
|
+
*
|
|
551
|
+
* A signal-killed child overrules everything the caller asked for: it
|
|
552
|
+
* settles 128 + the signal number with no `nextActions`, because the
|
|
553
|
+
* user stopped the run and there is nothing to reproduce.
|
|
554
|
+
*/
|
|
555
|
+
declare function exitWithChildStatus(options?: ExitWithChildStatusOptions): ChildStatusSettlement;
|
|
546
556
|
//#endregion
|
|
547
557
|
//#region src/context.d.ts
|
|
548
558
|
/** The handler context — the whole world arrives as one argument. */
|
|
@@ -597,6 +607,15 @@ interface CommandContext<TConfig = undefined, TCode extends number = never> {
|
|
|
597
607
|
* failure.
|
|
598
608
|
*/
|
|
599
609
|
readonly spawn: (options: SpawnOptions) => Promise<ChildResult>;
|
|
610
|
+
/**
|
|
611
|
+
* How the run's most recent completed child ended, or undefined when
|
|
612
|
+
* none has run. The engine records every child ctx.spawn returns, so
|
|
613
|
+
* a handler whose spawn happens deep in its own layering can still
|
|
614
|
+
* ask "did my child fail?" where it settles, without threading the
|
|
615
|
+
* result back by hand. This is the same record exitWithChildStatus
|
|
616
|
+
* settles from.
|
|
617
|
+
*/
|
|
618
|
+
readonly lastChild: () => ChildResult | undefined;
|
|
600
619
|
/** The one way to emit while running. */
|
|
601
620
|
readonly report: (event: EngineEvent) => void;
|
|
602
621
|
/** Interactive input. */
|
|
@@ -1020,7 +1039,8 @@ declare function defineCommand<TFlags extends Record<string, FlagSpec<unknown>>
|
|
|
1020
1039
|
* ok(undefined) exits 0 — or 130/143 when a signal ended the run, which
|
|
1021
1040
|
* the engine settles from its own record of that signal, not from
|
|
1022
1041
|
* anything the handler returns; one that returns
|
|
1023
|
-
* ok(exitWithChildStatus(
|
|
1042
|
+
* ok(exitWithChildStatus()) exits with the status of the child it
|
|
1043
|
+
* spawned.
|
|
1024
1044
|
*/
|
|
1025
1045
|
interface SessionCommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined> {
|
|
1026
1046
|
readonly kind: "session-command";
|
|
@@ -1118,6 +1138,42 @@ interface ErroredEnvelope {
|
|
|
1118
1138
|
}
|
|
1119
1139
|
//#endregion
|
|
1120
1140
|
//#region src/command-family.d.ts
|
|
1141
|
+
/**
|
|
1142
|
+
* A retired invocation and the invocation that replaced it. Redirects
|
|
1143
|
+
* are metadata, never commands: they stay out of help and out of the
|
|
1144
|
+
* command tree, and are consulted only when an invocation fails to
|
|
1145
|
+
* resolve.
|
|
1146
|
+
*/
|
|
1147
|
+
interface RedirectSpec {
|
|
1148
|
+
/**
|
|
1149
|
+
* The retired invocation as the user types it: a space-separated
|
|
1150
|
+
* absolute path in the mounted tree, the same convention as
|
|
1151
|
+
* MountedTree keys. Whitespace only separates segments, so it is
|
|
1152
|
+
* normalized away — `' migration \t apply '` is `'migration apply'`.
|
|
1153
|
+
*/
|
|
1154
|
+
readonly from: string;
|
|
1155
|
+
/**
|
|
1156
|
+
* When present, a retired FLAG on a live command: `from` names the
|
|
1157
|
+
* live command's path and this the retired flag's camelCase name
|
|
1158
|
+
* (rendered --kebab-case, as flag declarations are).
|
|
1159
|
+
*/
|
|
1160
|
+
readonly flag?: string;
|
|
1161
|
+
/**
|
|
1162
|
+
* The replacement invocation, written the way help examples are
|
|
1163
|
+
* written: no binary name, `{bin}` available when the name has to sit
|
|
1164
|
+
* mid-string. Placeholder arguments use angle brackets (`<ref>`).
|
|
1165
|
+
*/
|
|
1166
|
+
readonly replacement: string;
|
|
1167
|
+
/** One sentence of context, surfaced as the error's `why`. */
|
|
1168
|
+
readonly reason?: string;
|
|
1169
|
+
}
|
|
1170
|
+
/** The normalized redirect a command family carries. */
|
|
1171
|
+
interface CommandRedirect {
|
|
1172
|
+
readonly from: string;
|
|
1173
|
+
readonly flag: string | undefined;
|
|
1174
|
+
readonly replacement: string;
|
|
1175
|
+
readonly reason: string | undefined;
|
|
1176
|
+
}
|
|
1121
1177
|
/**
|
|
1122
1178
|
* The unit of contribution and ownership a package exports for CLI
|
|
1123
1179
|
* purposes: its config section (declared once — a family-level fact)
|
|
@@ -1133,11 +1189,14 @@ interface CommandFamily {
|
|
|
1133
1189
|
* diagnostic's docs link from base + code.
|
|
1134
1190
|
*/
|
|
1135
1191
|
readonly docsBaseUrl: string | undefined;
|
|
1192
|
+
/** The invocations this family retired. */
|
|
1193
|
+
readonly redirects: readonly CommandRedirect[];
|
|
1136
1194
|
}
|
|
1137
1195
|
declare function defineCommandFamily(spec: {
|
|
1138
1196
|
readonly configSection?: ConfigSection<unknown>;
|
|
1139
1197
|
readonly commands: Readonly<Record<string, AnyCommand>>;
|
|
1140
1198
|
readonly docsBaseUrl?: string;
|
|
1199
|
+
readonly redirects?: readonly RedirectSpec[];
|
|
1141
1200
|
}): CommandFamily;
|
|
1142
1201
|
/** What the shell builds: commands by PATH (space-separated, 'db migrate'). */
|
|
1143
1202
|
type MountedTree = Readonly<Record<string, AnyCommand>>;
|
|
@@ -1190,4 +1249,4 @@ interface RunSummary {
|
|
|
1190
1249
|
readonly snapshot: EngineCommandSnapshot;
|
|
1191
1250
|
}
|
|
1192
1251
|
//#endregion
|
|
1193
|
-
export {
|
|
1252
|
+
export { StreamEvent as $, BrowserWaitRequest as A, SpawnRequest as B, defineSessionCommand as C, OutputStream as D, LoadedConfig as E, ChildResult as F, Outcome as G, exitWithChildStatus as H, ChildStatusSettlement as I, PresentedResult as J, PRESENTED as K, ExitWithChildStatusOptions as L, OpenUrlOutcome as M, OpenUrlRequest as N, PRISMA_CONFIG_VERSION as O, PromptSurface as P, Severity as Q, SpawnChild as R, defineServerCommand as S, positional as St, InputStream as T, Block as U, SpawnedChild as V, Format as W, Ui as X, TreeNode as Y, EngineEvent as Z, NeedsSpec as _, Char as _t, MountedTree as a, CredentialOrigin as at, SpawnDeclarations as b, PositionalSpec as bt, AnyCommand as c, StoredSessions as ct, CommandHelp as d, TokenStorage$1 as dt, StreamMeta as et, CommandNeeds as f, ConfigSection as ft, HelpSpec as g, ArgsSpec as gt, Handler as h, Args as ht, CommandRedirect as i, CredentialManager as it, CommandContext as j, Runtime as k, CommandDefinition as l, ManagementApiClient$1 as lt, ErroredEnvelope as m, defineConfigSection as mt, RunSummary as n, Credential as nt, RedirectSpec as o, SERVICE_TOKEN_ENV_VAR as ot, CompletedEnvelope as p, SectionValidation as pt, Presentations as q, CommandFamily as r, CredentialIdentity as rt, defineCommandFamily as s, Session as st, EngineCommandSnapshot as t, ActiveCredential as tt, CommandHandler as u, ManagementApiClientConfig as ut, ServerCommandDefinition as v, CommandArgs as vt, HostProcess as w, defineCommand as x, flag as xt, SessionCommandDefinition as y, FlagSpec as yt, SpawnOptions as z };
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as StreamEvent, B as SpawnRequest, F as ChildResult, J as PresentedResult, R as SpawnChild, Z as EngineEvent, a as MountedTree, ct as StoredSessions, dt as TokenStorage, it as CredentialManager, k as Runtime, lt as ManagementApiClient, n as RunSummary, nt as Credential, r as CommandFamily, st as Session, tt as ActiveCredential, ut as ManagementApiClientConfig } from "./run-summary-DQx6CRvB.js";
|
|
2
2
|
|
|
3
3
|
//#region src/in-memory-credential-manager.d.ts
|
|
4
4
|
/** A stored session with its credential material — what the manager
|
package/dist/testing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as noSessionForWorkspaceError, i as buildEngine, m as credentialsRequiredError, n as claimedIdentity, p as credentialWorkspaceMismatchError, r as credentialWorkspaceId, t as claimedExpiresAt } from "./token-claims-
|
|
1
|
+
import { g as noSessionForWorkspaceError, i as buildEngine, m as credentialsRequiredError, n as claimedIdentity, p as credentialWorkspaceMismatchError, r as credentialWorkspaceId, t as claimedExpiresAt } from "./token-claims-DZ3p13Qu.js";
|
|
2
2
|
import { Buffer } from "node:buffer";
|
|
3
3
|
//#region src/in-memory-credential-manager.ts
|
|
4
4
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as okVoid, n as notOk, t as CliStructuredError } from "./protocol-C1JQcGl9.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import { buildApplication, buildCommand, buildRouteMap, run, text_en } from "@stricli/core";
|
|
3
|
+
import { FlagNotFoundError, buildApplication, buildCommand, buildRouteMap, run, text_en } from "@stricli/core";
|
|
4
4
|
import { existsSync, realpathSync } from "node:fs";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
6
|
import { Readable, Writable } from "node:stream";
|
|
@@ -95,29 +95,17 @@ const positional = {
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
|
+
/** The two directions of one rule: a flag key is camelCase in code and
|
|
99
|
+
* --kebab-case on the CLI. */
|
|
100
|
+
function kebabCase(key) {
|
|
101
|
+
return key.replace(/[A-Z]/g, (upper) => `-${upper.toLowerCase()}`);
|
|
102
|
+
}
|
|
103
|
+
function camelCase(typed) {
|
|
104
|
+
return typed.replace(/-([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
105
|
+
}
|
|
98
106
|
//#endregion
|
|
99
107
|
//#region src/spawn.ts
|
|
100
108
|
const CHILD_STATUS = Symbol.for("@prisma/cli-engine.childStatus");
|
|
101
|
-
/** Marks a ChildResult the engine watched a real child produce. */
|
|
102
|
-
const ENGINE_SPAWNED = Symbol.for("@prisma/cli-engine.engineSpawned");
|
|
103
|
-
function markEngineSpawned(value) {
|
|
104
|
-
return Object.freeze(Object.defineProperty(value, ENGINE_SPAWNED, { value: true }));
|
|
105
|
-
}
|
|
106
|
-
function isEngineSpawned(value) {
|
|
107
|
-
return value[ENGINE_SPAWNED] === true;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* The child result ctx.spawn hands back: the engine mints it from what
|
|
111
|
-
* the adapter reported, so a handler cannot pass off an invented one as
|
|
112
|
-
* a child's status. exitWithChildStatus carries the mark onto its
|
|
113
|
-
* settlement and the settlement refuses an unmarked one.
|
|
114
|
-
*/
|
|
115
|
-
function engineSpawnedResult(result) {
|
|
116
|
-
return markEngineSpawned({
|
|
117
|
-
exitCode: result.exitCode,
|
|
118
|
-
signal: result.signal
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
109
|
/** Signal numbers shared by Linux, macOS and the BSDs. Numbers that
|
|
122
110
|
* differ by platform (SIGBUS, SIGUSR1, SIGUSR2, …) are deliberately
|
|
123
111
|
* absent — a wrong 128+n is worse than the unknown-signal fallback. */
|
|
@@ -144,17 +132,22 @@ function childExitCode(child) {
|
|
|
144
132
|
const signalNumber = SIGNAL_NUMBERS[child.signal];
|
|
145
133
|
return signalNumber === void 0 ? 1 : 128 + signalNumber;
|
|
146
134
|
}
|
|
147
|
-
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
|
|
152
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Settles the run with the status of the child the run spawned — the
|
|
137
|
+
* one `ctx.lastChild()` reports. The handler names no child and no
|
|
138
|
+
* code: this is how a real child's status reaches the exit code, not
|
|
139
|
+
* how a handler picks one, so a run that spawned nothing is a
|
|
140
|
+
* construction error at settlement.
|
|
141
|
+
*
|
|
142
|
+
* A signal-killed child overrules everything the caller asked for: it
|
|
143
|
+
* settles 128 + the signal number with no `nextActions`, because the
|
|
144
|
+
* user stopped the run and there is nothing to reproduce.
|
|
145
|
+
*/
|
|
146
|
+
function exitWithChildStatus(options) {
|
|
147
|
+
return Object.freeze({
|
|
153
148
|
[CHILD_STATUS]: true,
|
|
154
|
-
exitCode: childExitCode(child),
|
|
155
149
|
nextActions: Object.freeze([...options?.nextActions ?? []])
|
|
156
|
-
};
|
|
157
|
-
return isEngineSpawned(child) ? markEngineSpawned(settlement) : Object.freeze(settlement);
|
|
150
|
+
});
|
|
158
151
|
}
|
|
159
152
|
function isChildStatusSettlement(value) {
|
|
160
153
|
return typeof value === "object" && value !== null && value[CHILD_STATUS] === true;
|
|
@@ -1045,6 +1038,67 @@ function buildCommandTree(spec) {
|
|
|
1045
1038
|
}
|
|
1046
1039
|
return root;
|
|
1047
1040
|
}
|
|
1041
|
+
function flagRedirectKey(commandPath, flag) {
|
|
1042
|
+
return `${commandPath} --${flag}`;
|
|
1043
|
+
}
|
|
1044
|
+
/** Where a path sits in the mounted tree; a group is a path some
|
|
1045
|
+
* command mounts under. */
|
|
1046
|
+
function mountedAs(spec, path) {
|
|
1047
|
+
if (spec.commands[path] !== void 0) return "command";
|
|
1048
|
+
const groupPrefix = `${path} `;
|
|
1049
|
+
return Object.keys(spec.commands).some((mounted) => mounted.startsWith(groupPrefix)) ? "command group" : void 0;
|
|
1050
|
+
}
|
|
1051
|
+
/** Engine-injected shared flags count: a command answers them whether
|
|
1052
|
+
* or not it declared them, so a redirect for one could never fire. */
|
|
1053
|
+
function acceptsFlag(def, flag) {
|
|
1054
|
+
if (def.args.flags[flag] !== void 0) return true;
|
|
1055
|
+
return def.kind !== "server-command" && RESERVED_FLAG_NAMES.has(flag);
|
|
1056
|
+
}
|
|
1057
|
+
function addVerbRedirect(spec, table, redirect) {
|
|
1058
|
+
const mounted = mountedAs(spec, redirect.from);
|
|
1059
|
+
if (mounted !== void 0) throw constructionError(`redirect '${redirect.from}' collides with a mounted ${mounted}`);
|
|
1060
|
+
if (table.has(redirect.from)) throw constructionError(`redirect '${redirect.from}' is declared twice`);
|
|
1061
|
+
table.set(redirect.from, redirect);
|
|
1062
|
+
}
|
|
1063
|
+
function addFlagRedirect(spec, table, redirect, flag) {
|
|
1064
|
+
if (!CAMEL_CASE.test(flag)) throw constructionError(`redirect for flag '${flag}' on '${redirect.from}' must name the flag in camelCase (it transliterates to --kebab-case on the CLI)`);
|
|
1065
|
+
const def = spec.commands[redirect.from];
|
|
1066
|
+
if (def === void 0) throw constructionError(`redirect for flag '${flag}' names '${redirect.from}', which is not a mounted command`);
|
|
1067
|
+
if (acceptsFlag(def, flag)) throw constructionError(`redirect for flag '${flag}' on '${redirect.from}' names a flag that command still accepts`);
|
|
1068
|
+
const key = flagRedirectKey(redirect.from, flag);
|
|
1069
|
+
if (table.has(key)) throw constructionError(`redirect for flag '${flag}' on '${redirect.from}' is declared twice`);
|
|
1070
|
+
table.set(key, redirect);
|
|
1071
|
+
}
|
|
1072
|
+
function buildRedirectTable(spec) {
|
|
1073
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
1074
|
+
const byFlag = /* @__PURE__ */ new Map();
|
|
1075
|
+
for (const commandFamily of spec.commandFamilies) for (const redirect of commandFamily.redirects) {
|
|
1076
|
+
if (redirect.from === "") throw constructionError("redirect declares an empty path, so no invocation can produce it");
|
|
1077
|
+
if (redirect.flag === void 0) addVerbRedirect(spec, byPath, redirect);
|
|
1078
|
+
else addFlagRedirect(spec, byFlag, redirect, redirect.flag);
|
|
1079
|
+
}
|
|
1080
|
+
return {
|
|
1081
|
+
byPath,
|
|
1082
|
+
byFlag
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
/** Longest match wins, since one retired path may prefix another.
|
|
1086
|
+
* Segments match exactly: a redirect is never a spelling suggestion. */
|
|
1087
|
+
function matchVerbRedirect(table, segments) {
|
|
1088
|
+
for (let length = segments.length; length > 0; length -= 1) {
|
|
1089
|
+
const redirect = table.byPath.get(segments.slice(0, length).join(" "));
|
|
1090
|
+
if (redirect !== void 0) return redirect;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
/** `typedFlags` are spelled as the user typed them, without the leading
|
|
1094
|
+
* dashes; the scanner accepts kebab for camel, so both spellings
|
|
1095
|
+
* resolve to the declared camelCase name. */
|
|
1096
|
+
function matchFlagRedirect(table, commandPath, typedFlags) {
|
|
1097
|
+
for (const typed of typedFlags) {
|
|
1098
|
+
const redirect = table.byFlag.get(flagRedirectKey(commandPath, camelCase(typed)));
|
|
1099
|
+
if (redirect !== void 0) return redirect;
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1048
1102
|
//#endregion
|
|
1049
1103
|
//#region src/execution/rendering.ts
|
|
1050
1104
|
function firstLine(text) {
|
|
@@ -1876,13 +1930,26 @@ async function runChild(invocation, terminal, spawnChild, request) {
|
|
|
1876
1930
|
const ended = new AbortController();
|
|
1877
1931
|
armTerminationLadder(invocation, terminal, child, ended.signal);
|
|
1878
1932
|
try {
|
|
1879
|
-
return
|
|
1933
|
+
return recordCompletedChild(invocation, await child.ended);
|
|
1880
1934
|
} catch (cause) {
|
|
1881
1935
|
throw spawnFailedError(request.command, cause);
|
|
1882
1936
|
} finally {
|
|
1883
1937
|
ended.abort();
|
|
1884
1938
|
}
|
|
1885
1939
|
}
|
|
1940
|
+
/** The engine mints the result the handler sees and keeps it on the
|
|
1941
|
+
* run: the settlement then reads the child's status from the engine's
|
|
1942
|
+
* own record rather than from anything the handler hands back, and a
|
|
1943
|
+
* handler whose spawn sits deep in its own layering can still ask how
|
|
1944
|
+
* the child ended through ctx.lastChild(). */
|
|
1945
|
+
function recordCompletedChild(invocation, ended) {
|
|
1946
|
+
const result = Object.freeze({
|
|
1947
|
+
exitCode: ended.exitCode,
|
|
1948
|
+
signal: ended.signal
|
|
1949
|
+
});
|
|
1950
|
+
invocation.state.lastChild = result;
|
|
1951
|
+
return result;
|
|
1952
|
+
}
|
|
1886
1953
|
/** A programmatic abort of ctx.signal (a delivered signal is recorded
|
|
1887
1954
|
* instead), or the engine ending a child the handler abandoned,
|
|
1888
1955
|
* terminates the child: SIGTERM, the grace period, SIGKILL. */
|
|
@@ -2017,6 +2084,7 @@ function makeContext(invocation, def, config, managesCredentials) {
|
|
|
2017
2084
|
return api;
|
|
2018
2085
|
},
|
|
2019
2086
|
spawn: makeSpawn(invocation, def),
|
|
2087
|
+
lastChild: () => state.lastChild,
|
|
2020
2088
|
report: (event) => reportEvent(invocation, event),
|
|
2021
2089
|
prompt: makePromptSurface(invocation),
|
|
2022
2090
|
openUrl: (request) => announceUrl(invocation, request),
|
|
@@ -2045,12 +2113,6 @@ function makeContext(invocation, def, config, managesCredentials) {
|
|
|
2045
2113
|
* only for WHICH flag names appear, never for values), and the parsed
|
|
2046
2114
|
* positional slots (reduced to a count on the spot).
|
|
2047
2115
|
*/
|
|
2048
|
-
function kebabCase(key) {
|
|
2049
|
-
return key.replace(/[A-Z]/g, (upper) => `-${upper.toLowerCase()}`);
|
|
2050
|
-
}
|
|
2051
|
-
function camelCase(raw) {
|
|
2052
|
-
return raw.replace(/-([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
2053
|
-
}
|
|
2054
2116
|
function declaredFlagKeys(def) {
|
|
2055
2117
|
const own = Object.keys(def.args.flags);
|
|
2056
2118
|
if (def.kind === "server-command") return own;
|
|
@@ -2221,7 +2283,8 @@ function commandParameters(def) {
|
|
|
2221
2283
|
}
|
|
2222
2284
|
/** Help examples never contain the binary name (operator ruling,
|
|
2223
2285
|
* 2026-08-09): `{bin}` is substituted with the CLI name; an example
|
|
2224
|
-
* without `{bin}` gets the name prepended.
|
|
2286
|
+
* without `{bin}` gets the name prepended. A redirect's replacement is
|
|
2287
|
+
* written the same way and rendered by the same rule. */
|
|
2225
2288
|
function resolveExample(example, cliName) {
|
|
2226
2289
|
return example.includes("{bin}") ? example.replaceAll("{bin}", cliName) : `${cliName} ${example}`;
|
|
2227
2290
|
}
|
|
@@ -2273,6 +2336,7 @@ function capturingText(state) {
|
|
|
2273
2336
|
return {
|
|
2274
2337
|
...text_en,
|
|
2275
2338
|
exceptionWhileParsingArguments(exc, ansiColor) {
|
|
2339
|
+
if (exc instanceof FlagNotFoundError) state.unresolvedFlagNames.push(exc.input);
|
|
2276
2340
|
const message = text_en.exceptionWhileParsingArguments.call(text_en, exc, ansiColor);
|
|
2277
2341
|
state.usageErrorText = message;
|
|
2278
2342
|
return message;
|
|
@@ -2416,20 +2480,23 @@ function settleVerbatimExitCode(invocation, exitCode) {
|
|
|
2416
2480
|
* never documented, because the code is not the handler's own
|
|
2417
2481
|
* conclusion, it is the child's.
|
|
2418
2482
|
*
|
|
2419
|
-
*
|
|
2483
|
+
* The status comes from the engine's own record of the child, never
|
|
2484
|
+
* from the handler, so there is nothing here for a handler to state.
|
|
2485
|
+
* Two conditions fence it, both construction errors: the command must
|
|
2420
2486
|
* hand the terminal to another program — reachable from a
|
|
2421
2487
|
* non-declaring handler this would also end a json stream without its
|
|
2422
|
-
* terminal result frame
|
|
2423
|
-
*
|
|
2424
|
-
*
|
|
2425
|
-
*
|
|
2426
|
-
*
|
|
2488
|
+
* terminal result frame — and a child must actually have run.
|
|
2489
|
+
*
|
|
2490
|
+
* A signal-killed child overrules whatever the handler asked for. The
|
|
2491
|
+
* user stopped the run: it settles 128 + the signal number, with no
|
|
2492
|
+
* envelope and no next actions, because there is nothing to reproduce.
|
|
2427
2493
|
*/
|
|
2428
2494
|
function settleChildStatus(invocation, def, settlement) {
|
|
2429
2495
|
if (!def.maySpawn) throw new Error(`@prisma/cli-engine: command '${invocation.state.commandId}' returned exitWithChildStatus without declaring maySpawn — only a command that hands the terminal to another program may settle with that program's status`);
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2496
|
+
const child = invocation.state.lastChild;
|
|
2497
|
+
if (child === void 0) throw new Error(`@prisma/cli-engine: command '${invocation.state.commandId}' returned exitWithChildStatus without a child having run — that settlement reports the status of a child ctx.spawn started, and this run started none`);
|
|
2498
|
+
if (child.signal === null) for (const action of settlement.nextActions) invocation.runtime.stderr.write(`${renderNextAction(action)}\n`);
|
|
2499
|
+
settleVerbatimExitCode(invocation, childExitCode(child));
|
|
2433
2500
|
}
|
|
2434
2501
|
/** A session command that returned ok shut down cleanly: no
|
|
2435
2502
|
* presentation, and exit 0 — unless a signal ended the run, which
|
|
@@ -2514,6 +2581,43 @@ function settleVersion(spec, invocation) {
|
|
|
2514
2581
|
});
|
|
2515
2582
|
return 0;
|
|
2516
2583
|
}
|
|
2584
|
+
/** What the user typed that no longer exists: a retired path, or a
|
|
2585
|
+
* retired flag on a command that still exists. */
|
|
2586
|
+
function retiredInvocation(redirect) {
|
|
2587
|
+
if (redirect.flag === void 0) return `\`${redirect.from}\``;
|
|
2588
|
+
return `\`--${kebabCase(redirect.flag)}\` on \`${redirect.from}\``;
|
|
2589
|
+
}
|
|
2590
|
+
/** A retired invocation the redirect table claims: the run names its
|
|
2591
|
+
* replacement instead of failing as an unknown command or flag. A
|
|
2592
|
+
* retired flag can name a server command, whose stdout belongs to a
|
|
2593
|
+
* foreign client — so this settlement renders to stderr for the same
|
|
2594
|
+
* reason settleUnhandled does. */
|
|
2595
|
+
function settleCommandMoved(spec, invocation, redirect, commandId) {
|
|
2596
|
+
if (spec.commands[redirect.from]?.kind === "server-command") invocation.state.format = "human";
|
|
2597
|
+
const useReplacement = {
|
|
2598
|
+
kind: "run-command",
|
|
2599
|
+
label: "Use the replacement",
|
|
2600
|
+
command: resolveExample(redirect.replacement, spec.name)
|
|
2601
|
+
};
|
|
2602
|
+
emitErrored(invocation, {
|
|
2603
|
+
ok: false,
|
|
2604
|
+
commandId,
|
|
2605
|
+
error: {
|
|
2606
|
+
code: "CLI.COMMAND_MOVED",
|
|
2607
|
+
severity: "error",
|
|
2608
|
+
summary: `${retiredInvocation(redirect)} has been replaced`,
|
|
2609
|
+
...redirect.reason === void 0 ? {} : { why: redirect.reason },
|
|
2610
|
+
nextActions: [useReplacement]
|
|
2611
|
+
},
|
|
2612
|
+
diagnostics: [],
|
|
2613
|
+
nextActions: [useReplacement]
|
|
2614
|
+
});
|
|
2615
|
+
return 2;
|
|
2616
|
+
}
|
|
2617
|
+
/** The command path stricli resolved, without the binary name. */
|
|
2618
|
+
function commandSegments(spec, prefix) {
|
|
2619
|
+
return prefix[0] === spec.name ? prefix.slice(1) : prefix;
|
|
2620
|
+
}
|
|
2517
2621
|
/** Maps stricli's own settlement (parse/route failures, framework bugs)
|
|
2518
2622
|
* onto the engine protocol when the pipeline never settled. A failure
|
|
2519
2623
|
* addressed at a server command renders to stderr — a foreign client on
|
|
@@ -2522,7 +2626,7 @@ function settleUnhandled(spec, invocation, stricliExitCode) {
|
|
|
2522
2626
|
const state = invocation.state;
|
|
2523
2627
|
const raw = typeof stricliExitCode === "number" ? stricliExitCode : 0;
|
|
2524
2628
|
if (raw === 0) return 0;
|
|
2525
|
-
const segments =
|
|
2629
|
+
const segments = commandSegments(spec, state.prefix);
|
|
2526
2630
|
if (spec.commands[segments.join(" ")]?.kind === "server-command") state.format = "human";
|
|
2527
2631
|
const usage = usageErrorCode(raw) !== void 0;
|
|
2528
2632
|
const captured = usage ? state.stricliStderr.trim() : state.usageErrorText ?? state.internalErrorText ?? state.stricliStderr.trim();
|
|
@@ -2566,6 +2670,7 @@ function waitFor(ms, signal) {
|
|
|
2566
2670
|
var EngineImpl = class {
|
|
2567
2671
|
spec;
|
|
2568
2672
|
root;
|
|
2673
|
+
redirects;
|
|
2569
2674
|
now;
|
|
2570
2675
|
delay;
|
|
2571
2676
|
configSections;
|
|
@@ -2575,6 +2680,7 @@ var EngineImpl = class {
|
|
|
2575
2680
|
this.delay = delay;
|
|
2576
2681
|
this.configSections = declaredConfigSections(spec);
|
|
2577
2682
|
this.root = buildRoutes(spec, buildCommandTree(spec), "", (invocation, entry, flags, values) => this.executeMounted(invocation, entry, flags, values));
|
|
2683
|
+
this.redirects = buildRedirectTable(spec);
|
|
2578
2684
|
}
|
|
2579
2685
|
async execute(argv, runtime, hooks) {
|
|
2580
2686
|
const state = {
|
|
@@ -2595,8 +2701,10 @@ var EngineImpl = class {
|
|
|
2595
2701
|
stricliStderr: "",
|
|
2596
2702
|
stdinIterator: void 0,
|
|
2597
2703
|
argv,
|
|
2704
|
+
unresolvedFlagNames: [],
|
|
2598
2705
|
snapshot: void 0,
|
|
2599
2706
|
delegatedTerminal: void 0,
|
|
2707
|
+
lastChild: void 0,
|
|
2600
2708
|
activePrompts: 0,
|
|
2601
2709
|
deliveredSignal: void 0,
|
|
2602
2710
|
pendingForceExit: void 0,
|
|
@@ -2675,11 +2783,36 @@ var EngineImpl = class {
|
|
|
2675
2783
|
unsubscribe();
|
|
2676
2784
|
await state.stdinIterator?.return?.();
|
|
2677
2785
|
}
|
|
2678
|
-
const exitCode = state.settledExitCode !== void 0 ? state.settledExitCode :
|
|
2786
|
+
const exitCode = state.settledExitCode !== void 0 ? state.settledExitCode : this.settleRouting(invocation, stricliProcess.exitCode);
|
|
2679
2787
|
this.fireOnSettled(invocation, exitCode, startedAtMs);
|
|
2680
2788
|
if (state.pendingForceExit !== void 0) runtime.exit(state.pendingForceExit === "SIGTERM" ? 143 : 130);
|
|
2681
2789
|
return exitCode;
|
|
2682
2790
|
}
|
|
2791
|
+
/** stricli routed or parsed nothing runnable. When the redirect table
|
|
2792
|
+
* claims the invocation the user typed, the run names its
|
|
2793
|
+
* replacement; otherwise it settles as the usage error it is. */
|
|
2794
|
+
settleRouting(invocation, stricliExitCode) {
|
|
2795
|
+
const matched = this.matchRedirect(invocation.state, stricliExitCode);
|
|
2796
|
+
if (matched === void 0) return settleUnhandled(this.spec, invocation, stricliExitCode);
|
|
2797
|
+
return settleCommandMoved(this.spec, invocation, matched.redirect, matched.commandId);
|
|
2798
|
+
}
|
|
2799
|
+
matchRedirect(state, stricliExitCode) {
|
|
2800
|
+
const failure = typeof stricliExitCode === "number" ? usageErrorCode(stricliExitCode) : void 0;
|
|
2801
|
+
if (failure === "CLI.UNKNOWN_COMMAND") {
|
|
2802
|
+
const redirect = matchVerbRedirect(this.redirects, attemptedPath(state.argv));
|
|
2803
|
+
return redirect === void 0 ? void 0 : {
|
|
2804
|
+
redirect,
|
|
2805
|
+
commandId: redirect.from.replaceAll(" ", ".")
|
|
2806
|
+
};
|
|
2807
|
+
}
|
|
2808
|
+
if (failure !== "CLI.INVALID_ARGUMENTS") return;
|
|
2809
|
+
const segments = commandSegments(this.spec, state.prefix);
|
|
2810
|
+
const redirect = matchFlagRedirect(this.redirects, segments.join(" "), state.unresolvedFlagNames);
|
|
2811
|
+
return redirect === void 0 ? void 0 : {
|
|
2812
|
+
redirect,
|
|
2813
|
+
commandId: segments.join(".")
|
|
2814
|
+
};
|
|
2815
|
+
}
|
|
2683
2816
|
/** The onSettled delivery: once per run, after the exit code is
|
|
2684
2817
|
* final, only for runs that mounted a command (--help, --version,
|
|
2685
2818
|
* and pre-mount usage errors leave no snapshot and fire nothing).
|
|
@@ -2829,6 +2962,16 @@ var EngineImpl = class {
|
|
|
2829
2962
|
}
|
|
2830
2963
|
}
|
|
2831
2964
|
};
|
|
2965
|
+
/** The path the user typed, for argv that routed to no command: the
|
|
2966
|
+
* leading tokens up to the first flag or argument escape. */
|
|
2967
|
+
function attemptedPath(argv) {
|
|
2968
|
+
const segments = [];
|
|
2969
|
+
for (const token of argv) {
|
|
2970
|
+
if (token.startsWith("-")) break;
|
|
2971
|
+
segments.push(token);
|
|
2972
|
+
}
|
|
2973
|
+
return segments;
|
|
2974
|
+
}
|
|
2832
2975
|
/** The closed set of config section names. Every mounted command
|
|
2833
2976
|
* contributes the section it needs, whether it reaches the tree
|
|
2834
2977
|
* through a command family or on its own — the shell mounts its own
|