cogsbox-shape 0.5.106 → 0.5.107

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.
Files changed (2) hide show
  1. package/dist/schema.js +13 -21
  2. package/package.json +1 -1
package/dist/schema.js CHANGED
@@ -478,32 +478,24 @@ export function createSchema(schema, relations) {
478
478
  if (sqlConfig &&
479
479
  typeof sqlConfig === "object" &&
480
480
  ["hasMany", "hasOne", "belongsTo", "manyToMany"].includes(sqlConfig.type)) {
481
- // Handle relations - create a lazy-evaluated schema
481
+ // Handle relations
482
482
  const relatedSchemaFactory = sqlConfig.schema;
483
- // Create a lazy getter for the child schema
484
- let cachedChildSchema = null;
485
- const getChildSchema = () => {
486
- if (!cachedChildSchema) {
487
- cachedChildSchema = createSchema(relatedSchemaFactory());
488
- }
489
- return cachedChildSchema;
490
- };
491
483
  let baseClientSchema;
492
484
  if (sqlConfig.type === "hasMany" || sqlConfig.type === "manyToMany") {
493
- // Create a custom Zod type that validates lazily
494
- baseClientSchema = z
495
- .array(z.lazy(() => getChildSchema().clientSchema))
496
- .optional();
497
- // Default values use a getter function
498
- defaultValues[key] = Array.from({ length: sqlConfig.defaultCount || 0 }, () => getChildSchema().defaultValues);
485
+ baseClientSchema = z.array(z.any()).optional();
486
+ // Make it a FUNCTION that returns the array
487
+ defaultValues[key] = () => Array.from({ length: sqlConfig.defaultCount || 0 }, () => {
488
+ const childSchema = createSchema(relatedSchemaFactory());
489
+ return childSchema.defaultValues;
490
+ });
499
491
  }
500
492
  else {
501
- // Create a custom Zod type that validates lazily
502
- baseClientSchema = z
503
- .lazy(() => getChildSchema().clientSchema)
504
- .optional();
505
- // Default value uses a getter function
506
- defaultValues[key] = () => getChildSchema().defaultValues;
493
+ baseClientSchema = z.any().optional();
494
+ // Make it a FUNCTION that returns the object
495
+ defaultValues[key] = () => {
496
+ const childSchema = createSchema(relatedSchemaFactory());
497
+ return childSchema.defaultValues;
498
+ };
507
499
  }
508
500
  clientFields[key] = config.clientTransform
509
501
  ? config.clientTransform(baseClientSchema)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.106",
3
+ "version": "0.5.107",
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",