cogsbox-shape 0.5.27 → 0.5.28
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/example/schema.d.ts +60 -60
- package/dist/example/user.d.ts +60 -60
- package/dist/schema.d.ts +1972 -963
- package/dist/schema.js +0 -77
- package/package.json +1 -1
package/dist/schema.js
CHANGED
|
@@ -274,83 +274,6 @@ export function reference(config) {
|
|
|
274
274
|
to: config.to,
|
|
275
275
|
};
|
|
276
276
|
}
|
|
277
|
-
function createSerializableSchema(schema) {
|
|
278
|
-
const serializableSchema = {
|
|
279
|
-
_tableName: schema._tableName,
|
|
280
|
-
__schemaId: crypto.randomUUID(),
|
|
281
|
-
_syncKey: schema._syncKey
|
|
282
|
-
? {
|
|
283
|
-
toString: schema._syncKey.toString(),
|
|
284
|
-
}
|
|
285
|
-
: undefined,
|
|
286
|
-
};
|
|
287
|
-
for (const [key, value] of Object.entries(schema)) {
|
|
288
|
-
if (key === "_tableName" || key === "__schemaId")
|
|
289
|
-
continue;
|
|
290
|
-
if (typeof value === "function") {
|
|
291
|
-
const relation = value();
|
|
292
|
-
if (!isRelation(relation)) {
|
|
293
|
-
throw new Error(`Invalid relation for key ${key}`);
|
|
294
|
-
}
|
|
295
|
-
// Call the schema function to get the actual schema
|
|
296
|
-
const childSchema = createSerializableSchema(relation.schema);
|
|
297
|
-
// Get toKey value by calling the function
|
|
298
|
-
const toKeyField = relation.toKey.type === "reference"
|
|
299
|
-
? relation.toKey.to()
|
|
300
|
-
: relation.toKey;
|
|
301
|
-
const serializedToKey = {
|
|
302
|
-
sql: toKeyField.sql,
|
|
303
|
-
jsonSchema: zodToJsonSchema(toKeyField.zodClientSchema),
|
|
304
|
-
defaultValue: toKeyField.defaultValue,
|
|
305
|
-
};
|
|
306
|
-
serializableSchema[key] = {
|
|
307
|
-
type: "relation",
|
|
308
|
-
relationType: relation.type,
|
|
309
|
-
fromKey: relation.fromKey,
|
|
310
|
-
toKey: serializedToKey,
|
|
311
|
-
schema: childSchema,
|
|
312
|
-
...(relation.type === "hasMany" && {
|
|
313
|
-
defaultCount: relation.defaultCount,
|
|
314
|
-
}),
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
// Handle regular fields or references (unchanged)
|
|
319
|
-
if (value.type === "reference") {
|
|
320
|
-
const referencedField = value.to();
|
|
321
|
-
const serializedField = {
|
|
322
|
-
sql: referencedField.sql,
|
|
323
|
-
jsonSchema: zodToJsonSchema(referencedField.zodClientSchema),
|
|
324
|
-
defaultValue: referencedField.defaultValue,
|
|
325
|
-
...(referencedField.toClient &&
|
|
326
|
-
referencedField.toDb && {
|
|
327
|
-
transforms: {
|
|
328
|
-
toClient: referencedField.toClient.toString(),
|
|
329
|
-
toDb: referencedField.toDb.toString(),
|
|
330
|
-
},
|
|
331
|
-
}),
|
|
332
|
-
};
|
|
333
|
-
serializableSchema[key] = serializedField;
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
-
const serializedField = {
|
|
337
|
-
sql: value.sql,
|
|
338
|
-
jsonSchema: zodToJsonSchema(value.zodClientSchema),
|
|
339
|
-
defaultValue: value.defaultValue,
|
|
340
|
-
...(value.toClient &&
|
|
341
|
-
value.toDb && {
|
|
342
|
-
transforms: {
|
|
343
|
-
toClient: value.toClient.toString(),
|
|
344
|
-
toDb: value.toDb.toString(),
|
|
345
|
-
},
|
|
346
|
-
}),
|
|
347
|
-
};
|
|
348
|
-
serializableSchema[key] = serializedField;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return serializableSchema;
|
|
353
|
-
}
|
|
354
277
|
export function createMixedValidationSchema(schema, clientSchema, dbSchema) {
|
|
355
278
|
// If schemas are provided, use them (to avoid circular calls)
|
|
356
279
|
if (clientSchema && dbSchema) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.28",
|
|
4
4
|
"description": "A TypeScript library for creating type-safe database schemas with Zod validation, SQL type definitions, and automatic client/server transformations. Unifies client, server, and database types through a single schema definition, with built-in support for relationships and serialization.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|