@prisma-next/family-sql 0.3.0-dev.5 → 0.3.0-dev.52
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 +12 -6
- package/dist/assembly-BVS641kd.mjs +106 -0
- package/dist/assembly-BVS641kd.mjs.map +1 -0
- package/dist/control-adapter.d.mts +60 -0
- package/dist/control-adapter.d.mts.map +1 -0
- package/dist/control-adapter.mjs +1 -0
- package/dist/control-instance-CWKSpACr.d.mts +292 -0
- package/dist/control-instance-CWKSpACr.d.mts.map +1 -0
- package/dist/control.d.mts +64 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +536 -0
- package/dist/control.mjs.map +1 -0
- package/dist/runtime.d.mts +27 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +38 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/schema-verify.d.mts +48 -0
- package/dist/schema-verify.d.mts.map +1 -0
- package/dist/schema-verify.mjs +4 -0
- package/dist/test-utils.d.mts +2 -0
- package/dist/test-utils.mjs +3 -0
- package/dist/verify-BfMETJcM.mjs +108 -0
- package/dist/verify-BfMETJcM.mjs.map +1 -0
- package/dist/verify-sql-schema-CpAVEi8A.mjs +1058 -0
- package/dist/verify-sql-schema-CpAVEi8A.mjs.map +1 -0
- package/dist/verify-sql-schema-DhHnkpPa.d.mts +67 -0
- package/dist/verify-sql-schema-DhHnkpPa.d.mts.map +1 -0
- package/dist/verify.d.mts +31 -0
- package/dist/verify.d.mts.map +1 -0
- package/dist/verify.mjs +3 -0
- package/package.json +36 -47
- package/src/core/assembly.ts +158 -59
- package/src/core/control-adapter.ts +15 -0
- package/src/core/control-descriptor.ts +37 -0
- package/src/core/{instance.ts → control-instance.ts} +108 -241
- package/src/core/migrations/types.ts +62 -163
- package/src/core/runtime-descriptor.ts +19 -41
- package/src/core/runtime-instance.ts +11 -133
- package/src/core/schema-verify/verify-helpers.ts +187 -97
- package/src/core/schema-verify/verify-sql-schema.ts +910 -392
- package/src/core/verify.ts +4 -13
- package/src/exports/control.ts +9 -6
- package/src/exports/runtime.ts +2 -6
- package/src/exports/schema-verify.ts +10 -2
- package/src/exports/test-utils.ts +0 -1
- package/dist/chunk-6K3RPBDP.js +0 -580
- package/dist/chunk-6K3RPBDP.js.map +0 -1
- package/dist/chunk-BHEGVBY7.js +0 -772
- package/dist/chunk-BHEGVBY7.js.map +0 -1
- package/dist/chunk-SU7LN2UH.js +0 -96
- package/dist/chunk-SU7LN2UH.js.map +0 -1
- package/dist/core/assembly.d.ts +0 -25
- package/dist/core/assembly.d.ts.map +0 -1
- package/dist/core/control-adapter.d.ts +0 -42
- package/dist/core/control-adapter.d.ts.map +0 -1
- package/dist/core/descriptor.d.ts +0 -31
- package/dist/core/descriptor.d.ts.map +0 -1
- package/dist/core/instance.d.ts +0 -142
- package/dist/core/instance.d.ts.map +0 -1
- package/dist/core/migrations/plan-helpers.d.ts +0 -20
- package/dist/core/migrations/plan-helpers.d.ts.map +0 -1
- package/dist/core/migrations/policies.d.ts +0 -6
- package/dist/core/migrations/policies.d.ts.map +0 -1
- package/dist/core/migrations/types.d.ts +0 -280
- package/dist/core/migrations/types.d.ts.map +0 -1
- package/dist/core/runtime-descriptor.d.ts +0 -19
- package/dist/core/runtime-descriptor.d.ts.map +0 -1
- package/dist/core/runtime-instance.d.ts +0 -54
- package/dist/core/runtime-instance.d.ts.map +0 -1
- package/dist/core/schema-verify/verify-helpers.d.ts +0 -50
- package/dist/core/schema-verify/verify-helpers.d.ts.map +0 -1
- package/dist/core/schema-verify/verify-sql-schema.d.ts +0 -45
- package/dist/core/schema-verify/verify-sql-schema.d.ts.map +0 -1
- package/dist/core/verify.d.ts +0 -39
- package/dist/core/verify.d.ts.map +0 -1
- package/dist/exports/control-adapter.d.ts +0 -2
- package/dist/exports/control-adapter.d.ts.map +0 -1
- package/dist/exports/control-adapter.js +0 -1
- package/dist/exports/control-adapter.js.map +0 -1
- package/dist/exports/control.d.ts +0 -13
- package/dist/exports/control.d.ts.map +0 -1
- package/dist/exports/control.js +0 -149
- package/dist/exports/control.js.map +0 -1
- package/dist/exports/runtime.d.ts +0 -8
- package/dist/exports/runtime.d.ts.map +0 -1
- package/dist/exports/runtime.js +0 -64
- package/dist/exports/runtime.js.map +0 -1
- package/dist/exports/schema-verify.d.ts +0 -11
- package/dist/exports/schema-verify.d.ts.map +0 -1
- package/dist/exports/schema-verify.js +0 -11
- package/dist/exports/schema-verify.js.map +0 -1
- package/dist/exports/test-utils.d.ts +0 -7
- package/dist/exports/test-utils.d.ts.map +0 -1
- package/dist/exports/test-utils.js +0 -17
- package/dist/exports/test-utils.js.map +0 -1
- package/dist/exports/verify.d.ts +0 -2
- package/dist/exports/verify.d.ts.map +0 -1
- package/dist/exports/verify.js +0 -11
- package/dist/exports/verify.js.map +0 -1
- package/src/core/descriptor.ts +0 -37
package/dist/runtime.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/core/runtime-instance.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a SQL execution-plane family instance.
|
|
4
|
+
*
|
|
5
|
+
* This will be renamed to `createSqlExecutionFamilyInstance()` as part of `TML-1842`.
|
|
6
|
+
*/
|
|
7
|
+
function createSqlRuntimeFamilyInstance() {
|
|
8
|
+
return { familyId: "sql" };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/core/runtime-descriptor.ts
|
|
13
|
+
/**
|
|
14
|
+
* SQL execution-plane family descriptor.
|
|
15
|
+
*
|
|
16
|
+
* Note: this is currently named `sqlRuntimeFamilyDescriptor` because the execution plane
|
|
17
|
+
* framework types are still using the `Runtime*` naming (`RuntimeFamilyDescriptor`, etc.).
|
|
18
|
+
*
|
|
19
|
+
* This will be renamed to `sqlExecutionFamilyDescriptor` as part of `TML-1842`.
|
|
20
|
+
*/
|
|
21
|
+
const sqlRuntimeFamilyDescriptor = {
|
|
22
|
+
kind: "family",
|
|
23
|
+
id: "sql",
|
|
24
|
+
familyId: "sql",
|
|
25
|
+
version: "0.0.1",
|
|
26
|
+
create() {
|
|
27
|
+
return createSqlRuntimeFamilyInstance();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
Object.freeze(sqlRuntimeFamilyDescriptor);
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/exports/runtime.ts
|
|
34
|
+
var runtime_default = sqlRuntimeFamilyDescriptor;
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { runtime_default as default };
|
|
38
|
+
//# sourceMappingURL=runtime.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":["sqlRuntimeFamilyDescriptor: RuntimeFamilyDescriptor<'sql', SqlRuntimeFamilyInstance>"],"sources":["../src/core/runtime-instance.ts","../src/core/runtime-descriptor.ts","../src/exports/runtime.ts"],"sourcesContent":["import type { RuntimeFamilyInstance } from '@prisma-next/core-execution-plane/types';\n\n/**\n * SQL execution-plane family instance interface.\n *\n * Note: this is currently named `SqlRuntimeFamilyInstance` because the execution plane\n * framework types are still using the `Runtime*` naming (`RuntimeFamilyInstance`, etc.).\n *\n * This will be renamed to `SqlExecutionFamilyInstance` as part of `TML-1842`.\n */\nexport interface SqlRuntimeFamilyInstance extends RuntimeFamilyInstance<'sql'> {}\n\n/**\n * Creates a SQL execution-plane family instance.\n *\n * This will be renamed to `createSqlExecutionFamilyInstance()` as part of `TML-1842`.\n */\nexport function createSqlRuntimeFamilyInstance(): SqlRuntimeFamilyInstance {\n return {\n familyId: 'sql' as const,\n };\n}\n","import type { RuntimeFamilyDescriptor } from '@prisma-next/core-execution-plane/types';\nimport { createSqlRuntimeFamilyInstance, type SqlRuntimeFamilyInstance } from './runtime-instance';\n\n/**\n * SQL execution-plane family descriptor.\n *\n * Note: this is currently named `sqlRuntimeFamilyDescriptor` because the execution plane\n * framework types are still using the `Runtime*` naming (`RuntimeFamilyDescriptor`, etc.).\n *\n * This will be renamed to `sqlExecutionFamilyDescriptor` as part of `TML-1842`.\n */\nexport const sqlRuntimeFamilyDescriptor: RuntimeFamilyDescriptor<'sql', SqlRuntimeFamilyInstance> =\n {\n kind: 'family',\n id: 'sql',\n familyId: 'sql',\n version: '0.0.1',\n create() {\n return createSqlRuntimeFamilyInstance();\n },\n };\n\nObject.freeze(sqlRuntimeFamilyDescriptor);\n","import { sqlRuntimeFamilyDescriptor } from '../core/runtime-descriptor';\n\nexport default sqlRuntimeFamilyDescriptor;\n"],"mappings":";;;;;;AAiBA,SAAgB,iCAA2D;AACzE,QAAO,EACL,UAAU,OACX;;;;;;;;;;;;;ACTH,MAAaA,6BACX;CACE,MAAM;CACN,IAAI;CACJ,UAAU;CACV,SAAS;CACT,SAAS;AACP,SAAO,gCAAgC;;CAE1C;AAEH,OAAO,OAAO,2BAA2B;;;;ACpBzC,sBAAe"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { i as verifySqlSchema, n as NativeTypeNormalizer, r as VerifySqlSchemaOptions } from "./verify-sql-schema-DhHnkpPa.mjs";
|
|
2
|
+
import { f as ComponentDatabaseDependency } from "./control-instance-CWKSpACr.mjs";
|
|
3
|
+
import { SchemaIssue, SchemaVerificationNode } from "@prisma-next/core-control-plane/types";
|
|
4
|
+
import { SqlIndexIR, SqlSchemaIR, SqlUniqueIR } from "@prisma-next/sql-schema-ir/types";
|
|
5
|
+
|
|
6
|
+
//#region src/core/schema-verify/verify-helpers.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Compares two arrays of strings for equality (order-sensitive).
|
|
10
|
+
*/
|
|
11
|
+
declare function arraysEqual(a: readonly string[], b: readonly string[]): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a unique constraint requirement is satisfied by the given columns.
|
|
14
|
+
*
|
|
15
|
+
* Semantic satisfaction: a unique constraint requirement can be satisfied by:
|
|
16
|
+
* - A unique constraint with the same columns, OR
|
|
17
|
+
* - A unique index with the same columns
|
|
18
|
+
*
|
|
19
|
+
* @param uniques - The unique constraints in the schema table
|
|
20
|
+
* @param indexes - The indexes in the schema table
|
|
21
|
+
* @param columns - The columns required by the unique constraint
|
|
22
|
+
* @returns true if the requirement is satisfied
|
|
23
|
+
*/
|
|
24
|
+
declare function isUniqueConstraintSatisfied(uniques: readonly SqlUniqueIR[], indexes: readonly SqlIndexIR[], columns: readonly string[]): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if an index requirement is satisfied by the given columns.
|
|
27
|
+
*
|
|
28
|
+
* Semantic satisfaction: a non-unique index requirement can be satisfied by:
|
|
29
|
+
* - Any index (unique or non-unique) with the same columns, OR
|
|
30
|
+
* - A unique constraint with the same columns (stronger satisfies weaker)
|
|
31
|
+
*
|
|
32
|
+
* @param indexes - The indexes in the schema table
|
|
33
|
+
* @param uniques - The unique constraints in the schema table
|
|
34
|
+
* @param columns - The columns required by the index
|
|
35
|
+
* @returns true if the requirement is satisfied
|
|
36
|
+
*/
|
|
37
|
+
declare function isIndexSatisfied(indexes: readonly SqlIndexIR[], uniques: readonly SqlUniqueIR[], columns: readonly string[]): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Verifies database dependencies are installed using component-owned verification hooks.
|
|
40
|
+
* Each dependency provides a pure verifyDatabaseDependencyInstalled function that checks
|
|
41
|
+
* whether the dependency is satisfied based on the in-memory schema IR (no DB I/O).
|
|
42
|
+
*
|
|
43
|
+
* Returns verification nodes for the tree.
|
|
44
|
+
*/
|
|
45
|
+
declare function verifyDatabaseDependencies(dependencies: ReadonlyArray<ComponentDatabaseDependency<unknown>>, schema: SqlSchemaIR, issues: SchemaIssue[]): SchemaVerificationNode[];
|
|
46
|
+
//#endregion
|
|
47
|
+
export { type NativeTypeNormalizer, type VerifySqlSchemaOptions, arraysEqual, isIndexSatisfied, isUniqueConstraintSatisfied, verifyDatabaseDependencies, verifySqlSchema };
|
|
48
|
+
//# sourceMappingURL=schema-verify.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-verify.d.mts","names":[],"sources":["../src/core/schema-verify/verify-helpers.ts"],"sourcesContent":[],"mappings":";;;;;;;AAgFA;AA0YA;;AACgB,iBApcA,WAAA,CAocA,CAAA,EAAA,SAAA,MAAA,EAAA,EAAA,CAAA,EAAA,SAAA,MAAA,EAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;iBAraA,2BAAA,mBACI,iCACA;;;;;;;;;;;;;iBAwBJ,gBAAA,mBACI,gCACA;;;;;;;;iBAwYJ,0BAAA,eACA,cAAc,+CACpB,qBACA,gBACP"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import "./assembly-BVS641kd.mjs";
|
|
2
|
+
import { a as verifyDatabaseDependencies, i as isUniqueConstraintSatisfied, n as arraysEqual, r as isIndexSatisfied, t as verifySqlSchema } from "./verify-sql-schema-CpAVEi8A.mjs";
|
|
3
|
+
|
|
4
|
+
export { arraysEqual, isIndexSatisfied, isUniqueConstraintSatisfied, verifyDatabaseDependencies, verifySqlSchema };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { c as extractOperationTypeImports, i as assembleOperationRegistry, o as extractCodecTypeImports, s as extractExtensionIds } from "./control-instance-CWKSpACr.mjs";
|
|
2
|
+
export { assembleOperationRegistry, extractCodecTypeImports, extractExtensionIds, extractOperationTypeImports };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as extractOperationTypeImports, i as extractExtensionIds, r as extractCodecTypeImports, t as assembleOperationRegistry } from "./assembly-BVS641kd.mjs";
|
|
2
|
+
|
|
3
|
+
export { assembleOperationRegistry, extractCodecTypeImports, extractExtensionIds, extractOperationTypeImports };
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
* Reads the contract marker from the database using the provided driver.
|
|
71
|
+
* Returns the parsed marker record or null if no marker is found.
|
|
72
|
+
* This abstracts SQL-specific details from the Control Plane.
|
|
73
|
+
*
|
|
74
|
+
* @param driver - ControlDriverInstance instance for executing queries
|
|
75
|
+
* @returns Promise resolving to ContractMarkerRecord or null if marker not found
|
|
76
|
+
*/
|
|
77
|
+
async function readMarker(driver) {
|
|
78
|
+
const markerStatement = readMarkerSql();
|
|
79
|
+
try {
|
|
80
|
+
const queryResult = await driver.query(markerStatement.sql, markerStatement.params);
|
|
81
|
+
if (queryResult.rows.length === 0) return null;
|
|
82
|
+
const markerRow = queryResult.rows[0];
|
|
83
|
+
if (!markerRow) throw new Error("Database query returned unexpected result structure");
|
|
84
|
+
return parseContractMarkerRow(markerRow);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error instanceof Error && (error.message.includes("does not exist") || error.code === "42P01")) return null;
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Collects supported codec type IDs from adapter and extension manifests.
|
|
92
|
+
* Returns a sorted, unique array of type IDs that are declared in the manifests.
|
|
93
|
+
* This enables coverage checks by comparing contract column types against supported types.
|
|
94
|
+
*
|
|
95
|
+
* Note: This extracts type IDs from manifest type imports, not from runtime codec registries.
|
|
96
|
+
* The manifests declare which codec types are available, but the actual type IDs
|
|
97
|
+
* are defined in the codec-types TypeScript modules that are imported.
|
|
98
|
+
*
|
|
99
|
+
* For MVP, we return an empty array since extracting type IDs from TypeScript modules
|
|
100
|
+
* would require runtime evaluation or static analysis. This can be enhanced later.
|
|
101
|
+
*/
|
|
102
|
+
function collectSupportedCodecTypeIds(descriptors) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
export { readMarkerSql as i, parseContractMarkerRow as n, readMarker as r, collectSupportedCodecTypeIds as t };
|
|
108
|
+
//# sourceMappingURL=verify-BfMETJcM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-BfMETJcM.mjs","names":["parsed: unknown"],"sources":["../src/core/verify.ts"],"sourcesContent":["import type { ContractMarkerRecord } from '@prisma-next/contract/types';\nimport type { ControlDriverInstance } 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 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 * 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 const markerStatement = readMarkerSql();\n\n try {\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 } catch (error) {\n // Handle case where marker table doesn't exist yet (empty database)\n // PostgreSQL error code 42P01 = undefined_table\n if (\n error instanceof Error &&\n (error.message.includes('does not exist') || (error as { code?: string }).code === '42P01')\n ) {\n return null;\n }\n throw error;\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":";;;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;;;;;;;;;;AAWH,eAAsB,WACpB,QACsC;CACtC,MAAM,kBAAkB,eAAe;AAEvC,KAAI;EACF,MAAM,cAAc,MAAM,OAAO,MAQ9B,gBAAgB,KAAK,gBAAgB,OAAO;AAE/C,MAAI,YAAY,KAAK,WAAW,EAC9B,QAAO;EAGT,MAAM,YAAY,YAAY,KAAK;AACnC,MAAI,CAAC,UAEH,OAAM,IAAI,MAAM,sDAAsD;AAGxE,SAAO,uBAAuB,UAAU;UACjC,OAAO;AAGd,MACE,iBAAiB,UAChB,MAAM,QAAQ,SAAS,iBAAiB,IAAK,MAA4B,SAAS,SAEnF,QAAO;AAET,QAAM;;;;;;;;;;;;;;;AAgBV,SAAgB,6BACd,aACmB;AAKnB,QAAO,EAAE"}
|