nanoppa commited on
Commit
21c8bff
·
verified ·
1 Parent(s): 9c0f270

Upload 3780 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +2 -0
  2. node_modules/@alloc/quick-lru/index.d.ts +128 -0
  3. node_modules/@alloc/quick-lru/index.js +263 -0
  4. node_modules/@alloc/quick-lru/license +9 -0
  5. node_modules/@alloc/quick-lru/package.json +43 -0
  6. node_modules/@alloc/quick-lru/readme.md +139 -0
  7. node_modules/@hookform/resolvers/LICENSE +21 -0
  8. node_modules/@hookform/resolvers/README.md +794 -0
  9. node_modules/@hookform/resolvers/ajv/dist/ajv.d.ts +2 -0
  10. node_modules/@hookform/resolvers/ajv/dist/ajv.js +2 -0
  11. node_modules/@hookform/resolvers/ajv/dist/ajv.js.map +1 -0
  12. node_modules/@hookform/resolvers/ajv/dist/ajv.mjs +2 -0
  13. node_modules/@hookform/resolvers/ajv/dist/ajv.modern.mjs +2 -0
  14. node_modules/@hookform/resolvers/ajv/dist/ajv.modern.mjs.map +1 -0
  15. node_modules/@hookform/resolvers/ajv/dist/ajv.module.js +2 -0
  16. node_modules/@hookform/resolvers/ajv/dist/ajv.module.js.map +1 -0
  17. node_modules/@hookform/resolvers/ajv/dist/ajv.umd.js +2 -0
  18. node_modules/@hookform/resolvers/ajv/dist/ajv.umd.js.map +1 -0
  19. node_modules/@hookform/resolvers/ajv/dist/index.d.ts +2 -0
  20. node_modules/@hookform/resolvers/ajv/dist/types.d.ts +5 -0
  21. node_modules/@hookform/resolvers/ajv/package.json +19 -0
  22. node_modules/@hookform/resolvers/ajv/src/__tests__/Form-native-validation.tsx +94 -0
  23. node_modules/@hookform/resolvers/ajv/src/__tests__/Form.tsx +65 -0
  24. node_modules/@hookform/resolvers/ajv/src/__tests__/__fixtures__/data.ts +90 -0
  25. node_modules/@hookform/resolvers/ajv/src/__tests__/__snapshots__/ajv.ts.snap +245 -0
  26. node_modules/@hookform/resolvers/ajv/src/__tests__/ajv.ts +103 -0
  27. node_modules/@hookform/resolvers/ajv/src/ajv.ts +88 -0
  28. node_modules/@hookform/resolvers/ajv/src/index.ts +2 -0
  29. node_modules/@hookform/resolvers/ajv/src/types.ts +12 -0
  30. node_modules/@hookform/resolvers/arktype/dist/arktype.d.ts +2 -0
  31. node_modules/@hookform/resolvers/arktype/dist/arktype.js +2 -0
  32. node_modules/@hookform/resolvers/arktype/dist/arktype.js.map +1 -0
  33. node_modules/@hookform/resolvers/arktype/dist/arktype.mjs +2 -0
  34. node_modules/@hookform/resolvers/arktype/dist/arktype.modern.mjs +2 -0
  35. node_modules/@hookform/resolvers/arktype/dist/arktype.modern.mjs.map +1 -0
  36. node_modules/@hookform/resolvers/arktype/dist/arktype.module.js +2 -0
  37. node_modules/@hookform/resolvers/arktype/dist/arktype.module.js.map +1 -0
  38. node_modules/@hookform/resolvers/arktype/dist/arktype.umd.js +2 -0
  39. node_modules/@hookform/resolvers/arktype/dist/arktype.umd.js.map +1 -0
  40. node_modules/@hookform/resolvers/arktype/dist/index.d.ts +2 -0
  41. node_modules/@hookform/resolvers/arktype/dist/types.d.ts +9 -0
  42. node_modules/@hookform/resolvers/arktype/package.json +18 -0
  43. node_modules/@hookform/resolvers/arktype/src/__tests__/Form-native-validation.tsx +82 -0
  44. node_modules/@hookform/resolvers/arktype/src/__tests__/Form.tsx +56 -0
  45. node_modules/@hookform/resolvers/arktype/src/__tests__/__fixtures__/data.ts +65 -0
  46. node_modules/@hookform/resolvers/arktype/src/__tests__/__snapshots__/arktype.ts.snap +467 -0
  47. node_modules/@hookform/resolvers/arktype/src/__tests__/arktype.ts +26 -0
  48. node_modules/@hookform/resolvers/arktype/src/arktype.ts +31 -0
  49. node_modules/@hookform/resolvers/arktype/src/index.ts +2 -0
  50. node_modules/@hookform/resolvers/arktype/src/types.ts +18 -0
