@duplojs/utils 1.0.7 → 1.1.8
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/coalescing.cjs +9 -0
- package/dist/array/coalescing.d.ts +3 -0
- package/dist/array/coalescing.mjs +7 -0
- package/dist/array/index.cjs +2 -0
- package/dist/array/index.d.ts +1 -0
- package/dist/array/index.mjs +1 -0
- package/dist/array/map.cjs +1 -1
- package/dist/array/map.d.ts +2 -2
- package/dist/array/map.mjs +1 -1
- package/dist/array/reduce.cjs +1 -1
- package/dist/array/reduce.mjs +1 -1
- package/dist/array/types/ArrayCoalescing.d.ts +1 -0
- package/dist/array/types/index.d.ts +1 -0
- package/dist/common/escapeRegExp.cjs +2 -2
- package/dist/common/escapeRegExp.d.ts +1 -1
- package/dist/common/escapeRegExp.mjs +2 -2
- package/dist/common/index.d.ts +2 -0
- package/dist/common/instanceOf.cjs +20 -0
- package/dist/common/instanceOf.d.ts +3 -0
- package/dist/common/instanceOf.mjs +18 -0
- package/dist/common/kind.cjs +45 -1
- package/dist/common/kind.d.ts +24 -4
- package/dist/common/kind.mjs +44 -2
- package/dist/common/memo.cjs +16 -0
- package/dist/common/memo.d.ts +5 -0
- package/dist/common/memo.mjs +14 -0
- package/dist/common/simpleClone.cjs +2 -2
- package/dist/common/simpleClone.mjs +2 -2
- package/dist/common/types/anyConstructor.d.ts +1 -0
- package/dist/common/types/anyPredicate.d.ts +1 -0
- package/dist/common/types/index.d.ts +2 -0
- package/dist/common/types/objectEntry.d.ts +1 -1
- package/dist/common/types/predicate.d.ts +1 -0
- package/dist/common/types/unionContain.d.ts +1 -1
- package/dist/dataParser/base.cjs +116 -0
- package/dist/dataParser/base.d.ts +44 -0
- package/dist/dataParser/base.mjs +109 -0
- package/dist/dataParser/baseExtended.cjs +55 -0
- package/dist/dataParser/baseExtended.d.ts +45 -0
- package/dist/dataParser/baseExtended.mjs +52 -0
- package/dist/dataParser/error.cjs +54 -0
- package/dist/dataParser/error.d.ts +31 -0
- package/dist/dataParser/error.mjs +41 -0
- package/dist/dataParser/extended/array.cjs +20 -0
- package/dist/dataParser/extended/array.d.ts +21 -0
- package/dist/dataParser/extended/array.mjs +18 -0
- package/dist/dataParser/extended/bigint.cjs +20 -0
- package/dist/dataParser/extended/bigint.d.ts +19 -0
- package/dist/dataParser/extended/bigint.mjs +18 -0
- package/dist/dataParser/extended/boolean.cjs +11 -0
- package/dist/dataParser/extended/boolean.d.ts +9 -0
- package/dist/dataParser/extended/boolean.mjs +9 -0
- package/dist/dataParser/extended/coerce/bigint.cjs +13 -0
- package/dist/dataParser/extended/coerce/bigint.d.ts +7 -0
- package/dist/dataParser/extended/coerce/bigint.mjs +11 -0
- package/dist/dataParser/extended/coerce/boolean.cjs +13 -0
- package/dist/dataParser/extended/coerce/boolean.d.ts +7 -0
- package/dist/dataParser/extended/coerce/boolean.mjs +11 -0
- package/dist/dataParser/extended/coerce/empty.cjs +13 -0
- package/dist/dataParser/extended/coerce/empty.d.ts +7 -0
- package/dist/dataParser/extended/coerce/empty.mjs +11 -0
- package/dist/dataParser/extended/coerce/index.cjs +17 -0
- package/dist/dataParser/extended/coerce/index.d.ts +6 -0
- package/dist/dataParser/extended/coerce/index.mjs +6 -0
- package/dist/dataParser/extended/coerce/nil.cjs +13 -0
- package/dist/dataParser/extended/coerce/nil.d.ts +7 -0
- package/dist/dataParser/extended/coerce/nil.mjs +11 -0
- package/dist/dataParser/extended/coerce/number.cjs +13 -0
- package/dist/dataParser/extended/coerce/number.d.ts +7 -0
- package/dist/dataParser/extended/coerce/number.mjs +11 -0
- package/dist/dataParser/extended/coerce/string.cjs +13 -0
- package/dist/dataParser/extended/coerce/string.d.ts +7 -0
- package/dist/dataParser/extended/coerce/string.mjs +11 -0
- package/dist/dataParser/extended/empty.cjs +11 -0
- package/dist/dataParser/extended/empty.d.ts +9 -0
- package/dist/dataParser/extended/empty.mjs +9 -0
- package/dist/dataParser/extended/index.cjs +48 -0
- package/dist/dataParser/extended/index.d.ts +22 -0
- package/dist/dataParser/extended/index.mjs +21 -0
- package/dist/dataParser/extended/lazy.cjs +11 -0
- package/dist/dataParser/extended/lazy.d.ts +11 -0
- package/dist/dataParser/extended/lazy.mjs +9 -0
- package/dist/dataParser/extended/literal.cjs +11 -0
- package/dist/dataParser/extended/literal.d.ts +11 -0
- package/dist/dataParser/extended/literal.mjs +9 -0
- package/dist/dataParser/extended/nil.cjs +11 -0
- package/dist/dataParser/extended/nil.d.ts +9 -0
- package/dist/dataParser/extended/nil.mjs +9 -0
- package/dist/dataParser/extended/nullable.cjs +11 -0
- package/dist/dataParser/extended/nullable.d.ts +11 -0
- package/dist/dataParser/extended/nullable.mjs +9 -0
- package/dist/dataParser/extended/number.cjs +27 -0
- package/dist/dataParser/extended/number.d.ts +24 -0
- package/dist/dataParser/extended/number.mjs +24 -0
- package/dist/dataParser/extended/object.cjs +11 -0
- package/dist/dataParser/extended/object.d.ts +11 -0
- package/dist/dataParser/extended/object.mjs +9 -0
- package/dist/dataParser/extended/optional.cjs +11 -0
- package/dist/dataParser/extended/optional.d.ts +11 -0
- package/dist/dataParser/extended/optional.mjs +9 -0
- package/dist/dataParser/extended/pipe.cjs +11 -0
- package/dist/dataParser/extended/pipe.d.ts +12 -0
- package/dist/dataParser/extended/pipe.mjs +9 -0
- package/dist/dataParser/extended/record.cjs +11 -0
- package/dist/dataParser/extended/record.d.ts +12 -0
- package/dist/dataParser/extended/record.mjs +9 -0
- package/dist/dataParser/extended/string.cjs +38 -0
- package/dist/dataParser/extended/string.d.ts +32 -0
- package/dist/dataParser/extended/string.mjs +34 -0
- package/dist/dataParser/extended/templateLiteral.cjs +10 -0
- package/dist/dataParser/extended/templateLiteral.d.ts +11 -0
- package/dist/dataParser/extended/templateLiteral.mjs +8 -0
- package/dist/dataParser/extended/transform.cjs +11 -0
- package/dist/dataParser/extended/transform.d.ts +14 -0
- package/dist/dataParser/extended/transform.mjs +9 -0
- package/dist/dataParser/extended/tuple.cjs +11 -0
- package/dist/dataParser/extended/tuple.d.ts +11 -0
- package/dist/dataParser/extended/tuple.mjs +9 -0
- package/dist/dataParser/extended/union.cjs +11 -0
- package/dist/dataParser/extended/union.d.ts +11 -0
- package/dist/dataParser/extended/union.mjs +9 -0
- package/dist/dataParser/extended/unknown.cjs +11 -0
- package/dist/dataParser/extended/unknown.d.ts +9 -0
- package/dist/dataParser/extended/unknown.mjs +9 -0
- package/dist/dataParser/index.cjs +128 -0
- package/dist/dataParser/index.d.ts +6 -0
- package/dist/dataParser/index.mjs +38 -0
- package/dist/dataParser/kind.cjs +7 -0
- package/dist/dataParser/kind.d.ts +1 -0
- package/dist/dataParser/kind.mjs +5 -0
- package/dist/dataParser/parsers/array/checkers/index.d.ts +2 -0
- package/dist/dataParser/parsers/array/checkers/max.cjs +23 -0
- package/dist/dataParser/parsers/array/checkers/max.d.ts +11 -0
- package/dist/dataParser/parsers/array/checkers/max.mjs +20 -0
- package/dist/dataParser/parsers/array/checkers/min.cjs +23 -0
- package/dist/dataParser/parsers/array/checkers/min.d.ts +11 -0
- package/dist/dataParser/parsers/array/checkers/min.mjs +20 -0
- package/dist/dataParser/parsers/array/index.cjs +64 -0
- package/dist/dataParser/parsers/array/index.d.ts +20 -0
- package/dist/dataParser/parsers/array/index.mjs +61 -0
- package/dist/dataParser/parsers/bigint/checkers/index.d.ts +2 -0
- package/dist/dataParser/parsers/bigint/checkers/max.cjs +23 -0
- package/dist/dataParser/parsers/bigint/checkers/max.d.ts +11 -0
- package/dist/dataParser/parsers/bigint/checkers/max.mjs +20 -0
- package/dist/dataParser/parsers/bigint/checkers/min.cjs +23 -0
- package/dist/dataParser/parsers/bigint/checkers/min.d.ts +11 -0
- package/dist/dataParser/parsers/bigint/checkers/min.mjs +20 -0
- package/dist/dataParser/parsers/bigint/index.cjs +31 -0
- package/dist/dataParser/parsers/bigint/index.d.ts +18 -0
- package/dist/dataParser/parsers/bigint/index.mjs +28 -0
- package/dist/dataParser/parsers/boolean.cjs +40 -0
- package/dist/dataParser/parsers/boolean.d.ts +12 -0
- package/dist/dataParser/parsers/boolean.mjs +37 -0
- package/dist/dataParser/parsers/coerce/bigint.cjs +13 -0
- package/dist/dataParser/parsers/coerce/bigint.d.ts +6 -0
- package/dist/dataParser/parsers/coerce/bigint.mjs +11 -0
- package/dist/dataParser/parsers/coerce/boolean.cjs +13 -0
- package/dist/dataParser/parsers/coerce/boolean.d.ts +6 -0
- package/dist/dataParser/parsers/coerce/boolean.mjs +11 -0
- package/dist/dataParser/parsers/coerce/empty.cjs +13 -0
- package/dist/dataParser/parsers/coerce/empty.d.ts +6 -0
- package/dist/dataParser/parsers/coerce/empty.mjs +11 -0
- package/dist/dataParser/parsers/coerce/index.cjs +17 -0
- package/dist/dataParser/parsers/coerce/index.d.ts +6 -0
- package/dist/dataParser/parsers/coerce/index.mjs +6 -0
- package/dist/dataParser/parsers/coerce/nil.cjs +13 -0
- package/dist/dataParser/parsers/coerce/nil.d.ts +6 -0
- package/dist/dataParser/parsers/coerce/nil.mjs +11 -0
- package/dist/dataParser/parsers/coerce/number.cjs +13 -0
- package/dist/dataParser/parsers/coerce/number.d.ts +6 -0
- package/dist/dataParser/parsers/coerce/number.mjs +11 -0
- package/dist/dataParser/parsers/coerce/string.cjs +13 -0
- package/dist/dataParser/parsers/coerce/string.d.ts +6 -0
- package/dist/dataParser/parsers/coerce/string.mjs +11 -0
- package/dist/dataParser/parsers/empty.cjs +27 -0
- package/dist/dataParser/parsers/empty.d.ts +12 -0
- package/dist/dataParser/parsers/empty.mjs +24 -0
- package/dist/dataParser/parsers/index.d.ts +20 -0
- package/dist/dataParser/parsers/lazy.cjs +21 -0
- package/dist/dataParser/parsers/lazy.d.ts +14 -0
- package/dist/dataParser/parsers/lazy.mjs +18 -0
- package/dist/dataParser/parsers/literal.cjs +25 -0
- package/dist/dataParser/parsers/literal.d.ts +15 -0
- package/dist/dataParser/parsers/literal.mjs +22 -0
- package/dist/dataParser/parsers/nil.cjs +27 -0
- package/dist/dataParser/parsers/nil.d.ts +12 -0
- package/dist/dataParser/parsers/nil.mjs +24 -0
- package/dist/dataParser/parsers/nullable.cjs +31 -0
- package/dist/dataParser/parsers/nullable.d.ts +14 -0
- package/dist/dataParser/parsers/nullable.mjs +28 -0
- package/dist/dataParser/parsers/number/checkers/index.d.ts +3 -0
- package/dist/dataParser/parsers/number/checkers/int.cjs +27 -0
- package/dist/dataParser/parsers/number/checkers/int.d.ts +15 -0
- package/dist/dataParser/parsers/number/checkers/int.mjs +23 -0
- package/dist/dataParser/parsers/number/checkers/max.cjs +18 -0
- package/dist/dataParser/parsers/number/checkers/max.d.ts +11 -0
- package/dist/dataParser/parsers/number/checkers/max.mjs +15 -0
- package/dist/dataParser/parsers/number/checkers/min.cjs +18 -0
- package/dist/dataParser/parsers/number/checkers/min.d.ts +11 -0
- package/dist/dataParser/parsers/number/checkers/min.mjs +15 -0
- package/dist/dataParser/parsers/number/index.cjs +31 -0
- package/dist/dataParser/parsers/number/index.d.ts +18 -0
- package/dist/dataParser/parsers/number/index.mjs +28 -0
- package/dist/dataParser/parsers/object.cjs +74 -0
- package/dist/dataParser/parsers/object.d.ts +26 -0
- package/dist/dataParser/parsers/object.mjs +71 -0
- package/dist/dataParser/parsers/optional.cjs +31 -0
- package/dist/dataParser/parsers/optional.d.ts +14 -0
- package/dist/dataParser/parsers/optional.mjs +28 -0
- package/dist/dataParser/parsers/pipe.cjs +34 -0
- package/dist/dataParser/parsers/pipe.d.ts +16 -0
- package/dist/dataParser/parsers/pipe.mjs +31 -0
- package/dist/dataParser/parsers/record.cjs +83 -0
- package/dist/dataParser/parsers/record.d.ts +30 -0
- package/dist/dataParser/parsers/record.mjs +80 -0
- package/dist/dataParser/parsers/string/checkers/email.cjs +31 -0
- package/dist/dataParser/parsers/string/checkers/email.d.ts +17 -0
- package/dist/dataParser/parsers/string/checkers/email.mjs +27 -0
- package/dist/dataParser/parsers/string/checkers/index.d.ts +5 -0
- package/dist/dataParser/parsers/string/checkers/max.cjs +18 -0
- package/dist/dataParser/parsers/string/checkers/max.d.ts +11 -0
- package/dist/dataParser/parsers/string/checkers/max.mjs +15 -0
- package/dist/dataParser/parsers/string/checkers/min.cjs +18 -0
- package/dist/dataParser/parsers/string/checkers/min.d.ts +11 -0
- package/dist/dataParser/parsers/string/checkers/min.mjs +15 -0
- package/dist/dataParser/parsers/string/checkers/regex.cjs +20 -0
- package/dist/dataParser/parsers/string/checkers/regex.d.ts +11 -0
- package/dist/dataParser/parsers/string/checkers/regex.mjs +17 -0
- package/dist/dataParser/parsers/string/checkers/url.cjs +48 -0
- package/dist/dataParser/parsers/string/checkers/url.d.ts +18 -0
- package/dist/dataParser/parsers/string/checkers/url.mjs +44 -0
- package/dist/dataParser/parsers/string/index.cjs +31 -0
- package/dist/dataParser/parsers/string/index.d.ts +18 -0
- package/dist/dataParser/parsers/string/index.mjs +28 -0
- package/dist/dataParser/parsers/templateLiteral.cjs +45 -0
- package/dist/dataParser/parsers/templateLiteral.d.ts +49 -0
- package/dist/dataParser/parsers/templateLiteral.mjs +42 -0
- package/dist/dataParser/parsers/transform.cjs +43 -0
- package/dist/dataParser/parsers/transform.d.ts +17 -0
- package/dist/dataParser/parsers/transform.mjs +40 -0
- package/dist/dataParser/parsers/tuple.cjs +83 -0
- package/dist/dataParser/parsers/tuple.d.ts +33 -0
- package/dist/dataParser/parsers/tuple.mjs +80 -0
- package/dist/dataParser/parsers/union.cjs +38 -0
- package/dist/dataParser/parsers/union.d.ts +15 -0
- package/dist/dataParser/parsers/union.mjs +35 -0
- package/dist/dataParser/parsers/unknown.cjs +17 -0
- package/dist/dataParser/parsers/unknown.d.ts +11 -0
- package/dist/dataParser/parsers/unknown.mjs +14 -0
- package/dist/dataParser/types/addCheckersToDefinition.d.ts +5 -0
- package/dist/dataParser/types/checkers.d.ts +3 -0
- package/dist/dataParser/types/dataParsers.d.ts +5 -0
- package/dist/dataParser/types/index.d.ts +4 -0
- package/dist/dataParser/types/mergeDefinition.d.ts +5 -0
- package/dist/either/bool/base.cjs +2 -2
- package/dist/either/bool/base.d.ts +1 -1
- package/dist/either/bool/base.mjs +2 -2
- package/dist/either/bool/falsy.cjs +5 -5
- package/dist/either/bool/falsy.d.ts +4 -4
- package/dist/either/bool/falsy.mjs +5 -5
- package/dist/either/bool/truthy.cjs +4 -4
- package/dist/either/bool/truthy.d.ts +5 -5
- package/dist/either/bool/truthy.mjs +4 -4
- package/dist/either/future/base.cjs +2 -2
- package/dist/either/future/base.d.ts +1 -1
- package/dist/either/future/base.mjs +2 -2
- package/dist/either/future/error.cjs +3 -3
- package/dist/either/future/error.d.ts +1 -1
- package/dist/either/future/error.mjs +3 -3
- package/dist/either/future/success.cjs +3 -3
- package/dist/either/future/success.d.ts +2 -2
- package/dist/either/future/success.mjs +3 -3
- package/dist/either/hasInformation.cjs +3 -3
- package/dist/either/hasInformation.d.ts +1 -1
- package/dist/either/hasInformation.mjs +1 -1
- package/dist/either/index.cjs +3 -2
- package/dist/either/index.d.ts +1 -1
- package/dist/either/index.mjs +1 -1
- package/dist/either/kind.cjs +9 -0
- package/dist/either/kind.d.ts +2 -0
- package/dist/either/kind.mjs +6 -0
- package/dist/either/left/create.cjs +3 -4
- package/dist/either/left/create.d.ts +2 -2
- package/dist/either/left/create.mjs +3 -4
- package/dist/either/left/error.cjs +3 -3
- package/dist/either/left/error.d.ts +1 -1
- package/dist/either/left/error.mjs +3 -3
- package/dist/either/left/fail.cjs +3 -3
- package/dist/either/left/fail.d.ts +1 -1
- package/dist/either/left/fail.mjs +3 -3
- package/dist/either/left/is.cjs +2 -2
- package/dist/either/left/is.mjs +1 -1
- package/dist/either/nullable/base.cjs +2 -2
- package/dist/either/nullable/base.d.ts +1 -1
- package/dist/either/nullable/base.mjs +2 -2
- package/dist/either/nullable/empty.cjs +3 -3
- package/dist/either/nullable/empty.d.ts +1 -1
- package/dist/either/nullable/empty.mjs +3 -3
- package/dist/either/nullable/filled.cjs +3 -3
- package/dist/either/nullable/filled.d.ts +1 -1
- package/dist/either/nullable/filled.mjs +3 -3
- package/dist/either/nullish/base.cjs +2 -2
- package/dist/either/nullish/base.d.ts +1 -1
- package/dist/either/nullish/base.mjs +2 -2
- package/dist/either/nullish/empty.cjs +3 -3
- package/dist/either/nullish/empty.d.ts +2 -2
- package/dist/either/nullish/empty.mjs +3 -3
- package/dist/either/nullish/filled.cjs +4 -4
- package/dist/either/nullish/filled.d.ts +1 -1
- package/dist/either/nullish/filled.mjs +4 -4
- package/dist/either/optional/base.cjs +2 -2
- package/dist/either/optional/base.d.ts +1 -1
- package/dist/either/optional/base.mjs +2 -2
- package/dist/either/optional/empty.cjs +5 -5
- package/dist/either/optional/empty.d.ts +3 -3
- package/dist/either/optional/empty.mjs +5 -5
- package/dist/either/optional/filled.cjs +5 -5
- package/dist/either/optional/filled.d.ts +3 -3
- package/dist/either/optional/filled.mjs +5 -5
- package/dist/either/right/asyncPipe.d.ts +2 -2
- package/dist/either/right/create.cjs +3 -4
- package/dist/either/right/create.d.ts +2 -2
- package/dist/either/right/create.mjs +3 -4
- package/dist/either/right/is.cjs +2 -2
- package/dist/either/right/is.mjs +1 -1
- package/dist/either/right/ok.cjs +3 -3
- package/dist/either/right/ok.d.ts +1 -1
- package/dist/either/right/ok.mjs +3 -3
- package/dist/either/right/success.cjs +3 -3
- package/dist/either/right/success.d.ts +2 -2
- package/dist/either/right/success.mjs +3 -3
- package/dist/either/whenHasInformation.cjs +2 -2
- package/dist/either/whenHasInformation.d.ts +1 -1
- package/dist/either/whenHasInformation.mjs +1 -1
- package/dist/generator/reduce.cjs +1 -1
- package/dist/generator/reduce.mjs +1 -1
- package/dist/index.cjs +15 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +12 -1
- package/dist/number/greater.cjs +12 -0
- package/dist/number/greater.d.ts +2 -0
- package/dist/number/greater.mjs +10 -0
- package/dist/number/greaterThan.cjs +12 -0
- package/dist/number/greaterThan.d.ts +2 -0
- package/dist/number/greaterThan.mjs +10 -0
- package/dist/number/index.cjs +8 -0
- package/dist/number/index.d.ts +4 -0
- package/dist/number/index.mjs +4 -0
- package/dist/number/less.cjs +12 -0
- package/dist/number/less.d.ts +2 -0
- package/dist/number/less.mjs +10 -0
- package/dist/number/lessThan.cjs +12 -0
- package/dist/number/lessThan.d.ts +2 -0
- package/dist/number/lessThan.mjs +10 -0
- package/dist/object/fromEntries.d.ts +1 -1
- package/dist/object/types/getPropsWithValueExtends.d.ts +1 -1
- package/dist/pattern/result.cjs +1 -1
- package/dist/pattern/result.mjs +1 -1
- package/dist/string/types/forbiddenCharacters.d.ts +5 -0
- package/dist/string/types/index.d.ts +1 -0
- package/package.json +57 -1
- package/dist/either/base.cjs +0 -7
- package/dist/either/base.d.ts +0 -1
- package/dist/either/base.mjs +0 -5
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var entries = require('../../object/entries.cjs');
|
|
4
|
+
var pipe = require('../../common/pipe.cjs');
|
|
5
|
+
var forward = require('../../common/forward.cjs');
|
|
6
|
+
var memo = require('../../common/memo.cjs');
|
|
7
|
+
var filter = require('../../array/filter.cjs');
|
|
8
|
+
var map = require('../../array/map.cjs');
|
|
9
|
+
var base = require('../base.cjs');
|
|
10
|
+
var error = require('../error.cjs');
|
|
11
|
+
var kind = require('../kind.cjs');
|
|
12
|
+
|
|
13
|
+
const dataParserObjectKind = kind.createDataParserKind("object");
|
|
14
|
+
function object(shape, definition) {
|
|
15
|
+
return base.dataParserInit(dataParserObjectKind, {
|
|
16
|
+
definition: {
|
|
17
|
+
shape,
|
|
18
|
+
errorMessage: definition?.errorMessage,
|
|
19
|
+
checkers: definition?.checkers ?? [],
|
|
20
|
+
optimizedShape: memo.memo(() => pipe.pipe(forward.forward(shape), entries.entries, filter.filter((entry) => base.dataParserKind.has(entry[1])), map.map(([key, value]) => ({
|
|
21
|
+
key,
|
|
22
|
+
value,
|
|
23
|
+
})))),
|
|
24
|
+
},
|
|
25
|
+
}, {
|
|
26
|
+
sync: (data, error$1, self) => {
|
|
27
|
+
if (!data
|
|
28
|
+
|| typeof data !== "object"
|
|
29
|
+
|| data instanceof Array) {
|
|
30
|
+
return error.SymbolDataParserErrorIssue;
|
|
31
|
+
}
|
|
32
|
+
let output = {};
|
|
33
|
+
const currentIndexPath = error$1.currentPath.length;
|
|
34
|
+
for (const entry of self.definition.optimizedShape.value) {
|
|
35
|
+
error.setErrorPath(error$1, entry.key, currentIndexPath);
|
|
36
|
+
const result = entry.value.exec(data[entry.key], error$1);
|
|
37
|
+
if (result === base.SymbolDataParserError) {
|
|
38
|
+
output = base.SymbolDataParserError;
|
|
39
|
+
}
|
|
40
|
+
else if (output !== base.SymbolDataParserError
|
|
41
|
+
&& result !== undefined) {
|
|
42
|
+
output[entry.key] = result;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
error.popErrorPath(error$1);
|
|
46
|
+
return output;
|
|
47
|
+
},
|
|
48
|
+
async: async (data, error$1, self) => {
|
|
49
|
+
if (!data
|
|
50
|
+
|| typeof data !== "object"
|
|
51
|
+
|| data instanceof Array) {
|
|
52
|
+
return error.SymbolDataParserErrorIssue;
|
|
53
|
+
}
|
|
54
|
+
let output = {};
|
|
55
|
+
const currentIndexPath = error$1.currentPath.length;
|
|
56
|
+
for (const entry of self.definition.optimizedShape.value) {
|
|
57
|
+
error.setErrorPath(error$1, entry.key, currentIndexPath);
|
|
58
|
+
const result = await entry.value.asyncExec(data[entry.key], error$1);
|
|
59
|
+
if (result === base.SymbolDataParserError) {
|
|
60
|
+
output = base.SymbolDataParserError;
|
|
61
|
+
}
|
|
62
|
+
else if (output !== base.SymbolDataParserError
|
|
63
|
+
&& result !== undefined) {
|
|
64
|
+
output[entry.key] = result;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
error.popErrorPath(error$1);
|
|
68
|
+
return output;
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
exports.dataParserObjectKind = dataParserObjectKind;
|
|
74
|
+
exports.object = object;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Kind, type IsEqual, type NeverCoalescing, type Memoized } from "../../common";
|
|
2
|
+
import { dataParserKind, type Input, type Output, type DataParser, type DataParserDefinition } from "../base";
|
|
3
|
+
import { type MergeDefinition, type DataParsers } from "../types";
|
|
4
|
+
import * as DObject from "../../object";
|
|
5
|
+
export type DataParserObjectShape = Readonly<Record<string, DataParsers>>;
|
|
6
|
+
export type DataParserObjectShapeOutput<GenericShape extends DataParserObjectShape> = IsEqual<GenericShape, DataParserObjectShape> extends true ? DataParserObjectShape : {
|
|
7
|
+
-readonly [Prop in keyof GenericShape as GenericShape[Prop] extends Kind<typeof dataParserKind.definition> ? Prop : never]: Output<GenericShape[Prop]>;
|
|
8
|
+
} extends infer InferredResult extends object ? DObject.PartialKeys<InferredResult, DObject.GetPropsWithValueExtends<InferredResult, undefined>> : never;
|
|
9
|
+
export type DataParserObjectShapeInput<GenericShape extends DataParserObjectShape> = IsEqual<GenericShape, DataParserObjectShape> extends true ? DataParserObjectShape : {
|
|
10
|
+
-readonly [Prop in keyof GenericShape as GenericShape[Prop] extends Kind<typeof dataParserKind.definition> ? Prop : never]: Input<GenericShape[Prop]>;
|
|
11
|
+
} extends infer InferredResult extends object ? DObject.PartialKeys<InferredResult, DObject.GetPropsWithValueExtends<InferredResult, undefined>> : never;
|
|
12
|
+
export interface DataParserDefinitionObject extends DataParserDefinition<never> {
|
|
13
|
+
readonly shape: DataParserObjectShape;
|
|
14
|
+
readonly optimizedShape: Memoized<{
|
|
15
|
+
readonly key: string;
|
|
16
|
+
readonly value: DataParsers;
|
|
17
|
+
}[]>;
|
|
18
|
+
}
|
|
19
|
+
export declare const dataParserObjectKind: import("../../common").KindHandler<import("../../common").KindDefinition<"@DataParser/object", unknown>>;
|
|
20
|
+
type _DataParserObject<GenericDefinition extends DataParserDefinitionObject> = (DataParser<GenericDefinition, DataParserObjectShapeOutput<GenericDefinition["shape"]>, DataParserObjectShapeInput<GenericDefinition["shape"]>> & Kind<typeof dataParserObjectKind.definition>);
|
|
21
|
+
export interface DataParserObject<GenericDefinition extends DataParserDefinitionObject = DataParserDefinitionObject> extends _DataParserObject<GenericDefinition> {
|
|
22
|
+
}
|
|
23
|
+
export declare function object<const GenericShape extends DataParserObjectShape, const GenericDefinition extends Partial<Omit<DataParserDefinitionObject, "shape">> = never>(shape: GenericShape, definition?: GenericDefinition): DataParserObject<MergeDefinition<DataParserDefinitionObject, NeverCoalescing<GenericDefinition, {}> & {
|
|
24
|
+
shape: GenericShape;
|
|
25
|
+
}>>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { entries } from '../../object/entries.mjs';
|
|
2
|
+
import { pipe } from '../../common/pipe.mjs';
|
|
3
|
+
import { forward } from '../../common/forward.mjs';
|
|
4
|
+
import { memo } from '../../common/memo.mjs';
|
|
5
|
+
import { filter } from '../../array/filter.mjs';
|
|
6
|
+
import { map } from '../../array/map.mjs';
|
|
7
|
+
import { dataParserInit, SymbolDataParserError, dataParserKind } from '../base.mjs';
|
|
8
|
+
import { SymbolDataParserErrorIssue, setErrorPath, popErrorPath } from '../error.mjs';
|
|
9
|
+
import { createDataParserKind } from '../kind.mjs';
|
|
10
|
+
|
|
11
|
+
const dataParserObjectKind = createDataParserKind("object");
|
|
12
|
+
function object(shape, definition) {
|
|
13
|
+
return dataParserInit(dataParserObjectKind, {
|
|
14
|
+
definition: {
|
|
15
|
+
shape,
|
|
16
|
+
errorMessage: definition?.errorMessage,
|
|
17
|
+
checkers: definition?.checkers ?? [],
|
|
18
|
+
optimizedShape: memo(() => pipe(forward(shape), entries, filter((entry) => dataParserKind.has(entry[1])), map(([key, value]) => ({
|
|
19
|
+
key,
|
|
20
|
+
value,
|
|
21
|
+
})))),
|
|
22
|
+
},
|
|
23
|
+
}, {
|
|
24
|
+
sync: (data, error, self) => {
|
|
25
|
+
if (!data
|
|
26
|
+
|| typeof data !== "object"
|
|
27
|
+
|| data instanceof Array) {
|
|
28
|
+
return SymbolDataParserErrorIssue;
|
|
29
|
+
}
|
|
30
|
+
let output = {};
|
|
31
|
+
const currentIndexPath = error.currentPath.length;
|
|
32
|
+
for (const entry of self.definition.optimizedShape.value) {
|
|
33
|
+
setErrorPath(error, entry.key, currentIndexPath);
|
|
34
|
+
const result = entry.value.exec(data[entry.key], error);
|
|
35
|
+
if (result === SymbolDataParserError) {
|
|
36
|
+
output = SymbolDataParserError;
|
|
37
|
+
}
|
|
38
|
+
else if (output !== SymbolDataParserError
|
|
39
|
+
&& result !== undefined) {
|
|
40
|
+
output[entry.key] = result;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
popErrorPath(error);
|
|
44
|
+
return output;
|
|
45
|
+
},
|
|
46
|
+
async: async (data, error, self) => {
|
|
47
|
+
if (!data
|
|
48
|
+
|| typeof data !== "object"
|
|
49
|
+
|| data instanceof Array) {
|
|
50
|
+
return SymbolDataParserErrorIssue;
|
|
51
|
+
}
|
|
52
|
+
let output = {};
|
|
53
|
+
const currentIndexPath = error.currentPath.length;
|
|
54
|
+
for (const entry of self.definition.optimizedShape.value) {
|
|
55
|
+
setErrorPath(error, entry.key, currentIndexPath);
|
|
56
|
+
const result = await entry.value.asyncExec(data[entry.key], error);
|
|
57
|
+
if (result === SymbolDataParserError) {
|
|
58
|
+
output = SymbolDataParserError;
|
|
59
|
+
}
|
|
60
|
+
else if (output !== SymbolDataParserError
|
|
61
|
+
&& result !== undefined) {
|
|
62
|
+
output[entry.key] = result;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
popErrorPath(error);
|
|
66
|
+
return output;
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { dataParserObjectKind, object };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var base = require('../base.cjs');
|
|
4
|
+
var kind = require('../kind.cjs');
|
|
5
|
+
|
|
6
|
+
const dataParserOptionalKind = kind.createDataParserKind("optional");
|
|
7
|
+
function optional(inner, definition) {
|
|
8
|
+
return base.dataParserInit(dataParserOptionalKind, {
|
|
9
|
+
definition: {
|
|
10
|
+
errorMessage: definition?.errorMessage,
|
|
11
|
+
checkers: definition?.checkers ?? [],
|
|
12
|
+
inner,
|
|
13
|
+
},
|
|
14
|
+
}, {
|
|
15
|
+
sync: (data, error, self) => {
|
|
16
|
+
if (data === undefined) {
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
return self.definition.inner.exec(data, error);
|
|
20
|
+
},
|
|
21
|
+
async: async (data, error, self) => {
|
|
22
|
+
if (data === undefined) {
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
return self.definition.inner.asyncExec(data, error);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.dataParserOptionalKind = dataParserOptionalKind;
|
|
31
|
+
exports.optional = optional;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type NeverCoalescing, type Kind } from "../../common";
|
|
2
|
+
import { type DataParserDefinition, type DataParser, type Output, type Input } from "../base";
|
|
3
|
+
import { type DataParsers, type MergeDefinition } from "../../dataParser/types";
|
|
4
|
+
export interface DataParserDefinitionOptional extends DataParserDefinition<never> {
|
|
5
|
+
readonly inner: DataParsers;
|
|
6
|
+
}
|
|
7
|
+
export declare const dataParserOptionalKind: import("../../common").KindHandler<import("../../common").KindDefinition<"@DataParser/optional", unknown>>;
|
|
8
|
+
type _DataParserOptional<GenericDefinition extends DataParserDefinitionOptional> = (DataParser<GenericDefinition, Output<GenericDefinition["inner"]> | undefined, Input<GenericDefinition["inner"]> | undefined> & Kind<typeof dataParserOptionalKind.definition>);
|
|
9
|
+
export interface DataParserOptional<GenericDefinition extends DataParserDefinitionOptional = DataParserDefinitionOptional> extends _DataParserOptional<GenericDefinition> {
|
|
10
|
+
}
|
|
11
|
+
export declare function optional<GenericDataParser extends DataParsers, const GenericDefinition extends Partial<Omit<DataParserDefinitionOptional, "inner">> = never>(inner: GenericDataParser, definition?: GenericDefinition): DataParserOptional<MergeDefinition<DataParserDefinitionOptional, NeverCoalescing<GenericDefinition, {}> & {
|
|
12
|
+
inner: GenericDataParser;
|
|
13
|
+
}>>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { dataParserInit } from '../base.mjs';
|
|
2
|
+
import { createDataParserKind } from '../kind.mjs';
|
|
3
|
+
|
|
4
|
+
const dataParserOptionalKind = createDataParserKind("optional");
|
|
5
|
+
function optional(inner, definition) {
|
|
6
|
+
return dataParserInit(dataParserOptionalKind, {
|
|
7
|
+
definition: {
|
|
8
|
+
errorMessage: definition?.errorMessage,
|
|
9
|
+
checkers: definition?.checkers ?? [],
|
|
10
|
+
inner,
|
|
11
|
+
},
|
|
12
|
+
}, {
|
|
13
|
+
sync: (data, error, self) => {
|
|
14
|
+
if (data === undefined) {
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
return self.definition.inner.exec(data, error);
|
|
18
|
+
},
|
|
19
|
+
async: async (data, error, self) => {
|
|
20
|
+
if (data === undefined) {
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
return self.definition.inner.asyncExec(data, error);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { dataParserOptionalKind, optional };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var base = require('../base.cjs');
|
|
4
|
+
var kind = require('../kind.cjs');
|
|
5
|
+
|
|
6
|
+
const dataParserPipeKind = kind.createDataParserKind("pipe");
|
|
7
|
+
function pipe(input, output, definition) {
|
|
8
|
+
return base.dataParserInit(dataParserPipeKind, {
|
|
9
|
+
definition: {
|
|
10
|
+
errorMessage: definition?.errorMessage,
|
|
11
|
+
checkers: definition?.checkers ?? [],
|
|
12
|
+
input,
|
|
13
|
+
output,
|
|
14
|
+
},
|
|
15
|
+
}, {
|
|
16
|
+
sync: (data, error, self) => {
|
|
17
|
+
const result = self.definition.input.exec(data, error);
|
|
18
|
+
if (result === base.SymbolDataParserError) {
|
|
19
|
+
return base.SymbolDataParserError;
|
|
20
|
+
}
|
|
21
|
+
return self.definition.output.exec(result, error);
|
|
22
|
+
},
|
|
23
|
+
async: async (data, error, self) => {
|
|
24
|
+
const result = await self.definition.input.asyncExec(data, error);
|
|
25
|
+
if (result === base.SymbolDataParserError) {
|
|
26
|
+
return base.SymbolDataParserError;
|
|
27
|
+
}
|
|
28
|
+
return self.definition.output.asyncExec(result, error);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exports.dataParserPipeKind = dataParserPipeKind;
|
|
34
|
+
exports.pipe = pipe;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type NeverCoalescing, type Kind } from "../../common";
|
|
2
|
+
import { type DataParserDefinition, type DataParser, type Output, type Input } from "../base";
|
|
3
|
+
import { type DataParsers, type MergeDefinition } from "../../dataParser/types";
|
|
4
|
+
export interface DataParserDefinitionPipe extends DataParserDefinition<never> {
|
|
5
|
+
readonly input: DataParsers;
|
|
6
|
+
readonly output: DataParsers;
|
|
7
|
+
}
|
|
8
|
+
export declare const dataParserPipeKind: import("../../common").KindHandler<import("../../common").KindDefinition<"@DataParser/pipe", unknown>>;
|
|
9
|
+
type _DataParserPipe<GenericDefinition extends DataParserDefinitionPipe> = (DataParser<GenericDefinition, Output<GenericDefinition["output"]>, Input<GenericDefinition["input"]>> & Kind<typeof dataParserPipeKind.definition>);
|
|
10
|
+
export interface DataParserPipe<GenericDefinition extends DataParserDefinitionPipe = DataParserDefinitionPipe> extends _DataParserPipe<GenericDefinition> {
|
|
11
|
+
}
|
|
12
|
+
export declare function pipe<GenericInput extends DataParsers, GenericOutput extends DataParsers, const GenericDefinition extends Partial<Omit<DataParserDefinitionPipe, "input" | "output">> = never>(input: GenericInput, output: GenericOutput, definition?: GenericDefinition): DataParserPipe<MergeDefinition<DataParserDefinitionPipe, NeverCoalescing<GenericDefinition, {}> & {
|
|
13
|
+
input: GenericInput;
|
|
14
|
+
output: GenericOutput;
|
|
15
|
+
}>>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { dataParserInit, SymbolDataParserError } from '../base.mjs';
|
|
2
|
+
import { createDataParserKind } from '../kind.mjs';
|
|
3
|
+
|
|
4
|
+
const dataParserPipeKind = createDataParserKind("pipe");
|
|
5
|
+
function pipe(input, output, definition) {
|
|
6
|
+
return dataParserInit(dataParserPipeKind, {
|
|
7
|
+
definition: {
|
|
8
|
+
errorMessage: definition?.errorMessage,
|
|
9
|
+
checkers: definition?.checkers ?? [],
|
|
10
|
+
input,
|
|
11
|
+
output,
|
|
12
|
+
},
|
|
13
|
+
}, {
|
|
14
|
+
sync: (data, error, self) => {
|
|
15
|
+
const result = self.definition.input.exec(data, error);
|
|
16
|
+
if (result === SymbolDataParserError) {
|
|
17
|
+
return SymbolDataParserError;
|
|
18
|
+
}
|
|
19
|
+
return self.definition.output.exec(result, error);
|
|
20
|
+
},
|
|
21
|
+
async: async (data, error, self) => {
|
|
22
|
+
const result = await self.definition.input.asyncExec(data, error);
|
|
23
|
+
if (result === SymbolDataParserError) {
|
|
24
|
+
return SymbolDataParserError;
|
|
25
|
+
}
|
|
26
|
+
return self.definition.output.asyncExec(result, error);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { dataParserPipeKind, pipe };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var base = require('../base.cjs');
|
|
4
|
+
var error = require('../error.cjs');
|
|
5
|
+
var kind = require('../kind.cjs');
|
|
6
|
+
|
|
7
|
+
const dataParserRecordKind = kind.createDataParserKind("record");
|
|
8
|
+
function record(key, value, definition) {
|
|
9
|
+
return base.dataParserInit(dataParserRecordKind, {
|
|
10
|
+
definition: {
|
|
11
|
+
errorMessage: definition?.errorMessage,
|
|
12
|
+
checkers: definition?.checkers ?? [],
|
|
13
|
+
key,
|
|
14
|
+
value,
|
|
15
|
+
},
|
|
16
|
+
}, {
|
|
17
|
+
sync: (data, error$1, self) => {
|
|
18
|
+
if (!data
|
|
19
|
+
|| typeof data !== "object"
|
|
20
|
+
|| data instanceof Array) {
|
|
21
|
+
return error.SymbolDataParserErrorIssue;
|
|
22
|
+
}
|
|
23
|
+
let output = {};
|
|
24
|
+
const currentIndexPath = error$1.currentPath.length;
|
|
25
|
+
for (const key in data) {
|
|
26
|
+
error.setErrorPath(error$1, key, currentIndexPath);
|
|
27
|
+
const resultKey = self
|
|
28
|
+
.definition
|
|
29
|
+
.key
|
|
30
|
+
.exec(key, error$1);
|
|
31
|
+
if (resultKey === base.SymbolDataParserError) {
|
|
32
|
+
output = base.SymbolDataParserError;
|
|
33
|
+
}
|
|
34
|
+
const resultValue = self
|
|
35
|
+
.definition
|
|
36
|
+
.value
|
|
37
|
+
.exec(data[key], error$1);
|
|
38
|
+
if (resultValue === base.SymbolDataParserError) {
|
|
39
|
+
output = base.SymbolDataParserError;
|
|
40
|
+
}
|
|
41
|
+
if (output !== base.SymbolDataParserError) {
|
|
42
|
+
output[resultKey] = resultValue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
error.popErrorPath(error$1);
|
|
46
|
+
return output;
|
|
47
|
+
},
|
|
48
|
+
async: async (data, error$1, self) => {
|
|
49
|
+
if (!data
|
|
50
|
+
|| typeof data !== "object"
|
|
51
|
+
|| data instanceof Array) {
|
|
52
|
+
return error.SymbolDataParserErrorIssue;
|
|
53
|
+
}
|
|
54
|
+
let output = {};
|
|
55
|
+
const currentIndexPath = error$1.currentPath.length;
|
|
56
|
+
for (const key in data) {
|
|
57
|
+
error.setErrorPath(error$1, key, currentIndexPath);
|
|
58
|
+
const resultKey = await self
|
|
59
|
+
.definition
|
|
60
|
+
.key
|
|
61
|
+
.asyncExec(key, error$1);
|
|
62
|
+
if (resultKey === base.SymbolDataParserError) {
|
|
63
|
+
output = base.SymbolDataParserError;
|
|
64
|
+
}
|
|
65
|
+
const resultValue = await self
|
|
66
|
+
.definition
|
|
67
|
+
.value
|
|
68
|
+
.asyncExec(data[key], error$1);
|
|
69
|
+
if (resultValue === base.SymbolDataParserError) {
|
|
70
|
+
output = base.SymbolDataParserError;
|
|
71
|
+
}
|
|
72
|
+
if (output !== base.SymbolDataParserError) {
|
|
73
|
+
output[resultKey] = resultValue;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
error.popErrorPath(error$1);
|
|
77
|
+
return output;
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
exports.dataParserRecordKind = dataParserRecordKind;
|
|
83
|
+
exports.record = record;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type NeverCoalescing, type Kind } from "../../common";
|
|
2
|
+
import { type DataParserDefinition, type DataParser, type Output, type Input } from "../base";
|
|
3
|
+
import { type DataParsers, type MergeDefinition } from "../../dataParser/types";
|
|
4
|
+
import { type DataParserString } from "./string";
|
|
5
|
+
import { type DataParserTemplateLiteral } from "./templateLiteral";
|
|
6
|
+
import { type DataParserDefinitionLiteral, type DataParserLiteral } from "./literal";
|
|
7
|
+
import { type DataParserDefinitionNumber, type DataParserNumber } from "./number";
|
|
8
|
+
import { type DataParserDefinitionUnion, type DataParserUnion } from "./union";
|
|
9
|
+
export type DataParserRecordKey = (DataParserString | DataParserTemplateLiteral | DataParserLiteral<DataParserDefinitionLiteral & {
|
|
10
|
+
value: string[];
|
|
11
|
+
}> | DataParserNumber<DataParserDefinitionNumber & {
|
|
12
|
+
coerce: true;
|
|
13
|
+
}> | DataParserUnion<DataParserDefinitionUnion & {
|
|
14
|
+
options: DataParserRecordKey[];
|
|
15
|
+
}>);
|
|
16
|
+
export interface DataParserDefinitionRecord extends DataParserDefinition<never> {
|
|
17
|
+
readonly key: DataParserRecordKey;
|
|
18
|
+
readonly value: DataParsers;
|
|
19
|
+
}
|
|
20
|
+
export declare const dataParserRecordKind: import("../../common").KindHandler<import("../../common").KindDefinition<"@DataParser/record", unknown>>;
|
|
21
|
+
export type DataParserRecordShapeOutput<GenericDataParserKey extends DataParserRecordKey, GenericDataParserValue extends DataParsers> = Extract<Record<Output<GenericDataParserKey> extends infer InferredKey extends string | number ? `${InferredKey}` : never, Output<GenericDataParserValue> extends infer InferredValue ? InferredValue : never>, any>;
|
|
22
|
+
export type DataParserRecordShapeInput<GenericDataParserKey extends DataParserRecordKey, GenericDataParserValue extends DataParsers> = Extract<Record<Input<GenericDataParserKey> extends infer InferredKey extends string | number ? InferredKey : never, Input<GenericDataParserValue> extends infer InferredValue ? InferredValue : never>, any>;
|
|
23
|
+
type _DataParserRecord<GenericDefinition extends DataParserDefinitionRecord> = (DataParser<GenericDefinition, DataParserRecordShapeOutput<GenericDefinition["key"], GenericDefinition["value"]> extends infer InferredOutput ? InferredOutput : never, DataParserRecordShapeInput<GenericDefinition["key"], GenericDefinition["value"]>> & Kind<typeof dataParserRecordKind.definition>);
|
|
24
|
+
export interface DataParserRecord<GenericDefinition extends DataParserDefinitionRecord = DataParserDefinitionRecord> extends _DataParserRecord<GenericDefinition> {
|
|
25
|
+
}
|
|
26
|
+
export declare function record<GenericDataParserKey extends DataParserRecordKey, GenericDataParserValue extends DataParsers, const GenericDefinition extends Partial<DataParserDefinitionRecord> = never>(key: GenericDataParserKey, value: GenericDataParserValue, definition?: GenericDefinition): DataParserRecord<MergeDefinition<DataParserDefinitionRecord, NeverCoalescing<GenericDefinition, {}> & {
|
|
27
|
+
key: GenericDataParserKey;
|
|
28
|
+
value: GenericDataParserValue;
|
|
29
|
+
}>>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { dataParserInit, SymbolDataParserError } from '../base.mjs';
|
|
2
|
+
import { SymbolDataParserErrorIssue, setErrorPath, popErrorPath } from '../error.mjs';
|
|
3
|
+
import { createDataParserKind } from '../kind.mjs';
|
|
4
|
+
|
|
5
|
+
const dataParserRecordKind = createDataParserKind("record");
|
|
6
|
+
function record(key, value, definition) {
|
|
7
|
+
return dataParserInit(dataParserRecordKind, {
|
|
8
|
+
definition: {
|
|
9
|
+
errorMessage: definition?.errorMessage,
|
|
10
|
+
checkers: definition?.checkers ?? [],
|
|
11
|
+
key,
|
|
12
|
+
value,
|
|
13
|
+
},
|
|
14
|
+
}, {
|
|
15
|
+
sync: (data, error, self) => {
|
|
16
|
+
if (!data
|
|
17
|
+
|| typeof data !== "object"
|
|
18
|
+
|| data instanceof Array) {
|
|
19
|
+
return SymbolDataParserErrorIssue;
|
|
20
|
+
}
|
|
21
|
+
let output = {};
|
|
22
|
+
const currentIndexPath = error.currentPath.length;
|
|
23
|
+
for (const key in data) {
|
|
24
|
+
setErrorPath(error, key, currentIndexPath);
|
|
25
|
+
const resultKey = self
|
|
26
|
+
.definition
|
|
27
|
+
.key
|
|
28
|
+
.exec(key, error);
|
|
29
|
+
if (resultKey === SymbolDataParserError) {
|
|
30
|
+
output = SymbolDataParserError;
|
|
31
|
+
}
|
|
32
|
+
const resultValue = self
|
|
33
|
+
.definition
|
|
34
|
+
.value
|
|
35
|
+
.exec(data[key], error);
|
|
36
|
+
if (resultValue === SymbolDataParserError) {
|
|
37
|
+
output = SymbolDataParserError;
|
|
38
|
+
}
|
|
39
|
+
if (output !== SymbolDataParserError) {
|
|
40
|
+
output[resultKey] = resultValue;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
popErrorPath(error);
|
|
44
|
+
return output;
|
|
45
|
+
},
|
|
46
|
+
async: async (data, error, self) => {
|
|
47
|
+
if (!data
|
|
48
|
+
|| typeof data !== "object"
|
|
49
|
+
|| data instanceof Array) {
|
|
50
|
+
return SymbolDataParserErrorIssue;
|
|
51
|
+
}
|
|
52
|
+
let output = {};
|
|
53
|
+
const currentIndexPath = error.currentPath.length;
|
|
54
|
+
for (const key in data) {
|
|
55
|
+
setErrorPath(error, key, currentIndexPath);
|
|
56
|
+
const resultKey = await self
|
|
57
|
+
.definition
|
|
58
|
+
.key
|
|
59
|
+
.asyncExec(key, error);
|
|
60
|
+
if (resultKey === SymbolDataParserError) {
|
|
61
|
+
output = SymbolDataParserError;
|
|
62
|
+
}
|
|
63
|
+
const resultValue = await self
|
|
64
|
+
.definition
|
|
65
|
+
.value
|
|
66
|
+
.asyncExec(data[key], error);
|
|
67
|
+
if (resultValue === SymbolDataParserError) {
|
|
68
|
+
output = SymbolDataParserError;
|
|
69
|
+
}
|
|
70
|
+
if (output !== SymbolDataParserError) {
|
|
71
|
+
output[resultKey] = resultValue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
popErrorPath(error);
|
|
75
|
+
return output;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { dataParserRecordKind, record };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var base = require('../../../base.cjs');
|
|
4
|
+
var error = require('../../../error.cjs');
|
|
5
|
+
var index = require('../index.cjs');
|
|
6
|
+
var kind = require('../../../kind.cjs');
|
|
7
|
+
|
|
8
|
+
const dataParserCheckerEmailKind = kind.createDataParserKind("checker-string-email");
|
|
9
|
+
const emailPattern = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9-]*\.)+[A-Za-z]{2,}$/;
|
|
10
|
+
function checkerEmail(definition = {}) {
|
|
11
|
+
return base.dataParserCheckerInit(dataParserCheckerEmailKind, {
|
|
12
|
+
definition: {
|
|
13
|
+
...definition,
|
|
14
|
+
pattern: emailPattern,
|
|
15
|
+
},
|
|
16
|
+
}, (input, self) => {
|
|
17
|
+
if (!self.definition.pattern.test(input)) {
|
|
18
|
+
return error.SymbolDataParserErrorIssue;
|
|
19
|
+
}
|
|
20
|
+
return self.definition.normalize ? input.toLowerCase() : input;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function email(definition) {
|
|
24
|
+
return index.string({
|
|
25
|
+
checkers: [checkerEmail(definition)],
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.checkerEmail = checkerEmail;
|
|
30
|
+
exports.dataParserCheckerEmailKind = dataParserCheckerEmailKind;
|
|
31
|
+
exports.email = email;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Kind } from "../../../../common";
|
|
2
|
+
import { type DataParserChecker, type DataParserCheckerDefinition } from "../../../../dataParser/base";
|
|
3
|
+
export interface DataParserCheckerDefinitionEmail extends DataParserCheckerDefinition {
|
|
4
|
+
normalize?: boolean;
|
|
5
|
+
pattern: RegExp;
|
|
6
|
+
}
|
|
7
|
+
export declare const dataParserCheckerEmailKind: import("../../../../common").KindHandler<import("../../../../common").KindDefinition<"@DataParser/checker-string-email", unknown>>;
|
|
8
|
+
type _DataParserCheckerEmail = (Kind<typeof dataParserCheckerEmailKind.definition> & DataParserChecker<DataParserCheckerDefinitionEmail, string>);
|
|
9
|
+
export interface DataParserCheckerEmail extends _DataParserCheckerEmail {
|
|
10
|
+
}
|
|
11
|
+
export declare function checkerEmail(definition?: Partial<DataParserCheckerDefinitionEmail>): DataParserCheckerEmail;
|
|
12
|
+
export declare function email(definition?: Partial<DataParserCheckerDefinitionEmail>): import("..").DataParserString<{
|
|
13
|
+
readonly checkers: readonly [DataParserCheckerEmail];
|
|
14
|
+
readonly errorMessage?: string | undefined;
|
|
15
|
+
readonly coerce: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { dataParserCheckerInit } from '../../../base.mjs';
|
|
2
|
+
import { SymbolDataParserErrorIssue } from '../../../error.mjs';
|
|
3
|
+
import { string } from '../index.mjs';
|
|
4
|
+
import { createDataParserKind } from '../../../kind.mjs';
|
|
5
|
+
|
|
6
|
+
const dataParserCheckerEmailKind = createDataParserKind("checker-string-email");
|
|
7
|
+
const emailPattern = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9-]*\.)+[A-Za-z]{2,}$/;
|
|
8
|
+
function checkerEmail(definition = {}) {
|
|
9
|
+
return dataParserCheckerInit(dataParserCheckerEmailKind, {
|
|
10
|
+
definition: {
|
|
11
|
+
...definition,
|
|
12
|
+
pattern: emailPattern,
|
|
13
|
+
},
|
|
14
|
+
}, (input, self) => {
|
|
15
|
+
if (!self.definition.pattern.test(input)) {
|
|
16
|
+
return SymbolDataParserErrorIssue;
|
|
17
|
+
}
|
|
18
|
+
return self.definition.normalize ? input.toLowerCase() : input;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function email(definition) {
|
|
22
|
+
return string({
|
|
23
|
+
checkers: [checkerEmail(definition)],
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { checkerEmail, dataParserCheckerEmailKind, email };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var base = require('../../../base.cjs');
|
|
4
|
+
var error = require('../../../error.cjs');
|
|
5
|
+
var kind = require('../../../kind.cjs');
|
|
6
|
+
|
|
7
|
+
const dataParserCheckerStringMaxKind = kind.createDataParserKind("checker-string-max");
|
|
8
|
+
function checkerStringMax(max, definition = {}) {
|
|
9
|
+
return base.dataParserCheckerInit(dataParserCheckerStringMaxKind, {
|
|
10
|
+
definition: {
|
|
11
|
+
...definition,
|
|
12
|
+
max,
|
|
13
|
+
},
|
|
14
|
+
}, (value, self) => value.length <= self.definition.max ? value : error.SymbolDataParserErrorIssue);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.checkerStringMax = checkerStringMax;
|
|
18
|
+
exports.dataParserCheckerStringMaxKind = dataParserCheckerStringMaxKind;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Kind } from "../../../../common";
|
|
2
|
+
import { type DataParserCheckerDefinition, type DataParserChecker } from "../../../../dataParser/base";
|
|
3
|
+
export interface DataParserCheckerDefinitionStringMax extends DataParserCheckerDefinition {
|
|
4
|
+
max: number;
|
|
5
|
+
}
|
|
6
|
+
export declare const dataParserCheckerStringMaxKind: import("../../../../common").KindHandler<import("../../../../common").KindDefinition<"@DataParser/checker-string-max", unknown>>;
|
|
7
|
+
type _DataParserCheckerStringMax = (Kind<typeof dataParserCheckerStringMaxKind.definition> & DataParserChecker<DataParserCheckerDefinitionStringMax, string>);
|
|
8
|
+
export interface DataParserCheckerStringMax extends _DataParserCheckerStringMax {
|
|
9
|
+
}
|
|
10
|
+
export declare function checkerStringMax(max: number, definition?: Partial<Omit<DataParserCheckerDefinitionStringMax, "max">>): DataParserCheckerStringMax;
|
|
11
|
+
export {};
|