@prisma/cli-engine 0.0.3 → 0.0.6
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 +19 -13
- package/dist/index.js +12 -123
- package/dist/{run-summary-DMFNIvjx.d.ts → run-summary-CNL0TNZu.d.ts} +78 -14
- package/dist/testing.d.ts +9 -1
- package/dist/testing.js +7 -6
- package/dist/{token-claims-DXO0q52l.js → token-claims-B6V7E0NS.js} +637 -93
- package/package.json +3 -2
|
@@ -1,7 +1,8 @@
|
|
|
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";
|
|
4
|
-
import {
|
|
3
|
+
import { FlagNotFoundError, buildApplication, buildCommand, buildRouteMap, run, text_en } from "@stricli/core";
|
|
4
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
5
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
6
|
import { Readable, Writable } from "node:stream";
|
|
6
7
|
import { Buffer } from "node:buffer";
|
|
7
8
|
//#region src/args.ts
|
|
@@ -94,9 +95,37 @@ const positional = {
|
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
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
|
+
}
|
|
97
106
|
//#endregion
|
|
98
107
|
//#region src/spawn.ts
|
|
99
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
|
+
}
|
|
100
129
|
/** Signal numbers shared by Linux, macOS and the BSDs. Numbers that
|
|
101
130
|
* differ by platform (SIGBUS, SIGUSR1, SIGUSR2, …) are deliberately
|
|
102
131
|
* absent — a wrong 128+n is worse than the unknown-signal fallback. */
|
|
@@ -118,21 +147,22 @@ const SIGNAL_NUMBERS = {
|
|
|
118
147
|
* child's own exit code, verbatim. Unknown is never success: a signal
|
|
119
148
|
* outside the portable table, or an adapter that cannot say how the
|
|
120
149
|
* child ended (exitCode and signal both null), settles 1. */
|
|
150
|
+
function childExitCode(child) {
|
|
151
|
+
if (child.signal === null) return child.exitCode ?? 1;
|
|
152
|
+
const signalNumber = SIGNAL_NUMBERS[child.signal];
|
|
153
|
+
return signalNumber === void 0 ? 1 : 128 + signalNumber;
|
|
154
|
+
}
|
|
155
|
+
/** Settles the run with the status of the child `ctx.spawn` returned.
|
|
156
|
+
* A result the engine did not produce is a construction error at
|
|
157
|
+
* settlement: this is how a real child's status reaches the exit code,
|
|
158
|
+
* not how a handler picks one. */
|
|
121
159
|
function exitWithChildStatus(child, options) {
|
|
122
|
-
const
|
|
123
|
-
if (child.signal !== null) {
|
|
124
|
-
const signalNumber = SIGNAL_NUMBERS[child.signal];
|
|
125
|
-
return Object.freeze({
|
|
126
|
-
[CHILD_STATUS]: true,
|
|
127
|
-
exitCode: signalNumber === void 0 ? 1 : 128 + signalNumber,
|
|
128
|
-
nextActions
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
return Object.freeze({
|
|
160
|
+
const settlement = {
|
|
132
161
|
[CHILD_STATUS]: true,
|
|
133
|
-
exitCode: child
|
|
134
|
-
nextActions
|
|
135
|
-
}
|
|
162
|
+
exitCode: childExitCode(child),
|
|
163
|
+
nextActions: Object.freeze([...options?.nextActions ?? []])
|
|
164
|
+
};
|
|
165
|
+
return isEngineSpawned(child) ? markEngineSpawned(settlement) : Object.freeze(settlement);
|
|
136
166
|
}
|
|
137
167
|
function isChildStatusSettlement(value) {
|
|
138
168
|
return typeof value === "object" && value !== null && value[CHILD_STATUS] === true;
|
|
@@ -257,6 +287,14 @@ function serviceTokenRejectedError(spec) {
|
|
|
257
287
|
}] });
|
|
258
288
|
}
|
|
259
289
|
//#endregion
|
|
290
|
+
//#region src/credential-manager.ts
|
|
291
|
+
/** The environment variables that supply a credential to a process: a
|
|
292
|
+
* service token, plus the workspace it acts in when the token's own
|
|
293
|
+
* claims name none. EnvironmentCredentialManager reads the pair; the
|
|
294
|
+
* spawn path writes it into a child's environment. */
|
|
295
|
+
const SERVICE_TOKEN_ENV_VAR = "PRISMA_SERVICE_TOKEN";
|
|
296
|
+
const WORKSPACE_ID_ENV_VAR = "PRISMA_WORKSPACE_ID";
|
|
297
|
+
//#endregion
|
|
260
298
|
//#region src/execution/debug.ts
|
|
261
299
|
const DEBUG_ENV_VAR = "PRISMA_NEXT_DEBUG";
|
|
262
300
|
/**
|
|
@@ -272,7 +310,6 @@ function makeDebugLog(runtime) {
|
|
|
272
310
|
}
|
|
273
311
|
//#endregion
|
|
274
312
|
//#region src/execution/api-client.ts
|
|
275
|
-
const SERVICE_TOKEN_ENV_VAR$1 = "PRISMA_SERVICE_TOKEN";
|
|
276
313
|
/**
|
|
277
314
|
* ctx.api: the ENGINE constructs and owns the management API client —
|
|
278
315
|
* ONE client for the active credential, once per run (process pinning
|
|
@@ -393,8 +430,8 @@ async function mapRequestFailure(invocation, debug, probe, pinned, cause) {
|
|
|
393
430
|
const manager = invocation.runtime.credentialManager;
|
|
394
431
|
if (manager === void 0 || pinned === void 0) return authError.refreshTokenInvalid === true ? credentialsRequiredError("expired") : authServiceError();
|
|
395
432
|
const homeRecord = hasHomeRecord(pinned.active);
|
|
396
|
-
if (authError.refreshTokenInvalid === true) return homeRecord ? credentialsRequiredError("expired") : credentialRejectedError(pinned.active.origin, SERVICE_TOKEN_ENV_VAR
|
|
397
|
-
if (cameFromRefresh && await couldNeverHaveBeenRenewed(pinned.storage)) return credentialRejectedError(pinned.active.origin, SERVICE_TOKEN_ENV_VAR
|
|
433
|
+
if (authError.refreshTokenInvalid === true) return homeRecord ? credentialsRequiredError("expired") : credentialRejectedError(pinned.active.origin, SERVICE_TOKEN_ENV_VAR);
|
|
434
|
+
if (cameFromRefresh && await couldNeverHaveBeenRenewed(pinned.storage)) return credentialRejectedError(pinned.active.origin, SERVICE_TOKEN_ENV_VAR);
|
|
398
435
|
return homeRecord ? mapAgainstStoredState(manager, pinned.active, cause) : authServiceError();
|
|
399
436
|
}
|
|
400
437
|
/** Whether this credential is backed by a stored session. The origin
|
|
@@ -474,6 +511,277 @@ function endpointVerdict(message) {
|
|
|
474
511
|
return description === -1 ? message : message.slice(0, description);
|
|
475
512
|
}
|
|
476
513
|
//#endregion
|
|
514
|
+
//#region src/runtime.ts
|
|
515
|
+
/**
|
|
516
|
+
* The config contract version defineConfig writes as the structural
|
|
517
|
+
* `$prismaConfig` marker; the loader checks it before interpreting
|
|
518
|
+
* anything.
|
|
519
|
+
*/
|
|
520
|
+
const PRISMA_CONFIG_VERSION = 1;
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/config-loader.ts
|
|
523
|
+
/**
|
|
524
|
+
* The prisma.config.ts loader behind Runtime.loadConfig: resolve the
|
|
525
|
+
* file (the one `--config` named, otherwise prisma.config.ts in cwd —
|
|
526
|
+
* cwd only, no walking up), evaluate it, check the defineConfig version
|
|
527
|
+
* marker, and produce LoadedConfig.
|
|
528
|
+
*
|
|
529
|
+
* Which section names a CLI recognises is not this module's business:
|
|
530
|
+
* it hands back every top-level key the file had, and the engine — not
|
|
531
|
+
* a Runtime member a host can replace — checks them against the
|
|
532
|
+
* sections the mounted commands declare.
|
|
533
|
+
*
|
|
534
|
+
* Absence of an undiscovered file is not an error: section validators
|
|
535
|
+
* own absence, so no prisma.config.ts in cwd yields no sections and no
|
|
536
|
+
* diagnostics.
|
|
537
|
+
* Absence of a file the user NAMED with --config is an error — they
|
|
538
|
+
* said which file to read and it was not there. An evaluated file
|
|
539
|
+
* WITHOUT the marker (a classic Prisma 7 config, which uses the same
|
|
540
|
+
* filename) fails early with one typed diagnostic — the loader never
|
|
541
|
+
* partially interprets an unmarked file, and never guesses.
|
|
542
|
+
*
|
|
543
|
+
* Evaluation goes through c12, the same loader prisma/prisma and
|
|
544
|
+
* prisma/composer use, because the shipped CLI runs on ordinary Node,
|
|
545
|
+
* which cannot import a .ts file. c12 transpiles it with jiti first.
|
|
546
|
+
* Every c12 feature beyond "evaluate this one file" is switched off
|
|
547
|
+
* below so discovery and merging stay exactly as they were.
|
|
548
|
+
*/
|
|
549
|
+
const CONFIG_FILE_NAME = "prisma.config.ts";
|
|
550
|
+
const MARKER_KEY = "$prismaConfig";
|
|
551
|
+
/**
|
|
552
|
+
* Top-level keys the config file format keeps for itself, so no
|
|
553
|
+
* section may be named one of them; buildCommandTree rejects the
|
|
554
|
+
* declaration at construction.
|
|
555
|
+
*
|
|
556
|
+
* `$`-prefixed keys are metadata: `$prismaConfig` is the version
|
|
557
|
+
* marker, and config loaders read `$env`, `$<NODE_ENV>` and `$meta` —
|
|
558
|
+
* c12 deletes `$meta` from the config object whatever else it is told.
|
|
559
|
+
* `extends` is the key config loaders take as "merge another file into
|
|
560
|
+
* this one". This loader switches that off (`extend: false`), so a key
|
|
561
|
+
* by that name does reach the config object. It stays reserved anyway:
|
|
562
|
+
* the file format has no layering of its own, `extends` is the name it
|
|
563
|
+
* would want if it gained some, and a section called `extends` would
|
|
564
|
+
* disappear the moment anything switched merging back on.
|
|
565
|
+
*
|
|
566
|
+
* `__proto__` is reserved for the reason `$meta` is: c12 merges layers
|
|
567
|
+
* with defu, which drops the key rather than let a config file reach an
|
|
568
|
+
* object's prototype, so a section by that name could never be read.
|
|
569
|
+
*/
|
|
570
|
+
function reservedConfigSectionName(name) {
|
|
571
|
+
return name === "extends" || name === "__proto__" || name.startsWith("$");
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Attaches the version marker to a prisma.config.ts export. Each
|
|
575
|
+
* top-level key names a config section, and the recognised section
|
|
576
|
+
* names are exactly the ones the CLI's command families declare. Never
|
|
577
|
+
* throws — bad section values are the section validator's problem, not
|
|
578
|
+
* defineConfig's.
|
|
579
|
+
*/
|
|
580
|
+
function defineConfig(config) {
|
|
581
|
+
return Object.freeze({
|
|
582
|
+
...config,
|
|
583
|
+
$prismaConfig: 1
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
function hasVersionMarker(value) {
|
|
587
|
+
return typeof value === "object" && value !== null && typeof value[MARKER_KEY] === "number";
|
|
588
|
+
}
|
|
589
|
+
function fileLevelConfig(path, diagnostic) {
|
|
590
|
+
return {
|
|
591
|
+
path,
|
|
592
|
+
sections: {},
|
|
593
|
+
diagnostics: [{
|
|
594
|
+
section: null,
|
|
595
|
+
diagnostic
|
|
596
|
+
}]
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
function missingMarkerDiagnostic(path) {
|
|
600
|
+
return {
|
|
601
|
+
code: "CLI.CONFIG_MISSING_MARKER",
|
|
602
|
+
severity: "error",
|
|
603
|
+
summary: `${path} was not written for this version of the Prisma CLI, so it cannot be used.`,
|
|
604
|
+
why: "Configs for this CLI are created with defineConfig, which records a version marker on the exported object. This file's default export has no marker — it is most likely a Prisma 7 config, which uses the same filename — and the CLI stops rather than misread it.",
|
|
605
|
+
nextActions: [{
|
|
606
|
+
kind: "user-choice",
|
|
607
|
+
label: "Migrate the file: wrap the exported object in defineConfig from @prisma/cli-engine and export the result as the default export."
|
|
608
|
+
}],
|
|
609
|
+
where: { path }
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
function firstLine$1(text) {
|
|
613
|
+
const newline = text.indexOf("\n");
|
|
614
|
+
return (newline === -1 ? text : text.slice(0, newline)).trim();
|
|
615
|
+
}
|
|
616
|
+
function unsupportedVersionDiagnostic(path, found) {
|
|
617
|
+
return {
|
|
618
|
+
code: "CLI.CONFIG_VERSION_UNSUPPORTED",
|
|
619
|
+
severity: "error",
|
|
620
|
+
summary: `${path} declares config version ${found}, but this CLI supports only version 1.`,
|
|
621
|
+
nextActions: [{
|
|
622
|
+
kind: "user-choice",
|
|
623
|
+
label: "Regenerate the config with a defineConfig matching this CLI, or update the CLI to a version that supports the declared config version."
|
|
624
|
+
}],
|
|
625
|
+
where: { path }
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function missingNamedFileDiagnostic(path) {
|
|
629
|
+
return {
|
|
630
|
+
code: "CLI.CONFIG_NOT_FOUND",
|
|
631
|
+
severity: "error",
|
|
632
|
+
summary: `--config named ${path}, and there is no file there.`,
|
|
633
|
+
why: "A config file found by discovery may be absent — the section validators supply their defaults. A config file named on the command line may not: the CLI would otherwise run against different settings than the ones asked for.",
|
|
634
|
+
nextActions: [{
|
|
635
|
+
kind: "user-choice",
|
|
636
|
+
label: "Correct the path passed to --config, or drop the flag to use the prisma.config.ts in the current directory."
|
|
637
|
+
}],
|
|
638
|
+
where: { path }
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
function unreadableDiagnostic(path, cause) {
|
|
642
|
+
return {
|
|
643
|
+
code: "CLI.CONFIG_UNREADABLE",
|
|
644
|
+
severity: "error",
|
|
645
|
+
summary: `${path} could not be evaluated: ${firstLine$1(cause instanceof Error ? cause.message : String(cause))}`,
|
|
646
|
+
nextActions: [{
|
|
647
|
+
kind: "user-choice",
|
|
648
|
+
label: "Fix the error in the file, then run the command again."
|
|
649
|
+
}],
|
|
650
|
+
where: { path }
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Everything c12 does beyond evaluating the one file it was handed.
|
|
655
|
+
* Composer leaves the last five at their defaults and can afford to:
|
|
656
|
+
* its config has a fixed set of keys, where every top-level key here is
|
|
657
|
+
* a user-authored section name, so all five are reachable from an
|
|
658
|
+
* ordinary config file.
|
|
659
|
+
*/
|
|
660
|
+
const EVALUATE_ONE_FILE_ONLY = {
|
|
661
|
+
rcFile: false,
|
|
662
|
+
globalRc: false,
|
|
663
|
+
packageJson: false,
|
|
664
|
+
/** Else `$production` blocks merge over the root under NODE_ENV. */
|
|
665
|
+
envName: false,
|
|
666
|
+
/** Else `$prismaConfig` is stripped and every config reads unmarked. */
|
|
667
|
+
omit$Keys: false,
|
|
668
|
+
/** Else `extends` is a merge directive rather than a section name. */
|
|
669
|
+
extend: false,
|
|
670
|
+
/** Else an `extends` URL is fetched over the network and evaluated. */
|
|
671
|
+
giget: false,
|
|
672
|
+
/** Else a neighbouring .env is read into process.env. */
|
|
673
|
+
dotenv: false
|
|
674
|
+
};
|
|
675
|
+
/**
|
|
676
|
+
* Evaluates the file at `path` and returns its default export. The call
|
|
677
|
+
* is prisma/composer's `loadAppConfig` with prisma/prisma's dynamic
|
|
678
|
+
* import, so a run with no config file never pays for c12 or jiti.
|
|
679
|
+
*
|
|
680
|
+
* The loaded-file check is in both references: c12 is asked for one
|
|
681
|
+
* exact path and must not answer with another.
|
|
682
|
+
*/
|
|
683
|
+
async function evaluateConfigFile(path) {
|
|
684
|
+
const result = await (await import("c12")).loadConfig({
|
|
685
|
+
name: "prisma",
|
|
686
|
+
configFile: path,
|
|
687
|
+
cwd: dirname(path),
|
|
688
|
+
...EVALUATE_ONE_FILE_ONLY
|
|
689
|
+
});
|
|
690
|
+
const loadedFile = result.configFile;
|
|
691
|
+
if (typeof loadedFile !== "string" || realpathSync(loadedFile) !== realpathSync(path)) throw new Error(`config loading resolved ${String(loadedFile)} instead of ${path}`);
|
|
692
|
+
return result.config;
|
|
693
|
+
}
|
|
694
|
+
/** Built with fromEntries rather than assigned key by key: assigning a
|
|
695
|
+
* key named `__proto__` runs Object.prototype's setter instead of
|
|
696
|
+
* creating an own property, so that one key would disappear from
|
|
697
|
+
* Object.keys and never be reported as unrecognised. */
|
|
698
|
+
function sectionsOf(exported) {
|
|
699
|
+
return Object.fromEntries(Object.entries(exported).filter(([key]) => key !== MARKER_KEY));
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* The file to read, always absolute: the one --config named, resolved
|
|
703
|
+
* against cwd, or prisma.config.ts in cwd.
|
|
704
|
+
*
|
|
705
|
+
* Absolute is not cosmetic, and it is one more thing than either
|
|
706
|
+
* reference repository does — both are handed an absolute path before
|
|
707
|
+
* they reach c12, so neither has to resolve one. Given a relative path,
|
|
708
|
+
* c12 resolves it a second time against its own cwd and looks for a
|
|
709
|
+
* file that is not there, and jiti cannot import a relative specifier
|
|
710
|
+
* at all. Resolving here also makes the file's path in every diagnostic
|
|
711
|
+
* absolute, and makes the loaded-file comparison compare like with
|
|
712
|
+
* like.
|
|
713
|
+
*/
|
|
714
|
+
function fileToRead(cwd, configPath) {
|
|
715
|
+
const root = resolve(cwd);
|
|
716
|
+
return configPath === void 0 ? join(root, CONFIG_FILE_NAME) : resolve(root, configPath);
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* The real-disk loader behind Runtime.loadConfig. The bin binds it to
|
|
720
|
+
* the process cwd; tests hand in fixtures.
|
|
721
|
+
*/
|
|
722
|
+
async function loadConfig(cwd, configPath) {
|
|
723
|
+
const path = fileToRead(cwd, configPath);
|
|
724
|
+
if (!existsSync(path)) return configPath === void 0 ? {
|
|
725
|
+
path,
|
|
726
|
+
sections: {},
|
|
727
|
+
diagnostics: []
|
|
728
|
+
} : fileLevelConfig(path, missingNamedFileDiagnostic(path));
|
|
729
|
+
let exported;
|
|
730
|
+
try {
|
|
731
|
+
exported = await evaluateConfigFile(path);
|
|
732
|
+
} catch (cause) {
|
|
733
|
+
return fileLevelConfig(path, unreadableDiagnostic(path, cause));
|
|
734
|
+
}
|
|
735
|
+
if (!hasVersionMarker(exported)) return fileLevelConfig(path, missingMarkerDiagnostic(path));
|
|
736
|
+
const version = exported[MARKER_KEY];
|
|
737
|
+
if (version !== 1) return fileLevelConfig(path, unsupportedVersionDiagnostic(path, version));
|
|
738
|
+
return {
|
|
739
|
+
path,
|
|
740
|
+
sections: sectionsOf(exported),
|
|
741
|
+
diagnostics: []
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
//#endregion
|
|
745
|
+
//#region src/execution/pre-parse-argv.ts
|
|
746
|
+
function flagTokens(argv) {
|
|
747
|
+
const terminator = argv.indexOf("--");
|
|
748
|
+
return terminator === -1 ? argv : argv.slice(0, terminator);
|
|
749
|
+
}
|
|
750
|
+
function versionFlagGiven(argv) {
|
|
751
|
+
return flagTokens(argv).includes("--version");
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* The one malformed `--config` shape the parser cannot see. stricli
|
|
755
|
+
* matches a flag-with-value against `/^--([a-z][a-z-.\d_]+)=(.+)$/`,
|
|
756
|
+
* which needs at least one character after the `=`, so the bare token
|
|
757
|
+
* `--config=` is not a flag to it at all and falls through to the
|
|
758
|
+
* command's positional arguments. prisma/prisma rejects that shape as a
|
|
759
|
+
* usage error (a user who wrote `--config=` meant to name a file), so
|
|
760
|
+
* the engine checks for the exact token before handing argv over.
|
|
761
|
+
*
|
|
762
|
+
* Running before parsing, this cannot tell a flag from data: it rejects
|
|
763
|
+
* `--config=` wherever it appears ahead of a bare `--`, including as
|
|
764
|
+
* another flag's value or a positional. prisma/prisma's scan does the
|
|
765
|
+
* same and does not stop at `--`; the token is an odd one to need as
|
|
766
|
+
* data, and `--` remains the way to pass it.
|
|
767
|
+
*/
|
|
768
|
+
function configFlagGivenNoValue(argv) {
|
|
769
|
+
return flagTokens(argv).includes("--config=");
|
|
770
|
+
}
|
|
771
|
+
/** The format requested by --json / --format / --format=<value>, if
|
|
772
|
+
* any. */
|
|
773
|
+
function formatFlagGiven(argv) {
|
|
774
|
+
const tokens = flagTokens(argv);
|
|
775
|
+
for (const [index, token] of tokens.entries()) {
|
|
776
|
+
if (token === "--json" || token === "--format=json") return "json";
|
|
777
|
+
if (token === "--format=human") return "human";
|
|
778
|
+
if (token === "--format") {
|
|
779
|
+
const value = tokens[index + 1];
|
|
780
|
+
if (value === "json" || value === "human") return value;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
//#endregion
|
|
477
785
|
//#region src/execution/shared-flags.ts
|
|
478
786
|
/** The engine-injected shared flag family. Commands cannot declare
|
|
479
787
|
* these names or aliases; handlers never see their values. */
|
|
@@ -487,6 +795,7 @@ const RESERVED_FLAG_NAMES = new Set([
|
|
|
487
795
|
"confirm",
|
|
488
796
|
"interactive",
|
|
489
797
|
"color",
|
|
798
|
+
"config",
|
|
490
799
|
"help",
|
|
491
800
|
"helpAll",
|
|
492
801
|
"version"
|
|
@@ -554,8 +863,33 @@ const SHARED_FLAG_PARAMETERS = {
|
|
|
554
863
|
optional: true,
|
|
555
864
|
withNegated: true,
|
|
556
865
|
brief: "Force ANSI color on or off"
|
|
866
|
+
},
|
|
867
|
+
config: {
|
|
868
|
+
kind: "parsed",
|
|
869
|
+
parse: parseConfigPath,
|
|
870
|
+
placeholder: "path",
|
|
871
|
+
optional: true,
|
|
872
|
+
brief: "Read this config file instead of ./prisma.config.ts"
|
|
557
873
|
}
|
|
558
874
|
};
|
|
875
|
+
/** Rejects `--config ""`, which a shell produces from
|
|
876
|
+
* `--config "$UNSET_VAR"`. prisma/prisma treats the empty value as a
|
|
877
|
+
* usage error rather than letting it reach the loader as an empty
|
|
878
|
+
* path, and so does this: the parser turns the throw into the run's
|
|
879
|
+
* usage error. */
|
|
880
|
+
function parseConfigPath(input) {
|
|
881
|
+
if (input === "") throw new Error("--config needs a path, and was given an empty value");
|
|
882
|
+
return input;
|
|
883
|
+
}
|
|
884
|
+
function configFlagGivenNoValueError() {
|
|
885
|
+
return new CliStructuredError("CLI.INVALID_ARGUMENTS", "--config needs a path, and was given an empty value", {
|
|
886
|
+
why: "`--config=` binds the flag to an empty value.",
|
|
887
|
+
nextActions: [{
|
|
888
|
+
kind: "user-choice",
|
|
889
|
+
label: "Pass a config path: --config <path> or --config=<path>."
|
|
890
|
+
}]
|
|
891
|
+
});
|
|
892
|
+
}
|
|
559
893
|
const SHARED_ALIASES = {
|
|
560
894
|
v: "verbose",
|
|
561
895
|
q: "quiet",
|
|
@@ -563,22 +897,9 @@ const SHARED_ALIASES = {
|
|
|
563
897
|
};
|
|
564
898
|
/** The pre-parse format decision: json framing must be in effect before
|
|
565
899
|
* stricli parses (its own failure output is framed too), so the format
|
|
566
|
-
* flags are
|
|
900
|
+
* flags are read from raw argv and a TTY stdout decides the rest. */
|
|
567
901
|
function sniffFormat(argv, runtime) {
|
|
568
|
-
return
|
|
569
|
-
}
|
|
570
|
-
/** The format requested by --json / --format / --format=<value>, if
|
|
571
|
-
* any. Arguments after a bare `--` are positionals, never flags. */
|
|
572
|
-
function explicitFormat(argv) {
|
|
573
|
-
for (const [index, argument] of argv.entries()) {
|
|
574
|
-
if (argument === "--") return;
|
|
575
|
-
if (argument === "--json" || argument === "--format=json") return "json";
|
|
576
|
-
if (argument === "--format=human") return "human";
|
|
577
|
-
if (argument === "--format") {
|
|
578
|
-
const value = argv[index + 1];
|
|
579
|
-
if (value === "json" || value === "human") return value;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
902
|
+
return formatFlagGiven(argv) ?? (runtime.isTty.stdout ? "human" : "json");
|
|
582
903
|
}
|
|
583
904
|
function applySharedFlags(state, shared, runtime) {
|
|
584
905
|
state.format = shared.format ?? resolveAutoFormat(shared, runtime);
|
|
@@ -587,6 +908,7 @@ function applySharedFlags(state, shared, runtime) {
|
|
|
587
908
|
state.interactive = shared.interactive ?? defaultInteractive(runtime);
|
|
588
909
|
state.logLevel = resolveLogLevel(shared);
|
|
589
910
|
state.colorEnabled = shared.color ?? (runtime.isTty.stdout && runtime.env.NO_COLOR === void 0);
|
|
911
|
+
state.configPath = shared.config;
|
|
590
912
|
}
|
|
591
913
|
/** Interactive iff TTY stdin outside CI; --interactive and
|
|
592
914
|
* --no-interactive override in either direction. Format never decides
|
|
@@ -687,6 +1009,22 @@ function validateSectionOwnership(spec, path, def) {
|
|
|
687
1009
|
if (commandFamily === void 0) return;
|
|
688
1010
|
if (commandFamily.configSection !== section) throw constructionError(`command '${path}' needs the '${section.name}' config section, which is not its command family's section`);
|
|
689
1011
|
}
|
|
1012
|
+
/** The config file's top-level keys are the declared section names, so
|
|
1013
|
+
* a section may only be named something the file format leaves free:
|
|
1014
|
+
* not `$`-prefixed (those are metadata — $prismaConfig is the version
|
|
1015
|
+
* marker, and a $meta key is deleted before the loader ever sees it),
|
|
1016
|
+
* and not `extends` (the key config loaders take as an instruction to
|
|
1017
|
+
* merge another file in). Both the families and the commands mounted
|
|
1018
|
+
* without one are checked: whoever declares the section, claiming a
|
|
1019
|
+
* reserved name is broken at build time, not at a user's runtime. */
|
|
1020
|
+
function validateConfigSectionNames(spec) {
|
|
1021
|
+
for (const commandFamily of spec.commandFamilies) rejectReservedSectionName("command family", commandFamily.configSection);
|
|
1022
|
+
for (const [path, def] of Object.entries(spec.commands)) rejectReservedSectionName(`command '${path}'`, def.needs.config);
|
|
1023
|
+
}
|
|
1024
|
+
function rejectReservedSectionName(owner, section) {
|
|
1025
|
+
if (section === void 0 || !reservedConfigSectionName(section.name)) return;
|
|
1026
|
+
throw constructionError(`${owner} declares config section '${section.name}', a name the config file reserves ('extends' is a config loader's merge directive, and '$'-prefixed keys are metadata)`);
|
|
1027
|
+
}
|
|
690
1028
|
function validateDocsBaseUrls(spec) {
|
|
691
1029
|
for (const commandFamily of spec.commandFamilies) {
|
|
692
1030
|
const base = commandFamily.docsBaseUrl;
|
|
@@ -697,6 +1035,7 @@ function buildCommandTree(spec) {
|
|
|
697
1035
|
const paths = Object.keys(spec.commands);
|
|
698
1036
|
if (paths.length === 0) throw constructionError("createCli requires at least one mounted command");
|
|
699
1037
|
validateDocsBaseUrls(spec);
|
|
1038
|
+
validateConfigSectionNames(spec);
|
|
700
1039
|
const root = emptyNode();
|
|
701
1040
|
for (const path of paths) {
|
|
702
1041
|
const def = spec.commands[path];
|
|
@@ -714,6 +1053,64 @@ function buildCommandTree(spec) {
|
|
|
714
1053
|
}
|
|
715
1054
|
return root;
|
|
716
1055
|
}
|
|
1056
|
+
function flagRedirectKey(commandPath, flag) {
|
|
1057
|
+
return `${commandPath} --${flag}`;
|
|
1058
|
+
}
|
|
1059
|
+
/** Where a path sits in the mounted tree; a group is a path some
|
|
1060
|
+
* command mounts under. */
|
|
1061
|
+
function mountedAs(spec, path) {
|
|
1062
|
+
if (spec.commands[path] !== void 0) return "command";
|
|
1063
|
+
const groupPrefix = `${path} `;
|
|
1064
|
+
return Object.keys(spec.commands).some((mounted) => mounted.startsWith(groupPrefix)) ? "command group" : void 0;
|
|
1065
|
+
}
|
|
1066
|
+
/** Engine-injected shared flags count: a command answers them whether
|
|
1067
|
+
* or not it declared them, so a redirect for one could never fire. */
|
|
1068
|
+
function acceptsFlag(def, flag) {
|
|
1069
|
+
if (def.args.flags[flag] !== void 0) return true;
|
|
1070
|
+
return def.kind !== "server-command" && RESERVED_FLAG_NAMES.has(flag);
|
|
1071
|
+
}
|
|
1072
|
+
function addVerbRedirect(spec, table, redirect) {
|
|
1073
|
+
const mounted = mountedAs(spec, redirect.from);
|
|
1074
|
+
if (mounted !== void 0) throw constructionError(`redirect '${redirect.from}' collides with a mounted ${mounted}`);
|
|
1075
|
+
if (table.has(redirect.from)) throw constructionError(`redirect '${redirect.from}' is declared twice`);
|
|
1076
|
+
table.set(redirect.from, redirect);
|
|
1077
|
+
}
|
|
1078
|
+
function addFlagRedirect(spec, table, redirect, flag) {
|
|
1079
|
+
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)`);
|
|
1080
|
+
const def = spec.commands[redirect.from];
|
|
1081
|
+
if (def === void 0) throw constructionError(`redirect for flag '${flag}' names '${redirect.from}', which is not a mounted command`);
|
|
1082
|
+
if (acceptsFlag(def, flag)) throw constructionError(`redirect for flag '${flag}' on '${redirect.from}' names a flag that command still accepts`);
|
|
1083
|
+
const key = flagRedirectKey(redirect.from, flag);
|
|
1084
|
+
if (table.has(key)) throw constructionError(`redirect for flag '${flag}' on '${redirect.from}' is declared twice`);
|
|
1085
|
+
table.set(key, redirect);
|
|
1086
|
+
}
|
|
1087
|
+
function buildRedirectTable(spec) {
|
|
1088
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
1089
|
+
const byFlag = /* @__PURE__ */ new Map();
|
|
1090
|
+
for (const commandFamily of spec.commandFamilies) for (const redirect of commandFamily.redirects) if (redirect.flag === void 0) addVerbRedirect(spec, byPath, redirect);
|
|
1091
|
+
else addFlagRedirect(spec, byFlag, redirect, redirect.flag);
|
|
1092
|
+
return {
|
|
1093
|
+
byPath,
|
|
1094
|
+
byFlag
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
/** Longest match wins, since one retired path may prefix another.
|
|
1098
|
+
* Segments match exactly: a redirect is never a spelling suggestion. */
|
|
1099
|
+
function matchVerbRedirect(table, segments) {
|
|
1100
|
+
for (let length = segments.length; length > 0; length -= 1) {
|
|
1101
|
+
const redirect = table.byPath.get(segments.slice(0, length).join(" "));
|
|
1102
|
+
if (redirect !== void 0) return redirect;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
/** `typedFlags` are spelled as the user typed them, without the leading
|
|
1106
|
+
* dashes; the scanner accepts kebab for camel, so both spellings
|
|
1107
|
+
* resolve to the declared camelCase name. */
|
|
1108
|
+
function matchFlagRedirect(table, commandPath, typedFlags) {
|
|
1109
|
+
for (const typed of typedFlags) {
|
|
1110
|
+
const redirect = table.byFlag.get(flagRedirectKey(commandPath, camelCase(typed)));
|
|
1111
|
+
if (redirect !== void 0) return redirect;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
717
1114
|
//#endregion
|
|
718
1115
|
//#region src/execution/rendering.ts
|
|
719
1116
|
function firstLine(text) {
|
|
@@ -923,7 +1320,7 @@ async function checkNeeds(def, invocation) {
|
|
|
923
1320
|
const credentials = await checkCredentials(needs, invocation);
|
|
924
1321
|
if (credentials.failure !== void 0) return credentials.failure;
|
|
925
1322
|
if (needs.config !== void 0) {
|
|
926
|
-
const outcome = checkConfiguration(needs.config, invocation);
|
|
1323
|
+
const outcome = await checkConfiguration(needs.config, invocation);
|
|
927
1324
|
return outcome.kind === "ok" ? {
|
|
928
1325
|
...outcome,
|
|
929
1326
|
spawnCredential: credentials.spawnCredential
|
|
@@ -983,16 +1380,52 @@ function nearExpiryFailure(credential, invocation) {
|
|
|
983
1380
|
if (credential.expiresAt.getTime() - invocation.now().getTime() > 3e5) return;
|
|
984
1381
|
return needsErrored(credentialsRequiredError("expiring-soon"));
|
|
985
1382
|
}
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1383
|
+
/**
|
|
1384
|
+
* A top-level key in the config file that is not one of the sections
|
|
1385
|
+
* the mounted commands and command families declare. The set is closed,
|
|
1386
|
+
* so an unrecognised key is a typo or a leftover, and staying silent
|
|
1387
|
+
* would mean quietly ignoring settings the user wrote.
|
|
1388
|
+
*
|
|
1389
|
+
* The check is the engine's rather than the loader's because the loader
|
|
1390
|
+
* is a Runtime member a host supplies: a check on the far side of that
|
|
1391
|
+
* seam holds only for as long as every host writes one.
|
|
1392
|
+
*/
|
|
1393
|
+
function unknownSectionDiagnostic(path, key, configSections) {
|
|
1394
|
+
return {
|
|
1395
|
+
code: "CLI.CONFIG_UNKNOWN_SECTION",
|
|
1396
|
+
severity: "error",
|
|
1397
|
+
summary: `${path} has a top-level key '${key}', which is not a config section this CLI recognises.`,
|
|
1398
|
+
why: `The sections this CLI recognises are: ${[...configSections].sort().join(", ")}.`,
|
|
1399
|
+
nextActions: [{
|
|
1400
|
+
kind: "user-choice",
|
|
1401
|
+
label: "Remove the key, or rename it to one of the recognised section names."
|
|
1402
|
+
}],
|
|
1403
|
+
where: { path }
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
function unknownSections(loaded, configSections) {
|
|
1407
|
+
const declared = new Set(configSections);
|
|
1408
|
+
return Object.keys(loaded.sections).filter((key) => !declared.has(key)).map((key) => unknownSectionDiagnostic(loaded.path, key, configSections));
|
|
1409
|
+
}
|
|
1410
|
+
/** The config file is read HERE and nowhere else, so a command with no
|
|
1411
|
+
* needs.config never touches it. The file `--config` named travels on
|
|
1412
|
+
* the run state; the closed set of section names comes from the
|
|
1413
|
+
* mounted command families, and every key outside it is reported here
|
|
1414
|
+
* whatever the loader did or did not check. */
|
|
1415
|
+
async function checkConfiguration(section, invocation) {
|
|
1416
|
+
const configPath = invocation.state.configPath;
|
|
1417
|
+
const loaded = await invocation.runtime.loadConfig(configPath);
|
|
1418
|
+
const fileLevel = [...loaded.diagnostics.filter((entry) => entry.section === null).map((entry) => entry.diagnostic), ...unknownSections(loaded, invocation.configSections)];
|
|
1419
|
+
if (fileLevel.length > 0) return needsErrored(structuredErrorFromDiagnostic(fileLevel[0]), fileLevel.slice(1));
|
|
1420
|
+
return validateConfigSection(section, loaded, invocation, configPath ?? "prisma.config.ts");
|
|
990
1421
|
}
|
|
991
1422
|
/** Validates the command's needed config section. The validator
|
|
992
1423
|
* owns absence (it receives undefined when the section is missing) and
|
|
993
|
-
* never throws — a throw is an engine-boundary bug, settled as one.
|
|
994
|
-
|
|
995
|
-
|
|
1424
|
+
* never throws — a throw is an engine-boundary bug, settled as one.
|
|
1425
|
+
* `configFile` is named in the error so a run under --config points at
|
|
1426
|
+
* the file it actually read. */
|
|
1427
|
+
function validateConfigSection(section, loaded, invocation, configFile) {
|
|
1428
|
+
const raw = loaded.sections[section.name];
|
|
996
1429
|
let validation;
|
|
997
1430
|
try {
|
|
998
1431
|
validation = section.validate(raw);
|
|
@@ -1002,7 +1435,7 @@ function validateConfigSection(section, invocation) {
|
|
|
1002
1435
|
cause: new Error(`@prisma/cli-engine: the '${section.name}' config section validator threw instead of returning diagnostics (a validator never throws)`, { cause })
|
|
1003
1436
|
};
|
|
1004
1437
|
}
|
|
1005
|
-
if (!validation.ok) return needsErrored(new CliStructuredError("CLI.
|
|
1438
|
+
if (!validation.ok) return needsErrored(new CliStructuredError("CLI.CONFIG_SECTION_INVALID", `The '${section.name}' section of ${configFile} is invalid.`, { nextActions: [{
|
|
1006
1439
|
kind: "user-choice",
|
|
1007
1440
|
label: "Fix the reported problems in that section, then run the command again."
|
|
1008
1441
|
}] }), validation.diagnostics);
|
|
@@ -1429,8 +1862,6 @@ function makePromptSurface(invocation) {
|
|
|
1429
1862
|
}
|
|
1430
1863
|
//#endregion
|
|
1431
1864
|
//#region src/execution/spawn.ts
|
|
1432
|
-
const SERVICE_TOKEN_ENV_VAR = "PRISMA_SERVICE_TOKEN";
|
|
1433
|
-
const WORKSPACE_ID_ENV_VAR = "PRISMA_WORKSPACE_ID";
|
|
1434
1865
|
/**
|
|
1435
1866
|
* D1 ruling (S3): how long a child terminated by a programmatic abort
|
|
1436
1867
|
* has to exit on its own after SIGTERM before the engine sends SIGKILL.
|
|
@@ -1511,7 +1942,7 @@ async function runChild(invocation, terminal, spawnChild, request) {
|
|
|
1511
1942
|
const ended = new AbortController();
|
|
1512
1943
|
armTerminationLadder(invocation, terminal, child, ended.signal);
|
|
1513
1944
|
try {
|
|
1514
|
-
return await child.ended;
|
|
1945
|
+
return engineSpawnedResult(await child.ended);
|
|
1515
1946
|
} catch (cause) {
|
|
1516
1947
|
throw spawnFailedError(request.command, cause);
|
|
1517
1948
|
} finally {
|
|
@@ -1680,12 +2111,6 @@ function makeContext(invocation, def, config, managesCredentials) {
|
|
|
1680
2111
|
* only for WHICH flag names appear, never for values), and the parsed
|
|
1681
2112
|
* positional slots (reduced to a count on the spot).
|
|
1682
2113
|
*/
|
|
1683
|
-
function kebabCase(key) {
|
|
1684
|
-
return key.replace(/[A-Z]/g, (upper) => `-${upper.toLowerCase()}`);
|
|
1685
|
-
}
|
|
1686
|
-
function camelCase(raw) {
|
|
1687
|
-
return raw.replace(/-([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
1688
|
-
}
|
|
1689
2114
|
function declaredFlagKeys(def) {
|
|
1690
2115
|
const own = Object.keys(def.args.flags);
|
|
1691
2116
|
if (def.kind === "server-command") return own;
|
|
@@ -1856,7 +2281,8 @@ function commandParameters(def) {
|
|
|
1856
2281
|
}
|
|
1857
2282
|
/** Help examples never contain the binary name (operator ruling,
|
|
1858
2283
|
* 2026-08-09): `{bin}` is substituted with the CLI name; an example
|
|
1859
|
-
* without `{bin}` gets the name prepended.
|
|
2284
|
+
* without `{bin}` gets the name prepended. A redirect's replacement is
|
|
2285
|
+
* written the same way and rendered by the same rule. */
|
|
1860
2286
|
function resolveExample(example, cliName) {
|
|
1861
2287
|
return example.includes("{bin}") ? example.replaceAll("{bin}", cliName) : `${cliName} ${example}`;
|
|
1862
2288
|
}
|
|
@@ -1908,6 +2334,7 @@ function capturingText(state) {
|
|
|
1908
2334
|
return {
|
|
1909
2335
|
...text_en,
|
|
1910
2336
|
exceptionWhileParsingArguments(exc, ansiColor) {
|
|
2337
|
+
if (exc instanceof FlagNotFoundError) state.unresolvedFlagNames.push(exc.input);
|
|
1911
2338
|
const message = text_en.exceptionWhileParsingArguments.call(text_en, exc, ansiColor);
|
|
1912
2339
|
state.usageErrorText = message;
|
|
1913
2340
|
return message;
|
|
@@ -1952,7 +2379,8 @@ function settleCompleted(invocation, def, presented) {
|
|
|
1952
2379
|
}
|
|
1953
2380
|
const state = invocation.state;
|
|
1954
2381
|
invocation.hooks.onPresented?.(presented);
|
|
1955
|
-
|
|
2382
|
+
const exitCode = runExitCode(invocation, presented.exitCode);
|
|
2383
|
+
state.settledExitCode = exitCode;
|
|
1956
2384
|
if (state.format === "json") {
|
|
1957
2385
|
emitFrame(invocation, {
|
|
1958
2386
|
kind: "result",
|
|
@@ -1960,7 +2388,7 @@ function settleCompleted(invocation, def, presented) {
|
|
|
1960
2388
|
ok: true,
|
|
1961
2389
|
commandId: state.commandId,
|
|
1962
2390
|
result: presented.presentation.json === void 0 ? presented.data : presented.presentation.json,
|
|
1963
|
-
exitCode
|
|
2391
|
+
exitCode,
|
|
1964
2392
|
diagnostics: presented.diagnostics.map((diagnostic) => withDocsUrl(state, diagnostic)),
|
|
1965
2393
|
nextActions: presented.presentation.next
|
|
1966
2394
|
},
|
|
@@ -1986,10 +2414,26 @@ function settleErrored(invocation, error, diagnostics = []) {
|
|
|
1986
2414
|
nextActions: error.nextActions
|
|
1987
2415
|
});
|
|
1988
2416
|
}
|
|
1989
|
-
/**
|
|
1990
|
-
*
|
|
1991
|
-
function signalExitCode(
|
|
1992
|
-
return
|
|
2417
|
+
/** The conventional code for a delivered signal: 128 + its number, so
|
|
2418
|
+
* 130 for SIGINT and 143 for SIGTERM. */
|
|
2419
|
+
function signalExitCode(signal) {
|
|
2420
|
+
return signal === "SIGTERM" ? 143 : 130;
|
|
2421
|
+
}
|
|
2422
|
+
/**
|
|
2423
|
+
* The engine's own signal record decides how a run ends. A run a
|
|
2424
|
+
* delivered signal terminated settles 128 + that signal's number even
|
|
2425
|
+
* when its handler caught the signal, cleaned up, and returned
|
|
2426
|
+
* successfully: the exit code states how the RUN ended, and a handler
|
|
2427
|
+
* cannot author it — the documented codes stop at 99.
|
|
2428
|
+
*
|
|
2429
|
+
* Verbatim codes are the exception, because they were never this CLI's
|
|
2430
|
+
* to state: a real child's status (the child owned the terminal and the
|
|
2431
|
+
* signal reached it too) and a server command's protocol conclusion
|
|
2432
|
+
* both pass through untouched.
|
|
2433
|
+
*/
|
|
2434
|
+
function runExitCode(invocation, completed) {
|
|
2435
|
+
const signal = invocation.state.deliveredSignal;
|
|
2436
|
+
return signal === void 0 ? completed : signalExitCode(signal);
|
|
1993
2437
|
}
|
|
1994
2438
|
function isAbortCause(cause, signal) {
|
|
1995
2439
|
if (!signal.aborted) return false;
|
|
@@ -2003,7 +2447,8 @@ function settleThrown(invocation, cause) {
|
|
|
2003
2447
|
}
|
|
2004
2448
|
function settleAborted(invocation) {
|
|
2005
2449
|
const state = invocation.state;
|
|
2006
|
-
|
|
2450
|
+
const signal = state.deliveredSignal;
|
|
2451
|
+
state.settledExitCode = signal === void 0 ? 3 : signalExitCode(signal);
|
|
2007
2452
|
emitErrored(invocation, {
|
|
2008
2453
|
ok: false,
|
|
2009
2454
|
commandId: state.commandId,
|
|
@@ -2021,32 +2466,42 @@ function settleAborted(invocation) {
|
|
|
2021
2466
|
* Settle an exit code the engine did not author, verbatim, with no
|
|
2022
2467
|
* envelope and no presentation: something other than this CLI's code
|
|
2023
2468
|
* space produced it. The two callers are the child-status settlement
|
|
2024
|
-
* and the server-command handoff.
|
|
2469
|
+
* and the server-command handoff. A delivered signal does not overrule
|
|
2470
|
+
* it — a code from outside is reported as it was received.
|
|
2025
2471
|
*/
|
|
2026
2472
|
function settleVerbatimExitCode(invocation, exitCode) {
|
|
2027
2473
|
invocation.state.settledExitCode = exitCode;
|
|
2028
2474
|
}
|
|
2029
2475
|
/**
|
|
2030
2476
|
* The child owned the terminal, so its status becomes the run's
|
|
2031
|
-
* verbatim
|
|
2032
|
-
*
|
|
2033
|
-
*
|
|
2034
|
-
*
|
|
2035
|
-
*
|
|
2036
|
-
*
|
|
2037
|
-
*
|
|
2477
|
+
* verbatim: the one path on which a result command settles a code it
|
|
2478
|
+
* never documented, because the code is not the handler's own
|
|
2479
|
+
* conclusion, it is the child's.
|
|
2480
|
+
*
|
|
2481
|
+
* Two conditions fence it, both construction errors. The command must
|
|
2482
|
+
* hand the terminal to another program — reachable from a
|
|
2483
|
+
* non-declaring handler this would also end a json stream without its
|
|
2484
|
+
* terminal result frame. And the status must be one the engine watched
|
|
2485
|
+
* a real child produce: a handler that invents a child result is
|
|
2486
|
+
* choosing an exit code through a door meant for reporting one, and a
|
|
2487
|
+
* handler interrupted mid-run has no need to, because the engine
|
|
2488
|
+
* settles a signal-terminated run itself.
|
|
2038
2489
|
*/
|
|
2039
2490
|
function settleChildStatus(invocation, def, settlement) {
|
|
2040
2491
|
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
|
+
if (!isEngineSpawned(settlement)) throw new Error(`@prisma/cli-engine: command '${invocation.state.commandId}' returned exitWithChildStatus for a child result the engine did not produce — only the result of a ctx.spawn carries a child's status`);
|
|
2041
2493
|
for (const action of settlement.nextActions) invocation.runtime.stderr.write(`${renderNextAction(action)}\n`);
|
|
2042
2494
|
settleVerbatimExitCode(invocation, settlement.exitCode);
|
|
2043
2495
|
}
|
|
2044
|
-
/** A session command that returned ok
|
|
2045
|
-
*
|
|
2046
|
-
*
|
|
2496
|
+
/** A session command that returned ok shut down cleanly: no
|
|
2497
|
+
* presentation, and exit 0 — unless a signal ended the run, which
|
|
2498
|
+
* settles 130/143 from the engine's record even though the shutdown
|
|
2499
|
+
* itself succeeded. In json mode the stream still terminates with
|
|
2500
|
+
* exactly one result frame. */
|
|
2047
2501
|
function settleSessionCompleted(invocation) {
|
|
2048
2502
|
const state = invocation.state;
|
|
2049
|
-
|
|
2503
|
+
const exitCode = runExitCode(invocation, 0);
|
|
2504
|
+
state.settledExitCode = exitCode;
|
|
2050
2505
|
if (state.format !== "json") return;
|
|
2051
2506
|
emitFrame(invocation, {
|
|
2052
2507
|
kind: "result",
|
|
@@ -2054,7 +2509,7 @@ function settleSessionCompleted(invocation) {
|
|
|
2054
2509
|
ok: true,
|
|
2055
2510
|
commandId: state.commandId,
|
|
2056
2511
|
result: null,
|
|
2057
|
-
exitCode
|
|
2512
|
+
exitCode,
|
|
2058
2513
|
diagnostics: [],
|
|
2059
2514
|
nextActions: []
|
|
2060
2515
|
},
|
|
@@ -2121,6 +2576,43 @@ function settleVersion(spec, invocation) {
|
|
|
2121
2576
|
});
|
|
2122
2577
|
return 0;
|
|
2123
2578
|
}
|
|
2579
|
+
/** What the user typed that no longer exists: a retired path, or a
|
|
2580
|
+
* retired flag on a command that still exists. */
|
|
2581
|
+
function retiredInvocation(redirect) {
|
|
2582
|
+
if (redirect.flag === void 0) return `\`${redirect.from}\``;
|
|
2583
|
+
return `\`--${kebabCase(redirect.flag)}\` on \`${redirect.from}\``;
|
|
2584
|
+
}
|
|
2585
|
+
/** A retired invocation the redirect table claims: the run names its
|
|
2586
|
+
* replacement instead of failing as an unknown command or flag. A
|
|
2587
|
+
* retired flag can name a server command, whose stdout belongs to a
|
|
2588
|
+
* foreign client — so this settlement renders to stderr for the same
|
|
2589
|
+
* reason settleUnhandled does. */
|
|
2590
|
+
function settleCommandMoved(spec, invocation, redirect, commandId) {
|
|
2591
|
+
if (spec.commands[redirect.from]?.kind === "server-command") invocation.state.format = "human";
|
|
2592
|
+
const useReplacement = {
|
|
2593
|
+
kind: "run-command",
|
|
2594
|
+
label: "Use the replacement",
|
|
2595
|
+
command: resolveExample(redirect.replacement, spec.name)
|
|
2596
|
+
};
|
|
2597
|
+
emitErrored(invocation, {
|
|
2598
|
+
ok: false,
|
|
2599
|
+
commandId,
|
|
2600
|
+
error: {
|
|
2601
|
+
code: "CLI.COMMAND_MOVED",
|
|
2602
|
+
severity: "error",
|
|
2603
|
+
summary: `${retiredInvocation(redirect)} has been replaced`,
|
|
2604
|
+
...redirect.reason === void 0 ? {} : { why: redirect.reason },
|
|
2605
|
+
nextActions: [useReplacement]
|
|
2606
|
+
},
|
|
2607
|
+
diagnostics: [],
|
|
2608
|
+
nextActions: [useReplacement]
|
|
2609
|
+
});
|
|
2610
|
+
return 2;
|
|
2611
|
+
}
|
|
2612
|
+
/** The command path stricli resolved, without the binary name. */
|
|
2613
|
+
function commandSegments(spec, prefix) {
|
|
2614
|
+
return prefix[0] === spec.name ? prefix.slice(1) : prefix;
|
|
2615
|
+
}
|
|
2124
2616
|
/** Maps stricli's own settlement (parse/route failures, framework bugs)
|
|
2125
2617
|
* onto the engine protocol when the pipeline never settled. A failure
|
|
2126
2618
|
* addressed at a server command renders to stderr — a foreign client on
|
|
@@ -2129,7 +2621,7 @@ function settleUnhandled(spec, invocation, stricliExitCode) {
|
|
|
2129
2621
|
const state = invocation.state;
|
|
2130
2622
|
const raw = typeof stricliExitCode === "number" ? stricliExitCode : 0;
|
|
2131
2623
|
if (raw === 0) return 0;
|
|
2132
|
-
const segments =
|
|
2624
|
+
const segments = commandSegments(spec, state.prefix);
|
|
2133
2625
|
if (spec.commands[segments.join(" ")]?.kind === "server-command") state.format = "human";
|
|
2134
2626
|
const usage = usageErrorCode(raw) !== void 0;
|
|
2135
2627
|
const captured = usage ? state.stricliStderr.trim() : state.usageErrorText ?? state.internalErrorText ?? state.stricliStderr.trim();
|
|
@@ -2173,13 +2665,17 @@ function waitFor(ms, signal) {
|
|
|
2173
2665
|
var EngineImpl = class {
|
|
2174
2666
|
spec;
|
|
2175
2667
|
root;
|
|
2668
|
+
redirects;
|
|
2176
2669
|
now;
|
|
2177
2670
|
delay;
|
|
2671
|
+
configSections;
|
|
2178
2672
|
constructor(spec, now = () => /* @__PURE__ */ new Date(), delay = waitFor) {
|
|
2179
2673
|
this.spec = spec;
|
|
2180
2674
|
this.now = now;
|
|
2181
2675
|
this.delay = delay;
|
|
2676
|
+
this.configSections = declaredConfigSections(spec);
|
|
2182
2677
|
this.root = buildRoutes(spec, buildCommandTree(spec), "", (invocation, entry, flags, values) => this.executeMounted(invocation, entry, flags, values));
|
|
2678
|
+
this.redirects = buildRedirectTable(spec);
|
|
2183
2679
|
}
|
|
2184
2680
|
async execute(argv, runtime, hooks) {
|
|
2185
2681
|
const state = {
|
|
@@ -2192,6 +2688,7 @@ var EngineImpl = class {
|
|
|
2192
2688
|
confirmValues: [],
|
|
2193
2689
|
interactive: defaultInteractive(runtime),
|
|
2194
2690
|
colorEnabled: false,
|
|
2691
|
+
configPath: void 0,
|
|
2195
2692
|
resolved: false,
|
|
2196
2693
|
settledExitCode: void 0,
|
|
2197
2694
|
usageErrorText: void 0,
|
|
@@ -2199,15 +2696,16 @@ var EngineImpl = class {
|
|
|
2199
2696
|
stricliStderr: "",
|
|
2200
2697
|
stdinIterator: void 0,
|
|
2201
2698
|
argv,
|
|
2699
|
+
unresolvedFlagNames: [],
|
|
2202
2700
|
snapshot: void 0,
|
|
2203
2701
|
delegatedTerminal: void 0,
|
|
2204
2702
|
activePrompts: 0,
|
|
2703
|
+
deliveredSignal: void 0,
|
|
2205
2704
|
pendingForceExit: void 0,
|
|
2206
2705
|
spawnCredential: void 0
|
|
2207
2706
|
};
|
|
2208
2707
|
const startedAtMs = this.now().getTime();
|
|
2209
2708
|
const controller = new AbortController();
|
|
2210
|
-
let signalDelivered = false;
|
|
2211
2709
|
/** The engine neither aborts nor exits while a child owns the
|
|
2212
2710
|
* terminal: it records, and the affordance replays on child exit,
|
|
2213
2711
|
* so the engine always outlives the child. */
|
|
@@ -2216,11 +2714,11 @@ var EngineImpl = class {
|
|
|
2216
2714
|
recordSignalDuringSpawn(state.delegatedTerminal, signal);
|
|
2217
2715
|
return;
|
|
2218
2716
|
}
|
|
2219
|
-
if (
|
|
2717
|
+
if (state.deliveredSignal !== void 0) {
|
|
2220
2718
|
runtime.exit(signal === "SIGTERM" ? 143 : 130);
|
|
2221
2719
|
return;
|
|
2222
2720
|
}
|
|
2223
|
-
|
|
2721
|
+
state.deliveredSignal = signal;
|
|
2224
2722
|
controller.abort(signal);
|
|
2225
2723
|
};
|
|
2226
2724
|
const unsubscribe = runtime.onSignal(deliverSignal);
|
|
@@ -2231,12 +2729,18 @@ var EngineImpl = class {
|
|
|
2231
2729
|
delay: this.delay,
|
|
2232
2730
|
state,
|
|
2233
2731
|
signal: controller.signal,
|
|
2732
|
+
configSections: this.configSections,
|
|
2234
2733
|
deliverSignal
|
|
2235
2734
|
};
|
|
2236
|
-
if (
|
|
2735
|
+
if (versionFlagGiven(argv)) {
|
|
2237
2736
|
unsubscribe();
|
|
2238
2737
|
return settleVersion(this.spec, invocation);
|
|
2239
2738
|
}
|
|
2739
|
+
if (configFlagGivenNoValue(argv)) {
|
|
2740
|
+
unsubscribe();
|
|
2741
|
+
settleErrored(invocation, configFlagGivenNoValueError());
|
|
2742
|
+
return 2;
|
|
2743
|
+
}
|
|
2240
2744
|
const stricliProcess = {
|
|
2241
2745
|
/** stricli writes only help text here. In json mode stdout carries
|
|
2242
2746
|
* exactly the frame stream, so help prose goes to stderr instead. */
|
|
@@ -2273,11 +2777,36 @@ var EngineImpl = class {
|
|
|
2273
2777
|
unsubscribe();
|
|
2274
2778
|
await state.stdinIterator?.return?.();
|
|
2275
2779
|
}
|
|
2276
|
-
const exitCode = state.settledExitCode !== void 0 ? state.settledExitCode :
|
|
2780
|
+
const exitCode = state.settledExitCode !== void 0 ? state.settledExitCode : this.settleRouting(invocation, stricliProcess.exitCode);
|
|
2277
2781
|
this.fireOnSettled(invocation, exitCode, startedAtMs);
|
|
2278
2782
|
if (state.pendingForceExit !== void 0) runtime.exit(state.pendingForceExit === "SIGTERM" ? 143 : 130);
|
|
2279
2783
|
return exitCode;
|
|
2280
2784
|
}
|
|
2785
|
+
/** stricli routed or parsed nothing runnable. When the redirect table
|
|
2786
|
+
* claims the invocation the user typed, the run names its
|
|
2787
|
+
* replacement; otherwise it settles as the usage error it is. */
|
|
2788
|
+
settleRouting(invocation, stricliExitCode) {
|
|
2789
|
+
const matched = this.matchRedirect(invocation.state, stricliExitCode);
|
|
2790
|
+
if (matched === void 0) return settleUnhandled(this.spec, invocation, stricliExitCode);
|
|
2791
|
+
return settleCommandMoved(this.spec, invocation, matched.redirect, matched.commandId);
|
|
2792
|
+
}
|
|
2793
|
+
matchRedirect(state, stricliExitCode) {
|
|
2794
|
+
const failure = typeof stricliExitCode === "number" ? usageErrorCode(stricliExitCode) : void 0;
|
|
2795
|
+
if (failure === "CLI.UNKNOWN_COMMAND") {
|
|
2796
|
+
const redirect = matchVerbRedirect(this.redirects, attemptedPath(state.argv));
|
|
2797
|
+
return redirect === void 0 ? void 0 : {
|
|
2798
|
+
redirect,
|
|
2799
|
+
commandId: redirect.from.replaceAll(" ", ".")
|
|
2800
|
+
};
|
|
2801
|
+
}
|
|
2802
|
+
if (failure !== "CLI.INVALID_ARGUMENTS") return;
|
|
2803
|
+
const segments = commandSegments(this.spec, state.prefix);
|
|
2804
|
+
const redirect = matchFlagRedirect(this.redirects, segments.join(" "), state.unresolvedFlagNames);
|
|
2805
|
+
return redirect === void 0 ? void 0 : {
|
|
2806
|
+
redirect,
|
|
2807
|
+
commandId: segments.join(".")
|
|
2808
|
+
};
|
|
2809
|
+
}
|
|
2281
2810
|
/** The onSettled delivery: once per run, after the exit code is
|
|
2282
2811
|
* final, only for runs that mounted a command (--help, --version,
|
|
2283
2812
|
* and pre-mount usage errors leave no snapshot and fire nothing).
|
|
@@ -2304,7 +2833,7 @@ var EngineImpl = class {
|
|
|
2304
2833
|
await this.executeServer(invocation, entry, rawFlags);
|
|
2305
2834
|
return;
|
|
2306
2835
|
}
|
|
2307
|
-
if (entry.def.maySpawn &&
|
|
2836
|
+
if (entry.def.maySpawn && formatFlagGiven(state.argv) === "json") {
|
|
2308
2837
|
state.format = "human";
|
|
2309
2838
|
settleErrored(invocation, jsonUnsupportedError(entry.id));
|
|
2310
2839
|
return;
|
|
@@ -2427,6 +2956,25 @@ var EngineImpl = class {
|
|
|
2427
2956
|
}
|
|
2428
2957
|
}
|
|
2429
2958
|
};
|
|
2959
|
+
/** The path the user typed, for argv that routed to no command: the
|
|
2960
|
+
* leading tokens up to the first flag or argument escape. */
|
|
2961
|
+
function attemptedPath(argv) {
|
|
2962
|
+
const segments = [];
|
|
2963
|
+
for (const token of argv) {
|
|
2964
|
+
if (token.startsWith("-")) break;
|
|
2965
|
+
segments.push(token);
|
|
2966
|
+
}
|
|
2967
|
+
return segments;
|
|
2968
|
+
}
|
|
2969
|
+
/** The closed set of config section names. Every mounted command
|
|
2970
|
+
* contributes the section it needs, whether it reaches the tree
|
|
2971
|
+
* through a command family or on its own — the shell mounts its own
|
|
2972
|
+
* commands with no family, and a section the CLI cannot name is a
|
|
2973
|
+
* section its own command could never read. Every other top-level key
|
|
2974
|
+
* in prisma.config.ts is reported by the config needs check. */
|
|
2975
|
+
function declaredConfigSections(spec) {
|
|
2976
|
+
return [...new Set([...spec.commandFamilies.map((commandFamily) => commandFamily.configSection?.name), ...Object.values(spec.commands).map((def) => def.needs.config?.name)].filter((name) => name !== void 0))];
|
|
2977
|
+
}
|
|
2430
2978
|
/** A command that may hand the terminal to a child cannot frame its
|
|
2431
2979
|
* output, so json is refused as soon as the command is known — before
|
|
2432
2980
|
* the needs check and before anything runs. */
|
|
@@ -2439,13 +2987,6 @@ function jsonUnsupportedError(commandId) {
|
|
|
2439
2987
|
}]
|
|
2440
2988
|
});
|
|
2441
2989
|
}
|
|
2442
|
-
function versionRequested(argv) {
|
|
2443
|
-
for (const argument of argv) {
|
|
2444
|
-
if (argument === "--") return false;
|
|
2445
|
-
if (argument === "--version") return true;
|
|
2446
|
-
}
|
|
2447
|
-
return false;
|
|
2448
|
-
}
|
|
2449
2990
|
function declaredFlags(def, rawFlags) {
|
|
2450
2991
|
const flags = {};
|
|
2451
2992
|
for (const key of Object.keys(def.args.flags)) flags[key] = rawFlags[key];
|
|
@@ -2491,12 +3032,15 @@ function claimedString(claims, name) {
|
|
|
2491
3032
|
const value = claims?.[name];
|
|
2492
3033
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
2493
3034
|
}
|
|
2494
|
-
/**
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
*
|
|
3035
|
+
/**
|
|
3036
|
+
* The workspace a credential names. One derivation, because a token
|
|
3037
|
+
* says it one of two ways and every caller wants the same answer: an
|
|
3038
|
+
* OAuth token carries `workspace_id`, while a service token names its
|
|
3039
|
+
* workspace through `sub` and carries no `workspace_id` at all. Reading
|
|
3040
|
+
* only the claim was a second path that happened to work because
|
|
3041
|
+
* service tokens reached it by a different route — a split nothing
|
|
3042
|
+
* enforced.
|
|
3043
|
+
*/
|
|
2500
3044
|
function credentialWorkspaceId(token) {
|
|
2501
3045
|
const claims = decodeTokenClaims(token);
|
|
2502
3046
|
const fromClaim = claimedString(claims, "workspace_id");
|
|
@@ -2527,4 +3071,4 @@ function claimedIdentity(token) {
|
|
|
2527
3071
|
};
|
|
2528
3072
|
}
|
|
2529
3073
|
//#endregion
|
|
2530
|
-
export {
|
|
3074
|
+
export { PRESENTED as _, CONFIG_FILE_NAME as a, positional as b, PRISMA_CONFIG_VERSION as c, authServiceError as d, credentialRejectedError as f, noSessionForWorkspaceError as g, emptyServiceTokenError as h, buildEngine as i, SERVICE_TOKEN_ENV_VAR as l, credentialsRequiredError as m, claimedIdentity as n, defineConfig as o, credentialWorkspaceMismatchError as p, credentialWorkspaceId as r, loadConfig as s, claimedExpiresAt as t, WORKSPACE_ID_ENV_VAR as u, exitWithChildStatus as v, flag as y };
|