@prisma-next/family-sql 0.12.0-dev.1 → 0.12.0-dev.11

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.
@@ -0,0 +1,115 @@
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, LedgerEntryRecord } 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
+ * Reads the per-migration ledger journal for `space` in apply order.
42
+ * Returns an empty array when the ledger store does not yet exist or
43
+ * has no rows for that space.
44
+ */
45
+ readLedger(driver: ControlDriverInstance<'sql', TTarget>, space: string): Promise<readonly LedgerEntryRecord[]>;
46
+ /**
47
+ * Introspects a database schema and returns a raw SqlSchemaIR.
48
+ *
49
+ * This is a pure schema discovery operation that queries the database catalog
50
+ * and returns the schema structure without type mapping or contract enrichment.
51
+ * Type mapping and enrichment are handled separately by enrichment helpers.
52
+ *
53
+ * @param driver - ControlDriverInstance instance for executing queries (target-specific)
54
+ * @param contract - Optional contract for contract-guided introspection (filtering, optimization)
55
+ * @param schema - Schema name to introspect (defaults to 'public')
56
+ * @returns Promise resolving to SqlSchemaIR representing the live database schema
57
+ */
58
+ introspect(driver: ControlDriverInstance<'sql', TTarget>, contract?: unknown, schema?: string): Promise<SqlSchemaIR>;
59
+ /**
60
+ * Optional target-specific normalizer for raw database default expressions.
61
+ * When provided, schema defaults (raw strings) are normalized before comparison
62
+ * with contract defaults (ColumnDefault objects) during schema verification.
63
+ */
64
+ readonly normalizeDefault?: DefaultNormalizer;
65
+ /**
66
+ * Optional target-specific normalizer for schema native type names.
67
+ * When provided, schema native types (from introspection) are normalized
68
+ * before comparison with contract native types during schema verification.
69
+ */
70
+ readonly normalizeNativeType?: NativeTypeNormalizer;
71
+ /**
72
+ * Optional bridging adapter for resolving the existing values of a
73
+ * native enum type from the introspected schema IR. Targets supply
74
+ * this so the family-level schema verifier can walk
75
+ * `PostgresEnumStorageEntry` entries natively without needing to
76
+ * know the target-specific `schema.annotations` shape
77
+ * (e.g. `schema.annotations.pg.storageTypes`).
78
+ */
79
+ readonly resolveExistingEnumValues?: (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
80
+ /**
81
+ * Optional contract-scoped factory for {@link resolveExistingEnumValues}.
82
+ * Targets that need the contract storage to resolve namespace → DDL schema
83
+ * supply this; the family control instance prefers it over the bare adapter
84
+ * hook when present.
85
+ */
86
+ readonly resolveExistingEnumValuesForContract?: (contract: Contract<SqlStorage>) => (schema: SqlSchemaIR, enumType: PostgresEnumStorageEntry, namespaceId: string) => readonly string[] | null;
87
+ /**
88
+ * Lower a SQL query AST into a target-flavored `{ sql, params }` payload.
89
+ *
90
+ * Migration tooling (e.g. the `dataTransform` operation) needs to materialize
91
+ * SQL at emit/plan time without instantiating the runtime adapter. The control
92
+ * adapter's `lower` is byte-equivalent to the runtime adapter's `lower` for the
93
+ * same AST and contract, ensuring planned SQL matches what the runtime would
94
+ * emit.
95
+ */
96
+ lower(ast: AnyQueryAst, context: LowererContext<unknown>): LoweredStatement;
97
+ }
98
+ /**
99
+ * SQL control adapter descriptor interface.
100
+ * Provides a factory method to create control adapter instances.
101
+ *
102
+ * @template TTarget - The target ID (e.g., 'postgres', 'mysql')
103
+ */
104
+ interface SqlControlAdapterDescriptor<TTarget extends string = string> {
105
+ /**
106
+ * Creates a SQL control adapter instance for control-plane operations.
107
+ *
108
+ * Receives the assembled `ControlStack` so adapters can read aggregated
109
+ * metadata (codec lookup, extension contributions) when materializing.
110
+ */
111
+ create(stack: ControlStack<'sql', TTarget>): SqlControlAdapter<TTarget>;
112
+ }
113
+ //#endregion
114
+ export { SqlControlAdapterDescriptor as n, SqlControlAdapter as t };
115
+ //# sourceMappingURL=control-adapter-Br03xBEv.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"control-adapter-Br03xBEv.d.mts","names":[],"sources":["../src/core/control-adapter.ts"],"mappings":";;;;;;;;;;AAyBA;;;;UAAiB,iBAAA,0CACP,sBAAA,QAA8B,OAAA;EAiB5B;;;;;;;;;;;;;;;EADV,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,WACC,OAAA,CAAQ,oBAAA;EA8CiB;;;;;;;EArC5B,cAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,IACpC,OAAA,CAAQ,WAAA,SAAoB,oBAAA;EAgFpB;;;;;EAzEX,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,KAAA,WACC,OAAA,UAAiB,iBAAA;EAzCa;;;;;;;;;;;;EAuDjC,UAAA,CACE,MAAA,EAAQ,qBAAA,QAA6B,OAAA,GACrC,QAAA,YACA,MAAA,YACC,OAAA,CAAQ,WAAA;EA7BT;;;;;EAAA,SAoCO,gBAAA,GAAmB,iBAAA;EA3BW;;;;;EAAA,SAkC9B,mBAAA,GAAsB,oBAAA;EAjBrB;;;;;;;;EAAA,SA2BD,yBAAA,IACP,MAAA,EAAQ,WAAA,EACR,QAAA,EAAU,wBAAA,EACV,WAAA;EAbO;;;;;;EAAA,SAqBA,oCAAA,IACP,QAAA,EAAU,QAAA,CAAS,UAAA,OAEnB,MAAA,EAAQ,WAAA,EACR,QAAA,EAAU,wBAAA,EACV,WAAA;EAbA;;;;;;;;;EAyBF,KAAA,CAAM,GAAA,EAAK,WAAA,EAAa,OAAA,EAAS,cAAA,YAA0B,gBAAA;AAAA;;;;;;;UAS5C,2BAAA;EAAA;;;;;;EAOf,MAAA,CAAO,KAAA,EAAO,YAAA,QAAoB,OAAA,IAAW,iBAAA,CAAkB,OAAA;AAAA"}
@@ -1,109 +1,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
1
+ import { n as SqlControlAdapterDescriptor, t as SqlControlAdapter } from "./control-adapter-Br03xBEv.mjs";
2
+ export { type SqlControlAdapter, type SqlControlAdapterDescriptor };
@@ -1,4 +1,4 @@
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";
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-DbGXj_Si.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
4
  import { NotOk, Ok } from "@prisma-next/utils/result";
