@prisma-next/family-sql 0.5.0-dev.66 → 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/{authoring-type-constructors-D9b8AG6y.mjs → authoring-type-constructors-F4JpCJl7.mjs} +2 -3
- package/dist/{authoring-type-constructors-D9b8AG6y.mjs.map → authoring-type-constructors-F4JpCJl7.mjs.map} +1 -1
- package/dist/control-adapter.d.mts +9 -2
- package/dist/control-adapter.d.mts.map +1 -1
- package/dist/control-adapter.mjs +1 -1
- package/dist/control.d.mts +28 -16
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +148 -22
- package/dist/control.mjs.map +1 -1
- package/dist/migration.d.mts +1 -2
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +1 -2
- package/dist/migration.mjs.map +1 -1
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +3 -5
- package/dist/pack.mjs.map +1 -1
- package/dist/runtime.d.mts +0 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +2 -6
- package/dist/runtime.mjs.map +1 -1
- package/dist/schema-verify.d.mts +2 -4
- package/dist/schema-verify.d.mts.map +1 -1
- package/dist/schema-verify.mjs +2 -3
- package/dist/test-utils.mjs +1 -2
- package/dist/{timestamp-now-generator-Bt4L3cfM.mjs → timestamp-now-generator-BWp8S2sa.mjs} +2 -2
- package/dist/{timestamp-now-generator-Bt4L3cfM.mjs.map → timestamp-now-generator-BWp8S2sa.mjs.map} +1 -1
- package/dist/{types-DFQkcr8A.d.mts → types-CIdiS2QK.d.mts} +117 -3
- package/dist/types-CIdiS2QK.d.mts.map +1 -0
- package/dist/{verify-BdES8wgQ.mjs → verify-pRYxnpiG.mjs} +2 -3
- package/dist/verify-pRYxnpiG.mjs.map +1 -0
- package/dist/{verify-sql-schema-Ovz7RXR5.mjs → verify-sql-schema-C84vejAP.mjs} +2 -6
- package/dist/verify-sql-schema-C84vejAP.mjs.map +1 -0
- package/dist/{verify-sql-schema-DW8Agf1F.d.mts → verify-sql-schema-CPHiuYHR.d.mts} +1 -2
- package/dist/verify-sql-schema-CPHiuYHR.d.mts.map +1 -0
- package/dist/verify.d.mts +0 -1
- package/dist/verify.d.mts.map +1 -1
- package/dist/verify.mjs +2 -3
- package/package.json +23 -23
- package/src/core/control-adapter.ts +11 -0
- package/src/core/control-descriptor.ts +2 -1
- 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-DFQkcr8A.d.mts.map +0 -1
- package/dist/verify-BdES8wgQ.mjs.map +0 -1
- package/dist/verify-sql-schema-DW8Agf1F.d.mts.map +0 -1
- package/dist/verify-sql-schema-Ovz7RXR5.mjs.map +0 -1
package/dist/{authoring-type-constructors-D9b8AG6y.mjs → authoring-type-constructors-F4JpCJl7.mjs}
RENAMED
|
@@ -166,7 +166,6 @@ const sqlFamilyAuthoringFieldPresets = {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
|
-
|
|
170
169
|
//#endregion
|
|
171
170
|
//#region src/core/authoring-type-constructors.ts
|
|
172
171
|
const sqlFamilyAuthoringTypes = { sql: { String: {
|
|
@@ -187,7 +186,7 @@ const sqlFamilyAuthoringTypes = { sql: { String: {
|
|
|
187
186
|
} }
|
|
188
187
|
}
|
|
189
188
|
} } };
|
|
190
|
-
|
|
191
189
|
//#endregion
|
|
192
190
|
export { sqlFamilyAuthoringFieldPresets as n, sqlFamilyAuthoringTypes as t };
|
|
193
|
-
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=authoring-type-constructors-F4JpCJl7.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authoring-type-constructors-
|
|
1
|
+
{"version":3,"file":"authoring-type-constructors-F4JpCJl7.mjs","names":[],"sources":["../src/core/authoring-field-presets.ts","../src/core/authoring-type-constructors.ts"],"sourcesContent":["import type { AuthoringFieldNamespace } from '@prisma-next/framework-components/authoring';\n\n/**\n * Family-level SQL authoring field presets.\n *\n * Only presets whose codec IDs align with the ID generator metadata live here\n * (see `@prisma-next/ids`). These presets are target-agnostic because the\n * generator metadata fixes their codec/native-type to `sql/char@1`\n * (`character`) regardless of target, and the PSL interpreter lets the\n * generator override the scalar descriptor.\n *\n * Scalar presets that map to target-specific codecs (e.g. `text`, `int`,\n * `boolean`, `dateTime`) are contributed by the target pack (see\n * `postgresAuthoringFieldPresets` in `@prisma-next/target-postgres`) so the\n * TS callback surface and the PSL scalar surface lower to byte-identical\n * contracts for the active target.\n */\n\nconst CHARACTER_CODEC_ID = 'sql/char@1';\nconst CHARACTER_NATIVE_TYPE = 'character';\n\nconst nanoidOptionsArgument = {\n kind: 'object',\n optional: true,\n properties: {\n size: {\n kind: 'number',\n optional: true,\n integer: true,\n minimum: 2,\n maximum: 255,\n },\n },\n} as const;\n\nexport const sqlFamilyAuthoringFieldPresets = {\n uuid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 36,\n },\n },\n },\n ulid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 26,\n },\n },\n },\n nanoid: {\n kind: 'fieldPreset',\n args: [nanoidOptionsArgument],\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: {\n kind: 'arg',\n index: 0,\n path: ['size'],\n default: 21,\n },\n },\n },\n },\n cuid2: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 24,\n },\n },\n },\n ksuid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 27,\n },\n },\n },\n id: {\n uuidv4: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 36,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv4',\n },\n },\n id: true,\n },\n },\n uuidv7: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 36,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv7',\n },\n },\n id: true,\n },\n },\n ulid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 26,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'ulid',\n },\n },\n id: true,\n },\n },\n nanoid: {\n kind: 'fieldPreset',\n args: [nanoidOptionsArgument],\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: {\n kind: 'arg',\n index: 0,\n path: ['size'],\n default: 21,\n },\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'nanoid',\n params: {\n size: {\n kind: 'arg',\n index: 0,\n path: ['size'],\n },\n },\n },\n },\n id: true,\n },\n },\n cuid2: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 24,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'cuid2',\n },\n },\n id: true,\n },\n },\n ksuid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 27,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'ksuid',\n },\n },\n id: true,\n },\n },\n },\n} as const satisfies AuthoringFieldNamespace;\n","import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';\n\nexport const sqlFamilyAuthoringTypes = {\n sql: {\n String: {\n kind: 'typeConstructor',\n args: [{ kind: 'number', name: 'length', integer: true, minimum: 1, maximum: 10485760 }],\n output: {\n codecId: 'sql/varchar@1',\n nativeType: 'character varying',\n typeParams: {\n length: { kind: 'arg', index: 0 },\n },\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,MAAM,qBAAqB;AAC3B,MAAM,wBAAwB;AAE9B,MAAM,wBAAwB;CAC5B,MAAM;CACN,UAAU;CACV,YAAY,EACV,MAAM;EACJ,MAAM;EACN,UAAU;EACV,SAAS;EACT,SAAS;EACT,SAAS;EACV,EACF;CACF;AAED,MAAa,iCAAiC;CAC5C,MAAM;EACJ,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACZ,YAAY,EACV,QAAQ,IACT;GACF;EACF;CACD,MAAM;EACJ,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACZ,YAAY,EACV,QAAQ,IACT;GACF;EACF;CACD,QAAQ;EACN,MAAM;EACN,MAAM,CAAC,sBAAsB;EAC7B,QAAQ;GACN,SAAS;GACT,YAAY;GACZ,YAAY,EACV,QAAQ;IACN,MAAM;IACN,OAAO;IACP,MAAM,CAAC,OAAO;IACd,SAAS;IACV,EACF;GACF;EACF;CACD,OAAO;EACL,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACZ,YAAY,EACV,QAAQ,IACT;GACF;EACF;CACD,OAAO;EACL,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACZ,YAAY,EACV,QAAQ,IACT;GACF;EACF;CACD,IAAI;EACF,QAAQ;GACN,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,IACT;IACD,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;KACL,EACF;IACD,IAAI;IACL;GACF;EACD,QAAQ;GACN,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,IACT;IACD,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;KACL,EACF;IACD,IAAI;IACL;GACF;EACD,MAAM;GACJ,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,IACT;IACD,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;KACL,EACF;IACD,IAAI;IACL;GACF;EACD,QAAQ;GACN,MAAM;GACN,MAAM,CAAC,sBAAsB;GAC7B,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ;KACN,MAAM;KACN,OAAO;KACP,MAAM,CAAC,OAAO;KACd,SAAS;KACV,EACF;IACD,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;KACJ,QAAQ,EACN,MAAM;MACJ,MAAM;MACN,OAAO;MACP,MAAM,CAAC,OAAO;MACf,EACF;KACF,EACF;IACD,IAAI;IACL;GACF;EACD,OAAO;GACL,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,IACT;IACD,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;KACL,EACF;IACD,IAAI;IACL;GACF;EACD,OAAO;GACL,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,IACT;IACD,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;KACL,EACF;IACD,IAAI;IACL;GACF;EACF;CACF;;;AC/MD,MAAa,0BAA0B,EACrC,KAAK,EACH,QAAQ;CACN,MAAM;CACN,MAAM,CAAC;EAAE,MAAM;EAAU,MAAM;EAAU,SAAS;EAAM,SAAS;EAAG,SAAS;EAAU,CAAC;CACxF,QAAQ;EACN,SAAS;EACT,YAAY;EACZ,YAAY,EACV,QAAQ;GAAE,MAAM;GAAO,OAAO;GAAG,EAClC;EACF;CACF,EACF,EACF"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { n as NativeTypeNormalizer, t as DefaultNormalizer } from "./verify-sql-schema-
|
|
1
|
+
import { n as NativeTypeNormalizer, t as DefaultNormalizer } from "./verify-sql-schema-CPHiuYHR.mjs";
|
|
2
2
|
import { ControlAdapterInstance, ControlDriverInstance, ControlStack } from "@prisma-next/framework-components/control";
|
|
3
3
|
import { ContractMarkerRecord } from "@prisma-next/contract/types";
|
|
4
4
|
import { AnyQueryAst, LoweredStatement, LowererContext } from "@prisma-next/sql-relational-core/ast";
|
|
5
5
|
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
6
6
|
|
|
7
7
|
//#region src/core/control-adapter.d.ts
|
|
8
|
-
|
|
9
8
|
/**
|
|
10
9
|
* SQL control adapter interface for control-plane operations.
|
|
11
10
|
* Implemented by target-specific adapters (e.g., Postgres, MySQL).
|
|
@@ -29,6 +28,14 @@ interface SqlControlAdapter<TTarget extends string = string> extends ControlAdap
|
|
|
29
28
|
* @returns Resolved marker record, or `null` if not yet stamped.
|
|
30
29
|
*/
|
|
31
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>>;
|
|
32
39
|
/**
|
|
33
40
|
* Introspects a database schema and returns a raw SqlSchemaIR.
|
|
34
41
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control-adapter.d.mts","names":[],"sources":["../src/core/control-adapter.ts"],"
|
|
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-adapter.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/dist/control.d.mts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
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
|
-
import * as _prisma_next_contract_types0 from "@prisma-next/contract/types";
|
|
5
4
|
import { ColumnDefault, Contract } from "@prisma-next/contract/types";
|
|
6
5
|
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
7
6
|
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
8
7
|
import { SqlStorage, StorageColumn } from "@prisma-next/sql-contract/types";
|
|
9
|
-
import
|
|
8
|
+
import { EmissionSpi } from "@prisma-next/framework-components/emission";
|
|
10
9
|
|
|
11
10
|
//#region src/core/control-descriptor.d.ts
|
|
12
11
|
declare class SqlFamilyDescriptor implements ControlFamilyDescriptor<'sql', SqlControlFamilyInstance> {
|
|
@@ -14,18 +13,7 @@ declare class SqlFamilyDescriptor implements ControlFamilyDescriptor<'sql', SqlC
|
|
|
14
13
|
readonly id = "sql";
|
|
15
14
|
readonly familyId: "sql";
|
|
16
15
|
readonly version = "0.0.1";
|
|
17
|
-
readonly emission:
|
|
18
|
-
readonly id: "sql";
|
|
19
|
-
readonly validateTypes: (contract: _prisma_next_contract_types0.Contract, _ctx: _prisma_next_framework_components_emission0.ValidationContext) => void;
|
|
20
|
-
readonly validateStructure: (contract: _prisma_next_contract_types0.Contract) => void;
|
|
21
|
-
readonly generateStorageType: (contract: _prisma_next_contract_types0.Contract, storageHashTypeName: string) => string;
|
|
22
|
-
readonly generateModelStorageType: (_modelName: string, model: _prisma_next_contract_types0.ContractModel) => string;
|
|
23
|
-
readonly resolveFieldTypeParams: (_modelName: string, fieldName: string, model: _prisma_next_contract_types0.ContractModel, contract: _prisma_next_contract_types0.Contract) => Record<string, unknown> | undefined;
|
|
24
|
-
readonly getFamilyImports: () => string[];
|
|
25
|
-
readonly getFamilyTypeAliases: (options?: _prisma_next_framework_components_emission0.GenerateContractTypesOptions) => string;
|
|
26
|
-
readonly getTypeMapsExpression: () => string;
|
|
27
|
-
readonly getContractWrapper: (contractBaseName: string, typeMapsName: string) => string;
|
|
28
|
-
};
|
|
16
|
+
readonly emission: EmissionSpi;
|
|
29
17
|
readonly authoring: {
|
|
30
18
|
readonly field: {
|
|
31
19
|
readonly uuid: {
|
|
@@ -316,6 +304,30 @@ interface ContractToSchemaIROptions {
|
|
|
316
304
|
*/
|
|
317
305
|
declare function contractToSchemaIR(contract: Contract<SqlStorage> | null, options: ContractToSchemaIROptions): SqlSchemaIR;
|
|
318
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
|
|
319
331
|
//#region src/core/migrations/plan-helpers.d.ts
|
|
320
332
|
declare function createMigrationPlan<TTargetDetails>(options: CreateSqlMigrationPlanOptions<TTargetDetails>): SqlMigrationPlan<TTargetDetails>;
|
|
321
333
|
declare function plannerSuccess<TTargetDetails>(plan: SqlMigrationPlan<TTargetDetails>): SqlPlannerSuccessResult<TTargetDetails>;
|
|
@@ -401,5 +413,5 @@ declare function temporalAuthoringPresets<const CodecId extends string, const Na
|
|
|
401
413
|
//#region src/exports/control.d.ts
|
|
402
414
|
declare const _default: SqlFamilyDescriptor;
|
|
403
415
|
//#endregion
|
|
404
|
-
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 };
|
|
405
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"],"
|
|
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
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { n as sqlFamilyAuthoringFieldPresets, t as sqlFamilyAuthoringTypes } from "./authoring-type-constructors-
|
|
2
|
-
import { c as extractCodecControlHooks, o as collectInitDependencies, s as isDatabaseDependencyProvider, t as verifySqlSchema } from "./verify-sql-schema-
|
|
3
|
-
import { t as collectSupportedCodecTypeIds } from "./verify-
|
|
4
|
-
import { n as temporalAuthoringPresets, r as timestampNowControlDescriptor } from "./timestamp-now-generator-
|
|
1
|
+
import { n as sqlFamilyAuthoringFieldPresets, t as sqlFamilyAuthoringTypes } from "./authoring-type-constructors-F4JpCJl7.mjs";
|
|
2
|
+
import { c as extractCodecControlHooks, o as collectInitDependencies, s as isDatabaseDependencyProvider, t as verifySqlSchema } from "./verify-sql-schema-C84vejAP.mjs";
|
|
3
|
+
import { t as collectSupportedCodecTypeIds } from "./verify-pRYxnpiG.mjs";
|
|
4
|
+
import { n as temporalAuthoringPresets, r as timestampNowControlDescriptor } from "./timestamp-now-generator-BWp8S2sa.mjs";
|
|
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";
|
|
11
12
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
12
13
|
import { notOk, ok } from "@prisma-next/utils/result";
|
|
13
|
-
|
|
14
14
|
//#region src/core/operation-preview.ts
|
|
15
15
|
function isDdlStatement(sqlStatement) {
|
|
16
16
|
const trimmed = sqlStatement.trim().toLowerCase();
|
|
@@ -43,7 +43,6 @@ function sqlOperationsToPreview(operations) {
|
|
|
43
43
|
language: "sql"
|
|
44
44
|
})) };
|
|
45
45
|
}
|
|
46
|
-
|
|
47
46
|
//#endregion
|
|
48
47
|
//#region src/core/psl-contract-infer/default-mapping.ts
|
|
49
48
|
const DEFAULT_FUNCTION_ATTRIBUTES = {
|
|
@@ -74,7 +73,6 @@ function quoteString(str) {
|
|
|
74
73
|
function escapeString(str) {
|
|
75
74
|
return JSON.stringify(str).slice(1, -1);
|
|
76
75
|
}
|
|
77
|
-
|
|
78
76
|
//#endregion
|
|
79
77
|
//#region src/core/psl-contract-infer/name-transforms.ts
|
|
80
78
|
const PSL_RESERVED_WORDS = new Set([
|
|
@@ -193,7 +191,6 @@ function toNamedTypeName(columnName) {
|
|
|
193
191
|
else name = columnName.charAt(0).toUpperCase() + columnName.slice(1);
|
|
194
192
|
return escapeIfNeeded(name);
|
|
195
193
|
}
|
|
196
|
-
|
|
197
194
|
//#endregion
|
|
198
195
|
//#region src/core/psl-contract-infer/postgres-default-mapping.ts
|
|
199
196
|
const POSTGRES_FUNCTION_ATTRIBUTES = { "gen_random_uuid()": "@default(dbgenerated(\"gen_random_uuid()\"))" };
|
|
@@ -206,7 +203,6 @@ function createPostgresDefaultMapping() {
|
|
|
206
203
|
fallbackFunctionAttribute: formatDbGeneratedAttribute
|
|
207
204
|
};
|
|
208
205
|
}
|
|
209
|
-
|
|
210
206
|
//#endregion
|
|
211
207
|
//#region src/core/psl-contract-infer/postgres-type-map.ts
|
|
212
208
|
const POSTGRES_TO_PSL = {
|
|
@@ -404,7 +400,6 @@ function extractEnumInfo(annotations) {
|
|
|
404
400
|
definitions
|
|
405
401
|
};
|
|
406
402
|
}
|
|
407
|
-
|
|
408
403
|
//#endregion
|
|
409
404
|
//#region src/core/psl-contract-infer/raw-default-parser.ts
|
|
410
405
|
const NEXTVAL_PATTERN = /^nextval\s*\(/i;
|
|
@@ -489,7 +484,6 @@ function parseRawDefault(rawDefault, nativeType) {
|
|
|
489
484
|
expression: trimmed
|
|
490
485
|
};
|
|
491
486
|
}
|
|
492
|
-
|
|
493
487
|
//#endregion
|
|
494
488
|
//#region src/core/psl-contract-infer/relation-inference.ts
|
|
495
489
|
const DEFAULT_ON_DELETE = "noAction";
|
|
@@ -589,7 +583,6 @@ function addRelationField(map, tableName, field) {
|
|
|
589
583
|
if (existing) existing.push(field);
|
|
590
584
|
else map.set(tableName, [field]);
|
|
591
585
|
}
|
|
592
|
-
|
|
593
586
|
//#endregion
|
|
594
587
|
//#region src/core/psl-contract-infer/sql-schema-ir-to-psl-ast.ts
|
|
595
588
|
const SYNTHETIC_SPAN = {
|
|
@@ -1015,7 +1008,6 @@ function topologicalSort(models, tables, modelNameMap) {
|
|
|
1015
1008
|
for (const name of sortedNames) visit(name);
|
|
1016
1009
|
return result;
|
|
1017
1010
|
}
|
|
1018
|
-
|
|
1019
1011
|
//#endregion
|
|
1020
1012
|
//#region src/core/control-instance.ts
|
|
1021
1013
|
function extractCodecTypeIdsFromContract(contract) {
|
|
@@ -1056,7 +1048,7 @@ function createVerifyResult(options) {
|
|
|
1056
1048
|
return result;
|
|
1057
1049
|
}
|
|
1058
1050
|
function isSqlControlAdapter(value) {
|
|
1059
|
-
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";
|
|
1060
1052
|
}
|
|
1061
1053
|
function buildSqlTypeMetadataRegistry(options) {
|
|
1062
1054
|
const { target, adapter, extensionPacks: extensions } = options;
|
|
@@ -1084,6 +1076,16 @@ function createSqlFamilyInstance(stack) {
|
|
|
1084
1076
|
const target = stack.target;
|
|
1085
1077
|
const adapter = stack.adapter;
|
|
1086
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
|
+
}
|
|
1087
1089
|
const { codecTypeImports, operationTypeImports, extensionIds } = stack;
|
|
1088
1090
|
const typeMetadataRegistry = buildSqlTypeMetadataRegistry({
|
|
1089
1091
|
target,
|
|
@@ -1092,7 +1094,7 @@ function createSqlFamilyInstance(stack) {
|
|
|
1092
1094
|
});
|
|
1093
1095
|
const getControlAdapter = () => {
|
|
1094
1096
|
const controlAdapter = adapter.create(stack);
|
|
1095
|
-
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)");
|
|
1096
1098
|
return controlAdapter;
|
|
1097
1099
|
};
|
|
1098
1100
|
return {
|
|
@@ -1210,6 +1212,19 @@ function createSqlFamilyInstance(stack) {
|
|
|
1210
1212
|
...ifDefined("normalizeNativeType", controlAdapter.normalizeNativeType)
|
|
1211
1213
|
});
|
|
1212
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
|
+
},
|
|
1213
1228
|
async sign(options) {
|
|
1214
1229
|
const { driver, contract: contractInput, contractPath, configPath } = options;
|
|
1215
1230
|
const startTime = Date.now();
|
|
@@ -1283,6 +1298,9 @@ function createSqlFamilyInstance(stack) {
|
|
|
1283
1298
|
async readMarker(options) {
|
|
1284
1299
|
return getControlAdapter().readMarker(options.driver, options.space);
|
|
1285
1300
|
},
|
|
1301
|
+
async readAllMarkers(options) {
|
|
1302
|
+
return getControlAdapter().readAllMarkers(options.driver);
|
|
1303
|
+
},
|
|
1286
1304
|
async introspect(options) {
|
|
1287
1305
|
return getControlAdapter().introspect(options.driver, options.contract);
|
|
1288
1306
|
},
|
|
@@ -1390,7 +1408,6 @@ function createSqlFamilyInstance(stack) {
|
|
|
1390
1408
|
}
|
|
1391
1409
|
};
|
|
1392
1410
|
}
|
|
1393
|
-
|
|
1394
1411
|
//#endregion
|
|
1395
1412
|
//#region src/core/control-descriptor.ts
|
|
1396
1413
|
var SqlFamilyDescriptor = class {
|
|
@@ -1407,7 +1424,6 @@ var SqlFamilyDescriptor = class {
|
|
|
1407
1424
|
return createSqlFamilyInstance(stack);
|
|
1408
1425
|
}
|
|
1409
1426
|
};
|
|
1410
|
-
|
|
1411
1427
|
//#endregion
|
|
1412
1428
|
//#region src/core/migrations/contract-to-schema-ir.ts
|
|
1413
1429
|
function convertColumn(name, column, storageTypes, expandNativeType, renderDefault) {
|
|
@@ -1562,7 +1578,119 @@ function deriveAnnotations(storage, annotationNamespace) {
|
|
|
1562
1578
|
for (const typeInstance of Object.values(storage.types)) byNativeType[typeInstance.nativeType] = typeInstance;
|
|
1563
1579
|
return { [annotationNamespace]: { storageTypes: byNativeType } };
|
|
1564
1580
|
}
|
|
1565
|
-
|
|
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
|
+
}
|
|
1566
1694
|
//#endregion
|
|
1567
1695
|
//#region src/core/migrations/plan-helpers.ts
|
|
1568
1696
|
const readOnlyEmptyObject = Object.freeze({});
|
|
@@ -1658,18 +1786,16 @@ function runnerFailure(code, summary, options) {
|
|
|
1658
1786
|
...options?.meta ? { meta: cloneRecord(options.meta) } : {}
|
|
1659
1787
|
}));
|
|
1660
1788
|
}
|
|
1661
|
-
|
|
1662
1789
|
//#endregion
|
|
1663
1790
|
//#region src/core/migrations/policies.ts
|
|
1664
1791
|
/**
|
|
1665
1792
|
* Policy used by `db init`: additive-only operations, no widening/destructive steps.
|
|
1666
1793
|
*/
|
|
1667
1794
|
const INIT_ADDITIVE_POLICY = Object.freeze({ allowedOperationClasses: Object.freeze(["additive"]) });
|
|
1668
|
-
|
|
1669
1795
|
//#endregion
|
|
1670
1796
|
//#region src/exports/control.ts
|
|
1671
1797
|
var control_default = new SqlFamilyDescriptor();
|
|
1672
|
-
|
|
1673
1798
|
//#endregion
|
|
1674
|
-
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 };
|
|
1800
|
+
|
|
1675
1801
|
//# sourceMappingURL=control.mjs.map
|