@duplojs/utils 1.6.1 → 1.6.3
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/array/types/createTuple.d.ts +1 -1
- package/dist/clean/constraint/base.cjs +7 -0
- package/dist/clean/constraint/base.d.ts +26 -6
- package/dist/clean/constraint/base.mjs +7 -0
- package/dist/clean/constraint/cast.cjs +18 -0
- package/dist/clean/constraint/cast.d.ts +29 -0
- package/dist/clean/constraint/cast.mjs +16 -0
- package/dist/clean/constraint/defaultConstraint/number.cjs +2 -10
- package/dist/clean/constraint/defaultConstraint/number.d.ts +12 -37
- package/dist/clean/constraint/defaultConstraint/number.mjs +3 -10
- package/dist/clean/constraint/defaultConstraint/string.d.ts +9 -5
- package/dist/clean/constraint/index.d.ts +1 -0
- package/dist/clean/constraint/set.cjs +7 -1
- package/dist/clean/constraint/set.d.ts +25 -5
- package/dist/clean/constraint/set.mjs +7 -1
- package/dist/clean/entity/index.cjs +14 -4
- package/dist/clean/entity/index.d.ts +11 -1
- package/dist/clean/entity/index.mjs +15 -6
- package/dist/clean/index.cjs +5 -1
- package/dist/clean/index.d.ts +1 -0
- package/dist/clean/index.mjs +4 -2
- package/dist/clean/newType.cjs +6 -1
- package/dist/clean/newType.d.ts +20 -5
- package/dist/clean/newType.mjs +6 -1
- package/dist/clean/primitive/operations/equal.cjs +3 -0
- package/dist/clean/primitive/operations/equal.d.ts +2 -2
- package/dist/clean/primitive/operations/equal.mjs +3 -0
- package/dist/clean/toMapDataParser.cjs +52 -0
- package/dist/clean/toMapDataParser.d.ts +53 -0
- package/dist/clean/toMapDataParser.mjs +50 -0
- package/dist/common/asserts.cjs +12 -0
- package/dist/common/asserts.d.ts +26 -0
- package/dist/common/asserts.mjs +12 -1
- package/dist/common/callThen.cjs +14 -0
- package/dist/common/callThen.d.ts +35 -0
- package/dist/common/callThen.mjs +12 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/printer.cjs +73 -0
- package/dist/common/printer.d.ts +139 -0
- package/dist/common/printer.mjs +73 -0
- package/dist/common/queue.cjs +90 -0
- package/dist/common/queue.d.ts +46 -0
- package/dist/common/queue.mjs +87 -0
- package/dist/common/types/and.d.ts +1 -2
- package/dist/common/types/or.d.ts +1 -2
- package/dist/dataParser/base.cjs +12 -35
- package/dist/dataParser/base.d.ts +6 -9
- package/dist/dataParser/base.mjs +8 -30
- package/dist/dataParser/error.cjs +39 -21
- package/dist/dataParser/error.d.ts +19 -19
- package/dist/dataParser/error.mjs +37 -18
- package/dist/dataParser/extended/index.cjs +3 -4
- package/dist/dataParser/extended/index.mjs +1 -1
- package/dist/dataParser/identifier.d.ts +6 -6
- package/dist/dataParser/index.cjs +3 -6
- package/dist/dataParser/index.mjs +2 -2
- package/dist/dataParser/parsers/array/checkers/max.cjs +3 -6
- package/dist/dataParser/parsers/array/checkers/max.mjs +4 -7
- package/dist/dataParser/parsers/array/checkers/min.cjs +3 -6
- package/dist/dataParser/parsers/array/checkers/min.mjs +4 -7
- package/dist/dataParser/parsers/array/index.cjs +8 -8
- package/dist/dataParser/parsers/array/index.mjs +4 -4
- package/dist/dataParser/parsers/bigint/checkers/max.cjs +2 -2
- package/dist/dataParser/parsers/bigint/checkers/max.mjs +3 -3
- package/dist/dataParser/parsers/bigint/checkers/min.cjs +2 -2
- package/dist/dataParser/parsers/bigint/checkers/min.mjs +3 -3
- package/dist/dataParser/parsers/bigint/index.cjs +2 -2
- package/dist/dataParser/parsers/bigint/index.mjs +3 -3
- package/dist/dataParser/parsers/boolean.cjs +3 -3
- package/dist/dataParser/parsers/boolean.mjs +4 -4
- package/dist/dataParser/parsers/date.cjs +4 -4
- package/dist/dataParser/parsers/date.mjs +5 -5
- package/dist/dataParser/parsers/empty.cjs +2 -2
- package/dist/dataParser/parsers/empty.mjs +3 -3
- package/dist/dataParser/parsers/literal.cjs +2 -2
- package/dist/dataParser/parsers/literal.mjs +3 -3
- package/dist/dataParser/parsers/nil.cjs +2 -2
- package/dist/dataParser/parsers/nil.mjs +3 -3
- package/dist/dataParser/parsers/number/checkers/int.cjs +2 -2
- package/dist/dataParser/parsers/number/checkers/int.mjs +3 -3
- package/dist/dataParser/parsers/number/checkers/max.cjs +3 -1
- package/dist/dataParser/parsers/number/checkers/max.mjs +4 -2
- package/dist/dataParser/parsers/number/checkers/min.cjs +3 -1
- package/dist/dataParser/parsers/number/checkers/min.mjs +4 -2
- package/dist/dataParser/parsers/number/index.cjs +2 -2
- package/dist/dataParser/parsers/number/index.mjs +3 -3
- package/dist/dataParser/parsers/object/index.cjs +8 -8
- package/dist/dataParser/parsers/object/index.mjs +4 -4
- package/dist/dataParser/parsers/pipe.cjs +25 -10
- package/dist/dataParser/parsers/pipe.mjs +22 -7
- package/dist/dataParser/parsers/record/index.cjs +18 -16
- package/dist/dataParser/parsers/record/index.mjs +8 -6
- package/dist/dataParser/parsers/recover.cjs +7 -6
- package/dist/dataParser/parsers/recover.mjs +2 -1
- package/dist/dataParser/parsers/refine.cjs +3 -1
- package/dist/dataParser/parsers/refine.mjs +4 -2
- package/dist/dataParser/parsers/string/checkers/email.cjs +2 -2
- package/dist/dataParser/parsers/string/checkers/email.mjs +3 -3
- package/dist/dataParser/parsers/string/checkers/max.cjs +3 -1
- package/dist/dataParser/parsers/string/checkers/max.mjs +4 -2
- package/dist/dataParser/parsers/string/checkers/min.cjs +3 -1
- package/dist/dataParser/parsers/string/checkers/min.mjs +4 -2
- package/dist/dataParser/parsers/string/checkers/regex.cjs +2 -2
- package/dist/dataParser/parsers/string/checkers/regex.mjs +3 -3
- package/dist/dataParser/parsers/string/checkers/url.cjs +4 -4
- package/dist/dataParser/parsers/string/checkers/url.mjs +5 -5
- package/dist/dataParser/parsers/string/index.cjs +2 -2
- package/dist/dataParser/parsers/string/index.mjs +3 -3
- package/dist/dataParser/parsers/templateLiteral/index.cjs +2 -2
- package/dist/dataParser/parsers/templateLiteral/index.mjs +3 -3
- package/dist/dataParser/parsers/time/checkers/max.cjs +3 -1
- package/dist/dataParser/parsers/time/checkers/max.mjs +4 -2
- package/dist/dataParser/parsers/time/checkers/min.cjs +3 -1
- package/dist/dataParser/parsers/time/checkers/min.mjs +4 -2
- package/dist/dataParser/parsers/time/index.cjs +4 -4
- package/dist/dataParser/parsers/time/index.mjs +5 -5
- package/dist/dataParser/parsers/transform.cjs +6 -6
- package/dist/dataParser/parsers/transform.d.ts +2 -2
- package/dist/dataParser/parsers/transform.mjs +4 -4
- package/dist/dataParser/parsers/tuple.cjs +14 -14
- package/dist/dataParser/parsers/tuple.mjs +4 -4
- package/dist/dataParser/parsers/union.cjs +26 -8
- package/dist/dataParser/parsers/union.mjs +26 -8
- package/dist/flow/calledByNext.cjs +13 -0
- package/dist/flow/calledByNext.d.ts +47 -0
- package/dist/flow/calledByNext.mjs +11 -0
- package/dist/flow/debounce.cjs +16 -0
- package/dist/flow/debounce.d.ts +63 -0
- package/dist/flow/debounce.mjs +14 -0
- package/dist/flow/exec.cjs +101 -0
- package/dist/flow/exec.d.ts +4 -3
- package/dist/flow/exec.mjs +101 -0
- package/dist/flow/index.cjs +28 -0
- package/dist/flow/index.d.ts +5 -0
- package/dist/flow/index.mjs +10 -1
- package/dist/flow/queue.cjs +19 -0
- package/dist/flow/queue.d.ts +47 -0
- package/dist/flow/queue.mjs +17 -0
- package/dist/flow/run.cjs +118 -0
- package/dist/flow/run.d.ts +6 -4
- package/dist/flow/run.mjs +113 -1
- package/dist/flow/theFlow/calledByNext.cjs +11 -0
- package/dist/flow/theFlow/calledByNext.d.ts +5 -0
- package/dist/flow/theFlow/calledByNext.mjs +8 -0
- package/dist/flow/theFlow/debounce.cjs +11 -0
- package/dist/flow/theFlow/debounce.d.ts +9 -0
- package/dist/flow/theFlow/debounce.mjs +8 -0
- package/dist/flow/theFlow/index.d.ts +11 -3
- package/dist/flow/theFlow/queue.cjs +11 -0
- package/dist/flow/theFlow/queue.d.ts +9 -0
- package/dist/flow/theFlow/queue.mjs +8 -0
- package/dist/flow/theFlow/throttling.cjs +11 -0
- package/dist/flow/theFlow/throttling.d.ts +10 -0
- package/dist/flow/theFlow/throttling.mjs +8 -0
- package/dist/flow/throttling.cjs +27 -0
- package/dist/flow/throttling.d.ts +60 -0
- package/dist/flow/throttling.mjs +25 -0
- package/dist/flow/toFunction.cjs +15 -0
- package/dist/flow/toFunction.d.ts +56 -0
- package/dist/flow/toFunction.mjs +13 -0
- package/dist/index.cjs +11 -0
- package/dist/index.mjs +4 -1
- package/dist/metadata.json +126 -0
- package/dist/number/types/isGreater.d.ts +26 -3
- package/dist/object/types/getPropsWithValue.d.ts +1 -1
- package/dist/object/types/getPropsWithValueExtends.d.ts +1 -1
- package/dist/string/length.d.ts +2 -2
- package/dist/string/types/split.d.ts +6 -5
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dataParserCheckerInit } from '../../../base.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { addIssue } from '../../../error.mjs';
|
|
3
3
|
import { string } from '../index.mjs';
|
|
4
4
|
import { createDataParserKind } from '../../../kind.mjs';
|
|
5
5
|
|
|
@@ -11,9 +11,9 @@ function checkerEmail(definition = {}) {
|
|
|
11
11
|
...definition,
|
|
12
12
|
pattern: emailPattern,
|
|
13
13
|
},
|
|
14
|
-
}, (input, self) => {
|
|
14
|
+
}, (input, error, self) => {
|
|
15
15
|
if (!self.definition.pattern.test(input)) {
|
|
16
|
-
return
|
|
16
|
+
return addIssue(error, "email", input, self.definition.errorMessage);
|
|
17
17
|
}
|
|
18
18
|
return self.definition.normalize ? input.toLowerCase() : input;
|
|
19
19
|
});
|
|
@@ -11,7 +11,9 @@ function checkerStringMax(max, definition = {}) {
|
|
|
11
11
|
...definition,
|
|
12
12
|
max,
|
|
13
13
|
},
|
|
14
|
-
}, (value, self) => value.length <= self.definition.max
|
|
14
|
+
}, (value, error$1, self) => value.length <= self.definition.max
|
|
15
|
+
? value
|
|
16
|
+
: error.addIssue(error$1, `string.length <= ${self.definition.max}`, value, self.definition.errorMessage));
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
exports.checkerStringMax = checkerStringMax;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dataParserCheckerInit } from '../../../base.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { addIssue } from '../../../error.mjs';
|
|
3
3
|
import { createDataParserKind } from '../../../kind.mjs';
|
|
4
4
|
|
|
5
5
|
const checkerStringMaxKind = createDataParserKind("checker-string-max");
|
|
@@ -9,7 +9,9 @@ function checkerStringMax(max, definition = {}) {
|
|
|
9
9
|
...definition,
|
|
10
10
|
max,
|
|
11
11
|
},
|
|
12
|
-
}, (value, self) => value.length <= self.definition.max
|
|
12
|
+
}, (value, error, self) => value.length <= self.definition.max
|
|
13
|
+
? value
|
|
14
|
+
: addIssue(error, `string.length <= ${self.definition.max}`, value, self.definition.errorMessage));
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export { checkerStringMax, checkerStringMaxKind };
|
|
@@ -11,7 +11,9 @@ function checkerStringMin(min, definition = {}) {
|
|
|
11
11
|
...definition,
|
|
12
12
|
min,
|
|
13
13
|
},
|
|
14
|
-
}, (value, self) => value.length >= self.definition.min
|
|
14
|
+
}, (value, error$1, self) => value.length >= self.definition.min
|
|
15
|
+
? value
|
|
16
|
+
: error.addIssue(error$1, `string.length >= ${self.definition.min}`, value, self.definition.errorMessage));
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
exports.checkerStringMin = checkerStringMin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dataParserCheckerInit } from '../../../base.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { addIssue } from '../../../error.mjs';
|
|
3
3
|
import { createDataParserKind } from '../../../kind.mjs';
|
|
4
4
|
|
|
5
5
|
const checkerStringMinKind = createDataParserKind("checker-string-min");
|
|
@@ -9,7 +9,9 @@ function checkerStringMin(min, definition = {}) {
|
|
|
9
9
|
...definition,
|
|
10
10
|
min,
|
|
11
11
|
},
|
|
12
|
-
}, (value, self) => value.length >= self.definition.min
|
|
12
|
+
}, (value, error, self) => value.length >= self.definition.min
|
|
13
|
+
? value
|
|
14
|
+
: addIssue(error, `string.length >= ${self.definition.min}`, value, self.definition.errorMessage));
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export { checkerStringMin, checkerStringMinKind };
|
|
@@ -11,9 +11,9 @@ function checkerStringRegex(regex, definition = {}) {
|
|
|
11
11
|
...definition,
|
|
12
12
|
regex,
|
|
13
13
|
},
|
|
14
|
-
}, (value, self) => self.definition.regex.test(value)
|
|
14
|
+
}, (value, error$1, self) => self.definition.regex.test(value)
|
|
15
15
|
? value
|
|
16
|
-
: error.
|
|
16
|
+
: error.addIssue(error$1, `string with pattern ${self.definition.regex.source.toString()}`, value, self.definition.errorMessage));
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
exports.checkerStringRegex = checkerStringRegex;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dataParserCheckerInit } from '../../../base.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { addIssue } from '../../../error.mjs';
|
|
3
3
|
import { createDataParserKind } from '../../../kind.mjs';
|
|
4
4
|
|
|
5
5
|
const checkerStringRegexKind = createDataParserKind("checker-string-regex");
|
|
@@ -9,9 +9,9 @@ function checkerStringRegex(regex, definition = {}) {
|
|
|
9
9
|
...definition,
|
|
10
10
|
regex,
|
|
11
11
|
},
|
|
12
|
-
}, (value, self) => self.definition.regex.test(value)
|
|
12
|
+
}, (value, error, self) => self.definition.regex.test(value)
|
|
13
13
|
? value
|
|
14
|
-
:
|
|
14
|
+
: addIssue(error, `string with pattern ${self.definition.regex.source.toString()}`, value, self.definition.errorMessage));
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export { checkerStringRegex, checkerStringRegexKind };
|
|
@@ -10,19 +10,19 @@ const regexRemoveDote = /:$/;
|
|
|
10
10
|
function checkerUrl(definition = {}) {
|
|
11
11
|
return base.dataParserCheckerInit(checkerUrlKind, {
|
|
12
12
|
definition: definition,
|
|
13
|
-
}, (input, self) => {
|
|
13
|
+
}, (input, error$1, self) => {
|
|
14
14
|
try {
|
|
15
15
|
const url = new URL(input);
|
|
16
16
|
if (self.definition.hostname) {
|
|
17
17
|
self.definition.hostname.lastIndex = 0;
|
|
18
18
|
if (!self.definition.hostname.test(url.hostname)) {
|
|
19
|
-
return error.
|
|
19
|
+
return error.addIssue(error$1, `URL with hostname matching ${self.definition.hostname.source}`, input, self.definition.errorMessage);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
if (self.definition.protocol) {
|
|
23
23
|
self.definition.protocol.lastIndex = 0;
|
|
24
24
|
if (!self.definition.protocol.test(url.protocol.replace(regexRemoveDote, ""))) {
|
|
25
|
-
return error.
|
|
25
|
+
return error.addIssue(error$1, `URL with protocol matching ${self.definition.protocol.source}`, input, self.definition.errorMessage);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
if (self.definition.normalize) {
|
|
@@ -33,7 +33,7 @@ function checkerUrl(definition = {}) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
catch {
|
|
36
|
-
return error.
|
|
36
|
+
return error.addIssue(error$1, "valid URL", input, self.definition.errorMessage);
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dataParserCheckerInit } from '../../../base.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { addIssue } from '../../../error.mjs';
|
|
3
3
|
import { string } from '../index.mjs';
|
|
4
4
|
import { createDataParserKind } from '../../../kind.mjs';
|
|
5
5
|
|
|
@@ -8,19 +8,19 @@ const regexRemoveDote = /:$/;
|
|
|
8
8
|
function checkerUrl(definition = {}) {
|
|
9
9
|
return dataParserCheckerInit(checkerUrlKind, {
|
|
10
10
|
definition: definition,
|
|
11
|
-
}, (input, self) => {
|
|
11
|
+
}, (input, error, self) => {
|
|
12
12
|
try {
|
|
13
13
|
const url = new URL(input);
|
|
14
14
|
if (self.definition.hostname) {
|
|
15
15
|
self.definition.hostname.lastIndex = 0;
|
|
16
16
|
if (!self.definition.hostname.test(url.hostname)) {
|
|
17
|
-
return
|
|
17
|
+
return addIssue(error, `URL with hostname matching ${self.definition.hostname.source}`, input, self.definition.errorMessage);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
if (self.definition.protocol) {
|
|
21
21
|
self.definition.protocol.lastIndex = 0;
|
|
22
22
|
if (!self.definition.protocol.test(url.protocol.replace(regexRemoveDote, ""))) {
|
|
23
|
-
return
|
|
23
|
+
return addIssue(error, `URL with protocol matching ${self.definition.protocol.source}`, input, self.definition.errorMessage);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
if (self.definition.normalize) {
|
|
@@ -31,7 +31,7 @@ function checkerUrl(definition = {}) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
catch {
|
|
34
|
-
return
|
|
34
|
+
return addIssue(error, "valid URL", input, self.definition.errorMessage);
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -14,7 +14,7 @@ function string(definition) {
|
|
|
14
14
|
errorMessage: definition?.errorMessage,
|
|
15
15
|
checkers: definition?.checkers ?? [],
|
|
16
16
|
coerce: definition?.coerce ?? false,
|
|
17
|
-
}, (data,
|
|
17
|
+
}, (data, error$1, self) => {
|
|
18
18
|
if (self.definition.coerce) {
|
|
19
19
|
try {
|
|
20
20
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -25,7 +25,7 @@ function string(definition) {
|
|
|
25
25
|
if (typeof data === "string") {
|
|
26
26
|
return data;
|
|
27
27
|
}
|
|
28
|
-
return error.
|
|
28
|
+
return error.addIssue(error$1, "string", data, self.definition.errorMessage);
|
|
29
29
|
}, string.overrideHandler);
|
|
30
30
|
return self;
|
|
31
31
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dataParserInit } from '../../base.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { addIssue } from '../../error.mjs';
|
|
3
3
|
import { createDataParserKind } from '../../kind.mjs';
|
|
4
4
|
import { createOverride } from '../../../common/override.mjs';
|
|
5
5
|
|
|
@@ -12,7 +12,7 @@ function string(definition) {
|
|
|
12
12
|
errorMessage: definition?.errorMessage,
|
|
13
13
|
checkers: definition?.checkers ?? [],
|
|
14
14
|
coerce: definition?.coerce ?? false,
|
|
15
|
-
}, (data,
|
|
15
|
+
}, (data, error, self) => {
|
|
16
16
|
if (self.definition.coerce) {
|
|
17
17
|
try {
|
|
18
18
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -23,7 +23,7 @@ function string(definition) {
|
|
|
23
23
|
if (typeof data === "string") {
|
|
24
24
|
return data;
|
|
25
25
|
}
|
|
26
|
-
return
|
|
26
|
+
return addIssue(error, "string", data, self.definition.errorMessage);
|
|
27
27
|
}, string.overrideHandler);
|
|
28
28
|
return self;
|
|
29
29
|
}
|
|
@@ -18,11 +18,11 @@ function templateLiteral(template, definition) {
|
|
|
18
18
|
checkers: definition?.checkers ?? [],
|
|
19
19
|
template,
|
|
20
20
|
pattern,
|
|
21
|
-
}, (data,
|
|
21
|
+
}, (data, error$1, self) => {
|
|
22
22
|
if (typeof data === "string" && self.definition.pattern.test(data)) {
|
|
23
23
|
return data;
|
|
24
24
|
}
|
|
25
|
-
return error.
|
|
25
|
+
return error.addIssue(error$1, `string matching template literal pattern ${self.definition.pattern.source}`, data, self.definition.errorMessage);
|
|
26
26
|
}, templateLiteral.overrideHandler);
|
|
27
27
|
return self;
|
|
28
28
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dataParserInit } from '../../base.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { addIssue } from '../../error.mjs';
|
|
3
3
|
import { createDataParserKind } from '../../kind.mjs';
|
|
4
4
|
import { createTemplateLiteralPattern } from './createTemplateLiteralPattern.mjs';
|
|
5
5
|
import { pipe } from '../../../common/pipe.mjs';
|
|
@@ -16,11 +16,11 @@ function templateLiteral(template, definition) {
|
|
|
16
16
|
checkers: definition?.checkers ?? [],
|
|
17
17
|
template,
|
|
18
18
|
pattern,
|
|
19
|
-
}, (data,
|
|
19
|
+
}, (data, error, self) => {
|
|
20
20
|
if (typeof data === "string" && self.definition.pattern.test(data)) {
|
|
21
21
|
return data;
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return addIssue(error, `string matching template literal pattern ${self.definition.pattern.source}`, data, self.definition.errorMessage);
|
|
24
24
|
}, templateLiteral.overrideHandler);
|
|
25
25
|
return self;
|
|
26
26
|
}
|
|
@@ -15,7 +15,9 @@ function checkerTimeMax(max, definition = {}) {
|
|
|
15
15
|
...definition,
|
|
16
16
|
max,
|
|
17
17
|
},
|
|
18
|
-
}, (value, self) => lessTime.lessTime(value, self.definition.max)
|
|
18
|
+
}, (value, error$1, self) => lessTime.lessTime(value, self.definition.max)
|
|
19
|
+
? value
|
|
20
|
+
: error.addIssue(error$1, `time <= ${self.definition.max.toString()}`, value, self.definition.errorMessage));
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
exports.checkerTimeMax = checkerTimeMax;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dataParserCheckerInit } from '../../../base.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { addIssue } from '../../../error.mjs';
|
|
3
3
|
import { createDataParserKind } from '../../../kind.mjs';
|
|
4
4
|
import { lessTime } from '../../../../date/operators/lessTime.mjs';
|
|
5
5
|
|
|
@@ -13,7 +13,9 @@ function checkerTimeMax(max, definition = {}) {
|
|
|
13
13
|
...definition,
|
|
14
14
|
max,
|
|
15
15
|
},
|
|
16
|
-
}, (value, self) => lessTime(value, self.definition.max)
|
|
16
|
+
}, (value, error, self) => lessTime(value, self.definition.max)
|
|
17
|
+
? value
|
|
18
|
+
: addIssue(error, `time <= ${self.definition.max.toString()}`, value, self.definition.errorMessage));
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export { checkerTimeMax, checkerTimeMaxKind };
|
|
@@ -15,7 +15,9 @@ function checkerTimeMin(min, definition = {}) {
|
|
|
15
15
|
...definition,
|
|
16
16
|
min,
|
|
17
17
|
},
|
|
18
|
-
}, (value, self) => greaterTime.greaterTime(value, self.definition.min)
|
|
18
|
+
}, (value, error$1, self) => greaterTime.greaterTime(value, self.definition.min)
|
|
19
|
+
? value
|
|
20
|
+
: error.addIssue(error$1, `time >= ${self.definition.min.toString()}`, value, self.definition.errorMessage));
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
exports.checkerTimeMin = checkerTimeMin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dataParserCheckerInit } from '../../../base.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { addIssue } from '../../../error.mjs';
|
|
3
3
|
import { createDataParserKind } from '../../../kind.mjs';
|
|
4
4
|
import { greaterTime } from '../../../../date/operators/greaterTime.mjs';
|
|
5
5
|
|
|
@@ -13,7 +13,9 @@ function checkerTimeMin(min, definition = {}) {
|
|
|
13
13
|
...definition,
|
|
14
14
|
min,
|
|
15
15
|
},
|
|
16
|
-
}, (value, self) => greaterTime(value, self.definition.min)
|
|
16
|
+
}, (value, error, self) => greaterTime(value, self.definition.min)
|
|
17
|
+
? value
|
|
18
|
+
: addIssue(error, `time >= ${self.definition.min.toString()}`, value, self.definition.errorMessage));
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export { checkerTimeMin, checkerTimeMinKind };
|
|
@@ -22,12 +22,12 @@ function time(definition) {
|
|
|
22
22
|
errorMessage: definition?.errorMessage,
|
|
23
23
|
checkers: definition?.checkers ?? [],
|
|
24
24
|
coerce: definition?.coerce ?? false,
|
|
25
|
-
}, (data,
|
|
25
|
+
}, (data, error$1, self) => {
|
|
26
26
|
if (self.definition.coerce) {
|
|
27
27
|
if (typeof data === "string" && constants.isoTimeRegex.test(data)) {
|
|
28
28
|
const result = createTime.createTime({ value: data });
|
|
29
29
|
if (is.isLeft(result)) {
|
|
30
|
-
return error.
|
|
30
|
+
return error.addIssue(error$1, "time", data, self.definition.errorMessage);
|
|
31
31
|
}
|
|
32
32
|
return unwrap.unwrap(result);
|
|
33
33
|
}
|
|
@@ -40,11 +40,11 @@ function time(definition) {
|
|
|
40
40
|
}
|
|
41
41
|
else if (typeof data === "number") {
|
|
42
42
|
if (!isSafeTimeValue.isSafeTimeValue(data)) {
|
|
43
|
-
return error.
|
|
43
|
+
return error.addIssue(error$1, "time", data, self.definition.errorMessage);
|
|
44
44
|
}
|
|
45
45
|
return theTime.TheTime.new(data);
|
|
46
46
|
}
|
|
47
|
-
return error.
|
|
47
|
+
return error.addIssue(error$1, "time", data, self.definition.errorMessage);
|
|
48
48
|
}, time.overrideHandler);
|
|
49
49
|
return self;
|
|
50
50
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dataParserInit } from '../../base.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { addIssue } from '../../error.mjs';
|
|
3
3
|
import { createDataParserKind } from '../../kind.mjs';
|
|
4
4
|
import { isoTimeRegex } from '../../../date/constants.mjs';
|
|
5
5
|
import { createTime } from '../../../date/createTime.mjs';
|
|
@@ -20,12 +20,12 @@ function time(definition) {
|
|
|
20
20
|
errorMessage: definition?.errorMessage,
|
|
21
21
|
checkers: definition?.checkers ?? [],
|
|
22
22
|
coerce: definition?.coerce ?? false,
|
|
23
|
-
}, (data,
|
|
23
|
+
}, (data, error, self) => {
|
|
24
24
|
if (self.definition.coerce) {
|
|
25
25
|
if (typeof data === "string" && isoTimeRegex.test(data)) {
|
|
26
26
|
const result = createTime({ value: data });
|
|
27
27
|
if (isLeft(result)) {
|
|
28
|
-
return
|
|
28
|
+
return addIssue(error, "time", data, self.definition.errorMessage);
|
|
29
29
|
}
|
|
30
30
|
return unwrap(result);
|
|
31
31
|
}
|
|
@@ -38,11 +38,11 @@ function time(definition) {
|
|
|
38
38
|
}
|
|
39
39
|
else if (typeof data === "number") {
|
|
40
40
|
if (!isSafeTimeValue(data)) {
|
|
41
|
-
return
|
|
41
|
+
return addIssue(error, "time", data, self.definition.errorMessage);
|
|
42
42
|
}
|
|
43
43
|
return TheTime.new(data);
|
|
44
44
|
}
|
|
45
|
-
return
|
|
45
|
+
return addIssue(error, "time", data, self.definition.errorMessage);
|
|
46
46
|
}, time.overrideHandler);
|
|
47
47
|
return self;
|
|
48
48
|
}
|
|
@@ -18,23 +18,23 @@ function transform(inner, theFunction, definition) {
|
|
|
18
18
|
}, {
|
|
19
19
|
sync: (data, error$1, self) => {
|
|
20
20
|
const innerResult = self.definition.inner.exec(data, error$1);
|
|
21
|
-
if (innerResult ===
|
|
22
|
-
return
|
|
21
|
+
if (innerResult === error.SymbolDataParserError) {
|
|
22
|
+
return error.SymbolDataParserError;
|
|
23
23
|
}
|
|
24
24
|
const result = self.definition.theFunction(innerResult, error$1);
|
|
25
25
|
if (result instanceof Promise) {
|
|
26
|
-
return error.
|
|
26
|
+
return error.addIssue(error$1, "non-promise transform result", result, self.definition.errorMessage);
|
|
27
27
|
}
|
|
28
28
|
return result;
|
|
29
29
|
},
|
|
30
30
|
async: async (data, error$1, self) => {
|
|
31
31
|
const innerResult = await self.definition.inner.asyncExec(data, error$1);
|
|
32
|
-
if (innerResult ===
|
|
33
|
-
return
|
|
32
|
+
if (innerResult === error.SymbolDataParserError) {
|
|
33
|
+
return error.SymbolDataParserError;
|
|
34
34
|
}
|
|
35
35
|
let result = self.definition.theFunction(innerResult, error$1);
|
|
36
36
|
if (result instanceof Promise) {
|
|
37
|
-
result = result.catch(() => error.
|
|
37
|
+
result = await result.catch(() => error.addIssue(error$1, "successful async transform result", result, self.definition.errorMessage));
|
|
38
38
|
}
|
|
39
39
|
return result;
|
|
40
40
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type FixDeepFunctionInfer, type Kind, type NeverCoalescing } from "../../common";
|
|
2
2
|
import { type DataParserDefinition, type DataParser, type Input, type Output, SymbolDataParserError, type DataParserChecker } from "../base";
|
|
3
3
|
import { type AddCheckersToDefinition, type MergeDefinition } from "../../dataParser/types";
|
|
4
|
-
import { type DataParserError
|
|
4
|
+
import { type DataParserError } from "../../dataParser/error";
|
|
5
5
|
import { type CheckerRefineImplementation } from "./refine";
|
|
6
6
|
import { type GetPropsWithValueExtends } from "../../object";
|
|
7
7
|
export interface DataParserTransformCheckerCustom<GenericInput extends unknown = unknown> {
|
|
@@ -12,7 +12,7 @@ export interface DataParserDefinitionTransform extends DataParserDefinition<Data
|
|
|
12
12
|
theFunction(input: any, error: DataParserError): unknown;
|
|
13
13
|
}
|
|
14
14
|
export declare const transformKind: import("../../common").KindHandler<import("../../common").KindDefinition<"@DuplojsUtilsDataParser/transform", unknown>>;
|
|
15
|
-
export type DataParserTransformOutput<GenericTheFunction extends DataParserDefinitionTransform["theFunction"]> = Exclude<Awaited<ReturnType<GenericTheFunction>>, SymbolDataParserError
|
|
15
|
+
export type DataParserTransformOutput<GenericTheFunction extends DataParserDefinitionTransform["theFunction"]> = Exclude<Awaited<ReturnType<GenericTheFunction>>, SymbolDataParserError>;
|
|
16
16
|
type _DataParserTransform<GenericDefinition extends DataParserDefinitionTransform> = (DataParser<GenericDefinition, DataParserTransformOutput<GenericDefinition["theFunction"]>, Input<GenericDefinition["inner"]>> & Kind<typeof transformKind.definition>);
|
|
17
17
|
export interface DataParserTransform<GenericDefinition extends DataParserDefinitionTransform = DataParserDefinitionTransform> extends _DataParserTransform<GenericDefinition> {
|
|
18
18
|
addChecker<GenericChecker extends readonly [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { dataParserInit
|
|
2
|
-
import {
|
|
1
|
+
import { dataParserInit } from '../base.mjs';
|
|
2
|
+
import { SymbolDataParserError, addIssue } from '../error.mjs';
|
|
3
3
|
import { createDataParserKind } from '../kind.mjs';
|
|
4
4
|
import { createOverride } from '../../common/override.mjs';
|
|
5
5
|
|
|
@@ -21,7 +21,7 @@ function transform(inner, theFunction, definition) {
|
|
|
21
21
|
}
|
|
22
22
|
const result = self.definition.theFunction(innerResult, error);
|
|
23
23
|
if (result instanceof Promise) {
|
|
24
|
-
return
|
|
24
|
+
return addIssue(error, "non-promise transform result", result, self.definition.errorMessage);
|
|
25
25
|
}
|
|
26
26
|
return result;
|
|
27
27
|
},
|
|
@@ -32,7 +32,7 @@ function transform(inner, theFunction, definition) {
|
|
|
32
32
|
}
|
|
33
33
|
let result = self.definition.theFunction(innerResult, error);
|
|
34
34
|
if (result instanceof Promise) {
|
|
35
|
-
result = result.catch(() =>
|
|
35
|
+
result = await result.catch(() => addIssue(error, "successful async transform result", result, self.definition.errorMessage));
|
|
36
36
|
}
|
|
37
37
|
return result;
|
|
38
38
|
},
|
|
@@ -19,17 +19,17 @@ function tuple(shape, definition) {
|
|
|
19
19
|
}, {
|
|
20
20
|
sync: (data, error$1, self) => {
|
|
21
21
|
if (!(data instanceof Array)) {
|
|
22
|
-
return error.
|
|
22
|
+
return error.addIssue(error$1, "tuple array", data, self.definition.errorMessage);
|
|
23
23
|
}
|
|
24
24
|
let output = [];
|
|
25
25
|
const currentIndexPath = error$1.currentPath.length;
|
|
26
26
|
for (let index = 0; index < self.definition.shape.length; index++) {
|
|
27
27
|
error.setErrorPath(error$1, `[${index}]`, currentIndexPath);
|
|
28
28
|
const result = self.definition.shape[index]?.exec(data[index], error$1);
|
|
29
|
-
if (result ===
|
|
30
|
-
output =
|
|
29
|
+
if (result === error.SymbolDataParserError) {
|
|
30
|
+
output = error.SymbolDataParserError;
|
|
31
31
|
}
|
|
32
|
-
else if (output !==
|
|
32
|
+
else if (output !== error.SymbolDataParserError) {
|
|
33
33
|
output.push(result);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -37,10 +37,10 @@ function tuple(shape, definition) {
|
|
|
37
37
|
for (let index = self.definition.shape.length; index < data.length; index++) {
|
|
38
38
|
error.setErrorPath(error$1, `[${index}]`, currentIndexPath);
|
|
39
39
|
const result = self.definition.rest.exec(data[index], error$1);
|
|
40
|
-
if (result ===
|
|
41
|
-
output =
|
|
40
|
+
if (result === error.SymbolDataParserError) {
|
|
41
|
+
output = error.SymbolDataParserError;
|
|
42
42
|
}
|
|
43
|
-
else if (output !==
|
|
43
|
+
else if (output !== error.SymbolDataParserError) {
|
|
44
44
|
output.push(result);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -50,17 +50,17 @@ function tuple(shape, definition) {
|
|
|
50
50
|
},
|
|
51
51
|
async: async (data, error$1, self) => {
|
|
52
52
|
if (!(data instanceof Array)) {
|
|
53
|
-
return error.
|
|
53
|
+
return error.addIssue(error$1, "tuple array", data, self.definition.errorMessage);
|
|
54
54
|
}
|
|
55
55
|
let output = [];
|
|
56
56
|
const currentIndexPath = error$1.currentPath.length;
|
|
57
57
|
for (let index = 0; index < self.definition.shape.length; index++) {
|
|
58
58
|
error.setErrorPath(error$1, `[${index}]`, currentIndexPath);
|
|
59
59
|
const result = await self.definition.shape[index]?.asyncExec(data[index], error$1);
|
|
60
|
-
if (result ===
|
|
61
|
-
output =
|
|
60
|
+
if (result === error.SymbolDataParserError) {
|
|
61
|
+
output = error.SymbolDataParserError;
|
|
62
62
|
}
|
|
63
|
-
else if (output !==
|
|
63
|
+
else if (output !== error.SymbolDataParserError) {
|
|
64
64
|
output.push(result);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -68,10 +68,10 @@ function tuple(shape, definition) {
|
|
|
68
68
|
for (let index = self.definition.shape.length; index < data.length; index++) {
|
|
69
69
|
error.setErrorPath(error$1, `[${index}]`, currentIndexPath);
|
|
70
70
|
const result = await self.definition.rest.asyncExec(data[index], error$1);
|
|
71
|
-
if (result ===
|
|
72
|
-
output =
|
|
71
|
+
if (result === error.SymbolDataParserError) {
|
|
72
|
+
output = error.SymbolDataParserError;
|
|
73
73
|
}
|
|
74
|
-
else if (output !==
|
|
74
|
+
else if (output !== error.SymbolDataParserError) {
|
|
75
75
|
output.push(result);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { dataParserInit
|
|
2
|
-
import {
|
|
1
|
+
import { dataParserInit } from '../base.mjs';
|
|
2
|
+
import { addIssue, setErrorPath, SymbolDataParserError, popErrorPath } from '../error.mjs';
|
|
3
3
|
import { createDataParserKind } from '../kind.mjs';
|
|
4
4
|
import { some } from '../../array/some.mjs';
|
|
5
5
|
import { createOverride } from '../../common/override.mjs';
|
|
@@ -17,7 +17,7 @@ function tuple(shape, definition) {
|
|
|
17
17
|
}, {
|
|
18
18
|
sync: (data, error, self) => {
|
|
19
19
|
if (!(data instanceof Array)) {
|
|
20
|
-
return
|
|
20
|
+
return addIssue(error, "tuple array", data, self.definition.errorMessage);
|
|
21
21
|
}
|
|
22
22
|
let output = [];
|
|
23
23
|
const currentIndexPath = error.currentPath.length;
|
|
@@ -48,7 +48,7 @@ function tuple(shape, definition) {
|
|
|
48
48
|
},
|
|
49
49
|
async: async (data, error, self) => {
|
|
50
50
|
if (!(data instanceof Array)) {
|
|
51
|
-
return
|
|
51
|
+
return addIssue(error, "tuple array", data, self.definition.errorMessage);
|
|
52
52
|
}
|
|
53
53
|
let output = [];
|
|
54
54
|
const currentIndexPath = error.currentPath.length;
|
|
@@ -17,22 +17,40 @@ function union(options, definition) {
|
|
|
17
17
|
options,
|
|
18
18
|
}, {
|
|
19
19
|
sync: (data, error$1, self) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const unionError = {
|
|
21
|
+
...error$1,
|
|
22
|
+
currentPath: [...error$1.currentPath],
|
|
23
|
+
issues: [],
|
|
24
|
+
};
|
|
25
|
+
const currentIndexPath = unionError.currentPath.length;
|
|
26
|
+
for (let index = 0; index < self.definition.options.length; index++) {
|
|
27
|
+
error.setErrorPath(unionError, `(option: ${index})`, currentIndexPath);
|
|
28
|
+
const dataParser = self.definition.options[index];
|
|
29
|
+
const result = dataParser.exec(data, unionError);
|
|
30
|
+
if (result !== error.SymbolDataParserError) {
|
|
23
31
|
return result;
|
|
24
32
|
}
|
|
25
33
|
}
|
|
26
|
-
|
|
34
|
+
error$1.issues.push(...unionError.issues);
|
|
35
|
+
return error.addIssue(error$1, "respect at least one union value", data, self.definition.errorMessage);
|
|
27
36
|
},
|
|
28
37
|
async: async (data, error$1, self) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
const unionError = {
|
|
39
|
+
...error$1,
|
|
40
|
+
currentPath: [...error$1.currentPath],
|
|
41
|
+
issues: [],
|
|
42
|
+
};
|
|
43
|
+
const currentIndexPath = unionError.currentPath.length;
|
|
44
|
+
for (let index = 0; index < self.definition.options.length; index++) {
|
|
45
|
+
error.setErrorPath(unionError, `(option: ${index})`, currentIndexPath);
|
|
46
|
+
const dataParser = self.definition.options[index];
|
|
47
|
+
const result = await dataParser.asyncExec(data, unionError);
|
|
48
|
+
if (result !== error.SymbolDataParserError) {
|
|
32
49
|
return result;
|
|
33
50
|
}
|
|
34
51
|
}
|
|
35
|
-
|
|
52
|
+
error$1.issues.push(...unionError.issues);
|
|
53
|
+
return error.addIssue(error$1, "respect at least one union value", data, self.definition.errorMessage);
|
|
36
54
|
},
|
|
37
55
|
isAsynchronous: (self) => some.some(self.definition.options, (element) => element.isAsynchronous()),
|
|
38
56
|
}, union.overrideHandler);
|