@page-speed/forms 0.1.0
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/LICENSE +28 -0
- package/README.md +469 -0
- package/dist/builder.cjs +4 -0
- package/dist/builder.cjs.map +1 -0
- package/dist/builder.d.cts +2 -0
- package/dist/builder.d.ts +2 -0
- package/dist/builder.js +3 -0
- package/dist/builder.js.map +1 -0
- package/dist/chunk-2FXAQT7S.cjs +236 -0
- package/dist/chunk-2FXAQT7S.cjs.map +1 -0
- package/dist/chunk-A3UV7BIN.js +357 -0
- package/dist/chunk-A3UV7BIN.js.map +1 -0
- package/dist/chunk-P37YLBFA.cjs +138 -0
- package/dist/chunk-P37YLBFA.cjs.map +1 -0
- package/dist/chunk-WHQMBQNI.js +127 -0
- package/dist/chunk-WHQMBQNI.js.map +1 -0
- package/dist/chunk-YTTOWHBZ.js +217 -0
- package/dist/chunk-YTTOWHBZ.js.map +1 -0
- package/dist/chunk-ZQCPEOB6.cjs +382 -0
- package/dist/chunk-ZQCPEOB6.cjs.map +1 -0
- package/dist/core.cjs +28 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +143 -0
- package/dist/core.d.ts +143 -0
- package/dist/core.js +3 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +28 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/inputs.cjs +555 -0
- package/dist/inputs.cjs.map +1 -0
- package/dist/inputs.d.cts +433 -0
- package/dist/inputs.d.ts +433 -0
- package/dist/inputs.js +529 -0
- package/dist/inputs.js.map +1 -0
- package/dist/integration.cjs +4 -0
- package/dist/integration.cjs.map +1 -0
- package/dist/integration.d.cts +2 -0
- package/dist/integration.d.ts +2 -0
- package/dist/integration.js +3 -0
- package/dist/integration.js.map +1 -0
- package/dist/types-Cw5CeZP-.d.cts +387 -0
- package/dist/types-Cw5CeZP-.d.ts +387 -0
- package/dist/upload.cjs +4 -0
- package/dist/upload.cjs.map +1 -0
- package/dist/upload.d.cts +2 -0
- package/dist/upload.d.ts +2 -0
- package/dist/upload.js +3 -0
- package/dist/upload.js.map +1 -0
- package/dist/validation-rules.cjs +80 -0
- package/dist/validation-rules.cjs.map +1 -0
- package/dist/validation-rules.d.cts +123 -0
- package/dist/validation-rules.d.ts +123 -0
- package/dist/validation-rules.js +3 -0
- package/dist/validation-rules.js.map +1 -0
- package/dist/validation-utils.cjs +48 -0
- package/dist/validation-utils.cjs.map +1 -0
- package/dist/validation-utils.d.cts +166 -0
- package/dist/validation-utils.d.ts +166 -0
- package/dist/validation-utils.js +3 -0
- package/dist/validation-utils.js.map +1 -0
- package/dist/validation-valibot.cjs +94 -0
- package/dist/validation-valibot.cjs.map +1 -0
- package/dist/validation-valibot.d.cts +92 -0
- package/dist/validation-valibot.d.ts +92 -0
- package/dist/validation-valibot.js +91 -0
- package/dist/validation-valibot.js.map +1 -0
- package/dist/validation.cjs +121 -0
- package/dist/validation.cjs.map +1 -0
- package/dist/validation.d.cts +4 -0
- package/dist/validation.d.ts +4 -0
- package/dist/validation.js +4 -0
- package/dist/validation.js.map +1 -0
- package/package.json +133 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { b as FormValues, V as ValidationSchema, F as FieldValidator } from './types-Cw5CeZP-.cjs';
|
|
2
|
+
import 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @page-speed/forms - Valibot Validation Adapter
|
|
6
|
+
*
|
|
7
|
+
* Integrates Valibot schema validation with @page-speed/forms.
|
|
8
|
+
* Provides tree-shakable validation with excellent performance.
|
|
9
|
+
*
|
|
10
|
+
* Valibot Benefits:
|
|
11
|
+
* - 95% smaller than Zod (0.6KB vs 13.4KB base)
|
|
12
|
+
* - 2-3x faster validation performance
|
|
13
|
+
* - Modular, tree-shakable API
|
|
14
|
+
* - Full TypeScript inference
|
|
15
|
+
*
|
|
16
|
+
* @see https://opensite.ai/developers/page-speed/forms/validation
|
|
17
|
+
* @see https://valibot.dev
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Valibot schema type (generic to avoid direct import)
|
|
22
|
+
* Users will pass their own Valibot schemas
|
|
23
|
+
*/
|
|
24
|
+
type ValibotSchema<T = any> = {
|
|
25
|
+
_types?: {
|
|
26
|
+
input: T;
|
|
27
|
+
output: T;
|
|
28
|
+
};
|
|
29
|
+
_parse(input: unknown): {
|
|
30
|
+
output: T;
|
|
31
|
+
issues?: any[];
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Create a validation schema from a Valibot schema
|
|
36
|
+
*
|
|
37
|
+
* Converts a Valibot object schema into @page-speed/forms ValidationSchema format.
|
|
38
|
+
* Supports both synchronous and asynchronous validation.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* import * as v from 'valibot';
|
|
43
|
+
* import { useForm } from '@page-speed/forms/core';
|
|
44
|
+
* import { createValibotSchema } from '@page-speed/forms/validation/valibot';
|
|
45
|
+
*
|
|
46
|
+
* const LoginSchema = v.object({
|
|
47
|
+
* email: v.pipe(v.string(), v.email('Invalid email')),
|
|
48
|
+
* password: v.pipe(v.string(), v.minLength(8, 'Too short')),
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* const form = useForm({
|
|
52
|
+
* initialValues: { email: '', password: '' },
|
|
53
|
+
* validationSchema: createValibotSchema(LoginSchema),
|
|
54
|
+
* onSubmit: async (values) => {
|
|
55
|
+
* await login(values);
|
|
56
|
+
* },
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare function createValibotSchema<T extends FormValues>(schema: ValibotSchema<T>): ValidationSchema<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Create a field validator from a Valibot schema
|
|
63
|
+
*
|
|
64
|
+
* For single-field validation without a full form schema.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* import * as v from 'valibot';
|
|
69
|
+
* import { Field } from '@page-speed/forms/core';
|
|
70
|
+
* import { createFieldValidator } from '@page-speed/forms/validation/valibot';
|
|
71
|
+
*
|
|
72
|
+
* const emailSchema = v.pipe(v.string(), v.email('Invalid email'));
|
|
73
|
+
*
|
|
74
|
+
* <Field
|
|
75
|
+
* name="email"
|
|
76
|
+
* validate={createFieldValidator(emailSchema)}
|
|
77
|
+
* >
|
|
78
|
+
* {({ field, meta }) => <input {...field} />}
|
|
79
|
+
* </Field>
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare function createFieldValidator<T = any>(schema: ValibotSchema<T>): FieldValidator<T>;
|
|
83
|
+
/**
|
|
84
|
+
* Helper to infer form values type from Valibot schema
|
|
85
|
+
*/
|
|
86
|
+
type InferValibotInput<T extends ValibotSchema> = T extends ValibotSchema<infer U> ? U : never;
|
|
87
|
+
/**
|
|
88
|
+
* Helper to infer form values type from Valibot schema output
|
|
89
|
+
*/
|
|
90
|
+
type InferValibotOutput<T extends ValibotSchema> = T extends ValibotSchema<infer U> ? U : never;
|
|
91
|
+
|
|
92
|
+
export { type InferValibotInput, type InferValibotOutput, type ValibotSchema, createFieldValidator, createValibotSchema };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { b as FormValues, V as ValidationSchema, F as FieldValidator } from './types-Cw5CeZP-.js';
|
|
2
|
+
import 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @page-speed/forms - Valibot Validation Adapter
|
|
6
|
+
*
|
|
7
|
+
* Integrates Valibot schema validation with @page-speed/forms.
|
|
8
|
+
* Provides tree-shakable validation with excellent performance.
|
|
9
|
+
*
|
|
10
|
+
* Valibot Benefits:
|
|
11
|
+
* - 95% smaller than Zod (0.6KB vs 13.4KB base)
|
|
12
|
+
* - 2-3x faster validation performance
|
|
13
|
+
* - Modular, tree-shakable API
|
|
14
|
+
* - Full TypeScript inference
|
|
15
|
+
*
|
|
16
|
+
* @see https://opensite.ai/developers/page-speed/forms/validation
|
|
17
|
+
* @see https://valibot.dev
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Valibot schema type (generic to avoid direct import)
|
|
22
|
+
* Users will pass their own Valibot schemas
|
|
23
|
+
*/
|
|
24
|
+
type ValibotSchema<T = any> = {
|
|
25
|
+
_types?: {
|
|
26
|
+
input: T;
|
|
27
|
+
output: T;
|
|
28
|
+
};
|
|
29
|
+
_parse(input: unknown): {
|
|
30
|
+
output: T;
|
|
31
|
+
issues?: any[];
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Create a validation schema from a Valibot schema
|
|
36
|
+
*
|
|
37
|
+
* Converts a Valibot object schema into @page-speed/forms ValidationSchema format.
|
|
38
|
+
* Supports both synchronous and asynchronous validation.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* import * as v from 'valibot';
|
|
43
|
+
* import { useForm } from '@page-speed/forms/core';
|
|
44
|
+
* import { createValibotSchema } from '@page-speed/forms/validation/valibot';
|
|
45
|
+
*
|
|
46
|
+
* const LoginSchema = v.object({
|
|
47
|
+
* email: v.pipe(v.string(), v.email('Invalid email')),
|
|
48
|
+
* password: v.pipe(v.string(), v.minLength(8, 'Too short')),
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* const form = useForm({
|
|
52
|
+
* initialValues: { email: '', password: '' },
|
|
53
|
+
* validationSchema: createValibotSchema(LoginSchema),
|
|
54
|
+
* onSubmit: async (values) => {
|
|
55
|
+
* await login(values);
|
|
56
|
+
* },
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare function createValibotSchema<T extends FormValues>(schema: ValibotSchema<T>): ValidationSchema<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Create a field validator from a Valibot schema
|
|
63
|
+
*
|
|
64
|
+
* For single-field validation without a full form schema.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* import * as v from 'valibot';
|
|
69
|
+
* import { Field } from '@page-speed/forms/core';
|
|
70
|
+
* import { createFieldValidator } from '@page-speed/forms/validation/valibot';
|
|
71
|
+
*
|
|
72
|
+
* const emailSchema = v.pipe(v.string(), v.email('Invalid email'));
|
|
73
|
+
*
|
|
74
|
+
* <Field
|
|
75
|
+
* name="email"
|
|
76
|
+
* validate={createFieldValidator(emailSchema)}
|
|
77
|
+
* >
|
|
78
|
+
* {({ field, meta }) => <input {...field} />}
|
|
79
|
+
* </Field>
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare function createFieldValidator<T = any>(schema: ValibotSchema<T>): FieldValidator<T>;
|
|
83
|
+
/**
|
|
84
|
+
* Helper to infer form values type from Valibot schema
|
|
85
|
+
*/
|
|
86
|
+
type InferValibotInput<T extends ValibotSchema> = T extends ValibotSchema<infer U> ? U : never;
|
|
87
|
+
/**
|
|
88
|
+
* Helper to infer form values type from Valibot schema output
|
|
89
|
+
*/
|
|
90
|
+
type InferValibotOutput<T extends ValibotSchema> = T extends ValibotSchema<infer U> ? U : never;
|
|
91
|
+
|
|
92
|
+
export { type InferValibotInput, type InferValibotOutput, type ValibotSchema, createFieldValidator, createValibotSchema };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// src/validation/valibot.ts
|
|
2
|
+
function createValibotSchema(schema) {
|
|
3
|
+
const hasSafeParse = "safeParse" in schema && typeof schema.safeParse === "function";
|
|
4
|
+
const validationSchema = {};
|
|
5
|
+
const createFieldValidator2 = (fieldName) => {
|
|
6
|
+
return async (_value, allValues) => {
|
|
7
|
+
try {
|
|
8
|
+
const result = hasSafeParse ? schema.safeParse(allValues) : (() => {
|
|
9
|
+
try {
|
|
10
|
+
const parsed = schema._parse(allValues);
|
|
11
|
+
return { success: !parsed.issues || parsed.issues.length === 0, output: parsed.output, issues: parsed.issues };
|
|
12
|
+
} catch (error) {
|
|
13
|
+
return { success: false, issues: error.issues || [{ path: [], message: error.message }] };
|
|
14
|
+
}
|
|
15
|
+
})();
|
|
16
|
+
if (!result.success && result.issues) {
|
|
17
|
+
for (const issue of result.issues) {
|
|
18
|
+
const path = issue.path || [];
|
|
19
|
+
if (path.length > 0) {
|
|
20
|
+
const key = path[0].key || path[0];
|
|
21
|
+
if (key === fieldName) {
|
|
22
|
+
return issue.message || "Validation error";
|
|
23
|
+
}
|
|
24
|
+
} else if (path.length === 0 && Object.keys(allValues).length === 1) {
|
|
25
|
+
return issue.message || "Validation error";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return void 0;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error.issues && Array.isArray(error.issues)) {
|
|
32
|
+
for (const issue of error.issues) {
|
|
33
|
+
const path = issue.path || [];
|
|
34
|
+
if (path.length > 0) {
|
|
35
|
+
const key = path[0].key || path[0];
|
|
36
|
+
if (key === fieldName) {
|
|
37
|
+
return issue.message || "Validation error";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return error.message || "Validation error";
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
return new Proxy(validationSchema, {
|
|
47
|
+
get(_target, prop) {
|
|
48
|
+
if (typeof prop === "string") {
|
|
49
|
+
return createFieldValidator2(prop);
|
|
50
|
+
}
|
|
51
|
+
return void 0;
|
|
52
|
+
},
|
|
53
|
+
ownKeys() {
|
|
54
|
+
return [];
|
|
55
|
+
},
|
|
56
|
+
getOwnPropertyDescriptor() {
|
|
57
|
+
return {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function createFieldValidator(schema) {
|
|
65
|
+
const hasSafeParse = "safeParse" in schema && typeof schema.safeParse === "function";
|
|
66
|
+
return async (value) => {
|
|
67
|
+
try {
|
|
68
|
+
const result = hasSafeParse ? schema.safeParse(value) : (() => {
|
|
69
|
+
try {
|
|
70
|
+
const parsed = schema._parse(value);
|
|
71
|
+
return { success: !parsed.issues || parsed.issues.length === 0, output: parsed.output, issues: parsed.issues };
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return { success: false, issues: error.issues || [{ message: error.message }] };
|
|
74
|
+
}
|
|
75
|
+
})();
|
|
76
|
+
if (!result.success && result.issues && result.issues.length > 0) {
|
|
77
|
+
return result.issues[0].message || "Validation error";
|
|
78
|
+
}
|
|
79
|
+
return void 0;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (error.issues && error.issues.length > 0) {
|
|
82
|
+
return error.issues[0].message || "Validation error";
|
|
83
|
+
}
|
|
84
|
+
return error.message || "Validation error";
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { createFieldValidator, createValibotSchema };
|
|
90
|
+
//# sourceMappingURL=validation-valibot.js.map
|
|
91
|
+
//# sourceMappingURL=validation-valibot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/validation/valibot.ts"],"names":["createFieldValidator"],"mappings":";AAwDO,SAAS,oBACd,MAAA,EACqB;AAErB,EAAA,MAAM,YAAA,GAAe,WAAA,IAAe,MAAA,IAAU,OAAO,OAAO,SAAA,KAAc,UAAA;AAE1E,EAAA,MAAM,mBAAwC,EAAC;AAG/C,EAAA,MAAMA,qBAAAA,GAAuB,CAC3B,SAAA,KACyB;AACzB,IAAA,OAAO,OAAO,QAAc,SAAA,KAAuD;AACjF,MAAA,IAAI;AAEF,QAAA,MAAM,SAAS,YAAA,GACV,MAAA,CAAe,SAAA,CAAU,SAAS,KAClC,MAAM;AACL,UAAA,IAAI;AACF,YAAA,MAAM,MAAA,GAAS,MAAA,CAAO,MAAA,CAAO,SAAS,C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,UAAU,MAAA,CAAO,MAAA,CAAO,MAAA,KAAW,CAAA,EAAG,MAAA,EAAQ,MAAA,CAAO,MAAA,EAAQ,MAAA,EAAQ,OAAO,MAAA,EAAO;AAAA,QAC/G,SAAS,KAAA,EAAY;AACnB,UAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,MAAA,EAAQ,KAAA,CAAM,MAAA,IAAU,CAAC,EAAE,OAAA,EAAS,KAAA,CAAM,OAAA,EAAS,CAAA,EAAE;AAAA,QAChF;AAAA,MACF,CAAA,GAAG;AAEP,MAAA,IAAI,CAAC,OAAO,OAAA,IAAW,MAAA,CAAO,UAAU,MAAA,CAAO,MAAA,CAAO,SAAS,CAAA,EAAG;AAChE,QAAA,OAAO,MAAA,CAAO,MAAA,CAAO,CAAC,CAAA,CAAE,OAAA,IAAW,kBAAA;AAAA,MACrC;AAEA,MAAA,OAAO,KAAA,CAAA;AAAA,IACT,SAAS,KAAA,EAAY;AACnB,MAAA,IAAI,KAAA,CAAM,MAAA,IAAU,KAAA,CAAM,MAAA,CAAO,SAAS,CAAA,EAAG;AAC3C,QAAA,OAAO,KAAA,CAAM,MAAA,CAAO,CAAC,CAAA,CAAE,OAAA,IAAW,kBAAA;AAAA,MACpC;AACA,MAAA,OAAO,MAAM,OAAA,IAAW,kBAAA;AAAA,IAC1B;AAAA,EACF,CAAA;AACF","file":"validation-valibot.js","sourcesContent":["/**\n * @page-speed/forms - Valibot Validation Adapter\n *\n * Integrates Valibot schema validation with @page-speed/forms.\n * Provides tree-shakable validation with excellent performance.\n *\n * Valibot Benefits:\n * - 95% smaller than Zod (0.6KB vs 13.4KB base)\n * - 2-3x faster validation performance\n * - Modular, tree-shakable API\n * - Full TypeScript inference\n *\n * @see https://opensite.ai/developers/page-speed/forms/validation\n * @see https://valibot.dev\n */\n\nimport type { FormValues, ValidationSchema, FieldValidator } from \"../core/types\";\n\n/**\n * Valibot schema type (generic to avoid direct import)\n * Users will pass their own Valibot schemas\n */\nexport type ValibotSchema<T = any> = {\n _types?: {\n input: T;\n output: T;\n };\n _parse(input: unknown): { output: T; issues?: any[] };\n};\n\n/**\n * Create a validation schema from a Valibot schema\n *\n * Converts a Valibot object schema into @page-speed/forms ValidationSchema format.\n * Supports both synchronous and asynchronous validation.\n *\n * @example\n * ```tsx\n * import * as v from 'valibot';\n * import { useForm } from '@page-speed/forms/core';\n * import { createValibotSchema } from '@page-speed/forms/validation/valibot';\n *\n * const LoginSchema = v.object({\n * email: v.pipe(v.string(), v.email('Invalid email')),\n * password: v.pipe(v.string(), v.minLength(8, 'Too short')),\n * });\n *\n * const form = useForm({\n * initialValues: { email: '', password: '' },\n * validationSchema: createValibotSchema(LoginSchema),\n * onSubmit: async (values) => {\n * await login(values);\n * },\n * });\n * ```\n */\nexport function createValibotSchema<T extends FormValues>(\n schema: ValibotSchema<T>\n): ValidationSchema<T> {\n // Check if safeParse exists (Valibot v0.31+)\n const hasSafeParse = \"safeParse\" in schema && typeof schema.safeParse === \"function\";\n\n const validationSchema: ValidationSchema<T> = {} as ValidationSchema<T>;\n\n // Create a validator function that will be called per-field\n const createFieldValidator = <K extends keyof T>(\n fieldName: K\n ): FieldValidator<T[K]> => {\n return async (_value: T[K], allValues: FormValues): Promise<string | undefined> => {\n try {\n // Validate the entire object to get field-specific errors\n const result = hasSafeParse\n ? (schema as any).safeParse(allValues)\n : (() => {\n try {\n const parsed = schema._parse(allValues);\n return { success: !parsed.issues || parsed.issues.length === 0, output: parsed.output, issues: parsed.issues };\n } catch (error: any) {\n return { success: false, issues: error.issues || [{ path: [], message: error.message }] };\n }\n })();\n\n if (!result.success && result.issues) {\n // Find error for this specific field\n for (const issue of result.issues) {\n const path = issue.path || [];\n\n // Check if this issue is for the current field\n if (path.length > 0) {\n const key = path[0].key || path[0];\n if (key === fieldName) {\n return issue.message || \"Validation error\";\n }\n } else if (path.length === 0 && Object.keys(allValues).length === 1) {\n // Single field validation\n return issue.message || \"Validation error\";\n }\n }\n }\n\n return undefined;\n } catch (error: any) {\n // Handle parsing errors\n if (error.issues && Array.isArray(error.issues)) {\n for (const issue of error.issues) {\n const path = issue.path || [];\n if (path.length > 0) {\n const key = path[0].key || path[0];\n if (key === fieldName) {\n return issue.message || \"Validation error\";\n }\n }\n }\n }\n\n return error.message || \"Validation error\";\n }\n };\n };\n\n // We can't introspect Valibot schema keys directly in a type-safe way,\n // so we'll return a proxy that creates validators on-demand\n return new Proxy(validationSchema, {\n get(_target, prop: string | symbol) {\n if (typeof prop === \"string\") {\n return createFieldValidator(prop as keyof T);\n }\n return undefined;\n },\n ownKeys() {\n // Return empty array - validators are created on-demand\n return [];\n },\n getOwnPropertyDescriptor() {\n return {\n enumerable: true,\n configurable: true,\n };\n },\n }) as ValidationSchema<T>;\n}\n\n/**\n * Create a field validator from a Valibot schema\n *\n * For single-field validation without a full form schema.\n *\n * @example\n * ```tsx\n * import * as v from 'valibot';\n * import { Field } from '@page-speed/forms/core';\n * import { createFieldValidator } from '@page-speed/forms/validation/valibot';\n *\n * const emailSchema = v.pipe(v.string(), v.email('Invalid email'));\n *\n * <Field\n * name=\"email\"\n * validate={createFieldValidator(emailSchema)}\n * >\n * {({ field, meta }) => <input {...field} />}\n * </Field>\n * ```\n */\nexport function createFieldValidator<T = any>(\n schema: ValibotSchema<T>\n): FieldValidator<T> {\n const hasSafeParse = \"safeParse\" in schema && typeof schema.safeParse === \"function\";\n\n return async (value: T): Promise<string | undefined> => {\n try {\n const result = hasSafeParse\n ? (schema as any).safeParse(value)\n : (() => {\n try {\n const parsed = schema._parse(value);\n return { success: !parsed.issues || parsed.issues.length === 0, output: parsed.output, issues: parsed.issues };\n } catch (error: any) {\n return { success: false, issues: error.issues || [{ message: error.message }] };\n }\n })();\n\n if (!result.success && result.issues && result.issues.length > 0) {\n return result.issues[0].message || \"Validation error\";\n }\n\n return undefined;\n } catch (error: any) {\n if (error.issues && error.issues.length > 0) {\n return error.issues[0].message || \"Validation error\";\n }\n return error.message || \"Validation error\";\n }\n };\n}\n\n/**\n * Helper to infer form values type from Valibot schema\n */\nexport type InferValibotInput<T extends ValibotSchema> = T extends ValibotSchema<\n infer U\n>\n ? U\n : never;\n\n/**\n * Helper to infer form values type from Valibot schema output\n */\nexport type InferValibotOutput<T extends ValibotSchema> = T extends ValibotSchema<\n infer U\n>\n ? U\n : never;\n"]}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk2FXAQT7S_cjs = require('./chunk-2FXAQT7S.cjs');
|
|
4
|
+
var chunkP37YLBFA_cjs = require('./chunk-P37YLBFA.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "alpha", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunk2FXAQT7S_cjs.alpha; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "alphanumeric", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunk2FXAQT7S_cjs.alphanumeric; }
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "compose", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return chunk2FXAQT7S_cjs.compose; }
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "creditCard", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return chunk2FXAQT7S_cjs.creditCard; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "email", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return chunk2FXAQT7S_cjs.email; }
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "integer", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return chunk2FXAQT7S_cjs.integer; }
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "matches", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return chunk2FXAQT7S_cjs.matches; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "max", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return chunk2FXAQT7S_cjs.max; }
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "maxLength", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () { return chunk2FXAQT7S_cjs.maxLength; }
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(exports, "min", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () { return chunk2FXAQT7S_cjs.min; }
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "minLength", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () { return chunk2FXAQT7S_cjs.minLength; }
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports, "numeric", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () { return chunk2FXAQT7S_cjs.numeric; }
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(exports, "oneOf", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () { return chunk2FXAQT7S_cjs.oneOf; }
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "pattern", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () { return chunk2FXAQT7S_cjs.pattern; }
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(exports, "phone", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () { return chunk2FXAQT7S_cjs.phone; }
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(exports, "postalCode", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function () { return chunk2FXAQT7S_cjs.postalCode; }
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "required", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () { return chunk2FXAQT7S_cjs.required; }
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(exports, "url", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () { return chunk2FXAQT7S_cjs.url; }
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(exports, "asyncValidator", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function () { return chunkP37YLBFA_cjs.asyncValidator; }
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "crossFieldValidator", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () { return chunkP37YLBFA_cjs.crossFieldValidator; }
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(exports, "debounce", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function () { return chunkP37YLBFA_cjs.debounce; }
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(exports, "defaultMessages", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function () { return chunkP37YLBFA_cjs.defaultMessages; }
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(exports, "getErrorMessage", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: function () { return chunkP37YLBFA_cjs.getErrorMessage; }
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(exports, "messageRegistry", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
get: function () { return chunkP37YLBFA_cjs.messageRegistry; }
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, "resetErrorMessages", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function () { return chunkP37YLBFA_cjs.resetErrorMessages; }
|
|
107
|
+
});
|
|
108
|
+
Object.defineProperty(exports, "setErrorMessages", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get: function () { return chunkP37YLBFA_cjs.setErrorMessages; }
|
|
111
|
+
});
|
|
112
|
+
Object.defineProperty(exports, "when", {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
get: function () { return chunkP37YLBFA_cjs.when; }
|
|
115
|
+
});
|
|
116
|
+
Object.defineProperty(exports, "withRaceConditionPrevention", {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () { return chunkP37YLBFA_cjs.withRaceConditionPrevention; }
|
|
119
|
+
});
|
|
120
|
+
//# sourceMappingURL=validation.cjs.map
|
|
121
|
+
//# sourceMappingURL=validation.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"validation.cjs"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { F as FieldValidator, a as ValidationMode, V as ValidationSchema } from './types-Cw5CeZP-.cjs';
|
|
2
|
+
export { ErrorMessageFn, ValidationRuleOptions, alpha, alphanumeric, compose, creditCard, email, integer, matches, max, maxLength, min, minLength, numeric, oneOf, pattern, phone, postalCode, required, url } from './validation-rules.cjs';
|
|
3
|
+
export { DebounceOptions, ErrorMessages, MessageTemplate, asyncValidator, crossFieldValidator, debounce, defaultMessages, getErrorMessage, messageRegistry, resetErrorMessages, setErrorMessages, when, withRaceConditionPrevention } from './validation-utils.cjs';
|
|
4
|
+
import 'react';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { F as FieldValidator, a as ValidationMode, V as ValidationSchema } from './types-Cw5CeZP-.js';
|
|
2
|
+
export { ErrorMessageFn, ValidationRuleOptions, alpha, alphanumeric, compose, creditCard, email, integer, matches, max, maxLength, min, minLength, numeric, oneOf, pattern, phone, postalCode, required, url } from './validation-rules.js';
|
|
3
|
+
export { DebounceOptions, ErrorMessages, MessageTemplate, asyncValidator, crossFieldValidator, debounce, defaultMessages, getErrorMessage, messageRegistry, resetErrorMessages, setErrorMessages, when, withRaceConditionPrevention } from './validation-utils.js';
|
|
4
|
+
import 'react';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { alpha, alphanumeric, compose, creditCard, email, integer, matches, max, maxLength, min, minLength, numeric, oneOf, pattern, phone, postalCode, required, url } from './chunk-YTTOWHBZ.js';
|
|
2
|
+
export { asyncValidator, crossFieldValidator, debounce, defaultMessages, getErrorMessage, messageRegistry, resetErrorMessages, setErrorMessages, when, withRaceConditionPrevention } from './chunk-WHQMBQNI.js';
|
|
3
|
+
//# sourceMappingURL=validation.js.map
|
|
4
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"validation.js"}
|
package/package.json
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@page-speed/forms",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Ultra-high-performance React form library with field-level reactivity and tree-shakable architecture",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"forms",
|
|
8
|
+
"validation",
|
|
9
|
+
"performance",
|
|
10
|
+
"pagespeed",
|
|
11
|
+
"tree-shakeable",
|
|
12
|
+
"valibot",
|
|
13
|
+
"observable",
|
|
14
|
+
"reactive"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/opensite-ai/page-speed-forms#readme",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/opensite-ai/page-speed-forms.git"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/opensite-ai/page-speed-forms/issues"
|
|
23
|
+
},
|
|
24
|
+
"author": "OpenSite AI (https://opensite.ai)",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.mjs",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.mjs",
|
|
34
|
+
"require": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./core": {
|
|
37
|
+
"types": "./dist/core.d.ts",
|
|
38
|
+
"import": "./dist/core.mjs",
|
|
39
|
+
"require": "./dist/core.js"
|
|
40
|
+
},
|
|
41
|
+
"./inputs": {
|
|
42
|
+
"types": "./dist/inputs.d.ts",
|
|
43
|
+
"import": "./dist/inputs.mjs",
|
|
44
|
+
"require": "./dist/inputs.js"
|
|
45
|
+
},
|
|
46
|
+
"./validation": {
|
|
47
|
+
"types": "./dist/validation.d.ts",
|
|
48
|
+
"import": "./dist/validation.mjs",
|
|
49
|
+
"require": "./dist/validation.js"
|
|
50
|
+
},
|
|
51
|
+
"./validation/valibot": {
|
|
52
|
+
"types": "./dist/validation-valibot.d.ts",
|
|
53
|
+
"import": "./dist/validation-valibot.mjs",
|
|
54
|
+
"require": "./dist/validation-valibot.js"
|
|
55
|
+
},
|
|
56
|
+
"./validation/rules": {
|
|
57
|
+
"types": "./dist/validation-rules.d.ts",
|
|
58
|
+
"import": "./dist/validation-rules.mjs",
|
|
59
|
+
"require": "./dist/validation-rules.js"
|
|
60
|
+
},
|
|
61
|
+
"./validation/utils": {
|
|
62
|
+
"types": "./dist/validation-utils.d.ts",
|
|
63
|
+
"import": "./dist/validation-utils.mjs",
|
|
64
|
+
"require": "./dist/validation-utils.js"
|
|
65
|
+
},
|
|
66
|
+
"./upload": {
|
|
67
|
+
"types": "./dist/upload.d.ts",
|
|
68
|
+
"import": "./dist/upload.mjs",
|
|
69
|
+
"require": "./dist/upload.js"
|
|
70
|
+
},
|
|
71
|
+
"./integration": {
|
|
72
|
+
"types": "./dist/integration.d.ts",
|
|
73
|
+
"import": "./dist/integration.mjs",
|
|
74
|
+
"require": "./dist/integration.js"
|
|
75
|
+
},
|
|
76
|
+
"./builder": {
|
|
77
|
+
"types": "./dist/builder.d.ts",
|
|
78
|
+
"import": "./dist/builder.mjs",
|
|
79
|
+
"require": "./dist/builder.js"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"files": [
|
|
83
|
+
"dist",
|
|
84
|
+
"README.md",
|
|
85
|
+
"LICENSE"
|
|
86
|
+
],
|
|
87
|
+
"publishConfig": {
|
|
88
|
+
"access": "public"
|
|
89
|
+
},
|
|
90
|
+
"sideEffects": false,
|
|
91
|
+
"scripts": {
|
|
92
|
+
"build": "tsup",
|
|
93
|
+
"dev": "tsup --watch",
|
|
94
|
+
"test": "vitest",
|
|
95
|
+
"test:ci": "vitest run",
|
|
96
|
+
"type-check": "tsc --noEmit",
|
|
97
|
+
"size": "size-limit",
|
|
98
|
+
"prepublishOnly": "pnpm run build && pnpm run test:ci && pnpm run size"
|
|
99
|
+
},
|
|
100
|
+
"peerDependencies": {
|
|
101
|
+
"react": ">=16.8.0",
|
|
102
|
+
"react-dom": ">=16.8.0"
|
|
103
|
+
},
|
|
104
|
+
"devDependencies": {
|
|
105
|
+
"@size-limit/preset-small-lib": "^11.2.0",
|
|
106
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
107
|
+
"@testing-library/react": "^16.3.0",
|
|
108
|
+
"@testing-library/user-event": "^14.6.1",
|
|
109
|
+
"@types/node": "^24.10.0",
|
|
110
|
+
"@types/react": "^18.3.12",
|
|
111
|
+
"@types/react-dom": "^18.3.1",
|
|
112
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
113
|
+
"@vitest/coverage-v8": "^4.0.10",
|
|
114
|
+
"@vitest/ui": "^4.0.10",
|
|
115
|
+
"happy-dom": "^20.0.10",
|
|
116
|
+
"jsdom": "^27.2.0",
|
|
117
|
+
"react": "^18.3.1",
|
|
118
|
+
"react-dom": "^18.3.1",
|
|
119
|
+
"size-limit": "^11.1.6",
|
|
120
|
+
"tsup": "^8.3.5",
|
|
121
|
+
"typescript": "^5.7.2",
|
|
122
|
+
"vitest": "^4.0.10"
|
|
123
|
+
},
|
|
124
|
+
"optionalDependencies": {
|
|
125
|
+
"@legendapp/state": "^3.0.0-beta.42",
|
|
126
|
+
"valibot": "^1.0.0"
|
|
127
|
+
},
|
|
128
|
+
"packageManager": "pnpm@9.14.4",
|
|
129
|
+
"engines": {
|
|
130
|
+
"node": ">=18.0.0",
|
|
131
|
+
"pnpm": ">=9.0.0"
|
|
132
|
+
}
|
|
133
|
+
}
|