@prisma-next/family-sql 0.11.0 → 0.12.0-dev.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-type-constructors-F4JpCJl7.mjs.map +1 -1
- package/dist/control-adapter-Br03xBEv.d.mts +115 -0
- package/dist/control-adapter-Br03xBEv.d.mts.map +1 -0
- package/dist/control-adapter.d.mts +2 -102
- package/dist/control.d.mts +25 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +50 -34
- package/dist/control.mjs.map +1 -1
- package/dist/ir.d.mts +4 -1
- package/dist/ir.d.mts.map +1 -1
- package/dist/ir.mjs +1 -1
- package/dist/ir.mjs.map +1 -1
- package/dist/migration.d.mts +1 -1
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs.map +1 -1
- package/dist/pack.mjs.map +1 -1
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/runtime.mjs.map +1 -1
- package/dist/schema-verify.d.mts +1 -1
- package/dist/schema-verify.d.mts.map +1 -1
- package/dist/schema-verify.mjs +1 -1
- package/dist/{sql-contract-serializer-COnYiewe.mjs → sql-contract-serializer-8axtK4lg.mjs} +31 -13
- package/dist/sql-contract-serializer-8axtK4lg.mjs.map +1 -0
- package/dist/{timestamp-now-generator-r7BP5n3l.mjs → timestamp-now-generator-BkjCQIde.mjs} +2 -1
- package/dist/{timestamp-now-generator-r7BP5n3l.mjs.map → timestamp-now-generator-BkjCQIde.mjs.map} +1 -1
- package/dist/{types-hQoMXr54.d.mts → types-DbGXj_Si.d.mts} +30 -42
- package/dist/types-DbGXj_Si.d.mts.map +1 -0
- package/dist/verify-Crewz6hG.mjs.map +1 -1
- package/dist/{verify-sql-schema-Bfvz07Ik.d.mts → verify-sql-schema-CN7pPoTC.d.mts} +2 -2
- package/dist/verify-sql-schema-CN7pPoTC.d.mts.map +1 -0
- package/dist/{verify-sql-schema-Bj4Wqe2c.mjs → verify-sql-schema-CYLsGCFO.mjs} +52 -38
- package/dist/verify-sql-schema-CYLsGCFO.mjs.map +1 -0
- package/dist/verify.d.mts.map +1 -1
- package/package.json +32 -21
- package/src/core/control-adapter.ts +30 -2
- package/src/core/control-instance.ts +22 -32
- package/src/core/ir/sql-contract-serializer-base.ts +67 -33
- package/src/core/migrations/contract-to-schema-ir.ts +86 -37
- package/src/core/migrations/types.ts +29 -46
- package/src/core/schema-verify/verify-sql-schema.ts +92 -43
- package/src/core/timestamp-now-generator.ts +1 -0
- package/src/exports/control.ts +1 -3
- package/dist/control-adapter.d.mts.map +0 -1
- package/dist/sql-contract-serializer-COnYiewe.mjs.map +0 -1
- package/dist/types-hQoMXr54.d.mts.map +0 -1
- package/dist/verify-sql-schema-Bfvz07Ik.d.mts.map +0 -1
- package/dist/verify-sql-schema-Bj4Wqe2c.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authoring-type-constructors-F4JpCJl7.mjs","names":[],"sources":["../src/core/authoring-field-presets.ts","../src/core/authoring-type-constructors.ts"],"sourcesContent":["import type { AuthoringFieldNamespace } from '@prisma-next/framework-components/authoring';\n\n/**\n * Family-level SQL authoring field presets.\n *\n * Only presets whose codec IDs align with the ID generator metadata live here\n * (see `@prisma-next/ids`). These presets are target-agnostic because the\n * generator metadata fixes their codec/native-type to `sql/char@1`\n * (`character`) regardless of target, and the PSL interpreter lets the\n * generator override the scalar descriptor.\n *\n * Scalar presets that map to target-specific codecs (e.g. `text`, `int`,\n * `boolean`, `dateTime`) are contributed by the target pack (see\n * `postgresAuthoringFieldPresets` in `@prisma-next/target-postgres`) so the\n * TS callback surface and the PSL scalar surface lower to byte-identical\n * contracts for the active target.\n */\n\nconst CHARACTER_CODEC_ID = 'sql/char@1';\nconst CHARACTER_NATIVE_TYPE = 'character';\n\nconst nanoidOptionsArgument = {\n kind: 'object',\n optional: true,\n properties: {\n size: {\n kind: 'number',\n optional: true,\n integer: true,\n minimum: 2,\n maximum: 255,\n },\n },\n} as const;\n\nexport const sqlFamilyAuthoringFieldPresets = {\n uuid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 36,\n },\n },\n },\n ulid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 26,\n },\n },\n },\n nanoid: {\n kind: 'fieldPreset',\n args: [nanoidOptionsArgument],\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: {\n kind: 'arg',\n index: 0,\n path: ['size'],\n default: 21,\n },\n },\n },\n },\n cuid2: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 24,\n },\n },\n },\n ksuid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 27,\n },\n },\n },\n id: {\n uuidv4: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 36,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv4',\n },\n },\n id: true,\n },\n },\n uuidv7: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 36,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv7',\n },\n },\n id: true,\n },\n },\n ulid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 26,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'ulid',\n },\n },\n id: true,\n },\n },\n nanoid: {\n kind: 'fieldPreset',\n args: [nanoidOptionsArgument],\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: {\n kind: 'arg',\n index: 0,\n path: ['size'],\n default: 21,\n },\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'nanoid',\n params: {\n size: {\n kind: 'arg',\n index: 0,\n path: ['size'],\n },\n },\n },\n },\n id: true,\n },\n },\n cuid2: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 24,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'cuid2',\n },\n },\n id: true,\n },\n },\n ksuid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 27,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'ksuid',\n },\n },\n id: true,\n },\n },\n },\n} as const satisfies AuthoringFieldNamespace;\n","import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';\n\nexport const sqlFamilyAuthoringTypes = {\n sql: {\n String: {\n kind: 'typeConstructor',\n args: [{ kind: 'number', name: 'length', integer: true, minimum: 1, maximum: 10485760 }],\n output: {\n codecId: 'sql/varchar@1',\n nativeType: 'character varying',\n typeParams: {\n length: { kind: 'arg', index: 0 },\n },\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,MAAM,qBAAqB;AAC3B,MAAM,wBAAwB;AAE9B,MAAM,wBAAwB;CAC5B,MAAM;CACN,UAAU;CACV,YAAY,EACV,MAAM;EACJ,MAAM;EACN,UAAU;EACV,SAAS;EACT,SAAS;EACT,SAAS;
|
|
1
|
+
{"version":3,"file":"authoring-type-constructors-F4JpCJl7.mjs","names":[],"sources":["../src/core/authoring-field-presets.ts","../src/core/authoring-type-constructors.ts"],"sourcesContent":["import type { AuthoringFieldNamespace } from '@prisma-next/framework-components/authoring';\n\n/**\n * Family-level SQL authoring field presets.\n *\n * Only presets whose codec IDs align with the ID generator metadata live here\n * (see `@prisma-next/ids`). These presets are target-agnostic because the\n * generator metadata fixes their codec/native-type to `sql/char@1`\n * (`character`) regardless of target, and the PSL interpreter lets the\n * generator override the scalar descriptor.\n *\n * Scalar presets that map to target-specific codecs (e.g. `text`, `int`,\n * `boolean`, `dateTime`) are contributed by the target pack (see\n * `postgresAuthoringFieldPresets` in `@prisma-next/target-postgres`) so the\n * TS callback surface and the PSL scalar surface lower to byte-identical\n * contracts for the active target.\n */\n\nconst CHARACTER_CODEC_ID = 'sql/char@1';\nconst CHARACTER_NATIVE_TYPE = 'character';\n\nconst nanoidOptionsArgument = {\n kind: 'object',\n optional: true,\n properties: {\n size: {\n kind: 'number',\n optional: true,\n integer: true,\n minimum: 2,\n maximum: 255,\n },\n },\n} as const;\n\nexport const sqlFamilyAuthoringFieldPresets = {\n uuid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 36,\n },\n },\n },\n ulid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 26,\n },\n },\n },\n nanoid: {\n kind: 'fieldPreset',\n args: [nanoidOptionsArgument],\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: {\n kind: 'arg',\n index: 0,\n path: ['size'],\n default: 21,\n },\n },\n },\n },\n cuid2: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 24,\n },\n },\n },\n ksuid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 27,\n },\n },\n },\n id: {\n uuidv4: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 36,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv4',\n },\n },\n id: true,\n },\n },\n uuidv7: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 36,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv7',\n },\n },\n id: true,\n },\n },\n ulid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 26,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'ulid',\n },\n },\n id: true,\n },\n },\n nanoid: {\n kind: 'fieldPreset',\n args: [nanoidOptionsArgument],\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: {\n kind: 'arg',\n index: 0,\n path: ['size'],\n default: 21,\n },\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'nanoid',\n params: {\n size: {\n kind: 'arg',\n index: 0,\n path: ['size'],\n },\n },\n },\n },\n id: true,\n },\n },\n cuid2: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 24,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'cuid2',\n },\n },\n id: true,\n },\n },\n ksuid: {\n kind: 'fieldPreset',\n output: {\n codecId: CHARACTER_CODEC_ID,\n nativeType: CHARACTER_NATIVE_TYPE,\n typeParams: {\n length: 27,\n },\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'ksuid',\n },\n },\n id: true,\n },\n },\n },\n} as const satisfies AuthoringFieldNamespace;\n","import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';\n\nexport const sqlFamilyAuthoringTypes = {\n sql: {\n String: {\n kind: 'typeConstructor',\n args: [{ kind: 'number', name: 'length', integer: true, minimum: 1, maximum: 10485760 }],\n output: {\n codecId: 'sql/varchar@1',\n nativeType: 'character varying',\n typeParams: {\n length: { kind: 'arg', index: 0 },\n },\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,MAAM,qBAAqB;AAC3B,MAAM,wBAAwB;AAE9B,MAAM,wBAAwB;CAC5B,MAAM;CACN,UAAU;CACV,YAAY,EACV,MAAM;EACJ,MAAM;EACN,UAAU;EACV,SAAS;EACT,SAAS;EACT,SAAS;CACX,EACF;AACF;AAEA,MAAa,iCAAiC;CAC5C,MAAM;EACJ,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACZ,YAAY,EACV,QAAQ,GACV;EACF;CACF;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACZ,YAAY,EACV,QAAQ,GACV;EACF;CACF;CACA,QAAQ;EACN,MAAM;EACN,MAAM,CAAC,qBAAqB;EAC5B,QAAQ;GACN,SAAS;GACT,YAAY;GACZ,YAAY,EACV,QAAQ;IACN,MAAM;IACN,OAAO;IACP,MAAM,CAAC,MAAM;IACb,SAAS;GACX,EACF;EACF;CACF;CACA,OAAO;EACL,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACZ,YAAY,EACV,QAAQ,GACV;EACF;CACF;CACA,OAAO;EACL,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;GACZ,YAAY,EACV,QAAQ,GACV;EACF;CACF;CACA,IAAI;EACF,QAAQ;GACN,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,GACV;IACA,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;IACN,EACF;IACA,IAAI;GACN;EACF;EACA,QAAQ;GACN,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,GACV;IACA,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;IACN,EACF;IACA,IAAI;GACN;EACF;EACA,MAAM;GACJ,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,GACV;IACA,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;IACN,EACF;IACA,IAAI;GACN;EACF;EACA,QAAQ;GACN,MAAM;GACN,MAAM,CAAC,qBAAqB;GAC5B,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ;KACN,MAAM;KACN,OAAO;KACP,MAAM,CAAC,MAAM;KACb,SAAS;IACX,EACF;IACA,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;KACJ,QAAQ,EACN,MAAM;MACJ,MAAM;MACN,OAAO;MACP,MAAM,CAAC,MAAM;KACf,EACF;IACF,EACF;IACA,IAAI;GACN;EACF;EACA,OAAO;GACL,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,GACV;IACA,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;IACN,EACF;IACA,IAAI;GACN;EACF;EACA,OAAO;GACL,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,YAAY,EACV,QAAQ,GACV;IACA,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;IACN,EACF;IACA,IAAI;GACN;EACF;CACF;AACF;;;AC/MA,MAAa,0BAA0B,EACrC,KAAK,EACH,QAAQ;CACN,MAAM;CACN,MAAM,CAAC;EAAE,MAAM;EAAU,MAAM;EAAU,SAAS;EAAM,SAAS;EAAG,SAAS;CAAS,CAAC;CACvF,QAAQ;EACN,SAAS;EACT,YAAY;EACZ,YAAY,EACV,QAAQ;GAAE,MAAM;GAAO,OAAO;EAAE,EAClC;CACF;AACF,EACF,EACF"}
|
|
@@ -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,102 +1,2 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
|
|
3
|
-
import { PostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
|
|
4
|
-
import { 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) => readonly string[] | null;
|
|
74
|
-
/**
|
|
75
|
-
* Lower a SQL query AST into a target-flavored `{ sql, params }` payload.
|
|
76
|
-
*
|
|
77
|
-
* Migration tooling (e.g. the `dataTransform` operation) needs to materialize
|
|
78
|
-
* SQL at emit/plan time without instantiating the runtime adapter. The control
|
|
79
|
-
* adapter's `lower` is byte-equivalent to the runtime adapter's `lower` for the
|
|
80
|
-
* same AST and contract, ensuring planned SQL matches what the runtime would
|
|
81
|
-
* emit.
|
|
82
|
-
*/
|
|
83
|
-
lower(ast: AnyQueryAst, context: LowererContext<unknown>): LoweredStatement;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* SQL control adapter descriptor interface.
|
|
87
|
-
* Provides a factory method to create control adapter instances.
|
|
88
|
-
*
|
|
89
|
-
* @template TTarget - The target ID (e.g., 'postgres', 'mysql')
|
|
90
|
-
*/
|
|
91
|
-
interface SqlControlAdapterDescriptor<TTarget extends string = string> {
|
|
92
|
-
/**
|
|
93
|
-
* Creates a SQL control adapter instance for control-plane operations.
|
|
94
|
-
*
|
|
95
|
-
* Receives the assembled `ControlStack` so adapters can read aggregated
|
|
96
|
-
* metadata (codec lookup, extension contributions) when materializing.
|
|
97
|
-
*/
|
|
98
|
-
create(stack: ControlStack<'sql', TTarget>): SqlControlAdapter<TTarget>;
|
|
99
|
-
}
|
|
100
|
-
//#endregion
|
|
101
|
-
export { type SqlControlAdapter, type SqlControlAdapterDescriptor };
|
|
102
|
-
//# 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 };
|
package/dist/control.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
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";
|
|
@@ -271,6 +271,21 @@ type NativeTypeExpander = (input: {
|
|
|
271
271
|
* `contractToSchemaIR`, keeping the family layer target-agnostic.
|
|
272
272
|
*/
|
|
273
273
|
type DefaultRenderer = (def: ColumnDefault, column: StorageColumn) => string;
|
|
274
|
+
/**
|
|
275
|
+
* Target-supplied callback that computes the schema-qualified annotation-map
|
|
276
|
+
* key for a namespace-scoped enum storage type.
|
|
277
|
+
*
|
|
278
|
+
* Enum lookups (`readExistingEnumValues`) are namespace/schema-qualified so two
|
|
279
|
+
* namespaces holding an enum with the same TypeScript name (and even the same
|
|
280
|
+
* native type) resolve to distinct live-database types. The *format* of that
|
|
281
|
+
* key — and the namespace → DDL-schema resolution it depends on — is a
|
|
282
|
+
* target-specific concern (Postgres schemas; SQLite/MySQL differ), so the
|
|
283
|
+
* target injects it here as data rather than the family layer importing a
|
|
284
|
+
* concrete `ddlSchemaName`/key implementation. This keeps the family layer
|
|
285
|
+
* target-agnostic (no `@prisma-next/target-*` dependency) while the projection
|
|
286
|
+
* still emits keys that match the target's read side exactly.
|
|
287
|
+
*/
|
|
288
|
+
type EnumStorageKeyResolver = (storage: SqlStorage, namespaceId: string, nativeType: string) => string;
|
|
274
289
|
/**
|
|
275
290
|
* Detects destructive changes between two contract storages.
|
|
276
291
|
*
|
|
@@ -285,6 +300,14 @@ interface ContractToSchemaIROptions {
|
|
|
285
300
|
readonly annotationNamespace: string;
|
|
286
301
|
readonly expandNativeType?: NativeTypeExpander;
|
|
287
302
|
readonly renderDefault?: DefaultRenderer;
|
|
303
|
+
/**
|
|
304
|
+
* Target-supplied resolver for namespace/schema-qualified enum annotation
|
|
305
|
+
* keys. When provided (Postgres), every namespace-scoped enum is keyed by the
|
|
306
|
+
* resolver's output so the projected `storageTypes` map matches the target's
|
|
307
|
+
* `readExistingEnumValues` lookup. Targets without namespace-qualified enum
|
|
308
|
+
* storage (SQLite) omit it; enums are absent there.
|
|
309
|
+
*/
|
|
310
|
+
readonly resolveEnumStorageKey?: EnumStorageKeyResolver;
|
|
288
311
|
}
|
|
289
312
|
/**
|
|
290
313
|
* Converts a `Contract` to `SqlSchemaIR`.
|
|
@@ -411,5 +434,5 @@ declare function temporalAuthoringPresets<const CodecId extends string, const Na
|
|
|
411
434
|
//#region src/exports/control.d.ts
|
|
412
435
|
declare const _default: SqlFamilyDescriptor;
|
|
413
436
|
//#endregion
|
|
414
|
-
export { type CodecControlHooks, type ContractToSchemaIROptions, type CreateSqlMigrationPlanOptions, type DefaultRenderer, type ExpandNativeTypeInput, type FieldEvent, type FieldEventContext, INIT_ADDITIVE_POLICY, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerResult, type
|
|
437
|
+
export { type CodecControlHooks, type ContractToSchemaIROptions, type CreateSqlMigrationPlanOptions, type DefaultRenderer, type EnumStorageKeyResolver, type ExpandNativeTypeInput, type FieldEvent, type FieldEventContext, INIT_ADDITIVE_POLICY, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerResult, type NativeTypeExpander, type PlanFieldEventOperationsOptions, type ResolveIdentityValueInput, type SqlControlAdapterDescriptor, type SqlControlExtensionDescriptor, type SqlControlFamilyInstance, type SqlControlTargetDescriptor, type SqlMigrationPlan, type SqlMigrationPlanContractInfo, type SqlMigrationPlanOperation, type SqlMigrationPlanOperationStep, type SqlMigrationPlanOperationTarget, type SqlMigrationPlanner, type SqlMigrationPlannerPlanOptions, type SqlMigrationRunner, type SqlMigrationRunnerErrorCode, type SqlMigrationRunnerExecuteCallbacks, type SqlMigrationRunnerExecuteOptions, type SqlMigrationRunnerFailure, type SqlMigrationRunnerResult, type SqlMigrationRunnerSuccessValue, type SqlPlanTargetDetails, type SqlPlannerConflict, type SqlPlannerConflictKind, type SqlPlannerConflictLocation, type SqlPlannerFailureResult, type SqlPlannerResult, type SqlPlannerSuccessResult, type StorageTypePlanResult, type TargetMigrationsCapability, assembleAuthoringContributions, contractToSchemaIR, createMigrationPlan, _default as default, detectDestructiveChanges, extractCodecControlHooks, planFieldEventOperations, plannerFailure, plannerSuccess, runnerFailure, runnerSuccess, temporalAuthoringPresets, timestampNowControlDescriptor };
|
|
415
438
|
//# sourceMappingURL=control.d.mts.map
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-descriptor.ts","../src/core/assembly.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/field-event-planner.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/core/timestamp-now-generator.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;cAUa,mBAAA,YACA,uBAAA,QAA+B,wBAAA;EAAA,SAEjC,IAAA;EAAA,SACA,EAAA;EAAA,SACA,QAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA,EAAU,WAAA;EAAA,SACV,SAAA;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKT,MAAA,0BAAA,CACE,KAAA,EAAO,YAAA,QAAoB,SAAA,IAC1B,wBAAA;AAAA;;;iBCHW,wBAAA,CACd,WAAA,EAAa,aAAA,CAAc,8BAAA,mBAC1B,GAAA,SAAY,iBAAA;;;;;;;;;ADdf;;;;
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-descriptor.ts","../src/core/assembly.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/field-event-planner.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/core/timestamp-now-generator.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;cAUa,mBAAA,YACA,uBAAA,QAA+B,wBAAA;EAAA,SAEjC,IAAA;EAAA,SACA,EAAA;EAAA,SACA,QAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA,EAAU,WAAA;EAAA,SACV,SAAA;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKT,MAAA,0BAAA,CACE,KAAA,EAAO,YAAA,QAAoB,SAAA,IAC1B,wBAAA;AAAA;;;iBCHW,wBAAA,CACd,WAAA,EAAa,aAAA,CAAc,8BAAA,mBAC1B,GAAA,SAAY,iBAAA;;;;;;;;;ADdf;;;;KE4BY,kBAAA,IAAsB,KAAA;EAAA,SACvB,UAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,MAAM;AAAA;;;;;;;;;;KAYlB,eAAA,IAAmB,GAAA,EAAK,aAAA,EAAe,MAAA,EAAQ,aAAa;;;;;;;;;;;;;;;KAgB5D,sBAAA,IACV,OAAA,EAAS,UAAU,EACnB,WAAA,UACA,UAAA;;;;;;;;;;iBAmKc,wBAAA,CACd,IAAA,EAAM,UAAA,SACN,EAAA,EAAI,UAAA,YACM,0BAAA;AAAA,UA8CK,yBAAA;EAAA,SACN,mBAAA;EAAA,SACA,gBAAA,GAAmB,kBAAA;EAAA,SACnB,aAAA,GAAgB,eAAA;;;;;;;;WAQhB,qBAAA,GAAwB,sBAAA;AAAA;;;;;;;;;;;;;;;iBAiBnB,kBAAA,CACd,QAAA,EAAU,QAAA,CAAS,UAAA,UACnB,OAAA,EAAS,yBAAA,GACR,WAAA;;;UC9Rc,+BAAA;EHZI;;;;EAAA,SGiBV,aAAA,EAAe,QAAA,CAAS,UAAA;;;;WAIxB,WAAA,EAAa,QAAA,CAAS,UAAA;;;;;;;;;;WAUtB,UAAA,EAAY,WAAA,SAAoB,iBAAA;AAAA;AAAA,iBAa3B,wBAAA,CACd,OAAA,EAAS,+BAAA,YACC,aAAa;;;iBCgCT,mBAAA,gBAAA,CACd,OAAA,EAAS,6BAAA,CAA8B,cAAA,IACtC,gBAAA,CAAiB,cAAA;AAAA,iBAcJ,cAAA,gBAAA,CACd,IAAA,EAAM,gBAAA,CAAiB,cAAA,IACtB,uBAAA,CAAwB,cAAA;AAAA,iBAOX,cAAA,CAAe,SAAA,WAAoB,kBAAA,KAAuB,uBAAuB;;;;iBAoBjF,aAAA,CAAc,KAAA;EAC5B,iBAAA;EACA,kBAAA;AAAA,IACE,EAAE,CAAC,8BAAA;;;;iBAYS,aAAA,CACd,IAAA,EAAM,2BAAA,EACN,OAAA,UACA,OAAA;EAAY,GAAA;EAAc,IAAA,GAAO,SAAA;AAAA,IAChC,KAAA,CAAM,yBAAA;;;;;;cC1JI,oBAAA,EAAsB,0BAEjC;;;;;;;;;;;;;;iBCoBc,6BAAA,CAAA,GAAiC,kCAAkC;;;;;;;;;;;iBAqBnE,wBAAA,+DAAA,CAGd,KAAA;EAAA,SAAkB,OAAA,EAAS,OAAA;EAAA,SAAkB,UAAA,EAAY,UAAA;AAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCsBlB,QAAA"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { n as sqlFamilyAuthoringFieldPresets, t as sqlFamilyAuthoringTypes } from "./authoring-type-constructors-F4JpCJl7.mjs";
|
|
2
|
-
import { t as SqlContractSerializer } from "./sql-contract-serializer-
|
|
3
|
-
import { a as extractCodecControlHooks, t as verifySqlSchema } from "./verify-sql-schema-
|
|
2
|
+
import { t as SqlContractSerializer } from "./sql-contract-serializer-8axtK4lg.mjs";
|
|
3
|
+
import { a as extractCodecControlHooks, t as verifySqlSchema } from "./verify-sql-schema-CYLsGCFO.mjs";
|
|
4
4
|
import { t as collectSupportedCodecTypeIds } from "./verify-Crewz6hG.mjs";
|
|
5
|
-
import { n as temporalAuthoringPresets, r as timestampNowControlDescriptor } from "./timestamp-now-generator-
|
|
5
|
+
import { n as temporalAuthoringPresets, r as timestampNowControlDescriptor } from "./timestamp-now-generator-BkjCQIde.mjs";
|
|
6
6
|
import { sqlEmission } from "@prisma-next/sql-contract-emitter";
|
|
7
7
|
import { APP_SPACE_ID, SchemaTreeNode, VERIFY_CODE_HASH_MISMATCH, VERIFY_CODE_MARKER_MISSING, VERIFY_CODE_TARGET_MISMATCH, assembleAuthoringContributions } from "@prisma-next/framework-components/control";
|
|
8
8
|
import { assertDescriptorSelfConsistency } from "@prisma-next/migration-tools/spaces";
|
|
9
|
+
import { sqlContractCanonicalizationHooks } from "@prisma-next/sql-contract/canonicalization-hooks";
|
|
9
10
|
import { ensureSchemaStatement, ensureTableStatement, writeContractMarker } from "@prisma-next/sql-runtime";
|
|
10
11
|
import { defaultIndexName } from "@prisma-next/sql-schema-ir/naming";
|
|
11
12
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
13
|
+
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
12
14
|
import { StorageTable, isPostgresEnumStorageEntry, isStorageTypeInstance, toStorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
13
15
|
import { UNSPECIFIED_PSL_NAMESPACE_ID } from "@prisma-next/framework-components/psl-ast";
|
|
14
16
|
import { notOk, ok } from "@prisma-next/utils/result";
|
|
@@ -1055,9 +1057,6 @@ function createVerifyResult(options) {
|
|
|
1055
1057
|
if (options.codecCoverageSkipped) result.codecCoverageSkipped = options.codecCoverageSkipped;
|
|
1056
1058
|
return result;
|
|
1057
1059
|
}
|
|
1058
|
-
function isSqlControlAdapter(value) {
|
|
1059
|
-
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";
|
|
1060
|
-
}
|
|
1061
1060
|
function buildSqlTypeMetadataRegistry(options) {
|
|
1062
1061
|
const { target, adapter, extensionPacks: extensions } = options;
|
|
1063
1062
|
const registry = /* @__PURE__ */ new Map();
|
|
@@ -1091,7 +1090,8 @@ function createSqlFamilyInstance(stack) {
|
|
|
1091
1090
|
target: contractJson.target,
|
|
1092
1091
|
targetFamily: contractJson.targetFamily,
|
|
1093
1092
|
storage: contractJson.storage,
|
|
1094
|
-
headRefHash: headRef.hash
|
|
1093
|
+
headRefHash: headRef.hash,
|
|
1094
|
+
...sqlContractCanonicalizationHooks
|
|
1095
1095
|
});
|
|
1096
1096
|
}
|
|
1097
1097
|
const { codecTypeImports, extensionIds } = stack;
|
|
@@ -1100,11 +1100,7 @@ function createSqlFamilyInstance(stack) {
|
|
|
1100
1100
|
adapter,
|
|
1101
1101
|
extensionPacks: extensions
|
|
1102
1102
|
});
|
|
1103
|
-
const getControlAdapter = () =>
|
|
1104
|
-
const controlAdapter = adapter.create(stack);
|
|
1105
|
-
if (!isSqlControlAdapter(controlAdapter)) throw new Error("Adapter does not implement SqlControlAdapter (missing introspect, readMarker, or readAllMarkers)");
|
|
1106
|
-
return controlAdapter;
|
|
1107
|
-
};
|
|
1103
|
+
const getControlAdapter = () => adapter.create(stack);
|
|
1108
1104
|
const targetSerializer = target.contractSerializer;
|
|
1109
1105
|
const deserializeWithTargetSerializer = (contractJson) => {
|
|
1110
1106
|
return (targetSerializer ?? new SqlContractSerializer()).deserializeContract(contractJson);
|
|
@@ -1211,6 +1207,7 @@ function createSqlFamilyInstance(stack) {
|
|
|
1211
1207
|
verifySchema(options) {
|
|
1212
1208
|
const contract = deserializeWithTargetSerializer(options.contract);
|
|
1213
1209
|
const controlAdapter = getControlAdapter();
|
|
1210
|
+
const resolveExistingEnumValues = controlAdapter.resolveExistingEnumValuesForContract?.(contract) ?? controlAdapter.resolveExistingEnumValues;
|
|
1214
1211
|
return verifySqlSchema({
|
|
1215
1212
|
contract,
|
|
1216
1213
|
schema: options.schema,
|
|
@@ -1219,7 +1216,7 @@ function createSqlFamilyInstance(stack) {
|
|
|
1219
1216
|
frameworkComponents: options.frameworkComponents,
|
|
1220
1217
|
...ifDefined("normalizeDefault", controlAdapter.normalizeDefault),
|
|
1221
1218
|
...ifDefined("normalizeNativeType", controlAdapter.normalizeNativeType),
|
|
1222
|
-
...ifDefined("resolveExistingEnumValues",
|
|
1219
|
+
...ifDefined("resolveExistingEnumValues", resolveExistingEnumValues)
|
|
1223
1220
|
});
|
|
1224
1221
|
},
|
|
1225
1222
|
async sign(options) {
|
|
@@ -1298,6 +1295,9 @@ function createSqlFamilyInstance(stack) {
|
|
|
1298
1295
|
async readAllMarkers(options) {
|
|
1299
1296
|
return getControlAdapter().readAllMarkers(options.driver);
|
|
1300
1297
|
},
|
|
1298
|
+
async readLedger(options) {
|
|
1299
|
+
return getControlAdapter().readLedger(options.driver, options.space);
|
|
1300
|
+
},
|
|
1301
1301
|
async introspect(options) {
|
|
1302
1302
|
return getControlAdapter().introspect(options.driver, options.contract);
|
|
1303
1303
|
},
|
|
@@ -1465,7 +1465,9 @@ function convertForeignKey(fk) {
|
|
|
1465
1465
|
referencedTable: fk.target.tableName,
|
|
1466
1466
|
referencedSchema: fk.target.namespaceId,
|
|
1467
1467
|
referencedColumns: fk.target.columns,
|
|
1468
|
-
...ifDefined("name", fk.name)
|
|
1468
|
+
...ifDefined("name", fk.name),
|
|
1469
|
+
...ifDefined("onDelete", fk.onDelete),
|
|
1470
|
+
...ifDefined("onUpdate", fk.onUpdate)
|
|
1469
1471
|
};
|
|
1470
1472
|
}
|
|
1471
1473
|
function convertTable(name, table, storageTypes, expandNativeType, renderDefault) {
|
|
@@ -1557,8 +1559,8 @@ function contractToSchemaIR(contract, options) {
|
|
|
1557
1559
|
const storage = contract.storage;
|
|
1558
1560
|
const allTypes = { ...storage.types ?? {} };
|
|
1559
1561
|
for (const ns of Object.values(storage.namespaces)) {
|
|
1560
|
-
const
|
|
1561
|
-
if (
|
|
1562
|
+
const nsEnums = ns.enum;
|
|
1563
|
+
if (nsEnums) for (const [k, v] of Object.entries(nsEnums)) allTypes[k] = v;
|
|
1562
1564
|
}
|
|
1563
1565
|
const storageTypes = allTypes;
|
|
1564
1566
|
const tables = {};
|
|
@@ -1570,30 +1572,44 @@ function contractToSchemaIR(contract, options) {
|
|
|
1570
1572
|
}
|
|
1571
1573
|
return {
|
|
1572
1574
|
tables,
|
|
1573
|
-
...ifDefined("annotations", deriveAnnotations(storage, options.annotationNamespace))
|
|
1575
|
+
...ifDefined("annotations", deriveAnnotations(storage, options.annotationNamespace, options.resolveEnumStorageKey))
|
|
1574
1576
|
};
|
|
1575
1577
|
}
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1578
|
+
/**
|
|
1579
|
+
* Normalises a native enum storage entry to the codec-typed annotation shape
|
|
1580
|
+
* `{codecId, nativeType, typeParams}` the introspector writes and
|
|
1581
|
+
* `readExistingEnumValues` reads (`existing.codecId` + `existing.typeParams.values`).
|
|
1582
|
+
* Without this the projector would emit the raw `PostgresEnumStorageEntry`
|
|
1583
|
+
* shape (top-level `values`, no `typeParams`) and the enum would read as new.
|
|
1584
|
+
*/
|
|
1585
|
+
function normalizeEnumAnnotation(entry) {
|
|
1586
|
+
return toStorageTypeInstance({
|
|
1587
|
+
codecId: entry.codecId,
|
|
1588
|
+
nativeType: entry.nativeType,
|
|
1589
|
+
typeParams: { values: entry.values }
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
function deriveAnnotations(storage, annotationNamespace, resolveEnumStorageKey) {
|
|
1593
|
+
const storageTypes = {};
|
|
1594
|
+
for (const typeInstance of Object.values(storage.types ?? {})) {
|
|
1586
1595
|
if (isPostgresEnumStorageEntry(typeInstance)) {
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
nativeType: typeInstance.nativeType,
|
|
1590
|
-
typeParams: { values: typeInstance.values }
|
|
1591
|
-
});
|
|
1596
|
+
const key = resolveEnumStorageKey ? resolveEnumStorageKey(storage, UNBOUND_NAMESPACE_ID, typeInstance.nativeType) : typeInstance.nativeType;
|
|
1597
|
+
storageTypes[key] = normalizeEnumAnnotation(typeInstance);
|
|
1592
1598
|
continue;
|
|
1593
1599
|
}
|
|
1594
|
-
if (isStorageTypeInstance(typeInstance))
|
|
1600
|
+
if (isStorageTypeInstance(typeInstance)) storageTypes[typeInstance.nativeType] = typeInstance;
|
|
1601
|
+
}
|
|
1602
|
+
for (const [namespaceId, ns] of Object.entries(storage.namespaces)) {
|
|
1603
|
+
const nsEnums = ns.enum;
|
|
1604
|
+
if (!nsEnums) continue;
|
|
1605
|
+
for (const entry of Object.values(nsEnums)) {
|
|
1606
|
+
if (!isPostgresEnumStorageEntry(entry)) continue;
|
|
1607
|
+
const key = resolveEnumStorageKey ? resolveEnumStorageKey(storage, namespaceId, entry.nativeType) : entry.nativeType;
|
|
1608
|
+
storageTypes[key] = normalizeEnumAnnotation(entry);
|
|
1609
|
+
}
|
|
1595
1610
|
}
|
|
1596
|
-
|
|
1611
|
+
if (Object.keys(storageTypes).length === 0) return void 0;
|
|
1612
|
+
return { [annotationNamespace]: { storageTypes } };
|
|
1597
1613
|
}
|
|
1598
1614
|
//#endregion
|
|
1599
1615
|
//#region src/core/migrations/field-event-planner.ts
|