@prisma-next/sql-contract 0.3.0-pr.93.5 → 0.3.0-pr.96.1
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/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/validators.js +10 -2
- package/dist/exports/validators.js.map +1 -1
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/validators.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/exports/types.ts +1 -0
- package/src/types.ts +27 -0
- package/src/validators.ts +10 -0
package/dist/exports/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { ExtractCodecTypes, ExtractOperationTypes, ForeignKey, ForeignKeyReferences, Index, ModelDefinition, ModelField, ModelStorage, PrimaryKey, SqlContract, SqlMappings, SqlStorage, StorageColumn, StorageTable, UniqueConstraint, } from '../types';
|
|
1
|
+
export type { ExtractCodecTypes, ExtractOperationTypes, ForeignKey, ForeignKeyReferences, Index, ModelDefinition, ModelField, ModelStorage, PrimaryKey, SqlContract, SqlMappings, SqlStorage, StorageColumn, StorageTable, StorageTypeInstance, UniqueConstraint, } from '../types';
|
|
2
2
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +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
|
+
{"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,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,UAAU,CAAC"}
|
|
@@ -3,7 +3,14 @@ import { type } from "arktype";
|
|
|
3
3
|
var StorageColumnSchema = type.declare().type({
|
|
4
4
|
nativeType: "string",
|
|
5
5
|
codecId: "string",
|
|
6
|
-
nullable: "boolean"
|
|
6
|
+
nullable: "boolean",
|
|
7
|
+
"typeParams?": "Record<string, unknown>",
|
|
8
|
+
"typeRef?": "string"
|
|
9
|
+
});
|
|
10
|
+
var StorageTypeInstanceSchema = type.declare().type({
|
|
11
|
+
codecId: "string",
|
|
12
|
+
nativeType: "string",
|
|
13
|
+
typeParams: "Record<string, unknown>"
|
|
7
14
|
});
|
|
8
15
|
var PrimaryKeySchema = type.declare().type({
|
|
9
16
|
columns: type.string.array().readonly(),
|
|
@@ -34,7 +41,8 @@ var StorageTableSchema = type.declare().type({
|
|
|
34
41
|
foreignKeys: ForeignKeySchema.array().readonly()
|
|
35
42
|
});
|
|
36
43
|
var StorageSchema = type.declare().type({
|
|
37
|
-
tables: type({ "[string]": StorageTableSchema })
|
|
44
|
+
tables: type({ "[string]": StorageTableSchema }),
|
|
45
|
+
"types?": type({ "[string]": StorageTypeInstanceSchema })
|
|
38
46
|
});
|
|
39
47
|
var ModelFieldSchema = type.declare().type({
|
|
40
48
|
column: "string"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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 StorageColumn,\n StorageTable,\n UniqueConstraint,\n} from './types';\n\nconst StorageColumnSchema = type.declare<StorageColumn>().type({\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\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});\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 coreHash: '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});\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 // 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":";AAAA,SAAS,YAAY;
|
|
1
|
+
{"version":3,"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 StorageColumn,\n StorageTable,\n StorageTypeInstance,\n UniqueConstraint,\n} from './types';\n\nconst StorageColumnSchema = type.declare<StorageColumn>().type({\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\n 'typeParams?': 'Record<string, unknown>',\n 'typeRef?': 'string',\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 coreHash: '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});\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 // 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":";AAAA,SAAS,YAAY;AAiBrB,IAAM,sBAAsB,KAAK,QAAuB,EAAE,KAAK;AAAA,EAC7D,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,UAAU;AAAA,EACV,eAAe;AAAA,EACf,YAAY;AACd,CAAC;AAED,IAAM,4BAA4B,KAAK,QAA6B,EAAE,KAAK;AAAA,EACzE,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,YAAY;AACd,CAAC;AAED,IAAM,mBAAmB,KAAK,QAAoB,EAAE,KAAK;AAAA,EACvD,SAAS,KAAK,OAAO,MAAM,EAAE,SAAS;AAAA,EACtC,SAAS;AACX,CAAC;AAED,IAAM,yBAAyB,KAAK,QAA0B,EAAE,KAAK;AAAA,EACnE,SAAS,KAAK,OAAO,MAAM,EAAE,SAAS;AAAA,EACtC,SAAS;AACX,CAAC;AAED,IAAM,cAAc,KAAK,QAAe,EAAE,KAAK;AAAA,EAC7C,SAAS,KAAK,OAAO,MAAM,EAAE,SAAS;AAAA,EACtC,SAAS;AACX,CAAC;AAED,IAAM,6BAA6B,KAAK,QAA8B,EAAE,KAAK;AAAA,EAC3E,OAAO;AAAA,EACP,SAAS,KAAK,OAAO,MAAM,EAAE,SAAS;AACxC,CAAC;AAED,IAAM,mBAAmB,KAAK,QAAoB,EAAE,KAAK;AAAA,EACvD,SAAS,KAAK,OAAO,MAAM,EAAE,SAAS;AAAA,EACtC,YAAY;AAAA,EACZ,SAAS;AACX,CAAC;AAED,IAAM,qBAAqB,KAAK,QAAsB,EAAE,KAAK;AAAA,EAC3D,SAAS,KAAK,EAAE,YAAY,oBAAoB,CAAC;AA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AAK,QAAQ;AACjC,UAAM,WAAW,OAAO,IAAI,CAAC,MAA2B,EAAE,OAAO,EAAE,KAAK,IAAI;AAC5E,UAAM,IAAI,MAAM,4BAA4B,QAAQ,EAAE;AAAA,EACxD;AACA,SAAO;AACT;AAkBO,SAAS,oBAAuD,OAAmB;AAExF,QAAM,WAAW;AACjB,MAAI,SAAS,iBAAiB,UAAa,SAAS,iBAAiB,OAAO;AAC1E,UAAM,IAAI,MAAM,8BAA8B,SAAS,YAAY,EAAE;AAAA,EACvE;AAEA,QAAM,iBAAiB,kBAAkB,KAAK;AAE9C,MAAI,0BAA0B,KAAK,QAAQ;AACzC,UAAM,WAAW,eAAe,IAAI,CAAC,MAA2B,EAAE,OAAO,EAAE,KAAK,IAAI;AACpF,UAAM,IAAI,MAAM,0CAA0C,QAAQ,EAAE;AAAA,EACtE;AAKA,SAAO;AACT;","names":[]}
|
package/dist/types.d.ts
CHANGED
|
@@ -3,6 +3,17 @@ export type StorageColumn = {
|
|
|
3
3
|
readonly nativeType: string;
|
|
4
4
|
readonly codecId: string;
|
|
5
5
|
readonly nullable: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Opaque, codec-owned JS/type parameters.
|
|
8
|
+
* The codec that owns `codecId` defines the shape and semantics.
|
|
9
|
+
* Mutually exclusive with `typeRef`.
|
|
10
|
+
*/
|
|
11
|
+
readonly typeParams?: Record<string, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Reference to a named type instance in `storage.types`.
|
|
14
|
+
* Mutually exclusive with `typeParams`.
|
|
15
|
+
*/
|
|
16
|
+
readonly typeRef?: string;
|
|
6
17
|
};
|
|
7
18
|
export type PrimaryKey = {
|
|
8
19
|
readonly columns: readonly string[];
|
|
@@ -32,8 +43,23 @@ export type StorageTable = {
|
|
|
32
43
|
readonly indexes: ReadonlyArray<Index>;
|
|
33
44
|
readonly foreignKeys: ReadonlyArray<ForeignKey>;
|
|
34
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* A named, parameterized type instance.
|
|
48
|
+
* These are registered in `storage.types` for reuse across columns
|
|
49
|
+
* and to enable ergonomic schema surfaces like `schema.types.MyType`.
|
|
50
|
+
*/
|
|
51
|
+
export type StorageTypeInstance = {
|
|
52
|
+
readonly codecId: string;
|
|
53
|
+
readonly nativeType: string;
|
|
54
|
+
readonly typeParams: Record<string, unknown>;
|
|
55
|
+
};
|
|
35
56
|
export type SqlStorage = {
|
|
36
57
|
readonly tables: Record<string, StorageTable>;
|
|
58
|
+
/**
|
|
59
|
+
* Named type instances for parameterized/custom types.
|
|
60
|
+
* Columns can reference these via `typeRef`.
|
|
61
|
+
*/
|
|
62
|
+
readonly types?: Record<string, StorageTypeInstance>;
|
|
37
63
|
};
|
|
38
64
|
export type ModelField = {
|
|
39
65
|
readonly column: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9C;;;OAGG;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UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAClE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAClE,CAAC;AAEF,MAAM,MAAM,WAAW,CACrB,CAAC,SAAS,UAAU,GAAG,UAAU,EACjC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,GAAG,SAAS,WAAW,GAAG,WAAW,IACnC,YAAY,GAAG;IACjB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACnB,QAAQ,CAAC,SAAS,EAAE,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"}
|
package/dist/validators.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,eAAe,EAIf,WAAW,EACX,UAAU,
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,eAAe,EAIf,WAAW,EACX,UAAU,EAKX,MAAM,SAAS,CAAC;AAmFjB;;;;;;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,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-contract",
|
|
3
|
-
"version": "0.3.0-pr.
|
|
3
|
+
"version": "0.3.0-pr.96.1",
|
|
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.3.0-pr.
|
|
9
|
+
"@prisma-next/contract": "0.3.0-pr.96.1"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"tsup": "8.5.1",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "tsup && tsc",
|
|
41
|
+
"build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
|
|
42
42
|
"test": "vitest run",
|
|
43
43
|
"test:coverage": "vitest run --coverage",
|
|
44
|
-
"typecheck": "tsc --noEmit",
|
|
44
|
+
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
45
45
|
"lint": "biome check . --error-on-warnings",
|
|
46
46
|
"lint:fix": "biome check --write .",
|
|
47
47
|
"lint:fix:unsafe": "biome check --write --unsafe .",
|
package/src/exports/types.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -4,6 +4,17 @@ export type StorageColumn = {
|
|
|
4
4
|
readonly nativeType: string;
|
|
5
5
|
readonly codecId: string;
|
|
6
6
|
readonly nullable: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Opaque, codec-owned JS/type parameters.
|
|
9
|
+
* The codec that owns `codecId` defines the shape and semantics.
|
|
10
|
+
* Mutually exclusive with `typeRef`.
|
|
11
|
+
*/
|
|
12
|
+
readonly typeParams?: Record<string, unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Reference to a named type instance in `storage.types`.
|
|
15
|
+
* Mutually exclusive with `typeParams`.
|
|
16
|
+
*/
|
|
17
|
+
readonly typeRef?: string;
|
|
7
18
|
};
|
|
8
19
|
|
|
9
20
|
export type PrimaryKey = {
|
|
@@ -40,8 +51,24 @@ export type StorageTable = {
|
|
|
40
51
|
readonly foreignKeys: ReadonlyArray<ForeignKey>;
|
|
41
52
|
};
|
|
42
53
|
|
|
54
|
+
/**
|
|
55
|
+
* A named, parameterized type instance.
|
|
56
|
+
* These are registered in `storage.types` for reuse across columns
|
|
57
|
+
* and to enable ergonomic schema surfaces like `schema.types.MyType`.
|
|
58
|
+
*/
|
|
59
|
+
export type StorageTypeInstance = {
|
|
60
|
+
readonly codecId: string;
|
|
61
|
+
readonly nativeType: string;
|
|
62
|
+
readonly typeParams: Record<string, unknown>;
|
|
63
|
+
};
|
|
64
|
+
|
|
43
65
|
export type SqlStorage = {
|
|
44
66
|
readonly tables: Record<string, StorageTable>;
|
|
67
|
+
/**
|
|
68
|
+
* Named type instances for parameterized/custom types.
|
|
69
|
+
* Columns can reference these via `typeRef`.
|
|
70
|
+
*/
|
|
71
|
+
readonly types?: Record<string, StorageTypeInstance>;
|
|
45
72
|
};
|
|
46
73
|
|
|
47
74
|
export type ModelField = {
|
package/src/validators.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
SqlStorage,
|
|
12
12
|
StorageColumn,
|
|
13
13
|
StorageTable,
|
|
14
|
+
StorageTypeInstance,
|
|
14
15
|
UniqueConstraint,
|
|
15
16
|
} from './types';
|
|
16
17
|
|
|
@@ -18,6 +19,14 @@ const StorageColumnSchema = type.declare<StorageColumn>().type({
|
|
|
18
19
|
nativeType: 'string',
|
|
19
20
|
codecId: 'string',
|
|
20
21
|
nullable: 'boolean',
|
|
22
|
+
'typeParams?': 'Record<string, unknown>',
|
|
23
|
+
'typeRef?': 'string',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const StorageTypeInstanceSchema = type.declare<StorageTypeInstance>().type({
|
|
27
|
+
codecId: 'string',
|
|
28
|
+
nativeType: 'string',
|
|
29
|
+
typeParams: 'Record<string, unknown>',
|
|
21
30
|
});
|
|
22
31
|
|
|
23
32
|
const PrimaryKeySchema = type.declare<PrimaryKey>().type({
|
|
@@ -56,6 +65,7 @@ const StorageTableSchema = type.declare<StorageTable>().type({
|
|
|
56
65
|
|
|
57
66
|
const StorageSchema = type.declare<SqlStorage>().type({
|
|
58
67
|
tables: type({ '[string]': StorageTableSchema }),
|
|
68
|
+
'types?': type({ '[string]': StorageTypeInstanceSchema }),
|
|
59
69
|
});
|
|
60
70
|
|
|
61
71
|
const ModelFieldSchema = type.declare<ModelField>().type({
|