@buildnbuzz/buzzform 0.1.1 → 0.1.3
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/README.md +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -14
- package/dist/index.mjs.map +1 -1
- package/dist/schema.d.mts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js.map +1 -1
- package/dist/{utils-Dzp_68i3.d.mts → utils-BRY27BLX.d.mts} +54 -77
- package/dist/{utils-CS2VrTJU.d.ts → utils-DgwUn6tN.d.ts} +54 -77
- package/package.json +1 -1
|
@@ -1,108 +1,85 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { F as Field, T as TextField, E as EmailField, P as PasswordField, o as TextareaField, N as NumberField, D as DateField, p as DatetimeField, r as SelectField, s as CheckboxField, t as SwitchField, u as RadioField, w as TagsField, x as UploadField, G as GroupField, y as ArrayField, z as RowField, I as TabsField, J as CollapsibleField, V as ValidationContext, K as FieldType, i as ValidationFn, A as ArrayHelpers } from './adapter-nQW28cyO.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
type ExtractL1<F> = F extends {
|
|
5
|
+
type: "row" | "collapsible";
|
|
6
|
+
fields: infer Nested extends readonly Field[];
|
|
7
|
+
} ? Nested[number] : F extends {
|
|
8
|
+
type: "tabs";
|
|
9
|
+
tabs: readonly (infer T)[];
|
|
10
|
+
} ? T extends {
|
|
11
|
+
fields: infer TabFields extends readonly Field[];
|
|
12
|
+
} ? TabFields[number] : never : F;
|
|
13
|
+
type ExtractL2<F> = ExtractL1<ExtractL1<F>>;
|
|
14
|
+
type ExtractL3<F> = ExtractL1<ExtractL2<F>>;
|
|
15
|
+
type ExtractL4<F> = ExtractL1<ExtractL3<F>>;
|
|
16
|
+
type FlattenedFields<F> = ExtractL4<F>;
|
|
17
|
+
type MakeOptional<T extends z.ZodTypeAny, F extends Field> = F extends {
|
|
18
|
+
required: true;
|
|
19
|
+
} ? T : z.ZodOptional<T>;
|
|
20
|
+
type InnerFieldsShape<T extends readonly Field[]> = {
|
|
21
|
+
[K in FlattenedFields<T[number]> as K extends {
|
|
22
|
+
name: infer N extends string;
|
|
23
|
+
} ? N : never]: K extends Field ? InnerFieldToZod<K> : never;
|
|
24
|
+
};
|
|
25
|
+
type InnerFieldToZod<F extends Field> = MakeOptional<InnerBaseFieldType<F>, F>;
|
|
26
|
+
type InnerBaseFieldType<F extends Field> = F extends {
|
|
11
27
|
schema: infer S extends z.ZodTypeAny;
|
|
12
28
|
} ? S : F extends {
|
|
13
|
-
type:
|
|
14
|
-
hasMany: true;
|
|
15
|
-
} ? z.ZodArray<z.ZodString> : F extends {
|
|
16
|
-
type: 'email';
|
|
17
|
-
hasMany: true;
|
|
18
|
-
} ? z.ZodArray<z.ZodString> : F extends {
|
|
19
|
-
type: 'text';
|
|
29
|
+
type: "text";
|
|
20
30
|
} ? z.ZodString : F extends {
|
|
21
|
-
type:
|
|
31
|
+
type: "email";
|
|
22
32
|
} ? z.ZodString : F extends {
|
|
23
|
-
type:
|
|
33
|
+
type: "password";
|
|
24
34
|
} ? z.ZodString : F extends {
|
|
25
|
-
type:
|
|
35
|
+
type: "textarea";
|
|
26
36
|
} ? z.ZodString : F extends {
|
|
27
|
-
type:
|
|
37
|
+
type: "number";
|
|
28
38
|
} ? z.ZodNumber : F extends {
|
|
29
|
-
type:
|
|
39
|
+
type: "date";
|
|
30
40
|
} ? z.ZodDate : F extends {
|
|
31
|
-
type:
|
|
41
|
+
type: "datetime";
|
|
32
42
|
} ? z.ZodDate : F extends {
|
|
33
|
-
type:
|
|
43
|
+
type: "checkbox";
|
|
34
44
|
} ? z.ZodBoolean : F extends {
|
|
35
|
-
type:
|
|
45
|
+
type: "switch";
|
|
36
46
|
} ? z.ZodBoolean : F extends {
|
|
37
|
-
type:
|
|
47
|
+
type: "select";
|
|
38
48
|
hasMany: true;
|
|
39
49
|
} ? z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>> : F extends {
|
|
40
|
-
type:
|
|
50
|
+
type: "select";
|
|
41
51
|
} ? z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]> : F extends {
|
|
42
|
-
type:
|
|
52
|
+
type: "radio";
|
|
43
53
|
} ? z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]> : F extends {
|
|
44
|
-
type:
|
|
54
|
+
type: "tags";
|
|
45
55
|
} ? z.ZodArray<z.ZodString> : F extends {
|
|
46
|
-
type:
|
|
56
|
+
type: "upload";
|
|
47
57
|
hasMany: true;
|
|
48
58
|
} ? z.ZodArray<z.ZodUnion<[z.ZodType<File>, z.ZodString]>> : F extends {
|
|
49
|
-
type:
|
|
50
|
-
} ? z.ZodUnion<[z.ZodType<File>, z.ZodString]> :
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* { type: 'text', name: 'email' },
|
|
60
|
-
* { type: 'number', name: 'age' },
|
|
61
|
-
* ] as const;
|
|
62
|
-
*
|
|
63
|
-
* type Shape = FieldsToShape<typeof fields>;
|
|
64
|
-
* // { email: z.ZodString; age: z.ZodNumber }
|
|
65
|
-
*/
|
|
66
|
-
type FieldsToShape<T extends readonly Field[]> = {
|
|
67
|
-
[K in T[number] as K extends {
|
|
68
|
-
name: infer N extends string;
|
|
69
|
-
} ? N : never]: K extends {
|
|
70
|
-
name: string;
|
|
71
|
-
} ? FieldToZod<K> : never;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Function signature for field schema builders.
|
|
75
|
-
* Each field type has a builder that converts the field config to a Zod schema.
|
|
76
|
-
*/
|
|
59
|
+
type: "upload";
|
|
60
|
+
} ? z.ZodUnion<[z.ZodType<File>, z.ZodString]> : F extends {
|
|
61
|
+
type: "group";
|
|
62
|
+
fields: infer Nested extends readonly Field[];
|
|
63
|
+
} ? z.ZodObject<InnerFieldsShape<Nested>> : F extends {
|
|
64
|
+
type: "array";
|
|
65
|
+
fields: infer Nested extends readonly Field[];
|
|
66
|
+
} ? z.ZodArray<z.ZodObject<InnerFieldsShape<Nested>>> : z.ZodTypeAny;
|
|
67
|
+
type FieldToZod<F extends Field> = MakeOptional<InnerBaseFieldType<F>, F>;
|
|
68
|
+
type FieldsToShape<T extends readonly Field[]> = InnerFieldsShape<T>;
|
|
77
69
|
type SchemaBuilder<TField extends Field = Field> = (field: TField) => z.ZodTypeAny;
|
|
78
|
-
/**
|
|
79
|
-
* Map of field types to their schema builders.
|
|
80
|
-
*/
|
|
81
70
|
type SchemaBuilderMap = {
|
|
82
|
-
[K in Field[
|
|
71
|
+
[K in Field["type"]]?: SchemaBuilder<Extract<Field, {
|
|
83
72
|
type: K;
|
|
84
73
|
}>>;
|
|
85
74
|
};
|
|
86
75
|
/**
|
|
87
76
|
* Infer the TypeScript type from a BuzzForm schema.
|
|
88
|
-
*
|
|
89
|
-
* Use this instead of `z.infer<typeof schema>` to avoid needing to import
|
|
90
|
-
* `z` from `@buildnbuzz/buzzform/zod`.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* import { createSchema, type InferSchema } from '@buildnbuzz/buzzform';
|
|
94
|
-
*
|
|
95
|
-
* const loginSchema = createSchema([
|
|
96
|
-
* { type: 'email', name: 'email', required: true },
|
|
97
|
-
* { type: 'password', name: 'password', required: true },
|
|
98
|
-
* ]);
|
|
99
|
-
*
|
|
100
|
-
* type LoginFormData = InferSchema<typeof loginSchema>;
|
|
101
|
-
* // { email: string; password: string }
|
|
102
|
-
*
|
|
103
|
-
* @see {@link https://form.buildnbuzz.com/docs/type-inference Type Inference Guide}
|
|
104
77
|
*/
|
|
105
|
-
type
|
|
78
|
+
type InferType<T extends z.ZodTypeAny> = z.infer<T>;
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated Use `InferType` instead. This will be removed in a future version.
|
|
81
|
+
*/
|
|
82
|
+
type InferSchema<T extends z.ZodTypeAny> = InferType<T>;
|
|
106
83
|
|
|
107
84
|
/**
|
|
108
85
|
* Strict field typing utilities for compile-time validation.
|
|
@@ -243,4 +220,4 @@ declare function setNestedValue<T extends Record<string, unknown>>(obj: T, path:
|
|
|
243
220
|
*/
|
|
244
221
|
declare function formatBytes(bytes: number, decimals?: number): string;
|
|
245
222
|
|
|
246
|
-
export { type FieldToZod as F, type
|
|
223
|
+
export { type FieldToZod as F, type InferType as I, type SchemaBuilder as S, type FieldsToShape as a, type SchemaBuilderMap as b, type InferSchema as c, createSchema as d, extractValidationConfig as e, fieldsToZodSchema as f, coerceToNumber as g, coerceToDate as h, getPatternErrorMessage as i, isFileLike as j, isFileTypeAccepted as k, createArrayHelpers as l, makeOptional as m, generateFieldId as n, getNestedValue as o, formatBytes as p, collectFieldValidators as q, getSiblingData as r, setNestedValue as s, getValueByPath as t, type FieldValidator as u };
|
|
@@ -1,108 +1,85 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { F as Field, T as TextField, E as EmailField, P as PasswordField, o as TextareaField, N as NumberField, D as DateField, p as DatetimeField, r as SelectField, s as CheckboxField, t as SwitchField, u as RadioField, w as TagsField, x as UploadField, G as GroupField, y as ArrayField, z as RowField, I as TabsField, J as CollapsibleField, V as ValidationContext, K as FieldType, i as ValidationFn, A as ArrayHelpers } from './adapter-nQW28cyO.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
type ExtractL1<F> = F extends {
|
|
5
|
+
type: "row" | "collapsible";
|
|
6
|
+
fields: infer Nested extends readonly Field[];
|
|
7
|
+
} ? Nested[number] : F extends {
|
|
8
|
+
type: "tabs";
|
|
9
|
+
tabs: readonly (infer T)[];
|
|
10
|
+
} ? T extends {
|
|
11
|
+
fields: infer TabFields extends readonly Field[];
|
|
12
|
+
} ? TabFields[number] : never : F;
|
|
13
|
+
type ExtractL2<F> = ExtractL1<ExtractL1<F>>;
|
|
14
|
+
type ExtractL3<F> = ExtractL1<ExtractL2<F>>;
|
|
15
|
+
type ExtractL4<F> = ExtractL1<ExtractL3<F>>;
|
|
16
|
+
type FlattenedFields<F> = ExtractL4<F>;
|
|
17
|
+
type MakeOptional<T extends z.ZodTypeAny, F extends Field> = F extends {
|
|
18
|
+
required: true;
|
|
19
|
+
} ? T : z.ZodOptional<T>;
|
|
20
|
+
type InnerFieldsShape<T extends readonly Field[]> = {
|
|
21
|
+
[K in FlattenedFields<T[number]> as K extends {
|
|
22
|
+
name: infer N extends string;
|
|
23
|
+
} ? N : never]: K extends Field ? InnerFieldToZod<K> : never;
|
|
24
|
+
};
|
|
25
|
+
type InnerFieldToZod<F extends Field> = MakeOptional<InnerBaseFieldType<F>, F>;
|
|
26
|
+
type InnerBaseFieldType<F extends Field> = F extends {
|
|
11
27
|
schema: infer S extends z.ZodTypeAny;
|
|
12
28
|
} ? S : F extends {
|
|
13
|
-
type:
|
|
14
|
-
hasMany: true;
|
|
15
|
-
} ? z.ZodArray<z.ZodString> : F extends {
|
|
16
|
-
type: 'email';
|
|
17
|
-
hasMany: true;
|
|
18
|
-
} ? z.ZodArray<z.ZodString> : F extends {
|
|
19
|
-
type: 'text';
|
|
29
|
+
type: "text";
|
|
20
30
|
} ? z.ZodString : F extends {
|
|
21
|
-
type:
|
|
31
|
+
type: "email";
|
|
22
32
|
} ? z.ZodString : F extends {
|
|
23
|
-
type:
|
|
33
|
+
type: "password";
|
|
24
34
|
} ? z.ZodString : F extends {
|
|
25
|
-
type:
|
|
35
|
+
type: "textarea";
|
|
26
36
|
} ? z.ZodString : F extends {
|
|
27
|
-
type:
|
|
37
|
+
type: "number";
|
|
28
38
|
} ? z.ZodNumber : F extends {
|
|
29
|
-
type:
|
|
39
|
+
type: "date";
|
|
30
40
|
} ? z.ZodDate : F extends {
|
|
31
|
-
type:
|
|
41
|
+
type: "datetime";
|
|
32
42
|
} ? z.ZodDate : F extends {
|
|
33
|
-
type:
|
|
43
|
+
type: "checkbox";
|
|
34
44
|
} ? z.ZodBoolean : F extends {
|
|
35
|
-
type:
|
|
45
|
+
type: "switch";
|
|
36
46
|
} ? z.ZodBoolean : F extends {
|
|
37
|
-
type:
|
|
47
|
+
type: "select";
|
|
38
48
|
hasMany: true;
|
|
39
49
|
} ? z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>> : F extends {
|
|
40
|
-
type:
|
|
50
|
+
type: "select";
|
|
41
51
|
} ? z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]> : F extends {
|
|
42
|
-
type:
|
|
52
|
+
type: "radio";
|
|
43
53
|
} ? z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]> : F extends {
|
|
44
|
-
type:
|
|
54
|
+
type: "tags";
|
|
45
55
|
} ? z.ZodArray<z.ZodString> : F extends {
|
|
46
|
-
type:
|
|
56
|
+
type: "upload";
|
|
47
57
|
hasMany: true;
|
|
48
58
|
} ? z.ZodArray<z.ZodUnion<[z.ZodType<File>, z.ZodString]>> : F extends {
|
|
49
|
-
type:
|
|
50
|
-
} ? z.ZodUnion<[z.ZodType<File>, z.ZodString]> :
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* { type: 'text', name: 'email' },
|
|
60
|
-
* { type: 'number', name: 'age' },
|
|
61
|
-
* ] as const;
|
|
62
|
-
*
|
|
63
|
-
* type Shape = FieldsToShape<typeof fields>;
|
|
64
|
-
* // { email: z.ZodString; age: z.ZodNumber }
|
|
65
|
-
*/
|
|
66
|
-
type FieldsToShape<T extends readonly Field[]> = {
|
|
67
|
-
[K in T[number] as K extends {
|
|
68
|
-
name: infer N extends string;
|
|
69
|
-
} ? N : never]: K extends {
|
|
70
|
-
name: string;
|
|
71
|
-
} ? FieldToZod<K> : never;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Function signature for field schema builders.
|
|
75
|
-
* Each field type has a builder that converts the field config to a Zod schema.
|
|
76
|
-
*/
|
|
59
|
+
type: "upload";
|
|
60
|
+
} ? z.ZodUnion<[z.ZodType<File>, z.ZodString]> : F extends {
|
|
61
|
+
type: "group";
|
|
62
|
+
fields: infer Nested extends readonly Field[];
|
|
63
|
+
} ? z.ZodObject<InnerFieldsShape<Nested>> : F extends {
|
|
64
|
+
type: "array";
|
|
65
|
+
fields: infer Nested extends readonly Field[];
|
|
66
|
+
} ? z.ZodArray<z.ZodObject<InnerFieldsShape<Nested>>> : z.ZodTypeAny;
|
|
67
|
+
type FieldToZod<F extends Field> = MakeOptional<InnerBaseFieldType<F>, F>;
|
|
68
|
+
type FieldsToShape<T extends readonly Field[]> = InnerFieldsShape<T>;
|
|
77
69
|
type SchemaBuilder<TField extends Field = Field> = (field: TField) => z.ZodTypeAny;
|
|
78
|
-
/**
|
|
79
|
-
* Map of field types to their schema builders.
|
|
80
|
-
*/
|
|
81
70
|
type SchemaBuilderMap = {
|
|
82
|
-
[K in Field[
|
|
71
|
+
[K in Field["type"]]?: SchemaBuilder<Extract<Field, {
|
|
83
72
|
type: K;
|
|
84
73
|
}>>;
|
|
85
74
|
};
|
|
86
75
|
/**
|
|
87
76
|
* Infer the TypeScript type from a BuzzForm schema.
|
|
88
|
-
*
|
|
89
|
-
* Use this instead of `z.infer<typeof schema>` to avoid needing to import
|
|
90
|
-
* `z` from `@buildnbuzz/buzzform/zod`.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* import { createSchema, type InferSchema } from '@buildnbuzz/buzzform';
|
|
94
|
-
*
|
|
95
|
-
* const loginSchema = createSchema([
|
|
96
|
-
* { type: 'email', name: 'email', required: true },
|
|
97
|
-
* { type: 'password', name: 'password', required: true },
|
|
98
|
-
* ]);
|
|
99
|
-
*
|
|
100
|
-
* type LoginFormData = InferSchema<typeof loginSchema>;
|
|
101
|
-
* // { email: string; password: string }
|
|
102
|
-
*
|
|
103
|
-
* @see {@link https://form.buildnbuzz.com/docs/type-inference Type Inference Guide}
|
|
104
77
|
*/
|
|
105
|
-
type
|
|
78
|
+
type InferType<T extends z.ZodTypeAny> = z.infer<T>;
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated Use `InferType` instead. This will be removed in a future version.
|
|
81
|
+
*/
|
|
82
|
+
type InferSchema<T extends z.ZodTypeAny> = InferType<T>;
|
|
106
83
|
|
|
107
84
|
/**
|
|
108
85
|
* Strict field typing utilities for compile-time validation.
|
|
@@ -243,4 +220,4 @@ declare function setNestedValue<T extends Record<string, unknown>>(obj: T, path:
|
|
|
243
220
|
*/
|
|
244
221
|
declare function formatBytes(bytes: number, decimals?: number): string;
|
|
245
222
|
|
|
246
|
-
export { type FieldToZod as F, type
|
|
223
|
+
export { type FieldToZod as F, type InferType as I, type SchemaBuilder as S, type FieldsToShape as a, type SchemaBuilderMap as b, type InferSchema as c, createSchema as d, extractValidationConfig as e, fieldsToZodSchema as f, coerceToNumber as g, coerceToDate as h, getPatternErrorMessage as i, isFileLike as j, isFileTypeAccepted as k, createArrayHelpers as l, makeOptional as m, generateFieldId as n, getNestedValue as o, formatBytes as p, collectFieldValidators as q, getSiblingData as r, setNestedValue as s, getValueByPath as t, type FieldValidator as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildnbuzz/buzzform",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Simple React form library for shadcn/ui. Declare fields, customize rendering, get live validation with minimal boilerplate.",
|
|
5
5
|
"author": "Parth Lad <parth@buildnbuzz.com>",
|
|
6
6
|
"license": "MIT",
|