cogsbox-shape 0.5.165 → 0.5.167

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.d.ts CHANGED
@@ -412,6 +412,7 @@ type CreateSchemaBoxReturn<S extends Record<string, SchemaWithPlaceholders>, R e
412
412
  };
413
413
  defaults: Resolved[K]["zodSchemas"]["defaultValues"];
414
414
  stateType: Resolved[K]["zodSchemas"]["stateType"];
415
+ generateDefaults: () => Resolved[K]["zodSchemas"]["defaultValues"];
415
416
  nav: NavigationProxy<K & string, Resolved>;
416
417
  RelationSelection: NavigationToSelection<NavigationProxy<K & string, Resolved>>;
417
418
  createView: <const TSelection extends NavigationToSelection<NavigationProxy<K & string, Resolved>>>(selection: TSelection) => DeriveViewResult<K & string, TSelection, Resolved>;
package/dist/schema.js CHANGED
@@ -489,10 +489,11 @@ export function createSchema(schema, relations) {
489
489
  serverFields[key] = config.zodValidationSchema;
490
490
  const initialValueOrFn = config.initialValue;
491
491
  defaultGenerators[key] = initialValueOrFn;
492
- defaultValues[key] = inferDefaultFromZod(config.zodClientSchema, {
493
- ...config.sql,
494
- default: undefined,
495
- });
492
+ // FIX: Call the function with { uuid } if it's a function
493
+ let rawDefault = isFunction(initialValueOrFn)
494
+ ? initialValueOrFn({ uuid })
495
+ : initialValueOrFn;
496
+ defaultValues[key] = rawDefault;
496
497
  if (config.transforms) {
497
498
  fieldTransforms[key] = config.transforms;
498
499
  }
@@ -519,7 +520,7 @@ export function createSchema(schema, relations) {
519
520
  defaultGenerators[key] = initialValueOrFn;
520
521
  // Get the raw default value
521
522
  let rawDefault = isFunction(initialValueOrFn)
522
- ? initialValueOrFn()
523
+ ? initialValueOrFn({ uuid })
523
524
  : initialValueOrFn;
524
525
  // Apply toClient transform if it exists
525
526
  if (config.transforms?.toClient && rawDefault !== undefined) {
@@ -558,9 +559,8 @@ export function createSchema(schema, relations) {
558
559
  for (const key in defaultGenerators) {
559
560
  const generatorOrValue = defaultGenerators[key];
560
561
  let rawValue = isFunction(generatorOrValue)
561
- ? generatorOrValue()
562
+ ? generatorOrValue({ uuid }) // Pass the tools
562
563
  : generatorOrValue;
563
- // Apply toClient transform if it exists
564
564
  if (fieldTransforms[key]?.toClient && rawValue !== undefined) {
565
565
  freshDefaults[key] = fieldTransforms[key].toClient(rawValue);
566
566
  }
@@ -591,7 +591,7 @@ export function createSchema(schema, relations) {
591
591
  return {
592
592
  pk: pkKeys.length ? pkKeys : null,
593
593
  clientPk: clientPkKeys.length ? clientPkKeys : null,
594
- isClientRecord, // NOW IT'S IN SCOPE
594
+ isClientRecord,
595
595
  sqlSchema: z.object(sqlFields),
596
596
  clientSchema: z.object(clientFields),
597
597
  validationSchema: z.object(serverFields),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.165",
3
+ "version": "0.5.167",
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",