nuxt-precognition 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
package/dist/runtime/useForm.js
CHANGED
|
@@ -4,6 +4,7 @@ import type { ValidationErrorParser } from './types/core.js';
|
|
|
4
4
|
import type { ClientStatusHandlers, Form, UseFormOptions } from './types/form.js';
|
|
5
5
|
export declare function makeValidator<TData extends object, TResp>(cb: (data: TData, precognitiveHeaders: Headers) => Promise<TResp>, options?: UseFormOptions<TData, TResp>): {
|
|
6
6
|
validate: DebouncedFuncLeading<(form: Form<TData, TResp>, ...keys: NestedKeyOf<TData>[]) => Promise<void>>;
|
|
7
|
+
reset: () => void;
|
|
7
8
|
errorParsers: ValidationErrorParser<TResp>[];
|
|
8
9
|
responseParsers: ((resp: TResp) => unknown)[];
|
|
9
10
|
setValidateFiles: (value: boolean) => void;
|
|
@@ -16,8 +16,11 @@ export function makeValidator(cb, options) {
|
|
|
16
16
|
errorParsers.push(makeNuxtValidationErrorParser());
|
|
17
17
|
const responseParsers = errorParsers.filter((p) => typeof p === "object").map((p) => p.responseParser);
|
|
18
18
|
const statusHandlers = { ...$precognition.statusHandlers, ...options?.statusHandlers };
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const pendingKeys = /* @__PURE__ */ new Set();
|
|
20
|
+
const debouncedValidate = debounce(
|
|
21
|
+
async function(form) {
|
|
22
|
+
const keys = Array.from(pendingKeys);
|
|
23
|
+
pendingKeys.clear();
|
|
21
24
|
const headers = requestPrecognitiveHeaders(validateOptions.validationHeaders, keys);
|
|
22
25
|
const data = form.data();
|
|
23
26
|
try {
|
|
@@ -61,11 +64,28 @@ export function makeValidator(cb, options) {
|
|
|
61
64
|
validateOptions.validationTimeout,
|
|
62
65
|
{ leading: true, trailing: true }
|
|
63
66
|
);
|
|
67
|
+
const validate = Object.assign(
|
|
68
|
+
(form, ...keys) => {
|
|
69
|
+
keys.forEach((k) => pendingKeys.add(k));
|
|
70
|
+
return debouncedValidate(form);
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
cancel: () => {
|
|
74
|
+
pendingKeys.clear();
|
|
75
|
+
debouncedValidate.cancel();
|
|
76
|
+
},
|
|
77
|
+
flush: () => debouncedValidate.flush()
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
function reset() {
|
|
81
|
+
validate.cancel();
|
|
82
|
+
}
|
|
64
83
|
function setValidateFiles(value) {
|
|
65
84
|
validateOptions.validateFiles = value;
|
|
66
85
|
}
|
|
67
86
|
return {
|
|
68
87
|
validate,
|
|
88
|
+
reset,
|
|
69
89
|
errorParsers,
|
|
70
90
|
responseParsers,
|
|
71
91
|
statusHandlers,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-precognition",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"description": "Nuxt module implementing Precognition protocol (inspired by official Laravel Precognition) for backend precognitive validation.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "sot1986",
|