package/dist/control.mjs CHANGED
@@ -1057,9 +1057,6 @@ 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
- }
1063
1060
  function buildSqlTypeMetadataRegistry(options) {
1064
1061
  const { target, adapter, extensionPacks: extensions } = options;
1065
1062
  const registry = /* @__PURE__ */ new Map();
@@ -1103,11 +1100,7 @@ function createSqlFamilyInstance(stack) {
1103
1100
  adapter,
1104
1101
  extensionPacks: extensions
1105
1102
  });
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
- };
1103
+ const getControlAdapter = () => adapter.create(stack);
1111
1104
  const targetSerializer = target.contractSerializer;
1112
1105
  const deserializeWithTargetSerializer = (contractJson) => {
1113
1106
  return (targetSerializer ?? new SqlContractSerializer()).deserializeContract(contractJson);
@@ -1302,6 +1295,9 @@ function createSqlFamilyInstance(stack) {
1302
1295
  async readAllMarkers(options) {
1303
1296
  return getControlAdapter().readAllMarkers(options.driver);
1304
1297
  },
1298
+ async readLedger(options) {
1299
+ return getControlAdapter().readLedger(options.driver, options.space);
1300
+ },
1305
1301
  async introspect(options) {
1306
1302
  return getControlAdapter().introspect(options.driver, options.contract);
1307
1303
  },