cogsbox-shape 0.5.111 → 0.5.112

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 +20 -1
  2. package/package.json +1 -1
package/dist/schema.d.ts CHANGED
@@ -306,6 +306,25 @@ type RegistryShape = Record<string, {
306
306
  toDb: (clientObject: any) => any;
307
307
  };
308
308
  }>;
309
+ type DeriveViewDefaults<TTableName extends keyof TRegistry, TSelection, TRegistry extends RegistryShape, Depth extends any[] = []> = Depth["length"] extends 10 ? any : // 1. Start with the base defaults for the table (id, name, etc.)
310
+ DeriveDefaults<TRegistry[TTableName]["rawSchema"]> & (TSelection extends Record<string, any> ? {
311
+ -readonly [K in keyof TSelection & keyof TRegistry[TTableName]["rawSchema"]]?: TRegistry[TTableName]["rawSchema"][K] extends {
312
+ config: {
313
+ sql: {
314
+ type: infer RelType;
315
+ schema: () => infer S;
316
+ };
317
+ };
318
+ } ? S extends {
319
+ _tableName: infer Target;
320
+ } ? Target extends keyof TRegistry ? RelType extends "hasMany" | "manyToMany" ? DeriveViewDefaults<Target, TSelection[K], TRegistry, [
321
+ ...Depth,
322
+ 1
323
+ ]>[] : DeriveViewDefaults<Target, TSelection[K], TRegistry, [
324
+ ...Depth,
325
+ 1
326
+ ]> | null | undefined : never : never : never;
327
+ } : {});
309
328
  type CreateSchemaBoxReturn<S extends Record<string, SchemaWithPlaceholders>, R extends ResolutionMap<S>, Resolved extends RegistryShape = ResolvedRegistryWithSchemas<S, R> extends RegistryShape ? ResolvedRegistryWithSchemas<S, R> : RegistryShape> = {
310
329
  [K in keyof Resolved]: {
311
330
  definition: Resolved[K]["rawSchema"];
@@ -325,7 +344,7 @@ type CreateSchemaBoxReturn<S extends Record<string, SchemaWithPlaceholders>, R e
325
344
  sql: Resolved[K]["zodSchemas"]["sqlSchema"];
326
345
  client: z.ZodObject<BuildZodShape<K, TSelection, "clientSchema", Resolved>>;
327
346
  validation: z.ZodObject<BuildZodShape<K, TSelection, "validationSchema", Resolved>>;
328
- defaults: any;
347
+ defaults: Prettify<DeriveViewDefaults<K & string, TSelection, Resolved>>;
329
348
  };
330
349
  };
331
350
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-shape",
3
- "version": "0.5.111",
3
+ "version": "0.5.112",
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",