cogsbox-shape 0.5.131 → 0.5.132
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 +2 -1
- package/dist/schema.js +4 -49
- package/package.json +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -36,10 +36,11 @@ type SQLToZodType<T extends SQLType, TDefault extends boolean> = T["pk"] extends
|
|
|
36
36
|
default: "CURRENT_TIMESTAMP";
|
|
37
37
|
} ? TDefault extends true ? never : z.ZodDate : z.ZodDate : never;
|
|
38
38
|
type ZodTypeFromPrimitive<T> = T extends string ? z.ZodString : T extends number ? z.ZodNumber : T extends boolean ? z.ZodBoolean : T extends Date ? z.ZodDate : z.ZodAny;
|
|
39
|
+
type NonLiteral<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T;
|
|
39
40
|
type CollapsedUnion<A extends z.ZodTypeAny, B extends z.ZodTypeAny> = A extends B ? (B extends A ? A : z.ZodUnion<[A, B]>) : z.ZodUnion<[A, B]>;
|
|
40
41
|
export interface IBuilderMethods<T extends SQLType | RelationConfig<any>, TSql extends z.ZodTypeAny, TNew extends z.ZodTypeAny, TInitialValue, TClient extends z.ZodTypeAny, TValidation extends z.ZodTypeAny> {
|
|
41
42
|
initialState: {
|
|
42
|
-
<
|
|
43
|
+
<TValue>(value: TValue extends (...args: any[]) => void | undefined ? never : TValue): TValue extends (...args: any[]) => infer R ? R extends void | undefined ? never : TValue extends z.ZodTypeAny ? Prettify<Builder<"new", T, TSql, TValue, z.infer<TValue>, CollapsedUnion<TSql, TValue>, CollapsedUnion<TSql, TValue>>> : Prettify<Builder<"new", T, TSql, ZodTypeFromPrimitive<R>, NonLiteral<R>, CollapsedUnion<TSql, ZodTypeFromPrimitive<R>>, CollapsedUnion<TSql, ZodTypeFromPrimitive<R>>>> : TValue extends z.ZodTypeAny ? Prettify<Builder<"new", T, TSql, TValue, z.infer<TValue>, CollapsedUnion<TSql, TValue>, CollapsedUnion<TSql, TValue>>> : Prettify<Builder<"new", T, TSql, ZodTypeFromPrimitive<TValue>, NonLiteral<TValue>, CollapsedUnion<TSql, ZodTypeFromPrimitive<TValue>>, CollapsedUnion<TSql, ZodTypeFromPrimitive<TValue>>>>;
|
|
43
44
|
<const TValue, TSchema extends z.ZodTypeAny>(value: TValue extends (...args: any[]) => void | undefined ? never : TValue, schema: TSchema): Prettify<Builder<"new", T, TSql, TSchema, TValue extends () => infer R ? R : TValue, CollapsedUnion<TSql, TSchema>, CollapsedUnion<TSql, TSchema>>>;
|
|
44
45
|
<const TValue, TSchema extends z.ZodTypeAny>(value: TValue extends (...args: any[]) => void | undefined ? never : TValue, schemaModifier: (baseSchema: TValue extends () => infer R ? R extends string | number | boolean ? z.ZodLiteral<R> : ZodTypeFromPrimitive<R> : TValue extends string | number | boolean ? z.ZodLiteral<TValue> : ZodTypeFromPrimitive<TValue>) => TSchema): Prettify<Builder<"new", T, TSql, TSchema, TValue extends () => infer R ? R : TValue, CollapsedUnion<TSql, TSchema>, CollapsedUnion<TSql, TSchema>>>;
|
|
45
46
|
};
|
package/dist/schema.js
CHANGED
|
@@ -135,13 +135,11 @@ function createBuilder(config) {
|
|
|
135
135
|
let finalSchema;
|
|
136
136
|
// Check if value is a Zod schema (single argument case)
|
|
137
137
|
if (value && typeof value === "object" && "_def" in value) {
|
|
138
|
-
// It's a Zod schema - infer the default value
|
|
139
138
|
baseSchema = value;
|
|
140
139
|
actualValue = inferDefaultFromZod(baseSchema, config.sqlConfig);
|
|
141
140
|
finalSchema = baseSchema;
|
|
142
141
|
}
|
|
143
142
|
else {
|
|
144
|
-
// Get the actual value
|
|
145
143
|
actualValue = isFunction(value) ? value() : value;
|
|
146
144
|
// If second parameter is provided and is a Zod schema, use it directly
|
|
147
145
|
if (schemaOrModifier &&
|
|
@@ -150,56 +148,13 @@ function createBuilder(config) {
|
|
|
150
148
|
finalSchema = schemaOrModifier;
|
|
151
149
|
}
|
|
152
150
|
else if (isFunction(schemaOrModifier)) {
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
if (typeof actualValue === "string") {
|
|
156
|
-
baseSchema = z.string();
|
|
157
|
-
}
|
|
158
|
-
else if (typeof actualValue === "number") {
|
|
159
|
-
baseSchema = z.number();
|
|
160
|
-
}
|
|
161
|
-
else if (typeof actualValue === "boolean") {
|
|
162
|
-
baseSchema = z.boolean();
|
|
163
|
-
}
|
|
164
|
-
else if (actualValue instanceof Date) {
|
|
165
|
-
baseSchema = z.date();
|
|
166
|
-
}
|
|
167
|
-
else if (actualValue === null) {
|
|
168
|
-
baseSchema = z.null();
|
|
169
|
-
}
|
|
170
|
-
else if (actualValue === undefined) {
|
|
171
|
-
baseSchema = z.undefined();
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
baseSchema = z.any();
|
|
175
|
-
}
|
|
176
|
-
// Apply the modifier
|
|
151
|
+
// Create base Zod schema from SQLType instead of value type
|
|
152
|
+
baseSchema = config.sqlZod;
|
|
177
153
|
finalSchema = schemaOrModifier(baseSchema);
|
|
178
154
|
}
|
|
179
155
|
else {
|
|
180
|
-
// No schema provided,
|
|
181
|
-
|
|
182
|
-
baseSchema = z.string();
|
|
183
|
-
}
|
|
184
|
-
else if (typeof actualValue === "number") {
|
|
185
|
-
baseSchema = z.number();
|
|
186
|
-
}
|
|
187
|
-
else if (typeof actualValue === "boolean") {
|
|
188
|
-
baseSchema = z.boolean();
|
|
189
|
-
}
|
|
190
|
-
else if (actualValue instanceof Date) {
|
|
191
|
-
baseSchema = z.date();
|
|
192
|
-
}
|
|
193
|
-
else if (actualValue === null) {
|
|
194
|
-
baseSchema = z.null();
|
|
195
|
-
}
|
|
196
|
-
else if (actualValue === undefined) {
|
|
197
|
-
baseSchema = z.undefined();
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
baseSchema = z.any();
|
|
201
|
-
}
|
|
202
|
-
finalSchema = baseSchema;
|
|
156
|
+
// No schema provided, use the SQL type's schema
|
|
157
|
+
finalSchema = config.sqlZod;
|
|
203
158
|
}
|
|
204
159
|
}
|
|
205
160
|
const newCompletedStages = new Set(completedStages);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.132",
|
|
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",
|