@prisma-next/sql-contract 0.5.0-dev.80 → 0.5.0-dev.82
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/factories.d.mts +1 -1
- package/dist/index-type-validation.d.mts +9 -0
- package/dist/index-type-validation.d.mts.map +1 -0
- package/dist/index-type-validation.mjs +18 -0
- package/dist/index-type-validation.mjs.map +1 -0
- package/dist/index-types-DqVqGHwg.d.mts +31 -0
- package/dist/index-types-DqVqGHwg.d.mts.map +1 -0
- package/dist/index-types.d.mts +2 -0
- package/dist/index-types.mjs +39 -0
- package/dist/index-types.mjs.map +1 -0
- package/dist/{types-CjGH62ec.d.mts → types-BTYquqSU.d.mts} +3 -11
- package/dist/types-BTYquqSU.d.mts.map +1 -0
- package/dist/types-hgzy8ME1.mjs.map +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/validate.d.mts +1 -1
- package/dist/validate.mjs +1 -1
- package/dist/{validators-CSYfYN19.mjs → validators-Dm5X-Hvg.mjs} +6 -5
- package/dist/{validators-CSYfYN19.mjs.map → validators-Dm5X-Hvg.mjs.map} +1 -1
- package/dist/validators.d.mts +3 -3
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +1 -1
- package/package.json +5 -3
- package/src/exports/index-type-validation.ts +1 -0
- package/src/exports/index-types.ts +9 -0
- package/src/index-type-validation.ts +37 -0
- package/src/index-types.ts +77 -0
- package/src/index.ts +2 -0
- package/src/types.ts +2 -10
- package/src/validators.ts +7 -4
- package/dist/types-CjGH62ec.d.mts.map +0 -1
package/dist/factories.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as StorageColumn, D as SqlModelStorage, E as SqlModelFieldStorage, F as UniqueConstraint, _ as PrimaryKey, f as ForeignKey, h as Index, j as StorageTable, p as ForeignKeyOptions } from "./types-
|
|
1
|
+
import { A as StorageColumn, D as SqlModelStorage, E as SqlModelFieldStorage, F as UniqueConstraint, _ as PrimaryKey, f as ForeignKey, h as Index, j as StorageTable, p as ForeignKeyOptions } from "./types-BTYquqSU.mjs";
|
|
2
2
|
import { ScalarFieldType } from "@prisma-next/contract/types";
|
|
3
3
|
|
|
4
4
|
//#region src/factories.d.ts
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { k as SqlStorage } from "./types-BTYquqSU.mjs";
|
|
2
|
+
import { a as IndexTypeRegistry } from "./index-types-DqVqGHwg.mjs";
|
|
3
|
+
import { Contract } from "@prisma-next/contract/types";
|
|
4
|
+
|
|
5
|
+
//#region src/index-type-validation.d.ts
|
|
6
|
+
declare function validateIndexTypes(contract: Contract<SqlStorage>, indexTypeRegistry: IndexTypeRegistry): void;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { validateIndexTypes };
|
|
9
|
+
//# sourceMappingURL=index-type-validation.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-type-validation.d.mts","names":[],"sources":["../src/index-type-validation.ts"],"mappings":";;;;;iBAMgB,kBAAA,CACd,QAAA,EAAU,QAAA,CAAS,UAAA,GACnB,iBAAA,EAAmB,iBAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ContractValidationError } from "@prisma-next/contract/validate-contract";
|
|
2
|
+
import { type } from "arktype";
|
|
3
|
+
//#region src/index-type-validation.ts
|
|
4
|
+
function validateIndexTypes(contract, indexTypeRegistry) {
|
|
5
|
+
for (const [tableName, table] of Object.entries(contract.storage.tables)) for (const index of table.indexes) {
|
|
6
|
+
if (index.type === void 0 && index.options !== void 0) throw new ContractValidationError(`Table "${tableName}" index on columns [${index.columns.join(", ")}] has options without a type`, "storage");
|
|
7
|
+
if (index.type === void 0) continue;
|
|
8
|
+
const entry = indexTypeRegistry.get(index.type);
|
|
9
|
+
if (entry === void 0) throw new ContractValidationError(`Table "${tableName}" index on columns [${index.columns.join(", ")}] uses unregistered index type "${index.type}"`, "storage");
|
|
10
|
+
const optionsValue = index.options ?? {};
|
|
11
|
+
const result = entry.options(optionsValue);
|
|
12
|
+
if (result instanceof type.errors) throw new ContractValidationError(`Table "${tableName}" index on columns [${index.columns.join(", ")}] has invalid options for type "${index.type}": ${result.summary}`, "storage");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { validateIndexTypes };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=index-type-validation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-type-validation.mjs","names":[],"sources":["../src/index-type-validation.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport { ContractValidationError } from '@prisma-next/contract/validate-contract';\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 [tableName, table] of Object.entries(contract.storage.tables)) {\n for (const index of table.indexes) {\n if (index.type === undefined && index.options !== undefined) {\n throw new ContractValidationError(\n `Table \"${tableName}\" index on columns [${index.columns.join(', ')}] 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 `Table \"${tableName}\" index on columns [${index.columns.join(', ')}] 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 `Table \"${tableName}\" index on columns [${index.columns.join(', ')}] has invalid options for type \"${index.type}\": ${result.summary}`,\n 'storage',\n );\n }\n }\n }\n}\n"],"mappings":";;;AAMA,SAAgB,mBACd,UACA,mBACM;CACN,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,SAAS,QAAQ,OAAO,EACtE,KAAK,MAAM,SAAS,MAAM,SAAS;EACjC,IAAI,MAAM,SAAS,KAAA,KAAa,MAAM,YAAY,KAAA,GAChD,MAAM,IAAI,wBACR,UAAU,UAAU,sBAAsB,MAAM,QAAQ,KAAK,KAAK,CAAC,+BACnE,UACD;EAEH,IAAI,MAAM,SAAS,KAAA,GAAW;EAC9B,MAAM,QAAQ,kBAAkB,IAAI,MAAM,KAAK;EAC/C,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,wBACR,UAAU,UAAU,sBAAsB,MAAM,QAAQ,KAAK,KAAK,CAAC,kCAAkC,MAAM,KAAK,IAChH,UACD;EAEH,MAAM,eAAe,MAAM,WAAW,EAAE;EACxC,MAAM,SAAS,MAAM,QAAQ,aAAa;EAC1C,IAAI,kBAAkB,KAAK,QACzB,MAAM,IAAI,wBACR,UAAU,UAAU,sBAAsB,MAAM,QAAQ,KAAK,KAAK,CAAC,kCAAkC,MAAM,KAAK,KAAK,OAAO,WAC5H,UACD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Type } from "arktype";
|
|
2
|
+
|
|
3
|
+
//#region src/index-types.d.ts
|
|
4
|
+
interface IndexTypeEntry<TOptions = unknown> {
|
|
5
|
+
readonly type: string;
|
|
6
|
+
readonly options: Type<TOptions>;
|
|
7
|
+
}
|
|
8
|
+
type IndexTypeMap = { readonly [K in string]: {
|
|
9
|
+
readonly options: unknown;
|
|
10
|
+
} };
|
|
11
|
+
interface IndexTypeRegistration<TMap extends IndexTypeMap = Record<never, never>> {
|
|
12
|
+
readonly IndexTypes: TMap;
|
|
13
|
+
readonly entries: ReadonlyArray<IndexTypeEntry>;
|
|
14
|
+
}
|
|
15
|
+
interface IndexTypeBuilder<TMap extends IndexTypeMap = Record<never, never>> extends IndexTypeRegistration<TMap> {
|
|
16
|
+
add<TLit extends string, TOpts>(typeLiteral: TLit, entry: {
|
|
17
|
+
readonly options: Type<TOpts>;
|
|
18
|
+
}): IndexTypeBuilder<TMap & Record<TLit, {
|
|
19
|
+
readonly options: TOpts;
|
|
20
|
+
}>>;
|
|
21
|
+
}
|
|
22
|
+
declare function defineIndexTypes(): IndexTypeBuilder<Record<never, never>>;
|
|
23
|
+
interface IndexTypeRegistry {
|
|
24
|
+
register(entry: IndexTypeEntry): void;
|
|
25
|
+
get(typeLiteral: string): IndexTypeEntry | undefined;
|
|
26
|
+
has(typeLiteral: string): boolean;
|
|
27
|
+
}
|
|
28
|
+
declare function createIndexTypeRegistry(): IndexTypeRegistry;
|
|
29
|
+
//#endregion
|
|
30
|
+
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-DqVqGHwg.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-types-DqVqGHwg.d.mts","names":[],"sources":["../src/index-types.ts"],"mappings":";;;UAEiB,cAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA,EAAS,IAAA,CAAK,QAAA;AAAA;AAAA,KAGb,YAAA;EAAA,SAAoD,OAAA;AAAA;AAAA,UAE/C,qBAAA,cAAmC,YAAA,GAAe,MAAA;EAAA,SACxD,UAAA,EAAY,IAAA;EAAA,SACZ,OAAA,EAAS,aAAA,CAAc,cAAA;AAAA;AAAA,UAGjB,gBAAA,cAA8B,YAAA,GAAe,MAAA,wBACpD,qBAAA,CAAsB,IAAA;EAC9B,GAAA,6BACE,WAAA,EAAa,IAAA,EACb,KAAA;IAAA,SAAkB,OAAA,EAAS,IAAA,CAAK,KAAA;EAAA,IAC/B,gBAAA,CAAiB,IAAA,GAAO,MAAA,CAAO,IAAA;IAAA,SAAiB,OAAA,EAAS,KAAA;EAAA;AAAA;AAAA,iBA0B9C,gBAAA,CAAA,GAAoB,gBAAA,CAAiB,MAAA;AAAA,UAIpC,iBAAA;EACf,QAAA,CAAS,KAAA,EAAO,cAAA;EAChB,GAAA,CAAI,WAAA,WAAsB,cAAA;EAC1B,GAAA,CAAI,WAAA;AAAA;AAAA,iBAsBU,uBAAA,CAAA,GAA2B,iBAAA"}
|
|
@@ -0,0 +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-DqVqGHwg.mjs";
|
|
2
|
+
export { type IndexTypeBuilder, type IndexTypeEntry, type IndexTypeMap, type IndexTypeRegistration, type IndexTypeRegistry, createIndexTypeRegistry, defineIndexTypes };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/index-types.ts
|
|
2
|
+
var IndexTypeBuilderImpl = class IndexTypeBuilderImpl {
|
|
3
|
+
entries;
|
|
4
|
+
IndexTypes;
|
|
5
|
+
constructor(entries) {
|
|
6
|
+
this.entries = entries;
|
|
7
|
+
this.IndexTypes = {};
|
|
8
|
+
}
|
|
9
|
+
add(typeLiteral, entry) {
|
|
10
|
+
if (this.entries.some((e) => e.type === typeLiteral)) throw new Error(`Index type "${typeLiteral}" is already declared in this builder`);
|
|
11
|
+
return new IndexTypeBuilderImpl([...this.entries, {
|
|
12
|
+
type: typeLiteral,
|
|
13
|
+
options: entry.options
|
|
14
|
+
}]);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
function defineIndexTypes() {
|
|
18
|
+
return new IndexTypeBuilderImpl([]);
|
|
19
|
+
}
|
|
20
|
+
var IndexTypeRegistryImpl = class {
|
|
21
|
+
entries = /* @__PURE__ */ new Map();
|
|
22
|
+
register(entry) {
|
|
23
|
+
if (this.entries.has(entry.type)) throw new Error(`Index type "${entry.type}" is already registered`);
|
|
24
|
+
this.entries.set(entry.type, entry);
|
|
25
|
+
}
|
|
26
|
+
get(typeLiteral) {
|
|
27
|
+
return this.entries.get(typeLiteral);
|
|
28
|
+
}
|
|
29
|
+
has(typeLiteral) {
|
|
30
|
+
return this.entries.has(typeLiteral);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
function createIndexTypeRegistry() {
|
|
34
|
+
return new IndexTypeRegistryImpl();
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { createIndexTypeRegistry, defineIndexTypes };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=index-types.mjs.map
|
|
@@ -0,0 +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 new Error(`Index type \"${typeLiteral}\" is already declared in this builder`);\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 new Error(`Index type \"${entry.type}\" is already registered`);\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":";AAsBA,IAAM,uBAAN,MAAM,qBAAkF;CACtF;CACA;CAEA,YAAY,SAAwC;EAClD,KAAK,UAAU;EACf,KAAK,aAAa,EAAE;;CAGtB,IACE,aACA,OACoE;EACpE,IAAI,KAAK,QAAQ,MAAM,MAAM,EAAE,SAAS,YAAY,EAClD,MAAM,IAAI,MAAM,eAAe,YAAY,uCAAuC;EAEpF,OAAO,IAAI,qBAAuE,CAChF,GAAG,KAAK,SACR;GAAE,MAAM;GAAa,SAAS,MAAM;GAA0B,CAC/D,CAAC;;;AAIN,SAAgB,mBAA2D;CACzE,OAAO,IAAI,qBAAqB,EAAE,CAAC;;AASrC,IAAM,wBAAN,MAAyD;CACvD,0BAA2B,IAAI,KAA6B;CAE5D,SAAS,OAA6B;EACpC,IAAI,KAAK,QAAQ,IAAI,MAAM,KAAK,EAC9B,MAAM,IAAI,MAAM,eAAe,MAAM,KAAK,yBAAyB;EAErE,KAAK,QAAQ,IAAI,MAAM,MAAM,MAAM;;CAGrC,IAAI,aAAiD;EACnD,OAAO,KAAK,QAAQ,IAAI,YAAY;;CAGtC,IAAI,aAA8B;EAChC,OAAO,KAAK,QAAQ,IAAI,YAAY;;;AAIxC,SAAgB,0BAA6C;CAC3D,OAAO,IAAI,uBAAuB"}
|
|
@@ -41,16 +41,8 @@ type UniqueConstraint = {
|
|
|
41
41
|
type Index = {
|
|
42
42
|
readonly columns: readonly string[];
|
|
43
43
|
readonly name?: string;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* Extension-specific methods are represented as strings and interpreted
|
|
47
|
-
* by the owning extension package.
|
|
48
|
-
*/
|
|
49
|
-
readonly using?: string;
|
|
50
|
-
/**
|
|
51
|
-
* Optional extension-owned index configuration payload.
|
|
52
|
-
*/
|
|
53
|
-
readonly config?: Record<string, unknown>;
|
|
44
|
+
readonly type?: string;
|
|
45
|
+
readonly options?: Record<string, unknown>;
|
|
54
46
|
};
|
|
55
47
|
type ForeignKeyReferences = {
|
|
56
48
|
readonly table: string;
|
|
@@ -196,4 +188,4 @@ type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? Ext
|
|
|
196
188
|
type ResolveOperationTypes<_TContract, TTypeMaps> = OperationTypesOf<TTypeMaps>;
|
|
197
189
|
//#endregion
|
|
198
190
|
export { StorageColumn as A, ReferentialAction as C, SqlModelStorage as D, SqlModelFieldStorage as E, UniqueConstraint as F, applyFkDefaults as I, StorageTypeInstance as M, TypeMaps as N, SqlQueryOperationTypes as O, TypeMapsPhantomKey as P, QueryOperationTypesOf as S, ResolveOperationTypes as T, PrimaryKey as _, ExtractCodecTypes as a, QueryOperationTypeEntry as b, ExtractQueryOperationTypes as c, FieldOutputTypesOf as d, ForeignKey as f, OperationTypesOf as g, Index as h, DEFAULT_FK_INDEX as i, StorageTable as j, SqlStorage as k, ExtractTypeMapsFromContract as l, ForeignKeyReferences as m, ContractWithTypeMaps as n, ExtractFieldInputTypes as o, ForeignKeyOptions as p, DEFAULT_FK_CONSTRAINT as r, ExtractFieldOutputTypes as s, CodecTypesOf as t, FieldInputTypesOf as u, QueryOperationReturn as v, ResolveCodecTypes as w, QueryOperationTypesBase as x, QueryOperationSelfSpec as y };
|
|
199
|
-
//# sourceMappingURL=types-
|
|
191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A,KAC5E,sBAAA,MAA4B,iBAAA,CAAkB,2BAAA,CAA4B,CAAA;AAAA,KAE1E,iBAAA,0BAA2C,SAAA,oBACnD,iBAAA,CAAkB,SAAA,IAClB,YAAA,CAAa,SAAA;AAAA,KAEL,qBAAA,0BAA+C,gBAAA,CAAiB,SAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-hgzy8ME1.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { ColumnDefault, StorageBase } from '@prisma-next/contract/types';\nimport type { CodecTrait } from '@prisma-next/framework-components/codec';\n\n/**\n * A column definition in storage.\n *\n * `typeParams` is optional because most columns use non-parameterized types.\n * Columns with parameterized types can either inline `typeParams` or reference\n * a named {@link StorageTypeInstance} via `typeRef`.\n */\nexport type StorageColumn = {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n /**\n * Opaque, codec-owned JS/type parameters.\n * The codec that owns `codecId` defines the shape and semantics.\n * Mutually exclusive with `typeRef`.\n */\n readonly typeParams?: Record<string, unknown>;\n /**\n * Reference to a named type instance in `storage.types`.\n * Mutually exclusive with `typeParams`.\n */\n readonly typeRef?: string;\n /**\n * Default value for the column.\n * Can be a literal value or database function.\n */\n readonly default?: ColumnDefault;\n};\n\nexport type PrimaryKey = {\n readonly columns: readonly string[];\n readonly name?: string;\n};\n\nexport type UniqueConstraint = {\n readonly columns: readonly string[];\n readonly name?: string;\n};\n\nexport type Index = {\n readonly columns: readonly string[];\n readonly name?: string;\n
|
|
1
|
+
{"version":3,"file":"types-hgzy8ME1.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { ColumnDefault, StorageBase } from '@prisma-next/contract/types';\nimport type { CodecTrait } from '@prisma-next/framework-components/codec';\n\n/**\n * A column definition in storage.\n *\n * `typeParams` is optional because most columns use non-parameterized types.\n * Columns with parameterized types can either inline `typeParams` or reference\n * a named {@link StorageTypeInstance} via `typeRef`.\n */\nexport type StorageColumn = {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n /**\n * Opaque, codec-owned JS/type parameters.\n * The codec that owns `codecId` defines the shape and semantics.\n * Mutually exclusive with `typeRef`.\n */\n readonly typeParams?: Record<string, unknown>;\n /**\n * Reference to a named type instance in `storage.types`.\n * Mutually exclusive with `typeParams`.\n */\n readonly typeRef?: string;\n /**\n * Default value for the column.\n * Can be a literal value or database function.\n */\n readonly default?: ColumnDefault;\n};\n\nexport type PrimaryKey = {\n readonly columns: readonly string[];\n readonly name?: string;\n};\n\nexport type UniqueConstraint = {\n readonly columns: readonly string[];\n readonly name?: string;\n};\n\nexport type Index = {\n readonly columns: readonly string[];\n readonly name?: string;\n readonly type?: string;\n readonly options?: Record<string, unknown>;\n};\n\nexport type ForeignKeyReferences = {\n readonly table: string;\n readonly columns: readonly string[];\n};\n\nexport type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport type ForeignKeyOptions = {\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n};\n\nexport type ForeignKey = {\n readonly columns: readonly string[];\n readonly references: ForeignKeyReferences;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */\n readonly constraint: boolean;\n /** Whether to emit a backing index for the FK columns. */\n readonly index: boolean;\n};\n\nexport type StorageTable = {\n readonly columns: Record<string, StorageColumn>;\n readonly primaryKey?: PrimaryKey;\n readonly uniques: ReadonlyArray<UniqueConstraint>;\n readonly indexes: ReadonlyArray<Index>;\n readonly foreignKeys: ReadonlyArray<ForeignKey>;\n};\n\n/**\n * A named, parameterized type instance.\n * These are registered in `storage.types` for reuse across columns\n * and to enable ergonomic schema surfaces like `schema.types.MyType`.\n *\n * Unlike {@link StorageColumn}, `typeParams` is required here because\n * `StorageTypeInstance` exists specifically to define reusable parameterized types.\n * A type instance without parameters would be redundant—columns can reference\n * the codec directly via `codecId`.\n */\nexport type StorageTypeInstance = {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams: Record<string, unknown>;\n};\n\nexport type SqlStorage<THash extends string = string> = StorageBase<THash> & {\n readonly tables: Record<string, StorageTable>;\n /**\n * Named type instances for parameterized/custom types.\n * Columns can reference these via `typeRef`.\n */\n readonly types?: Record<string, StorageTypeInstance>;\n};\n\nexport type SqlModelFieldStorage = {\n readonly column: string;\n readonly codecId?: string;\n readonly nullable?: boolean;\n};\n\nexport type SqlModelStorage = {\n readonly table: string;\n readonly fields: Record<string, SqlModelFieldStorage>;\n};\n\nexport const DEFAULT_FK_CONSTRAINT = true;\nexport const DEFAULT_FK_INDEX = true;\n\nexport function applyFkDefaults(\n fk: { constraint?: boolean | undefined; index?: boolean | undefined },\n overrideDefaults?: { constraint?: boolean | undefined; index?: boolean | undefined },\n): { constraint: boolean; index: boolean } {\n return {\n constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,\n index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX,\n };\n}\n\nexport type TypeMaps<\n TCodecTypes extends Record<string, { output: unknown }> = Record<string, never>,\n TOperationTypes extends Record<string, unknown> = Record<string, never>,\n TQueryOperationTypes extends Record<string, unknown> = Record<string, never>,\n TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,\n TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly operationTypes: TOperationTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n readonly fieldOutputTypes: TFieldOutputTypes;\n readonly fieldInputTypes: TFieldInputTypes;\n};\n\nexport type CodecTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly codecTypes: infer C }\n ? C extends Record<string, { output: unknown }>\n ? C\n : Record<string, never>\n : Record<string, never>;\n\nexport type OperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly operationTypes: infer O }\n ? O extends Record<string, unknown>\n ? O\n : Record<string, never>\n : Record<string, never>;\n\n/**\n * Dispatch hint identifying the first-argument target of an operation.\n *\n * Used by ORM column helpers to decide whether an operation is reachable on a\n * field. Either names a concrete codec identity or a set of capability traits\n * that the field's codec must carry.\n */\nexport type QueryOperationSelfSpec =\n | { readonly codecId: string; readonly traits?: never }\n | { readonly traits: readonly CodecTrait[]; readonly codecId?: never };\n\n/**\n * Structural shape an operation's impl must return: any value carrying a\n * codec-exact `returnType` descriptor. `Expression<T>` (from\n * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)\n * extends this. Trait-targeted returns are deliberately excluded — predicate\n * detection and result decoding both depend on knowing the concrete return\n * codec.\n */\nexport type QueryOperationReturn = {\n readonly returnType: { readonly codecId: string; readonly nullable: boolean };\n};\n\nexport type QueryOperationTypeEntry = {\n readonly self?: QueryOperationSelfSpec;\n readonly impl: (...args: never[]) => QueryOperationReturn;\n};\n\nexport type SqlQueryOperationTypes<\n _CT extends Record<string, { readonly input: unknown; readonly output: unknown }>,\n T extends Record<string, QueryOperationTypeEntry>,\n> = T;\n\nexport type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;\n\nexport type QueryOperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly queryOperationTypes: infer Q }\n ? Q extends Record<string, unknown>\n ? Q\n : Record<string, never>\n : Record<string, never>;\n\nexport type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';\n\nexport type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & {\n readonly [K in TypeMapsPhantomKey]?: TTypeMaps;\n};\n\nexport type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T\n ? NonNullable<T[TypeMapsPhantomKey & keyof T]>\n : never;\n\nexport type FieldOutputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldOutputTypes: infer F }\n ? F extends Record<string, Record<string, unknown>>\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type FieldInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldInputTypes: infer F }\n ? F extends Record<string, Record<string, unknown>>\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n\nexport type ResolveOperationTypes<_TContract, TTypeMaps> = OperationTypesOf<TTypeMaps>;\n"],"mappings":";AAsHA,MAAa,wBAAwB;AACrC,MAAa,mBAAmB;AAEhC,SAAgB,gBACd,IACA,kBACyC;CACzC,OAAO;EACL,YAAY,GAAG,cAAc,kBAAkB,cAAA;EAC/C,OAAO,GAAG,SAAS,kBAAkB,SAAA;EACtC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as StorageColumn, C as ReferentialAction, D as SqlModelStorage, E as SqlModelFieldStorage, F as UniqueConstraint, I as applyFkDefaults, M as StorageTypeInstance, N as TypeMaps, O as SqlQueryOperationTypes, P as TypeMapsPhantomKey, S as QueryOperationTypesOf, T as ResolveOperationTypes, _ as PrimaryKey, a as ExtractCodecTypes, b as QueryOperationTypeEntry, c as ExtractQueryOperationTypes, d as FieldOutputTypesOf, f as ForeignKey, g as OperationTypesOf, h as Index, i as DEFAULT_FK_INDEX, j as StorageTable, k as SqlStorage, l as ExtractTypeMapsFromContract, m as ForeignKeyReferences, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as ForeignKeyOptions, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as FieldInputTypesOf, v as QueryOperationReturn, w as ResolveCodecTypes, x as QueryOperationTypesBase, y as QueryOperationSelfSpec } from "./types-
|
|
1
|
+
import { A as StorageColumn, C as ReferentialAction, D as SqlModelStorage, E as SqlModelFieldStorage, F as UniqueConstraint, I as applyFkDefaults, M as StorageTypeInstance, N as TypeMaps, O as SqlQueryOperationTypes, P as TypeMapsPhantomKey, S as QueryOperationTypesOf, T as ResolveOperationTypes, _ as PrimaryKey, a as ExtractCodecTypes, b as QueryOperationTypeEntry, c as ExtractQueryOperationTypes, d as FieldOutputTypesOf, f as ForeignKey, g as OperationTypesOf, h as Index, i as DEFAULT_FK_INDEX, j as StorageTable, k as SqlStorage, l as ExtractTypeMapsFromContract, m as ForeignKeyReferences, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as ForeignKeyOptions, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as FieldInputTypesOf, v as QueryOperationReturn, w as ResolveCodecTypes, x as QueryOperationTypesBase, y as QueryOperationSelfSpec } from "./types-BTYquqSU.mjs";
|
|
2
2
|
export { type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractFieldInputTypes, type ExtractFieldOutputTypes, type ExtractQueryOperationTypes, type ExtractTypeMapsFromContract, type FieldInputTypesOf, type FieldOutputTypesOf, type ForeignKey, type ForeignKeyOptions, type ForeignKeyReferences, type Index, type OperationTypesOf, type PrimaryKey, type QueryOperationReturn, type QueryOperationSelfSpec, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type ResolveOperationTypes, type SqlModelFieldStorage, type SqlModelStorage, type SqlQueryOperationTypes, type SqlStorage, type StorageColumn, type StorageTable, type StorageTypeInstance, type TypeMaps, type TypeMapsPhantomKey, type UniqueConstraint, applyFkDefaults };
|
package/dist/validate.d.mts
CHANGED
package/dist/validate.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as validateStorageSemantics, l as validateSqlContract } from "./validators-
|
|
1
|
+
import { d as validateStorageSemantics, l as validateSqlContract } from "./validators-Dm5X-Hvg.mjs";
|
|
2
2
|
import { ContractValidationError, validateContract as validateContract$1 } from "@prisma-next/contract/validate-contract";
|
|
3
3
|
//#region src/validate.ts
|
|
4
4
|
function validateModelStorageReferences(contract) {
|
|
@@ -67,8 +67,8 @@ const UniqueConstraintSchema = type.declare().type({
|
|
|
67
67
|
const IndexSchema = type({
|
|
68
68
|
columns: type.string.array().readonly(),
|
|
69
69
|
"name?": "string",
|
|
70
|
-
"
|
|
71
|
-
"
|
|
70
|
+
"type?": "string",
|
|
71
|
+
"options?": "Record<string, unknown>"
|
|
72
72
|
});
|
|
73
73
|
const ForeignKeyReferencesSchema = type.declare().type({
|
|
74
74
|
table: "string",
|
|
@@ -245,14 +245,15 @@ function validateStorageSemantics(storage) {
|
|
|
245
245
|
}
|
|
246
246
|
seenUniqueDefinitions.add(signature);
|
|
247
247
|
}
|
|
248
|
+
const sortOptions = (o) => o ? Object.fromEntries(Object.entries(o).sort(([a], [b]) => a.localeCompare(b))) : null;
|
|
248
249
|
const seenIndexDefinitions = /* @__PURE__ */ new Set();
|
|
249
250
|
for (const index of table.indexes) {
|
|
250
251
|
const duplicateColumn = findDuplicateValue(index.columns);
|
|
251
252
|
if (duplicateColumn !== void 0) errors.push(`Table "${tableName}": index contains duplicate column "${duplicateColumn}"`);
|
|
252
253
|
const signature = JSON.stringify({
|
|
253
254
|
columns: index.columns,
|
|
254
|
-
|
|
255
|
-
|
|
255
|
+
type: index.type ?? null,
|
|
256
|
+
options: sortOptions(index.options)
|
|
256
257
|
});
|
|
257
258
|
if (seenIndexDefinitions.has(signature)) {
|
|
258
259
|
errors.push(`Table "${tableName}": duplicate index definition on columns [${index.columns.join(", ")}]`);
|
|
@@ -290,4 +291,4 @@ function validateStorageSemantics(storage) {
|
|
|
290
291
|
//#endregion
|
|
291
292
|
export { ForeignKeySchema as a, validateModel as c, validateStorageSemantics as d, ForeignKeyReferencesSchema as i, validateSqlContract as l, ColumnDefaultLiteralSchema as n, IndexSchema as o, ColumnDefaultSchema as r, ReferentialActionSchema as s, ColumnDefaultFunctionSchema as t, validateStorage as u };
|
|
292
293
|
|
|
293
|
-
//# sourceMappingURL=validators-
|
|
294
|
+
//# sourceMappingURL=validators-Dm5X-Hvg.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators-CSYfYN19.mjs","names":[],"sources":["../src/validators.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport { ContractValidationError } from '@prisma-next/contract/validate-contract';\nimport { type } from 'arktype';\nimport type {\n ForeignKey,\n ForeignKeyReferences,\n PrimaryKey,\n ReferentialAction,\n SqlStorage,\n StorageTypeInstance,\n UniqueConstraint,\n} from './types';\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 };\nconst literalKindSchema = type(\"'literal'\");\nconst functionKindSchema = type(\"'function'\");\nconst generatorKindSchema = type(\"'generator'\");\nconst generatorIdSchema = type('string').narrow((value, ctx) => {\n return /^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(value) ? true : ctx.mustBe('a flat generator id');\n});\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 ExecutionMutationDefaultValueSchema = type({\n '+': 'reject',\n kind: generatorKindSchema,\n id: generatorIdSchema,\n 'params?': 'Record<string, unknown>',\n});\n\nconst ExecutionMutationDefaultSchema = type({\n '+': 'reject',\n ref: {\n '+': 'reject',\n table: 'string',\n column: 'string',\n },\n 'onCreate?': ExecutionMutationDefaultValueSchema,\n 'onUpdate?': ExecutionMutationDefaultValueSchema,\n});\n\nconst ExecutionSchema = type({\n '+': 'reject',\n executionHash: 'string',\n mutations: {\n '+': 'reject',\n defaults: ExecutionMutationDefaultSchema.array().readonly(),\n },\n});\n\nconst StorageColumnSchema = type({\n '+': 'reject',\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\n 'typeParams?': 'Record<string, unknown>',\n 'typeRef?': 'string',\n 'default?': ColumnDefaultSchema,\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\nconst StorageTypeInstanceSchema = type.declare<StorageTypeInstance>().type({\n codecId: 'string',\n nativeType: 'string',\n typeParams: 'Record<string, unknown>',\n});\n\nconst PrimaryKeySchema = type.declare<PrimaryKey>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nconst UniqueConstraintSchema = type.declare<UniqueConstraint>().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 'using?': 'string',\n 'config?': 'Record<string, unknown>',\n});\n\nexport const ForeignKeyReferencesSchema = type.declare<ForeignKeyReferences>().type({\n table: 'string',\n columns: type.string.array().readonly(),\n});\n\nexport const ReferentialActionSchema = type\n .declare<ReferentialAction>()\n .type(\"'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'\");\n\nexport const ForeignKeySchema = type.declare<ForeignKey>().type({\n columns: type.string.array().readonly(),\n references: ForeignKeyReferencesSchema,\n 'name?': 'string',\n 'onDelete?': ReferentialActionSchema,\n 'onUpdate?': ReferentialActionSchema,\n constraint: 'boolean',\n index: 'boolean',\n});\n\nconst 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});\n\nconst StorageSchema = type({\n '+': 'reject',\n storageHash: 'string',\n tables: type({ '[string]': StorageTableSchema }),\n 'types?': type({ '[string]': StorageTypeInstanceSchema }),\n});\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction findDuplicateValue(values: readonly string[]): string | undefined {\n const seen = new Set<string>();\n for (const value of values) {\n if (seen.has(value)) {\n return value;\n }\n seen.add(value);\n }\n return undefined;\n}\n\nfunction isContractFieldType(value: unknown): boolean {\n if (!isPlainRecord(value)) return false;\n const kind = value['kind'];\n if (kind === 'scalar') {\n if (typeof value['codecId'] !== 'string') return false;\n const typeParams = value['typeParams'];\n if (typeParams !== undefined && !isPlainRecord(typeParams)) return false;\n return true;\n }\n if (kind === 'valueObject') {\n return typeof value['name'] === 'string';\n }\n if (kind === 'union') {\n const members = value['members'];\n if (!Array.isArray(members)) return false;\n return members.every((m) => isContractFieldType(m));\n }\n return false;\n}\n\nconst ContractFieldTypeSchema = type('unknown').narrow((value, ctx) =>\n isContractFieldType(value) ? true : ctx.mustBe('scalar, valueObject, or union field type'),\n);\n\nconst ModelFieldSchema = type({\n '+': 'reject',\n nullable: 'boolean',\n type: ContractFieldTypeSchema,\n 'many?': 'true',\n 'dict?': 'true',\n});\n\nconst ModelStorageFieldSchema = type({\n column: 'string',\n 'codecId?': 'string',\n 'nullable?': 'boolean',\n});\n\nconst ModelStorageSchema = type({\n table: 'string',\n fields: type({ '[string]': ModelStorageFieldSchema }),\n});\n\nconst ModelSchema = type({\n storage: ModelStorageSchema,\n 'fields?': type({ '[string]': ModelFieldSchema }),\n 'relations?': type({ '[string]': 'unknown' }),\n 'discriminator?': 'unknown',\n 'variants?': 'unknown',\n 'base?': 'string',\n 'owner?': 'string',\n});\n\nconst ContractMetaSchema = type({\n '[string]': 'unknown',\n});\n\nconst SqlContractSchema = type({\n '+': 'reject',\n target: 'string',\n targetFamily: \"'sql'\",\n 'coreHash?': 'string',\n profileHash: 'string',\n 'capabilities?': 'Record<string, Record<string, boolean>>',\n 'extensionPacks?': 'Record<string, unknown>',\n 'meta?': ContractMetaSchema,\n 'roots?': 'Record<string, string>',\n models: type({ '[string]': ModelSchema }),\n 'valueObjects?': 'Record<string, unknown>',\n storage: StorageSchema,\n 'execution?': ExecutionSchema,\n});\n\n// NOTE: StorageColumnSchema, StorageTableSchema, and StorageSchema use bare type()\n// instead of type.declare<T>().type() because the ColumnDefault union's value field\n// includes bigint | Date (runtime-only types after decoding) which cannot be expressed\n// in Arktype's JSON validation DSL. The `as SqlStorage` cast in validateStorage() bridges\n// the gap between the JSON-safe Arktype output and the runtime TypeScript type.\n// See decodeContractDefaults() in validate.ts for the decoding step.\n\n/**\n * Validates the structural shape of SqlStorage using Arktype.\n *\n * @param value - The storage value to validate\n * @returns The validated storage if structure is valid\n * @throws Error if the storage structure is invalid\n */\nexport function validateStorage(value: unknown): SqlStorage {\n const result = StorageSchema(value);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Storage validation failed: ${messages}`);\n }\n return result as SqlStorage;\n}\n\nexport function validateModel(value: unknown): unknown {\n const result = ModelSchema(value);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Model validation failed: ${messages}`);\n }\n return result;\n}\n\n/**\n * Validates the structural shape of an SQL contract using Arktype.\n *\n * Ensures all required fields are present and have the correct types,\n * including SQL-specific storage structure (tables, columns, constraints).\n *\n * @param value - The contract value to validate (typically from a JSON import)\n * @returns The validated contract if structure is valid\n * @throws ContractValidationError if the contract structure is invalid\n */\nexport function validateSqlContract<T extends Contract<SqlStorage>>(value: unknown): T {\n if (typeof value !== 'object' || value === null) {\n throw new ContractValidationError(\n 'Contract structural validation failed: value must be an object',\n 'structural',\n );\n }\n\n const rawValue = value as { targetFamily?: string };\n if (rawValue.targetFamily !== undefined && rawValue.targetFamily !== 'sql') {\n throw new ContractValidationError(\n `Unsupported target family: ${rawValue.targetFamily}`,\n 'structural',\n );\n }\n\n const contractResult = SqlContractSchema(value);\n\n if (contractResult instanceof type.errors) {\n const messages = contractResult.map((p: { message: string }) => p.message).join('; ');\n throw new ContractValidationError(\n `Contract structural validation failed: ${messages}`,\n 'structural',\n );\n }\n\n // Arktype's inferred output type differs from T due to exactOptionalPropertyTypes\n // and branded hash types — the runtime value is structurally compatible after validation\n return contractResult as unknown as T;\n}\n\n/**\n * Validates semantic constraints on SqlStorage that cannot be expressed in Arktype schemas.\n *\n * Returns an array of human-readable error strings. Empty array = valid.\n *\n * Currently checks:\n * - duplicate named primary key / unique / index / foreign key objects within a table\n * - duplicate unique, index, or foreign key declarations within a table\n * - duplicate columns within primary key / unique / index definitions\n * - nullable columns in primary key definitions\n * - `setNull` referential action on a non-nullable FK column (would fail at runtime)\n * - `setDefault` referential action on a non-nullable FK column without a DEFAULT (would fail at runtime)\n */\nexport function validateStorageSemantics(storage: SqlStorage): string[] {\n const errors: string[] = [];\n\n for (const [tableName, table] of Object.entries(storage.tables)) {\n const namedObjects = new Map<string, string[]>();\n const registerNamedObject = (kind: string, name: string | undefined) => {\n if (!name) return;\n namedObjects.set(name, [...(namedObjects.get(name) ?? []), kind]);\n };\n\n registerNamedObject('primary key', table.primaryKey?.name);\n for (const unique of table.uniques) {\n registerNamedObject('unique constraint', unique.name);\n }\n for (const index of table.indexes) {\n registerNamedObject('index', index.name);\n }\n for (const fk of table.foreignKeys) {\n registerNamedObject('foreign key', fk.name);\n }\n\n for (const [name, kinds] of namedObjects) {\n if (kinds.length > 1) {\n errors.push(\n `Table \"${tableName}\": named object \"${name}\" is declared multiple times (${kinds.join(', ')})`,\n );\n }\n }\n\n if (table.primaryKey) {\n const duplicateColumn = findDuplicateValue(table.primaryKey.columns);\n if (duplicateColumn !== undefined) {\n errors.push(\n `Table \"${tableName}\": primary key contains duplicate column \"${duplicateColumn}\"`,\n );\n }\n\n for (const columnName of table.primaryKey.columns) {\n const column = table.columns[columnName];\n if (column?.nullable === true) {\n errors.push(\n `Table \"${tableName}\": primary key column \"${columnName}\" is nullable; primary key columns must be NOT NULL`,\n );\n }\n }\n }\n\n const seenUniqueDefinitions = new Set<string>();\n for (const unique of table.uniques) {\n const duplicateColumn = findDuplicateValue(unique.columns);\n if (duplicateColumn !== undefined) {\n errors.push(\n `Table \"${tableName}\": unique constraint contains duplicate column \"${duplicateColumn}\"`,\n );\n }\n\n const signature = JSON.stringify({ columns: unique.columns });\n if (seenUniqueDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate unique constraint definition on columns [${unique.columns.join(', ')}]`,\n );\n continue;\n }\n seenUniqueDefinitions.add(signature);\n }\n\n const seenIndexDefinitions = new Set<string>();\n for (const index of table.indexes) {\n const duplicateColumn = findDuplicateValue(index.columns);\n if (duplicateColumn !== undefined) {\n errors.push(`Table \"${tableName}\": index contains duplicate column \"${duplicateColumn}\"`);\n }\n\n const signature = JSON.stringify({\n columns: index.columns,\n using: index.using ?? null,\n config: index.config ?? null,\n });\n if (seenIndexDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate index definition on columns [${index.columns.join(', ')}]`,\n );\n continue;\n }\n seenIndexDefinitions.add(signature);\n }\n\n const seenForeignKeyDefinitions = new Set<string>();\n for (const fk of table.foreignKeys) {\n const signature = JSON.stringify({\n columns: fk.columns,\n references: fk.references,\n onDelete: fk.onDelete ?? null,\n onUpdate: fk.onUpdate ?? null,\n constraint: fk.constraint,\n index: fk.index,\n });\n if (seenForeignKeyDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate foreign key definition on columns [${fk.columns.join(', ')}]`,\n );\n continue;\n }\n seenForeignKeyDefinitions.add(signature);\n }\n\n for (const fk of table.foreignKeys) {\n for (const colName of fk.columns) {\n const column = table.columns[colName];\n if (!column) continue;\n\n if (fk.onDelete === 'setNull' && !column.nullable) {\n errors.push(\n `Table \"${tableName}\": onDelete setNull on foreign key column \"${colName}\" which is NOT NULL`,\n );\n }\n if (fk.onUpdate === 'setNull' && !column.nullable) {\n errors.push(\n `Table \"${tableName}\": onUpdate setNull on foreign key column \"${colName}\" which is NOT NULL`,\n );\n }\n if (fk.onDelete === 'setDefault' && !column.nullable && column.default === undefined) {\n errors.push(\n `Table \"${tableName}\": onDelete setDefault on foreign key column \"${colName}\" which is NOT NULL and has no DEFAULT`,\n );\n }\n if (fk.onUpdate === 'setDefault' && !column.nullable && column.default === undefined) {\n errors.push(\n `Table \"${tableName}\": onUpdate setDefault on foreign key column \"${colName}\" which is NOT NULL and has no DEFAULT`,\n );\n }\n }\n }\n }\n\n return errors;\n}\n"],"mappings":";;;AAkBA,MAAM,oBAAoB,KAAK,YAAY;AAC3C,MAAM,qBAAqB,KAAK,aAAa;AAC7C,MAAM,sBAAsB,KAAK,cAAc;AAC/C,MAAM,oBAAoB,KAAK,SAAS,CAAC,QAAQ,OAAO,QAAQ;CAC9D,OAAO,8BAA8B,KAAK,MAAM,GAAG,OAAO,IAAI,OAAO,sBAAsB;EAC3F;AAEF,MAAa,6BAA6B,KAAK,SAA+B,CAAC,KAAK;CAClF,MAAM;CACN,OAAO;CACR,CAAC;AAEF,MAAa,8BAA8B,KAAK,SAAgC,CAAC,KAAK;CACpF,MAAM;CACN,YAAY;CACb,CAAC;AAEF,MAAa,sBAAsB,2BAA2B,GAAG,4BAA4B;AAE7F,MAAM,sCAAsC,KAAK;CAC/C,KAAK;CACL,MAAM;CACN,IAAI;CACJ,WAAW;CACZ,CAAC;AAaF,MAAM,kBAAkB,KAAK;CAC3B,KAAK;CACL,eAAe;CACf,WAAW;EACT,KAAK;EACL,UAhBmC,KAAK;GAC1C,KAAK;GACL,KAAK;I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C,OAAO,UACvC,OAAO,KACL,UAAU,UAAU,6CAA6C,QAAQ,qBAC1E;GAEH,IAAI,GAAG,aAAa,aAAa,CAAC,OAAO,UACvC,OAAO,KACL,UAAU,UAAU,6CAA6C,QAAQ,qBAC1E;GAEH,IAAI,GAAG,aAAa,gBAAgB,CAAC,OAAO,YAAY,OAAO,YAAY,KAAA,GACzE,OAAO,KACL,UAAU,UAAU,gDAAgD,QAAQ,wCAC7E;GAEH,IAAI,GAAG,aAAa,gBAAgB,CAAC,OAAO,YAAY,OAAO,YAAY,KAAA,GACzE,OAAO,KACL,UAAU,UAAU,gDAAgD,QAAQ,wCAC7E;;;CAMT,OAAO"}
|
|
1
|
+
{"version":3,"file":"validators-Dm5X-Hvg.mjs","names":[],"sources":["../src/validators.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport { ContractValidationError } from '@prisma-next/contract/validate-contract';\nimport { type } from 'arktype';\nimport type {\n ForeignKey,\n ForeignKeyReferences,\n PrimaryKey,\n ReferentialAction,\n SqlStorage,\n StorageTypeInstance,\n UniqueConstraint,\n} from './types';\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 };\nconst literalKindSchema = type(\"'literal'\");\nconst functionKindSchema = type(\"'function'\");\nconst generatorKindSchema = type(\"'generator'\");\nconst generatorIdSchema = type('string').narrow((value, ctx) => {\n return /^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(value) ? true : ctx.mustBe('a flat generator id');\n});\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 ExecutionMutationDefaultValueSchema = type({\n '+': 'reject',\n kind: generatorKindSchema,\n id: generatorIdSchema,\n 'params?': 'Record<string, unknown>',\n});\n\nconst ExecutionMutationDefaultSchema = type({\n '+': 'reject',\n ref: {\n '+': 'reject',\n table: 'string',\n column: 'string',\n },\n 'onCreate?': ExecutionMutationDefaultValueSchema,\n 'onUpdate?': ExecutionMutationDefaultValueSchema,\n});\n\nconst ExecutionSchema = type({\n '+': 'reject',\n executionHash: 'string',\n mutations: {\n '+': 'reject',\n defaults: ExecutionMutationDefaultSchema.array().readonly(),\n },\n});\n\nconst StorageColumnSchema = type({\n '+': 'reject',\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\n 'typeParams?': 'Record<string, unknown>',\n 'typeRef?': 'string',\n 'default?': ColumnDefaultSchema,\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\nconst StorageTypeInstanceSchema = type.declare<StorageTypeInstance>().type({\n codecId: 'string',\n nativeType: 'string',\n typeParams: 'Record<string, unknown>',\n});\n\nconst PrimaryKeySchema = type.declare<PrimaryKey>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nconst UniqueConstraintSchema = type.declare<UniqueConstraint>().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 ForeignKeyReferencesSchema = type.declare<ForeignKeyReferences>().type({\n table: 'string',\n columns: type.string.array().readonly(),\n});\n\nexport const ReferentialActionSchema = type\n .declare<ReferentialAction>()\n .type(\"'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'\");\n\nexport const ForeignKeySchema = type.declare<ForeignKey>().type({\n columns: type.string.array().readonly(),\n references: ForeignKeyReferencesSchema,\n 'name?': 'string',\n 'onDelete?': ReferentialActionSchema,\n 'onUpdate?': ReferentialActionSchema,\n constraint: 'boolean',\n index: 'boolean',\n});\n\nconst 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});\n\nconst StorageSchema = type({\n '+': 'reject',\n storageHash: 'string',\n tables: type({ '[string]': StorageTableSchema }),\n 'types?': type({ '[string]': StorageTypeInstanceSchema }),\n});\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction findDuplicateValue(values: readonly string[]): string | undefined {\n const seen = new Set<string>();\n for (const value of values) {\n if (seen.has(value)) {\n return value;\n }\n seen.add(value);\n }\n return undefined;\n}\n\nfunction isContractFieldType(value: unknown): boolean {\n if (!isPlainRecord(value)) return false;\n const kind = value['kind'];\n if (kind === 'scalar') {\n if (typeof value['codecId'] !== 'string') return false;\n const typeParams = value['typeParams'];\n if (typeParams !== undefined && !isPlainRecord(typeParams)) return false;\n return true;\n }\n if (kind === 'valueObject') {\n return typeof value['name'] === 'string';\n }\n if (kind === 'union') {\n const members = value['members'];\n if (!Array.isArray(members)) return false;\n return members.every((m) => isContractFieldType(m));\n }\n return false;\n}\n\nconst ContractFieldTypeSchema = type('unknown').narrow((value, ctx) =>\n isContractFieldType(value) ? true : ctx.mustBe('scalar, valueObject, or union field type'),\n);\n\nconst ModelFieldSchema = type({\n '+': 'reject',\n nullable: 'boolean',\n type: ContractFieldTypeSchema,\n 'many?': 'true',\n 'dict?': 'true',\n});\n\nconst ModelStorageFieldSchema = type({\n column: 'string',\n 'codecId?': 'string',\n 'nullable?': 'boolean',\n});\n\nconst ModelStorageSchema = type({\n table: 'string',\n fields: type({ '[string]': ModelStorageFieldSchema }),\n});\n\nconst ModelSchema = type({\n storage: ModelStorageSchema,\n 'fields?': type({ '[string]': ModelFieldSchema }),\n 'relations?': type({ '[string]': 'unknown' }),\n 'discriminator?': 'unknown',\n 'variants?': 'unknown',\n 'base?': 'string',\n 'owner?': 'string',\n});\n\nconst ContractMetaSchema = type({\n '[string]': 'unknown',\n});\n\nconst SqlContractSchema = type({\n '+': 'reject',\n target: 'string',\n targetFamily: \"'sql'\",\n 'coreHash?': 'string',\n profileHash: 'string',\n 'capabilities?': 'Record<string, Record<string, boolean>>',\n 'extensionPacks?': 'Record<string, unknown>',\n 'meta?': ContractMetaSchema,\n 'roots?': 'Record<string, string>',\n models: type({ '[string]': ModelSchema }),\n 'valueObjects?': 'Record<string, unknown>',\n storage: StorageSchema,\n 'execution?': ExecutionSchema,\n});\n\n// NOTE: StorageColumnSchema, StorageTableSchema, and StorageSchema use bare type()\n// instead of type.declare<T>().type() because the ColumnDefault union's value field\n// includes bigint | Date (runtime-only types after decoding) which cannot be expressed\n// in Arktype's JSON validation DSL. The `as SqlStorage` cast in validateStorage() bridges\n// the gap between the JSON-safe Arktype output and the runtime TypeScript type.\n// See decodeContractDefaults() in validate.ts for the decoding step.\n\n/**\n * Validates the structural shape of SqlStorage using Arktype.\n *\n * @param value - The storage value to validate\n * @returns The validated storage if structure is valid\n * @throws Error if the storage structure is invalid\n */\nexport function validateStorage(value: unknown): SqlStorage {\n const result = StorageSchema(value);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Storage validation failed: ${messages}`);\n }\n return result as SqlStorage;\n}\n\nexport function validateModel(value: unknown): unknown {\n const result = ModelSchema(value);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Model validation failed: ${messages}`);\n }\n return result;\n}\n\n/**\n * Validates the structural shape of an SQL contract using Arktype.\n *\n * Ensures all required fields are present and have the correct types,\n * including SQL-specific storage structure (tables, columns, constraints).\n *\n * @param value - The contract value to validate (typically from a JSON import)\n * @returns The validated contract if structure is valid\n * @throws ContractValidationError if the contract structure is invalid\n */\nexport function validateSqlContract<T extends Contract<SqlStorage>>(value: unknown): T {\n if (typeof value !== 'object' || value === null) {\n throw new ContractValidationError(\n 'Contract structural validation failed: value must be an object',\n 'structural',\n );\n }\n\n const rawValue = value as { targetFamily?: string };\n if (rawValue.targetFamily !== undefined && rawValue.targetFamily !== 'sql') {\n throw new ContractValidationError(\n `Unsupported target family: ${rawValue.targetFamily}`,\n 'structural',\n );\n }\n\n const contractResult = SqlContractSchema(value);\n\n if (contractResult instanceof type.errors) {\n const messages = contractResult.map((p: { message: string }) => p.message).join('; ');\n throw new ContractValidationError(\n `Contract structural validation failed: ${messages}`,\n 'structural',\n );\n }\n\n // Arktype's inferred output type differs from T due to exactOptionalPropertyTypes\n // and branded hash types — the runtime value is structurally compatible after validation\n return contractResult as unknown as T;\n}\n\n/**\n * Validates semantic constraints on SqlStorage that cannot be expressed in Arktype schemas.\n *\n * Returns an array of human-readable error strings. Empty array = valid.\n *\n * Currently checks:\n * - duplicate named primary key / unique / index / foreign key objects within a table\n * - duplicate unique, index, or foreign key declarations within a table\n * - duplicate columns within primary key / unique / index definitions\n * - nullable columns in primary key definitions\n * - `setNull` referential action on a non-nullable FK column (would fail at runtime)\n * - `setDefault` referential action on a non-nullable FK column without a DEFAULT (would fail at runtime)\n */\nexport function validateStorageSemantics(storage: SqlStorage): string[] {\n const errors: string[] = [];\n\n for (const [tableName, table] of Object.entries(storage.tables)) {\n const namedObjects = new Map<string, string[]>();\n const registerNamedObject = (kind: string, name: string | undefined) => {\n if (!name) return;\n namedObjects.set(name, [...(namedObjects.get(name) ?? []), kind]);\n };\n\n registerNamedObject('primary key', table.primaryKey?.name);\n for (const unique of table.uniques) {\n registerNamedObject('unique constraint', unique.name);\n }\n for (const index of table.indexes) {\n registerNamedObject('index', index.name);\n }\n for (const fk of table.foreignKeys) {\n registerNamedObject('foreign key', fk.name);\n }\n\n for (const [name, kinds] of namedObjects) {\n if (kinds.length > 1) {\n errors.push(\n `Table \"${tableName}\": named object \"${name}\" is declared multiple times (${kinds.join(', ')})`,\n );\n }\n }\n\n if (table.primaryKey) {\n const duplicateColumn = findDuplicateValue(table.primaryKey.columns);\n if (duplicateColumn !== undefined) {\n errors.push(\n `Table \"${tableName}\": primary key contains duplicate column \"${duplicateColumn}\"`,\n );\n }\n\n for (const columnName of table.primaryKey.columns) {\n const column = table.columns[columnName];\n if (column?.nullable === true) {\n errors.push(\n `Table \"${tableName}\": primary key column \"${columnName}\" is nullable; primary key columns must be NOT NULL`,\n );\n }\n }\n }\n\n const seenUniqueDefinitions = new Set<string>();\n for (const unique of table.uniques) {\n const duplicateColumn = findDuplicateValue(unique.columns);\n if (duplicateColumn !== undefined) {\n errors.push(\n `Table \"${tableName}\": unique constraint contains duplicate column \"${duplicateColumn}\"`,\n );\n }\n\n const signature = JSON.stringify({ columns: unique.columns });\n if (seenUniqueDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate unique constraint definition on columns [${unique.columns.join(', ')}]`,\n );\n continue;\n }\n seenUniqueDefinitions.add(signature);\n }\n\n const sortOptions = (o: Record<string, unknown> | undefined): Record<string, unknown> | null =>\n o ? Object.fromEntries(Object.entries(o).sort(([a], [b]) => a.localeCompare(b))) : null;\n\n const seenIndexDefinitions = new Set<string>();\n for (const index of table.indexes) {\n const duplicateColumn = findDuplicateValue(index.columns);\n if (duplicateColumn !== undefined) {\n errors.push(`Table \"${tableName}\": index contains duplicate column \"${duplicateColumn}\"`);\n }\n\n const signature = JSON.stringify({\n columns: index.columns,\n type: index.type ?? null,\n options: sortOptions(index.options),\n });\n if (seenIndexDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate index definition on columns [${index.columns.join(', ')}]`,\n );\n continue;\n }\n seenIndexDefinitions.add(signature);\n }\n\n const seenForeignKeyDefinitions = new Set<string>();\n for (const fk of table.foreignKeys) {\n const signature = JSON.stringify({\n columns: fk.columns,\n references: fk.references,\n onDelete: fk.onDelete ?? null,\n onUpdate: fk.onUpdate ?? null,\n constraint: fk.constraint,\n index: fk.index,\n });\n if (seenForeignKeyDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate foreign key definition on columns [${fk.columns.join(', ')}]`,\n );\n continue;\n }\n seenForeignKeyDefinitions.add(signature);\n }\n\n for (const fk of table.foreignKeys) {\n for (const colName of fk.columns) {\n const column = table.columns[colName];\n if (!column) continue;\n\n if (fk.onDelete === 'setNull' && !column.nullable) {\n errors.push(\n `Table \"${tableName}\": onDelete setNull on foreign key column \"${colName}\" which is NOT NULL`,\n );\n }\n if (fk.onUpdate === 'setNull' && !column.nullable) {\n errors.push(\n `Table \"${tableName}\": onUpdate setNull on foreign key column \"${colName}\" which is NOT NULL`,\n );\n }\n if (fk.onDelete === 'setDefault' && !column.nullable && column.default === undefined) {\n errors.push(\n `Table \"${tableName}\": onDelete setDefault on foreign key column \"${colName}\" which is NOT NULL and has no DEFAULT`,\n );\n }\n if (fk.onUpdate === 'setDefault' && !column.nullable && column.default === undefined) {\n errors.push(\n `Table \"${tableName}\": onUpdate setDefault on foreign key column \"${colName}\" which is NOT NULL and has no DEFAULT`,\n );\n }\n }\n }\n }\n\n return errors;\n}\n"],"mappings":";;;AAkBA,MAAM,oBAAoB,KAAK,YAAY;AAC3C,MAAM,qBAAqB,KAAK,aAAa;AAC7C,MAAM,sBAAsB,KAAK,cAAc;AAC/C,MAAM,oBAAoB,KAAK,SAAS,CAAC,QAAQ,OAAO,QAAQ;CAC9D,OAAO,8BAA8B,KAAK,MAAM,GAAG,OAAO,IAAI,OAAO,sBAAsB;EAC3F;AAEF,MAAa,6BAA6B,KAAK,SAA+B,CAAC,KAAK;CAClF,MAAM;CACN,OAAO;CACR,CAAC;AAEF,MAAa,8BAA8B,KAAK,SAAgC,CAAC,KAAK;CACpF,MAAM;CACN,YAAY;CACb,CAAC;AAEF,MAAa,sBAAsB,2BAA2B,GAAG,4BAA4B;AAE7F,MAAM,sCAAsC,KAAK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ACX,CAAC;GACF,IAAI,0BAA0B,IAAI,UAAU,EAAE;IAC5C,OAAO,KACL,UAAU,UAAU,kDAAkD,GAAG,QAAQ,KAAK,KAAK,CAAC,GAC7F;IACD;;GAEF,0BAA0B,IAAI,UAAU;;EAG1C,KAAK,MAAM,MAAM,MAAM,aACrB,KAAK,MAAM,WAAW,GAAG,SAAS;GAChC,MAAM,SAAS,MAAM,QAAQ;GAC7B,IAAI,CAAC,QAAQ;GAEb,IAAI,GAAG,aAAa,aAAa,CAAC,OAAO,UACvC,OAAO,KACL,UAAU,UAAU,6CAA6C,QAAQ,qBAC1E;GAEH,IAAI,GAAG,aAAa,aAAa,CAAC,OAAO,UACvC,OAAO,KACL,UAAU,UAAU,6CAA6C,QAAQ,qBAC1E;GAEH,IAAI,GAAG,aAAa,gBAAgB,CAAC,OAAO,YAAY,OAAO,YAAY,KAAA,GACzE,OAAO,KACL,UAAU,UAAU,gDAAgD,QAAQ,wCAC7E;GAEH,IAAI,GAAG,aAAa,gBAAgB,CAAC,OAAO,YAAY,OAAO,YAAY,KAAA,GACzE,OAAO,KACL,UAAU,UAAU,gDAAgD,QAAQ,wCAC7E;;;CAMT,OAAO"}
|
package/dist/validators.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ReferentialAction, f as ForeignKey, k as SqlStorage, m as ForeignKeyReferences } from "./types-
|
|
1
|
+
import { C as ReferentialAction, f as ForeignKey, k as SqlStorage, m as ForeignKeyReferences } from "./types-BTYquqSU.mjs";
|
|
2
2
|
import { Contract } from "@prisma-next/contract/types";
|
|
3
3
|
import * as _$arktype_internal_variants_object_ts0 from "arktype/internal/variants/object.ts";
|
|
4
4
|
import * as _$arktype_internal_variants_string_ts0 from "arktype/internal/variants/string.ts";
|
|
@@ -18,8 +18,8 @@ declare const ColumnDefaultSchema: _$arktype_internal_variants_object_ts0.Object
|
|
|
18
18
|
declare const IndexSchema: _$arktype_internal_variants_object_ts0.ObjectType<{
|
|
19
19
|
columns: readonly string[];
|
|
20
20
|
name?: string;
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
type?: string;
|
|
22
|
+
options?: Record<string, unknown>;
|
|
23
23
|
}, {}>;
|
|
24
24
|
declare const ForeignKeyReferencesSchema: _$arktype_internal_variants_object_ts0.ObjectType<ForeignKeyReferences, {}>;
|
|
25
25
|
declare const ReferentialActionSchema: _$arktype_internal_variants_string_ts0.StringType<ReferentialAction, {}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.mts","names":[],"sources":["../src/validators.ts"],"mappings":";;;;;;KAaK,oBAAA;EAAA,SACM,IAAA;EAAA,SACA,KAAA,8BAAmC,MAAA;AAAA;AAAA,KAEzC,qBAAA;EAAA,SAAmC,IAAA;EAAA,SAA2B,UAAA;AAAA;AAAA,cAQtD,0BAAA,EAA0B,sCAAA,CAAA,UAAA,CAAA,oBAAA;AAAA,cAK1B,2BAAA,EAA2B,sCAAA,CAAA,UAAA,CAAA,qBAAA;AAAA,cAK3B,mBAAA,EAAmB,sCAAA,CAAA,UAAA,CAAA,oBAAA,GAAA,qBAAA;AAAA,cA4DnB,WAAA,EAKX,sCAAA,CALsB,UAAA;;;;
|
|
1
|
+
{"version":3,"file":"validators.d.mts","names":[],"sources":["../src/validators.ts"],"mappings":";;;;;;KAaK,oBAAA;EAAA,SACM,IAAA;EAAA,SACA,KAAA,8BAAmC,MAAA;AAAA;AAAA,KAEzC,qBAAA;EAAA,SAAmC,IAAA;EAAA,SAA2B,UAAA;AAAA;AAAA,cAQtD,0BAAA,EAA0B,sCAAA,CAAA,UAAA,CAAA,oBAAA;AAAA,cAK1B,2BAAA,EAA2B,sCAAA,CAAA,UAAA,CAAA,qBAAA;AAAA,cAK3B,mBAAA,EAAmB,sCAAA,CAAA,UAAA,CAAA,oBAAA,GAAA,qBAAA;AAAA,cA4DnB,WAAA,EAKX,sCAAA,CALsB,UAAA;;;;YAKtB,MAAA;AAAA;AAAA,cAEW,0BAAA,EAA0B,sCAAA,CAAA,UAAA,CAAA,oBAAA;AAAA,cAK1B,uBAAA,EAAuB,sCAAA,CAAA,UAAA,CAAA,iBAAA;AAAA,cAIvB,gBAAA,EAAgB,sCAAA,CAAA,UAAA,CAAA,UAAA;;;;AAjF7B;;;;iBAiNgB,eAAA,CAAgB,KAAA,YAAiB,UAAA;AAAA,iBASjC,aAAA,CAAc,KAAA;;;;;;;;;;;iBAmBd,mBAAA,WAA8B,QAAA,CAAS,UAAA,EAAA,CAAa,KAAA,YAAiB,CAAA;;AA5KrF;;;;;;;;;;;;iBAwNgB,wBAAA,CAAyB,OAAA,EAAS,UAAA"}
|
package/dist/validators.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ForeignKeySchema, c as validateModel, d as validateStorageSemantics, i as ForeignKeyReferencesSchema, l as validateSqlContract, n as ColumnDefaultLiteralSchema, o as IndexSchema, r as ColumnDefaultSchema, s as ReferentialActionSchema, t as ColumnDefaultFunctionSchema, u as validateStorage } from "./validators-
|
|
1
|
+
import { a as ForeignKeySchema, c as validateModel, d as validateStorageSemantics, i as ForeignKeyReferencesSchema, l as validateSqlContract, n as ColumnDefaultLiteralSchema, o as IndexSchema, r as ColumnDefaultSchema, s as ReferentialActionSchema, t as ColumnDefaultFunctionSchema, u as validateStorage } from "./validators-Dm5X-Hvg.mjs";
|
|
2
2
|
export { ColumnDefaultFunctionSchema, ColumnDefaultLiteralSchema, ColumnDefaultSchema, ForeignKeyReferencesSchema, ForeignKeySchema, IndexSchema, ReferentialActionSchema, validateModel, validateSqlContract, validateStorage, validateStorageSemantics };
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-contract",
|
|
3
|
-
"version": "0.5.0-dev.
|
|
3
|
+
"version": "0.5.0-dev.82",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "SQL contract types, validators, and IR factories for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"arktype": "^2.1.29",
|
|
10
|
-
"@prisma-next/contract": "0.5.0-dev.
|
|
11
|
-
"@prisma-next/framework-components": "0.5.0-dev.
|
|
10
|
+
"@prisma-next/contract": "0.5.0-dev.82",
|
|
11
|
+
"@prisma-next/framework-components": "0.5.0-dev.82"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"tsdown": "0.22.0",
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
],
|
|
25
25
|
"exports": {
|
|
26
26
|
"./factories": "./dist/factories.mjs",
|
|
27
|
+
"./index-type-validation": "./dist/index-type-validation.mjs",
|
|
28
|
+
"./index-types": "./dist/index-types.mjs",
|
|
27
29
|
"./pack-types": "./dist/pack-types.mjs",
|
|
28
30
|
"./types": "./dist/types.mjs",
|
|
29
31
|
"./validate": "./dist/validate.mjs",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../index-type-validation';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Contract } from '@prisma-next/contract/types';
|
|
2
|
+
import { ContractValidationError } from '@prisma-next/contract/validate-contract';
|
|
3
|
+
import { type } from 'arktype';
|
|
4
|
+
import type { IndexTypeRegistry } from './index-types';
|
|
5
|
+
import type { SqlStorage } from './types';
|
|
6
|
+
|
|
7
|
+
export function validateIndexTypes(
|
|
8
|
+
contract: Contract<SqlStorage>,
|
|
9
|
+
indexTypeRegistry: IndexTypeRegistry,
|
|
10
|
+
): void {
|
|
11
|
+
for (const [tableName, table] of Object.entries(contract.storage.tables)) {
|
|
12
|
+
for (const index of table.indexes) {
|
|
13
|
+
if (index.type === undefined && index.options !== undefined) {
|
|
14
|
+
throw new ContractValidationError(
|
|
15
|
+
`Table "${tableName}" index on columns [${index.columns.join(', ')}] has options without a type`,
|
|
16
|
+
'storage',
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
if (index.type === undefined) continue;
|
|
20
|
+
const entry = indexTypeRegistry.get(index.type);
|
|
21
|
+
if (entry === undefined) {
|
|
22
|
+
throw new ContractValidationError(
|
|
23
|
+
`Table "${tableName}" index on columns [${index.columns.join(', ')}] uses unregistered index type "${index.type}"`,
|
|
24
|
+
'storage',
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
const optionsValue = index.options ?? {};
|
|
28
|
+
const result = entry.options(optionsValue);
|
|
29
|
+
if (result instanceof type.errors) {
|
|
30
|
+
throw new ContractValidationError(
|
|
31
|
+
`Table "${tableName}" index on columns [${index.columns.join(', ')}] has invalid options for type "${index.type}": ${result.summary}`,
|
|
32
|
+
'storage',
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Type } from 'arktype';
|
|
2
|
+
|
|
3
|
+
export interface IndexTypeEntry<TOptions = unknown> {
|
|
4
|
+
readonly type: string;
|
|
5
|
+
readonly options: Type<TOptions>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type IndexTypeMap = { readonly [K in string]: { readonly options: unknown } };
|
|
9
|
+
|
|
10
|
+
export interface IndexTypeRegistration<TMap extends IndexTypeMap = Record<never, never>> {
|
|
11
|
+
readonly IndexTypes: TMap;
|
|
12
|
+
readonly entries: ReadonlyArray<IndexTypeEntry>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IndexTypeBuilder<TMap extends IndexTypeMap = Record<never, never>>
|
|
16
|
+
extends IndexTypeRegistration<TMap> {
|
|
17
|
+
add<TLit extends string, TOpts>(
|
|
18
|
+
typeLiteral: TLit,
|
|
19
|
+
entry: { readonly options: Type<TOpts> },
|
|
20
|
+
): IndexTypeBuilder<TMap & Record<TLit, { readonly options: TOpts }>>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class IndexTypeBuilderImpl<TMap extends IndexTypeMap> implements IndexTypeBuilder<TMap> {
|
|
24
|
+
readonly entries: ReadonlyArray<IndexTypeEntry>;
|
|
25
|
+
readonly IndexTypes: TMap;
|
|
26
|
+
|
|
27
|
+
constructor(entries: ReadonlyArray<IndexTypeEntry>) {
|
|
28
|
+
this.entries = entries;
|
|
29
|
+
this.IndexTypes = {} as TMap;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
add<TLit extends string, TOpts>(
|
|
33
|
+
typeLiteral: TLit,
|
|
34
|
+
entry: { readonly options: Type<TOpts> },
|
|
35
|
+
): IndexTypeBuilder<TMap & Record<TLit, { readonly options: TOpts }>> {
|
|
36
|
+
if (this.entries.some((e) => e.type === typeLiteral)) {
|
|
37
|
+
throw new Error(`Index type "${typeLiteral}" is already declared in this builder`);
|
|
38
|
+
}
|
|
39
|
+
return new IndexTypeBuilderImpl<TMap & Record<TLit, { readonly options: TOpts }>>([
|
|
40
|
+
...this.entries,
|
|
41
|
+
{ type: typeLiteral, options: entry.options as Type<unknown> },
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function defineIndexTypes(): IndexTypeBuilder<Record<never, never>> {
|
|
47
|
+
return new IndexTypeBuilderImpl([]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface IndexTypeRegistry {
|
|
51
|
+
register(entry: IndexTypeEntry): void;
|
|
52
|
+
get(typeLiteral: string): IndexTypeEntry | undefined;
|
|
53
|
+
has(typeLiteral: string): boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
class IndexTypeRegistryImpl implements IndexTypeRegistry {
|
|
57
|
+
private readonly entries = new Map<string, IndexTypeEntry>();
|
|
58
|
+
|
|
59
|
+
register(entry: IndexTypeEntry): void {
|
|
60
|
+
if (this.entries.has(entry.type)) {
|
|
61
|
+
throw new Error(`Index type "${entry.type}" is already registered`);
|
|
62
|
+
}
|
|
63
|
+
this.entries.set(entry.type, entry);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get(typeLiteral: string): IndexTypeEntry | undefined {
|
|
67
|
+
return this.entries.get(typeLiteral);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
has(typeLiteral: string): boolean {
|
|
71
|
+
return this.entries.has(typeLiteral);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function createIndexTypeRegistry(): IndexTypeRegistry {
|
|
76
|
+
return new IndexTypeRegistryImpl();
|
|
77
|
+
}
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -43,16 +43,8 @@ export type UniqueConstraint = {
|
|
|
43
43
|
export type Index = {
|
|
44
44
|
readonly columns: readonly string[];
|
|
45
45
|
readonly name?: string;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* Extension-specific methods are represented as strings and interpreted
|
|
49
|
-
* by the owning extension package.
|
|
50
|
-
*/
|
|
51
|
-
readonly using?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Optional extension-owned index configuration payload.
|
|
54
|
-
*/
|
|
55
|
-
readonly config?: Record<string, unknown>;
|
|
46
|
+
readonly type?: string;
|
|
47
|
+
readonly options?: Record<string, unknown>;
|
|
56
48
|
};
|
|
57
49
|
|
|
58
50
|
export type ForeignKeyReferences = {
|
package/src/validators.ts
CHANGED
|
@@ -96,8 +96,8 @@ const UniqueConstraintSchema = type.declare<UniqueConstraint>().type({
|
|
|
96
96
|
export const IndexSchema = type({
|
|
97
97
|
columns: type.string.array().readonly(),
|
|
98
98
|
'name?': 'string',
|
|
99
|
-
'
|
|
100
|
-
'
|
|
99
|
+
'type?': 'string',
|
|
100
|
+
'options?': 'Record<string, unknown>',
|
|
101
101
|
});
|
|
102
102
|
|
|
103
103
|
export const ForeignKeyReferencesSchema = type.declare<ForeignKeyReferences>().type({
|
|
@@ -375,6 +375,9 @@ export function validateStorageSemantics(storage: SqlStorage): string[] {
|
|
|
375
375
|
seenUniqueDefinitions.add(signature);
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
+
const sortOptions = (o: Record<string, unknown> | undefined): Record<string, unknown> | null =>
|
|
379
|
+
o ? Object.fromEntries(Object.entries(o).sort(([a], [b]) => a.localeCompare(b))) : null;
|
|
380
|
+
|
|
378
381
|
const seenIndexDefinitions = new Set<string>();
|
|
379
382
|
for (const index of table.indexes) {
|
|
380
383
|
const duplicateColumn = findDuplicateValue(index.columns);
|
|
@@ -384,8 +387,8 @@ export function validateStorageSemantics(storage: SqlStorage): string[] {
|
|
|
384
387
|
|
|
385
388
|
const signature = JSON.stringify({
|
|
386
389
|
columns: index.columns,
|
|
387
|
-
|
|
388
|
-
|
|
390
|
+
type: index.type ?? null,
|
|
391
|
+
options: sortOptions(index.options),
|
|
389
392
|
});
|
|
390
393
|
if (seenIndexDefinitions.has(signature)) {
|
|
391
394
|
errors.push(
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-CjGH62ec.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;AAUA;;;;;KAAY,aAAA;EAAA,SACD,UAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAWA;;;;;EAAA,SALA,UAAA,GAAa,MAAA;EAaF;;;;EAAA,SARX,OAAA;EAaiB;;;;EAAA,SARjB,OAAA,GAAU,aAAA;AAAA;AAAA,KAGT,UAAA;EAAA,SACD,OAAA;EAAA,SACA,IAAA;AAAA;AAAA,KAGC,gBAAA;EAAA,SACD,OAAA;EAAA,SACA,IAAA;AAAA;AAAA,KAGC,KAAA;EAAA,SACD,OAAA;EAAA,SACA,IAAA;;;;AAkBX;;WAZW,KAAA;EAYkB;;AAE7B;EAF6B,SARlB,MAAA,GAAS,MAAA;AAAA;AAAA,KAGR,oBAAA;EAAA,SACD,KAAA;EAAA,SACA,OAAA;AAAA;AAAA,KAGC,iBAAA;AAAA,KAEA,iBAAA;EAAA,SACD,IAAA;EAAA,SACA,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAA;AAAA;AAAA,KAGV,UAAA;EAAA,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