cogsbox-shape 0.5.72 → 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 +60 -3
  2. package/package.json +1 -1
package/dist/schema.d.ts CHANGED
@@ -223,9 +223,6 @@ type Relation<U extends Schema<any>> = {
223
223
  schema: U;
224
224
  defaultCount?: number;
225
225
  };
226
- type Prettify<T> = {
227
- [K in keyof T]: T[K];
228
- } & {};
229
226
  export declare function createMixedValidationSchema<T extends Schema<any>>(schema: T, clientSchema?: z.ZodObject<any>, dbSchema?: z.ZodObject<any>): z.ZodObject<any>;
230
227
  type SchemaDefinition = {
231
228
  _tableName: string;
@@ -322,4 +319,64 @@ export declare function schemaRelations<TSchema extends Schema<any>, RefObject e
322
319
  __parentTableType: TSchema & RefObject;
323
320
  };
324
321
  };
322
+ type Prettify<T> = {
323
+ [K in keyof T]: T[K];
324
+ } & {};
325
+ type DeriveSchemaByKey<T, Key extends "zodSqlSchema" | "zodClientSchema" | "zodValidationSchema", Depth extends any[] = []> = Depth["length"] extends 10 ? any : {
326
+ [K in keyof T as K extends "_tableName" | typeof SchemaWrapperBrand ? never : K]: T[K] extends {
327
+ config: {
328
+ sql: {
329
+ type: "hasMany" | "manyToMany";
330
+ schema: () => infer S;
331
+ };
332
+ };
333
+ } ? z.ZodArray<S extends {
334
+ _tableName: string;
335
+ } ? z.ZodObject<Prettify<DeriveSchemaByKey<S, Key, [...Depth, 1]>>> : z.ZodObject<any>> : T[K] extends {
336
+ config: {
337
+ sql: {
338
+ type: "hasOne" | "belongsTo";
339
+ schema: () => infer S;
340
+ };
341
+ };
342
+ } ? S extends {
343
+ _tableName: string;
344
+ } ? z.ZodObject<Prettify<DeriveSchemaByKey<S, Key, [...Depth, 1]>>> : z.ZodObject<any> : T[K] extends {
345
+ type: "reference";
346
+ to: () => infer RefField;
347
+ } ? RefField extends {
348
+ config: {
349
+ [P in Key]: infer ZodSchema;
350
+ };
351
+ } ? ZodSchema : never : T[K] extends {
352
+ config: {
353
+ [P in Key]: infer ZodSchema extends z.ZodTypeAny;
354
+ };
355
+ } ? ZodSchema : never;
356
+ };
357
+ type DeriveDefaults<T> = Prettify<{
358
+ [K in keyof T as K extends "_tableName" | typeof SchemaWrapperBrand ? never : K]: T[K] extends {
359
+ config: {
360
+ initialValue: infer D;
361
+ };
362
+ } ? D extends () => infer R ? R : D : never;
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
+ }>;
325
382
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.72",
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",