@prisma-next/family-sql 0.5.0-dev.2 → 0.5.0-dev.21

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/package.json CHANGED
@@ -1,33 +1,32 @@
1
1
  {
2
2
  "name": "@prisma-next/family-sql",
3
- "version": "0.5.0-dev.2",
3
+ "version": "0.5.0-dev.21",
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/emitter": "0.5.0-dev.2",
10
- "@prisma-next/contract": "0.5.0-dev.2",
11
- "@prisma-next/operations": "0.5.0-dev.2",
12
- "@prisma-next/migration-tools": "0.5.0-dev.2",
13
- "@prisma-next/sql-contract": "0.5.0-dev.2",
14
- "@prisma-next/sql-contract-emitter": "0.5.0-dev.2",
15
- "@prisma-next/sql-contract-ts": "0.5.0-dev.2",
16
- "@prisma-next/runtime-executor": "0.5.0-dev.2",
17
- "@prisma-next/sql-operations": "0.5.0-dev.2",
18
- "@prisma-next/sql-relational-core": "0.5.0-dev.2",
19
- "@prisma-next/framework-components": "0.5.0-dev.2",
20
- "@prisma-next/sql-runtime": "0.5.0-dev.2",
21
- "@prisma-next/utils": "0.5.0-dev.2",
22
- "@prisma-next/sql-schema-ir": "0.5.0-dev.2"
9
+ "@prisma-next/contract": "0.5.0-dev.21",
10
+ "@prisma-next/emitter": "0.5.0-dev.21",
11
+ "@prisma-next/framework-components": "0.5.0-dev.21",
12
+ "@prisma-next/operations": "0.5.0-dev.21",
13
+ "@prisma-next/sql-contract": "0.5.0-dev.21",
14
+ "@prisma-next/migration-tools": "0.5.0-dev.21",
15
+ "@prisma-next/sql-contract-emitter": "0.5.0-dev.21",
16
+ "@prisma-next/sql-contract-ts": "0.5.0-dev.21",
17
+ "@prisma-next/sql-operations": "0.5.0-dev.21",
18
+ "@prisma-next/sql-relational-core": "0.5.0-dev.21",
19
+ "@prisma-next/sql-runtime": "0.5.0-dev.21",
20
+ "@prisma-next/utils": "0.5.0-dev.21",
21
+ "@prisma-next/sql-schema-ir": "0.5.0-dev.21"
23
22
  },
