cogsbox-shape 0.5.111 → 0.5.113
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 +30 -13
- package/package.json +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -274,7 +274,16 @@ type NavigationProxy<CurrentTable extends string, Registry extends RegistryShape
|
|
|
274
274
|
type NavigationToSelection<Nav> = Nav extends object ? {
|
|
275
275
|
[K in keyof Nav]?: boolean | NavigationToSelection<Nav[K]>;
|
|
276
276
|
} : never;
|
|
277
|
-
type BuildZodShape<TTableName extends keyof TRegistry, TSelection, TKey extends "clientSchema" | "validationSchema", TRegistry extends RegistryShape> = TRegistry[TTableName]["zodSchemas"][TKey] extends z.ZodObject<infer Base> ? TSelection extends Record<string, any> ?
|
|
277
|
+
type BuildZodShape<TTableName extends keyof TRegistry, TSelection, TKey extends "clientSchema" | "validationSchema", TRegistry extends RegistryShape> = TRegistry[TTableName]["zodSchemas"][TKey] extends z.ZodObject<infer Base> ? TSelection extends Record<string, any> ? // First get the base fields without relations
|
|
278
|
+
{
|
|
279
|
+
[K in keyof Base as K extends keyof TRegistry[TTableName]["rawSchema"] ? TRegistry[TTableName]["rawSchema"][K] extends {
|
|
280
|
+
config: {
|
|
281
|
+
sql: {
|
|
282
|
+
schema: any;
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
} ? never : K : K]: Base[K];
|
|
286
|
+
} & {
|
|
278
287
|
[K in keyof TSelection & keyof TRegistry[TTableName]["rawSchema"]]: TRegistry[TTableName]["rawSchema"][K] extends {
|
|
279
288
|
config: {
|
|
280
289
|
sql: {
|
|
@@ -306,6 +315,25 @@ type RegistryShape = Record<string, {
|
|
|
306
315
|
toDb: (clientObject: any) => any;
|
|
307
316
|
};
|
|
308
317
|
}>;
|
|
318
|
+
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.)
|
|
319
|
+
DeriveDefaults<TRegistry[TTableName]["rawSchema"]> & (TSelection extends Record<string, any> ? {
|
|
320
|
+
-readonly [K in keyof TSelection & keyof TRegistry[TTableName]["rawSchema"]]?: TRegistry[TTableName]["rawSchema"][K] extends {
|
|
321
|
+
config: {
|
|
322
|
+
sql: {
|
|
323
|
+
type: infer RelType;
|
|
324
|
+
schema: () => infer S;
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
} ? S extends {
|
|
328
|
+
_tableName: infer Target;
|
|
329
|
+
} ? Target extends keyof TRegistry ? RelType extends "hasMany" | "manyToMany" ? DeriveViewDefaults<Target, TSelection[K], TRegistry, [
|
|
330
|
+
...Depth,
|
|
331
|
+
1
|
|
332
|
+
]>[] : DeriveViewDefaults<Target, TSelection[K], TRegistry, [
|
|
333
|
+
...Depth,
|
|
334
|
+
1
|
|
335
|
+
]> | null | undefined : never : never : never;
|
|
336
|
+
} : {});
|
|
309
337
|
type CreateSchemaBoxReturn<S extends Record<string, SchemaWithPlaceholders>, R extends ResolutionMap<S>, Resolved extends RegistryShape = ResolvedRegistryWithSchemas<S, R> extends RegistryShape ? ResolvedRegistryWithSchemas<S, R> : RegistryShape> = {
|
|
310
338
|
[K in keyof Resolved]: {
|
|
311
339
|
definition: Resolved[K]["rawSchema"];
|
|
@@ -325,7 +353,7 @@ type CreateSchemaBoxReturn<S extends Record<string, SchemaWithPlaceholders>, R e
|
|
|
325
353
|
sql: Resolved[K]["zodSchemas"]["sqlSchema"];
|
|
326
354
|
client: z.ZodObject<BuildZodShape<K, TSelection, "clientSchema", Resolved>>;
|
|
327
355
|
validation: z.ZodObject<BuildZodShape<K, TSelection, "validationSchema", Resolved>>;
|
|
328
|
-
defaults:
|
|
356
|
+
defaults: Prettify<DeriveViewDefaults<K & string, TSelection, Resolved>>;
|
|
329
357
|
};
|
|
330
358
|
};
|
|
331
359
|
};
|
|
@@ -380,15 +408,4 @@ type DeriveDefaults<T, Depth extends any[] = []> = Prettify<Depth["length"] exte
|
|
|
380
408
|
};
|
|
381
409
|
} ? D extends () => infer R ? R : D : never;
|
|
382
410
|
}>;
|
|
383
|
-
export type InferFromSchema<T extends {
|
|
384
|
-
_tableName: string;
|
|
385
|
-
}> = Prettify<{
|
|
386
|
-
SqlSchema: z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodSqlSchema">>>;
|
|
387
|
-
ClientSchema: z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodClientSchema">>>;
|
|
388
|
-
ValidationSchema: z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodValidationSchema">>>;
|
|
389
|
-
Sql: z.infer<z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodSqlSchema">>>>;
|
|
390
|
-
Client: z.infer<z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodClientSchema">>>>;
|
|
391
|
-
Validation: z.infer<z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodValidationSchema">>>>;
|
|
392
|
-
Defaults: DeriveDefaults<T>;
|
|
393
|
-
}>;
|
|
394
411
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.113",
|
|
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",
|