@fgv/ts-utils 5.1.0-4 → 5.1.0-40
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/README.md +21 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -0
- package/dist/packlets/base/brand.js.map +1 -0
- package/dist/packlets/base/index.js +2 -0
- package/dist/packlets/base/index.js.map +1 -0
- package/dist/packlets/base/mapResults.js.map +1 -0
- package/dist/packlets/base/messageAggregator.js.map +1 -0
- package/dist/packlets/base/normalize.js +54 -1
- package/dist/packlets/base/normalize.js.map +1 -0
- package/dist/packlets/base/result.js +326 -2
- package/dist/packlets/base/result.js.map +1 -0
- package/dist/packlets/base/shouldNotFail.js +123 -0
- package/dist/packlets/base/shouldNotFail.js.map +1 -0
- package/dist/packlets/base/utils.js.map +1 -0
- package/dist/packlets/base/uuid.js +55 -0
- package/dist/packlets/base/uuid.js.map +1 -0
- package/dist/packlets/collections/aggregatedResultMap.js.map +1 -0
- package/dist/packlets/collections/collectible.js.map +1 -0
- package/dist/packlets/collections/collector.js +23 -9
- package/dist/packlets/collections/collector.js.map +1 -0
- package/dist/packlets/collections/collectorValidator.js +6 -1
- package/dist/packlets/collections/collectorValidator.js.map +1 -0
- package/dist/packlets/collections/common.js.map +1 -0
- package/dist/packlets/collections/converters.js.map +1 -0
- package/dist/packlets/collections/convertingCollector.js.map +1 -0
- package/dist/packlets/collections/convertingCollectorValidator.js.map +1 -0
- package/dist/packlets/collections/convertingResultMap.js.map +1 -0
- package/dist/packlets/collections/index.js +1 -0
- package/dist/packlets/collections/index.js.map +1 -0
- package/dist/packlets/collections/keyValueConverters.js.map +1 -0
- package/dist/packlets/collections/readOnlyConvertingResultMap.js +18 -0
- package/dist/packlets/collections/readOnlyConvertingResultMap.js.map +1 -0
- package/dist/packlets/collections/readonlyResultMap.js.map +1 -0
- package/dist/packlets/collections/resultMap.js.map +1 -0
- package/dist/packlets/collections/resultMapValidator.js.map +1 -0
- package/dist/packlets/collections/retainingRingBuffer.js +159 -0
- package/dist/packlets/collections/retainingRingBuffer.js.map +1 -0
- package/dist/packlets/collections/utils.js.map +1 -0
- package/dist/packlets/collections/validatingCollector.js.map +1 -0
- package/dist/packlets/collections/validatingConvertingCollector.js.map +1 -0
- package/dist/packlets/collections/validatingConvertingResultMap.js.map +1 -0
- package/dist/packlets/collections/validatingResultMap.js.map +1 -0
- package/dist/packlets/conversion/advancedConverters.js.map +1 -0
- package/dist/packlets/conversion/baseConverter.js +107 -18
- package/dist/packlets/conversion/baseConverter.js.map +1 -0
- package/dist/packlets/conversion/basicConverters.js +24 -5
- package/dist/packlets/conversion/basicConverters.js.map +1 -0
- package/dist/packlets/conversion/converter.js +11 -1
- package/dist/packlets/conversion/converter.js.map +1 -0
- package/dist/packlets/conversion/converters.js.map +1 -0
- package/dist/packlets/conversion/defaultingConverter.js.map +1 -0
- package/dist/packlets/conversion/index.js.map +1 -0
- package/dist/packlets/conversion/objectConverter.js.map +1 -0
- package/dist/packlets/conversion/stringConverter.js.map +1 -0
- package/dist/packlets/hash/crcNormalizer.js.map +1 -0
- package/dist/packlets/hash/hashingNormalizer.js.map +1 -0
- package/dist/packlets/hash/index.js.map +1 -0
- package/dist/packlets/logging/bootLogger.js.map +1 -0
- package/dist/packlets/logging/index.js +2 -0
- package/dist/packlets/logging/index.js.map +1 -0
- package/dist/packlets/logging/logReporter.js.map +1 -0
- package/dist/packlets/logging/logger.js +51 -18
- package/dist/packlets/logging/logger.js.map +1 -0
- package/dist/packlets/logging/multiLogger.js +104 -0
- package/dist/packlets/logging/multiLogger.js.map +1 -0
- package/dist/packlets/logging/retainingLogger.js +114 -0
- package/dist/packlets/logging/retainingLogger.js.map +1 -0
- package/dist/packlets/logging-interface/index.js +28 -0
- package/dist/packlets/logging-interface/index.js.map +1 -0
- package/dist/packlets/validation/array.js.map +1 -0
- package/dist/packlets/validation/boolean.js.map +1 -0
- package/dist/packlets/validation/classes.js.map +1 -0
- package/dist/packlets/validation/common.js.map +1 -0
- package/dist/packlets/validation/compositeId.js.map +1 -0
- package/dist/packlets/validation/field.js.map +1 -0
- package/dist/packlets/validation/genericValidator.js.map +1 -0
- package/dist/packlets/validation/index.js.map +1 -0
- package/dist/packlets/validation/number.js.map +1 -0
- package/dist/packlets/validation/object.js.map +1 -0
- package/dist/packlets/validation/oneOf.js.map +1 -0
- package/dist/packlets/validation/string.js.map +1 -0
- package/dist/packlets/validation/traits.js.map +1 -0
- package/dist/packlets/validation/typeGuard.js.map +1 -0
- package/dist/packlets/validation/validator.js.map +1 -0
- package/dist/packlets/validation/validatorBase.js.map +1 -0
- package/dist/packlets/validation/validators.js.map +1 -0
- package/dist/ts-utils.d.ts +1089 -59
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -0
- package/lib/packlets/base/brand.d.ts.map +1 -0
- package/lib/packlets/base/brand.js.map +1 -0
- package/lib/packlets/base/index.d.ts +2 -0
- package/lib/packlets/base/index.d.ts.map +1 -0
- package/lib/packlets/base/index.js +2 -0
- package/lib/packlets/base/index.js.map +1 -0
- package/lib/packlets/base/mapResults.d.ts.map +1 -0
- package/lib/packlets/base/mapResults.js.map +1 -0
- package/lib/packlets/base/messageAggregator.d.ts.map +1 -0
- package/lib/packlets/base/messageAggregator.js.map +1 -0
- package/lib/packlets/base/normalize.d.ts +24 -0
- package/lib/packlets/base/normalize.d.ts.map +1 -0
- package/lib/packlets/base/normalize.js +53 -0
- package/lib/packlets/base/normalize.js.map +1 -0
- package/lib/packlets/base/result.d.ts +295 -1
- package/lib/packlets/base/result.d.ts.map +1 -0
- package/lib/packlets/base/result.js +330 -3
- package/lib/packlets/base/result.js.map +1 -0
- package/lib/packlets/base/shouldNotFail.d.ts +53 -0
- package/lib/packlets/base/shouldNotFail.d.ts.map +1 -0
- package/lib/packlets/base/shouldNotFail.js +129 -0
- package/lib/packlets/base/shouldNotFail.js.map +1 -0
- package/lib/packlets/base/utils.d.ts +12 -0
- package/lib/packlets/base/utils.d.ts.map +1 -0
- package/lib/packlets/base/utils.js.map +1 -0
- package/lib/packlets/base/uuid.d.ts +27 -0
- package/lib/packlets/base/uuid.d.ts.map +1 -0
- package/lib/packlets/base/uuid.js +59 -0
- package/lib/packlets/base/uuid.js.map +1 -0
- package/lib/packlets/collections/aggregatedResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/aggregatedResultMap.js.map +1 -0
- package/lib/packlets/collections/collectible.d.ts.map +1 -0
- package/lib/packlets/collections/collectible.js.map +1 -0
- package/lib/packlets/collections/collector.d.ts +23 -9
- package/lib/packlets/collections/collector.d.ts.map +1 -0
- package/lib/packlets/collections/collector.js +23 -9
- package/lib/packlets/collections/collector.js.map +1 -0
- package/lib/packlets/collections/collectorValidator.d.ts +29 -5
- package/lib/packlets/collections/collectorValidator.d.ts.map +1 -0
- package/lib/packlets/collections/collectorValidator.js +6 -1
- package/lib/packlets/collections/collectorValidator.js.map +1 -0
- package/lib/packlets/collections/common.d.ts.map +1 -0
- package/lib/packlets/collections/common.js.map +1 -0
- package/lib/packlets/collections/converters.d.ts.map +1 -0
- package/lib/packlets/collections/converters.js.map +1 -0
- package/lib/packlets/collections/convertingCollector.d.ts +21 -3
- package/lib/packlets/collections/convertingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/convertingCollector.js.map +1 -0
- package/lib/packlets/collections/convertingCollectorValidator.d.ts +22 -3
- package/lib/packlets/collections/convertingCollectorValidator.d.ts.map +1 -0
- package/lib/packlets/collections/convertingCollectorValidator.js.map +1 -0
- package/lib/packlets/collections/convertingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/convertingResultMap.js.map +1 -0
- package/lib/packlets/collections/index.d.ts +1 -0
- package/lib/packlets/collections/index.d.ts.map +1 -0
- package/lib/packlets/collections/index.js +1 -0
- package/lib/packlets/collections/index.js.map +1 -0
- package/lib/packlets/collections/keyValueConverters.d.ts.map +1 -0
- package/lib/packlets/collections/keyValueConverters.js.map +1 -0
- package/lib/packlets/collections/readOnlyConvertingResultMap.d.ts +13 -1
- package/lib/packlets/collections/readOnlyConvertingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/readOnlyConvertingResultMap.js +19 -1
- package/lib/packlets/collections/readOnlyConvertingResultMap.js.map +1 -0
- package/lib/packlets/collections/readonlyResultMap.d.ts +18 -7
- package/lib/packlets/collections/readonlyResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/readonlyResultMap.js.map +1 -0
- package/lib/packlets/collections/resultMap.d.ts.map +1 -0
- package/lib/packlets/collections/resultMap.js.map +1 -0
- package/lib/packlets/collections/resultMapValidator.d.ts.map +1 -0
- package/lib/packlets/collections/resultMapValidator.js.map +1 -0
- package/lib/packlets/collections/retainingRingBuffer.d.ts +147 -0
- package/lib/packlets/collections/retainingRingBuffer.d.ts.map +1 -0
- package/lib/packlets/collections/retainingRingBuffer.js +163 -0
- package/lib/packlets/collections/retainingRingBuffer.js.map +1 -0
- package/lib/packlets/collections/utils.d.ts.map +1 -0
- package/lib/packlets/collections/utils.js.map +1 -0
- package/lib/packlets/collections/validatingCollector.d.ts +7 -3
- package/lib/packlets/collections/validatingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/validatingCollector.js.map +1 -0
- package/lib/packlets/collections/validatingConvertingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/validatingConvertingCollector.js.map +1 -0
- package/lib/packlets/collections/validatingConvertingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/validatingConvertingResultMap.js.map +1 -0
- package/lib/packlets/collections/validatingResultMap.d.ts +2 -1
- package/lib/packlets/collections/validatingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/validatingResultMap.js.map +1 -0
- package/lib/packlets/conversion/advancedConverters.d.ts.map +1 -0
- package/lib/packlets/conversion/advancedConverters.js.map +1 -0
- package/lib/packlets/conversion/baseConverter.d.ts +108 -19
- package/lib/packlets/conversion/baseConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/baseConverter.js +107 -18
- package/lib/packlets/conversion/baseConverter.js.map +1 -0
- package/lib/packlets/conversion/basicConverters.d.ts +14 -0
- package/lib/packlets/conversion/basicConverters.d.ts.map +1 -0
- package/lib/packlets/conversion/basicConverters.js +24 -5
- package/lib/packlets/conversion/basicConverters.js.map +1 -0
- package/lib/packlets/conversion/converter.d.ts +9 -1
- package/lib/packlets/conversion/converter.d.ts.map +1 -0
- package/lib/packlets/conversion/converter.js +12 -0
- package/lib/packlets/conversion/converter.js.map +1 -0
- package/lib/packlets/conversion/converters.d.ts.map +1 -0
- package/lib/packlets/conversion/converters.js.map +1 -0
- package/lib/packlets/conversion/defaultingConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/defaultingConverter.js.map +1 -0
- package/lib/packlets/conversion/index.d.ts.map +1 -0
- package/lib/packlets/conversion/index.js.map +1 -0
- package/lib/packlets/conversion/objectConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/objectConverter.js.map +1 -0
- package/lib/packlets/conversion/stringConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/stringConverter.js.map +1 -0
- package/lib/packlets/hash/crcNormalizer.d.ts.map +1 -0
- package/lib/packlets/hash/crcNormalizer.js.map +1 -0
- package/lib/packlets/hash/hashingNormalizer.d.ts.map +1 -0
- package/lib/packlets/hash/hashingNormalizer.js.map +1 -0
- package/lib/packlets/hash/index.d.ts.map +1 -0
- package/lib/packlets/hash/index.js.map +1 -0
- package/lib/packlets/logging/bootLogger.d.ts.map +1 -0
- package/lib/packlets/logging/bootLogger.js.map +1 -0
- package/lib/packlets/logging/index.d.ts +2 -0
- package/lib/packlets/logging/index.d.ts.map +1 -0
- package/lib/packlets/logging/index.js +2 -0
- package/lib/packlets/logging/index.js.map +1 -0
- package/lib/packlets/logging/logReporter.d.ts.map +1 -0
- package/lib/packlets/logging/logReporter.js.map +1 -0
- package/lib/packlets/logging/logger.d.ts +25 -70
- package/lib/packlets/logging/logger.d.ts.map +1 -0
- package/lib/packlets/logging/logger.js +54 -20
- package/lib/packlets/logging/logger.js.map +1 -0
- package/lib/packlets/logging/multiLogger.d.ts +54 -0
- package/lib/packlets/logging/multiLogger.d.ts.map +1 -0
- package/lib/packlets/logging/multiLogger.js +108 -0
- package/lib/packlets/logging/multiLogger.js.map +1 -0
- package/lib/packlets/logging/retainingLogger.d.ts +123 -0
- package/lib/packlets/logging/retainingLogger.d.ts.map +1 -0
- package/lib/packlets/logging/retainingLogger.js +118 -0
- package/lib/packlets/logging/retainingLogger.js.map +1 -0
- package/lib/packlets/logging-interface/index.d.ts +98 -0
- package/lib/packlets/logging-interface/index.d.ts.map +1 -0
- package/lib/packlets/logging-interface/index.js +32 -0
- package/lib/packlets/logging-interface/index.js.map +1 -0
- package/lib/packlets/validation/array.d.ts.map +1 -0
- package/lib/packlets/validation/array.js.map +1 -0
- package/lib/packlets/validation/boolean.d.ts.map +1 -0
- package/lib/packlets/validation/boolean.js.map +1 -0
- package/lib/packlets/validation/classes.d.ts.map +1 -0
- package/lib/packlets/validation/classes.js.map +1 -0
- package/lib/packlets/validation/common.d.ts.map +1 -0
- package/lib/packlets/validation/common.js.map +1 -0
- package/lib/packlets/validation/compositeId.d.ts.map +1 -0
- package/lib/packlets/validation/compositeId.js.map +1 -0
- package/lib/packlets/validation/field.d.ts.map +1 -0
- package/lib/packlets/validation/field.js.map +1 -0
- package/lib/packlets/validation/genericValidator.d.ts.map +1 -0
- package/lib/packlets/validation/genericValidator.js.map +1 -0
- package/lib/packlets/validation/index.d.ts.map +1 -0
- package/lib/packlets/validation/index.js.map +1 -0
- package/lib/packlets/validation/number.d.ts.map +1 -0
- package/lib/packlets/validation/number.js.map +1 -0
- package/lib/packlets/validation/object.d.ts.map +1 -0
- package/lib/packlets/validation/object.js.map +1 -0
- package/lib/packlets/validation/oneOf.d.ts.map +1 -0
- package/lib/packlets/validation/oneOf.js.map +1 -0
- package/lib/packlets/validation/string.d.ts.map +1 -0
- package/lib/packlets/validation/string.js.map +1 -0
- package/lib/packlets/validation/traits.d.ts.map +1 -0
- package/lib/packlets/validation/traits.js.map +1 -0
- package/lib/packlets/validation/typeGuard.d.ts.map +1 -0
- package/lib/packlets/validation/typeGuard.js.map +1 -0
- package/lib/packlets/validation/validator.d.ts.map +1 -0
- package/lib/packlets/validation/validator.js.map +1 -0
- package/lib/packlets/validation/validatorBase.d.ts +2 -1
- package/lib/packlets/validation/validatorBase.d.ts.map +1 -0
- package/lib/packlets/validation/validatorBase.js.map +1 -0
- package/lib/packlets/validation/validators.d.ts.map +1 -0
- package/lib/packlets/validation/validators.js.map +1 -0
- package/package.json +3 -3
- package/dist/test/helpers/jest/helpers/fsHelpers.js +0 -139
- package/dist/test/helpers/jest/helpers/index.js +0 -2
- package/dist/test/helpers/jest/index.js +0 -17
- package/dist/test/helpers/jest/matchers/index.js +0 -14
- package/dist/test/helpers/jest/matchers/toFail/index.js +0 -23
- package/dist/test/helpers/jest/matchers/toFail/predicate.js +0 -5
- package/dist/test/helpers/jest/matchers/toFailTest/index.js +0 -28
- package/dist/test/helpers/jest/matchers/toFailTest/predicate.js +0 -8
- package/dist/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/index.js +0 -24
- package/dist/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/predicate.js +0 -11
- package/dist/test/helpers/jest/matchers/toFailTestWith/index.js +0 -29
- package/dist/test/helpers/jest/matchers/toFailTestWith/predicate.js +0 -26
- package/dist/test/helpers/jest/matchers/toFailWith/index.js +0 -27
- package/dist/test/helpers/jest/matchers/toFailWith/predicate.js +0 -16
- package/dist/test/helpers/jest/matchers/toFailWithDetail/index.js +0 -27
- package/dist/test/helpers/jest/matchers/toFailWithDetail/predicate.js +0 -22
- package/dist/test/helpers/jest/matchers/toSucceed/index.js +0 -23
- package/dist/test/helpers/jest/matchers/toSucceed/predicate.js +0 -5
- package/dist/test/helpers/jest/matchers/toSucceedAndMatchInlineSnapshot/index.js +0 -24
- package/dist/test/helpers/jest/matchers/toSucceedAndMatchSnapshot/index.js +0 -24
- package/dist/test/helpers/jest/matchers/toSucceedAndSatisfy/index.js +0 -53
- package/dist/test/helpers/jest/matchers/toSucceedAndSatisfy/predicate.js +0 -17
- package/dist/test/helpers/jest/matchers/toSucceedWith/index.js +0 -27
- package/dist/test/helpers/jest/matchers/toSucceedWith/predicate.js +0 -12
- package/dist/test/helpers/jest/matchers/toSucceedWithDetail/index.js +0 -27
- package/dist/test/helpers/jest/matchers/toSucceedWithDetail/predicate.js +0 -17
- package/dist/test/helpers/jest/resolvers/cli.js +0 -10
- package/dist/test/helpers/jest/resolvers/ide.js +0 -10
- package/dist/test/helpers/jest/ts-utils.js +0 -2
- package/dist/test/helpers/jest/types/index.js +0 -3
- package/dist/test/helpers/jest/utils/matcherHelpers.js +0 -47
- package/dist/test/helpers/jest/utils/snapshotResolver.js +0 -11
- package/dist/test/unit/collections/helpers.js +0 -106
- package/dist/test/unit/hashTextEncodeCompat.js +0 -23
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/packlets/logging/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAA4B,aAAa,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAIL,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,cAAc,EAA4C,oBAAoB,EAAE,gBAAgB,EAAE,CAAC;AAE5G;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,OAAwB,EAAE,QAA0B;IAC5E,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC,CAAC,2CAA2C;IAC1D,CAAC;IACD,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,CAAC,iCAAiC;IACjD,CAAC;IACD,IAAI,OAAO,KAAK,OAAO,EAAE,C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;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,UAAU;IACxC;;;OAGG;IACH,YAAmB,QAA2B;QAC5C,KAAK,CAAC,QAAQ,CAAC,CAAC;IAClB,CAAC;IAED;;;OAGG;IACO,IAAI,CAAC,OAAe,EAAE,OAAwB;QACtD,QAAQ;QACR,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\nimport { MessageLogLevel, Success, captureResult, succeed } from '../base';\nimport {\n IDetailLogger,\n ILogger,\n ReporterLogLevel,\n allReporterLogLevels,\n isDetailLogger,\n reporterLogLevel\n} from '../logging-interface';\n\nexport { isDetailLogger, ReporterLogLevel, ILogger, IDetailLogger, allReporterLogLevels, reporterLogLevel };\n\n/**\n * Compares two log levels.\n * @param message - The first log level.\n * @param reporter - The second log level.\n * @returns `true` if the message should be logged, `false` if it should be suppressed.\n * @public\n */\nexport function shouldLog(message: MessageLogLevel, reporter: ReporterLogLevel): boolean {\n if (reporter === 'all') {\n return true; // 'all' logs everything, including 'quiet'\n }\n if (reporter === 'silent') {\n return false; // 'silent' suppresses everything\n }\n if (message === 'quiet') {\n return false; // 'quiet' messages only show when reporter is 'all'\n }\n switch (reporter) {\n case 'error':\n return message === 'error';\n case 'warning':\n return message === 'warning' || message === 'error';\n case 'info':\n return message !== 'detail';\n }\n return true;\n}\n\n/**\n * Stringifies an arbitrary value for logging.\n * @param value - The value to stringify.\n * @returns The stringified value.\n * @param maxLength - The maximum length of the stringified value.\n * @public\n */\nexport function stringifyLogValue(value: unknown, maxLength?: number): string {\n maxLength = maxLength ?? 40;\n if (typeof value === 'string') {\n return value;\n }\n const str = String(value);\n if (str === '[object Object]') {\n return captureResult(() => JSON.stringify(value))\n .onSuccess((s) => {\n return succeed(s.length < maxLength ? s : s.substring(0, maxLength - 3) + '...');\n })\n .orDefault(str);\n }\n return str;\n}\n\n/**\n * Abstract base class which implements {@link Logging.IDetailLogger | IDetailLogger}.\n * @public\n */\nexport abstract class LoggerBase implements IDetailLogger {\n /**\n * The level of logging to be used.\n */\n public logLevel: ReporterLogLevel = 'info';\n\n protected constructor(logLevel?: ReporterLogLevel) {\n this.logLevel = logLevel ?? 'info';\n }\n\n /**\n * Logs a detail message.\n * @param message - The message to log.\n * @param parameters - The parameters to log.\n * @returns `Success` with the logged message if the level is enabled, or\n * `Success` with `undefined` if the message is suppressed.\n */\n public detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {\n return this.log('detail', message, ...parameters);\n }\n\n /**\n * Logs an info message.\n * @param message - The message to log.\n * @param parameters - The parameters to log.\n * @returns `Success` with the logged message if the level is enabled, or\n * `Success` with `undefined` if the message is suppressed.\n */\n public info(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {\n return this.log('info', message, ...parameters);\n }\n\n /**\n * Logs a warning message.\n * @param message - The message to log.\n * @param parameters - The parameters to log.\n * @returns `Success` with the logged message if the level is enabled, or\n * `Success` with `undefined` if the message is suppressed.\n */\n public warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {\n return this.log('warning', message, ...parameters);\n }\n\n /**\n * Logs an error message.\n * @param message - The message to log.\n * @param parameters - The parameters to log.\n * @returns `Success` with the logged message if the level is enabled, or\n * `Success` with `undefined` if the message is suppressed.\n */\n public error(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {\n return this.log('error', message, ...parameters);\n }\n\n /**\n * Logs a short error summary at `error` level, then emits `detail` at `detail` level.\n * @param message - Short human-readable summary.\n * @param detail - Full detail (e.g. raw converter error) logged at `detail` level.\n */\n public errorWithDetail(message: string, detail: unknown): Success<string | undefined> {\n this.detail(detail);\n return this.error(message);\n }\n\n /**\n * Logs a short warning summary at `warning` level, then emits `detail` at `detail` level.\n * @param message - Short human-readable summary.\n * @param detail - Full detail logged at `detail` level.\n */\n public warnWithDetail(message: string, detail: unknown): Success<string | undefined> {\n this.detail(detail);\n return this.warn(message);\n }\n\n /**\n * Logs a message at the given level.\n * @param level - The level of the message.\n * @param message - The message to log.\n * @param parameters - The parameters to log.\n * @returns `Success` with the logged message if the level is enabled, or\n * `Success` with `undefined` if the message is suppressed.\n */\n public log(\n level: MessageLogLevel,\n message?: unknown,\n ...parameters: unknown[]\n ): Success<string | undefined> {\n if (shouldLog(level, this.logLevel)) {\n const formatted = this._format(message, ...parameters);\n this._logStructured(level, formatted, message, parameters);\n return this._log(formatted, level);\n }\n return this._suppressLog(level, message, ...parameters);\n }\n\n /**\n * Formats a message and parameters into a string.\n * @param message - The message to format.\n * @param parameters - The parameters to format.\n * @returns The formatted message.\n * @public\n */\n protected _format(message?: unknown, ...parameters: unknown[]): string {\n const raw = [message, ...parameters];\n const filtered = raw.filter((m): m is string => m !== undefined);\n const strings = filtered.map((m) => stringifyLogValue(m));\n const joined = strings.join('');\n return joined;\n }\n\n /**\n * Inner hook called for logged messages alongside {@link Logging.LoggerBase._log | _log},\n * exposing the structured `(level, formatted, message, parameters)` form before it is\n * collapsed to the formatted string. The default implementation is a no-op; subclasses\n * that need to retain structured records (e.g. {@link Logging.RetainingLogger | RetainingLogger})\n * override this. Fired only in the `shouldLog` branch, so suppressed messages never reach it.\n * @param __level - The {@link MessageLogLevel | level} of the message.\n * @param __formatted - The formatted message (same string passed to `_log`).\n * @param __message - The raw message argument before formatting.\n * @param __parameters - The raw parameter arguments before formatting.\n * @public\n */\n protected _logStructured(\n __level: MessageLogLevel,\n __formatted: string,\n __message?: unknown,\n __parameters?: readonly unknown[]\n ): void {\n /* no-op; subclasses that retain structured records override this */\n }\n\n /**\n * Inner method called for suppressed log messages.\n * @public\n */\n protected _suppressLog(\n __level: MessageLogLevel,\n __message?: unknown,\n ...__parameters: unknown[]\n ): Success<undefined> {\n return succeed(undefined);\n }\n\n /**\n * Inner method called for logged messages. Should be implemented by derived classes.\n * @param message - The message to log.\n * @param level - The {@link MessageLogLevel | level} of the message.\n * @returns `Success` with the logged message, or `Success` with `undefined` if the message is suppressed.\n * @public\n */\n protected abstract _log(message: string, level: MessageLogLevel): Success<string | undefined>;\n}\n\n/**\n * An in-memory logger that stores logged and suppressed messages.\n * @public\n */\nexport class InMemoryLogger extends LoggerBase {\n /**\n * The messages that have been logged.\n * @internal\n */\n private _logged: string[] = [];\n\n /**\n * The messages that have been suppressed.\n * @internal\n */\n private _suppressed: string[] = [];\n\n /**\n * Creates a new in-memory logger.\n * @param logLevel - The level of logging to be used.\n */\n public constructor(logLevel?: ReporterLogLevel) {\n super(logLevel);\n }\n\n /**\n * The messages that have been logged.\n */\n public get logged(): string[] {\n return this._logged;\n }\n\n /**\n * The messages that have been suppressed.\n */\n public get suppressed(): string[] {\n return this._suppressed;\n }\n\n /**\n * Clears the logged and suppressed messages.\n */\n public clear(): void {\n this._logged = [];\n this._suppressed = [];\n }\n\n /**\n * {@inheritDoc Logging.LoggerBase._log}\n * @internal\n */\n protected _log(message: string, __level: MessageLogLevel): Success<string | undefined> {\n this._logged.push(message);\n return succeed(message);\n }\n\n /**\n * {@inheritDoc Logging.LoggerBase._suppressLog}\n * @internal\n */\n protected _suppressLog(\n level: MessageLogLevel,\n message?: unknown,\n ...parameters: unknown[]\n ): Success<undefined> {\n const formatted = this._format(message, ...parameters);\n this._suppressed.push(formatted);\n return succeed(undefined);\n }\n}\n\n/**\n * A console logger that outputs messages to the console.\n * @public\n */\nexport class ConsoleLogger extends LoggerBase {\n /**\n * Creates a new console logger.\n * @param logLevel - The level of logging to be used.\n */\n public constructor(logLevel?: ReporterLogLevel) {\n super(logLevel);\n }\n\n /**\n * {@inheritDoc Logging.LoggerBase._log}\n * @internal\n */\n protected _log(message: string, level: MessageLogLevel): Success<string | undefined> {\n switch (level) {\n case 'error':\n console.error(message);\n break;\n case 'warning':\n console.warn(message);\n break;\n case 'info':\n console.info(message);\n break;\n default:\n console.log(message);\n break;\n }\n return succeed(message);\n }\n}\n\n/**\n * A no-op {@link Logging.LoggerBase | LoggerBase} that does not log anything.\n * @public\n */\nexport class NoOpLogger extends LoggerBase {\n /**\n * Creates a new no-op logger.\n * @param logLevel - The level of logging to be used.\n */\n public constructor(logLevel?: ReporterLogLevel) {\n super(logLevel);\n }\n\n /**\n * {@inheritDoc Logging.LoggerBase._log}\n * @internal\n */\n protected _log(message: string, __level: MessageLogLevel): Success<string | undefined> {\n // no-op\n return succeed(message);\n }\n}\n"]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { succeed } from '../base';
|
|
23
|
+
/**
|
|
24
|
+
* Verbosity rank for each {@link Logging.ReporterLogLevel | ReporterLogLevel}, materializing
|
|
25
|
+
* the {@link Logging.shouldLog | shouldLog} ordering. A higher rank is more permissive
|
|
26
|
+
* (emits strictly more message levels).
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
const verbosityRank = {
|
|
30
|
+
silent: 0,
|
|
31
|
+
error: 1,
|
|
32
|
+
warning: 2,
|
|
33
|
+
info: 3,
|
|
34
|
+
detail: 4,
|
|
35
|
+
all: 5
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* An {@link Logging.ILogger | ILogger} that fans every log call out to N child loggers,
|
|
39
|
+
* each applying its own threshold.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* The composite does not pre-filter — it forwards the raw `(level, message, ...params)`
|
|
43
|
+
* to each child's public method so each child formats and filters per its own rules.
|
|
44
|
+
* This lets a single pinned logger feed, for example, a {@link Logging.ConsoleLogger | ConsoleLogger}
|
|
45
|
+
* (stdout) and a {@link Logging.RetainingLogger | RetainingLogger} (observability buffer)
|
|
46
|
+
* with independent log levels.
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export class MultiLogger {
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new multi logger.
|
|
53
|
+
* @param loggers - The child loggers to fan calls out to.
|
|
54
|
+
*/
|
|
55
|
+
constructor(loggers) {
|
|
56
|
+
this._loggers = [...loggers];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The most-verbose (most-permissive) level among the children, so an upstream
|
|
60
|
+
* `shouldLog` gate does not suppress a call before it can fan out to a more
|
|
61
|
+
* permissive child. Computed on access, since a child's level may change.
|
|
62
|
+
*/
|
|
63
|
+
get logLevel() {
|
|
64
|
+
return this._loggers.reduce((most, logger) => (verbosityRank[logger.logLevel] > verbosityRank[most] ? logger.logLevel : most), 'silent');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* {@inheritDoc Logging.ILogger.log}
|
|
68
|
+
*/
|
|
69
|
+
log(level, message, ...parameters) {
|
|
70
|
+
let logged;
|
|
71
|
+
for (const logger of this._loggers) {
|
|
72
|
+
const value = logger.log(level, message, ...parameters).value;
|
|
73
|
+
if (value !== undefined) {
|
|
74
|
+
logged = value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return succeed(logged);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* {@inheritDoc Logging.ILogger.detail}
|
|
81
|
+
*/
|
|
82
|
+
detail(message, ...parameters) {
|
|
83
|
+
return this.log('detail', message, ...parameters);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* {@inheritDoc Logging.ILogger.info}
|
|
87
|
+
*/
|
|
88
|
+
info(message, ...parameters) {
|
|
89
|
+
return this.log('info', message, ...parameters);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* {@inheritDoc Logging.ILogger.warn}
|
|
93
|
+
*/
|
|
94
|
+
warn(message, ...parameters) {
|
|
95
|
+
return this.log('warning', message, ...parameters);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* {@inheritDoc Logging.ILogger.error}
|
|
99
|
+
*/
|
|
100
|
+
error(message, ...parameters) {
|
|
101
|
+
return this.log('error', message, ...parameters);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=multiLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiLogger.js","sourceRoot":"","sources":["../../../src/packlets/logging/multiLogger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAA4B,OAAO,EAAE,MAAM,SAAS,CAAC;AAG5D;;;;;GAKG;AACH,MAAM,aAAa,GAAqC;IACtD,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,CAAC;CACP,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,WAAW;IAOtB;;;OAGG;IACH,YAAmB,OAA+B;QAChD,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACH,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CACzB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,EACjG,QAAQ,CACT,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,GAAG,CACR,KAAsB,EACtB,OAAiB,EACjB,GAAG,UAAqB;QAExB,IAAI,MAA0B,CAAC;QAC/B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC,KAAK,CAAC;YAC9D,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,MAAM,GAAG,KAAK,CAAC;YACjB,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,OAAiB,EAAE,GAAG,UAAqB;QACvD,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACI,IAAI,CAAC,OAAiB,EAAE,GAAG,UAAqB;QACrD,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACI,IAAI,CAAC,OAAiB,EAAE,GAAG,UAAqB;QACrD,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAiB,EAAE,GAAG,UAAqB;QACtD,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC;IACnD,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\nimport { MessageLogLevel, Success, succeed } from '../base';\nimport { ILogger, ReporterLogLevel } from './logger';\n\n/**\n * Verbosity rank for each {@link Logging.ReporterLogLevel | ReporterLogLevel}, materializing\n * the {@link Logging.shouldLog | shouldLog} ordering. A higher rank is more permissive\n * (emits strictly more message levels).\n * @internal\n */\nconst verbosityRank: Record<ReporterLogLevel, number> = {\n silent: 0,\n error: 1,\n warning: 2,\n info: 3,\n detail: 4,\n all: 5\n};\n\n/**\n * An {@link Logging.ILogger | ILogger} that fans every log call out to N child loggers,\n * each applying its own threshold.\n *\n * @remarks\n * The composite does not pre-filter — it forwards the raw `(level, message, ...params)`\n * to each child's public method so each child formats and filters per its own rules.\n * This lets a single pinned logger feed, for example, a {@link Logging.ConsoleLogger | ConsoleLogger}\n * (stdout) and a {@link Logging.RetainingLogger | RetainingLogger} (observability buffer)\n * with independent log levels.\n *\n * @public\n */\nexport class MultiLogger implements ILogger {\n /**\n * The child loggers calls are fanned out to.\n * @internal\n */\n private readonly _loggers: ReadonlyArray<ILogger>;\n\n /**\n * Creates a new multi logger.\n * @param loggers - The child loggers to fan calls out to.\n */\n public constructor(loggers: ReadonlyArray<ILogger>) {\n this._loggers = [...loggers];\n }\n\n /**\n * The most-verbose (most-permissive) level among the children, so an upstream\n * `shouldLog` gate does not suppress a call before it can fan out to a more\n * permissive child. Computed on access, since a child's level may change.\n */\n public get logLevel(): ReporterLogLevel {\n return this._loggers.reduce<ReporterLogLevel>(\n (most, logger) => (verbosityRank[logger.logLevel] > verbosityRank[most] ? logger.logLevel : most),\n 'silent'\n );\n }\n\n /**\n * {@inheritDoc Logging.ILogger.log}\n */\n public log(\n level: MessageLogLevel,\n message?: unknown,\n ...parameters: unknown[]\n ): Success<string | undefined> {\n let logged: string | undefined;\n for (const logger of this._loggers) {\n const value = logger.log(level, message, ...parameters).value;\n if (value !== undefined) {\n logged = value;\n }\n }\n return succeed(logged);\n }\n\n /**\n * {@inheritDoc Logging.ILogger.detail}\n */\n public detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {\n return this.log('detail', message, ...parameters);\n }\n\n /**\n * {@inheritDoc Logging.ILogger.info}\n */\n public info(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {\n return this.log('info', message, ...parameters);\n }\n\n /**\n * {@inheritDoc Logging.ILogger.warn}\n */\n public warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {\n return this.log('warning', message, ...parameters);\n }\n\n /**\n * {@inheritDoc Logging.ILogger.error}\n */\n public error(message?: unknown, ...parameters: unknown[]): Success<string | undefined> {\n return this.log('error', message, ...parameters);\n }\n}\n"]}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { succeed } from '../base';
|
|
23
|
+
import { RetainingRingBuffer } from '../collections';
|
|
24
|
+
import { LoggerBase, shouldLog } from './logger';
|
|
25
|
+
/**
|
|
26
|
+
* An {@link Logging.ILogger | ILogger} that retains structured log records in a bounded
|
|
27
|
+
* most-recent-N ring, with a query API supporting min-severity filtering and
|
|
28
|
+
* since-cursor incremental paging.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* Records are captured via the {@link Logging.LoggerBase._logStructured | _logStructured} hook,
|
|
32
|
+
* so the full structured form (`level` + formatted `message` + raw `args`) is retained.
|
|
33
|
+
* The logger emits nowhere itself — pair it with a {@link Logging.MultiLogger | MultiLogger}
|
|
34
|
+
* to also feed a {@link Logging.ConsoleLogger | ConsoleLogger} or other durable sink.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export class RetainingLogger extends LoggerBase {
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new retaining logger.
|
|
41
|
+
* @param logLevel - The level of logging to retain. Defaults to `'detail'` to capture
|
|
42
|
+
* broadly and filter at query time.
|
|
43
|
+
* @param maxRecords - The maximum number of records to retain. Defaults to `1000`.
|
|
44
|
+
* @param now - Injected clock returning milliseconds since epoch. Defaults to `Date.now`.
|
|
45
|
+
*/
|
|
46
|
+
constructor(logLevel = 'detail', maxRecords = 1000, now = () => Date.now()) {
|
|
47
|
+
super(logLevel);
|
|
48
|
+
/**
|
|
49
|
+
* The monotonic sequence counter. The logger owns `seq` assignment and
|
|
50
|
+
* increments this before each push so the buffer receives strictly increasing
|
|
51
|
+
* sequence numbers.
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
this._nextSeq = 0;
|
|
55
|
+
this._now = now;
|
|
56
|
+
this._ring = new RetainingRingBuffer({ maxRecords });
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The retained records, oldest-first.
|
|
60
|
+
*/
|
|
61
|
+
get records() {
|
|
62
|
+
return this._ring.records;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The most recently assigned sequence number. A client can hold this value and
|
|
66
|
+
* pass it as `sinceSeq` to page only records logged afterward.
|
|
67
|
+
*/
|
|
68
|
+
get lastSeq() {
|
|
69
|
+
return this._ring.lastSeq;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns retained records, oldest-first, optionally filtered.
|
|
73
|
+
* @param options - {@link Logging.IGetRecordsOptions | Filtering and paging options}.
|
|
74
|
+
* @returns The matching records, oldest-first.
|
|
75
|
+
*/
|
|
76
|
+
getRecords(options) {
|
|
77
|
+
const minLevel = options === null || options === void 0 ? void 0 : options.minLevel;
|
|
78
|
+
return this._ring.query({
|
|
79
|
+
sinceSeq: options === null || options === void 0 ? void 0 : options.sinceSeq,
|
|
80
|
+
filter: minLevel !== undefined ? (r) => shouldLog(r.level, minLevel) : undefined,
|
|
81
|
+
limit: options === null || options === void 0 ? void 0 : options.limit
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Clears all retained records. Does NOT reset the sequence counter, so a client
|
|
86
|
+
* holding a `sinceSeq` cursor never re-sees a sequence number.
|
|
87
|
+
*/
|
|
88
|
+
clear() {
|
|
89
|
+
this._ring.clear();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* {@inheritDoc Logging.LoggerBase._logStructured}
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
_logStructured(level, formatted, message, parameters) {
|
|
96
|
+
this._nextSeq += 1;
|
|
97
|
+
const record = {
|
|
98
|
+
seq: this._nextSeq,
|
|
99
|
+
timestamp: this._now(),
|
|
100
|
+
level,
|
|
101
|
+
message: formatted,
|
|
102
|
+
args: [message, ...parameters]
|
|
103
|
+
};
|
|
104
|
+
this._ring.push(record);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* {@inheritDoc Logging.LoggerBase._log}
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
_log(message, __level) {
|
|
111
|
+
return succeed(message);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=retainingLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retainingLogger.js","sourceRoot":"","sources":["../../../src/packlets/logging/retainingLogger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAA4B,OAAO,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAoB,SAAS,EAAE,MAAM,UAAU,CAAC;AAoDnE;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAuB7C;;;;;;OAMG;IACH,YACE,WAA6B,QAAQ,EACrC,aAAqB,IAAI,EACzB,MAAoB,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;QAEpC,KAAK,CAAC,QAAQ,CAAC,CAAC;QA5BlB;;;;;WAKG;QACK,aAAQ,GAAW,CAAC,CAAC;QAuB3B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,mBAAmB,CAAa,EAAE,UAAU,EAAE,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACH,IA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sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\nimport { MessageLogLevel, Success, succeed } from '../base';\nimport { RetainingRingBuffer } from '../collections';\nimport { LoggerBase, ReporterLogLevel, shouldLog } from './logger';\n\n/**\n * A retained log record. Preserves the level and an ordering cursor so consumers\n * can filter by severity and page incrementally.\n * @public\n */\nexport interface ILogRecord {\n /**\n * Monotonic 1-based sequence number, stable across ring eviction.\n */\n readonly seq: number;\n /**\n * Milliseconds since epoch when the record was logged (from the injected clock).\n */\n readonly timestamp: number;\n /**\n * The level the record was logged at.\n */\n readonly level: MessageLogLevel;\n /**\n * The formatted message (same formatting {@link Logging.LoggerBase._format | LoggerBase._format} produces).\n */\n readonly message: string;\n /**\n * The raw structured inputs `[message, ...parameters]` before formatting.\n */\n readonly args?: readonly unknown[];\n}\n\n/**\n * Options for {@link Logging.RetainingLogger.getRecords | RetainingLogger.getRecords}.\n * @public\n */\nexport interface IGetRecordsOptions {\n /**\n * If supplied, only records whose level would be emitted at this threshold\n * (per {@link Logging.shouldLog | shouldLog}) are returned.\n */\n readonly minLevel?: ReporterLogLevel;\n /**\n * If supplied, only records with `seq > sinceSeq` are returned, enabling\n * incremental paging from a previously-held cursor.\n */\n readonly sinceSeq?: number;\n /**\n * If supplied, returns at most this many records — the most recent N (tail),\n * still ordered oldest-first.\n */\n readonly limit?: number;\n}\n\n/**\n * An {@link Logging.ILogger | ILogger} that retains structured log records in a bounded\n * most-recent-N ring, with a query API supporting min-severity filtering and\n * since-cursor incremental paging.\n *\n * @remarks\n * Records are captured via the {@link Logging.LoggerBase._logStructured | _logStructured} hook,\n * so the full structured form (`level` + formatted `message` + raw `args`) is retained.\n * The logger emits nowhere itself — pair it with a {@link Logging.MultiLogger | MultiLogger}\n * to also feed a {@link Logging.ConsoleLogger | ConsoleLogger} or other durable sink.\n *\n * @public\n */\nexport class RetainingLogger extends LoggerBase {\n /**\n * Injected clock used to timestamp records.\n * @internal\n */\n private readonly _now: () => number;\n\n /**\n * The monotonic sequence counter. The logger owns `seq` assignment and\n * increments this before each push so the buffer receives strictly increasing\n * sequence numbers.\n * @internal\n */\n private _nextSeq: number = 0;\n\n /**\n * The backing ring buffer. Retains up to `maxRecords` log records, evicting\n * the oldest when full. The buffer is a pure seq-ring — it does not assign\n * `seq`; the logger does.\n * @internal\n */\n private readonly _ring: RetainingRingBuffer<ILogRecord>;\n\n /**\n * Creates a new retaining logger.\n * @param logLevel - The level of logging to retain. Defaults to `'detail'` to capture\n * broadly and filter at query time.\n * @param maxRecords - The maximum number of records to retain. Defaults to `1000`.\n * @param now - Injected clock returning milliseconds since epoch. Defaults to `Date.now`.\n */\n public constructor(\n logLevel: ReporterLogLevel = 'detail',\n maxRecords: number = 1000,\n now: () => number = () => Date.now()\n ) {\n super(logLevel);\n this._now = now;\n this._ring = new RetainingRingBuffer<ILogRecord>({ maxRecords });\n }\n\n /**\n * The retained records, oldest-first.\n */\n public get records(): ReadonlyArray<ILogRecord> {\n return this._ring.records;\n }\n\n /**\n * The most recently assigned sequence number. A client can hold this value and\n * pass it as `sinceSeq` to page only records logged afterward.\n */\n public get lastSeq(): number {\n return this._ring.lastSeq;\n }\n\n /**\n * Returns retained records, oldest-first, optionally filtered.\n * @param options - {@link Logging.IGetRecordsOptions | Filtering and paging options}.\n * @returns The matching records, oldest-first.\n */\n public getRecords(options?: IGetRecordsOptions): ReadonlyArray<ILogRecord> {\n const minLevel = options?.minLevel;\n return this._ring.query({\n sinceSeq: options?.sinceSeq,\n filter: minLevel !== undefined ? (r) => shouldLog(r.level, minLevel) : undefined,\n limit: options?.limit\n });\n }\n\n /**\n * Clears all retained records. Does NOT reset the sequence counter, so a client\n * holding a `sinceSeq` cursor never re-sees a sequence number.\n */\n public clear(): void {\n this._ring.clear();\n }\n\n /**\n * {@inheritDoc Logging.LoggerBase._logStructured}\n * @internal\n */\n protected _logStructured(\n level: MessageLogLevel,\n formatted: string,\n message: unknown,\n parameters: readonly unknown[]\n ): void {\n this._nextSeq += 1;\n const record: ILogRecord = {\n seq: this._nextSeq,\n timestamp: this._now(),\n level,\n message: formatted,\n args: [message, ...parameters]\n };\n this._ring.push(record);\n }\n\n /**\n * {@inheritDoc Logging.LoggerBase._log}\n * @internal\n */\n protected _log(message: string, __level: MessageLogLevel): Success<string | undefined> {\n return succeed(message);\n }\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Converters } from '../conversion';
|
|
2
|
+
// Untyped (literal-tuple-inferred) source of truth for allReporterLogLevels, kept separate from the
|
|
3
|
+
// widened public export below so the exhaustiveness check actually inspects the literal values instead
|
|
4
|
+
// of being widened away to {@link Logging.ReporterLogLevel | ReporterLogLevel} before the check runs.
|
|
5
|
+
const reporterLogLevelValues = ['all', 'detail', 'info', 'warning', 'error', 'silent'];
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
|
+
const _reporterLogLevelExhaustivenessCheck = true;
|
|
8
|
+
/**
|
|
9
|
+
* Exhaustive list of all {@link Logging.ReporterLogLevel | ReporterLogLevel} values.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export const allReporterLogLevels = reporterLogLevelValues;
|
|
13
|
+
/**
|
|
14
|
+
* A ready-made {@link Converter | Converter} for {@link Logging.ReporterLogLevel | ReporterLogLevel} values.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export const reporterLogLevel = Converters.enumeratedValue(allReporterLogLevels);
|
|
18
|
+
/**
|
|
19
|
+
* Type guard that checks whether a logger implements {@link IDetailLogger}.
|
|
20
|
+
* @param logger - The logger to check.
|
|
21
|
+
* @returns `true` if the logger implements `IDetailLogger`.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export function isDetailLogger(logger) {
|
|
25
|
+
return (typeof logger.errorWithDetail === 'function' &&
|
|
26
|
+
typeof logger.warnWithDetail === 'function');
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/logging-interface/index.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAa,UAAU,EAAE,MAAM,eAAe,CAAC;AAQtD,oGAAoG;AACpG,uGAAuG;AACvG,sGAAsG;AACtG,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;AAchG,6DAA6D;AAC7D,MAAM,oCAAoC,GAAyC,IAAI,CAAC;AAExF;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAgC,sBAAsB,CAAC;AAExF;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAGzB,UAAU,CAAC,eAAe,CAAmB,oBAAoB,CAAC,CAAC;AAmFvE;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAAe;IAC5C,OAAO,CACL,OAAQ,MAAwB,CAAC,eAAe,KAAK,UAAU;QAC/D,OAAQ,MAAwB,CAAC,cAAc,KAAK,UAAU,CAC/D,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\nimport { MessageLogLevel, Success } from '../base';\nimport { Converter, Converters } from '../conversion';\n\n/**\n * The level of logging to be used.\n * @public\n */\nexport type ReporterLogLevel = 'all' | 'detail' | 'info' | 'warning' | 'error' | 'silent';\n\n// Untyped (literal-tuple-inferred) source of truth for allReporterLogLevels, kept separate from the\n// widened public export below so the exhaustiveness check actually inspects the literal values instead\n// of being widened away to {@link Logging.ReporterLogLevel | ReporterLogLevel} before the check runs.\nconst reporterLogLevelValues = ['all', 'detail', 'info', 'warning', 'error', 'silent'] as const;\n\n/**\n * Compile-time exhaustiveness guard ensuring {@link reporterLogLevelValues} exactly matches every member of\n * {@link Logging.ReporterLogLevel | ReporterLogLevel}. Adding or removing a union member without updating the array fails the build.\n * Deliberately not exported - this exists only to force the compiler to evaluate the check below.\n */\ntype _ReporterLogLevelExhaustivenessCheck = [\n Exclude<ReporterLogLevel, (typeof reporterLogLevelValues)[number]>,\n Exclude<(typeof reporterLogLevelValues)[number], ReporterLogLevel>\n] extends [never, never]\n ? true\n : never;\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst _reporterLogLevelExhaustivenessCheck: _ReporterLogLevelExhaustivenessCheck = true;\n\n/**\n * Exhaustive list of all {@link Logging.ReporterLogLevel | ReporterLogLevel} values.\n * @public\n */\nexport const allReporterLogLevels: readonly ReporterLogLevel[] = reporterLogLevelValues;\n\n/**\n * A ready-made {@link Converter | Converter} for {@link Logging.ReporterLogLevel | ReporterLogLevel} values.\n * @public\n */\nexport const reporterLogLevel: Converter<\n ReporterLogLevel,\n ReadonlyArray<ReporterLogLevel>\n> = Converters.enumeratedValue<ReporterLogLevel>(allReporterLogLevels);\n\n/**\n * Generic Result-aware logger interface with multiple levels of logging.\n * @public\n */\nexport interface ILogger {\n /**\n * The level of logging to be used.\n */\n readonly logLevel: ReporterLogLevel;\n\n /**\n * Logs a message at the given level.\n * @param level - The level of the message.\n * @param message - The message to log.\n * @param parameters - The parameters to log.\n * @returns `Success` with the logged message if the level is enabled, or\n * `Success` with `undefined` if the message is suppressed.\n */\n log(level: MessageLogLevel, message?: unknown, ...parameters: unknown[]): Success<string | undefined>;\n\n /**\n * Logs a detail message.\n * @param message - The message to log.\n * @param parameters - The parameters to log.\n * @returns `Success` with the logged message if the level is enabled, or\n * `Success` with `undefined` if the message is suppressed.\n */\n detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;\n\n /**\n * Logs an info message.\n * @param message - The message to log.\n * @param parameters - The parameters to log.\n * @returns `Success` with the logged message if the level is enabled, or\n * `Success` with `undefined` if the message is suppressed.\n */\n info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;\n\n /**\n * Logs a warning message.\n * @param message - The message to log.\n * @param parameters - The parameters to log.\n * @returns `Success` with the logged message if the level is enabled, or\n * `Success` with `undefined` if the message is suppressed.\n */\n warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;\n\n /**\n * Logs an error message.\n * @param message - The message to log.\n * @param parameters - The parameters to log.\n * @returns `Success` with the logged message if the level is enabled, or\n * `Success` with `undefined` if the message is suppressed.\n */\n error(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;\n}\n\n/**\n * Extended logger interface that supports logging a short summary message at a\n * primary level (error/warn) while emitting the full detail at `detail` level.\n *\n * The detail is suppressed by default (requires log level `'detail'` or `'all'`),\n * keeping the primary log clean while preserving the full context for debugging.\n * @public\n */\nexport interface IDetailLogger extends ILogger {\n /**\n * Logs a short error summary at `error` level, then emits `detail` at `detail` level.\n * @param message - Short human-readable summary.\n * @param detail - Full detail (e.g. raw converter error) logged at `detail` level.\n */\n errorWithDetail(message: string, detail: unknown): Success<string | undefined>;\n\n /**\n * Logs a short warning summary at `warning` level, then emits `detail` at `detail` level.\n * @param message - Short human-readable summary.\n * @param detail - Full detail logged at `detail` level.\n */\n warnWithDetail(message: string, detail: unknown): Success<string | undefined>;\n}\n\n/**\n * Type guard that checks whether a logger implements {@link IDetailLogger}.\n * @param logger - The logger to check.\n * @returns `true` if the logger implements `IDetailLogger`.\n * @public\n */\nexport function isDetailLogger(logger: ILogger): logger is IDetailLogger {\n return (\n typeof (logger as IDetailLogger).errorWithDetail === 'function' &&\n typeof (logger as IDetailLogger).warnWithDetail === 'function'\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../../src/packlets/validation/array.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAW,IAAI,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,aAAa,EAAkC,MAAM,iBAAiB,CAAC;AAYhF;;;;GAIG;AACH,MAAM,OAAO,cAAgC,SAAQ,aAAsB;IASzE;;;;OAIG;IACH,YAAmB,MAA8C;;QAC/D,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,eAAe,CAAC;QAC/C,IAAI,CAAC,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;;;OASG;IACO,SAAS,CAAC,IAAa,EAAE,OAAY,EAAE,IAAyB;QACxE,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;gBACxB,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBAC7D,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;oBACxB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAM,IAAI,IAAI,iBAAiB,CAAC,CAAC;IAC9C,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2022 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { Validator, ValidatorOptions } from './validator';\nimport { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.ArrayValidator | ArrayValidator}.\n * @public\n */\n\nexport interface ArrayValidatorConstructorParams<T, TC = unknown>\n extends ValidatorBaseConstructorParams<T[], TC> {\n validateElement: Validator<T, TC>;\n}\n\n/**\n * An in-place {@link Validator | Validator} for arrays of validated\n * values or objects.\n * @public\n */\nexport class ArrayValidator<T, TC = unknown> extends ValidatorBase<T[], TC> {\n /**\n * {@link Validation.ValidatorOptions | Options} which apply to this\n * validator.\n */\n public readonly options: ValidatorOptions<TC>;\n\n protected readonly _validateElement: Validator<T, TC>;\n\n /**\n * Constructs a new {@link Validation.Classes.ArrayValidator | ArrayValidator}.\n * @param params - Optional {@link Validation.Classes.ArrayValidatorConstructorParams | init params} for the\n * new {@link Validation.Classes.ArrayValidator | ArrayValidator}.\n */\n public constructor(params: ArrayValidatorConstructorParams<T, TC>) {\n super(params);\n this._validateElement = params.validateElement;\n this.options = params.options ?? {};\n }\n\n /**\n * Static method which validates that a supplied `unknown` value is a `array`\n * and that every element of the array can be validated by the supplied array\n * validator.\n * @param from - The `unknown` value to be tested.\n * @param context - Optional validation context will be propagated to element validator.\n * @param self - Optional self-reference for recursive validation.\n * @returns Returns `true` if `from` is an `array` of valid elements, or\n * {@link Failure} with an error message if not.\n */\n protected _validate(from: unknown, context?: TC, self?: Validator<T[], TC>): boolean | Failure<T[]> {\n if (Array.isArray(from)) {\n for (const elem of from) {\n const result = this._validateElement.validate(elem, context);\n if (!result.isSuccess()) {\n return fail(result.message);\n }\n }\n return true;\n }\n return fail<T[]>(`\"${from}\": not an array`);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../src/packlets/validation/boolean.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAW,IAAI,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAqC,MAAM,oBAAoB,CAAC;AAQzF;;;GAGG;AACH,MAAM,OAAO,gBAA+B,SAAQ,gBAA6B;IAC/E;;;;OAIG;IACH,YAAmB,MAA8C;QAC/D,oBAAoB;QACpB,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;QACtB,KAAK,iBACH,SAAS,EAAE,gBAAgB,CAAC,eAAe,IACxC,MAAM,EACT,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,eAAe,CAAC,IAAa;QACzC,IAAI,OAAO,IAAI,KAAK,SAAS,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,IAAI,kBAAkB,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { GenericValidator, GenericValidatorConstructorParams } from './genericValidator';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.BooleanValidator | BooleanValidator}.\n * @public\n */\nexport type BooleanValidatorConstructorParams<TC = unknown> = GenericValidatorConstructorParams<boolean, TC>;\n\n/**\n * An in-place {@link Validation.Validator | Validator} for `boolean` values.\n * @public\n */\nexport class BooleanValidator<TC = unknown> extends GenericValidator<boolean, TC> {\n /**\n * Constructs a new {@link Validation.Classes.BooleanValidator | BooleanValidator}.\n * @param params - Optional {@link Validation.Classes.BooleanValidatorConstructorParams | init params} for the\n * new {@link Validation.Classes.BooleanValidator | BooleanValidator}.\n */\n public constructor(params?: BooleanValidatorConstructorParams<TC>) {\n /* c8 ignore next */\n params = params ?? {};\n super({\n validator: BooleanValidator.validateBoolean,\n ...params\n });\n }\n\n /**\n * Static method which validates that a supplied `unknown` value is a `boolean`.\n * @param from - The `unknown` value to be tested.\n * @returns Returns `true` if `from` is a `boolean`, or {@link Failure} with an error\n * message if not.\n */\n public static validateBoolean(from: unknown): boolean | Failure<boolean> {\n if (typeof from === 'boolean') {\n return true;\n }\n return fail(`\"${from}\": not a boolean`);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classes.js","sourceRoot":"","sources":["../../../src/packlets/validation/classes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,qBAAqB;AAErB,OAAO,EAAE,cAAc,EAAmC,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAqC,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAyC,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAoC,MAAM,UAAU,CAAC;AAC7E,OAAO,EAEL,eAAe,EAGhB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAmC,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAoC,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAuC,MAAM,aAAa,CAAC;AAEtF,oBAAoB","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/* c8 ignore start */\n\nexport { ArrayValidator, ArrayValidatorConstructorParams } from './array';\nexport { BooleanValidator, BooleanValidatorConstructorParams } from './boolean';\nexport { CompositeIdValidator, CompositeIdValidatorConstructorParams } from './compositeId';\nexport { NumberValidator, NumberValidatorConstructorParams } from './number';\nexport {\n FieldValidators,\n ObjectValidator,\n ObjectValidatorConstructorParams,\n ObjectValidatorOptions\n} from './object';\nexport { OneOfValidator, OneOfValidatorConstructorParams } from './oneOf';\nexport { StringValidator, StringValidatorConstructorParams } from './string';\nexport { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';\n\n/* c8 ignore stop */\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/packlets/validation/common.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2022 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * A type guard function which validates a specific type, with an optional context\n * that can be used to shape the validation.\n * @public\n */\nexport type TypeGuardWithContext<T, TC = unknown> = (from: unknown, context?: TC) => from is T;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compositeId.js","sourceRoot":"","sources":["../../../src/packlets/validation/compositeId.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,M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MAAM,GAAG,IAAI,CAAC,sBAAsB;aACvC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;aAC/B,SAAS,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QACpE,OAAO,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAI,GAAG,KAAK,4BAA4B,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3G,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { Validator } from './validator';\nimport { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.StringValidator | StringValidator}.\n * @public\n */\nexport interface CompositeIdValidatorConstructorParams<\n T extends string = string,\n TCOLLECTIONID extends string = string,\n TITEMID extends string = string,\n TC = unknown\n> extends ValidatorBaseConstructorParams<T, TC> {\n readonly collectionId: Validator<TCOLLECTIONID, TC>;\n readonly separator: string;\n readonly itemId: Validator<TITEMID, TC>;\n}\n\n/**\n * An in-place {@link Validation.Validator | Validator} for a strongly-typed composite ID.\n * @public\n */\nexport class CompositeIdValidator<\n T extends string = string,\n TCOLLECTIONID extends string = string,\n TITEMID extends string = string,\n TC = unknown\n> extends ValidatorBase<T, TC> {\n protected readonly _collectionIdValidator: Validator<TCOLLECTIONID, TC>;\n protected readonly _itemIdValidator: Validator<TITEMID, TC>;\n protected readonly _separator: string;\n\n /**\n * Constructs a new {@link Validation.Classes.StringValidator | StringValidator}.\n * @param params - Optional {@link Validation.Classes.StringValidatorConstructorParams | init params}\n * for the new {@link Validation.Classes.StringValidator | StringValidator}.\n */\n public constructor(params: CompositeIdValidatorConstructorParams<T, TCOLLECTIONID, TITEMID, TC>) {\n /* c8 ignore next */\n super({\n ...params\n });\n const { collectionId, separator, itemId } = params;\n\n this._collectionIdValidator = collectionId.withFormattedError(\n (value, err) => `${value}: invalid composite collection ID (${err}).`\n );\n this._itemIdValidator = itemId.withFormattedError(\n (value, err) => `${value}: invalid composite item ID (${err}).`\n );\n this._separator = separator;\n }\n\n protected override _validate(value: unknown, context?: TC): boolean | Failure<T> {\n if (typeof value !== 'string') {\n return fail(`${value}: invalid non-string composite ID.`);\n }\n const parts = value.split(this._separator);\n if (parts.length < 2) {\n return fail(`${value}: invalid composite ID - separator '${this._separator}' not found.`);\n } else if (parts.length > 2) {\n return fail(`${value}: invalid composite ID - multiple separators '${this._separator}.' found.`);\n }\n const [collectionId, itemId] = parts;\n const result = this._collectionIdValidator\n .validate(collectionId, context)\n .onSuccess(() => this._itemIdValidator.validate(itemId, context));\n return result.isSuccess() ? true : Failure.with<T>(`${value}: invalid composite ID - ${result.message}`);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field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C,CAAC,CAAC,CAAC;oBAEL,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;gBACxC,CAAC;YACH,CAAC;YAED,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,0BAA0B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACpG,CAAC;QACD,0CAA0C;QAC1C,OAAO,IAAI,CAAC,0BAA0B,IAAI,CAAC,SAAS,sBAAsB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrG,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail, isKeyOf } from '../base';\nimport { Validator, ValidatorOptions } from './validator';\nimport { ValidatorBase } from './validatorBase';\n\n/**\n * Parameters used to construct a {@link Validation.FieldValidator | FieldValidator}.\n * @public\n */\n\nexport interface FieldValidatorOptions<TC> extends ValidatorOptions<TC> {\n optional?: boolean;\n}\n\n/**\n * An in-place {@link Validation.Validator | Validator} for properties\n * an an object.\n * @public\n */\nexport class FieldValidator<T, TC = unknown> extends ValidatorBase<T, TC> {\n /**\n * The name of the property that this validator should validate.\n */\n public readonly fieldName: string;\n /**\n * The {@link Validation.Validator | Validator} to be applied against the named property.\n */\n public readonly fieldValidator: Validator<T, TC>;\n /**\n * @internal\n */\n protected readonly _fieldOptions: FieldValidatorOptions<TC>;\n\n /**\n * Constructs a new {@link Validation.FieldValidator | FieldValidator.}.\n * @param fieldName - The name of the property that this validator should validate.\n * @param fieldValidator - The {@link Validation.Validator | Validator} to be applied\n * against the named property.\n * @param options - Additional {@link Validation.FieldValidatorOptions | options} to be\n * applied to this validation.\n */\n public constructor(\n fieldName: string,\n fieldValidator: Validator<T, TC>,\n options?: FieldValidatorOptions<TC>\n ) {\n super({ options });\n this.fieldName = fieldName;\n this.fieldValidator = fieldValidator;\n /* c8 ignore next */\n this._fieldOptions = options ?? {};\n }\n\n /**\n * {@inheritDoc Validation.ValidatorBase._validate}\n */\n protected _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T> {\n if (typeof from === 'object' && !Array.isArray(from) && from !== null) {\n const optional = this._fieldOptions.optional === true;\n\n if (isKeyOf(this.fieldName, from)) {\n if (!optional || from[this.fieldName] !== undefined) {\n const result = this.fieldValidator\n .validate(from[this.fieldName], context)\n .onFailure((message: string) => {\n return fail(`${this.fieldName}: ${message}`);\n });\n\n return result.success ? true : result;\n }\n }\n\n return optional ? true : fail(`\"${this.fieldName}\": Field not found in \"${JSON.stringify(from)}`);\n }\n /* c8 ignore next 2 -- defense in depth */\n return fail(`Cannot validate field '${this.fieldName}' from non-object \"${JSON.stringify(from)}\"`);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genericValidator.js","sourceRoot":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\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Brand, Failure, Result, fail, succeed } from '../base';\nimport { ConstraintTrait, ValidatorTraits } from './traits';\nimport {\n Constraint,\n ValidationErrorFormatter,\n Validator,\n ValidatorFunc,\n ValidatorOptions\n} from './validator';\n\n/**\n * Options used to initialize a {@link Validation.Base.GenericValidator | GenericValidator}.\n * @public\n */\n\nexport interface GenericValidatorConstructorParams<T, TC> {\n options?: ValidatorOptions<TC>;\n traits?: Partial<ValidatorTraits>;\n validator?: ValidatorFunc<T, TC>;\n}\n\n/**\n * Generic base implementation for an in-place {@link Validation.Validator | Validator}.\n * @public\n */\nexport class GenericValidator<T, TC = unknown> implements Validator<T, TC> {\n /**\n * {@inheritDoc Validation.Validator.traits}\n */\n public readonly traits: ValidatorTraits;\n\n /**\n * @internal\n */\n protected readonly _validator: ValidatorFunc<T, TC>;\n /**\n * @internal\n */\n protected readonly _options: ValidatorOptions<TC>;\n\n /**\n * Constructs a new {@link Validation.Base.GenericValidator | GenericValidator<T>}.\n * @param params - The {@link Validation.Base.GenericValidatorConstructorParams | constructor params}\n * used to configure validation.\n */\n public constructor(params: Partial<GenericValidatorConstructorParams<T, TC>>) {\n if (!params.validator) {\n throw new Error('No validator function supplied');\n }\n this._validator = params.validator;\n this._options = params.options ?? {};\n this.traits = new ValidatorTraits(params.traits);\n }\n\n /**\n * {@inheritDoc Validation.Validator.isOptional}\n */\n public get isOptional(): boolean {\n return this.traits.isOptional;\n }\n\n /**\n * {@inheritDoc Validation.Validator.brand}\n */\n public get brand(): string | undefined {\n return this.traits.brand;\n }\n\n /**\n * {@inheritDoc Validation.Validator.validate}\n */\n public validate(from: unknown, context?: TC): Result<T> {\n const result = this._validator(from, this._context(context), this);\n if (typeof result === 'boolean') {\n return result ? succeed(from as T) : fail<T>('Invalid value');\n }\n return result;\n }\n\n /**\n * {@inheritDoc Validation.Validator.convert}\n */\n public convert(from: unknown, context?: TC): Result<T> {\n const result = this._validator(from, this._context(context), this);\n if (typeof result === 'boolean') {\n return result ? succeed(from as T) : fail<T>('Invalid value');\n }\n return result;\n }\n\n /**\n * {@inheritDoc Validation.Validator.validateOptional}\n */\n public validateOptional(from: unknown, context?: TC): Result<T | undefined> {\n return from === undefined ? succeed(undefined) : this.validate(from, context);\n }\n\n /**\n * {@inheritDoc Validation.Validator.guard}\n */\n public guard(from: unknown, context?: TC): from is T {\n return this._validator(from, this._context(context), this) === true;\n }\n\n /**\n * {@inheritDoc Validation.Validator.optional}\n */\n public optional(): Validator<T | undefined, TC> {\n return new GenericValidator({\n validator: (from: unknown, context?: TC, self?: Validator<T | undefined, TC>) => {\n return from === undefined || this._validator(from, this._context(context), this);\n },\n traits: { isOptional: true }\n });\n }\n\n /**\n * {@inheritDoc Validation.Validator.withConstraint}\n */\n public withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC> {\n trait = trait ?? { type: 'function' };\n return new GenericValidator({\n validator: (from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T> => {\n const result = this._validator(from, this._context(context), this);\n if (result === true) {\n const constraintResult = constraint(from as T);\n if (typeof constraintResult === 'boolean') {\n return constraintResult\n ? true\n : fail(`Invalid value \"${JSON.stringify(from)}\": does not meet constraint.`);\n }\n return constraintResult;\n }\n return result;\n },\n traits: { constraints: [trait] }\n });\n }\n\n /**\n * {@inheritDoc Validation.Validator.brand}\n */\n public withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC> {\n if (this.brand) {\n throw new Error(`Cannot replace existing brand \"${this.brand}\" with \"${brand}\".`);\n }\n\n return new GenericValidator<Brand<T, B>, TC>({\n validator: (from: unknown, context?: TC, self?: Validator<Brand<T, B>, TC>) => {\n return this._validator(from, this._context(context), this) as boolean | Failure<Brand<T, B>>;\n },\n traits: { brand }\n });\n }\n\n /**\n * {@inheritDoc Validation.Validator.withFormattedError}\n */\n public withFormattedError(formatter: ValidationErrorFormatter<TC>): Validator<T, TC> {\n return new GenericValidator<T, TC>({\n validator: (from: unknown, context?: TC, self?: Validator<T, TC>) => {\n const result = this._validator(from, this._context(context), this);\n if (result === true) {\n return true;\n }\n /* c8 ignore next - defense in depth */\n const message = result === false ? undefined : result.message;\n return fail(formatter(from, message, this._context(context)));\n }\n });\n }\n\n /**\n * {@inheritDoc Validation.Validator.or}\n */\n public or(other: Validator<T, TC>): Validator<T, TC> {\n return new GenericValidator<T, TC>({\n validator: (from: unknown, context?: TC, __self?: Validator<T, TC>): boolean | Failure<T> => {\n if (this._validator(from, this._context(context), this) === true) {\n return true;\n }\n const otherResult = other.validate(from, this._context(context));\n return otherResult.isSuccess() ? true : otherResult;\n }\n });\n }\n\n /**\n * Gets a default or explicit context.\n * @param explicitContext - Optional explicit context.\n * @returns The appropriate context to use.\n * @internal\n */\n protected _context(explicitContext?: TC): TC | undefined {\n return explicitContext ?? this._options.defaultContext;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/validation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAE5B,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './common';\nexport * from './traits';\nexport * from './validator';\n\nimport * as Classes from './classes';\nimport * as Base from './genericValidator';\nimport * as Validators from './validators';\n\nexport { Base, Classes, Validators };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../../src/packlets/validation/number.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAW,IAAI,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAqC,MAAM,oBAAoB,CAAC;AAWzF;;;GAGG;AACH,MAAM,OAAO,eAAyD,SAAQ,gBAAuB;IACnG;;;;OAIG;IACH,YAAmB,MAAgD;QACjE,sBAAsB;QACtB,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;QACtB,KAAK,iBACH,SAAS,EAAE,eAAe,CAAC,cAAc,IACtC,MAAM,EACT,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,cAAc,CAAmB,IAAa;QAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAI,IAAI,IAAI,iBAAiB,CAAC,CAAC;IAC5C,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { GenericValidator, GenericValidatorConstructorParams } from './genericValidator';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.NumberValidator | NumberValidator}.\n * @public\n */\nexport type NumberValidatorConstructorParams<\n T extends number = number,\n TC = unknown\n> = GenericValidatorConstructorParams<T, TC>;\n\n/**\n * An in-place {@link Validation.Validator | Validator} for `number` values.\n * @public\n */\nexport class NumberValidator<T extends number = number, TC = unknown> extends GenericValidator<T, TC> {\n /**\n * Constructs a new {@link Validation.Classes.NumberValidator | NumberValidator}.\n * @param params - Optional {@link Validation.Classes.NumberValidatorConstructorParams | init params} for the\n * new {@link Validation.Classes.NumberValidator | NumberValidator}.\n */\n public constructor(params?: NumberValidatorConstructorParams<T, TC>) {\n /* c8 ignore next 1 */\n params = params ?? {};\n super({\n validator: NumberValidator.validateNumber,\n ...params\n });\n }\n\n /**\n * Static method which validates that a supplied `unknown` value is a `number`.\n * @param from - The `unknown` value to be tested.\n * @returns Returns `true` if `from` is a `number`, or {@link Failure} with an error\n * message if not.\n */\n public static validateNumber<T extends number>(from: unknown): boolean | Failure<T> {\n if (typeof from === 'number') {\n return true;\n }\n return fail<T>(`\"${from}\": not a number`);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../../src/packlets/validation/object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAW,IAAI,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,aAAa,EAAkC,MAAM,iBAAiB,CAAC;AAEhF,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AA4CzC;;;;;;;GAOG;AACH,MAAM,OAAO,eAAiC,SAAQ,aAAoB;IAoBxE;;;OAGG;IACH,YAAmB,MAA+C;;QAChE,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,MA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AAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,cAAe,CAAC,GAAG,CAAC,CAAY,CAAC,CAAC,CAAC;YACzF,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,sCAAsC,CAAC,CAAC,CAAC;QACtF,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { Validator, ValidatorOptions } from './validator';\nimport { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';\n\nimport { FieldValidator } from './field';\n\n/**\n * Per-property {@link Validation.Validator | validators} for each of the properties in `<T>`.\n * @public\n */\nexport type FieldValidators<T, TC = unknown> = { [key in keyof T]: Validator<T[key], TC> };\n\n/**\n * Options for an {@link Validation.Classes.ObjectValidator | ObjectValidator}.\n * @public\n */\n\nexport interface ObjectValidatorOptions<T, TC> extends ValidatorOptions<TC> {\n /**\n * If present, lists optional fields. Missing non-optional fields cause an error.\n */\n optionalFields?: (keyof T)[];\n /**\n * If true, unrecognized fields yield an error. If false or undefined (default),\n * unrecognized fields are ignored.\n */\n strict?: boolean;\n}\n\n/**\n * Options for the {@link Validation.Classes.ObjectValidator | ObjectValidator} constructor.\n * @public\n */\n\nexport interface ObjectValidatorConstructorParams<T, TC> extends ValidatorBaseConstructorParams<T, TC> {\n /**\n * A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a\n * {@link Validation.Validator | Validator} for each of the expected properties\n * of a result object.\n */\n fields: FieldValidators<T>;\n /**\n * Optional additional {@link Validation.Classes.ObjectValidatorOptions | ValidatorOptions} to\n * configure validation.\n */\n options?: ObjectValidatorOptions<T, TC>;\n}\n\n/**\n * In-place {@link Validation.Validator | Validator} for an object of type `<T>`.\n * @remarks\n * By default, succeeds if all of the required fields exist and are validate, and fails if\n * any required fields do not exist or are invalid. See {@link Validation.Classes.ObjectValidatorOptions}\n * for other validation options.\n * @public\n */\nexport class ObjectValidator<T, TC = unknown> extends ValidatorBase<T, TC> {\n /**\n * A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a\n * {@link Validation.Validator | Validator} for each of the expected properties\n */\n public readonly fields: FieldValidators<T>;\n /**\n * {@link Validation.Classes.ObjectValidatorOptions | Options} which apply to this\n * validator.\n */\n public readonly options: ObjectValidatorOptions<T, TC>;\n /**\n * @internal\n */\n protected readonly _innerValidators: FieldValidators<T>;\n /**\n * @internal\n */\n protected readonly _allowedFields?: Set<keyof T>;\n\n /**\n * Constructs a new {@link Validation.Classes.ObjectValidator | ObjectValidator<T>}.\n * @param params - Construction parameters including field validators and options.\n */\n public constructor(params: ObjectValidatorConstructorParams<T, TC>) {\n super(params);\n\n this.fields = params.fields;\n this.options = params.options ?? {};\n this._innerValidators = ObjectValidator._resolveValidators(this.fields, this.options);\n this._allowedFields =\n this.options.strict === true ? new Set(Object.keys(this.fields) as (keyof T)[]) : undefined;\n }\n\n /**\n * Creates the actual {@link Validation.Classes.FieldValidators | FieldValidators<T>} to be\n * used by this converter by applying any options or traits defined in the options\n * to the field converters passed to the constructor.\n * @param fields - The base {@link Validation.Classes.FieldValidators | FieldValidators<T>} passed\n * in to the constructor.\n * @param options - The {@link Validation.Classes.ObjectValidatorOptions | object validator options}\n * passed in to the constructor.\n * @returns A new {@link Validation.Classes.FieldValidators | FieldValidators} with the fully-configured\n * individual {@link Validation.Validator | field validators} to be applied.\n * @internal\n */\n protected static _resolveValidators<T, TC>(\n fields: FieldValidators<T, TC>,\n options?: ObjectValidatorOptions<T, TC>\n ): FieldValidators<T, TC> {\n const resolved: Partial<FieldValidators<T, TC>> = {};\n for (const key in fields) {\n if (fields[key]) {\n /* c8 ignore next */\n const optional = fields[key].isOptional || options?.optionalFields?.includes(key);\n resolved[key] = new FieldValidator(key, fields[key], { optional });\n }\n }\n return resolved as FieldValidators<T, TC>;\n }\n\n /**\n * Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with\n * new optional properties as specified by a supplied\n * {@link Validation.Classes.ObjectValidatorOptions | ObjectValidatorOptions<T>}.\n * @param options - The {@link Validation.Classes.ObjectValidatorOptions | options} to be applied to the new\n * {@link Validation.Classes.ObjectValidator | validator}.\n * @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional\n * source properties.\n */\n public partial(options?: ObjectValidatorOptions<T, TC>): ObjectValidator<Partial<T>, TC> {\n /* c8 ignore next */\n options = options ?? {};\n return new ObjectValidator<Partial<T>, TC>({\n fields: this.fields as FieldValidators<Partial<T>, TC>,\n options: {\n ...this.options,\n ...options\n },\n traits: this.traits\n });\n }\n\n /**\n * Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with\n * new optional properties as specified by a supplied array of `keyof T`.\n * @param addOptionalFields - The keys to be made optional.\n * @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional\n * source properties.\n */\n public addPartial(addOptionalFields: (keyof T)[]): ObjectValidator<Partial<T>, TC> {\n return this.partial({\n optionalFields: [...(this.options.optionalFields ?? []), ...addOptionalFields]\n });\n }\n\n /**\n * {@inheritDoc Validation.ValidatorBase._validate}\n * @internal\n */\n protected _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T> {\n if (typeof from !== 'object' || from === null || Array.isArray(from)) {\n return fail('source is not an object');\n }\n\n // eslint bug thinks key is used before defined\n\n const converted = {} as { [key in keyof T]: T[key] };\n const errors: string[] = [];\n for (const key in this._innerValidators) {\n if (this._innerValidators[key]) {\n const result = this._innerValidators[key].validate(from, context);\n if (result.success && result.value !== undefined) {\n converted[key] = result.value;\n } else if (result.isFailure()) {\n errors.push(result.message);\n }\n }\n }\n\n if (this._allowedFields) {\n const invalid = Object.keys(from).filter((k) => !this._allowedFields!.has(k as keyof T));\n invalid.forEach((key) => errors.push(`${key}: unexpected field in source object.`));\n }\n return errors.length === 0 ? true : fail(errors.join('\\n'));\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oneOf.js","sourceRoot":"","sources":["../../../src/packlets/validation/oneOf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAW,IAAI,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,aAAa,EAAkC,MAAM,iBAAiB,CAAC;AAYhF;;;;GAIG;AACH,MAAM,OAAO,cAAgC,SAAQ,aAAoB;IASvE;;;;OAIG;IACH,YAAmB,MAA8C;;QAC/D,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;;OAQG;IACO,SAAS,CAAI,IAAa,EAAE,OAAY,EAAE,IAAuB;QACzE,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;QACrE,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,IAAI,iCAAiC,CAAC,CAAC;IAC/D,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2024 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { Validator, ValidatorOptions } from './validator';\nimport { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.OneOfValidator | OneOfValidator}.\n * @public\n */\n\nexport interface OneOfValidatorConstructorParams<T, TC = unknown>\n extends ValidatorBaseConstructorParams<T, TC> {\n validators: Validator<T, TC>[];\n}\n\n/**\n * An in-place {@link Validator | Validator} which validates that a supplied\n * value matches one of several other validators.\n * @public\n */\nexport class OneOfValidator<T, TC = unknown> extends ValidatorBase<T, TC> {\n /**\n * {@link Validation.ValidatorOptions | Options} which apply to this\n * validator.\n */\n public readonly options: ValidatorOptions<TC>;\n\n protected readonly _validators: Validator<T, TC>[];\n\n /**\n * Constructs a new {@link Validation.Classes.OneOfValidator | OneOfValidator}.\n * @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | init params} for the\n * new {@link Validation.Classes.OneOfValidator | OneOfValidator}.\n */\n public constructor(params: OneOfValidatorConstructorParams<T, TC>) {\n super(params);\n this._validators = params.validators;\n this.options = params.options ?? {};\n }\n\n /**\n * Static method which validates that a supplied `unknown` value matches at least one\n * of the configured validators.\n * @param from - The `unknown` value to be tested.\n * @param context - Optional validation context will be propagated to element validator.\n * @param self - Optional self-reference for recursive validation.\n * @returns Returns `true` if `from` is an `array` of valid elements, or\n * {@link Failure} with an error message if not.\n */\n protected _validate<T>(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T> {\n const found = this._validators.some((v) => v.validate(from).success);\n if (found) {\n return true;\n }\n return fail(`value \"${from}\" does not match any validator.`);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../../src/packlets/validation/string.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAW,IAAI,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAqC,MAAM,oBAAoB,CAAC;AAWzF;;;GAGG;AACH,MAAM,OAAO,eAAyD,SAAQ,gBAAuB;IACnG;;;;OAIG;IACH,YAAmB,MAAgD;QACjE,oBAAoB;QACpB,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;QACtB,KAAK,iBACH,SAAS,EAAE,eAAe,CAAC,cAAc,IACtC,MAAM,EACT,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,cAAc,CAAmB,IAAa;QAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAI,IAAI,IAAI,iBAAiB,CAAC,CAAC;IAC5C,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { GenericValidator, GenericValidatorConstructorParams } from './genericValidator';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.StringValidator | StringValidator}.\n * @public\n */\nexport type StringValidatorConstructorParams<\n T extends string = string,\n TC = unknown\n> = GenericValidatorConstructorParams<T, TC>;\n\n/**\n * An in-place {@link Validation.Validator | Validator} for `string` values.\n * @public\n */\nexport class StringValidator<T extends string = string, TC = unknown> extends GenericValidator<T, TC> {\n /**\n * Constructs a new {@link Validation.Classes.StringValidator | StringValidator}.\n * @param params - Optional {@link Validation.Classes.StringValidatorConstructorParams | init params}\n * for the new {@link Validation.Classes.StringValidator | StringValidator}.\n */\n public constructor(params?: StringValidatorConstructorParams<T, TC>) {\n /* c8 ignore next */\n params = params ?? {};\n super({\n validator: StringValidator.validateString,\n ...params\n });\n }\n\n /**\n * Static method which validates that a supplied `unknown` value is a `string`.\n * @param from - The `unknown` value to be tested.\n * @returns Returns `true` if `from` is a `string`, or {@link Failure} with an error\n * message if not.\n */\n public static validateString<T extends string>(from: unknown): boolean | Failure<T> {\n if (typeof from === 'string') {\n return true;\n }\n return fail<T>(`\"${from}\": not a string`);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traits.js","sourceRoot":"","sources":["../../../src/packlets/validation/traits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AA4CH;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAyB;IAC1D,UAAU,EAAE,KAAK;IACjB,WAAW,EAAE,EAAE;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,eAAe;IAgB1B;;;;;;;OAOG;IACH,YAAmB,IAAoC,EAAE,IAA2B;;QAClF,sBAAsB;QACtB,IAAI,CAAC,UAAU,GAAG,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,mCAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,mCAAI,sBAAsB,CAAC,UAAU,CAAC;QAC5F,IAAI,CAAC,KAAK,GAAG,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,mCAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,mCAAI,sBAAsB,CAAC,KAAK,CAAC;QACxE,IAAI,CAAC,WAAW,GAAG;YACjB,GAAG,sBAAsB,CAAC,WAAW;YACrC,sBAAsB;YACtB,GAAG,CAAC,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,mCAAI,EAAE,CAAC;YAC5B,GAAG,CAAC,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,mCAAI,EAAE,CAAC;SAC7B,CAAC;IACJ,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * A {@link Validation.ConstraintTrait | ConstraintTrait} indicating that\n * a {@link Validation.Constraint | Constraint<T>} function provides an\n * additional constraint implementation.\n * @public\n */\n\nexport interface FunctionConstraintTrait {\n type: 'function';\n}\n\n/**\n * Union of all supported constraint traits.\n * @public\n */\nexport type ConstraintTrait = FunctionConstraintTrait;\n\n/**\n * Interface describing the supported validator traits.\n * @public\n */\n\nexport interface ValidatorTraitValues {\n /**\n * Indicates whether the validator accepts `undefined` as\n * a valid value.\n */\n readonly isOptional: boolean;\n\n /**\n * If present, indicates that the result will be branded\n * with the corresponding brand.\n */\n readonly brand?: string;\n\n /**\n * Zero or more additional {@link Validation.ConstraintTrait | ConstraintTrait}s\n * describing additional constraints applied by this {@link Validation.Validator | Validator}.\n */\n readonly constraints: ConstraintTrait[];\n}\n\n/**\n * Default {@link Validation.ValidatorTraitValues | validation traits}.\n * @public\n */\nexport const defaultValidatorTraits: ValidatorTraitValues = {\n isOptional: false,\n constraints: []\n};\n\n/**\n * Generic implementation of {@link Validation.ValidatorTraitValues | ValidatorTraitValues}.\n * @public\n */\nexport class ValidatorTraits implements ValidatorTraitValues {\n /**\n * {@inheritDoc Validation.ValidatorTraitValues.isOptional}\n */\n public readonly isOptional: boolean;\n\n /**\n * {@inheritDoc Validation.ValidatorTraitValues.brand}\n */\n public readonly brand?: string;\n\n /**\n * {@inheritDoc Validation.ValidatorTraitValues.constraints}\n */\n public readonly constraints: ConstraintTrait[];\n\n /**\n * Constructs a new {@link Validation.ValidatorTraits | ValidatorTraits} optionally\n * initialized with the supplied base and initial values.\n * @remarks\n * Initial values take priority over base values, which fall back to the global default values.\n * @param init - Partial initial values to be set in the resulting {@link Validation.Validator | Validator}.\n * @param base - Base values to be used when no initial values are present.\n */\n public constructor(init?: Partial<ValidatorTraitValues>, base?: ValidatorTraitValues) {\n /* c8 ignore next 2 */\n this.isOptional = init?.isOptional ?? base?.isOptional ?? defaultValidatorTraits.isOptional;\n this.brand = init?.brand ?? base?.brand ?? defaultValidatorTraits.brand;\n this.constraints = [\n ...defaultValidatorTraits.constraints,\n /* c8 ignore next 1 */\n ...(base?.constraints ?? []),\n ...(init?.constraints ?? [])\n ];\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeGuard.js","sourceRoot":"","sources":["../../../src/packlets/validation/typeGuard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAW,IAAI,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,aAAa,EAAkC,MAAM,iBAAiB,CAAC;AAgBhF;;;;GAIG;AACH,MAAM,OAAO,kBAAoC,SAAQ,aAAoB;IAU3E;;;;OAIG;IACH,YAAmB,MAAkD;;QACnE,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;;;OASG;IACO,SAAS,CAAC,IAAa,EAAE,OAAY,EAAE,IAAuB;QACtE,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvE,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';\n\nimport { TypeGuardWithContext } from './common';\nimport { Validator, ValidatorOptions } from './validator';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.TypeGuardValidator}.\n * @public\n */\n\nexport interface TypeGuardValidatorConstructorParams<T, TC = unknown>\n extends ValidatorBaseConstructorParams<T, TC> {\n guard: TypeGuardWithContext<T, TC>;\n description: string;\n}\n\n/**\n * An in-place {@link Validation.Validator | Validator} that can be instantiated using a type guard\n * function.\n * @public\n */\nexport class TypeGuardValidator<T, TC = unknown> extends ValidatorBase<T, TC> {\n /**\n * {@link Validation.ValidatorOptions | Options} which apply to this\n * validator.\n */\n public readonly options: ValidatorOptions<TC>;\n public readonly description: string;\n\n protected readonly _guard: TypeGuardWithContext<T, TC>;\n\n /**\n * Constructs a new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.\n * @param params - Optional {@link Validation.Classes.TypeGuardValidatorConstructorParams | init params} for the\n * new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.\n */\n public constructor(params: TypeGuardValidatorConstructorParams<T, TC>) {\n super(params);\n this.description = params.description;\n this._guard = params.guard;\n this.options = params.options ?? {};\n }\n\n /**\n * Static method which validates that a supplied `unknown` value matches the supplied\n * type guard, returning a `Failure<T>` containing more information about a failure.\n * @param from - Value to be converted.\n * @param context - Optional validation context.\n * @param self - Optional self-reference for recursive validation.\n * @returns `true` if `from` is valid, {@link Failure | Failure<T>}\n * with an error message if `from` is invalid.\n * @internal\n */\n protected _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T> {\n if (this._guard(from, context)) {\n return true;\n }\n return fail(`invalid ${this.description} (${JSON.stringify(from)})`);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../../src/packlets/validation/validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Brand, Failure, Result } from '../base';\nimport { ConstraintTrait, ValidatorTraits } from './traits';\n\n/**\n * Type for a validation function, which validates that a supplied `unknown`\n * value is a valid value of type `<T>`, possibly as influenced by\n * an optionally-supplied validation context of type `<TC>`.\n * @public\n */\nexport type ValidatorFunc<T, TC> = (\n from: unknown,\n context?: TC,\n self?: Validator<T, TC>\n) => boolean | Failure<T>;\n\n/**\n * Options that apply to any {@link Validation.Validator | Validator}.\n * @public\n */\n\nexport interface ValidatorOptions<TC> {\n defaultContext?: TC;\n}\n\n/**\n * A {@link Validation.Constraint | Constraint<T>} function returns\n * `true` if the supplied value meets the constraint. Can return\n * {@link Failure} with an error message or simply return `false`\n * for a default message.\n * @public\n */\nexport type Constraint<T> = (val: T) => boolean | Failure<T>;\n\n/**\n * Formats an incoming error message and value that failed validation.\n * @param val - The value that failed validation.\n * @param message - The default error message, if any.\n * @param context - Optional validation context.\n * @returns The formatted error message.\n * @public\n */\nexport type ValidationErrorFormatter<TC = unknown> = (val: unknown, message?: string, context?: TC) => string;\n\n/**\n * In-place validation that a supplied unknown matches some\n * required characteristics (type, values, etc).\n * @public\n */\n\nexport interface Validator<T, TC = unknown> {\n /**\n * {@link Validation.ValidatorTraits | Traits} describing this validation.\n */\n readonly traits: ValidatorTraits;\n\n /**\n * Indicates whether this element is explicitly optional.\n */\n readonly isOptional: boolean;\n\n /**\n * The brand for a branded type.\n */\n readonly brand: string | undefined;\n\n /**\n * Tests to see if a supplied `unknown` value matches this validation. All\n * validate calls are guaranteed to return the entity passed in on Success.\n * @param from - The `unknown` value to be tested.\n * @param context - Optional validation context.\n * @returns {@link Success} with the typed, validated value,\n * or {@link Failure} with an error message if validation fails.\n */\n validate(from: unknown, context?: TC): Result<T>;\n\n /**\n * Tests to see if a supplied 'unknown' value matches this validation. In\n * contrast to {@link Validator.validate | validate}, makes no guarantees\n * about the identity of the returned value.\n * @param from - The `unknown` value to be tested.\n * @param context - Optional validation context.\n * @returns {@link Success} with the typed, conversion value,\n * or {@link Failure} with an error message if conversion fails.\n */\n convert(from: unknown, context?: TC): Result<T>;\n\n /**\n * Tests to see if a supplied `unknown` value matches this\n * validation. Accepts `undefined`.\n * @param from - The `unknown` value to be tested.\n * @param context - Optional validation context.\n * @returns {@link Success} with the typed, validated value,\n * or {@link Failure} with an error message if validation fails.\n */\n validateOptional(from: unknown, context?: TC): Result<T | undefined>;\n\n /**\n * Non-throwing type guard\n * @param from - The value to be tested.\n * @param context - Optional validation context.\n */\n guard(from: unknown, context?: TC): from is T;\n\n /**\n * Creates an {@link Validation.Validator | in-place validator}\n * which is derived from this one but which also matches `undefined`.\n */\n optional(): Validator<T | undefined, TC>;\n\n /**\n * Creates an {@link Validation.Validator | in-place validator}\n * which is derived from this one but which applies additional constraints.\n * @param constraint - the constraint to be applied\n * @param trait - As optional {@link Validation.ConstraintTrait | ConstraintTrait}\n * to be applied to the resulting {@link Validation.Validator | Validator}.\n * @returns A new {@link Validation.Validator | Validator}.\n */\n withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC>;\n\n /**\n * Creates a new {@link Validation.Validator | in-place validator} which\n * is derived from this one but which matches a branded result.\n * @param brand - The brand to be applied.\n */\n withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC>;\n\n /**\n * Creates a new {@link Validation.Validator | in-place validator} which\n * is derived from this one but which returns an error message supplied\n * by the provided formatter if an error occurs.\n * @param formatter - The error message formatter to be applied.\n * @returns A new {@link Validation.Validator | Validator}.\n */\n withFormattedError(formatter: ValidationErrorFormatter<TC>): Validator<T, TC>;\n\n /**\n * Chains this validator with another of the same type, to be attempted if this\n * validator fails.\n * @param other - The other {@link Validation.Validator | Validator} to be attempted\n * if this one fails.\n */\n or(other: Validator<T, TC>): Validator<T, TC>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatorBase.js","sourceRoot":"","sources":["../../../src/packlets/validation/validatorBase.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,gBAAgB,EAAqC,MAAM,oBAAoB,CAAC;AAazF;;;GAGG;AACH,MAAM,OAAgB,aAA+B,SAAQ,gBAAuB;IAClF;;;;OAIG;IACH,YAAsB,MAAsD;QAC1E,KAAK,iBACH,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,IACpE,MAAM,EACT,CAAC;IACL,CAAC;CAYF","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { GenericValidator, GenericValidatorConstructorParams } from './genericValidator';\nimport { Validator } from './validator';\n\nimport { Failure } from '../base';\n\n/**\n * @internal\n */\nexport type ValidatorBaseConstructorParams<T, TC> = Omit<\n GenericValidatorConstructorParams<T, TC>,\n 'validator'\n>;\n\n/**\n * Abstract base helper class for specific validator implementations\n * @internal\n */\nexport abstract class ValidatorBase<T, TC = unknown> extends GenericValidator<T, TC> {\n /**\n * Inner constructor\n * @param params - Initialization params.\n * @internal\n */\n protected constructor(params: Partial<ValidatorBaseConstructorParams<T, TC>>) {\n super({\n validator: (from, context, self) => this._validate(from, context, self),\n ...params\n });\n }\n\n /**\n * Abstract validation method to me implemented by derived classes.\n * @param from - Value to be converted.\n * @param context - Optional validation context.\n * @param self - Optional self-reference for recursive validation.\n * @returns `true` if `from` is valid, {@link Failure | Failure<T>}\n * with an error message if `from` is invalid.\n * @internal\n */\n protected abstract _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T>;\n}\n"]}
|