@form-instant/react-resolver-zod 1.18.12 → 2.0.0-rc.2
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/components/FormInstantProvider.d.ts +10 -0
- package/dist/components/SchemaMapper.d.ts +24 -0
- package/dist/examples/completeExample.d.ts +6 -0
- package/dist/examples/fieldConfigExample.d.ts +158 -0
- package/dist/examples/formInstantExample.d.ts +6 -0
- package/dist/examples/legacyCompatibility.d.ts +30 -0
- package/dist/hooks/useSchema.d.ts +11 -0
- package/dist/hooks/useSchemaMapping.d.ts +22 -0
- package/dist/hooks/useSchemaMetadata.d.ts +26 -0
- package/dist/hooks/useSchemaNavigation.d.ts +18 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +2 -7
- package/dist/index.js.map +14 -0
- package/dist/types.d.ts +48 -0
- package/dist/utils/pathResolver.d.ts +26 -0
- package/dist/utils/schemaParser.d.ts +19 -0
- package/dist/utils/zodExtensions.d.ts +7 -0
- package/package.json +60 -58
- package/dist/context.d.ts +0 -2
- package/dist/funcs/default-values.d.ts +0 -4
- package/dist/funcs/field-config.d.ts +0 -11
- package/dist/funcs/field-type-inference.d.ts +0 -3
- package/dist/funcs/index.d.ts +0 -5
- package/dist/funcs/schema-parser.d.ts +0 -2
- package/dist/funcs/types.d.ts +0 -11
- package/dist/provider.d.ts +0 -6
- package/dist/react-resolver-zod.cjs.development.js +0 -416
- package/dist/react-resolver-zod.cjs.development.js.map +0 -1
- package/dist/react-resolver-zod.cjs.production.min.js +0 -2
- package/dist/react-resolver-zod.cjs.production.min.js.map +0 -1
- package/dist/react-resolver-zod.esm.js +0 -401
- package/dist/react-resolver-zod.esm.js.map +0 -1
- package/dist/type.d.ts +0 -2
- package/dist/useSchema.d.ts +0 -14
- /package/dist/{element.d.ts → components/FormInstantElement.d.ts} +0 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { zodResolverProps } from 'types';
|
3
|
+
export declare const ZodResolverContext: import("react").Context<any>;
|
4
|
+
export declare const FormInstantProvider: FCC<{
|
5
|
+
schema: zodResolverProps;
|
6
|
+
}>;
|
7
|
+
/**
|
8
|
+
* Hook to get a specific field by name from the schema
|
9
|
+
*/
|
10
|
+
export declare const useFields: <Sc extends Record<string, any>>(key: keyof Sc) => any;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { SchemaMapperProps, ElementProps } from '../types';
|
2
|
+
/**
|
3
|
+
* Main component for mapping Zod schemas to React components
|
4
|
+
* Provides an agnostic way to map schema fields to components
|
5
|
+
*/
|
6
|
+
export declare function SchemaMapper({ schema, componentMapping, defaultComponent, transformProps, children, }: SchemaMapperProps): import("react/jsx-runtime").JSX.Element;
|
7
|
+
/**
|
8
|
+
* Hook to use schema mapping context
|
9
|
+
*/
|
10
|
+
export declare function useSchemaMappingContext(): {
|
11
|
+
metadata: any;
|
12
|
+
mappingConfig: any;
|
13
|
+
};
|
14
|
+
/**
|
15
|
+
* Component for rendering a specific field by name
|
16
|
+
* Maintains backward compatibility with the old Element component
|
17
|
+
*/
|
18
|
+
export declare function FormInstantElement<S extends Record<string, any>>({ name }: ElementProps<S>): import("react/jsx-runtime").JSX.Element | null;
|
19
|
+
/**
|
20
|
+
* Component for rendering a field by path
|
21
|
+
*/
|
22
|
+
export declare function SchemaField({ path }: {
|
23
|
+
path: string;
|
24
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
@@ -0,0 +1,6 @@
|
|
1
|
+
export declare function UserFormExample1(): import("react/jsx-runtime").JSX.Element;
|
2
|
+
export declare function UserFormExample2(): import("react/jsx-runtime").JSX.Element;
|
3
|
+
export declare function UserFormExample3(): import("react/jsx-runtime").JSX.Element;
|
4
|
+
export declare function CustomUserForm(): import("react/jsx-runtime").JSX.Element;
|
5
|
+
export declare function UserFormWithValidation(): import("react/jsx-runtime").JSX.Element;
|
6
|
+
export declare const styles = "\n.user-form {\n max-width: 600px;\n margin: 0 auto;\n padding: 20px;\n}\n\n.form-section {\n margin-bottom: 30px;\n padding: 20px;\n border: 1px solid #e0e0e0;\n border-radius: 8px;\n}\n\n.form-section h3 {\n margin-top: 0;\n color: #333;\n border-bottom: 2px solid #007bff;\n padding-bottom: 10px;\n}\n\n.form-field {\n margin-bottom: 20px;\n}\n\n.form-label {\n display: block;\n margin-bottom: 5px;\n font-weight: 600;\n color: #333;\n}\n\n.required {\n color: #dc3545;\n margin-left: 4px;\n}\n\n.form-input,\n.form-select,\n.form-textarea {\n width: 100%;\n padding: 10px;\n border: 1px solid #ddd;\n border-radius: 4px;\n font-size: 14px;\n}\n\n.form-input:focus,\n.form-select:focus,\n.form-textarea:focus {\n outline: none;\n border-color: #007bff;\n box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);\n}\n\n.checkbox {\n display: flex;\n align-items: flex-start;\n}\n\n.checkbox-label {\n display: flex;\n align-items: center;\n cursor: pointer;\n}\n\n.form-checkbox {\n margin-right: 8px;\n}\n\n.checkbox-text {\n font-weight: 500;\n}\n\n.field-description {\n margin-top: 5px;\n font-size: 12px;\n color: #666;\n}\n\n.validation-message {\n margin-top: 5px;\n font-size: 12px;\n color: #dc3545;\n}\n\n.async-validation {\n margin-top: 5px;\n font-size: 12px;\n color: #007bff;\n}\n\n.field-info {\n margin-top: 5px;\n font-size: 12px;\n color: #28a745;\n background: #f8f9fa;\n padding: 5px;\n border-radius: 3px;\n}\n\n.field-debug {\n margin-top: 5px;\n padding: 5px;\n background: #f8f9fa;\n border-radius: 3px;\n font-family: monospace;\n}\n\n.form-actions {\n margin-top: 30px;\n text-align: center;\n}\n\n.submit-button {\n background: #007bff;\n color: white;\n border: none;\n padding: 12px 30px;\n border-radius: 4px;\n font-size: 16px;\n cursor: pointer;\n transition: background-color 0.2s;\n}\n\n.submit-button:hover {\n background: #0056b3;\n}\n";
|
@@ -0,0 +1,158 @@
|
|
1
|
+
import { BaseFieldConfigOptions } from '../utils/zodExtensions';
|
2
|
+
interface UserFieldConfig extends BaseFieldConfigOptions {
|
3
|
+
dp?: Record<string, any>;
|
4
|
+
userSpecific?: {
|
5
|
+
minAge?: number;
|
6
|
+
maxAge?: number;
|
7
|
+
};
|
8
|
+
}
|
9
|
+
export declare function createUserSchema(): import("zod").ZodObject<{
|
10
|
+
name: import("zod").ZodString;
|
11
|
+
email: import("zod").ZodString;
|
12
|
+
age: import("zod").ZodOptional<import("zod").ZodNumber>;
|
13
|
+
isActive: import("zod").ZodBoolean;
|
14
|
+
role: import("zod").ZodEnum<{
|
15
|
+
[x: string]: string;
|
16
|
+
}>;
|
17
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
18
|
+
fieldConfig: <TConfig = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodObject<{
|
19
|
+
name: import("zod").ZodString;
|
20
|
+
email: import("zod").ZodString;
|
21
|
+
age: import("zod").ZodOptional<import("zod").ZodNumber>;
|
22
|
+
isActive: import("zod").ZodBoolean;
|
23
|
+
role: import("zod").ZodEnum<{
|
24
|
+
[x: string]: string;
|
25
|
+
}>;
|
26
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
27
|
+
};
|
28
|
+
export declare function createProfileSchema(): import("zod").ZodObject<{
|
29
|
+
user: import("zod").ZodObject<{
|
30
|
+
profile: import("zod").ZodObject<{
|
31
|
+
email: import("zod").ZodString;
|
32
|
+
name: import("zod").ZodString;
|
33
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
34
|
+
fieldConfig: <TConfig = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodObject<{
|
35
|
+
email: import("zod").ZodString;
|
36
|
+
name: import("zod").ZodString;
|
37
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
38
|
+
};
|
39
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
40
|
+
fieldConfig: <TConfig_1 = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig_1>) => import("zod").ZodObject<{
|
41
|
+
profile: import("zod").ZodObject<{
|
42
|
+
email: import("zod").ZodString;
|
43
|
+
name: import("zod").ZodString;
|
44
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
45
|
+
fieldConfig: <TConfig = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodObject<{
|
46
|
+
email: import("zod").ZodString;
|
47
|
+
name: import("zod").ZodString;
|
48
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
49
|
+
};
|
50
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
51
|
+
};
|
52
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
53
|
+
fieldConfig: <TConfig_2 = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig_2>) => import("zod").ZodObject<{
|
54
|
+
user: import("zod").ZodObject<{
|
55
|
+
profile: import("zod").ZodObject<{
|
56
|
+
email: import("zod").ZodString;
|
57
|
+
name: import("zod").ZodString;
|
58
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
59
|
+
fieldConfig: <TConfig = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodObject<{
|
60
|
+
email: import("zod").ZodString;
|
61
|
+
name: import("zod").ZodString;
|
62
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
63
|
+
};
|
64
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
65
|
+
fieldConfig: <TConfig_1 = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig_1>) => import("zod").ZodObject<{
|
66
|
+
profile: import("zod").ZodObject<{
|
67
|
+
email: import("zod").ZodString;
|
68
|
+
name: import("zod").ZodString;
|
69
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
70
|
+
fieldConfig: <TConfig = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodObject<{
|
71
|
+
email: import("zod").ZodString;
|
72
|
+
name: import("zod").ZodString;
|
73
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
74
|
+
};
|
75
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
76
|
+
};
|
77
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
78
|
+
};
|
79
|
+
export declare function createFormSchema(): import("zod").ZodObject<{
|
80
|
+
step1: import("zod").ZodObject<{
|
81
|
+
firstName: import("zod").ZodString;
|
82
|
+
lastName: import("zod").ZodString;
|
83
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
84
|
+
fieldConfig: <TConfig = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodObject<{
|
85
|
+
firstName: import("zod").ZodString;
|
86
|
+
lastName: import("zod").ZodString;
|
87
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
88
|
+
};
|
89
|
+
step2: import("zod").ZodObject<{
|
90
|
+
email: import("zod").ZodString;
|
91
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
92
|
+
fieldConfig: <TConfig_1 = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig_1>) => import("zod").ZodObject<{
|
93
|
+
email: import("zod").ZodString;
|
94
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
95
|
+
};
|
96
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
97
|
+
fieldConfig: <TConfig_2 = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig_2>) => import("zod").ZodObject<{
|
98
|
+
step1: import("zod").ZodObject<{
|
99
|
+
firstName: import("zod").ZodString;
|
100
|
+
lastName: import("zod").ZodString;
|
101
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
102
|
+
fieldConfig: <TConfig = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodObject<{
|
103
|
+
firstName: import("zod").ZodString;
|
104
|
+
lastName: import("zod").ZodString;
|
105
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
106
|
+
};
|
107
|
+
step2: import("zod").ZodObject<{
|
108
|
+
email: import("zod").ZodString;
|
109
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
110
|
+
fieldConfig: <TConfig_1 = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig_1>) => import("zod").ZodObject<{
|
111
|
+
email: import("zod").ZodString;
|
112
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
113
|
+
};
|
114
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
115
|
+
};
|
116
|
+
export declare function createUsersArraySchema(): import("zod").ZodObject<{
|
117
|
+
users: import("zod").ZodArray<import("zod").ZodObject<{
|
118
|
+
name: import("zod").ZodString;
|
119
|
+
email: import("zod").ZodString;
|
120
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
121
|
+
fieldConfig: <TConfig = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodObject<{
|
122
|
+
name: import("zod").ZodString;
|
123
|
+
email: import("zod").ZodString;
|
124
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
125
|
+
}>;
|
126
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
127
|
+
fieldConfig: <TConfig_1 = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig_1>) => import("zod").ZodObject<{
|
128
|
+
users: import("zod").ZodArray<import("zod").ZodObject<{
|
129
|
+
name: import("zod").ZodString;
|
130
|
+
email: import("zod").ZodString;
|
131
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
132
|
+
fieldConfig: <TConfig = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodObject<{
|
133
|
+
name: import("zod").ZodString;
|
134
|
+
email: import("zod").ZodString;
|
135
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
136
|
+
}>;
|
137
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
138
|
+
};
|
139
|
+
export declare function getFieldConfiguration(): {
|
140
|
+
fieldType: "text";
|
141
|
+
} & {
|
142
|
+
label: string;
|
143
|
+
placeholder?: string | undefined;
|
144
|
+
maxLength?: number | undefined;
|
145
|
+
} & UserFieldConfig;
|
146
|
+
export declare function legacyCompatibilityExample(): import("zod").ZodObject<{
|
147
|
+
name: import("zod").ZodString & {
|
148
|
+
fieldConfig: <TConfig = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodString;
|
149
|
+
};
|
150
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
151
|
+
export declare function defaultTypeExample(): import("zod").ZodObject<{
|
152
|
+
simpleField: import("zod").ZodString;
|
153
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
154
|
+
fieldConfig: <TConfig = BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodObject<{
|
155
|
+
simpleField: import("zod").ZodString;
|
156
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
157
|
+
};
|
158
|
+
export {};
|
@@ -0,0 +1,6 @@
|
|
1
|
+
export declare function UserFormExample1(): import("react/jsx-runtime").JSX.Element;
|
2
|
+
export declare function UserFormExample2(): import("react/jsx-runtime").JSX.Element;
|
3
|
+
export declare function UserFormExample3(): import("react/jsx-runtime").JSX.Element;
|
4
|
+
export declare function UserFormWithHooks(): import("react/jsx-runtime").JSX.Element;
|
5
|
+
export declare function UserFormWithValidation(): import("react/jsx-runtime").JSX.Element;
|
6
|
+
export declare const styles = "\n.user-form {\n max-width: 600px;\n margin: 0 auto;\n padding: 20px;\n}\n\n.form-section {\n margin-bottom: 30px;\n padding: 20px;\n border: 1px solid #e0e0e0;\n border-radius: 8px;\n}\n\n.form-section h3 {\n margin-top: 0;\n color: #333;\n border-bottom: 2px solid #007bff;\n padding-bottom: 10px;\n}\n\n.form-field {\n margin-bottom: 20px;\n}\n\n.form-label {\n display: block;\n margin-bottom: 5px;\n font-weight: 600;\n color: #333;\n}\n\n.required {\n color: #dc3545;\n margin-left: 4px;\n}\n\n.form-input,\n.form-select,\n.form-textarea {\n width: 100%;\n padding: 10px;\n border: 1px solid #ddd;\n border-radius: 4px;\n font-size: 14px;\n}\n\n.form-input:focus,\n.form-select:focus,\n.form-textarea:focus {\n outline: none;\n border-color: #007bff;\n box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);\n}\n\n.checkbox {\n display: flex;\n align-items: flex-start;\n}\n\n.checkbox-label {\n display: flex;\n align-items: center;\n cursor: pointer;\n}\n\n.form-checkbox {\n margin-right: 8px;\n}\n\n.checkbox-text {\n font-weight: 500;\n}\n\n.field-description {\n margin-top: 5px;\n font-size: 12px;\n color: #666;\n}\n\n.validation-message {\n margin-top: 5px;\n font-size: 12px;\n color: #dc3545;\n}\n\n.async-validation {\n margin-top: 5px;\n font-size: 12px;\n color: #007bff;\n}\n\n.field-info {\n margin-top: 5px;\n font-size: 12px;\n color: #28a745;\n background: #f8f9fa;\n padding: 5px;\n border-radius: 3px;\n}\n\n.form-actions {\n margin-top: 30px;\n text-align: center;\n}\n\n.submit-button {\n background: #007bff;\n color: white;\n border: none;\n padding: 12px 30px;\n border-radius: 4px;\n font-size: 16px;\n cursor: pointer;\n transition: background-color 0.2s;\n}\n\n.submit-button:hover {\n background: #0056b3;\n}\n\n.form-data-display {\n margin-bottom: 30px;\n padding: 20px;\n background: #f8f9fa;\n border-radius: 8px;\n}\n\n.data-section {\n margin-bottom: 20px;\n}\n\n.data-section h5 {\n margin-bottom: 10px;\n color: #333;\n}\n\n.data-section pre {\n background: #fff;\n padding: 10px;\n border-radius: 4px;\n border: 1px solid #ddd;\n font-size: 12px;\n overflow-x: auto;\n}\n";
|
@@ -0,0 +1,30 @@
|
|
1
|
+
export declare function createLegacyCompatibleSchema(): import("zod").ZodObject<{
|
2
|
+
name: import("zod").ZodString & {
|
3
|
+
fieldConfig: <TConfig = import("../utils/zodExtensions").BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodString;
|
4
|
+
};
|
5
|
+
email: import("zod").ZodString & {
|
6
|
+
fieldConfig: <TConfig = import("../utils/zodExtensions").BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodString;
|
7
|
+
};
|
8
|
+
age: import("zod").ZodOptional<import("zod").ZodNumber & {
|
9
|
+
fieldConfig: <TConfig_1 = import("../utils/zodExtensions").BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig_1>) => import("zod").ZodNumber;
|
10
|
+
}>;
|
11
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
12
|
+
export declare function useLegacySchema(): any;
|
13
|
+
export declare function migrationExample(): {
|
14
|
+
oldSchema: import("zod").ZodObject<{
|
15
|
+
name: import("zod").ZodString & {
|
16
|
+
fieldConfig: <TConfig = import("../utils/zodExtensions").BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodString;
|
17
|
+
};
|
18
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
19
|
+
newSchema: import("zod").ZodObject<{
|
20
|
+
name: import("zod").ZodString & {
|
21
|
+
fieldConfig: <TConfig = import("../utils/zodExtensions").BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodString;
|
22
|
+
};
|
23
|
+
}, import("zod/v4/core/schemas.cjs").$strip> & {
|
24
|
+
fieldConfig: <TConfig_1 = import("../utils/zodExtensions").BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig_1>) => import("zod").ZodObject<{
|
25
|
+
name: import("zod").ZodString & {
|
26
|
+
fieldConfig: <TConfig = import("../utils/zodExtensions").BaseFieldConfigOptions>(config: import("../utils/zodExtensions").FieldConfigOptions<TConfig>) => import("zod").ZodString;
|
27
|
+
};
|
28
|
+
}, import("zod/v4/core/schemas.cjs").$strip>;
|
29
|
+
};
|
30
|
+
};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
type Data = z.ZodObject<any, any> | z.ZodTypeAny | z.ZodDiscriminatedUnion<any, any>;
|
3
|
+
type DP = Record<string, any>;
|
4
|
+
/**
|
5
|
+
* Hook that provides reactive schema and initial values
|
6
|
+
*/
|
7
|
+
export declare const useSchema: <T extends Data>(cbP: (dp: DP, preData?: Data) => T, dp: DP) => {
|
8
|
+
readonly schema: T;
|
9
|
+
readonly initialValues: z.core.output<T>;
|
10
|
+
};
|
11
|
+
export {};
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { ZodSchema, ComponentMapping, SchemaMappingResult } from '../types';
|
3
|
+
/**
|
4
|
+
* Main hook for schema mapping functionality
|
5
|
+
* Provides schema metadata and mapping configuration for component mapping
|
6
|
+
*/
|
7
|
+
export declare function useSchemaMapping(schema: ZodSchema, componentMapping: ComponentMapping, options?: {
|
8
|
+
defaultComponent?: React.ComponentType<any>;
|
9
|
+
transformProps?: (props: any) => any;
|
10
|
+
}): SchemaMappingResult;
|
11
|
+
/**
|
12
|
+
* Hook for getting field information by path
|
13
|
+
*/
|
14
|
+
export declare function useFieldByPath(schema: ZodSchema, path: string): any;
|
15
|
+
/**
|
16
|
+
* Hook for getting all available paths in a schema
|
17
|
+
*/
|
18
|
+
export declare function useSchemaPaths(schema: ZodSchema): any;
|
19
|
+
/**
|
20
|
+
* Hook for checking if a path exists in a schema
|
21
|
+
*/
|
22
|
+
export declare function useHasPath(schema: ZodSchema, path: string): any;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { ZodSchema, FieldMetadata, SchemaMetadataResult } from '../types';
|
2
|
+
/**
|
3
|
+
* Hook for schema metadata functionality
|
4
|
+
* Provides utilities for extracting and working with schema metadata
|
5
|
+
*/
|
6
|
+
export declare function useSchemaMetadata(schema: ZodSchema): SchemaMetadataResult;
|
7
|
+
/**
|
8
|
+
* Hook for getting field metadata by name
|
9
|
+
*/
|
10
|
+
export declare function useFieldMetadata(schema: ZodSchema, fieldName: string): any;
|
11
|
+
/**
|
12
|
+
* Hook for getting all field metadata
|
13
|
+
*/
|
14
|
+
export declare function useAllFields(schema: ZodSchema): Record<string, any>;
|
15
|
+
/**
|
16
|
+
* Hook for getting schema structure
|
17
|
+
*/
|
18
|
+
export declare function useSchemaStructure(schema: ZodSchema): any;
|
19
|
+
/**
|
20
|
+
* Hook for getting required fields
|
21
|
+
*/
|
22
|
+
export declare function useRequiredFields(schema: ZodSchema): Record<string, FieldMetadata>;
|
23
|
+
/**
|
24
|
+
* Hook for getting optional fields
|
25
|
+
*/
|
26
|
+
export declare function useOptionalFields(schema: ZodSchema): Record<string, FieldMetadata>;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { ZodSchema, SchemaPath, FieldMetadata, SchemaNavigationResult } from '../types';
|
2
|
+
/**
|
3
|
+
* Hook for schema navigation functionality
|
4
|
+
* Provides utilities for navigating through schema structures using dot notation paths
|
5
|
+
*/
|
6
|
+
export declare function useSchemaNavigation(schema: ZodSchema): SchemaNavigationResult;
|
7
|
+
/**
|
8
|
+
* Hook for getting a specific field by path
|
9
|
+
*/
|
10
|
+
export declare function useField(schema: ZodSchema, path: SchemaPath): FieldMetadata | null;
|
11
|
+
/**
|
12
|
+
* Hook for getting all paths in a schema
|
13
|
+
*/
|
14
|
+
export declare function usePaths(schema: ZodSchema): string[];
|
15
|
+
/**
|
16
|
+
* Hook for checking if a path exists
|
17
|
+
*/
|
18
|
+
export declare function usePathExists(schema: ZodSchema, path: SchemaPath): boolean;
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export
|
2
|
-
export
|
3
|
-
export
|
4
|
-
export * from './
|
5
|
-
export * from './
|
6
|
-
export * from './
|
1
|
+
export { FormInstantProvider, useFields } from './components/FormInstantProvider';
|
2
|
+
export { useSchema } from './hooks/useSchema';
|
3
|
+
export { FormInstantElement } from './components/FormInstantElement';
|
4
|
+
export * from './types';
|
5
|
+
export * from './utils/schemaParser';
|
6
|
+
export * from './utils/zodExtensions';
|
package/dist/index.js
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
+
import{createContext as N,useContext as y}from"react";import{z as X}from"zod";function M(B){return B._zod?.def?.type||"unknown"}function g(B){let A=B?._fieldConfig;if(!A)return;return A}function j(B){let A={},K=[],Q={};function J(U){if(U instanceof X.ZodObject)return U.shape;if(U instanceof X.ZodDiscriminatedUnion){let L=U.options;if(L.length>0)return J(L[0])}return{}}function _(U,L,q="",D=Q){let Z=g(L),G=q?`${q}.${U}`:U,z=Z?.fieldType||M(L),k=L instanceof X.ZodOptional,E=L instanceof X.ZodDefault,F=!k&&!E,H=void 0;if(E)try{let W=L.safeParse(void 0);if(W.success)H=W.data}catch{}else try{let W=L.safeParse(void 0);if(W.success)H=W.data}catch{}let P=(()=>{if(L instanceof X.ZodEnum)return L.options.map((W)=>[String(W),String(W)]);if(L.constructor.name==="ZodNativeEnum")return L.options.map((Y)=>[String(Y),String(Y)]);return[]})(),T={name:{current:U,history:G},fieldType:z,required:F,default:H,fieldConfig:Z,options:P};if(A[G]=T,K.push(G),D[U]=T,L instanceof X.ZodObject){let W=L.shape,Y={};D[U]=Y,Object.keys(W).forEach((w)=>{_(w,W[w],G,Y)})}if(L instanceof X.ZodArray){let W=L.element;if(W instanceof X.ZodObject){let Y={};D[U]=Y;let w=W.shape;Object.keys(w).forEach((I)=>{_(I,w[I],`${G}[0]`,Y)})}}}let $=J(B);return Object.keys($).forEach((U)=>{_(U,$[U])}),{fields:A}}function d(B){return M(B)}function m(B){let A=B instanceof X.ZodOptional,K=B instanceof X.ZodDefault;return!A&&!K}function s(B){try{let A=B.safeParse(void 0);return A.success?A.data:void 0}catch{return}}import{jsx as o}from"react/jsx-runtime";var b=N(null),S=({children:B,schema:A})=>{return o(b.Provider,{value:A,children:B})},R=(B)=>{let A=y(b);if(!A)throw new Error("useFields must be used within FormInstantProvider");let{fields:K}=j(A);return K[B]};import{useMemo as v}from"react";import{z as p}from"zod";var C=(B,A)=>{try{let K=(()=>{if(B instanceof p.ZodObject)return B.shape;return{}})(),Q={};for(let J of Object.keys(K)){let _=K[J],$=_.safeParse(void 0);if($.success){Q[J]=$.data;continue}if(Object.keys(A).includes(J)){Q[J]=A[J];continue}let U={ZodString(){Q[J]=""},ZodNumber(){Q[J]=0},ZodBoolean(){Q[J]=!1},ZodDate(){Q[J]=null},ZodArray(){Q[J]=[]},ZodObject(){Q[J]=C(_,A)}},L=_.constructor.name,q=U[L];if(q){q();continue}Q[J]=null}return Q}catch(K){if(console.log("\uD83D\uDD34 initialValues error",K),K instanceof Error)console.log(K.cause),console.log(K.message);return{}}},u=(B,A)=>{let K=v(()=>{let J=B(A);if(J._fieldConfig)return J.fieldConfig({dp:A,...J._fieldConfig});return J},[B,A]),Q=v(()=>C(K,A),[K,A]);return{schema:K,initialValues:Q}};import{ElementMapping as V}from"@form-instant/react-input-mapping";import{useId as f}from"react";import{jsx as O,Fragment as x}from"react/jsx-runtime";var n=({name:B})=>{let A=R(B),K=f();if(!["object"].includes(A.fieldType))return O(V,{formProps:A});return O(x,{children:Object.values(A.schema||{}).map((Q)=>{return O(x,{children:O(V,{formProps:Q})},`${K}-${Q.name?.history||""}`)})})};import{z as h}from"zod";var r=Object.getPrototypeOf(h.string());Object.defineProperty(r,"fieldConfig",{value(B){return this._fieldConfig=B,this},writable:!0,configurable:!0});export{u as useSchema,R as useFields,j as parseSchema,m as isFieldRequired,d as getFieldType,s as getDefaultValue,S as FormInstantProvider,n as FormInstantElement};
|
1
2
|
|
2
|
-
|
3
|
-
|
4
|
-
if (process.env.NODE_ENV === 'production') {
|
5
|
-
module.exports = require('./react-resolver-zod.cjs.production.min.js')
|
6
|
-
} else {
|
7
|
-
module.exports = require('./react-resolver-zod.cjs.development.js')
|
8
|
-
}
|
3
|
+
//# debugId=B96E0FE823875AC964756E2164756E21
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["../src/components/FormInstantProvider.tsx", "../src/utils/schemaParser.ts", "../src/hooks/useSchema.ts", "../src/components/FormInstantElement.tsx", "../src/utils/zodExtensions.ts"],
|
4
|
+
"sourcesContent": [
|
5
|
+
"import { createContext, useContext } from 'react';\nimport { zodResolverProps } from 'types';\nimport { parseSchema } from '../utils/schemaParser';\n\nexport const ZodResolverContext = createContext<zodResolverProps | null>(null);\n\nexport const FormInstantProvider: FCC<{\n schema: zodResolverProps;\n}> = ({ children, schema }) => {\n return <ZodResolverContext.Provider value={schema}>{children}</ZodResolverContext.Provider>;\n};\n\n/**\n * Hook to get a specific field by name from the schema\n */\nexport const useFields = <Sc extends Record<string, any>>(key: keyof Sc) => {\n const schema = useContext(ZodResolverContext);\n if (!schema) {\n throw new Error('useFields must be used within FormInstantProvider');\n }\n\n const { fields } = parseSchema(schema);\n return fields[key as string];\n};\n",
|
6
|
+
"import { z } from 'zod';\nimport { FieldConfig, FieldMetadata, SchemaPath } from '../types';\n\n// Schema type detection using the internal type property\nfunction getSchemaType(schema: z.ZodTypeAny): string {\n return schema._zod?.def?.type || 'unknown';\n}\n\n/**\n * Extracts fieldConfig from a Zod schema\n */\nfunction extractFieldConfig(schema: z.ZodTypeAny) {\n const fieldConfig = (schema as any)?._fieldConfig as FieldConfig<Record<string, object>>;\n if (!fieldConfig) return undefined;\n\n return fieldConfig;\n}\n\n/**\n * Parses a Zod schema and extracts metadata for mapping\n */\nexport function parseSchema(schema: z.ZodTypeAny): { fields: Record<string, any> } {\n const fields: Record<string, FieldMetadata> = {};\n const paths: SchemaPath[] = [];\n const structure: Record<string, any> = {};\n\n function extractShape(schema: z.ZodTypeAny): Record<string, any> {\n // Handle ZodObject\n if (schema instanceof z.ZodObject) {\n return schema.shape;\n }\n\n // Handle ZodDiscriminatedUnion\n if (schema instanceof z.ZodDiscriminatedUnion) {\n // For discriminated unions, we'll use the first option as default\n const options = schema.options;\n if (options.length > 0) {\n return extractShape(options[0] as z.ZodTypeAny);\n }\n }\n\n return {};\n }\n\n function processField(\n fieldName: string,\n fieldSchema: z.ZodTypeAny,\n parentPath: string = '',\n parentStructure: Record<string, any> = structure,\n ) {\n // Extract fieldConfig from the schema\n const fieldConfig = extractFieldConfig(fieldSchema);\n const currentPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;\n const fieldType = fieldConfig?.fieldType || getSchemaType(fieldSchema);\n\n // Check if field is required\n const isOptional = fieldSchema instanceof z.ZodOptional;\n const hasDefault = fieldSchema instanceof z.ZodDefault;\n const isRequired = !isOptional && !hasDefault;\n\n // Get default value\n let defaultValue: any = undefined;\n if (hasDefault) {\n // For ZodDefault, try to get the default value\n try {\n const result = fieldSchema.safeParse(undefined);\n if (result.success) {\n defaultValue = result.data;\n }\n } catch {\n // Could not get default value\n }\n } else {\n try {\n const result = fieldSchema.safeParse(undefined);\n if (result.success) {\n defaultValue = result.data;\n }\n } catch {\n // Field is required, no default value\n }\n }\n\n // Extract options for enums\n const options: [string, string][] = (() => {\n if (fieldSchema instanceof z.ZodEnum) {\n return fieldSchema.options.map((value) => [String(value), String(value)]);\n }\n\n if (fieldSchema.constructor.name === 'ZodNativeEnum') {\n const enumValues = (fieldSchema as z.ZodEnum).options;\n return enumValues.map((value) => [String(value), String(value)]);\n }\n return [];\n })();\n\n // Create field metadata\n const fieldMetadata: FieldMetadata = {\n name: {\n current: fieldName,\n history: currentPath,\n },\n fieldType: fieldType,\n required: isRequired,\n default: defaultValue,\n fieldConfig,\n options,\n };\n\n // Store field metadata by path\n fields[currentPath] = fieldMetadata;\n paths.push(currentPath);\n parentStructure[fieldName] = fieldMetadata;\n\n // Handle nested objects\n if (fieldSchema instanceof z.ZodObject) {\n const nestedShape = fieldSchema.shape;\n const nestedStructure: Record<string, any> = {};\n parentStructure[fieldName] = nestedStructure;\n\n Object.keys(nestedShape).forEach((nestedFieldName) => {\n processField(\n nestedFieldName,\n nestedShape[nestedFieldName],\n currentPath,\n nestedStructure,\n );\n });\n }\n\n // Handle arrays\n if (fieldSchema instanceof z.ZodArray) {\n const elementSchema = fieldSchema.element;\n if (elementSchema instanceof z.ZodObject) {\n const arrayStructure: Record<string, any> = {};\n parentStructure[fieldName] = arrayStructure;\n\n const elementShape = elementSchema.shape;\n Object.keys(elementShape).forEach((elementFieldName) => {\n processField(\n elementFieldName,\n elementShape[elementFieldName],\n `${currentPath}[0]`,\n arrayStructure,\n );\n });\n }\n }\n }\n\n const shape = extractShape(schema);\n Object.keys(shape).forEach((fieldName) => {\n processField(fieldName, shape[fieldName]);\n });\n\n return {\n fields,\n };\n}\n\n/**\n * Gets the field type from a Zod schema\n */\nexport function getFieldType(schema: z.ZodTypeAny): string {\n return getSchemaType(schema);\n}\n\n/**\n * Checks if a field is required\n */\nexport function isFieldRequired(schema: z.ZodTypeAny): boolean {\n const isOptional = schema instanceof z.ZodOptional;\n const hasDefault = schema instanceof z.ZodDefault;\n return !isOptional && !hasDefault;\n}\n\n/**\n * Gets the default value for a field\n */\nexport function getDefaultValue(schema: z.ZodTypeAny): any {\n try {\n const result = schema.safeParse(undefined);\n return result.success ? result.data : undefined;\n } catch {\n return undefined;\n }\n}\n",
|
7
|
+
"import { useMemo } from 'react';\nimport { z } from 'zod';\n\n// Types for useSchema hook\ntype Data = z.ZodObject<any, any> | z.ZodTypeAny | z.ZodDiscriminatedUnion<any, any>;\ntype DP = Record<string, any>;\n\n/**\n * Generates initial values from schema and dependencies\n */\nconst generateInitialValues = <T extends Data>(schema: T, dp: DP): z.infer<T> => {\n try {\n const shape = (() => {\n if (schema instanceof z.ZodObject) return (schema as z.ZodObject<any>).shape;\n return {};\n })();\n\n const initialValues: Record<string, any> = {};\n\n for (const key of Object.keys(shape)) {\n const fieldSchema = shape[key];\n const result = fieldSchema.safeParse(undefined);\n\n // Si tiene valor por defecto\n if (result.success) {\n initialValues[key] = result.data;\n continue;\n }\n\n if (Object.keys(dp).includes(key)) {\n initialValues[key] = dp[key];\n continue;\n }\n\n // Inferir tipo para campos requeridos sin default\n const fieldConfig = {\n ZodString() {\n initialValues[key] = '';\n },\n ZodNumber() {\n initialValues[key] = 0;\n },\n ZodBoolean() {\n initialValues[key] = false;\n },\n ZodDate() {\n initialValues[key] = null;\n },\n ZodArray() {\n initialValues[key] = [];\n },\n ZodObject() {\n initialValues[key] = generateInitialValues(fieldSchema, dp);\n },\n };\n\n const fieldType = fieldSchema.constructor.name;\n const fieldHandler = fieldConfig[fieldType as keyof typeof fieldConfig];\n\n if (fieldHandler) {\n fieldHandler();\n continue;\n }\n\n initialValues[key] = null;\n }\n\n return initialValues as z.infer<T>;\n } catch (error) {\n console.log('🔴 initialValues error', error);\n\n if (error instanceof Error) {\n console.log(error.cause);\n console.log(error.message);\n }\n\n return {} as z.infer<T>;\n }\n};\n\n/**\n * Hook that provides reactive schema and initial values\n */\nexport const useSchema = <T extends Data>(cbP: (dp: DP, preData?: Data) => T, dp: DP) => {\n const schema = useMemo(() => {\n const baseSchema = cbP(dp);\n // Check if fieldConfig exists (for backward compatibility)\n if ((baseSchema as any)._fieldConfig) {\n return (baseSchema as any).fieldConfig({\n dp,\n ...(baseSchema as any)._fieldConfig,\n }) as T;\n }\n return baseSchema as T;\n }, [cbP, dp]);\n\n const initialValues = useMemo(() => generateInitialValues<T>(schema, dp), [schema, dp]);\n\n return { schema, initialValues } as const;\n};\n",
|
8
|
+
"'use client';\nimport { ElementMapping } from '@form-instant/react-input-mapping';\nimport { Fragment, useId } from 'react';\nimport { useFields } from './FormInstantProvider';\n\nexport interface ElementProps<Schema extends Record<string, any>> {\n name: keyof Schema;\n}\n\nexport const FormInstantElement = <S extends Record<string, any>>({ name }: ElementProps<S>) => {\n const field = useFields(name);\n\n const id = useId();\n\n if (!['object'].includes(field.fieldType)) return <ElementMapping formProps={field} />;\n\n return (\n <>\n {Object.values(field.schema || {}).map((props: any) => {\n return (\n <Fragment key={`${id}-${props.name?.history || ''}`}>\n <ElementMapping formProps={props} />\n </Fragment>\n );\n })}\n </>\n );\n};\n",
|
9
|
+
"import { z } from 'zod';\nimport { FieldConfig } from '../types';\n\n// Extend ZodType interface to include fieldConfig method\ndeclare module 'zod' {\n interface ZodType {\n fieldConfig: <Ob extends Record<string, any>>(config: FieldConfig<Ob, keyof Ob>) => this;\n _fieldConfig?: FieldConfig<any, any>;\n }\n}\n\n// Extend Zod with fieldConfig method\nconst zodTypePrototype = Object.getPrototypeOf(z.string());\nObject.defineProperty(zodTypePrototype, 'fieldConfig', {\n value(config: FieldConfig<any, any>) {\n (this as any)._fieldConfig = config;\n return this;\n },\n writable: true,\n configurable: true,\n});\n"
|
10
|
+
],
|
11
|
+
"mappings": "AAAA,wBAAS,gBAAe,cCAxB,YAAS,YAIT,SAAS,CAAa,CAAC,EAA8B,CACjD,OAAO,EAAO,MAAM,KAAK,MAAQ,UAMrC,SAAS,CAAkB,CAAC,EAAsB,CAC9C,IAAM,EAAe,GAAgB,aACrC,IAAK,EAAa,OAElB,OAAO,EAMJ,SAAS,CAAW,CAAC,EAAuD,CAC/E,IAAM,EAAwC,CAAC,EACzC,EAAsB,CAAC,EACvB,EAAiC,CAAC,EAExC,SAAS,CAAY,CAAC,EAA2C,CAE7D,GAAI,aAAkB,EAAE,UACpB,OAAO,EAAO,MAIlB,GAAI,aAAkB,EAAE,sBAAuB,CAE3C,IAAM,EAAU,EAAO,QACvB,GAAI,EAAQ,OAAS,EACjB,OAAO,EAAa,EAAQ,EAAkB,EAItD,MAAO,CAAC,EAGZ,SAAS,CAAY,CACjB,EACA,EACA,EAAqB,GACrB,EAAuC,EACzC,CAEE,IAAM,EAAc,EAAmB,CAAW,EAC5C,EAAc,EAAa,GAAG,KAAc,IAAc,EAC1D,EAAY,GAAa,WAAa,EAAc,CAAW,EAG/D,EAAa,aAAuB,E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A+B,CAEjC,OADC,KAAa,aAAe,EACtB,MAEX,SAAU,GACV,aAAc,EAClB,CAAC",
|
12
|
+
"debugId": "B96E0FE823875AC964756E2164756E21",
|
13
|
+
"names": []
|
14
|
+
}
|
package/dist/types.d.ts
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
import { ParsedField } from '@form-instant/react-input-mapping';
|
2
|
+
import { ReactNode } from 'react';
|
3
|
+
export type ZodSchema = any;
|
4
|
+
export type ComponentMapping = Record<string, React.ComponentType<any>>;
|
5
|
+
export type SchemaPath = string;
|
6
|
+
export type PathSegment = string;
|
7
|
+
export type FieldConfig<Ob, K extends keyof Ob = keyof Ob> = {
|
8
|
+
fieldType: K;
|
9
|
+
} & Ob[K];
|
10
|
+
export type FieldMetadata = ParsedField<any, string>;
|
11
|
+
export interface SchemaMetadata {
|
12
|
+
fields: Record<string, FieldMetadata>;
|
13
|
+
paths: SchemaPath[];
|
14
|
+
structure: Record<string, any>;
|
15
|
+
}
|
16
|
+
export interface MappingConfig {
|
17
|
+
componentMapping: ComponentMapping;
|
18
|
+
defaultComponent?: React.ComponentType<any>;
|
19
|
+
transformProps?: (props: any) => any;
|
20
|
+
}
|
21
|
+
export interface SchemaMappingResult {
|
22
|
+
schema: ZodSchema;
|
23
|
+
metadata: SchemaMetadata;
|
24
|
+
mappingConfig: MappingConfig;
|
25
|
+
}
|
26
|
+
export interface SchemaNavigationResult {
|
27
|
+
navigate: (path: SchemaPath) => FieldMetadata | null;
|
28
|
+
getField: (path: SchemaPath) => FieldMetadata | null;
|
29
|
+
getPaths: () => SchemaPath[];
|
30
|
+
hasPath: (path: SchemaPath) => boolean;
|
31
|
+
}
|
32
|
+
export interface SchemaMetadataResult {
|
33
|
+
metadata: SchemaMetadata;
|
34
|
+
getField: (path: SchemaPath) => FieldMetadata | null;
|
35
|
+
getPaths: () => SchemaPath[];
|
36
|
+
getStructure: () => Record<string, any>;
|
37
|
+
}
|
38
|
+
export type zodResolverProps = ZodSchema;
|
39
|
+
export interface SchemaMapperProps {
|
40
|
+
schema: ZodSchema;
|
41
|
+
componentMapping: ComponentMapping;
|
42
|
+
defaultComponent?: React.ComponentType<any>;
|
43
|
+
transformProps?: (props: any) => any;
|
44
|
+
children?: ReactNode;
|
45
|
+
}
|
46
|
+
export interface ElementProps<Schema extends Record<string, any>> {
|
47
|
+
name: keyof Schema;
|
48
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { SchemaPath, PathSegment, FieldMetadata } from '../types';
|
3
|
+
/**
|
4
|
+
* Resolves a path in a Zod schema and returns the field metadata
|
5
|
+
*/
|
6
|
+
export declare function resolvePath(schema: z.ZodTypeAny, path: SchemaPath): FieldMetadata | null;
|
7
|
+
/**
|
8
|
+
* Gets all possible paths in a schema
|
9
|
+
*/
|
10
|
+
export declare function getAllPaths(schema: z.ZodTypeAny): SchemaPath[];
|
11
|
+
/**
|
12
|
+
* Validates if a path exists in the schema
|
13
|
+
*/
|
14
|
+
export declare function hasPath(schema: z.ZodTypeAny, path: SchemaPath): boolean;
|
15
|
+
/**
|
16
|
+
* Gets the schema at a specific path
|
17
|
+
*/
|
18
|
+
export declare function getSchemaAtPath(schema: z.ZodTypeAny, path: SchemaPath): z.ZodTypeAny | null;
|
19
|
+
/**
|
20
|
+
* Splits a path into segments
|
21
|
+
*/
|
22
|
+
export declare function splitPath(path: SchemaPath): PathSegment[];
|
23
|
+
/**
|
24
|
+
* Joins path segments into a path
|
25
|
+
*/
|
26
|
+
export declare function joinPath(segments: PathSegment[]): SchemaPath;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
/**
|
3
|
+
* Parses a Zod schema and extracts metadata for mapping
|
4
|
+
*/
|
5
|
+
export declare function parseSchema(schema: z.ZodTypeAny): {
|
6
|
+
fields: Record<string, any>;
|
7
|
+
};
|
8
|
+
/**
|
9
|
+
* Gets the field type from a Zod schema
|
10
|
+
*/
|
11
|
+
export declare function getFieldType(schema: z.ZodTypeAny): string;
|
12
|
+
/**
|
13
|
+
* Checks if a field is required
|
14
|
+
*/
|
15
|
+
export declare function isFieldRequired(schema: z.ZodTypeAny): boolean;
|
16
|
+
/**
|
17
|
+
* Gets the default value for a field
|
18
|
+
*/
|
19
|
+
export declare function getDefaultValue(schema: z.ZodTypeAny): any;
|