cogsbox-shape 0.5.63 → 0.5.65
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 +112 -594
- package/dist/example/user.d.ts +112 -594
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +18 -16
- package/package.json +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ type BaseRelationConfig<T extends Schema<any>> = {
|
|
|
85
85
|
schema: () => T;
|
|
86
86
|
defaultCount?: number;
|
|
87
87
|
};
|
|
88
|
-
type RelationConfig<T extends Schema<any>> = (BaseRelationConfig<T> & {
|
|
88
|
+
export type RelationConfig<T extends Schema<any>> = (BaseRelationConfig<T> & {
|
|
89
89
|
type: "hasMany";
|
|
90
90
|
}) | (BaseRelationConfig<T> & {
|
|
91
91
|
type: "hasOne";
|
package/dist/schema.js
CHANGED
|
@@ -486,29 +486,31 @@ export function createSchema(schema) {
|
|
|
486
486
|
// --- THIS IS THE KEY PART FOR RELATION BUILDERS ---
|
|
487
487
|
const relationConfig = sqlConfig;
|
|
488
488
|
const childSchemaResult = createSchema(relationConfig.schema);
|
|
489
|
-
|
|
490
|
-
let
|
|
489
|
+
// 1. Create the BASE schema WITHOUT .optional()
|
|
490
|
+
let rawClientSchema;
|
|
491
|
+
let rawValidationSchema;
|
|
491
492
|
if (relationConfig.type === "hasMany" ||
|
|
492
493
|
relationConfig.type === "manyToMany") {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
.array(childSchemaResult.validationSchema)
|
|
496
|
-
.optional();
|
|
494
|
+
rawClientSchema = z.array(childSchemaResult.clientSchema);
|
|
495
|
+
rawValidationSchema = z.array(childSchemaResult.validationSchema);
|
|
497
496
|
defaultValues[key] = Array.from({ length: relationConfig.defaultCount || 0 }, () => childSchemaResult.defaultValues);
|
|
498
497
|
}
|
|
499
498
|
else {
|
|
500
|
-
|
|
501
|
-
|
|
499
|
+
rawClientSchema = childSchemaResult.clientSchema;
|
|
500
|
+
rawValidationSchema = childSchemaResult.validationSchema;
|
|
502
501
|
defaultValues[key] = childSchemaResult.defaultValues;
|
|
503
502
|
}
|
|
504
|
-
// Apply the
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
503
|
+
// 2. Apply the transform to the RAW schema
|
|
504
|
+
const transformedClientSchema = config.clientTransform
|
|
505
|
+
? config.clientTransform(rawClientSchema)
|
|
506
|
+
: rawClientSchema;
|
|
507
|
+
const transformedValidationSchema = config.validationTransform
|
|
508
|
+
? config.validationTransform(rawValidationSchema)
|
|
509
|
+
: transformedClientSchema;
|
|
510
|
+
// 3. Assign the final schemas. NO .optional() is added.
|
|
511
|
+
sqlFields[key] = z.array(childSchemaResult.sqlSchema).optional(); // SQL is still optional, as it might not be loaded.
|
|
512
|
+
clientFields[key] = transformedClientSchema; // <-- NO .optional()
|
|
513
|
+
validationFields[key] = transformedValidationSchema; // <-- NO .optional()
|
|
512
514
|
}
|
|
513
515
|
else {
|
|
514
516
|
// It's a standard field builder (`shape.sql(...)`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.65",
|
|
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",
|