@prisma-next/sql-contract 0.3.0-dev.13 → 0.3.0-dev.131
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/LICENSE +201 -0
- package/README.md +84 -10
- package/dist/factories.d.mts +48 -0
- package/dist/factories.d.mts.map +1 -0
- package/dist/factories.mjs +84 -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-CB821Pqa.d.mts +197 -0
- package/dist/types-CB821Pqa.d.mts.map +1 -0
- package/dist/types-DRR5stkj.mjs +13 -0
- package/dist/types-DRR5stkj.mjs.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +3 -0
- package/dist/validate.d.mts +11 -0
- package/dist/validate.d.mts.map +1 -0
- package/dist/validate.mjs +437 -0
- package/dist/validate.mjs.map +1 -0
- package/dist/validators-CNxeypbZ.mjs +234 -0
- package/dist/validators-CNxeypbZ.mjs.map +1 -0
- package/dist/validators.d.mts +71 -0
- package/dist/validators.d.mts.map +1 -0
- package/dist/validators.mjs +3 -0
- package/package.json +20 -24
- package/src/construct.ts +181 -0
- package/src/exports/types.ts +21 -0
- package/src/exports/validate.ts +6 -0
- package/src/exports/validators.ts +1 -1
- package/src/factories.ts +41 -8
- package/src/index.ts +1 -0
- package/src/types.ts +176 -9
- package/src/validate.ts +560 -0
- package/src/validators.ts +184 -18
- 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 -96
- 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 -68
- package/dist/types.d.ts.map +0 -1
- package/dist/validators.d.ts +0 -35
- package/dist/validators.d.ts.map +0 -1
package/src/validators.ts
CHANGED
|
@@ -2,22 +2,84 @@ import { type } from 'arktype';
|
|
|
2
2
|
import type {
|
|
3
3
|
ForeignKey,
|
|
4
4
|
ForeignKeyReferences,
|
|
5
|
-
Index,
|
|
6
5
|
ModelDefinition,
|
|
7
|
-
ModelField,
|
|
8
|
-
ModelStorage,
|
|
9
6
|
PrimaryKey,
|
|
7
|
+
ReferentialAction,
|
|
10
8
|
SqlContract,
|
|
11
9
|
SqlStorage,
|
|
12
|
-
|
|
13
|
-
StorageTable,
|
|
10
|
+
StorageTypeInstance,
|
|
14
11
|
UniqueConstraint,
|
|
15
12
|
} from './types';
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
type ColumnDefaultLiteral = {
|
|
15
|
+
readonly kind: 'literal';
|
|
16
|
+
readonly value: string | number | boolean | Record<string, unknown> | unknown[] | null;
|
|
17
|
+
};
|
|
18
|
+
type ColumnDefaultFunction = { readonly kind: 'function'; readonly expression: string };
|
|
19
|
+
const literalKindSchema = type("'literal'");
|
|
20
|
+
const functionKindSchema = type("'function'");
|
|
21
|
+
const generatorKindSchema = type("'generator'");
|
|
22
|
+
const generatorIdSchema = type('string').narrow((value, ctx) => {
|
|
23
|
+
return /^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(value) ? true : ctx.mustBe('a flat generator id');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const ColumnDefaultLiteralSchema = type.declare<ColumnDefaultLiteral>().type({
|
|
27
|
+
kind: literalKindSchema,
|
|
28
|
+
value: 'string | number | boolean | null | unknown[] | Record<string, unknown>',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const ColumnDefaultFunctionSchema = type.declare<ColumnDefaultFunction>().type({
|
|
32
|
+
kind: functionKindSchema,
|
|
33
|
+
expression: 'string',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);
|
|
37
|
+
|
|
38
|
+
const ExecutionMutationDefaultValueSchema = type({
|
|
39
|
+
'+': 'reject',
|
|
40
|
+
kind: generatorKindSchema,
|
|
41
|
+
id: generatorIdSchema,
|
|
42
|
+
'params?': 'Record<string, unknown>',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const ExecutionMutationDefaultSchema = type({
|
|
46
|
+
'+': 'reject',
|
|
47
|
+
ref: {
|
|
48
|
+
'+': 'reject',
|
|
49
|
+
table: 'string',
|
|
50
|
+
column: 'string',
|
|
51
|
+
},
|
|
52
|
+
'onCreate?': ExecutionMutationDefaultValueSchema,
|
|
53
|
+
'onUpdate?': ExecutionMutationDefaultValueSchema,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const ExecutionSchema = type({
|
|
57
|
+
'+': 'reject',
|
|
58
|
+
mutations: {
|
|
59
|
+
'+': 'reject',
|
|
60
|
+
defaults: ExecutionMutationDefaultSchema.array().readonly(),
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const StorageColumnSchema = type({
|
|
65
|
+
'+': 'reject',
|
|
18
66
|
nativeType: 'string',
|
|
19
67
|
codecId: 'string',
|
|
20
68
|
nullable: 'boolean',
|
|
69
|
+
'typeParams?': 'Record<string, unknown>',
|
|
70
|
+
'typeRef?': 'string',
|
|
71
|
+
'default?': ColumnDefaultSchema,
|
|
72
|
+
}).narrow((col, ctx) => {
|
|
73
|
+
if (col.typeParams !== undefined && col.typeRef !== undefined) {
|
|
74
|
+
return ctx.mustBe('a column with either typeParams or typeRef, not both');
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const StorageTypeInstanceSchema = type.declare<StorageTypeInstance>().type({
|
|
80
|
+
codecId: 'string',
|
|
81
|
+
nativeType: 'string',
|
|
82
|
+
typeParams: 'Record<string, unknown>',
|
|
21
83
|
});
|
|
22
84
|
|
|
23
85
|
const PrimaryKeySchema = type.declare<PrimaryKey>().type({
|
|
@@ -30,23 +92,34 @@ const UniqueConstraintSchema = type.declare<UniqueConstraint>().type({
|
|
|
30
92
|
'name?': 'string',
|
|
31
93
|
});
|
|
32
94
|
|
|
33
|
-
const IndexSchema = type
|
|
95
|
+
export const IndexSchema = type({
|
|
34
96
|
columns: type.string.array().readonly(),
|
|
35
97
|
'name?': 'string',
|
|
98
|
+
'using?': 'string',
|
|
99
|
+
'config?': 'Record<string, unknown>',
|
|
36
100
|
});
|
|
37
101
|
|
|
38
|
-
const ForeignKeyReferencesSchema = type.declare<ForeignKeyReferences>().type({
|
|
102
|
+
export const ForeignKeyReferencesSchema = type.declare<ForeignKeyReferences>().type({
|
|
39
103
|
table: 'string',
|
|
40
104
|
columns: type.string.array().readonly(),
|
|
41
105
|
});
|
|
42
106
|
|
|
43
|
-
const
|
|
107
|
+
export const ReferentialActionSchema = type
|
|
108
|
+
.declare<ReferentialAction>()
|
|
109
|
+
.type("'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'");
|
|
110
|
+
|
|
111
|
+
export const ForeignKeySchema = type.declare<ForeignKey>().type({
|
|
44
112
|
columns: type.string.array().readonly(),
|
|
45
113
|
references: ForeignKeyReferencesSchema,
|
|
46
114
|
'name?': 'string',
|
|
115
|
+
'onDelete?': ReferentialActionSchema,
|
|
116
|
+
'onUpdate?': ReferentialActionSchema,
|
|
117
|
+
constraint: 'boolean',
|
|
118
|
+
index: 'boolean',
|
|
47
119
|
});
|
|
48
120
|
|
|
49
|
-
const StorageTableSchema = type
|
|
121
|
+
const StorageTableSchema = type({
|
|
122
|
+
'+': 'reject',
|
|
50
123
|
columns: type({ '[string]': StorageColumnSchema }),
|
|
51
124
|
'primaryKey?': PrimaryKeySchema,
|
|
52
125
|
uniques: UniqueConstraintSchema.array().readonly(),
|
|
@@ -54,38 +127,82 @@ const StorageTableSchema = type.declare<StorageTable>().type({
|
|
|
54
127
|
foreignKeys: ForeignKeySchema.array().readonly(),
|
|
55
128
|
});
|
|
56
129
|
|
|
57
|
-
const StorageSchema = type
|
|
130
|
+
const StorageSchema = type({
|
|
131
|
+
'+': 'reject',
|
|
58
132
|
tables: type({ '[string]': StorageTableSchema }),
|
|
133
|
+
'types?': type({ '[string]': StorageTypeInstanceSchema }),
|
|
59
134
|
});
|
|
60
135
|
|
|
61
|
-
const ModelFieldSchema = type
|
|
136
|
+
const ModelFieldSchema = type({
|
|
137
|
+
'column?': 'string',
|
|
138
|
+
'nullable?': 'boolean',
|
|
139
|
+
'codecId?': 'string',
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const ModelStorageFieldSchema = type({
|
|
62
143
|
column: 'string',
|
|
144
|
+
'codecId?': 'string',
|
|
145
|
+
'nullable?': 'boolean',
|
|
63
146
|
});
|
|
64
147
|
|
|
65
|
-
const ModelStorageSchema = type
|
|
148
|
+
const ModelStorageSchema = type({
|
|
66
149
|
table: 'string',
|
|
150
|
+
'fields?': type({ '[string]': ModelStorageFieldSchema }),
|
|
67
151
|
});
|
|
68
152
|
|
|
69
|
-
const ModelSchema = type
|
|
153
|
+
const ModelSchema = type({
|
|
70
154
|
storage: ModelStorageSchema,
|
|
71
155
|
fields: type({ '[string]': ModelFieldSchema }),
|
|
72
156
|
relations: type({ '[string]': 'unknown' }),
|
|
157
|
+
'discriminator?': 'unknown',
|
|
158
|
+
'variants?': 'unknown',
|
|
159
|
+
'base?': 'string',
|
|
160
|
+
'owner?': 'string',
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const MappingsSchema = type({
|
|
164
|
+
'+': 'reject',
|
|
165
|
+
'modelToTable?': 'null | Record<string, string>',
|
|
166
|
+
'tableToModel?': 'null | Record<string, string>',
|
|
167
|
+
'fieldToColumn?': 'null | Record<string, Record<string, string>>',
|
|
168
|
+
'columnToField?': 'null | Record<string, Record<string, string>>',
|
|
169
|
+
'codecTypes?': 'null | Record<string, unknown>',
|
|
170
|
+
'operationTypes?': 'null | Record<string, Record<string, unknown>>',
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const ContractMetaSchema = type({
|
|
174
|
+
'[string]': 'unknown',
|
|
73
175
|
});
|
|
74
176
|
|
|
75
177
|
const SqlContractSchema = type({
|
|
178
|
+
'+': 'reject',
|
|
76
179
|
'schemaVersion?': "'1'",
|
|
77
180
|
target: 'string',
|
|
78
181
|
targetFamily: "'sql'",
|
|
79
|
-
coreHash: 'string',
|
|
182
|
+
'coreHash?': 'string',
|
|
183
|
+
storageHash: 'string',
|
|
184
|
+
'executionHash?': 'string',
|
|
80
185
|
'profileHash?': 'string',
|
|
186
|
+
'_generated?': 'Record<string, unknown>',
|
|
81
187
|
'capabilities?': 'Record<string, Record<string, boolean>>',
|
|
82
188
|
'extensionPacks?': 'Record<string, unknown>',
|
|
83
|
-
'meta?':
|
|
189
|
+
'meta?': ContractMetaSchema,
|
|
84
190
|
'sources?': 'Record<string, unknown>',
|
|
191
|
+
'relations?': type({ '[string]': 'unknown' }),
|
|
192
|
+
'roots?': 'Record<string, string>',
|
|
193
|
+
'mappings?': MappingsSchema,
|
|
85
194
|
models: type({ '[string]': ModelSchema }),
|
|
86
195
|
storage: StorageSchema,
|
|
196
|
+
'execution?': ExecutionSchema,
|
|
87
197
|
});
|
|
88
198
|
|
|
199
|
+
// NOTE: StorageColumnSchema, StorageTableSchema, and StorageSchema use bare type()
|
|
200
|
+
// instead of type.declare<T>().type() because the ColumnDefault union's value field
|
|
201
|
+
// includes bigint | Date (runtime-only types after decoding) which cannot be expressed
|
|
202
|
+
// in Arktype's JSON validation DSL. The `as SqlStorage` cast in validateStorage() bridges
|
|
203
|
+
// the gap between the JSON-safe Arktype output and the runtime TypeScript type.
|
|
204
|
+
// See decodeContractDefaults() in validate.ts for the decoding step.
|
|
205
|
+
|
|
89
206
|
/**
|
|
90
207
|
* Validates the structural shape of SqlStorage using Arktype.
|
|
91
208
|
*
|
|
@@ -99,7 +216,7 @@ export function validateStorage(value: unknown): SqlStorage {
|
|
|
99
216
|
const messages = result.map((p: { message: string }) => p.message).join('; ');
|
|
100
217
|
throw new Error(`Storage validation failed: ${messages}`);
|
|
101
218
|
}
|
|
102
|
-
return result;
|
|
219
|
+
return result as SqlStorage;
|
|
103
220
|
}
|
|
104
221
|
|
|
105
222
|
/**
|
|
@@ -115,7 +232,7 @@ export function validateModel(value: unknown): ModelDefinition {
|
|
|
115
232
|
const messages = result.map((p: { message: string }) => p.message).join('; ');
|
|
116
233
|
throw new Error(`Model validation failed: ${messages}`);
|
|
117
234
|
}
|
|
118
|
-
return result;
|
|
235
|
+
return result as ModelDefinition;
|
|
119
236
|
}
|
|
120
237
|
|
|
121
238
|
/**
|
|
@@ -135,6 +252,10 @@ export function validateModel(value: unknown): ModelDefinition {
|
|
|
135
252
|
* @throws Error if the contract structure is invalid
|
|
136
253
|
*/
|
|
137
254
|
export function validateSqlContract<T extends SqlContract<SqlStorage>>(value: unknown): T {
|
|
255
|
+
if (typeof value !== 'object' || value === null) {
|
|
256
|
+
throw new Error('Contract structural validation failed: value must be an object');
|
|
257
|
+
}
|
|
258
|
+
|
|
138
259
|
// Check targetFamily first to provide a clear error message for unsupported target families
|
|
139
260
|
const rawValue = value as { targetFamily?: string };
|
|
140
261
|
if (rawValue.targetFamily !== undefined && rawValue.targetFamily !== 'sql') {
|
|
@@ -153,3 +274,48 @@ export function validateSqlContract<T extends SqlContract<SqlStorage>>(value: un
|
|
|
153
274
|
// between Arktype's inferred type and the generic T, but runtime-wise they're compatible
|
|
154
275
|
return contractResult as T;
|
|
155
276
|
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Validates semantic constraints on SqlStorage that cannot be expressed in Arktype schemas.
|
|
280
|
+
*
|
|
281
|
+
* Returns an array of human-readable error strings. Empty array = valid.
|
|
282
|
+
*
|
|
283
|
+
* Currently checks:
|
|
284
|
+
* - `setNull` referential action on a non-nullable FK column (would fail at runtime)
|
|
285
|
+
* - `setDefault` referential action on a non-nullable FK column without a DEFAULT (would fail at runtime)
|
|
286
|
+
*/
|
|
287
|
+
export function validateStorageSemantics(storage: SqlStorage): string[] {
|
|
288
|
+
const errors: string[] = [];
|
|
289
|
+
|
|
290
|
+
for (const [tableName, table] of Object.entries(storage.tables)) {
|
|
291
|
+
for (const fk of table.foreignKeys) {
|
|
292
|
+
for (const colName of fk.columns) {
|
|
293
|
+
const column = table.columns[colName];
|
|
294
|
+
if (!column) continue;
|
|
295
|
+
|
|
296
|
+
if (fk.onDelete === 'setNull' && !column.nullable) {
|
|
297
|
+
errors.push(
|
|
298
|
+
`Table "${tableName}": onDelete setNull on foreign key column "${colName}" which is NOT NULL`,
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
if (fk.onUpdate === 'setNull' && !column.nullable) {
|
|
302
|
+
errors.push(
|
|
303
|
+
`Table "${tableName}": onUpdate setNull on foreign key column "${colName}" which is NOT NULL`,
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
if (fk.onDelete === 'setDefault' && !column.nullable && column.default === undefined) {
|
|
307
|
+
errors.push(
|
|
308
|
+
`Table "${tableName}": onDelete setDefault on foreign key column "${colName}" which is NOT NULL and has no DEFAULT`,
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
if (fk.onUpdate === 'setDefault' && !column.nullable && column.default === undefined) {
|
|
312
|
+
errors.push(
|
|
313
|
+
`Table "${tableName}": onUpdate setDefault on foreign key column "${colName}" which is NOT NULL and has no DEFAULT`,
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return errors;
|
|
321
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
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,83 +0,0 @@
|
|
|
1
|
-
// src/factories.ts
|
|
2
|
-
function col(nativeType, codecId, nullable = false) {
|
|
3
|
-
return {
|
|
4
|
-
nativeType,
|
|
5
|
-
codecId,
|
|
6
|
-
nullable
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
function pk(...columns) {
|
|
10
|
-
return {
|
|
11
|
-
columns
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
function unique(...columns) {
|
|
15
|
-
return {
|
|
16
|
-
columns
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function index(...columns) {
|
|
20
|
-
return {
|
|
21
|
-
columns
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function fk(columns, refTable, refColumns, name) {
|
|
25
|
-
const references = {
|
|
26
|
-
table: refTable,
|
|
27
|
-
columns: refColumns
|
|
28
|
-
};
|
|
29
|
-
return {
|
|
30
|
-
columns,
|
|
31
|
-
references,
|
|
32
|
-
...name !== void 0 && { name }
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function table(columns, opts) {
|
|
36
|
-
return {
|
|
37
|
-
columns,
|
|
38
|
-
...opts?.pk !== void 0 && { primaryKey: opts.pk },
|
|
39
|
-
uniques: opts?.uniques ?? [],
|
|
40
|
-
indexes: opts?.indexes ?? [],
|
|
41
|
-
foreignKeys: opts?.fks ?? []
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function model(table2, fields, relations = {}) {
|
|
45
|
-
const storage2 = { table: table2 };
|
|
46
|
-
return {
|
|
47
|
-
storage: storage2,
|
|
48
|
-
fields,
|
|
49
|
-
relations
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function storage(tables) {
|
|
53
|
-
return { tables };
|
|
54
|
-
}
|
|
55
|
-
function contract(opts) {
|
|
56
|
-
return {
|
|
57
|
-
schemaVersion: opts.schemaVersion ?? "1",
|
|
58
|
-
target: opts.target,
|
|
59
|
-
targetFamily: opts.targetFamily ?? "sql",
|
|
60
|
-
coreHash: opts.coreHash,
|
|
61
|
-
storage: opts.storage,
|
|
62
|
-
models: opts.models ?? {},
|
|
63
|
-
relations: opts.relations ?? {},
|
|
64
|
-
mappings: opts.mappings ?? {},
|
|
65
|
-
...opts.profileHash !== void 0 && { profileHash: opts.profileHash },
|
|
66
|
-
...opts.capabilities !== void 0 && { capabilities: opts.capabilities },
|
|
67
|
-
...opts.extensionPacks !== void 0 && { extensionPacks: opts.extensionPacks },
|
|
68
|
-
...opts.meta !== void 0 && { meta: opts.meta },
|
|
69
|
-
...opts.sources !== void 0 && { sources: opts.sources }
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
export {
|
|
73
|
-
col,
|
|
74
|
-
contract,
|
|
75
|
-
fk,
|
|
76
|
-
index,
|
|
77
|
-
model,
|
|
78
|
-
pk,
|
|
79
|
-
storage,
|
|
80
|
-
table,
|
|
81
|
-
unique
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=factories.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/factories.ts"],"sourcesContent":["import type {\n ForeignKey,\n ForeignKeyReferences,\n Index,\n ModelDefinition,\n ModelField,\n ModelStorage,\n PrimaryKey,\n SqlContract,\n SqlMappings,\n SqlStorage,\n StorageColumn,\n StorageTable,\n UniqueConstraint,\n} from './types';\n\n/**\n * Creates a StorageColumn with nativeType and codecId.\n *\n * @param nativeType - Native database type identifier (e.g., 'int4', 'text', 'vector')\n * @param codecId - Codec identifier (e.g., 'pg/int4@1', 'pg/text@1')\n * @param nullable - Whether the column is nullable (default: false)\n * @returns StorageColumn with nativeType and codecId\n */\nexport function col(nativeType: string, codecId: string, nullable = false): StorageColumn {\n return {\n nativeType,\n codecId,\n nullable,\n };\n}\n\nexport function pk(...columns: readonly string[]): PrimaryKey {\n return {\n columns,\n };\n}\n\nexport function unique(...columns: readonly string[]): UniqueConstraint {\n return {\n columns,\n };\n}\n\nexport function index(...columns: readonly string[]): Index {\n return {\n columns,\n };\n}\n\nexport function fk(\n columns: readonly string[],\n refTable: string,\n refColumns: readonly string[],\n name?: string,\n): ForeignKey {\n const references: ForeignKeyReferences = {\n table: refTable,\n columns: refColumns,\n };\n return {\n columns,\n references,\n ...(name !== undefined && { name }),\n };\n}\n\nexport function table(\n columns: Record<string, StorageColumn>,\n opts?: {\n pk?: PrimaryKey;\n uniques?: readonly UniqueConstraint[];\n indexes?: readonly Index[];\n fks?: readonly ForeignKey[];\n },\n): StorageTable {\n return {\n columns,\n ...(opts?.pk !== undefined && { primaryKey: opts.pk }),\n uniques: opts?.uniques ?? [],\n indexes: opts?.indexes ?? [],\n foreignKeys: opts?.fks ?? [],\n };\n}\n\nexport function model(\n table: string,\n fields: Record<string, ModelField>,\n relations: Record<string, unknown> = {},\n): ModelDefinition {\n const storage: ModelStorage = { table };\n return {\n storage,\n fields,\n relations,\n };\n}\n\nexport function storage(tables: Record<string, StorageTable>): SqlStorage {\n return { tables };\n}\n\nexport function contract(opts: {\n target: string;\n coreHash: string;\n storage: SqlStorage;\n models?: Record<string, ModelDefinition>;\n relations?: Record<string, unknown>;\n mappings?: Partial<SqlMappings>;\n schemaVersion?: '1';\n targetFamily?: 'sql';\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}): SqlContract {\n return {\n schemaVersion: opts.schemaVersion ?? '1',\n target: opts.target,\n targetFamily: opts.targetFamily ?? 'sql',\n coreHash: opts.coreHash,\n storage: opts.storage,\n models: opts.models ?? {},\n relations: opts.relations ?? {},\n mappings: (opts.mappings ?? {}) as SqlMappings,\n ...(opts.profileHash !== undefined && { profileHash: opts.profileHash }),\n ...(opts.capabilities !== undefined && { capabilities: opts.capabilities }),\n ...(opts.extensionPacks !== undefined && { extensionPacks: opts.extensionPacks }),\n ...(opts.meta !== undefined && { meta: opts.meta }),\n ...(opts.sources !== undefined && { sources: opts.sources as Record<string, unknown> }),\n } as SqlContract;\n}\n"],"mappings":";AAwBO,SAAS,IAAI,YAAoB,SAAiB,WAAW,OAAsB;AACxF,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,MAAM,SAAwC;AAC5D,SAAO;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,UAAU,SAA8C;AACtE,SAAO;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,SAAS,SAAmC;AAC1D,SAAO;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,GACd,SACA,UACA,YACA,MACY;AACZ,QAAM,aAAmC;AAAA,IACvC,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,GAAI,SAAS,UAAa,EAAE,KAAK;AAAA,EACnC;AACF;AAEO,SAAS,MACd,SACA,MAMc;AACd,SAAO;AAAA,IACL;AAAA,IACA,GAAI,MAAM,OAAO,UAAa,EAAE,YAAY,KAAK,GAAG;AAAA,IACpD,SAAS,MAAM,WAAW,CAAC;AAAA,IAC3B,SAAS,MAAM,WAAW,CAAC;AAAA,IAC3B,aAAa,MAAM,OAAO,CAAC;AAAA,EAC7B;AACF;AAEO,SAAS,MACdA,QACA,QACA,YAAqC,CAAC,GACrB;AACjB,QAAMC,WAAwB,EAAE,OAAAD,OAAM;AACtC,SAAO;AAAA,IACL,SAAAC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,QAAQ,QAAkD;AACxE,SAAO,EAAE,OAAO;AAClB;AAEO,SAAS,SAAS,MAcT;AACd,SAAO;AAAA,IACL,eAAe,KAAK,iBAAiB;AAAA,IACrC,QAAQ,KAAK;AAAA,IACb,cAAc,KAAK,gBAAgB;AAAA,IACnC,UAAU,KAAK;AAAA,IACf,SAAS,KAAK;AAAA,IACd,QAAQ,KAAK,UAAU,CAAC;AAAA,IACxB,WAAW,KAAK,aAAa,CAAC;AAAA,IAC9B,UAAW,KAAK,YAAY,CAAC;AAAA,IAC7B,GAAI,KAAK,gBAAgB,UAAa,EAAE,aAAa,KAAK,YAAY;AAAA,IACtE,GAAI,KAAK,iBAAiB,UAAa,EAAE,cAAc,KAAK,aAAa;AAAA,IACzE,GAAI,KAAK,mBAAmB,UAAa,EAAE,gBAAgB,KAAK,eAAe;AAAA,IAC/E,GAAI,KAAK,SAAS,UAAa,EAAE,MAAM,KAAK,KAAK;AAAA,IACjD,GAAI,KAAK,YAAY,UAAa,EAAE,SAAS,KAAK,QAAmC;AAAA,EACvF;AACF;","names":["table","storage"]}
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=pack-types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/exports/types.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/exports/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// src/validators.ts
|
|
2
|
-
import { type } from "arktype";
|
|
3
|
-
var StorageColumnSchema = type.declare().type({
|
|
4
|
-
nativeType: "string",
|
|
5
|
-
codecId: "string",
|
|
6
|
-
nullable: "boolean"
|
|
7
|
-
});
|
|
8
|
-
var PrimaryKeySchema = type.declare().type({
|
|
9
|
-
columns: type.string.array().readonly(),
|
|
10
|
-
"name?": "string"
|
|
11
|
-
});
|
|
12
|
-
var UniqueConstraintSchema = type.declare().type({
|
|
13
|
-
columns: type.string.array().readonly(),
|
|
14
|
-
"name?": "string"
|
|
15
|
-
});
|
|
16
|
-
var IndexSchema = type.declare().type({
|
|
17
|
-
columns: type.string.array().readonly(),
|
|
18
|
-
"name?": "string"
|
|
19
|
-
});
|
|
20
|
-
var ForeignKeyReferencesSchema = type.declare().type({
|
|
21
|
-
table: "string",
|
|
22
|
-
columns: type.string.array().readonly()
|
|
23
|
-
});
|
|
24
|
-
var ForeignKeySchema = type.declare().type({
|
|
25
|
-
columns: type.string.array().readonly(),
|
|
26
|
-
references: ForeignKeyReferencesSchema,
|
|
27
|
-
"name?": "string"
|
|
28
|
-
});
|
|
29
|
-
var StorageTableSchema = type.declare().type({
|
|
30
|
-
columns: type({ "[string]": StorageColumnSchema }),
|
|
31
|
-
"primaryKey?": PrimaryKeySchema,
|
|
32
|
-
uniques: UniqueConstraintSchema.array().readonly(),
|
|
33
|
-
indexes: IndexSchema.array().readonly(),
|
|
34
|
-
foreignKeys: ForeignKeySchema.array().readonly()
|
|
35
|
-
});
|
|
36
|
-
var StorageSchema = type.declare().type({
|
|
37
|
-
tables: type({ "[string]": StorageTableSchema })
|
|
38
|
-
});
|
|
39
|
-
var ModelFieldSchema = type.declare().type({
|
|
40
|
-
column: "string"
|
|
41
|
-
});
|
|
42
|
-
var ModelStorageSchema = type.declare().type({
|
|
43
|
-
table: "string"
|
|
44
|
-
});
|
|
45
|
-
var ModelSchema = type.declare().type({
|
|
46
|
-
storage: ModelStorageSchema,
|
|
47
|
-
fields: type({ "[string]": ModelFieldSchema }),
|
|
48
|
-
relations: type({ "[string]": "unknown" })
|
|
49
|
-
});
|
|
50
|
-
var SqlContractSchema = type({
|
|
51
|
-
"schemaVersion?": "'1'",
|
|
52
|
-
target: "string",
|
|
53
|
-
targetFamily: "'sql'",
|
|
54
|
-
coreHash: "string",
|
|
55
|
-
"profileHash?": "string",
|
|
56
|
-
"capabilities?": "Record<string, Record<string, boolean>>",
|
|
57
|
-
"extensionPacks?": "Record<string, unknown>",
|
|
58
|
-
"meta?": "Record<string, unknown>",
|
|
59
|
-
"sources?": "Record<string, unknown>",
|
|
60
|
-
models: type({ "[string]": ModelSchema }),
|
|
61
|
-
storage: StorageSchema
|
|
62
|
-
});
|
|
63
|
-
function validateStorage(value) {
|
|
64
|
-
const result = StorageSchema(value);
|
|
65
|
-
if (result instanceof type.errors) {
|
|
66
|
-
const messages = result.map((p) => p.message).join("; ");
|
|
67
|
-
throw new Error(`Storage validation failed: ${messages}`);
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
function validateModel(value) {
|
|
72
|
-
const result = ModelSchema(value);
|
|
73
|
-
if (result instanceof type.errors) {
|
|
74
|
-
const messages = result.map((p) => p.message).join("; ");
|
|
75
|
-
throw new Error(`Model validation failed: ${messages}`);
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
function validateSqlContract(value) {
|
|
80
|
-
const rawValue = value;
|
|
81
|
-
if (rawValue.targetFamily !== void 0 && rawValue.targetFamily !== "sql") {
|
|
82
|
-
throw new Error(`Unsupported target family: ${rawValue.targetFamily}`);
|
|
83
|
-
}
|
|
84
|
-
const contractResult = SqlContractSchema(value);
|
|
85
|
-
if (contractResult instanceof type.errors) {
|
|
86
|
-
const messages = contractResult.map((p) => p.message).join("; ");
|
|
87
|
-
throw new Error(`Contract structural validation failed: ${messages}`);
|
|
88
|
-
}
|
|
89
|
-
return contractResult;
|
|
90
|
-
}
|
|
91
|
-
export {
|
|
92
|
-
validateModel,
|
|
93
|
-
validateSqlContract,
|
|
94
|
-
validateStorage
|
|
95
|
-
};
|
|
96
|
-
//# sourceMappingURL=validators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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":"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","names":[]}
|
package/dist/factories.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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
|
package/dist/factories.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../src/factories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,KAAK,EACL,eAAe,EACf,UAAU,EAEV,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,aAAa,EACb,YAAY,EACZ,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,UAAQ,GAAG,aAAa,CAMxF;AAED,wBAAgB,EAAE,CAAC,GAAG,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,CAI5D;AAED,wBAAgB,MAAM,CAAC,GAAG,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,gBAAgB,CAItE;AAED,wBAAgB,KAAK,CAAC,GAAG,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,KAAK,CAI1D;AAED,wBAAgB,EAAE,CAChB,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,IAAI,CAAC,EAAE,MAAM,GACZ,UAAU,CAUZ;AAED,wBAAgB,KAAK,CACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EACtC,IAAI,CAAC,EAAE;IACL,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,OAAO,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACtC,OAAO,CAAC,EAAE,SAAS,KAAK,EAAE,CAAC;IAC3B,GAAG,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7B,GACA,YAAY,CAQd;AAED,wBAAgB,KAAK,CACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EAClC,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACtC,eAAe,CAOjB;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,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"}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/pack-types.d.ts
DELETED
package/dist/pack-types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|