cogsbox-shape 0.5.63 → 0.5.64
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/schema.js +18 -15
- package/package.json +1 -1
package/dist/schema.js
CHANGED
|
@@ -486,29 +486,32 @@ 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
|
-
|
|
489
|
+
// --- THE FIX IS HERE ---
|
|
490
|
+
// 1. Create the BASE schema WITHOUT .optional()
|
|
491
|
+
let rawClientSchema;
|
|
492
|
+
let rawValidationSchema;
|
|
491
493
|
if (relationConfig.type === "hasMany" ||
|
|
492
494
|
relationConfig.type === "manyToMany") {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
.array(childSchemaResult.validationSchema)
|
|
496
|
-
.optional();
|
|
495
|
+
rawClientSchema = z.array(childSchemaResult.clientSchema); // No .optional()
|
|
496
|
+
rawValidationSchema = z.array(childSchemaResult.validationSchema); // No .optional()
|
|
497
497
|
defaultValues[key] = Array.from({ length: relationConfig.defaultCount || 0 }, () => childSchemaResult.defaultValues);
|
|
498
498
|
}
|
|
499
499
|
else {
|
|
500
|
-
|
|
501
|
-
|
|
500
|
+
rawClientSchema = childSchemaResult.clientSchema; // No .optional()
|
|
501
|
+
rawValidationSchema = childSchemaResult.validationSchema; // No .optional()
|
|
502
502
|
defaultValues[key] = childSchemaResult.defaultValues;
|
|
503
503
|
}
|
|
504
|
-
// Apply the
|
|
504
|
+
// 2. Apply the transform to the RAW schema
|
|
505
|
+
const transformedClientSchema = config.clientTransform
|
|
506
|
+
? config.clientTransform(rawClientSchema)
|
|
507
|
+
: rawClientSchema;
|
|
508
|
+
const transformedValidationSchema = config.validationTransform
|
|
509
|
+
? config.validationTransform(rawValidationSchema)
|
|
510
|
+
: transformedClientSchema;
|
|
511
|
+
// 3. NOW, make the final, transformed schema optional.
|
|
505
512
|
sqlFields[key] = z.array(childSchemaResult.sqlSchema).optional();
|
|
506
|
-
clientFields[key] =
|
|
507
|
-
|
|
508
|
-
: baseClientSchema;
|
|
509
|
-
validationFields[key] = config.validationTransform
|
|
510
|
-
? config.validationTransform(baseValidationSchema) // APPLY VALIDATION TRANSFORM
|
|
511
|
-
: clientFields[key]; // Fallback to the (potentially transformed) client schema
|
|
513
|
+
clientFields[key] = transformedClientSchema.optional();
|
|
514
|
+
validationFields[key] = transformedValidationSchema.optional();
|
|
512
515
|
}
|
|
513
516
|
else {
|
|
514
517
|
// 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.64",
|
|
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",
|