cogsbox-shape 0.5.6 → 0.5.8

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,11 +1216,12 @@ type BaseSchemaField<T extends SQLType = SQLType> = {
1216
1216
  toClient?: (dbValue: any) => any;
1217
1217
  toDb?: (clientValue: any) => any;
1218
1218
  };
1219
- type ReferenceField = {
1219
+ type AnyFieldDefinition = ReturnType<typeof shape.sql>;
1220
+ type ReferenceField<TField extends AnyFieldDefinition, TTo extends SchemaField> = TField & {
1220
1221
  type: "reference";
1221
- to: () => BaseSchemaField;
1222
+ to: () => TTo;
1222
1223
  };
1223
- type SchemaField<T extends SQLType = SQLType> = BaseSchemaField<T> | ReferenceField;
1224
+ type SchemaField<T extends SQLType = SQLType> = BaseSchemaField<T> | ReferenceField<AnyFieldDefinition, any>;
1224
1225
  export type Schema<T extends Record<string, SchemaField | (() => Relation<any>)>> = {
1225
1226
  _tableName: string;
1226
1227
  __schemaId?: string;
@@ -1408,10 +1409,13 @@ type InferSerializedSchema<T> = {
1408
1409
  };
1409
1410
  } : never;
1410
1411
  };
1411
- export declare function reference<T = any>(config: {
1412
- to: () => T;
1413
- field: BaseSchemaField;
1414
- }): ReferenceField;
1412
+ export declare function reference<TTargetField extends SchemaField, TField extends object>(config: {
1413
+ to: () => TTargetField;
1414
+ field: TField;
1415
+ }): TField & {
1416
+ type: "reference";
1417
+ to: () => TTargetField;
1418
+ };
1415
1419
  export declare function createSchema<T extends Schema<any>>(schema: T): {
1416
1420
  dbSchema: z.ZodObject<Prettify<InferDBSchema<T>>>;
1417
1421
  clientSchema: z.ZodObject<Prettify<OmitNever<InferSchema<T>>>>;
package/dist/schema.js CHANGED
@@ -305,17 +305,11 @@ function inferDefaultFromZod(zodType, sqlConfig) {
305
305
  }
306
306
  return undefined;
307
307
  }
308
- // Update reference function
309
308
  export function reference(config) {
310
309
  return {
310
+ ...config.field,
311
311
  type: "reference",
312
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,
319
313
  };
320
314
  }
321
315
  function createSerializableSchema(schema) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.6",
3
+ "version": "0.5.8",
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",