.gitattributes CHANGED
@@ -34,3 +34,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  generated-icon.png filter=lfs diff=lfs merge=lfs -text
 
 
 
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  generated-icon.png filter=lfs diff=lfs merge=lfs -text
37
+ node_modules/drizzle-kit/node_modules/@esbuild/darwin-arm64/bin/esbuild filter=lfs diff=lfs merge=lfs -text
38
+ node_modules/drizzle-kit/node_modules/esbuild/bin/esbuild filter=lfs diff=lfs merge=lfs -text
node_modules/@alloc/quick-lru/index.d.ts ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ declare namespace QuickLRU {
2
+ interface Options<KeyType, ValueType> {
3
+ /**
4
+ The maximum number of milliseconds an item should remain in the cache.
5
+
6
+ @default Infinity
7
+
8
+ By default, `maxAge` will be `Infinity`, which means that items will never expire.
9
+ Lazy expiration upon the next write or read call.
10
+
11
+ Individual expiration of an item can be specified by the `set(key, value, maxAge)` method.
12
+ */
13
+ readonly maxAge?: number;
14
+
15
+ /**
16
+ The maximum number of items before evicting the least recently used items.
17
+ */
18
+ readonly maxSize: number;
19
+
20
+ /**
21
+ Called right before an item is evicted from the cache.
22
+
23
+ Useful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`).
24
+ */
25
+ onEviction?: (key: KeyType, value: ValueType) => void;
26
+ }
27
+ }
28
+
29
+ declare class QuickLRU<KeyType, ValueType>
30
+ implements Iterable<[KeyType, ValueType]> {
31
+ /**
32
+ The stored item count.
33
+ */
34
+ readonly size: number;
35
+
36
+ /**
37
+ Simple ["Least Recently Used" (LRU) cache](https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29).
38
+
39
+ The instance is [`iterable`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) so you can use it directly in a [`for…of`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) loop.
40
+
41
+ @example
42
+ ```
43
+ import QuickLRU = require('quick-lru');
44
+
45
+ const lru = new QuickLRU({maxSize: 1000});
46
+
47
+ lru.set('🦄', '🌈');
48
+
49
+ lru.has('🦄');
50
+ //=> true
51
+
52
+ lru.get('🦄');
53
+ //=> '🌈'
54
+ ```
55
+ */
56
+ constructor(options: QuickLRU.Options<KeyType, ValueType>);
57
+
58
+ [Symbol.iterator](): IterableIterator<[KeyType, ValueType]>;
59
+
60
+ /**
61
+ Set an item. Returns the instance.
62
+
63
+ Individual expiration of an item can be specified with the `maxAge` option. If not specified, the global `maxAge` value will be used in case it is specified in the constructor, otherwise the item will never expire.
64
+
65
+ @returns The list instance.
66
+ */
67
+ set(key: KeyType, value: ValueType, options?: {maxAge?: number}): this;
68
+
69
+ /**
70
+ Get an item.
71
+
72
+ @returns The stored item or `undefined`.
73
+ */
74
+ get(key: KeyType): ValueType | undefined;
75
+
76
+ /**
77
+ Check if an item exists.
78
+ */
79
+ has(key: KeyType): boolean;
80
+
81
+ /**
82
+ Get an item without marking it as recently used.
83
+
84
+ @returns The stored item or `undefined`.
85
+ */
86
+ peek(key: KeyType): ValueType | undefined;
87
+
88
+ /**
89
+ Delete an item.
90
+
91
+ @returns `true` if the item is removed or `false` if the item doesn't exist.
92
+ */
93
+ delete(key: KeyType): boolean;
94
+
95
+ /**
96
+ Delete all items.
97
+ */
98
+ clear(): void;
99
+
100
+ /**
101
+ Update the `maxSize` in-place, discarding items as necessary. Insertion order is mostly preserved, though this is not a strong guarantee.
102
+
103
+ Useful for on-the-fly tuning of cache sizes in live systems.
104
+ */
105
+ resize(maxSize: number): void;
106
+
107
+ /**
108
+ Iterable for all the keys.
109
+ */
110
+ keys(): IterableIterator<KeyType>;
111
+
112
+ /**
113
+ Iterable for all the values.
114
+ */
115
+ values(): IterableIterator<ValueType>;
116
+
117
+ /**
118
+ Iterable for all entries, starting with the oldest (ascending in recency).
119
+ */
120
+ entriesAscending(): IterableIterator<[KeyType, ValueType]>;
121
+
122
+ /**
123
+ Iterable for all entries, starting with the newest (descending in recency).
124
+ */
125
+ entriesDescending(): IterableIterator<[KeyType, ValueType]>;
126
+ }
127
+
128
+ export = QuickLRU;
node_modules/@alloc/quick-lru/index.js ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ class QuickLRU {
4
+ constructor(options = {}) {
5
+ if (!(options.maxSize && options.maxSize > 0)) {
6
+ throw new TypeError('`maxSize` must be a number greater than 0');
7
+ }
8
+
9
+ if (typeof options.maxAge === 'number' && options.maxAge === 0) {
10
+ throw new TypeError('`maxAge` must be a number greater than 0');
11
+ }
12
+
13
+ this.maxSize = options.maxSize;
14
+ this.maxAge = options.maxAge || Infinity;
15
+ this.onEviction = options.onEviction;
16
+ this.cache = new Map();
17
+ this.oldCache = new Map();
18
+ this._size = 0;
19
+ }
20
+
21
+ _emitEvictions(cache) {
22
+ if (typeof this.onEviction !== 'function') {
23
+ return;
24
+ }
25
+
26
+ for (const [key, item] of cache) {
27
+ this.onEviction(key, item.value);
28
+ }
29
+ }
30
+
31
+ _deleteIfExpired(key, item) {
32
+ if (typeof item.expiry === 'number' && item.expiry <= Date.now()) {
33
+ if (typeof this.onEviction === 'function') {
34
+ this.onEviction(key, item.value);
35
+ }
36
+
37
+ return this.delete(key);
38
+ }
39
+
40
+ return false;
41
+ }
42
+
43
+ _getOrDeleteIfExpired(key, item) {
44
+ const deleted = this._deleteIfExpired(key, item);
45
+ if (deleted === false) {
46
+ return item.value;
47
+ }
48
+ }
49
+
50
+ _getItemValue(key, item) {
51
+ return item.expiry ? this._getOrDeleteIfExpired(key, item) : item.value;
52
+ }
53
+
54
+ _peek(key, cache) {
55
+ const item = cache.get(key);
56
+
57
+ return this._getItemValue(key, item);
58
+ }
59
+
60
+ _set(key, value) {
61
+ this.cache.set(key, value);
62
+ this._size++;
63
+
64
+ if (this._size >= this.maxSize) {
65
+ this._size = 0;
66
+ this._emitEvictions(this.oldCache);
67
+ this.oldCache = this.cache;
68
+ this.cache = new Map();
69
+ }
70
+ }
71
+
72
+ _moveToRecent(key, item) {
73
+ this.oldCache.delete(key);
74
+ this._set(key, item);
75
+ }
76
+
77
+ * _entriesAscending() {
78
+ for (const item of this.oldCache) {
79
+ const [key, value] = item;
80
+ if (!this.cache.has(key)) {
81
+ const deleted = this._deleteIfExpired(key, value);
82
+ if (deleted === false) {
83
+ yield item;
84
+ }
85
+ }
86
+ }
87
+
88
+ for (const item of this.cache) {
89
+ const [key, value] = item;
90
+ const deleted = this._deleteIfExpired(key, value);
91
+ if (deleted === false) {
92
+ yield item;
93
+ }
94
+ }
95
+ }
96
+
97
+ get(key) {
98
+ if (this.cache.has(key)) {
99
+ const item = this.cache.get(key);
100
+
101
+ return this._getItemValue(key, item);
102
+ }
103
+
104
+ if (this.oldCache.has(key)) {
105
+ const item = this.oldCache.get(key);
106
+ if (this._deleteIfExpired(key, item) === false) {
107
+ this._moveToRecent(key, item);
108
+ return item.value;
109
+ }
110
+ }
111
+ }
112
+
113
+ set(key, value, {maxAge = this.maxAge === Infinity ? undefined : Date.now() + this.maxAge} = {}) {
114
+ if (this.cache.has(key)) {
115
+ this.cache.set(key, {
116
+ value,
117
+ maxAge
118
+ });
119
+ } else {
120
+ this._set(key, {value, expiry: maxAge});
121
+ }
122
+ }
123
+
124
+ has(key) {
125
+ if (this.cache.has(key)) {
126
+ return !this._deleteIfExpired(key, this.cache.get(key));
127
+ }
128
+
129
+ if (this.oldCache.has(key)) {
130
+ return !this._deleteIfExpired(key, this.oldCache.get(key));
131
+ }
132
+
133
+ return false;
134
+ }
135
+
136
+ peek(key) {
137
+ if (this.cache.has(key)) {
138
+ return this._peek(key, this.cache);
139
+ }
140
+
141
+ if (this.oldCache.has(key)) {
142
+ return this._peek(key, this.oldCache);
143
+ }
144
+ }
145
+
146
+ delete(key) {
147
+ const deleted = this.cache.delete(key);
148
+ if (deleted) {
149
+ this._size--;
150
+ }
151
+
152
+ return this.oldCache.delete(key) || deleted;
153
+ }
154
+
155
+ clear() {
156
+ this.cache.clear();
157
+ this.oldCache.clear();
158
+ this._size = 0;
159
+ }
160
+
161
+ resize(newSize) {
162
+ if (!(newSize && newSize > 0)) {
163
+ throw new TypeError('`maxSize` must be a number greater than 0');
164
+ }
165
+
166
+ const items = [...this._entriesAscending()];
167
+ const removeCount = items.length - newSize;
168
+ if (removeCount < 0) {
169
+ this.cache = new Map(items);
170
+ this.oldCache = new Map();
171
+ this._size = items.length;
172
+ } else {
173
+ if (removeCount > 0) {
174
+ this._emitEvictions(items.slice(0, removeCount));
175
+ }
176
+
177
+ this.oldCache = new Map(items.slice(removeCount));
178
+ this.cache = new Map();
179
+ this._size = 0;
180
+ }
181
+
182
+ this.maxSize = newSize;
183
+ }
184
+
185
+ * keys() {
186
+ for (const [key] of this) {
187
+ yield key;
188
+ }
189
+ }
190
+
191
+ * values() {
192
+ for (const [, value] of this) {
193
+ yield value;
194
+ }
195
+ }
196
+
197
+ * [Symbol.iterator]() {
198
+ for (const item of this.cache) {
199
+ const [key, value] = item;
200
+ const deleted = this._deleteIfExpired(key, value);
201
+ if (deleted === false) {
202
+ yield [key, value.value];
203
+ }
204
+ }
205
+
206
+ for (const item of this.oldCache) {
207
+ const [key, value] = item;
208
+ if (!this.cache.has(key)) {
209
+ const deleted = this._deleteIfExpired(key, value);
210
+ if (deleted === false) {
211
+ yield [key, value.value];
212
+ }
213
+ }
214
+ }
215
+ }
216
+
217
+ * entriesDescending() {
218
+ let items = [...this.cache];
219
+ for (let i = items.length - 1; i >= 0; --i) {
220
+ const item = items[i];
221
+ const [key, value] = item;
222
+ const deleted = this._deleteIfExpired(key, value);
223
+ if (deleted === false) {
224
+ yield [key, value.value];
225
+ }
226
+ }
227
+
228
+ items = [...this.oldCache];
229
+ for (let i = items.length - 1; i >= 0; --i) {
230
+ const item = items[i];
231
+ const [key, value] = item;
232
+ if (!this.cache.has(key)) {
233
+ const deleted = this._deleteIfExpired(key, value);
234
+ if (deleted === false) {
235
+ yield [key, value.value];
236
+ }
237
+ }
238
+ }
239
+ }
240
+
241
+ * entriesAscending() {
242
+ for (const [key, value] of this._entriesAscending()) {
243
+ yield [key, value.value];
244
+ }
245
+ }
246
+
247
+ get size() {
248
+ if (!this._size) {
249
+ return this.oldCache.size;
250
+ }
251
+
252
+ let oldCacheSize = 0;
253
+ for (const key of this.oldCache.keys()) {
254
+ if (!this.cache.has(key)) {
255
+ oldCacheSize++;
256
+ }
257
+ }
258
+
259
+ return Math.min(this._size + oldCacheSize, this.maxSize);
260
+ }
261
+ }
262
+
263
+ module.exports = QuickLRU;
node_modules/@alloc/quick-lru/license ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
node_modules/@alloc/quick-lru/package.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@alloc/quick-lru",
3
+ "version": "5.2.0",
4
+ "description": "Simple “Least Recently Used” (LRU) cache",
5
+ "license": "MIT",
6
+ "repository": "sindresorhus/quick-lru",
7
+ "funding": "https://github.com/sponsors/sindresorhus",
8
+ "author": {
9
+ "name": "Sindre Sorhus",
10
+ "email": "[email protected]",
11
+ "url": "https://sindresorhus.com"
12
+ },
13
+ "engines": {
14
+ "node": ">=10"
15
+ },
16
+ "scripts": {
17
+ "test": "xo && nyc ava && tsd"
18
+ },
19
+ "files": [
20
+ "index.js",
21
+ "index.d.ts"
22
+ ],
23
+ "keywords": [
24
+ "lru",
25
+ "quick",
26
+ "cache",
27
+ "caching",
28
+ "least",
29
+ "recently",
30
+ "used",
31
+ "fast",
32
+ "map",
33
+ "hash",
34
+ "buffer"
35
+ ],
36
+ "devDependencies": {
37
+ "ava": "^2.0.0",
38
+ "coveralls": "^3.0.3",
39
+ "nyc": "^15.0.0",
40
+ "tsd": "^0.11.0",
41
+ "xo": "^0.26.0"
42
+ }
43
+ }
node_modules/@alloc/quick-lru/readme.md ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # quick-lru [![Build Status](https://travis-ci.org/sindresorhus/quick-lru.svg?branch=master)](https://travis-ci.org/sindresorhus/quick-lru) [![Coverage Status](https://coveralls.io/repos/github/sindresorhus/quick-lru/badge.svg?branch=master)](https://coveralls.io/github/sindresorhus/quick-lru?branch=master)
2
+
3
+ > Simple [“Least Recently Used” (LRU) cache](https://en.m.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29)
4
+
5
+ Useful when you need to cache something and limit memory usage.
6
+
7
+ Inspired by the [`hashlru` algorithm](https://github.com/dominictarr/hashlru#algorithm), but instead uses [`Map`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map) to support keys of any type, not just strings, and values can be `undefined`.
8
+
9
+ ## Install
10
+
11
+ ```
12
+ $ npm install quick-lru
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ const QuickLRU = require('quick-lru');
19
+
20
+ const lru = new QuickLRU({maxSize: 1000});
21
+
22
+ lru.set('🦄', '🌈');
23
+
24
+ lru.has('🦄');
25
+ //=> true
26
+
27
+ lru.get('🦄');
28
+ //=> '🌈'
29
+ ```
30
+
31
+ ## API
32
+
33
+ ### new QuickLRU(options?)
34
+
35
+ Returns a new instance.
36
+
37
+ ### options
38
+
39
+ Type: `object`
40
+
41
+ #### maxSize
42
+
43
+ *Required*\
44
+ Type: `number`
45
+
46
+ The maximum number of items before evicting the least recently used items.
47
+
48
+ #### maxAge
49
+
50
+ Type: `number`\
51
+ Default: `Infinity`
52
+
53
+ The maximum number of milliseconds an item should remain in cache.
54
+ By default maxAge will be Infinity, which means that items will never expire.
55
+
56
+ Lazy expiration happens upon the next `write` or `read` call.
57
+
58
+ Individual expiration of an item can be specified by the `set(key, value, options)` method.
59
+
60
+ #### onEviction
61
+
62
+ *Optional*\
63
+ Type: `(key, value) => void`
64
+
65
+ Called right before an item is evicted from the cache.
66
+
67
+ Useful for side effects or for items like object URLs that need explicit cleanup (`revokeObjectURL`).
68
+
69
+ ### Instance
70
+
71
+ The instance is [`iterable`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) so you can use it directly in a [`for…of`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of) loop.
72
+
73
+ Both `key` and `value` can be of any type.
74
+
75
+ #### .set(key, value, options?)
76
+
77
+ Set an item. Returns the instance.
78
+
79
+ Individual expiration of an item can be specified with the `maxAge` option. If not specified, the global `maxAge` value will be used in case it is specified on the constructor, otherwise the item will never expire.
80
+
81
+ #### .get(key)
82
+
83
+ Get an item.
84
+
85
+ #### .has(key)
86
+
87
+ Check if an item exists.
88
+
89
+ #### .peek(key)
90
+
91
+ Get an item without marking it as recently used.
92
+
93
+ #### .delete(key)
94
+
95
+ Delete an item.
96
+
97
+ Returns `true` if the item is removed or `false` if the item doesn't exist.
98
+
99
+ #### .clear()
100
+
101
+ Delete all items.
102
+
103
+ #### .resize(maxSize)
104
+
105
+ Update the `maxSize`, discarding items as necessary. Insertion order is mostly preserved, though this is not a strong guarantee.
106
+
107
+ Useful for on-the-fly tuning of cache sizes in live systems.
108
+
109
+ #### .keys()
110
+
111
+ Iterable for all the keys.
112
+
113
+ #### .values()
114
+
115
+ Iterable for all the values.
116
+
117
+ #### .entriesAscending()
118
+
119
+ Iterable for all entries, starting with the oldest (ascending in recency).
120
+
121
+ #### .entriesDescending()
122
+
123
+ Iterable for all entries, starting with the newest (descending in recency).
124
+
125
+ #### .size
126
+
127
+ The stored item count.
128
+
129
+ ---
130
+
131
+ <div align="center">
132
+ <b>
133
+ <a href="https://tidelift.com/subscription/pkg/npm-quick-lru?utm_source=npm-quick-lru&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
134
+ </b>
135
+ <br>
136
+ <sub>
137
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
138
+ </sub>
139
+ </div>
node_modules/@hookform/resolvers/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2019-present Beier(Bill) Luo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
node_modules/@hookform/resolvers/README.md ADDED
@@ -0,0 +1,794 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div align="center">
2
+ <p align="center">
3
+ <a href="https://react-hook-form.com" title="React Hook Form - Simple React forms validation">
4
+ <img src="https://raw.githubusercontent.com/bluebill1049/react-hook-form/master/docs/logo.png" alt="React Hook Form Logo - React hook custom hook for form validation" />
5
+ </a>
6
+ </p>
7
+ </div>
8
+
9
+ <p align="center">Performant, flexible and extensible forms with easy to use validation.</p>
10
+
11
+ <div align="center">
12
+
13
+ [![npm downloads](https://img.shields.io/npm/dm/@hookform/resolvers.svg?style=for-the-badge)](https://www.npmjs.com/package/@hookform/resolvers)
14
+ [![npm](https://img.shields.io/npm/dt/@hookform/resolvers.svg?style=for-the-badge)](https://www.npmjs.com/package/@hookform/resolvers)
15
+ [![npm](https://img.shields.io/bundlephobia/minzip/@hookform/resolvers?style=for-the-badge)](https://bundlephobia.com/result?p=@hookform/resolvers)
16
+
17
+ </div>
18
+
19
+ ## Install
20
+
21
+ npm install @hookform/resolvers
22
+
23
+ ## Links
24
+
25
+ - [React-hook-form validation resolver documentation ](https://react-hook-form.com/api/useform/#resolver)
26
+
27
+ ### Supported resolvers
28
+
29
+ - [Install](#install)
30
+ - [Links](#links)
31
+ - [Supported resolvers](#supported-resolvers)
32
+ - [API](#api)
33
+ - [Quickstart](#quickstart)
34
+ - [Yup](#yup)
35
+ - [Zod](#zod)
36
+ - [Superstruct](#superstruct)
37
+ - [Joi](#joi)
38
+ - [Vest](#vest)
39
+ - [Class Validator](#class-validator)
40
+ - [io-ts](#io-ts)
41
+ - [Nope](#nope)
42
+ - [computed-types](#computed-types)
43
+ - [typanion](#typanion)
44
+ - [Ajv](#ajv)
45
+ - [TypeBox](#typebox)
46
+ - [With `ValueCheck`](#with-valuecheck)
47
+ - [With `TypeCompiler`](#with-typecompiler)
48
+ - [ArkType](#arktype)
49
+ - [Valibot](#valibot)
50
+ - [TypeSchema](#typeschema)
51
+ - [effect-ts](#effect-ts)
52
+ - [VineJS](#vinejs)
53
+ - [fluentvalidation-ts](#fluentvalidation-ts)
54
+ - [Backers](#backers)
55
+ - [Sponsors](#sponsors)
56
+ - [Contributors](#contributors)
57
+
58
+ ## API
59
+
60
+ ```
61
+ type Options = {
62
+ mode: 'async' | 'sync',
63
+ raw?: boolean
64
+ }
65
+
66
+ resolver(schema: object, schemaOptions?: object, resolverOptions: Options)
67
+ ```
68
+
69
+ | | type | Required | Description |
70
+ | --------------- | -------- | -------- | --------------------------------------------- |
71
+ | schema | `object` | ✓ | validation schema |
72
+ | schemaOptions | `object` | | validation library schema options |
73
+ | resolverOptions | `object` | | resolver options, `async` is the default mode |
74
+
75
+ ## Quickstart
76
+
77
+ ### [Yup](https://github.com/jquense/yup)
78
+
79
+ Dead simple Object schema validation.
80
+
81
+ [![npm](https://img.shields.io/bundlephobia/minzip/yup?style=for-the-badge)](https://bundlephobia.com/result?p=yup)
82
+
83
+ ```typescript jsx
84
+ import { useForm } from 'react-hook-form';
85
+ import { yupResolver } from '@hookform/resolvers/yup';
86
+ import * as yup from 'yup';
87
+
88
+ const schema = yup
89
+ .object()
90
+ .shape({
91
+ name: yup.string().required(),
92
+ age: yup.number().required(),
93
+ })
94
+ .required();
95
+
96
+ const App = () => {
97
+ const { register, handleSubmit } = useForm({
98
+ resolver: yupResolver(schema),
99
+ });
100
+
101
+ return (
102
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
103
+ <input {...register('name')} />
104
+ <input type="number" {...register('age')} />
105
+ <input type="submit" />
106
+ </form>
107
+ );
108
+ };
109
+ ```
110
+
111
+ ### [Zod](https://github.com/vriad/zod)
112
+
113
+ TypeScript-first schema validation with static type inference
114
+
115
+ [![npm](https://img.shields.io/bundlephobia/minzip/zod?style=for-the-badge)](https://bundlephobia.com/result?p=zod)
116
+
117
+ > ⚠️ Example below uses the `valueAsNumber`, which requires `react-hook-form` v6.12.0 (released Nov 28, 2020) or later.
118
+
119
+ ```tsx
120
+ import { useForm } from 'react-hook-form';
121
+ import { zodResolver } from '@hookform/resolvers/zod';
122
+ import * as z from 'zod';
123
+
124
+ const schema = z.object({
125
+ name: z.string().min(1, { message: 'Required' }),
126
+ age: z.number().min(10),
127
+ });
128
+
129
+ const App = () => {
130
+ const {
131
+ register,
132
+ handleSubmit,
133
+ formState: { errors },
134
+ } = useForm({
135
+ resolver: zodResolver(schema),
136
+ });
137
+
138
+ return (
139
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
140
+ <input {...register('name')} />
141
+ {errors.name?.message && <p>{errors.name?.message}</p>}
142
+ <input type="number" {...register('age', { valueAsNumber: true })} />
143
+ {errors.age?.message && <p>{errors.age?.message}</p>}
144
+ <input type="submit" />
145
+ </form>
146
+ );
147
+ };
148
+ ```
149
+
150
+ ### [Superstruct](https://github.com/ianstormtaylor/superstruct)
151
+
152
+ A simple and composable way to validate data in JavaScript (or TypeScript).
153
+
154
+ [![npm](https://img.shields.io/bundlephobia/minzip/superstruct?style=for-the-badge)](https://bundlephobia.com/result?p=superstruct)
155
+
156
+ ```typescript jsx
157
+ import { useForm } from 'react-hook-form';
158
+ import { superstructResolver } from '@hookform/resolvers/superstruct';
159
+ import { object, string, number } from 'superstruct';
160
+
161
+ const schema = object({
162
+ name: string(),
163
+ age: number(),
164
+ });
165
+
166
+ const App = () => {
167
+ const { register, handleSubmit } = useForm({
168
+ resolver: superstructResolver(schema),
169
+ });
170
+
171
+ return (
172
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
173
+ <input {...register('name')} />
174
+ <input type="number" {...register('age', { valueAsNumber: true })} />
175
+ <input type="submit" />
176
+ </form>
177
+ );
178
+ };
179
+ ```
180
+
181
+ ### [Joi](https://github.com/sideway/joi)
182
+
183
+ The most powerful data validation library for JS.
184
+
185
+ [![npm](https://img.shields.io/bundlephobia/minzip/joi?style=for-the-badge)](https://bundlephobia.com/result?p=joi)
186
+
187
+ ```typescript jsx
188
+ import { useForm } from 'react-hook-form';
189
+ import { joiResolver } from '@hookform/resolvers/joi';
190
+ import Joi from 'joi';
191
+
192
+ const schema = Joi.object({
193
+ name: Joi.string().required(),
194
+ age: Joi.number().required(),
195
+ });
196
+
197
+ const App = () => {
198
+ const { register, handleSubmit } = useForm({
199
+ resolver: joiResolver(schema),
200
+ });
201
+
202
+ return (
203
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
204
+ <input {...register('name')} />
205
+ <input type="number" {...register('age')} />
206
+ <input type="submit" />
207
+ </form>
208
+ );
209
+ };
210
+ ```
211
+
212
+ ### [Vest](https://github.com/ealush/vest)
213
+
214
+ Vest 🦺 Declarative Validation Testing.
215
+
216
+ [![npm](https://img.shields.io/bundlephobia/minzip/vest?style=for-the-badge)](https://bundlephobia.com/result?p=vest)
217
+
218
+ ```typescript jsx
219
+ import { useForm } from 'react-hook-form';
220
+ import { vestResolver } from '@hookform/resolvers/vest';
221
+ import { create, test, enforce } from 'vest';
222
+
223
+ const validationSuite = create((data = {}) => {
224
+ test('username', 'Username is required', () => {
225
+ enforce(data.username).isNotEmpty();
226
+ });
227
+
228
+ test('password', 'Password is required', () => {
229
+ enforce(data.password).isNotEmpty();
230
+ });
231
+ });
232
+
233
+ const App = () => {
234
+ const { register, handleSubmit, errors } = useForm({
235
+ resolver: vestResolver(validationSuite),
236
+ });
237
+
238
+ return (
239
+ <form onSubmit={handleSubmit((data) => console.log(data))}>
240
+ <input {...register('username')} />
241
+ <input type="password" {...register('password')} />
242
+ <input type="submit" />
243
+ </form>
244
+ );
245
+ };
246
+ ```
247
+
248
+ ### [Class Validator](https://github.com/typestack/class-validator)
249
+
250
+ Decorator-based property validation for classes.
251
+
252
+ [![npm](https://img.shields.io/bundlephobia/minzip/class-validator?style=for-the-badge)](https://bundlephobia.com/result?p=class-validator)
253
+
254
+ > ⚠️ Remember to add these options to your `tsconfig.json`!
255
+
256
+ ```
257
+ "strictPropertyInitialization": false,
258
+ "experimentalDecorators": true
259
+ ```
260
+
261
+ ```tsx
262
+ import { useForm } from 'react-hook-form';
263
+ import { classValidatorResolver } from '@hookform/resolvers/class-validator';
264
+ import { Length, Min, IsEmail } from 'class-validator';
265
+
266
+ class User {
267
+ @Length(2, 30)
268
+ username: string;
269
+
270
+ @IsEmail()
271
+ email: string;
272
+ }
273
+
274
+ const resolver = classValidatorResolver(User);
275
+
276
+ const App = () => {
277
+ const {
278
+ register,
279
+ handleSubmit,
280
+ formState: { errors },
281
+ } = useForm<User>({ resolver });
282
+
283
+ return (
284
+ <form onSubmit={handleSubmit((data) => console.log(data))}>
285
+ <input type="text" {...register('username')} />
286
+ {errors.username && <span>{errors.username.message}</span>}
287
+ <input type="text" {...register('email')} />
288
+ {errors.email && <span>{errors.email.message}</span>}
289
+ <input type="submit" value="Submit" />
290
+ </form>
291
+ );
292
+ };
293
+ ```
294
+
295
+ ### [io-ts](https://github.com/gcanti/io-ts)
296
+
297
+ Validate your data with powerful decoders.
298
+
299
+ [![npm](https://img.shields.io/bundlephobia/minzip/io-ts?style=for-the-badge)](https://bundlephobia.com/result?p=io-ts)
300
+
301
+ ```typescript jsx
302
+ import React from 'react';
303
+ import { useForm } from 'react-hook-form';
304
+ import { ioTsResolver } from '@hookform/resolvers/io-ts';
305
+ import t from 'io-ts';
306
+ // you don't have to use io-ts-types, but it's very useful
307
+ import tt from 'io-ts-types';
308
+
309
+ const schema = t.type({
310
+ username: t.string,
311
+ age: tt.NumberFromString,
312
+ });
313
+
314
+ const App = () => {
315
+ const { register, handleSubmit } = useForm({
316
+ resolver: ioTsResolver(schema),
317
+ });
318
+
319
+ return (
320
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
321
+ <input {...register('username')} />
322
+ <input type="number" {...register('age')} />
323
+ <input type="submit" />
324
+ </form>
325
+ );
326
+ };
327
+
328
+ export default App;
329
+ ```
330
+
331
+ ### [Nope](https://github.com/bvego/nope-validator)
332
+
333
+ A small, simple, and fast JS validator
334
+
335
+ [![npm](https://img.shields.io/bundlephobia/minzip/nope-validator?style=for-the-badge)](https://bundlephobia.com/result?p=nope-validator)
336
+
337
+ ```typescript jsx
338
+ import { useForm } from 'react-hook-form';
339
+ import { nopeResolver } from '@hookform/resolvers/nope';
340
+ import Nope from 'nope-validator';
341
+
342
+ const schema = Nope.object().shape({
343
+ name: Nope.string().required(),
344
+ age: Nope.number().required(),
345
+ });
346
+
347
+ const App = () => {
348
+ const { register, handleSubmit } = useForm({
349
+ resolver: nopeResolver(schema),
350
+ });
351
+
352
+ return (
353
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
354
+ <input {...register('name')} />
355
+ <input type="number" {...register('age')} />
356
+ <input type="submit" />
357
+ </form>
358
+ );
359
+ };
360
+ ```
361
+
362
+ ### [computed-types](https://github.com/neuledge/computed-types)
363
+
364
+ TypeScript-first schema validation with static type inference
365
+
366
+ [![npm](https://img.shields.io/bundlephobia/minzip/computed-types?style=for-the-badge)](https://bundlephobia.com/result?p=computed-types)
367
+
368
+ ```tsx
369
+ import { useForm } from 'react-hook-form';
370
+ import { computedTypesResolver } from '@hookform/resolvers/computed-types';
371
+ import Schema, { number, string } from 'computed-types';
372
+
373
+ const schema = Schema({
374
+ username: string.min(1).error('username field is required'),
375
+ age: number,
376
+ });
377
+
378
+ const App = () => {
379
+ const {
380
+ register,
381
+ handleSubmit,
382
+ formState: { errors },
383
+ } = useForm({
384
+ resolver: computedTypesResolver(schema),
385
+ });
386
+
387
+ return (
388
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
389
+ <input {...register('name')} />
390
+ {errors.name?.message && <p>{errors.name?.message}</p>}
391
+ <input type="number" {...register('age', { valueAsNumber: true })} />
392
+ {errors.age?.message && <p>{errors.age?.message}</p>}
393
+ <input type="submit" />
394
+ </form>
395
+ );
396
+ };
397
+ ```
398
+
399
+ ### [typanion](https://github.com/arcanis/typanion)
400
+
401
+ Static and runtime type assertion library with no dependencies
402
+
403
+ [![npm](https://img.shields.io/bundlephobia/minzip/typanion?style=for-the-badge)](https://bundlephobia.com/result?p=typanion)
404
+
405
+ ```tsx
406
+ import { useForm } from 'react-hook-form';
407
+ import { typanionResolver } from '@hookform/resolvers/typanion';
408
+ import * as t from 'typanion';
409
+
410
+ const isUser = t.isObject({
411
+ username: t.applyCascade(t.isString(), [t.hasMinLength(1)]),
412
+ age: t.applyCascade(t.isNumber(), [
413
+ t.isInteger(),
414
+ t.isInInclusiveRange(1, 100),
415
+ ]),
416
+ });
417
+
418
+ const App = () => {
419
+ const {
420
+ register,
421
+ handleSubmit,
422
+ formState: { errors },
423
+ } = useForm({
424
+ resolver: typanionResolver(isUser),
425
+ });
426
+
427
+ return (
428
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
429
+ <input {...register('name')} />
430
+ {errors.name?.message && <p>{errors.name?.message}</p>}
431
+ <input type="number" {...register('age')} />
432
+ {errors.age?.message && <p>{errors.age?.message}</p>}
433
+ <input type="submit" />
434
+ </form>
435
+ );
436
+ };
437
+ ```
438
+
439
+ ### [Ajv](https://github.com/ajv-validator/ajv)
440
+
441
+ The fastest JSON validator for Node.js and browser
442
+
443
+ [![npm](https://img.shields.io/bundlephobia/minzip/ajv?style=for-the-badge)](https://bundlephobia.com/result?p=ajv)
444
+
445
+ ```tsx
446
+ import { useForm } from 'react-hook-form';
447
+ import { ajvResolver } from '@hookform/resolvers/ajv';
448
+
449
+ // must use `minLength: 1` to implement required field
450
+ const schema = {
451
+ type: 'object',
452
+ properties: {
453
+ username: {
454
+ type: 'string',
455
+ minLength: 1,
456
+ errorMessage: { minLength: 'username field is required' },
457
+ },
458
+ password: {
459
+ type: 'string',
460
+ minLength: 1,
461
+ errorMessage: { minLength: 'password field is required' },
462
+ },
463
+ },
464
+ required: ['username', 'password'],
465
+ additionalProperties: false,
466
+ };
467
+
468
+ const App = () => {
469
+ const {
470
+ register,
471
+ handleSubmit,
472
+ formState: { errors },
473
+ } = useForm({
474
+ resolver: ajvResolver(schema),
475
+ });
476
+
477
+ return (
478
+ <form onSubmit={handleSubmit((data) => console.log(data))}>
479
+ <input {...register('username')} />
480
+ {errors.username && <span>{errors.username.message}</span>}
481
+ <input {...register('password')} />
482
+ {errors.password && <span>{errors.password.message}</span>}
483
+ <button type="submit">submit</button>
484
+ </form>
485
+ );
486
+ };
487
+ ```
488
+
489
+ ### [TypeBox](https://github.com/sinclairzx81/typebox)
490
+
491
+ JSON Schema Type Builder with Static Type Resolution for TypeScript
492
+
493
+ [![npm](https://img.shields.io/bundlephobia/minzip/@sinclair/typebox?style=for-the-badge)](https://bundlephobia.com/result?p=@sinclair/typebox)
494
+
495
+ #### With `ValueCheck`
496
+
497
+ ```typescript jsx
498
+ import { useForm } from 'react-hook-form';
499
+ import { typeboxResolver } from '@hookform/resolvers/typebox';
500
+ import { Type } from '@sinclair/typebox';
501
+
502
+ const schema = Type.Object({
503
+ username: Type.String({ minLength: 1 }),
504
+ password: Type.String({ minLength: 1 }),
505
+ });
506
+
507
+ const App = () => {
508
+ const { register, handleSubmit } = useForm({
509
+ resolver: typeboxResolver(schema),
510
+ });
511
+
512
+ return (
513
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
514
+ <input {...register('username')} />
515
+ <input type="password" {...register('password')} />
516
+ <input type="submit" />
517
+ </form>
518
+ );
519
+ };
520
+ ```
521
+
522
+ #### With `TypeCompiler`
523
+
524
+ A high-performance JIT of `TypeBox`, [read more](https://github.com/sinclairzx81/typebox#typecompiler)
525
+
526
+ ```typescript jsx
527
+ import { useForm } from 'react-hook-form';
528
+ import { typeboxResolver } from '@hookform/resolvers/typebox';
529
+ import { Type } from '@sinclair/typebox';
530
+ import { TypeCompiler } from '@sinclair/typebox/compiler';
531
+
532
+ const schema = Type.Object({
533
+ username: Type.String({ minLength: 1 }),
534
+ password: Type.String({ minLength: 1 }),
535
+ });
536
+
537
+ const typecheck = TypeCompiler.Compile(schema);
538
+
539
+ const App = () => {
540
+ const { register, handleSubmit } = useForm({
541
+ resolver: typeboxResolver(typecheck),
542
+ });
543
+
544
+ return (
545
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
546
+ <input {...register('username')} />
547
+ <input type="password" {...register('password')} />
548
+ <input type="submit" />
549
+ </form>
550
+ );
551
+ };
552
+ ```
553
+
554
+ ### [ArkType](https://github.com/arktypeio/arktype)
555
+
556
+ TypeScript's 1:1 validator, optimized from editor to runtime
557
+
558
+ [![npm](https://img.shields.io/bundlephobia/minzip/arktype?style=for-the-badge)](https://bundlephobia.com/result?p=arktype)
559
+
560
+ ```typescript jsx
561
+ import { useForm } from 'react-hook-form';
562
+ import { arktypeResolver } from '@hookform/resolvers/arktype';
563
+ import { type } from 'arktype';
564
+
565
+ const schema = type({
566
+ username: 'string>1',
567
+ password: 'string>1',
568
+ });
569
+
570
+ const App = () => {
571
+ const { register, handleSubmit } = useForm({
572
+ resolver: arktypeResolver(schema),
573
+ });
574
+
575
+ return (
576
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
577
+ <input {...register('username')} />
578
+ <input type="password" {...register('password')} />
579
+ <input type="submit" />
580
+ </form>
581
+ );
582
+ };
583
+ ```
584
+
585
+ ### [Valibot](https://github.com/fabian-hiller/valibot)
586
+
587
+ The modular and type safe schema library for validating structural data
588
+
589
+ [![npm](https://img.shields.io/bundlephobia/minzip/valibot?style=for-the-badge)](https://bundlephobia.com/result?p=valibot)
590
+
591
+ ```typescript jsx
592
+ import { useForm } from 'react-hook-form';
593
+ import { valibotResolver } from '@hookform/resolvers/valibot';
594
+ import * as v from 'valibot';
595
+
596
+ const schema = v.object({
597
+ username: v.pipe(
598
+ v.string('username is required'),
599
+ v.minLength(3, 'Needs to be at least 3 characters'),
600
+ v.endsWith('cool', 'Needs to end with `cool`'),
601
+ ),
602
+ password: v.string('password is required'),
603
+ });
604
+
605
+ const App = () => {
606
+ const { register, handleSubmit } = useForm({
607
+ resolver: valibotResolver(schema),
608
+ });
609
+
610
+ return (
611
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
612
+ <input {...register('username')} />
613
+ <input type="password" {...register('password')} />
614
+ <input type="submit" />
615
+ </form>
616
+ );
617
+ };
618
+ ```
619
+
620
+ ### [TypeSchema](https://typeschema.com)
621
+
622
+ Universal adapter for schema validation, compatible with [any validation library](https://typeschema.com/#coverage)
623
+
624
+ [![npm](https://img.shields.io/bundlephobia/minzip/@typeschema/main?style=for-the-badge)](https://bundlephobia.com/result?p=@typeschema/main)
625
+
626
+ ```typescript jsx
627
+ import { useForm } from 'react-hook-form';
628
+ import { typeschemaResolver } from '@hookform/resolvers/typeschema';
629
+ import * as z from 'zod';
630
+
631
+ // Use your favorite validation library
632
+ const schema = z.object({
633
+ username: z.string().min(1, { message: 'Required' }),
634
+ password: z.number().min(1, { message: 'Required' }),
635
+ });
636
+
637
+ const App = () => {
638
+ const { register, handleSubmit } = useForm({
639
+ resolver: typeschemaResolver(schema),
640
+ });
641
+
642
+ return (
643
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
644
+ <input {...register('username')} />
645
+ <input type="password" {...register('password')} />
646
+ <input type="submit" />
647
+ </form>
648
+ );
649
+ };
650
+ ```
651
+
652
+ ### [effect-ts](https://github.com/Effect-TS/effect)
653
+
654
+ A powerful TypeScript framework that provides a fully-fledged functional effect system with a rich standard library.
655
+
656
+ [![npm](https://img.shields.io/bundlephobia/minzip/@effect/schema?style=for-the-badge)](https://bundlephobia.com/result?p=effect)
657
+
658
+ ```typescript jsx
659
+ import React from 'react';
660
+ import { useForm } from 'react-hook-form';
661
+ import { effectTsResolver } from '@hookform/resolvers/effect-ts';
662
+ import { Schema } from '@effect/schema';
663
+
664
+ const schema = Schema.Struct({
665
+ username: Schema.String.pipe(
666
+ Schema.nonEmpty({ message: () => 'username required' }),
667
+ ),
668
+ password: Schema.String.pipe(
669
+ Schema.nonEmpty({ message: () => 'password required' }),
670
+ ),
671
+ });
672
+
673
+ type FormData = Schema.Schema.Type<typeof schema>;
674
+
675
+ interface Props {
676
+ onSubmit: (data: FormData) => void;
677
+ }
678
+
679
+ function TestComponent({ onSubmit }: Props) {
680
+ const {
681
+ register,
682
+ handleSubmit,
683
+ formState: { errors },
684
+ // provide generic if TS has issues inferring types
685
+ } = useForm<FormData>({
686
+ resolver: effectTsResolver(schema),
687
+ });
688
+
689
+ return (
690
+ <form onSubmit={handleSubmit(onSubmit)}>
691
+ <input {...register('username')} />
692
+ {errors.username && <span role="alert">{errors.username.message}</span>}
693
+
694
+ <input {...register('password')} />
695
+ {errors.password && <span role="alert">{errors.password.message}</span>}
696
+
697
+ <button type="submit">submit</button>
698
+ </form>
699
+ );
700
+ }
701
+ ```
702
+
703
+ ### [VineJS](https://github.com/vinejs/vine)
704
+
705
+ VineJS is a form data validation library for Node.js
706
+
707
+ [![npm](https://img.shields.io/bundlephobia/minzip/@vinejs/vine?style=for-the-badge)](https://bundlephobia.com/result?p=@vinejs/vine)
708
+
709
+ ```typescript jsx
710
+ import { useForm } from 'react-hook-form';
711
+ import { vineResolver } from '@hookform/resolvers/vine';
712
+ import vine from '@vinejs/vine';
713
+
714
+ const schema = vine.compile(
715
+ vine.object({
716
+ username: vine.string().minLength(1),
717
+ password: vine.string().minLength(1),
718
+ }),
719
+ );
720
+
721
+ const App = () => {
722
+ const { register, handleSubmit } = useForm({
723
+ resolver: vineResolver(schema),
724
+ });
725
+
726
+ return (
727
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
728
+ <input {...register('username')} />
729
+ {errors.username && <span role="alert">{errors.username.message}</span>}
730
+ <input {...register('password')} />
731
+ {errors.password && <span role="alert">{errors.password.message}</span>}
732
+ <button type="submit">submit</button>
733
+ </form>
734
+ );
735
+ };
736
+ ```
737
+
738
+
739
+ ### [fluentvalidation-ts](https://github.com/AlexJPotter/fluentvalidation-ts)
740
+
741
+ A TypeScript-first library for building strongly-typed validation rules
742
+
743
+ [![npm](https://img.shields.io/bundlephobia/minzip/@vinejs/vine?style=for-the-badge)](https://bundlephobia.com/result?p=@vinejs/vine)
744
+
745
+ ```typescript jsx
746
+ import { useForm } from 'react-hook-form';
747
+ import { fluentValidationResolver } from '@hookform/resolvers/fluentvalidation-ts';
748
+ import { Validator } from 'fluentvalidation-ts';
749
+
750
+ class FormDataValidator extends Validator<FormData> {
751
+ constructor() {
752
+ super();
753
+
754
+ this.ruleFor('username')
755
+ .notEmpty()
756
+ .withMessage('username is a required field');
757
+ this.ruleFor('password')
758
+ .notEmpty()
759
+ .withMessage('password is a required field');
760
+ }
761
+ }
762
+
763
+ const App = () => {
764
+ const { register, handleSubmit } = useForm({
765
+ resolver: fluentValidationResolver(new FormDataValidator()),
766
+ });
767
+
768
+ return (
769
+ <form onSubmit={handleSubmit((d) => console.log(d))}>
770
+ <input {...register('username')} />
771
+ {errors.username && <span role="alert">{errors.username.message}</span>}
772
+ <input {...register('password')} />
773
+ {errors.password && <span role="alert">{errors.password.message}</span>}
774
+ <button type="submit">submit</button>
775
+ </form>
776
+ );
777
+ };
778
+ ```
779
+
780
+ ## Backers
781
+
782
+ Thanks go to all our backers! [[Become a backer](https://opencollective.com/react-hook-form#backer)].
783
+
784
+ <a href="https://opencollective.com/react-hook-form#backers">
785
+ <img src="https://opencollective.com/react-hook-form/backers.svg?width=950" />
786
+ </a>
787
+
788
+ ## Contributors
789
+
790
+ Thanks go to these wonderful people! [[Become a contributor](CONTRIBUTING.md)].
791
+
792
+ <a href="https://github.com/react-hook-form/react-hook-form/graphs/contributors">
793
+ <img src="https://opencollective.com/react-hook-form/contributors.svg?width=950" />
794
+ </a>
node_modules/@hookform/resolvers/ajv/dist/ajv.d.ts ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import { Resolver } from './types';
2
+ export declare const ajvResolver: Resolver;
node_modules/@hookform/resolvers/ajv/dist/ajv.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ var e=require("@hookform/resolvers"),r=require("ajv"),a=require("ajv-errors"),s=require("react-hook-form");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=/*#__PURE__*/t(r),i=/*#__PURE__*/t(a),n=function(e,r){return e.forEach(function(e){"required"===e.keyword&&(e.instancePath+="/"+e.params.missingProperty)}),e.reduce(function(e,a){var t=a.instancePath.substring(1).replace(/\//g,".");if(e[t]||(e[t]={message:a.message,type:a.keyword}),r){var o=e[t].types,i=o&&o[a.keyword];e[t]=s.appendErrors(t,r,e,a.keyword,i?[].concat(i,a.message||""):a.message)}return e},{})};exports.ajvResolver=function(r,a,s){return void 0===s&&(s={}),function(t,u,c){try{var l=new o.default(Object.assign({},{allErrors:!0,validateSchema:!0},a));i.default(l);var d=l.compile(Object.assign({$async:s&&"async"===s.mode},r)),v=d(t);return c.shouldUseNativeValidation&&e.validateFieldsNatively({},c),Promise.resolve(v?{values:t,errors:{}}:{values:{},errors:e.toNestErrors(n(d.errors,!c.shouldUseNativeValidation&&"all"===c.criteriaMode),c)})}catch(e){return Promise.reject(e)}}};
2
+ //# sourceMappingURL=ajv.js.map
node_modules/@hookform/resolvers/ajv/dist/ajv.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"ajv.js","sources":["../src/ajv.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport Ajv, { DefinedError } from 'ajv';\nimport ajvErrors from 'ajv-errors';\nimport { FieldError, appendErrors } from 'react-hook-form';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (\n ajvErrors: DefinedError[],\n validateAllFieldCriteria: boolean,\n) => {\n // Ajv will return empty instancePath when require error\n ajvErrors.forEach((error) => {\n if (error.keyword === 'required') {\n error.instancePath += '/' + error.params.missingProperty;\n }\n });\n\n return ajvErrors.reduce<Record<string, FieldError>>((previous, error) => {\n // `/deepObject/data` -> `deepObject.data`\n const path = error.instancePath.substring(1).replace(/\\//g, '.');\n\n if (!previous[path]) {\n previous[path] = {\n message: error.message,\n type: error.keyword,\n };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[path].types;\n const messages = types && types[error.keyword];\n\n previous[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n previous,\n error.keyword,\n messages\n ? ([] as string[]).concat(messages as string[], error.message || '')\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n }, {});\n};\n\nexport const ajvResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n const ajv = new Ajv(\n Object.assign(\n {},\n {\n allErrors: true,\n validateSchema: true,\n },\n schemaOptions,\n ),\n );\n\n ajvErrors(ajv);\n\n const validate = ajv.compile(\n Object.assign(\n { $async: resolverOptions && resolverOptions.mode === 'async' },\n schema,\n ),\n );\n\n const valid = validate(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return valid\n ? { values, errors: {} }\n : {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n validate.errors as DefinedError[],\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","ajvErrors","validateAllFieldCriteria","forEach","error","keyword","instancePath","params","missingProperty","reduce","previous","path","substring","replace","message","type","types","messages","appendErrors","concat","schema","schemaOptions","resolverOptions","values","_","options","ajv","Ajv","Object","assign","allErrors","validateSchema","validate","compile","$async","mode","valid","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","errors","toNestErrors","criteriaMode","e","reject"],"mappings":"+NAMMA,EAAmB,SACvBC,EACAC,GASA,OANAD,EAAUE,QAAQ,SAACC,GACK,aAAlBA,EAAMC,UACRD,EAAME,cAAgB,IAAMF,EAAMG,OAAOC,gBAE7C,GAEOP,EAAUQ,OAAmC,SAACC,EAAUN,GAE7D,IAAMO,EAAOP,EAAME,aAAaM,UAAU,GAAGC,QAAQ,MAAO,KAS5D,GAPKH,EAASC,KACZD,EAASC,GAAQ,CACfG,QAASV,EAAMU,QACfC,KAAMX,EAAMC,UAIZH,EAA0B,CAC5B,IAAMc,EAAQN,EAASC,GAAMK,MACvBC,EAAWD,GAASA,EAAMZ,EAAMC,SAEtCK,EAASC,GAAQO,eACfP,EACAT,EACAQ,EACAN,EAAMC,QACNY,EACK,GAAgBE,OAAOF,EAAsBb,EAAMU,SAAW,IAC/DV,EAAMU,QAEd,CAEA,OAAOJ,CACT,EAAG,GACL,sBAGE,SAACU,EAAQC,EAAeC,GAAoB,gBAApBA,IAAAA,EAAkB,CAAA,GAAE,SACrCC,EAAQC,EAAGC,GAAO,IACvB,IAAMC,EAAM,IAAIC,UACdC,OAAOC,OACL,CAAE,EACF,CACEC,WAAW,EACXC,gBAAgB,GAElBV,IAIJpB,EAAS,QAACyB,GAEV,IAAMM,EAAWN,EAAIO,QACnBL,OAAOC,OACL,CAAEK,OAAQZ,GAA4C,UAAzBA,EAAgBa,MAC7Cf,IAIEgB,EAAQJ,EAAST,GAIvB,OAFAE,EAAQY,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEb,GAEhEc,QAAAC,QAAOJ,EACH,CAAEb,OAAAA,EAAQkB,OAAQ,CAAI,GACtB,CACElB,OAAQ,CAAA,EACRkB,OAAQC,eACN1C,EACEgC,EAASS,QACRhB,EAAQY,2BACkB,QAAzBZ,EAAQkB,cAEZlB,IAGV,CAAC,MAAAmB,GAAA,OAAAL,QAAAM,OAAAD,EAAA,CAAA,CAAA"}
node_modules/@hookform/resolvers/ajv/dist/ajv.mjs ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import o from"ajv";import a from"ajv-errors";import{appendErrors as s}from"react-hook-form";var t=function(r,e){return r.forEach(function(r){"required"===r.keyword&&(r.instancePath+="/"+r.params.missingProperty)}),r.reduce(function(r,o){var a=o.instancePath.substring(1).replace(/\//g,".");if(r[a]||(r[a]={message:o.message,type:o.keyword}),e){var t=r[a].types,i=t&&t[o.keyword];r[a]=s(a,e,r,o.keyword,i?[].concat(i,o.message||""):o.message)}return r},{})},i=function(s,i,n){return void 0===n&&(n={}),function(c,m,u){try{var l=new o(Object.assign({},{allErrors:!0,validateSchema:!0},i));a(l);var v=l.compile(Object.assign({$async:n&&"async"===n.mode},s)),d=v(c);return u.shouldUseNativeValidation&&r({},u),Promise.resolve(d?{values:c,errors:{}}:{values:{},errors:e(t(v.errors,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)})}catch(r){return Promise.reject(r)}}};export{i as ajvResolver};
2
+ //# sourceMappingURL=ajv.module.js.map
node_modules/@hookform/resolvers/ajv/dist/ajv.modern.mjs ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import{validateFieldsNatively as e,toNestErrors as r}from"@hookform/resolvers";import s from"ajv";import o from"ajv-errors";import{appendErrors as a}from"react-hook-form";const t=(e,r)=>(e.forEach(e=>{"required"===e.keyword&&(e.instancePath+="/"+e.params.missingProperty)}),e.reduce((e,s)=>{const o=s.instancePath.substring(1).replace(/\//g,".");if(e[o]||(e[o]={message:s.message,type:s.keyword}),r){const t=e[o].types,i=t&&t[s.keyword];e[o]=a(o,r,e,s.keyword,i?[].concat(i,s.message||""):s.message)}return e},{})),i=(a,i,n={})=>async(c,m,l)=>{const d=new s(Object.assign({},{allErrors:!0,validateSchema:!0},i));o(d);const p=d.compile(Object.assign({$async:n&&"async"===n.mode},a)),y=p(c);return l.shouldUseNativeValidation&&e({},l),y?{values:c,errors:{}}:{values:{},errors:r(t(p.errors,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)}};export{i as ajvResolver};
2
+ //# sourceMappingURL=ajv.modern.mjs.map
node_modules/@hookform/resolvers/ajv/dist/ajv.modern.mjs.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"ajv.modern.mjs","sources":["../src/ajv.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport Ajv, { DefinedError } from 'ajv';\nimport ajvErrors from 'ajv-errors';\nimport { FieldError, appendErrors } from 'react-hook-form';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (\n ajvErrors: DefinedError[],\n validateAllFieldCriteria: boolean,\n) => {\n // Ajv will return empty instancePath when require error\n ajvErrors.forEach((error) => {\n if (error.keyword === 'required') {\n error.instancePath += '/' + error.params.missingProperty;\n }\n });\n\n return ajvErrors.reduce<Record<string, FieldError>>((previous, error) => {\n // `/deepObject/data` -> `deepObject.data`\n const path = error.instancePath.substring(1).replace(/\\//g, '.');\n\n if (!previous[path]) {\n previous[path] = {\n message: error.message,\n type: error.keyword,\n };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[path].types;\n const messages = types && types[error.keyword];\n\n previous[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n previous,\n error.keyword,\n messages\n ? ([] as string[]).concat(messages as string[], error.message || '')\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n }, {});\n};\n\nexport const ajvResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n const ajv = new Ajv(\n Object.assign(\n {},\n {\n allErrors: true,\n validateSchema: true,\n },\n schemaOptions,\n ),\n );\n\n ajvErrors(ajv);\n\n const validate = ajv.compile(\n Object.assign(\n { $async: resolverOptions && resolverOptions.mode === 'async' },\n schema,\n ),\n );\n\n const valid = validate(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return valid\n ? { values, errors: {} }\n : {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n validate.errors as DefinedError[],\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","ajvErrors","validateAllFieldCriteria","forEach","error","keyword","instancePath","params","missingProperty","reduce","previous","path","substring","replace","message","type","types","messages","appendErrors","concat","ajvResolver","schema","schemaOptions","resolverOptions","async","values","_","options","ajv","Ajv","Object","assign","allErrors","validateSchema","validate","compile","$async","mode","valid","shouldUseNativeValidation","validateFieldsNatively","errors","toNestErrors","criteriaMode"],"mappings":"2KAMA,MAAMA,EAAmBA,CACvBC,EACAC,KAGAD,EAAUE,QAASC,IACK,aAAlBA,EAAMC,UACRD,EAAME,cAAgB,IAAMF,EAAMG,OAAOC,gBAC3C,GAGKP,EAAUQ,OAAmC,CAACC,EAAUN,KAE7D,MAAMO,EAAOP,EAAME,aAAaM,UAAU,GAAGC,QAAQ,MAAO,KAS5D,GAPKH,EAASC,KACZD,EAASC,GAAQ,CACfG,QAASV,EAAMU,QACfC,KAAMX,EAAMC,UAIZH,EAA0B,CAC5B,MAAMc,EAAQN,EAASC,GAAMK,MACvBC,EAAWD,GAASA,EAAMZ,EAAMC,SAEtCK,EAASC,GAAQO,EACfP,EACAT,EACAQ,EACAN,EAAMC,QACNY,EACK,GAAgBE,OAAOF,EAAsBb,EAAMU,SAAW,IAC/DV,EAAMU,QAEd,CAEA,OAAOJ,GACN,KAGQU,EACXA,CAACC,EAAQC,EAAeC,EAAkB,KAC1CC,MAAOC,EAAQC,EAAGC,KAChB,MAAMC,EAAM,IAAIC,EACdC,OAAOC,OACL,CAAE,EACF,CACEC,WAAW,EACXC,gBAAgB,GAElBX,IAIJrB,EAAU2B,GAEV,MAAMM,EAAWN,EAAIO,QACnBL,OAAOC,OACL,CAAEK,OAAQb,GAA4C,UAAzBA,EAAgBc,MAC7ChB,IAIEiB,EAAQJ,EAAST,GAIvB,OAFAE,EAAQY,2BAA6BC,EAAuB,GAAIb,GAEzDW,EACH,CAAEb,SAAQgB,OAAQ,CAAA,GAClB,CACEhB,OAAQ,GACRgB,OAAQC,EACN1C,EACEkC,EAASO,QACRd,EAAQY,2BACkB,QAAzBZ,EAAQgB,cAEZhB"}
node_modules/@hookform/resolvers/ajv/dist/ajv.module.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import o from"ajv";import a from"ajv-errors";import{appendErrors as s}from"react-hook-form";var t=function(r,e){return r.forEach(function(r){"required"===r.keyword&&(r.instancePath+="/"+r.params.missingProperty)}),r.reduce(function(r,o){var a=o.instancePath.substring(1).replace(/\//g,".");if(r[a]||(r[a]={message:o.message,type:o.keyword}),e){var t=r[a].types,i=t&&t[o.keyword];r[a]=s(a,e,r,o.keyword,i?[].concat(i,o.message||""):o.message)}return r},{})},i=function(s,i,n){return void 0===n&&(n={}),function(c,m,u){try{var l=new o(Object.assign({},{allErrors:!0,validateSchema:!0},i));a(l);var v=l.compile(Object.assign({$async:n&&"async"===n.mode},s)),d=v(c);return u.shouldUseNativeValidation&&r({},u),Promise.resolve(d?{values:c,errors:{}}:{values:{},errors:e(t(v.errors,!u.shouldUseNativeValidation&&"all"===u.criteriaMode),u)})}catch(r){return Promise.reject(r)}}};export{i as ajvResolver};
2
+ //# sourceMappingURL=ajv.module.js.map
node_modules/@hookform/resolvers/ajv/dist/ajv.module.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"ajv.module.js","sources":["../src/ajv.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport Ajv, { DefinedError } from 'ajv';\nimport ajvErrors from 'ajv-errors';\nimport { FieldError, appendErrors } from 'react-hook-form';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (\n ajvErrors: DefinedError[],\n validateAllFieldCriteria: boolean,\n) => {\n // Ajv will return empty instancePath when require error\n ajvErrors.forEach((error) => {\n if (error.keyword === 'required') {\n error.instancePath += '/' + error.params.missingProperty;\n }\n });\n\n return ajvErrors.reduce<Record<string, FieldError>>((previous, error) => {\n // `/deepObject/data` -> `deepObject.data`\n const path = error.instancePath.substring(1).replace(/\\//g, '.');\n\n if (!previous[path]) {\n previous[path] = {\n message: error.message,\n type: error.keyword,\n };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[path].types;\n const messages = types && types[error.keyword];\n\n previous[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n previous,\n error.keyword,\n messages\n ? ([] as string[]).concat(messages as string[], error.message || '')\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n }, {});\n};\n\nexport const ajvResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n const ajv = new Ajv(\n Object.assign(\n {},\n {\n allErrors: true,\n validateSchema: true,\n },\n schemaOptions,\n ),\n );\n\n ajvErrors(ajv);\n\n const validate = ajv.compile(\n Object.assign(\n { $async: resolverOptions && resolverOptions.mode === 'async' },\n schema,\n ),\n );\n\n const valid = validate(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return valid\n ? { values, errors: {} }\n : {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n validate.errors as DefinedError[],\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","ajvErrors","validateAllFieldCriteria","forEach","error","keyword","instancePath","params","missingProperty","reduce","previous","path","substring","replace","message","type","types","messages","appendErrors","concat","ajvResolver","schema","schemaOptions","resolverOptions","values","_","options","ajv","Ajv","Object","assign","allErrors","validateSchema","validate","compile","$async","mode","valid","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","errors","toNestErrors","criteriaMode","e","reject"],"mappings":"2KAMA,IAAMA,EAAmB,SACvBC,EACAC,GASA,OANAD,EAAUE,QAAQ,SAACC,GACK,aAAlBA,EAAMC,UACRD,EAAME,cAAgB,IAAMF,EAAMG,OAAOC,gBAE7C,GAEOP,EAAUQ,OAAmC,SAACC,EAAUN,GAE7D,IAAMO,EAAOP,EAAME,aAAaM,UAAU,GAAGC,QAAQ,MAAO,KAS5D,GAPKH,EAASC,KACZD,EAASC,GAAQ,CACfG,QAASV,EAAMU,QACfC,KAAMX,EAAMC,UAIZH,EAA0B,CAC5B,IAAMc,EAAQN,EAASC,GAAMK,MACvBC,EAAWD,GAASA,EAAMZ,EAAMC,SAEtCK,EAASC,GAAQO,EACfP,EACAT,EACAQ,EACAN,EAAMC,QACNY,EACK,GAAgBE,OAAOF,EAAsBb,EAAMU,SAAW,IAC/DV,EAAMU,QAEd,CAEA,OAAOJ,CACT,EAAG,GACL,EAEaU,EACX,SAACC,EAAQC,EAAeC,GAAoB,gBAApBA,IAAAA,EAAkB,CAAA,GAAE,SACrCC,EAAQC,EAAGC,GAAO,IACvB,IAAMC,EAAM,IAAIC,EACdC,OAAOC,OACL,CAAE,EACF,CACEC,WAAW,EACXC,gBAAgB,GAElBV,IAIJrB,EAAU0B,GAEV,IAAMM,EAAWN,EAAIO,QACnBL,OAAOC,OACL,CAAEK,OAAQZ,GAA4C,UAAzBA,EAAgBa,MAC7Cf,IAIEgB,EAAQJ,EAAST,GAIvB,OAFAE,EAAQY,2BAA6BC,EAAuB,CAAE,EAAEb,GAEhEc,QAAAC,QAAOJ,EACH,CAAEb,OAAAA,EAAQkB,OAAQ,CAAI,GACtB,CACElB,OAAQ,CAAA,EACRkB,OAAQC,EACN3C,EACEiC,EAASS,QACRhB,EAAQY,2BACkB,QAAzBZ,EAAQkB,cAEZlB,IAGV,CAAC,MAAAmB,GAAA,OAAAL,QAAAM,OAAAD,EAAA,CAAA,CAAA"}
node_modules/@hookform/resolvers/ajv/dist/ajv.umd.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@hookform/resolvers"),require("ajv"),require("ajv-errors"),require("react-hook-form")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","ajv","ajv-errors","react-hook-form"],r):r((e||self).hookformResolversAjv={},e.hookformResolvers,e.ajv,e.ajvErrors,e.ReactHookForm)}(this,function(e,r,o,a,s){function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=/*#__PURE__*/t(o),n=/*#__PURE__*/t(a),u=function(e,r){return e.forEach(function(e){"required"===e.keyword&&(e.instancePath+="/"+e.params.missingProperty)}),e.reduce(function(e,o){var a=o.instancePath.substring(1).replace(/\//g,".");if(e[a]||(e[a]={message:o.message,type:o.keyword}),r){var t=e[a].types,i=t&&t[o.keyword];e[a]=s.appendErrors(a,r,e,o.keyword,i?[].concat(i,o.message||""):o.message)}return e},{})};e.ajvResolver=function(e,o,a){return void 0===a&&(a={}),function(s,t,f){try{var l=new i.default(Object.assign({},{allErrors:!0,validateSchema:!0},o));n.default(l);var c=l.compile(Object.assign({$async:a&&"async"===a.mode},e)),d=c(s);return f.shouldUseNativeValidation&&r.validateFieldsNatively({},f),Promise.resolve(d?{values:s,errors:{}}:{values:{},errors:r.toNestErrors(u(c.errors,!f.shouldUseNativeValidation&&"all"===f.criteriaMode),f)})}catch(e){return Promise.reject(e)}}}});
2
+ //# sourceMappingURL=ajv.umd.js.map
node_modules/@hookform/resolvers/ajv/dist/ajv.umd.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"ajv.umd.js","sources":["../src/ajv.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport Ajv, { DefinedError } from 'ajv';\nimport ajvErrors from 'ajv-errors';\nimport { FieldError, appendErrors } from 'react-hook-form';\nimport { Resolver } from './types';\n\nconst parseErrorSchema = (\n ajvErrors: DefinedError[],\n validateAllFieldCriteria: boolean,\n) => {\n // Ajv will return empty instancePath when require error\n ajvErrors.forEach((error) => {\n if (error.keyword === 'required') {\n error.instancePath += '/' + error.params.missingProperty;\n }\n });\n\n return ajvErrors.reduce<Record<string, FieldError>>((previous, error) => {\n // `/deepObject/data` -> `deepObject.data`\n const path = error.instancePath.substring(1).replace(/\\//g, '.');\n\n if (!previous[path]) {\n previous[path] = {\n message: error.message,\n type: error.keyword,\n };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[path].types;\n const messages = types && types[error.keyword];\n\n previous[path] = appendErrors(\n path,\n validateAllFieldCriteria,\n previous,\n error.keyword,\n messages\n ? ([] as string[]).concat(messages as string[], error.message || '')\n : error.message,\n ) as FieldError;\n }\n\n return previous;\n }, {});\n};\n\nexport const ajvResolver: Resolver =\n (schema, schemaOptions, resolverOptions = {}) =>\n async (values, _, options) => {\n const ajv = new Ajv(\n Object.assign(\n {},\n {\n allErrors: true,\n validateSchema: true,\n },\n schemaOptions,\n ),\n );\n\n ajvErrors(ajv);\n\n const validate = ajv.compile(\n Object.assign(\n { $async: resolverOptions && resolverOptions.mode === 'async' },\n schema,\n ),\n );\n\n const valid = validate(values);\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return valid\n ? { values, errors: {} }\n : {\n values: {},\n errors: toNestErrors(\n parseErrorSchema(\n validate.errors as DefinedError[],\n !options.shouldUseNativeValidation &&\n options.criteriaMode === 'all',\n ),\n options,\n ),\n };\n };\n"],"names":["parseErrorSchema","ajvErrors","validateAllFieldCriteria","forEach","error","keyword","instancePath","params","missingProperty","reduce","previous","path","substring","replace","message","type","types","messages","appendErrors","concat","schema","schemaOptions","resolverOptions","values","_","options","ajv","Ajv","Object","assign","allErrors","validateSchema","validate","compile","$async","mode","valid","shouldUseNativeValidation","validateFieldsNatively","Promise","resolve","errors","toNestErrors","criteriaMode","e","reject"],"mappings":"0jBAMMA,EAAmB,SACvBC,EACAC,GASA,OANAD,EAAUE,QAAQ,SAACC,GACK,aAAlBA,EAAMC,UACRD,EAAME,cAAgB,IAAMF,EAAMG,OAAOC,gBAE7C,GAEOP,EAAUQ,OAAmC,SAACC,EAAUN,GAE7D,IAAMO,EAAOP,EAAME,aAAaM,UAAU,GAAGC,QAAQ,MAAO,KAS5D,GAPKH,EAASC,KACZD,EAASC,GAAQ,CACfG,QAASV,EAAMU,QACfC,KAAMX,EAAMC,UAIZH,EAA0B,CAC5B,IAAMc,EAAQN,EAASC,GAAMK,MACvBC,EAAWD,GAASA,EAAMZ,EAAMC,SAEtCK,EAASC,GAAQO,eACfP,EACAT,EACAQ,EACAN,EAAMC,QACNY,EACK,GAAgBE,OAAOF,EAAsBb,EAAMU,SAAW,IAC/DV,EAAMU,QAEd,CAEA,OAAOJ,CACT,EAAG,GACL,gBAGE,SAACU,EAAQC,EAAeC,GAAoB,gBAApBA,IAAAA,EAAkB,CAAA,GAAE,SACrCC,EAAQC,EAAGC,GAAO,IACvB,IAAMC,EAAM,IAAIC,UACdC,OAAOC,OACL,CAAE,EACF,CACEC,WAAW,EACXC,gBAAgB,GAElBV,IAIJpB,EAAS,QAACyB,GAEV,IAAMM,EAAWN,EAAIO,QACnBL,OAAOC,OACL,CAAEK,OAAQZ,GAA4C,UAAzBA,EAAgBa,MAC7Cf,IAIEgB,EAAQJ,EAAST,GAIvB,OAFAE,EAAQY,2BAA6BC,EAAAA,uBAAuB,CAAE,EAAEb,GAEhEc,QAAAC,QAAOJ,EACH,CAAEb,OAAAA,EAAQkB,OAAQ,CAAI,GACtB,CACElB,OAAQ,CAAA,EACRkB,OAAQC,eACN1C,EACEgC,EAASS,QACRhB,EAAQY,2BACkB,QAAzBZ,EAAQkB,cAEZlB,IAGV,CAAC,MAAAmB,GAAA,OAAAL,QAAAM,OAAAD,EAAA,CAAA,CAAA"}
node_modules/@hookform/resolvers/ajv/dist/index.d.ts ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ export * from './ajv';
2
+ export * from './types';
node_modules/@hookform/resolvers/ajv/dist/types.d.ts ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import * as Ajv from 'ajv';
2
+ import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
3
+ export type Resolver = <T>(schema: Ajv.JSONSchemaType<T>, schemaOptions?: Ajv.Options, factoryOptions?: {
4
+ mode?: 'async' | 'sync';
5
+ }) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
node_modules/@hookform/resolvers/ajv/package.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@hookform/resolvers/ajv",
3
+ "amdName": "hookformResolversAjv",
4
+ "version": "1.0.0",
5
+ "private": true,
6
+ "description": "React Hook Form validation resolver: ajv",
7
+ "main": "dist/ajv.js",
8
+ "module": "dist/ajv.module.js",
9
+ "umd:main": "dist/ajv.umd.js",
10
+ "source": "src/index.ts",
11
+ "types": "dist/index.d.ts",
12
+ "license": "MIT",
13
+ "peerDependencies": {
14
+ "react-hook-form": "^7.0.0",
15
+ "@hookform/resolvers": "^2.0.0",
16
+ "ajv": "^8.12.0",
17
+ "ajv-errors": "^3.0.0"
18
+ }
19
+ }
node_modules/@hookform/resolvers/ajv/src/__tests__/Form-native-validation.tsx ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { render, screen } from '@testing-library/react';
2
+ import user from '@testing-library/user-event';
3
+ import { JSONSchemaType } from 'ajv';
4
+ import React from 'react';
5
+ import { useForm } from 'react-hook-form';
6
+ import { ajvResolver } from '..';
7
+
8
+ const USERNAME_REQUIRED_MESSAGE = 'username field is required';
9
+ const PASSWORD_REQUIRED_MESSAGE = 'password field is required';
10
+
11
+ type FormData = { username: string; password: string };
12
+
13
+ const schema: JSONSchemaType<FormData> = {
14
+ type: 'object',
15
+ properties: {
16
+ username: {
17
+ type: 'string',
18
+ minLength: 1,
19
+ errorMessage: { minLength: USERNAME_REQUIRED_MESSAGE },
20
+ },
21
+ password: {
22
+ type: 'string',
23
+ minLength: 1,
24
+ errorMessage: { minLength: PASSWORD_REQUIRED_MESSAGE },
25
+ },
26
+ },
27
+ required: ['username', 'password'],
28
+ additionalProperties: false,
29
+ };
30
+
31
+ interface Props {
32
+ onSubmit: (data: FormData) => void;
33
+ }
34
+
35
+ function TestComponent({ onSubmit }: Props) {
36
+ const { register, handleSubmit } = useForm<FormData>({
37
+ resolver: ajvResolver(schema),
38
+ shouldUseNativeValidation: true,
39
+ });
40
+
41
+ return (
42
+ <form onSubmit={handleSubmit(onSubmit)}>
43
+ <input {...register('username')} placeholder="username" />
44
+
45
+ <input {...register('password')} placeholder="password" />
46
+
47
+ <button type="submit">submit</button>
48
+ </form>
49
+ );
50
+ }
51
+
52
+ test("form's native validation with Ajv", async () => {
53
+ const handleSubmit = vi.fn();
54
+ render(<TestComponent onSubmit={handleSubmit} />);
55
+
56
+ // username
57
+ let usernameField = screen.getByPlaceholderText(
58
+ /username/i,
59
+ ) as HTMLInputElement;
60
+ expect(usernameField.validity.valid).toBe(true);
61
+ expect(usernameField.validationMessage).toBe('');
62
+
63
+ // password
64
+ let passwordField = screen.getByPlaceholderText(
65
+ /password/i,
66
+ ) as HTMLInputElement;
67
+ expect(passwordField.validity.valid).toBe(true);
68
+ expect(passwordField.validationMessage).toBe('');
69
+
70
+ await user.click(screen.getByText(/submit/i));
71
+
72
+ // username
73
+ usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
74
+ expect(usernameField.validity.valid).toBe(false);
75
+ expect(usernameField.validationMessage).toBe(USERNAME_REQUIRED_MESSAGE);
76
+
77
+ // password
78
+ passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
79
+ expect(passwordField.validity.valid).toBe(false);
80
+ expect(passwordField.validationMessage).toBe(PASSWORD_REQUIRED_MESSAGE);
81
+
82
+ await user.type(screen.getByPlaceholderText(/username/i), 'joe');
83
+ await user.type(screen.getByPlaceholderText(/password/i), 'password');
84
+
85
+ // username
86
+ usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
87
+ expect(usernameField.validity.valid).toBe(true);
88
+ expect(usernameField.validationMessage).toBe('');
89
+
90
+ // password
91
+ passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
92
+ expect(passwordField.validity.valid).toBe(true);
93
+ expect(passwordField.validationMessage).toBe('');
94
+ });
node_modules/@hookform/resolvers/ajv/src/__tests__/Form.tsx ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { render, screen } from '@testing-library/react';
2
+ import user from '@testing-library/user-event';
3
+ import { JSONSchemaType } from 'ajv';
4
+ import React from 'react';
5
+ import { useForm } from 'react-hook-form';
6
+ import { ajvResolver } from '..';
7
+
8
+ type FormData = { username: string; password: string };
9
+
10
+ const schema: JSONSchemaType<FormData> = {
11
+ type: 'object',
12
+ properties: {
13
+ username: {
14
+ type: 'string',
15
+ minLength: 1,
16
+ errorMessage: { minLength: 'username field is required' },
17
+ },
18
+ password: {
19
+ type: 'string',
20
+ minLength: 1,
21
+ errorMessage: { minLength: 'password field is required' },
22
+ },
23
+ },
24
+ required: ['username', 'password'],
25
+ additionalProperties: false,
26
+ };
27
+
28
+ interface Props {
29
+ onSubmit: (data: FormData) => void;
30
+ }
31
+
32
+ function TestComponent({ onSubmit }: Props) {
33
+ const {
34
+ register,
35
+ formState: { errors },
36
+ handleSubmit,
37
+ } = useForm<FormData>({
38
+ resolver: ajvResolver(schema), // Useful to check TypeScript regressions
39
+ });
40
+
41
+ return (
42
+ <form onSubmit={handleSubmit(onSubmit)}>
43
+ <input {...register('username')} />
44
+ {errors.username && <span role="alert">{errors.username.message}</span>}
45
+
46
+ <input {...register('password')} />
47
+ {errors.password && <span role="alert">{errors.password.message}</span>}
48
+
49
+ <button type="submit">submit</button>
50
+ </form>
51
+ );
52
+ }
53
+
54
+ test("form's validation with Ajv and TypeScript's integration", async () => {
55
+ const handleSubmit = vi.fn();
56
+ render(<TestComponent onSubmit={handleSubmit} />);
57
+
58
+ expect(screen.queryAllByRole('alert')).toHaveLength(0);
59
+
60
+ await user.click(screen.getByText(/submit/i));
61
+
62
+ expect(screen.getByText(/username field is required/i)).toBeInTheDocument();
63
+ expect(screen.getByText(/password field is required/i)).toBeInTheDocument();
64
+ expect(handleSubmit).not.toHaveBeenCalled();
65
+ });
node_modules/@hookform/resolvers/ajv/src/__tests__/__fixtures__/data.ts ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { JSONSchemaType } from 'ajv';
2
+ import { Field, InternalFieldName } from 'react-hook-form';
3
+
4
+ interface Data {
5
+ username: string;
6
+ password: string;
7
+ deepObject: { data: string; twoLayersDeep: { name: string } };
8
+ }
9
+
10
+ export const schema: JSONSchemaType<Data> = {
11
+ type: 'object',
12
+ properties: {
13
+ username: {
14
+ type: 'string',
15
+ minLength: 3,
16
+ },
17
+ password: {
18
+ type: 'string',
19
+ pattern: '.*[A-Z].*',
20
+ errorMessage: {
21
+ pattern: 'One uppercase character',
22
+ },
23
+ },
24
+ deepObject: {
25
+ type: 'object',
26
+ properties: {
27
+ data: { type: 'string' },
28
+ twoLayersDeep: {
29
+ type: 'object',
30
+ properties: { name: { type: 'string' } },
31
+ additionalProperties: false,
32
+ required: ['name'],
33
+ },
34
+ },
35
+ required: ['data', 'twoLayersDeep'],
36
+ },
37
+ },
38
+ required: ['username', 'password', 'deepObject'],
39
+ additionalProperties: false,
40
+ };
41
+
42
+ export const validData: Data = {
43
+ username: 'jsun969',
44
+ password: 'validPassword',
45
+ deepObject: {
46
+ twoLayersDeep: {
47
+ name: 'deeper',
48
+ },
49
+ data: 'data',
50
+ },
51
+ };
52
+
53
+ export const invalidData = {
54
+ username: '__',
55
+ password: 'invalid-password',
56
+ deepObject: {
57
+ data: 233,
58
+ twoLayersDeep: { name: 123 },
59
+ },
60
+ };
61
+
62
+ export const invalidDataWithUndefined = {
63
+ username: 'jsun969',
64
+ password: undefined,
65
+ deepObject: {
66
+ twoLayersDeep: {
67
+ name: 'deeper',
68
+ },
69
+ data: undefined,
70
+ },
71
+ };
72
+
73
+ export const fields: Record<InternalFieldName, Field['_f']> = {
74
+ username: {
75
+ ref: { name: 'username' },
76
+ name: 'username',
77
+ },
78
+ password: {
79
+ ref: { name: 'password' },
80
+ name: 'password',
81
+ },
82
+ email: {
83
+ ref: { name: 'email' },
84
+ name: 'email',
85
+ },
86
+ birthday: {
87
+ ref: { name: 'birthday' },
88
+ name: 'birthday',
89
+ },
90
+ };
node_modules/@hookform/resolvers/ajv/src/__tests__/__snapshots__/ajv.ts.snap ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`ajvResolver > should return all the error messages from ajvResolver when requirement fails and validateAllFieldCriteria set to true 1`] = `
4
+ {
5
+ "errors": {
6
+ "deepObject": {
7
+ "message": "must have required property 'deepObject'",
8
+ "ref": undefined,
9
+ "type": "required",
10
+ },
11
+ "password": {
12
+ "message": "must have required property 'password'",
13
+ "ref": {
14
+ "name": "password",
15
+ },
16
+ "type": "required",
17
+ },
18
+ "username": {
19
+ "message": "must have required property 'username'",
20
+ "ref": {
21
+ "name": "username",
22
+ },
23
+ "type": "required",
24
+ },
25
+ },
26
+ "values": {},
27
+ }
28
+ `;
29
+
30
+ exports[`ajvResolver > should return all the error messages from ajvResolver when requirement fails and validateAllFieldCriteria set to true and \`mode: sync\` 1`] = `
31
+ {
32
+ "errors": {
33
+ "deepObject": {
34
+ "message": "must have required property 'deepObject'",
35
+ "ref": undefined,
36
+ "type": "required",
37
+ },
38
+ "password": {
39
+ "message": "must have required property 'password'",
40
+ "ref": {
41
+ "name": "password",
42
+ },
43
+ "type": "required",
44
+ },
45
+ "username": {
46
+ "message": "must have required property 'username'",
47
+ "ref": {
48
+ "name": "username",
49
+ },
50
+ "type": "required",
51
+ },
52
+ },
53
+ "values": {},
54
+ }
55
+ `;
56
+
57
+ exports[`ajvResolver > should return all the error messages from ajvResolver when some property is undefined and result will keep the input data structure 1`] = `
58
+ {
59
+ "errors": {
60
+ "deepObject": {
61
+ "data": {
62
+ "message": "must have required property 'data'",
63
+ "ref": undefined,
64
+ "type": "required",
65
+ },
66
+ },
67
+ "password": {
68
+ "message": "must have required property 'password'",
69
+ "ref": {
70
+ "name": "password",
71
+ },
72
+ "type": "required",
73
+ },
74
+ },
75
+ "values": {},
76
+ }
77
+ `;
78
+
79
+ exports[`ajvResolver > should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true 1`] = `
80
+ {
81
+ "errors": {
82
+ "deepObject": {
83
+ "data": {
84
+ "message": "must be string",
85
+ "ref": undefined,
86
+ "type": "type",
87
+ "types": {
88
+ "type": "must be string",
89
+ },
90
+ },
91
+ "twoLayersDeep": {
92
+ "name": {
93
+ "message": "must be string",
94
+ "ref": undefined,
95
+ "type": "type",
96
+ "types": {
97
+ "type": "must be string",
98
+ },
99
+ },
100
+ },
101
+ },
102
+ "password": {
103
+ "message": "One uppercase character",
104
+ "ref": {
105
+ "name": "password",
106
+ },
107
+ "type": "errorMessage",
108
+ "types": {
109
+ "errorMessage": "One uppercase character",
110
+ },
111
+ },
112
+ "username": {
113
+ "message": "must NOT have fewer than 3 characters",
114
+ "ref": {
115
+ "name": "username",
116
+ },
117
+ "type": "minLength",
118
+ "types": {
119
+ "minLength": "must NOT have fewer than 3 characters",
120
+ },
121
+ },
122
+ },
123
+ "values": {},
124
+ }
125
+ `;
126
+
127
+ exports[`ajvResolver > should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true and \`mode: sync\` 1`] = `
128
+ {
129
+ "errors": {
130
+ "deepObject": {
131
+ "data": {
132
+ "message": "must be string",
133
+ "ref": undefined,
134
+ "type": "type",
135
+ "types": {
136
+ "type": "must be string",
137
+ },
138
+ },
139
+ "twoLayersDeep": {
140
+ "name": {
141
+ "message": "must be string",
142
+ "ref": undefined,
143
+ "type": "type",
144
+ "types": {
145
+ "type": "must be string",
146
+ },
147
+ },
148
+ },
149
+ },
150
+ "password": {
151
+ "message": "One uppercase character",
152
+ "ref": {
153
+ "name": "password",
154
+ },
155
+ "type": "errorMessage",
156
+ "types": {
157
+ "errorMessage": "One uppercase character",
158
+ },
159
+ },
160
+ "username": {
161
+ "message": "must NOT have fewer than 3 characters",
162
+ "ref": {
163
+ "name": "username",
164
+ },
165
+ "type": "minLength",
166
+ "types": {
167
+ "minLength": "must NOT have fewer than 3 characters",
168
+ },
169
+ },
170
+ },
171
+ "values": {},
172
+ }
173
+ `;
174
+
175
+ exports[`ajvResolver > should return single error message from ajvResolver when validation fails and validateAllFieldCriteria set to false 1`] = `
176
+ {
177
+ "errors": {
178
+ "deepObject": {
179
+ "data": {
180
+ "message": "must be string",
181
+ "ref": undefined,
182
+ "type": "type",
183
+ },
184
+ "twoLayersDeep": {
185
+ "name": {
186
+ "message": "must be string",
187
+ "ref": undefined,
188
+ "type": "type",
189
+ },
190
+ },
191
+ },
192
+ "password": {
193
+ "message": "One uppercase character",
194
+ "ref": {
195
+ "name": "password",
196
+ },
197
+ "type": "errorMessage",
198
+ },
199
+ "username": {
200
+ "message": "must NOT have fewer than 3 characters",
201
+ "ref": {
202
+ "name": "username",
203
+ },
204
+ "type": "minLength",
205
+ },
206
+ },
207
+ "values": {},
208
+ }
209
+ `;
210
+
211
+ exports[`ajvResolver > should return single error message from ajvResolver when validation fails and validateAllFieldCriteria set to false and \`mode: sync\` 1`] = `
212
+ {
213
+ "errors": {
214
+ "deepObject": {
215
+ "data": {
216
+ "message": "must be string",
217
+ "ref": undefined,
218
+ "type": "type",
219
+ },
220
+ "twoLayersDeep": {
221
+ "name": {
222
+ "message": "must be string",
223
+ "ref": undefined,
224
+ "type": "type",
225
+ },
226
+ },
227
+ },
228
+ "password": {
229
+ "message": "One uppercase character",
230
+ "ref": {
231
+ "name": "password",
232
+ },
233
+ "type": "errorMessage",
234
+ },
235
+ "username": {
236
+ "message": "must NOT have fewer than 3 characters",
237
+ "ref": {
238
+ "name": "username",
239
+ },
240
+ "type": "minLength",
241
+ },
242
+ },
243
+ "values": {},
244
+ }
245
+ `;
node_modules/@hookform/resolvers/ajv/src/__tests__/ajv.ts ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { ajvResolver } from '..';
2
+ import {
3
+ fields,
4
+ invalidData,
5
+ invalidDataWithUndefined,
6
+ schema,
7
+ validData,
8
+ } from './__fixtures__/data';
9
+
10
+ const shouldUseNativeValidation = false;
11
+
12
+ describe('ajvResolver', () => {
13
+ it('should return values from ajvResolver when validation pass', async () => {
14
+ expect(
15
+ await ajvResolver(schema)(validData, undefined, {
16
+ fields,
17
+ shouldUseNativeValidation,
18
+ }),
19
+ ).toEqual({
20
+ values: validData,
21
+ errors: {},
22
+ });
23
+ });
24
+
25
+ it('should return values from ajvResolver with `mode: sync` when validation pass', async () => {
26
+ expect(
27
+ await ajvResolver(schema, undefined, {
28
+ mode: 'sync',
29
+ })(validData, undefined, { fields, shouldUseNativeValidation }),
30
+ ).toEqual({
31
+ values: validData,
32
+ errors: {},
33
+ });
34
+ });
35
+
36
+ it('should return single error message from ajvResolver when validation fails and validateAllFieldCriteria set to false', async () => {
37
+ expect(
38
+ await ajvResolver(schema)(invalidData, undefined, {
39
+ fields,
40
+ shouldUseNativeValidation,
41
+ }),
42
+ ).toMatchSnapshot();
43
+ });
44
+
45
+ it('should return single error message from ajvResolver when validation fails and validateAllFieldCriteria set to false and `mode: sync`', async () => {
46
+ expect(
47
+ await ajvResolver(schema, undefined, {
48
+ mode: 'sync',
49
+ })(invalidData, undefined, { fields, shouldUseNativeValidation }),
50
+ ).toMatchSnapshot();
51
+ });
52
+
53
+ it('should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true', async () => {
54
+ expect(
55
+ await ajvResolver(schema)(
56
+ invalidData,
57
+ {},
58
+ { fields, criteriaMode: 'all', shouldUseNativeValidation },
59
+ ),
60
+ ).toMatchSnapshot();
61
+ });
62
+
63
+ it('should return all the error messages from ajvResolver when validation fails and validateAllFieldCriteria set to true and `mode: sync`', async () => {
64
+ expect(
65
+ await ajvResolver(schema, undefined, { mode: 'sync' })(
66
+ invalidData,
67
+ {},
68
+ { fields, criteriaMode: 'all', shouldUseNativeValidation },
69
+ ),
70
+ ).toMatchSnapshot();
71
+ });
72
+
73
+ it('should return all the error messages from ajvResolver when requirement fails and validateAllFieldCriteria set to true', async () => {
74
+ expect(
75
+ await ajvResolver(schema)({}, undefined, {
76
+ fields,
77
+ shouldUseNativeValidation,
78
+ }),
79
+ ).toMatchSnapshot();
80
+ });
81
+
82
+ it('should return all the error messages from ajvResolver when requirement fails and validateAllFieldCriteria set to true and `mode: sync`', async () => {
83
+ expect(
84
+ await ajvResolver(schema, undefined, { mode: 'sync' })({}, undefined, {
85
+ fields,
86
+ shouldUseNativeValidation,
87
+ }),
88
+ ).toMatchSnapshot();
89
+ });
90
+
91
+ it('should return all the error messages from ajvResolver when some property is undefined and result will keep the input data structure', async () => {
92
+ expect(
93
+ await ajvResolver(schema, undefined, { mode: 'sync' })(
94
+ invalidDataWithUndefined,
95
+ undefined,
96
+ {
97
+ fields,
98
+ shouldUseNativeValidation,
99
+ },
100
+ ),
101
+ ).toMatchSnapshot();
102
+ });
103
+ });
node_modules/@hookform/resolvers/ajv/src/ajv.ts ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
2
+ import Ajv, { DefinedError } from 'ajv';
3
+ import ajvErrors from 'ajv-errors';
4
+ import { FieldError, appendErrors } from 'react-hook-form';
5
+ import { Resolver } from './types';
6
+
7
+ const parseErrorSchema = (
8
+ ajvErrors: DefinedError[],
9
+ validateAllFieldCriteria: boolean,
10
+ ) => {
11
+ // Ajv will return empty instancePath when require error
12
+ ajvErrors.forEach((error) => {
13
+ if (error.keyword === 'required') {
14
+ error.instancePath += '/' + error.params.missingProperty;
15
+ }
16
+ });
17
+
18
+ return ajvErrors.reduce<Record<string, FieldError>>((previous, error) => {
19
+ // `/deepObject/data` -> `deepObject.data`
20
+ const path = error.instancePath.substring(1).replace(/\//g, '.');
21
+
22
+ if (!previous[path]) {
23
+ previous[path] = {
24
+ message: error.message,
25
+ type: error.keyword,
26
+ };
27
+ }
28
+
29
+ if (validateAllFieldCriteria) {
30
+ const types = previous[path].types;
31
+ const messages = types && types[error.keyword];
32
+
33
+ previous[path] = appendErrors(
34
+ path,
35
+ validateAllFieldCriteria,
36
+ previous,
37
+ error.keyword,
38
+ messages
39
+ ? ([] as string[]).concat(messages as string[], error.message || '')
40
+ : error.message,
41
+ ) as FieldError;
42
+ }
43
+
44
+ return previous;
45
+ }, {});
46
+ };
47
+
48
+ export const ajvResolver: Resolver =
49
+ (schema, schemaOptions, resolverOptions = {}) =>
50
+ async (values, _, options) => {
51
+ const ajv = new Ajv(
52
+ Object.assign(
53
+ {},
54
+ {
55
+ allErrors: true,
56
+ validateSchema: true,
57
+ },
58
+ schemaOptions,
59
+ ),
60
+ );
61
+
62
+ ajvErrors(ajv);
63
+
64
+ const validate = ajv.compile(
65
+ Object.assign(
66
+ { $async: resolverOptions && resolverOptions.mode === 'async' },
67
+ schema,
68
+ ),
69
+ );
70
+
71
+ const valid = validate(values);
72
+
73
+ options.shouldUseNativeValidation && validateFieldsNatively({}, options);
74
+
75
+ return valid
76
+ ? { values, errors: {} }
77
+ : {
78
+ values: {},
79
+ errors: toNestErrors(
80
+ parseErrorSchema(
81
+ validate.errors as DefinedError[],
82
+ !options.shouldUseNativeValidation &&
83
+ options.criteriaMode === 'all',
84
+ ),
85
+ options,
86
+ ),
87
+ };
88
+ };
node_modules/@hookform/resolvers/ajv/src/index.ts ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ export * from './ajv';
2
+ export * from './types';
node_modules/@hookform/resolvers/ajv/src/types.ts ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import * as Ajv from 'ajv';
2
+ import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
3
+
4
+ export type Resolver = <T>(
5
+ schema: Ajv.JSONSchemaType<T>,
6
+ schemaOptions?: Ajv.Options,
7
+ factoryOptions?: { mode?: 'async' | 'sync' },
8
+ ) => <TFieldValues extends FieldValues, TContext>(
9
+ values: TFieldValues,
10
+ context: TContext | undefined,
11
+ options: ResolverOptions<TFieldValues>,
12
+ ) => Promise<ResolverResult<TFieldValues>>;
node_modules/@hookform/resolvers/arktype/dist/arktype.d.ts ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import type { Resolver } from './types';
2
+ export declare const arktypeResolver: Resolver;
node_modules/@hookform/resolvers/arktype/dist/arktype.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ var r=require("@hookform/resolvers"),e=require("arktype");exports.arktypeResolver=function(o,t,a){return void 0===a&&(a={}),function(t,s,i){var n,u=o(t);return u instanceof e.ArkErrors?{values:{},errors:r.toNestErrors((n=u,n.forEach(function(r){return Object.assign(r,{type:r.code})}),n.byPath),i)}:(i.shouldUseNativeValidation&&r.validateFieldsNatively({},i),{errors:{},values:a.raw?t:u})}};
2
+ //# sourceMappingURL=arktype.js.map
node_modules/@hookform/resolvers/arktype/dist/arktype.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"arktype.js","sources":["../src/arktype.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { ArkErrors } from 'arktype';\nimport { FieldError, FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (e: ArkErrors): Record<string, FieldError> => {\n // copy code to type to match FieldError shape\n e.forEach((e) => Object.assign(e, { type: e.code }));\n // need to cast here because TS doesn't understand we added the type field\n return e.byPath as never;\n};\n\nexport const arktypeResolver: Resolver =\n (schema, _schemaOptions, resolverOptions = {}) =>\n (values, _, options) => {\n const out = schema(values);\n\n if (out instanceof ArkErrors) {\n return {\n values: {},\n errors: toNestErrors(parseErrorSchema(out), options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : out,\n };\n };\n"],"names":["schema","_schemaOptions","resolverOptions","values","_","options","e","out","ArkErrors","errors","toNestErrors","forEach","Object","assign","type","code","byPath","shouldUseNativeValidation","validateFieldsNatively","raw"],"mappings":"kFAaE,SAACA,EAAQC,EAAgBC,GACzB,YADyBA,IAAAA,IAAAA,EAAkB,CAAA,GAC3C,SAACC,EAAQC,EAAGC,GACV,IAVsBC,EAUhBC,EAAMP,EAAOG,GAEnB,OAAII,aAAeC,EAAAA,UACV,CACLL,OAAQ,CAAE,EACVM,OAAQC,EAAYA,cAfFJ,EAeoBC,EAb5CD,EAAEK,QAAQ,SAACL,UAAMM,OAAOC,OAAOP,EAAG,CAAEQ,KAAMR,EAAES,MAAO,GAE5CT,EAAEU,QAWyCX,KAIhDA,EAAQY,2BAA6BC,EAAsBA,uBAAC,CAAE,EAAEb,GAEzD,CACLI,OAAQ,CAAiB,EACzBN,OAAQD,EAAgBiB,IAAMhB,EAASI,GAE3C,CAAC"}
node_modules/@hookform/resolvers/arktype/dist/arktype.mjs ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import{toNestErrors as r,validateFieldsNatively as o}from"@hookform/resolvers";import{ArkErrors as e}from"arktype";var t=function(t,a,n){return void 0===n&&(n={}),function(a,i,s){var u,f=t(a);return f instanceof e?{values:{},errors:r((u=f,u.forEach(function(r){return Object.assign(r,{type:r.code})}),u.byPath),s)}:(s.shouldUseNativeValidation&&o({},s),{errors:{},values:n.raw?a:f})}};export{t as arktypeResolver};
2
+ //# sourceMappingURL=arktype.module.js.map
node_modules/@hookform/resolvers/arktype/dist/arktype.modern.mjs ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import{toNestErrors as r,validateFieldsNatively as o}from"@hookform/resolvers";import{ArkErrors as e}from"arktype";const s=(s,t,a={})=>(t,i,n)=>{const c=s(t);return c instanceof e?{values:{},errors:r((f=c,f.forEach(r=>Object.assign(r,{type:r.code})),f.byPath),n)}:(n.shouldUseNativeValidation&&o({},n),{errors:{},values:a.raw?t:c});var f};export{s as arktypeResolver};
2
+ //# sourceMappingURL=arktype.modern.mjs.map
node_modules/@hookform/resolvers/arktype/dist/arktype.modern.mjs.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"arktype.modern.mjs","sources":["../src/arktype.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { ArkErrors } from 'arktype';\nimport { FieldError, FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (e: ArkErrors): Record<string, FieldError> => {\n // copy code to type to match FieldError shape\n e.forEach((e) => Object.assign(e, { type: e.code }));\n // need to cast here because TS doesn't understand we added the type field\n return e.byPath as never;\n};\n\nexport const arktypeResolver: Resolver =\n (schema, _schemaOptions, resolverOptions = {}) =>\n (values, _, options) => {\n const out = schema(values);\n\n if (out instanceof ArkErrors) {\n return {\n values: {},\n errors: toNestErrors(parseErrorSchema(out), options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : out,\n };\n };\n"],"names":["arktypeResolver","schema","_schemaOptions","resolverOptions","values","_","options","out","ArkErrors","errors","toNestErrors","e","forEach","Object","assign","type","code","byPath","shouldUseNativeValidation","validateFieldsNatively","raw"],"mappings":"mHAKA,MAOaA,EACXA,CAACC,EAAQC,EAAgBC,EAAkB,CAAA,IAC3C,CAACC,EAAQC,EAAGC,KACV,MAAMC,EAAMN,EAAOG,GAEnB,OAAIG,aAAeC,EACV,CACLJ,OAAQ,CAAE,EACVK,OAAQC,GAfUC,EAeoBJ,EAb5CI,EAAEC,QAASD,GAAME,OAAOC,OAAOH,EAAG,CAAEI,KAAMJ,EAAEK,QAErCL,EAAEM,QAWyCX,KAIhDA,EAAQY,2BAA6BC,EAAuB,GAAIb,GAEzD,CACLG,OAAQ,CAAA,EACRL,OAAQD,EAAgBiB,IAAMhB,EAASG,IAvBnBI"}
node_modules/@hookform/resolvers/arktype/dist/arktype.module.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ import{toNestErrors as r,validateFieldsNatively as o}from"@hookform/resolvers";import{ArkErrors as e}from"arktype";var t=function(t,a,n){return void 0===n&&(n={}),function(a,i,s){var u,f=t(a);return f instanceof e?{values:{},errors:r((u=f,u.forEach(function(r){return Object.assign(r,{type:r.code})}),u.byPath),s)}:(s.shouldUseNativeValidation&&o({},s),{errors:{},values:n.raw?a:f})}};export{t as arktypeResolver};
2
+ //# sourceMappingURL=arktype.module.js.map
node_modules/@hookform/resolvers/arktype/dist/arktype.module.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"arktype.module.js","sources":["../src/arktype.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { ArkErrors } from 'arktype';\nimport { FieldError, FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (e: ArkErrors): Record<string, FieldError> => {\n // copy code to type to match FieldError shape\n e.forEach((e) => Object.assign(e, { type: e.code }));\n // need to cast here because TS doesn't understand we added the type field\n return e.byPath as never;\n};\n\nexport const arktypeResolver: Resolver =\n (schema, _schemaOptions, resolverOptions = {}) =>\n (values, _, options) => {\n const out = schema(values);\n\n if (out instanceof ArkErrors) {\n return {\n values: {},\n errors: toNestErrors(parseErrorSchema(out), options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : out,\n };\n };\n"],"names":["arktypeResolver","schema","_schemaOptions","resolverOptions","values","_","options","e","out","ArkErrors","errors","toNestErrors","forEach","Object","assign","type","code","byPath","shouldUseNativeValidation","validateFieldsNatively","raw"],"mappings":"mHAKA,IAOaA,EACX,SAACC,EAAQC,EAAgBC,GACzB,YADyBA,IAAAA,IAAAA,EAAkB,CAAA,GAC3C,SAACC,EAAQC,EAAGC,GACV,IAVsBC,EAUhBC,EAAMP,EAAOG,GAEnB,OAAII,aAAeC,EACV,CACLL,OAAQ,CAAE,EACVM,OAAQC,GAfUJ,EAeoBC,EAb5CD,EAAEK,QAAQ,SAACL,UAAMM,OAAOC,OAAOP,EAAG,CAAEQ,KAAMR,EAAES,MAAO,GAE5CT,EAAEU,QAWyCX,KAIhDA,EAAQY,2BAA6BC,EAAuB,CAAE,EAAEb,GAEzD,CACLI,OAAQ,CAAiB,EACzBN,OAAQD,EAAgBiB,IAAMhB,EAASI,GAE3C,CAAC"}
node_modules/@hookform/resolvers/arktype/dist/arktype.umd.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@hookform/resolvers"),require("arktype")):"function"==typeof define&&define.amd?define(["exports","@hookform/resolvers","arktype"],o):o((e||self).hookformResolversArktype={},e.hookformResolvers,e.arktype)}(this,function(e,o,r){e.arktypeResolver=function(e,t,s){return void 0===s&&(s={}),function(t,n,i){var f,a=e(t);return a instanceof r.ArkErrors?{values:{},errors:o.toNestErrors((f=a,f.forEach(function(e){return Object.assign(e,{type:e.code})}),f.byPath),i)}:(i.shouldUseNativeValidation&&o.validateFieldsNatively({},i),{errors:{},values:s.raw?t:a})}}});
2
+ //# sourceMappingURL=arktype.umd.js.map
node_modules/@hookform/resolvers/arktype/dist/arktype.umd.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"arktype.umd.js","sources":["../src/arktype.ts"],"sourcesContent":["import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';\nimport { ArkErrors } from 'arktype';\nimport { FieldError, FieldErrors } from 'react-hook-form';\nimport type { Resolver } from './types';\n\nconst parseErrorSchema = (e: ArkErrors): Record<string, FieldError> => {\n // copy code to type to match FieldError shape\n e.forEach((e) => Object.assign(e, { type: e.code }));\n // need to cast here because TS doesn't understand we added the type field\n return e.byPath as never;\n};\n\nexport const arktypeResolver: Resolver =\n (schema, _schemaOptions, resolverOptions = {}) =>\n (values, _, options) => {\n const out = schema(values);\n\n if (out instanceof ArkErrors) {\n return {\n values: {},\n errors: toNestErrors(parseErrorSchema(out), options),\n };\n }\n\n options.shouldUseNativeValidation && validateFieldsNatively({}, options);\n\n return {\n errors: {} as FieldErrors,\n values: resolverOptions.raw ? values : out,\n };\n };\n"],"names":["schema","_schemaOptions","resolverOptions","values","_","options","e","out","ArkErrors","errors","toNestErrors","forEach","Object","assign","type","code","byPath","shouldUseNativeValidation","validateFieldsNatively","raw"],"mappings":"wXAaE,SAACA,EAAQC,EAAgBC,GACzB,YADyBA,IAAAA,IAAAA,EAAkB,CAAA,GAC3C,SAACC,EAAQC,EAAGC,GACV,IAVsBC,EAUhBC,EAAMP,EAAOG,GAEnB,OAAII,aAAeC,EAAAA,UACV,CACLL,OAAQ,CAAE,EACVM,OAAQC,EAAYA,cAfFJ,EAeoBC,EAb5CD,EAAEK,QAAQ,SAACL,UAAMM,OAAOC,OAAOP,EAAG,CAAEQ,KAAMR,EAAES,MAAO,GAE5CT,EAAEU,QAWyCX,KAIhDA,EAAQY,2BAA6BC,EAAsBA,uBAAC,CAAE,EAAEb,GAEzD,CACLI,OAAQ,CAAiB,EACzBN,OAAQD,EAAgBiB,IAAMhB,EAASI,GAE3C,CAAC"}
node_modules/@hookform/resolvers/arktype/dist/index.d.ts ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ export * from './arktype';
2
+ export * from './types';
node_modules/@hookform/resolvers/arktype/dist/types.d.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import { Type } from 'arktype';
2
+ import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
3
+ export type Resolver = <T extends Type<any>>(schema: T, schemaOptions?: undefined, factoryOptions?: {
4
+ /**
5
+ * Return the raw input values rather than the parsed values.
6
+ * @default false
7
+ */
8
+ raw?: boolean;
9
+ }) => <TFieldValues extends FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => ResolverResult<TFieldValues>;
node_modules/@hookform/resolvers/arktype/package.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@hookform/resolvers/arktype",
3
+ "amdName": "hookformResolversArktype",
4
+ "version": "2.0.0",
5
+ "private": true,
6
+ "description": "React Hook Form validation resolver: arktype",
7
+ "main": "dist/arktype.js",
8
+ "module": "dist/arktype.module.js",
9
+ "umd:main": "dist/arktype.umd.js",
10
+ "source": "src/index.ts",
11
+ "types": "dist/index.d.ts",
12
+ "license": "MIT",
13
+ "peerDependencies": {
14
+ "react-hook-form": "^7.0.0",
15
+ "@hookform/resolvers": "^2.0.0",
16
+ "arktype": "2.0.0-dev.14"
17
+ }
18
+ }
node_modules/@hookform/resolvers/arktype/src/__tests__/Form-native-validation.tsx ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { render, screen } from '@testing-library/react';
2
+ import user from '@testing-library/user-event';
3
+ import { type } from 'arktype';
4
+ import React from 'react';
5
+ import { useForm } from 'react-hook-form';
6
+ import { arktypeResolver } from '..';
7
+
8
+ const schema = type({
9
+ username: 'string>1',
10
+ password: 'string>1',
11
+ });
12
+
13
+ type FormData = typeof schema.infer;
14
+
15
+ interface Props {
16
+ onSubmit: (data: FormData) => void;
17
+ }
18
+
19
+ function TestComponent({ onSubmit }: Props) {
20
+ const { register, handleSubmit } = useForm<FormData>({
21
+ resolver: arktypeResolver(schema),
22
+ shouldUseNativeValidation: true,
23
+ });
24
+
25
+ return (
26
+ <form onSubmit={handleSubmit(onSubmit)}>
27
+ <input {...register('username')} placeholder="username" />
28
+
29
+ <input {...register('password')} placeholder="password" />
30
+
31
+ <button type="submit">submit</button>
32
+ </form>
33
+ );
34
+ }
35
+
36
+ test("form's native validation with Zod", async () => {
37
+ const handleSubmit = vi.fn();
38
+ render(<TestComponent onSubmit={handleSubmit} />);
39
+
40
+ // username
41
+ let usernameField = screen.getByPlaceholderText(
42
+ /username/i,
43
+ ) as HTMLInputElement;
44
+ expect(usernameField.validity.valid).toBe(true);
45
+ expect(usernameField.validationMessage).toBe('');
46
+
47
+ // password
48
+ let passwordField = screen.getByPlaceholderText(
49
+ /password/i,
50
+ ) as HTMLInputElement;
51
+ expect(passwordField.validity.valid).toBe(true);
52
+ expect(passwordField.validationMessage).toBe('');
53
+
54
+ await user.click(screen.getByText(/submit/i));
55
+
56
+ // username
57
+ usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
58
+ expect(usernameField.validity.valid).toBe(false);
59
+ expect(usernameField.validationMessage).toBe(
60
+ 'username must be more than length 1',
61
+ );
62
+
63
+ // password
64
+ passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
65
+ expect(passwordField.validity.valid).toBe(false);
66
+ expect(passwordField.validationMessage).toBe(
67
+ 'password must be more than length 1',
68
+ );
69
+
70
+ await user.type(screen.getByPlaceholderText(/username/i), 'joe');
71
+ await user.type(screen.getByPlaceholderText(/password/i), 'password');
72
+
73
+ // username
74
+ usernameField = screen.getByPlaceholderText(/username/i) as HTMLInputElement;
75
+ expect(usernameField.validity.valid).toBe(true);
76
+ expect(usernameField.validationMessage).toBe('');
77
+
78
+ // password
79
+ passwordField = screen.getByPlaceholderText(/password/i) as HTMLInputElement;
80
+ expect(passwordField.validity.valid).toBe(true);
81
+ expect(passwordField.validationMessage).toBe('');
82
+ });
node_modules/@hookform/resolvers/arktype/src/__tests__/Form.tsx ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { render, screen } from '@testing-library/react';
2
+ import user from '@testing-library/user-event';
3
+ import { type } from 'arktype';
4
+ import React from 'react';
5
+ import { useForm } from 'react-hook-form';
6
+ import { arktypeResolver } from '..';
7
+
8
+ const schema = type({
9
+ username: 'string>1',
10
+ password: 'string>1',
11
+ });
12
+
13
+ type FormData = typeof schema.infer & { unusedProperty: string };
14
+
15
+ interface Props {
16
+ onSubmit: (data: FormData) => void;
17
+ }
18
+
19
+ function TestComponent({ onSubmit }: Props) {
20
+ const {
21
+ register,
22
+ handleSubmit,
23
+ formState: { errors },
24
+ } = useForm<FormData>({
25
+ resolver: arktypeResolver(schema), // Useful to check TypeScript regressions
26
+ });
27
+
28
+ return (
29
+ <form onSubmit={handleSubmit(onSubmit)}>
30
+ <input {...register('username')} />
31
+ {errors.username && <span role="alert">{errors.username.message}</span>}
32
+
33
+ <input {...register('password')} />
34
+ {errors.password && <span role="alert">{errors.password.message}</span>}
35
+
36
+ <button type="submit">submit</button>
37
+ </form>
38
+ );
39
+ }
40
+
41
+ test("form's validation with arkType and TypeScript's integration", async () => {
42
+ const handleSubmit = vi.fn();
43
+ render(<TestComponent onSubmit={handleSubmit} />);
44
+
45
+ expect(screen.queryAllByRole('alert')).toHaveLength(0);
46
+
47
+ await user.click(screen.getByText(/submit/i));
48
+
49
+ expect(
50
+ screen.getByText('username must be more than length 1 (was 0)'),
51
+ ).toBeInTheDocument();
52
+ expect(
53
+ screen.getByText('password must be more than length 1 (was 0)'),
54
+ ).toBeInTheDocument();
55
+ expect(handleSubmit).not.toHaveBeenCalled();
56
+ });
node_modules/@hookform/resolvers/arktype/src/__tests__/__fixtures__/data.ts ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { type } from 'arktype';
2
+ import { Field, InternalFieldName } from 'react-hook-form';
3
+
4
+ export const schema = type({
5
+ username: 'string>2',
6
+ password: '/.*[A-Za-z].*/>8|/.*\\d.*/',
7
+ repeatPassword: 'string>1',
8
+ accessToken: 'string|number',
9
+ birthYear: '1900<number<2013',
10
+ email: 'email',
11
+ tags: 'string[]',
12
+ enabled: 'boolean',
13
+ url: 'string>1',
14
+ 'like?': type({
15
+ id: 'number',
16
+ name: 'string>3',
17
+ }).array(),
18
+ dateStr: 'Date',
19
+ });
20
+
21
+ export const validData: typeof schema.infer = {
22
+ username: 'Doe',
23
+ password: 'Password123_',
24
+ repeatPassword: 'Password123_',
25
+ birthYear: 2000,
26
+ email: '[email protected]',
27
+ tags: ['tag1', 'tag2'],
28
+ enabled: true,
29
+ accessToken: 'accessToken',
30
+ url: 'https://react-hook-form.com/',
31
+ like: [
32
+ {
33
+ id: 1,
34
+ name: 'name',
35
+ },
36
+ ],
37
+ dateStr: new Date('2020-01-01'),
38
+ };
39
+
40
+ export const invalidData = {
41
+ password: '___',
42
+ email: '',
43
+ birthYear: 'birthYear',
44
+ like: [{ id: 'z' }],
45
+ url: 'abc',
46
+ };
47
+
48
+ export const fields: Record<InternalFieldName, Field['_f']> = {
49
+ username: {
50
+ ref: { name: 'username' },
51
+ name: 'username',
52
+ },
53
+ password: {
54
+ ref: { name: 'password' },
55
+ name: 'password',
56
+ },
57
+ email: {
58
+ ref: { name: 'email' },
59
+ name: 'email',
60
+ },
61
+ birthday: {
62
+ ref: { name: 'birthday' },
63
+ name: 'birthday',
64
+ },
65
+ };
node_modules/@hookform/resolvers/arktype/src/__tests__/__snapshots__/arktype.ts.snap ADDED
@@ -0,0 +1,467 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`arktypeResolver > should return a single error from arktypeResolver when validation fails 1`] = `
4
+ {
5
+ "errors": {
6
+ "accessToken": ArkError {
7
+ "code": "required",
8
+ "data": {
9
+ "birthYear": "birthYear",
10
+ "email": "",
11
+ "like": [
12
+ {
13
+ "id": "z",
14
+ },
15
+ ],
16
+ "password": "___",
17
+ "url": "abc",
18
+ },
19
+ "input": {
20
+ "code": "required",
21
+ "missingValueDescription": "a number or a string",
22
+ "relativePath": [
23
+ "accessToken",
24
+ ],
25
+ },
26
+ "missingValueDescription": "a number or a string",
27
+ "nodeConfig": {
28
+ "actual": [Function],
29
+ "description": [Function],
30
+ "expected": [Function],
31
+ "message": [Function],
32
+ "problem": [Function],
33
+ },
34
+ "path": [
35
+ "accessToken",
36
+ ],
37
+ "ref": undefined,
38
+ "relativePath": [
39
+ "accessToken",
40
+ ],
41
+ "type": "required",
42
+ Symbol(ArkTypeInternalKind): "error",
43
+ },
44
+ "birthYear": ArkError {
45
+ "code": "domain",
46
+ "data": "birthYear",
47
+ "description": "a number",
48
+ "domain": "number",
49
+ "input": {
50
+ "code": "domain",
51
+ "description": "a number",
52
+ "domain": "number",
53
+ },
54
+ "nodeConfig": {
55
+ "actual": [Function],
56
+ "description": [Function],
57
+ "expected": [Function],
58
+ "message": [Function],
59
+ "problem": [Function],
60
+ },
61
+ "path": [
62
+ "birthYear",
63
+ ],
64
+ "ref": undefined,
65
+ "type": "domain",
66
+ Symbol(ArkTypeInternalKind): "error",
67
+ },
68
+ "dateStr": ArkError {
69
+ "code": "required",
70
+ "data": {
71
+ "birthYear": "birthYear",
72
+ "email": "",
73
+ "like": [
74
+ {
75
+ "id": "z",
76
+ },
77
+ ],
78
+ "password": "___",
79
+ "url": "abc",
80
+ },
81
+ "input": {
82
+ "code": "required",
83
+ "missingValueDescription": "a Date",
84
+ "relativePath": [
85
+ "dateStr",
86
+ ],
87
+ },
88
+ "missingValueDescription": "a Date",
89
+ "nodeConfig": {
90
+ "actual": [Function],
91
+ "description": [Function],
92
+ "expected": [Function],
93
+ "message": [Function],
94
+ "problem": [Function],
95
+ },
96
+ "path": [
97
+ "dateStr",
98
+ ],
99
+ "ref": undefined,
100
+ "relativePath": [
101
+ "dateStr",
102
+ ],
103
+ "type": "required",
104
+ Symbol(ArkTypeInternalKind): "error",
105
+ },
106
+ "email": ArkError {
107
+ "code": "pattern",
108
+ "data": "",
109
+ "description": "a valid email",
110
+ "flags": "",
111
+ "input": {
112
+ "code": "pattern",
113
+ "description": "a valid email",
114
+ "flags": "",
115
+ "rule": "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$",
116
+ },
117
+ "nodeConfig": {
118
+ "actual": [Function],
119
+ "description": [Function],
120
+ "expected": [Function],
121
+ "message": [Function],
122
+ "problem": [Function],
123
+ },
124
+ "path": [
125
+ "email",
126
+ ],
127
+ "ref": {
128
+ "name": "email",
129
+ },
130
+ "rule": "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$",
131
+ "type": "pattern",
132
+ Symbol(ArkTypeInternalKind): "error",
133
+ },
134
+ "enabled": ArkError {
135
+ "code": "required",
136
+ "data": {
137
+ "birthYear": "birthYear",
138
+ "email": "",
139
+ "like": [
140
+ {
141
+ "id": "z",
142
+ },
143
+ ],
144
+ "password": "___",
145
+ "url": "abc",
146
+ },
147
+ "input": {
148
+ "code": "required",
149
+ "missingValueDescription": "boolean",
150
+ "relativePath": [
151
+ "enabled",
152
+ ],
153
+ },
154
+ "missingValueDescription": "boolean",
155
+ "nodeConfig": {
156
+ "actual": [Function],
157
+ "description": [Function],
158
+ "expected": [Function],
159
+ "message": [Function],
160
+ "problem": [Function],
161
+ },
162
+ "path": [
163
+ "enabled",
164
+ ],
165
+ "ref": undefined,
166
+ "relativePath": [
167
+ "enabled",
168
+ ],
169
+ "type": "required",
170
+ Symbol(ArkTypeInternalKind): "error",
171
+ },
172
+ "like": [
173
+ {
174
+ "id": ArkError {
175
+ "code": "domain",
176
+ "data": "z",
177
+ "description": "a number",
178
+ "domain": "number",
179
+ "input": {
180
+ "code": "domain",
181
+ "description": "a number",
182
+ "domain": "number",
183
+ },
184
+ "nodeConfig": {
185
+ "actual": [Function],
186
+ "description": [Function],
187
+ "expected": [Function],
188
+ "message": [Function],
189
+ "problem": [Function],
190
+ },
191
+ "path": [
192
+ "like",
193
+ 0,
194
+ "id",
195
+ ],
196
+ "ref": undefined,
197
+ "type": "domain",
198
+ Symbol(ArkTypeInternalKind): "error",
199
+ },
200
+ "name": ArkError {
201
+ "code": "required",
202
+ "data": {
203
+ "id": "z",
204
+ },
205
+ "input": {
206
+ "code": "required",
207
+ "missingValueDescription": "a string",
208
+ "relativePath": [
209
+ "name",
210
+ ],
211
+ },
212
+ "missingValueDescription": "a string",
213
+ "nodeConfig": {
214
+ "actual": [Function],
215
+ "description": [Function],
216
+ "expected": [Function],
217
+ "message": [Function],
218
+ "problem": [Function],
219
+ },
220
+ "path": [
221
+ "like",
222
+ 0,
223
+ "name",
224
+ ],
225
+ "ref": undefined,
226
+ "relativePath": [
227
+ "name",
228
+ ],
229
+ "type": "required",
230
+ Symbol(ArkTypeInternalKind): "error",
231
+ },
232
+ },
233
+ ],
234
+ "password": ArkError {
235
+ "code": "union",
236
+ "data": "___",
237
+ "errors": [
238
+ ArkError {
239
+ "code": "pattern",
240
+ "data": "___",
241
+ "description": "matched by .*[A-Za-z].*",
242
+ "input": {
243
+ "code": "pattern",
244
+ "description": "matched by .*[A-Za-z].*",
245
+ "rule": ".*[A-Za-z].*",
246
+ },
247
+ "nodeConfig": {
248
+ "actual": [Function],
249
+ "description": [Function],
250
+ "expected": [Function],
251
+ "message": [Function],
252
+ "problem": [Function],
253
+ },
254
+ "path": [
255
+ "password",
256
+ ],
257
+ "rule": ".*[A-Za-z].*",
258
+ Symbol(ArkTypeInternalKind): "error",
259
+ },
260
+ ArkError {
261
+ "code": "pattern",
262
+ "data": "___",
263
+ "description": "matched by .*\\d.*",
264
+ "input": {
265
+ "code": "pattern",
266
+ "description": "matched by .*\\d.*",
267
+ "rule": ".*\\d.*",
268
+ },
269
+ "nodeConfig": {
270
+ "actual": [Function],
271
+ "description": [Function],
272
+ "expected": [Function],
273
+ "message": [Function],
274
+ "problem": [Function],
275
+ },
276
+ "path": [
277
+ "password",
278
+ ],
279
+ "rule": ".*\\d.*",
280
+ Symbol(ArkTypeInternalKind): "error",
281
+ },
282
+ ],
283
+ "input": {
284
+ "code": "union",
285
+ "errors": [
286
+ ArkError {
287
+ "code": "pattern",
288
+ "data": "___",
289
+ "description": "matched by .*[A-Za-z].*",
290
+ "input": {
291
+ "code": "pattern",
292
+ "description": "matched by .*[A-Za-z].*",
293
+ "rule": ".*[A-Za-z].*",
294
+ },
295
+ "nodeConfig": {
296
+ "actual": [Function],
297
+ "description": [Function],
298
+ "expected": [Function],
299
+ "message": [Function],
300
+ "problem": [Function],
301
+ },
302
+ "path": [
303
+ "password",
304
+ ],
305
+ "rule": ".*[A-Za-z].*",
306
+ Symbol(ArkTypeInternalKind): "error",
307
+ },
308
+ ArkError {
309
+ "code": "pattern",
310
+ "data": "___",
311
+ "description": "matched by .*\\d.*",
312
+ "input": {
313
+ "code": "pattern",
314
+ "description": "matched by .*\\d.*",
315
+ "rule": ".*\\d.*",
316
+ },
317
+ "nodeConfig": {
318
+ "actual": [Function],
319
+ "description": [Function],
320
+ "expected": [Function],
321
+ "message": [Function],
322
+ "problem": [Function],
323
+ },
324
+ "path": [
325
+ "password",
326
+ ],
327
+ "rule": ".*\\d.*",
328
+ Symbol(ArkTypeInternalKind): "error",
329
+ },
330
+ ],
331
+ },
332
+ "nodeConfig": {
333
+ "actual": [Function],
334
+ "description": [Function],
335
+ "expected": [Function],
336
+ "message": [Function],
337
+ "problem": [Function],
338
+ },
339
+ "path": [
340
+ "password",
341
+ ],
342
+ "ref": {
343
+ "name": "password",
344
+ },
345
+ "type": "union",
346
+ Symbol(ArkTypeInternalKind): "error",
347
+ },
348
+ "repeatPassword": ArkError {
349
+ "code": "required",
350
+ "data": {
351
+ "birthYear": "birthYear",
352
+ "email": "",
353
+ "like": [
354
+ {
355
+ "id": "z",
356
+ },
357
+ ],
358
+ "password": "___",
359
+ "url": "abc",
360
+ },
361
+ "input": {
362
+ "code": "required",
363
+ "missingValueDescription": "a string",
364
+ "relativePath": [
365
+ "repeatPassword",
366
+ ],
367
+ },
368
+ "missingValueDescription": "a string",
369
+ "nodeConfig": {
370
+ "actual": [Function],
371
+ "description": [Function],
372
+ "expected": [Function],
373
+ "message": [Function],
374
+ "problem": [Function],
375
+ },
376
+ "path": [
377
+ "repeatPassword",
378
+ ],
379
+ "ref": undefined,
380
+ "relativePath": [
381
+ "repeatPassword",
382
+ ],
383
+ "type": "required",
384
+ Symbol(ArkTypeInternalKind): "error",
385
+ },
386
+ "tags": ArkError {
387
+ "code": "required",
388
+ "data": {
389
+ "birthYear": "birthYear",
390
+ "email": "",
391
+ "like": [
392
+ {
393
+ "id": "z",
394
+ },
395
+ ],
396
+ "password": "___",
397
+ "url": "abc",
398
+ },
399
+ "input": {
400
+ "code": "required",
401
+ "missingValueDescription": "an array",
402
+ "relativePath": [
403
+ "tags",
404
+ ],
405
+ },
406
+ "missingValueDescription": "an array",
407
+ "nodeConfig": {
408
+ "actual": [Function],
409
+ "description": [Function],
410
+ "expected": [Function],
411
+ "message": [Function],
412
+ "problem": [Function],
413
+ },
414
+ "path": [
415
+ "tags",
416
+ ],
417
+ "ref": undefined,
418
+ "relativePath": [
419
+ "tags",
420
+ ],
421
+ "type": "required",
422
+ Symbol(ArkTypeInternalKind): "error",
423
+ },
424
+ "username": ArkError {
425
+ "code": "required",
426
+ "data": {
427
+ "birthYear": "birthYear",
428
+ "email": "",
429
+ "like": [
430
+ {
431
+ "id": "z",
432
+ },
433
+ ],
434
+ "password": "___",
435
+ "url": "abc",
436
+ },
437
+ "input": {
438
+ "code": "required",
439
+ "missingValueDescription": "a string",
440
+ "relativePath": [
441
+ "username",
442
+ ],
443
+ },
444
+ "missingValueDescription": "a string",
445
+ "nodeConfig": {
446
+ "actual": [Function],
447
+ "description": [Function],
448
+ "expected": [Function],
449
+ "message": [Function],
450
+ "problem": [Function],
451
+ },
452
+ "path": [
453
+ "username",
454
+ ],
455
+ "ref": {
456
+ "name": "username",
457
+ },
458
+ "relativePath": [
459
+ "username",
460
+ ],
461
+ "type": "required",
462
+ Symbol(ArkTypeInternalKind): "error",
463
+ },
464
+ },
465
+ "values": {},
466
+ }
467
+ `;
node_modules/@hookform/resolvers/arktype/src/__tests__/arktype.ts ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { arktypeResolver } from '..';
2
+ import { fields, invalidData, schema, validData } from './__fixtures__/data';
3
+
4
+ const shouldUseNativeValidation = false;
5
+
6
+ describe('arktypeResolver', () => {
7
+ it('should return values from arktypeResolver when validation pass & raw=true', async () => {
8
+ const result = await arktypeResolver(schema, undefined, {
9
+ raw: true,
10
+ })(validData, undefined, {
11
+ fields,
12
+ shouldUseNativeValidation,
13
+ });
14
+
15
+ expect(result).toEqual({ errors: {}, values: validData });
16
+ });
17
+
18
+ it('should return a single error from arktypeResolver when validation fails', async () => {
19
+ const result = await arktypeResolver(schema)(invalidData, undefined, {
20
+ fields,
21
+ shouldUseNativeValidation,
22
+ });
23
+
24
+ expect(result).toMatchSnapshot();
25
+ });
26
+ });
node_modules/@hookform/resolvers/arktype/src/arktype.ts ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
2
+ import { ArkErrors } from 'arktype';
3
+ import { FieldError, FieldErrors } from 'react-hook-form';
4
+ import type { Resolver } from './types';
5
+
6
+ const parseErrorSchema = (e: ArkErrors): Record<string, FieldError> => {
7
+ // copy code to type to match FieldError shape
8
+ e.forEach((e) => Object.assign(e, { type: e.code }));
9
+ // need to cast here because TS doesn't understand we added the type field
10
+ return e.byPath as never;
11
+ };
12
+
13
+ export const arktypeResolver: Resolver =
14
+ (schema, _schemaOptions, resolverOptions = {}) =>
15
+ (values, _, options) => {
16
+ const out = schema(values);
17
+
18
+ if (out instanceof ArkErrors) {
19
+ return {
20
+ values: {},
21
+ errors: toNestErrors(parseErrorSchema(out), options),
22
+ };
23
+ }
24
+
25
+ options.shouldUseNativeValidation && validateFieldsNatively({}, options);
26
+
27
+ return {
28
+ errors: {} as FieldErrors,
29
+ values: resolverOptions.raw ? values : out,
30
+ };
31
+ };
node_modules/@hookform/resolvers/arktype/src/index.ts ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ export * from './arktype';
2
+ export * from './types';
node_modules/@hookform/resolvers/arktype/src/types.ts ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Type } from 'arktype';
2
+ import { FieldValues, ResolverOptions, ResolverResult } from 'react-hook-form';
3
+
4
+ export type Resolver = <T extends Type<any>>(
5
+ schema: T,
6
+ schemaOptions?: undefined,
7
+ factoryOptions?: {
8
+ /**
9
+ * Return the raw input values rather than the parsed values.
10
+ * @default false
11
+ */
12
+ raw?: boolean;
13
+ },
14
+ ) => <TFieldValues extends FieldValues, TContext>(
15
+ values: TFieldValues,
16
+ context: TContext | undefined,
17
+ options: ResolverOptions<TFieldValues>,
18
+ ) => ResolverResult<TFieldValues>;