cogsbox-shape 0.5.4 → 0.5.6

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
@@ -1216,9 +1216,9 @@ type BaseSchemaField<T extends SQLType = SQLType> = {
1216
1216
  toClient?: (dbValue: any) => any;
1217
1217
  toDb?: (clientValue: any) => any;
1218
1218
  };
1219
- type ReferenceField<T extends BaseSchemaField = BaseSchemaField> = {
1219
+ type ReferenceField = {
1220
1220
  type: "reference";
1221
- to: () => T;
1221
+ to: () => BaseSchemaField;
1222
1222
  };
1223
1223
  type SchemaField<T extends SQLType = SQLType> = BaseSchemaField<T> | ReferenceField;
1224
1224
  export type Schema<T extends Record<string, SchemaField | (() => Relation<any>)>> = {
@@ -1408,9 +1408,10 @@ type InferSerializedSchema<T> = {
1408
1408
  };
1409
1409
  } : never;
1410
1410
  };
1411
- export declare function reference<T extends () => BaseSchemaField>(config: {
1412
- to: T;
1413
- }): SchemaField;
1411
+ export declare function reference<T = any>(config: {
1412
+ to: () => T;
1413
+ field: BaseSchemaField;
1414
+ }): ReferenceField;
1414
1415
  export declare function createSchema<T extends Schema<any>>(schema: T): {
1415
1416
  dbSchema: z.ZodObject<Prettify<InferDBSchema<T>>>;
1416
1417
  clientSchema: z.ZodObject<Prettify<OmitNever<InferSchema<T>>>>;
package/dist/schema.js CHANGED
@@ -305,10 +305,17 @@ function inferDefaultFromZod(zodType, sqlConfig) {
305
305
  }
306
306
  return undefined;
307
307
  }
308
+ // Update reference function
308
309
  export function reference(config) {
309
310
  return {
310
311
  type: "reference",
311
312
  to: config.to,
313
+ sql: config.field.sql,
314
+ zodDbSchema: config.field.zodDbSchema,
315
+ zodClientSchema: config.field.zodClientSchema,
316
+ defaultValue: config.field.defaultValue,
317
+ toClient: config.field.toClient,
318
+ toDb: config.field.toDb,
312
319
  };
313
320
  }
314
321
  function createSerializableSchema(schema) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
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",