cogsbox-shape 0.5.72 → 0.5.73
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 +90 -3
- 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,94 @@ 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
|
+
/**
|
|
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 : {
|
|
331
|
+
[K in keyof T as K extends "_tableName" | typeof SchemaWrapperBrand ? never : K]: T[K] extends {
|
|
332
|
+
config: {
|
|
333
|
+
sql: {
|
|
334
|
+
type: "hasMany" | "manyToMany";
|
|
335
|
+
schema: () => infer S;
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
} ? z.ZodArray<S extends {
|
|
339
|
+
_tableName: string;
|
|
340
|
+
} ? z.ZodObject<Prettify<InferByKey<S, Key, [...Depth, 1]>>> : z.ZodObject<any>> : T[K] extends {
|
|
341
|
+
config: {
|
|
342
|
+
sql: {
|
|
343
|
+
type: "hasOne" | "belongsTo";
|
|
344
|
+
schema: () => infer S;
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
} ? S extends {
|
|
348
|
+
_tableName: string;
|
|
349
|
+
} ? z.ZodObject<Prettify<InferByKey<S, Key, [...Depth, 1]>>> : z.ZodObject<any> : T[K] extends {
|
|
350
|
+
type: "reference";
|
|
351
|
+
to: () => infer RefField;
|
|
352
|
+
} ? RefField extends {
|
|
353
|
+
config: {
|
|
354
|
+
[P in Key]: infer ZodSchema;
|
|
355
|
+
};
|
|
356
|
+
} ? ZodSchema : never : T[K] extends {
|
|
357
|
+
config: {
|
|
358
|
+
[P in Key]: infer ZodSchema extends z.ZodTypeAny;
|
|
359
|
+
};
|
|
360
|
+
} ? ZodSchema : never;
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* [INTERNAL] Core utility to infer default values directly from the schema definition.
|
|
364
|
+
*/
|
|
365
|
+
type InferDefaults<T> = {
|
|
366
|
+
[K in keyof T as K extends "_tableName" | typeof SchemaWrapperBrand ? never : K]: T[K] extends {
|
|
367
|
+
config: {
|
|
368
|
+
initialValue: infer D;
|
|
369
|
+
};
|
|
370
|
+
} ? 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
|
+
}
|
|
325
412
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.73",
|
|
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",
|