@fgv/ts-utils 5.0.0-2 → 5.0.0-20
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/.vscode/launch.json +16 -0
- package/.vscode/settings.json +36 -0
- package/config/api-extractor.json +343 -0
- package/config/rig.json +16 -0
- package/dist/ts-utils.d.ts +20 -8
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/packlets/base/result.d.ts +8 -0
- package/lib/packlets/base/result.js +11 -0
- package/lib/packlets/hash/crcNormalizer.js +3 -1
- package/lib/packlets/validation/array.d.ts +2 -1
- package/lib/packlets/validation/array.js +2 -1
- package/lib/packlets/validation/common.d.ts +0 -8
- package/lib/packlets/validation/field.d.ts +1 -1
- package/lib/packlets/validation/field.js +1 -1
- package/lib/packlets/validation/genericValidator.d.ts +1 -6
- package/lib/packlets/validation/genericValidator.js +11 -11
- package/lib/packlets/validation/object.d.ts +1 -1
- package/lib/packlets/validation/object.js +1 -1
- package/lib/packlets/validation/oneOf.d.ts +2 -1
- package/lib/packlets/validation/oneOf.js +2 -1
- package/lib/packlets/validation/typeGuard.d.ts +3 -2
- package/lib/packlets/validation/typeGuard.js +2 -1
- package/lib/packlets/validation/validator.d.ts +7 -0
- package/lib/packlets/validation/validatorBase.d.ts +2 -1
- package/lib/packlets/validation/validatorBase.js +1 -1
- package/lib/packlets/validation/validators.d.ts +2 -2
- package/lib/packlets/validation/validators.js +3 -3
- package/lib/test/helpers/jest/helpers/fsHelpers.d.ts +52 -0
- package/lib/test/helpers/jest/helpers/fsHelpers.js +180 -0
- package/lib/test/helpers/jest/helpers/index.d.ts +2 -0
- package/lib/test/helpers/jest/helpers/index.js +18 -0
- package/lib/test/helpers/jest/index.d.ts +3 -0
- package/lib/test/helpers/jest/index.js +27 -0
- package/lib/test/helpers/jest/matchers/index.d.ts +16 -0
- package/lib/test/helpers/jest/matchers/index.js +19 -0
- package/lib/test/helpers/jest/matchers/toFail/index.d.ts +16 -0
- package/lib/test/helpers/jest/matchers/toFail/index.js +25 -0
- package/lib/test/helpers/jest/matchers/toFail/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toFail/predicate.js +9 -0
- package/lib/test/helpers/jest/matchers/toFailTest/index.d.ts +16 -0
- package/lib/test/helpers/jest/matchers/toFailTest/index.js +30 -0
- package/lib/test/helpers/jest/matchers/toFailTest/predicate.d.ts +3 -0
- package/lib/test/helpers/jest/matchers/toFailTest/predicate.js +12 -0
- package/lib/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/index.d.ts +17 -0
- package/lib/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/index.js +26 -0
- package/lib/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/predicate.js +15 -0
- package/lib/test/helpers/jest/matchers/toFailTestWith/index.d.ts +18 -0
- package/lib/test/helpers/jest/matchers/toFailTestWith/index.js +31 -0
- package/lib/test/helpers/jest/matchers/toFailTestWith/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toFailTestWith/predicate.js +30 -0
- package/lib/test/helpers/jest/matchers/toFailWith/index.d.ts +18 -0
- package/lib/test/helpers/jest/matchers/toFailWith/index.js +29 -0
- package/lib/test/helpers/jest/matchers/toFailWith/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toFailWith/predicate.js +20 -0
- package/lib/test/helpers/jest/matchers/toFailWithDetail/index.d.ts +19 -0
- package/lib/test/helpers/jest/matchers/toFailWithDetail/index.js +29 -0
- package/lib/test/helpers/jest/matchers/toFailWithDetail/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toFailWithDetail/predicate.js +26 -0
- package/lib/test/helpers/jest/matchers/toSucceed/index.d.ts +16 -0
- package/lib/test/helpers/jest/matchers/toSucceed/index.js +25 -0
- package/lib/test/helpers/jest/matchers/toSucceed/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toSucceed/predicate.js +9 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndMatchInlineSnapshot/index.d.ts +17 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndMatchInlineSnapshot/index.js +26 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndMatchSnapshot/index.d.ts +17 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndMatchSnapshot/index.js +26 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndSatisfy/index.d.ts +19 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndSatisfy/index.js +55 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndSatisfy/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toSucceedAndSatisfy/predicate.js +21 -0
- package/lib/test/helpers/jest/matchers/toSucceedWith/index.d.ts +18 -0
- package/lib/test/helpers/jest/matchers/toSucceedWith/index.js +29 -0
- package/lib/test/helpers/jest/matchers/toSucceedWith/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toSucceedWith/predicate.js +16 -0
- package/lib/test/helpers/jest/matchers/toSucceedWithDetail/index.d.ts +18 -0
- package/lib/test/helpers/jest/matchers/toSucceedWithDetail/index.js +29 -0
- package/lib/test/helpers/jest/matchers/toSucceedWithDetail/predicate.d.ts +4 -0
- package/lib/test/helpers/jest/matchers/toSucceedWithDetail/predicate.js +21 -0
- package/lib/test/helpers/jest/resolvers/cli.d.ts +5 -0
- package/lib/test/helpers/jest/resolvers/cli.js +48 -0
- package/lib/test/helpers/jest/resolvers/ide.d.ts +5 -0
- package/lib/test/helpers/jest/resolvers/ide.js +48 -0
- package/lib/test/helpers/jest/ts-utils.d.ts +2 -0
- package/lib/test/helpers/jest/ts-utils.js +18 -0
- package/lib/test/helpers/jest/types/index.d.ts +79 -0
- package/lib/test/helpers/jest/types/index.js +4 -0
- package/lib/test/helpers/jest/utils/matcherHelpers.d.ts +6 -0
- package/lib/test/helpers/jest/utils/matcherHelpers.js +53 -0
- package/lib/test/helpers/jest/utils/snapshotResolver.d.ts +4 -0
- package/lib/test/helpers/jest/utils/snapshotResolver.js +19 -0
- package/lib/test/unit/collections/collectible.test.d.ts +2 -0
- package/lib/test/unit/collections/collector.test.d.ts +2 -0
- package/lib/test/unit/collections/collectors.test.d.ts +2 -0
- package/lib/test/unit/collections/convertingCollector.test.d.ts +2 -0
- package/lib/test/unit/collections/helpers.d.ts +44 -0
- package/lib/test/unit/collections/helpers.js +115 -0
- package/lib/test/unit/collections/resultMap.test.d.ts +2 -0
- package/lib/test/unit/collections/validatingCollector.test.d.ts +2 -0
- package/lib/test/unit/collections/validatingConvertingCollector.test.d.ts +2 -0
- package/lib/test/unit/collections/validatingResultMap.test.d.ts +2 -0
- package/lib/test/unit/converter.test.d.ts +2 -0
- package/lib/test/unit/converters.test.d.ts +2 -0
- package/lib/test/unit/defaultingConverter.test.d.ts +2 -0
- package/lib/test/unit/file-tree/fileItem.test.d.ts +2 -0
- package/lib/test/unit/file-tree/fileTree.test.d.ts +2 -0
- package/lib/test/unit/file-tree/fsTree.test.d.ts +2 -0
- package/lib/test/unit/file-tree/inMemoryTree.test.d.ts +2 -0
- package/lib/test/unit/file-tree/sample/rootFile.json +1 -0
- package/lib/test/unit/file-tree/sample/some/other/path/file2.json +1 -0
- package/lib/test/unit/file-tree/sample/some/path/below/file4.json +1 -0
- package/lib/test/unit/file-tree/sample/some/path/file1.json +1 -0
- package/lib/test/unit/file-tree/sample/some/path/file3.json +1 -0
- package/lib/test/unit/hash.test.d.ts +2 -0
- package/lib/test/unit/logger.test.d.ts +2 -0
- package/lib/test/unit/mapResults.test.d.ts +3 -0
- package/lib/test/unit/messageAggregator.test.d.ts +3 -0
- package/lib/test/unit/normalize.test.d.ts +2 -0
- package/lib/test/unit/result.test.d.ts +3 -0
- package/lib/test/unit/utils.test.d.ts +3 -0
- package/lib/test/unit/validation/array.test.d.ts +2 -0
- package/lib/test/unit/validation/boolean.test.d.ts +2 -0
- package/lib/test/unit/validation/genericValidator.test.d.ts +2 -0
- package/lib/test/unit/validation/number.test.d.ts +2 -0
- package/lib/test/unit/validation/object.test.d.ts +2 -0
- package/lib/test/unit/validation/oneOf.test.d.ts +2 -0
- package/lib/test/unit/validation/recordOf.test.d.ts +2 -0
- package/lib/test/unit/validation/recursiveValidation.test.d.ts +2 -0
- package/lib/test/unit/validation/string.test.d.ts +2 -0
- package/lib/test/unit/validation/traits.test.d.ts +2 -0
- package/lib/test/unit/validation/typeGuard.test.d.ts +2 -0
- package/lib/test/unit/validation/validators.test.d.ts +2 -0
- package/package.json +9 -9
- package/src/index.ts +63 -0
- package/src/packlets/base/brand.ts +28 -0
- package/src/packlets/base/index.ts +31 -0
- package/src/packlets/base/logger.ts +156 -0
- package/src/packlets/base/mapResults.ts +302 -0
- package/src/packlets/base/messageAggregator.ts +120 -0
- package/src/packlets/base/normalize.ts +144 -0
- package/src/packlets/base/result.ts +961 -0
- package/src/packlets/base/utils.ts +236 -0
- package/src/packlets/collections/collectible.ts +238 -0
- package/src/packlets/collections/collector.ts +273 -0
- package/src/packlets/collections/collectorValidator.ts +178 -0
- package/src/packlets/collections/common.ts +27 -0
- package/src/packlets/collections/convertingCollector.ts +223 -0
- package/src/packlets/collections/convertingCollectorValidator.ts +164 -0
- package/src/packlets/collections/index.ts +39 -0
- package/src/packlets/collections/keyValueConverters.ts +142 -0
- package/src/packlets/collections/readonlyResultMap.ts +99 -0
- package/src/packlets/collections/resultMap.ts +322 -0
- package/src/packlets/collections/resultMapValidator.ts +188 -0
- package/src/packlets/collections/utils.ts +33 -0
- package/src/packlets/collections/validatingCollector.ts +123 -0
- package/src/packlets/collections/validatingConvertingCollector.ts +113 -0
- package/src/packlets/collections/validatingResultMap.ts +94 -0
- package/src/packlets/conversion/baseConverter.ts +330 -0
- package/src/packlets/conversion/converter.ts +260 -0
- package/src/packlets/conversion/converters.ts +1039 -0
- package/src/packlets/conversion/defaultingConverter.ts +188 -0
- package/src/packlets/conversion/index.ts +30 -0
- package/src/packlets/conversion/objectConverter.ts +259 -0
- package/src/packlets/conversion/stringConverter.ts +165 -0
- package/src/packlets/file-tree/directoryItem.ts +84 -0
- package/src/packlets/file-tree/fileItem.ts +119 -0
- package/src/packlets/file-tree/fileTree.ts +152 -0
- package/src/packlets/file-tree/fileTreeAccessors.ts +176 -0
- package/src/packlets/file-tree/fsTree.ts +118 -0
- package/src/packlets/file-tree/in-memory/inMemoryTree.ts +171 -0
- package/src/packlets/file-tree/in-memory/index.ts +23 -0
- package/src/packlets/file-tree/in-memory/treeBuilder.ts +203 -0
- package/src/packlets/file-tree/index.ts +31 -0
- package/src/packlets/hash/crcNormalizer.ts +81 -0
- package/src/packlets/hash/hashingNormalizer.ts +102 -0
- package/src/packlets/hash/index.ts +24 -0
- package/src/packlets/validation/array.ts +84 -0
- package/src/packlets/validation/boolean.ts +63 -0
- package/src/packlets/validation/classes.ts +38 -0
- package/src/packlets/validation/common.ts +28 -0
- package/src/packlets/validation/field.ts +99 -0
- package/src/packlets/validation/genericValidator.ts +204 -0
- package/src/packlets/validation/index.ts +31 -0
- package/src/packlets/validation/number.ts +66 -0
- package/src/packlets/validation/object.ts +208 -0
- package/src/packlets/validation/oneOf.ts +78 -0
- package/src/packlets/validation/string.ts +66 -0
- package/src/packlets/validation/traits.ts +113 -0
- package/src/packlets/validation/typeGuard.ts +83 -0
- package/src/packlets/validation/validator.ts +157 -0
- package/src/packlets/validation/validatorBase.ts +66 -0
- package/src/packlets/validation/validators.ts +254 -0
- package/CHANGELOG.md +0 -135
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/packlets/base/brand.d.ts.map +0 -1
- package/lib/packlets/base/brand.js.map +0 -1
- package/lib/packlets/base/index.d.ts.map +0 -1
- package/lib/packlets/base/index.js.map +0 -1
- package/lib/packlets/base/logger.d.ts.map +0 -1
- package/lib/packlets/base/logger.js.map +0 -1
- package/lib/packlets/base/mapResults.d.ts.map +0 -1
- package/lib/packlets/base/mapResults.js.map +0 -1
- package/lib/packlets/base/messageAggregator.d.ts.map +0 -1
- package/lib/packlets/base/messageAggregator.js.map +0 -1
- package/lib/packlets/base/normalize.d.ts.map +0 -1
- package/lib/packlets/base/normalize.js.map +0 -1
- package/lib/packlets/base/result.d.ts.map +0 -1
- package/lib/packlets/base/result.js.map +0 -1
- package/lib/packlets/base/utils.d.ts.map +0 -1
- package/lib/packlets/base/utils.js.map +0 -1
- package/lib/packlets/collections/collectible.d.ts.map +0 -1
- package/lib/packlets/collections/collectible.js.map +0 -1
- package/lib/packlets/collections/collector.d.ts.map +0 -1
- package/lib/packlets/collections/collector.js.map +0 -1
- package/lib/packlets/collections/collectorValidator.d.ts.map +0 -1
- package/lib/packlets/collections/collectorValidator.js.map +0 -1
- package/lib/packlets/collections/common.d.ts.map +0 -1
- package/lib/packlets/collections/common.js.map +0 -1
- package/lib/packlets/collections/convertingCollector.d.ts.map +0 -1
- package/lib/packlets/collections/convertingCollector.js.map +0 -1
- package/lib/packlets/collections/convertingCollectorValidator.d.ts.map +0 -1
- package/lib/packlets/collections/convertingCollectorValidator.js.map +0 -1
- package/lib/packlets/collections/index.d.ts.map +0 -1
- package/lib/packlets/collections/index.js.map +0 -1
- package/lib/packlets/collections/keyValueConverters.d.ts.map +0 -1
- package/lib/packlets/collections/keyValueConverters.js.map +0 -1
- package/lib/packlets/collections/readonlyResultMap.d.ts.map +0 -1
- package/lib/packlets/collections/readonlyResultMap.js.map +0 -1
- package/lib/packlets/collections/resultMap.d.ts.map +0 -1
- package/lib/packlets/collections/resultMap.js.map +0 -1
- package/lib/packlets/collections/resultMapValidator.d.ts.map +0 -1
- package/lib/packlets/collections/resultMapValidator.js.map +0 -1
- package/lib/packlets/collections/utils.d.ts.map +0 -1
- package/lib/packlets/collections/utils.js.map +0 -1
- package/lib/packlets/collections/validatingCollector.d.ts.map +0 -1
- package/lib/packlets/collections/validatingCollector.js.map +0 -1
- package/lib/packlets/collections/validatingConvertingCollector.d.ts.map +0 -1
- package/lib/packlets/collections/validatingConvertingCollector.js.map +0 -1
- package/lib/packlets/collections/validatingResultMap.d.ts.map +0 -1
- package/lib/packlets/collections/validatingResultMap.js.map +0 -1
- package/lib/packlets/conversion/baseConverter.d.ts.map +0 -1
- package/lib/packlets/conversion/baseConverter.js.map +0 -1
- package/lib/packlets/conversion/converter.d.ts.map +0 -1
- package/lib/packlets/conversion/converter.js.map +0 -1
- package/lib/packlets/conversion/converters.d.ts.map +0 -1
- package/lib/packlets/conversion/converters.js.map +0 -1
- package/lib/packlets/conversion/defaultingConverter.d.ts.map +0 -1
- package/lib/packlets/conversion/defaultingConverter.js.map +0 -1
- package/lib/packlets/conversion/index.d.ts.map +0 -1
- package/lib/packlets/conversion/index.js.map +0 -1
- package/lib/packlets/conversion/objectConverter.d.ts.map +0 -1
- package/lib/packlets/conversion/objectConverter.js.map +0 -1
- package/lib/packlets/conversion/stringConverter.d.ts.map +0 -1
- package/lib/packlets/conversion/stringConverter.js.map +0 -1
- package/lib/packlets/file-tree/directoryItem.d.ts.map +0 -1
- package/lib/packlets/file-tree/directoryItem.js.map +0 -1
- package/lib/packlets/file-tree/fileItem.d.ts.map +0 -1
- package/lib/packlets/file-tree/fileItem.js.map +0 -1
- package/lib/packlets/file-tree/fileTree.d.ts.map +0 -1
- package/lib/packlets/file-tree/fileTree.js.map +0 -1
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts.map +0 -1
- package/lib/packlets/file-tree/fileTreeAccessors.js.map +0 -1
- package/lib/packlets/file-tree/fsTree.d.ts.map +0 -1
- package/lib/packlets/file-tree/fsTree.js.map +0 -1
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts.map +0 -1
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js.map +0 -1
- package/lib/packlets/file-tree/in-memory/index.d.ts.map +0 -1
- package/lib/packlets/file-tree/in-memory/index.js.map +0 -1
- package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts.map +0 -1
- package/lib/packlets/file-tree/in-memory/treeBuilder.js.map +0 -1
- package/lib/packlets/file-tree/index.d.ts.map +0 -1
- package/lib/packlets/file-tree/index.js.map +0 -1
- package/lib/packlets/hash/crcNormalizer.d.ts.map +0 -1
- package/lib/packlets/hash/crcNormalizer.js.map +0 -1
- package/lib/packlets/hash/hashingNormalizer.d.ts.map +0 -1
- package/lib/packlets/hash/hashingNormalizer.js.map +0 -1
- package/lib/packlets/hash/index.d.ts.map +0 -1
- package/lib/packlets/hash/index.js.map +0 -1
- package/lib/packlets/validation/array.d.ts.map +0 -1
- package/lib/packlets/validation/array.js.map +0 -1
- package/lib/packlets/validation/boolean.d.ts.map +0 -1
- package/lib/packlets/validation/boolean.js.map +0 -1
- package/lib/packlets/validation/classes.d.ts.map +0 -1
- package/lib/packlets/validation/classes.js.map +0 -1
- package/lib/packlets/validation/common.d.ts.map +0 -1
- package/lib/packlets/validation/common.js.map +0 -1
- package/lib/packlets/validation/field.d.ts.map +0 -1
- package/lib/packlets/validation/field.js.map +0 -1
- package/lib/packlets/validation/genericValidator.d.ts.map +0 -1
- package/lib/packlets/validation/genericValidator.js.map +0 -1
- package/lib/packlets/validation/index.d.ts.map +0 -1
- package/lib/packlets/validation/index.js.map +0 -1
- package/lib/packlets/validation/number.d.ts.map +0 -1
- package/lib/packlets/validation/number.js.map +0 -1
- package/lib/packlets/validation/object.d.ts.map +0 -1
- package/lib/packlets/validation/object.js.map +0 -1
- package/lib/packlets/validation/oneOf.d.ts.map +0 -1
- package/lib/packlets/validation/oneOf.js.map +0 -1
- package/lib/packlets/validation/string.d.ts.map +0 -1
- package/lib/packlets/validation/string.js.map +0 -1
- package/lib/packlets/validation/traits.d.ts.map +0 -1
- package/lib/packlets/validation/traits.js.map +0 -1
- package/lib/packlets/validation/typeGuard.d.ts.map +0 -1
- package/lib/packlets/validation/typeGuard.js.map +0 -1
- package/lib/packlets/validation/validator.d.ts.map +0 -1
- package/lib/packlets/validation/validator.js.map +0 -1
- package/lib/packlets/validation/validatorBase.d.ts.map +0 -1
- package/lib/packlets/validation/validatorBase.js.map +0 -1
- package/lib/packlets/validation/validators.d.ts.map +0 -1
- package/lib/packlets/validation/validators.js.map +0 -1
|
@@ -59,7 +59,7 @@ class GenericValidator {
|
|
|
59
59
|
* {@inheritdoc Validation.Validator.validate}
|
|
60
60
|
*/
|
|
61
61
|
validate(from, context) {
|
|
62
|
-
const result = this._validator(from, this._context(context));
|
|
62
|
+
const result = this._validator(from, this._context(context), this);
|
|
63
63
|
if (typeof result === 'boolean') {
|
|
64
64
|
return result ? (0, base_1.succeed)(from) : (0, base_1.fail)('Invalid value');
|
|
65
65
|
}
|
|
@@ -69,7 +69,7 @@ class GenericValidator {
|
|
|
69
69
|
* {@inheritdoc Validation.Validator.convert}
|
|
70
70
|
*/
|
|
71
71
|
convert(from, context) {
|
|
72
|
-
const result = this._validator(from, this._context(context));
|
|
72
|
+
const result = this._validator(from, this._context(context), this);
|
|
73
73
|
if (typeof result === 'boolean') {
|
|
74
74
|
return result ? (0, base_1.succeed)(from) : (0, base_1.fail)('Invalid value');
|
|
75
75
|
}
|
|
@@ -85,15 +85,15 @@ class GenericValidator {
|
|
|
85
85
|
* {@inheritdoc Validation.Validator.guard}
|
|
86
86
|
*/
|
|
87
87
|
guard(from, context) {
|
|
88
|
-
return this._validator(from, this._context(context)) === true;
|
|
88
|
+
return this._validator(from, this._context(context), this) === true;
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* {@inheritdoc Validation.Validator.optional}
|
|
92
92
|
*/
|
|
93
93
|
optional() {
|
|
94
94
|
return new GenericValidator({
|
|
95
|
-
validator: (from, context) => {
|
|
96
|
-
return from === undefined || this._validator(from, this._context(context));
|
|
95
|
+
validator: (from, context, self) => {
|
|
96
|
+
return from === undefined || this._validator(from, this._context(context), this);
|
|
97
97
|
},
|
|
98
98
|
traits: { isOptional: true }
|
|
99
99
|
});
|
|
@@ -104,8 +104,8 @@ class GenericValidator {
|
|
|
104
104
|
withConstraint(constraint, trait) {
|
|
105
105
|
trait = trait !== null && trait !== void 0 ? trait : { type: 'function' };
|
|
106
106
|
return new GenericValidator({
|
|
107
|
-
validator: (from, context) => {
|
|
108
|
-
const result = this._validator(from, this._context(context));
|
|
107
|
+
validator: (from, context, self) => {
|
|
108
|
+
const result = this._validator(from, this._context(context), this);
|
|
109
109
|
if (result === true) {
|
|
110
110
|
const constraintResult = constraint(from);
|
|
111
111
|
if (typeof constraintResult === 'boolean') {
|
|
@@ -128,8 +128,8 @@ class GenericValidator {
|
|
|
128
128
|
throw new Error(`Cannot replace existing brand "${this.brand}" with "${brand}".`);
|
|
129
129
|
}
|
|
130
130
|
return new GenericValidator({
|
|
131
|
-
validator: (from, context) => {
|
|
132
|
-
return this._validator(from, this._context(context));
|
|
131
|
+
validator: (from, context, self) => {
|
|
132
|
+
return this._validator(from, this._context(context), this);
|
|
133
133
|
},
|
|
134
134
|
traits: { brand }
|
|
135
135
|
});
|
|
@@ -139,8 +139,8 @@ class GenericValidator {
|
|
|
139
139
|
*/
|
|
140
140
|
withFormattedError(formatter) {
|
|
141
141
|
return new GenericValidator({
|
|
142
|
-
validator: (from, context) => {
|
|
143
|
-
const result = this._validator(from, this._context(context));
|
|
142
|
+
validator: (from, context, self) => {
|
|
143
|
+
const result = this._validator(from, this._context(context), this);
|
|
144
144
|
if (result === true) {
|
|
145
145
|
return true;
|
|
146
146
|
}
|
|
@@ -110,6 +110,6 @@ export declare class ObjectValidator<T, TC = unknown> extends ValidatorBase<T, T
|
|
|
110
110
|
* {@inheritdoc Validation.ValidatorBase._validate}
|
|
111
111
|
* @internal
|
|
112
112
|
*/
|
|
113
|
-
protected _validate(from: unknown, context?: TC): boolean | Failure<T>;
|
|
113
|
+
protected _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T>;
|
|
114
114
|
}
|
|
115
115
|
//# sourceMappingURL=object.d.ts.map
|
|
@@ -109,7 +109,7 @@ class ObjectValidator extends validatorBase_1.ValidatorBase {
|
|
|
109
109
|
* {@inheritdoc Validation.ValidatorBase._validate}
|
|
110
110
|
* @internal
|
|
111
111
|
*/
|
|
112
|
-
_validate(from, context) {
|
|
112
|
+
_validate(from, context, self) {
|
|
113
113
|
if (typeof from !== 'object' || from === null || Array.isArray(from)) {
|
|
114
114
|
return (0, base_1.fail)('source is not an object');
|
|
115
115
|
}
|
|
@@ -31,9 +31,10 @@ export declare class OneOfValidator<T, TC = unknown> extends ValidatorBase<T, TC
|
|
|
31
31
|
* of the configured validators.
|
|
32
32
|
* @param from - The `unknown` value to be tested.
|
|
33
33
|
* @param context - Optional validation context will be propagated to element validator.
|
|
34
|
+
* @param self - Optional self-reference for recursive validation.
|
|
34
35
|
* @returns Returns `true` if `from` is an `array` of valid elements, or
|
|
35
36
|
* {@link Failure} with an error message if not.
|
|
36
37
|
*/
|
|
37
|
-
protected _validate<T>(from: unknown, context?: TC): boolean | Failure<T>;
|
|
38
|
+
protected _validate<T>(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T>;
|
|
38
39
|
}
|
|
39
40
|
//# sourceMappingURL=oneOf.d.ts.map
|
|
@@ -46,10 +46,11 @@ class OneOfValidator extends validatorBase_1.ValidatorBase {
|
|
|
46
46
|
* of the configured validators.
|
|
47
47
|
* @param from - The `unknown` value to be tested.
|
|
48
48
|
* @param context - Optional validation context will be propagated to element validator.
|
|
49
|
+
* @param self - Optional self-reference for recursive validation.
|
|
49
50
|
* @returns Returns `true` if `from` is an `array` of valid elements, or
|
|
50
51
|
* {@link Failure} with an error message if not.
|
|
51
52
|
*/
|
|
52
|
-
_validate(from, context) {
|
|
53
|
+
_validate(from, context, self) {
|
|
53
54
|
const found = this._validators.some((v) => v.validate(from).success);
|
|
54
55
|
if (found) {
|
|
55
56
|
return true;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Failure } from '../base';
|
|
2
2
|
import { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';
|
|
3
3
|
import { TypeGuardWithContext } from './common';
|
|
4
|
-
import { ValidatorOptions } from './validator';
|
|
4
|
+
import { Validator, ValidatorOptions } from './validator';
|
|
5
5
|
/**
|
|
6
6
|
* Parameters used to construct a {@link Validation.Classes.TypeGuardValidator}.
|
|
7
7
|
* @public
|
|
@@ -34,10 +34,11 @@ export declare class TypeGuardValidator<T, TC = unknown> extends ValidatorBase<T
|
|
|
34
34
|
* type guard, returning a `Failure<T>` containing more information about a failure.
|
|
35
35
|
* @param from - Value to be converted.
|
|
36
36
|
* @param context - Optional validation context.
|
|
37
|
+
* @param self - Optional self-reference for recursive validation.
|
|
37
38
|
* @returns `true` if `from` is valid, {@link Failure | Failure<T>}
|
|
38
39
|
* with an error message if `from` is invalid.
|
|
39
40
|
* @internal
|
|
40
41
|
*/
|
|
41
|
-
protected _validate(from: unknown, context?: TC): boolean | Failure<T>;
|
|
42
|
+
protected _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T>;
|
|
42
43
|
}
|
|
43
44
|
//# sourceMappingURL=typeGuard.d.ts.map
|
|
@@ -47,11 +47,12 @@ class TypeGuardValidator extends validatorBase_1.ValidatorBase {
|
|
|
47
47
|
* type guard, returning a `Failure<T>` containing more information about a failure.
|
|
48
48
|
* @param from - Value to be converted.
|
|
49
49
|
* @param context - Optional validation context.
|
|
50
|
+
* @param self - Optional self-reference for recursive validation.
|
|
50
51
|
* @returns `true` if `from` is valid, {@link Failure | Failure<T>}
|
|
51
52
|
* with an error message if `from` is invalid.
|
|
52
53
|
* @internal
|
|
53
54
|
*/
|
|
54
|
-
_validate(from, context) {
|
|
55
|
+
_validate(from, context, self) {
|
|
55
56
|
if (this._guard(from, context)) {
|
|
56
57
|
return true;
|
|
57
58
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { Brand, Failure, Result } from '../base';
|
|
2
2
|
import { ConstraintTrait, ValidatorTraits } from './traits';
|
|
3
|
+
/**
|
|
4
|
+
* Type for a validation function, which validates that a supplied `unknown`
|
|
5
|
+
* value is a valid value of type `<T>`, possibly as influenced by
|
|
6
|
+
* an optionally-supplied validation context of type `<TC>`.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export type ValidatorFunc<T, TC> = (from: unknown, context?: TC, self?: Validator<T, TC>) => boolean | Failure<T>;
|
|
3
10
|
/**
|
|
4
11
|
* Options that apply to any {@link Validation.Validator | Validator}.
|
|
5
12
|
* @public
|
|
@@ -19,10 +19,11 @@ export declare abstract class ValidatorBase<T, TC = unknown> extends GenericVali
|
|
|
19
19
|
* Abstract validation method to me implemented by derived classes.
|
|
20
20
|
* @param from - Value to be converted.
|
|
21
21
|
* @param context - Optional validation context.
|
|
22
|
+
* @param self - Optional self-reference for recursive validation.
|
|
22
23
|
* @returns `true` if `from` is valid, {@link Failure | Failure<T>}
|
|
23
24
|
* with an error message if `from` is invalid.
|
|
24
25
|
* @internal
|
|
25
26
|
*/
|
|
26
|
-
protected abstract _validate(from: unknown, context?: TC): boolean | Failure<T>;
|
|
27
|
+
protected abstract _validate(from: unknown, context?: TC, self?: import('./validator').Validator<T, TC>): boolean | Failure<T>;
|
|
27
28
|
}
|
|
28
29
|
//# sourceMappingURL=validatorBase.d.ts.map
|
|
@@ -34,7 +34,7 @@ class ValidatorBase extends genericValidator_1.GenericValidator {
|
|
|
34
34
|
* @internal
|
|
35
35
|
*/
|
|
36
36
|
constructor(params) {
|
|
37
|
-
super(Object.assign({ validator: (from, context) => this._validate(from, context) }, params));
|
|
37
|
+
super(Object.assign({ validator: (from, context, self) => this._validate(from, context, self) }, params));
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
exports.ValidatorBase = ValidatorBase;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ArrayValidator, ArrayValidatorConstructorParams } from './array';
|
|
2
2
|
import { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams } from './object';
|
|
3
3
|
import { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';
|
|
4
|
-
import { TypeGuardWithContext
|
|
4
|
+
import { TypeGuardWithContext } from './common';
|
|
5
5
|
import { OneOfValidator, OneOfValidatorConstructorParams } from './oneOf';
|
|
6
|
-
import { Validator } from './validator';
|
|
6
|
+
import { Validator, ValidatorFunc } from './validator';
|
|
7
7
|
/**
|
|
8
8
|
* A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.
|
|
9
9
|
* @public
|
|
@@ -94,7 +94,7 @@ function arrayOf(validateElement, params) {
|
|
|
94
94
|
function recordOf(validator, options) {
|
|
95
95
|
const opts = Object.assign({ onError: 'fail' }, options);
|
|
96
96
|
return new genericValidator_1.GenericValidator({
|
|
97
|
-
validator: (from, context) => {
|
|
97
|
+
validator: (from, context, self) => {
|
|
98
98
|
if (typeof from !== 'object' || from === null || Array.isArray(from)) {
|
|
99
99
|
return (0, base_1.fail)(`Not a string-keyed object: ${JSON.stringify(from)}`);
|
|
100
100
|
}
|
|
@@ -139,7 +139,7 @@ function recordOf(validator, options) {
|
|
|
139
139
|
*/
|
|
140
140
|
function enumeratedValue(values) {
|
|
141
141
|
return new genericValidator_1.GenericValidator({
|
|
142
|
-
validator: (from, context) => {
|
|
142
|
+
validator: (from, context, self) => {
|
|
143
143
|
if (typeof from === 'string') {
|
|
144
144
|
const v = context !== null && context !== void 0 ? context : values;
|
|
145
145
|
const index = v.indexOf(from);
|
|
@@ -156,7 +156,7 @@ function enumeratedValue(values) {
|
|
|
156
156
|
*/
|
|
157
157
|
function literal(value) {
|
|
158
158
|
return new genericValidator_1.GenericValidator({
|
|
159
|
-
validator: (from) => {
|
|
159
|
+
validator: (from, context, self) => {
|
|
160
160
|
return from === value
|
|
161
161
|
? true
|
|
162
162
|
: (0, base_1.fail)(`Expected literal ${String(value)}, found "${JSON.stringify(from, undefined, 2)}`);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
export interface IMockFileConfig {
|
|
5
|
+
path: string;
|
|
6
|
+
backingFile?: string;
|
|
7
|
+
payload?: string;
|
|
8
|
+
writable?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare class ReadWriteSpies {
|
|
14
|
+
readonly read: jest.SpyInstance;
|
|
15
|
+
readonly write: jest.SpyInstance;
|
|
16
|
+
constructor(read: jest.SpyInstance, write: jest.SpyInstance);
|
|
17
|
+
clear(): void;
|
|
18
|
+
restore(): void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface IMockFileSystemOptions {
|
|
24
|
+
mockWriteOnly?: boolean;
|
|
25
|
+
allowUnknownMockWrite?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
type ReadFunc = (path: string | number | Buffer | URL, options?: {
|
|
31
|
+
encoding?: null;
|
|
32
|
+
flag?: string;
|
|
33
|
+
} | null) => Buffer;
|
|
34
|
+
/**
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export declare class MockFileSystem {
|
|
38
|
+
protected readonly _options?: IMockFileSystemOptions;
|
|
39
|
+
protected readonly _config: Map<string, IMockFileConfig>;
|
|
40
|
+
protected readonly _data: Map<string, string>;
|
|
41
|
+
protected readonly _realReadFileSync: ReadFunc;
|
|
42
|
+
protected readonly _extraWrites: string[];
|
|
43
|
+
constructor(configs: Iterable<IMockFileConfig>, options?: IMockFileSystemOptions);
|
|
44
|
+
readMockFileSync(wanted: string): string;
|
|
45
|
+
writeMockFileSync(wanted: string, body: string): void;
|
|
46
|
+
getExtraFilesWritten(): string[];
|
|
47
|
+
tryGetPayload(want: string): string | undefined;
|
|
48
|
+
reset(): void;
|
|
49
|
+
startSpies(): ReadWriteSpies;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=fsHelpers.d.ts.map
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2020 Erik Fortune
|
|
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.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}) : function(o, v) {
|
|
37
|
+
o["default"] = v;
|
|
38
|
+
});
|
|
39
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
+
var ownKeys = function(o) {
|
|
41
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
+
var ar = [];
|
|
43
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
+
return ar;
|
|
45
|
+
};
|
|
46
|
+
return ownKeys(o);
|
|
47
|
+
};
|
|
48
|
+
return function (mod) {
|
|
49
|
+
if (mod && mod.__esModule) return mod;
|
|
50
|
+
var result = {};
|
|
51
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
+
__setModuleDefault(result, mod);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
56
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
57
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
58
|
+
};
|
|
59
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
+
exports.MockFileSystem = exports.ReadWriteSpies = void 0;
|
|
61
|
+
const fs_1 = __importDefault(require("fs"));
|
|
62
|
+
const path = __importStar(require("path"));
|
|
63
|
+
/**
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
class ReadWriteSpies {
|
|
67
|
+
constructor(read, write) {
|
|
68
|
+
this.read = read;
|
|
69
|
+
this.write = write;
|
|
70
|
+
}
|
|
71
|
+
clear() {
|
|
72
|
+
this.read.mockClear();
|
|
73
|
+
this.write.mockClear();
|
|
74
|
+
}
|
|
75
|
+
restore() {
|
|
76
|
+
this.read.mockRestore();
|
|
77
|
+
this.write.mockRestore();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.ReadWriteSpies = ReadWriteSpies;
|
|
81
|
+
/**
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
class MockFileSystem {
|
|
85
|
+
constructor(configs, options) {
|
|
86
|
+
this._extraWrites = [];
|
|
87
|
+
this._config = new Map();
|
|
88
|
+
this._data = new Map();
|
|
89
|
+
this._options = options;
|
|
90
|
+
this._realReadFileSync = fs_1.default.readFileSync;
|
|
91
|
+
for (const config of configs) {
|
|
92
|
+
const fullPath = path.resolve(config.path);
|
|
93
|
+
this._config.set(fullPath, config);
|
|
94
|
+
if (config.backingFile) {
|
|
95
|
+
this.readMockFileSync(fullPath);
|
|
96
|
+
}
|
|
97
|
+
else if (config.payload) {
|
|
98
|
+
this._data.set(fullPath, config.payload);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
readMockFileSync(wanted) {
|
|
103
|
+
var _a;
|
|
104
|
+
const fullPathWanted = path.resolve(wanted);
|
|
105
|
+
if (!this._data.has(fullPathWanted)) {
|
|
106
|
+
const config = this._config.get(fullPathWanted);
|
|
107
|
+
if ((config === null || config === void 0 ? void 0 : config.backingFile) === undefined) {
|
|
108
|
+
if (((_a = this._options) === null || _a === void 0 ? void 0 : _a.mockWriteOnly) !== true) {
|
|
109
|
+
throw new Error(`Mock file not found: ${wanted}`);
|
|
110
|
+
}
|
|
111
|
+
const body = this._realReadFileSync(fullPathWanted).toString();
|
|
112
|
+
this._data.set(fullPathWanted, body);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const fullBackingPath = path.resolve(config.backingFile);
|
|
116
|
+
const body = this._realReadFileSync(fullBackingPath).toString();
|
|
117
|
+
this._data.set(fullPathWanted, body);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const payload = this._data.get(fullPathWanted);
|
|
121
|
+
// not actually reproducible right now
|
|
122
|
+
/* c8 ignore next 3 */
|
|
123
|
+
if (payload === undefined) {
|
|
124
|
+
throw new Error(`Mock file ${wanted} payload is undefined.`);
|
|
125
|
+
}
|
|
126
|
+
return payload;
|
|
127
|
+
}
|
|
128
|
+
writeMockFileSync(wanted, body) {
|
|
129
|
+
var _a;
|
|
130
|
+
const fullPathWanted = path.resolve(wanted);
|
|
131
|
+
const config = this._config.get(fullPathWanted);
|
|
132
|
+
if (config === undefined) {
|
|
133
|
+
if (((_a = this._options) === null || _a === void 0 ? void 0 : _a.allowUnknownMockWrite) !== true) {
|
|
134
|
+
throw new Error(`Mock path not found: ${wanted}`);
|
|
135
|
+
}
|
|
136
|
+
this._extraWrites.push(fullPathWanted);
|
|
137
|
+
}
|
|
138
|
+
else if (config.writable !== true) {
|
|
139
|
+
throw new Error(`Mock permission denied: ${wanted}`);
|
|
140
|
+
}
|
|
141
|
+
this._data.set(fullPathWanted, body);
|
|
142
|
+
}
|
|
143
|
+
getExtraFilesWritten() {
|
|
144
|
+
return Array.from(this._extraWrites);
|
|
145
|
+
}
|
|
146
|
+
tryGetPayload(want) {
|
|
147
|
+
return this._data.get(path.resolve(want));
|
|
148
|
+
}
|
|
149
|
+
reset() {
|
|
150
|
+
const writable = Array.from(this._config.values()).filter((c) => c.writable === true);
|
|
151
|
+
for (const config of writable) {
|
|
152
|
+
this._data.delete(path.resolve(config.path));
|
|
153
|
+
if (config.backingFile) {
|
|
154
|
+
this.readMockFileSync(path.resolve(config.path));
|
|
155
|
+
}
|
|
156
|
+
else if (config.payload) {
|
|
157
|
+
this._data.set(path.resolve(config.path), config.payload);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
for (const path of this._extraWrites) {
|
|
161
|
+
this._data.delete(path);
|
|
162
|
+
}
|
|
163
|
+
this._extraWrites.splice(0, this._extraWrites.length);
|
|
164
|
+
}
|
|
165
|
+
startSpies() {
|
|
166
|
+
return new ReadWriteSpies(jest.spyOn(fs_1.default, 'readFileSync').mockImplementation((wanted) => {
|
|
167
|
+
if (typeof wanted !== 'string') {
|
|
168
|
+
throw new Error('readFileSync mock supports only string parameters');
|
|
169
|
+
}
|
|
170
|
+
return this.readMockFileSync(wanted);
|
|
171
|
+
}), jest.spyOn(fs_1.default, 'writeFileSync').mockImplementation((wanted, payload) => {
|
|
172
|
+
if (typeof wanted !== 'string' || typeof payload !== 'string') {
|
|
173
|
+
throw new Error('writeFileSync mock supports only string parameters');
|
|
174
|
+
}
|
|
175
|
+
return this.writeMockFileSync(wanted, payload);
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.MockFileSystem = MockFileSystem;
|
|
180
|
+
//# sourceMappingURL=fsHelpers.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./fsHelpers"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MockFileSystem = void 0;
|
|
7
|
+
const matchers_1 = __importDefault(require("./matchers"));
|
|
8
|
+
require("./types");
|
|
9
|
+
var helpers_1 = require("./helpers");
|
|
10
|
+
Object.defineProperty(exports, "MockFileSystem", { enumerable: true, get: function () { return helpers_1.MockFileSystem; } });
|
|
11
|
+
// eslint-disable-next-line no-undef
|
|
12
|
+
function isJestGlobal(g) {
|
|
13
|
+
return g.hasOwnProperty('expect');
|
|
14
|
+
}
|
|
15
|
+
/* c8 ignore else */
|
|
16
|
+
if (isJestGlobal(global)) {
|
|
17
|
+
global.expect.extend(matchers_1.default);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
/* eslint-disable no-console */
|
|
21
|
+
console.error([
|
|
22
|
+
"Unable to find Jest's global expect",
|
|
23
|
+
'Please check that you have added ts-utils-jest correctly to your jest configuration.'
|
|
24
|
+
].join('\n'));
|
|
25
|
+
/* eslint-enable no-console */
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
toSucceedWithDetail: <T extends import("../ts-utils").DetailedResult<unknown, unknown>>(received: T, expected: import("../ts-utils").ResultValueType<T> | RegExp, detail: import("../ts-utils").ResultDetailType<T> | undefined) => jest.CustomMatcherResult;
|
|
3
|
+
toSucceedWith: <T extends import("../ts-utils").Result<unknown>>(received: T, expected: import("../ts-utils").ResultValueType<T> | RegExp) => jest.CustomMatcherResult;
|
|
4
|
+
toSucceedAndSatisfy: <T>(this: jest.MatcherContext, received: import("../ts-utils").Result<T>, test: (value: T) => boolean | void) => jest.CustomMatcherResult;
|
|
5
|
+
toSucceedAndMatchSnapshot: <T>(this: jest.MatcherContext, received: import("../ts-utils").Result<T>) => jest.CustomMatcherResult;
|
|
6
|
+
toSucceedAndMatchInlineSnapshot: <T>(this: jest.MatcherContext, received: import("../ts-utils").Result<T>, snapshot: string | undefined) => jest.CustomMatcherResult;
|
|
7
|
+
toSucceed: <T>(received: import("../ts-utils").Result<T>) => jest.CustomMatcherResult;
|
|
8
|
+
toFailWithDetail: <T extends import("../ts-utils").DetailedResult<unknown, unknown>>(received: T, expectedMessage: string | RegExp | undefined, expectedDetail: import("../ts-utils").ResultDetailType<T>) => jest.CustomMatcherResult;
|
|
9
|
+
toFailWith: <T>(received: import("../ts-utils").Result<T>, expected: string | RegExp | undefined) => jest.CustomMatcherResult;
|
|
10
|
+
toFailTestWith: <T>(cb: () => void, expected: RegExp | string | string[]) => jest.CustomMatcherResult;
|
|
11
|
+
toFailTestAndMatchSnapshot: <T>(this: jest.MatcherContext, cb: () => void) => jest.CustomMatcherResult;
|
|
12
|
+
toFailTest: <T>(cb: () => void) => jest.CustomMatcherResult;
|
|
13
|
+
toFail: <T extends import("../ts-utils").Result<unknown>>(received: T) => jest.CustomMatcherResult;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const toFail_1 = __importDefault(require("./toFail"));
|
|
7
|
+
const toFailTest_1 = __importDefault(require("./toFailTest"));
|
|
8
|
+
const toFailTestAndMatchSnapshot_1 = __importDefault(require("./toFailTestAndMatchSnapshot"));
|
|
9
|
+
const toFailTestWith_1 = __importDefault(require("./toFailTestWith"));
|
|
10
|
+
const toFailWith_1 = __importDefault(require("./toFailWith"));
|
|
11
|
+
const toFailWithDetail_1 = __importDefault(require("./toFailWithDetail"));
|
|
12
|
+
const toSucceed_1 = __importDefault(require("./toSucceed"));
|
|
13
|
+
const toSucceedAndMatchInlineSnapshot_1 = __importDefault(require("./toSucceedAndMatchInlineSnapshot"));
|
|
14
|
+
const toSucceedAndMatchSnapshot_1 = __importDefault(require("./toSucceedAndMatchSnapshot"));
|
|
15
|
+
const toSucceedAndSatisfy_1 = __importDefault(require("./toSucceedAndSatisfy"));
|
|
16
|
+
const toSucceedWith_1 = __importDefault(require("./toSucceedWith"));
|
|
17
|
+
const toSucceedWithDetail_1 = __importDefault(require("./toSucceedWithDetail"));
|
|
18
|
+
exports.default = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, toFail_1.default), toFailTest_1.default), toFailTestAndMatchSnapshot_1.default), toFailTestWith_1.default), toFailWith_1.default), toFailWithDetail_1.default), toSucceed_1.default), toSucceedAndMatchInlineSnapshot_1.default), toSucceedAndMatchSnapshot_1.default), toSucceedAndSatisfy_1.default), toSucceedWith_1.default), toSucceedWithDetail_1.default);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Result } from '../../../../../index';
|
|
2
|
+
declare global {
|
|
3
|
+
namespace jest {
|
|
4
|
+
interface Matchers<R, T> {
|
|
5
|
+
/**
|
|
6
|
+
* Use .toFail to verify that a Result<T> is a failure
|
|
7
|
+
*/
|
|
8
|
+
toFail(): R;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
declare const _default: {
|
|
13
|
+
toFail: <T extends Result<unknown>>(received: T) => jest.CustomMatcherResult;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const matcherHelpers_1 = require("../../utils/matcherHelpers");
|
|
4
|
+
const predicate_1 = require("./predicate");
|
|
5
|
+
const jest_matcher_utils_1 = require("jest-matcher-utils");
|
|
6
|
+
function passMessage(received) {
|
|
7
|
+
return () => [
|
|
8
|
+
(0, jest_matcher_utils_1.matcherHint)(`.not.${predicate_1.matcherName}`),
|
|
9
|
+
(0, matcherHelpers_1.printExpectedResult)('failure', false),
|
|
10
|
+
(0, matcherHelpers_1.printReceivedResult)(received)
|
|
11
|
+
].join('\n');
|
|
12
|
+
}
|
|
13
|
+
function failMessage(received) {
|
|
14
|
+
return () => [(0, jest_matcher_utils_1.matcherHint)(`${predicate_1.matcherName}`), (0, matcherHelpers_1.printExpectedResult)('failure', true), (0, matcherHelpers_1.printReceivedResult)(received)].join('\n');
|
|
15
|
+
}
|
|
16
|
+
exports.default = {
|
|
17
|
+
toFail: function (received) {
|
|
18
|
+
const pass = (0, predicate_1.predicate)(received);
|
|
19
|
+
if (pass) {
|
|
20
|
+
return { pass: true, message: passMessage(received) };
|
|
21
|
+
}
|
|
22
|
+
return { pass: false, message: failMessage(received) };
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matcherName = void 0;
|
|
4
|
+
exports.predicate = predicate;
|
|
5
|
+
exports.matcherName = 'toFail';
|
|
6
|
+
function predicate(received) {
|
|
7
|
+
return received.isFailure();
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=predicate.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
namespace jest {
|
|
3
|
+
interface Matchers<R, T> {
|
|
4
|
+
/**
|
|
5
|
+
* Use .toFailTest to test a custom matcher by
|
|
6
|
+
* verifying that a test case fails.
|
|
7
|
+
*/
|
|
8
|
+
toFailTest<T>(): R;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
declare const _default: {
|
|
13
|
+
toFailTest: <T>(cb: () => void) => jest.CustomMatcherResult;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|