@prisma-next/family-sql 0.5.0-dev.5 → 0.5.0-dev.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/control-adapter.d.mts +12 -1
- package/dist/control-adapter.d.mts.map +1 -1
- package/dist/control.d.mts +4 -3
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +1027 -11
- package/dist/control.mjs.map +1 -1
- package/dist/migration.d.mts +22 -23
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +24 -22
- package/dist/migration.mjs.map +1 -1
- package/dist/schema-verify.d.mts +2 -2
- package/dist/{types-C6K4mxDM.d.mts → types-UI3K69S6.d.mts} +46 -22
- package/dist/types-UI3K69S6.d.mts.map +1 -0
- package/dist/verify-BdES8wgQ.mjs +82 -0
- package/dist/verify-BdES8wgQ.mjs.map +1 -0
- package/dist/verify-sql-schema-Ovz7RXR5.mjs.map +1 -1
- package/dist/{verify-sql-schema-BBhkqEDo.d.mts → verify-sql-schema-_EoNcGIq.d.mts} +2 -2
- package/dist/{verify-sql-schema-BBhkqEDo.d.mts.map → verify-sql-schema-_EoNcGIq.d.mts.map} +1 -1
- package/dist/verify.d.mts +16 -20
- package/dist/verify.d.mts.map +1 -1
- package/dist/verify.mjs +2 -2
- package/package.json +19 -19
- package/src/core/control-adapter.ts +12 -0
- package/src/core/control-instance.ts +43 -15
- package/src/core/migrations/plan-helpers.ts +3 -0
- package/src/core/migrations/types.ts +38 -20
- package/src/core/operation-preview.ts +62 -0
- package/src/core/psl-contract-infer/default-mapping.ts +56 -0
- package/src/core/psl-contract-infer/name-transforms.ts +178 -0
- package/src/core/psl-contract-infer/postgres-default-mapping.ts +16 -0
- package/src/core/psl-contract-infer/postgres-type-map.ts +165 -0
- package/src/core/psl-contract-infer/printer-config.ts +55 -0
- package/src/core/psl-contract-infer/raw-default-parser.ts +91 -0
- package/src/core/psl-contract-infer/relation-inference.ts +196 -0
- package/src/core/psl-contract-infer/sql-schema-ir-to-psl-ast.ts +832 -0
- package/src/core/sql-migration.ts +25 -23
- package/src/core/verify.ts +46 -108
- package/src/exports/control.ts +0 -1
- package/src/exports/verify.ts +1 -1
- package/dist/types-C6K4mxDM.d.mts.map +0 -1
- package/dist/verify-4GshvY4p.mjs +0 -122
- package/dist/verify-4GshvY4p.mjs.map +0 -1
package/dist/migration.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration.mjs","names":[],"sources":["../src/core/sql-migration.ts"],"sourcesContent":["import { Migration } from '@prisma-next/migration-tools/migration';\nimport type {
|
|
1
|
+
{"version":3,"file":"migration.mjs","names":[],"sources":["../src/core/sql-migration.ts"],"sourcesContent":["import { deriveProvidedInvariants } from '@prisma-next/migration-tools/invariants';\nimport { Migration } from '@prisma-next/migration-tools/migration';\nimport type { SqlMigrationPlanOperation, SqlPlanTargetDetails } from './migrations/types';\n\n/**\n * Family-owned base class for SQL migrations.\n *\n * Generic in `TDetails` (family plan target details, e.g. Postgres vs SQLite)\n * and in `TTargetId` (the literal target identifier, e.g. `'postgres'`).\n *\n * Adapters (Postgres, SQLite, …) extend this with a concrete `TDetails` and\n * a fixed `TTargetId` literal, so the public `Migration<TOp>` base sees the\n * fully concrete operation shape. Target-free code in SQL family / tooling\n * parameterises over `TDetails` (and usually `TTargetId = string`).\n *\n * Keeps target-free contract/runtime features in the family layer while\n * letting adapters own target shape.\n */\nexport abstract class SqlMigration<\n TDetails extends SqlPlanTargetDetails,\n TTargetId extends string = string,\n> extends Migration<SqlMigrationPlanOperation<TDetails>, 'sql', TTargetId> {\n /**\n * Sorted, deduplicated invariant ids declared by this migration's\n * data-transform ops. Derived from `this.operations` so the field remains\n * consistent with the operation list — planner-built plans (`db init`,\n * `db update`) yield `[]` because they emit no data-transform ops.\n *\n * Required by `SqlMigrationPlan.providedInvariants` (tightened from\n * optional at the SQL-family layer); the framework-level\n * `MigrationPlan.providedInvariants?` stays optional.\n */\n get providedInvariants(): readonly string[] {\n return deriveProvidedInvariants(this.operations);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,IAAsB,eAAtB,cAGU,UAAiE;;;;;;;;;;;CAWzE,IAAI,qBAAwC;AAC1C,SAAO,yBAAyB,KAAK,WAAW"}
|
package/dist/schema-verify.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as verifySqlSchema, n as NativeTypeNormalizer, r as VerifySqlSchemaOptions } from "./verify-sql-schema-
|
|
2
|
-
import {
|
|
1
|
+
import { i as verifySqlSchema, n as NativeTypeNormalizer, r as VerifySqlSchemaOptions } from "./verify-sql-schema-_EoNcGIq.mjs";
|
|
2
|
+
import { i as ComponentDatabaseDependency } from "./types-UI3K69S6.mjs";
|
|
3
3
|
import { SchemaIssue, SchemaVerificationNode } from "@prisma-next/framework-components/control";
|
|
4
4
|
import { SqlIndexIR, SqlSchemaIR, SqlUniqueIR } from "@prisma-next/sql-schema-ir/types";
|
|
5
5
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ControlAdapterDescriptor, ControlDriverInstance, ControlExtensionDescriptor, ControlFamilyInstance, ControlStack,
|
|
1
|
+
import { ControlAdapterDescriptor, ControlDriverInstance, ControlExtensionDescriptor, ControlFamilyInstance, ControlStack, MigratableTargetDescriptor, MigrationOperationPolicy, MigrationPlan, MigrationPlanOperation, MigrationPlannerConflict, MigrationPlannerFailureResult, MigrationPlannerSuccessResult, MigrationRunnerExecutionChecks, MigrationRunnerFailure, MigrationRunnerSuccessValue, OperationContext, OperationPreview, OperationPreviewCapable, PslContractInferCapable, SchemaIssue, SchemaViewCapable, SignDatabaseResult, VerifyDatabaseResult, VerifyDatabaseSchemaResult } from "@prisma-next/framework-components/control";
|
|
2
2
|
import { Result } from "@prisma-next/utils/result";
|
|
3
|
-
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
4
3
|
import { Contract } from "@prisma-next/contract/types";
|
|
4
|
+
import { SqlSchemaIR } from "@prisma-next/sql-schema-ir/types";
|
|
5
5
|
import { TargetBoundComponentDescriptor } from "@prisma-next/framework-components/components";
|
|
6
6
|
import { SqlStorage, StorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
7
7
|
import { TypesImportSpec } from "@prisma-next/framework-components/emission";
|
|
8
|
+
import { PslDocumentAst } from "@prisma-next/framework-components/psl-ast";
|
|
8
9
|
import { SqlOperationDescriptor } from "@prisma-next/sql-operations";
|
|
9
10
|
|
|
10
11
|
//#region src/core/control-instance.d.ts
|
|
@@ -32,7 +33,7 @@ interface SchemaVerifyOptions {
|
|
|
32
33
|
*/
|
|
33
34
|
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
34
35
|
}
|
|
35
|
-
interface SqlControlFamilyInstance extends ControlFamilyInstance<'sql', SqlSchemaIR>, SchemaViewCapable<SqlSchemaIR>, SqlFamilyInstanceState {
|
|
36
|
+
interface SqlControlFamilyInstance extends ControlFamilyInstance<'sql', SqlSchemaIR>, SchemaViewCapable<SqlSchemaIR>, PslContractInferCapable<SqlSchemaIR>, OperationPreviewCapable, SqlFamilyInstanceState {
|
|
36
37
|
validateContract(contractJson: unknown): Contract;
|
|
37
38
|
verify(options: {
|
|
38
39
|
readonly driver: ControlDriverInstance<'sql', string>;
|
|
@@ -52,6 +53,8 @@ interface SqlControlFamilyInstance extends ControlFamilyInstance<'sql', SqlSchem
|
|
|
52
53
|
readonly driver: ControlDriverInstance<'sql', string>;
|
|
53
54
|
readonly contract?: unknown;
|
|
54
55
|
}): Promise<SqlSchemaIR>;
|
|
56
|
+
inferPslContract(schemaIR: SqlSchemaIR): PslDocumentAst;
|
|
57
|
+
toOperationPreview(operations: readonly MigrationPlanOperation[]): OperationPreview;
|
|
55
58
|
}
|
|
56
59
|
//#endregion
|
|
57
60
|
//#region src/core/migrations/types.d.ts
|
|
@@ -143,6 +146,15 @@ interface SqlControlAdapterDescriptor<TTargetId extends string> extends ControlA
|
|
|
143
146
|
interface SqlMigrationPlanOperationStep {
|
|
144
147
|
readonly description: string;
|
|
145
148
|
readonly sql: string;
|
|
149
|
+
/**
|
|
150
|
+
* Optional parameter values bound at execution time. The runner forwards
|
|
151
|
+
* these to `driver.query(sql, params ?? [])`, so step authors can use
|
|
152
|
+
* placeholder syntax (`$1`, `$2`, …) instead of inlining literals into
|
|
153
|
+
* the SQL string. Reuses the driver's parameter binder rather than
|
|
154
|
+
* rolling per-target literal serialization for every type the planner
|
|
155
|
+
* may emit.
|
|
156
|
+
*/
|
|
157
|
+
readonly params?: readonly unknown[];
|
|
146
158
|
readonly meta?: AnyRecord;
|
|
147
159
|
}
|
|
148
160
|
/**
|
|
@@ -168,16 +180,6 @@ interface SqlMigrationPlanOperation<TTargetDetails> extends MigrationPlanOperati
|
|
|
168
180
|
readonly postcheck: readonly SqlMigrationPlanOperationStep[];
|
|
169
181
|
readonly meta?: AnyRecord;
|
|
170
182
|
}
|
|
171
|
-
/**
|
|
172
|
-
* Union of all operation shapes a SQL-family migration may emit: schema-facing
|
|
173
|
-
* `SqlMigrationPlanOperation`s and family-agnostic `DataTransformOperation`s.
|
|
174
|
-
*
|
|
175
|
-
* Mirrors `AnyMongoMigrationOperation` in shape — the runner already handles
|
|
176
|
-
* both branches via `isDataTransformOperation`, and authored `migration.ts`
|
|
177
|
-
* files must be able to intermix `dataTransform(endContract, …)` calls with
|
|
178
|
-
* DDL factory calls (e.g. `setNotNull(…)`) in a single `operations` array.
|
|
179
|
-
*/
|
|
180
|
-
type AnySqlMigrationOperation<TTargetDetails> = SqlMigrationPlanOperation<TTargetDetails> | DataTransformOperation;
|
|
181
183
|
interface SqlMigrationPlanContractInfo {
|
|
182
184
|
readonly storageHash: string;
|
|
183
185
|
readonly profileHash?: string;
|
|
@@ -193,6 +195,15 @@ interface SqlMigrationPlan<TTargetDetails> extends MigrationPlan {
|
|
|
193
195
|
*/
|
|
194
196
|
readonly destination: SqlMigrationPlanContractInfo;
|
|
195
197
|
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
198
|
+
/**
|
|
199
|
+
* Sorted, deduplicated invariant ids declared by this plan's data-transform
|
|
200
|
+
* ops. Required at the SQL-family layer (the SQL runners consume this as
|
|
201
|
+
* the source of truth for marker writes and self-edge no-op checks); the
|
|
202
|
+
* framework-level {@link MigrationPlan.providedInvariants} stays optional
|
|
203
|
+
* because `db init` / `db update` plans don't have a corresponding
|
|
204
|
+
* migration manifest.
|
|
205
|
+
*/
|
|
206
|
+
readonly providedInvariants: readonly string[];
|
|
196
207
|
readonly meta?: AnyRecord;
|
|
197
208
|
}
|
|
198
209
|
type SqlPlannerConflictKind = 'typeMismatch' | 'nullabilityConflict' | 'indexIncompatible' | 'foreignKeyConflict' | 'missingButNonAdditive' | 'unsupportedOperation';
|
|
@@ -223,14 +234,21 @@ interface SqlMigrationPlannerPlanOptions {
|
|
|
223
234
|
readonly policy: MigrationOperationPolicy;
|
|
224
235
|
readonly schemaName?: string;
|
|
225
236
|
/**
|
|
226
|
-
* The "from" contract (state the planner assumes the database starts at)
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
237
|
+
* The "from" contract (state the planner assumes the database starts at),
|
|
238
|
+
* or `null` for reconciliation flows that have no prior contract.
|
|
239
|
+
*
|
|
240
|
+
* Required at every call site so the structural fact "I have a prior
|
|
241
|
+
* contract / I don't" is visible in the type. `migration plan` supplies
|
|
242
|
+
* the previous bundle's `metadata.toContract`; `db update` / `db init`
|
|
243
|
+
* reconcile against the live schema and pass `null`. Strategies that
|
|
244
|
+
* need from/to column-shape comparisons (unsafe type change, nullability
|
|
230
245
|
* tightening) use this to decide whether to emit `dataTransform`
|
|
231
|
-
* placeholders
|
|
246
|
+
* placeholders; they short-circuit when it is `null`.
|
|
247
|
+
*
|
|
248
|
+
* Planners also derive the "from" identity they stamp onto the produced
|
|
249
|
+
* plan's `describe()` as `fromContract?.storage.storageHash ?? null`.
|
|
232
250
|
*/
|
|
233
|
-
readonly fromContract
|
|
251
|
+
readonly fromContract: Contract<SqlStorage> | null;
|
|
234
252
|
/**
|
|
235
253
|
* Active framework components participating in this composition.
|
|
236
254
|
* SQL targets can interpret this list to derive database dependencies.
|
|
@@ -274,7 +292,7 @@ interface SqlMigrationRunnerExecuteOptions<TTargetDetails> {
|
|
|
274
292
|
*/
|
|
275
293
|
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<'sql', string>>;
|
|
276
294
|
}
|
|
277
|
-
type SqlMigrationRunnerErrorCode = 'DESTINATION_CONTRACT_MISMATCH' | 'MARKER_ORIGIN_MISMATCH' | 'POLICY_VIOLATION' | 'PRECHECK_FAILED' | 'POSTCHECK_FAILED' | 'SCHEMA_VERIFY_FAILED' | 'EXECUTION_FAILED';
|
|
295
|
+
type SqlMigrationRunnerErrorCode = 'DESTINATION_CONTRACT_MISMATCH' | 'MARKER_ORIGIN_MISMATCH' | 'POLICY_VIOLATION' | 'PRECHECK_FAILED' | 'POSTCHECK_FAILED' | 'SCHEMA_VERIFY_FAILED' | 'FOREIGN_KEY_VIOLATION' | 'EXECUTION_FAILED';
|
|
278
296
|
interface SqlMigrationRunnerFailure extends MigrationRunnerFailure {
|
|
279
297
|
readonly code: SqlMigrationRunnerErrorCode;
|
|
280
298
|
readonly meta?: AnyRecord;
|
|
@@ -294,8 +312,14 @@ interface CreateSqlMigrationPlanOptions<TTargetDetails> {
|
|
|
294
312
|
readonly origin?: SqlMigrationPlanContractInfo | null;
|
|
295
313
|
readonly destination: SqlMigrationPlanContractInfo;
|
|
296
314
|
readonly operations: readonly SqlMigrationPlanOperation<TTargetDetails>[];
|
|
315
|
+
/**
|
|
316
|
+
* Sorted, deduplicated invariant ids for this plan; mirrors the required
|
|
317
|
+
* field on {@link SqlMigrationPlan}. Callers without a migration manifest
|
|
318
|
+
* (`db init`, `db update`, planner-built plans) pass `[]`.
|
|
319
|
+
*/
|
|
320
|
+
readonly providedInvariants: readonly string[];
|
|
297
321
|
readonly meta?: AnyRecord;
|
|
298
322
|
}
|
|
299
323
|
//#endregion
|
|
300
|
-
export {
|
|
301
|
-
//# sourceMappingURL=types-
|
|
324
|
+
export { SqlPlannerResult as A, SqlMigrationRunnerResult as C, SqlPlannerConflictKind as D, SqlPlannerConflict as E, SchemaVerifyOptions as F, SqlControlFamilyInstance as I, StorageTypePlanResult as M, collectInitDependencies as N, SqlPlannerConflictLocation as O, isDatabaseDependencyProvider as P, SqlMigrationRunnerFailure as S, SqlPlanTargetDetails as T, SqlMigrationPlannerPlanOptions as _, CreateSqlMigrationPlanOptions as a, SqlMigrationRunnerExecuteCallbacks as b, SqlControlAdapterDescriptor as c, SqlMigrationPlan as d, SqlMigrationPlanContractInfo as f, SqlMigrationPlanner as g, SqlMigrationPlanOperationTarget as h, ComponentDatabaseDependency as i, SqlPlannerSuccessResult as j, SqlPlannerFailureResult as k, SqlControlExtensionDescriptor as l, SqlMigrationPlanOperationStep as m, CodecControlHooks as n, ExpandNativeTypeInput as o, SqlMigrationPlanOperation as p, ComponentDatabaseDependencies as r, ResolveIdentityValueInput as s, AnyRecord as t, SqlControlTargetDescriptor as u, SqlMigrationRunner as v, SqlMigrationRunnerSuccessValue as w, SqlMigrationRunnerExecuteOptions as x, SqlMigrationRunnerErrorCode as y };
|
|
325
|
+
//# sourceMappingURL=types-UI3K69S6.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-UI3K69S6.d.mts","names":[],"sources":["../src/core/control-instance.ts","../src/core/migrations/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;UAgKU,eAAA;;;;;AA3HsE;AA2HvD,KAOpB,uBAAA,GAA0B,GAAH,CAAA,MAAA,EAAe,eAAA,CAAZ;AAAG,UAExB,sBAAA,CAAsB;EACW,SAAA,gBAAA,EAAd,aAAc,CAAA,eAAA,CAAA;EAAd,SAAA,oBAAA,EACI,aADJ,CACkB,eADlB,CAAA;EACkB,SAAA,YAAA,EACtB,aADsB,CAAA,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(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
|
+
/**
|
|
19
|
+
* SQLite stores `contract_json` as TEXT, so the wire shape is a JSON string;
|
|
20
|
+
* Postgres uses `jsonb` and returns an already-parsed value. Normalize both
|
|
21
|
+
* here so `ContractMarkerRecord.contractJson` is always the structured form.
|
|
22
|
+
*/
|
|
23
|
+
function parseContractJson(value) {
|
|
24
|
+
if (value === null || value === void 0) return null;
|
|
25
|
+
if (typeof value !== "string") return value;
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(value);
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const ContractMarkerRowSchema = type({
|
|
33
|
+
core_hash: "string",
|
|
34
|
+
profile_hash: "string",
|
|
35
|
+
"contract_json?": "unknown | null",
|
|
36
|
+
"canonical_version?": "number | null",
|
|
37
|
+
"updated_at?": "Date | string",
|
|
38
|
+
"app_tag?": "string | null",
|
|
39
|
+
"meta?": "unknown | null",
|
|
40
|
+
invariants: type("string").array()
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Parses a contract marker row from database query result.
|
|
44
|
+
* This is SQL-specific parsing logic (handles SQL row structure with snake_case columns).
|
|
45
|
+
*/
|
|
46
|
+
function parseContractMarkerRow(row) {
|
|
47
|
+
const result = ContractMarkerRowSchema(row);
|
|
48
|
+
if (result instanceof type.errors) {
|
|
49
|
+
const messages = result.map((p) => p.message).join("; ");
|
|
50
|
+
throw new Error(`Invalid contract marker row: ${messages}`);
|
|
51
|
+
}
|
|
52
|
+
const updatedAt = result.updated_at ? result.updated_at instanceof Date ? result.updated_at : new Date(result.updated_at) : /* @__PURE__ */ new Date();
|
|
53
|
+
return {
|
|
54
|
+
storageHash: result.core_hash,
|
|
55
|
+
profileHash: result.profile_hash,
|
|
56
|
+
contractJson: parseContractJson(result.contract_json),
|
|
57
|
+
canonicalVersion: result.canonical_version ?? null,
|
|
58
|
+
updatedAt,
|
|
59
|
+
appTag: result.app_tag ?? null,
|
|
60
|
+
meta: parseMeta(result.meta),
|
|
61
|
+
invariants: result.invariants
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Collects supported codec type IDs from adapter and extension manifests.
|
|
66
|
+
* Returns a sorted, unique array of type IDs that are declared in the manifests.
|
|
67
|
+
* This enables coverage checks by comparing contract column types against supported types.
|
|
68
|
+
*
|
|
69
|
+
* Note: This extracts type IDs from manifest type imports, not from runtime codec registries.
|
|
70
|
+
* The manifests declare which codec types are available, but the actual type IDs
|
|
71
|
+
* are defined in the codec-types TypeScript modules that are imported.
|
|
72
|
+
*
|
|
73
|
+
* For MVP, we return an empty array since extracting type IDs from TypeScript modules
|
|
74
|
+
* would require runtime evaluation or static analysis. This can be enhanced later.
|
|
75
|
+
*/
|
|
76
|
+
function collectSupportedCodecTypeIds(descriptors) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { parseContractMarkerRow as n, collectSupportedCodecTypeIds as t };
|
|
82
|
+
//# sourceMappingURL=verify-BdES8wgQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-BdES8wgQ.mjs","names":["parsed: unknown"],"sources":["../src/core/verify.ts"],"sourcesContent":["import type { ContractMarkerRecord } from '@prisma-next/contract/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\n/**\n * SQLite stores `contract_json` as TEXT, so the wire shape is a JSON string;\n * Postgres uses `jsonb` and returns an already-parsed value. Normalize both\n * here so `ContractMarkerRecord.contractJson` is always the structured form.\n */\nfunction parseContractJson(value: unknown): unknown {\n if (value === null || value === undefined) return null;\n if (typeof value !== 'string') return value;\n try {\n return JSON.parse(value);\n } catch {\n return null;\n }\n}\n\n/**\n * Wire shape of a `prisma_contract.marker` row as it comes out of a SQL\n * driver. Snake-cased to match the on-disk column names. Shared by every\n * SQL target's `readMarker` so each runner doesn't redeclare it inline.\n */\nexport type ContractMarkerRow = {\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 // SQLite stores arrays as JSON-TEXT, so this is `string` on the wire from\n // a SQLite driver and `string[]` from a Postgres driver. Targets normalize\n // before passing to `parseContractMarkerRow`.\n invariants: 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 invariants: type('string').array(),\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 updatedAt = result.updated_at\n ? result.updated_at instanceof Date\n ? result.updated_at\n : new Date(result.updated_at)\n : new Date();\n\n return {\n storageHash: result.core_hash,\n profileHash: result.profile_hash,\n contractJson: parseContractJson(result.contract_json),\n canonicalVersion: result.canonical_version ?? null,\n updatedAt,\n appTag: result.app_tag ?? null,\n meta: parseMeta(result.meta),\n invariants: result.invariants,\n };\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":";;;AAGA,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;;;;;;;AAQT,SAAS,kBAAkB,OAAyB;AAClD,KAAI,UAAU,QAAQ,UAAU,OAAW,QAAO;AAClD,KAAI,OAAO,UAAU,SAAU,QAAO;AACtC,KAAI;AACF,SAAO,KAAK,MAAM,MAAM;SAClB;AACN,SAAO;;;AAuBX,MAAM,0BAA0B,KAAK;CACnC,WAAW;CACX,cAAc;CACd,kBAAkB;CAClB,sBAAsB;CACtB,eAAe;CACf,YAAY;CACZ,SAAS;CACT,YAAY,KAAK,SAAS,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