cogsbox-shape 0.5.73 → 0.5.74

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.d.ts +23 -53
  2. package/package.json +1 -1
package/dist/schema.d.ts CHANGED
@@ -322,12 +322,7 @@ export declare function schemaRelations<TSchema extends Schema<any>, RefObject e
322
322
  type Prettify<T> = {
323
323
  [K in keyof T]: T[K];
324
324
  } & {};
325
- /**
326
- * [INTERNAL] Core recursive utility to inspect the schema definition.
327
- * It iterates through the schema, finds the `config` object in each
328
- * builder, and extracts the specified Zod schema.
329
- */
330
- type InferByKey<T, Key extends "zodSqlSchema" | "zodClientSchema" | "zodValidationSchema", Depth extends any[] = []> = Depth["length"] extends 10 ? any : {
325
+ type DeriveSchemaByKey<T, Key extends "zodSqlSchema" | "zodClientSchema" | "zodValidationSchema", Depth extends any[] = []> = Depth["length"] extends 10 ? any : {
331
326
  [K in keyof T as K extends "_tableName" | typeof SchemaWrapperBrand ? never : K]: T[K] extends {
332
327
  config: {
333
328
  sql: {
@@ -337,7 +332,7 @@ type InferByKey<T, Key extends "zodSqlSchema" | "zodClientSchema" | "zodValidati
337
332
  };
338
333
  } ? z.ZodArray<S extends {
339
334
  _tableName: string;
340
- } ? z.ZodObject<Prettify<InferByKey<S, Key, [...Depth, 1]>>> : z.ZodObject<any>> : T[K] extends {
335
+ } ? z.ZodObject<Prettify<DeriveSchemaByKey<S, Key, [...Depth, 1]>>> : z.ZodObject<any>> : T[K] extends {
341
336
  config: {
342
337
  sql: {
343
338
  type: "hasOne" | "belongsTo";
@@ -346,7 +341,7 @@ type InferByKey<T, Key extends "zodSqlSchema" | "zodClientSchema" | "zodValidati
346
341
  };
347
342
  } ? S extends {
348
343
  _tableName: string;
349
- } ? z.ZodObject<Prettify<InferByKey<S, Key, [...Depth, 1]>>> : z.ZodObject<any> : T[K] extends {
344
+ } ? z.ZodObject<Prettify<DeriveSchemaByKey<S, Key, [...Depth, 1]>>> : z.ZodObject<any> : T[K] extends {
350
345
  type: "reference";
351
346
  to: () => infer RefField;
352
347
  } ? RefField extends {
@@ -359,54 +354,29 @@ type InferByKey<T, Key extends "zodSqlSchema" | "zodClientSchema" | "zodValidati
359
354
  };
360
355
  } ? ZodSchema : never;
361
356
  };
362
- /**
363
- * [INTERNAL] Core utility to infer default values directly from the schema definition.
364
- */
365
- type InferDefaults<T> = {
357
+ type DeriveDefaults<T> = Prettify<{
366
358
  [K in keyof T as K extends "_tableName" | typeof SchemaWrapperBrand ? never : K]: T[K] extends {
367
359
  config: {
368
360
  initialValue: infer D;
369
361
  };
370
362
  } ? D extends () => infer R ? R : D : never;
371
- };
372
- /**
373
- * A new, non-conflicting namespace for directly inferring types from your schema definitions.
374
- * This is more performant than using `ReturnType<typeof createSchema>`.
375
- */
376
- export declare namespace Infer {
377
- /**
378
- * Directly infers the Zod schema for the **SQL (database)** layer.
379
- */
380
- type SqlSchema<T extends {
381
- _tableName: string;
382
- }> = z.ZodObject<Prettify<InferByKey<T, "zodSqlSchema">>>;
383
- /**
384
- * Directly infers the Zod schema for the **Client** layer.
385
- */
386
- type ClientSchema<T extends {
387
- _tableName: string;
388
- }> = z.ZodObject<Prettify<InferByKey<T, "zodClientSchema">>>;
389
- /**
390
- * Directly infers the Zod schema for the **Validation** layer.
391
- */
392
- type ValidationSchema<T extends {
393
- _tableName: string;
394
- }> = z.ZodObject<Prettify<InferByKey<T, "zodValidationSchema">>>;
395
- /** The TypeScript type for data as it exists in the database. */
396
- type Sql<T extends {
397
- _tableName: string;
398
- }> = z.infer<SqlSchema<T>>;
399
- /** The TypeScript type for data as it is represented on the client. */
400
- type Client<T extends {
401
- _tableName: string;
402
- }> = z.infer<ClientSchema<T>>;
403
- /** The TypeScript type for validation data, often the most flexible shape. */
404
- type Validation<T extends {
405
- _tableName: string;
406
- }> = z.infer<ValidationSchema<T>>;
407
- /** The TypeScript type for the default values object. */
408
- type Defaults<T extends {
409
- _tableName: string;
410
- }> = Prettify<InferDefaults<T>>;
411
- }
363
+ }>;
364
+ export type InferFromSchema<T extends {
365
+ _tableName: string;
366
+ }> = Prettify<{
367
+ /** The Zod schema for the **SQL (database)** layer. */
368
+ SqlSchema: z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodSqlSchema">>>;
369
+ /** The Zod schema for the **Client** layer. */
370
+ ClientSchema: z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodClientSchema">>>;
371
+ /** The Zod schema for the **Validation** layer. */
372
+ ValidationSchema: z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodValidationSchema">>>;
373
+ /** The TypeScript type for data as it exists in the **database**. */
374
+ Sql: z.infer<z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodSqlSchema">>>>;
375
+ /** The TypeScript type for data as it is represented on the **client**. */
376
+ Client: z.infer<z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodClientSchema">>>>;
377
+ /** The TypeScript type for **validation** data, often the most flexible shape. */
378
+ Validation: z.infer<z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodValidationSchema">>>>;
379
+ /** The TypeScript type for the object of **default values**. */
380
+ Defaults: DeriveDefaults<T>;
381
+ }>;
412
382
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.73",
3
+ "version": "0.5.74",
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",