cogsbox-shape 0.5.35 → 0.5.37
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 +11 -7
- package/dist/schema.js +32 -2
- package/package.json +1 -1
package/dist/schema.d.ts
CHANGED
|
@@ -4849,17 +4849,21 @@ 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
|
+
schemas: ReturnType<typeof createSchema<T>>;
|
|
4856
|
+
validate: (data: unknown) => z.SafeParseReturnType<T extends {
|
|
4857
|
+
validation: (s: any) => infer V extends z.ZodSchema;
|
|
4858
|
+
} ? z.infer<V> : InferSchemaTypes<T>["validation"], InferSchemaTypes<T>["validation"]>;
|
|
4859
|
+
validateClient: (data: unknown) => z.SafeParseReturnType<T extends {
|
|
4860
|
+
client: (s: any) => infer V extends z.ZodSchema;
|
|
4861
|
+
} ? z.infer<V> : InferSchemaTypes<T>["client"], InferSchemaTypes<T>["client"]>;
|
|
4858
4862
|
};
|
|
4859
|
-
type
|
|
4863
|
+
export type ProcessedSyncSchemaMap<T extends Record<string, {
|
|
4860
4864
|
_tableName: string;
|
|
4861
4865
|
}>> = {
|
|
4862
|
-
[K in keyof T]:
|
|
4866
|
+
[K in keyof T]: ProcessedSyncSchemaEntry<T[K]>;
|
|
4863
4867
|
};
|
|
4864
4868
|
export declare function createSyncSchema<T extends Record<string, {
|
|
4865
4869
|
_tableName: string;
|
|
@@ -4869,5 +4873,5 @@ export declare function createSyncSchema<T extends Record<string, {
|
|
|
4869
4873
|
validation?: (schema: ReturnType<typeof createSchema<T[K]>>["validationSchema"]) => z.ZodSchema;
|
|
4870
4874
|
client?: (schema: ReturnType<typeof createSchema<T[K]>>["clientSchema"]) => z.ZodSchema;
|
|
4871
4875
|
};
|
|
4872
|
-
}):
|
|
4876
|
+
}): ProcessedSyncSchemaMap<T>;
|
|
4873
4877
|
export {};
|
package/dist/schema.js
CHANGED
|
@@ -117,7 +117,7 @@ function createBuilder(config) {
|
|
|
117
117
|
: schemaOrDefault
|
|
118
118
|
: config.sqlZod; // Keep SQL type if just setting default
|
|
119
119
|
const finalDefaultValue = hasTypeParam
|
|
120
|
-
? defaultValue
|
|
120
|
+
? defaultValue
|
|
121
121
|
: schemaOrDefault;
|
|
122
122
|
const newCompletedStages = new Set(completedStages);
|
|
123
123
|
newCompletedStages.add("new");
|
|
@@ -399,6 +399,36 @@ 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
|
+
// Keep the generated schemas for reference or other uses
|
|
421
|
+
schemas: {
|
|
422
|
+
sql: sqlSchema,
|
|
423
|
+
client: clientSchema,
|
|
424
|
+
validation: validationSchema,
|
|
425
|
+
defaults: defaultValues,
|
|
426
|
+
},
|
|
427
|
+
// Create the final validator FUNCTIONS that the DO can call directly.
|
|
428
|
+
validate: (data) => finalValidationSchema.safeParse(data),
|
|
429
|
+
validateClient: (data) => finalClientSchema.safeParse(data),
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
// Return the new object containing the schemas AND the validator functions.
|
|
433
|
+
return processedOutput;
|
|
404
434
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.37",
|
|
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",
|