@prisma/composer-cli 0.34.0 → 0.35.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{dev-current-vAfxVcnD-Drp6NbCc.mjs → dev-current-BB02pfSh-vMKS1rYi.mjs} +6 -6
- package/dist/{dev-current-vAfxVcnD-Drp6NbCc.mjs.map → dev-current-BB02pfSh-vMKS1rYi.mjs.map} +1 -1
- package/dist/{dist-j4X7U5yA.mjs → dist-B9-nLeho.mjs} +10 -4
- package/dist/{dist-j4X7U5yA.mjs.map → dist-B9-nLeho.mjs.map} +1 -1
- package/dist/{execute-deploy-destroy-CdjqjHzw-BgnsJ75H.mjs → execute-deploy-destroy-DwcoZIks-CiW-dlB1.mjs} +7 -13
- package/dist/execute-deploy-destroy-DwcoZIks-CiW-dlB1.mjs.map +1 -0
- package/dist/{execute-dev-C75Y_wIa-lffN9oPi.mjs → execute-dev-BHRWoEnd-DrGMSTD3.mjs} +163 -36
- package/dist/{execute-dev-C75Y_wIa-lffN9oPi.mjs.map → execute-dev-BHRWoEnd-DrGMSTD3.mjs.map} +1 -1
- package/dist/{execute-dev-current-C0y1X-EE-DB7Q506a.mjs → execute-dev-current-D4RkOtPA-BFoZ0cXm.mjs} +10 -8
- package/dist/execute-dev-current-D4RkOtPA-BFoZ0cXm.mjs.map +1 -0
- package/dist/{family-BYcJFXg--DbwOABZy.d.mts → family-xJ6y4fXc-CFBu6q4b.d.mts} +114 -32
- package/dist/family-xJ6y4fXc-CFBu6q4b.d.mts.map +1 -0
- package/dist/family.d.mts +35 -4
- package/dist/family.d.mts.map +1 -1
- package/dist/family.mjs +175 -56
- package/dist/family.mjs.map +1 -1
- package/dist/{generate-dev-stack-DSBhURJV-Gv1jakWP.mjs → generate-dev-stack-CfneNj97-Yx3Z2-9u.mjs} +5 -3
- package/dist/generate-dev-stack-CfneNj97-Yx3Z2-9u.mjs.map +1 -0
- package/dist/list-deployed-7tjEhYgA.mjs +354 -0
- package/dist/list-deployed-7tjEhYgA.mjs.map +1 -0
- package/dist/{local-target-DZ6bu7Aj.mjs → local-target-CK8gvYV4.mjs} +2 -2
- package/dist/{local-target-DZ6bu7Aj.mjs.map → local-target-CK8gvYV4.mjs.map} +1 -1
- package/dist/{pipeline-Dpesfd2j-DKL3f1bj.mjs → pipeline-BmWt-Nhb-Bos4TFXR.mjs} +107 -24
- package/dist/pipeline-BmWt-Nhb-Bos4TFXR.mjs.map +1 -0
- package/dist/{composer-config-CY9fET8H-CgnpfWc2.mjs → run-alchemy-Dl_MWw4g-DaWV9tkH.mjs} +333 -310
- package/dist/run-alchemy-Dl_MWw4g-DaWV9tkH.mjs.map +1 -0
- package/dist/testing.d.mts +3 -1
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +5 -4
- package/dist/testing.mjs.map +1 -1
- package/dist/validate-stage-DxRW3MwT-DOWCXHa_.mjs +13 -0
- package/dist/validate-stage-DxRW3MwT-DOWCXHa_.mjs.map +1 -0
- package/package.json +9 -7
- package/src/exports/family.ts +8 -1
- package/src/family/deploy-list.ts +96 -0
- package/src/family/deployed-nodes.ts +55 -0
- package/src/family/list-deployed.ts +64 -0
- package/dist/composer-config-CY9fET8H-CgnpfWc2.mjs.map +0 -1
- package/dist/execute-deploy-destroy-CdjqjHzw-BgnsJ75H.mjs.map +0 -1
- package/dist/execute-dev-current-C0y1X-EE-DB7Q506a.mjs.map +0 -1
- package/dist/family-BYcJFXg--DbwOABZy.d.mts.map +0 -1
- package/dist/generate-dev-stack-DSBhURJV-Gv1jakWP.mjs.map +0 -1
- package/dist/pipeline-Dpesfd2j-DKL3f1bj.mjs.map +0 -1
|
@@ -2,6 +2,230 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import spawn from "cross-spawn";
|
|
5
|
+
//#region ../../0-framework/3-tooling/cli/dist/composer-config-ehUUVHtU.mjs
|
|
6
|
+
/**
|
|
7
|
+
* What makes a `composer` section valid, shared by the CLI's section validator and the programmatic operations.
|
|
8
|
+
* It imports nothing from the CLI engine, because `@prisma/composer` must not depend on it.
|
|
9
|
+
*/
|
|
10
|
+
const SECTION_FIX = "Write `composer: composer({ entry: './module.ts', extensions: [...], state: ... })` in prisma.config.ts, with `import { defineConfig as composer } from '@prisma/composer/config'`.";
|
|
11
|
+
const MOVE_TO_SECTION_FIX = `${SECTION_FIX} If the project has a prisma-composer.config.ts, move its extensions and state into that section and delete the file.`;
|
|
12
|
+
const SECTION_IS_THE_ONLY_SOURCE = "Composer reads its configuration only from the `composer` section of prisma.config.ts.";
|
|
13
|
+
const DESCRIPTOR_FIX = "Use the descriptor the extension factory returns, unchanged, instead of building one by hand.";
|
|
14
|
+
const RETIRED_FILE_NAMES = [
|
|
15
|
+
"ts",
|
|
16
|
+
"mts",
|
|
17
|
+
"mjs",
|
|
18
|
+
"js"
|
|
19
|
+
].map((extension) => `prisma-composer.config.${extension}`);
|
|
20
|
+
const sectionMissing = {
|
|
21
|
+
code: "CONFIG.SECTION_MISSING",
|
|
22
|
+
summary: "No loaded prisma.config.ts declares a `composer` section.",
|
|
23
|
+
why: `${SECTION_IS_THE_ONLY_SOURCE} A prisma-composer.config.ts file is no longer read.`,
|
|
24
|
+
fix: MOVE_TO_SECTION_FIX
|
|
25
|
+
};
|
|
26
|
+
/** What the generated stack file throws when the file it imports has no `composer` export. */
|
|
27
|
+
function noComposerExportMessage(configFile) {
|
|
28
|
+
return `${configFile} declares no \`composer\` section. Pass the prisma.config.ts that declares it.`;
|
|
29
|
+
}
|
|
30
|
+
function configFileMissing(file) {
|
|
31
|
+
return {
|
|
32
|
+
code: "CONFIG.FILE_MISSING",
|
|
33
|
+
summary: `${file} does not exist.`,
|
|
34
|
+
fix: "Pass the path of the prisma.config.ts that declares the `composer` section.",
|
|
35
|
+
where: file
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** A prisma-composer.config.* beside the declaring file would otherwise be silently ignored. */
|
|
39
|
+
/** The path with symlinks resolved; the path itself when it cannot be resolved, so the check never throws. */
|
|
40
|
+
function realPath(file) {
|
|
41
|
+
try {
|
|
42
|
+
return fs.realpathSync(file);
|
|
43
|
+
} catch {
|
|
44
|
+
return file;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function retiredFileFinding(configFile) {
|
|
48
|
+
const directory = path.dirname(realPath(configFile));
|
|
49
|
+
const found = RETIRED_FILE_NAMES.map((name) => path.join(directory, name)).find((file) => fs.existsSync(file));
|
|
50
|
+
if (found === void 0) return void 0;
|
|
51
|
+
return {
|
|
52
|
+
code: "CONFIG.FILE_RETIRED",
|
|
53
|
+
summary: `${found} is no longer read.`,
|
|
54
|
+
why: SECTION_IS_THE_ONLY_SOURCE,
|
|
55
|
+
fix: MOVE_TO_SECTION_FIX,
|
|
56
|
+
where: found
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function isObject(value) {
|
|
60
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
61
|
+
}
|
|
62
|
+
function isExtensionDescriptor(value) {
|
|
63
|
+
return isObject(value) && typeof value["id"] === "string" && value["id"].length > 0 && isObject(value["nodes"]);
|
|
64
|
+
}
|
|
65
|
+
function isStateDescriptor(value) {
|
|
66
|
+
return isObject(value) && typeof value["extension"] === "string" && typeof value["create"] === "function";
|
|
67
|
+
}
|
|
68
|
+
const stateInvalid = {
|
|
69
|
+
code: "CONFIG.FIELD_INVALID",
|
|
70
|
+
summary: "`composer.state` must be a state descriptor with a string `extension` and a `create` function.",
|
|
71
|
+
fix: "Set `state` to the state descriptor an extension provides, e.g. `state: prismaState()`.",
|
|
72
|
+
field: "state"
|
|
73
|
+
};
|
|
74
|
+
const SECTION_FIELDS = /* @__PURE__ */ new Set([
|
|
75
|
+
"entry",
|
|
76
|
+
"extensions",
|
|
77
|
+
"state"
|
|
78
|
+
]);
|
|
79
|
+
const entryInvalid = {
|
|
80
|
+
code: "CONFIG.FIELD_INVALID",
|
|
81
|
+
summary: "`composer.entry` must be a non-empty string: the path to the module whose default export is the app.",
|
|
82
|
+
fix: "Set `entry` to that module's path, relative to prisma.config.ts, e.g. `entry: './module.ts'`.",
|
|
83
|
+
field: "entry"
|
|
84
|
+
};
|
|
85
|
+
/** Neither the section's `entry` nor an override names the module whose default export is the app. */
|
|
86
|
+
const entryMissing = {
|
|
87
|
+
code: "CONFIG.ENTRY_MISSING",
|
|
88
|
+
summary: "No entry module is set, so there is no app to load.",
|
|
89
|
+
why: "The entry is the module whose default export is the app root, built with module(...).",
|
|
90
|
+
fix: "Set `entry: './module.ts'` in the `composer` section of prisma.config.ts, or pass `--entry <path>` (the `entry` input when calling @prisma/composer/control).",
|
|
91
|
+
field: "entry"
|
|
92
|
+
};
|
|
93
|
+
function unknownField(key) {
|
|
94
|
+
return {
|
|
95
|
+
code: "CONFIG.FIELD_UNKNOWN",
|
|
96
|
+
summary: `The \`composer\` section has no field \`${key}\`.`,
|
|
97
|
+
fix: key === "composer" ? "Pass the `composer` property of the prisma.config.ts export, not the whole export. The section takes only `entry`, `extensions` and `state`." : `Remove \`${key}\`. The section takes only \`entry\`, \`extensions\` and \`state\`.`,
|
|
98
|
+
field: key
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function checkExtensions(value) {
|
|
102
|
+
if (!Array.isArray(value)) return {
|
|
103
|
+
extensions: [],
|
|
104
|
+
findings: [{
|
|
105
|
+
code: "CONFIG.FIELD_INVALID",
|
|
106
|
+
summary: "`composer.extensions` must be an array of extension descriptors.",
|
|
107
|
+
fix: "Set `extensions` to the descriptors your extensions provide, e.g. `extensions: [nodeBuild()]`.",
|
|
108
|
+
field: "extensions"
|
|
109
|
+
}]
|
|
110
|
+
};
|
|
111
|
+
const findings = [];
|
|
112
|
+
const extensions = [];
|
|
113
|
+
const seen = /* @__PURE__ */ new Set();
|
|
114
|
+
for (const [index, entry] of value.entries()) {
|
|
115
|
+
const field = `extensions[${index}]`;
|
|
116
|
+
if (!isObject(entry)) {
|
|
117
|
+
findings.push({
|
|
118
|
+
code: "CONFIG.FIELD_INVALID",
|
|
119
|
+
summary: `\`composer.${field}\` must be an extension descriptor object.`,
|
|
120
|
+
fix: "Put the descriptor an extension factory returns here, e.g. `nodeBuild()`, not the factory itself.",
|
|
121
|
+
field
|
|
122
|
+
});
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const id = entry["id"];
|
|
126
|
+
if (typeof id !== "string" || id.length === 0) findings.push({
|
|
127
|
+
code: "CONFIG.FIELD_INVALID",
|
|
128
|
+
summary: `\`composer.${field}.id\` must be a non-empty string (the extension package name).`,
|
|
129
|
+
fix: DESCRIPTOR_FIX,
|
|
130
|
+
field: `${field}.id`
|
|
131
|
+
});
|
|
132
|
+
else if (seen.has(id)) findings.push({
|
|
133
|
+
code: "CONFIG.EXTENSION_DUPLICATE",
|
|
134
|
+
summary: `Extension "${id}" is listed more than once in \`composer.extensions\`.`,
|
|
135
|
+
fix: `Remove the repeated "${id}" entry from \`extensions\`.`,
|
|
136
|
+
field: `${field}.id`
|
|
137
|
+
});
|
|
138
|
+
else seen.add(id);
|
|
139
|
+
if (!isObject(entry["nodes"])) findings.push({
|
|
140
|
+
code: "CONFIG.FIELD_INVALID",
|
|
141
|
+
summary: `\`composer.${field}.nodes\` must be an object (the node-ID → control registry).`,
|
|
142
|
+
fix: DESCRIPTOR_FIX,
|
|
143
|
+
field: `${field}.nodes`
|
|
144
|
+
});
|
|
145
|
+
if (isExtensionDescriptor(entry)) extensions.push(entry);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
findings,
|
|
149
|
+
extensions
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function checkFields(section) {
|
|
153
|
+
if (Object.hasOwn(section, "configPath")) return {
|
|
154
|
+
ok: false,
|
|
155
|
+
findings: [{
|
|
156
|
+
code: "CONFIG.FIELD_RETIRED",
|
|
157
|
+
summary: "`composer.configPath` is no longer supported: prisma-composer.config.ts is no longer read.",
|
|
158
|
+
why: SECTION_IS_THE_ONLY_SOURCE,
|
|
159
|
+
fix: `Replace \`configPath\` with the section itself. ${MOVE_TO_SECTION_FIX}`,
|
|
160
|
+
field: "configPath"
|
|
161
|
+
}]
|
|
162
|
+
};
|
|
163
|
+
if (Object.hasOwn(section, "composer")) return {
|
|
164
|
+
ok: false,
|
|
165
|
+
findings: [unknownField("composer")]
|
|
166
|
+
};
|
|
167
|
+
const findings = Object.keys(section).filter((key) => !SECTION_FIELDS.has(key)).map(unknownField);
|
|
168
|
+
const checked = checkExtensions(section["extensions"]);
|
|
169
|
+
findings.push(...checked.findings);
|
|
170
|
+
const state = section["state"];
|
|
171
|
+
if (!isStateDescriptor(state)) findings.push(stateInvalid);
|
|
172
|
+
const entry = section["entry"];
|
|
173
|
+
const entryValid = entry === void 0 || typeof entry === "string" && entry.length > 0;
|
|
174
|
+
if (!entryValid) findings.push(entryInvalid);
|
|
175
|
+
const [first, ...rest] = findings;
|
|
176
|
+
if (first === void 0 && isStateDescriptor(state) && entryValid) return {
|
|
177
|
+
ok: true,
|
|
178
|
+
value: {
|
|
179
|
+
extensions: checked.extensions,
|
|
180
|
+
state,
|
|
181
|
+
...entry === void 0 ? {} : { entry }
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
ok: false,
|
|
186
|
+
findings: [first ?? stateInvalid, ...rest]
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Checks the fields that identify each descriptor and returns the descriptors as the config file's own objects.
|
|
191
|
+
* Never throws: a section's values are user code, and a throwing getter or Proxy trap becomes a finding.
|
|
192
|
+
*/
|
|
193
|
+
function checkComposerSection(raw) {
|
|
194
|
+
if (!isObject(raw)) return {
|
|
195
|
+
ok: false,
|
|
196
|
+
findings: [{
|
|
197
|
+
code: "CONFIG.FIELD_INVALID",
|
|
198
|
+
summary: "The `composer` section of prisma.config.ts must be an object.",
|
|
199
|
+
fix: SECTION_FIX
|
|
200
|
+
}]
|
|
201
|
+
};
|
|
202
|
+
try {
|
|
203
|
+
return checkFields({ ...raw });
|
|
204
|
+
} catch (cause) {
|
|
205
|
+
return {
|
|
206
|
+
ok: false,
|
|
207
|
+
findings: [{
|
|
208
|
+
code: "CONFIG.FIELD_INVALID",
|
|
209
|
+
summary: "The `composer` section of prisma.config.ts could not be read.",
|
|
210
|
+
why: `Reading it threw: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
211
|
+
fix: SECTION_FIX
|
|
212
|
+
}]
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The whole check, shared by the section validator and the programmatic operations so both report the same findings in the same order: the retired file beside the declaring `configFile` (resolved through symlinks), then every field finding.
|
|
218
|
+
*/
|
|
219
|
+
function checkComposerConfig(raw, configFile) {
|
|
220
|
+
const retired = retiredFileFinding(configFile);
|
|
221
|
+
const checked = checkComposerSection(raw);
|
|
222
|
+
if (retired === void 0) return checked;
|
|
223
|
+
return {
|
|
224
|
+
ok: false,
|
|
225
|
+
findings: checked.ok ? [retired] : [retired, ...checked.findings]
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
//#endregion
|
|
5
229
|
//#region ../../0-framework/0-foundation/foundation/dist/casts-DpaahrlC.mjs
|
|
6
230
|
/**
|
|
7
231
|
* **Last-resort escape hatch for unsafe type assertions. Not a sanctioned tool to reach for.**
|
|
@@ -57,93 +281,6 @@ var InternalError = class extends Error {
|
|
|
57
281
|
}
|
|
58
282
|
};
|
|
59
283
|
//#endregion
|
|
60
|
-
//#region ../../0-framework/0-foundation/foundation/dist/result.mjs
|
|
61
|
-
/**
|
|
62
|
-
* Generic Result type for representing success or failure outcomes.
|
|
63
|
-
*
|
|
64
|
-
* This is the standard way to return "expected failures" as values rather than
|
|
65
|
-
* throwing exceptions. See docs/Error Handling.md for the full taxonomy.
|
|
66
|
-
*
|
|
67
|
-
* Naming rationale:
|
|
68
|
-
* - `Ok<T>` / `NotOk<F>` mirror the `ok: true/false` discriminator
|
|
69
|
-
* - `NotOk` avoids collision with domain types like "Failure" or "Error"
|
|
70
|
-
* - `failure` property distinguishes from JS Error semantics
|
|
71
|
-
*/
|
|
72
|
-
/**
|
|
73
|
-
* Result class that implements both Ok and NotOk variants.
|
|
74
|
-
*/
|
|
75
|
-
var ResultImpl = class ResultImpl {
|
|
76
|
-
ok;
|
|
77
|
-
_value;
|
|
78
|
-
_failure;
|
|
79
|
-
constructor(ok, valueOrFailure) {
|
|
80
|
-
this.ok = ok;
|
|
81
|
-
if (ok) this._value = blindCast(valueOrFailure);
|
|
82
|
-
else this._failure = blindCast(valueOrFailure);
|
|
83
|
-
Object.freeze(this);
|
|
84
|
-
}
|
|
85
|
-
get value() {
|
|
86
|
-
if (!this.ok) throw new InternalError("Cannot access value on NotOk result");
|
|
87
|
-
return this._value;
|
|
88
|
-
}
|
|
89
|
-
get failure() {
|
|
90
|
-
if (this.ok) throw new InternalError("Cannot access failure on Ok result");
|
|
91
|
-
return this._failure;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Creates a successful result.
|
|
95
|
-
*/
|
|
96
|
-
static ok(value) {
|
|
97
|
-
return blindCast(new ResultImpl(true, value));
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Creates an unsuccessful result.
|
|
101
|
-
*/
|
|
102
|
-
static notOk(failure) {
|
|
103
|
-
return blindCast(new ResultImpl(false, failure));
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Asserts that this result is Ok and returns the value.
|
|
107
|
-
* Throws if the result is NotOk.
|
|
108
|
-
*/
|
|
109
|
-
assertOk() {
|
|
110
|
-
if (!this.ok) throw new InternalError("Expected Ok result but got NotOk");
|
|
111
|
-
return this.value;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Asserts that this result is NotOk and returns the failure.
|
|
115
|
-
* Throws if the result is Ok.
|
|
116
|
-
*/
|
|
117
|
-
assertNotOk() {
|
|
118
|
-
if (this.ok) throw new InternalError("Expected NotOk result but got Ok");
|
|
119
|
-
return this.failure;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* Creates a successful result.
|
|
124
|
-
*/
|
|
125
|
-
function ok(value) {
|
|
126
|
-
return ResultImpl.ok(value);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Creates an unsuccessful result.
|
|
130
|
-
*/
|
|
131
|
-
function notOk(failure) {
|
|
132
|
-
return ResultImpl.notOk(failure);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Singleton for void success results.
|
|
136
|
-
* Use this for validation checks that don't produce a value.
|
|
137
|
-
*/
|
|
138
|
-
const OK_VOID = ResultImpl.ok(void 0);
|
|
139
|
-
/**
|
|
140
|
-
* Returns a successful void result.
|
|
141
|
-
* Use this for validation checks that don't produce a value.
|
|
142
|
-
*/
|
|
143
|
-
function okVoid() {
|
|
144
|
-
return OK_VOID;
|
|
145
|
-
}
|
|
146
|
-
//#endregion
|
|
147
284
|
//#region ../../0-framework/0-foundation/foundation/dist/errors.mjs
|
|
148
285
|
/**
|
|
149
286
|
* Returns an object with the key/value if value is defined, otherwise an empty object.
|
|
@@ -202,33 +339,120 @@ var CliStructuredError = class extends Error {
|
|
|
202
339
|
});
|
|
203
340
|
}
|
|
204
341
|
/**
|
|
205
|
-
* Converts this error to a CLI error envelope for output formatting.
|
|
342
|
+
* Converts this error to a CLI error envelope for output formatting.
|
|
343
|
+
*/
|
|
344
|
+
toEnvelope() {
|
|
345
|
+
return {
|
|
346
|
+
ok: false,
|
|
347
|
+
code: this.code,
|
|
348
|
+
severity: this.severity,
|
|
349
|
+
summary: this.message,
|
|
350
|
+
...ifDefined("why", this.why),
|
|
351
|
+
...ifDefined("fix", this.fix),
|
|
352
|
+
...ifDefined("where", this.where),
|
|
353
|
+
...ifDefined("meta", this.meta),
|
|
354
|
+
...ifDefined("docsUrl", this.docsUrl)
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Type guard to check if an error is a CliStructuredError.
|
|
359
|
+
* Uses duck-typing to work across module boundaries where instanceof may fail.
|
|
360
|
+
*/
|
|
361
|
+
static is(error) {
|
|
362
|
+
if (!(error instanceof Error)) return false;
|
|
363
|
+
const candidate = blindCast(error);
|
|
364
|
+
return candidate.name === "CliStructuredError" && typeof candidate.code === "string" && typeof candidate.toEnvelope === "function";
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region ../../0-framework/0-foundation/foundation/dist/result.mjs
|
|
369
|
+
/**
|
|
370
|
+
* Generic Result type for representing success or failure outcomes.
|
|
371
|
+
*
|
|
372
|
+
* This is the standard way to return "expected failures" as values rather than
|
|
373
|
+
* throwing exceptions. See docs/Error Handling.md for the full taxonomy.
|
|
374
|
+
*
|
|
375
|
+
* Naming rationale:
|
|
376
|
+
* - `Ok<T>` / `NotOk<F>` mirror the `ok: true/false` discriminator
|
|
377
|
+
* - `NotOk` avoids collision with domain types like "Failure" or "Error"
|
|
378
|
+
* - `failure` property distinguishes from JS Error semantics
|
|
379
|
+
*/
|
|
380
|
+
/**
|
|
381
|
+
* Result class that implements both Ok and NotOk variants.
|
|
382
|
+
*/
|
|
383
|
+
var ResultImpl = class ResultImpl {
|
|
384
|
+
ok;
|
|
385
|
+
_value;
|
|
386
|
+
_failure;
|
|
387
|
+
constructor(ok, valueOrFailure) {
|
|
388
|
+
this.ok = ok;
|
|
389
|
+
if (ok) this._value = blindCast(valueOrFailure);
|
|
390
|
+
else this._failure = blindCast(valueOrFailure);
|
|
391
|
+
Object.freeze(this);
|
|
392
|
+
}
|
|
393
|
+
get value() {
|
|
394
|
+
if (!this.ok) throw new InternalError("Cannot access value on NotOk result");
|
|
395
|
+
return this._value;
|
|
396
|
+
}
|
|
397
|
+
get failure() {
|
|
398
|
+
if (this.ok) throw new InternalError("Cannot access failure on Ok result");
|
|
399
|
+
return this._failure;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Creates a successful result.
|
|
403
|
+
*/
|
|
404
|
+
static ok(value) {
|
|
405
|
+
return blindCast(new ResultImpl(true, value));
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Creates an unsuccessful result.
|
|
206
409
|
*/
|
|
207
|
-
|
|
208
|
-
return
|
|
209
|
-
ok: false,
|
|
210
|
-
code: this.code,
|
|
211
|
-
severity: this.severity,
|
|
212
|
-
summary: this.message,
|
|
213
|
-
...ifDefined("why", this.why),
|
|
214
|
-
...ifDefined("fix", this.fix),
|
|
215
|
-
...ifDefined("where", this.where),
|
|
216
|
-
...ifDefined("meta", this.meta),
|
|
217
|
-
...ifDefined("docsUrl", this.docsUrl)
|
|
218
|
-
};
|
|
410
|
+
static notOk(failure) {
|
|
411
|
+
return blindCast(new ResultImpl(false, failure));
|
|
219
412
|
}
|
|
220
413
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
414
|
+
* Asserts that this result is Ok and returns the value.
|
|
415
|
+
* Throws if the result is NotOk.
|
|
223
416
|
*/
|
|
224
|
-
|
|
225
|
-
if (!(
|
|
226
|
-
|
|
227
|
-
|
|
417
|
+
assertOk() {
|
|
418
|
+
if (!this.ok) throw new InternalError("Expected Ok result but got NotOk");
|
|
419
|
+
return this.value;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Asserts that this result is NotOk and returns the failure.
|
|
423
|
+
* Throws if the result is Ok.
|
|
424
|
+
*/
|
|
425
|
+
assertNotOk() {
|
|
426
|
+
if (this.ok) throw new InternalError("Expected NotOk result but got Ok");
|
|
427
|
+
return this.failure;
|
|
228
428
|
}
|
|
229
429
|
};
|
|
430
|
+
/**
|
|
431
|
+
* Creates a successful result.
|
|
432
|
+
*/
|
|
433
|
+
function ok(value) {
|
|
434
|
+
return ResultImpl.ok(value);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Creates an unsuccessful result.
|
|
438
|
+
*/
|
|
439
|
+
function notOk(failure) {
|
|
440
|
+
return ResultImpl.notOk(failure);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Singleton for void success results.
|
|
444
|
+
* Use this for validation checks that don't produce a value.
|
|
445
|
+
*/
|
|
446
|
+
const OK_VOID = ResultImpl.ok(void 0);
|
|
447
|
+
/**
|
|
448
|
+
* Returns a successful void result.
|
|
449
|
+
* Use this for validation checks that don't produce a value.
|
|
450
|
+
*/
|
|
451
|
+
function okVoid() {
|
|
452
|
+
return OK_VOID;
|
|
453
|
+
}
|
|
230
454
|
//#endregion
|
|
231
|
-
//#region ../../0-framework/3-tooling/cli/dist/run-alchemy-
|
|
455
|
+
//#region ../../0-framework/3-tooling/cli/dist/run-alchemy-Dl_MWw4g.mjs
|
|
232
456
|
/**
|
|
233
457
|
* Which Alchemy CLI runs a generated stack file: the `alchemy` that
|
|
234
458
|
* `@prisma/composer` depends on, found from the app the way the stack file's
|
|
@@ -438,207 +662,6 @@ function spawnCommandLine(line) {
|
|
|
438
662
|
});
|
|
439
663
|
}
|
|
440
664
|
//#endregion
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* What makes a `composer` section valid, shared by the CLI's section validator and the programmatic operations.
|
|
444
|
-
* It imports nothing from the CLI engine, because `@prisma/composer` must not depend on it.
|
|
445
|
-
*/
|
|
446
|
-
const SECTION_FIX = "Write `composer: composer({ extensions: [...], state: ... })` in prisma.config.ts, with `import { defineConfig as composer } from '@prisma/composer/config'`.";
|
|
447
|
-
const MOVE_TO_SECTION_FIX = `${SECTION_FIX} If the project has a prisma-composer.config.ts, move its extensions and state into that section and delete the file.`;
|
|
448
|
-
const SECTION_IS_THE_ONLY_SOURCE = "Composer reads its configuration only from the `composer` section of prisma.config.ts.";
|
|
449
|
-
const DESCRIPTOR_FIX = "Use the descriptor the extension factory returns, unchanged, instead of building one by hand.";
|
|
450
|
-
const RETIRED_FILE_NAMES = [
|
|
451
|
-
"ts",
|
|
452
|
-
"mts",
|
|
453
|
-
"mjs",
|
|
454
|
-
"js"
|
|
455
|
-
].map((extension) => `prisma-composer.config.${extension}`);
|
|
456
|
-
const sectionMissing = {
|
|
457
|
-
code: "CONFIG.SECTION_MISSING",
|
|
458
|
-
summary: "No loaded prisma.config.ts declares a `composer` section.",
|
|
459
|
-
why: `${SECTION_IS_THE_ONLY_SOURCE} A prisma-composer.config.ts file is no longer read.`,
|
|
460
|
-
fix: MOVE_TO_SECTION_FIX
|
|
461
|
-
};
|
|
462
|
-
/** What the generated stack file throws when the file it imports has no `composer` export. */
|
|
463
|
-
function noComposerExportMessage(configFile) {
|
|
464
|
-
return `${configFile} declares no \`composer\` section. Pass the prisma.config.ts that declares it.`;
|
|
465
|
-
}
|
|
466
|
-
function configFileMissing(file) {
|
|
467
|
-
return {
|
|
468
|
-
code: "CONFIG.FILE_MISSING",
|
|
469
|
-
summary: `${file} does not exist.`,
|
|
470
|
-
fix: "Pass the path of the prisma.config.ts that declares the `composer` section.",
|
|
471
|
-
where: file
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
/** A prisma-composer.config.* beside the declaring file would otherwise be silently ignored. */
|
|
475
|
-
/** The path with symlinks resolved; the path itself when it cannot be resolved, so the check never throws. */
|
|
476
|
-
function realPath(file) {
|
|
477
|
-
try {
|
|
478
|
-
return fs.realpathSync(file);
|
|
479
|
-
} catch {
|
|
480
|
-
return file;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
function retiredFileFinding(configFile) {
|
|
484
|
-
const directory = path.dirname(realPath(configFile));
|
|
485
|
-
const found = RETIRED_FILE_NAMES.map((name) => path.join(directory, name)).find((file) => fs.existsSync(file));
|
|
486
|
-
if (found === void 0) return void 0;
|
|
487
|
-
return {
|
|
488
|
-
code: "CONFIG.FILE_RETIRED",
|
|
489
|
-
summary: `${found} is no longer read.`,
|
|
490
|
-
why: SECTION_IS_THE_ONLY_SOURCE,
|
|
491
|
-
fix: MOVE_TO_SECTION_FIX,
|
|
492
|
-
where: found
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
function isObject(value) {
|
|
496
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
497
|
-
}
|
|
498
|
-
function isExtensionDescriptor(value) {
|
|
499
|
-
return isObject(value) && typeof value["id"] === "string" && value["id"].length > 0 && isObject(value["nodes"]);
|
|
500
|
-
}
|
|
501
|
-
function isStateDescriptor(value) {
|
|
502
|
-
return isObject(value) && typeof value["extension"] === "string" && typeof value["create"] === "function";
|
|
503
|
-
}
|
|
504
|
-
const stateInvalid = {
|
|
505
|
-
code: "CONFIG.FIELD_INVALID",
|
|
506
|
-
summary: "`composer.state` must be a state descriptor with a string `extension` and a `create` function.",
|
|
507
|
-
fix: "Set `state` to the state descriptor an extension provides, e.g. `state: prismaState()`.",
|
|
508
|
-
field: "state"
|
|
509
|
-
};
|
|
510
|
-
function unknownField(key) {
|
|
511
|
-
return {
|
|
512
|
-
code: "CONFIG.FIELD_UNKNOWN",
|
|
513
|
-
summary: `The \`composer\` section has no field \`${key}\`.`,
|
|
514
|
-
fix: key === "composer" ? "Pass the `composer` property of the prisma.config.ts export, not the whole export. The section takes only `extensions` and `state`." : `Remove \`${key}\`. The section takes only \`extensions\` and \`state\`.`,
|
|
515
|
-
field: key
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
function checkExtensions(value) {
|
|
519
|
-
if (!Array.isArray(value)) return {
|
|
520
|
-
extensions: [],
|
|
521
|
-
findings: [{
|
|
522
|
-
code: "CONFIG.FIELD_INVALID",
|
|
523
|
-
summary: "`composer.extensions` must be an array of extension descriptors.",
|
|
524
|
-
fix: "Set `extensions` to the descriptors your extensions provide, e.g. `extensions: [nodeBuild()]`.",
|
|
525
|
-
field: "extensions"
|
|
526
|
-
}]
|
|
527
|
-
};
|
|
528
|
-
const findings = [];
|
|
529
|
-
const extensions = [];
|
|
530
|
-
const seen = /* @__PURE__ */ new Set();
|
|
531
|
-
for (const [index, entry] of value.entries()) {
|
|
532
|
-
const field = `extensions[${index}]`;
|
|
533
|
-
if (!isObject(entry)) {
|
|
534
|
-
findings.push({
|
|
535
|
-
code: "CONFIG.FIELD_INVALID",
|
|
536
|
-
summary: `\`composer.${field}\` must be an extension descriptor object.`,
|
|
537
|
-
fix: "Put the descriptor an extension factory returns here, e.g. `nodeBuild()`, not the factory itself.",
|
|
538
|
-
field
|
|
539
|
-
});
|
|
540
|
-
continue;
|
|
541
|
-
}
|
|
542
|
-
const id = entry["id"];
|
|
543
|
-
if (typeof id !== "string" || id.length === 0) findings.push({
|
|
544
|
-
code: "CONFIG.FIELD_INVALID",
|
|
545
|
-
summary: `\`composer.${field}.id\` must be a non-empty string (the extension package name).`,
|
|
546
|
-
fix: DESCRIPTOR_FIX,
|
|
547
|
-
field: `${field}.id`
|
|
548
|
-
});
|
|
549
|
-
else if (seen.has(id)) findings.push({
|
|
550
|
-
code: "CONFIG.EXTENSION_DUPLICATE",
|
|
551
|
-
summary: `Extension "${id}" is listed more than once in \`composer.extensions\`.`,
|
|
552
|
-
fix: `Remove the repeated "${id}" entry from \`extensions\`.`,
|
|
553
|
-
field: `${field}.id`
|
|
554
|
-
});
|
|
555
|
-
else seen.add(id);
|
|
556
|
-
if (!isObject(entry["nodes"])) findings.push({
|
|
557
|
-
code: "CONFIG.FIELD_INVALID",
|
|
558
|
-
summary: `\`composer.${field}.nodes\` must be an object (the node-ID → control registry).`,
|
|
559
|
-
fix: DESCRIPTOR_FIX,
|
|
560
|
-
field: `${field}.nodes`
|
|
561
|
-
});
|
|
562
|
-
if (isExtensionDescriptor(entry)) extensions.push(entry);
|
|
563
|
-
}
|
|
564
|
-
return {
|
|
565
|
-
findings,
|
|
566
|
-
extensions
|
|
567
|
-
};
|
|
568
|
-
}
|
|
569
|
-
function checkFields(section) {
|
|
570
|
-
if (Object.hasOwn(section, "configPath")) return {
|
|
571
|
-
ok: false,
|
|
572
|
-
findings: [{
|
|
573
|
-
code: "CONFIG.FIELD_RETIRED",
|
|
574
|
-
summary: "`composer.configPath` is no longer supported: prisma-composer.config.ts is no longer read.",
|
|
575
|
-
why: SECTION_IS_THE_ONLY_SOURCE,
|
|
576
|
-
fix: `Replace \`configPath\` with the section itself. ${MOVE_TO_SECTION_FIX}`,
|
|
577
|
-
field: "configPath"
|
|
578
|
-
}]
|
|
579
|
-
};
|
|
580
|
-
if (Object.hasOwn(section, "composer")) return {
|
|
581
|
-
ok: false,
|
|
582
|
-
findings: [unknownField("composer")]
|
|
583
|
-
};
|
|
584
|
-
const findings = Object.keys(section).filter((key) => key !== "extensions" && key !== "state").map(unknownField);
|
|
585
|
-
const checked = checkExtensions(section["extensions"]);
|
|
586
|
-
findings.push(...checked.findings);
|
|
587
|
-
const state = section["state"];
|
|
588
|
-
if (!isStateDescriptor(state)) findings.push(stateInvalid);
|
|
589
|
-
const [first, ...rest] = findings;
|
|
590
|
-
if (first === void 0 && isStateDescriptor(state)) return {
|
|
591
|
-
ok: true,
|
|
592
|
-
value: {
|
|
593
|
-
extensions: checked.extensions,
|
|
594
|
-
state
|
|
595
|
-
}
|
|
596
|
-
};
|
|
597
|
-
return {
|
|
598
|
-
ok: false,
|
|
599
|
-
findings: [first ?? stateInvalid, ...rest]
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
/**
|
|
603
|
-
* Checks the fields that identify each descriptor and returns the descriptors as the config file's own objects.
|
|
604
|
-
* Never throws: a section's values are user code, and a throwing getter or Proxy trap becomes a finding.
|
|
605
|
-
*/
|
|
606
|
-
function checkComposerSection(raw) {
|
|
607
|
-
if (!isObject(raw)) return {
|
|
608
|
-
ok: false,
|
|
609
|
-
findings: [{
|
|
610
|
-
code: "CONFIG.FIELD_INVALID",
|
|
611
|
-
summary: "The `composer` section of prisma.config.ts must be an object.",
|
|
612
|
-
fix: SECTION_FIX
|
|
613
|
-
}]
|
|
614
|
-
};
|
|
615
|
-
try {
|
|
616
|
-
return checkFields({ ...raw });
|
|
617
|
-
} catch (cause) {
|
|
618
|
-
return {
|
|
619
|
-
ok: false,
|
|
620
|
-
findings: [{
|
|
621
|
-
code: "CONFIG.FIELD_INVALID",
|
|
622
|
-
summary: "The `composer` section of prisma.config.ts could not be read.",
|
|
623
|
-
why: `Reading it threw: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
624
|
-
fix: SECTION_FIX
|
|
625
|
-
}]
|
|
626
|
-
};
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
/**
|
|
630
|
-
* The whole check, shared by the section validator and the programmatic operations so both report the same findings in the same order: the retired file beside the declaring `configFile` (resolved through symlinks), then every field finding.
|
|
631
|
-
*/
|
|
632
|
-
function checkComposerConfig(raw, configFile) {
|
|
633
|
-
const retired = retiredFileFinding(configFile);
|
|
634
|
-
const checked = checkComposerSection(raw);
|
|
635
|
-
if (retired === void 0) return checked;
|
|
636
|
-
return {
|
|
637
|
-
ok: false,
|
|
638
|
-
findings: checked.ok ? [retired] : [retired, ...checked.findings]
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
//#endregion
|
|
642
|
-
export { alchemyCommandLine as a, spawnAlchemy as c, ok as d, okVoid as f, sectionMissing as i, CliStructuredError as l, blindCast as m, configFileMissing as n, alchemyInvocation as o, InternalError as p, noComposerExportMessage as r, reproduceCommand as s, checkComposerConfig as t, notOk as u };
|
|
665
|
+
export { notOk as a, CliStructuredError as c, checkComposerConfig as d, configFileMissing as f, sectionMissing as h, spawnAlchemy as i, InternalError as l, noComposerExportMessage as m, alchemyInvocation as n, ok as o, entryMissing as p, reproduceCommand as r, okVoid as s, alchemyCommandLine as t, blindCast as u };
|
|
643
666
|
|
|
644
|
-
//# sourceMappingURL=
|
|
667
|
+
//# sourceMappingURL=run-alchemy-Dl_MWw4g-DaWV9tkH.mjs.map
|