@prisma/orm-toolchain 8.0.0-rc.16-dev.5 → 8.0.0-rc.16-dev.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{aggregate-DLptsx8n.d.mts → aggregate-BGdw05Nj.d.mts} +20 -3
- package/dist/{aggregate-DLptsx8n.d.mts.map → aggregate-BGdw05Nj.d.mts.map} +1 -1
- package/dist/{aggregate-C7IHVcsV.mjs → aggregate-CG8Nfsg1.mjs} +26 -7
- package/dist/aggregate-CG8Nfsg1.mjs.map +1 -0
- package/dist/{caught-errors-N266GMql-B7p73Xyj.mjs → caught-errors-DHRx2eml-Az6yWv1r.mjs} +86 -8
- package/dist/caught-errors-DHRx2eml-Az6yWv1r.mjs.map +1 -0
- package/dist/cli-telemetry.mjs +1 -1
- package/dist/cli.mjs +57 -13
- package/dist/cli.mjs.map +1 -1
- package/dist/cli__control-api.d.mts +54 -5
- package/dist/cli__control-api.d.mts.map +1 -1
- package/dist/cli__control-api.mjs +3 -3
- package/dist/cli__control-api__testing.d.mts +1 -1
- package/dist/cli__control-api__testing.mjs +1 -0
- package/dist/cli__control-api__testing.mjs.map +1 -1
- package/dist/cli__migration-cli.d.mts +1 -1
- package/dist/cli__migration-cli.mjs +3 -3
- package/dist/cli__migration-cli.mjs.map +1 -1
- package/dist/config-loader.mjs +1 -1
- package/dist/{contract-snapshot-store-1S_6vaGt-CQPNFWho.mjs → contract-snapshot-store-1S_6vaGt-HJIMKsVd.mjs} +2 -2
- package/dist/{contract-snapshot-store-1S_6vaGt-CQPNFWho.mjs.map → contract-snapshot-store-1S_6vaGt-HJIMKsVd.mjs.map} +1 -1
- package/dist/{db-sign-BxYV7wMQ-CNy01Yj7.d.mts → db-sign-DqskX43K-CtEwW2Y6.d.mts} +36 -4
- package/dist/db-sign-DqskX43K-CtEwW2Y6.d.mts.map +1 -0
- package/dist/emitter.mjs +1 -1
- package/dist/{exports-02v-utfh.mjs → exports-Bd3uWDtm.mjs} +2 -2
- package/dist/{exports-02v-utfh.mjs.map → exports-Bd3uWDtm.mjs.map} +1 -1
- package/dist/{exports-Ca10vlXU.mjs → exports-C7GzkPEc.mjs} +3 -3
- package/dist/{exports-Ca10vlXU.mjs.map → exports-C7GzkPEc.mjs.map} +1 -1
- package/dist/{exports-B41NJHCo-BaEu3TXy.mjs → exports-DaDckULH-JNQeM6Nn.mjs} +30 -5
- package/dist/exports-DaDckULH-JNQeM6Nn.mjs.map +1 -0
- package/dist/{io-xKnQrxIC-BPHEfarH.mjs → io-xKnQrxIC-CEXpCgE_.mjs} +3 -3
- package/dist/{io-xKnQrxIC-BPHEfarH.mjs.map → io-xKnQrxIC-CEXpCgE_.mjs.map} +1 -1
- package/dist/{migration-B2ljMJim.d.mts → migration-Bjz05034.d.mts} +12 -5
- package/dist/migration-Bjz05034.d.mts.map +1 -0
- package/dist/{migration-DaFjTC8t.mjs → migration-oIynqb-J.mjs} +14 -2
- package/dist/migration-oIynqb-J.mjs.map +1 -0
- package/dist/migration-tools.d.mts +3 -3
- package/dist/migration-tools.mjs +9 -9
- package/dist/migration-tools__aggregate.d.mts +2 -2
- package/dist/migration-tools__aggregate.mjs +1 -1
- package/dist/migration-tools__contract-snapshot-store.mjs +1 -1
- package/dist/migration-tools__io.mjs +1 -1
- package/dist/migration-tools__migration-ts.mjs +1 -1
- package/dist/migration-tools__migration.d.mts +1 -1
- package/dist/migration-tools__migration.mjs +1 -1
- package/dist/migration-tools__ref-resolution.mjs +1 -1
- package/dist/migration-tools__refs.mjs +1 -1
- package/dist/migration-tools__spaces.mjs +2 -2
- package/dist/{migration-ts-BQuIba9e.mjs → migration-ts-FyF55c4M.mjs} +2 -2
- package/dist/{migration-ts-BQuIba9e.mjs.map → migration-ts-FyF55c4M.mjs.map} +1 -1
- package/dist/{ref-BCEAH4F9-Dxp5Czpw.mjs → ref-QYB51IgO-ywgKx10n.mjs} +606 -32
- package/dist/ref-QYB51IgO-ywgKx10n.mjs.map +1 -0
- package/dist/{ref-resolution-d7rcmU6F.mjs → ref-resolution-Be_zewf7.mjs} +2 -2
- package/dist/{ref-resolution-d7rcmU6F.mjs.map → ref-resolution-Be_zewf7.mjs.map} +1 -1
- package/dist/{refs-qwvw4_dV-X8sR92eT.mjs → refs-qwvw4_dV-DNg_7WTD.mjs} +2 -2
- package/dist/{refs-qwvw4_dV-X8sR92eT.mjs.map → refs-qwvw4_dV-DNg_7WTD.mjs.map} +1 -1
- package/dist/{spaces-CzLQQYa9.mjs → spaces-DGu96Hkk.mjs} +5 -5
- package/dist/{spaces-CzLQQYa9.mjs.map → spaces-DGu96Hkk.mjs.map} +1 -1
- package/dist/{verify-contract-spaces-CYjc343k-FXABEJZE.mjs → verify-contract-spaces-CYjc343k-ClHHEkJF.mjs} +3 -3
- package/dist/{verify-contract-spaces-CYjc343k-FXABEJZE.mjs.map → verify-contract-spaces-CYjc343k-ClHHEkJF.mjs.map} +1 -1
- package/dist/vite-plugin-contract-emit.mjs +3 -3
- package/package.json +12 -12
- package/dist/aggregate-C7IHVcsV.mjs.map +0 -1
- package/dist/caught-errors-N266GMql-B7p73Xyj.mjs.map +0 -1
- package/dist/db-sign-BxYV7wMQ-CNy01Yj7.d.mts.map +0 -1
- package/dist/exports-B41NJHCo-BaEu3TXy.mjs.map +0 -1
- package/dist/migration-B2ljMJim.d.mts.map +0 -1
- package/dist/migration-DaFjTC8t.mjs.map +0 -1
- package/dist/ref-BCEAH4F9-Dxp5Czpw.mjs.map +0 -1
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
import { i as expandContractInputs } from "./exports-
|
|
1
|
+
import { i as expandContractInputs } from "./exports-C7GzkPEc.mjs";
|
|
2
2
|
import { D as errorNoInvariantPath, M as errorUnknownInvariant, b as errorInvalidRefName, r as errorContractDeserializationFailed, t as MigrationToolsError } from "./errors-DD6iLGXk-6I9PqjpZ.mjs";
|
|
3
3
|
import { r as verifyMigrationHash, t as computeMigrationHash } from "./hash-BAZVWU4a-BQovI7hF.mjs";
|
|
4
|
-
import { a as snapshotsImportPathFrom, n as createSnapshotContentVerifier, o as writeContractSnapshot, r as readContractSnapshotJson, t as contractSnapshotDir } from "./contract-snapshot-store-1S_6vaGt-
|
|
4
|
+
import { a as snapshotsImportPathFrom, n as createSnapshotContentVerifier, o as writeContractSnapshot, r as readContractSnapshotJson, t as contractSnapshotDir } from "./contract-snapshot-store-1S_6vaGt-HJIMKsVd.mjs";
|
|
5
5
|
import { t as deriveProvidedInvariants } from "./invariants-C0lpc60l-CMUCvk4O.mjs";
|
|
6
|
-
import { i as materialiseExtensionMigrationPackageIfMissing, r as formatMigrationDirName, u as writeMigrationPackage } from "./io-xKnQrxIC-
|
|
6
|
+
import { i as materialiseExtensionMigrationPackageIfMissing, r as formatMigrationDirName, u as writeMigrationPackage } from "./io-xKnQrxIC-CEXpCgE_.mjs";
|
|
7
7
|
import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
|
|
8
8
|
import { i as findPathWithDecision, r as findPath } from "./migration-graph-BoiiZAaU-DLht12k7.mjs";
|
|
9
|
-
import { a as isValidSpaceId, c as spaceMigrationDirectory, l as spaceRefsDirectory, o as listContractSpaceDirectories, s as readContractSpaceHeadRef, t as APP_SPACE_ID$1 } from "./verify-contract-spaces-CYjc343k-
|
|
10
|
-
import { i as emitContractSpaceArtifacts, o as planAllSpaces } from "./spaces-
|
|
11
|
-
import { A as errorPlanProducedNoOperations, D as errorPathUnreachable, F as errorRuntime, G as
|
|
12
|
-
import { r as getEmittedArtifactPaths, t as emit } from "./exports-
|
|
9
|
+
import { a as isValidSpaceId, c as spaceMigrationDirectory, l as spaceRefsDirectory, o as listContractSpaceDirectories, s as readContractSpaceHeadRef, t as APP_SPACE_ID$1 } from "./verify-contract-spaces-CYjc343k-ClHHEkJF.mjs";
|
|
10
|
+
import { i as emitContractSpaceArtifacts, o as planAllSpaces } from "./spaces-DGu96Hkk.mjs";
|
|
11
|
+
import { $ as runCommandAction, A as errorPlanProducedNoOperations, B as errorStatementOriginUnknown, D as errorPathUnreachable, F as errorRuntime, G as getTargetMigrations, H as errorTargetMigrationNotSupported, J as readContractEnvelope, K as mapRefResolutionError, L as errorSnapshotMissing, M as errorRefSetEmptySentinel, N as errorRefSetHashNotInGraph, O as errorPlanForgotTheFlag, Q as resolveMigrationPaths, R as errorSpaceNotFound, S as errorMarkerMismatch, T as errorMigrationPlanningFailed, V as errorStatementUnresolved, W as errorUnexpected, X as requireLiveDatabase, Z as resolveContractPath, _ as errorFileNotFound, a as closeQuietly, b as errorInvalidSpaceId, c as errorAmbiguousMigrationRef, f as errorContractConfigMissing, h as errorDestructiveChanges, i as chooseAction, j as errorRefSetBundleNotFound, k as errorPlanOriginUnknown, l as errorConfigValidation$1, n as CliStructuredError$1, o as collectDeclaredInvariants, p as errorContractValidationFailed, tt as toStructuralEdge, u as errorConsentPlanMismatch, v as errorFromCaught, z as errorStatementInvalid } from "./caught-errors-DHRx2eml-Az6yWv1r.mjs";
|
|
12
|
+
import { r as getEmittedArtifactPaths, t as emit } from "./exports-DaDckULH-JNQeM6Nn.mjs";
|
|
13
13
|
import { n as isGraphNode, t as assertHashIsGraphNode } from "./graph-membership-C_ZO26nT-B7C4CJsh.mjs";
|
|
14
|
-
import { d as writeRef, i as readRefs, l as validateRefName, n as deleteRef, o as refsByContractHash, t as HEAD_REF_NAME, u as validateRefValue } from "./refs-qwvw4_dV-
|
|
15
|
-
import { a as contractHashAtMarker, c as loadContractSpaceAggregate, d as requireHeadRef, f as resolveRecordedPath, m as verifyMigration, n as buildFabricatedMigrationEdge, p as spacesInApplyOrder, r as collectAggregateNamespaces, t as allStorageElementsExternal, u as planMigration } from "./aggregate-
|
|
14
|
+
import { d as writeRef, i as readRefs, l as validateRefName, n as deleteRef, o as refsByContractHash, t as HEAD_REF_NAME, u as validateRefValue } from "./refs-qwvw4_dV-DNg_7WTD.mjs";
|
|
15
|
+
import { a as contractHashAtMarker, c as loadContractSpaceAggregate, d as requireHeadRef, f as resolveRecordedPath, m as verifyMigration, n as buildFabricatedMigrationEdge, p as spacesInApplyOrder, r as collectAggregateNamespaces, t as allStorageElementsExternal, u as planMigration } from "./aggregate-CG8Nfsg1.mjs";
|
|
16
16
|
import { c as internalImportRoot, o as importRootForDependencies, r as createImportSpecifierResolver, t as ImportRootError } from "./import-roots-BeAYfehL.mjs";
|
|
17
|
-
import { c as parseContractRef, l as parseMigrationRef, o as isLiveMarkerRef, r as RESERVED_CONTRACT_REFS, s as isReservedContractRef, t as EMPTY_CONTRACT_REF } from "./ref-resolution-
|
|
18
|
-
import { i as writeMigrationTs } from "./migration-ts-
|
|
17
|
+
import { c as parseContractRef, l as parseMigrationRef, o as isLiveMarkerRef, r as RESERVED_CONTRACT_REFS, s as isReservedContractRef, t as EMPTY_CONTRACT_REF } from "./ref-resolution-Be_zewf7.mjs";
|
|
18
|
+
import { i as writeMigrationTs } from "./migration-ts-FyF55c4M.mjs";
|
|
19
19
|
import { createRequire } from "node:module";
|
|
20
20
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
21
21
|
import { CliStructuredError } from "@prisma/orm-framework/errors/control";
|
|
22
|
-
import { APP_SPACE_ID, createControlStack, hasMigrations, hasOperationPreview, hasPslContractInfer, hasSchemaSubjectClassifier, hasSchemaView } from "@prisma/orm-framework/components/control";
|
|
22
|
+
import { APP_SPACE_ID, CONTRACT_SNAPSHOTS_DIRNAME, createControlStack, describeMigrationStatement, hasMigrations, hasOperationPreview, hasPslContractInfer, hasSchemaSubjectClassifier, hasSchemaView, isStorageHashHex, migrationStatementJson, modelDisplayName, planOriginOf } from "@prisma/orm-framework/components/control";
|
|
23
23
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
24
24
|
import { isStructuredErrorCode, structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
25
|
-
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
26
25
|
import { basename, dirname, isAbsolute, join, relative, resolve } from "pathe";
|
|
26
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
27
27
|
import { createHash } from "node:crypto";
|
|
28
28
|
import { canonicalizeJson } from "@prisma/orm-framework/components/utils";
|
|
29
29
|
import { blindCast, castAs } from "@prisma/orm-framework/utils/casts";
|
|
30
30
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
31
31
|
import { keepInternalSpecifiers } from "@prisma/orm-framework/components/emission";
|
|
32
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma/orm-framework/components/ir";
|
|
32
33
|
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
33
34
|
import { mergeCapabilityMatrices } from "@prisma/orm-framework/components/components";
|
|
35
|
+
import { asNamespaceId } from "@prisma/orm-framework/contract/types";
|
|
34
36
|
import { abortable } from "@prisma/orm-framework/utils/abortable";
|
|
35
37
|
import { resolve as resolve$1 } from "node:path";
|
|
36
|
-
//#region ../../../1-framework/3-tooling/cli/dist/ref-
|
|
38
|
+
//#region ../../../1-framework/3-tooling/cli/dist/ref-QYB51IgO.mjs
|
|
37
39
|
/**
|
|
38
40
|
* Asserts that all framework components are compatible with the expected family and target.
|
|
39
41
|
*
|
|
@@ -167,6 +169,418 @@ function enrichContract(ir, components) {
|
|
|
167
169
|
};
|
|
168
170
|
}
|
|
169
171
|
/**
|
|
172
|
+
* `operationOffset` is the number of operations the result lists before the plan that applied the
|
|
173
|
+
* statements, so that each position indexes the result's `operations`.
|
|
174
|
+
*/
|
|
175
|
+
function reportAppliedStatements(applied, fromContract, contract, operationOffset) {
|
|
176
|
+
return applied.map((entry) => ({
|
|
177
|
+
statement: migrationStatementJson(entry.statement),
|
|
178
|
+
operationIndexes: entry.operationIndexes.map((index) => operationOffset + index),
|
|
179
|
+
description: describeMigrationStatement(entry.statement, fromContract ?? contract, contract)
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
const MAX_SEGMENTS = 3;
|
|
183
|
+
/** The forms a statement takes, with an example of each. */
|
|
184
|
+
function statementFormsFix(verb) {
|
|
185
|
+
return `Write the statement as --${verb} <old>:<new>, where each side is Model, namespace.Model, Model.field or namespace.Model.field, for example --${verb} Profile:User for a model or --${verb} User.name:User.fullName for a field.`;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The two statements a user who named a model on one side and a field on the other may have
|
|
189
|
+
* meant, written with their names.
|
|
190
|
+
*/
|
|
191
|
+
function mixedSidesFix(verb, from, to) {
|
|
192
|
+
const modelIsOld = from.length < to.length;
|
|
193
|
+
const field = modelIsOld ? to : from;
|
|
194
|
+
const model = (modelIsOld ? from : to).join(".");
|
|
195
|
+
const fieldModel = field.slice(0, -1).join(".");
|
|
196
|
+
const fieldName = field[field.length - 1];
|
|
197
|
+
const [modelStatement, fieldStatement] = modelIsOld ? [`${model}:${fieldModel}`, `${fieldModel}.<old field>:${field.join(".")}`] : [`${fieldModel}:${model}`, `${model}.${fieldName}:${model}.<new field>`];
|
|
198
|
+
return `To rename the model, write --${verb} ${modelStatement}. To rename a field, write --${verb} ${fieldStatement}, naming the field's model as the new contract names it.`;
|
|
199
|
+
}
|
|
200
|
+
function invalid(statement, why) {
|
|
201
|
+
return errorStatementInvalid(statement, why, statementFormsFix(statement.verb));
|
|
202
|
+
}
|
|
203
|
+
function parseSide(statement, side) {
|
|
204
|
+
const segments = side.split(".");
|
|
205
|
+
if (segments.some((segment) => segment === "")) return notOk(invalid(statement, `"${side}" has an empty name.`));
|
|
206
|
+
const [first, second, third] = segments;
|
|
207
|
+
if (first === void 0 || segments.length > MAX_SEGMENTS) return notOk(invalid(statement, `"${side}" has ${segments.length} names; at most three are allowed.`));
|
|
208
|
+
if (second === void 0) return ok([first]);
|
|
209
|
+
if (third === void 0) return ok([first, second]);
|
|
210
|
+
return ok([
|
|
211
|
+
first,
|
|
212
|
+
second,
|
|
213
|
+
third
|
|
214
|
+
]);
|
|
215
|
+
}
|
|
216
|
+
function namesModelAndField(from, to) {
|
|
217
|
+
const lengths = [from.length, to.length];
|
|
218
|
+
return lengths.includes(1) && lengths.includes(MAX_SEGMENTS);
|
|
219
|
+
}
|
|
220
|
+
/** Parses the text of one rename statement, `<old>:<new>`. */
|
|
221
|
+
function parseRenameStatement(statement) {
|
|
222
|
+
const sides = statement.text.split(":");
|
|
223
|
+
const [oldSide, newSide] = sides;
|
|
224
|
+
if (oldSide === void 0 || newSide === void 0) return notOk(invalid(statement, "The statement has no \":\" between the old and new name."));
|
|
225
|
+
if (sides.length > 2) return notOk(invalid(statement, "The statement has more than one \":\"."));
|
|
226
|
+
const from = parseSide(statement, oldSide);
|
|
227
|
+
if (!from.ok) return from;
|
|
228
|
+
const to = parseSide(statement, newSide);
|
|
229
|
+
if (!to.ok) return to;
|
|
230
|
+
if (namesModelAndField(from.value, to.value)) return notOk(errorStatementInvalid(statement, "The statement names a model on one side and a field on the other.", mixedSidesFix(statement.verb, from.value, to.value)));
|
|
231
|
+
return ok({
|
|
232
|
+
verb: "rename",
|
|
233
|
+
text: statement.text,
|
|
234
|
+
from: from.value,
|
|
235
|
+
to: to.value
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
const MODEL_RENAMES = "model";
|
|
239
|
+
const FIELD_RENAMES = "field";
|
|
240
|
+
const LISTED_LIMIT = 20;
|
|
241
|
+
const CHECK_NAMES_FIX = "The old name must exist in the origin contract and not in the destination contract, and the new name the other way round. Names match exactly, including case.";
|
|
242
|
+
const STORED_NAME_ONLY = "If only the stored name changed (@map or @@map), a statement cannot state that in this release, and a plan without it drops and creates what the model or field is stored in, with its data. With migration plan, edit the planned migration.ts to rename the stored name instead of dropping and creating it. With db update, rename it in the database yourself first, then run db update, which then finds nothing that loses data.";
|
|
243
|
+
const VALUE_OBJECT_FIX = "Leave value objects and their fields out of the statements.";
|
|
244
|
+
const REPEATED_NAME_FIX = "Give each model or field at most one statement, and each new name to one model or field only.";
|
|
245
|
+
function qualifiedModel(coordinate) {
|
|
246
|
+
return modelDisplayName(coordinate);
|
|
247
|
+
}
|
|
248
|
+
function displayName(namespaceId, name) {
|
|
249
|
+
return modelDisplayName({
|
|
250
|
+
namespaceId: asNamespaceId(namespaceId),
|
|
251
|
+
model: name
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
function qualifiedField(coordinate) {
|
|
255
|
+
return `${qualifiedModel(coordinate)}.${coordinate.field}`;
|
|
256
|
+
}
|
|
257
|
+
function listed(names) {
|
|
258
|
+
if (names.length === 0) return "(none)";
|
|
259
|
+
const sorted = [...names].sort();
|
|
260
|
+
const shown = sorted.slice(0, LISTED_LIMIT).join(", ");
|
|
261
|
+
return sorted.length > LISTED_LIMIT ? `${shown} and ${sorted.length - LISTED_LIMIT} more` : shown;
|
|
262
|
+
}
|
|
263
|
+
function sentence(reason) {
|
|
264
|
+
return `${reason.charAt(0).toUpperCase()}${reason.slice(1)}.`;
|
|
265
|
+
}
|
|
266
|
+
function unresolved(statement, refusal) {
|
|
267
|
+
return errorStatementUnresolved(statement, sentence(refusal.reason), refusal.fix);
|
|
268
|
+
}
|
|
269
|
+
function modelIn(namespace, name) {
|
|
270
|
+
return Object.hasOwn(namespace.models, name) ? namespace.models[name] : void 0;
|
|
271
|
+
}
|
|
272
|
+
function hasValueObject(namespace, name) {
|
|
273
|
+
return namespace.valueObjects !== void 0 && Object.hasOwn(namespace.valueObjects, name);
|
|
274
|
+
}
|
|
275
|
+
function modelAt(contract, coordinate) {
|
|
276
|
+
const namespaces = contract.domain.namespaces;
|
|
277
|
+
const namespace = Object.hasOwn(namespaces, coordinate.namespaceId) ? namespaces[coordinate.namespaceId] : void 0;
|
|
278
|
+
return namespace === void 0 ? void 0 : modelIn(namespace, coordinate.model);
|
|
279
|
+
}
|
|
280
|
+
function fieldNames(model) {
|
|
281
|
+
return [...Object.keys(model.fields), ...Object.keys(model.relations)];
|
|
282
|
+
}
|
|
283
|
+
function hasField(model, field) {
|
|
284
|
+
return Object.hasOwn(model.fields, field) || Object.hasOwn(model.relations, field);
|
|
285
|
+
}
|
|
286
|
+
function missing(reason) {
|
|
287
|
+
return {
|
|
288
|
+
reason,
|
|
289
|
+
fix: CHECK_NAMES_FIX
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function valueObjectRefusal(name) {
|
|
293
|
+
return {
|
|
294
|
+
reason: `"${name}" is a value object, and value object renames are not supported in this release`,
|
|
295
|
+
fix: VALUE_OBJECT_FIX
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function lookupModelInNamespace(contract, namespaceId, namespace, name) {
|
|
299
|
+
const model = modelIn(namespace, name);
|
|
300
|
+
if (model !== void 0) return {
|
|
301
|
+
kind: "found",
|
|
302
|
+
coordinate: {
|
|
303
|
+
namespaceId: asNamespaceId(namespaceId),
|
|
304
|
+
model: name
|
|
305
|
+
},
|
|
306
|
+
model
|
|
307
|
+
};
|
|
308
|
+
if (hasValueObject(namespace, name)) return {
|
|
309
|
+
kind: "refused",
|
|
310
|
+
...valueObjectRefusal(displayName(namespaceId, name))
|
|
311
|
+
};
|
|
312
|
+
return {
|
|
313
|
+
kind: "missing",
|
|
314
|
+
...missing(`the ${contract.name} contract has no model "${name}" in namespace "${namespaceId}" (models there: ${listed(Object.keys(namespace.models))})`)
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
function lookupModel(contract, namespaceId, name) {
|
|
318
|
+
const namespaces = contract.contract.domain.namespaces;
|
|
319
|
+
if (namespaceId !== void 0) {
|
|
320
|
+
const namespace = Object.hasOwn(namespaces, namespaceId) ? namespaces[namespaceId] : void 0;
|
|
321
|
+
if (namespace === void 0) {
|
|
322
|
+
const named = Object.keys(namespaces).filter((id) => id !== UNBOUND_NAMESPACE_ID);
|
|
323
|
+
return {
|
|
324
|
+
kind: "missing",
|
|
325
|
+
...missing(named.length === 0 ? `the ${contract.name} contract has no namespaces` : `the ${contract.name} contract has no namespace "${namespaceId}" (namespaces: ${listed(named)})`)
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
return lookupModelInNamespace(contract, namespaceId, namespace, name);
|
|
329
|
+
}
|
|
330
|
+
const declaring = Object.entries(namespaces).filter(([, namespace]) => modelIn(namespace, name) !== void 0);
|
|
331
|
+
const [only] = declaring;
|
|
332
|
+
if (only !== void 0 && declaring.length === 1) return lookupModelInNamespace(contract, only[0], only[1], name);
|
|
333
|
+
if (declaring.length > 1) {
|
|
334
|
+
const candidates = declaring.map(([id]) => `${id}.${name}`).sort();
|
|
335
|
+
return {
|
|
336
|
+
kind: "refused",
|
|
337
|
+
reason: `"${name}" is a model in more than one namespace of the ${contract.name} contract (${listed(candidates)})`,
|
|
338
|
+
fix: `Name the model with its namespace, for example ${candidates[0]}.`
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
if (Object.values(namespaces).some((namespace) => hasValueObject(namespace, name))) return {
|
|
342
|
+
kind: "refused",
|
|
343
|
+
...valueObjectRefusal(name)
|
|
344
|
+
};
|
|
345
|
+
const models = Object.entries(namespaces).flatMap(([id, namespace]) => Object.keys(namespace.models).map((model) => displayName(id, model)));
|
|
346
|
+
return {
|
|
347
|
+
kind: "missing",
|
|
348
|
+
...missing(`the ${contract.name} contract has no model "${name}" (models: ${listed(models)})`)
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function readModel(state, side, namespaceId, name) {
|
|
352
|
+
const lookup = lookupModel(side === "old" ? state.origin : state.destination, namespaceId, name);
|
|
353
|
+
if (lookup.kind !== "found") return notOk(lookup);
|
|
354
|
+
return ok({
|
|
355
|
+
entity: "model",
|
|
356
|
+
coordinate: lookup.coordinate,
|
|
357
|
+
model: lookup.model
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
function readFieldOf(contract, found, field, destinationModel) {
|
|
361
|
+
if (!hasField(found.model, field)) return notOk(missing(`the ${contract.name} model "${qualifiedModel(found.coordinate)}" has no field "${field}" (fields: ${listed(fieldNames(found.model))})`));
|
|
362
|
+
return ok({
|
|
363
|
+
entity: "field",
|
|
364
|
+
coordinate: {
|
|
365
|
+
...found.coordinate,
|
|
366
|
+
field
|
|
367
|
+
},
|
|
368
|
+
model: found.model,
|
|
369
|
+
destinationModel
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
function originCounterpart(state, destinationModel) {
|
|
373
|
+
const coordinate = state.originOfRenamedModel.get(qualifiedModel(destinationModel)) ?? destinationModel;
|
|
374
|
+
const model = modelAt(state.origin.contract, coordinate);
|
|
375
|
+
return model === void 0 ? void 0 : {
|
|
376
|
+
coordinate,
|
|
377
|
+
model
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* The old side of a field rename names the model as the destination spells
|
|
382
|
+
* it, and the field as the origin counterpart of that model has it. When the
|
|
383
|
+
* model is not in the destination but the origin has it with that field, the
|
|
384
|
+
* reading still resolves so the caller can say the field would move between
|
|
385
|
+
* models.
|
|
386
|
+
*/
|
|
387
|
+
function readOldField(state, namespaceId, modelName, field) {
|
|
388
|
+
const destination = lookupModel(state.destination, namespaceId, modelName);
|
|
389
|
+
if (destination.kind === "found") {
|
|
390
|
+
const counterpart = originCounterpart(state, destination.coordinate);
|
|
391
|
+
if (counterpart === void 0) {
|
|
392
|
+
const name = qualifiedModel(destination.coordinate);
|
|
393
|
+
return notOk({
|
|
394
|
+
reason: `the destination model "${name}" has no counterpart in the origin contract: the origin has no model "${name}" and no earlier statement renames a model to it`,
|
|
395
|
+
fix: `Rename the origin model to "${name}" with its own --rename statement before this one, or check the names.`,
|
|
396
|
+
modelWithoutCounterpart: name
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
return readFieldOf(state.origin, counterpart, field, destination.coordinate);
|
|
400
|
+
}
|
|
401
|
+
if (destination.kind === "refused") return notOk(destination);
|
|
402
|
+
const origin = lookupModel(state.origin, namespaceId, modelName);
|
|
403
|
+
if (origin.kind === "found" && hasField(origin.model, field)) return readFieldOf(state.origin, origin, field, void 0);
|
|
404
|
+
return notOk(destination);
|
|
405
|
+
}
|
|
406
|
+
function readNewField(state, namespaceId, modelName, field) {
|
|
407
|
+
const destination = lookupModel(state.destination, namespaceId, modelName);
|
|
408
|
+
if (destination.kind !== "found") return notOk(destination);
|
|
409
|
+
return readFieldOf(state.destination, destination, field, destination.coordinate);
|
|
410
|
+
}
|
|
411
|
+
function readField(state, side, namespaceId, modelName, field) {
|
|
412
|
+
return side === "old" ? readOldField(state, namespaceId, modelName, field) : readNewField(state, namespaceId, modelName, field);
|
|
413
|
+
}
|
|
414
|
+
function readSide(state, side, segments) {
|
|
415
|
+
if (segments.length === 1) return readModel(state, side, void 0, segments[0]);
|
|
416
|
+
if (segments.length === 3) return readField(state, side, ...segments);
|
|
417
|
+
const [first, second] = segments;
|
|
418
|
+
const asModel = readModel(state, side, first, second);
|
|
419
|
+
const asField = readField(state, side, void 0, first, second);
|
|
420
|
+
if (asModel.ok && asField.ok) return notOk({
|
|
421
|
+
reason: `"${first}.${second}" resolves both as namespace "${first}" model "${second}" and as model "${first}" field "${second}"`,
|
|
422
|
+
fix: "Write the field as namespace.Model.field if you mean the field."
|
|
423
|
+
});
|
|
424
|
+
if (asModel.ok) return asModel;
|
|
425
|
+
if (asField.ok) return asField;
|
|
426
|
+
const contract = side === "old" ? state.origin : state.destination;
|
|
427
|
+
if (!Object.keys(contract.contract.domain.namespaces).some((id) => id !== UNBOUND_NAMESPACE_ID)) return asField;
|
|
428
|
+
return notOk({
|
|
429
|
+
...missing(`"${first}.${second}" resolves neither as namespace.Model (${asModel.failure.reason}) nor as Model.field (${asField.failure.reason})`),
|
|
430
|
+
...ifDefined("modelWithoutCounterpart", asField.failure.modelWithoutCounterpart)
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
function resolveModelRename(state, statement, from, to) {
|
|
434
|
+
const fromKey = `${MODEL_RENAMES}:${qualifiedModel(from)}`;
|
|
435
|
+
const toKey = `${MODEL_RENAMES}:${qualifiedModel(to)}`;
|
|
436
|
+
if (state.renamedFrom.has(fromKey)) return notOk(errorStatementInvalid(statement, `An earlier statement already renames "${qualifiedModel(from)}".`, REPEATED_NAME_FIX));
|
|
437
|
+
if (state.renamedTo.has(toKey)) return notOk(errorStatementInvalid(statement, `An earlier statement already renames a model to "${qualifiedModel(to)}".`, REPEATED_NAME_FIX));
|
|
438
|
+
if (qualifiedModel(from) === qualifiedModel(to)) return notOk(errorStatementInvalid(statement, `The statement renames model "${qualifiedModel(from)}" to itself.`, `Leave out --${statement.verb} ${statement.text}. ${STORED_NAME_ONLY}`));
|
|
439
|
+
if (modelAt(state.origin.contract, to) !== void 0 && modelAt(state.destination.contract, from) !== void 0) return notOk(swapRefusal(statement, "model", qualifiedModel(from), qualifiedModel(to)));
|
|
440
|
+
if (modelAt(state.origin.contract, to) !== void 0) return notOk(errorStatementUnresolved(statement, `"${qualifiedModel(to)}" already exists in the origin contract, so it cannot be the new name of a model.`, CHECK_NAMES_FIX));
|
|
441
|
+
if (modelAt(state.destination.contract, from) !== void 0) return notOk(errorStatementUnresolved(statement, `"${qualifiedModel(from)}" still exists in the destination contract, so it was not renamed.`, CHECK_NAMES_FIX));
|
|
442
|
+
state.renamedFrom.add(fromKey);
|
|
443
|
+
state.renamedTo.add(toKey);
|
|
444
|
+
state.originOfRenamedModel.set(qualifiedModel(to), from);
|
|
445
|
+
return ok({
|
|
446
|
+
kind: "rename",
|
|
447
|
+
entity: "model",
|
|
448
|
+
from,
|
|
449
|
+
to
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
function modelPart(side) {
|
|
453
|
+
return side.slice(0, -1).join(".");
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* The old side names a model the destination contract does not have. The
|
|
457
|
+
* user most likely named the field's model by its old name, so the error
|
|
458
|
+
* writes the statement with the model named as the destination names it.
|
|
459
|
+
*/
|
|
460
|
+
function oldModelNotInDestination(state, statement, from, toModel) {
|
|
461
|
+
const oldModel = modelPart(statement.from);
|
|
462
|
+
const newModel = modelPart(statement.to);
|
|
463
|
+
const corrected = `${newModel}.${from.coordinate.field}:${statement.to.join(".")}`;
|
|
464
|
+
const renamedEarlier = state.originOfRenamedModel.get(toModel);
|
|
465
|
+
const modelRenamed = renamedEarlier !== void 0 && qualifiedModel(renamedEarlier) === qualifiedModel(from.coordinate);
|
|
466
|
+
const modelStatement = `${oldModel}:${newModel}`;
|
|
467
|
+
return errorStatementInvalid(statement, [
|
|
468
|
+
`"${qualifiedModel(from.coordinate)}" is not a model of the destination contract, and a field cannot move between models.`,
|
|
469
|
+
`Name a field's model as the destination contract names it: --${statement.verb} ${corrected}.`,
|
|
470
|
+
...modelRenamed ? [] : [`The model also needs its own statement, --rename ${modelStatement}, before it.`]
|
|
471
|
+
].join(" "), modelRenamed ? `Write the statement as --${statement.verb} ${corrected}.` : `Write the statements as --rename ${modelStatement} --${statement.verb} ${corrected}.`);
|
|
472
|
+
}
|
|
473
|
+
function fieldMovesBetweenModels(statement, fromModel, toModel) {
|
|
474
|
+
return errorStatementInvalid(statement, `The old name is a field of "${fromModel}" and the new name a field of "${toModel}"; a field cannot move between models.`, "Rename a field within one model, and name that model as the destination contract names it.");
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* True when the old side most likely names the new side's model by its old
|
|
478
|
+
* name: no earlier statement renamed the old model to some other model or
|
|
479
|
+
* some other model to the new model, and the origin does not have the new
|
|
480
|
+
* model.
|
|
481
|
+
*/
|
|
482
|
+
function oldSideNamesNewModel(state, from, to) {
|
|
483
|
+
const oldModel = qualifiedModel(from.coordinate);
|
|
484
|
+
const renamedTo = [...state.originOfRenamedModel.entries()].find(([, origin]) => qualifiedModel(origin) === oldModel)?.[0];
|
|
485
|
+
if (renamedTo !== void 0) return renamedTo === qualifiedModel(to.coordinate);
|
|
486
|
+
if (state.originOfRenamedModel.has(qualifiedModel(to.coordinate))) return false;
|
|
487
|
+
return modelAt(state.origin.contract, to.coordinate) === void 0;
|
|
488
|
+
}
|
|
489
|
+
function resolveFieldRename(state, statement, from, to) {
|
|
490
|
+
const toModel = qualifiedModel(to.coordinate);
|
|
491
|
+
if (from.destinationModel === void 0) return notOk(oldSideNamesNewModel(state, from, to) ? oldModelNotInDestination(state, statement, from, toModel) : fieldMovesBetweenModels(statement, qualifiedModel(from.coordinate), toModel));
|
|
492
|
+
if (qualifiedModel(from.destinationModel) !== toModel) return notOk(fieldMovesBetweenModels(statement, qualifiedModel(from.destinationModel), toModel));
|
|
493
|
+
const fromKey = `${FIELD_RENAMES}:${qualifiedField(from.coordinate)}`;
|
|
494
|
+
const toKey = `${FIELD_RENAMES}:${qualifiedField(to.coordinate)}`;
|
|
495
|
+
if (state.renamedFrom.has(fromKey)) return notOk(errorStatementInvalid(statement, `An earlier statement already renames "${qualifiedField(from.coordinate)}".`, REPEATED_NAME_FIX));
|
|
496
|
+
if (state.renamedTo.has(toKey)) return notOk(errorStatementInvalid(statement, `An earlier statement already renames a field to "${qualifiedField(to.coordinate)}".`, REPEATED_NAME_FIX));
|
|
497
|
+
if (from.coordinate.field === to.coordinate.field) return notOk(errorStatementInvalid(statement, `The statement renames field "${toModel}.${to.coordinate.field}" to itself.`, `Leave out --${statement.verb} ${statement.text}. ${STORED_NAME_ONLY}`));
|
|
498
|
+
if (hasField(from.model, to.coordinate.field) && hasField(to.model, from.coordinate.field)) return notOk(swapRefusal(statement, "field", `${toModel}.${from.coordinate.field}`, `${toModel}.${to.coordinate.field}`));
|
|
499
|
+
if (hasField(from.model, to.coordinate.field)) return notOk(errorStatementUnresolved(statement, `The field "${to.coordinate.field}" already exists on the origin model "${qualifiedModel(from.coordinate)}", so it cannot be the new name of a field.`, CHECK_NAMES_FIX));
|
|
500
|
+
if (hasField(to.model, from.coordinate.field)) return notOk(errorStatementUnresolved(statement, `The field "${from.coordinate.field}" still exists on the destination model "${toModel}", so it was not renamed.`, CHECK_NAMES_FIX));
|
|
501
|
+
state.renamedFrom.add(fromKey);
|
|
502
|
+
state.renamedTo.add(toKey);
|
|
503
|
+
return ok({
|
|
504
|
+
kind: "rename",
|
|
505
|
+
entity: "field",
|
|
506
|
+
from: from.coordinate,
|
|
507
|
+
to: to.coordinate
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Two names that trade places: each is an old name and a new name, which one plan cannot do.
|
|
512
|
+
* Statements resolve against contracts, so the swap takes three plans through a temporary name.
|
|
513
|
+
*/
|
|
514
|
+
function swapRefusal(statement, entity, first, second) {
|
|
515
|
+
const verb = statement.verb;
|
|
516
|
+
const oldName = statement.from.join(".");
|
|
517
|
+
const newName = statement.to.join(".");
|
|
518
|
+
const temporary = entity === "field" ? `${statement.to.slice(0, -1).join(".")}.<temporary name>` : "<temporary name>";
|
|
519
|
+
return errorStatementInvalid(statement, `"${first}" and "${second}" swap names: each is both an old name and a new name, and statements cannot swap names in one plan.`, `Make the swap in three plans. First change the contract so that "${first}" has a temporary name, and plan it with --${verb} ${oldName}:${temporary}. Then give "${second}" the name "${first}", and plan it with --${verb} ${newName}:${oldName}. Then give the temporary name the name "${second}", and plan it with --${verb} ${temporary}:${newName}.`);
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* The old side does not resolve. Says so in terms of what the user can do next when the statement
|
|
523
|
+
* is the wrong way round, when the rename has already happened, or when a later statement renames
|
|
524
|
+
* the field's model.
|
|
525
|
+
*/
|
|
526
|
+
function oldSideRefusal(state, statement, later, refusal) {
|
|
527
|
+
const oldText = statement.from.join(".");
|
|
528
|
+
const newText = statement.to.join(".");
|
|
529
|
+
const newIsInOrigin = readSide(state, "old", statement.to).ok;
|
|
530
|
+
const newIsInDestination = readSide(state, "new", statement.to).ok;
|
|
531
|
+
const oldIsInDestination = readSide(state, "new", statement.from).ok;
|
|
532
|
+
if (newIsInOrigin && oldIsInDestination && !newIsInDestination) return errorStatementUnresolved(statement, `The statement is the wrong way round: "${newText}" is the old name, in the origin contract, and "${oldText}" the new name, in the destination contract.`, `Write the old name first: --${statement.verb} ${newText}:${oldText}.`);
|
|
533
|
+
if (newIsInOrigin && newIsInDestination && !oldIsInDestination) return errorStatementUnresolved(statement, `The origin contract already has "${newText}" and has no "${oldText}", so this rename has already happened. For db update, the database is already at the new name.`, `Leave out --${statement.verb} ${statement.text}.`);
|
|
534
|
+
const model = refusal.modelWithoutCounterpart;
|
|
535
|
+
const renamesModel = model === void 0 ? void 0 : later.find((candidate) => candidate.to.length < 3 && readSide(state, "new", candidate.to).ok && [model, model.split(".").pop()].includes(candidate.to.join(".")));
|
|
536
|
+
if (renamesModel !== void 0) return errorStatementUnresolved(statement, `${sentence(refusal.reason)} A later statement, --${renamesModel.verb} ${renamesModel.text}, renames it, and statements apply in the order given.`, `Put --${renamesModel.verb} ${renamesModel.text} before --${statement.verb} ${statement.text}.`);
|
|
537
|
+
return unresolved(statement, refusal);
|
|
538
|
+
}
|
|
539
|
+
function resolveStatement(state, statement, later) {
|
|
540
|
+
const from = readSide(state, "old", statement.from);
|
|
541
|
+
if (!from.ok) return notOk(oldSideRefusal(state, statement, later, from.failure));
|
|
542
|
+
const to = readSide(state, "new", statement.to);
|
|
543
|
+
if (!to.ok) return notOk(unresolved(statement, to.failure));
|
|
544
|
+
if (from.value.entity === "model" && to.value.entity === "model") return resolveModelRename(state, statement, from.value.coordinate, to.value.coordinate);
|
|
545
|
+
if (from.value.entity === "field" && to.value.entity === "field") return resolveFieldRename(state, statement, from.value, to.value);
|
|
546
|
+
return notOk(errorStatementInvalid(statement, "The statement names a model on one side and a field on the other.", mixedSidesFix(statement.verb, statement.from, statement.to)));
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Resolves the statements a user gave, in order, against the origin and
|
|
550
|
+
* destination contracts. Each resolved statement names its old and new entity
|
|
551
|
+
* by namespace, model and field.
|
|
552
|
+
*/
|
|
553
|
+
function resolveStatements(input) {
|
|
554
|
+
if (input.statements.length === 0) return ok([]);
|
|
555
|
+
if (input.origin.kind === "missing") return notOk(errorStatementOriginUnknown(input.origin));
|
|
556
|
+
const state = {
|
|
557
|
+
origin: {
|
|
558
|
+
name: "origin",
|
|
559
|
+
contract: input.origin.contract
|
|
560
|
+
},
|
|
561
|
+
destination: {
|
|
562
|
+
name: "destination",
|
|
563
|
+
contract: input.destination
|
|
564
|
+
},
|
|
565
|
+
originOfRenamedModel: /* @__PURE__ */ new Map(),
|
|
566
|
+
renamedFrom: /* @__PURE__ */ new Set(),
|
|
567
|
+
renamedTo: /* @__PURE__ */ new Set()
|
|
568
|
+
};
|
|
569
|
+
const parsed = [];
|
|
570
|
+
for (const entry of input.statements) {
|
|
571
|
+
const statement = parseRenameStatement(entry);
|
|
572
|
+
if (!statement.ok) return statement;
|
|
573
|
+
parsed.push(statement.value);
|
|
574
|
+
}
|
|
575
|
+
const resolved = [];
|
|
576
|
+
for (const [index, statement] of parsed.entries()) {
|
|
577
|
+
const result = resolveStatement(state, statement, parsed.slice(index + 1));
|
|
578
|
+
if (!result.ok) return result;
|
|
579
|
+
resolved.push(result.value);
|
|
580
|
+
}
|
|
581
|
+
return ok(resolved);
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
170
584
|
* Project the CLI's `Config.extensions` array into the canonical
|
|
171
585
|
* {@link ExtensionPackInput} shape. The single `as ExtensionPackLike`
|
|
172
586
|
* structural cast in the CLI lives inside this function.
|
|
@@ -663,6 +1077,25 @@ async function executeRun(options) {
|
|
|
663
1077
|
if (!loaded.ok) throw loaded.failure;
|
|
664
1078
|
const aggregate = loaded.value;
|
|
665
1079
|
const markerRows = await familyInstance.readAllMarkers({ driver });
|
|
1080
|
+
let fromContract = null;
|
|
1081
|
+
let statements = [];
|
|
1082
|
+
const statementTexts = options.action === "dbUpdate" ? options.statements : [];
|
|
1083
|
+
if (statementTexts.length > 0) {
|
|
1084
|
+
const appOrigin = await readAppOrigin({
|
|
1085
|
+
marker: markerRows.get(aggregate.app.spaceId) ?? null,
|
|
1086
|
+
migrationsDir,
|
|
1087
|
+
deserializeContract: (json) => familyInstance.deserializeContract(json),
|
|
1088
|
+
...ifDefined("verifySnapshotContent", options.verifySnapshotContent)
|
|
1089
|
+
});
|
|
1090
|
+
const resolved = resolveStatements({
|
|
1091
|
+
statements: statementTexts,
|
|
1092
|
+
origin: appOrigin.origin,
|
|
1093
|
+
destination: contract
|
|
1094
|
+
});
|
|
1095
|
+
if (!resolved.ok) throw resolved.failure;
|
|
1096
|
+
statements = resolved.value;
|
|
1097
|
+
fromContract = appOrigin.contract;
|
|
1098
|
+
}
|
|
666
1099
|
if (mode === "apply") {
|
|
667
1100
|
const orphanMarkerError = detectOrphanMarkers(aggregate, markerRows);
|
|
668
1101
|
if (orphanMarkerError !== null) throw orphanMarkerError;
|
|
@@ -699,7 +1132,11 @@ async function executeRun(options) {
|
|
|
699
1132
|
migrations,
|
|
700
1133
|
frameworkComponents,
|
|
701
1134
|
callerPolicy: { ignoreGraphFor: /* @__PURE__ */ new Set([aggregate.app.spaceId]) },
|
|
702
|
-
operationPolicy: policy
|
|
1135
|
+
operationPolicy: policy,
|
|
1136
|
+
appSpace: {
|
|
1137
|
+
fromContract,
|
|
1138
|
+
statements
|
|
1139
|
+
}
|
|
703
1140
|
});
|
|
704
1141
|
if (!planResult.ok) {
|
|
705
1142
|
onProgress?.({
|
|
@@ -721,6 +1158,7 @@ async function executeRun(options) {
|
|
|
721
1158
|
const appResolution = orderedResolutions.find((r) => r.spaceId === aggregate.app.spaceId);
|
|
722
1159
|
if (!appResolution) throw new InternalError("Aggregate planner returned no plan for the app space — the planner is supposed to always emit one.");
|
|
723
1160
|
const appPlan = appResolution.entry.plan;
|
|
1161
|
+
const appliedStatements = action === "dbUpdate" ? reportAppliedStatements(appResolution.entry.appliedStatements, fromContract, contract, operationsBefore(orderedResolutions, aggregate.app.spaceId)) : void 0;
|
|
724
1162
|
if (mode === "plan") {
|
|
725
1163
|
const aggregateOps = orderedResolutions.flatMap((r) => r.entry.displayOps);
|
|
726
1164
|
const preview = hasOperationPreview(familyInstance) ? familyInstance.toOperationPreview(aggregateOps) : void 0;
|
|
@@ -732,6 +1170,7 @@ async function executeRun(options) {
|
|
|
732
1170
|
preview,
|
|
733
1171
|
perSpace,
|
|
734
1172
|
summary,
|
|
1173
|
+
appliedStatements,
|
|
735
1174
|
...ifDefined("warnings", plannerWarnings)
|
|
736
1175
|
});
|
|
737
1176
|
}
|
|
@@ -781,9 +1220,77 @@ async function executeRun(options) {
|
|
|
781
1220
|
operationsExecuted: applied.value.totalOpsExecuted,
|
|
782
1221
|
perSpace: applied.value.perSpace,
|
|
783
1222
|
summary,
|
|
1223
|
+
appliedStatements,
|
|
784
1224
|
...ifDefined("warnings", plannerWarnings)
|
|
785
1225
|
});
|
|
786
1226
|
}
|
|
1227
|
+
/**
|
|
1228
|
+
* The contract the application space's marker names, from the local snapshot
|
|
1229
|
+
* store, or where it was looked for and why it could not be used.
|
|
1230
|
+
*/
|
|
1231
|
+
async function readAppOrigin(input) {
|
|
1232
|
+
const snapshotsDir = join(input.migrationsDir, CONTRACT_SNAPSHOTS_DIRNAME);
|
|
1233
|
+
if (input.marker === null) return {
|
|
1234
|
+
origin: {
|
|
1235
|
+
kind: "missing",
|
|
1236
|
+
hash: null,
|
|
1237
|
+
snapshotDirectory: snapshotsDir,
|
|
1238
|
+
unreadable: void 0
|
|
1239
|
+
},
|
|
1240
|
+
contract: null
|
|
1241
|
+
};
|
|
1242
|
+
const hash = input.marker.storageHash;
|
|
1243
|
+
if (!isStorageHashHex(hash)) return {
|
|
1244
|
+
origin: {
|
|
1245
|
+
kind: "missing",
|
|
1246
|
+
hash,
|
|
1247
|
+
snapshotDirectory: snapshotsDir,
|
|
1248
|
+
unreadable: void 0
|
|
1249
|
+
},
|
|
1250
|
+
contract: null
|
|
1251
|
+
};
|
|
1252
|
+
const snapshotDirectory = contractSnapshotDir(input.migrationsDir, hash);
|
|
1253
|
+
let json;
|
|
1254
|
+
try {
|
|
1255
|
+
json = await readContractSnapshotJson(input.migrationsDir, hash, input.verifySnapshotContent);
|
|
1256
|
+
} catch (error) {
|
|
1257
|
+
if (!MigrationToolsError.is(error)) throw error;
|
|
1258
|
+
return {
|
|
1259
|
+
origin: {
|
|
1260
|
+
kind: "missing",
|
|
1261
|
+
hash,
|
|
1262
|
+
snapshotDirectory,
|
|
1263
|
+
unreadable: error.code === "MIGRATION.CONTRACT_SNAPSHOT_MISSING" ? void 0 : error.why
|
|
1264
|
+
},
|
|
1265
|
+
contract: null
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
try {
|
|
1269
|
+
const contract = input.deserializeContract(json);
|
|
1270
|
+
return {
|
|
1271
|
+
origin: {
|
|
1272
|
+
kind: "contract",
|
|
1273
|
+
contract
|
|
1274
|
+
},
|
|
1275
|
+
contract
|
|
1276
|
+
};
|
|
1277
|
+
} catch (error) {
|
|
1278
|
+
return {
|
|
1279
|
+
origin: {
|
|
1280
|
+
kind: "missing",
|
|
1281
|
+
hash,
|
|
1282
|
+
snapshotDirectory,
|
|
1283
|
+
unreadable: error instanceof Error ? error.message : String(error)
|
|
1284
|
+
},
|
|
1285
|
+
contract: null
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
/** How many operations the spaces applied before `spaceId` list ahead of it in `operations`. */
|
|
1290
|
+
function operationsBefore(orderedResolutions, spaceId) {
|
|
1291
|
+
const position = orderedResolutions.findIndex((resolution) => resolution.spaceId === spaceId);
|
|
1292
|
+
return orderedResolutions.slice(0, position).reduce((count, resolution) => count + resolution.entry.displayOps.length, 0);
|
|
1293
|
+
}
|
|
787
1294
|
function aggregatePlannerWarnings(orderedResolutions) {
|
|
788
1295
|
const warnings = orderedResolutions.flatMap((r) => r.entry.warnings ?? []);
|
|
789
1296
|
return warnings.length > 0 ? warnings : void 0;
|
|
@@ -852,6 +1359,7 @@ function mapPlannerError(error) {
|
|
|
852
1359
|
function wrapPlanResult(args) {
|
|
853
1360
|
return ok({
|
|
854
1361
|
mode: "plan",
|
|
1362
|
+
...ifDefined("appliedStatements", args.appliedStatements),
|
|
855
1363
|
plan: {
|
|
856
1364
|
operations: stripOperations(args.operations),
|
|
857
1365
|
...ifDefined("preview", args.preview)
|
|
@@ -868,6 +1376,7 @@ function wrapPlanResult(args) {
|
|
|
868
1376
|
function wrapApplyResult(args) {
|
|
869
1377
|
return ok({
|
|
870
1378
|
mode: "apply",
|
|
1379
|
+
...ifDefined("appliedStatements", args.appliedStatements),
|
|
871
1380
|
plan: { operations: stripOperations(args.operations) },
|
|
872
1381
|
destination: {
|
|
873
1382
|
storageHash: args.destination.storageHash,
|
|
@@ -1257,6 +1766,7 @@ async function executeDbUpdate(options) {
|
|
|
1257
1766
|
extensions: options.extensions ?? [],
|
|
1258
1767
|
policy: DB_UPDATE_POLICY,
|
|
1259
1768
|
action: "dbUpdate",
|
|
1769
|
+
statements: options.statements ?? [],
|
|
1260
1770
|
...ifDefined("verifySnapshotContent", options.verifySnapshotContent),
|
|
1261
1771
|
...ifDefined("onProgress", options.onProgress)
|
|
1262
1772
|
};
|
|
@@ -1783,6 +2293,7 @@ function buildAtHeadResolution(args) {
|
|
|
1783
2293
|
displayOps: [],
|
|
1784
2294
|
destinationContract: space.contract(),
|
|
1785
2295
|
strategy: "declared-state",
|
|
2296
|
+
appliedStatements: [],
|
|
1786
2297
|
migrationEdges: [buildFabricatedMigrationEdge({
|
|
1787
2298
|
currentMarkerStorageHash: liveMarker?.storageHash,
|
|
1788
2299
|
destinationStorageHash: targetHash,
|
|
@@ -2136,6 +2647,7 @@ var ControlClientImpl = class {
|
|
|
2136
2647
|
extensions: this.options.extensions ?? [],
|
|
2137
2648
|
...ifDefined("acceptDataLoss", options.acceptDataLoss),
|
|
2138
2649
|
...ifDefined("consent", options.consent),
|
|
2650
|
+
...ifDefined("statements", options.statements),
|
|
2139
2651
|
...ifDefined("verifySnapshotContent", this.snapshotVerifier),
|
|
2140
2652
|
...ifDefined("onProgress", onProgress)
|
|
2141
2653
|
});
|
|
@@ -3009,6 +3521,7 @@ function retryCommandFor(args) {
|
|
|
3009
3521
|
...suggestsOffline ? ["--from <contract>"] : [],
|
|
3010
3522
|
...args.to === void 0 ? [] : [`--to ${args.to}`],
|
|
3011
3523
|
...args.advanceRef === void 0 ? [] : [`--advance-ref ${args.advanceRef}`],
|
|
3524
|
+
...(args.renames ?? []).map((rename) => `--rename ${rename}`),
|
|
3012
3525
|
...needsConnection ? ["--db $DATABASE_URL"] : []
|
|
3013
3526
|
].join(" ");
|
|
3014
3527
|
}
|
|
@@ -4202,7 +4715,9 @@ function buildPlaceholderContractDts(spaceId) {
|
|
|
4202
4715
|
function isEnoent(error) {
|
|
4203
4716
|
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
4204
4717
|
}
|
|
4205
|
-
|
|
4718
|
+
/** The origin of a plan from an empty database: no models, so no statement resolves. */
|
|
4719
|
+
const EMPTY_ORIGIN = { domain: { namespaces: {} } };
|
|
4720
|
+
async function runPlannerLeg(planner, migrations, frameworkComponents, contract, origin, destination, statements, noOperationsExpected, spaceId, ownership, snapshotsImportPath, resolveImportSpecifier) {
|
|
4206
4721
|
const fromContract = origin.kind === "contract" ? origin.contract : null;
|
|
4207
4722
|
const fromSchema = migrations.contractToSchema(fromContract, frameworkComponents);
|
|
4208
4723
|
const plannerResult = planner.plan({
|
|
@@ -4215,17 +4730,25 @@ async function runPlannerLeg(planner, migrations, frameworkComponents, contract,
|
|
|
4215
4730
|
"data"
|
|
4216
4731
|
] },
|
|
4217
4732
|
fromContract,
|
|
4733
|
+
origin: planOriginOf(fromContract),
|
|
4734
|
+
statements,
|
|
4218
4735
|
frameworkComponents,
|
|
4219
4736
|
spaceId,
|
|
4220
4737
|
ownership,
|
|
4221
4738
|
snapshotsImportPath
|
|
4222
4739
|
});
|
|
4223
|
-
if (plannerResult.kind === "failure") return notOk(
|
|
4740
|
+
if (plannerResult.kind === "failure") return notOk({
|
|
4741
|
+
reason: "refused",
|
|
4742
|
+
error: errorMigrationPlanningFailed({ conflicts: castAs(plannerResult.conflicts) })
|
|
4743
|
+
});
|
|
4224
4744
|
let plannedOps = [];
|
|
4225
4745
|
let hasPlaceholders = false;
|
|
4226
4746
|
try {
|
|
4227
4747
|
plannedOps = await Promise.all(plannerResult.plan.operations);
|
|
4228
|
-
if (plannedOps.length === 0) return notOk(
|
|
4748
|
+
if (plannedOps.length === 0 && !noOperationsExpected) return notOk({
|
|
4749
|
+
reason: "noOperations",
|
|
4750
|
+
error: errorPlanProducedNoOperations(origin, destination)
|
|
4751
|
+
});
|
|
4229
4752
|
} catch (e) {
|
|
4230
4753
|
if (CliStructuredError$1.is(e) && e.code === "MIGRATION.UNFILLED_PLACEHOLDER") {
|
|
4231
4754
|
hasPlaceholders = true;
|
|
@@ -4239,9 +4762,21 @@ async function runPlannerLeg(planner, migrations, frameworkComponents, contract,
|
|
|
4239
4762
|
return ok({
|
|
4240
4763
|
plannedOps,
|
|
4241
4764
|
migrationTsContent: plannerResult.plan.renderTypeScript(resolveImportSpecifier),
|
|
4242
|
-
hasPlaceholders
|
|
4765
|
+
hasPlaceholders,
|
|
4766
|
+
appliedStatements: reportAppliedStatements(plannerResult.appliedStatements, fromContract, contract, 0)
|
|
4243
4767
|
});
|
|
4244
4768
|
}
|
|
4769
|
+
/**
|
|
4770
|
+
* The operations a result lists. For a leg with unfilled placeholders these are the operations
|
|
4771
|
+
* that resolved; the placeholders themselves are not operations yet.
|
|
4772
|
+
*/
|
|
4773
|
+
function operationSummaries(ops) {
|
|
4774
|
+
return ops.map((op) => ({
|
|
4775
|
+
id: op.id,
|
|
4776
|
+
label: op.label,
|
|
4777
|
+
operationClass: op.operationClass
|
|
4778
|
+
}));
|
|
4779
|
+
}
|
|
4245
4780
|
async function writePlannedMigrationPackage(packageDir, fromHash, toHash, createdAt, leg) {
|
|
4246
4781
|
const opsForWrite = leg.hasPlaceholders ? [] : leg.plannedOps;
|
|
4247
4782
|
const metadataWithInvariants = {
|
|
@@ -4401,6 +4936,20 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
4401
4936
|
toStorageHash = toResolution.value.hash;
|
|
4402
4937
|
destinationInStore = true;
|
|
4403
4938
|
}
|
|
4939
|
+
let statements = [];
|
|
4940
|
+
const statementTexts = options.statements ?? [];
|
|
4941
|
+
if (statementTexts.length > 0) {
|
|
4942
|
+
const resolved = resolveStatements({
|
|
4943
|
+
statements: statementTexts,
|
|
4944
|
+
origin: {
|
|
4945
|
+
kind: "contract",
|
|
4946
|
+
contract: fromContract ?? EMPTY_ORIGIN
|
|
4947
|
+
},
|
|
4948
|
+
destination: toContract
|
|
4949
|
+
});
|
|
4950
|
+
if (!resolved.ok) return notOk(resolved.failure);
|
|
4951
|
+
statements = resolved.value;
|
|
4952
|
+
}
|
|
4404
4953
|
const resolveImportSpecifier = createProjectSpecifierResolver(options.projectDir);
|
|
4405
4954
|
let destinationDeclarations = null;
|
|
4406
4955
|
if (!destinationInStore && fromHash !== toStorageHash) {
|
|
@@ -4424,7 +4973,7 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
4424
4973
|
})));
|
|
4425
4974
|
const carried = options.carryEmittedExtensionDirs ?? [];
|
|
4426
4975
|
const emittedExtensionDirs = [...carried, ...seededThisRun.filter((entry) => !carried.some((prior) => prior.spaceId === entry.spaceId && prior.dirName === entry.dirName))];
|
|
4427
|
-
if (fromHash === toStorageHash && !isAutoBaseline) return ok({
|
|
4976
|
+
if (fromHash === toStorageHash && !isAutoBaseline && statements.length === 0) return ok({
|
|
4428
4977
|
ok: true,
|
|
4429
4978
|
noOp: true,
|
|
4430
4979
|
from: fromHash,
|
|
@@ -4432,6 +4981,7 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
4432
4981
|
operations: [],
|
|
4433
4982
|
emittedExtensionDirs,
|
|
4434
4983
|
...warnings.length > 0 ? { warnings } : {},
|
|
4984
|
+
appliedStatements: [],
|
|
4435
4985
|
summary: "No changes detected between contracts",
|
|
4436
4986
|
timings: { total: Date.now() - startTime }
|
|
4437
4987
|
});
|
|
@@ -4478,12 +5028,19 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
4478
5028
|
}, {
|
|
4479
5029
|
hash: fromHash,
|
|
4480
5030
|
isEmitted: false
|
|
4481
|
-
}, aggregate.app.spaceId, aggregate, snapshotsImportPathFrom(baselinePackageDir, migrationsDir), resolveImportSpecifier);
|
|
4482
|
-
if (!baselineLeg.ok) return notOk(baselineLeg.failure);
|
|
5031
|
+
}, [], false, aggregate.app.spaceId, aggregate, snapshotsImportPathFrom(baselinePackageDir, migrationsDir), resolveImportSpecifier);
|
|
5032
|
+
if (!baselineLeg.ok) return notOk(baselineLeg.failure.error);
|
|
4483
5033
|
const consentFailure = refuseUnconsentedDestructiveBaseline(baselineLeg.value, fromHash, options.consent);
|
|
4484
5034
|
if (consentFailure !== null) return notOk(consentFailure);
|
|
5035
|
+
const deltaLeg = fromHash === toStorageHash ? void 0 : await runPlannerLeg(planner, migrations, frameworkComponents, aggregate.app.contract(), fromOrigin, planDestination, statements, false, aggregate.app.spaceId, aggregate, snapshotsImportPathFrom(deltaPackageDir, migrationsDir), resolveImportSpecifier);
|
|
5036
|
+
if (deltaLeg !== void 0 && !deltaLeg.ok && deltaLeg.failure.reason === "refused") return notOk(deltaLeg.failure.error);
|
|
4485
5037
|
await writePlannedMigrationPackage(baselinePackageDir, null, fromHash, baselineTimestamp, baselineLeg.value);
|
|
4486
|
-
if (
|
|
5038
|
+
if (deltaLeg !== void 0 && !deltaLeg.ok) return notOk(deltaLeg.failure.error);
|
|
5039
|
+
if (deltaLeg === void 0) {
|
|
5040
|
+
const statementsWithoutOperations = reportAppliedStatements(statements.map((statement) => ({
|
|
5041
|
+
statement,
|
|
5042
|
+
operationIndexes: []
|
|
5043
|
+
})), fromContract, aggregate.app.contract(), 0);
|
|
4487
5044
|
const baselineOps = baselineLeg.value.hasPlaceholders ? [] : baselineLeg.value.plannedOps;
|
|
4488
5045
|
if (baselineLeg.value.hasPlaceholders) {
|
|
4489
5046
|
const baselineDir = relative(cwd, baselinePackageDir);
|
|
@@ -4494,10 +5051,11 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
4494
5051
|
to: toStorageHash,
|
|
4495
5052
|
dir: baselineDir,
|
|
4496
5053
|
baselineDir,
|
|
4497
|
-
operations:
|
|
5054
|
+
operations: operationSummaries(baselineLeg.value.plannedOps),
|
|
4498
5055
|
emittedExtensionDirs,
|
|
4499
5056
|
...warnings.length > 0 ? { warnings } : {},
|
|
4500
5057
|
pendingPlaceholders: true,
|
|
5058
|
+
appliedStatements: statementsWithoutOperations,
|
|
4501
5059
|
summary: "Planned baseline with placeholder(s) — edit migration.ts then run `node migration.ts` to self-emit",
|
|
4502
5060
|
timings: { total: Date.now() - startTime }
|
|
4503
5061
|
});
|
|
@@ -4517,12 +5075,11 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
4517
5075
|
emittedExtensionDirs,
|
|
4518
5076
|
...preview !== void 0 ? { preview } : {},
|
|
4519
5077
|
...warnings.length > 0 ? { warnings } : {},
|
|
5078
|
+
appliedStatements: statementsWithoutOperations,
|
|
4520
5079
|
summary: buildAutoBaselinePlanSummary(baselineOps.length, 0, emittedExtensionDirs.length),
|
|
4521
5080
|
timings: { total: Date.now() - startTime }
|
|
4522
5081
|
});
|
|
4523
5082
|
}
|
|
4524
|
-
const deltaLeg = await runPlannerLeg(planner, migrations, frameworkComponents, aggregate.app.contract(), fromOrigin, planDestination, aggregate.app.spaceId, aggregate, snapshotsImportPathFrom(deltaPackageDir, migrationsDir), resolveImportSpecifier);
|
|
4525
|
-
if (!deltaLeg.ok) return notOk(deltaLeg.failure);
|
|
4526
5083
|
await writePlannedMigrationPackage(deltaPackageDir, fromHash, toStorageHash, deltaTimestamp, deltaLeg.value);
|
|
4527
5084
|
await writeDestinationSnapshot(toStorageHash);
|
|
4528
5085
|
const baselineOps = baselineLeg.value.hasPlaceholders ? [] : baselineLeg.value.plannedOps;
|
|
@@ -4534,10 +5091,12 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
4534
5091
|
to: toStorageHash,
|
|
4535
5092
|
dir: relative(cwd, deltaPackageDir),
|
|
4536
5093
|
baselineDir: relative(cwd, baselinePackageDir),
|
|
4537
|
-
operations:
|
|
5094
|
+
operations: operationSummaries(deltaLeg.value.plannedOps),
|
|
5095
|
+
baselineOperations: operationSummaries(baselineLeg.value.plannedOps),
|
|
4538
5096
|
emittedExtensionDirs,
|
|
4539
5097
|
...warnings.length > 0 ? { warnings } : {},
|
|
4540
5098
|
pendingPlaceholders: true,
|
|
5099
|
+
appliedStatements: deltaLeg.value.appliedStatements,
|
|
4541
5100
|
summary: "Planned baseline + migration with placeholder(s) — edit migration.ts then run `node migration.ts` to self-emit",
|
|
4542
5101
|
timings: { total: Date.now() - startTime }
|
|
4543
5102
|
});
|
|
@@ -4562,14 +5121,27 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
4562
5121
|
emittedExtensionDirs,
|
|
4563
5122
|
...preview !== void 0 ? { preview } : {},
|
|
4564
5123
|
...warnings.length > 0 ? { warnings } : {},
|
|
5124
|
+
appliedStatements: deltaLeg.value.appliedStatements,
|
|
4565
5125
|
summary: buildAutoBaselinePlanSummary(baselineOps.length, deltaOps.length, emittedExtensionDirs.length),
|
|
4566
5126
|
timings: { total: Date.now() - startTime }
|
|
4567
5127
|
});
|
|
4568
5128
|
}
|
|
4569
5129
|
const timestamp = /* @__PURE__ */ new Date();
|
|
4570
5130
|
const packageDir = join(appMigrationsDir, formatMigrationDirName(timestamp, options.name ?? "migration"));
|
|
4571
|
-
const deltaLeg = await runPlannerLeg(planner, migrations, frameworkComponents, aggregate.app.contract(), fromOrigin, planDestination, aggregate.app.spaceId, aggregate, snapshotsImportPathFrom(packageDir, migrationsDir), resolveImportSpecifier);
|
|
4572
|
-
if (!deltaLeg.ok) return notOk(deltaLeg.failure);
|
|
5131
|
+
const deltaLeg = await runPlannerLeg(planner, migrations, frameworkComponents, aggregate.app.contract(), fromOrigin, planDestination, statements, statements.length > 0 && fromHash === toStorageHash, aggregate.app.spaceId, aggregate, snapshotsImportPathFrom(packageDir, migrationsDir), resolveImportSpecifier);
|
|
5132
|
+
if (!deltaLeg.ok) return notOk(deltaLeg.failure.error);
|
|
5133
|
+
if (!deltaLeg.value.hasPlaceholders && deltaLeg.value.plannedOps.length === 0) return ok({
|
|
5134
|
+
ok: true,
|
|
5135
|
+
noOp: true,
|
|
5136
|
+
from: fromHash,
|
|
5137
|
+
to: toStorageHash,
|
|
5138
|
+
operations: [],
|
|
5139
|
+
emittedExtensionDirs,
|
|
5140
|
+
...warnings.length > 0 ? { warnings } : {},
|
|
5141
|
+
appliedStatements: deltaLeg.value.appliedStatements,
|
|
5142
|
+
summary: "No changes to plan: the statements need no operations",
|
|
5143
|
+
timings: { total: Date.now() - startTime }
|
|
5144
|
+
});
|
|
4573
5145
|
await writePlannedMigrationPackage(packageDir, fromHash, toStorageHash, timestamp, deltaLeg.value);
|
|
4574
5146
|
await writeDestinationSnapshot(toStorageHash);
|
|
4575
5147
|
if (deltaLeg.value.hasPlaceholders) return ok({
|
|
@@ -4578,11 +5150,12 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
4578
5150
|
from: fromHash,
|
|
4579
5151
|
to: toStorageHash,
|
|
4580
5152
|
dir: relative(cwd, packageDir),
|
|
4581
|
-
operations:
|
|
5153
|
+
operations: operationSummaries(deltaLeg.value.plannedOps),
|
|
4582
5154
|
emittedExtensionDirs,
|
|
4583
5155
|
...warnings.length > 0 ? { warnings } : {},
|
|
4584
5156
|
pendingPlaceholders: true,
|
|
4585
5157
|
...fromDefaulted ? { fromDefaulted } : {},
|
|
5158
|
+
appliedStatements: deltaLeg.value.appliedStatements,
|
|
4586
5159
|
summary: "Planned migration with placeholder(s) — edit migration.ts then run `node migration.ts` to self-emit",
|
|
4587
5160
|
timings: { total: Date.now() - startTime }
|
|
4588
5161
|
});
|
|
@@ -4603,6 +5176,7 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
4603
5176
|
...preview !== void 0 ? { preview } : {},
|
|
4604
5177
|
...fromDefaulted ? { fromDefaulted } : {},
|
|
4605
5178
|
...warnings.length > 0 ? { warnings } : {},
|
|
5179
|
+
appliedStatements: deltaLeg.value.appliedStatements,
|
|
4606
5180
|
summary: buildPlanSummary(plannedOps.length, emittedExtensionDirs.length),
|
|
4607
5181
|
timings: { total: Date.now() - startTime }
|
|
4608
5182
|
});
|
|
@@ -4745,6 +5319,6 @@ async function executeRefListCommand(options) {
|
|
|
4745
5319
|
}
|
|
4746
5320
|
}
|
|
4747
5321
|
//#endregion
|
|
4748
|
-
export { refuseUnknownInvariants as $, executeRefListCommand as A, loadContractSourceWithStack as B, executeDbUpdate as C, executeMigrationPlanCommand as D, executeMigrationNewCommand as E, listRefsByContractHash as F, migrationSpaceListEntriesFromAggregate as G, looksLikePath as H, liveMarkerUse as I, refuseContractSpaceIntegrity as J, preflightRefAdvancement as K, loadAggregateIntegrityViolations as L, findPackageByDirPath as M, formatSourceDiagnostic as N, executeRefAdvancement as O, hasMigrationPath as P, refusePackageCorruptionOnAggregate as Q, loadContractRawSafely as R, executeDbSign as S, executeMigrateShowPlan as T, mapContractAtError as U, loadContractSpaceAggregateForCli as V, mapIntegrityViolations as W, refuseMarkerOutsideGraph as X, refuseDeclaredExtensionTargetMismatch as Y, refuseMissingInvariantPath as Z, disposeEmitQueue as _, RECORDED_OR_EMPTY_CONTRACT_REF_FORMS as a, resolveMigrationRef as at, executeContractEmit as b, appliedHashesFromLedger as c,
|
|
5322
|
+
export { refuseUnknownInvariants as $, executeRefListCommand as A, loadContractSourceWithStack as B, executeDbUpdate as C, executeMigrationPlanCommand as D, executeMigrationNewCommand as E, listRefsByContractHash as F, migrationSpaceListEntriesFromAggregate as G, looksLikePath as H, liveMarkerUse as I, refuseContractSpaceIntegrity as J, preflightRefAdvancement as K, loadAggregateIntegrityViolations as L, findPackageByDirPath as M, formatSourceDiagnostic as N, executeRefAdvancement as O, hasMigrationPath as P, refusePackageCorruptionOnAggregate as Q, loadContractRawSafely as R, executeDbSign as S, executeMigrateShowPlan as T, mapContractAtError as U, loadContractSpaceAggregateForCli as V, mapIntegrityViolations as W, refuseMarkerOutsideGraph as X, refuseDeclaredExtensionTargetMismatch as Y, refuseMissingInvariantPath as Z, disposeEmitQueue as _, RECORDED_OR_EMPTY_CONTRACT_REF_FORMS as a, resolveMigrationRef as at, executeContractEmit as b, appliedHashesFromLedger as c, retryCommandFor as ct, buildReadAggregate as d, runMigrationList as dt, requireDatabaseForLiveMarkerUse as et, buildRefAdvancementFields as f, snapshotVerifierFor as ft, deriveStatusEdgeAnnotations as g, validateLoadedContract as gt, createControlClient as h, toDeclaredExtensionsFromRaw as ht, RECORDED_CONTRACT_REF_FORMS as i, resolveFromForPlan as it, executeRefSetCommand as j, executeRefDeleteCommand as k, buildContractSpaceAggregate as l, runContractSpaceSeedPhase as lt, computeRefAdvancementName as m, statusForMigrationHash as mt, DB_UPDATE_POLICY as n, resolveContractRef$1 as nt, advanceRefSafely as o, resolveStatements as ot, checkSingleTarget as p, sourceWarningDiagnostic as pt, readMigrationRefs as q, NO_REF_ADVANCEMENT as r, resolveContractRefToSnapshot as rt, appContractStandInFromIdentity as s, resolveToForPlan as st, ALL_CONTRACT_REF_FORMS as t, resolveAppTargetPath as tt, buildMigrationSpaceGraphEntries as u, runMigrationCheck as ut, enrichContract as v, executeDbVerify as w, executeDbInit as x, enumerateCheckSpaces as y, loadContractSource as z };
|
|
4749
5323
|
|
|
4750
|
-
//# sourceMappingURL=ref-
|
|
5324
|
+
//# sourceMappingURL=ref-QYB51IgO-ywgKx10n.mjs.map
|