@prisma-next/family-sql 0.5.0-dev.67 → 0.5.0-dev.68
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-adapter.d.mts +8 -0
- package/dist/control-adapter.d.mts.map +1 -1
- package/dist/control.d.mts +26 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +143 -3
- package/dist/control.mjs.map +1 -1
- package/dist/migration.d.mts +1 -1
- package/dist/schema-verify.d.mts +1 -1
- package/dist/{types-Ds4dJyTI.d.mts → types-CIdiS2QK.d.mts} +117 -3
- package/dist/types-CIdiS2QK.d.mts.map +1 -0
- package/dist/verify-sql-schema-C84vejAP.mjs.map +1 -1
- package/package.json +18 -18
- package/src/core/control-adapter.ts +11 -0
- package/src/core/control-instance.ts +70 -2
- package/src/core/migrations/field-event-planner.ts +196 -0
- package/src/core/migrations/types.ts +117 -1
- package/src/exports/control.ts +7 -0
- package/dist/types-Ds4dJyTI.d.mts.map +0 -1
|
@@ -28,6 +28,14 @@ interface SqlControlAdapter<TTarget extends string = string> extends ControlAdap
|
|
|
28
28
|
* @returns Resolved marker record, or `null` if not yet stamped.
|
|
29
29
|
*/
|
|
30
30
|
readMarker(driver: ControlDriverInstance<'sql', TTarget>, space: string): Promise<ContractMarkerRecord | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Reads every marker row from `prisma_contract.marker` (one per
|
|
33
|
+
* contract space) and returns them keyed by `space`. Used by the
|
|
34
|
+
* per-space verifier to detect marker-vs-on-disk drift and orphan
|
|
35
|
+
* marker rows. Returns an empty map when the marker table does not
|
|
36
|
+
* yet exist (fresh database / never-signed project).
|
|
37
|
+
*/
|
|
38
|
+
readAllMarkers(driver: ControlDriverInstance<'sql', TTarget>): Promise<ReadonlyMap<string, ContractMarkerRecord>>;
|
|
31
39
|
/**
|
|
32
40
|
* Introspects a database schema and returns a raw SqlSchemaIR.
|
|
33
41
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-adapter.d.mts","names":[],"sources":["../src/core/control-adapter.ts"],"mappings":";;;;;;;;;AAoBA;;;;UAAiB,iBAAA,0CACP,sBAAA,QAA8B,OAAA;EAiB5B;;;;;;;;;;;;;;;EADV,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,WACC,OAAA,CAAQ,oBAAA;
|
|
1
|
+
{"version":3,"file":"control-adapter.d.mts","names":[],"sources":["../src/core/control-adapter.ts"],"mappings":";;;;;;;;;AAoBA;;;;UAAiB,iBAAA,0CACP,sBAAA,QAA8B,OAAA;EAiB5B;;;;;;;;;;;;;;;EADV,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,WACC,OAAA,CAAQ,oBAAA;EAsDgD;;;;;;;EA7C3D,cAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,IACpC,OAAA,CAAQ,WAAA,SAAoB,oBAAA;EAbrB;;;;;;;;;;;;EA2BV,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,QAAA,YACA,MAAA,YACC,OAAA,CAAQ,WAAA;EAJX;;;;;EAAA,SAWS,gBAAA,GAAmB,iBAAA;EAPzB;;;;;EAAA,SAcM,mBAAA,GAAsB,oBAAA;EAW/B;;;;;;;;AASF;EATE,KAAA,CAAM,GAAA,EAAK,WAAA,EAAa,OAAA,EAAS,cAAA,YAA0B,gBAAA;AAAA;;;;;;;UAS5C,2BAAA;EAOf;;;;;;EAAA,MAAA,CAAO,KAAA,EAAO,YAAA,QAAoB,OAAA,IAAW,iBAAA,CAAkB,OAAA;AAAA"}
|
package/dist/control.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as SqlPlanTargetDetails, B as SchemaVerifyOptions, C as SqlMigrationRunner, D as SqlMigrationRunnerFailure, E as SqlMigrationRunnerExecuteOptions, F as SqlPlannerResult, I as SqlPlannerSuccessResult, L as StorageTypePlanResult, M as SqlPlannerConflictKind, N as SqlPlannerConflictLocation, O as SqlMigrationRunnerResult, P as SqlPlannerFailureResult, R as collectInitDependencies, S as SqlMigrationPlannerPlanOptions, T as SqlMigrationRunnerExecuteCallbacks, V as SqlControlFamilyInstance, _ as SqlMigrationPlanContractInfo, a as CreateSqlMigrationPlanOptions, b as SqlMigrationPlanOperationTarget, c as FieldEventContext, d as MultiSpaceRunnerSuccessValue, f as ResolveIdentityValueInput, g as SqlMigrationPlan, h as SqlControlTargetDescriptor, i as ComponentDatabaseDependency, j as SqlPlannerConflict, k as SqlMigrationRunnerSuccessValue, l as MultiSpaceRunnerFailure, m as SqlControlExtensionDescriptor, n as CodecControlHooks, o as ExpandNativeTypeInput, p as SqlControlAdapterDescriptor, r as ComponentDatabaseDependencies, s as FieldEvent, t as AnyRecord, u as MultiSpaceRunnerResult, v as SqlMigrationPlanOperation, w as SqlMigrationRunnerErrorCode, x as SqlMigrationPlanner, y as SqlMigrationPlanOperationStep, z as isDatabaseDependencyProvider } from "./types-CIdiS2QK.mjs";
|
|
2
2
|
import { ControlFamilyDescriptor, ControlStack, MigrationOperationClass, MigrationOperationPolicy, MigrationOperationPolicy as MigrationOperationPolicy$1, MigrationPlan, MigrationPlanOperation, MigrationPlanner, MigrationPlannerConflict, MigrationPlannerConflict as MigrationPlannerConflict$1, MigrationPlannerResult, MutationDefaultGeneratorDescriptor, TargetMigrationsCapability, assembleAuthoringContributions } from "@prisma-next/framework-components/control";
|
|
3
3
|
import { NotOk, Ok } from "@prisma-next/utils/result";
|
|
4
4
|
import { ColumnDefault, Contract } from "@prisma-next/contract/types";
|
|
@@ -304,6 +304,30 @@ interface ContractToSchemaIROptions {
|
|
|
304
304
|
*/
|
|
305
305
|
declare function contractToSchemaIR(contract: Contract<SqlStorage> | null, options: ContractToSchemaIROptions): SqlSchemaIR;
|
|
306
306
|
//#endregion
|
|
307
|
+
//#region src/core/migrations/field-event-planner.d.ts
|
|
308
|
+
interface PlanFieldEventOperationsOptions {
|
|
309
|
+
/**
|
|
310
|
+
* Prior contract the planner is diffing against. `null` for first emits
|
|
311
|
+
* (every field is treated as added).
|
|
312
|
+
*/
|
|
313
|
+
readonly priorContract: Contract<SqlStorage> | null;
|
|
314
|
+
/**
|
|
315
|
+
* New contract the user just authored.
|
|
316
|
+
*/
|
|
317
|
+
readonly newContract: Contract<SqlStorage>;
|
|
318
|
+
/**
|
|
319
|
+
* Codec-id keyed map of control hooks, as produced by
|
|
320
|
+
* {@link import('./assembly').extractCodecControlHooks}. Hooks carry
|
|
321
|
+
* `unknown` target details after extraction; the caller casts the
|
|
322
|
+
* helper's returned ops to its target's `SqlMigrationPlanOperation`
|
|
323
|
+
* specialisation at the integration boundary, mirroring how
|
|
324
|
+
* `storageTypePlanCallStrategy` lifts `planTypeOperations` results into
|
|
325
|
+
* `RawSqlCall`.
|
|
326
|
+
*/
|
|
327
|
+
readonly codecHooks: ReadonlyMap<string, CodecControlHooks>;
|
|
328
|
+
}
|
|
329
|
+
declare function planFieldEventOperations(options: PlanFieldEventOperationsOptions): readonly SqlMigrationPlanOperation<unknown>[];
|
|
330
|
+
//#endregion
|
|
307
331
|
//#region src/core/migrations/plan-helpers.d.ts
|
|
308
332
|
declare function createMigrationPlan<TTargetDetails>(options: CreateSqlMigrationPlanOptions<TTargetDetails>): SqlMigrationPlan<TTargetDetails>;
|
|
309
333
|
declare function plannerSuccess<TTargetDetails>(plan: SqlMigrationPlan<TTargetDetails>): SqlPlannerSuccessResult<TTargetDetails>;
|
|
@@ -389,5 +413,5 @@ declare function temporalAuthoringPresets<const CodecId extends string, const Na
|
|
|
389
413
|
//#region src/exports/control.d.ts
|
|
390
414
|
declare const _default: SqlFamilyDescriptor;
|
|
391
415
|
//#endregion
|
|
392
|
-
export { type CodecControlHooks, type ComponentDatabaseDependencies, type ComponentDatabaseDependency, type ContractToSchemaIROptions, type CreateSqlMigrationPlanOptions, type DefaultRenderer, type ExpandNativeTypeInput, INIT_ADDITIVE_POLICY, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerResult, type NativeTypeExpander, type ResolveIdentityValueInput, type SchemaVerifyOptions, type SqlControlAdapterDescriptor, type SqlControlExtensionDescriptor, type SqlControlFamilyInstance, type SqlControlTargetDescriptor, type SqlMigrationPlan, type SqlMigrationPlanContractInfo, type SqlMigrationPlanOperation, type SqlMigrationPlanOperationStep, type SqlMigrationPlanOperationTarget, type SqlMigrationPlanner, type SqlMigrationPlannerPlanOptions, type SqlMigrationRunner, type SqlMigrationRunnerErrorCode, type SqlMigrationRunnerExecuteCallbacks, type SqlMigrationRunnerExecuteOptions, type SqlMigrationRunnerFailure, type SqlMigrationRunnerResult, type SqlMigrationRunnerSuccessValue, type SqlPlanTargetDetails, type SqlPlannerConflict, type SqlPlannerConflictKind, type SqlPlannerConflictLocation, type SqlPlannerFailureResult, type SqlPlannerResult, type SqlPlannerSuccessResult, type StorageTypePlanResult, type TargetMigrationsCapability, assembleAuthoringContributions, collectInitDependencies, contractToSchemaIR, createMigrationPlan, _default as default, detectDestructiveChanges, extractCodecControlHooks, isDatabaseDependencyProvider, plannerFailure, plannerSuccess, runnerFailure, runnerSuccess, temporalAuthoringPresets, timestampNowControlDescriptor };
|
|
416
|
+
export { type CodecControlHooks, type ComponentDatabaseDependencies, type ComponentDatabaseDependency, type ContractToSchemaIROptions, type CreateSqlMigrationPlanOptions, type DefaultRenderer, type ExpandNativeTypeInput, type FieldEvent, type FieldEventContext, INIT_ADDITIVE_POLICY, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerResult, type MultiSpaceRunnerFailure, type MultiSpaceRunnerResult, type MultiSpaceRunnerSuccessValue, type NativeTypeExpander, type PlanFieldEventOperationsOptions, type ResolveIdentityValueInput, type SchemaVerifyOptions, type SqlControlAdapterDescriptor, type SqlControlExtensionDescriptor, type SqlControlFamilyInstance, type SqlControlTargetDescriptor, type SqlMigrationPlan, type SqlMigrationPlanContractInfo, type SqlMigrationPlanOperation, type SqlMigrationPlanOperationStep, type SqlMigrationPlanOperationTarget, type SqlMigrationPlanner, type SqlMigrationPlannerPlanOptions, type SqlMigrationRunner, type SqlMigrationRunnerErrorCode, type SqlMigrationRunnerExecuteCallbacks, type SqlMigrationRunnerExecuteOptions, type SqlMigrationRunnerFailure, type SqlMigrationRunnerResult, type SqlMigrationRunnerSuccessValue, type SqlPlanTargetDetails, type SqlPlannerConflict, type SqlPlannerConflictKind, type SqlPlannerConflictLocation, type SqlPlannerFailureResult, type SqlPlannerResult, type SqlPlannerSuccessResult, type StorageTypePlanResult, type TargetMigrationsCapability, assembleAuthoringContributions, collectInitDependencies, contractToSchemaIR, createMigrationPlan, _default as default, detectDestructiveChanges, extractCodecControlHooks, isDatabaseDependencyProvider, planFieldEventOperations, plannerFailure, plannerSuccess, runnerFailure, runnerSuccess, temporalAuthoringPresets, timestampNowControlDescriptor };
|
|
393
417
|
//# sourceMappingURL=control.d.mts.map
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-descriptor.ts","../src/core/assembly.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/core/timestamp-now-generator.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;cAUa,mBAAA,YACA,uBAAA,QAA+B,wBAAA;EAAA,SAEjC,IAAA;EAAA,SACA,EAAA;EAAA,SACA,QAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA,EAAU,WAAA;EAAA,SACV,SAAA;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKT,MAAA,0BAAA,CACE,KAAA,EAAO,YAAA,QAAoB,SAAA,IAC1B,wBAAA;AAAA;;;iBCHW,wBAAA,CACd,WAAA,EAAa,aAAA,CAAc,8BAAA,mBAC1B,GAAA,SAAY,iBAAA;;;;;;;;ADdf;;;;;KE0BY,kBAAA,IAAsB,KAAA;EAAA,SACvB,UAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,MAAA;AAAA;;;;;;;;;;KAYZ,eAAA,IAAmB,GAAA,EAAK,aAAA,EAAe,MAAA,EAAQ,aAAA;;;;;;;;;;iBAuI3C,wBAAA,CACd,IAAA,EAAM,UAAA,SACN,EAAA,EAAI,UAAA,YACM,0BAAA;AAAA,UAiCK,yBAAA;EAAA,SACN,mBAAA;EAAA,SACA,gBAAA,GAAmB,kBAAA;EAAA,SACnB,aAAA,GAAgB,eAAA;EAAA,SAChB,mBAAA,GAAsB,aAAA,CAAc,8BAAA;AAAA;;;;;;;;;;;;;;;;iBAkB/B,kBAAA,CACd,QAAA,EAAU,QAAA,CAAS,UAAA,UACnB,OAAA,EAAS,yBAAA,GACR,WAAA;;;
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-descriptor.ts","../src/core/assembly.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/field-event-planner.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/core/timestamp-now-generator.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;cAUa,mBAAA,YACA,uBAAA,QAA+B,wBAAA;EAAA,SAEjC,IAAA;EAAA,SACA,EAAA;EAAA,SACA,QAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA,EAAU,WAAA;EAAA,SACV,SAAA;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKT,MAAA,0BAAA,CACE,KAAA,EAAO,YAAA,QAAoB,SAAA,IAC1B,wBAAA;AAAA;;;iBCHW,wBAAA,CACd,WAAA,EAAa,aAAA,CAAc,8BAAA,mBAC1B,GAAA,SAAY,iBAAA;;;;;;;;ADdf;;;;;KE0BY,kBAAA,IAAsB,KAAA;EAAA,SACvB,UAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,MAAA;AAAA;;;;;;;;;;KAYZ,eAAA,IAAmB,GAAA,EAAK,aAAA,EAAe,MAAA,EAAQ,aAAA;;;;;;;;;;iBAuI3C,wBAAA,CACd,IAAA,EAAM,UAAA,SACN,EAAA,EAAI,UAAA,YACM,0BAAA;AAAA,UAiCK,yBAAA;EAAA,SACN,mBAAA;EAAA,SACA,gBAAA,GAAmB,kBAAA;EAAA,SACnB,aAAA,GAAgB,eAAA;EAAA,SAChB,mBAAA,GAAsB,aAAA,CAAc,8BAAA;AAAA;;;;;;;;;;;;;;;;iBAkB/B,kBAAA,CACd,QAAA,EAAU,QAAA,CAAS,UAAA,UACnB,OAAA,EAAS,yBAAA,GACR,WAAA;;;UCxNc,+BAAA;EHhBN;;;;EAAA,SGqBA,aAAA,EAAe,QAAA,CAAS,UAAA;;;;WAIxB,WAAA,EAAa,QAAA,CAAS,UAAA;;;;;;;;;;WAUtB,UAAA,EAAY,WAAA,SAAoB,iBAAA;AAAA;AAAA,iBAY3B,wBAAA,CACd,OAAA,EAAS,+BAAA,YACC,yBAAA;;;iBC+BI,mBAAA,gBAAA,CACd,OAAA,EAAS,6BAAA,CAA8B,cAAA,IACtC,gBAAA,CAAiB,cAAA;AAAA,iBAcJ,cAAA,gBAAA,CACd,IAAA,EAAM,gBAAA,CAAiB,cAAA,IACtB,uBAAA,CAAwB,cAAA;AAAA,iBAOX,cAAA,CAAe,SAAA,WAAoB,kBAAA,KAAuB,uBAAA;;;;iBAoB1D,aAAA,CAAc,KAAA;EAC5B,iBAAA;EACA,kBAAA;AAAA,IACE,EAAA,CAAG,8BAAA;;;;iBAYS,aAAA,CACd,IAAA,EAAM,2BAAA,EACN,OAAA,UACA,OAAA;EAAY,GAAA;EAAc,IAAA,GAAO,SAAA;AAAA,IAChC,KAAA,CAAM,yBAAA;;;;;;cC1JI,oBAAA,EAAsB,0BAAA;;;;;;;;;;;;;;iBCsBnB,6BAAA,CAAA,GAAiC,kCAAA;;;;;;;;;;;iBAoBjC,wBAAA,+DAAA,CAGd,KAAA;EAAA,SAAkB,OAAA,EAAS,OAAA;EAAA,SAAkB,UAAA,EAAY,UAAA;AAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cC4BlB,QAAA"}
|
package/dist/control.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { n as temporalAuthoringPresets, r as timestampNowControlDescriptor } fro
|
|
|
5
5
|
import { sqlEmission } from "@prisma-next/sql-contract-emitter";
|
|
6
6
|
import { emptyCodecLookup } from "@prisma-next/framework-components/codec";
|
|
7
7
|
import { APP_SPACE_ID, SchemaTreeNode, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_TARGET_MISMATCH, assembleAuthoringContributions } from "@prisma-next/framework-components/control";
|
|
8
|
+
import { assertDescriptorSelfConsistency } from "@prisma-next/migration-tools/spaces";
|
|
8
9
|
import { validateContract } from "@prisma-next/sql-contract/validate";
|
|
9
10
|
import { ensureSchemaStatement, ensureTableStatement, writeContractMarker } from "@prisma-next/sql-runtime";
|
|
10
11
|
import { defaultIndexName } from "@prisma-next/sql-schema-ir/naming";
|
|
@@ -1047,7 +1048,7 @@ function createVerifyResult(options) {
|
|
|
1047
1048
|
return result;
|
|
1048
1049
|
}
|
|
1049
1050
|
function isSqlControlAdapter(value) {
|
|
1050
|
-
return typeof value === "object" && value !== null && "introspect" in value && typeof value.introspect === "function" && "readMarker" in value && typeof value.readMarker === "function";
|
|
1051
|
+
return typeof value === "object" && value !== null && "introspect" in value && typeof value.introspect === "function" && "readMarker" in value && typeof value.readMarker === "function" && "readAllMarkers" in value && typeof value.readAllMarkers === "function";
|
|
1051
1052
|
}
|
|
1052
1053
|
function buildSqlTypeMetadataRegistry(options) {
|
|
1053
1054
|
const { target, adapter, extensionPacks: extensions } = options;
|
|
@@ -1075,6 +1076,16 @@ function createSqlFamilyInstance(stack) {
|
|
|
1075
1076
|
const target = stack.target;
|
|
1076
1077
|
const adapter = stack.adapter;
|
|
1077
1078
|
const extensions = stack.extensionPacks;
|
|
1079
|
+
for (const extension of extensions) if (extension.contractSpace) {
|
|
1080
|
+
const { contractJson, headRef } = extension.contractSpace;
|
|
1081
|
+
assertDescriptorSelfConsistency({
|
|
1082
|
+
extensionId: extension.id,
|
|
1083
|
+
target: contractJson.target,
|
|
1084
|
+
targetFamily: contractJson.targetFamily,
|
|
1085
|
+
storage: contractJson.storage,
|
|
1086
|
+
headRefHash: headRef.hash
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1078
1089
|
const { codecTypeImports, operationTypeImports, extensionIds } = stack;
|
|
1079
1090
|
const typeMetadataRegistry = buildSqlTypeMetadataRegistry({
|
|
1080
1091
|
target,
|
|
@@ -1083,7 +1094,7 @@ function createSqlFamilyInstance(stack) {
|
|
|
1083
1094
|
});
|
|
1084
1095
|
const getControlAdapter = () => {
|
|
1085
1096
|
const controlAdapter = adapter.create(stack);
|
|
1086
|
-
if (!isSqlControlAdapter(controlAdapter)) throw new Error("Adapter does not implement SqlControlAdapter (missing introspect or
|
|
1097
|
+
if (!isSqlControlAdapter(controlAdapter)) throw new Error("Adapter does not implement SqlControlAdapter (missing introspect, readMarker, or readAllMarkers)");
|
|
1087
1098
|
return controlAdapter;
|
|
1088
1099
|
};
|
|
1089
1100
|
return {
|
|
@@ -1201,6 +1212,19 @@ function createSqlFamilyInstance(stack) {
|
|
|
1201
1212
|
...ifDefined("normalizeNativeType", controlAdapter.normalizeNativeType)
|
|
1202
1213
|
});
|
|
1203
1214
|
},
|
|
1215
|
+
schemaVerifyAgainstSchema(options) {
|
|
1216
|
+
const contract = validateContract(options.contract, emptyCodecLookup);
|
|
1217
|
+
const controlAdapter = getControlAdapter();
|
|
1218
|
+
return verifySqlSchema({
|
|
1219
|
+
contract,
|
|
1220
|
+
schema: options.schema,
|
|
1221
|
+
strict: options.strict,
|
|
1222
|
+
typeMetadataRegistry,
|
|
1223
|
+
frameworkComponents: options.frameworkComponents,
|
|
1224
|
+
...ifDefined("normalizeDefault", controlAdapter.normalizeDefault),
|
|
1225
|
+
...ifDefined("normalizeNativeType", controlAdapter.normalizeNativeType)
|
|
1226
|
+
});
|
|
1227
|
+
},
|
|
1204
1228
|
async sign(options) {
|
|
1205
1229
|
const { driver, contract: contractInput, contractPath, configPath } = options;
|
|
1206
1230
|
const startTime = Date.now();
|
|
@@ -1274,6 +1298,9 @@ function createSqlFamilyInstance(stack) {
|
|
|
1274
1298
|
async readMarker(options) {
|
|
1275
1299
|
return getControlAdapter().readMarker(options.driver, options.space);
|
|
1276
1300
|
},
|
|
1301
|
+
async readAllMarkers(options) {
|
|
1302
|
+
return getControlAdapter().readAllMarkers(options.driver);
|
|
1303
|
+
},
|
|
1277
1304
|
async introspect(options) {
|
|
1278
1305
|
return getControlAdapter().introspect(options.driver, options.contract);
|
|
1279
1306
|
},
|
|
@@ -1552,6 +1579,119 @@ function deriveAnnotations(storage, annotationNamespace) {
|
|
|
1552
1579
|
return { [annotationNamespace]: { storageTypes: byNativeType } };
|
|
1553
1580
|
}
|
|
1554
1581
|
//#endregion
|
|
1582
|
+
//#region src/core/migrations/field-event-planner.ts
|
|
1583
|
+
function planFieldEventOperations(options) {
|
|
1584
|
+
const priorTables = options.priorContract?.storage.tables ?? {};
|
|
1585
|
+
const newTables = options.newContract.storage.tables;
|
|
1586
|
+
const added = [];
|
|
1587
|
+
const dropped = [];
|
|
1588
|
+
const altered = [];
|
|
1589
|
+
const tableNames = unionSorted(Object.keys(priorTables), Object.keys(newTables));
|
|
1590
|
+
for (const tableName of tableNames) {
|
|
1591
|
+
const priorTable = priorTables[tableName];
|
|
1592
|
+
const newTable = newTables[tableName];
|
|
1593
|
+
const fieldNames = unionSorted(priorTable ? Object.keys(priorTable.columns) : [], newTable ? Object.keys(newTable.columns) : []);
|
|
1594
|
+
for (const fieldName of fieldNames) {
|
|
1595
|
+
const priorField = priorTable?.columns[fieldName];
|
|
1596
|
+
const newField = newTable?.columns[fieldName];
|
|
1597
|
+
const entry = {
|
|
1598
|
+
tableName,
|
|
1599
|
+
fieldName,
|
|
1600
|
+
priorTable,
|
|
1601
|
+
newTable,
|
|
1602
|
+
priorField,
|
|
1603
|
+
newField
|
|
1604
|
+
};
|
|
1605
|
+
if (priorField === void 0 && newField !== void 0) added.push(entry);
|
|
1606
|
+
else if (priorField !== void 0 && newField === void 0) dropped.push(entry);
|
|
1607
|
+
else if (priorField !== void 0 && newField !== void 0) {
|
|
1608
|
+
if (isAlteration(priorField, newField)) altered.push(entry);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
const ops = [];
|
|
1613
|
+
appendOps("added", added, options.codecHooks, ops, (e) => e.newField?.codecId);
|
|
1614
|
+
appendOps("dropped", dropped, options.codecHooks, ops, (e) => e.priorField?.codecId);
|
|
1615
|
+
appendOps("altered", altered, options.codecHooks, ops, (e) => e.newField?.codecId);
|
|
1616
|
+
return ops;
|
|
1617
|
+
}
|
|
1618
|
+
function appendOps(event, entries, codecHooks, ops, pickCodecId) {
|
|
1619
|
+
for (const entry of entries) {
|
|
1620
|
+
const codecId = pickCodecId(entry);
|
|
1621
|
+
if (codecId === void 0) continue;
|
|
1622
|
+
const hook = codecHooks.get(codecId);
|
|
1623
|
+
if (!hook?.onFieldEvent) continue;
|
|
1624
|
+
const ctx = buildContext(event, entry);
|
|
1625
|
+
const emitted = hook.onFieldEvent(event, ctx);
|
|
1626
|
+
for (const op of emitted) ops.push(op);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
/**
|
|
1630
|
+
* The context's prior/new sides are scoped to the event:
|
|
1631
|
+
*
|
|
1632
|
+
* - `'added'` — only `newTable` / `newField` populated.
|
|
1633
|
+
* - `'dropped'` — only `priorTable` / `priorField` populated.
|
|
1634
|
+
* - `'altered'` — both sides populated.
|
|
1635
|
+
*/
|
|
1636
|
+
function buildContext(event, entry) {
|
|
1637
|
+
const base = {
|
|
1638
|
+
tableName: entry.tableName,
|
|
1639
|
+
fieldName: entry.fieldName
|
|
1640
|
+
};
|
|
1641
|
+
if (event === "added") return {
|
|
1642
|
+
...base,
|
|
1643
|
+
...entry.newTable !== void 0 ? { newTable: entry.newTable } : {},
|
|
1644
|
+
...entry.newField !== void 0 ? { newField: entry.newField } : {}
|
|
1645
|
+
};
|
|
1646
|
+
if (event === "dropped") return {
|
|
1647
|
+
...base,
|
|
1648
|
+
...entry.priorTable !== void 0 ? { priorTable: entry.priorTable } : {},
|
|
1649
|
+
...entry.priorField !== void 0 ? { priorField: entry.priorField } : {}
|
|
1650
|
+
};
|
|
1651
|
+
return {
|
|
1652
|
+
...base,
|
|
1653
|
+
...entry.priorTable !== void 0 ? { priorTable: entry.priorTable } : {},
|
|
1654
|
+
...entry.newTable !== void 0 ? { newTable: entry.newTable } : {},
|
|
1655
|
+
...entry.priorField !== void 0 ? { priorField: entry.priorField } : {},
|
|
1656
|
+
...entry.newField !== void 0 ? { newField: entry.newField } : {}
|
|
1657
|
+
};
|
|
1658
|
+
}
|
|
1659
|
+
/**
|
|
1660
|
+
* `'altered'` predicate. Returns `false` whenever `codecId` differs —
|
|
1661
|
+
* any codec change suppresses the `altered` event entirely, including
|
|
1662
|
+
* cases where another property also differs in the same diff. Codec
|
|
1663
|
+
* rotation is a v1 non-goal (project spec § Non-goals); avoiding the
|
|
1664
|
+
* mixed event keeps the migration semantics for codec changes explicit
|
|
1665
|
+
* (out of scope) rather than smuggling them through as `altered`.
|
|
1666
|
+
*
|
|
1667
|
+
* For non-`codecId` diffs, returns `true` iff any other column property
|
|
1668
|
+
* differs.
|
|
1669
|
+
*/
|
|
1670
|
+
function isAlteration(prior, current) {
|
|
1671
|
+
if (prior.codecId !== current.codecId) return false;
|
|
1672
|
+
return !sameStorageColumn(prior, current);
|
|
1673
|
+
}
|
|
1674
|
+
function sameStorageColumn(a, b) {
|
|
1675
|
+
if (a === b) return true;
|
|
1676
|
+
if (a.nativeType !== b.nativeType) return false;
|
|
1677
|
+
if (a.nullable !== b.nullable) return false;
|
|
1678
|
+
if (a.typeRef !== b.typeRef) return false;
|
|
1679
|
+
if (!sameJson(a.typeParams, b.typeParams)) return false;
|
|
1680
|
+
if (!sameJson(a.default, b.default)) return false;
|
|
1681
|
+
return true;
|
|
1682
|
+
}
|
|
1683
|
+
function sameJson(a, b) {
|
|
1684
|
+
if (a === b) return true;
|
|
1685
|
+
if (a === void 0 || b === void 0) return false;
|
|
1686
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
1687
|
+
}
|
|
1688
|
+
function unionSorted(a, b) {
|
|
1689
|
+
const set = /* @__PURE__ */ new Set();
|
|
1690
|
+
for (const name of a) set.add(name);
|
|
1691
|
+
for (const name of b) set.add(name);
|
|
1692
|
+
return [...set].sort((x, y) => x < y ? -1 : x > y ? 1 : 0);
|
|
1693
|
+
}
|
|
1694
|
+
//#endregion
|
|
1555
1695
|
//#region src/core/migrations/plan-helpers.ts
|
|
1556
1696
|
const readOnlyEmptyObject = Object.freeze({});
|
|
1557
1697
|
function cloneRecord(value) {
|
|
@@ -1656,6 +1796,6 @@ const INIT_ADDITIVE_POLICY = Object.freeze({ allowedOperationClasses: Object.fre
|
|
|
1656
1796
|
//#region src/exports/control.ts
|
|
1657
1797
|
var control_default = new SqlFamilyDescriptor();
|
|
1658
1798
|
//#endregion
|
|
1659
|
-
export { INIT_ADDITIVE_POLICY, assembleAuthoringContributions, collectInitDependencies, contractToSchemaIR, createMigrationPlan, control_default as default, detectDestructiveChanges, extractCodecControlHooks, isDatabaseDependencyProvider, plannerFailure, plannerSuccess, runnerFailure, runnerSuccess, temporalAuthoringPresets, timestampNowControlDescriptor };
|
|
1799
|
+
export { INIT_ADDITIVE_POLICY, assembleAuthoringContributions, collectInitDependencies, contractToSchemaIR, createMigrationPlan, control_default as default, detectDestructiveChanges, extractCodecControlHooks, isDatabaseDependencyProvider, planFieldEventOperations, plannerFailure, plannerSuccess, runnerFailure, runnerSuccess, temporalAuthoringPresets, timestampNowControlDescriptor };
|
|
1660
1800
|
|
|
1661
1801
|
//# sourceMappingURL=control.mjs.map
|