@prisma-next/sql-contract 0.15.0 → 0.16.0-dev.2
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/canonicalization-hooks.d.mts +0 -1
- package/dist/canonicalization-hooks.d.mts.map +1 -1
- package/dist/canonicalization-hooks.mjs +0 -10
- package/dist/canonicalization-hooks.mjs.map +1 -1
- package/dist/contract-view.d.mts +1 -2
- package/dist/contract-view.d.mts.map +1 -1
- package/dist/entity-handle-lowering-hook.d.mts.map +1 -1
- package/dist/{entity-kinds-BEPZdFBN.mjs → entity-kinds-CVg6HzG2.mjs} +4 -6
- package/dist/entity-kinds-CVg6HzG2.mjs.map +1 -0
- package/dist/entity-kinds.d.mts +2 -3
- package/dist/entity-kinds.d.mts.map +1 -1
- package/dist/entity-kinds.mjs +1 -1
- package/dist/factories.d.mts +4 -6
- package/dist/factories.d.mts.map +1 -1
- package/dist/factories.mjs +2 -9
- package/dist/factories.mjs.map +1 -1
- package/dist/{foreign-key-DM1UTydh.d.mts → foreign-key-CWCEM2IT.d.mts} +11 -10
- package/dist/foreign-key-CWCEM2IT.d.mts.map +1 -0
- package/dist/foreign-key-materialization.d.mts +63 -0
- package/dist/foreign-key-materialization.d.mts.map +1 -0
- package/dist/foreign-key-materialization.mjs +67 -0
- package/dist/foreign-key-materialization.mjs.map +1 -0
- package/dist/index-type-validation.d.mts +3 -3
- package/dist/index-type-validation.d.mts.map +1 -1
- package/dist/{index-types-Czsyu7Iw.d.mts → index-types-DPVhsW0v.d.mts} +2 -3
- package/dist/index-types-DPVhsW0v.d.mts.map +1 -0
- package/dist/index-types.d.mts +1 -1
- package/dist/pack-types.d.mts.map +1 -1
- package/dist/referential-action-sql.d.mts +1 -2
- package/dist/referential-action-sql.d.mts.map +1 -1
- package/dist/resolve-storage-table.d.mts +2 -3
- package/dist/resolve-storage-table.d.mts.map +1 -1
- package/dist/{sql-node-V214WXQD.d.mts → sql-node-QXu33IeX.d.mts} +1 -2
- package/dist/sql-node-QXu33IeX.d.mts.map +1 -0
- package/dist/{sql-storage-Dt5ipcRl.d.mts → sql-storage-BIErcfFA.d.mts} +4 -5
- package/dist/sql-storage-BIErcfFA.d.mts.map +1 -0
- package/dist/{storage-table-y6R6pxyI.mjs → storage-table-DBpYBmty.mjs} +10 -6
- package/dist/storage-table-DBpYBmty.mjs.map +1 -0
- package/dist/{storage-table-Bj1ZN1P7.d.mts → storage-table-mNGckl3_.d.mts} +5 -56
- package/dist/storage-table-mNGckl3_.d.mts.map +1 -0
- package/dist/{storage-value-set-Tx3CFoS_.mjs → storage-value-set-3BKuha5q.mjs} +2 -2
- package/dist/{storage-value-set-Tx3CFoS_.mjs.map → storage-value-set-3BKuha5q.mjs.map} +1 -1
- package/dist/{storage-value-set-D-jww77l.d.mts → storage-value-set-DPHvvSdB.d.mts} +2 -3
- package/dist/storage-value-set-DPHvvSdB.d.mts.map +1 -0
- package/dist/{types-zBvpNCmg.d.mts → types-lpzJtKpv.d.mts} +8 -4
- package/dist/types-lpzJtKpv.d.mts.map +1 -0
- package/dist/types.d.mts +8 -8
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +12 -3
- package/dist/types.mjs.map +1 -1
- package/dist/unique-constraint-WHfanEUq.d.mts +54 -0
- package/dist/unique-constraint-WHfanEUq.d.mts.map +1 -0
- package/dist/validators.d.mts +4 -4
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +2 -4
- package/dist/validators.mjs.map +1 -1
- package/dist/value-set-derivation-hook.d.mts +1 -2
- package/dist/value-set-derivation-hook.d.mts.map +1 -1
- package/package.json +10 -8
- package/src/canonicalization-hooks.ts +1 -2
- package/src/exports/foreign-key-materialization.ts +8 -0
- package/src/factories.ts +1 -5
- package/src/foreign-key-materialization.ts +107 -0
- package/src/ir/foreign-key.ts +9 -9
- package/src/ir/storage-entry-schemas.ts +0 -2
- package/src/validators.ts +0 -2
- package/dist/entity-kinds-BEPZdFBN.mjs.map +0 -1
- package/dist/foreign-key-DM1UTydh.d.mts.map +0 -1
- package/dist/index-types-Czsyu7Iw.d.mts.map +0 -1
- package/dist/sql-node-V214WXQD.d.mts.map +0 -1
- package/dist/sql-storage-Dt5ipcRl.d.mts.map +0 -1
- package/dist/storage-table-Bj1ZN1P7.d.mts.map +0 -1
- package/dist/storage-table-y6R6pxyI.mjs.map +0 -1
- package/dist/storage-value-set-D-jww77l.d.mts.map +0 -1
- package/dist/types-Hkxybhdj.mjs +0 -13
- package/dist/types-Hkxybhdj.mjs.map +0 -1
- package/dist/types-zBvpNCmg.d.mts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonicalization-hooks.d.mts","names":[],"sources":["../src/canonicalization-hooks.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"canonicalization-hooks.d.mts","names":[],"sources":["../src/canonicalization-hooks.ts"],"mappings":";;cAoDa;WACF,qBAAqB;WACrB,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonicalization-hooks.mjs","names":[],"sources":["../src/canonicalization-hooks.ts"],"sourcesContent":["import type { PreserveEmptyPredicate, StorageSort } from '@prisma-next/contract/hashing';\nimport {\n createPreserveEmptyPredicate,\n createStorageSort,\n matchesPathPattern,\n type NamedArraySortTarget,\n type PathPattern,\n} from '@prisma-next/contract/hashing-utils';\n\nconst preserveEmptyPatterns = [\n ['storage', 'namespaces', '*', 'entries', 'table'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', ['uniques', 'indexes', 'foreignKeys']],\n
|
|
1
|
+
{"version":3,"file":"canonicalization-hooks.mjs","names":[],"sources":["../src/canonicalization-hooks.ts"],"sourcesContent":["import type { PreserveEmptyPredicate, StorageSort } from '@prisma-next/contract/hashing';\nimport {\n createPreserveEmptyPredicate,\n createStorageSort,\n matchesPathPattern,\n type NamedArraySortTarget,\n type PathPattern,\n} from '@prisma-next/contract/hashing-utils';\n\nconst preserveEmptyPatterns = [\n ['storage', 'namespaces', '*', 'entries', 'table'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', ['uniques', 'indexes', 'foreignKeys']],\n // A column default's literal payload is data, not shape — `{ kind:\n // 'literal', value: false }` (or `value: []`) must survive the\n // default-omission walk or the emitted contract fails its own\n // validation on the next read (CONTRACT.VALIDATION_FAILED on `Boolean @default(false)`).\n ['storage', 'namespaces', '*', 'entries', 'table', '*', 'columns', '*', 'default', 'value'],\n] as const satisfies readonly PathPattern[];\n\n// A literal column default's value is user data, not omittable structure:\n// `@default(false)` (and empty objects/arrays at any depth inside the value)\n// must survive canonicalization, or the emitted contract fails the runtime's\n// structural validation with `default.value … (was missing)`.\nconst columnDefaultValuePrefix = [\n 'storage',\n 'namespaces',\n '*',\n 'entries',\n 'table',\n '*',\n 'columns',\n '*',\n 'default',\n 'value',\n] as const satisfies PathPattern;\n\nconst isColumnDefaultValuePath = (path: readonly string[]): boolean =>\n path.length >= columnDefaultValuePrefix.length &&\n matchesPathPattern(path.slice(0, columnDefaultValuePrefix.length), columnDefaultValuePrefix);\n\nconst sortTargets = [\n { path: ['namespaces', '*', 'entries', 'table', '*'], arrayKeys: ['indexes', 'uniques'] },\n] as const satisfies readonly NamedArraySortTarget[];\n\nconst matchesPreserveEmptyPattern = createPreserveEmptyPredicate(preserveEmptyPatterns);\n\nconst shouldPreserveEmpty: PreserveEmptyPredicate = (path) =>\n isColumnDefaultValuePath(path) || matchesPreserveEmptyPattern(path);\n\nconst sortStorage: StorageSort = createStorageSort(sortTargets);\n\nexport const sqlContractCanonicalizationHooks: {\n readonly shouldPreserveEmpty: PreserveEmptyPredicate;\n readonly sortStorage: StorageSort;\n} = {\n shouldPreserveEmpty,\n sortStorage,\n};\n"],"mappings":";;AASA,MAAM,wBAAwB;CAC5B;EAAC;EAAW;EAAc;EAAK;EAAW;CAAO;CACjD;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;CAAG;CACtD;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;EAAK;GAAC;GAAW;GAAW;EAAa;CAAC;CAK7F;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;EAAK;EAAW;EAAK;EAAW;CAAO;AAC5F;AAMA,MAAM,2BAA2B;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,4BAA4B,SAChC,KAAK,UAAU,yBAAyB,UACxC,mBAAmB,KAAK,MAAM,GAAG,yBAAyB,MAAM,GAAG,wBAAwB;AAE7F,MAAM,cAAc,CAClB;CAAE,MAAM;EAAC;EAAc;EAAK;EAAW;EAAS;CAAG;CAAG,WAAW,CAAC,WAAW,SAAS;AAAE,CAC1F;AAEA,MAAM,8BAA8B,6BAA6B,qBAAqB;AAEtF,MAAM,uBAA+C,SACnD,yBAAyB,IAAI,KAAK,4BAA4B,IAAI;AAIpE,MAAa,mCAGT;CACF;CACA,aAP+B,kBAAkB,WAOjD;AACF"}
|
package/dist/contract-view.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { s as SqlStorage } from "./sql-storage-
|
|
1
|
+
import { s as SqlStorage } from "./sql-storage-BIErcfFA.mjs";
|
|
2
2
|
import { DefaultNamespaceEntries, NamespacedEntities, SingleNamespaceView } from "@prisma-next/framework-components/ir";
|
|
3
3
|
import { Contract } from "@prisma-next/contract/types";
|
|
4
|
-
|
|
5
4
|
//#region src/contract-view.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* The SQL family's statically-named built-in entity kinds. `table` and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract-view.d.mts","names":[],"sources":["../src/contract-view.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"contract-view.d.mts","names":[],"sources":["../src/contract-view.ts"],"mappings":";;;;;;;;;cAea;KACD,yBAAyB;KAEhC,WAAW,kBAAkB,SAAS,eAAe,wBACxD;;;;;;;KASU,4BAA4B,kBAAkB,SAAS,eACjE,oBAAoB,WAAW,YAAY;;;;;;;;;;KAWjC,uBAAuB,kBAAkB,SAAS,eAAe,YAC3E,4BAA4B;WACjB,WAAW,mBAAmB,sBAAsB;;;;;;;;;iBAUjD,4BAA4B,kBAAkB,SAAS,aACrE,UAAU,YACT,uBAAuB;;;;;;;;;;;KAyBd,uBAAuB,kBAAkB,SAAS,eAAe;WAClE,WAAW,mBAAmB,sBAAsB;;;;;;iBAO/C,4BAA4B,kBAAkB,SAAS,aACrE,UAAU,YACT,uBAAuB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-handle-lowering-hook.d.mts","names":[],"sources":["../src/entity-handle-lowering-hook.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"entity-handle-lowering-hook.d.mts","names":[],"sources":["../src/entity-handle-lowering-hook.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;UAwBiB;WACN;WACA,OAAO,SAAS;;;;;;;;;KAUf;WAEG;WACA;WACA;WACA;;WAGA;WACA;WACA;WACA;WACA;;WAGA;WACA;;;UAIE;WACN,QAAQ;WACR,MAAM,SAAS,eAAe;;UAGxB;;WAEN,kBAAkB;WAClB;;;UAIM;WACN;WACA;WACA;WACA;;UAGM;;;;;;EAMf,mBAAmB,OAAO,qCAAqC;;;iBAIjD,6BACd,qBACC,aAAa;;;;;;;;;KAgBJ,uBAAuB,SAAS;WAA0B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as StorageTable } from "./storage-table-
|
|
2
|
-
import { t as StorageValueSet } from "./storage-value-set-
|
|
1
|
+
import { t as StorageTable } from "./storage-table-DBpYBmty.mjs";
|
|
2
|
+
import { t as StorageValueSet } from "./storage-value-set-3BKuha5q.mjs";
|
|
3
3
|
import { type } from "arktype";
|
|
4
4
|
//#region src/ir/storage-entry-schemas.ts
|
|
5
5
|
const literalKindSchema = type("'literal'");
|
|
@@ -78,9 +78,7 @@ const ForeignKeySchema = type.declare().type({
|
|
|
78
78
|
target: ForeignKeyReferenceSchema,
|
|
79
79
|
"name?": "string",
|
|
80
80
|
"onDelete?": ReferentialActionSchema,
|
|
81
|
-
"onUpdate?": ReferentialActionSchema
|
|
82
|
-
constraint: "boolean",
|
|
83
|
-
index: "boolean"
|
|
81
|
+
"onUpdate?": ReferentialActionSchema
|
|
84
82
|
});
|
|
85
83
|
const CheckConstraintSchema = type({
|
|
86
84
|
"+": "reject",
|
|
@@ -129,4 +127,4 @@ function composeSqlEntityKinds(packKinds = []) {
|
|
|
129
127
|
//#endregion
|
|
130
128
|
export { ColumnDefaultFunctionSchema as a, ForeignKeyReferenceSchema as c, IndexSchema as d, ReferentialActionSchema as f, CheckConstraintSchema as i, ForeignKeySchema as l, StorageValueSetSchema as m, tableEntityKind as n, ColumnDefaultLiteralSchema as o, StorageTableSchema as p, valueSetEntityKind as r, ColumnDefaultSchema as s, composeSqlEntityKinds as t, ForeignKeySourceSchema as u };
|
|
131
129
|
|
|
132
|
-
//# sourceMappingURL=entity-kinds-
|
|
130
|
+
//# sourceMappingURL=entity-kinds-CVg6HzG2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-kinds-CVg6HzG2.mjs","names":[],"sources":["../src/ir/storage-entry-schemas.ts","../src/entity-kinds.ts"],"sourcesContent":["import { type Type, type } from 'arktype';\nimport type { ForeignKeyInput, ReferentialAction } from './foreign-key';\nimport type { ForeignKeyReferenceInput } from './foreign-key-reference';\nimport type { PrimaryKeyInput } from './primary-key';\nimport type { UniqueConstraintInput } from './unique-constraint';\n\ntype ColumnDefaultLiteral = {\n readonly kind: 'literal';\n readonly value: string | number | boolean | Record<string, unknown> | unknown[] | null;\n};\ntype ColumnDefaultFunction = { readonly kind: 'function'; readonly expression: string };\n\nconst literalKindSchema = type(\"'literal'\");\nconst functionKindSchema = type(\"'function'\");\nconst ControlPolicySchema = type(\"'managed' | 'tolerated' | 'external' | 'observed'\");\n\nexport const ColumnDefaultLiteralSchema = type.declare<ColumnDefaultLiteral>().type({\n kind: literalKindSchema,\n value: 'string | number | boolean | null | unknown[] | Record<string, unknown>',\n});\n\nexport const ColumnDefaultFunctionSchema = type.declare<ColumnDefaultFunction>().type({\n kind: functionKindSchema,\n expression: 'string',\n});\n\nexport const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);\n\nconst StorageValueSetRefSchema = type({\n plane: \"'storage'\",\n namespaceId: 'string',\n entityKind: \"'valueSet'\",\n entityName: 'string',\n 'spaceId?': 'string',\n});\n\nconst StorageColumnSchema = type({\n '+': 'reject',\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\n 'many?': 'boolean',\n 'typeParams?': 'Record<string, unknown>',\n 'typeRef?': 'string',\n 'default?': ColumnDefaultSchema,\n 'control?': ControlPolicySchema,\n 'valueSet?': StorageValueSetRefSchema,\n}).narrow((col, ctx) => {\n if (col.typeParams !== undefined && col.typeRef !== undefined) {\n return ctx.mustBe('a column with either typeParams or typeRef, not both');\n }\n return true;\n});\n\n/**\n * Storage value-set entry under `storage.namespaces[id].entries.valueSet[name]`.\n * Carries a `kind: 'valueSet'` discriminator (enumerable, survives JSON) and an\n * ordered `values` array of codec-encoded permitted values.\n */\nexport const StorageValueSetSchema = type({\n kind: \"'valueSet'\",\n values: type('string | number | boolean | null | unknown[] | Record<string, unknown>')\n .array()\n .readonly(),\n});\n\nconst PrimaryKeySchema = type.declare<PrimaryKeyInput>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nconst UniqueConstraintSchema = type.declare<UniqueConstraintInput>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nexport const IndexSchema = type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n 'type?': 'string',\n 'options?': 'Record<string, unknown>',\n});\n\nexport const ForeignKeyReferenceSchema = type({\n '+': 'reject',\n namespaceId: 'string',\n tableName: 'string',\n columns: type.string.array().readonly(),\n 'spaceId?': 'string',\n}) satisfies Type<ForeignKeyReferenceInput>;\n\nexport const ForeignKeySourceSchema = type({\n '+': 'reject',\n namespaceId: 'string',\n tableName: 'string',\n columns: type.string.array().readonly(),\n}) satisfies Type<ForeignKeyReferenceInput>;\n\nexport const ReferentialActionSchema = type\n .declare<ReferentialAction>()\n .type(\"'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'\");\n\nexport const ForeignKeySchema = type.declare<ForeignKeyInput>().type({\n source: ForeignKeySourceSchema,\n target: ForeignKeyReferenceSchema,\n 'name?': 'string',\n 'onDelete?': ReferentialActionSchema,\n 'onUpdate?': ReferentialActionSchema,\n});\n\nexport const CheckConstraintSchema = type({\n '+': 'reject',\n name: 'string',\n column: 'string',\n valueSet: StorageValueSetRefSchema,\n});\n\nexport const StorageTableSchema = type({\n '+': 'reject',\n columns: type({ '[string]': StorageColumnSchema }),\n 'primaryKey?': PrimaryKeySchema,\n uniques: UniqueConstraintSchema.array().readonly(),\n indexes: IndexSchema.array().readonly(),\n foreignKeys: ForeignKeySchema.array().readonly(),\n 'control?': ControlPolicySchema,\n 'checks?': CheckConstraintSchema.array().readonly(),\n});\n","import type {\n AnyEntityKindDescriptor,\n EntityKindDescriptor,\n} from '@prisma-next/framework-components/ir';\nimport { StorageTableSchema, StorageValueSetSchema } from './ir/storage-entry-schemas';\nimport { StorageTable, type StorageTableInput } from './ir/storage-table';\nimport { StorageValueSet, type StorageValueSetInput } from './ir/storage-value-set';\n\nexport const tableEntityKind: EntityKindDescriptor<StorageTableInput, StorageTable> = {\n kind: 'table',\n schema: StorageTableSchema,\n construct: (input) => new StorageTable(input),\n};\n\nexport const valueSetEntityKind: EntityKindDescriptor<StorageValueSetInput, StorageValueSet> = {\n kind: 'valueSet',\n schema: StorageValueSetSchema,\n construct: (input) => new StorageValueSet(input),\n};\n\n/**\n * Assembles the `kind → descriptor` registry for SQL namespaces: the built-in\n * `table` and `valueSet` kinds plus any target `packKinds`. This builds the\n * lookup table — it does not touch contract data. `hydrateNamespaceEntities`\n * later consumes this registry to turn a namespace's raw entries into IR\n * instances, and `createSqlContractSchema` derives validation from the same\n * registry. Throws on a duplicate kind.\n */\nexport function composeSqlEntityKinds(\n packKinds: readonly AnyEntityKindDescriptor[] = [],\n): ReadonlyMap<string, AnyEntityKindDescriptor> {\n const kinds = new Map<string, AnyEntityKindDescriptor>([\n ['table', tableEntityKind],\n ['valueSet', valueSetEntityKind],\n ]);\n for (const descriptor of packKinds) {\n if (kinds.has(descriptor.kind)) {\n throw new Error(\n `composeSqlEntityKinds: duplicate entity kind \"${descriptor.kind}\" — each kind may be registered only once`,\n );\n }\n kinds.set(descriptor.kind, descriptor);\n }\n return kinds;\n}\n"],"mappings":";;;;AAYA,MAAM,oBAAoB,KAAK,WAAW;AAC1C,MAAM,qBAAqB,KAAK,YAAY;AAC5C,MAAM,sBAAsB,KAAK,mDAAmD;AAEpF,MAAa,6BAA6B,KAAK,QAA8B,CAAC,CAAC,KAAK;CAClF,MAAM;CACN,OAAO;AACT,CAAC;AAED,MAAa,8BAA8B,KAAK,QAA+B,CAAC,CAAC,KAAK;CACpF,MAAM;CACN,YAAY;AACd,CAAC;AAED,MAAa,sBAAsB,2BAA2B,GAAG,2BAA2B;AAE5F,MAAM,2BAA2B,KAAK;CACpC,OAAO;CACP,aAAa;CACb,YAAY;CACZ,YAAY;CACZ,YAAY;AACd,CAAC;AAED,MAAM,sBAAsB,KAAK;CAC/B,KAAK;CACL,YAAY;CACZ,SAAS;CACT,UAAU;CACV,SAAS;CACT,eAAe;CACf,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,aAAa;AACf,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ;CACtB,IAAI,IAAI,eAAe,KAAA,KAAa,IAAI,YAAY,KAAA,GAClD,OAAO,IAAI,OAAO,sDAAsD;CAE1E,OAAO;AACT,CAAC;;;;;;AAOD,MAAa,wBAAwB,KAAK;CACxC,MAAM;CACN,QAAQ,KAAK,wEAAwE,CAAC,CACnF,MAAM,CAAC,CACP,SAAS;AACd,CAAC;AAED,MAAM,mBAAmB,KAAK,QAAyB,CAAC,CAAC,KAAK;CAC5D,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACtC,SAAS;AACX,CAAC;AAED,MAAM,yBAAyB,KAAK,QAA+B,CAAC,CAAC,KAAK;CACxE,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACtC,SAAS;AACX,CAAC;AAED,MAAa,cAAc,KAAK;CAC9B,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACtC,SAAS;CACT,SAAS;CACT,YAAY;AACd,CAAC;AAED,MAAa,4BAA4B,KAAK;CAC5C,KAAK;CACL,aAAa;CACb,WAAW;CACX,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACtC,YAAY;AACd,CAAC;AAED,MAAa,yBAAyB,KAAK;CACzC,KAAK;CACL,aAAa;CACb,WAAW;CACX,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;AACxC,CAAC;AAED,MAAa,0BAA0B,KACpC,QAA2B,CAAC,CAC5B,KAAK,gEAAgE;AAExE,MAAa,mBAAmB,KAAK,QAAyB,CAAC,CAAC,KAAK;CACnE,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,aAAa;CACb,aAAa;AACf,CAAC;AAED,MAAa,wBAAwB,KAAK;CACxC,KAAK;CACL,MAAM;CACN,QAAQ;CACR,UAAU;AACZ,CAAC;AAED,MAAa,qBAAqB,KAAK;CACrC,KAAK;CACL,SAAS,KAAK,EAAE,YAAY,oBAAoB,CAAC;CACjD,eAAe;CACf,SAAS,uBAAuB,MAAM,CAAC,CAAC,SAAS;CACjD,SAAS,YAAY,MAAM,CAAC,CAAC,SAAS;CACtC,aAAa,iBAAiB,MAAM,CAAC,CAAC,SAAS;CAC/C,YAAY;CACZ,WAAW,sBAAsB,MAAM,CAAC,CAAC,SAAS;AACpD,CAAC;;;ACtHD,MAAa,kBAAyE;CACpF,MAAM;CACN,QAAQ;CACR,YAAY,UAAU,IAAI,aAAa,KAAK;AAC9C;AAEA,MAAa,qBAAkF;CAC7F,MAAM;CACN,QAAQ;CACR,YAAY,UAAU,IAAI,gBAAgB,KAAK;AACjD;;;;;;;;;AAUA,SAAgB,sBACd,YAAgD,CAAC,GACH;CAC9C,MAAM,wBAAQ,IAAI,IAAqC,CACrD,CAAC,SAAS,eAAe,GACzB,CAAC,YAAY,kBAAkB,CACjC,CAAC;CACD,KAAK,MAAM,cAAc,WAAW;EAClC,IAAI,MAAM,IAAI,WAAW,IAAI,GAC3B,MAAM,IAAI,MACR,iDAAiD,WAAW,KAAK,0CACnE;EAEF,MAAM,IAAI,WAAW,MAAM,UAAU;CACvC;CACA,OAAO;AACT"}
|
package/dist/entity-kinds.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { n as StorageTableInput, t as StorageTable } from "./storage-table-
|
|
2
|
-
import { n as StorageValueSetInput, t as StorageValueSet } from "./storage-value-set-
|
|
1
|
+
import { n as StorageTableInput, t as StorageTable } from "./storage-table-mNGckl3_.mjs";
|
|
2
|
+
import { n as StorageValueSetInput, t as StorageValueSet } from "./storage-value-set-DPHvvSdB.mjs";
|
|
3
3
|
import { AnyEntityKindDescriptor, EntityKindDescriptor } from "@prisma-next/framework-components/ir";
|
|
4
|
-
|
|
5
4
|
//#region src/entity-kinds.d.ts
|
|
6
5
|
declare const tableEntityKind: EntityKindDescriptor<StorageTableInput, StorageTable>;
|
|
7
6
|
declare const valueSetEntityKind: EntityKindDescriptor<StorageValueSetInput, StorageValueSet>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-kinds.d.mts","names":[],"sources":["../src/entity-kinds.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"entity-kinds.d.mts","names":[],"sources":["../src/entity-kinds.ts"],"mappings":";;;;cAQa,iBAAiB,qBAAqB,mBAAmB;cAMzD,oBAAoB,qBAAqB,sBAAsB;;;;;;;;;iBAc5D,sBACd,qBAAoB,4BACnB,oBAAoB"}
|
package/dist/entity-kinds.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as tableEntityKind, r as valueSetEntityKind, t as composeSqlEntityKinds } from "./entity-kinds-
|
|
1
|
+
import { n as tableEntityKind, r as valueSetEntityKind, t as composeSqlEntityKinds } from "./entity-kinds-CVg6HzG2.mjs";
|
|
2
2
|
export { composeSqlEntityKinds, tableEntityKind, valueSetEntityKind };
|
package/dist/factories.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as ForeignKey } from "./foreign-key-
|
|
3
|
-
import {
|
|
1
|
+
import { i as StorageColumnInput, r as StorageColumn, t as StorageTable } from "./storage-table-mNGckl3_.mjs";
|
|
2
|
+
import { t as ForeignKey } from "./foreign-key-CWCEM2IT.mjs";
|
|
3
|
+
import { a as PrimaryKey, r as Index, t as UniqueConstraint } from "./unique-constraint-WHfanEUq.mjs";
|
|
4
|
+
import { T as SqlModelStorage, m as ForeignKeyOptions, w as SqlModelFieldStorage } from "./types-lpzJtKpv.mjs";
|
|
4
5
|
import { ScalarFieldType } from "@prisma-next/contract/types";
|
|
5
|
-
|
|
6
6
|
//#region src/factories.d.ts
|
|
7
7
|
declare function col(nativeType: string, codecId: string, nullable?: boolean, opts?: {
|
|
8
8
|
readonly many?: boolean;
|
|
@@ -11,8 +11,6 @@ declare function pk(...columns: readonly string[]): PrimaryKey;
|
|
|
11
11
|
declare function unique(...columns: readonly string[]): UniqueConstraint;
|
|
12
12
|
declare function index(...columns: readonly string[]): Index;
|
|
13
13
|
declare function fk(srcTableName: string, srcColumns: readonly string[], targetTableName: string, targetColumns: readonly string[], opts?: ForeignKeyOptions & {
|
|
14
|
-
constraint?: boolean;
|
|
15
|
-
index?: boolean;
|
|
16
14
|
namespaceId?: string;
|
|
17
15
|
}): ForeignKey;
|
|
18
16
|
declare function table(columns: Record<string, StorageColumn | StorageColumnInput>, opts?: {
|
package/dist/factories.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.d.mts","names":[],"sources":["../src/factories.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"factories.d.mts","names":[],"sources":["../src/factories.ts"],"mappings":";;;;;;iBAegB,IACd,oBACA,iBACA,oBACA;WAAkB;IACjB;iBASa,MAAM,6BAA6B;iBAInC,UAAU,6BAA6B;iBAIvC,SAAS,6BAA6B;iBAItC,GACd,sBACA,+BACA,yBACA,kCACA,OAAO;EAAsB;IAC5B;iBAWa,MACd,SAAS,eAAe,gBAAgB,qBACxC;EACE,KAAK;EACL,mBAAmB;EACnB,mBAAmB;EACnB,eAAe;IAEhB;iBAUa,MACd,mBACA,QAAQ,eAAe,uBACvB,YAAW,yBACX;EAEA,SAAS;EACT,QAAQ;aAA0B;aAA4B,MAAM;;EACpE,WAAW"}
|
package/dist/factories.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { a as PrimaryKey, i as Index, n as UniqueConstraint, o as ForeignKey, r as StorageColumn, t as StorageTable } from "./storage-table-
|
|
2
|
-
import { r as applyFkDefaults } from "./types-Hkxybhdj.mjs";
|
|
1
|
+
import { a as PrimaryKey, i as Index, n as UniqueConstraint, o as ForeignKey, r as StorageColumn, t as StorageTable } from "./storage-table-DBpYBmty.mjs";
|
|
3
2
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
4
3
|
import { asNamespaceId } from "@prisma-next/contract/types";
|
|
5
4
|
//#region src/factories.ts
|
|
@@ -21,10 +20,6 @@ function index(...columns) {
|
|
|
21
20
|
return new Index({ columns });
|
|
22
21
|
}
|
|
23
22
|
function fk(srcTableName, srcColumns, targetTableName, targetColumns, opts) {
|
|
24
|
-
const defaults = applyFkDefaults({
|
|
25
|
-
constraint: opts?.constraint,
|
|
26
|
-
index: opts?.index
|
|
27
|
-
});
|
|
28
23
|
const namespaceId = asNamespaceId(opts?.namespaceId ?? UNBOUND_NAMESPACE_ID);
|
|
29
24
|
return new ForeignKey({
|
|
30
25
|
source: {
|
|
@@ -39,9 +34,7 @@ function fk(srcTableName, srcColumns, targetTableName, targetColumns, opts) {
|
|
|
39
34
|
},
|
|
40
35
|
...opts?.name !== void 0 && { name: opts.name },
|
|
41
36
|
...opts?.onDelete !== void 0 && { onDelete: opts.onDelete },
|
|
42
|
-
...opts?.onUpdate !== void 0 && { onUpdate: opts.onUpdate }
|
|
43
|
-
constraint: defaults.constraint,
|
|
44
|
-
index: defaults.index
|
|
37
|
+
...opts?.onUpdate !== void 0 && { onUpdate: opts.onUpdate }
|
|
45
38
|
});
|
|
46
39
|
}
|
|
47
40
|
function table(columns, opts) {
|
package/dist/factories.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.mjs","names":[],"sources":["../src/factories.ts"],"sourcesContent":["import { asNamespaceId, type ScalarFieldType } from '@prisma-next/contract/types';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport {\n
|
|
1
|
+
{"version":3,"file":"factories.mjs","names":[],"sources":["../src/factories.ts"],"sourcesContent":["import { asNamespaceId, type ScalarFieldType } from '@prisma-next/contract/types';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport {\n ForeignKey,\n type ForeignKeyOptions,\n Index,\n PrimaryKey,\n type SqlModelFieldStorage,\n type SqlModelStorage,\n StorageColumn,\n type StorageColumnInput,\n StorageTable,\n UniqueConstraint,\n} from './types';\n\nexport function col(\n nativeType: string,\n codecId: string,\n nullable = false,\n opts?: { readonly many?: boolean },\n): StorageColumn {\n return new StorageColumn({\n nativeType,\n codecId,\n nullable,\n ...(opts?.many !== undefined && { many: opts.many }),\n });\n}\n\nexport function pk(...columns: readonly string[]): PrimaryKey {\n return new PrimaryKey({ columns });\n}\n\nexport function unique(...columns: readonly string[]): UniqueConstraint {\n return new UniqueConstraint({ columns });\n}\n\nexport function index(...columns: readonly string[]): Index {\n return new Index({ columns });\n}\n\nexport function fk(\n srcTableName: string,\n srcColumns: readonly string[],\n targetTableName: string,\n targetColumns: readonly string[],\n opts?: ForeignKeyOptions & { namespaceId?: string },\n): ForeignKey {\n const namespaceId = asNamespaceId(opts?.namespaceId ?? UNBOUND_NAMESPACE_ID);\n return new ForeignKey({\n source: { namespaceId, tableName: srcTableName, columns: srcColumns },\n target: { namespaceId, tableName: targetTableName, columns: targetColumns },\n ...(opts?.name !== undefined && { name: opts.name }),\n ...(opts?.onDelete !== undefined && { onDelete: opts.onDelete }),\n ...(opts?.onUpdate !== undefined && { onUpdate: opts.onUpdate }),\n });\n}\n\nexport function table(\n columns: Record<string, StorageColumn | StorageColumnInput>,\n opts?: {\n pk?: PrimaryKey;\n uniques?: readonly UniqueConstraint[];\n indexes?: readonly Index[];\n fks?: readonly ForeignKey[];\n },\n): StorageTable {\n return new StorageTable({\n columns,\n ...(opts?.pk !== undefined && { primaryKey: opts.pk }),\n uniques: opts?.uniques ?? [],\n indexes: opts?.indexes ?? [],\n foreignKeys: opts?.fks ?? [],\n });\n}\n\nexport function model(\n tableName: string,\n fields: Record<string, SqlModelFieldStorage>,\n relations: Record<string, unknown> = {},\n namespaceId: string = UNBOUND_NAMESPACE_ID,\n): {\n storage: SqlModelStorage;\n fields: Record<string, { readonly nullable: boolean; readonly type: ScalarFieldType }>;\n relations: Record<string, unknown>;\n} {\n const storage: SqlModelStorage = { table: tableName, namespaceId, fields };\n const domainFields = Object.fromEntries(\n Object.entries(fields).map(([name, field]) => [\n name,\n {\n nullable: field.nullable ?? false,\n type: { kind: 'scalar' as const, codecId: field.codecId ?? 'core/unknown@1' },\n },\n ]),\n ) as Record<string, { nullable: boolean; type: ScalarFieldType }>;\n return {\n storage,\n fields: domainFields,\n relations,\n };\n}\n"],"mappings":";;;;AAeA,SAAgB,IACd,YACA,SACA,WAAW,OACX,MACe;CACf,OAAO,IAAI,cAAc;EACvB;EACA;EACA;EACA,GAAI,MAAM,SAAS,KAAA,KAAa,EAAE,MAAM,KAAK,KAAK;CACpD,CAAC;AACH;AAEA,SAAgB,GAAG,GAAG,SAAwC;CAC5D,OAAO,IAAI,WAAW,EAAE,QAAQ,CAAC;AACnC;AAEA,SAAgB,OAAO,GAAG,SAA8C;CACtE,OAAO,IAAI,iBAAiB,EAAE,QAAQ,CAAC;AACzC;AAEA,SAAgB,MAAM,GAAG,SAAmC;CAC1D,OAAO,IAAI,MAAM,EAAE,QAAQ,CAAC;AAC9B;AAEA,SAAgB,GACd,cACA,YACA,iBACA,eACA,MACY;CACZ,MAAM,cAAc,cAAc,MAAM,eAAe,oBAAoB;CAC3E,OAAO,IAAI,WAAW;EACpB,QAAQ;GAAE;GAAa,WAAW;GAAc,SAAS;EAAW;EACpE,QAAQ;GAAE;GAAa,WAAW;GAAiB,SAAS;EAAc;EAC1E,GAAI,MAAM,SAAS,KAAA,KAAa,EAAE,MAAM,KAAK,KAAK;EAClD,GAAI,MAAM,aAAa,KAAA,KAAa,EAAE,UAAU,KAAK,SAAS;EAC9D,GAAI,MAAM,aAAa,KAAA,KAAa,EAAE,UAAU,KAAK,SAAS;CAChE,CAAC;AACH;AAEA,SAAgB,MACd,SACA,MAMc;CACd,OAAO,IAAI,aAAa;EACtB;EACA,GAAI,MAAM,OAAO,KAAA,KAAa,EAAE,YAAY,KAAK,GAAG;EACpD,SAAS,MAAM,WAAW,CAAC;EAC3B,SAAS,MAAM,WAAW,CAAC;EAC3B,aAAa,MAAM,OAAO,CAAC;CAC7B,CAAC;AACH;AAEA,SAAgB,MACd,WACA,QACA,YAAqC,CAAC,GACtC,cAAsB,sBAKtB;CAWA,OAAO;EACL,SAAA;GAXiC,OAAO;GAAW;GAAa;EAW1D;EACN,QAXmB,OAAO,YAC1B,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAC5C,MACA;GACE,UAAU,MAAM,YAAY;GAC5B,MAAM;IAAE,MAAM;IAAmB,SAAS,MAAM,WAAW;GAAiB;EAC9E,CACF,CAAC,CAIkB;EACnB;CACF;AACF"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { t as SqlNode } from "./sql-node-
|
|
1
|
+
import { t as SqlNode } from "./sql-node-QXu33IeX.mjs";
|
|
2
2
|
import { NamespaceId } from "@prisma-next/contract/types";
|
|
3
|
-
|
|
4
3
|
//#region src/ir/foreign-key-reference.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Input for a foreign-key reference (one side of a foreign-key declaration).
|
|
@@ -51,13 +50,17 @@ interface ForeignKeyInput {
|
|
|
51
50
|
readonly name?: string;
|
|
52
51
|
readonly onDelete?: ReferentialAction;
|
|
53
52
|
readonly onUpdate?: ReferentialAction;
|
|
54
|
-
/** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
|
|
55
|
-
readonly constraint: boolean;
|
|
56
|
-
/** Whether to emit a backing index for the FK columns. */
|
|
57
|
-
readonly index: boolean;
|
|
58
53
|
}
|
|
59
54
|
/**
|
|
60
|
-
* SQL Contract IR node for a table-level foreign-key declaration
|
|
55
|
+
* SQL Contract IR node for a table-level foreign-key declaration — the
|
|
56
|
+
* referential constraint only (source, target, `onDelete`/`onUpdate`).
|
|
57
|
+
*
|
|
58
|
+
* A persisted `foreignKeys[]` entry always denotes a real constraint: whether
|
|
59
|
+
* to emit the constraint at all, and whether to back it with an index, are
|
|
60
|
+
* authoring-time decisions (PSL `@relation(index:)`, TS `fk({ constraint,
|
|
61
|
+
* index })`) resolved once at `contract emit` — a `constraint: false` FK
|
|
62
|
+
* simply has no entry here, and a backing index (if any) is its own discrete,
|
|
63
|
+
* named entry in the table's `indexes[]`.
|
|
61
64
|
*
|
|
62
65
|
* Each FK carries explicit `source` and `target` {@link ForeignKeyReference}
|
|
63
66
|
* coordinates (namespace, table, columns). For single-namespace contracts the
|
|
@@ -71,8 +74,6 @@ interface ForeignKeyInput {
|
|
|
71
74
|
declare class ForeignKey extends SqlNode {
|
|
72
75
|
readonly source: ForeignKeyReference;
|
|
73
76
|
readonly target: ForeignKeyReference;
|
|
74
|
-
readonly constraint: boolean;
|
|
75
|
-
readonly index: boolean;
|
|
76
77
|
readonly name?: string;
|
|
77
78
|
readonly onDelete?: ReferentialAction;
|
|
78
79
|
readonly onUpdate?: ReferentialAction;
|
|
@@ -80,4 +81,4 @@ declare class ForeignKey extends SqlNode {
|
|
|
80
81
|
}
|
|
81
82
|
//#endregion
|
|
82
83
|
export { ForeignKeyReferenceInput as a, ForeignKeyReference as i, ForeignKeyInput as n, ReferentialAction as r, ForeignKey as t };
|
|
83
|
-
//# sourceMappingURL=foreign-key-
|
|
84
|
+
//# sourceMappingURL=foreign-key-CWCEM2IT.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreign-key-CWCEM2IT.d.mts","names":[],"sources":["../src/ir/foreign-key-reference.ts","../src/ir/foreign-key.ts"],"mappings":";;;;;;;;;;;;;;UAeiB;WACN;WACA;WACA;WACA;;;;;;;;;;;;;;;;;;cAmBE,4BAA4B;WAC9B,aAAa;WACb;WACA;WACQ;cAEL,OAAO;;;;KCxCT;UAEK;WACN,QAAQ,sBAAsB;WAC9B,QAAQ,sBAAsB;WAC9B;WACA,WAAW;WACX,WAAW;;;;;;;;;;;;;;;;;;;;;;cAuBT,mBAAmB;WACrB,QAAQ;WACR,QAAQ;WACA;WACA,WAAW;WACX,WAAW;cAEhB,OAAO"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { a as ForeignKeyReferenceInput, n as ForeignKeyInput, r as ReferentialAction } from "./foreign-key-CWCEM2IT.mjs";
|
|
2
|
+
import { i as IndexInput, n as UniqueConstraintInput, o as PrimaryKeyInput } from "./unique-constraint-WHfanEUq.mjs";
|
|
3
|
+
//#region src/foreign-key-materialization.d.ts
|
|
4
|
+
type BackingIndexCandidates = {
|
|
5
|
+
readonly indexes: readonly {
|
|
6
|
+
readonly columns: readonly string[];
|
|
7
|
+
}[];
|
|
8
|
+
readonly uniques: readonly {
|
|
9
|
+
readonly columns: readonly string[];
|
|
10
|
+
}[];
|
|
11
|
+
readonly primaryKey?: {
|
|
12
|
+
readonly columns: readonly string[];
|
|
13
|
+
} | undefined;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The column-list keys (`"colA,colB"`, order preserved) a table's own
|
|
17
|
+
* indexes, unique constraints, and primary key already back. A foreign key
|
|
18
|
+
* whose source columns join to one of these keys needs no separately
|
|
19
|
+
* derived backing index.
|
|
20
|
+
*
|
|
21
|
+
* Shared by {@link isBackedByColumnKeys}'s callers: `materializeForeignKeysAndIndexes`
|
|
22
|
+
* (deriving the discrete backing-index entities persisted at `contract emit`)
|
|
23
|
+
* and the postgres PSL inferrer (deciding whether an introspected relation
|
|
24
|
+
* needs an explicit `index: false`).
|
|
25
|
+
*/
|
|
26
|
+
declare function backingIndexColumnKeys(table: BackingIndexCandidates): readonly string[];
|
|
27
|
+
/**
|
|
28
|
+
* Whether `columns`, in order, matches one of `backingKeys` (see
|
|
29
|
+
* {@link backingIndexColumnKeys}). Order-sensitive: `(a, b)` does not
|
|
30
|
+
* satisfy a backing index declared as `(b, a)`.
|
|
31
|
+
*/
|
|
32
|
+
declare function isBackedByColumnKeys(columns: readonly string[], backingKeys: readonly string[]): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* A foreign key as authored, before FK1 materialization: the referential
|
|
35
|
+
* coordinates plus the `constraint`/`index` intent booleans that drive
|
|
36
|
+
* whether — and how — it survives into the persisted contract.
|
|
37
|
+
*/
|
|
38
|
+
interface ForeignKeyAuthoringInput {
|
|
39
|
+
readonly source: ForeignKeyReferenceInput;
|
|
40
|
+
readonly target: ForeignKeyReferenceInput;
|
|
41
|
+
readonly name?: string;
|
|
42
|
+
readonly onDelete?: ReferentialAction;
|
|
43
|
+
readonly onUpdate?: ReferentialAction;
|
|
44
|
+
readonly constraint: boolean;
|
|
45
|
+
readonly index: boolean;
|
|
46
|
+
}
|
|
47
|
+
interface MaterializedTableConstraints {
|
|
48
|
+
readonly foreignKeys: readonly ForeignKeyInput[];
|
|
49
|
+
readonly indexes: readonly IndexInput[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Lowers a table's authored foreign keys into the discrete entities
|
|
53
|
+
* `contract.json` persists: a `constraint: false` FK contributes no
|
|
54
|
+
* `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already
|
|
55
|
+
* backed by a declared index/unique/primary-key contributes a named
|
|
56
|
+
* `indexes[]` entry (`defaultIndexName`). Declared indexes always survive
|
|
57
|
+
* unchanged; a second FK sharing already-synthesized backing columns does not
|
|
58
|
+
* mint a duplicate index.
|
|
59
|
+
*/
|
|
60
|
+
declare function materializeForeignKeysAndIndexes(tableName: string, foreignKeys: readonly ForeignKeyAuthoringInput[], declaredIndexes: readonly IndexInput[], uniques: readonly UniqueConstraintInput[], primaryKey: PrimaryKeyInput | undefined): MaterializedTableConstraints;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { type BackingIndexCandidates, type ForeignKeyAuthoringInput, type MaterializedTableConstraints, backingIndexColumnKeys, isBackedByColumnKeys, materializeForeignKeysAndIndexes };
|
|
63
|
+
//# sourceMappingURL=foreign-key-materialization.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreign-key-materialization.d.mts","names":[],"sources":["../src/foreign-key-materialization.ts"],"mappings":";;;KAOY;WACD;aAA6B;;WAC7B;aAA6B;;WAC7B;aAAwB;;;;;;;;;;;;;;iBAcnB,uBAAuB,OAAO;;;;;;iBAa9B,qBACd,4BACA;;;;;;UAUe;WACN,QAAQ;WACR,QAAQ;WACR;WACA,WAAW;WACX,WAAW;WACX;WACA;;UAGM;WACN,sBAAsB;WACtB,kBAAkB;;;;;;;;;;;iBAYb,iCACd,mBACA,sBAAsB,4BACtB,0BAA0B,cAC1B,kBAAkB,yBAClB,YAAY,8BACX"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { defaultIndexName } from "@prisma-next/sql-schema-ir/naming";
|
|
2
|
+
//#region src/foreign-key-materialization.ts
|
|
3
|
+
/**
|
|
4
|
+
* The column-list keys (`"colA,colB"`, order preserved) a table's own
|
|
5
|
+
* indexes, unique constraints, and primary key already back. A foreign key
|
|
6
|
+
* whose source columns join to one of these keys needs no separately
|
|
7
|
+
* derived backing index.
|
|
8
|
+
*
|
|
9
|
+
* Shared by {@link isBackedByColumnKeys}'s callers: `materializeForeignKeysAndIndexes`
|
|
10
|
+
* (deriving the discrete backing-index entities persisted at `contract emit`)
|
|
11
|
+
* and the postgres PSL inferrer (deciding whether an introspected relation
|
|
12
|
+
* needs an explicit `index: false`).
|
|
13
|
+
*/
|
|
14
|
+
function backingIndexColumnKeys(table) {
|
|
15
|
+
return [
|
|
16
|
+
...table.indexes.map((index) => index.columns.join(",")),
|
|
17
|
+
...table.uniques.map((unique) => unique.columns.join(",")),
|
|
18
|
+
...table.primaryKey ? [table.primaryKey.columns.join(",")] : []
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether `columns`, in order, matches one of `backingKeys` (see
|
|
23
|
+
* {@link backingIndexColumnKeys}). Order-sensitive: `(a, b)` does not
|
|
24
|
+
* satisfy a backing index declared as `(b, a)`.
|
|
25
|
+
*/
|
|
26
|
+
function isBackedByColumnKeys(columns, backingKeys) {
|
|
27
|
+
return backingKeys.includes(columns.join(","));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Lowers a table's authored foreign keys into the discrete entities
|
|
31
|
+
* `contract.json` persists: a `constraint: false` FK contributes no
|
|
32
|
+
* `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already
|
|
33
|
+
* backed by a declared index/unique/primary-key contributes a named
|
|
34
|
+
* `indexes[]` entry (`defaultIndexName`). Declared indexes always survive
|
|
35
|
+
* unchanged; a second FK sharing already-synthesized backing columns does not
|
|
36
|
+
* mint a duplicate index.
|
|
37
|
+
*/
|
|
38
|
+
function materializeForeignKeysAndIndexes(tableName, foreignKeys, declaredIndexes, uniques, primaryKey) {
|
|
39
|
+
const satisfiedIndexColumns = new Set(backingIndexColumnKeys({
|
|
40
|
+
indexes: declaredIndexes,
|
|
41
|
+
uniques,
|
|
42
|
+
primaryKey
|
|
43
|
+
}));
|
|
44
|
+
const synthesizedIndexes = [];
|
|
45
|
+
const materializedForeignKeys = [];
|
|
46
|
+
for (const { constraint, index, ...reference } of foreignKeys) {
|
|
47
|
+
if (constraint !== false) materializedForeignKeys.push(reference);
|
|
48
|
+
if (index !== false) {
|
|
49
|
+
const key = reference.source.columns.join(",");
|
|
50
|
+
if (!satisfiedIndexColumns.has(key)) {
|
|
51
|
+
synthesizedIndexes.push({
|
|
52
|
+
columns: reference.source.columns,
|
|
53
|
+
name: defaultIndexName(tableName, reference.source.columns)
|
|
54
|
+
});
|
|
55
|
+
satisfiedIndexColumns.add(key);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
foreignKeys: materializedForeignKeys,
|
|
61
|
+
indexes: [...declaredIndexes, ...synthesizedIndexes]
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { backingIndexColumnKeys, isBackedByColumnKeys, materializeForeignKeysAndIndexes };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=foreign-key-materialization.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreign-key-materialization.mjs","names":[],"sources":["../src/foreign-key-materialization.ts"],"sourcesContent":["import { defaultIndexName } from '@prisma-next/sql-schema-ir/naming';\nimport type { ForeignKeyInput, ReferentialAction } from './ir/foreign-key';\nimport type { ForeignKeyReferenceInput } from './ir/foreign-key-reference';\nimport type { PrimaryKeyInput } from './ir/primary-key';\nimport type { IndexInput } from './ir/sql-index';\nimport type { UniqueConstraintInput } from './ir/unique-constraint';\n\nexport type BackingIndexCandidates = {\n readonly indexes: readonly { readonly columns: readonly string[] }[];\n readonly uniques: readonly { readonly columns: readonly string[] }[];\n readonly primaryKey?: { readonly columns: readonly string[] } | undefined;\n};\n\n/**\n * The column-list keys (`\"colA,colB\"`, order preserved) a table's own\n * indexes, unique constraints, and primary key already back. A foreign key\n * whose source columns join to one of these keys needs no separately\n * derived backing index.\n *\n * Shared by {@link isBackedByColumnKeys}'s callers: `materializeForeignKeysAndIndexes`\n * (deriving the discrete backing-index entities persisted at `contract emit`)\n * and the postgres PSL inferrer (deciding whether an introspected relation\n * needs an explicit `index: false`).\n */\nexport function backingIndexColumnKeys(table: BackingIndexCandidates): readonly string[] {\n return [\n ...table.indexes.map((index) => index.columns.join(',')),\n ...table.uniques.map((unique) => unique.columns.join(',')),\n ...(table.primaryKey ? [table.primaryKey.columns.join(',')] : []),\n ];\n}\n\n/**\n * Whether `columns`, in order, matches one of `backingKeys` (see\n * {@link backingIndexColumnKeys}). Order-sensitive: `(a, b)` does not\n * satisfy a backing index declared as `(b, a)`.\n */\nexport function isBackedByColumnKeys(\n columns: readonly string[],\n backingKeys: readonly string[],\n): boolean {\n return backingKeys.includes(columns.join(','));\n}\n\n/**\n * A foreign key as authored, before FK1 materialization: the referential\n * coordinates plus the `constraint`/`index` intent booleans that drive\n * whether — and how — it survives into the persisted contract.\n */\nexport interface ForeignKeyAuthoringInput {\n readonly source: ForeignKeyReferenceInput;\n readonly target: ForeignKeyReferenceInput;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n readonly constraint: boolean;\n readonly index: boolean;\n}\n\nexport interface MaterializedTableConstraints {\n readonly foreignKeys: readonly ForeignKeyInput[];\n readonly indexes: readonly IndexInput[];\n}\n\n/**\n * Lowers a table's authored foreign keys into the discrete entities\n * `contract.json` persists: a `constraint: false` FK contributes no\n * `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already\n * backed by a declared index/unique/primary-key contributes a named\n * `indexes[]` entry (`defaultIndexName`). Declared indexes always survive\n * unchanged; a second FK sharing already-synthesized backing columns does not\n * mint a duplicate index.\n */\nexport function materializeForeignKeysAndIndexes(\n tableName: string,\n foreignKeys: readonly ForeignKeyAuthoringInput[],\n declaredIndexes: readonly IndexInput[],\n uniques: readonly UniqueConstraintInput[],\n primaryKey: PrimaryKeyInput | undefined,\n): MaterializedTableConstraints {\n const satisfiedIndexColumns = new Set(\n backingIndexColumnKeys({ indexes: declaredIndexes, uniques, primaryKey }),\n );\n const synthesizedIndexes: IndexInput[] = [];\n const materializedForeignKeys: ForeignKeyInput[] = [];\n\n for (const { constraint, index, ...reference } of foreignKeys) {\n if (constraint !== false) {\n materializedForeignKeys.push(reference);\n }\n if (index !== false) {\n const key = reference.source.columns.join(',');\n if (!satisfiedIndexColumns.has(key)) {\n synthesizedIndexes.push({\n columns: reference.source.columns,\n name: defaultIndexName(tableName, reference.source.columns),\n });\n satisfiedIndexColumns.add(key);\n }\n }\n }\n\n return {\n foreignKeys: materializedForeignKeys,\n indexes: [...declaredIndexes, ...synthesizedIndexes],\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,SAAgB,uBAAuB,OAAkD;CACvF,OAAO;EACL,GAAG,MAAM,QAAQ,KAAK,UAAU,MAAM,QAAQ,KAAK,GAAG,CAAC;EACvD,GAAG,MAAM,QAAQ,KAAK,WAAW,OAAO,QAAQ,KAAK,GAAG,CAAC;EACzD,GAAI,MAAM,aAAa,CAAC,MAAM,WAAW,QAAQ,KAAK,GAAG,CAAC,IAAI,CAAC;CACjE;AACF;;;;;;AAOA,SAAgB,qBACd,SACA,aACS;CACT,OAAO,YAAY,SAAS,QAAQ,KAAK,GAAG,CAAC;AAC/C;;;;;;;;;;AA+BA,SAAgB,iCACd,WACA,aACA,iBACA,SACA,YAC8B;CAC9B,MAAM,wBAAwB,IAAI,IAChC,uBAAuB;EAAE,SAAS;EAAiB;EAAS;CAAW,CAAC,CAC1E;CACA,MAAM,qBAAmC,CAAC;CAC1C,MAAM,0BAA6C,CAAC;CAEpD,KAAK,MAAM,EAAE,YAAY,OAAO,GAAG,eAAe,aAAa;EAC7D,IAAI,eAAe,OACjB,wBAAwB,KAAK,SAAS;EAExC,IAAI,UAAU,OAAO;GACnB,MAAM,MAAM,UAAU,OAAO,QAAQ,KAAK,GAAG;GAC7C,IAAI,CAAC,sBAAsB,IAAI,GAAG,GAAG;IACnC,mBAAmB,KAAK;KACtB,SAAS,UAAU,OAAO;KAC1B,MAAM,iBAAiB,WAAW,UAAU,OAAO,OAAO;IAC5D,CAAC;IACD,sBAAsB,IAAI,GAAG;GAC/B;EACF;CACF;CAEA,OAAO;EACL,aAAa;EACb,SAAS,CAAC,GAAG,iBAAiB,GAAG,kBAAkB;CACrD;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { s as SqlStorage } from "./sql-storage-
|
|
2
|
-
import
|
|
1
|
+
import { s as SqlStorage } from "./sql-storage-BIErcfFA.mjs";
|
|
2
|
+
import "./types-lpzJtKpv.mjs";
|
|
3
|
+
import { a as IndexTypeRegistry } from "./index-types-DPVhsW0v.mjs";
|
|
3
4
|
import { Contract } from "@prisma-next/contract/types";
|
|
4
|
-
|
|
5
5
|
//#region src/index-type-validation.d.ts
|
|
6
6
|
declare function validateIndexTypes(contract: Contract<SqlStorage>, indexTypeRegistry: IndexTypeRegistry): void;
|
|
7
7
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-type-validation.d.mts","names":[],"sources":["../src/index-type-validation.ts"],"mappings":";;;;;iBAMgB,
|
|
1
|
+
{"version":3,"file":"index-type-validation.d.mts","names":[],"sources":["../src/index-type-validation.ts"],"mappings":";;;;;iBAMgB,mBACd,UAAU,SAAS,aACnB,mBAAmB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Type } from "arktype";
|
|
2
|
-
|
|
3
2
|
//#region src/index-types.d.ts
|
|
4
3
|
interface IndexTypeEntry<TOptions = unknown> {
|
|
5
4
|
readonly type: string;
|
|
@@ -7,7 +6,7 @@ interface IndexTypeEntry<TOptions = unknown> {
|
|
|
7
6
|
}
|
|
8
7
|
type IndexTypeMap = { readonly [K in string]: {
|
|
9
8
|
readonly options: unknown;
|
|
10
|
-
} };
|
|
9
|
+
}; };
|
|
11
10
|
interface IndexTypeRegistration<TMap extends IndexTypeMap = Record<never, never>> {
|
|
12
11
|
readonly IndexTypes: TMap;
|
|
13
12
|
readonly entries: ReadonlyArray<IndexTypeEntry>;
|
|
@@ -28,4 +27,4 @@ interface IndexTypeRegistry {
|
|
|
28
27
|
declare function createIndexTypeRegistry(): IndexTypeRegistry;
|
|
29
28
|
//#endregion
|
|
30
29
|
export { IndexTypeRegistry as a, IndexTypeRegistration as i, IndexTypeEntry as n, createIndexTypeRegistry as o, IndexTypeMap as r, defineIndexTypes as s, IndexTypeBuilder as t };
|
|
31
|
-
//# sourceMappingURL=index-types-
|
|
30
|
+
//# sourceMappingURL=index-types-DPVhsW0v.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-types-DPVhsW0v.d.mts","names":[],"sources":["../src/index-types.ts"],"mappings":";;UAEiB,eAAe;WACrB;WACA,SAAS,KAAK;;KAGb,2BAA2B;WAAyB;;UAE/C,sBAAsB,aAAa,eAAe;WACxD,YAAY;WACZ,SAAS,cAAc;;UAGjB,iBAAiB,aAAa,eAAe,8BACpD,sBAAsB;EAC9B,IAAI,qBAAqB,OACvB,aAAa,MACb;aAAkB,SAAS,KAAK;MAC/B,iBAAiB,OAAO,OAAO;aAAiB,SAAS;;;iBA0B9C,oBAAoB,iBAAiB;UAIpC;EACf,SAAS,OAAO;EAChB,IAAI,sBAAsB;EAC1B,IAAI;;iBAsBU,2BAA2B"}
|
package/dist/index-types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as IndexTypeRegistry, i as IndexTypeRegistration, n as IndexTypeEntry, o as createIndexTypeRegistry, r as IndexTypeMap, s as defineIndexTypes, t as IndexTypeBuilder } from "./index-types-
|
|
1
|
+
import { a as IndexTypeRegistry, i as IndexTypeRegistration, n as IndexTypeEntry, o as createIndexTypeRegistry, r as IndexTypeMap, s as defineIndexTypes, t as IndexTypeBuilder } from "./index-types-DPVhsW0v.mjs";
|
|
2
2
|
export { type IndexTypeBuilder, type IndexTypeEntry, type IndexTypeMap, type IndexTypeRegistration, type IndexTypeRegistry, createIndexTypeRegistry, defineIndexTypes };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack-types.d.mts","names":[],"sources":["../src/pack-types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"pack-types.d.mts","names":[],"sources":["../src/pack-types.ts"],"mappings":";;;;UAGiB;WACN;WACA;WACA;WACA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { r as ReferentialAction } from "./foreign-key-
|
|
2
|
-
|
|
1
|
+
import { r as ReferentialAction } from "./foreign-key-CWCEM2IT.mjs";
|
|
3
2
|
//#region src/referential-action-sql.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Maps each `ReferentialAction` value to the SQL keyword used in ON DELETE /
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"referential-action-sql.d.mts","names":[],"sources":["../src/referential-action-sql.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"referential-action-sql.d.mts","names":[],"sources":["../src/referential-action-sql.ts"],"mappings":";;;;;;;cAOa,wBAAwB,OAAO"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { t as StorageTable } from "./storage-table-
|
|
2
|
-
import { s as SqlStorage } from "./sql-storage-
|
|
3
|
-
|
|
1
|
+
import { t as StorageTable } from "./storage-table-mNGckl3_.mjs";
|
|
2
|
+
import { s as SqlStorage } from "./sql-storage-BIErcfFA.mjs";
|
|
4
3
|
//#region src/resolve-storage-table.d.ts
|
|
5
4
|
interface ResolvedStorageTable {
|
|
6
5
|
readonly namespaceId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-storage-table.d.mts","names":[],"sources":["../src/resolve-storage-table.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolve-storage-table.d.mts","names":[],"sources":["../src/resolve-storage-table.ts"],"mappings":";;;UAIiB;WACN;WACA,OAAO;;;;;;;;;;;iBAYF,oBACd,SAAS,YACT,mBACA,uBACC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IRNodeBase } from "@prisma-next/framework-components/ir";
|
|
2
|
-
|
|
3
2
|
//#region src/ir/sql-node.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* SQL family IR node base. Carries the family-level `kind` discriminator
|
|
@@ -39,4 +38,4 @@ declare abstract class SqlNode extends IRNodeBase {
|
|
|
39
38
|
}
|
|
40
39
|
//#endregion
|
|
41
40
|
export { SqlNode as t };
|
|
42
|
-
//# sourceMappingURL=sql-node-
|
|
41
|
+
//# sourceMappingURL=sql-node-QXu33IeX.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-node-QXu33IeX.d.mts","names":[],"sources":["../src/ir/sql-node.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAkCsB,gBAAgB;WAC3B"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { t as SqlNode } from "./sql-node-
|
|
2
|
-
import { t as StorageTable } from "./storage-table-
|
|
3
|
-
import { t as StorageValueSet } from "./storage-value-set-
|
|
1
|
+
import { t as SqlNode } from "./sql-node-QXu33IeX.mjs";
|
|
2
|
+
import { t as StorageTable } from "./storage-table-mNGckl3_.mjs";
|
|
3
|
+
import { t as StorageValueSet } from "./storage-value-set-DPHvvSdB.mjs";
|
|
4
4
|
import { Namespace, NamespaceBase, Storage, StorageType } from "@prisma-next/framework-components/ir";
|
|
5
5
|
import { StorageHashBase } from "@prisma-next/contract/types";
|
|
6
6
|
import { AuthoringContributions } from "@prisma-next/framework-components/authoring";
|
|
7
|
-
|
|
8
7
|
//#region src/ir/storage-type-instance.d.ts
|
|
9
8
|
/**
|
|
10
9
|
* Sentinel kind for the legacy codec-triple shape persisted under
|
|
@@ -168,4 +167,4 @@ declare class SqlStorage<THash extends string = string> extends SqlNode implemen
|
|
|
168
167
|
}
|
|
169
168
|
//#endregion
|
|
170
169
|
export { SqlNamespaceFactory as a, SqlStorageInput as c, isSqlAuthoringContributions as d, CODEC_INSTANCE_KIND as f, toStorageTypeInstance as g, isStorageTypeInstance as h, SqlNamespaceEntries as i, SqlStorageTypeEntry as l, StorageTypeInstanceInput as m, SqlNamespace as n, SqlNamespaceInput as o, StorageTypeInstance as p, SqlNamespaceBase as r, SqlStorage as s, SqlAuthoringContributions as t, isMaterializedSqlNamespace as u };
|
|
171
|
-
//# sourceMappingURL=sql-storage-
|
|
170
|
+
//# sourceMappingURL=sql-storage-BIErcfFA.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-storage-BIErcfFA.d.mts","names":[],"sources":["../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts"],"mappings":";;;;;;;;;;;;;;cASa;;;;;;;;;UAUI,4BAA4B;WAClC,aAAa;WACb;WACA;WACA,YAAY;;;;;;;;;UAUN;WACN;WACA;WACA,aAAa;;;;;;;iBAQR,sBAAsB,OAAO,2BAA2B;;;;;;iBAcxD,sBAAsB,iBAAiB,SAAS;;;;;;;;;;KChCpD,sBAAsB,sBAAsB;UAEvC;WACN;WACA,SAAS,SAAS,eAAe,SAAS;;;;;;KAOzC,uBAAuB,OAAO,sBAAsB;;;;;;;;UAS/C,kCAAkC;WACxC,kBAAkB;;;;;;iBAOb,4BACd,WAAW,qCACV,aAAa;UAOC,gBAAgB;WACtB,aAAa,gBAAgB;WAC7B,QAAQ,eAAe;WACvB,YAAY,SAAS,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8BnC,sBAAsB,SAAS,eAAe,SAAS;WACxD,QAAQ,SAAS,eAAe;WAChC,WAAW,SAAS,eAAe;;;;;;;;;;;UAY7B;WACN;WACA;WACA,SAAS;WACT;EACT,cAAc;;;;;;;;uBASM,yBAAyB,yBAAyB;oBAC3C;oBACA,SAAS;WAE3B,aAAa;;;;;;;;;;;;iBAaR,2BAA2B,aAAa,KAAK;cAKhD,WAAW,uCAAuC,mBAAmB;WACvE,aAAa,gBAAgB;WAC7B,YAAY,SAAS,eAAe;WAC5B,QAAQ,SAAS,eAAe;cAErC,OAAO,gBAAgB"}
|
|
@@ -107,7 +107,15 @@ var ForeignKeyReference = class extends SqlNode {
|
|
|
107
107
|
//#endregion
|
|
108
108
|
//#region src/ir/foreign-key.ts
|
|
109
109
|
/**
|
|
110
|
-
* SQL Contract IR node for a table-level foreign-key declaration
|
|
110
|
+
* SQL Contract IR node for a table-level foreign-key declaration — the
|
|
111
|
+
* referential constraint only (source, target, `onDelete`/`onUpdate`).
|
|
112
|
+
*
|
|
113
|
+
* A persisted `foreignKeys[]` entry always denotes a real constraint: whether
|
|
114
|
+
* to emit the constraint at all, and whether to back it with an index, are
|
|
115
|
+
* authoring-time decisions (PSL `@relation(index:)`, TS `fk({ constraint,
|
|
116
|
+
* index })`) resolved once at `contract emit` — a `constraint: false` FK
|
|
117
|
+
* simply has no entry here, and a backing index (if any) is its own discrete,
|
|
118
|
+
* named entry in the table's `indexes[]`.
|
|
111
119
|
*
|
|
112
120
|
* Each FK carries explicit `source` and `target` {@link ForeignKeyReference}
|
|
113
121
|
* coordinates (namespace, table, columns). For single-namespace contracts the
|
|
@@ -121,14 +129,10 @@ var ForeignKeyReference = class extends SqlNode {
|
|
|
121
129
|
var ForeignKey = class extends SqlNode {
|
|
122
130
|
source;
|
|
123
131
|
target;
|
|
124
|
-
constraint;
|
|
125
|
-
index;
|
|
126
132
|
constructor(input) {
|
|
127
133
|
super();
|
|
128
134
|
this.source = input.source instanceof ForeignKeyReference ? input.source : new ForeignKeyReference(input.source);
|
|
129
135
|
this.target = input.target instanceof ForeignKeyReference ? input.target : new ForeignKeyReference(input.target);
|
|
130
|
-
this.constraint = input.constraint;
|
|
131
|
-
this.index = input.index;
|
|
132
136
|
if (input.name !== void 0) this.name = input.name;
|
|
133
137
|
if (input.onDelete !== void 0) this.onDelete = input.onDelete;
|
|
134
138
|
if (input.onUpdate !== void 0) this.onUpdate = input.onUpdate;
|
|
@@ -265,4 +269,4 @@ var StorageTable = class StorageTable extends SqlNode {
|
|
|
265
269
|
//#endregion
|
|
266
270
|
export { PrimaryKey as a, CheckConstraint as c, Index as i, SqlNode as l, UniqueConstraint as n, ForeignKey as o, StorageColumn as r, ForeignKeyReference as s, StorageTable as t };
|
|
267
271
|
|
|
268
|
-
//# sourceMappingURL=storage-table-
|
|
272
|
+
//# sourceMappingURL=storage-table-DBpYBmty.mjs.map
|