cogsbox-shape 0.5.64 → 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 +8 -9
- 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,19 +486,18 @@ 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
|
-
// --- THE FIX IS HERE ---
|
|
490
489
|
// 1. Create the BASE schema WITHOUT .optional()
|
|
491
490
|
let rawClientSchema;
|
|
492
491
|
let rawValidationSchema;
|
|
493
492
|
if (relationConfig.type === "hasMany" ||
|
|
494
493
|
relationConfig.type === "manyToMany") {
|
|
495
|
-
rawClientSchema = z.array(childSchemaResult.clientSchema);
|
|
496
|
-
rawValidationSchema = z.array(childSchemaResult.validationSchema);
|
|
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
|
-
rawClientSchema = childSchemaResult.clientSchema;
|
|
501
|
-
rawValidationSchema = childSchemaResult.validationSchema;
|
|
499
|
+
rawClientSchema = childSchemaResult.clientSchema;
|
|
500
|
+
rawValidationSchema = childSchemaResult.validationSchema;
|
|
502
501
|
defaultValues[key] = childSchemaResult.defaultValues;
|
|
503
502
|
}
|
|
504
503
|
// 2. Apply the transform to the RAW schema
|
|
@@ -508,10 +507,10 @@ export function createSchema(schema) {
|
|
|
508
507
|
const transformedValidationSchema = config.validationTransform
|
|
509
508
|
? config.validationTransform(rawValidationSchema)
|
|
510
509
|
: transformedClientSchema;
|
|
511
|
-
// 3.
|
|
512
|
-
sqlFields[key] = z.array(childSchemaResult.sqlSchema).optional();
|
|
513
|
-
clientFields[key] = transformedClientSchema.optional()
|
|
514
|
-
validationFields[key] = transformedValidationSchema.optional()
|
|
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()
|
|
515
514
|
}
|
|
516
515
|
else {
|
|
517
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",
|