@prisma-next/family-sql 0.5.0-dev.9 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/{authoring-type-constructors-BAR65pSK.mjs → authoring-type-constructors-F4JpCJl7.mjs} +14 -15
- package/dist/authoring-type-constructors-F4JpCJl7.mjs.map +1 -0
- package/dist/control-adapter.d.mts +26 -2
- package/dist/control-adapter.d.mts.map +1 -1
- package/dist/control-adapter.mjs +1 -1
- package/dist/control.d.mts +125 -45
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +1174 -54
- package/dist/control.mjs.map +1 -1
- package/dist/migration.d.mts +22 -24
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +25 -24
- package/dist/migration.mjs.map +1 -1
- package/dist/pack.d.mts +35 -23
- 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 +19 -2
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +26 -4
- package/dist/runtime.mjs.map +1 -1
- package/dist/schema-verify.d.mts +4 -15
- package/dist/schema-verify.d.mts.map +1 -1
- package/dist/schema-verify.mjs +2 -3
- package/dist/test-utils.d.mts +2 -2
- package/dist/test-utils.mjs +2 -3
- package/dist/timestamp-now-generator-BWp8S2sa.mjs +86 -0
- package/dist/timestamp-now-generator-BWp8S2sa.mjs.map +1 -0
- package/dist/types-mhjAPuMn.d.mts +470 -0
- package/dist/types-mhjAPuMn.d.mts.map +1 -0
- package/dist/verify-pRYxnpiG.mjs +81 -0
- package/dist/verify-pRYxnpiG.mjs.map +1 -0
- package/dist/{verify-sql-schema-Ovz7RXR5.mjs → verify-sql-schema-1tDh3x5x.mjs} +18 -72
- package/dist/verify-sql-schema-1tDh3x5x.mjs.map +1 -0
- package/dist/{verify-sql-schema-BBhkqEDo.d.mts → verify-sql-schema-CPHiuYHR.d.mts} +2 -3
- package/dist/verify-sql-schema-CPHiuYHR.d.mts.map +1 -0
- package/dist/verify.d.mts +16 -21
- package/dist/verify.d.mts.map +1 -1
- package/dist/verify.mjs +2 -3
- package/package.json +23 -21
- package/src/core/authoring-field-presets.ts +35 -23
- package/src/core/control-adapter.ts +32 -0
- package/src/core/control-descriptor.ts +2 -1
- package/src/core/control-instance.ts +117 -30
- package/src/core/migrations/contract-to-schema-ir.ts +4 -29
- package/src/core/migrations/field-event-planner.ts +194 -0
- package/src/core/migrations/plan-helpers.ts +4 -0
- package/src/core/migrations/types.ts +207 -59
- package/src/core/operation-preview.ts +62 -0
- package/src/core/psl-contract-infer/default-mapping.ts +56 -0
- package/src/core/psl-contract-infer/name-transforms.ts +178 -0
- package/src/core/psl-contract-infer/postgres-default-mapping.ts +16 -0
- package/src/core/psl-contract-infer/postgres-type-map.ts +165 -0
- package/src/core/psl-contract-infer/printer-config.ts +55 -0
- package/src/core/psl-contract-infer/raw-default-parser.ts +91 -0
- package/src/core/psl-contract-infer/relation-inference.ts +196 -0
- package/src/core/psl-contract-infer/sql-schema-ir-to-psl-ast.ts +832 -0
- package/src/core/schema-verify/verify-helpers.ts +47 -70
- package/src/core/schema-verify/verify-sql-schema.ts +1 -6
- package/src/core/sql-migration.ts +25 -23
- package/src/core/timestamp-now-generator.ts +74 -0
- package/src/core/timestamp-now-runtime-generator.ts +24 -0
- package/src/core/verify.ts +46 -108
- package/src/exports/control.ts +11 -4
- package/src/exports/runtime.ts +2 -0
- package/src/exports/schema-verify.ts +0 -1
- package/src/exports/test-utils.ts +0 -1
- package/src/exports/verify.ts +1 -1
- package/dist/authoring-type-constructors-BAR65pSK.mjs.map +0 -1
- package/dist/types-C6K4mxDM.d.mts +0 -301
- package/dist/types-C6K4mxDM.d.mts.map +0 -1
- package/dist/verify-4GshvY4p.mjs +0 -122
- package/dist/verify-4GshvY4p.mjs.map +0 -1
- package/dist/verify-sql-schema-BBhkqEDo.d.mts.map +0 -1
- package/dist/verify-sql-schema-Ovz7RXR5.mjs.map +0 -1
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
import { ControlAdapterDescriptor, ControlDriverInstance, ControlExtensionDescriptor, ControlFamilyInstance, ControlStack, DataTransformOperation, MigratableTargetDescriptor, MigrationOperationPolicy, MigrationPlan, MigrationPlanOperation, MigrationPlannerConflict, MigrationPlannerFailureResult, MigrationPlannerSuccessResult, MigrationRunnerExecutionChecks, MigrationRunnerFailure, MigrationRunnerSuccessValue, OperationContext, SchemaIssue, SchemaViewCapable, SignDatabaseResult, VerifyDatabaseResult, VerifyDatabaseSchemaResult } from "@prisma-next/framework-components/control";
|
|
2
|
-
import { Result } from "@prisma-next/utils/result";
|
|
3
|
-
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
4
|
-
import { Contract } from "@prisma-next/contract/types";
|
|
5
|
-
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
6
|
-
import { SqlStorage, StorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
7
|
-
import { TypesImportSpec } from "@prisma-next/framework-components/emission";
|
|
8
|
-
import { SqlOperationDescriptor } from "@prisma-next/sql-operations";
|
|
9
|
-
|
|
10
|
-
//#region src/core/control-instance.d.ts
|
|
11
|
-
interface SqlTypeMetadata {
|
|
12
|
-
readonly typeId: string;
|
|
13
|
-
readonly familyId: 'sql';
|
|
14
|
-
readonly targetId: string;
|
|
15
|
-
readonly nativeType?: string;
|
|
16
|
-
}
|
|
17
|
-
type SqlTypeMetadataRegistry = Map<string, SqlTypeMetadata>;
|
|
18
|
-
interface SqlFamilyInstanceState {
|
|
19
|
-
readonly codecTypeImports: ReadonlyArray<TypesImportSpec>;
|
|
20
|
-
readonly operationTypeImports: ReadonlyArray<TypesImportSpec>;
|
|
21
|
-
readonly extensionIds: ReadonlyArray<string>;
|
|
22
|
-
readonly typeMetadataRegistry: SqlTypeMetadataRegistry;
|
|
23
|
-
}
|
|
24
|
-
interface SchemaVerifyOptions {
|
|
25
|
-
readonly driver: ControlDriverInstance<'sql', string>;
|
|
26
|
-
readonly contract: unknown;
|
|
27
|
-
readonly strict: boolean;
|
|
28
|
-
readonly context?: OperationContext;
|
|
29
|
-
/**
|
|
30
|
-
* Active framework components participating in this composition.
|
|
31
|
-
* All components must have matching familyId ('sql') and targetId.
|
|
32
|
-
*/
|
|
33
|
-
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
34
|
-
}
|
|
35
|
-
interface SqlControlFamilyInstance extends ControlFamilyInstance<'sql', SqlSchemaIR>, SchemaViewCapable<SqlSchemaIR>, SqlFamilyInstanceState {
|
|
36
|
-
validateContract(contractJson: unknown): Contract;
|
|
37
|
-
verify(options: {
|
|
38
|
-
readonly driver: ControlDriverInstance<'sql', string>;
|
|
39
|
-
readonly contract: unknown;
|
|
40
|
-
readonly expectedTargetId: string;
|
|
41
|
-
readonly contractPath: string;
|
|
42
|
-
readonly configPath?: string;
|
|
43
|
-
}): Promise<VerifyDatabaseResult>;
|
|
44
|
-
schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult>;
|
|
45
|
-
sign(options: {
|
|
46
|
-
readonly driver: ControlDriverInstance<'sql', string>;
|
|
47
|
-
readonly contract: unknown;
|
|
48
|
-
readonly contractPath: string;
|
|
49
|
-
readonly configPath?: string;
|
|
50
|
-
}): Promise<SignDatabaseResult>;
|
|
51
|
-
introspect(options: {
|
|
52
|
-
readonly driver: ControlDriverInstance<'sql', string>;
|
|
53
|
-
readonly contract?: unknown;
|
|
54
|
-
}): Promise<SqlSchemaIR>;
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/core/migrations/types.d.ts
|
|
58
|
-
type AnyRecord = Readonly<Record<string, unknown>>;
|
|
59
|
-
interface ComponentDatabaseDependency<TTargetDetails> {
|
|
60
|
-
readonly id: string;
|
|
61
|
-
readonly label: string;
|
|
62
|
-
readonly install: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
63
|
-
}
|
|
64
|
-
interface ComponentDatabaseDependencies<TTargetDetails> {
|
|
65
|
-
readonly init?: readonly ComponentDatabaseDependency<TTargetDetails>[];
|
|
66
|
-
}
|
|
67
|
-
interface DatabaseDependencyProvider {
|
|
68
|
-
readonly databaseDependencies?: ComponentDatabaseDependencies<unknown>;
|
|
69
|
-
}
|
|
70
|
-
declare function isDatabaseDependencyProvider(value: unknown): value is DatabaseDependencyProvider;
|
|
71
|
-
declare function collectInitDependencies(components: ReadonlyArray<unknown>): readonly ComponentDatabaseDependency<unknown>[];
|
|
72
|
-
interface StorageTypePlanResult<TTargetDetails> {
|
|
73
|
-
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Input for expanding parameterized native types.
|
|
77
|
-
*/
|
|
78
|
-
interface ExpandNativeTypeInput {
|
|
79
|
-
readonly nativeType: string;
|
|
80
|
-
readonly codecId?: string;
|
|
81
|
-
readonly typeParams?: Record<string, unknown>;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Input for resolving an identity-value SQL literal used to backfill existing rows when
|
|
85
|
-
* adding a NOT NULL column without an explicit default.
|
|
86
|
-
*
|
|
87
|
-
* "Identity value" in the algebraic (monoid) sense: the neutral element for the type
|
|
88
|
-
* (0 for numbers, '' for strings, false for booleans, etc.).
|
|
89
|
-
*/
|
|
90
|
-
interface ResolveIdentityValueInput {
|
|
91
|
-
readonly nativeType: string;
|
|
92
|
-
readonly codecId?: string;
|
|
93
|
-
readonly typeParams?: Record<string, unknown>;
|
|
94
|
-
}
|
|
95
|
-
interface CodecControlHooks<TTargetDetails = unknown> {
|
|
96
|
-
planTypeOperations?: (options: {
|
|
97
|
-
readonly typeName: string;
|
|
98
|
-
readonly typeInstance: StorageTypeInstance;
|
|
99
|
-
readonly contract: Contract<SqlStorage>;
|
|
100
|
-
readonly schema: SqlSchemaIR;
|
|
101
|
-
readonly schemaName?: string;
|
|
102
|
-
readonly policy: MigrationOperationPolicy;
|
|
103
|
-
}) => StorageTypePlanResult<TTargetDetails>;
|
|
104
|
-
verifyType?: (options: {
|
|
105
|
-
readonly typeName: string;
|
|
106
|
-
readonly typeInstance: StorageTypeInstance;
|
|
107
|
-
readonly schema: SqlSchemaIR;
|
|
108
|
-
readonly schemaName?: string;
|
|
109
|
-
}) => readonly SchemaIssue[];
|
|
110
|
-
introspectTypes?: (options: {
|
|
111
|
-
readonly driver: ControlDriverInstance<'sql', string>;
|
|
112
|
-
readonly schemaName?: string;
|
|
113
|
-
}) => Promise<Record<string, StorageTypeInstance>>;
|
|
114
|
-
/**
|
|
115
|
-
* Expands a parameterized native type to its full SQL representation.
|
|
116
|
-
* Used by schema verification to compare contract types against database types.
|
|
117
|
-
*
|
|
118
|
-
* For example, expands:
|
|
119
|
-
* - { nativeType: 'character varying', typeParams: { length: 255 } } -> 'character varying(255)'
|
|
120
|
-
* - { nativeType: 'numeric', typeParams: { precision: 10, scale: 2 } } -> 'numeric(10,2)'
|
|
121
|
-
*
|
|
122
|
-
* Returns the expanded type string, or the original nativeType if no expansion is needed.
|
|
123
|
-
*/
|
|
124
|
-
expandNativeType?: (input: ExpandNativeTypeInput) => string;
|
|
125
|
-
/**
|
|
126
|
-
* Resolves the identity value (monoid neutral element) as a SQL literal for safely adding
|
|
127
|
-
* a NOT NULL column without an explicit default to a non-empty table.
|
|
128
|
-
*
|
|
129
|
-
* Return semantics:
|
|
130
|
-
* - string: use this literal
|
|
131
|
-
* - null: explicitly no safe identity value is known; fall back to another strategy
|
|
132
|
-
* - undefined: no opinion; planner may use built-in fallbacks
|
|
133
|
-
*/
|
|
134
|
-
resolveIdentityValue?: (input: ResolveIdentityValueInput) => string | null | undefined;
|
|
135
|
-
}
|
|
136
|
-
interface SqlControlExtensionDescriptor<TTargetId extends string> extends ControlExtensionDescriptor<'sql', TTargetId> {
|
|
137
|
-
readonly databaseDependencies?: ComponentDatabaseDependencies<unknown>;
|
|
138
|
-
readonly queryOperations?: () => ReadonlyArray<SqlOperationDescriptor>;
|
|
139
|
-
}
|
|
140
|
-
interface SqlControlAdapterDescriptor<TTargetId extends string> extends ControlAdapterDescriptor<'sql', TTargetId> {
|
|
141
|
-
readonly queryOperations?: () => ReadonlyArray<SqlOperationDescriptor>;
|
|
142
|
-
}
|
|
143
|
-
interface SqlMigrationPlanOperationStep {
|
|
144
|
-
readonly description: string;
|
|
145
|
-
readonly sql: string;
|
|
146
|
-
readonly meta?: AnyRecord;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Minimal shape every SQL-family target must conform to for its per-operation
|
|
150
|
-
* `target.details` payload. Each SQL operation addresses a named database
|
|
151
|
-
* object in some schema; targets (Postgres, MySQL, SQLite, …) extend this
|
|
152
|
-
* shape with their own fields (e.g. Postgres adds `objectType` and optional
|
|
153
|
-
* `table`).
|
|
154
|
-
*/
|
|
155
|
-
interface SqlPlanTargetDetails {
|
|
156
|
-
readonly schema: string;
|
|
157
|
-
readonly name: string;
|
|
158
|
-
}
|
|
159
|
-
interface SqlMigrationPlanOperationTarget<TTargetDetails> {
|
|
160
|
-
readonly id: string;
|
|
161
|
-
readonly details?: TTargetDetails;
|
|
162
|
-
}
|
|
163
|
-
interface SqlMigrationPlanOperation<TTargetDetails> extends MigrationPlanOperation {
|
|
164
|
-
readonly summary?: string;
|
|
165
|
-
readonly target: SqlMigrationPlanOperationTarget<TTargetDetails>;
|
|
166
|
-
readonly precheck: readonly SqlMigrationPlanOperationStep[];
|
|
167
|
-
readonly execute: readonly SqlMigrationPlanOperationStep[];
|
|
168
|
-
readonly postcheck: readonly SqlMigrationPlanOperationStep[];
|
|
169
|
-
readonly meta?: AnyRecord;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Union of all operation shapes a SQL-family migration may emit: schema-facing
|
|
173
|
-
* `SqlMigrationPlanOperation`s and family-agnostic `DataTransformOperation`s.
|
|
174
|
-
*
|
|
175
|
-
* Mirrors `AnyMongoMigrationOperation` in shape — the runner already handles
|
|
176
|
-
* both branches via `isDataTransformOperation`, and authored `migration.ts`
|
|
177
|
-
* files must be able to intermix `dataTransform(endContract, …)` calls with
|
|
178
|
-
* DDL factory calls (e.g. `setNotNull(…)`) in a single `operations` array.
|
|
179
|
-
*/
|
|
180
|
-
type AnySqlMigrationOperation<TTargetDetails> = SqlMigrationPlanOperation<TTargetDetails> | DataTransformOperation;
|
|
181
|
-
interface SqlMigrationPlanContractInfo {
|
|
182
|
-
readonly storageHash: string;
|
|
183
|
-
readonly profileHash?: string;
|
|
184
|
-
}
|
|
185
|
-
interface SqlMigrationPlan<TTargetDetails> extends MigrationPlan {
|
|
186
|
-
/**
|
|
187
|
-
* Origin contract identity that the plan expects the database to currently be at.
|
|
188
|
-
* If omitted or null, the runner skips origin validation entirely.
|
|
189
|
-
*/
|
|
190
|
-
readonly origin?: SqlMigrationPlanContractInfo | null;
|
|
191
|
-
/**
|
|
192
|
-
* Destination contract identity that the plan intends to reach.
|
|
193
|
-
*/
|
|
194
|
-
readonly destination: SqlMigrationPlanContractInfo;
|
|
195
|
-
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
196
|
-
readonly meta?: AnyRecord;
|
|
197
|
-
}
|
|
198
|
-
type SqlPlannerConflictKind = 'typeMismatch' | 'nullabilityConflict' | 'indexIncompatible' | 'foreignKeyConflict' | 'missingButNonAdditive' | 'unsupportedOperation';
|
|
199
|
-
interface SqlPlannerConflictLocation {
|
|
200
|
-
readonly table?: string;
|
|
201
|
-
readonly column?: string;
|
|
202
|
-
readonly index?: string;
|
|
203
|
-
readonly constraint?: string;
|
|
204
|
-
readonly type?: string;
|
|
205
|
-
}
|
|
206
|
-
interface SqlPlannerConflict extends MigrationPlannerConflict {
|
|
207
|
-
readonly kind: SqlPlannerConflictKind;
|
|
208
|
-
readonly location?: SqlPlannerConflictLocation;
|
|
209
|
-
readonly meta?: AnyRecord;
|
|
210
|
-
}
|
|
211
|
-
interface SqlPlannerSuccessResult<TTargetDetails> extends Omit<MigrationPlannerSuccessResult, 'plan'> {
|
|
212
|
-
readonly kind: 'success';
|
|
213
|
-
readonly plan: SqlMigrationPlan<TTargetDetails>;
|
|
214
|
-
}
|
|
215
|
-
interface SqlPlannerFailureResult extends Omit<MigrationPlannerFailureResult, 'conflicts'> {
|
|
216
|
-
readonly kind: 'failure';
|
|
217
|
-
readonly conflicts: readonly SqlPlannerConflict[];
|
|
218
|
-
}
|
|
219
|
-
type SqlPlannerResult<TTargetDetails> = SqlPlannerSuccessResult<TTargetDetails> | SqlPlannerFailureResult;
|
|
220
|
-
interface SqlMigrationPlannerPlanOptions {
|
|
221
|
-
readonly contract: Contract<SqlStorage>;
|
|
222
|
-
readonly schema: SqlSchemaIR;
|
|
223
|
-
readonly policy: MigrationOperationPolicy;
|
|
224
|
-
readonly schemaName?: string;
|
|
225
|
-
/**
|
|
226
|
-
* The "from" contract (state the planner assumes the database starts at).
|
|
227
|
-
* Only `migration plan` supplies this; `db update` / `db init` reconcile
|
|
228
|
-
* against the live schema with no old contract. Strategies that need
|
|
229
|
-
* from/to column-shape comparisons (unsafe type change, nullability
|
|
230
|
-
* tightening) use this to decide whether to emit `dataTransform`
|
|
231
|
-
* placeholders.
|
|
232
|
-
*/
|
|
233
|
-
readonly fromContract?: Contract<SqlStorage> | null;
|
|
234
|
-
/**
|
|
235
|
-
* Active framework components participating in this composition.
|
|
236
|
-
* SQL targets can interpret this list to derive database dependencies.
|
|
237
|
-
* All components must have matching familyId ('sql') and targetId.
|
|
238
|
-
*/
|
|
239
|
-
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
240
|
-
}
|
|
241
|
-
interface SqlMigrationPlanner<TTargetDetails> {
|
|
242
|
-
plan(options: SqlMigrationPlannerPlanOptions): SqlPlannerResult<TTargetDetails>;
|
|
243
|
-
}
|
|
244
|
-
interface SqlMigrationRunnerExecuteCallbacks<TTargetDetails> {
|
|
245
|
-
onOperationStart?(operation: SqlMigrationPlanOperation<TTargetDetails>): void;
|
|
246
|
-
onOperationComplete?(operation: SqlMigrationPlanOperation<TTargetDetails>): void;
|
|
247
|
-
}
|
|
248
|
-
interface SqlMigrationRunnerExecuteOptions<TTargetDetails> {
|
|
249
|
-
readonly plan: SqlMigrationPlan<TTargetDetails>;
|
|
250
|
-
readonly driver: ControlDriverInstance<'sql', string>;
|
|
251
|
-
/**
|
|
252
|
-
* Destination contract IR.
|
|
253
|
-
* Must correspond to `plan.destination` and is used for schema verification and marker/ledger writes.
|
|
254
|
-
*/
|
|
255
|
-
readonly destinationContract: Contract<SqlStorage>;
|
|
256
|
-
/**
|
|
257
|
-
* Execution-time policy that defines which operation classes are allowed.
|
|
258
|
-
* The runner validates each operation against this policy before execution.
|
|
259
|
-
*/
|
|
260
|
-
readonly policy: MigrationOperationPolicy;
|
|
261
|
-
readonly schemaName?: string;
|
|
262
|
-
readonly strictVerification?: boolean;
|
|
263
|
-
readonly callbacks?: SqlMigrationRunnerExecuteCallbacks<TTargetDetails>;
|
|
264
|
-
readonly context?: OperationContext;
|
|
265
|
-
/**
|
|
266
|
-
* Execution-time checks configuration.
|
|
267
|
-
* All checks default to `true` (enabled) when omitted.
|
|
268
|
-
*/
|
|
269
|
-
readonly executionChecks?: MigrationRunnerExecutionChecks;
|
|
270
|
-
/**
|
|
271
|
-
* Active framework components participating in this composition.
|
|
272
|
-
* SQL targets can interpret this list to derive database dependencies.
|
|
273
|
-
* All components must have matching familyId ('sql') and targetId.
|
|
274
|
-
*/
|
|
275
|
-
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
276
|
-
}
|
|
277
|
-
type SqlMigrationRunnerErrorCode = 'DESTINATION_CONTRACT_MISMATCH' | 'MARKER_ORIGIN_MISMATCH' | 'POLICY_VIOLATION' | 'PRECHECK_FAILED' | 'POSTCHECK_FAILED' | 'SCHEMA_VERIFY_FAILED' | 'EXECUTION_FAILED';
|
|
278
|
-
interface SqlMigrationRunnerFailure extends MigrationRunnerFailure {
|
|
279
|
-
readonly code: SqlMigrationRunnerErrorCode;
|
|
280
|
-
readonly meta?: AnyRecord;
|
|
281
|
-
}
|
|
282
|
-
interface SqlMigrationRunnerSuccessValue extends MigrationRunnerSuccessValue {}
|
|
283
|
-
type SqlMigrationRunnerResult = Result<SqlMigrationRunnerSuccessValue, SqlMigrationRunnerFailure>;
|
|
284
|
-
interface SqlMigrationRunner<TTargetDetails> {
|
|
285
|
-
execute(options: SqlMigrationRunnerExecuteOptions<TTargetDetails>): Promise<SqlMigrationRunnerResult>;
|
|
286
|
-
}
|
|
287
|
-
interface SqlControlTargetDescriptor<TTargetId extends string, TTargetDetails> extends MigratableTargetDescriptor<'sql', TTargetId, SqlControlFamilyInstance> {
|
|
288
|
-
readonly queryOperations?: () => ReadonlyArray<SqlOperationDescriptor>;
|
|
289
|
-
createPlanner(family: SqlControlFamilyInstance): SqlMigrationPlanner<TTargetDetails>;
|
|
290
|
-
createRunner(family: SqlControlFamilyInstance): SqlMigrationRunner<TTargetDetails>;
|
|
291
|
-
}
|
|
292
|
-
interface CreateSqlMigrationPlanOptions<TTargetDetails> {
|
|
293
|
-
readonly targetId: string;
|
|
294
|
-
readonly origin?: SqlMigrationPlanContractInfo | null;
|
|
295
|
-
readonly destination: SqlMigrationPlanContractInfo;
|
|
296
|
-
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
297
|
-
readonly meta?: AnyRecord;
|
|
298
|
-
}
|
|
299
|
-
//#endregion
|
|
300
|
-
export { SqlPlannerFailureResult as A, SqlMigrationRunnerFailure as C, SqlPlannerConflict as D, SqlPlanTargetDetails as E, isDatabaseDependencyProvider as F, SchemaVerifyOptions as I, SqlControlFamilyInstance as L, SqlPlannerSuccessResult as M, StorageTypePlanResult as N, SqlPlannerConflictKind as O, collectInitDependencies as P, SqlMigrationRunnerExecuteOptions as S, SqlMigrationRunnerSuccessValue as T, SqlMigrationPlanner as _, ComponentDatabaseDependency as a, SqlMigrationRunnerErrorCode as b, ResolveIdentityValueInput as c, SqlControlTargetDescriptor as d, SqlMigrationPlan as f, SqlMigrationPlanOperationTarget as g, SqlMigrationPlanOperationStep as h, ComponentDatabaseDependencies as i, SqlPlannerResult as j, SqlPlannerConflictLocation as k, SqlControlAdapterDescriptor as l, SqlMigrationPlanOperation as m, AnySqlMigrationOperation as n, CreateSqlMigrationPlanOptions as o, SqlMigrationPlanContractInfo as p, CodecControlHooks as r, ExpandNativeTypeInput as s, AnyRecord as t, SqlControlExtensionDescriptor as u, SqlMigrationPlannerPlanOptions as v, SqlMigrationRunnerResult as w, SqlMigrationRunnerExecuteCallbacks as x, SqlMigrationRunner as y };
|
|
301
|
-
//# sourceMappingURL=types-C6K4mxDM.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-C6K4mxDM.d.mts","names":[],"sources":["../src/core/control-instance.ts","../src/core/migrations/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;UAyJU,eAAA;;;;;AAzHsE;AAyHvD,KAOpB,uBAAA,GAA0B,GAAH,CAAA,MAAA,EAAe,eAAA,CAAZ;AAAG,UAExB,sBAAA,CAAsB;EACW,SAAA,gBAAA,EAAd,aAAc,CAAA,eAAA,CAAA;EAAd,SAAA,oBAAA,EACI,aADJ,CACkB,eADlB,CAAA;EACkB,SAAA,YAAA,EACtB,aADsB,CAAA,MAAA,CAAA;EAAd,SAAA,oBAAA,EAEA,uBAFA;;AAEA,UAGhB,mBAAA,CAHgB;EAAuB,SAAA,MAAA,EAIrC,qBAJqC,CAAA,KAAA,EAAA,MAAA,CAAA;EAGvC,SAAA,QAAA,EAAA,OAAmB;EACjB,SAAA,MAAA,EAAA,OAAA;EAGE,SAAA,OAAA,CAAA,EAAA,gBAAA;EAKyB;;;AAG9C;EACuC,SAAA,mBAAA,EAJP,aAIO,CAJO,8BAIP,CAAA,KAAA,EAAA,MAAA,CAAA,CAAA;;AAGI,UAJ1B,wBAAA,SACP,q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A3DjB,cA2DiB,CAAA;EAC5B,SAAA,MAAA,EA3DJ,qBA2DI,CAAA,KAAA,EAAA,MAAA,CAAA;EAA8C;;;;EAGpD,SAAA,mBAAA,EAzDe,QAyDc,CAzDL,UAyDK,CAAA;EAE1B;;;;EAGF,SAAA,MAAA,EAzDC,wBAyDD;EAAS,SAAA,UAAA,CAAA,EAAA,MAAA;;uBAtDJ,mCAAmC;qBACrC;;;;;6BAKQ;;;;;;gCAMG,cAAc;;KAGlC,2BAAA;UASK,yBAAA,SAAkC;iBAClC;kBACC;;UAGD,8BAAA,SAAuC;KAE5C,wBAAA,GAA2B,OACrC,gCACA;UAGe;mBAEJ,iCAAiC,kBACzC,QAAQ;;UAGI,6EACP,kCAAkC,WAAW;mCACpB,cAAc;wBACzB,2BAA2B,oBAAoB;uBAChD,2BAA2B,mBAAmB;;UAGpD;;oBAEG;wBACI;gCACQ,0BAA0B;kBACxC"}
|
package/dist/verify-4GshvY4p.mjs
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { type } from "arktype";
|
|
2
|
-
|
|
3
|
-
//#region src/core/verify.ts
|
|
4
|
-
const MetaSchema = type({ "[string]": "unknown" });
|
|
5
|
-
function parseMeta(meta) {
|
|
6
|
-
if (meta === null || meta === void 0) return {};
|
|
7
|
-
let parsed;
|
|
8
|
-
if (typeof meta === "string") try {
|
|
9
|
-
parsed = JSON.parse(meta);
|
|
10
|
-
} catch {
|
|
11
|
-
return {};
|
|
12
|
-
}
|
|
13
|
-
else parsed = meta;
|
|
14
|
-
const result = MetaSchema(parsed);
|
|
15
|
-
if (result instanceof type.errors) return {};
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
const ContractMarkerRowSchema = type({
|
|
19
|
-
core_hash: "string",
|
|
20
|
-
profile_hash: "string",
|
|
21
|
-
"contract_json?": "unknown | null",
|
|
22
|
-
"canonical_version?": "number | null",
|
|
23
|
-
"updated_at?": "Date | string",
|
|
24
|
-
"app_tag?": "string | null",
|
|
25
|
-
"meta?": "unknown | null"
|
|
26
|
-
});
|
|
27
|
-
/**
|
|
28
|
-
* Parses a contract marker row from database query result.
|
|
29
|
-
* This is SQL-specific parsing logic (handles SQL row structure with snake_case columns).
|
|
30
|
-
*/
|
|
31
|
-
function parseContractMarkerRow(row) {
|
|
32
|
-
const result = ContractMarkerRowSchema(row);
|
|
33
|
-
if (result instanceof type.errors) {
|
|
34
|
-
const messages = result.map((p) => p.message).join("; ");
|
|
35
|
-
throw new Error(`Invalid contract marker row: ${messages}`);
|
|
36
|
-
}
|
|
37
|
-
const validatedRow = result;
|
|
38
|
-
const updatedAt = validatedRow.updated_at ? validatedRow.updated_at instanceof Date ? validatedRow.updated_at : new Date(validatedRow.updated_at) : /* @__PURE__ */ new Date();
|
|
39
|
-
return {
|
|
40
|
-
storageHash: validatedRow.core_hash,
|
|
41
|
-
profileHash: validatedRow.profile_hash,
|
|
42
|
-
contractJson: validatedRow.contract_json ?? null,
|
|
43
|
-
canonicalVersion: validatedRow.canonical_version ?? null,
|
|
44
|
-
updatedAt,
|
|
45
|
-
appTag: validatedRow.app_tag ?? null,
|
|
46
|
-
meta: parseMeta(validatedRow.meta)
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Returns the SQL statement to read the contract marker.
|
|
51
|
-
* This is a migration-plane helper (no runtime imports).
|
|
52
|
-
* @internal - Used internally by readMarker(). Prefer readMarker() for Control Plane usage.
|
|
53
|
-
*/
|
|
54
|
-
function readMarkerSql() {
|
|
55
|
-
return {
|
|
56
|
-
sql: `select
|
|
57
|
-
core_hash,
|
|
58
|
-
profile_hash,
|
|
59
|
-
contract_json,
|
|
60
|
-
canonical_version,
|
|
61
|
-
updated_at,
|
|
62
|
-
app_tag,
|
|
63
|
-
meta
|
|
64
|
-
from prisma_contract.marker
|
|
65
|
-
where id = $1`,
|
|
66
|
-
params: [1]
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Returns the SQL statement that probes for the existence of the marker table.
|
|
71
|
-
* Uses the SQL-standard `information_schema.tables` view so the query succeeds
|
|
72
|
-
* (returning zero rows) when the table has not been created yet — avoiding a
|
|
73
|
-
* `relation does not exist` error. Some Postgres wire-protocol implementations
|
|
74
|
-
* (e.g. PGlite's TCP proxy) do not fully recover from an extended-protocol
|
|
75
|
-
* parse error, so we probe first instead of relying on an error signal.
|
|
76
|
-
* @internal - Used internally by readMarker().
|
|
77
|
-
*/
|
|
78
|
-
function markerTableExistsSql() {
|
|
79
|
-
return {
|
|
80
|
-
sql: `select 1
|
|
81
|
-
from information_schema.tables
|
|
82
|
-
where table_schema = $1 and table_name = $2`,
|
|
83
|
-
params: ["prisma_contract", "marker"]
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Reads the contract marker from the database using the provided driver.
|
|
88
|
-
* Returns the parsed marker record or null if no marker is found.
|
|
89
|
-
* This abstracts SQL-specific details from the Control Plane.
|
|
90
|
-
*
|
|
91
|
-
* @param driver - ControlDriverInstance instance for executing queries
|
|
92
|
-
* @returns Promise resolving to ContractMarkerRecord or null if marker not found
|
|
93
|
-
*/
|
|
94
|
-
async function readMarker(driver) {
|
|
95
|
-
const existsStatement = markerTableExistsSql();
|
|
96
|
-
if ((await driver.query(existsStatement.sql, existsStatement.params)).rows.length === 0) return null;
|
|
97
|
-
const markerStatement = readMarkerSql();
|
|
98
|
-
const queryResult = await driver.query(markerStatement.sql, markerStatement.params);
|
|
99
|
-
if (queryResult.rows.length === 0) return null;
|
|
100
|
-
const markerRow = queryResult.rows[0];
|
|
101
|
-
if (!markerRow) throw new Error("Database query returned unexpected result structure");
|
|
102
|
-
return parseContractMarkerRow(markerRow);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Collects supported codec type IDs from adapter and extension manifests.
|
|
106
|
-
* Returns a sorted, unique array of type IDs that are declared in the manifests.
|
|
107
|
-
* This enables coverage checks by comparing contract column types against supported types.
|
|
108
|
-
*
|
|
109
|
-
* Note: This extracts type IDs from manifest type imports, not from runtime codec registries.
|
|
110
|
-
* The manifests declare which codec types are available, but the actual type IDs
|
|
111
|
-
* are defined in the codec-types TypeScript modules that are imported.
|
|
112
|
-
*
|
|
113
|
-
* For MVP, we return an empty array since extracting type IDs from TypeScript modules
|
|
114
|
-
* would require runtime evaluation or static analysis. This can be enhanced later.
|
|
115
|
-
*/
|
|
116
|
-
function collectSupportedCodecTypeIds(descriptors) {
|
|
117
|
-
return [];
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
//#endregion
|
|
121
|
-
export { readMarkerSql as i, parseContractMarkerRow as n, readMarker as r, collectSupportedCodecTypeIds as t };
|
|
122
|
-
//# sourceMappingURL=verify-4GshvY4p.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"verify-4GshvY4p.mjs","names":["parsed: unknown"],"sources":["../src/core/verify.ts"],"sourcesContent":["import type { ContractMarkerRecord } from '@prisma-next/contract/types';\nimport type { ControlDriverInstance } from '@prisma-next/framework-components/control';\nimport { type } from 'arktype';\n\nconst MetaSchema = type({ '[string]': 'unknown' });\n\nfunction parseMeta(meta: unknown): Record<string, unknown> {\n if (meta === null || meta === undefined) {\n return {};\n }\n\n let parsed: unknown;\n if (typeof meta === 'string') {\n try {\n parsed = JSON.parse(meta);\n } catch {\n return {};\n }\n } else {\n parsed = meta;\n }\n\n const result = MetaSchema(parsed);\n if (result instanceof type.errors) {\n return {};\n }\n\n return result as Record<string, unknown>;\n}\n\nconst ContractMarkerRowSchema = type({\n core_hash: 'string',\n profile_hash: 'string',\n 'contract_json?': 'unknown | null',\n 'canonical_version?': 'number | null',\n 'updated_at?': 'Date | string',\n 'app_tag?': 'string | null',\n 'meta?': 'unknown | null',\n});\n\n/**\n * Parses a contract marker row from database query result.\n * This is SQL-specific parsing logic (handles SQL row structure with snake_case columns).\n */\nexport function parseContractMarkerRow(row: unknown): ContractMarkerRecord {\n const result = ContractMarkerRowSchema(row);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Invalid contract marker row: ${messages}`);\n }\n\n const validatedRow = result as {\n core_hash: string;\n profile_hash: string;\n contract_json?: unknown | null;\n canonical_version?: number | null;\n updated_at?: Date | string;\n app_tag?: string | null;\n meta?: unknown | null;\n };\n\n const updatedAt = validatedRow.updated_at\n ? validatedRow.updated_at instanceof Date\n ? validatedRow.updated_at\n : new Date(validatedRow.updated_at)\n : new Date();\n\n return {\n storageHash: validatedRow.core_hash,\n profileHash: validatedRow.profile_hash,\n contractJson: validatedRow.contract_json ?? null,\n canonicalVersion: validatedRow.canonical_version ?? null,\n updatedAt,\n appTag: validatedRow.app_tag ?? null,\n meta: parseMeta(validatedRow.meta),\n };\n}\n\n/**\n * Returns the SQL statement to read the contract marker.\n * This is a migration-plane helper (no runtime imports).\n * @internal - Used internally by readMarker(). Prefer readMarker() for Control Plane usage.\n */\nexport function readMarkerSql(): { readonly sql: string; readonly params: readonly unknown[] } {\n return {\n sql: `select\n core_hash,\n profile_hash,\n contract_json,\n canonical_version,\n updated_at,\n app_tag,\n meta\n from prisma_contract.marker\n where id = $1`,\n params: [1],\n };\n}\n\n/**\n * Returns the SQL statement that probes for the existence of the marker table.\n * Uses the SQL-standard `information_schema.tables` view so the query succeeds\n * (returning zero rows) when the table has not been created yet — avoiding a\n * `relation does not exist` error. Some Postgres wire-protocol implementations\n * (e.g. PGlite's TCP proxy) do not fully recover from an extended-protocol\n * parse error, so we probe first instead of relying on an error signal.\n * @internal - Used internally by readMarker().\n */\nexport function markerTableExistsSql(): {\n readonly sql: string;\n readonly params: readonly unknown[];\n} {\n return {\n sql: `select 1\n from information_schema.tables\n where table_schema = $1 and table_name = $2`,\n params: ['prisma_contract', 'marker'],\n };\n}\n\n/**\n * Reads the contract marker from the database using the provided driver.\n * Returns the parsed marker record or null if no marker is found.\n * This abstracts SQL-specific details from the Control Plane.\n *\n * @param driver - ControlDriverInstance instance for executing queries\n * @returns Promise resolving to ContractMarkerRecord or null if marker not found\n */\nexport async function readMarker(\n driver: ControlDriverInstance<'sql', string>,\n): Promise<ContractMarkerRecord | null> {\n // Probe for the marker table first so that a fresh database (no\n // `prisma_contract` schema) returns null cleanly instead of surfacing a\n // `relation does not exist` error. This keeps the control connection in a\n // predictable state for driver implementations that are sensitive to\n // extended-protocol parse errors.\n const existsStatement = markerTableExistsSql();\n const existsResult = await driver.query(existsStatement.sql, existsStatement.params);\n if (existsResult.rows.length === 0) {\n return null;\n }\n\n const markerStatement = readMarkerSql();\n const queryResult = await driver.query<{\n core_hash: string;\n profile_hash: string;\n contract_json: unknown | null;\n canonical_version: number | null;\n updated_at: Date | string;\n app_tag: string | null;\n meta: unknown | null;\n }>(markerStatement.sql, markerStatement.params);\n\n if (queryResult.rows.length === 0) {\n return null;\n }\n\n const markerRow = queryResult.rows[0];\n if (!markerRow) {\n throw new Error('Database query returned unexpected result structure');\n }\n\n return parseContractMarkerRow(markerRow);\n}\n\n/**\n * Collects supported codec type IDs from adapter and extension manifests.\n * Returns a sorted, unique array of type IDs that are declared in the manifests.\n * This enables coverage checks by comparing contract column types against supported types.\n *\n * Note: This extracts type IDs from manifest type imports, not from runtime codec registries.\n * The manifests declare which codec types are available, but the actual type IDs\n * are defined in the codec-types TypeScript modules that are imported.\n *\n * For MVP, we return an empty array since extracting type IDs from TypeScript modules\n * would require runtime evaluation or static analysis. This can be enhanced later.\n */\nexport function collectSupportedCodecTypeIds(\n descriptors: ReadonlyArray<{ readonly id: string }>,\n): readonly string[] {\n // For MVP, return empty array\n // Future enhancement: Extract type IDs from codec-types modules via static analysis\n // or require manifests to explicitly list supported type IDs\n void descriptors;\n return [];\n}\n"],"mappings":";;;AAIA,MAAM,aAAa,KAAK,EAAE,YAAY,WAAW,CAAC;AAElD,SAAS,UAAU,MAAwC;AACzD,KAAI,SAAS,QAAQ,SAAS,OAC5B,QAAO,EAAE;CAGX,IAAIA;AACJ,KAAI,OAAO,SAAS,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