cogsbox-shape 0.5.196 → 0.5.197
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
CHANGED
|
@@ -215,9 +215,13 @@ type RefineEntry = {
|
|
|
215
215
|
deps: string[] | null;
|
|
216
216
|
check: (row: any) => RefinementError | RefinementError[] | undefined | null;
|
|
217
217
|
};
|
|
218
|
-
type RefineHelper = {
|
|
219
|
-
(
|
|
220
|
-
(
|
|
218
|
+
type RefineHelper<T extends ShapeSchema> = {
|
|
219
|
+
(layer: "client", check: (row: InferClientRow<T>) => RefinementError | RefinementError[] | undefined | null, deps?: string | string[]): RefineEntry;
|
|
220
|
+
(layer: "clientInput", check: (row: InferClientInputRow<T>) => RefinementError | RefinementError[] | undefined | null, deps?: string | string[]): RefineEntry;
|
|
221
|
+
(layer: "server", check: (row: InferValidationRow<T>) => RefinementError | RefinementError[] | undefined | null, deps?: string | string[]): RefineEntry;
|
|
222
|
+
(layer: "sql", check: (row: InferSqlRow<T>) => RefinementError | RefinementError[] | undefined | null, deps?: string | string[]): RefineEntry;
|
|
223
|
+
(layer: "all", check: (row: InferClientRow<T>) => RefinementError | RefinementError[] | undefined | null, deps?: string | string[]): RefineEntry;
|
|
224
|
+
(layer: RefineLayer[], check: (row: InferClientRow<T>) => RefinementError | RefinementError[] | undefined | null, deps?: string | string[]): RefineEntry;
|
|
221
225
|
};
|
|
222
226
|
type PickPrimaryKeys<T extends ShapeSchema> = {
|
|
223
227
|
[K in keyof T as T[K] extends {
|
|
@@ -245,6 +249,9 @@ type PickDbFieldKeys<T extends ShapeSchema> = {
|
|
|
245
249
|
} ? never : K : never;
|
|
246
250
|
}[keyof T];
|
|
247
251
|
type InferClientRow<T extends ShapeSchema> = Prettify<z.infer<z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodClientSchema">>>>>;
|
|
252
|
+
type InferClientInputRow<T extends ShapeSchema> = Prettify<z.infer<z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodClientInputSchema">>>>>;
|
|
253
|
+
type InferValidationRow<T extends ShapeSchema> = Prettify<z.infer<z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodValidationSchema">>>>>;
|
|
254
|
+
type InferSqlRow<T extends ShapeSchema> = Prettify<z.infer<z.ZodObject<Prettify<DeriveSchemaByKey<T, "zodSqlSchema">>>>>;
|
|
248
255
|
type SchemaBuilder<T extends ShapeSchema> = Prettify<EnrichFields<T>> & {
|
|
249
256
|
__primaryKeySQL?: string;
|
|
250
257
|
__derives?: {
|
|
@@ -261,7 +268,7 @@ type SchemaBuilder<T extends ShapeSchema> = Prettify<EnrichFields<T>> & {
|
|
|
261
268
|
[K in PickDbFieldKeys<T>]?: (row: InferClientRow<T>) => any;
|
|
262
269
|
};
|
|
263
270
|
}) => SchemaBuilder<T>;
|
|
264
|
-
refine: (fn: (r: RefineHelper) => RefineEntry[]) => SchemaBuilder<T>;
|
|
271
|
+
refine: (fn: (r: RefineHelper<T>) => RefineEntry[]) => SchemaBuilder<T>;
|
|
265
272
|
};
|
|
266
273
|
export declare function schema<T extends string, U extends ShapeSchema<T>>(schema: U): SchemaBuilder<U>;
|
|
267
274
|
export type RelationType = "hasMany" | "hasOne" | "manyToMany";
|
|
@@ -1071,7 +1071,7 @@ describe("refine", () => {
|
|
|
1071
1071
|
password: s.sqlite({ type: "varchar" }).clientInput({ value: "" }),
|
|
1072
1072
|
confirmPassword: s.sqlite({ type: "varchar" }).clientInput({ value: "" }),
|
|
1073
1073
|
}).refine((r) => [
|
|
1074
|
-
r("clientInput", (row) => {
|
|
1074
|
+
r(["clientInput", "client"], (row) => {
|
|
1075
1075
|
if (row.password !== row.confirmPassword) {
|
|
1076
1076
|
return {
|
|
1077
1077
|
path: ["confirmPassword"],
|
|
@@ -10,7 +10,7 @@ describe("refine runtime behavior", () => {
|
|
|
10
10
|
max: s.sqlite({ type: "int", nullable: true }).clientInput({ value: null, schema: z.number().nullable() }),
|
|
11
11
|
label: s.sqlite({ type: "varchar" }).clientInput({ value: "" }),
|
|
12
12
|
}).refine((r) => [
|
|
13
|
-
r("clientInput", (row) => {
|
|
13
|
+
r(["clientInput", "client"], (row) => {
|
|
14
14
|
if (row.min !== null && row.max !== null && row.min >= row.max) {
|
|
15
15
|
return { path: ["max"], message: "Max must be > min" };
|
|
16
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cogsbox-shape",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.197",
|
|
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",
|