cogsbox-shape 0.5.52 → 0.5.53
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 +45 -4
- package/package.json +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -4784,13 +4784,54 @@ export declare function reference<TField extends object>(config: TField): {
|
|
|
4784
4784
|
to: TField;
|
|
4785
4785
|
};
|
|
4786
4786
|
export declare function createMixedValidationSchema<T extends Schema<any>>(schema: T, clientSchema?: z.ZodObject<any>, dbSchema?: z.ZodObject<any>): z.ZodObject<any>;
|
|
4787
|
+
type SchemaDefinition = {
|
|
4788
|
+
_tableName: string;
|
|
4789
|
+
[key: string]: any;
|
|
4790
|
+
};
|
|
4791
|
+
type InferSchemaByKey<T, Key extends "zodSqlSchema" | "zodClientSchema" | "zodValidationSchema"> = {
|
|
4792
|
+
[K in keyof T as K extends "_tableName" ? never : K]: T[K] extends {
|
|
4793
|
+
config: {
|
|
4794
|
+
[P in Key]: infer S extends z.ZodTypeAny;
|
|
4795
|
+
};
|
|
4796
|
+
} ? S : T[K] extends {
|
|
4797
|
+
type: "reference";
|
|
4798
|
+
to: () => {
|
|
4799
|
+
config: {
|
|
4800
|
+
[P in Key]: infer S extends z.ZodTypeAny;
|
|
4801
|
+
};
|
|
4802
|
+
};
|
|
4803
|
+
} ? S : T[K] extends () => {
|
|
4804
|
+
type: "hasMany" | "manyToMany";
|
|
4805
|
+
schema: infer S extends SchemaDefinition;
|
|
4806
|
+
} ? z.ZodArray<z.ZodObject<Prettify<InferSchemaByKey<S, Key>>>> : T[K] extends () => {
|
|
4807
|
+
type: "hasOne" | "belongsTo";
|
|
4808
|
+
schema: infer S extends SchemaDefinition;
|
|
4809
|
+
} ? z.ZodObject<Prettify<InferSchemaByKey<S, Key>>> : never;
|
|
4810
|
+
};
|
|
4811
|
+
type InferSqlSchema<T> = InferSchemaByKey<T, "zodSqlSchema">;
|
|
4812
|
+
type InferClientSchema<T> = InferSchemaByKey<T, "zodClientSchema">;
|
|
4813
|
+
type InferValidationSchema<T> = InferSchemaByKey<T, "zodValidationSchema">;
|
|
4814
|
+
type InferDefaultValues2<T> = {
|
|
4815
|
+
[K in keyof T as K extends "_tableName" ? never : K]: T[K] extends {
|
|
4816
|
+
config: {
|
|
4817
|
+
initialValue: infer D;
|
|
4818
|
+
};
|
|
4819
|
+
} ? D : T[K] extends () => {
|
|
4820
|
+
type: "hasMany" | "manyToMany";
|
|
4821
|
+
schema: infer S extends SchemaDefinition;
|
|
4822
|
+
defaultCount?: number;
|
|
4823
|
+
} ? Array<Prettify<InferDefaultValues2<S>>> : T[K] extends () => {
|
|
4824
|
+
type: "hasOne" | "belongsTo";
|
|
4825
|
+
schema: infer S extends SchemaDefinition;
|
|
4826
|
+
} ? Prettify<InferDefaultValues2<S>> : never;
|
|
4827
|
+
};
|
|
4787
4828
|
export declare function createSchema<T extends {
|
|
4788
4829
|
_tableName: string;
|
|
4789
4830
|
}>(schema: T): {
|
|
4790
|
-
sqlSchema: z.ZodObject<
|
|
4791
|
-
clientSchema: z.ZodObject<
|
|
4792
|
-
validationSchema: z.ZodObject<
|
|
4793
|
-
defaultValues:
|
|
4831
|
+
sqlSchema: z.ZodObject<Prettify<InferSqlSchema<T>>>;
|
|
4832
|
+
clientSchema: z.ZodObject<Prettify<InferClientSchema<T>>>;
|
|
4833
|
+
validationSchema: z.ZodObject<Prettify<InferValidationSchema<T>>>;
|
|
4834
|
+
defaultValues: Prettify<InferDefaultValues2<T>>;
|
|
4794
4835
|
};
|
|
4795
4836
|
export type InferSchemaTypes<T extends {
|
|
4796
4837
|
_tableName: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.53",
|
|
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",
|