cogsbox-shape 0.5.28 → 0.5.30

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 CHANGED
@@ -235,29 +235,29 @@ export function manyToMany(config) {
235
235
  });
236
236
  }
237
237
  function inferDefaultFromZod(zodType, sqlConfig) {
238
- if (sqlConfig?.pk) {
239
- return uuidv4();
240
- }
241
- if (zodType instanceof z.ZodOptional) {
242
- return undefined;
238
+ // Check SQL type first for better defaults
239
+ if (sqlConfig && !sqlConfig.nullable) {
240
+ switch (sqlConfig.type) {
241
+ case "varchar":
242
+ case "text":
243
+ case "char":
244
+ case "longtext":
245
+ return "";
246
+ case "int":
247
+ return 0;
248
+ case "boolean":
249
+ return false;
250
+ case "date":
251
+ case "datetime":
252
+ return new Date();
253
+ }
243
254
  }
244
- if (zodType instanceof z.ZodNullable) {
255
+ if (sqlConfig?.nullable) {
245
256
  return null;
246
257
  }
247
- if (zodType instanceof z.ZodArray) {
248
- return [];
249
- }
250
- if (zodType instanceof z.ZodObject) {
251
- return {};
252
- }
253
- if (zodType instanceof z.ZodString) {
254
- return "";
255
- }
256
- if (zodType instanceof z.ZodNumber) {
257
- return 0;
258
- }
259
- if (zodType instanceof z.ZodBoolean) {
260
- return false;
258
+ // Fall back to existing zod-based inference
259
+ if (zodType instanceof z.ZodOptional) {
260
+ return undefined;
261
261
  }
262
262
  // Check for explicit default last
263
263
  if (zodType instanceof z.ZodDefault && zodType._def?.defaultValue) {
@@ -269,9 +269,9 @@ function inferDefaultFromZod(zodType, sqlConfig) {
269
269
  }
270
270
  export function reference(config) {
271
271
  return {
272
- ...config.field,
272
+ field: config.field,
273
273
  type: "reference",
274
- to: config.to,
274
+ to: typeof config.to === "function" ? config.to : () => config.to,
275
275
  };
276
276
  }
277
277
  export function createMixedValidationSchema(schema, clientSchema, dbSchema) {
@@ -394,3 +394,6 @@ export function createSchema(schema) {
394
394
  defaultValues: defaultValues,
395
395
  };
396
396
  }
397
+ export function createSyncSchema(config) {
398
+ return config;
399
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.28",
3
+ "version": "0.5.30",
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",