@prisma-next/family-sql 0.12.0-dev.17 → 0.12.0-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/control-adapter.d.mts +109 -2
- package/dist/control-adapter.d.mts.map +1 -0
- package/dist/control.d.mts +2 -2
- package/dist/control.mjs +13 -20
- package/dist/control.mjs.map +1 -1
- package/dist/migration.d.mts +1 -1
- package/dist/runtime.d.mts +1 -3
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +1 -3
- package/dist/runtime.mjs.map +1 -1
- package/dist/schema-verify.d.mts +1 -1
- package/dist/schema-verify.d.mts.map +1 -1
- package/dist/schema-verify.mjs +1 -1
- package/dist/{types-BQiqw6kR.d.mts → types-CeeCStqw.d.mts} +5 -14
- package/dist/types-CeeCStqw.d.mts.map +1 -0
- package/dist/{verify-sql-schema-Cj3c2t5Z.d.mts → verify-sql-schema-CN7pPoTC.d.mts} +2 -8
- package/dist/verify-sql-schema-CN7pPoTC.d.mts.map +1 -0
- package/dist/{verify-sql-schema-CXW_D9dW.mjs → verify-sql-schema-CYLsGCFO.mjs} +310 -403
- package/dist/verify-sql-schema-CYLsGCFO.mjs.map +1 -0
- package/package.json +21 -21
- package/src/core/control-adapter.ts +3 -44
- package/src/core/control-instance.ts +41 -40
- package/src/core/migrations/types.ts +1 -8
- package/src/core/schema-verify/verify-helpers.ts +110 -151
- package/src/core/schema-verify/verify-sql-schema.ts +155 -291
- package/src/exports/runtime.ts +0 -7
- package/dist/control-adapter-8tV9WgWK.d.mts +0 -134
- package/dist/control-adapter-8tV9WgWK.d.mts.map +0 -1
- package/dist/types-BQiqw6kR.d.mts.map +0 -1
- package/dist/verify-sql-schema-CXW_D9dW.mjs.map +0 -1
- package/dist/verify-sql-schema-Cj3c2t5Z.d.mts.map +0 -1
- package/src/core/default-namespace.ts +0 -9
- package/src/core/schema-verify/control-verify-emit.ts +0 -46
- package/src/core/schema-verify/verifier-disposition.ts +0 -53
|
@@ -1,2 +1,109 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
|
|
1
|
+
import { n as NativeTypeNormalizer, t as DefaultNormalizer } from "./verify-sql-schema-CN7pPoTC.mjs";
|
|
2
|
+
import { ControlAdapterInstance, ControlDriverInstance, ControlStack } from "@prisma-next/framework-components/control";
|
|
3
|
+
import { PostgresEnumStorageEntry, SqlStorage } from "@prisma-next/sql-contract/types";
|
|
4
|
+
import { Contract, ContractMarkerRecord } from "@prisma-next/contract/types";
|
|
5
|
+
import { AnyQueryAst, LoweredStatement, LowererContext } from "@prisma-next/sql-relational-core/ast";
|
|
6
|
+
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
7
|
+
|
|
8
|
+
//#region src/core/control-adapter.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* SQL control adapter interface for control-plane operations.
|
|
11
|
+
* Implemented by target-specific adapters (e.g., Postgres, MySQL).
|
|
12
|
+
*
|
|
13
|
+
* @template TTarget - The target ID (e.g., 'postgres', 'mysql')
|
|
14
|
+
*/
|
|
15
|
+
interface SqlControlAdapter<TTarget extends string = string> extends ControlAdapterInstance<'sql', TTarget> {
|
|
16
|
+
/**
|
|
17
|
+
* Reads the contract marker for `space` from the database, returning
|
|
18
|
+
* `null` if no marker row exists for that space (or if the marker
|
|
19
|
+
* table itself is missing). Implementations are responsible for the
|
|
20
|
+
* dialect-specific existence probe (e.g. Postgres
|
|
21
|
+
* `information_schema.tables` vs SQLite `sqlite_master`) and parameter
|
|
22
|
+
* placeholders.
|
|
23
|
+
*
|
|
24
|
+
* `space` is required so callers cannot accidentally fall through to
|
|
25
|
+
* the app's marker row when reading per-extension markers.
|
|
26
|
+
*
|
|
27
|
+
* @param driver - ControlDriverInstance for executing queries (target-specific)
|
|
28
|
+
* @param space - Contract space id whose marker row to read (e.g. `'app'`)
|
|
29
|
+
* @returns Resolved marker record, or `null` if not yet stamped.
|
|
30
|
+
*/
|
|
31
|
+
readMarker(driver: ControlDriverInstance<'sql', TTarget>, space: string): Promise<ContractMarkerRecord | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Reads every marker row from `prisma_contract.marker` (one per
|
|
34
|
+
* contract space) and returns them keyed by `space`. Used by the
|
|
35
|
+
* per-space verifier to detect marker-vs-on-disk drift and orphan
|
|
36
|
+
* marker rows. Returns an empty map when the marker table does not
|
|
37
|
+
* yet exist (fresh database / never-signed project).
|
|
38
|
+
*/
|
|
39
|
+
readAllMarkers(driver: ControlDriverInstance<'sql', TTarget>): Promise<ReadonlyMap<string, ContractMarkerRecord>>;
|
|
40
|
+
/**
|
|
41
|
+
* Introspects a database schema and returns a raw SqlSchemaIR.
|
|
42
|
+
*
|
|
43
|
+
* This is a pure schema discovery operation that queries the database catalog
|
|
44
|
+
* and returns the schema structure without type mapping or contract enrichment.
|
|
45
|
+
* Type mapping and enrichment are handled separately by enrichment helpers.
|
|
46
|
+
*
|
|
47
|
+
* @param driver - ControlDriverInstance instance for executing queries (target-specific)
|
|
48
|
+
* @param contract - Optional contract for contract-guided introspection (filtering, optimization)
|
|
49
|
+
* @param schema - Schema name to introspect (defaults to 'public')
|
|
50
|
+
* @returns Promise resolving to SqlSchemaIR representing the live database schema
|
|
51
|
+
*/
|
|
52
|
+
introspect(driver: ControlDriverInstance<'sql', TTarget>, contract?: unknown, schema?: string): Promise<SqlSchemaIR>;
|
|
53
|
+
/**
|
|
54
|
+
* Optional target-specific normalizer for raw database default expressions.
|
|
55
|
+
* When provided, schema defaults (raw strings) are normalized before comparison
|
|
56
|
+
* with contract defaults (ColumnDefault objects) during schema verification.
|
|
57
|
+
*/
|
|
58
|
+
readonly normalizeDefault?: DefaultNormalizer;
|
|
59
|
+
/**
|
|
60
|
+
* Optional target-specific normalizer for schema native type names.
|
|
61
|
+
* When provided, schema native types (from introspection) are normalized
|
|
62
|
+
* before comparison with contract native types during schema verification.
|
|
63
|
+
*/
|
|
64
|
+
readonly normalizeNativeType?: NativeTypeNormalizer;
|
|
65
|
+
/**
|
|
66
|
+
* Optional bridging adapter for resolving the existing values of a
|
|
67
|
+
* native enum type from the introspected schema IR. Targets supply
|
|
68
|
+
* this so the family-level schema verifier can walk
|
|
69
|
+
* `PostgresEnumStorageEntry` entries natively without needing to
|
|
70
|
+
* know the target-specific `schema.annotations` shape
|
|
71
|
+
* (e.g. `schema.annotations.pg.storageTypes`).
|
|
72
|
+
*/
|
|
73
|
+
readonly resolveExistingEnumValues?: (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
|
|
74
|
+
/**
|
|
75
|
+
* Optional contract-scoped factory for {@link resolveExistingEnumValues}.
|
|
76
|
+
* Targets that need the contract storage to resolve namespace → DDL schema
|
|
77
|
+
* supply this; the family control instance prefers it over the bare adapter
|
|
78
|
+
* hook when present.
|
|
79
|
+
*/
|
|
80
|
+
readonly resolveExistingEnumValuesForContract?: (contract: Contract<SqlStorage>) => (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
|
|
81
|
+
/**
|
|
82
|
+
* Lower a SQL query AST into a target-flavored `{ sql, params }` payload.
|
|
83
|
+
*
|
|
84
|
+
* Migration tooling (e.g. the `dataTransform` operation) needs to materialize
|
|
85
|
+
* SQL at emit/plan time without instantiating the runtime adapter. The control
|
|
86
|
+
* adapter's `lower` is byte-equivalent to the runtime adapter's `lower` for the
|
|
87
|
+
* same AST and contract, ensuring planned SQL matches what the runtime would
|
|
88
|
+
* emit.
|
|
89
|
+
*/
|
|
90
|
+
lower(ast: AnyQueryAst, context: LowererContext<unknown>): LoweredStatement;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* SQL control adapter descriptor interface.
|
|
94
|
+
* Provides a factory method to create control adapter instances.
|
|
95
|
+
*
|
|
96
|
+
* @template TTarget - The target ID (e.g., 'postgres', 'mysql')
|
|
97
|
+
*/
|
|
98
|
+
interface SqlControlAdapterDescriptor<TTarget extends string = string> {
|
|
99
|
+
/**
|
|
100
|
+
* Creates a SQL control adapter instance for control-plane operations.
|
|
101
|
+
*
|
|
102
|
+
* Receives the assembled `ControlStack` so adapters can read aggregated
|
|
103
|
+
* metadata (codec lookup, extension contributions) when materializing.
|
|
104
|
+
*/
|
|
105
|
+
create(stack: ControlStack<'sql', TTarget>): SqlControlAdapter<TTarget>;
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { type SqlControlAdapter, type SqlControlAdapterDescriptor };
|
|
109
|
+
//# sourceMappingURL=control-adapter.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-adapter.d.mts","names":[],"sources":["../src/core/control-adapter.ts"],"mappings":";;;;;;;;;;AAqBA;;;;UAAiB,iBAAA,0CACP,sBAAA,QAA8B,OAAA;EAiB5B;;;;;;;;;;;;;;;EADV,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,WACC,OAAA,CAAQ,oBAAA;EAiEU;;;;;;;EAxDrB,cAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,IACpC,OAAA,CAAQ,WAAA,SAAoB,oBAAA;EA9BD;;;;;;;;;;;;EA4C9B,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,QAAA,YACA,MAAA,YACC,OAAA,CAAQ,WAAA;EAnBD;;;;;EAAA,SA0BD,gBAAA,GAAmB,iBAAA;EAX5B;;;;;EAAA,SAkBS,mBAAA,GAAsB,oBAAA;EAd5B;;;;;;;;EAAA,SAwBM,yBAAA,IACP,MAAA,EAAQ,WAAA,EACR,QAAA,EAAU,wBAAA,EACV,WAAA;EADU;;;;;;EAAA,SASH,oCAAA,IACP,QAAA,EAAU,QAAA,CAAS,UAAA,OAEnB,MAAA,EAAQ,WAAA,EACR,QAAA,EAAU,wBAAA,EACV,WAAA;EAFQ;;;;;;;;;EAcV,KAAA,CAAM,GAAA,EAAK,WAAA,EAAa,OAAA,EAAS,cAAA,YAA0B,gBAAA;AAAA;;AAAgB;AAS7E;;;;UAAiB,2BAAA;EAOgD;;;;;;EAA/D,MAAA,CAAO,KAAA,EAAO,YAAA,QAAoB,OAAA,IAAW,iBAAA,CAAkB,OAAA;AAAA"}
|
package/dist/control.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { A as SqlPlannerResult, C as SqlMigrationRunnerResult, D as SqlPlannerConflictKind, E as SqlPlannerConflict, M as StorageTypePlanResult, N as SqlControlFamilyInstance, O as SqlPlannerConflictLocation, S as SqlMigrationRunnerFailure, T as SqlPlanTargetDetails, _ as SqlMigrationPlannerPlanOptions, a as FieldEvent, b as SqlMigrationRunnerExecuteCallbacks, c as SqlControlAdapterDescriptor, d as SqlMigrationPlan, f as SqlMigrationPlanContractInfo, g as SqlMigrationPlanner, h as SqlMigrationPlanOperationTarget, i as ExpandNativeTypeInput, j as SqlPlannerSuccessResult, k as SqlPlannerFailureResult, l as SqlControlExtensionDescriptor, m as SqlMigrationPlanOperationStep, n as CodecControlHooks, o as FieldEventContext, p as SqlMigrationPlanOperation, r as CreateSqlMigrationPlanOptions, s as ResolveIdentityValueInput, t as AnyRecord, u as SqlControlTargetDescriptor, v as SqlMigrationRunner, w as SqlMigrationRunnerSuccessValue, x as SqlMigrationRunnerExecuteOptions, y as SqlMigrationRunnerErrorCode } from "./types-
|
|
1
|
+
import { A as SqlPlannerResult, C as SqlMigrationRunnerResult, D as SqlPlannerConflictKind, E as SqlPlannerConflict, M as StorageTypePlanResult, N as SqlControlFamilyInstance, O as SqlPlannerConflictLocation, S as SqlMigrationRunnerFailure, T as SqlPlanTargetDetails, _ as SqlMigrationPlannerPlanOptions, a as FieldEvent, b as SqlMigrationRunnerExecuteCallbacks, c as SqlControlAdapterDescriptor, d as SqlMigrationPlan, f as SqlMigrationPlanContractInfo, g as SqlMigrationPlanner, h as SqlMigrationPlanOperationTarget, i as ExpandNativeTypeInput, j as SqlPlannerSuccessResult, k as SqlPlannerFailureResult, l as SqlControlExtensionDescriptor, m as SqlMigrationPlanOperationStep, n as CodecControlHooks, o as FieldEventContext, p as SqlMigrationPlanOperation, r as CreateSqlMigrationPlanOptions, s as ResolveIdentityValueInput, t as AnyRecord, u as SqlControlTargetDescriptor, v as SqlMigrationRunner, w as SqlMigrationRunnerSuccessValue, x as SqlMigrationRunnerExecuteOptions, y as SqlMigrationRunnerErrorCode } from "./types-CeeCStqw.mjs";
|
|
2
2
|
import { ControlFamilyDescriptor, ControlStack, MigrationOperationClass, MigrationOperationPolicy, MigrationOperationPolicy as MigrationOperationPolicy$1, MigrationPlan, MigrationPlanOperation, MigrationPlanner, MigrationPlannerConflict, MigrationPlannerConflict as MigrationPlannerConflict$1, MigrationPlannerResult, MutationDefaultGeneratorDescriptor, OpFactoryCall, TargetMigrationsCapability, assembleAuthoringContributions } from "@prisma-next/framework-components/control";
|
|
3
3
|
import { SqlStorage, StorageColumn } from "@prisma-next/sql-contract/types";
|
|
4
|
-
import { ColumnDefault, Contract } from "@prisma-next/contract/types";
|
|
5
4
|
import { NotOk, Ok } from "@prisma-next/utils/result";
|
|
5
|
+
import { ColumnDefault, Contract } from "@prisma-next/contract/types";
|
|
6
6
|
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
7
7
|
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
8
8
|
import { EmissionSpi } from "@prisma-next/framework-components/emission";
|
package/dist/control.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { n as sqlFamilyAuthoringFieldPresets, t as sqlFamilyAuthoringTypes } from "./authoring-type-constructors-F4JpCJl7.mjs";
|
|
2
2
|
import { t as SqlContractSerializer } from "./sql-contract-serializer-8axtK4lg.mjs";
|
|
3
|
-
import { a as extractCodecControlHooks, t as verifySqlSchema } from "./verify-sql-schema-
|
|
3
|
+
import { a as extractCodecControlHooks, t as verifySqlSchema } from "./verify-sql-schema-CYLsGCFO.mjs";
|
|
4
4
|
import { t as collectSupportedCodecTypeIds } from "./verify-Crewz6hG.mjs";
|
|
5
5
|
import { n as temporalAuthoringPresets, r as timestampNowControlDescriptor } from "./timestamp-now-generator-BkjCQIde.mjs";
|
|
6
6
|
import { sqlEmission } from "@prisma-next/sql-contract-emitter";
|
|
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
8
|
import { assertDescriptorSelfConsistency } from "@prisma-next/migration-tools/spaces";
|
|
9
9
|
import { sqlContractCanonicalizationHooks } from "@prisma-next/sql-contract/canonicalization-hooks";
|
|
10
|
-
import { writeContractMarker } from "@prisma-next/sql-runtime";
|
|
10
|
+
import { ensureSchemaStatement, ensureTableStatement, writeContractMarker } from "@prisma-next/sql-runtime";
|
|
11
11
|
import { defaultIndexName } from "@prisma-next/sql-schema-ir/naming";
|
|
12
12
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
13
13
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
@@ -1057,6 +1057,9 @@ function createVerifyResult(options) {
|
|
|
1057
1057
|
if (options.codecCoverageSkipped) result.codecCoverageSkipped = options.codecCoverageSkipped;
|
|
1058
1058
|
return result;
|
|
1059
1059
|
}
|
|
1060
|
+
function isSqlControlAdapter(value) {
|
|
1061
|
+
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" && "lower" in value && typeof value.lower === "function";
|
|
1062
|
+
}
|
|
1060
1063
|
function buildSqlTypeMetadataRegistry(options) {
|
|
1061
1064
|
const { target, adapter, extensionPacks: extensions } = options;
|
|
1062
1065
|
const registry = /* @__PURE__ */ new Map();
|
|
@@ -1100,7 +1103,11 @@ function createSqlFamilyInstance(stack) {
|
|
|
1100
1103
|
adapter,
|
|
1101
1104
|
extensionPacks: extensions
|
|
1102
1105
|
});
|
|
1103
|
-
const getControlAdapter = () =>
|
|
1106
|
+
const getControlAdapter = () => {
|
|
1107
|
+
const controlAdapter = adapter.create(stack);
|
|
1108
|
+
if (!isSqlControlAdapter(controlAdapter)) throw new Error("Adapter does not implement SqlControlAdapter (missing introspect, readMarker, or readAllMarkers)");
|
|
1109
|
+
return controlAdapter;
|
|
1110
|
+
};
|
|
1104
1111
|
const targetSerializer = target.contractSerializer;
|
|
1105
1112
|
const deserializeWithTargetSerializer = (contractJson) => {
|
|
1106
1113
|
return (targetSerializer ?? new SqlContractSerializer()).deserializeContract(contractJson);
|
|
@@ -1216,7 +1223,6 @@ function createSqlFamilyInstance(stack) {
|
|
|
1216
1223
|
frameworkComponents: options.frameworkComponents,
|
|
1217
1224
|
...ifDefined("normalizeDefault", controlAdapter.normalizeDefault),
|
|
1218
1225
|
...ifDefined("normalizeNativeType", controlAdapter.normalizeNativeType),
|
|
1219
|
-
...ifDefined("columnsCompatible", controlAdapter.columnsCompatible),
|
|
1220
1226
|
...ifDefined("resolveExistingEnumValues", resolveExistingEnumValues)
|
|
1221
1227
|
});
|
|
1222
1228
|
},
|
|
@@ -1227,13 +1233,9 @@ function createSqlFamilyInstance(stack) {
|
|
|
1227
1233
|
const contractStorageHash = contract.storage.storageHash;
|
|
1228
1234
|
const contractProfileHash = "profileHash" in contract && typeof contract.profileHash === "string" ? contract.profileHash : contractStorageHash;
|
|
1229
1235
|
const contractTarget = contract.target;
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
const lowered = controlAdapter.lower(query, lowererContext);
|
|
1234
|
-
await driver.query(lowered.sql, lowered.params);
|
|
1235
|
-
}
|
|
1236
|
-
const existingMarker = await controlAdapter.readMarker(driver, APP_SPACE_ID);
|
|
1236
|
+
await driver.query(ensureSchemaStatement.sql, ensureSchemaStatement.params);
|
|
1237
|
+
await driver.query(ensureTableStatement.sql, ensureTableStatement.params);
|
|
1238
|
+
const existingMarker = await getControlAdapter().readMarker(driver, APP_SPACE_ID);
|
|
1237
1239
|
let markerCreated = false;
|
|
1238
1240
|
let markerUpdated = false;
|
|
1239
1241
|
let previousHashes;
|
|
@@ -1300,9 +1302,6 @@ function createSqlFamilyInstance(stack) {
|
|
|
1300
1302
|
async readAllMarkers(options) {
|
|
1301
1303
|
return getControlAdapter().readAllMarkers(options.driver);
|
|
1302
1304
|
},
|
|
1303
|
-
async readLedger(options) {
|
|
1304
|
-
return getControlAdapter().readLedger(options.driver, options.space);
|
|
1305
|
-
},
|
|
1306
1305
|
async introspect(options) {
|
|
1307
1306
|
return getControlAdapter().introspect(options.driver, options.contract);
|
|
1308
1307
|
},
|
|
@@ -1312,12 +1311,6 @@ function createSqlFamilyInstance(stack) {
|
|
|
1312
1311
|
lowerAst(ast, context) {
|
|
1313
1312
|
return getControlAdapter().lower(ast, context);
|
|
1314
1313
|
},
|
|
1315
|
-
bootstrapControlTableQueries() {
|
|
1316
|
-
return getControlAdapter().bootstrapControlTableQueries();
|
|
1317
|
-
},
|
|
1318
|
-
bootstrapSignMarkerQueries() {
|
|
1319
|
-
return getControlAdapter().bootstrapSignMarkerQueries();
|
|
1320
|
-
},
|
|
1321
1314
|
toOperationPreview(operations) {
|
|
1322
1315
|
return sqlOperationsToPreview(operations);
|
|
1323
1316
|
},
|