@prisma-next/sql-contract 0.16.0-dev.3 → 0.16.0-dev.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/canonicalization-hooks.d.mts.map +1 -1
- package/dist/canonicalization-hooks.mjs +10 -0
- package/dist/canonicalization-hooks.mjs.map +1 -1
- package/dist/contract-errors-CPZcBw8G.mjs +9 -0
- package/dist/contract-errors-CPZcBw8G.mjs.map +1 -0
- package/dist/contract-view.d.mts +1 -1
- package/dist/{entity-kinds-CVg6HzG2.mjs → entity-kinds-CdHJQGi0.mjs} +11 -6
- package/dist/entity-kinds-CdHJQGi0.mjs.map +1 -0
- package/dist/entity-kinds.d.mts +1 -1
- package/dist/entity-kinds.d.mts.map +1 -1
- package/dist/entity-kinds.mjs +1 -1
- package/dist/factories.d.mts +10 -4
- package/dist/factories.d.mts.map +1 -1
- package/dist/factories.mjs +11 -3
- package/dist/factories.mjs.map +1 -1
- package/dist/foreign-key-materialization.d.mts +7 -6
- package/dist/foreign-key-materialization.d.mts.map +1 -1
- package/dist/foreign-key-materialization.mjs +12 -9
- package/dist/foreign-key-materialization.mjs.map +1 -1
- package/dist/index-naming-DsnarUVW.mjs +43 -0
- package/dist/index-naming-DsnarUVW.mjs.map +1 -0
- package/dist/index-naming.d.mts +25 -0
- package/dist/index-naming.d.mts.map +1 -0
- package/dist/index-naming.mjs +2 -0
- package/dist/index-type-validation.d.mts +2 -2
- package/dist/index-type-validation.mjs +3 -3
- package/dist/index-type-validation.mjs.map +1 -1
- package/dist/index-types-DPVhsW0v.d.mts.map +1 -1
- package/dist/index-types.mjs +3 -2
- package/dist/index-types.mjs.map +1 -1
- package/dist/resolve-storage-table.d.mts +2 -2
- package/dist/resolve-storage-table.d.mts.map +1 -1
- package/dist/resolve-storage-table.mjs +5 -4
- package/dist/resolve-storage-table.mjs.map +1 -1
- package/dist/sql-index-Wzbj2nbH.d.mts +79 -0
- package/dist/sql-index-Wzbj2nbH.d.mts.map +1 -0
- package/dist/{sql-storage-BIErcfFA.d.mts → sql-storage-DjqU3XXV.d.mts} +2 -2
- package/dist/{sql-storage-BIErcfFA.d.mts.map → sql-storage-DjqU3XXV.d.mts.map} +1 -1
- package/dist/{storage-table-DBpYBmty.mjs → storage-table-DKTrkwZt.mjs} +30 -6
- package/dist/storage-table-DKTrkwZt.mjs.map +1 -0
- package/dist/{storage-table-mNGckl3_.d.mts → storage-table-zrxIuCJ3.d.mts} +3 -2
- package/dist/storage-table-zrxIuCJ3.d.mts.map +1 -0
- package/dist/{storage-value-set-3BKuha5q.mjs → storage-value-set-DdL4oin-.mjs} +2 -2
- package/dist/{storage-value-set-3BKuha5q.mjs.map → storage-value-set-DdL4oin-.mjs.map} +1 -1
- package/dist/{types-lpzJtKpv.d.mts → types-Bxa1Pyzg.d.mts} +5 -4
- package/dist/types-Bxa1Pyzg.d.mts.map +1 -0
- package/dist/types.d.mts +5 -4
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +4 -3
- package/dist/types.mjs.map +1 -1
- package/dist/unique-constraint-Bp-q-mr-.d.mts +31 -0
- package/dist/unique-constraint-Bp-q-mr-.d.mts.map +1 -0
- package/dist/validators.d.mts +15 -7
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +14 -10
- package/dist/validators.mjs.map +1 -1
- package/package.json +9 -8
- package/src/canonicalization-hooks.ts +4 -0
- package/src/contract-errors.ts +14 -0
- package/src/entity-kinds.ts +4 -1
- package/src/exports/index-naming.ts +1 -0
- package/src/factories.ts +19 -2
- package/src/foreign-key-materialization.ts +18 -11
- package/src/index-naming.ts +65 -0
- package/src/index-type-validation.ts +3 -3
- package/src/index-types.ts +11 -2
- package/src/ir/sql-index.ts +94 -11
- package/src/ir/sql-storage.ts +2 -1
- package/src/ir/storage-entry-schemas.ts +6 -2
- package/src/ir/storage-table.ts +2 -1
- package/src/resolve-storage-table.ts +4 -1
- package/src/validators.ts +25 -9
- package/dist/entity-kinds-CVg6HzG2.mjs.map +0 -1
- package/dist/storage-table-DBpYBmty.mjs.map +0 -1
- package/dist/storage-table-mNGckl3_.d.mts.map +0 -1
- package/dist/types-lpzJtKpv.d.mts.map +0 -1
- package/dist/unique-constraint-WHfanEUq.d.mts +0 -54
- package/dist/unique-constraint-WHfanEUq.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -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":";;cAwDa;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 // 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;
|
|
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 // An index's `unique` flag is a required boolean: `unique: false` must\n // survive the default-omission walk or the emitted contract fails its own\n // IndexSchema validation on the next read.\n ['storage', 'namespaces', '*', 'entries', 'table', '*', 'indexes', 'unique'],\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;CAI7F;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;EAAK;EAAW;CAAQ;CAK3E;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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { structuredError } from "@prisma-next/utils/structured-error";
|
|
2
|
+
//#region src/contract-errors.ts
|
|
3
|
+
function contractError(code, message, options) {
|
|
4
|
+
return structuredError(code, message, options);
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { contractError as t };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=contract-errors-CPZcBw8G.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-errors-CPZcBw8G.mjs","names":[],"sources":["../src/contract-errors.ts"],"sourcesContent":["import type { StructuredError, StructuredErrorOptions } from '@prisma-next/utils/structured-error';\nimport { structuredError } from '@prisma-next/utils/structured-error';\n\ntype ContractCode = `CONTRACT.${ContractSubcode}`;\n\ntype ContractSubcode = 'PACK_CONTRIBUTION_INVALID' | 'TABLE_AMBIGUOUS' | 'VALIDATION_FAILED';\n\nexport function contractError(\n code: ContractCode,\n message: string,\n options?: StructuredErrorOptions,\n): StructuredError {\n return structuredError(code, message, options);\n}\n"],"mappings":";;AAOA,SAAgB,cACd,MACA,SACA,SACiB;CACjB,OAAO,gBAAgB,MAAM,SAAS,OAAO;AAC/C"}
|
package/dist/contract-view.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as SqlStorage } from "./sql-storage-
|
|
1
|
+
import { s as SqlStorage } from "./sql-storage-DjqU3XXV.mjs";
|
|
2
2
|
import { DefaultNamespaceEntries, NamespacedEntities, SingleNamespaceView } from "@prisma-next/framework-components/ir";
|
|
3
3
|
import { Contract } from "@prisma-next/contract/types";
|
|
4
4
|
//#region src/contract-view.d.ts
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { t as
|
|
1
|
+
import { t as contractError } from "./contract-errors-CPZcBw8G.mjs";
|
|
2
|
+
import { t as StorageTable } from "./storage-table-DKTrkwZt.mjs";
|
|
3
|
+
import { t as StorageValueSet } from "./storage-value-set-DdL4oin-.mjs";
|
|
3
4
|
import { type } from "arktype";
|
|
4
5
|
//#region src/ir/storage-entry-schemas.ts
|
|
5
6
|
const literalKindSchema = type("'literal'");
|
|
@@ -54,8 +55,12 @@ const UniqueConstraintSchema = type.declare().type({
|
|
|
54
55
|
"name?": "string"
|
|
55
56
|
});
|
|
56
57
|
const IndexSchema = type({
|
|
57
|
-
|
|
58
|
-
"
|
|
58
|
+
name: "string",
|
|
59
|
+
"prefix?": "string",
|
|
60
|
+
"columns?": type.string.array().readonly(),
|
|
61
|
+
"expression?": "string",
|
|
62
|
+
"where?": "string",
|
|
63
|
+
unique: "boolean",
|
|
59
64
|
"type?": "string",
|
|
60
65
|
"options?": "Record<string, unknown>"
|
|
61
66
|
});
|
|
@@ -119,7 +124,7 @@ const valueSetEntityKind = {
|
|
|
119
124
|
function composeSqlEntityKinds(packKinds = []) {
|
|
120
125
|
const kinds = /* @__PURE__ */ new Map([["table", tableEntityKind], ["valueSet", valueSetEntityKind]]);
|
|
121
126
|
for (const descriptor of packKinds) {
|
|
122
|
-
if (kinds.has(descriptor.kind)) throw
|
|
127
|
+
if (kinds.has(descriptor.kind)) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `composeSqlEntityKinds: duplicate entity kind "${descriptor.kind}" — each kind may be registered only once`, { meta: { entityKind: descriptor.kind } });
|
|
123
128
|
kinds.set(descriptor.kind, descriptor);
|
|
124
129
|
}
|
|
125
130
|
return kinds;
|
|
@@ -127,4 +132,4 @@ function composeSqlEntityKinds(packKinds = []) {
|
|
|
127
132
|
//#endregion
|
|
128
133
|
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 };
|
|
129
134
|
|
|
130
|
-
//# sourceMappingURL=entity-kinds-
|
|
135
|
+
//# sourceMappingURL=entity-kinds-CdHJQGi0.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-kinds-CdHJQGi0.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 name: 'string',\n 'prefix?': 'string',\n 'columns?': type.string.array().readonly(),\n 'expression?': 'string',\n 'where?': 'string',\n unique: 'boolean',\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 { contractError } from './contract-errors';\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 contractError(\n 'CONTRACT.PACK_CONTRIBUTION_INVALID',\n `composeSqlEntityKinds: duplicate entity kind \"${descriptor.kind}\" — each kind may be registered only once`,\n { meta: { entityKind: descriptor.kind } },\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,MAAM;CACN,WAAW;CACX,YAAY,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACzC,eAAe;CACf,UAAU;CACV,QAAQ;CACR,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;;;ACzHD,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,cACJ,sCACA,iDAAiD,WAAW,KAAK,4CACjE,EAAE,MAAM,EAAE,YAAY,WAAW,KAAK,EAAE,CAC1C;EAEF,MAAM,IAAI,WAAW,MAAM,UAAU;CACvC;CACA,OAAO;AACT"}
|
package/dist/entity-kinds.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as StorageTableInput, t as StorageTable } from "./storage-table-
|
|
1
|
+
import { n as StorageTableInput, t as StorageTable } from "./storage-table-zrxIuCJ3.mjs";
|
|
2
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
4
|
//#region src/entity-kinds.d.ts
|
|
@@ -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":";;;;cASa,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-CdHJQGi0.mjs";
|
|
2
2
|
export { composeSqlEntityKinds, tableEntityKind, valueSetEntityKind };
|
package/dist/factories.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { i as StorageColumnInput, r as StorageColumn, t as StorageTable } from "./storage-table-
|
|
1
|
+
import { i as StorageColumnInput, r as StorageColumn, t as StorageTable } from "./storage-table-zrxIuCJ3.mjs";
|
|
2
2
|
import { t as ForeignKey } from "./foreign-key-CWCEM2IT.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { r as PrimaryKey, t as UniqueConstraint } from "./unique-constraint-Bp-q-mr-.mjs";
|
|
4
|
+
import { t as Index } from "./sql-index-Wzbj2nbH.mjs";
|
|
5
|
+
import { T as SqlModelStorage, m as ForeignKeyOptions, w as SqlModelFieldStorage } from "./types-Bxa1Pyzg.mjs";
|
|
5
6
|
import { ScalarFieldType } from "@prisma-next/contract/types";
|
|
6
7
|
//#region src/factories.d.ts
|
|
7
8
|
declare function col(nativeType: string, codecId: string, nullable?: boolean, opts?: {
|
|
@@ -9,7 +10,12 @@ declare function col(nativeType: string, codecId: string, nullable?: boolean, op
|
|
|
9
10
|
}): StorageColumn;
|
|
10
11
|
declare function pk(...columns: readonly string[]): PrimaryKey;
|
|
11
12
|
declare function unique(...columns: readonly string[]): UniqueConstraint;
|
|
12
|
-
declare function index(
|
|
13
|
+
declare function index(name: string, columns: readonly string[], opts?: {
|
|
14
|
+
readonly prefix?: string;
|
|
15
|
+
readonly unique?: boolean;
|
|
16
|
+
readonly type?: string;
|
|
17
|
+
readonly options?: Record<string, unknown>;
|
|
18
|
+
}): Index;
|
|
13
19
|
declare function fk(srcTableName: string, srcColumns: readonly string[], targetTableName: string, targetColumns: readonly string[], opts?: ForeignKeyOptions & {
|
|
14
20
|
namespaceId?: string;
|
|
15
21
|
}): ForeignKey;
|
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,MACd,cACA,4BACA;WACW;WACA;WACA;WACA,UAAU;IAEpB;iBAYa,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,4 +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-
|
|
1
|
+
import { a as PrimaryKey, i as Index, n as UniqueConstraint, o as ForeignKey, r as StorageColumn, t as StorageTable } from "./storage-table-DKTrkwZt.mjs";
|
|
2
2
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
3
3
|
import { asNamespaceId } from "@prisma-next/contract/types";
|
|
4
4
|
//#region src/factories.ts
|
|
@@ -16,8 +16,16 @@ function pk(...columns) {
|
|
|
16
16
|
function unique(...columns) {
|
|
17
17
|
return new UniqueConstraint({ columns });
|
|
18
18
|
}
|
|
19
|
-
function index(
|
|
20
|
-
return new Index({
|
|
19
|
+
function index(name, columns, opts) {
|
|
20
|
+
return new Index({
|
|
21
|
+
name,
|
|
22
|
+
prefix: opts?.prefix,
|
|
23
|
+
columns,
|
|
24
|
+
where: void 0,
|
|
25
|
+
unique: opts?.unique ?? false,
|
|
26
|
+
type: opts?.type,
|
|
27
|
+
options: opts?.options
|
|
28
|
+
});
|
|
21
29
|
}
|
|
22
30
|
function fk(srcTableName, srcColumns, targetTableName, targetColumns, opts) {
|
|
23
31
|
const namespaceId = asNamespaceId(opts?.namespaceId ?? UNBOUND_NAMESPACE_ID);
|
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 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(
|
|
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(\n name: string,\n columns: readonly string[],\n opts?: {\n readonly prefix?: string;\n readonly unique?: boolean;\n readonly type?: string;\n readonly options?: Record<string, unknown>;\n },\n): Index {\n return new Index({\n name,\n prefix: opts?.prefix,\n columns,\n where: undefined,\n unique: opts?.unique ?? false,\n type: opts?.type,\n options: opts?.options,\n });\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,MACd,MACA,SACA,MAMO;CACP,OAAO,IAAI,MAAM;EACf;EACA,QAAQ,MAAM;EACd;EACA,OAAO,KAAA;EACP,QAAQ,MAAM,UAAU;EACxB,MAAM,MAAM;EACZ,SAAS,MAAM;CACjB,CAAC;AACH;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,9 +1,10 @@
|
|
|
1
1
|
import { a as ForeignKeyReferenceInput, n as ForeignKeyInput, r as ReferentialAction } from "./foreign-key-CWCEM2IT.mjs";
|
|
2
|
-
import { i as
|
|
2
|
+
import { i as PrimaryKeyInput, n as UniqueConstraintInput } from "./unique-constraint-Bp-q-mr-.mjs";
|
|
3
|
+
import { n as IndexInput } from "./sql-index-Wzbj2nbH.mjs";
|
|
3
4
|
//#region src/foreign-key-materialization.d.ts
|
|
4
5
|
type BackingIndexCandidates = {
|
|
5
6
|
readonly indexes: readonly {
|
|
6
|
-
readonly columns
|
|
7
|
+
readonly columns?: readonly string[];
|
|
7
8
|
}[];
|
|
8
9
|
readonly uniques: readonly {
|
|
9
10
|
readonly columns: readonly string[];
|
|
@@ -52,10 +53,10 @@ interface MaterializedTableConstraints {
|
|
|
52
53
|
* Lowers a table's authored foreign keys into the discrete entities
|
|
53
54
|
* `contract.json` persists: a `constraint: false` FK contributes no
|
|
54
55
|
* `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already
|
|
55
|
-
* backed by a declared index/unique/primary-key contributes a
|
|
56
|
-
* `indexes[]` entry (
|
|
57
|
-
* unchanged; a second FK sharing already-synthesized
|
|
58
|
-
* mint a duplicate index.
|
|
56
|
+
* backed by a declared index/unique/primary-key contributes a managed
|
|
57
|
+
* `indexes[]` entry (default prefix + content-hash wire name). Declared
|
|
58
|
+
* indexes always survive unchanged; a second FK sharing already-synthesized
|
|
59
|
+
* backing columns does not mint a duplicate index.
|
|
59
60
|
*/
|
|
60
61
|
declare function materializeForeignKeysAndIndexes(tableName: string, foreignKeys: readonly ForeignKeyAuthoringInput[], declaredIndexes: readonly IndexInput[], uniques: readonly UniqueConstraintInput[], primaryKey: PrimaryKeyInput | undefined): MaterializedTableConstraints;
|
|
61
62
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"foreign-key-materialization.d.mts","names":[],"sources":["../src/foreign-key-materialization.ts"],"mappings":"
|
|
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;;;;;;iBAe9B,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as lowerAuthoredIndex } from "./index-naming-DsnarUVW.mjs";
|
|
2
2
|
//#region src/foreign-key-materialization.ts
|
|
3
3
|
/**
|
|
4
4
|
* The column-list keys (`"colA,colB"`, order preserved) a table's own
|
|
@@ -13,7 +13,7 @@ import { defaultIndexName } from "@prisma-next/sql-schema-ir/naming";
|
|
|
13
13
|
*/
|
|
14
14
|
function backingIndexColumnKeys(table) {
|
|
15
15
|
return [
|
|
16
|
-
...table.indexes.
|
|
16
|
+
...table.indexes.flatMap((index) => index.columns !== void 0 ? [index.columns.join(",")] : []),
|
|
17
17
|
...table.uniques.map((unique) => unique.columns.join(",")),
|
|
18
18
|
...table.primaryKey ? [table.primaryKey.columns.join(",")] : []
|
|
19
19
|
];
|
|
@@ -30,10 +30,10 @@ function isBackedByColumnKeys(columns, backingKeys) {
|
|
|
30
30
|
* Lowers a table's authored foreign keys into the discrete entities
|
|
31
31
|
* `contract.json` persists: a `constraint: false` FK contributes no
|
|
32
32
|
* `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already
|
|
33
|
-
* backed by a declared index/unique/primary-key contributes a
|
|
34
|
-
* `indexes[]` entry (
|
|
35
|
-
* unchanged; a second FK sharing already-synthesized
|
|
36
|
-
* mint a duplicate index.
|
|
33
|
+
* backed by a declared index/unique/primary-key contributes a managed
|
|
34
|
+
* `indexes[]` entry (default prefix + content-hash wire name). Declared
|
|
35
|
+
* indexes always survive unchanged; a second FK sharing already-synthesized
|
|
36
|
+
* backing columns does not mint a duplicate index.
|
|
37
37
|
*/
|
|
38
38
|
function materializeForeignKeysAndIndexes(tableName, foreignKeys, declaredIndexes, uniques, primaryKey) {
|
|
39
39
|
const satisfiedIndexColumns = new Set(backingIndexColumnKeys({
|
|
@@ -48,10 +48,13 @@ function materializeForeignKeysAndIndexes(tableName, foreignKeys, declaredIndexe
|
|
|
48
48
|
if (index !== false) {
|
|
49
49
|
const key = reference.source.columns.join(",");
|
|
50
50
|
if (!satisfiedIndexColumns.has(key)) {
|
|
51
|
-
synthesizedIndexes.push({
|
|
51
|
+
synthesizedIndexes.push(lowerAuthoredIndex(tableName, {
|
|
52
52
|
columns: reference.source.columns,
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
map: void 0,
|
|
54
|
+
name: void 0,
|
|
55
|
+
type: void 0,
|
|
56
|
+
options: void 0
|
|
57
|
+
}));
|
|
55
58
|
satisfiedIndexColumns.add(key);
|
|
56
59
|
}
|
|
57
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"foreign-key-materialization.mjs","names":[],"sources":["../src/foreign-key-materialization.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"foreign-key-materialization.mjs","names":[],"sources":["../src/foreign-key-materialization.ts"],"sourcesContent":["import { lowerAuthoredIndex } from './index-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.flatMap((index) =>\n index.columns !== undefined ? [index.columns.join(',')] : [],\n ),\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 managed\n * `indexes[]` entry (default prefix + content-hash wire name). Declared\n * indexes always survive unchanged; a second FK sharing already-synthesized\n * backing columns does not 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 lowerAuthoredIndex(tableName, {\n columns: reference.source.columns,\n map: undefined,\n name: undefined,\n type: undefined,\n options: undefined,\n }),\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,SAAS,UACxB,MAAM,YAAY,KAAA,IAAY,CAAC,MAAM,QAAQ,KAAK,GAAG,CAAC,IAAI,CAAC,CAC7D;EACA,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,KACjB,mBAAmB,WAAW;KAC5B,SAAS,UAAU,OAAO;KAC1B,KAAK,KAAA;KACL,MAAM,KAAA;KACN,MAAM,KAAA;KACN,SAAS,KAAA;IACX,CAAC,CACH;IACA,sBAAsB,IAAI,GAAG;GAC/B;EACF;CACF;CAEA,OAAO;EACL,aAAa;EACb,SAAS,CAAC,GAAG,iBAAiB,GAAG,kBAAkB;CACrD;AACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { InternalError } from "@prisma-next/utils/internal-error";
|
|
2
|
+
import { assertWireNamePrefixLength, computeIndexContentHash, defaultIndexName, formatWireName } from "@prisma-next/sql-schema-ir/naming";
|
|
3
|
+
//#region src/index-naming.ts
|
|
4
|
+
/**
|
|
5
|
+
* Lowers an authored index into the name-identified entity `contract.json`
|
|
6
|
+
* persists: exact mode adopts `map` verbatim (no prefix, no hash); managed
|
|
7
|
+
* mode appends the content-hash suffix to the authored or default prefix.
|
|
8
|
+
* `unique` always lowers `false` — no authoring surface sets it yet.
|
|
9
|
+
*/
|
|
10
|
+
function lowerAuthoredIndex(tableName, authored) {
|
|
11
|
+
if (authored.map !== void 0) {
|
|
12
|
+
if (authored.name !== void 0) throw new InternalError(`Index "${authored.map}" on table "${tableName}": map and name are mutually exclusive.`);
|
|
13
|
+
return {
|
|
14
|
+
name: authored.map,
|
|
15
|
+
prefix: void 0,
|
|
16
|
+
columns: authored.columns,
|
|
17
|
+
where: void 0,
|
|
18
|
+
unique: false,
|
|
19
|
+
type: authored.type,
|
|
20
|
+
options: authored.options
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const prefix = authored.name ?? defaultIndexName(tableName, authored.columns);
|
|
24
|
+
assertWireNamePrefixLength(prefix, "index prefix");
|
|
25
|
+
return {
|
|
26
|
+
name: formatWireName(prefix, computeIndexContentHash({
|
|
27
|
+
columns: authored.columns,
|
|
28
|
+
unique: false,
|
|
29
|
+
...authored.type !== void 0 && { type: authored.type },
|
|
30
|
+
...authored.options !== void 0 && { options: authored.options }
|
|
31
|
+
})),
|
|
32
|
+
prefix,
|
|
33
|
+
columns: authored.columns,
|
|
34
|
+
where: void 0,
|
|
35
|
+
unique: false,
|
|
36
|
+
type: authored.type,
|
|
37
|
+
options: authored.options
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { lowerAuthoredIndex as t };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=index-naming-DsnarUVW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-naming-DsnarUVW.mjs","names":[],"sources":["../src/index-naming.ts"],"sourcesContent":["import {\n assertWireNamePrefixLength,\n computeIndexContentHash,\n defaultIndexName,\n formatWireName,\n} from '@prisma-next/sql-schema-ir/naming';\nimport { InternalError } from '@prisma-next/utils/internal-error';\nimport type { IndexInput } from './ir/sql-index';\n\n/**\n * An index as authored, before naming: `map` is an exact physical name\n * (adopted verbatim, PSL `map:`); `name` is a managed wire-name prefix\n * (TS `name:`). With neither, the managed prefix defaults to\n * `defaultIndexName(table, columns)`.\n */\nexport interface AuthoredIndexInput {\n readonly columns: readonly string[];\n readonly map: string | undefined;\n readonly name: string | undefined;\n readonly type: string | undefined;\n readonly options: Record<string, unknown> | undefined;\n}\n\n/**\n * Lowers an authored index into the name-identified entity `contract.json`\n * persists: exact mode adopts `map` verbatim (no prefix, no hash); managed\n * mode appends the content-hash suffix to the authored or default prefix.\n * `unique` always lowers `false` — no authoring surface sets it yet.\n */\nexport function lowerAuthoredIndex(tableName: string, authored: AuthoredIndexInput): IndexInput {\n if (authored.map !== undefined) {\n if (authored.name !== undefined) {\n throw new InternalError(\n `Index \"${authored.map}\" on table \"${tableName}\": map and name are mutually exclusive.`,\n );\n }\n return {\n name: authored.map,\n prefix: undefined,\n columns: authored.columns,\n where: undefined,\n unique: false,\n type: authored.type,\n options: authored.options,\n };\n }\n\n const prefix = authored.name ?? defaultIndexName(tableName, authored.columns);\n assertWireNamePrefixLength(prefix, 'index prefix');\n const hash = computeIndexContentHash({\n columns: authored.columns,\n unique: false,\n ...(authored.type !== undefined && { type: authored.type }),\n ...(authored.options !== undefined && { options: authored.options }),\n });\n return {\n name: formatWireName(prefix, hash),\n prefix,\n columns: authored.columns,\n where: undefined,\n unique: false,\n type: authored.type,\n options: authored.options,\n };\n}\n"],"mappings":";;;;;;;;;AA6BA,SAAgB,mBAAmB,WAAmB,UAA0C;CAC9F,IAAI,SAAS,QAAQ,KAAA,GAAW;EAC9B,IAAI,SAAS,SAAS,KAAA,GACpB,MAAM,IAAI,cACR,UAAU,SAAS,IAAI,cAAc,UAAU,wCACjD;EAEF,OAAO;GACL,MAAM,SAAS;GACf,QAAQ,KAAA;GACR,SAAS,SAAS;GAClB,OAAO,KAAA;GACP,QAAQ;GACR,MAAM,SAAS;GACf,SAAS,SAAS;EACpB;CACF;CAEA,MAAM,SAAS,SAAS,QAAQ,iBAAiB,WAAW,SAAS,OAAO;CAC5E,2BAA2B,QAAQ,cAAc;CAOjD,OAAO;EACL,MAAM,eAAe,QAPV,wBAAwB;GACnC,SAAS,SAAS;GAClB,QAAQ;GACR,GAAI,SAAS,SAAS,KAAA,KAAa,EAAE,MAAM,SAAS,KAAK;GACzD,GAAI,SAAS,YAAY,KAAA,KAAa,EAAE,SAAS,SAAS,QAAQ;EACpE,CAEkC,CAAC;EACjC;EACA,SAAS,SAAS;EAClB,OAAO,KAAA;EACP,QAAQ;EACR,MAAM,SAAS;EACf,SAAS,SAAS;CACpB;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { n as IndexInput } from "./sql-index-Wzbj2nbH.mjs";
|
|
2
|
+
//#region src/index-naming.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* An index as authored, before naming: `map` is an exact physical name
|
|
5
|
+
* (adopted verbatim, PSL `map:`); `name` is a managed wire-name prefix
|
|
6
|
+
* (TS `name:`). With neither, the managed prefix defaults to
|
|
7
|
+
* `defaultIndexName(table, columns)`.
|
|
8
|
+
*/
|
|
9
|
+
interface AuthoredIndexInput {
|
|
10
|
+
readonly columns: readonly string[];
|
|
11
|
+
readonly map: string | undefined;
|
|
12
|
+
readonly name: string | undefined;
|
|
13
|
+
readonly type: string | undefined;
|
|
14
|
+
readonly options: Record<string, unknown> | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Lowers an authored index into the name-identified entity `contract.json`
|
|
18
|
+
* persists: exact mode adopts `map` verbatim (no prefix, no hash); managed
|
|
19
|
+
* mode appends the content-hash suffix to the authored or default prefix.
|
|
20
|
+
* `unique` always lowers `false` — no authoring surface sets it yet.
|
|
21
|
+
*/
|
|
22
|
+
declare function lowerAuthoredIndex(tableName: string, authored: AuthoredIndexInput): IndexInput;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { type AuthoredIndexInput, lowerAuthoredIndex };
|
|
25
|
+
//# sourceMappingURL=index-naming.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-naming.d.mts","names":[],"sources":["../src/index-naming.ts"],"mappings":";;;;;;;;UAeiB;WACN;WACA;WACA;WACA;WACA,SAAS;;;;;;;;iBASJ,mBAAmB,mBAAmB,UAAU,qBAAqB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { s as SqlStorage } from "./sql-storage-
|
|
2
|
-
import "./types-
|
|
1
|
+
import { s as SqlStorage } from "./sql-storage-DjqU3XXV.mjs";
|
|
2
|
+
import "./types-Bxa1Pyzg.mjs";
|
|
3
3
|
import { a as IndexTypeRegistry } from "./index-types-DPVhsW0v.mjs";
|
|
4
4
|
import { Contract } from "@prisma-next/contract/types";
|
|
5
5
|
//#region src/index-type-validation.d.ts
|
|
@@ -3,13 +3,13 @@ import { ContractValidationError } from "@prisma-next/contract/contract-validati
|
|
|
3
3
|
//#region src/index-type-validation.ts
|
|
4
4
|
function validateIndexTypes(contract, indexTypeRegistry) {
|
|
5
5
|
for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) for (const index of table.indexes) {
|
|
6
|
-
if (index.type === void 0 && index.options !== void 0) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index
|
|
6
|
+
if (index.type === void 0 && index.options !== void 0) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index "${index.name}" has options without a type`, "storage");
|
|
7
7
|
if (index.type === void 0) continue;
|
|
8
8
|
const entry = indexTypeRegistry.get(index.type);
|
|
9
|
-
if (entry === void 0) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index
|
|
9
|
+
if (entry === void 0) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index "${index.name}" uses unregistered index type "${index.type}"`, "storage");
|
|
10
10
|
const optionsValue = index.options ?? {};
|
|
11
11
|
const result = entry.options(optionsValue);
|
|
12
|
-
if (result instanceof type.errors) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index
|
|
12
|
+
if (result instanceof type.errors) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index "${index.name}" has invalid options for type "${index.type}": ${result.summary}`, "storage");
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-type-validation.mjs","names":[],"sources":["../src/index-type-validation.ts"],"sourcesContent":["import { ContractValidationError } from '@prisma-next/contract/contract-validation-error';\nimport type { Contract } from '@prisma-next/contract/types';\nimport { type } from 'arktype';\nimport type { IndexTypeRegistry } from './index-types';\nimport type { SqlStorage } from './types';\n\nexport function validateIndexTypes(\n contract: Contract<SqlStorage>,\n indexTypeRegistry: IndexTypeRegistry,\n): void {\n for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) {\n for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) {\n for (const index of table.indexes) {\n if (index.type === undefined && index.options !== undefined) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index
|
|
1
|
+
{"version":3,"file":"index-type-validation.mjs","names":[],"sources":["../src/index-type-validation.ts"],"sourcesContent":["import { ContractValidationError } from '@prisma-next/contract/contract-validation-error';\nimport type { Contract } from '@prisma-next/contract/types';\nimport { type } from 'arktype';\nimport type { IndexTypeRegistry } from './index-types';\nimport type { SqlStorage } from './types';\n\nexport function validateIndexTypes(\n contract: Contract<SqlStorage>,\n indexTypeRegistry: IndexTypeRegistry,\n): void {\n for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) {\n for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) {\n for (const index of table.indexes) {\n if (index.type === undefined && index.options !== undefined) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index \"${index.name}\" has options without a type`,\n 'storage',\n );\n }\n if (index.type === undefined) continue;\n const entry = indexTypeRegistry.get(index.type);\n if (entry === undefined) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index \"${index.name}\" uses unregistered index type \"${index.type}\"`,\n 'storage',\n );\n }\n const optionsValue = index.options ?? {};\n const result = entry.options(optionsValue);\n if (result instanceof type.errors) {\n throw new ContractValidationError(\n `Namespace \"${namespaceId}\" table \"${tableName}\" index \"${index.name}\" has invalid options for type \"${index.type}\": ${result.summary}`,\n 'storage',\n );\n }\n }\n }\n }\n}\n"],"mappings":";;;AAMA,SAAgB,mBACd,UACA,mBACM;CACN,KAAK,MAAM,CAAC,aAAa,OAAO,OAAO,QAAQ,SAAS,QAAQ,UAAU,GACxE,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,GAAG,QAAQ,SAAS,CAAC,CAAC,GACpE,KAAK,MAAM,SAAS,MAAM,SAAS;EACjC,IAAI,MAAM,SAAS,KAAA,KAAa,MAAM,YAAY,KAAA,GAChD,MAAM,IAAI,wBACR,cAAc,YAAY,WAAW,UAAU,WAAW,MAAM,KAAK,+BACrE,SACF;EAEF,IAAI,MAAM,SAAS,KAAA,GAAW;EAC9B,MAAM,QAAQ,kBAAkB,IAAI,MAAM,IAAI;EAC9C,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,wBACR,cAAc,YAAY,WAAW,UAAU,WAAW,MAAM,KAAK,kCAAkC,MAAM,KAAK,IAClH,SACF;EAEF,MAAM,eAAe,MAAM,WAAW,CAAC;EACvC,MAAM,SAAS,MAAM,QAAQ,YAAY;EACzC,IAAI,kBAAkB,KAAK,QACzB,MAAM,IAAI,wBACR,cAAc,YAAY,WAAW,UAAU,WAAW,MAAM,KAAK,kCAAkC,MAAM,KAAK,KAAK,OAAO,WAC9H,SACF;CAEJ;AAGN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-types-DPVhsW0v.d.mts","names":[],"sources":["../src/index-types.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index-types-DPVhsW0v.d.mts","names":[],"sources":["../src/index-types.ts"],"mappings":";;UAGiB,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;;;iBA8B9C,oBAAoB,iBAAiB;UAIpC;EACf,SAAS,OAAO;EAChB,IAAI,sBAAsB;EAC1B,IAAI;;iBA0BU,2BAA2B"}
|
package/dist/index-types.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as contractError } from "./contract-errors-CPZcBw8G.mjs";
|
|
1
2
|
//#region src/index-types.ts
|
|
2
3
|
var IndexTypeBuilderImpl = class IndexTypeBuilderImpl {
|
|
3
4
|
entries;
|
|
@@ -7,7 +8,7 @@ var IndexTypeBuilderImpl = class IndexTypeBuilderImpl {
|
|
|
7
8
|
this.IndexTypes = {};
|
|
8
9
|
}
|
|
9
10
|
add(typeLiteral, entry) {
|
|
10
|
-
if (this.entries.some((e) => e.type === typeLiteral)) throw
|
|
11
|
+
if (this.entries.some((e) => e.type === typeLiteral)) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Index type "${typeLiteral}" is already declared in this builder`, { meta: { indexType: typeLiteral } });
|
|
11
12
|
return new IndexTypeBuilderImpl([...this.entries, {
|
|
12
13
|
type: typeLiteral,
|
|
13
14
|
options: entry.options
|
|
@@ -20,7 +21,7 @@ function defineIndexTypes() {
|
|
|
20
21
|
var IndexTypeRegistryImpl = class {
|
|
21
22
|
entries = /* @__PURE__ */ new Map();
|
|
22
23
|
register(entry) {
|
|
23
|
-
if (this.entries.has(entry.type)) throw
|
|
24
|
+
if (this.entries.has(entry.type)) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Index type "${entry.type}" is already registered`, { meta: { indexType: entry.type } });
|
|
24
25
|
this.entries.set(entry.type, entry);
|
|
25
26
|
}
|
|
26
27
|
get(typeLiteral) {
|
package/dist/index-types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-types.mjs","names":[],"sources":["../src/index-types.ts"],"sourcesContent":["import type { Type } from 'arktype';\n\nexport interface IndexTypeEntry<TOptions = unknown> {\n readonly type: string;\n readonly options: Type<TOptions>;\n}\n\nexport type IndexTypeMap = { readonly [K in string]: { readonly options: unknown } };\n\nexport interface IndexTypeRegistration<TMap extends IndexTypeMap = Record<never, never>> {\n readonly IndexTypes: TMap;\n readonly entries: ReadonlyArray<IndexTypeEntry>;\n}\n\nexport interface IndexTypeBuilder<TMap extends IndexTypeMap = Record<never, never>>\n extends IndexTypeRegistration<TMap> {\n add<TLit extends string, TOpts>(\n typeLiteral: TLit,\n entry: { readonly options: Type<TOpts> },\n ): IndexTypeBuilder<TMap & Record<TLit, { readonly options: TOpts }>>;\n}\n\nclass IndexTypeBuilderImpl<TMap extends IndexTypeMap> implements IndexTypeBuilder<TMap> {\n readonly entries: ReadonlyArray<IndexTypeEntry>;\n readonly IndexTypes: TMap;\n\n constructor(entries: ReadonlyArray<IndexTypeEntry>) {\n this.entries = entries;\n this.IndexTypes = {} as TMap;\n }\n\n add<TLit extends string, TOpts>(\n typeLiteral: TLit,\n entry: { readonly options: Type<TOpts> },\n ): IndexTypeBuilder<TMap & Record<TLit, { readonly options: TOpts }>> {\n if (this.entries.some((e) => e.type === typeLiteral)) {\n throw
|
|
1
|
+
{"version":3,"file":"index-types.mjs","names":[],"sources":["../src/index-types.ts"],"sourcesContent":["import type { Type } from 'arktype';\nimport { contractError } from './contract-errors';\n\nexport interface IndexTypeEntry<TOptions = unknown> {\n readonly type: string;\n readonly options: Type<TOptions>;\n}\n\nexport type IndexTypeMap = { readonly [K in string]: { readonly options: unknown } };\n\nexport interface IndexTypeRegistration<TMap extends IndexTypeMap = Record<never, never>> {\n readonly IndexTypes: TMap;\n readonly entries: ReadonlyArray<IndexTypeEntry>;\n}\n\nexport interface IndexTypeBuilder<TMap extends IndexTypeMap = Record<never, never>>\n extends IndexTypeRegistration<TMap> {\n add<TLit extends string, TOpts>(\n typeLiteral: TLit,\n entry: { readonly options: Type<TOpts> },\n ): IndexTypeBuilder<TMap & Record<TLit, { readonly options: TOpts }>>;\n}\n\nclass IndexTypeBuilderImpl<TMap extends IndexTypeMap> implements IndexTypeBuilder<TMap> {\n readonly entries: ReadonlyArray<IndexTypeEntry>;\n readonly IndexTypes: TMap;\n\n constructor(entries: ReadonlyArray<IndexTypeEntry>) {\n this.entries = entries;\n this.IndexTypes = {} as TMap;\n }\n\n add<TLit extends string, TOpts>(\n typeLiteral: TLit,\n entry: { readonly options: Type<TOpts> },\n ): IndexTypeBuilder<TMap & Record<TLit, { readonly options: TOpts }>> {\n if (this.entries.some((e) => e.type === typeLiteral)) {\n throw contractError(\n 'CONTRACT.PACK_CONTRIBUTION_INVALID',\n `Index type \"${typeLiteral}\" is already declared in this builder`,\n { meta: { indexType: typeLiteral } },\n );\n }\n return new IndexTypeBuilderImpl<TMap & Record<TLit, { readonly options: TOpts }>>([\n ...this.entries,\n { type: typeLiteral, options: entry.options as Type<unknown> },\n ]);\n }\n}\n\nexport function defineIndexTypes(): IndexTypeBuilder<Record<never, never>> {\n return new IndexTypeBuilderImpl([]);\n}\n\nexport interface IndexTypeRegistry {\n register(entry: IndexTypeEntry): void;\n get(typeLiteral: string): IndexTypeEntry | undefined;\n has(typeLiteral: string): boolean;\n}\n\nclass IndexTypeRegistryImpl implements IndexTypeRegistry {\n private readonly entries = new Map<string, IndexTypeEntry>();\n\n register(entry: IndexTypeEntry): void {\n if (this.entries.has(entry.type)) {\n throw contractError(\n 'CONTRACT.PACK_CONTRIBUTION_INVALID',\n `Index type \"${entry.type}\" is already registered`,\n { meta: { indexType: entry.type } },\n );\n }\n this.entries.set(entry.type, entry);\n }\n\n get(typeLiteral: string): IndexTypeEntry | undefined {\n return this.entries.get(typeLiteral);\n }\n\n has(typeLiteral: string): boolean {\n return this.entries.has(typeLiteral);\n }\n}\n\nexport function createIndexTypeRegistry(): IndexTypeRegistry {\n return new IndexTypeRegistryImpl();\n}\n"],"mappings":";;AAuBA,IAAM,uBAAN,MAAM,qBAAkF;CACtF;CACA;CAEA,YAAY,SAAwC;EAClD,KAAK,UAAU;EACf,KAAK,aAAa,CAAC;CACrB;CAEA,IACE,aACA,OACoE;EACpE,IAAI,KAAK,QAAQ,MAAM,MAAM,EAAE,SAAS,WAAW,GACjD,MAAM,cACJ,sCACA,eAAe,YAAY,wCAC3B,EAAE,MAAM,EAAE,WAAW,YAAY,EAAE,CACrC;EAEF,OAAO,IAAI,qBAAuE,CAChF,GAAG,KAAK,SACR;GAAE,MAAM;GAAa,SAAS,MAAM;EAAyB,CAC/D,CAAC;CACH;AACF;AAEA,SAAgB,mBAA2D;CACzE,OAAO,IAAI,qBAAqB,CAAC,CAAC;AACpC;AAQA,IAAM,wBAAN,MAAyD;CACvD,0BAA2B,IAAI,IAA4B;CAE3D,SAAS,OAA6B;EACpC,IAAI,KAAK,QAAQ,IAAI,MAAM,IAAI,GAC7B,MAAM,cACJ,sCACA,eAAe,MAAM,KAAK,0BAC1B,EAAE,MAAM,EAAE,WAAW,MAAM,KAAK,EAAE,CACpC;EAEF,KAAK,QAAQ,IAAI,MAAM,MAAM,KAAK;CACpC;CAEA,IAAI,aAAiD;EACnD,OAAO,KAAK,QAAQ,IAAI,WAAW;CACrC;CAEA,IAAI,aAA8B;EAChC,OAAO,KAAK,QAAQ,IAAI,WAAW;CACrC;AACF;AAEA,SAAgB,0BAA6C;CAC3D,OAAO,IAAI,sBAAsB;AACnC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as StorageTable } from "./storage-table-
|
|
2
|
-
import { s as SqlStorage } from "./sql-storage-
|
|
1
|
+
import { t as StorageTable } from "./storage-table-zrxIuCJ3.mjs";
|
|
2
|
+
import { s as SqlStorage } from "./sql-storage-DjqU3XXV.mjs";
|
|
3
3
|
//#region src/resolve-storage-table.d.ts
|
|
4
4
|
interface ResolvedStorageTable {
|
|
5
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":";;;UAKiB;WACN;WACA,OAAO;;;;;;;;;;;iBAYF,oBACd,SAAS,YACT,mBACA,uBACC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as contractError } from "./contract-errors-CPZcBw8G.mjs";
|
|
1
2
|
import { entityAt } from "@prisma-next/framework-components/ir";
|
|
2
3
|
//#region src/resolve-storage-table.ts
|
|
3
4
|
/**
|
|
@@ -33,10 +34,10 @@ function resolveStorageTable(storage, tableName, namespaceId) {
|
|
|
33
34
|
table
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
|
-
if (matches.length > 1) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
37
|
+
if (matches.length > 1) throw contractError("CONTRACT.TABLE_AMBIGUOUS", `Storage table "${tableName}" is ambiguous across namespaces [${matches.map((match) => match.namespaceId).sort().join(", ")}]; qualify it with a namespace coordinate.`, { meta: {
|
|
38
|
+
tableName,
|
|
39
|
+
candidates: matches.map((match) => match.namespaceId).sort()
|
|
40
|
+
} });
|
|
40
41
|
return matches[0];
|
|
41
42
|
}
|
|
42
43
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-storage-table.mjs","names":[],"sources":["../src/resolve-storage-table.ts"],"sourcesContent":["import { entityAt } from '@prisma-next/framework-components/ir';\nimport type { SqlStorage } from './ir/sql-storage';\nimport type { StorageTable } from './ir/storage-table';\n\nexport interface ResolvedStorageTable {\n readonly namespaceId: string;\n readonly table: StorageTable;\n}\n\n/**\n * Resolve a bare storage table name to its namespace coordinate and table IR.\n *\n * When `namespaceId` is supplied, the table is resolved strictly within that\n * namespace (no scan). When omitted, a bare name unique across namespaces\n * resolves to its sole namespace; a bare name declared in more than one\n * namespace throws a fail-fast diagnostic naming the candidate namespaces\n * rather than silently selecting the first match.\n */\nexport function resolveStorageTable(\n storage: SqlStorage,\n tableName: string,\n namespaceId?: string,\n): ResolvedStorageTable | undefined {\n if (namespaceId !== undefined) {\n const table = entityAt<StorageTable>(storage, {\n namespaceId,\n entityKind: 'table',\n entityName: tableName,\n });\n return table === undefined ? undefined : { namespaceId, table };\n }\n\n const matches: ResolvedStorageTable[] = [];\n for (const candidateNamespaceId of Object.keys(storage.namespaces)) {\n const table = entityAt<StorageTable>(storage, {\n namespaceId: candidateNamespaceId,\n entityKind: 'table',\n entityName: tableName,\n });\n if (table !== undefined) {\n matches.push({ namespaceId: candidateNamespaceId, table });\n }\n }\n\n if (matches.length > 1) {\n const candidates = matches\n .map((match) => match.namespaceId)\n .sort()\n .join(', ');\n throw
|
|
1
|
+
{"version":3,"file":"resolve-storage-table.mjs","names":[],"sources":["../src/resolve-storage-table.ts"],"sourcesContent":["import { entityAt } from '@prisma-next/framework-components/ir';\nimport { contractError } from './contract-errors';\nimport type { SqlStorage } from './ir/sql-storage';\nimport type { StorageTable } from './ir/storage-table';\n\nexport interface ResolvedStorageTable {\n readonly namespaceId: string;\n readonly table: StorageTable;\n}\n\n/**\n * Resolve a bare storage table name to its namespace coordinate and table IR.\n *\n * When `namespaceId` is supplied, the table is resolved strictly within that\n * namespace (no scan). When omitted, a bare name unique across namespaces\n * resolves to its sole namespace; a bare name declared in more than one\n * namespace throws a fail-fast diagnostic naming the candidate namespaces\n * rather than silently selecting the first match.\n */\nexport function resolveStorageTable(\n storage: SqlStorage,\n tableName: string,\n namespaceId?: string,\n): ResolvedStorageTable | undefined {\n if (namespaceId !== undefined) {\n const table = entityAt<StorageTable>(storage, {\n namespaceId,\n entityKind: 'table',\n entityName: tableName,\n });\n return table === undefined ? undefined : { namespaceId, table };\n }\n\n const matches: ResolvedStorageTable[] = [];\n for (const candidateNamespaceId of Object.keys(storage.namespaces)) {\n const table = entityAt<StorageTable>(storage, {\n namespaceId: candidateNamespaceId,\n entityKind: 'table',\n entityName: tableName,\n });\n if (table !== undefined) {\n matches.push({ namespaceId: candidateNamespaceId, table });\n }\n }\n\n if (matches.length > 1) {\n const candidates = matches\n .map((match) => match.namespaceId)\n .sort()\n .join(', ');\n throw contractError(\n 'CONTRACT.TABLE_AMBIGUOUS',\n `Storage table \"${tableName}\" is ambiguous across namespaces [${candidates}]; qualify it with a namespace coordinate.`,\n { meta: { tableName, candidates: matches.map((match) => match.namespaceId).sort() } },\n );\n }\n\n return matches[0];\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,oBACd,SACA,WACA,aACkC;CAClC,IAAI,gBAAgB,KAAA,GAAW;EAC7B,MAAM,QAAQ,SAAuB,SAAS;GAC5C;GACA,YAAY;GACZ,YAAY;EACd,CAAC;EACD,OAAO,UAAU,KAAA,IAAY,KAAA,IAAY;GAAE;GAAa;EAAM;CAChE;CAEA,MAAM,UAAkC,CAAC;CACzC,KAAK,MAAM,wBAAwB,OAAO,KAAK,QAAQ,UAAU,GAAG;EAClE,MAAM,QAAQ,SAAuB,SAAS;GAC5C,aAAa;GACb,YAAY;GACZ,YAAY;EACd,CAAC;EACD,IAAI,UAAU,KAAA,GACZ,QAAQ,KAAK;GAAE,aAAa;GAAsB;EAAM,CAAC;CAE7D;CAEA,IAAI,QAAQ,SAAS,GAKnB,MAAM,cACJ,4BACA,kBAAkB,UAAU,oCANX,QAChB,KAAK,UAAU,MAAM,WAAW,CAAC,CACjC,KAAK,CAAC,CACN,KAAK,IAGmE,EAAE,6CAC3E,EAAE,MAAM;EAAE;EAAW,YAAY,QAAQ,KAAK,UAAU,MAAM,WAAW,CAAC,CAAC,KAAK;CAAE,EAAE,CACtF;CAGF,OAAO,QAAQ;AACjB"}
|