24
23
  "devDependencies": {
25
24
  "tsdown": "0.18.4",
26
25
  "typescript": "5.9.3",
27
26
  "vitest": "4.0.17",
28
- "@prisma-next/driver-postgres": "0.5.0-dev.2",
29
- "@prisma-next/psl-parser": "0.5.0-dev.2",
30
- "@prisma-next/sql-contract-psl": "0.5.0-dev.2",
27
+ "@prisma-next/driver-postgres": "0.5.0-dev.21",
28
+ "@prisma-next/sql-contract-psl": "0.5.0-dev.21",
29
+ "@prisma-next/psl-parser": "0.5.0-dev.21",
31
30
  "@prisma-next/test-utils": "0.0.1",
32
31
  "@prisma-next/tsconfig": "0.0.0",
33
32
  "@prisma-next/tsdown": "0.0.0"
@@ -1,3 +1,4 @@
1
+ import type { ContractMarkerRecord } from '@prisma-next/contract/types';
1
2
  import type {
2
3
  ControlAdapterInstance,
3
4
  ControlDriverInstance,
@@ -19,6 +20,17 @@ import type { DefaultNormalizer, NativeTypeNormalizer } from './schema-verify/ve
19
20
  */
20
21
  export interface SqlControlAdapter<TTarget extends string = string>
21
22
  extends ControlAdapterInstance<'sql', TTarget> {
23
+ /**
24
+ * Reads the contract marker from the database, returning `null` if the marker
25
+ * table or its row is missing. Implementations are responsible for the
26
+ * dialect-specific existence probe (e.g. Postgres `information_schema.tables`
27
+ * vs SQLite `sqlite_master`) and parameter placeholders.
28
+ *
29
+ * @param driver - ControlDriverInstance for executing queries (target-specific)
30
+ * @returns Resolved marker record, or `null` if not yet stamped.
31
+ */
32
+ readMarker(driver: ControlDriverInstance<'sql', TTarget>): Promise<ContractMarkerRecord | null>;
33
+
22
34
  /**
23
35
  * Introspects a database schema and returns a raw SqlSchemaIR.
24
36
  *
@@ -38,7 +38,7 @@ import type {
38
38
  SqlControlExtensionDescriptor,
39
39
  } from './migrations/types';
40
40
  import { verifySqlSchema } from './schema-verify/verify-sql-schema';
41
- import { collectSupportedCodecTypeIds, readMarker } from './verify';
41
+ import { collectSupportedCodecTypeIds } from './verify';
42
42
 
43
43
  function extractCodecTypeIdsFromContract(contract: unknown): readonly string[] {
44
44
  const typeIds = new Set<string>();
@@ -217,7 +217,9 @@ function isSqlControlAdapter<TTargetId extends string>(
217
217
  typeof value === 'object' &&
218
218
  value !== null &&
219
219
  'introspect' in value &&
220
- typeof (value as { introspect: unknown }).introspect === 'function'
220
+ typeof (value as { introspect: unknown }).introspect === 'function' &&
221
+ 'readMarker' in value &&
222
+ typeof (value as { readMarker: unknown }).readMarker === 'function'
221
223
  );
222
224
  }
223
225
 
@@ -293,6 +295,20 @@ export function createSqlFamilyInstance<TTargetId extends string>(
293
295
  extensionPacks: extensions,
294
296
  });
295
297
 
298
+ // Family-instance methods accept `ControlDriverInstance<'sql', string>` —
299
+ // the family API isn't generic on the target id. Letting `isSqlControlAdapter`
300
+ // default its type parameter narrows the adapter to `SqlControlAdapter<string>`,
301
+ // which matches the family-level driver type without any cast at call sites.
302
+ const getControlAdapter = () => {
303
+ const controlAdapter = adapter.create(stack);
304
+ if (!isSqlControlAdapter(controlAdapter)) {
305
+ throw new Error(
306
+ 'Adapter does not implement SqlControlAdapter (missing introspect or readMarker)',
307
+ );
308
+ }
309
+ return controlAdapter;
310
+ };
311
+
296
312
  return {
297
313
  familyId: 'sql',
298
314
  codecTypeImports,
@@ -326,7 +342,7 @@ export function createSqlFamilyInstance<TTargetId extends string>(
326
342
  const contractProfileHash = contract.profileHash;
327
343
  const contractTarget = contract.target;
328
344
 
329
- const marker = await readMarker(driver);
345
+ const marker = await getControlAdapter().readMarker(driver);
330
346
 
331
347
  let missingCodecs: readonly string[] | undefined;
332
348
  let codecCoverageSkipped = false;
@@ -435,10 +451,7 @@ export function createSqlFamilyInstance<TTargetId extends string>(
435
451
 
436
452
  const contract = sqlValidateContract<Contract<SqlStorage>>(contractInput, emptyCodecLookup);
437
453
 
438
- const controlAdapter = adapter.create(stack);
439
- if (!isSqlControlAdapter(controlAdapter)) {
440
- throw new Error('Adapter does not implement SqlControlAdapter.introspect()');
441
- }
454
+ const controlAdapter = getControlAdapter();
442
455
  const schemaIR = await controlAdapter.introspect(driver, contractInput);
443
456
 
444
457
  return verifySqlSchema({
@@ -474,7 +487,7 @@ export function createSqlFamilyInstance<TTargetId extends string>(
474
487
  await driver.query(ensureSchemaStatement.sql, ensureSchemaStatement.params);
475
488
  await driver.query(ensureTableStatement.sql, ensureTableStatement.params);
476
489
 
477
- const existingMarker = await readMarker(driver);
490
+ const existingMarker = await getControlAdapter().readMarker(driver);
478
491
 
479
492
  let markerCreated = false;
480
493
  let markerUpdated = false;
@@ -551,19 +564,13 @@ export function createSqlFamilyInstance<TTargetId extends string>(
551
564
  async readMarker(options: {
552
565
  readonly driver: ControlDriverInstance<'sql', string>;
553
566
  }): Promise<ContractMarkerRecord | null> {
554
- return readMarker(options.driver);
567
+ return getControlAdapter().readMarker(options.driver);
555
568
  },
556
569
  async introspect(options: {
557
570
  readonly driver: ControlDriverInstance<'sql', string>;
558
571
  readonly contract?: unknown;
559
572
  }): Promise<SqlSchemaIR> {
560
- const { driver, contract } = options;
561
-
562
- const controlAdapter = adapter.create(stack);
563
- if (!isSqlControlAdapter(controlAdapter)) {
564
- throw new Error('Adapter does not implement SqlControlAdapter.introspect()');
565
- }
566
- return controlAdapter.introspect(driver, contract);
573
+ return getControlAdapter().introspect(options.driver, options.contract);
567
574
  },
568
575
 
569
576
  toSchemaView(schema: SqlSchemaIR): CoreSchemaView {
@@ -296,6 +296,12 @@ export interface SqlMigrationRunnerExecuteOptions<TTargetDetails> {
296
296
  * All components must have matching familyId ('sql') and targetId.
297
297
  */
298
298
  readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
299
+ /**
300
+ * Invariant ids contributed by this apply (the migration's `providedInvariants`).
301
+ * The runner unions these into `marker.invariants` atomically with the marker write.
302
+ * Defaults to `[]` for marker-only flows (`db update`, `db init`).
303
+ */
304
+ readonly invariants?: readonly string[];
299
305
  }
300
306
 
301
307
  export type SqlMigrationRunnerErrorCode =
@@ -305,6 +311,7 @@ export type SqlMigrationRunnerErrorCode =
305
311
  | 'PRECHECK_FAILED'
306
312
  | 'POSTCHECK_FAILED'
307
313
  | 'SCHEMA_VERIFY_FAILED'
314
+ | 'FOREIGN_KEY_VIOLATION'
308
315
  | 'EXECUTION_FAILED';
309
316
 
310
317
  export interface SqlMigrationRunnerFailure extends MigrationRunnerFailure {
@@ -1,5 +1,4 @@
1
1
  import type { ContractMarkerRecord } from '@prisma-next/contract/types';
2
- import type { ControlDriverInstance } from '@prisma-next/framework-components/control';
3
2
  import { type } from 'arktype';
4
3
 
5
4
  const MetaSchema = type({ '[string]': 'unknown' });
@@ -28,6 +27,40 @@ function parseMeta(meta: unknown): Record<string, unknown> {
28
27
  return result as Record<string, unknown>;
29
28
  }
30
29
 
30
+ /**
31
+ * SQLite stores `contract_json` as TEXT, so the wire shape is a JSON string;
32
+ * Postgres uses `jsonb` and returns an already-parsed value. Normalize both
33
+ * here so `ContractMarkerRecord.contractJson` is always the structured form.
34
+ */
35
+ function parseContractJson(value: unknown): unknown {
36
+ if (value === null || value === undefined) return null;
37
+ if (typeof value !== 'string') return value;
38
+ try {
39
+ return JSON.parse(value);
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Wire shape of a `prisma_contract.marker` row as it comes out of a SQL
47
+ * driver. Snake-cased to match the on-disk column names. Shared by every
48
+ * SQL target's `readMarker` so each runner doesn't redeclare it inline.
49
+ */
50
+ export type ContractMarkerRow = {
51
+ core_hash: string;
52
+ profile_hash: string;
53
+ contract_json: unknown | null;
54
+ canonical_version: number | null;
55
+ updated_at: Date | string;
56
+ app_tag: string | null;
57
+ meta: unknown | null;
58
+ // SQLite stores arrays as JSON-TEXT, so this is `string` on the wire from
59
+ // a SQLite driver and `string[]` from a Postgres driver. Targets normalize
60
+ // before passing to `parseContractMarkerRow`.
61
+ invariants: unknown;
62
+ };
63
+
31
64
  const ContractMarkerRowSchema = type({
32
65
  core_hash: 'string',
33
66
  profile_hash: 'string',
@@ -36,6 +69,7 @@ const ContractMarkerRowSchema = type({
36
69
  'updated_at?': 'Date | string',
37
70
  'app_tag?': 'string | null',
38
71
  'meta?': 'unknown | null',
72
+ invariants: type('string').array(),
39
73
  });
40
74
 
41
75
  /**
@@ -49,120 +83,24 @@ export function parseContractMarkerRow(row: unknown): ContractMarkerRecord {
49
83
  throw new Error(`Invalid contract marker row: ${messages}`);
50
84
  }
51
85
 
52
- const validatedRow = result as {
53
- core_hash: string;
54
- profile_hash: string;
55
- contract_json?: unknown | null;
56
- canonical_version?: number | null;
57
- updated_at?: Date | string;
58
- app_tag?: string | null;
59
- meta?: unknown | null;
60
- };
61
-
62
- const updatedAt = validatedRow.updated_at
63
- ? validatedRow.updated_at instanceof Date
64
- ? validatedRow.updated_at
65
- : new Date(validatedRow.updated_at)
86
+ const updatedAt = result.updated_at
87
+ ? result.updated_at instanceof Date
88
+ ? result.updated_at
89
+ : new Date(result.updated_at)
66
90
  : new Date();
67
91
 
68
92
  return {
69
- storageHash: validatedRow.core_hash,
70
- profileHash: validatedRow.profile_hash,
71
- contractJson: validatedRow.contract_json ?? null,
72
- canonicalVersion: validatedRow.canonical_version ?? null,
93
+ storageHash: result.core_hash,
94
+ profileHash: result.profile_hash,
95
+ contractJson: parseContractJson(result.contract_json),
96
+ canonicalVersion: result.canonical_version ?? null,
73
97
  updatedAt,
74
- appTag: validatedRow.app_tag ?? null,
75
- meta: parseMeta(validatedRow.meta),
98
+ appTag: result.app_tag ?? null,
99
+ meta: parseMeta(result.meta),
100
+ invariants: result.invariants,
76
101
  };
77
102
  }
78
103
 
79
- /**
80
- * Returns the SQL statement to read the contract marker.
81
- * This is a migration-plane helper (no runtime imports).
82
- * @internal - Used internally by readMarker(). Prefer readMarker() for Control Plane usage.
83
- */
84
- export function readMarkerSql(): { readonly sql: string; readonly params: readonly unknown[] } {
85
- return {
86
- sql: `select
87
- core_hash,
88
- profile_hash,
89
- contract_json,
90
- canonical_version,
91
- updated_at,
92
- app_tag,
93
- meta
94
- from prisma_contract.marker
95
- where id = $1`,
96
- params: [1],
97
- };
98
- }
99
-
100
- /**
101
- * Returns the SQL statement that probes for the existence of the marker table.
102
- * Uses the SQL-standard `information_schema.tables` view so the query succeeds
103
- * (returning zero rows) when the table has not been created yet — avoiding a
104
- * `relation does not exist` error. Some Postgres wire-protocol implementations
105
- * (e.g. PGlite's TCP proxy) do not fully recover from an extended-protocol
106
- * parse error, so we probe first instead of relying on an error signal.
107
- * @internal - Used internally by readMarker().
108
- */
109
- export function markerTableExistsSql(): {
110
- readonly sql: string;
111
- readonly params: readonly unknown[];
112
- } {
113
- return {
114
- sql: `select 1
115
- from information_schema.tables
116
- where table_schema = $1 and table_name = $2`,
117
- params: ['prisma_contract', 'marker'],
118
- };
119
- }
120
-
121
- /**
122
- * Reads the contract marker from the database using the provided driver.
123
- * Returns the parsed marker record or null if no marker is found.
124
- * This abstracts SQL-specific details from the Control Plane.
125
- *
126
- * @param driver - ControlDriverInstance instance for executing queries
127
- * @returns Promise resolving to ContractMarkerRecord or null if marker not found
128
- */
129
- export async function readMarker(
130
- driver: ControlDriverInstance<'sql', string>,
131
- ): Promise<ContractMarkerRecord | null> {
132
- // Probe for the marker table first so that a fresh database (no
133
- // `prisma_contract` schema) returns null cleanly instead of surfacing a
134
- // `relation does not exist` error. This keeps the control connection in a
135
- // predictable state for driver implementations that are sensitive to
136
- // extended-protocol parse errors.
137
- const existsStatement = markerTableExistsSql();
138
- const existsResult = await driver.query(existsStatement.sql, existsStatement.params);
139
- if (existsResult.rows.length === 0) {
140
- return null;
141
- }
142
-
143
- const markerStatement = readMarkerSql();
144
- const queryResult = await driver.query<{
145
- core_hash: string;
146
- profile_hash: string;
147
- contract_json: unknown | null;
148
- canonical_version: number | null;
149
- updated_at: Date | string;
150
- app_tag: string | null;
151
- meta: unknown | null;
152
- }>(markerStatement.sql, markerStatement.params);
153
-
154
- if (queryResult.rows.length === 0) {
155
- return null;
156
- }
157
-
158
- const markerRow = queryResult.rows[0];
159
- if (!markerRow) {
160
- throw new Error('Database query returned unexpected result structure');
161
- }
162
-
163
- return parseContractMarkerRow(markerRow);
164
- }
165
-
166
104
  /**
167
105
  * Collects supported codec type IDs from adapter and extension manifests.
168
106
  * Returns a sorted, unique array of type IDs that are declared in the manifests.
@@ -1 +1 @@
1
- export { parseContractMarkerRow, readMarker, readMarkerSql } from '../core/verify';
1
+ export { type ContractMarkerRow, parseContractMarkerRow } from '../core/verify';
@@ -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,SAClB,KAAI;AACF,WAAS,KAAK,MAAM,KAAK;SACnB;AACN,SAAO,EAAE;;KAGX,UAAS;CAGX,MAAM,SAAS,WAAW,OAAO;AACjC,KAAI,kBAAkB,KAAK,OACzB,QAAO,EAAE;AAGX,QAAO;;AAGT,MAAM,0BAA0B,KAAK;CACnC,WAAW;CACX,cAAc;CACd,kBAAkB;CAClB,sBAAsB;CACtB,eAAe;CACf,YAAY;CACZ,SAAS;CACV,CAAC;;;;;AAMF,SAAgB,uBAAuB,KAAoC;CACzE,MAAM,SAAS,wBAAwB,IAAI;AAC3C,KAAI,kBAAkB,KAAK,QAAQ;EACjC,MAAM,WAAW,OAAO,KAAK,MAA2B,EAAE,QAAQ,CAAC,KAAK,KAAK;AAC7E,QAAM,IAAI,MAAM,gCAAgC,WAAW;;CAG7D,MAAM,eAAe;CAUrB,MAAM,YAAY,aAAa,aAC3B,aAAa,sBAAsB,OACjC,aAAa,aACb,IAAI,KAAK,aAAa,WAAW,mBACnC,IAAI,MAAM;AAEd,QAAO;EACL,aAAa,aAAa;EAC1B,aAAa,aAAa;EAC1B,cAAc,aAAa,iBAAiB;EAC5C,kBAAkB,aAAa,qBAAqB;EACpD;EACA,QAAQ,aAAa,WAAW;EAChC,MAAM,UAAU,aAAa,KAAK;EACnC;;;;;;;AAQH,SAAgB,gBAA+E;AAC7F,QAAO;EACL,KAAK;;;;;;;;;;EAUL,QAAQ,CAAC,EAAE;EACZ;;;;;;;;;;;AAYH,SAAgB,uBAGd;AACA,QAAO;EACL,KAAK;;;EAGL,QAAQ,CAAC,mBAAmB,SAAS;EACtC;;;;;;;;;;AAWH,eAAsB,WACpB,QACsC;CAMtC,MAAM,kBAAkB,sBAAsB;AAE9C,MADqB,MAAM,OAAO,MAAM,gBAAgB,KAAK,gBAAgB,OAAO,EACnE,KAAK,WAAW,EAC/B,QAAO;CAGT,MAAM,kBAAkB,eAAe;CACvC,MAAM,cAAc,MAAM,OAAO,MAQ9B,gBAAgB,KAAK,gBAAgB,OAAO;AAE/C,KAAI,YAAY,KAAK,WAAW,EAC9B,QAAO;CAGT,MAAM,YAAY,YAAY,KAAK;AACnC,KAAI,CAAC,UACH,OAAM,IAAI,MAAM,sDAAsD;AAGxE,QAAO,uBAAuB,UAAU;;;;;;;;;;;;;;AAe1C,SAAgB,6BACd,aACmB;AAKnB,QAAO,EAAE"}