@prisma/cli-engine 0.0.6 → 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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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
|
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,9 +13,14 @@ 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
|
+
}
|
|
16
21
|
function normalizeRedirect(spec) {
|
|
17
22
|
return Object.freeze({
|
|
18
|
-
from: spec.from,
|
|
23
|
+
from: normalizePath(spec.from),
|
|
19
24
|
flag: spec.flag,
|
|
20
25
|
replacement: spec.replacement,
|
|
21
26
|
reason: spec.reason
|
|
@@ -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";
|
|
@@ -1128,7 +1148,8 @@ interface RedirectSpec {
|
|
|
1128
1148
|
/**
|
|
1129
1149
|
* The retired invocation as the user types it: a space-separated
|
|
1130
1150
|
* absolute path in the mounted tree, the same convention as
|
|
1131
|
-
* MountedTree keys.
|
|
1151
|
+
* MountedTree keys. Whitespace only separates segments, so it is
|
|
1152
|
+
* normalized away — `' migration \t apply '` is `'migration apply'`.
|
|
1132
1153
|
*/
|
|
1133
1154
|
readonly from: string;
|
|
1134
1155
|
/**
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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
|
/**
|
|
@@ -106,26 +106,6 @@ function camelCase(typed) {
|
|
|
106
106
|
//#endregion
|
|
107
107
|
//#region src/spawn.ts
|
|
108
108
|
const CHILD_STATUS = Symbol.for("@prisma/cli-engine.childStatus");
|
|
109
|
-
/** Marks a ChildResult the engine watched a real child produce. */
|
|
110
|
-
const ENGINE_SPAWNED = Symbol.for("@prisma/cli-engine.engineSpawned");
|
|
111
|
-
function markEngineSpawned(value) {
|
|
112
|
-
return Object.freeze(Object.defineProperty(value, ENGINE_SPAWNED, { value: true }));
|
|
113
|
-
}
|
|
114
|
-
function isEngineSpawned(value) {
|
|
115
|
-
return value[ENGINE_SPAWNED] === true;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* The child result ctx.spawn hands back: the engine mints it from what
|
|
119
|
-
* the adapter reported, so a handler cannot pass off an invented one as
|
|
120
|
-
* a child's status. exitWithChildStatus carries the mark onto its
|
|
121
|
-
* settlement and the settlement refuses an unmarked one.
|
|
122
|
-
*/
|
|
123
|
-
function engineSpawnedResult(result) {
|
|
124
|
-
return markEngineSpawned({
|
|
125
|
-
exitCode: result.exitCode,
|
|
126
|
-
signal: result.signal
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
109
|
/** Signal numbers shared by Linux, macOS and the BSDs. Numbers that
|
|
130
110
|
* differ by platform (SIGBUS, SIGUSR1, SIGUSR2, …) are deliberately
|
|
131
111
|
* absent — a wrong 128+n is worse than the unknown-signal fallback. */
|
|
@@ -152,17 +132,22 @@ function childExitCode(child) {
|
|
|
152
132
|
const signalNumber = SIGNAL_NUMBERS[child.signal];
|
|
153
133
|
return signalNumber === void 0 ? 1 : 128 + signalNumber;
|
|
154
134
|
}
|
|
155
|
-
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
|
|
160
|
-
|
|
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({
|
|
161
148
|
[CHILD_STATUS]: true,
|
|
162
|
-
exitCode: childExitCode(child),
|
|
163
149
|
nextActions: Object.freeze([...options?.nextActions ?? []])
|
|
164
|
-
};
|
|
165
|
-
return isEngineSpawned(child) ? markEngineSpawned(settlement) : Object.freeze(settlement);
|
|
150
|
+
});
|
|
166
151
|
}
|
|
167
152
|
function isChildStatusSettlement(value) {
|
|
168
153
|
return typeof value === "object" && value !== null && value[CHILD_STATUS] === true;
|
|
@@ -1087,8 +1072,11 @@ function addFlagRedirect(spec, table, redirect, flag) {
|
|
|
1087
1072
|
function buildRedirectTable(spec) {
|
|
1088
1073
|
const byPath = /* @__PURE__ */ new Map();
|
|
1089
1074
|
const byFlag = /* @__PURE__ */ new Map();
|
|
1090
|
-
for (const commandFamily of spec.commandFamilies) for (const redirect of commandFamily.redirects)
|
|
1091
|
-
|
|
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
|
+
}
|
|
1092
1080
|
return {
|
|
1093
1081
|
byPath,
|
|
1094
1082
|
byFlag
|
|
@@ -1942,13 +1930,26 @@ async function runChild(invocation, terminal, spawnChild, request) {
|
|
|
1942
1930
|
const ended = new AbortController();
|
|
1943
1931
|
armTerminationLadder(invocation, terminal, child, ended.signal);
|
|
1944
1932
|
try {
|
|
1945
|
-
return
|
|
1933
|
+
return recordCompletedChild(invocation, await child.ended);
|
|
1946
1934
|
} catch (cause) {
|
|
1947
1935
|
throw spawnFailedError(request.command, cause);
|
|
1948
1936
|
} finally {
|
|
1949
1937
|
ended.abort();
|
|
1950
1938
|
}
|
|
1951
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
|
+
}
|
|
1952
1953
|
/** A programmatic abort of ctx.signal (a delivered signal is recorded
|
|
1953
1954
|
* instead), or the engine ending a child the handler abandoned,
|
|
1954
1955
|
* terminates the child: SIGTERM, the grace period, SIGKILL. */
|
|
@@ -2083,6 +2084,7 @@ function makeContext(invocation, def, config, managesCredentials) {
|
|
|
2083
2084
|
return api;
|
|
2084
2085
|
},
|
|
2085
2086
|
spawn: makeSpawn(invocation, def),
|
|
2087
|
+
lastChild: () => state.lastChild,
|
|
2086
2088
|
report: (event) => reportEvent(invocation, event),
|
|
2087
2089
|
prompt: makePromptSurface(invocation),
|
|
2088
2090
|
openUrl: (request) => announceUrl(invocation, request),
|
|
@@ -2478,20 +2480,23 @@ function settleVerbatimExitCode(invocation, exitCode) {
|
|
|
2478
2480
|
* never documented, because the code is not the handler's own
|
|
2479
2481
|
* conclusion, it is the child's.
|
|
2480
2482
|
*
|
|
2481
|
-
*
|
|
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
|
|
2482
2486
|
* hand the terminal to another program — reachable from a
|
|
2483
2487
|
* non-declaring handler this would also end a json stream without its
|
|
2484
|
-
* terminal result frame
|
|
2485
|
-
*
|
|
2486
|
-
*
|
|
2487
|
-
*
|
|
2488
|
-
*
|
|
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.
|
|
2489
2493
|
*/
|
|
2490
2494
|
function settleChildStatus(invocation, def, settlement) {
|
|
2491
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`);
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
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));
|
|
2495
2500
|
}
|
|
2496
2501
|
/** A session command that returned ok shut down cleanly: no
|
|
2497
2502
|
* presentation, and exit 0 — unless a signal ended the run, which
|
|
@@ -2699,6 +2704,7 @@ var EngineImpl = class {
|
|
|
2699
2704
|
unresolvedFlagNames: [],
|
|
2700
2705
|
snapshot: void 0,
|
|
2701
2706
|
delegatedTerminal: void 0,
|
|
2707
|
+
lastChild: void 0,
|
|
2702
2708
|
activePrompts: 0,
|
|
2703
2709
|
deliveredSignal: void 0,
|
|
2704
2710
|
pendingForceExit: void 0,
|