cogsbox-shape 0.5.36 → 0.5.38
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 +12 -7
- package/dist/schema.js +32 -1
- package/package.json +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -4849,17 +4849,22 @@ export type InferSchemaTypes<T extends {
|
|
|
4849
4849
|
/** The TypeScript type for the default values object. */
|
|
4850
4850
|
defaults: ReturnType<typeof createSchema<T>>["defaultValues"];
|
|
4851
4851
|
}>;
|
|
4852
|
-
type
|
|
4852
|
+
export type ProcessedSyncSchemaEntry<T extends {
|
|
4853
4853
|
_tableName: string;
|
|
4854
4854
|
}> = {
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4855
|
+
rawSchema: T;
|
|
4856
|
+
schemas: ReturnType<typeof createSchema<T>>;
|
|
4857
|
+
validate: (data: unknown) => z.SafeParseReturnType<T extends {
|
|
4858
|
+
validation: (s: any) => infer V extends z.ZodSchema;
|
|
4859
|
+
} ? z.infer<V> : InferSchemaTypes<T>["validation"], InferSchemaTypes<T>["validation"]>;
|
|
4860
|
+
validateClient: (data: unknown) => z.SafeParseReturnType<T extends {
|
|
4861
|
+
client: (s: any) => infer V extends z.ZodSchema;
|
|
4862
|
+
} ? z.infer<V> : InferSchemaTypes<T>["client"], InferSchemaTypes<T>["client"]>;
|
|
4858
4863
|
};
|
|
4859
|
-
type
|
|
4864
|
+
export type ProcessedSyncSchemaMap<T extends Record<string, {
|
|
4860
4865
|
_tableName: string;
|
|
4861
4866
|
}>> = {
|
|
4862
|
-
[K in keyof T]:
|
|
4867
|
+
[K in keyof T]: ProcessedSyncSchemaEntry<T[K]>;
|
|
4863
4868
|
};
|
|
4864
4869
|
export declare function createSyncSchema<T extends Record<string, {
|
|
4865
4870
|
_tableName: string;
|
|
@@ -4869,5 +4874,5 @@ export declare function createSyncSchema<T extends Record<string, {
|
|
|
4869
4874
|
validation?: (schema: ReturnType<typeof createSchema<T[K]>>["validationSchema"]) => z.ZodSchema;
|
|
4870
4875
|
client?: (schema: ReturnType<typeof createSchema<T[K]>>["clientSchema"]) => z.ZodSchema;
|
|
4871
4876
|
};
|
|
4872
|
-
}):
|
|
4877
|
+
}): ProcessedSyncSchemaMap<T>;
|
|
4873
4878
|
export {};
|
package/dist/schema.js
CHANGED
|
@@ -399,6 +399,37 @@ export function createSchema(schema) {
|
|
|
399
399
|
defaultValues: defaultValues,
|
|
400
400
|
};
|
|
401
401
|
}
|
|
402
|
+
// The function that does the work, with the corrected generic constraint.
|
|
402
403
|
export function createSyncSchema(config) {
|
|
403
|
-
|
|
404
|
+
const processedOutput = {};
|
|
405
|
+
// Loop through each entry in your config (e.g., 'chatMessages')
|
|
406
|
+
for (const key in config) {
|
|
407
|
+
const entry = config[key];
|
|
408
|
+
// 1. Call createSchema ONCE to generate all the base Zod schemas and defaults.
|
|
409
|
+
const { sqlSchema, clientSchema, validationSchema, defaultValues } = createSchema(entry.schema);
|
|
410
|
+
// 2. Determine the FINAL validation schema.
|
|
411
|
+
const finalValidationSchema = entry.validation
|
|
412
|
+
? entry.validation(validationSchema)
|
|
413
|
+
: validationSchema;
|
|
414
|
+
// 3. Determine the FINAL client schema.
|
|
415
|
+
const finalClientSchema = entry.client
|
|
416
|
+
? entry.client(clientSchema)
|
|
417
|
+
: clientSchema;
|
|
418
|
+
// 4. ASSIGN everything to the output object.
|
|
419
|
+
processedOutput[key] = {
|
|
420
|
+
rawSchema: entry.schema,
|
|
421
|
+
// Keep the generated schemas for reference or other uses
|
|
422
|
+
schemas: {
|
|
423
|
+
sql: sqlSchema,
|
|
424
|
+
client: clientSchema,
|
|
425
|
+
validation: validationSchema,
|
|
426
|
+
defaults: defaultValues,
|
|
427
|
+
},
|
|
428
|
+
// Create the final validator FUNCTIONS that the DO can call directly.
|
|
429
|
+
validate: (data) => finalValidationSchema.safeParse(data),
|
|
430
|
+
validateClient: (data) => finalClientSchema.safeParse(data),
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
// Return the new object containing the schemas AND the validator functions.
|
|
434
|
+
return processedOutput;
|
|
404
435
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.38",
|
|
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",
|