@prisma/orm-family-sql 8.0.0-rc.16-dev.7 → 8.0.0-rc.16-dev.9
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/{control-C4VZIU-L.mjs → control-BRbds4vn.mjs} +290 -120
- package/dist/control-BRbds4vn.mjs.map +1 -0
- package/dist/{control-BT0wr9QC.d.mts → control-BkyDhucB.d.mts} +73 -4
- package/dist/control-BkyDhucB.d.mts.map +1 -0
- package/dist/family.d.mts +2 -2
- package/dist/family.mjs +2 -2
- package/dist/family__control.d.mts +2 -2
- package/dist/family__control.mjs +2 -2
- package/dist/orm-client.d.mts +120 -120
- package/dist/orm-client.d.mts.map +1 -1
- package/dist/orm-client.mjs +1268 -1268
- package/dist/orm-client.mjs.map +1 -1
- package/package.json +18 -18
- package/dist/control-BT0wr9QC.d.mts.map +0 -1
- package/dist/control-C4VZIU-L.mjs.map +0 -1
|
@@ -21,7 +21,7 @@ import { assembleDataTypes, canonicalFormOf } from "@prisma/orm-framework/compon
|
|
|
21
21
|
import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
22
22
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
23
23
|
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
24
|
-
import { effectiveControlPolicy } from "@prisma/orm-framework/contract/types";
|
|
24
|
+
import { asNamespaceId, effectiveControlPolicy } from "@prisma/orm-framework/contract/types";
|
|
25
25
|
import { APP_SPACE_ID, SchemaTreeNode, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_TARGET_MISMATCH, assembleAuthoringContributions, describeMigrationStatement, extractCodecLookup, issueOutcome, modelDisplayName, sameMarkerHashes } from "@prisma/orm-framework/components/control";
|
|
26
26
|
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
27
27
|
import { assertDescriptorSelfConsistency } from "@prisma/orm-toolchain/migration-tools/spaces";
|
|
@@ -76,6 +76,38 @@ function assertContractMatchesStack(contract, stack) {
|
|
|
76
76
|
const problems = [...dataTypeProblems(contract.storage, stack.codecLookup), ...valueObjectProblems(contract, stack.authoringContributions)];
|
|
77
77
|
if (problems.length > 0) throw new ContractValidationError(problems.join("; "), "storage");
|
|
78
78
|
}
|
|
79
|
+
function isStorageDetails(details) {
|
|
80
|
+
if (typeof details !== "object" || details === null) return false;
|
|
81
|
+
const [objectType, name, schema, table] = [
|
|
82
|
+
"objectType",
|
|
83
|
+
"name",
|
|
84
|
+
"schema",
|
|
85
|
+
"table"
|
|
86
|
+
].map((key) => Reflect.get(details, key));
|
|
87
|
+
return typeof objectType === "string" && typeof name === "string" && (schema === void 0 || typeof schema === "string") && (table === void 0 || typeof table === "string");
|
|
88
|
+
}
|
|
89
|
+
function storageDetailsOf(operation) {
|
|
90
|
+
const target = Reflect.get(operation, "target");
|
|
91
|
+
if (typeof target !== "object" || target === null) return void 0;
|
|
92
|
+
const details = Reflect.get(target, "details");
|
|
93
|
+
return isStorageDetails(details) ? details : void 0;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The name the database knows an operation's object by, read from the operation's target
|
|
97
|
+
* details: `schema.table.column` for a column, `schema.name` for anything else, without the
|
|
98
|
+
* schema in the unbound namespace. An operation without details is named by its id.
|
|
99
|
+
*/
|
|
100
|
+
function storageNameOfOperation(operation) {
|
|
101
|
+
const details = storageDetailsOf(operation);
|
|
102
|
+
if (details === void 0) return operation.id;
|
|
103
|
+
const schema = details.schema === void 0 || details.schema === UNBOUND_NAMESPACE_ID ? [] : [details.schema];
|
|
104
|
+
const table = details.objectType === "column" && details.table !== void 0 ? [details.table] : [];
|
|
105
|
+
return [
|
|
106
|
+
...schema,
|
|
107
|
+
...table,
|
|
108
|
+
details.name
|
|
109
|
+
].join(".");
|
|
110
|
+
}
|
|
79
111
|
function isDdlStatement(sqlStatement) {
|
|
80
112
|
const trimmed = sqlStatement.trim().toLowerCase();
|
|
81
113
|
return trimmed.startsWith("create ") || trimmed.startsWith("alter ") || trimmed.startsWith("drop ");
|
|
@@ -535,6 +567,9 @@ function createSqlFamilyInstance(stack) {
|
|
|
535
567
|
toOperationPreview(operations) {
|
|
536
568
|
return sqlOperationsToPreview(operations);
|
|
537
569
|
},
|
|
570
|
+
storageNameOf(operation) {
|
|
571
|
+
return storageNameOfOperation(operation);
|
|
572
|
+
},
|
|
538
573
|
toSchemaView(schema) {
|
|
539
574
|
const root = blindCast(schema);
|
|
540
575
|
const namespaceEntries = root.namespaces !== void 0 ? Object.entries(root.namespaces).map(([namespaceKey, namespace]) => [namespaceKey, namespace.tables]) : [[void 0, root.tables ?? {}]];
|
|
@@ -1093,6 +1128,10 @@ function subjectKey(subject) {
|
|
|
1093
1128
|
return `${subject.namespaceId}\u0000${subject.entityKind ?? ""}\u0000${subject.entityName ?? ""}\u0000${subject.rlsPolicy ?? ""}`;
|
|
1094
1129
|
}
|
|
1095
1130
|
function planFieldEventOperations(options) {
|
|
1131
|
+
return planFieldEventCalls(options).map(({ call }) => call);
|
|
1132
|
+
}
|
|
1133
|
+
/** The calls the codec hooks return, each with the field event's column. */
|
|
1134
|
+
function planFieldEventCalls(options) {
|
|
1096
1135
|
const priorContract = options.priorContract;
|
|
1097
1136
|
const newContract = options.newContract;
|
|
1098
1137
|
const renamedTo = new Map(options.tableRenames.map((rename) => [renameKey(rename.namespaceId, rename.from), rename.to]));
|
|
@@ -1156,7 +1195,12 @@ function appendCalls(event, entries, codecHooks, calls, pickCodecId) {
|
|
|
1156
1195
|
if (!hook?.onFieldEvent) continue;
|
|
1157
1196
|
const ctx = buildContext(event, entry);
|
|
1158
1197
|
const emitted = hook.onFieldEvent(event, ctx);
|
|
1159
|
-
for (const call of emitted) calls.push(
|
|
1198
|
+
for (const call of emitted) calls.push({
|
|
1199
|
+
call,
|
|
1200
|
+
namespaceId: entry.namespaceId,
|
|
1201
|
+
tableName: entry.tableName,
|
|
1202
|
+
columnName: entry.fieldName
|
|
1203
|
+
});
|
|
1160
1204
|
}
|
|
1161
1205
|
}
|
|
1162
1206
|
/**
|
|
@@ -1225,115 +1269,6 @@ function unionSorted(a, b) {
|
|
|
1225
1269
|
for (const name of b) set.add(name);
|
|
1226
1270
|
return [...set].sort((x, y) => x < y ? -1 : x > y ? 1 : 0);
|
|
1227
1271
|
}
|
|
1228
|
-
const readOnlyEmptyObject = Object.freeze({});
|
|
1229
|
-
function cloneRecord(value) {
|
|
1230
|
-
if (value === readOnlyEmptyObject) return value;
|
|
1231
|
-
return blindCast(Object.freeze({ ...value }));
|
|
1232
|
-
}
|
|
1233
|
-
function freezeSteps(steps) {
|
|
1234
|
-
if (steps.length === 0) return Object.freeze([]);
|
|
1235
|
-
return Object.freeze(steps.map((step) => Object.freeze({
|
|
1236
|
-
description: step.description,
|
|
1237
|
-
sql: step.sql,
|
|
1238
|
-
...step.params ? { params: Object.freeze([...step.params]) } : {},
|
|
1239
|
-
...step.meta ? { meta: cloneRecord(step.meta) } : {}
|
|
1240
|
-
})));
|
|
1241
|
-
}
|
|
1242
|
-
function freezeDetailsValue(value) {
|
|
1243
|
-
if (value === null || value === void 0) return value;
|
|
1244
|
-
if (typeof value !== "object") return value;
|
|
1245
|
-
if (Array.isArray(value)) return blindCast(Object.freeze([...value]));
|
|
1246
|
-
return blindCast(Object.freeze({ ...value }));
|
|
1247
|
-
}
|
|
1248
|
-
function freezeTargetDetails(target) {
|
|
1249
|
-
return Object.freeze({
|
|
1250
|
-
id: target.id,
|
|
1251
|
-
...target.details !== void 0 ? { details: freezeDetailsValue(target.details) } : {}
|
|
1252
|
-
});
|
|
1253
|
-
}
|
|
1254
|
-
function freezeOperation(operation) {
|
|
1255
|
-
return Object.freeze({
|
|
1256
|
-
id: operation.id,
|
|
1257
|
-
label: operation.label,
|
|
1258
|
-
...operation.summary ? { summary: operation.summary } : {},
|
|
1259
|
-
operationClass: operation.operationClass,
|
|
1260
|
-
...operation.invariantId ? { invariantId: operation.invariantId } : {},
|
|
1261
|
-
target: freezeTargetDetails(operation.target),
|
|
1262
|
-
precheck: freezeSteps(operation.precheck),
|
|
1263
|
-
execute: freezeSteps(operation.execute),
|
|
1264
|
-
postcheck: freezeSteps(operation.postcheck),
|
|
1265
|
-
...operation.meta ? { meta: cloneRecord(operation.meta) } : {}
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
function freezeOperations(operations) {
|
|
1269
|
-
if (operations.length === 0) return Object.freeze([]);
|
|
1270
|
-
return Object.freeze(operations.map((operation) => freezeOperation(operation)));
|
|
1271
|
-
}
|
|
1272
|
-
function createMigrationPlan(options) {
|
|
1273
|
-
return Object.freeze({
|
|
1274
|
-
targetId: options.targetId,
|
|
1275
|
-
spaceId: options.spaceId,
|
|
1276
|
-
...options.origin !== void 0 ? { origin: options.origin ? Object.freeze({ ...options.origin }) : null } : {},
|
|
1277
|
-
destination: Object.freeze({ ...options.destination }),
|
|
1278
|
-
operations: freezeOperations(options.operations),
|
|
1279
|
-
providedInvariants: Object.freeze([...options.providedInvariants]),
|
|
1280
|
-
...options.meta ? { meta: cloneRecord(options.meta) } : {}
|
|
1281
|
-
});
|
|
1282
|
-
}
|
|
1283
|
-
function plannerSuccess(plan, appliedStatements, warnings) {
|
|
1284
|
-
return Object.freeze({
|
|
1285
|
-
kind: "success",
|
|
1286
|
-
plan,
|
|
1287
|
-
appliedStatements: Object.freeze([...appliedStatements]),
|
|
1288
|
-
...warnings && warnings.length > 0 ? { warnings: Object.freeze(warnings.map((conflict) => Object.freeze({
|
|
1289
|
-
kind: conflict.kind,
|
|
1290
|
-
summary: conflict.summary,
|
|
1291
|
-
...conflict.why ? { why: conflict.why } : {},
|
|
1292
|
-
...conflict.location ? { location: Object.freeze({ ...conflict.location }) } : {},
|
|
1293
|
-
...conflict.refusedStatement ? { refusedStatement: conflict.refusedStatement } : {},
|
|
1294
|
-
...conflict.refusedOperationClass ? { refusedOperationClass: conflict.refusedOperationClass } : {},
|
|
1295
|
-
...conflict.meta ? { meta: cloneRecord(conflict.meta) } : {}
|
|
1296
|
-
}))) } : {}
|
|
1297
|
-
});
|
|
1298
|
-
}
|
|
1299
|
-
function plannerFailure(conflicts) {
|
|
1300
|
-
return Object.freeze({
|
|
1301
|
-
kind: "failure",
|
|
1302
|
-
conflicts: Object.freeze(conflicts.map((conflict) => Object.freeze({
|
|
1303
|
-
kind: conflict.kind,
|
|
1304
|
-
summary: conflict.summary,
|
|
1305
|
-
...conflict.why ? { why: conflict.why } : {},
|
|
1306
|
-
...conflict.location ? { location: Object.freeze({ ...conflict.location }) } : {},
|
|
1307
|
-
...conflict.refusedStatement ? { refusedStatement: conflict.refusedStatement } : {},
|
|
1308
|
-
...conflict.refusedOperationClass ? { refusedOperationClass: conflict.refusedOperationClass } : {},
|
|
1309
|
-
...conflict.meta ? { meta: cloneRecord(conflict.meta) } : {}
|
|
1310
|
-
})))
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
|
-
/**
|
|
1314
|
-
* Creates a successful migration runner result.
|
|
1315
|
-
*/
|
|
1316
|
-
function runnerSuccess(value) {
|
|
1317
|
-
return ok(Object.freeze({
|
|
1318
|
-
operationsPlanned: value.operationsPlanned,
|
|
1319
|
-
operationsExecuted: value.operationsExecuted
|
|
1320
|
-
}));
|
|
1321
|
-
}
|
|
1322
|
-
/**
|
|
1323
|
-
* Creates a failed migration runner result.
|
|
1324
|
-
*/
|
|
1325
|
-
function runnerFailure(code, summary, options) {
|
|
1326
|
-
return notOk(Object.freeze({
|
|
1327
|
-
code,
|
|
1328
|
-
summary,
|
|
1329
|
-
...options?.why ? { why: options.why } : {},
|
|
1330
|
-
...options?.meta ? { meta: cloneRecord(options.meta) } : {}
|
|
1331
|
-
}));
|
|
1332
|
-
}
|
|
1333
|
-
/**
|
|
1334
|
-
* Policy used by `db init`: additive-only operations, no widening/destructive steps.
|
|
1335
|
-
*/
|
|
1336
|
-
const INIT_ADDITIVE_POLICY = Object.freeze({ allowedOperationClasses: Object.freeze(["additive"]) });
|
|
1337
1272
|
const COLUMN_RENAME_UNMATCHED_CODE = "MIGRATION.COLUMN_RENAME_UNMATCHED";
|
|
1338
1273
|
function tableLabel$1(namespaceId, table) {
|
|
1339
1274
|
return namespaceId === void 0 || namespaceId === UNBOUND_NAMESPACE_ID ? table : `${namespaceId}.${table}`;
|
|
@@ -1478,13 +1413,7 @@ function resolveTableRenameAgainst(previous, endContract, rename) {
|
|
|
1478
1413
|
if (!checked.ok) return notOk(unmatchedTableRename(rename, tableRenameMismatchReason(rename, checked.failure)));
|
|
1479
1414
|
return ok(checked.value);
|
|
1480
1415
|
}
|
|
1481
|
-
/**
|
|
1482
|
-
function sqlTypeLookupsOf(frameworkComponents) {
|
|
1483
|
-
return {
|
|
1484
|
-
codecLookup: extractCodecLookup(frameworkComponents),
|
|
1485
|
-
dataTypeLookup: assembleDataTypes(frameworkComponents).lookup
|
|
1486
|
-
};
|
|
1487
|
-
}
|
|
1416
|
+
/** Whether a model's storage names a table, as a model a SQL contract stores in a table does. */
|
|
1488
1417
|
function isSqlModelStorage(storage) {
|
|
1489
1418
|
return typeof storage["table"] === "string" && typeof storage["namespaceId"] === "string" && typeof storage["fields"] === "object" && storage["fields"] !== null;
|
|
1490
1419
|
}
|
|
@@ -1771,6 +1700,247 @@ function planStatements(input) {
|
|
|
1771
1700
|
appliedStatements
|
|
1772
1701
|
});
|
|
1773
1702
|
}
|
|
1703
|
+
/** What a codec hook's call is about: the column of the field event it was returned for. */
|
|
1704
|
+
function fieldEventStorage(field) {
|
|
1705
|
+
return {
|
|
1706
|
+
storageName: [
|
|
1707
|
+
...field.namespaceId === UNBOUND_NAMESPACE_ID ? [] : [field.namespaceId],
|
|
1708
|
+
field.tableName,
|
|
1709
|
+
field.columnName
|
|
1710
|
+
].join("."),
|
|
1711
|
+
table: {
|
|
1712
|
+
namespaceId: field.namespaceId,
|
|
1713
|
+
table: field.tableName,
|
|
1714
|
+
column: field.columnName
|
|
1715
|
+
}
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1718
|
+
/**
|
|
1719
|
+
* Names for destructive calls a target cannot map to storage: each call's factory name, with a
|
|
1720
|
+
* `#n` ordinal when several calls of the plan share it, so each name picks out one call.
|
|
1721
|
+
*/
|
|
1722
|
+
function unknownCallNames(calls) {
|
|
1723
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1724
|
+
for (const call of calls) counts.set(call.factoryName, (counts.get(call.factoryName) ?? 0) + 1);
|
|
1725
|
+
const seen = /* @__PURE__ */ new Map();
|
|
1726
|
+
return new Map(calls.map((call) => {
|
|
1727
|
+
const ordinal = (seen.get(call.factoryName) ?? 0) + 1;
|
|
1728
|
+
seen.set(call.factoryName, ordinal);
|
|
1729
|
+
return [call, (counts.get(call.factoryName) ?? 0) > 1 ? `${call.factoryName}#${ordinal}` : call.factoryName];
|
|
1730
|
+
}));
|
|
1731
|
+
}
|
|
1732
|
+
function originTable(context, namespaceId, table) {
|
|
1733
|
+
for (const statement of context.statements) {
|
|
1734
|
+
if (statement.entity !== "model") continue;
|
|
1735
|
+
const effect = modelRenameStorageEffect(statement, context.fromContract, context.contract);
|
|
1736
|
+
if (!effect.ok || effect.value.kind !== "renameTable") continue;
|
|
1737
|
+
const { rename } = effect.value;
|
|
1738
|
+
if (rename.namespaceId === namespaceId && rename.to === table) return rename.from;
|
|
1739
|
+
}
|
|
1740
|
+
return table;
|
|
1741
|
+
}
|
|
1742
|
+
function originColumn(context, namespaceId, table, column) {
|
|
1743
|
+
for (const statement of context.statements) {
|
|
1744
|
+
if (statement.entity !== "field") continue;
|
|
1745
|
+
const effect = fieldRenameStorageEffect(statement, context.fromContract, context.contract);
|
|
1746
|
+
if (!effect.ok || effect.value.kind !== "renameColumn") continue;
|
|
1747
|
+
const rename = effect.value;
|
|
1748
|
+
if (rename.table.namespaceId === namespaceId && rename.table.table === table && rename.to === column) return rename.from;
|
|
1749
|
+
}
|
|
1750
|
+
return column;
|
|
1751
|
+
}
|
|
1752
|
+
/** The models of `contract` that store `table`: a model and its variants share one. */
|
|
1753
|
+
function modelsStoring(contract, namespaceId, table) {
|
|
1754
|
+
return Object.entries(contract.domain.namespaces).flatMap(([modelNamespace, namespace]) => Object.entries(namespace.models).flatMap(([model, definition]) => {
|
|
1755
|
+
const { storage } = definition;
|
|
1756
|
+
if (!isSqlModelStorage(storage)) return [];
|
|
1757
|
+
if (storage.namespaceId !== namespaceId || storage.table !== table) return [];
|
|
1758
|
+
return [{
|
|
1759
|
+
coordinate: {
|
|
1760
|
+
namespaceId: asNamespaceId(modelNamespace),
|
|
1761
|
+
model
|
|
1762
|
+
},
|
|
1763
|
+
isRoot: definition.base === void 0,
|
|
1764
|
+
fields: storage.fields
|
|
1765
|
+
}];
|
|
1766
|
+
}));
|
|
1767
|
+
}
|
|
1768
|
+
function subjectOf(target, context) {
|
|
1769
|
+
const storage = {
|
|
1770
|
+
kind: "storage",
|
|
1771
|
+
name: target.storageName
|
|
1772
|
+
};
|
|
1773
|
+
const { fromContract } = context;
|
|
1774
|
+
if (target.table === void 0 || fromContract === null) return storage;
|
|
1775
|
+
const withOrigin = {
|
|
1776
|
+
...context,
|
|
1777
|
+
fromContract
|
|
1778
|
+
};
|
|
1779
|
+
const { namespaceId } = target.table;
|
|
1780
|
+
const table = originTable(withOrigin, namespaceId, target.table.table);
|
|
1781
|
+
const models = modelsStoring(fromContract, namespaceId, table);
|
|
1782
|
+
if (target.table.column === void 0) {
|
|
1783
|
+
const model = models.find(({ isRoot }) => isRoot) ?? models[0];
|
|
1784
|
+
return model === void 0 ? storage : {
|
|
1785
|
+
kind: "model",
|
|
1786
|
+
...model.coordinate
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
const column = originColumn(withOrigin, namespaceId, table, target.table.column);
|
|
1790
|
+
for (const model of [...models].sort((a, b) => Number(b.isRoot) - Number(a.isRoot))) {
|
|
1791
|
+
const field = Object.entries(model.fields).find(([, stored]) => stored.column === column)?.[0];
|
|
1792
|
+
if (field !== void 0) return {
|
|
1793
|
+
kind: "field",
|
|
1794
|
+
...model.coordinate,
|
|
1795
|
+
field
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1798
|
+
return storage;
|
|
1799
|
+
}
|
|
1800
|
+
/**
|
|
1801
|
+
* The subject of each operation that loses data and each that widens access, at its position in
|
|
1802
|
+
* the plan. A subject is a model or a field of the origin contract when one stores it, found under
|
|
1803
|
+
* its origin name when a rename statement renamed its table or column earlier in the plan.
|
|
1804
|
+
*/
|
|
1805
|
+
function subjectsOfCalls(calls, context) {
|
|
1806
|
+
const dataLoss = [];
|
|
1807
|
+
const accessWidening = [];
|
|
1808
|
+
let operationIndex = 0;
|
|
1809
|
+
for (const call of calls) {
|
|
1810
|
+
for (const target of call.dataLoss) dataLoss.push({
|
|
1811
|
+
operationIndex,
|
|
1812
|
+
subject: subjectOf(target, context)
|
|
1813
|
+
});
|
|
1814
|
+
for (const target of call.accessWidening) accessWidening.push({
|
|
1815
|
+
operationIndex,
|
|
1816
|
+
subject: subjectOf(target, context),
|
|
1817
|
+
widens: target.widens
|
|
1818
|
+
});
|
|
1819
|
+
operationIndex += call.operationCount;
|
|
1820
|
+
}
|
|
1821
|
+
return {
|
|
1822
|
+
dataLoss,
|
|
1823
|
+
accessWidening
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
const readOnlyEmptyObject = Object.freeze({});
|
|
1827
|
+
function cloneRecord(value) {
|
|
1828
|
+
if (value === readOnlyEmptyObject) return value;
|
|
1829
|
+
return blindCast(Object.freeze({ ...value }));
|
|
1830
|
+
}
|
|
1831
|
+
function freezeSteps(steps) {
|
|
1832
|
+
if (steps.length === 0) return Object.freeze([]);
|
|
1833
|
+
return Object.freeze(steps.map((step) => Object.freeze({
|
|
1834
|
+
description: step.description,
|
|
1835
|
+
sql: step.sql,
|
|
1836
|
+
...step.params ? { params: Object.freeze([...step.params]) } : {},
|
|
1837
|
+
...step.meta ? { meta: cloneRecord(step.meta) } : {}
|
|
1838
|
+
})));
|
|
1839
|
+
}
|
|
1840
|
+
function freezeDetailsValue(value) {
|
|
1841
|
+
if (value === null || value === void 0) return value;
|
|
1842
|
+
if (typeof value !== "object") return value;
|
|
1843
|
+
if (Array.isArray(value)) return blindCast(Object.freeze([...value]));
|
|
1844
|
+
return blindCast(Object.freeze({ ...value }));
|
|
1845
|
+
}
|
|
1846
|
+
function freezeTargetDetails(target) {
|
|
1847
|
+
return Object.freeze({
|
|
1848
|
+
id: target.id,
|
|
1849
|
+
...target.details !== void 0 ? { details: freezeDetailsValue(target.details) } : {}
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
function freezeOperation(operation) {
|
|
1853
|
+
return Object.freeze({
|
|
1854
|
+
id: operation.id,
|
|
1855
|
+
label: operation.label,
|
|
1856
|
+
...operation.summary ? { summary: operation.summary } : {},
|
|
1857
|
+
operationClass: operation.operationClass,
|
|
1858
|
+
...operation.invariantId ? { invariantId: operation.invariantId } : {},
|
|
1859
|
+
target: freezeTargetDetails(operation.target),
|
|
1860
|
+
precheck: freezeSteps(operation.precheck),
|
|
1861
|
+
execute: freezeSteps(operation.execute),
|
|
1862
|
+
postcheck: freezeSteps(operation.postcheck),
|
|
1863
|
+
...operation.meta ? { meta: cloneRecord(operation.meta) } : {}
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
function freezeOperations(operations) {
|
|
1867
|
+
if (operations.length === 0) return Object.freeze([]);
|
|
1868
|
+
return Object.freeze(operations.map((operation) => freezeOperation(operation)));
|
|
1869
|
+
}
|
|
1870
|
+
function createMigrationPlan(options) {
|
|
1871
|
+
return Object.freeze({
|
|
1872
|
+
targetId: options.targetId,
|
|
1873
|
+
spaceId: options.spaceId,
|
|
1874
|
+
...options.origin !== void 0 ? { origin: options.origin ? Object.freeze({ ...options.origin }) : null } : {},
|
|
1875
|
+
destination: Object.freeze({ ...options.destination }),
|
|
1876
|
+
operations: freezeOperations(options.operations),
|
|
1877
|
+
providedInvariants: Object.freeze([...options.providedInvariants]),
|
|
1878
|
+
...options.meta ? { meta: cloneRecord(options.meta) } : {}
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
function plannerSuccess(plan, appliedStatements, subjects, warnings) {
|
|
1882
|
+
return Object.freeze({
|
|
1883
|
+
kind: "success",
|
|
1884
|
+
plan,
|
|
1885
|
+
appliedStatements: Object.freeze([...appliedStatements]),
|
|
1886
|
+
dataLoss: Object.freeze([...subjects.dataLoss]),
|
|
1887
|
+
accessWidening: Object.freeze([...subjects.accessWidening]),
|
|
1888
|
+
...warnings && warnings.length > 0 ? { warnings: Object.freeze(warnings.map((conflict) => Object.freeze({
|
|
1889
|
+
kind: conflict.kind,
|
|
1890
|
+
summary: conflict.summary,
|
|
1891
|
+
...conflict.why ? { why: conflict.why } : {},
|
|
1892
|
+
...conflict.location ? { location: Object.freeze({ ...conflict.location }) } : {},
|
|
1893
|
+
...conflict.refusedStatement ? { refusedStatement: conflict.refusedStatement } : {},
|
|
1894
|
+
...conflict.refusedOperationClass ? { refusedOperationClass: conflict.refusedOperationClass } : {},
|
|
1895
|
+
...conflict.meta ? { meta: cloneRecord(conflict.meta) } : {}
|
|
1896
|
+
}))) } : {}
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
function plannerFailure(conflicts) {
|
|
1900
|
+
return Object.freeze({
|
|
1901
|
+
kind: "failure",
|
|
1902
|
+
conflicts: Object.freeze(conflicts.map((conflict) => Object.freeze({
|
|
1903
|
+
kind: conflict.kind,
|
|
1904
|
+
summary: conflict.summary,
|
|
1905
|
+
...conflict.why ? { why: conflict.why } : {},
|
|
1906
|
+
...conflict.location ? { location: Object.freeze({ ...conflict.location }) } : {},
|
|
1907
|
+
...conflict.refusedStatement ? { refusedStatement: conflict.refusedStatement } : {},
|
|
1908
|
+
...conflict.refusedOperationClass ? { refusedOperationClass: conflict.refusedOperationClass } : {},
|
|
1909
|
+
...conflict.meta ? { meta: cloneRecord(conflict.meta) } : {}
|
|
1910
|
+
})))
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1913
|
+
/**
|
|
1914
|
+
* Creates a successful migration runner result.
|
|
1915
|
+
*/
|
|
1916
|
+
function runnerSuccess(value) {
|
|
1917
|
+
return ok(Object.freeze({
|
|
1918
|
+
operationsPlanned: value.operationsPlanned,
|
|
1919
|
+
operationsExecuted: value.operationsExecuted
|
|
1920
|
+
}));
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Creates a failed migration runner result.
|
|
1924
|
+
*/
|
|
1925
|
+
function runnerFailure(code, summary, options) {
|
|
1926
|
+
return notOk(Object.freeze({
|
|
1927
|
+
code,
|
|
1928
|
+
summary,
|
|
1929
|
+
...options?.why ? { why: options.why } : {},
|
|
1930
|
+
...options?.meta ? { meta: cloneRecord(options.meta) } : {}
|
|
1931
|
+
}));
|
|
1932
|
+
}
|
|
1933
|
+
/**
|
|
1934
|
+
* Policy used by `db init`: additive-only operations, no widening/destructive steps.
|
|
1935
|
+
*/
|
|
1936
|
+
const INIT_ADDITIVE_POLICY = Object.freeze({ allowedOperationClasses: Object.freeze(["additive"]) });
|
|
1937
|
+
/** The codecs and data types a set of composed components registers. */
|
|
1938
|
+
function sqlTypeLookupsOf(frameworkComponents) {
|
|
1939
|
+
return {
|
|
1940
|
+
codecLookup: extractCodecLookup(frameworkComponents),
|
|
1941
|
+
dataTypeLookup: assembleDataTypes(frameworkComponents).lookup
|
|
1942
|
+
};
|
|
1943
|
+
}
|
|
1774
1944
|
const TABLE_NAME_CASE_CHANGED_CODE = "MIGRATION.TABLE_NAME_CASE_CHANGED";
|
|
1775
1945
|
function lowerFirst(value) {
|
|
1776
1946
|
return value.charAt(0).toLowerCase() + value.slice(1);
|
|
@@ -1885,6 +2055,6 @@ function temporalCodecPresetWithPrecision(input) {
|
|
|
1885
2055
|
}
|
|
1886
2056
|
var control_default = new SqlFamilyDescriptor();
|
|
1887
2057
|
//#endregion
|
|
1888
|
-
export {
|
|
2058
|
+
export { temporalStringAuthoringPresets as A, resolveTableRenameAgainst as C, storageNameOfOperation as D, sqlTypeLookupsOf as E, unmatchedColumnRename as M, unmatchedTableRename as N, subjectsOfCalls as O, resolveColumnRenameAgainst as S, runnerSuccess as T, planFieldEventCalls as _, contractNamespaceToSchemaIR as a, plannerFailure as b, control_default as c, detectTableNameCaseChanges as d, fieldEventStorage as f, partitionIssuesByControlPolicy as g, partitionCallsByControlPolicy as h, assembleAuthoringContributions as i, unknownCallNames as j, temporalCodecPresetWithPrecision as k, createMigrationPlan as l, modelRenameStorageEffect as m, INIT_ADDITIVE_POLICY as n, contractToSchemaIR as o, fieldRenameStorageEffect as p, TABLE_NAME_CASE_CHANGED_CODE as r, controlPolicyForCall as s, COLUMN_RENAME_UNMATCHED_CODE as t, detectDestructiveChanges as u, planFieldEventOperations as v, runnerFailure as w, plannerSuccess as x, planStatements as y };
|
|
1889
2059
|
|
|
1890
|
-
//# sourceMappingURL=control-
|
|
2060
|
+
//# sourceMappingURL=control-BRbds4vn.mjs.map
|