@prisma-next/sql-contract 0.3.0-dev.34 → 0.3.0-dev.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -8
- package/dist/factories.d.mts +45 -0
- package/dist/factories.d.mts.map +1 -0
- package/dist/factories.mjs +76 -0
- package/dist/factories.mjs.map +1 -0
- package/dist/pack-types.d.mts +13 -0
- package/dist/pack-types.d.mts.map +1 -0
- package/dist/pack-types.mjs +1 -0
- package/dist/types-D3AOQgwo.d.mts +117 -0
- package/dist/types-D3AOQgwo.d.mts.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/dist/validate.d.mts +7 -0
- package/dist/validate.d.mts.map +1 -0
- package/dist/validate.mjs +171 -0
- package/dist/validate.mjs.map +1 -0
- package/dist/validators-DY_87pfS.mjs +160 -0
- package/dist/validators-DY_87pfS.mjs.map +1 -0
- package/dist/{validators.d.ts → validators.d.mts} +21 -5
- package/dist/validators.d.mts.map +1 -0
- package/dist/validators.mjs +3 -0
- package/package.json +19 -22
- package/src/exports/validate.ts +1 -0
- package/src/exports/validators.ts +1 -1
- package/src/factories.ts +33 -6
- package/src/index.ts +1 -0
- package/src/types.ts +18 -2
- package/src/validate.ts +324 -0
- package/src/validators.ts +60 -17
- package/dist/exports/factories.d.ts +0 -2
- package/dist/exports/factories.d.ts.map +0 -1
- package/dist/exports/factories.js +0 -83
- package/dist/exports/factories.js.map +0 -1
- package/dist/exports/pack-types.d.ts +0 -2
- package/dist/exports/pack-types.d.ts.map +0 -1
- package/dist/exports/pack-types.js +0 -1
- package/dist/exports/pack-types.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -1
- package/dist/exports/types.js.map +0 -1
- package/dist/exports/validators.d.ts +0 -2
- package/dist/exports/validators.d.ts.map +0 -1
- package/dist/exports/validators.js +0 -109
- package/dist/exports/validators.js.map +0 -1
- package/dist/factories.d.ts +0 -38
- package/dist/factories.d.ts.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/pack-types.d.ts +0 -10
- package/dist/pack-types.d.ts.map +0 -1
- package/dist/types.d.ts +0 -106
- package/dist/types.d.ts.map +0 -1
- package/dist/validators.d.ts.map +0 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { type } from "arktype";
|
|
2
|
+
|
|
3
|
+
//#region src/validators.ts
|
|
4
|
+
const literalKindSchema = type("'literal'");
|
|
5
|
+
const functionKindSchema = type("'function'");
|
|
6
|
+
const generatorKindSchema = type("'generator'");
|
|
7
|
+
const generatorIdSchema = type("'ulid' | 'nanoid' | 'uuidv7' | 'uuidv4' | 'cuid2' | 'ksuid'");
|
|
8
|
+
const ColumnDefaultLiteralSchema = type.declare().type({
|
|
9
|
+
kind: literalKindSchema,
|
|
10
|
+
expression: "string"
|
|
11
|
+
});
|
|
12
|
+
const ColumnDefaultFunctionSchema = type.declare().type({
|
|
13
|
+
kind: functionKindSchema,
|
|
14
|
+
expression: "string"
|
|
15
|
+
});
|
|
16
|
+
const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);
|
|
17
|
+
const ExecutionMutationDefaultValueSchema = type({
|
|
18
|
+
kind: generatorKindSchema,
|
|
19
|
+
id: generatorIdSchema,
|
|
20
|
+
"params?": "Record<string, unknown>"
|
|
21
|
+
});
|
|
22
|
+
const ExecutionSchema = type({ mutations: { defaults: type({
|
|
23
|
+
ref: {
|
|
24
|
+
table: "string",
|
|
25
|
+
column: "string"
|
|
26
|
+
},
|
|
27
|
+
"onCreate?": ExecutionMutationDefaultValueSchema,
|
|
28
|
+
"onUpdate?": ExecutionMutationDefaultValueSchema
|
|
29
|
+
}).array().readonly() } });
|
|
30
|
+
const StorageColumnSchema = type({
|
|
31
|
+
nativeType: "string",
|
|
32
|
+
codecId: "string",
|
|
33
|
+
nullable: "boolean",
|
|
34
|
+
"typeParams?": "Record<string, unknown>",
|
|
35
|
+
"typeRef?": "string",
|
|
36
|
+
"default?": ColumnDefaultSchema
|
|
37
|
+
}).narrow((col, ctx) => {
|
|
38
|
+
if (col.typeParams !== void 0 && col.typeRef !== void 0) return ctx.mustBe("a column with either typeParams or typeRef, not both");
|
|
39
|
+
return true;
|
|
40
|
+
});
|
|
41
|
+
const StorageTypeInstanceSchema = type.declare().type({
|
|
42
|
+
codecId: "string",
|
|
43
|
+
nativeType: "string",
|
|
44
|
+
typeParams: "Record<string, unknown>"
|
|
45
|
+
});
|
|
46
|
+
const PrimaryKeySchema = type.declare().type({
|
|
47
|
+
columns: type.string.array().readonly(),
|
|
48
|
+
"name?": "string"
|
|
49
|
+
});
|
|
50
|
+
const UniqueConstraintSchema = type.declare().type({
|
|
51
|
+
columns: type.string.array().readonly(),
|
|
52
|
+
"name?": "string"
|
|
53
|
+
});
|
|
54
|
+
const IndexSchema = type.declare().type({
|
|
55
|
+
columns: type.string.array().readonly(),
|
|
56
|
+
"name?": "string"
|
|
57
|
+
});
|
|
58
|
+
const ForeignKeyReferencesSchema = type.declare().type({
|
|
59
|
+
table: "string",
|
|
60
|
+
columns: type.string.array().readonly()
|
|
61
|
+
});
|
|
62
|
+
const ForeignKeySchema = type.declare().type({
|
|
63
|
+
columns: type.string.array().readonly(),
|
|
64
|
+
references: ForeignKeyReferencesSchema,
|
|
65
|
+
"name?": "string"
|
|
66
|
+
});
|
|
67
|
+
const StorageTableSchema = type.declare().type({
|
|
68
|
+
columns: type({ "[string]": StorageColumnSchema }),
|
|
69
|
+
"primaryKey?": PrimaryKeySchema,
|
|
70
|
+
uniques: UniqueConstraintSchema.array().readonly(),
|
|
71
|
+
indexes: IndexSchema.array().readonly(),
|
|
72
|
+
foreignKeys: ForeignKeySchema.array().readonly()
|
|
73
|
+
});
|
|
74
|
+
const StorageSchema = type.declare().type({
|
|
75
|
+
tables: type({ "[string]": StorageTableSchema }),
|
|
76
|
+
"types?": type({ "[string]": StorageTypeInstanceSchema })
|
|
77
|
+
});
|
|
78
|
+
const ModelFieldSchema = type.declare().type({ column: "string" });
|
|
79
|
+
const ModelStorageSchema = type.declare().type({ table: "string" });
|
|
80
|
+
const ModelSchema = type.declare().type({
|
|
81
|
+
storage: ModelStorageSchema,
|
|
82
|
+
fields: type({ "[string]": ModelFieldSchema }),
|
|
83
|
+
relations: type({ "[string]": "unknown" })
|
|
84
|
+
});
|
|
85
|
+
const SqlContractSchema = type({
|
|
86
|
+
"schemaVersion?": "'1'",
|
|
87
|
+
target: "string",
|
|
88
|
+
targetFamily: "'sql'",
|
|
89
|
+
storageHash: "string",
|
|
90
|
+
"executionHash?": "string",
|
|
91
|
+
"profileHash?": "string",
|
|
92
|
+
"capabilities?": "Record<string, Record<string, boolean>>",
|
|
93
|
+
"extensionPacks?": "Record<string, unknown>",
|
|
94
|
+
"meta?": "Record<string, unknown>",
|
|
95
|
+
"sources?": "Record<string, unknown>",
|
|
96
|
+
models: type({ "[string]": ModelSchema }),
|
|
97
|
+
storage: StorageSchema,
|
|
98
|
+
"execution?": ExecutionSchema
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* Validates the structural shape of SqlStorage using Arktype.
|
|
102
|
+
*
|
|
103
|
+
* @param value - The storage value to validate
|
|
104
|
+
* @returns The validated storage if structure is valid
|
|
105
|
+
* @throws Error if the storage structure is invalid
|
|
106
|
+
*/
|
|
107
|
+
function validateStorage(value) {
|
|
108
|
+
const result = StorageSchema(value);
|
|
109
|
+
if (result instanceof type.errors) {
|
|
110
|
+
const messages = result.map((p) => p.message).join("; ");
|
|
111
|
+
throw new Error(`Storage validation failed: ${messages}`);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Validates the structural shape of ModelDefinition using Arktype.
|
|
117
|
+
*
|
|
118
|
+
* @param value - The model value to validate
|
|
119
|
+
* @returns The validated model if structure is valid
|
|
120
|
+
* @throws Error if the model structure is invalid
|
|
121
|
+
*/
|
|
122
|
+
function validateModel(value) {
|
|
123
|
+
const result = ModelSchema(value);
|
|
124
|
+
if (result instanceof type.errors) {
|
|
125
|
+
const messages = result.map((p) => p.message).join("; ");
|
|
126
|
+
throw new Error(`Model validation failed: ${messages}`);
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Validates the structural shape of a SqlContract using Arktype.
|
|
132
|
+
*
|
|
133
|
+
* **Responsibility: Validation Only**
|
|
134
|
+
* This function validates that the contract has the correct structure and types.
|
|
135
|
+
* It does NOT normalize the contract - normalization must happen in the contract builder.
|
|
136
|
+
*
|
|
137
|
+
* The contract passed to this function must already be normalized (all required fields present).
|
|
138
|
+
* If normalization is needed, it should be done by the contract builder before calling this function.
|
|
139
|
+
*
|
|
140
|
+
* This ensures all required fields are present and have the correct types.
|
|
141
|
+
*
|
|
142
|
+
* @param value - The contract value to validate (typically from a JSON import)
|
|
143
|
+
* @returns The validated contract if structure is valid
|
|
144
|
+
* @throws Error if the contract structure is invalid
|
|
145
|
+
*/
|
|
146
|
+
function validateSqlContract(value) {
|
|
147
|
+
if (typeof value !== "object" || value === null) throw new Error("Contract structural validation failed: value must be an object");
|
|
148
|
+
const rawValue = value;
|
|
149
|
+
if (rawValue.targetFamily !== void 0 && rawValue.targetFamily !== "sql") throw new Error(`Unsupported target family: ${rawValue.targetFamily}`);
|
|
150
|
+
const contractResult = SqlContractSchema(value);
|
|
151
|
+
if (contractResult instanceof type.errors) {
|
|
152
|
+
const messages = contractResult.map((p) => p.message).join("; ");
|
|
153
|
+
throw new Error(`Contract structural validation failed: ${messages}`);
|
|
154
|
+
}
|
|
155
|
+
return contractResult;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
//#endregion
|
|
159
|
+
export { validateSqlContract as a, validateModel as i, ColumnDefaultLiteralSchema as n, validateStorage as o, ColumnDefaultSchema as r, ColumnDefaultFunctionSchema as t };
|
|
160
|
+
//# sourceMappingURL=validators-DY_87pfS.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators-DY_87pfS.mjs","names":[],"sources":["../src/validators.ts"],"sourcesContent":["import { type } from 'arktype';\nimport type {\n ForeignKey,\n ForeignKeyReferences,\n Index,\n ModelDefinition,\n ModelField,\n ModelStorage,\n PrimaryKey,\n SqlContract,\n SqlStorage,\n StorageTable,\n StorageTypeInstance,\n UniqueConstraint,\n} from './types';\n\ntype ColumnDefaultLiteral = { readonly kind: 'literal'; readonly expression: string };\ntype ColumnDefaultFunction = { readonly kind: 'function'; readonly expression: string };\nconst literalKindSchema = type(\"'literal'\");\nconst functionKindSchema = type(\"'function'\");\nconst generatorKindSchema = type(\"'generator'\");\nconst generatorIdSchema = type(\"'ulid' | 'nanoid' | 'uuidv7' | 'uuidv4' | 'cuid2' | 'ksuid'\");\n\nexport const ColumnDefaultLiteralSchema = type.declare<ColumnDefaultLiteral>().type({\n kind: literalKindSchema,\n expression: 'string',\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 kind: generatorKindSchema,\n id: generatorIdSchema,\n 'params?': 'Record<string, unknown>',\n});\n\nconst ExecutionMutationDefaultSchema = type({\n ref: {\n table: 'string',\n column: 'string',\n },\n 'onCreate?': ExecutionMutationDefaultValueSchema,\n 'onUpdate?': ExecutionMutationDefaultValueSchema,\n});\n\nconst ExecutionSchema = type({\n mutations: {\n defaults: ExecutionMutationDefaultSchema.array().readonly(),\n },\n});\n\nconst StorageColumnSchema = type({\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\nconst IndexSchema = type.declare<Index>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nconst ForeignKeyReferencesSchema = type.declare<ForeignKeyReferences>().type({\n table: 'string',\n columns: type.string.array().readonly(),\n});\n\nconst ForeignKeySchema = type.declare<ForeignKey>().type({\n columns: type.string.array().readonly(),\n references: ForeignKeyReferencesSchema,\n 'name?': 'string',\n});\n\nconst StorageTableSchema = type.declare<StorageTable>().type({\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.declare<SqlStorage>().type({\n tables: type({ '[string]': StorageTableSchema }),\n 'types?': type({ '[string]': StorageTypeInstanceSchema }),\n});\n\nconst ModelFieldSchema = type.declare<ModelField>().type({\n column: 'string',\n});\n\nconst ModelStorageSchema = type.declare<ModelStorage>().type({\n table: 'string',\n});\n\nconst ModelSchema = type.declare<ModelDefinition>().type({\n storage: ModelStorageSchema,\n fields: type({ '[string]': ModelFieldSchema }),\n relations: type({ '[string]': 'unknown' }),\n});\n\nconst SqlContractSchema = type({\n 'schemaVersion?': \"'1'\",\n target: 'string',\n targetFamily: \"'sql'\",\n storageHash: 'string',\n 'executionHash?': 'string',\n 'profileHash?': 'string',\n 'capabilities?': 'Record<string, Record<string, boolean>>',\n 'extensionPacks?': 'Record<string, unknown>',\n 'meta?': 'Record<string, unknown>',\n 'sources?': 'Record<string, unknown>',\n models: type({ '[string]': ModelSchema }),\n storage: StorageSchema,\n 'execution?': ExecutionSchema,\n});\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;\n}\n\n/**\n * Validates the structural shape of ModelDefinition using Arktype.\n *\n * @param value - The model value to validate\n * @returns The validated model if structure is valid\n * @throws Error if the model structure is invalid\n */\nexport function validateModel(value: unknown): ModelDefinition {\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 a SqlContract using Arktype.\n *\n * **Responsibility: Validation Only**\n * This function validates that the contract has the correct structure and types.\n * It does NOT normalize the contract - normalization must happen in the contract builder.\n *\n * The contract passed to this function must already be normalized (all required fields present).\n * If normalization is needed, it should be done by the contract builder before calling this function.\n *\n * This ensures all required fields are present and have the correct types.\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 Error if the contract structure is invalid\n */\nexport function validateSqlContract<T extends SqlContract<SqlStorage>>(value: unknown): T {\n if (typeof value !== 'object' || value === null) {\n throw new Error('Contract structural validation failed: value must be an object');\n }\n\n // Check targetFamily first to provide a clear error message for unsupported target families\n const rawValue = value as { targetFamily?: string };\n if (rawValue.targetFamily !== undefined && rawValue.targetFamily !== 'sql') {\n throw new Error(`Unsupported target family: ${rawValue.targetFamily}`);\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 Error(`Contract structural validation failed: ${messages}`);\n }\n\n // After validation, contractResult matches the schema and preserves the input structure\n // TypeScript needs an assertion here due to exactOptionalPropertyTypes differences\n // between Arktype's inferred type and the generic T, but runtime-wise they're compatible\n return contractResult as T;\n}\n"],"mappings":"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"}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { f as SqlStorage, o as ModelDefinition, u as SqlContract } from "./types-D3AOQgwo.mjs";
|
|
2
|
+
import * as arktype_internal_variants_object_ts0 from "arktype/internal/variants/object.ts";
|
|
3
|
+
|
|
4
|
+
//#region src/validators.d.ts
|
|
5
|
+
type ColumnDefaultLiteral = {
|
|
6
|
+
readonly kind: 'literal';
|
|
7
|
+
readonly expression: string;
|
|
8
|
+
};
|
|
9
|
+
type ColumnDefaultFunction = {
|
|
10
|
+
readonly kind: 'function';
|
|
11
|
+
readonly expression: string;
|
|
12
|
+
};
|
|
13
|
+
declare const ColumnDefaultLiteralSchema: arktype_internal_variants_object_ts0.ObjectType<ColumnDefaultLiteral, {}>;
|
|
14
|
+
declare const ColumnDefaultFunctionSchema: arktype_internal_variants_object_ts0.ObjectType<ColumnDefaultFunction, {}>;
|
|
15
|
+
declare const ColumnDefaultSchema: arktype_internal_variants_object_ts0.ObjectType<ColumnDefaultLiteral | ColumnDefaultFunction, {}>;
|
|
2
16
|
/**
|
|
3
17
|
* Validates the structural shape of SqlStorage using Arktype.
|
|
4
18
|
*
|
|
@@ -6,7 +20,7 @@ import type { ModelDefinition, SqlContract, SqlStorage } from './types';
|
|
|
6
20
|
* @returns The validated storage if structure is valid
|
|
7
21
|
* @throws Error if the storage structure is invalid
|
|
8
22
|
*/
|
|
9
|
-
|
|
23
|
+
declare function validateStorage(value: unknown): SqlStorage;
|
|
10
24
|
/**
|
|
11
25
|
* Validates the structural shape of ModelDefinition using Arktype.
|
|
12
26
|
*
|
|
@@ -14,7 +28,7 @@ export declare function validateStorage(value: unknown): SqlStorage;
|
|
|
14
28
|
* @returns The validated model if structure is valid
|
|
15
29
|
* @throws Error if the model structure is invalid
|
|
16
30
|
*/
|
|
17
|
-
|
|
31
|
+
declare function validateModel(value: unknown): ModelDefinition;
|
|
18
32
|
/**
|
|
19
33
|
* Validates the structural shape of a SqlContract using Arktype.
|
|
20
34
|
*
|
|
@@ -31,5 +45,7 @@ export declare function validateModel(value: unknown): ModelDefinition;
|
|
|
31
45
|
* @returns The validated contract if structure is valid
|
|
32
46
|
* @throws Error if the contract structure is invalid
|
|
33
47
|
*/
|
|
34
|
-
|
|
35
|
-
//#
|
|
48
|
+
declare function validateSqlContract<T extends SqlContract<SqlStorage>>(value: unknown): T;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { ColumnDefaultFunctionSchema, ColumnDefaultLiteralSchema, ColumnDefaultSchema, validateModel, validateSqlContract, validateStorage };
|
|
51
|
+
//# sourceMappingURL=validators.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.mts","names":[],"sources":["../src/validators.ts"],"sourcesContent":[],"mappings":";;;;KAgBK,oBAAA;;;AAFY,CAAA;AAEQ,KACpB,qBAAA,GAAqB;EAMb,SAAA,IAAA,EAAA,UAAA;EAKA,SAAA,UAAA,EAAA,MAAA;AAKb,CAAA;AAAgC,cAVnB,0BAUmB,EAVO,oCAAA,CAAA,UAUP,CAVO,oBAUP,EAAA,CAAA,CAAA,CAAA;AAAA,cALnB,2BAKmB,EALQ,oCAAA,CAAA,UAKR,CALQ,qBAKR,EAAA,CAAA,CAAA,CAAA;AAAA,cAAnB,mBAAmB,EAAA,oCAAA,CAAA,UAAA,CAAA,oBAAA,GAAA,qBAAA,EAAA,CAAA,CAAA,CAAA;;AAuHhC;AAgBA;AAyBA;;;;AAAyF,iBAzCzE,eAAA,CAyCyE,KAAA,EAAA,OAAA,CAAA,EAzCxC,UAyCwC;;;;;;;;iBAzBzE,aAAA,kBAA+B;;;;;;;;;;;;;;;;;iBAyB/B,8BAA8B,YAAY,8BAA8B"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as validateSqlContract, i as validateModel, n as ColumnDefaultLiteralSchema, o as validateStorage, r as ColumnDefaultSchema, t as ColumnDefaultFunctionSchema } from "./validators-DY_87pfS.mjs";
|
|
2
|
+
|
|
3
|
+
export { ColumnDefaultFunctionSchema, ColumnDefaultLiteralSchema, ColumnDefaultSchema, validateModel, validateSqlContract, validateStorage };
|
package/package.json
CHANGED
|
@@ -1,44 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-contract",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.35",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"plane": "shared",
|
|
5
6
|
"sideEffects": false,
|
|
6
7
|
"description": "SQL contract types, validators, and IR factories for Prisma Next",
|
|
7
8
|
"dependencies": {
|
|
8
9
|
"arktype": "^2.1.25",
|
|
9
|
-
"@prisma-next/contract": "0.3.0-dev.
|
|
10
|
+
"@prisma-next/contract": "0.3.0-dev.35"
|
|
10
11
|
},
|
|
11
12
|
"devDependencies": {
|
|
12
|
-
"
|
|
13
|
+
"tsdown": "0.18.4",
|
|
13
14
|
"typescript": "5.9.3",
|
|
14
|
-
"vitest": "4.0.
|
|
15
|
+
"vitest": "4.0.17",
|
|
15
16
|
"@prisma-next/test-utils": "0.0.1",
|
|
16
|
-
"@prisma-next/tsconfig": "0.0.0"
|
|
17
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
18
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
17
19
|
},
|
|
18
20
|
"files": [
|
|
19
21
|
"dist",
|
|
20
22
|
"src"
|
|
21
23
|
],
|
|
22
24
|
"exports": {
|
|
23
|
-
"./
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"./validators":
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
"./pack-types": {
|
|
36
|
-
"types": "./dist/exports/pack-types.d.ts",
|
|
37
|
-
"import": "./dist/exports/pack-types.js"
|
|
38
|
-
}
|
|
25
|
+
"./factories": "./dist/factories.mjs",
|
|
26
|
+
"./pack-types": "./dist/pack-types.mjs",
|
|
27
|
+
"./types": "./dist/types.mjs",
|
|
28
|
+
"./validate": "./dist/validate.mjs",
|
|
29
|
+
"./validators": "./dist/validators.mjs",
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/prisma/prisma-next.git",
|
|
35
|
+
"directory": "packages/2-sql/1-core/contract"
|
|
39
36
|
},
|
|
40
37
|
"scripts": {
|
|
41
|
-
"build": "
|
|
38
|
+
"build": "tsdown",
|
|
42
39
|
"test": "vitest run",
|
|
43
40
|
"test:coverage": "vitest run --coverage",
|
|
44
41
|
"typecheck": "tsc --noEmit",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { validateContract } from '../validate';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from '../validators';
|
package/src/factories.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExecutionHashBase,
|
|
3
|
+
ProfileHashBase,
|
|
4
|
+
StorageHashBase,
|
|
5
|
+
} from '@prisma-next/contract/types';
|
|
1
6
|
import type {
|
|
2
7
|
ForeignKey,
|
|
3
8
|
ForeignKeyReferences,
|
|
@@ -100,26 +105,40 @@ export function storage(tables: Record<string, StorageTable>): SqlStorage {
|
|
|
100
105
|
return { tables };
|
|
101
106
|
}
|
|
102
107
|
|
|
103
|
-
export function contract
|
|
108
|
+
export function contract<
|
|
109
|
+
TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,
|
|
110
|
+
TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,
|
|
111
|
+
TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,
|
|
112
|
+
>(opts: {
|
|
104
113
|
target: string;
|
|
105
|
-
|
|
114
|
+
storageHash: TStorageHash;
|
|
115
|
+
executionHash?: TExecutionHash;
|
|
106
116
|
storage: SqlStorage;
|
|
107
117
|
models?: Record<string, ModelDefinition>;
|
|
108
118
|
relations?: Record<string, unknown>;
|
|
109
119
|
mappings?: Partial<SqlMappings>;
|
|
110
120
|
schemaVersion?: '1';
|
|
111
121
|
targetFamily?: 'sql';
|
|
112
|
-
profileHash?:
|
|
122
|
+
profileHash?: TProfileHash;
|
|
113
123
|
capabilities?: Record<string, Record<string, boolean>>;
|
|
114
124
|
extensionPacks?: Record<string, unknown>;
|
|
115
125
|
meta?: Record<string, unknown>;
|
|
116
126
|
sources?: Record<string, unknown>;
|
|
117
|
-
}): SqlContract
|
|
127
|
+
}): SqlContract<
|
|
128
|
+
SqlStorage,
|
|
129
|
+
Record<string, unknown>,
|
|
130
|
+
Record<string, unknown>,
|
|
131
|
+
SqlMappings,
|
|
132
|
+
TStorageHash,
|
|
133
|
+
TExecutionHash,
|
|
134
|
+
TProfileHash
|
|
135
|
+
> {
|
|
118
136
|
return {
|
|
119
137
|
schemaVersion: opts.schemaVersion ?? '1',
|
|
120
138
|
target: opts.target,
|
|
121
139
|
targetFamily: opts.targetFamily ?? 'sql',
|
|
122
|
-
|
|
140
|
+
storageHash: opts.storageHash,
|
|
141
|
+
...(opts.executionHash !== undefined && { executionHash: opts.executionHash }),
|
|
123
142
|
storage: opts.storage,
|
|
124
143
|
models: opts.models ?? {},
|
|
125
144
|
relations: opts.relations ?? {},
|
|
@@ -129,5 +148,13 @@ export function contract(opts: {
|
|
|
129
148
|
...(opts.extensionPacks !== undefined && { extensionPacks: opts.extensionPacks }),
|
|
130
149
|
...(opts.meta !== undefined && { meta: opts.meta }),
|
|
131
150
|
...(opts.sources !== undefined && { sources: opts.sources as Record<string, unknown> }),
|
|
132
|
-
} as SqlContract
|
|
151
|
+
} as SqlContract<
|
|
152
|
+
SqlStorage,
|
|
153
|
+
Record<string, unknown>,
|
|
154
|
+
Record<string, unknown>,
|
|
155
|
+
SqlMappings,
|
|
156
|
+
TStorageHash,
|
|
157
|
+
TExecutionHash,
|
|
158
|
+
TProfileHash
|
|
159
|
+
>;
|
|
133
160
|
}
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ColumnDefault,
|
|
3
|
+
ContractBase,
|
|
4
|
+
ExecutionHashBase,
|
|
5
|
+
ExecutionSection,
|
|
6
|
+
ProfileHashBase,
|
|
7
|
+
StorageHashBase,
|
|
8
|
+
} from '@prisma-next/contract/types';
|
|
2
9
|
|
|
3
10
|
/**
|
|
4
11
|
* A column definition in storage.
|
|
@@ -22,6 +29,11 @@ export type StorageColumn = {
|
|
|
22
29
|
* Mutually exclusive with `typeParams`.
|
|
23
30
|
*/
|
|
24
31
|
readonly typeRef?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Default value for the column.
|
|
34
|
+
* Can be a literal value or database function.
|
|
35
|
+
*/
|
|
36
|
+
readonly default?: ColumnDefault;
|
|
25
37
|
};
|
|
26
38
|
|
|
27
39
|
export type PrimaryKey = {
|
|
@@ -111,12 +123,16 @@ export type SqlContract<
|
|
|
111
123
|
M extends Record<string, unknown> = Record<string, unknown>,
|
|
112
124
|
R extends Record<string, unknown> = Record<string, unknown>,
|
|
113
125
|
Map extends SqlMappings = SqlMappings,
|
|
114
|
-
> =
|
|
126
|
+
TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,
|
|
127
|
+
TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,
|
|
128
|
+
TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,
|
|
129
|
+
> = ContractBase<TStorageHash, TExecutionHash, TProfileHash> & {
|
|
115
130
|
readonly targetFamily: string;
|
|
116
131
|
readonly storage: S;
|
|
117
132
|
readonly models: M;
|
|
118
133
|
readonly relations: R;
|
|
119
134
|
readonly mappings: Map;
|
|
135
|
+
readonly execution?: ExecutionSection;
|
|
120
136
|
};
|
|
121
137
|
|
|
122
138
|
export type ExtractCodecTypes<TContract extends SqlContract<SqlStorage>> =
|