rustica 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.
Potentially problematic release.
This version of rustica might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +228 -0
- package/dist/form/index.d.ts +60 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +186 -0
- package/dist/form/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +55 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +120 -0
- package/dist/react/index.js.map +1 -0
- package/dist/schema/builders.d.ts +110 -0
- package/dist/schema/builders.d.ts.map +1 -0
- package/dist/schema/builders.js +183 -0
- package/dist/schema/builders.js.map +1 -0
- package/dist/schema/index.d.ts +35 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +42 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/types.d.ts +54 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +5 -0
- package/dist/schema/types.js.map +1 -0
- package/dist/validator/index.d.ts +67 -0
- package/dist/validator/index.d.ts.map +1 -0
- package/dist/validator/index.js +118 -0
- package/dist/validator/index.js.map +1 -0
- package/package.json +72 -0
- package/pkg/README.md +228 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, useRef } from "react";
|
|
2
|
+
import { createForm } from "../form";
|
|
3
|
+
/**
|
|
4
|
+
* React hook for WASM-powered form validation
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const form = useWasmForm({
|
|
9
|
+
* schema: loginSchema,
|
|
10
|
+
* defaultValues: { email: '', password: '' },
|
|
11
|
+
* onSubmit: async (data) => console.log(data)
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* <form onSubmit={form.handleSubmit}>
|
|
15
|
+
* <input {...form.register('email')} />
|
|
16
|
+
* {form.errors.email && <span>{form.errors.email.message}</span>}
|
|
17
|
+
* </form>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function useWasmForm(config) {
|
|
21
|
+
// Create form instance (only once)
|
|
22
|
+
const formRef = useRef(createForm(config));
|
|
23
|
+
const form = formRef.current;
|
|
24
|
+
// Local state for React re-renders
|
|
25
|
+
const [, forceUpdate] = useState({});
|
|
26
|
+
// Subscribe to form changes on mount
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const unsubscribe = form.subscribe(() => {
|
|
29
|
+
forceUpdate({});
|
|
30
|
+
});
|
|
31
|
+
return unsubscribe;
|
|
32
|
+
}, [form]);
|
|
33
|
+
/**
|
|
34
|
+
* Register a field with the form
|
|
35
|
+
* Returns props to spread on input element
|
|
36
|
+
*/
|
|
37
|
+
const register = useCallback((name) => {
|
|
38
|
+
return {
|
|
39
|
+
name: String(name),
|
|
40
|
+
value: form.values[name] ?? "",
|
|
41
|
+
onChange: (event) => {
|
|
42
|
+
let value;
|
|
43
|
+
if ("type" in event.target && event.target.type === "checkbox") {
|
|
44
|
+
value = event.target.checked;
|
|
45
|
+
}
|
|
46
|
+
else if ("type" in event.target && event.target.type === "number") {
|
|
47
|
+
// Convert to number for number inputs
|
|
48
|
+
const numValue = event.target.valueAsNumber;
|
|
49
|
+
value = isNaN(numValue) ? event.target.value : numValue;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
value = event.target.value;
|
|
53
|
+
}
|
|
54
|
+
form.handleChange(name, value);
|
|
55
|
+
},
|
|
56
|
+
onBlur: (event) => {
|
|
57
|
+
form.handleBlur(name);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}, [form]);
|
|
61
|
+
/**
|
|
62
|
+
* Set field value programmatically
|
|
63
|
+
*/
|
|
64
|
+
const setValue = useCallback((field, value) => {
|
|
65
|
+
form.setValue(field, value);
|
|
66
|
+
}, [form]);
|
|
67
|
+
/**
|
|
68
|
+
* Set field error programmatically
|
|
69
|
+
* Useful for async validation or server-side errors
|
|
70
|
+
*/
|
|
71
|
+
const setError = useCallback((field, error) => {
|
|
72
|
+
form.errors[field] = error;
|
|
73
|
+
forceUpdate({});
|
|
74
|
+
}, [form]);
|
|
75
|
+
/**
|
|
76
|
+
* Handle form submission
|
|
77
|
+
*/
|
|
78
|
+
const handleSubmit = useCallback(async (event) => {
|
|
79
|
+
await form.handleSubmit(event);
|
|
80
|
+
}, [form]);
|
|
81
|
+
/**
|
|
82
|
+
* Reset form to initial state
|
|
83
|
+
*/
|
|
84
|
+
const reset = useCallback(() => {
|
|
85
|
+
form.reset();
|
|
86
|
+
}, [form]);
|
|
87
|
+
return {
|
|
88
|
+
register,
|
|
89
|
+
values: form.values,
|
|
90
|
+
errors: form.errors,
|
|
91
|
+
touched: form.touched,
|
|
92
|
+
isSubmitting: form.isSubmitting,
|
|
93
|
+
isValid: form.isValid,
|
|
94
|
+
setValue,
|
|
95
|
+
setError,
|
|
96
|
+
handleSubmit,
|
|
97
|
+
reset,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Hook to get field error message
|
|
102
|
+
* Returns error message if field is touched and has error
|
|
103
|
+
*/
|
|
104
|
+
export function useFieldError(form, field) {
|
|
105
|
+
const error = form.errors[field];
|
|
106
|
+
const touched = form.touched[field];
|
|
107
|
+
if (touched && error) {
|
|
108
|
+
return error.message;
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Hook to check if field has error
|
|
114
|
+
*/
|
|
115
|
+
export function useFieldHasError(form, field) {
|
|
116
|
+
const error = form.errors[field];
|
|
117
|
+
const touched = form.touched[field];
|
|
118
|
+
return touched && error !== null;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","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AI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,OAAO;QACL,QAAQ;QACR,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,QAAQ;QACR,QAAQ;QACR,YAAY;QACZ,KAAK;KACN,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,IAA0B,EAC1B,KAAc;IAEd,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAEpC,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAA0B,EAC1B,KAAc;IAEd,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAEpC,OAAO,OAAO,IAAI,KAAK,KAAK,IAAI,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { StringSchema, NumberSchema, BooleanSchema, ObjectSchema, UiConfig } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all schema builders
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class SchemaBuilder<T> {
|
|
6
|
+
abstract toJSON(): any;
|
|
7
|
+
/**
|
|
8
|
+
* Add UI configuration for forms
|
|
9
|
+
*/
|
|
10
|
+
abstract ui(config: UiConfig): this;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* String schema builder with fluent API
|
|
14
|
+
*/
|
|
15
|
+
export declare class ZString extends SchemaBuilder<string> {
|
|
16
|
+
private schema;
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Set minimum length constraint
|
|
20
|
+
*/
|
|
21
|
+
min(length: number, message?: string): this;
|
|
22
|
+
/**
|
|
23
|
+
* Set maximum length constraint
|
|
24
|
+
*/
|
|
25
|
+
max(length: number, message?: string): this;
|
|
26
|
+
/**
|
|
27
|
+
* Mark as email validation
|
|
28
|
+
*/
|
|
29
|
+
email(message?: string): this;
|
|
30
|
+
/**
|
|
31
|
+
* Mark as URL validation
|
|
32
|
+
*/
|
|
33
|
+
url(message?: string): this;
|
|
34
|
+
/**
|
|
35
|
+
* Add pattern matching
|
|
36
|
+
*/
|
|
37
|
+
pattern(regex: string, message?: string): this;
|
|
38
|
+
/**
|
|
39
|
+
* Add UI configuration
|
|
40
|
+
*/
|
|
41
|
+
ui(config: UiConfig): this;
|
|
42
|
+
/**
|
|
43
|
+
* Serialize to JSON for Rust validation
|
|
44
|
+
*/
|
|
45
|
+
toJSON(): StringSchema;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Number schema builder with fluent API
|
|
49
|
+
*/
|
|
50
|
+
export declare class ZNumber extends SchemaBuilder<number> {
|
|
51
|
+
private schema;
|
|
52
|
+
constructor();
|
|
53
|
+
/**
|
|
54
|
+
* Set minimum value constraint
|
|
55
|
+
*/
|
|
56
|
+
min(value: number, message?: string): this;
|
|
57
|
+
/**
|
|
58
|
+
* Set maximum value constraint
|
|
59
|
+
*/
|
|
60
|
+
max(value: number, message?: string): this;
|
|
61
|
+
/**
|
|
62
|
+
* Require integer values only
|
|
63
|
+
*/
|
|
64
|
+
integer(message?: string): this;
|
|
65
|
+
/**
|
|
66
|
+
* Require positive values only
|
|
67
|
+
*/
|
|
68
|
+
positive(message?: string): this;
|
|
69
|
+
/**
|
|
70
|
+
* Add UI configuration
|
|
71
|
+
*/
|
|
72
|
+
ui(config: UiConfig): this;
|
|
73
|
+
/**
|
|
74
|
+
* Serialize to JSON for Rust validation
|
|
75
|
+
*/
|
|
76
|
+
toJSON(): NumberSchema;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Boolean schema builder with fluent API
|
|
80
|
+
*/
|
|
81
|
+
export declare class ZBoolean extends SchemaBuilder<boolean> {
|
|
82
|
+
private schema;
|
|
83
|
+
constructor();
|
|
84
|
+
/**
|
|
85
|
+
* Add UI configuration
|
|
86
|
+
*/
|
|
87
|
+
ui(config: UiConfig): this;
|
|
88
|
+
/**
|
|
89
|
+
* Serialize to JSON for Rust validation
|
|
90
|
+
*/
|
|
91
|
+
toJSON(): BooleanSchema;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Object schema builder with fluent API
|
|
95
|
+
*/
|
|
96
|
+
export declare class ZObject<T extends Record<string, SchemaBuilder<any>>> extends SchemaBuilder<{
|
|
97
|
+
[K in keyof T]: T[K] extends SchemaBuilder<infer U> ? U : never;
|
|
98
|
+
}> {
|
|
99
|
+
private schema;
|
|
100
|
+
constructor(shape: T);
|
|
101
|
+
/**
|
|
102
|
+
* Add UI configuration
|
|
103
|
+
*/
|
|
104
|
+
ui(config: UiConfig): this;
|
|
105
|
+
/**
|
|
106
|
+
* Serialize to JSON for Rust validation
|
|
107
|
+
*/
|
|
108
|
+
toJSON(): ObjectSchema;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../src/schema/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,QAAQ,EACT,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,8BAAsB,aAAa,CAAC,CAAC;IACnC,QAAQ,CAA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AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,aAAa,CAAC,OAAO,CAAC;IAClD,OAAO,CAAC,MAAM,CAAgB;;IAO9B;;OAEG;IACH,EAAE,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI;IAK1B;;OAEG;IACH,MAAM,IAAI,aAAa;CAGxB;AAED;;GAEG;AACH,qBAAa,OAAO,CAClB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAC5C,SAAQ,aAAa,CAAC;KACrB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAChE,CAAC;IACA,OAAO,CAAC,MAAM,CAAe;gBAEjB,KAAK,EAAE,CAAC;IAepB;;OAEG;IACH,EAAE,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI;IAK1B;;OAEG;IACH,MAAM,IAAI,YAAY;CAGvB"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all schema builders
|
|
3
|
+
*/
|
|
4
|
+
export class SchemaBuilder {
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* String schema builder with fluent API
|
|
8
|
+
*/
|
|
9
|
+
export class ZString extends SchemaBuilder {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this.schema = { type: "string" };
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Set minimum length constraint
|
|
16
|
+
*/
|
|
17
|
+
min(length, message) {
|
|
18
|
+
this.schema.min = length;
|
|
19
|
+
if (message)
|
|
20
|
+
this.schema.minMessage = message;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Set maximum length constraint
|
|
25
|
+
*/
|
|
26
|
+
max(length, message) {
|
|
27
|
+
this.schema.max = length;
|
|
28
|
+
if (message)
|
|
29
|
+
this.schema.maxMessage = message;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Mark as email validation
|
|
34
|
+
*/
|
|
35
|
+
email(message) {
|
|
36
|
+
this.schema.email = true;
|
|
37
|
+
if (message)
|
|
38
|
+
this.schema.emailMessage = message;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Mark as URL validation
|
|
43
|
+
*/
|
|
44
|
+
url(message) {
|
|
45
|
+
this.schema.url = true;
|
|
46
|
+
if (message)
|
|
47
|
+
this.schema.urlMessage = message;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Add pattern matching
|
|
52
|
+
*/
|
|
53
|
+
pattern(regex, message) {
|
|
54
|
+
this.schema.pattern = regex;
|
|
55
|
+
if (message)
|
|
56
|
+
this.schema.patternMessage = message;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Add UI configuration
|
|
61
|
+
*/
|
|
62
|
+
ui(config) {
|
|
63
|
+
this.schema.ui = config;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Serialize to JSON for Rust validation
|
|
68
|
+
*/
|
|
69
|
+
toJSON() {
|
|
70
|
+
return { ...this.schema };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Number schema builder with fluent API
|
|
75
|
+
*/
|
|
76
|
+
export class ZNumber extends SchemaBuilder {
|
|
77
|
+
constructor() {
|
|
78
|
+
super();
|
|
79
|
+
this.schema = { type: "number" };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Set minimum value constraint
|
|
83
|
+
*/
|
|
84
|
+
min(value, message) {
|
|
85
|
+
this.schema.min = value;
|
|
86
|
+
if (message)
|
|
87
|
+
this.schema.minMessage = message;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Set maximum value constraint
|
|
92
|
+
*/
|
|
93
|
+
max(value, message) {
|
|
94
|
+
this.schema.max = value;
|
|
95
|
+
if (message)
|
|
96
|
+
this.schema.maxMessage = message;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Require integer values only
|
|
101
|
+
*/
|
|
102
|
+
integer(message) {
|
|
103
|
+
this.schema.integer = true;
|
|
104
|
+
if (message)
|
|
105
|
+
this.schema.integerMessage = message;
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Require positive values only
|
|
110
|
+
*/
|
|
111
|
+
positive(message) {
|
|
112
|
+
this.schema.positive = true;
|
|
113
|
+
if (message)
|
|
114
|
+
this.schema.positiveMessage = message;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Add UI configuration
|
|
119
|
+
*/
|
|
120
|
+
ui(config) {
|
|
121
|
+
this.schema.ui = config;
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Serialize to JSON for Rust validation
|
|
126
|
+
*/
|
|
127
|
+
toJSON() {
|
|
128
|
+
return { ...this.schema };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Boolean schema builder with fluent API
|
|
133
|
+
*/
|
|
134
|
+
export class ZBoolean extends SchemaBuilder {
|
|
135
|
+
constructor() {
|
|
136
|
+
super();
|
|
137
|
+
this.schema = { type: "boolean" };
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Add UI configuration
|
|
141
|
+
*/
|
|
142
|
+
ui(config) {
|
|
143
|
+
this.schema.ui = config;
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Serialize to JSON for Rust validation
|
|
148
|
+
*/
|
|
149
|
+
toJSON() {
|
|
150
|
+
return { ...this.schema };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Object schema builder with fluent API
|
|
155
|
+
*/
|
|
156
|
+
export class ZObject extends SchemaBuilder {
|
|
157
|
+
constructor(shape) {
|
|
158
|
+
super();
|
|
159
|
+
// Convert SchemaBuilder instances to their JSON representation
|
|
160
|
+
const jsonShape = {};
|
|
161
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
162
|
+
jsonShape[key] = value.toJSON();
|
|
163
|
+
}
|
|
164
|
+
this.schema = {
|
|
165
|
+
type: "object",
|
|
166
|
+
shape: jsonShape,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Add UI configuration
|
|
171
|
+
*/
|
|
172
|
+
ui(config) {
|
|
173
|
+
this.schema.ui = config;
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Serialize to JSON for Rust validation
|
|
178
|
+
*/
|
|
179
|
+
toJSON() {
|
|
180
|
+
return { ...this.schema };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=builders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.js","sourceRoot":"","sources":["../../src/schema/builders.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,OAAgB,aAAa;CAOlC;AAED;;GAEG;AACH,MAAM,OAAO,OAAQ,SAAQ,aAAqB;IAGhD;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,MAAc,EAAE,OAAgB;QAClC,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC;QACzB,IAAI,OAAO;YAAE,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,MAAc,EAAE,OAAgB;QAClC,IAAI,CAAC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;IACH,MAAM;QACJ,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,OAEX,SAAQ,aAER;IAGA,YAAY,KAAQ;QAClB,KAAK,EAAE,CAAC;QAER,+DAA+D;QAC/D,MAAM,SAAS,GAAwB,EAAE,CAAC;QAC1C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAClC,CAAC;QAED,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,SAAS;SACjB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,EAAE,CAAC,MAAgB;QACjB,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ZString, ZNumber, ZBoolean, ZObject, SchemaBuilder } from "./builders";
|
|
2
|
+
/**
|
|
3
|
+
* Main schema builder API (Rustica-style)
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const schema = r.object({
|
|
8
|
+
* email: r.string().min(3).email(),
|
|
9
|
+
* age: r.number().min(0).integer()
|
|
10
|
+
* });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const r: {
|
|
14
|
+
/**
|
|
15
|
+
* Create a string schema
|
|
16
|
+
*/
|
|
17
|
+
string(): ZString;
|
|
18
|
+
/**
|
|
19
|
+
* Create a number schema
|
|
20
|
+
*/
|
|
21
|
+
number(): ZNumber;
|
|
22
|
+
/**
|
|
23
|
+
* Create a boolean schema
|
|
24
|
+
*/
|
|
25
|
+
boolean(): ZBoolean;
|
|
26
|
+
/**
|
|
27
|
+
* Create an object schema
|
|
28
|
+
*/
|
|
29
|
+
object<T extends Record<string, SchemaBuilder<any>>>(shape: T): ZObject<T>;
|
|
30
|
+
};
|
|
31
|
+
export type Infer<T> = T extends SchemaBuilder<infer U> ? U : never;
|
|
32
|
+
export { ZString, ZNumber, ZBoolean, ZObject, SchemaBuilder };
|
|
33
|
+
export type { UiConfig } from "./types";
|
|
34
|
+
export * from "./types";
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,CAAC;IACZ;;OAEG;cACO,OAAO;IAIjB;;OAEG;cACO,OAAO;IAIjB;;OAEG;eACQ,QAAQ;IAInB;;OAEG;WACI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAG3E,CAAC;AAGF,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAGpE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;AAC9D,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ZString, ZNumber, ZBoolean, ZObject, SchemaBuilder } from "./builders";
|
|
2
|
+
/**
|
|
3
|
+
* Main schema builder API (Rustica-style)
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const schema = r.object({
|
|
8
|
+
* email: r.string().min(3).email(),
|
|
9
|
+
* age: r.number().min(0).integer()
|
|
10
|
+
* });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export const r = {
|
|
14
|
+
/**
|
|
15
|
+
* Create a string schema
|
|
16
|
+
*/
|
|
17
|
+
string() {
|
|
18
|
+
return new ZString();
|
|
19
|
+
},
|
|
20
|
+
/**
|
|
21
|
+
* Create a number schema
|
|
22
|
+
*/
|
|
23
|
+
number() {
|
|
24
|
+
return new ZNumber();
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* Create a boolean schema
|
|
28
|
+
*/
|
|
29
|
+
boolean() {
|
|
30
|
+
return new ZBoolean();
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* Create an object schema
|
|
34
|
+
*/
|
|
35
|
+
object(shape) {
|
|
36
|
+
return new ZObject(shape);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
// Re-export builders for advanced usage
|
|
40
|
+
export { ZString, ZNumber, ZBoolean, ZObject, SchemaBuilder };
|
|
41
|
+
export * from "./types";
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,CAAC,GAAG;IACf;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,OAAO,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,OAAO,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,QAAQ,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,MAAM,CAA+C,KAAQ;QAC3D,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;CACF,CAAC;AAKF,wCAAwC;AACxC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;AAE9D,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema types matching Rust Schema enum
|
|
3
|
+
*/
|
|
4
|
+
export interface UiConfig {
|
|
5
|
+
label?: string;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface StringSchema {
|
|
10
|
+
type: "string";
|
|
11
|
+
min?: number;
|
|
12
|
+
max?: number;
|
|
13
|
+
email?: boolean;
|
|
14
|
+
url?: boolean;
|
|
15
|
+
pattern?: string;
|
|
16
|
+
minMessage?: string;
|
|
17
|
+
maxMessage?: string;
|
|
18
|
+
emailMessage?: string;
|
|
19
|
+
urlMessage?: string;
|
|
20
|
+
patternMessage?: string;
|
|
21
|
+
ui?: UiConfig;
|
|
22
|
+
}
|
|
23
|
+
export interface NumberSchema {
|
|
24
|
+
type: "number";
|
|
25
|
+
min?: number;
|
|
26
|
+
max?: number;
|
|
27
|
+
integer?: boolean;
|
|
28
|
+
positive?: boolean;
|
|
29
|
+
minMessage?: string;
|
|
30
|
+
maxMessage?: string;
|
|
31
|
+
integerMessage?: string;
|
|
32
|
+
positiveMessage?: string;
|
|
33
|
+
ui?: UiConfig;
|
|
34
|
+
}
|
|
35
|
+
export interface BooleanSchema {
|
|
36
|
+
type: "boolean";
|
|
37
|
+
ui?: UiConfig;
|
|
38
|
+
}
|
|
39
|
+
export interface ObjectSchema {
|
|
40
|
+
type: "object";
|
|
41
|
+
shape: Record<string, Schema>;
|
|
42
|
+
ui?: UiConfig;
|
|
43
|
+
}
|
|
44
|
+
export type Schema = StringSchema | NumberSchema | BooleanSchema | ObjectSchema;
|
|
45
|
+
export interface ValidationError {
|
|
46
|
+
path: string[];
|
|
47
|
+
code: string;
|
|
48
|
+
message: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ValidationResult {
|
|
51
|
+
success: boolean;
|
|
52
|
+
errors?: ValidationError[];
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/schema/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,EAAE,CAAC,EAAE,QAAQ,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,EAAE,CAAC,EAAE,QAAQ,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,CAAC,EAAE,QAAQ,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,EAAE,CAAC,EAAE,QAAQ,CAAC;CACf;AAED,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,YAAY,GAAG,aAAa,GAAG,YAAY,CAAC;AAEhF,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;CAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/schema/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Schema, ValidationResult, ValidationError } from "../schema/types";
|
|
2
|
+
import type { SchemaBuilder } from "../schema/builders";
|
|
3
|
+
/**
|
|
4
|
+
* WASM module interface
|
|
5
|
+
* Auto-generated by wasm-pack
|
|
6
|
+
*/
|
|
7
|
+
export interface WasmModule {
|
|
8
|
+
WasmValidator: {
|
|
9
|
+
validate(schema_json: string, value_json: string): string;
|
|
10
|
+
validate_at_path(schema_json: string, value_json: string, path_json: string): string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Initialize WASM module
|
|
15
|
+
* Must be called before validation
|
|
16
|
+
*/
|
|
17
|
+
export declare function initWasm(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Core validator using WASM
|
|
20
|
+
*/
|
|
21
|
+
export declare class Validator {
|
|
22
|
+
/**
|
|
23
|
+
* Validate data against a schema
|
|
24
|
+
*
|
|
25
|
+
* @param schema - Schema definition (builder or JSON)
|
|
26
|
+
* @param value - Data to validate
|
|
27
|
+
* @returns Validation result with errors if any
|
|
28
|
+
*/
|
|
29
|
+
static validate<T>(schema: SchemaBuilder<T> | Schema, value: unknown): ValidationResult;
|
|
30
|
+
/**
|
|
31
|
+
* Validate data at a specific path in the schema
|
|
32
|
+
* Useful for field-level validation in forms
|
|
33
|
+
*
|
|
34
|
+
* @param schema - Schema definition
|
|
35
|
+
* @param value - Complete data object
|
|
36
|
+
* @param path - Path to validate (e.g., ['user', 'email'])
|
|
37
|
+
* @returns Validation result for the specific field
|
|
38
|
+
*/
|
|
39
|
+
static validateAtPath<T>(schema: SchemaBuilder<T> | Schema, value: unknown, path: string[]): ValidationResult;
|
|
40
|
+
/**
|
|
41
|
+
* Validate and throw on error (for convenience)
|
|
42
|
+
*/
|
|
43
|
+
static parse<T>(schema: SchemaBuilder<T> | Schema, value: unknown): T;
|
|
44
|
+
/**
|
|
45
|
+
* Safe parse that returns result object
|
|
46
|
+
*/
|
|
47
|
+
static safeParse<T>(schema: SchemaBuilder<T> | Schema, value: unknown): {
|
|
48
|
+
success: true;
|
|
49
|
+
data: T;
|
|
50
|
+
} | {
|
|
51
|
+
success: false;
|
|
52
|
+
errors: ValidationError[];
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validation exception for parse() method
|
|
57
|
+
*/
|
|
58
|
+
export declare class ValidationException extends Error {
|
|
59
|
+
errors: ValidationError[];
|
|
60
|
+
constructor(errors: ValidationError[]);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Auto-initialization wrapper
|
|
64
|
+
* Automatically initializes WASM on first use
|
|
65
|
+
*/
|
|
66
|
+
export declare function createValidator(): Promise<typeof Validator>;
|
|
67
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validator/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,gBAAgB,EAChB,eAAe,EAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE;QACb,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;QAC1D,gBAAgB,CACd,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,MAAM,CAAC;KACX,CAAC;CACH;AAOD;;;GAGG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAkB9C;AAcD;;GAEG;AACH,qBAAa,SAAS;IACpB;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,CAAC,EACf,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,EACjC,KAAK,EAAE,OAAO,GACb,gBAAgB;IAkBnB;;;;;;;;OAQG;IACH,MAAM,CAAC,cAAc,CAAC,CAAC,EACrB,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,EACjC,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,EAAE,GACb,gBAAgB;IAqBnB;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC;IAUrE;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,EAChB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