@prisma/cli-engine 0.0.6 → 0.0.8
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 +7 -2
- package/dist/{run-summary-CNL0TNZu.d.ts → run-summary-CVHIRjTS.d.ts} +107 -24
- package/dist/testing.d.ts +6 -1
- package/dist/testing.js +7 -4
- package/dist/{token-claims-B6V7E0NS.js → token-claims-_AF7BYbq.js} +250 -69
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as TreeNode, A as BrowserWaitRequest, B as SpawnRequest, C as defineSessionCommand, Ct as FlagSpec, D as OutputStream, E as LoadedConfig, Et as positional, 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 Tone, R as SpawnChild, S as defineServerCommand, St as CommandArgs, T as InputStream, Tt as flag, U as Block, V as SpawnedChild, W as Format, X as Status, Y as Span, Z as Text, _ as NeedsSpec, _t as SectionValidation, a as MountedTree, at as ActiveCredential, b as SpawnDeclarations, bt as ArgsSpec, c as AnyCommand, ct as CredentialManager, d as CommandHelp, dt as Session, et as Ui, f as CommandNeeds, ft as StoredSessions, g as HelpSpec, gt as ConfigSection, h as Handler, ht as TokenStorage, i as CommandRedirect, it as StreamMeta, j as CommandContext, k as Runtime, l as CommandDefinition, lt as CredentialOrigin, m as ErroredEnvelope, mt as ManagementApiClientConfig, n as RunSummary, nt as Severity, o as RedirectSpec, ot as Credential, p as CompletedEnvelope, pt as ManagementApiClient, q as Presentations, r as CommandFamily, rt as StreamEvent, s as defineCommandFamily, st as CredentialIdentity, t as EngineCommandSnapshot, tt as EngineEvent, u as CommandHandler, ut as SERVICE_TOKEN_ENV_VAR, v as ServerCommandDefinition, vt as defineConfigSection, w as HostProcess, wt as PositionalSpec, x as defineCommand, xt as Char, y as SessionCommandDefinition, yt as Args, z as SpawnOptions } from "./run-summary-CVHIRjTS.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 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 };
|
|
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 };
|
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-_AF7BYbq.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
|
|
@@ -439,6 +439,34 @@ interface Presentations {
|
|
|
439
439
|
readonly json?: () => unknown;
|
|
440
440
|
readonly next?: () => readonly NextAction[];
|
|
441
441
|
}
|
|
442
|
+
/**
|
|
443
|
+
* What happened: it selects the glyph (✔ ✘ ⚠ ℹ) and carries a default
|
|
444
|
+
* Tone of the same name. Separate from Tone because a failure can be
|
|
445
|
+
* painted in a colour that is not `error` — a tree node in its branch
|
|
446
|
+
* lane's hue, say — and a colour can be chosen where nothing happened.
|
|
447
|
+
*/
|
|
448
|
+
type Status = "ok" | "error" | "warn" | "info";
|
|
449
|
+
/**
|
|
450
|
+
* What colour to paint, and nothing else. Semantic names and indexed
|
|
451
|
+
* colours in one union: a command asks for meaning where it has one and
|
|
452
|
+
* for a distinguishable colour where it does not. The indexed colours
|
|
453
|
+
* are for telling adjacent things apart — one per branch lane in a
|
|
454
|
+
* graph, say — and deliberately exclude red so no series member reads
|
|
455
|
+
* as an error.
|
|
456
|
+
*/
|
|
457
|
+
type Tone = "ok" | "warn" | "error" | "info" | "heading" | "identifier" | "ref" | "placeholder" | "link" | "emphasis" | "muted" | "structure" | "highlight" | "color-1" | "color-2" | "color-3" | "color-4" | "color-5" | "color-6";
|
|
458
|
+
/**
|
|
459
|
+
* A run of text and the meaning of its colour. A handler never emits
|
|
460
|
+
* escape sequences: the engine measures width from `text`, so colour
|
|
461
|
+
* cannot break alignment, and the same spans can be re-themed or
|
|
462
|
+
* stripped without re-rendering.
|
|
463
|
+
*/
|
|
464
|
+
interface Span {
|
|
465
|
+
readonly text: string;
|
|
466
|
+
readonly tone?: Tone;
|
|
467
|
+
}
|
|
468
|
+
/** Display text anywhere a block or Ui takes it. A bare string is untoned. */
|
|
469
|
+
type Text = string | readonly Span[];
|
|
442
470
|
/**
|
|
443
471
|
* Deliberately small; grows by the same evidence rule as events.
|
|
444
472
|
* Recorded findings are NOT a Block — they are the outcome's
|
|
@@ -447,35 +475,64 @@ interface Presentations {
|
|
|
447
475
|
*/
|
|
448
476
|
type Block = {
|
|
449
477
|
readonly kind: "summary";
|
|
450
|
-
readonly
|
|
451
|
-
readonly
|
|
478
|
+
readonly status: Status; /** Overrides the colour the status implies. Never the glyph. */
|
|
479
|
+
readonly tone?: Tone;
|
|
480
|
+
readonly text: Text;
|
|
452
481
|
} | {
|
|
482
|
+
/** A key/value card: the engine pads the keys so every value
|
|
483
|
+
* starts in the same column. */
|
|
453
484
|
readonly kind: "fields";
|
|
454
485
|
readonly rows: ReadonlyArray<{
|
|
455
|
-
readonly label:
|
|
456
|
-
readonly value:
|
|
486
|
+
readonly label: Text;
|
|
487
|
+
readonly value: Text;
|
|
457
488
|
readonly sensitive?: boolean;
|
|
458
489
|
}>;
|
|
490
|
+
/** Draws the dim `│` rail down the left of the card. A command
|
|
491
|
+
* knows whether it is drawing a header card or a plain one, so
|
|
492
|
+
* this is per block rather than a global setting. */
|
|
493
|
+
readonly rail?: boolean;
|
|
459
494
|
} | {
|
|
460
|
-
readonly kind: "table";
|
|
461
|
-
readonly columns: readonly
|
|
462
|
-
readonly rows: ReadonlyArray<readonly
|
|
495
|
+
/** The engine sizes every column to its widest cell. */readonly kind: "table";
|
|
496
|
+
readonly columns: readonly Text[];
|
|
497
|
+
readonly rows: ReadonlyArray<readonly Text[]>;
|
|
463
498
|
} | {
|
|
464
499
|
readonly kind: "list";
|
|
465
|
-
readonly items: readonly
|
|
500
|
+
readonly items: readonly Text[];
|
|
466
501
|
} | {
|
|
467
502
|
readonly kind: "tree";
|
|
468
503
|
readonly roots: readonly TreeNode[];
|
|
504
|
+
} | {
|
|
505
|
+
/**
|
|
506
|
+
* Lines of spans, rendered verbatim — no layout, no reflow, no
|
|
507
|
+
* truncation. For output whose two-dimensional structure the
|
|
508
|
+
* engine cannot derive, such as a migration graph's lane gutter,
|
|
509
|
+
* where the same hue has to reach the gutter cell, the node glyph
|
|
510
|
+
* and the label alike.
|
|
511
|
+
*/
|
|
512
|
+
readonly kind: "drawing";
|
|
513
|
+
readonly lines: readonly Text[];
|
|
469
514
|
};
|
|
470
515
|
interface TreeNode {
|
|
471
|
-
readonly label:
|
|
516
|
+
readonly label: Text;
|
|
517
|
+
/** Renders its glyph before the label. */
|
|
518
|
+
readonly status?: Status;
|
|
519
|
+
/** Colours the glyph and the label; defaults to the status. */
|
|
520
|
+
readonly tone?: Tone;
|
|
472
521
|
readonly children?: readonly TreeNode[];
|
|
473
522
|
}
|
|
474
523
|
/** Styling helpers usable inside block text; no direct writing. */
|
|
475
524
|
interface Ui {
|
|
525
|
+
/**
|
|
526
|
+
* How much room the command has: stderr's terminal width, or
|
|
527
|
+
* Number.POSITIVE_INFINITY when stderr is not a terminal. Only the
|
|
528
|
+
* command knows what to sacrifice, so the engine hands over the number
|
|
529
|
+
* and prints an overrun unmodified.
|
|
530
|
+
*/
|
|
531
|
+
readonly width: number;
|
|
476
532
|
readonly emphasize: (text: string) => string;
|
|
477
533
|
readonly dim: (text: string) => string;
|
|
478
534
|
readonly code: (text: string) => string;
|
|
535
|
+
readonly tone: (tone: Tone, text: string) => string;
|
|
479
536
|
}
|
|
480
537
|
//#endregion
|
|
481
538
|
//#region src/spawn.d.ts
|
|
@@ -489,8 +546,9 @@ interface SpawnRequest {
|
|
|
489
546
|
readonly env: Readonly<Record<string, string | undefined>>;
|
|
490
547
|
}
|
|
491
548
|
/** How a child ended. A signal-killed child carries `signal` and a null
|
|
492
|
-
* `exitCode
|
|
493
|
-
*
|
|
549
|
+
* `exitCode`, and is an abort rather than a failure: exitWithChildStatus
|
|
550
|
+
* settles it as one, and a handler that reads the result itself branches
|
|
551
|
+
* on `signal` before `exitCode`. */
|
|
494
552
|
interface ChildResult {
|
|
495
553
|
readonly exitCode: number | null;
|
|
496
554
|
readonly signal: string | null;
|
|
@@ -524,25 +582,34 @@ declare const CHILD_STATUS: unique symbol;
|
|
|
524
582
|
* The sanctioned settlement outcome for "exit with the child's status
|
|
525
583
|
* verbatim": no envelope, the same settlement bypass server commands
|
|
526
584
|
* use. Built exclusively by exitWithChildStatus, and only settled by a
|
|
527
|
-
* command that declares maySpawn
|
|
528
|
-
*
|
|
529
|
-
*
|
|
585
|
+
* command that declares maySpawn. It carries no exit code, because the
|
|
586
|
+
* code is not the handler's to state: the engine reads it off its own
|
|
587
|
+
* record of the child. `nextActions` render to stderr before the
|
|
588
|
+
* process exits with the child's code.
|
|
530
589
|
*/
|
|
531
590
|
interface ChildStatusSettlement {
|
|
532
591
|
readonly [CHILD_STATUS]: true;
|
|
533
|
-
readonly exitCode: number;
|
|
534
592
|
readonly nextActions: readonly NextAction[];
|
|
535
593
|
}
|
|
536
594
|
interface ExitWithChildStatusOptions {
|
|
537
595
|
/** Engine-styled guidance printed to stderr before the exit — a
|
|
538
|
-
* failed converge's reproduce hint. The envelope stays absent
|
|
596
|
+
* failed converge's reproduce hint. The envelope stays absent, and
|
|
597
|
+
* a signal-killed child drops these entirely: the user stopped the
|
|
598
|
+
* run, so there is nothing to reproduce. */
|
|
539
599
|
readonly nextActions?: readonly NextAction[];
|
|
540
600
|
}
|
|
541
|
-
/**
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
|
|
601
|
+
/**
|
|
602
|
+
* Settles the run with the status of the child the run spawned — the
|
|
603
|
+
* one `ctx.lastChild()` reports. The handler names no child and no
|
|
604
|
+
* code: this is how a real child's status reaches the exit code, not
|
|
605
|
+
* how a handler picks one, so a run that spawned nothing is a
|
|
606
|
+
* construction error at settlement.
|
|
607
|
+
*
|
|
608
|
+
* A signal-killed child overrules everything the caller asked for: it
|
|
609
|
+
* settles 128 + the signal number with no `nextActions`, because the
|
|
610
|
+
* user stopped the run and there is nothing to reproduce.
|
|
611
|
+
*/
|
|
612
|
+
declare function exitWithChildStatus(options?: ExitWithChildStatusOptions): ChildStatusSettlement;
|
|
546
613
|
//#endregion
|
|
547
614
|
//#region src/context.d.ts
|
|
548
615
|
/** The handler context — the whole world arrives as one argument. */
|
|
@@ -597,6 +664,15 @@ interface CommandContext<TConfig = undefined, TCode extends number = never> {
|
|
|
597
664
|
* failure.
|
|
598
665
|
*/
|
|
599
666
|
readonly spawn: (options: SpawnOptions) => Promise<ChildResult>;
|
|
667
|
+
/**
|
|
668
|
+
* How the run's most recent completed child ended, or undefined when
|
|
669
|
+
* none has run. The engine records every child ctx.spawn returns, so
|
|
670
|
+
* a handler whose spawn happens deep in its own layering can still
|
|
671
|
+
* ask "did my child fail?" where it settles, without threading the
|
|
672
|
+
* result back by hand. This is the same record exitWithChildStatus
|
|
673
|
+
* settles from.
|
|
674
|
+
*/
|
|
675
|
+
readonly lastChild: () => ChildResult | undefined;
|
|
600
676
|
/** The one way to emit while running. */
|
|
601
677
|
readonly report: (event: EngineEvent) => void;
|
|
602
678
|
/** Interactive input. */
|
|
@@ -728,6 +804,10 @@ interface PromptSurface {
|
|
|
728
804
|
/** Minimal structural stream types; no NodeJS.* in the public surface. */
|
|
729
805
|
interface OutputStream {
|
|
730
806
|
write(text: string): void;
|
|
807
|
+
/** The stream's terminal width, absent when it is not a terminal.
|
|
808
|
+
* The engine reads it at render time rather than caching it, so a
|
|
809
|
+
* terminal resized mid-run is respected by the next thing drawn. */
|
|
810
|
+
readonly columns?: number;
|
|
731
811
|
}
|
|
732
812
|
/**
|
|
733
813
|
* Byte-oriented, so server commands can implement byte-counted
|
|
@@ -826,6 +906,7 @@ interface HostProcess {
|
|
|
826
906
|
readonly stderr: {
|
|
827
907
|
write(text: string): unknown;
|
|
828
908
|
isTTY?: boolean;
|
|
909
|
+
columns?: number;
|
|
829
910
|
};
|
|
830
911
|
readonly stdin: {
|
|
831
912
|
isTTY?: boolean;
|
|
@@ -1020,7 +1101,8 @@ declare function defineCommand<TFlags extends Record<string, FlagSpec<unknown>>
|
|
|
1020
1101
|
* ok(undefined) exits 0 — or 130/143 when a signal ended the run, which
|
|
1021
1102
|
* the engine settles from its own record of that signal, not from
|
|
1022
1103
|
* anything the handler returns; one that returns
|
|
1023
|
-
* ok(exitWithChildStatus(
|
|
1104
|
+
* ok(exitWithChildStatus()) exits with the status of the child it
|
|
1105
|
+
* spawned.
|
|
1024
1106
|
*/
|
|
1025
1107
|
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
1108
|
readonly kind: "session-command";
|
|
@@ -1128,7 +1210,8 @@ interface RedirectSpec {
|
|
|
1128
1210
|
/**
|
|
1129
1211
|
* The retired invocation as the user types it: a space-separated
|
|
1130
1212
|
* absolute path in the mounted tree, the same convention as
|
|
1131
|
-
* MountedTree keys.
|
|
1213
|
+
* MountedTree keys. Whitespace only separates segments, so it is
|
|
1214
|
+
* normalized away — `' migration \t apply '` is `'migration apply'`.
|
|
1132
1215
|
*/
|
|
1133
1216
|
readonly from: string;
|
|
1134
1217
|
/**
|
|
@@ -1228,4 +1311,4 @@ interface RunSummary {
|
|
|
1228
1311
|
readonly snapshot: EngineCommandSnapshot;
|
|
1229
1312
|
}
|
|
1230
1313
|
//#endregion
|
|
1231
|
-
export {
|
|
1314
|
+
export { TreeNode as $, BrowserWaitRequest as A, SpawnRequest as B, defineSessionCommand as C, FlagSpec as Ct, OutputStream as D, LoadedConfig as E, positional as Et, 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, Tone as Q, SpawnChild as R, defineServerCommand as S, CommandArgs as St, InputStream as T, flag as Tt, Block as U, SpawnedChild as V, Format as W, Status as X, Span as Y, Text as Z, NeedsSpec as _, SectionValidation as _t, MountedTree as a, ActiveCredential as at, SpawnDeclarations as b, ArgsSpec as bt, AnyCommand as c, CredentialManager as ct, CommandHelp as d, Session as dt, Ui as et, CommandNeeds as f, StoredSessions as ft, HelpSpec as g, ConfigSection as gt, Handler as h, TokenStorage$1 as ht, CommandRedirect as i, StreamMeta as it, CommandContext as j, Runtime as k, CommandDefinition as l, CredentialOrigin as lt, ErroredEnvelope as m, ManagementApiClientConfig as mt, RunSummary as n, Severity as nt, RedirectSpec as o, Credential as ot, CompletedEnvelope as p, ManagementApiClient$1 as pt, Presentations as q, CommandFamily as r, StreamEvent as rt, defineCommandFamily as s, CredentialIdentity as st, EngineCommandSnapshot as t, EngineEvent as tt, CommandHandler as u, SERVICE_TOKEN_ENV_VAR as ut, ServerCommandDefinition as v, defineConfigSection as vt, HostProcess as w, PositionalSpec as wt, defineCommand as x, Char as xt, SessionCommandDefinition as y, Args as yt, SpawnOptions as z };
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as SpawnRequest, F as ChildResult, J as PresentedResult, R as SpawnChild, a as MountedTree, at as ActiveCredential, ct as CredentialManager, dt as Session, ft as StoredSessions, ht as TokenStorage, k as Runtime, mt as ManagementApiClientConfig, n as RunSummary, ot as Credential, pt as ManagementApiClient, r as CommandFamily, rt as StreamEvent, tt as EngineEvent } from "./run-summary-CVHIRjTS.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
|
|
@@ -130,6 +130,11 @@ interface TestCli {
|
|
|
130
130
|
stdout?: boolean;
|
|
131
131
|
stderr?: boolean;
|
|
132
132
|
};
|
|
133
|
+
/** Terminal width, as the stream would report it. Absent means
|
|
134
|
+
* not a terminal, which is what ui.width reads as unbounded. */
|
|
135
|
+
readonly columns?: {
|
|
136
|
+
stderr?: number;
|
|
137
|
+
};
|
|
133
138
|
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
134
139
|
}): Promise<{
|
|
135
140
|
readonly exitCode: number;
|
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-_AF7BYbq.js";
|
|
2
2
|
import { Buffer } from "node:buffer";
|
|
3
3
|
//#region src/in-memory-credential-manager.ts
|
|
4
4
|
/**
|
|
@@ -378,9 +378,12 @@ function createTestCli(spec) {
|
|
|
378
378
|
stdout: { write: (text) => {
|
|
379
379
|
stdoutText += text;
|
|
380
380
|
} },
|
|
381
|
-
stderr: {
|
|
382
|
-
|
|
383
|
-
|
|
381
|
+
stderr: {
|
|
382
|
+
write: (text) => {
|
|
383
|
+
stderrText += text;
|
|
384
|
+
},
|
|
385
|
+
columns: opts?.columns?.stderr
|
|
386
|
+
},
|
|
384
387
|
stdin: inputStreamFromString(opts?.stdin ?? ""),
|
|
385
388
|
cwd: opts?.cwd ?? "/",
|
|
386
389
|
env: spec.environmentCredential === void 0 ? opts?.env ?? {} : {
|
|
@@ -3,6 +3,8 @@ import { createRequire } from "node:module";
|
|
|
3
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
|
+
import { createColors } from "colorette";
|
|
7
|
+
import stringWidth from "string-width";
|
|
6
8
|
import { Readable, Writable } from "node:stream";
|
|
7
9
|
import { Buffer } from "node:buffer";
|
|
8
10
|
//#region src/args.ts
|
|
@@ -106,26 +108,6 @@ function camelCase(typed) {
|
|
|
106
108
|
//#endregion
|
|
107
109
|
//#region src/spawn.ts
|
|
108
110
|
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
111
|
/** Signal numbers shared by Linux, macOS and the BSDs. Numbers that
|
|
130
112
|
* differ by platform (SIGBUS, SIGUSR1, SIGUSR2, …) are deliberately
|
|
131
113
|
* absent — a wrong 128+n is worse than the unknown-signal fallback. */
|
|
@@ -152,17 +134,22 @@ function childExitCode(child) {
|
|
|
152
134
|
const signalNumber = SIGNAL_NUMBERS[child.signal];
|
|
153
135
|
return signalNumber === void 0 ? 1 : 128 + signalNumber;
|
|
154
136
|
}
|
|
155
|
-
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
|
|
160
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Settles the run with the status of the child the run spawned — the
|
|
139
|
+
* one `ctx.lastChild()` reports. The handler names no child and no
|
|
140
|
+
* code: this is how a real child's status reaches the exit code, not
|
|
141
|
+
* how a handler picks one, so a run that spawned nothing is a
|
|
142
|
+
* construction error at settlement.
|
|
143
|
+
*
|
|
144
|
+
* A signal-killed child overrules everything the caller asked for: it
|
|
145
|
+
* settles 128 + the signal number with no `nextActions`, because the
|
|
146
|
+
* user stopped the run and there is nothing to reproduce.
|
|
147
|
+
*/
|
|
148
|
+
function exitWithChildStatus(options) {
|
|
149
|
+
return Object.freeze({
|
|
161
150
|
[CHILD_STATUS]: true,
|
|
162
|
-
exitCode: childExitCode(child),
|
|
163
151
|
nextActions: Object.freeze([...options?.nextActions ?? []])
|
|
164
|
-
};
|
|
165
|
-
return isEngineSpawned(child) ? markEngineSpawned(settlement) : Object.freeze(settlement);
|
|
152
|
+
});
|
|
166
153
|
}
|
|
167
154
|
function isChildStatusSettlement(value) {
|
|
168
155
|
return typeof value === "object" && value !== null && value[CHILD_STATUS] === true;
|
|
@@ -907,9 +894,20 @@ function applySharedFlags(state, shared, runtime) {
|
|
|
907
894
|
state.confirmValues = [...shared.confirm ?? []];
|
|
908
895
|
state.interactive = shared.interactive ?? defaultInteractive(runtime);
|
|
909
896
|
state.logLevel = resolveLogLevel(shared);
|
|
910
|
-
state.colorEnabled = shared
|
|
897
|
+
state.colorEnabled = resolveColorEnabled(shared, runtime);
|
|
911
898
|
state.configPath = shared.config;
|
|
912
899
|
}
|
|
900
|
+
/**
|
|
901
|
+
* Explicit flag, then the environment, then the stream. The stream is
|
|
902
|
+
* stderr because that is where blocks render: keying off stdout meant
|
|
903
|
+
* `cmd > file` lost colour a human was watching and `cmd 2> file` kept
|
|
904
|
+
* colour nobody could see.
|
|
905
|
+
*/
|
|
906
|
+
function resolveColorEnabled(shared, runtime) {
|
|
907
|
+
if (shared.color !== void 0) return shared.color;
|
|
908
|
+
if (runtime.env.NO_COLOR !== void 0) return false;
|
|
909
|
+
return runtime.isTty.stderr;
|
|
910
|
+
}
|
|
913
911
|
/** Interactive iff TTY stdin outside CI; --interactive and
|
|
914
912
|
* --no-interactive override in either direction. Format never decides
|
|
915
913
|
* interactivity (operator ruling, 2026-08-09): an interactive json run
|
|
@@ -1087,8 +1085,11 @@ function addFlagRedirect(spec, table, redirect, flag) {
|
|
|
1087
1085
|
function buildRedirectTable(spec) {
|
|
1088
1086
|
const byPath = /* @__PURE__ */ new Map();
|
|
1089
1087
|
const byFlag = /* @__PURE__ */ new Map();
|
|
1090
|
-
for (const commandFamily of spec.commandFamilies) for (const redirect of commandFamily.redirects)
|
|
1091
|
-
|
|
1088
|
+
for (const commandFamily of spec.commandFamilies) for (const redirect of commandFamily.redirects) {
|
|
1089
|
+
if (redirect.from === "") throw constructionError("redirect declares an empty path, so no invocation can produce it");
|
|
1090
|
+
if (redirect.flag === void 0) addVerbRedirect(spec, byPath, redirect);
|
|
1091
|
+
else addFlagRedirect(spec, byFlag, redirect, redirect.flag);
|
|
1092
|
+
}
|
|
1092
1093
|
return {
|
|
1093
1094
|
byPath,
|
|
1094
1095
|
byFlag
|
|
@@ -1112,6 +1113,72 @@ function matchFlagRedirect(table, commandPath, typedFlags) {
|
|
|
1112
1113
|
}
|
|
1113
1114
|
}
|
|
1114
1115
|
//#endregion
|
|
1116
|
+
//#region src/execution/palette.ts
|
|
1117
|
+
/**
|
|
1118
|
+
* Tones into bytes, and text into a display width. Basic 16-colour SGR
|
|
1119
|
+
* only — no 256-colour, no truecolor, and therefore no colour-depth
|
|
1120
|
+
* detection to own.
|
|
1121
|
+
*/
|
|
1122
|
+
/**
|
|
1123
|
+
* Every rendering is taken from a shipping implementation rather than
|
|
1124
|
+
* chosen fresh: the platform shell's semantic colours
|
|
1125
|
+
* (`packages/cli/src/shell/ui.ts`) and the ORM CLI's formatters. The
|
|
1126
|
+
* indexed colours are the ORM's lane rotation, in order, which excludes
|
|
1127
|
+
* red so a lane cannot be mistaken for an error.
|
|
1128
|
+
*
|
|
1129
|
+
* `heading` and `identifier` both render cyan because both shipping
|
|
1130
|
+
* CLIs use cyan for both. They stay separately named so a later
|
|
1131
|
+
* re-theme can separate them without touching a single command.
|
|
1132
|
+
*/
|
|
1133
|
+
const TONE_VERB = {
|
|
1134
|
+
ok: "greenBright",
|
|
1135
|
+
warn: "yellow",
|
|
1136
|
+
error: "redBright",
|
|
1137
|
+
info: "blue",
|
|
1138
|
+
heading: "cyan",
|
|
1139
|
+
identifier: "cyan",
|
|
1140
|
+
ref: "green",
|
|
1141
|
+
placeholder: "dim",
|
|
1142
|
+
link: "blue",
|
|
1143
|
+
emphasis: "bold",
|
|
1144
|
+
muted: "dim",
|
|
1145
|
+
structure: "dim",
|
|
1146
|
+
highlight: "greenBright",
|
|
1147
|
+
"color-1": "white",
|
|
1148
|
+
"color-2": "cyan",
|
|
1149
|
+
"color-3": "yellow",
|
|
1150
|
+
"color-4": "blueBright",
|
|
1151
|
+
"color-5": "magenta",
|
|
1152
|
+
"color-6": "green"
|
|
1153
|
+
};
|
|
1154
|
+
const COLORED = createColors({ useColor: true });
|
|
1155
|
+
const PLAIN = createColors({ useColor: false });
|
|
1156
|
+
function makePaint(colorEnabled) {
|
|
1157
|
+
const colors = colorEnabled ? COLORED : PLAIN;
|
|
1158
|
+
return (tone, text) => colors[TONE_VERB[tone]](text);
|
|
1159
|
+
}
|
|
1160
|
+
function renderText(text, paint) {
|
|
1161
|
+
if (typeof text === "string") return text;
|
|
1162
|
+
let rendered = "";
|
|
1163
|
+
for (const span of text) rendered += span.tone === void 0 ? span.text : paint(span.tone, span.text);
|
|
1164
|
+
return rendered;
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* The display width of what the reader sees, measured on the text the
|
|
1168
|
+
* spans carry rather than on the rendered bytes: colour cannot change a
|
|
1169
|
+
* column's width, and a CJK name is two cells wide, not one.
|
|
1170
|
+
*/
|
|
1171
|
+
function textWidth(text) {
|
|
1172
|
+
return stringWidth(plainText(text));
|
|
1173
|
+
}
|
|
1174
|
+
/** The text a reader sees, with every tone dropped. */
|
|
1175
|
+
function plainText(text) {
|
|
1176
|
+
if (typeof text === "string") return text;
|
|
1177
|
+
let plain = "";
|
|
1178
|
+
for (const span of text) plain += span.text;
|
|
1179
|
+
return plain;
|
|
1180
|
+
}
|
|
1181
|
+
//#endregion
|
|
1115
1182
|
//#region src/execution/rendering.ts
|
|
1116
1183
|
function firstLine(text) {
|
|
1117
1184
|
const newline = text.indexOf("\n");
|
|
@@ -1119,7 +1186,7 @@ function firstLine(text) {
|
|
|
1119
1186
|
}
|
|
1120
1187
|
const STEP_OUTCOME_SYMBOL = {
|
|
1121
1188
|
ok: "✔",
|
|
1122
|
-
failed: "
|
|
1189
|
+
failed: "✘",
|
|
1123
1190
|
skipped: "↷",
|
|
1124
1191
|
warning: "⚠"
|
|
1125
1192
|
};
|
|
@@ -1157,40 +1224,125 @@ function renderEventHuman(invocation, event) {
|
|
|
1157
1224
|
return;
|
|
1158
1225
|
}
|
|
1159
1226
|
}
|
|
1160
|
-
|
|
1227
|
+
/**
|
|
1228
|
+
* The four Status glyphs. The step-outcome map above and the
|
|
1229
|
+
* diagnostic-severity map below answer different questions, but the
|
|
1230
|
+
* three draw the same characters on purpose: one run must not report a
|
|
1231
|
+
* failure with one mark and explain it with another.
|
|
1232
|
+
*/
|
|
1233
|
+
const STATUS_SYMBOL = {
|
|
1161
1234
|
ok: "✔",
|
|
1162
|
-
error: "
|
|
1235
|
+
error: "✘",
|
|
1163
1236
|
warn: "⚠",
|
|
1164
1237
|
info: "ℹ"
|
|
1165
1238
|
};
|
|
1166
|
-
|
|
1239
|
+
const MASK = "********";
|
|
1240
|
+
const COLUMN_GAP = " ";
|
|
1241
|
+
const RAIL = "│";
|
|
1242
|
+
const BRANCH = "├─";
|
|
1243
|
+
const LAST_BRANCH = "└─";
|
|
1244
|
+
const TRAILING_SPACES = / +$/;
|
|
1245
|
+
/**
|
|
1246
|
+
* The engine draws; a command describes. Every escape sequence in the
|
|
1247
|
+
* output originates here, which is what makes width measurable and
|
|
1248
|
+
* alignment safe: a handler hands over spans, never bytes.
|
|
1249
|
+
*/
|
|
1250
|
+
function renderBlock(block, paint, write) {
|
|
1167
1251
|
switch (block.kind) {
|
|
1168
1252
|
case "summary":
|
|
1169
|
-
write(`${
|
|
1253
|
+
write(`${paint(block.tone ?? block.status, STATUS_SYMBOL[block.status])} ${renderText(block.text, paint)}`);
|
|
1170
1254
|
return;
|
|
1171
1255
|
case "fields":
|
|
1172
|
-
|
|
1256
|
+
writeFields(block.rows, block.rail === true, paint, write);
|
|
1173
1257
|
return;
|
|
1174
1258
|
case "table":
|
|
1175
|
-
|
|
1176
|
-
for (const row of block.rows) write(row.join(" "));
|
|
1259
|
+
writeTable(block.columns, block.rows, paint, write);
|
|
1177
1260
|
return;
|
|
1178
1261
|
case "list":
|
|
1179
|
-
for (const item of block.items) write(`- ${item}`);
|
|
1262
|
+
for (const item of block.items) write(`- ${renderText(item, paint)}`);
|
|
1180
1263
|
return;
|
|
1181
1264
|
case "tree":
|
|
1182
|
-
|
|
1265
|
+
for (const root of block.roots) {
|
|
1266
|
+
write(treeLabel(root, paint));
|
|
1267
|
+
writeBranches(root.children ?? [], "", paint, write);
|
|
1268
|
+
}
|
|
1269
|
+
return;
|
|
1270
|
+
case "drawing":
|
|
1271
|
+
for (const line of block.lines) write(renderText(line, paint));
|
|
1183
1272
|
return;
|
|
1184
1273
|
}
|
|
1185
1274
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1275
|
+
/** Appends to the text's last span, so a pad or a colon inherits the
|
|
1276
|
+
* tone of the run it extends — which is what makes a padded key one
|
|
1277
|
+
* continuous coloured field, as the legacy card drew it. */
|
|
1278
|
+
function extend(text, suffix) {
|
|
1279
|
+
if (suffix === "") return text;
|
|
1280
|
+
if (typeof text === "string") return `${text}${suffix}`;
|
|
1281
|
+
const last = text.at(-1);
|
|
1282
|
+
if (last === void 0) return suffix;
|
|
1283
|
+
return [...text.slice(0, -1), {
|
|
1284
|
+
...last,
|
|
1285
|
+
text: `${last.text}${suffix}`
|
|
1286
|
+
}];
|
|
1287
|
+
}
|
|
1288
|
+
function padTo(text, width) {
|
|
1289
|
+
const gap = width - textWidth(text);
|
|
1290
|
+
return gap > 0 ? extend(text, " ".repeat(gap)) : text;
|
|
1291
|
+
}
|
|
1292
|
+
/** The tone a cell falls back to when it states none of its own. */
|
|
1293
|
+
function toned(text, tone) {
|
|
1294
|
+
if (typeof text === "string") return [{
|
|
1295
|
+
text,
|
|
1296
|
+
tone
|
|
1297
|
+
}];
|
|
1298
|
+
return text.map((span) => span.tone === void 0 ? {
|
|
1299
|
+
...span,
|
|
1300
|
+
tone
|
|
1301
|
+
} : span);
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* The legacy card, restored: `${label}:` padded to a common width so
|
|
1305
|
+
* every value starts in the same column, the label in the accent
|
|
1306
|
+
* colour, two spaces between the two.
|
|
1307
|
+
*/
|
|
1308
|
+
function writeFields(rows, rail, paint, write) {
|
|
1309
|
+
const cells = rows.map((row) => ({
|
|
1310
|
+
label: toned(extend(row.label, ":"), "heading"),
|
|
1311
|
+
value: row.sensitive === true ? MASK : row.value
|
|
1312
|
+
}));
|
|
1313
|
+
const width = Math.max(0, ...cells.map((cell) => textWidth(cell.label)));
|
|
1314
|
+
const prefix = rail ? `${paint("structure", RAIL)}${COLUMN_GAP}` : "";
|
|
1315
|
+
for (const cell of cells) write(`${prefix}${renderText(padTo(cell.label, width), paint)}${COLUMN_GAP}${renderText(cell.value, paint)}`);
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Every column as wide as its widest cell, measured on the text rather
|
|
1319
|
+
* than the bytes so colour cannot shift a column. The last column is
|
|
1320
|
+
* never padded, so no line carries trailing whitespace.
|
|
1321
|
+
*/
|
|
1322
|
+
function writeTable(columns, rows, paint, write) {
|
|
1323
|
+
const all = [columns.map((column) => toned(column, "heading")), ...rows];
|
|
1324
|
+
const widths = [];
|
|
1325
|
+
for (const row of all) for (const [index, cell] of row.entries()) widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
1326
|
+
for (const row of all) write(row.map((cell, index) => renderText(index === row.length - 1 ? cell : padTo(cell, widths[index]), paint)).join(COLUMN_GAP).replace(TRAILING_SPACES, ""));
|
|
1327
|
+
}
|
|
1328
|
+
/** Roots carry no connector; every level below is drawn from its
|
|
1329
|
+
* parent's prefix, so a deep branch stays under its own lane. */
|
|
1330
|
+
function writeBranches(nodes, prefix, paint, write) {
|
|
1331
|
+
for (const [index, node] of nodes.entries()) {
|
|
1332
|
+
const last = index === nodes.length - 1;
|
|
1333
|
+
write(`${prefix}${paint("structure", last ? LAST_BRANCH : BRANCH)} ${treeLabel(node, paint)}`);
|
|
1334
|
+
const continuation = last ? " " : `${paint("structure", RAIL)}${COLUMN_GAP}`;
|
|
1335
|
+
writeBranches(node.children ?? [], `${prefix}${continuation}`, paint, write);
|
|
1190
1336
|
}
|
|
1191
1337
|
}
|
|
1338
|
+
function treeLabel(node, paint) {
|
|
1339
|
+
const tone = node.tone ?? node.status;
|
|
1340
|
+
const label = renderText(tone === void 0 ? node.label : toned(node.label, tone), paint);
|
|
1341
|
+
if (node.status === void 0) return label;
|
|
1342
|
+
return `${paint(node.tone ?? node.status, STATUS_SYMBOL[node.status])} ${label}`;
|
|
1343
|
+
}
|
|
1192
1344
|
const DIAGNOSTIC_SYMBOL = {
|
|
1193
|
-
error: "
|
|
1345
|
+
error: "✘",
|
|
1194
1346
|
warn: "⚠",
|
|
1195
1347
|
info: "ℹ"
|
|
1196
1348
|
};
|
|
@@ -1226,7 +1378,8 @@ function withDocsUrl(state, diagnostic) {
|
|
|
1226
1378
|
* payload on stdout, always — human mode stays pipe-clean. */
|
|
1227
1379
|
function renderCompletedHuman(invocation, presented) {
|
|
1228
1380
|
const { runtime, state } = invocation;
|
|
1229
|
-
|
|
1381
|
+
const paint = makePaint(state.colorEnabled);
|
|
1382
|
+
for (const block of presented.presentation.human) renderBlock(block, paint, (line) => runtime.stderr.write(`${line}\n`));
|
|
1230
1383
|
for (const action of presented.presentation.next) runtime.stderr.write(`${renderNextAction(action)}\n`);
|
|
1231
1384
|
for (const diagnostic of presented.diagnostics) writeDiagnostic(runtime.stderr, withDocsUrl(state, diagnostic));
|
|
1232
1385
|
for (const line of presented.presentation.stdout) runtime.stdout.write(`${line}\n`);
|
|
@@ -1249,7 +1402,7 @@ function eventDisplaySeverity(event) {
|
|
|
1249
1402
|
* so the only surface left is a stderr note — throwing here would
|
|
1250
1403
|
* surface as an unhandled rejection in a detached async context. */
|
|
1251
1404
|
function reportAfterResolution(invocation) {
|
|
1252
|
-
invocation.runtime.stderr.write("
|
|
1405
|
+
invocation.runtime.stderr.write("✘ [CLI.INTERNAL_ERROR] @prisma/cli-engine: report() was called after the handler resolved\n");
|
|
1253
1406
|
}
|
|
1254
1407
|
function reportEvent(invocation, event) {
|
|
1255
1408
|
const state = invocation.state;
|
|
@@ -1942,13 +2095,26 @@ async function runChild(invocation, terminal, spawnChild, request) {
|
|
|
1942
2095
|
const ended = new AbortController();
|
|
1943
2096
|
armTerminationLadder(invocation, terminal, child, ended.signal);
|
|
1944
2097
|
try {
|
|
1945
|
-
return
|
|
2098
|
+
return recordCompletedChild(invocation, await child.ended);
|
|
1946
2099
|
} catch (cause) {
|
|
1947
2100
|
throw spawnFailedError(request.command, cause);
|
|
1948
2101
|
} finally {
|
|
1949
2102
|
ended.abort();
|
|
1950
2103
|
}
|
|
1951
2104
|
}
|
|
2105
|
+
/** The engine mints the result the handler sees and keeps it on the
|
|
2106
|
+
* run: the settlement then reads the child's status from the engine's
|
|
2107
|
+
* own record rather than from anything the handler hands back, and a
|
|
2108
|
+
* handler whose spawn sits deep in its own layering can still ask how
|
|
2109
|
+
* the child ended through ctx.lastChild(). */
|
|
2110
|
+
function recordCompletedChild(invocation, ended) {
|
|
2111
|
+
const result = Object.freeze({
|
|
2112
|
+
exitCode: ended.exitCode,
|
|
2113
|
+
signal: ended.signal
|
|
2114
|
+
});
|
|
2115
|
+
invocation.state.lastChild = result;
|
|
2116
|
+
return result;
|
|
2117
|
+
}
|
|
1952
2118
|
/** A programmatic abort of ctx.signal (a delivered signal is recorded
|
|
1953
2119
|
* instead), or the engine ending a child the handler abandoned,
|
|
1954
2120
|
* terminates the child: SIGTERM, the grace period, SIGKILL. */
|
|
@@ -2029,16 +2195,26 @@ function spawnFailedError(command, cause) {
|
|
|
2029
2195
|
}
|
|
2030
2196
|
//#endregion
|
|
2031
2197
|
//#region src/execution/command-context.ts
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2198
|
+
/** Unbounded off-terminal, so the arithmetic a renderer already does —
|
|
2199
|
+
* Math.min(x, ui.width), ui.width - gutter — stays correct with no
|
|
2200
|
+
* special case. */
|
|
2201
|
+
function availableWidth(stream) {
|
|
2202
|
+
const columns = stream.columns;
|
|
2203
|
+
return columns !== void 0 && columns > 0 ? columns : Number.POSITIVE_INFINITY;
|
|
2204
|
+
}
|
|
2205
|
+
/** Blocks render to stderr, so both the width and the colour decision
|
|
2206
|
+
* are stderr's. `width` is a getter because the contract reads it per
|
|
2207
|
+
* render rather than caching it. */
|
|
2208
|
+
function makeUi(colorEnabled, stderr) {
|
|
2209
|
+
const paint = makePaint(colorEnabled);
|
|
2038
2210
|
return {
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2211
|
+
get width() {
|
|
2212
|
+
return availableWidth(stderr);
|
|
2213
|
+
},
|
|
2214
|
+
emphasize: (text) => paint("emphasis", text),
|
|
2215
|
+
dim: (text) => paint("muted", text),
|
|
2216
|
+
code: (text) => `\`${text}\``,
|
|
2217
|
+
tone: paint
|
|
2042
2218
|
};
|
|
2043
2219
|
}
|
|
2044
2220
|
/** Materializes ONLY the active format's presentation functions, at the
|
|
@@ -2059,7 +2235,7 @@ function materializePresentation(state, ui, presentations) {
|
|
|
2059
2235
|
}
|
|
2060
2236
|
function makeContext(invocation, def, config, managesCredentials) {
|
|
2061
2237
|
const state = invocation.state;
|
|
2062
|
-
const ui = makeUi(state.colorEnabled);
|
|
2238
|
+
const ui = makeUi(state.colorEnabled, invocation.runtime.stderr);
|
|
2063
2239
|
const present = (outcome, presentations) => {
|
|
2064
2240
|
if (state.delegatedTerminal !== void 0) throw constructionError(`command '${state.commandId}' called ctx.present while a child owned the terminal`);
|
|
2065
2241
|
const exitCode = outcome.exitCode ?? 0;
|
|
@@ -2083,6 +2259,7 @@ function makeContext(invocation, def, config, managesCredentials) {
|
|
|
2083
2259
|
return api;
|
|
2084
2260
|
},
|
|
2085
2261
|
spawn: makeSpawn(invocation, def),
|
|
2262
|
+
lastChild: () => state.lastChild,
|
|
2086
2263
|
report: (event) => reportEvent(invocation, event),
|
|
2087
2264
|
prompt: makePromptSurface(invocation),
|
|
2088
2265
|
openUrl: (request) => announceUrl(invocation, request),
|
|
@@ -2478,20 +2655,23 @@ function settleVerbatimExitCode(invocation, exitCode) {
|
|
|
2478
2655
|
* never documented, because the code is not the handler's own
|
|
2479
2656
|
* conclusion, it is the child's.
|
|
2480
2657
|
*
|
|
2481
|
-
*
|
|
2658
|
+
* The status comes from the engine's own record of the child, never
|
|
2659
|
+
* from the handler, so there is nothing here for a handler to state.
|
|
2660
|
+
* Two conditions fence it, both construction errors: the command must
|
|
2482
2661
|
* hand the terminal to another program — reachable from a
|
|
2483
2662
|
* non-declaring handler this would also end a json stream without its
|
|
2484
|
-
* terminal result frame
|
|
2485
|
-
*
|
|
2486
|
-
*
|
|
2487
|
-
*
|
|
2488
|
-
*
|
|
2663
|
+
* terminal result frame — and a child must actually have run.
|
|
2664
|
+
*
|
|
2665
|
+
* A signal-killed child overrules whatever the handler asked for. The
|
|
2666
|
+
* user stopped the run: it settles 128 + the signal number, with no
|
|
2667
|
+
* envelope and no next actions, because there is nothing to reproduce.
|
|
2489
2668
|
*/
|
|
2490
2669
|
function settleChildStatus(invocation, def, settlement) {
|
|
2491
2670
|
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
|
-
|
|
2671
|
+
const child = invocation.state.lastChild;
|
|
2672
|
+
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`);
|
|
2673
|
+
if (child.signal === null) for (const action of settlement.nextActions) invocation.runtime.stderr.write(`${renderNextAction(action)}\n`);
|
|
2674
|
+
settleVerbatimExitCode(invocation, childExitCode(child));
|
|
2495
2675
|
}
|
|
2496
2676
|
/** A session command that returned ok shut down cleanly: no
|
|
2497
2677
|
* presentation, and exit 0 — unless a signal ended the run, which
|
|
@@ -2699,6 +2879,7 @@ var EngineImpl = class {
|
|
|
2699
2879
|
unresolvedFlagNames: [],
|
|
2700
2880
|
snapshot: void 0,
|
|
2701
2881
|
delegatedTerminal: void 0,
|
|
2882
|
+
lastChild: void 0,
|
|
2702
2883
|
activePrompts: 0,
|
|
2703
2884
|
deliveredSignal: void 0,
|
|
2704
2885
|
pendingForceExit: void 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/cli-engine",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "The execution engine of the unified Prisma CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -49,7 +49,9 @@
|
|
|
49
49
|
"@clack/prompts": "1.5.0",
|
|
50
50
|
"@prisma/management-api-sdk": "1.55.0",
|
|
51
51
|
"@stricli/core": "1.3.0",
|
|
52
|
-
"c12": "3.3.4"
|
|
52
|
+
"c12": "3.3.4",
|
|
53
|
+
"colorette": "^2.0.20",
|
|
54
|
+
"string-width": "^8.2.1"
|
|
53
55
|
},
|
|
54
56
|
"devDependencies": {
|
|
55
57
|
"@repo/tsconfig": "workspace:8.0.0-rc.1",
|