@prisma-next/family-sql 0.1.0-dev.3 → 0.1.0-dev.30
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 +42 -0
- package/dist/exports/chunk-6P44BVZ4.js +580 -0
- package/dist/exports/chunk-6P44BVZ4.js.map +1 -0
- package/dist/exports/{chunk-3HYKCN35.js → chunk-C3GKWCKA.js} +16 -9
- package/dist/exports/chunk-C3GKWCKA.js.map +1 -0
- package/dist/exports/chunk-F252JMEU.js +772 -0
- package/dist/exports/chunk-F252JMEU.js.map +1 -0
- package/dist/exports/control-adapter.d.ts +1 -1
- package/dist/exports/control.d.ts +47 -117
- package/dist/exports/control.js +128 -1355
- package/dist/exports/control.js.map +1 -1
- package/dist/exports/instance-DiZi2k_2.d.ts +127 -0
- package/dist/exports/runtime.d.ts +16 -10
- package/dist/exports/runtime.js +17 -24
- package/dist/exports/runtime.js.map +1 -1
- package/dist/exports/schema-verify.d.ts +75 -0
- package/dist/exports/schema-verify.js +11 -0
- package/dist/exports/schema-verify.js.map +1 -0
- package/dist/exports/test-utils.d.ts +33 -0
- package/dist/exports/test-utils.js +17 -0
- package/dist/exports/test-utils.js.map +1 -0
- package/dist/exports/types-Bh7ftf0Q.d.ts +275 -0
- package/dist/exports/verify.d.ts +1 -1
- package/dist/exports/verify.js +1 -1
- package/package.json +31 -22
- package/dist/exports/chunk-3HYKCN35.js.map +0 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { SchemaIssue, SchemaVerificationNode, OperationContext, VerifyDatabaseSchemaResult } from '@prisma-next/core-control-plane/types';
|
|
2
|
+
import { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
3
|
+
import { i as ComponentDatabaseDependency } from './types-Bh7ftf0Q.js';
|
|
4
|
+
import { TargetBoundComponentDescriptor } from '@prisma-next/contract/framework-components';
|
|
5
|
+
import { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
6
|
+
import '@prisma-next/utils/result';
|
|
7
|
+
import './instance-DiZi2k_2.js';
|
|
8
|
+
import '@prisma-next/contract/ir';
|
|
9
|
+
import '@prisma-next/contract/pack-manifest-types';
|
|
10
|
+
import '@prisma-next/contract/types';
|
|
11
|
+
import '@prisma-next/core-control-plane/schema-view';
|
|
12
|
+
import '@prisma-next/operations';
|
|
13
|
+
import '@prisma-next/sql-operations';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Pure verification helper functions for SQL schema verification.
|
|
17
|
+
* These functions verify schema IR against contract requirements.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Compares two arrays of strings for equality (order-sensitive).
|
|
22
|
+
*/
|
|
23
|
+
declare function arraysEqual(a: readonly string[], b: readonly string[]): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Verifies database dependencies are installed using component-owned verification hooks.
|
|
26
|
+
* Each dependency provides a pure verifyDatabaseDependencyInstalled function that checks
|
|
27
|
+
* whether the dependency is satisfied based on the in-memory schema IR (no DB I/O).
|
|
28
|
+
*
|
|
29
|
+
* Returns verification nodes for the tree.
|
|
30
|
+
*/
|
|
31
|
+
declare function verifyDatabaseDependencies(dependencies: ReadonlyArray<ComponentDatabaseDependency<unknown>>, schema: SqlSchemaIR, issues: SchemaIssue[]): SchemaVerificationNode[];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Pure SQL schema verification function.
|
|
35
|
+
*
|
|
36
|
+
* This module provides a pure function that verifies a SqlSchemaIR against
|
|
37
|
+
* a SqlContract without requiring a database connection. It can be reused
|
|
38
|
+
* by migration planners and other tools that need to compare schema states.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Options for the pure schema verification function.
|
|
43
|
+
*/
|
|
44
|
+
interface VerifySqlSchemaOptions {
|
|
45
|
+
/** The validated SQL contract to verify against */
|
|
46
|
+
readonly contract: SqlContract<SqlStorage>;
|
|
47
|
+
/** The schema IR from introspection (or another source) */
|
|
48
|
+
readonly schema: SqlSchemaIR;
|
|
49
|
+
/** Whether to run in strict mode (detects extra tables/columns) */
|
|
50
|
+
readonly strict: boolean;
|
|
51
|
+
/** Optional operation context for metadata */
|
|
52
|
+
readonly context?: OperationContext;
|
|
53
|
+
/** Type metadata registry for codec consistency warnings */
|
|
54
|
+
readonly typeMetadataRegistry: ReadonlyMap<string, {
|
|
55
|
+
nativeType?: string;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Active framework components participating in this composition.
|
|
59
|
+
* All components must have matching familyId ('sql') and targetId.
|
|
60
|
+
*/
|
|
61
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Verifies that a SqlSchemaIR matches a SqlContract.
|
|
65
|
+
*
|
|
66
|
+
* This is a pure function that does NOT perform any database I/O.
|
|
67
|
+
* It takes an already-introspected schema IR and compares it against
|
|
68
|
+
* the contract requirements.
|
|
69
|
+
*
|
|
70
|
+
* @param options - Verification options
|
|
71
|
+
* @returns VerifyDatabaseSchemaResult with verification tree and issues
|
|
72
|
+
*/
|
|
73
|
+
declare function verifySqlSchema(options: VerifySqlSchemaOptions): VerifyDatabaseSchemaResult;
|
|
74
|
+
|
|
75
|
+
export { type VerifySqlSchemaOptions, arraysEqual, verifyDatabaseDependencies, verifySqlSchema };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { OperationManifest } from '@prisma-next/contract/pack-manifest-types';
|
|
2
|
+
import { TypesImportSpec } from '@prisma-next/contract/types';
|
|
3
|
+
import { ControlTargetDescriptor, ControlAdapterDescriptor, ControlExtensionDescriptor } from '@prisma-next/core-control-plane/types';
|
|
4
|
+
import { OperationSignature, OperationRegistry } from '@prisma-next/operations';
|
|
5
|
+
export { c as convertOperationManifest } from './instance-DiZi2k_2.js';
|
|
6
|
+
import '@prisma-next/contract/framework-components';
|
|
7
|
+
import '@prisma-next/contract/ir';
|
|
8
|
+
import '@prisma-next/core-control-plane/schema-view';
|
|
9
|
+
import '@prisma-next/sql-operations';
|
|
10
|
+
import '@prisma-next/sql-schema-ir/types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Assembles an operation registry from descriptors (adapter, target, extensions).
|
|
14
|
+
* Loops over descriptors, extracts operations, converts them using the provided
|
|
15
|
+
* conversion function, and registers them in a new registry.
|
|
16
|
+
*/
|
|
17
|
+
declare function assembleOperationRegistry(descriptors: ReadonlyArray<ControlTargetDescriptor<'sql', string> | ControlAdapterDescriptor<'sql', string> | ControlExtensionDescriptor<'sql', string>>, convertOperationManifest: (manifest: OperationManifest) => OperationSignature): OperationRegistry;
|
|
18
|
+
/**
|
|
19
|
+
* Extracts codec type imports from descriptors for contract.d.ts generation.
|
|
20
|
+
*/
|
|
21
|
+
declare function extractCodecTypeImports(descriptors: ReadonlyArray<ControlTargetDescriptor<'sql', string> | ControlAdapterDescriptor<'sql', string> | ControlExtensionDescriptor<'sql', string>>): ReadonlyArray<TypesImportSpec>;
|
|
22
|
+
/**
|
|
23
|
+
* Extracts operation type imports from descriptors for contract.d.ts generation.
|
|
24
|
+
*/
|
|
25
|
+
declare function extractOperationTypeImports(descriptors: ReadonlyArray<ControlTargetDescriptor<'sql', string> | ControlAdapterDescriptor<'sql', string> | ControlExtensionDescriptor<'sql', string>>): ReadonlyArray<TypesImportSpec>;
|
|
26
|
+
/**
|
|
27
|
+
* Extracts extension IDs from descriptors in deterministic order:
|
|
28
|
+
* [adapter.id, target.id, ...extensions.map(e => e.id)]
|
|
29
|
+
* Deduplicates while preserving stable order.
|
|
30
|
+
*/
|
|
31
|
+
declare function extractExtensionIds(adapter: ControlAdapterDescriptor<'sql', string>, target: ControlTargetDescriptor<'sql', string>, extensions: ReadonlyArray<ControlExtensionDescriptor<'sql', string>>): ReadonlyArray<string>;
|
|
32
|
+
|
|
33
|
+
export { assembleOperationRegistry, extractCodecTypeImports, extractExtensionIds, extractOperationTypeImports };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assembleOperationRegistry,
|
|
3
|
+
convertOperationManifest,
|
|
4
|
+
extractCodecTypeImports,
|
|
5
|
+
extractExtensionIds,
|
|
6
|
+
extractOperationTypeImports
|
|
7
|
+
} from "./chunk-6P44BVZ4.js";
|
|
8
|
+
import "./chunk-C3GKWCKA.js";
|
|
9
|
+
import "./chunk-F252JMEU.js";
|
|
10
|
+
export {
|
|
11
|
+
assembleOperationRegistry,
|
|
12
|
+
convertOperationManifest,
|
|
13
|
+
extractCodecTypeImports,
|
|
14
|
+
extractExtensionIds,
|
|
15
|
+
extractOperationTypeImports
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=test-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { TargetBoundComponentDescriptor } from '@prisma-next/contract/framework-components';
|
|
2
|
+
import { ControlTargetDescriptor, ControlTargetInstance, MigrationOperationPolicy, MigrationPlannerSuccessResult, MigrationPlan, MigrationPlanOperation, MigrationPlannerFailureResult, MigrationPlannerConflict, ControlDriverInstance, OperationContext, MigrationRunnerExecutionChecks, MigrationRunnerSuccessValue, MigrationRunnerFailure, SchemaIssue, ControlExtensionDescriptor } from '@prisma-next/core-control-plane/types';
|
|
3
|
+
import { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
4
|
+
import { SqlSchemaIR } from '@prisma-next/sql-schema-ir/types';
|
|
5
|
+
import { Result } from '@prisma-next/utils/result';
|
|
6
|
+
import { S as SqlControlFamilyInstance } from './instance-DiZi2k_2.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* SQL-specific migration types.
|
|
10
|
+
*
|
|
11
|
+
* These types extend the canonical migration types from the framework control plane
|
|
12
|
+
* with SQL-specific fields for execution (precheck SQL, execute SQL, etc.).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
type AnyRecord = Readonly<Record<string, unknown>>;
|
|
16
|
+
/**
|
|
17
|
+
* A single database dependency declared by a framework component.
|
|
18
|
+
* Uses SqlMigrationPlanOperation so we inherit the existing precheck/execute/postcheck contract.
|
|
19
|
+
*
|
|
20
|
+
* Database dependencies allow components (extensions, adapters) to declare what database-side
|
|
21
|
+
* persistence structures they require (e.g., Postgres extensions, schemas, functions).
|
|
22
|
+
* The planner emits these as migration operations, and the verifier uses the pure verification
|
|
23
|
+
* hook to check satisfaction against the schema IR.
|
|
24
|
+
*/
|
|
25
|
+
interface ComponentDatabaseDependency<TTargetDetails> {
|
|
26
|
+
/** Stable identifier for the dependency (e.g. 'postgres.extension.vector') */
|
|
27
|
+
readonly id: string;
|
|
28
|
+
/** Human label for output (e.g. 'Enable vector extension') */
|
|
29
|
+
readonly label: string;
|
|
30
|
+
/**
|
|
31
|
+
* Operations that install/ensure the dependency.
|
|
32
|
+
* Use SqlMigrationPlanOperation so we inherit the existing precheck/execute/postcheck contract.
|
|
33
|
+
*/
|
|
34
|
+
readonly install: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
35
|
+
/**
|
|
36
|
+
* Pure verification hook: checks whether this dependency is already installed
|
|
37
|
+
* based on the in-memory schema IR (no DB I/O).
|
|
38
|
+
*
|
|
39
|
+
* This must return structured issues suitable for CLI and tree output, not just a boolean.
|
|
40
|
+
*/
|
|
41
|
+
readonly verifyDatabaseDependencyInstalled: (schema: SqlSchemaIR) => readonly SchemaIssue[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Database dependencies declared by a framework component.
|
|
45
|
+
*/
|
|
46
|
+
interface ComponentDatabaseDependencies<TTargetDetails> {
|
|
47
|
+
/**
|
|
48
|
+
* Dependencies required for db init.
|
|
49
|
+
* Future: update dependencies can be added later (e.g. widening/destructive).
|
|
50
|
+
*/
|
|
51
|
+
readonly init?: readonly ComponentDatabaseDependency<TTargetDetails>[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* SQL-specific extension descriptor with optional database dependencies.
|
|
55
|
+
* Extends the core ControlExtensionDescriptor with SQL-specific metadata.
|
|
56
|
+
*
|
|
57
|
+
* Database dependencies are attached to the descriptor (not the instance) because
|
|
58
|
+
* they are declarative metadata that planner/verifier need without constructing instances.
|
|
59
|
+
*/
|
|
60
|
+
interface SqlControlExtensionDescriptor<TTargetId extends string> extends ControlExtensionDescriptor<'sql', TTargetId> {
|
|
61
|
+
/** Optional database dependencies this extension requires. */
|
|
62
|
+
readonly databaseDependencies?: ComponentDatabaseDependencies<unknown>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A single step in a SQL migration operation (precheck, execute, or postcheck).
|
|
66
|
+
*/
|
|
67
|
+
interface SqlMigrationPlanOperationStep {
|
|
68
|
+
readonly description: string;
|
|
69
|
+
readonly sql: string;
|
|
70
|
+
readonly meta?: AnyRecord;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Target details for a SQL migration operation (table, column, index, etc.).
|
|
74
|
+
*/
|
|
75
|
+
interface SqlMigrationPlanOperationTarget<TTargetDetails> {
|
|
76
|
+
readonly id: string;
|
|
77
|
+
readonly details?: TTargetDetails;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A single SQL migration operation with SQL-specific fields.
|
|
81
|
+
* Extends the core MigrationPlanOperation with SQL execution details.
|
|
82
|
+
*/
|
|
83
|
+
interface SqlMigrationPlanOperation<TTargetDetails> extends MigrationPlanOperation {
|
|
84
|
+
/** Optional detailed explanation of what this operation does and why. */
|
|
85
|
+
readonly summary?: string;
|
|
86
|
+
readonly target: SqlMigrationPlanOperationTarget<TTargetDetails>;
|
|
87
|
+
readonly precheck: readonly SqlMigrationPlanOperationStep[];
|
|
88
|
+
readonly execute: readonly SqlMigrationPlanOperationStep[];
|
|
89
|
+
readonly postcheck: readonly SqlMigrationPlanOperationStep[];
|
|
90
|
+
readonly meta?: AnyRecord;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Contract identity information for SQL migrations.
|
|
94
|
+
*/
|
|
95
|
+
interface SqlMigrationPlanContractInfo {
|
|
96
|
+
readonly coreHash: string;
|
|
97
|
+
readonly profileHash?: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A SQL migration plan with SQL-specific fields.
|
|
101
|
+
* Extends the core MigrationPlan with origin tracking and metadata.
|
|
102
|
+
*/
|
|
103
|
+
interface SqlMigrationPlan<TTargetDetails> extends MigrationPlan {
|
|
104
|
+
/**
|
|
105
|
+
* Origin contract identity that the plan expects the database to currently be at.
|
|
106
|
+
* If omitted, the runner treats the origin as "no marker present" (empty database),
|
|
107
|
+
* and will only proceed if no marker exists (or if the marker already matches destination).
|
|
108
|
+
*/
|
|
109
|
+
readonly origin?: SqlMigrationPlanContractInfo | null;
|
|
110
|
+
/**
|
|
111
|
+
* Destination contract identity that the plan intends to reach.
|
|
112
|
+
*/
|
|
113
|
+
readonly destination: SqlMigrationPlanContractInfo;
|
|
114
|
+
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
115
|
+
readonly meta?: AnyRecord;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Specific conflict kinds for SQL migrations.
|
|
119
|
+
*/
|
|
120
|
+
type SqlPlannerConflictKind = 'typeMismatch' | 'nullabilityConflict' | 'indexIncompatible' | 'foreignKeyConflict' | 'missingButNonAdditive' | 'unsupportedExtension' | 'extensionMissing' | 'unsupportedOperation';
|
|
121
|
+
/**
|
|
122
|
+
* Location information for SQL planner conflicts.
|
|
123
|
+
*/
|
|
124
|
+
interface SqlPlannerConflictLocation {
|
|
125
|
+
readonly table?: string;
|
|
126
|
+
readonly column?: string;
|
|
127
|
+
readonly index?: string;
|
|
128
|
+
readonly constraint?: string;
|
|
129
|
+
readonly extension?: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* A SQL-specific planner conflict with additional location information.
|
|
133
|
+
* Extends the core MigrationPlannerConflict.
|
|
134
|
+
*/
|
|
135
|
+
interface SqlPlannerConflict extends MigrationPlannerConflict {
|
|
136
|
+
readonly kind: SqlPlannerConflictKind;
|
|
137
|
+
readonly location?: SqlPlannerConflictLocation;
|
|
138
|
+
readonly meta?: AnyRecord;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Successful SQL planner result with the migration plan.
|
|
142
|
+
*/
|
|
143
|
+
interface SqlPlannerSuccessResult<TTargetDetails> extends Omit<MigrationPlannerSuccessResult, 'plan'> {
|
|
144
|
+
readonly kind: 'success';
|
|
145
|
+
readonly plan: SqlMigrationPlan<TTargetDetails>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Failed SQL planner result with the list of conflicts.
|
|
149
|
+
*/
|
|
150
|
+
interface SqlPlannerFailureResult extends Omit<MigrationPlannerFailureResult, 'conflicts'> {
|
|
151
|
+
readonly kind: 'failure';
|
|
152
|
+
readonly conflicts: readonly SqlPlannerConflict[];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Union type for SQL planner results.
|
|
156
|
+
*/
|
|
157
|
+
type SqlPlannerResult<TTargetDetails> = SqlPlannerSuccessResult<TTargetDetails> | SqlPlannerFailureResult;
|
|
158
|
+
/**
|
|
159
|
+
* Options for SQL migration planner.
|
|
160
|
+
*/
|
|
161
|
+
interface SqlMigrationPlannerPlanOptions {
|
|
162
|
+
readonly contract: SqlContract<SqlStorage>;
|
|
163
|
+
readonly schema: SqlSchemaIR;
|
|
164
|
+
readonly policy: MigrationOperationPolicy;
|
|
165
|
+
readonly schemaName?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Active framework components participating in this composition.
|
|
168
|
+
* SQL targets can interpret this list to derive database dependencies.
|
|
169
|
+
* All components must have matching familyId ('sql') and targetId.
|
|
170
|
+
*/
|
|
171
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* SQL migration planner interface.
|
|
175
|
+
* Extends the core MigrationPlanner with SQL-specific types.
|
|
176
|
+
*/
|
|
177
|
+
interface SqlMigrationPlanner<TTargetDetails> {
|
|
178
|
+
plan(options: SqlMigrationPlannerPlanOptions): SqlPlannerResult<TTargetDetails>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Callbacks for SQL migration runner execution.
|
|
182
|
+
*/
|
|
183
|
+
interface SqlMigrationRunnerExecuteCallbacks<TTargetDetails> {
|
|
184
|
+
onOperationStart?(operation: SqlMigrationPlanOperation<TTargetDetails>): void;
|
|
185
|
+
onOperationComplete?(operation: SqlMigrationPlanOperation<TTargetDetails>): void;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Options for SQL migration runner execution.
|
|
189
|
+
*/
|
|
190
|
+
interface SqlMigrationRunnerExecuteOptions<TTargetDetails> {
|
|
191
|
+
readonly plan: SqlMigrationPlan<TTargetDetails>;
|
|
192
|
+
readonly driver: ControlDriverInstance<'sql', string>;
|
|
193
|
+
/**
|
|
194
|
+
* Destination contract IR.
|
|
195
|
+
* Must correspond to `plan.destination` and is used for schema verification and marker/ledger writes.
|
|
196
|
+
*/
|
|
197
|
+
readonly destinationContract: SqlContract<SqlStorage>;
|
|
198
|
+
/**
|
|
199
|
+
* Execution-time policy that defines which operation classes are allowed.
|
|
200
|
+
* The runner validates each operation against this policy before execution.
|
|
201
|
+
*/
|
|
202
|
+
readonly policy: MigrationOperationPolicy;
|
|
203
|
+
readonly schemaName?: string;
|
|
204
|
+
readonly strictVerification?: boolean;
|
|
205
|
+
readonly callbacks?: SqlMigrationRunnerExecuteCallbacks<TTargetDetails>;
|
|
206
|
+
readonly context?: OperationContext;
|
|
207
|
+
/**
|
|
208
|
+
* Execution-time checks configuration.
|
|
209
|
+
* All checks default to `true` (enabled) when omitted.
|
|
210
|
+
*/
|
|
211
|
+
readonly executionChecks?: MigrationRunnerExecutionChecks;
|
|
212
|
+
/**
|
|
213
|
+
* Active framework components participating in this composition.
|
|
214
|
+
* SQL targets can interpret this list to derive database dependencies.
|
|
215
|
+
* All components must have matching familyId ('sql') and targetId.
|
|
216
|
+
*/
|
|
217
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Error codes for SQL migration runner failures.
|
|
221
|
+
*/
|
|
222
|
+
type SqlMigrationRunnerErrorCode = 'DESTINATION_CONTRACT_MISMATCH' | 'MARKER_ORIGIN_MISMATCH' | 'POLICY_VIOLATION' | 'PRECHECK_FAILED' | 'POSTCHECK_FAILED' | 'SCHEMA_VERIFY_FAILED' | 'EXECUTION_FAILED';
|
|
223
|
+
/**
|
|
224
|
+
* Detailed information about a SQL migration runner failure.
|
|
225
|
+
* Extends the core MigrationRunnerFailure with SQL-specific error codes.
|
|
226
|
+
*/
|
|
227
|
+
interface SqlMigrationRunnerFailure extends MigrationRunnerFailure {
|
|
228
|
+
readonly code: SqlMigrationRunnerErrorCode;
|
|
229
|
+
readonly meta?: AnyRecord;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Success value for SQL migration runner execution.
|
|
233
|
+
* Extends core type for type branding and potential SQL-specific extensions.
|
|
234
|
+
*/
|
|
235
|
+
interface SqlMigrationRunnerSuccessValue extends MigrationRunnerSuccessValue {
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Result type for SQL migration runner execution.
|
|
239
|
+
*/
|
|
240
|
+
type SqlMigrationRunnerResult = Result<SqlMigrationRunnerSuccessValue, SqlMigrationRunnerFailure>;
|
|
241
|
+
/**
|
|
242
|
+
* SQL migration runner interface.
|
|
243
|
+
* Extends the core MigrationRunner with SQL-specific types.
|
|
244
|
+
*/
|
|
245
|
+
interface SqlMigrationRunner<TTargetDetails> {
|
|
246
|
+
execute(options: SqlMigrationRunnerExecuteOptions<TTargetDetails>): Promise<SqlMigrationRunnerResult>;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* SQL control target descriptor with migration support.
|
|
250
|
+
* Extends the core ControlTargetDescriptor with SQL-specific migration methods.
|
|
251
|
+
*/
|
|
252
|
+
interface SqlControlTargetDescriptor<TTargetId extends string, TTargetDetails> extends ControlTargetDescriptor<'sql', TTargetId, ControlTargetInstance<'sql', TTargetId>, SqlControlFamilyInstance> {
|
|
253
|
+
/**
|
|
254
|
+
* Creates a SQL migration planner for this target.
|
|
255
|
+
* Direct method for SQL-specific usage.
|
|
256
|
+
*/
|
|
257
|
+
createPlanner(family: SqlControlFamilyInstance): SqlMigrationPlanner<TTargetDetails>;
|
|
258
|
+
/**
|
|
259
|
+
* Creates a SQL migration runner for this target.
|
|
260
|
+
* Direct method for SQL-specific usage.
|
|
261
|
+
*/
|
|
262
|
+
createRunner(family: SqlControlFamilyInstance): SqlMigrationRunner<TTargetDetails>;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Options for creating a SQL migration plan.
|
|
266
|
+
*/
|
|
267
|
+
interface CreateSqlMigrationPlanOptions<TTargetDetails> {
|
|
268
|
+
readonly targetId: string;
|
|
269
|
+
readonly origin?: SqlMigrationPlanContractInfo | null;
|
|
270
|
+
readonly destination: SqlMigrationPlanContractInfo;
|
|
271
|
+
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
272
|
+
readonly meta?: AnyRecord;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export type { AnyRecord as A, CreateSqlMigrationPlanOptions as C, SqlControlTargetDescriptor as S, SqlMigrationPlan as a, SqlPlannerConflict as b, SqlPlannerFailureResult as c, SqlPlannerSuccessResult as d, SqlMigrationRunnerErrorCode as e, SqlMigrationRunnerFailure as f, SqlMigrationRunnerSuccessValue as g, ComponentDatabaseDependencies as h, ComponentDatabaseDependency as i, SqlControlExtensionDescriptor as j, SqlMigrationPlanContractInfo as k, SqlMigrationPlanner as l, SqlMigrationPlannerPlanOptions as m, SqlMigrationPlanOperation as n, SqlMigrationPlanOperationStep as o, SqlMigrationPlanOperationTarget as p, SqlMigrationRunner as q, SqlMigrationRunnerExecuteCallbacks as r, SqlMigrationRunnerExecuteOptions as s, SqlMigrationRunnerResult as t, SqlPlannerConflictKind as u, SqlPlannerConflictLocation as v, SqlPlannerResult as w };
|
package/dist/exports/verify.d.ts
CHANGED
|
@@ -23,6 +23,6 @@ declare function readMarkerSql(): {
|
|
|
23
23
|
* @param driver - ControlDriverInstance instance for executing queries
|
|
24
24
|
* @returns Promise resolving to ContractMarkerRecord or null if marker not found
|
|
25
25
|
*/
|
|
26
|
-
declare function readMarker(driver: ControlDriverInstance): Promise<ContractMarkerRecord | null>;
|
|
26
|
+
declare function readMarker(driver: ControlDriverInstance<'sql', string>): Promise<ContractMarkerRecord | null>;
|
|
27
27
|
|
|
28
28
|
export { parseContractMarkerRow, readMarker, readMarkerSql };
|
package/dist/exports/verify.js
CHANGED
package/package.json
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/family-sql",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.30",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "SQL family descriptor for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"arktype": "^2.0.0",
|
|
9
|
-
"@prisma-next/cli": "0.1.0-dev.
|
|
10
|
-
"@prisma-next/contract": "0.1.0-dev.
|
|
11
|
-
"@prisma-next/core-
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/runtime-executor": "0.1.0-dev.
|
|
14
|
-
"@prisma-next/sql-contract-emitter": "0.1.0-dev.
|
|
15
|
-
"@prisma-next/sql-contract-ts": "0.1.0-dev.
|
|
16
|
-
"@prisma-next/
|
|
17
|
-
"@prisma-next/sql-contract": "0.1.0-dev.
|
|
18
|
-
"@prisma-next/sql-
|
|
19
|
-
"@prisma-next/sql-
|
|
20
|
-
"@prisma-next/sql-runtime": "0.1.0-dev.
|
|
21
|
-
"@prisma-next/sql-schema-ir": "0.1.0-dev.
|
|
9
|
+
"@prisma-next/cli": "0.1.0-dev.30",
|
|
10
|
+
"@prisma-next/contract": "0.1.0-dev.30",
|
|
11
|
+
"@prisma-next/core-control-plane": "0.1.0-dev.30",
|
|
12
|
+
"@prisma-next/core-execution-plane": "0.1.0-dev.30",
|
|
13
|
+
"@prisma-next/runtime-executor": "0.1.0-dev.30",
|
|
14
|
+
"@prisma-next/sql-contract-emitter": "0.1.0-dev.30",
|
|
15
|
+
"@prisma-next/sql-contract-ts": "0.1.0-dev.30",
|
|
16
|
+
"@prisma-next/operations": "0.1.0-dev.30",
|
|
17
|
+
"@prisma-next/sql-contract": "0.1.0-dev.30",
|
|
18
|
+
"@prisma-next/sql-operations": "0.1.0-dev.30",
|
|
19
|
+
"@prisma-next/sql-relational-core": "0.1.0-dev.30",
|
|
20
|
+
"@prisma-next/sql-runtime": "0.1.0-dev.30",
|
|
21
|
+
"@prisma-next/sql-schema-ir": "0.1.0-dev.30",
|
|
22
|
+
"@prisma-next/utils": "0.1.0-dev.30"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
25
|
+
"@vitest/coverage-v8": "^4.0.0",
|
|
24
26
|
"tsup": "^8.3.0",
|
|
25
27
|
"typescript": "^5.9.3",
|
|
26
28
|
"vite-tsconfig-paths": "^5.1.4",
|
|
27
|
-
"vitest": "^
|
|
28
|
-
"@prisma-next/
|
|
29
|
-
"@prisma-next/test-utils": "0.0.1"
|
|
30
|
-
"@prisma-next/driver-postgres": "0.1.0-dev.3"
|
|
29
|
+
"vitest": "^4.0.16",
|
|
30
|
+
"@prisma-next/driver-postgres": "0.1.0-dev.30",
|
|
31
|
+
"@prisma-next/test-utils": "0.0.1"
|
|
31
32
|
},
|
|
32
33
|
"files": [
|
|
33
34
|
"dist"
|
|
@@ -48,14 +49,22 @@
|
|
|
48
49
|
"./verify": {
|
|
49
50
|
"types": "./dist/exports/verify.d.ts",
|
|
50
51
|
"import": "./dist/exports/verify.js"
|
|
52
|
+
},
|
|
53
|
+
"./test-utils": {
|
|
54
|
+
"types": "./dist/exports/test-utils.d.ts",
|
|
55
|
+
"import": "./dist/exports/test-utils.js"
|
|
56
|
+
},
|
|
57
|
+
"./schema-verify": {
|
|
58
|
+
"types": "./dist/exports/schema-verify.d.ts",
|
|
59
|
+
"import": "./dist/exports/schema-verify.js"
|
|
51
60
|
}
|
|
52
61
|
},
|
|
53
62
|
"scripts": {
|
|
54
63
|
"build": "tsup --config tsup.config.ts",
|
|
55
|
-
"test": "vitest run
|
|
56
|
-
"test:coverage": "vitest run --coverage
|
|
64
|
+
"test": "vitest run",
|
|
65
|
+
"test:coverage": "vitest run --coverage",
|
|
57
66
|
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
58
|
-
"lint": "biome check . --config-path
|
|
59
|
-
"clean": "node
|
|
67
|
+
"lint": "biome check . --config-path ../../../../biome.json --error-on-warnings",
|
|
68
|
+
"clean": "node ../../../../scripts/clean.mjs"
|
|
60
69
|
}
|
|
61
70
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/verify.ts"],"sourcesContent":["import type { ContractMarkerRecord } from '@prisma-next/contract/types';\nimport type {\n ControlAdapterDescriptor,\n ControlDriverInstance,\n ControlExtensionDescriptor,\n ControlTargetDescriptor,\n} from '@prisma-next/core-control-plane/types';\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 coreHash: 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 * 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,\n): Promise<ContractMarkerRecord | null> {\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 // If rows array has length > 0 but first element is undefined, this is an unexpected result structure\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<TFamilyId extends string, TTargetId extends string>(\n descriptors: ReadonlyArray<\n | ControlTargetDescriptor<TFamilyId, TTargetId>\n | ControlAdapterDescriptor<TFamilyId, TTargetId>\n | ControlExtensionDescriptor<TFamilyId, TTargetId>\n >,\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":";AAOA,SAAS,YAAY;AAErB,IAAM,aAAa,KAAK,EAAE,YAAY,UAAU,CAAC;AAEjD,SAAS,UAAU,MAAwC;AACzD,MAAI,SAAS,QAAQ,SAAS,QAAW;AACvC,WAAO,CAAC;AAAA,EACV;AAEA,MAAI;AACJ,MAAI,OAAO,SAAS,UAAU;AAC5B,QAAI;AACF,eAAS,KAAK,MAAM,IAAI;AAAA,IAC1B,QAAQ;AACN,aAAO,CAAC;AAAA,IACV;AAAA,EACF,OAAO;AACL,aAAS;AAAA,EACX;AAEA,QAAM,SAAS,WAAW,MAAM;AAChC,MAAI,kBAAkB,KAAK,QAAQ;AACjC,WAAO,CAAC;AAAA,EACV;AAEA,SAAO;AACT;AAEA,IAAM,0BAA0B,KAAK;AAAA,EACnC,WAAW;AAAA,EACX,cAAc;AAAA,EACd,kBAAkB;AAAA,EAClB,sBAAsB;AAAA,EACtB,eAAe;AAAA,EACf,YAAY;AAAA,EACZ,SAAS;AACX,CAAC;AAMM,SAAS,uBAAuB,KAAoC;AACzE,QAAM,SAAS,wBAAwB,GAAG;AAC1C,MAAI,kBAAkB,KAAK,QAAQ;AACjC,UAAM,WAAW,OAAO,IAAI,CAAC,MAA2B,EAAE,OAAO,EAAE,KAAK,IAAI;AAC5E,UAAM,IAAI,MAAM,gCAAgC,QAAQ,EAAE;AAAA,EAC5D;AAEA,QAAM,eAAe;AAUrB,QAAM,YAAY,aAAa,aAC3B,aAAa,sBAAsB,OACjC,aAAa,aACb,IAAI,KAAK,aAAa,UAAU,IAClC,oBAAI,KAAK;AAEb,SAAO;AAAA,IACL,UAAU,aAAa;AAAA,IACvB,aAAa,aAAa;AAAA,IAC1B,cAAc,aAAa,iBAAiB;AAAA,IAC5C,kBAAkB,aAAa,qBAAqB;AAAA,IACpD;AAAA,IACA,QAAQ,aAAa,WAAW;AAAA,IAChC,MAAM,UAAU,aAAa,IAAI;AAAA,EACnC;AACF;AAOO,SAAS,gBAA+E;AAC7F,SAAO;AAAA,IACL,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAUL,QAAQ,CAAC,CAAC;AAAA,EACZ;AACF;AAUA,eAAsB,WACpB,QACsC;AACtC,QAAM,kBAAkB,cAAc;AACtC,QAAM,cAAc,MAAM,OAAO,MAQ9B,gBAAgB,KAAK,gBAAgB,MAAM;AAE9C,MAAI,YAAY,KAAK,WAAW,GAAG;AACjC,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,YAAY,KAAK,CAAC;AACpC,MAAI,CAAC,WAAW;AAEd,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AAEA,SAAO,uBAAuB,SAAS;AACzC;AAcO,SAAS,6BACd,aAKmB;AAInB,OAAK;AACL,SAAO,CAAC;AACV;","names":[]}
|