cogsbox-shape 0.5.171 → 0.5.172
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 +8 -8
- package/dist/schema.js +6 -6
- package/package.json +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -218,7 +218,7 @@ export declare function createSchema<T extends {
|
|
|
218
218
|
isClientRecord: ((record: any) => boolean) | undefined;
|
|
219
219
|
sqlSchema: z.ZodObject<Prettify<DeriveSchemaByKey<TActualSchema, "zodSqlSchema">>>;
|
|
220
220
|
clientSchema: z.ZodObject<Prettify<DeriveSchemaByKey<TActualSchema, "zodClientSchema">>>;
|
|
221
|
-
|
|
221
|
+
serverSchema: z.ZodObject<Prettify<DeriveSchemaByKey<TActualSchema, "zodValidationSchema">>>;
|
|
222
222
|
defaultValues: Prettify<DeriveDefaults<TActualSchema>>;
|
|
223
223
|
stateType: Prettify<DeriveStateType<TActualSchema>>;
|
|
224
224
|
generateDefaults: () => Prettify<DeriveDefaults<TActualSchema>>;
|
|
@@ -288,7 +288,7 @@ type ResolvedRegistryWithSchemas<S extends Record<string, SchemaWithPlaceholders
|
|
|
288
288
|
zodSchemas: {
|
|
289
289
|
sqlSchema: z.ZodObject<Prettify<DeriveSchemaByKey<ResolveSchema<S[K], K extends keyof R ? (R[K] extends object ? R[K] : {}) : {}>, "zodSqlSchema">>>;
|
|
290
290
|
clientSchema: z.ZodObject<Prettify<DeriveSchemaByKey<ResolveSchema<S[K], K extends keyof R ? (R[K] extends object ? R[K] : {}) : {}>, "zodClientSchema">>>;
|
|
291
|
-
|
|
291
|
+
serverSchema: z.ZodObject<Prettify<DeriveSchemaByKey<ResolveSchema<S[K], K extends keyof R ? (R[K] extends object ? R[K] : {}) : {}>, "zodValidationSchema">>>;
|
|
292
292
|
defaultValues: Prettify<DeriveDefaults<ResolveSchema<S[K], K extends keyof R ? (R[K] extends object ? R[K] : {}) : {}>>>;
|
|
293
293
|
stateType: Prettify<DeriveStateType<ResolveSchema<S[K], K extends keyof R ? (R[K] extends object ? R[K] : {}) : {}>>>;
|
|
294
294
|
toClient: (dbObject: any) => any;
|
|
@@ -324,7 +324,7 @@ type GetRelationRegistryKey<Field, TRegistry extends RegistryShape> = Field exte
|
|
|
324
324
|
type OmitRelationFields<Shape, RawSchema> = Omit<Shape, {
|
|
325
325
|
[K in keyof Shape]: K extends keyof RawSchema ? IsRelationField<RawSchema[K]> extends true ? K : never : never;
|
|
326
326
|
}[keyof Shape]>;
|
|
327
|
-
type _DeriveViewShape<TTableName extends keyof TRegistry, TSelection, TRegistry extends RegistryShape, TKey extends "clientSchema" | "
|
|
327
|
+
type _DeriveViewShape<TTableName extends keyof TRegistry, TSelection, TRegistry extends RegistryShape, TKey extends "clientSchema" | "serverSchema", Depth extends any[] = []> = Depth["length"] extends 10 ? any : TRegistry[TTableName]["zodSchemas"][TKey] extends z.ZodObject<infer BaseShape> ? TSelection extends Record<string, any> ? Prettify<OmitRelationFields<BaseShape, TRegistry[TTableName]["rawSchema"]> & {
|
|
328
328
|
[K in keyof TSelection & keyof TRegistry[TTableName]["rawSchema"] as IsRelationField<TRegistry[TTableName]["rawSchema"][K]> extends true ? K : never]: GetRelationRegistryKey<TRegistry[TTableName]["rawSchema"][K], TRegistry> extends infer TargetKey ? TargetKey extends keyof TRegistry ? TRegistry[TTableName]["rawSchema"][K] extends {
|
|
329
329
|
config: {
|
|
330
330
|
sql: {
|
|
@@ -361,13 +361,13 @@ export type DeriveViewResult<TTableName extends keyof TRegistry, TSelection, TRe
|
|
|
361
361
|
schemas: {
|
|
362
362
|
sql: TRegistry[TTableName]["zodSchemas"]["sqlSchema"];
|
|
363
363
|
client: z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "clientSchema">>;
|
|
364
|
-
server: z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "
|
|
364
|
+
server: z.ZodObject<_DeriveViewShape<TTableName, TSelection, TRegistry, "serverSchema">>;
|
|
365
365
|
};
|
|
366
366
|
transforms: {
|
|
367
367
|
toClient: TRegistry[TTableName]["zodSchemas"]["toClient"];
|
|
368
368
|
toDb: TRegistry[TTableName]["zodSchemas"]["toDb"];
|
|
369
369
|
};
|
|
370
|
-
parseForDb: (appData: z.input<TRegistry[TTableName]["zodSchemas"]["
|
|
370
|
+
parseForDb: (appData: z.input<TRegistry[TTableName]["zodSchemas"]["serverSchema"]>) => z.infer<TRegistry[TTableName]["zodSchemas"]["sqlSchema"]>;
|
|
371
371
|
parseFromDb: (dbData: Partial<z.infer<TRegistry[TTableName]["zodSchemas"]["sqlSchema"]>>) => z.infer<TRegistry[TTableName]["zodSchemas"]["clientSchema"]>;
|
|
372
372
|
defaults: DeriveViewDefaults<TTableName, TSelection, TRegistry>;
|
|
373
373
|
pk: string[] | null;
|
|
@@ -405,7 +405,7 @@ type RegistryShape = Record<string, {
|
|
|
405
405
|
zodSchemas: {
|
|
406
406
|
sqlSchema: z.ZodObject<any>;
|
|
407
407
|
clientSchema: z.ZodObject<any>;
|
|
408
|
-
|
|
408
|
+
serverSchema: z.ZodObject<any>;
|
|
409
409
|
defaultValues: any;
|
|
410
410
|
stateType: any;
|
|
411
411
|
toClient: (dbObject: any) => any;
|
|
@@ -425,13 +425,13 @@ type CreateSchemaBoxReturn<S extends Record<string, SchemaWithPlaceholders>, R e
|
|
|
425
425
|
schemas: {
|
|
426
426
|
sql: Resolved[K]["zodSchemas"]["sqlSchema"];
|
|
427
427
|
client: Resolved[K]["zodSchemas"]["clientSchema"];
|
|
428
|
-
server: Resolved[K]["zodSchemas"]["
|
|
428
|
+
server: Resolved[K]["zodSchemas"]["serverSchema"];
|
|
429
429
|
};
|
|
430
430
|
transforms: {
|
|
431
431
|
toClient: Resolved[K]["zodSchemas"]["toClient"];
|
|
432
432
|
toDb: Resolved[K]["zodSchemas"]["toDb"];
|
|
433
433
|
};
|
|
434
|
-
parseForDb: (appData: z.input<Resolved[K]["zodSchemas"]["
|
|
434
|
+
parseForDb: (appData: z.input<Resolved[K]["zodSchemas"]["serverSchema"]>) => z.infer<Resolved[K]["zodSchemas"]["sqlSchema"]>;
|
|
435
435
|
parseFromDb: (dbData: Partial<z.infer<Resolved[K]["zodSchemas"]["sqlSchema"]>>) => z.infer<Resolved[K]["zodSchemas"]["clientSchema"]>;
|
|
436
436
|
defaults: Resolved[K]["zodSchemas"]["defaultValues"];
|
|
437
437
|
stateType: Resolved[K]["zodSchemas"]["stateType"];
|
package/dist/schema.js
CHANGED
|
@@ -253,7 +253,7 @@ function createBuilder(config) {
|
|
|
253
253
|
if (completedStages.has("server")) {
|
|
254
254
|
throw new Error("validation() can only be called once in the chain");
|
|
255
255
|
}
|
|
256
|
-
const
|
|
256
|
+
const serverSchema = isFunction(assert)
|
|
257
257
|
? assert({
|
|
258
258
|
sql: config.sqlZod,
|
|
259
259
|
initialState: config.newZod,
|
|
@@ -265,7 +265,7 @@ function createBuilder(config) {
|
|
|
265
265
|
return createBuilder({
|
|
266
266
|
...config,
|
|
267
267
|
stage: "server",
|
|
268
|
-
validationZod:
|
|
268
|
+
validationZod: serverSchema,
|
|
269
269
|
completedStages: newCompletedStages,
|
|
270
270
|
});
|
|
271
271
|
},
|
|
@@ -539,7 +539,7 @@ export function createSchema(schema, relations) {
|
|
|
539
539
|
isClientRecord,
|
|
540
540
|
sqlSchema: finalSqlSchema,
|
|
541
541
|
clientSchema: finalClientSchema,
|
|
542
|
-
|
|
542
|
+
serverSchema: finalValidationSchema,
|
|
543
543
|
defaultValues: defaultValues,
|
|
544
544
|
stateType: {},
|
|
545
545
|
generateDefaults,
|
|
@@ -581,7 +581,7 @@ function createViewObject(initialRegistryKey, selection, registry, tableNameToRe
|
|
|
581
581
|
}
|
|
582
582
|
}
|
|
583
583
|
const baseSchema = schemaType === "server"
|
|
584
|
-
? registryEntry.zodSchemas.
|
|
584
|
+
? registryEntry.zodSchemas.serverSchema
|
|
585
585
|
: registryEntry.zodSchemas.clientSchema;
|
|
586
586
|
const primitiveShape = baseSchema.shape;
|
|
587
587
|
if (subSelection === true) {
|
|
@@ -749,11 +749,11 @@ export function createSchemaBox(schemas, resolver) {
|
|
|
749
749
|
const entry = finalRegistry[tableName];
|
|
750
750
|
cleanerRegistry[tableName] = {
|
|
751
751
|
definition: entry.rawSchema,
|
|
752
|
-
schemaKey: tableName,
|
|
752
|
+
schemaKey: tableName,
|
|
753
753
|
schemas: {
|
|
754
754
|
sql: entry.zodSchemas.sqlSchema,
|
|
755
755
|
client: entry.zodSchemas.clientSchema,
|
|
756
|
-
server: entry.zodSchemas.
|
|
756
|
+
server: entry.zodSchemas.serverSchema,
|
|
757
757
|
},
|
|
758
758
|
transforms: {
|
|
759
759
|
toClient: entry.zodSchemas.toClient,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.172",
|
|
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",
|