cogsbox-shape 0.5.26 → 0.5.27
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 +47 -4
- package/dist/schema.js +8 -8
- package/package.json +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -2276,33 +2276,62 @@ export declare function reference<TTargetField extends SchemaField, TField exten
|
|
|
2276
2276
|
to: () => TTargetField;
|
|
2277
2277
|
};
|
|
2278
2278
|
export declare function createMixedValidationSchema<T extends Schema<any>>(schema: T, clientSchema?: z.ZodObject<any>, dbSchema?: z.ZodObject<any>): z.ZodObject<any>;
|
|
2279
|
+
type SchemaDefinition = {
|
|
2280
|
+
_tableName: string;
|
|
2281
|
+
[key: string]: any;
|
|
2282
|
+
};
|
|
2279
2283
|
type InferSqlSchema<T> = {
|
|
2280
2284
|
[K in keyof T as K extends "_tableName" ? never : K]: T[K] extends {
|
|
2281
2285
|
config: {
|
|
2282
2286
|
zodSqlSchema: infer S extends z.ZodTypeAny;
|
|
2283
2287
|
};
|
|
2284
|
-
} ? S :
|
|
2288
|
+
} ? S : T[K] extends () => {
|
|
2289
|
+
type: "hasMany" | "manyToMany";
|
|
2290
|
+
schema: infer S extends SchemaDefinition;
|
|
2291
|
+
} ? z.ZodArray<z.ZodObject<Prettify<InferSqlSchema<S>>>> : T[K] extends () => {
|
|
2292
|
+
type: "hasOne" | "belongsTo";
|
|
2293
|
+
schema: infer S extends SchemaDefinition;
|
|
2294
|
+
} ? z.ZodObject<Prettify<InferSqlSchema<S>>> : never;
|
|
2285
2295
|
};
|
|
2286
2296
|
type InferClientSchema<T> = {
|
|
2287
2297
|
[K in keyof T as K extends "_tableName" ? never : K]: T[K] extends {
|
|
2288
2298
|
config: {
|
|
2289
2299
|
zodClientSchema: infer C extends z.ZodTypeAny;
|
|
2290
2300
|
};
|
|
2291
|
-
} ? C :
|
|
2301
|
+
} ? C : T[K] extends () => {
|
|
2302
|
+
type: "hasMany" | "manyToMany";
|
|
2303
|
+
schema: infer S extends SchemaDefinition;
|
|
2304
|
+
} ? z.ZodArray<z.ZodObject<Prettify<InferClientSchema<S>>>> : T[K] extends () => {
|
|
2305
|
+
type: "hasOne" | "belongsTo";
|
|
2306
|
+
schema: infer S extends SchemaDefinition;
|
|
2307
|
+
} ? z.ZodObject<Prettify<InferClientSchema<S>>> : never;
|
|
2292
2308
|
};
|
|
2293
2309
|
type InferValidationSchema<T> = {
|
|
2294
2310
|
[K in keyof T as K extends "_tableName" ? never : K]: T[K] extends {
|
|
2295
2311
|
config: {
|
|
2296
2312
|
zodValidationSchema: infer V extends z.ZodTypeAny;
|
|
2297
2313
|
};
|
|
2298
|
-
} ? V :
|
|
2314
|
+
} ? V : T[K] extends () => {
|
|
2315
|
+
type: "hasMany" | "manyToMany";
|
|
2316
|
+
schema: infer S extends SchemaDefinition;
|
|
2317
|
+
} ? z.ZodArray<z.ZodObject<Prettify<InferValidationSchema<S>>>> : T[K] extends () => {
|
|
2318
|
+
type: "hasOne" | "belongsTo";
|
|
2319
|
+
schema: infer S extends SchemaDefinition;
|
|
2320
|
+
} ? z.ZodObject<Prettify<InferValidationSchema<S>>> : never;
|
|
2299
2321
|
};
|
|
2300
2322
|
type InferDefaultValues2<T> = {
|
|
2301
2323
|
[K in keyof T as K extends "_tableName" ? never : K]: T[K] extends {
|
|
2302
2324
|
config: {
|
|
2303
2325
|
initialValue: infer D;
|
|
2304
2326
|
};
|
|
2305
|
-
} ? D :
|
|
2327
|
+
} ? D : T[K] extends () => {
|
|
2328
|
+
type: "hasMany" | "manyToMany";
|
|
2329
|
+
schema: infer S extends SchemaDefinition;
|
|
2330
|
+
defaultCount?: number;
|
|
2331
|
+
} ? Array<Prettify<InferDefaultValues2<S>>> : T[K] extends () => {
|
|
2332
|
+
type: "hasOne" | "belongsTo";
|
|
2333
|
+
schema: infer S extends SchemaDefinition;
|
|
2334
|
+
} ? Prettify<InferDefaultValues2<S>> : never;
|
|
2306
2335
|
};
|
|
2307
2336
|
export declare function createSchema<T extends {
|
|
2308
2337
|
_tableName: string;
|
|
@@ -2314,4 +2343,18 @@ export declare function createSchema<T extends {
|
|
|
2314
2343
|
validationSchema: z.ZodObject<Prettify<InferValidationSchema<T>>>;
|
|
2315
2344
|
defaultValues: Prettify<InferDefaultValues2<T>>;
|
|
2316
2345
|
};
|
|
2346
|
+
export type InferSchemaTypes<T extends {
|
|
2347
|
+
_tableName: string;
|
|
2348
|
+
} & {
|
|
2349
|
+
[key: string]: any;
|
|
2350
|
+
}> = Prettify<{
|
|
2351
|
+
/** The TypeScript type for data as it exists in the database. */
|
|
2352
|
+
sql: z.infer<ReturnType<typeof createSchema<T>>["sqlSchema"]>;
|
|
2353
|
+
/** The TypeScript type for data as it is represented on the client. */
|
|
2354
|
+
client: z.infer<ReturnType<typeof createSchema<T>>["clientSchema"]>;
|
|
2355
|
+
/** The TypeScript type for data during validation, often the most flexible shape. */
|
|
2356
|
+
validation: z.infer<ReturnType<typeof createSchema<T>>["validationSchema"]>;
|
|
2357
|
+
/** The TypeScript type for the default values object. */
|
|
2358
|
+
defaults: ReturnType<typeof createSchema<T>>["defaultValues"];
|
|
2359
|
+
}>;
|
|
2317
2360
|
export {};
|
package/dist/schema.js
CHANGED
|
@@ -234,14 +234,6 @@ export function manyToMany(config) {
|
|
|
234
234
|
defaultCount: config.defaultCount,
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
|
-
function isRelation(value) {
|
|
238
|
-
return (value &&
|
|
239
|
-
typeof value === "object" &&
|
|
240
|
-
"type" in value &&
|
|
241
|
-
"fromKey" in value &&
|
|
242
|
-
"toKey" in value &&
|
|
243
|
-
"schema" in value);
|
|
244
|
-
}
|
|
245
237
|
function inferDefaultFromZod(zodType, sqlConfig) {
|
|
246
238
|
if (sqlConfig?.pk) {
|
|
247
239
|
return uuidv4();
|
|
@@ -422,6 +414,14 @@ export function createMixedValidationSchema(schema, clientSchema, dbSchema) {
|
|
|
422
414
|
}
|
|
423
415
|
return z.object(mixedFields);
|
|
424
416
|
}
|
|
417
|
+
function isRelation(value) {
|
|
418
|
+
return (value &&
|
|
419
|
+
typeof value === "object" &&
|
|
420
|
+
"type" in value &&
|
|
421
|
+
"fromKey" in value &&
|
|
422
|
+
"toKey" in value &&
|
|
423
|
+
"schema" in value);
|
|
424
|
+
}
|
|
425
425
|
export function createSchema(schema) {
|
|
426
426
|
const sqlFields = {};
|
|
427
427
|
const clientFields = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.27",
|
|
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",
|