@prisma-next/sql-contract 0.2.0 → 0.3.0-dev.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,41 +1,2 @@
1
- import { StorageColumn, SqlStorage, ModelDefinition, SqlMappings, SqlContract, ForeignKey, Index, ModelField, PrimaryKey, StorageTable, UniqueConstraint } from './types.js';
2
- import '@prisma-next/contract/types';
3
-
4
- /**
5
- * Creates a StorageColumn with nativeType and codecId.
6
- *
7
- * @param nativeType - Native database type identifier (e.g., 'int4', 'text', 'vector')
8
- * @param codecId - Codec identifier (e.g., 'pg/int4@1', 'pg/text@1')
9
- * @param nullable - Whether the column is nullable (default: false)
10
- * @returns StorageColumn with nativeType and codecId
11
- */
12
- declare function col(nativeType: string, codecId: string, nullable?: boolean): StorageColumn;
13
- declare function pk(...columns: readonly string[]): PrimaryKey;
14
- declare function unique(...columns: readonly string[]): UniqueConstraint;
15
- declare function index(...columns: readonly string[]): Index;
16
- declare function fk(columns: readonly string[], refTable: string, refColumns: readonly string[], name?: string): ForeignKey;
17
- declare function table(columns: Record<string, StorageColumn>, opts?: {
18
- pk?: PrimaryKey;
19
- uniques?: readonly UniqueConstraint[];
20
- indexes?: readonly Index[];
21
- fks?: readonly ForeignKey[];
22
- }): StorageTable;
23
- declare function model(table: string, fields: Record<string, ModelField>, relations?: Record<string, unknown>): ModelDefinition;
24
- declare function storage(tables: Record<string, StorageTable>): SqlStorage;
25
- declare function contract(opts: {
26
- target: string;
27
- coreHash: string;
28
- storage: SqlStorage;
29
- models?: Record<string, ModelDefinition>;
30
- relations?: Record<string, unknown>;
31
- mappings?: Partial<SqlMappings>;
32
- schemaVersion?: '1';
33
- targetFamily?: 'sql';
34
- profileHash?: string;
35
- capabilities?: Record<string, Record<string, boolean>>;
36
- extensionPacks?: Record<string, unknown>;
37
- meta?: Record<string, unknown>;
38
- sources?: Record<string, unknown>;
39
- }): SqlContract;
40
-
41
- export { col, contract, fk, index, model, pk, storage, table, unique };
1
+ export { col, contract, fk, index, model, pk, storage, table, unique, } from '../factories';
2
+ //# sourceMappingURL=factories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../../src/exports/factories.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,EAAE,EACF,KAAK,EACL,KAAK,EACL,EAAE,EACF,OAAO,EACP,KAAK,EACL,MAAM,GACP,MAAM,cAAc,CAAC"}
@@ -1,11 +1,2 @@
1
- /**
2
- * Storage type metadata for pack refs.
3
- */
4
- interface StorageTypeMetadata {
5
- readonly typeId: string;
6
- readonly familyId: string;
7
- readonly targetId: string;
8
- readonly nativeType?: string;
9
- }
10
-
11
- export type { StorageTypeMetadata };
1
+ export type { StorageTypeMetadata } from '../pack-types';
2
+ //# sourceMappingURL=pack-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack-types.d.ts","sourceRoot":"","sources":["../../src/exports/pack-types.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
@@ -1,70 +1,2 @@
1
- import { ContractBase } from '@prisma-next/contract/types';
2
-
3
- type StorageColumn = {
4
- readonly nativeType: string;
5
- readonly codecId: string;
6
- readonly nullable: boolean;
7
- };
8
- type PrimaryKey = {
9
- readonly columns: readonly string[];
10
- readonly name?: string;
11
- };
12
- type UniqueConstraint = {
13
- readonly columns: readonly string[];
14
- readonly name?: string;
15
- };
16
- type Index = {
17
- readonly columns: readonly string[];
18
- readonly name?: string;
19
- };
20
- type ForeignKeyReferences = {
21
- readonly table: string;
22
- readonly columns: readonly string[];
23
- };
24
- type ForeignKey = {
25
- readonly columns: readonly string[];
26
- readonly references: ForeignKeyReferences;
27
- readonly name?: string;
28
- };
29
- type StorageTable = {
30
- readonly columns: Record<string, StorageColumn>;
31
- readonly primaryKey?: PrimaryKey;
32
- readonly uniques: ReadonlyArray<UniqueConstraint>;
33
- readonly indexes: ReadonlyArray<Index>;
34
- readonly foreignKeys: ReadonlyArray<ForeignKey>;
35
- };
36
- type SqlStorage = {
37
- readonly tables: Record<string, StorageTable>;
38
- };
39
- type ModelField = {
40
- readonly column: string;
41
- };
42
- type ModelStorage = {
43
- readonly table: string;
44
- };
45
- type ModelDefinition = {
46
- readonly storage: ModelStorage;
47
- readonly fields: Record<string, ModelField>;
48
- readonly relations: Record<string, unknown>;
49
- };
50
- type SqlMappings = {
51
- readonly modelToTable?: Record<string, string>;
52
- readonly tableToModel?: Record<string, string>;
53
- readonly fieldToColumn?: Record<string, Record<string, string>>;
54
- readonly columnToField?: Record<string, Record<string, string>>;
55
- readonly codecTypes: Record<string, {
56
- readonly output: unknown;
57
- }>;
58
- readonly operationTypes: Record<string, Record<string, unknown>>;
59
- };
60
- type SqlContract<S extends SqlStorage = SqlStorage, M extends Record<string, unknown> = Record<string, unknown>, R extends Record<string, unknown> = Record<string, unknown>, Map extends SqlMappings = SqlMappings> = ContractBase & {
61
- readonly targetFamily: string;
62
- readonly storage: S;
63
- readonly models: M;
64
- readonly relations: R;
65
- readonly mappings: Map;
66
- };
67
- type ExtractCodecTypes<TContract extends SqlContract<SqlStorage>> = TContract['mappings']['codecTypes'];
68
- type ExtractOperationTypes<TContract extends SqlContract<SqlStorage>> = TContract['mappings']['operationTypes'];
69
-
70
- export type { ExtractCodecTypes, ExtractOperationTypes, ForeignKey, ForeignKeyReferences, Index, ModelDefinition, ModelField, ModelStorage, PrimaryKey, SqlContract, SqlMappings, SqlStorage, StorageColumn, StorageTable, UniqueConstraint };
1
+ export type { ExtractCodecTypes, ExtractOperationTypes, ForeignKey, ForeignKeyReferences, Index, ModelDefinition, ModelField, ModelStorage, PrimaryKey, SqlContract, SqlMappings, SqlStorage, StorageColumn, StorageTable, UniqueConstraint, } from '../types';
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/exports/types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,iBAAiB,EACjB,qBAAqB,EACrB,UAAU,EACV,oBAAoB,EACpB,KAAK,EACL,eAAe,EACf,UAAU,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,aAAa,EACb,YAAY,EACZ,gBAAgB,GACjB,MAAM,UAAU,CAAC"}
@@ -1,38 +1,2 @@
1
- import { ModelDefinition, SqlContract, SqlStorage } from './types.js';
2
- import '@prisma-next/contract/types';
3
-
4
- /**
5
- * Validates the structural shape of SqlStorage using Arktype.
6
- *
7
- * @param value - The storage value to validate
8
- * @returns The validated storage if structure is valid
9
- * @throws Error if the storage structure is invalid
10
- */
11
- declare function validateStorage(value: unknown): SqlStorage;
12
- /**
13
- * Validates the structural shape of ModelDefinition using Arktype.
14
- *
15
- * @param value - The model value to validate
16
- * @returns The validated model if structure is valid
17
- * @throws Error if the model structure is invalid
18
- */
19
- declare function validateModel(value: unknown): ModelDefinition;
20
- /**
21
- * Validates the structural shape of a SqlContract using Arktype.
22
- *
23
- * **Responsibility: Validation Only**
24
- * This function validates that the contract has the correct structure and types.
25
- * It does NOT normalize the contract - normalization must happen in the contract builder.
26
- *
27
- * The contract passed to this function must already be normalized (all required fields present).
28
- * If normalization is needed, it should be done by the contract builder before calling this function.
29
- *
30
- * This ensures all required fields are present and have the correct types.
31
- *
32
- * @param value - The contract value to validate (typically from a JSON import)
33
- * @returns The validated contract if structure is valid
34
- * @throws Error if the contract structure is invalid
35
- */
36
- declare function validateSqlContract<T extends SqlContract<SqlStorage>>(value: unknown): T;
37
-
38
- export { validateModel, validateSqlContract, validateStorage };
1
+ export { validateModel, validateSqlContract, validateStorage } from '../validators';
2
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/exports/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { ForeignKey, Index, ModelDefinition, ModelField, PrimaryKey, SqlContract, SqlMappings, SqlStorage, StorageColumn, StorageTable, UniqueConstraint } from './types';
2
+ /**
3
+ * Creates a StorageColumn with nativeType and codecId.
4
+ *
5
+ * @param nativeType - Native database type identifier (e.g., 'int4', 'text', 'vector')
6
+ * @param codecId - Codec identifier (e.g., 'pg/int4@1', 'pg/text@1')
7
+ * @param nullable - Whether the column is nullable (default: false)
8
+ * @returns StorageColumn with nativeType and codecId
9
+ */
10
+ export declare function col(nativeType: string, codecId: string, nullable?: boolean): StorageColumn;
11
+ export declare function pk(...columns: readonly string[]): PrimaryKey;
12
+ export declare function unique(...columns: readonly string[]): UniqueConstraint;
13
+ export declare function index(...columns: readonly string[]): Index;
14
+ export declare function fk(columns: readonly string[], refTable: string, refColumns: readonly string[], name?: string): ForeignKey;
15
+ export declare function table(columns: Record<string, StorageColumn>, opts?: {
16
+ pk?: PrimaryKey;
17
+ uniques?: readonly UniqueConstraint[];
18
+ indexes?: readonly Index[];
19
+ fks?: readonly ForeignKey[];
20
+ }): StorageTable;
21
+ export declare function model(table: string, fields: Record<string, ModelField>, relations?: Record<string, unknown>): ModelDefinition;
22
+ export declare function storage(tables: Record<string, StorageTable>): SqlStorage;
23
+ export declare function contract(opts: {
24
+ target: string;
25
+ coreHash: string;
26
+ storage: SqlStorage;
27
+ models?: Record<string, ModelDefinition>;
28
+ relations?: Record<string, unknown>;
29
+ mappings?: Partial<SqlMappings>;
30
+ schemaVersion?: '1';
31
+ targetFamily?: 'sql';
32
+ profileHash?: string;
33
+ capabilities?: Record<string, Record<string, boolean>>;
34
+ extensionPacks?: Record<string, unknown>;
35
+ meta?: Record<string, unknown>;
36
+ sources?: Record<string, unknown>;
37
+ }): SqlContract;
38
+ //# sourceMappingURL=factories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../src/factories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AAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,UAAU,CAExE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,UAAU,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAChC,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,GAAG,WAAW,CAgBd"}
@@ -0,0 +1,4 @@
1
+ export * from './exports/factories';
2
+ export * from './exports/types';
3
+ export * from './exports/validators';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Storage type metadata for pack refs.
3
+ */
4
+ export interface StorageTypeMetadata {
5
+ readonly typeId: string;
6
+ readonly familyId: string;
7
+ readonly targetId: string;
8
+ readonly nativeType?: string;
9
+ }
10
+ //# sourceMappingURL=pack-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack-types.d.ts","sourceRoot":"","sources":["../src/pack-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B"}
@@ -0,0 +1,68 @@
1
+ import type { ContractBase } from '@prisma-next/contract/types';
2
+ export type StorageColumn = {
3
+ readonly nativeType: string;
4
+ readonly codecId: string;
5
+ readonly nullable: boolean;
6
+ };
7
+ export type PrimaryKey = {
8
+ readonly columns: readonly string[];
9
+ readonly name?: string;
10
+ };
11
+ export type UniqueConstraint = {
12
+ readonly columns: readonly string[];
13
+ readonly name?: string;
14
+ };
15
+ export type Index = {
16
+ readonly columns: readonly string[];
17
+ readonly name?: string;
18
+ };
19
+ export type ForeignKeyReferences = {
20
+ readonly table: string;
21
+ readonly columns: readonly string[];
22
+ };
23
+ export type ForeignKey = {
24
+ readonly columns: readonly string[];
25
+ readonly references: ForeignKeyReferences;
26
+ readonly name?: string;
27
+ };
28
+ export type StorageTable = {
29
+ readonly columns: Record<string, StorageColumn>;
30
+ readonly primaryKey?: PrimaryKey;
31
+ readonly uniques: ReadonlyArray<UniqueConstraint>;
32
+ readonly indexes: ReadonlyArray<Index>;
33
+ readonly foreignKeys: ReadonlyArray<ForeignKey>;
34
+ };
35
+ export type SqlStorage = {
36
+ readonly tables: Record<string, StorageTable>;
37
+ };
38
+ export type ModelField = {
39
+ readonly column: string;
40
+ };
41
+ export type ModelStorage = {
42
+ readonly table: string;
43
+ };
44
+ export type ModelDefinition = {
45
+ readonly storage: ModelStorage;
46
+ readonly fields: Record<string, ModelField>;
47
+ readonly relations: Record<string, unknown>;
48
+ };
49
+ export type SqlMappings = {
50
+ readonly modelToTable?: Record<string, string>;
51
+ readonly tableToModel?: Record<string, string>;
52
+ readonly fieldToColumn?: Record<string, Record<string, string>>;
53
+ readonly columnToField?: Record<string, Record<string, string>>;
54
+ readonly codecTypes: Record<string, {
55
+ readonly output: unknown;
56
+ }>;
57
+ readonly operationTypes: Record<string, Record<string, unknown>>;
58
+ };
59
+ export type SqlContract<S extends SqlStorage = SqlStorage, M extends Record<string, unknown> = Record<string, unknown>, R extends Record<string, unknown> = Record<string, unknown>, Map extends SqlMappings = SqlMappings> = ContractBase & {
60
+ readonly targetFamily: string;
61
+ readonly storage: S;
62
+ readonly models: M;
63
+ readonly relations: R;
64
+ readonly mappings: Map;
65
+ };
66
+ export type ExtractCodecTypes<TContract extends SqlContract<SqlStorage>> = TContract['mappings']['codecTypes'];
67
+ export type ExtractOperationTypes<TContract extends SqlContract<SqlStorage>> = TContract['mappings']['operationTypes'];
68
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF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AAE,CAAC,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,SAAS,SAAS,WAAW,CAAC,UAAU,CAAC,IACrE,SAAS,CAAC,UAAU,CAAC,CAAC,YAAY,CAAC,CAAC;AAEtC,MAAM,MAAM,qBAAqB,CAAC,SAAS,SAAS,WAAW,CAAC,UAAU,CAAC,IACzE,SAAS,CAAC,UAAU,CAAC,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { ModelDefinition, SqlContract, SqlStorage } from './types';
2
+ /**
3
+ * Validates the structural shape of SqlStorage using Arktype.
4
+ *
5
+ * @param value - The storage value to validate
6
+ * @returns The validated storage if structure is valid
7
+ * @throws Error if the storage structure is invalid
8
+ */
9
+ export declare function validateStorage(value: unknown): SqlStorage;
10
+ /**
11
+ * Validates the structural shape of ModelDefinition using Arktype.
12
+ *
13
+ * @param value - The model value to validate
14
+ * @returns The validated model if structure is valid
15
+ * @throws Error if the model structure is invalid
16
+ */
17
+ export declare function validateModel(value: unknown): ModelDefinition;
18
+ /**
19
+ * Validates the structural shape of a SqlContract using Arktype.
20
+ *
21
+ * **Responsibility: Validation Only**
22
+ * This function validates that the contract has the correct structure and types.
23
+ * It does NOT normalize the contract - normalization must happen in the contract builder.
24
+ *
25
+ * The contract passed to this function must already be normalized (all required fields present).
26
+ * If normalization is needed, it should be done by the contract builder before calling this function.
27
+ *
28
+ * This ensures all required fields are present and have the correct types.
29
+ *
30
+ * @param value - The contract value to validate (typically from a JSON import)
31
+ * @returns The validated contract if structure is valid
32
+ * @throws Error if the contract structure is invalid
33
+ */
34
+ export declare function validateSqlContract<T extends SqlContract<SqlStorage>>(value: unknown): T;
35
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,eAAe,EAIf,WAAW,EACX,UAAU,EAIX,MAAM,SAAS,CAAC;AA0EjB;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAO1D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAO7D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,WAAW,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAkBxF"}
package/package.json CHANGED
@@ -1,22 +1,23 @@
1
1
  {
2
2
  "name": "@prisma-next/sql-contract",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-dev.10",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "SQL contract types, validators, and IR factories for Prisma Next",
7
7
  "dependencies": {
8
8
  "arktype": "^2.1.25",
9
- "@prisma-next/contract": "0.2.0"
9
+ "@prisma-next/contract": "0.3.0-dev.10"
10
10
  },
11
11
  "devDependencies": {
12
- "@vitest/coverage-v8": "^4.0.0",
13
- "tsup": "^8.3.0",
14
- "typescript": "^5.9.3",
15
- "vitest": "^4.0.16",
12
+ "@vitest/coverage-v8": "4.0.16",
13
+ "tsup": "8.5.1",
14
+ "typescript": "5.9.3",
15
+ "vitest": "4.0.16",
16
16
  "@prisma-next/test-utils": "0.0.1"
17
17
  },
18
18
  "files": [
19
- "dist"
19
+ "dist",
20
+ "src"
20
21
  ],
21
22
  "exports": {
22
23
  "./types": {
@@ -37,7 +38,7 @@
37
38
  }
38
39
  },
39
40
  "scripts": {
40
- "build": "tsup --config tsup.config.ts",
41
+ "build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
41
42
  "test": "vitest run",
42
43
  "test:coverage": "vitest run --coverage",
43
44
  "typecheck": "tsc --project tsconfig.json --noEmit",
@@ -0,0 +1,11 @@
1
+ export {
2
+ col,
3
+ contract,
4
+ fk,
5
+ index,
6
+ model,
7
+ pk,
8
+ storage,
9
+ table,
10
+ unique,
11
+ } from '../factories';
@@ -0,0 +1 @@
1
+ export type { StorageTypeMetadata } from '../pack-types';
@@ -0,0 +1,17 @@
1
+ export type {
2
+ ExtractCodecTypes,
3
+ ExtractOperationTypes,
4
+ ForeignKey,
5
+ ForeignKeyReferences,
6
+ Index,
7
+ ModelDefinition,
8
+ ModelField,
9
+ ModelStorage,
10
+ PrimaryKey,
11
+ SqlContract,
12
+ SqlMappings,
13
+ SqlStorage,
14
+ StorageColumn,
15
+ StorageTable,
16
+ UniqueConstraint,
17
+ } from '../types';
@@ -0,0 +1 @@
1
+ export { validateModel, validateSqlContract, validateStorage } from '../validators';
@@ -0,0 +1,133 @@
1
+ import type {
2
+ ForeignKey,
3
+ ForeignKeyReferences,
4
+ Index,
5
+ ModelDefinition,
6
+ ModelField,
7
+ ModelStorage,
8
+ PrimaryKey,
9
+ SqlContract,
10
+ SqlMappings,
11
+ SqlStorage,
12
+ StorageColumn,
13
+ StorageTable,
14
+ UniqueConstraint,
15
+ } from './types';
16
+
17
+ /**
18
+ * Creates a StorageColumn with nativeType and codecId.
19
+ *
20
+ * @param nativeType - Native database type identifier (e.g., 'int4', 'text', 'vector')
21
+ * @param codecId - Codec identifier (e.g., 'pg/int4@1', 'pg/text@1')
22
+ * @param nullable - Whether the column is nullable (default: false)
23
+ * @returns StorageColumn with nativeType and codecId
24
+ */
25
+ export function col(nativeType: string, codecId: string, nullable = false): StorageColumn {
26
+ return {
27
+ nativeType,
28
+ codecId,
29
+ nullable,
30
+ };
31
+ }
32
+
33
+ export function pk(...columns: readonly string[]): PrimaryKey {
34
+ return {
35
+ columns,
36
+ };
37
+ }
38
+
39
+ export function unique(...columns: readonly string[]): UniqueConstraint {
40
+ return {
41
+ columns,
42
+ };
43
+ }
44
+
45
+ export function index(...columns: readonly string[]): Index {
46
+ return {
47
+ columns,
48
+ };
49
+ }
50
+
51
+ export function fk(
52
+ columns: readonly string[],
53
+ refTable: string,
54
+ refColumns: readonly string[],
55
+ name?: string,
56
+ ): ForeignKey {
57
+ const references: ForeignKeyReferences = {
58
+ table: refTable,
59
+ columns: refColumns,
60
+ };
61
+ return {
62
+ columns,
63
+ references,
64
+ ...(name !== undefined && { name }),
65
+ };
66
+ }
67
+
68
+ export function table(
69
+ columns: Record<string, StorageColumn>,
70
+ opts?: {
71
+ pk?: PrimaryKey;
72
+ uniques?: readonly UniqueConstraint[];
73
+ indexes?: readonly Index[];
74
+ fks?: readonly ForeignKey[];
75
+ },
76
+ ): StorageTable {
77
+ return {
78
+ columns,
79
+ ...(opts?.pk !== undefined && { primaryKey: opts.pk }),
80
+ uniques: opts?.uniques ?? [],
81
+ indexes: opts?.indexes ?? [],
82
+ foreignKeys: opts?.fks ?? [],
83
+ };
84
+ }
85
+
86
+ export function model(
87
+ table: string,
88
+ fields: Record<string, ModelField>,
89
+ relations: Record<string, unknown> = {},
90
+ ): ModelDefinition {
91
+ const storage: ModelStorage = { table };
92
+ return {
93
+ storage,
94
+ fields,
95
+ relations,
96
+ };
97
+ }
98
+
99
+ export function storage(tables: Record<string, StorageTable>): SqlStorage {
100
+ return { tables };
101
+ }
102
+
103
+ export function contract(opts: {
104
+ target: string;
105
+ coreHash: string;
106
+ storage: SqlStorage;
107
+ models?: Record<string, ModelDefinition>;
108
+ relations?: Record<string, unknown>;
109
+ mappings?: Partial<SqlMappings>;
110
+ schemaVersion?: '1';
111
+ targetFamily?: 'sql';
112
+ profileHash?: string;
113
+ capabilities?: Record<string, Record<string, boolean>>;
114
+ extensionPacks?: Record<string, unknown>;
115
+ meta?: Record<string, unknown>;
116
+ sources?: Record<string, unknown>;
117
+ }): SqlContract {
118
+ return {
119
+ schemaVersion: opts.schemaVersion ?? '1',
120
+ target: opts.target,
121
+ targetFamily: opts.targetFamily ?? 'sql',
122
+ coreHash: opts.coreHash,
123
+ storage: opts.storage,
124
+ models: opts.models ?? {},
125
+ relations: opts.relations ?? {},
126
+ mappings: (opts.mappings ?? {}) as SqlMappings,
127
+ ...(opts.profileHash !== undefined && { profileHash: opts.profileHash }),
128
+ ...(opts.capabilities !== undefined && { capabilities: opts.capabilities }),
129
+ ...(opts.extensionPacks !== undefined && { extensionPacks: opts.extensionPacks }),
130
+ ...(opts.meta !== undefined && { meta: opts.meta }),
131
+ ...(opts.sources !== undefined && { sources: opts.sources as Record<string, unknown> }),
132
+ } as SqlContract;
133
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './exports/factories';
2
+ export * from './exports/types';
3
+ export * from './exports/validators';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Storage type metadata for pack refs.
3
+ */
4
+ export interface StorageTypeMetadata {
5
+ readonly typeId: string;
6
+ readonly familyId: string;
7
+ readonly targetId: string;
8
+ readonly nativeType?: string;
9
+ }
package/src/types.ts ADDED
@@ -0,0 +1,87 @@
1
+ import type { ContractBase } from '@prisma-next/contract/types';
2
+
3
+ export type StorageColumn = {
4
+ readonly nativeType: string;
5
+ readonly codecId: string;
6
+ readonly nullable: boolean;
7
+ };
8
+
9
+ export type PrimaryKey = {
10
+ readonly columns: readonly string[];
11
+ readonly name?: string;
12
+ };
13
+
14
+ export type UniqueConstraint = {
15
+ readonly columns: readonly string[];
16
+ readonly name?: string;
17
+ };
18
+
19
+ export type Index = {
20
+ readonly columns: readonly string[];
21
+ readonly name?: string;
22
+ };
23
+
24
+ export type ForeignKeyReferences = {
25
+ readonly table: string;
26
+ readonly columns: readonly string[];
27
+ };
28
+
29
+ export type ForeignKey = {
30
+ readonly columns: readonly string[];
31
+ readonly references: ForeignKeyReferences;
32
+ readonly name?: string;
33
+ };
34
+
35
+ export type StorageTable = {
36
+ readonly columns: Record<string, StorageColumn>;
37
+ readonly primaryKey?: PrimaryKey;
38
+ readonly uniques: ReadonlyArray<UniqueConstraint>;
39
+ readonly indexes: ReadonlyArray<Index>;
40
+ readonly foreignKeys: ReadonlyArray<ForeignKey>;
41
+ };
42
+
43
+ export type SqlStorage = {
44
+ readonly tables: Record<string, StorageTable>;
45
+ };
46
+
47
+ export type ModelField = {
48
+ readonly column: string;
49
+ };
50
+
51
+ export type ModelStorage = {
52
+ readonly table: string;
53
+ };
54
+
55
+ export type ModelDefinition = {
56
+ readonly storage: ModelStorage;
57
+ readonly fields: Record<string, ModelField>;
58
+ readonly relations: Record<string, unknown>;
59
+ };
60
+
61
+ export type SqlMappings = {
62
+ readonly modelToTable?: Record<string, string>;
63
+ readonly tableToModel?: Record<string, string>;
64
+ readonly fieldToColumn?: Record<string, Record<string, string>>;
65
+ readonly columnToField?: Record<string, Record<string, string>>;
66
+ readonly codecTypes: Record<string, { readonly output: unknown }>;
67
+ readonly operationTypes: Record<string, Record<string, unknown>>;
68
+ };
69
+
70
+ export type SqlContract<
71
+ S extends SqlStorage = SqlStorage,
72
+ M extends Record<string, unknown> = Record<string, unknown>,
73
+ R extends Record<string, unknown> = Record<string, unknown>,
74
+ Map extends SqlMappings = SqlMappings,
75
+ > = ContractBase & {
76
+ readonly targetFamily: string;
77
+ readonly storage: S;
78
+ readonly models: M;
79
+ readonly relations: R;
80
+ readonly mappings: Map;
81
+ };
82
+
83
+ export type ExtractCodecTypes<TContract extends SqlContract<SqlStorage>> =
84
+ TContract['mappings']['codecTypes'];
85
+
86
+ export type ExtractOperationTypes<TContract extends SqlContract<SqlStorage>> =
87
+ TContract['mappings']['operationTypes'];
@@ -0,0 +1,155 @@
1
+ import { type } from 'arktype';
2
+ import type {
3
+ ForeignKey,
4
+ ForeignKeyReferences,
5
+ Index,
6
+ ModelDefinition,
7
+ ModelField,
8
+ ModelStorage,
9
+ PrimaryKey,
10
+ SqlContract,
11
+ SqlStorage,
12
+ StorageColumn,
13
+ StorageTable,
14
+ UniqueConstraint,
15
+ } from './types';
16
+
17
+ const StorageColumnSchema = type.declare<StorageColumn>().type({
18
+ nativeType: 'string',
19
+ codecId: 'string',
20
+ nullable: 'boolean',
21
+ });
22
+
23
+ const PrimaryKeySchema = type.declare<PrimaryKey>().type({
24
+ columns: type.string.array().readonly(),
25
+ 'name?': 'string',
26
+ });
27
+
28
+ const UniqueConstraintSchema = type.declare<UniqueConstraint>().type({
29
+ columns: type.string.array().readonly(),
30
+ 'name?': 'string',
31
+ });
32
+
33
+ const IndexSchema = type.declare<Index>().type({
34
+ columns: type.string.array().readonly(),
35
+ 'name?': 'string',
36
+ });
37
+
38
+ const ForeignKeyReferencesSchema = type.declare<ForeignKeyReferences>().type({
39
+ table: 'string',
40
+ columns: type.string.array().readonly(),
41
+ });
42
+
43
+ const ForeignKeySchema = type.declare<ForeignKey>().type({
44
+ columns: type.string.array().readonly(),
45
+ references: ForeignKeyReferencesSchema,
46
+ 'name?': 'string',
47
+ });
48
+
49
+ const StorageTableSchema = type.declare<StorageTable>().type({
50
+ columns: type({ '[string]': StorageColumnSchema }),
51
+ 'primaryKey?': PrimaryKeySchema,
52
+ uniques: UniqueConstraintSchema.array().readonly(),
53
+ indexes: IndexSchema.array().readonly(),
54
+ foreignKeys: ForeignKeySchema.array().readonly(),
55
+ });
56
+
57
+ const StorageSchema = type.declare<SqlStorage>().type({
58
+ tables: type({ '[string]': StorageTableSchema }),
59
+ });
60
+
61
+ const ModelFieldSchema = type.declare<ModelField>().type({
62
+ column: 'string',
63
+ });
64
+
65
+ const ModelStorageSchema = type.declare<ModelStorage>().type({
66
+ table: 'string',
67
+ });
68
+
69
+ const ModelSchema = type.declare<ModelDefinition>().type({
70
+ storage: ModelStorageSchema,
71
+ fields: type({ '[string]': ModelFieldSchema }),
72
+ relations: type({ '[string]': 'unknown' }),
73
+ });
74
+
75
+ const SqlContractSchema = type({
76
+ 'schemaVersion?': "'1'",
77
+ target: 'string',
78
+ targetFamily: "'sql'",
79
+ coreHash: 'string',
80
+ 'profileHash?': 'string',
81
+ 'capabilities?': 'Record<string, Record<string, boolean>>',
82
+ 'extensionPacks?': 'Record<string, unknown>',
83
+ 'meta?': 'Record<string, unknown>',
84
+ 'sources?': 'Record<string, unknown>',
85
+ models: type({ '[string]': ModelSchema }),
86
+ storage: StorageSchema,
87
+ });
88
+
89
+ /**
90
+ * Validates the structural shape of SqlStorage using Arktype.
91
+ *
92
+ * @param value - The storage value to validate
93
+ * @returns The validated storage if structure is valid
94
+ * @throws Error if the storage structure is invalid
95
+ */
96
+ export function validateStorage(value: unknown): SqlStorage {
97
+ const result = StorageSchema(value);
98
+ if (result instanceof type.errors) {
99
+ const messages = result.map((p: { message: string }) => p.message).join('; ');
100
+ throw new Error(`Storage validation failed: ${messages}`);
101
+ }
102
+ return result;
103
+ }
104
+
105
+ /**
106
+ * Validates the structural shape of ModelDefinition using Arktype.
107
+ *
108
+ * @param value - The model value to validate
109
+ * @returns The validated model if structure is valid
110
+ * @throws Error if the model structure is invalid
111
+ */
112
+ export function validateModel(value: unknown): ModelDefinition {
113
+ const result = ModelSchema(value);
114
+ if (result instanceof type.errors) {
115
+ const messages = result.map((p: { message: string }) => p.message).join('; ');
116
+ throw new Error(`Model validation failed: ${messages}`);
117
+ }
118
+ return result;
119
+ }
120
+
121
+ /**
122
+ * Validates the structural shape of a SqlContract using Arktype.
123
+ *
124
+ * **Responsibility: Validation Only**
125
+ * This function validates that the contract has the correct structure and types.
126
+ * It does NOT normalize the contract - normalization must happen in the contract builder.
127
+ *
128
+ * The contract passed to this function must already be normalized (all required fields present).
129
+ * If normalization is needed, it should be done by the contract builder before calling this function.
130
+ *
131
+ * This ensures all required fields are present and have the correct types.
132
+ *
133
+ * @param value - The contract value to validate (typically from a JSON import)
134
+ * @returns The validated contract if structure is valid
135
+ * @throws Error if the contract structure is invalid
136
+ */
137
+ export function validateSqlContract<T extends SqlContract<SqlStorage>>(value: unknown): T {
138
+ // Check targetFamily first to provide a clear error message for unsupported target families
139
+ const rawValue = value as { targetFamily?: string };
140
+ if (rawValue.targetFamily !== undefined && rawValue.targetFamily !== 'sql') {
141
+ throw new Error(`Unsupported target family: ${rawValue.targetFamily}`);
142
+ }
143
+
144
+ const contractResult = SqlContractSchema(value);
145
+
146
+ if (contractResult instanceof type.errors) {
147
+ const messages = contractResult.map((p: { message: string }) => p.message).join('; ');
148
+ throw new Error(`Contract structural validation failed: ${messages}`);
149
+ }
150
+
151
+ // After validation, contractResult matches the schema and preserves the input structure
152
+ // TypeScript needs an assertion here due to exactOptionalPropertyTypes differences
153
+ // between Arktype's inferred type and the generic T, but runtime-wise they're compatible
154
+ return contractResult as T;
155
+ }