@fgv/ts-utils 5.1.0-2 → 5.1.0-21
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.map +1 -0
- package/dist/packlets/base/brand.js.map +1 -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.map +1 -0
- package/dist/packlets/base/result.js +227 -2
- package/dist/packlets/base/result.js.map +1 -0
- package/dist/packlets/base/utils.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.map +1 -0
- package/dist/packlets/collections/keyValueConverters.js.map +1 -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/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 +102 -16
- package/dist/packlets/conversion/baseConverter.js.map +1 -0
- package/dist/packlets/conversion/basicConverters.js.map +1 -0
- 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.map +1 -0
- package/dist/packlets/logging/logReporter.js.map +1 -0
- package/dist/packlets/logging/logger.js +33 -8
- package/dist/packlets/logging/logger.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 +441 -56
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts.map +1 -0
- 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.map +1 -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.map +1 -0
- package/lib/packlets/base/normalize.js.map +1 -0
- package/lib/packlets/base/result.d.ts +179 -1
- package/lib/packlets/base/result.d.ts.map +1 -0
- package/lib/packlets/base/result.js +231 -3
- package/lib/packlets/base/result.js.map +1 -0
- package/lib/packlets/base/utils.d.ts.map +1 -0
- package/lib/packlets/base/utils.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.map +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.map +1 -0
- 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/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 +102 -16
- package/lib/packlets/conversion/baseConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/baseConverter.js +102 -16
- package/lib/packlets/conversion/baseConverter.js.map +1 -0
- package/lib/packlets/conversion/basicConverters.d.ts.map +1 -0
- package/lib/packlets/conversion/basicConverters.js.map +1 -0
- package/lib/packlets/conversion/converter.d.ts.map +1 -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.map +1 -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 +33 -8
- package/lib/packlets/logging/logger.d.ts.map +1 -0
- package/lib/packlets/logging/logger.js +33 -8
- package/lib/packlets/logging/logger.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 +20 -18
- 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
|
@@ -92,51 +92,76 @@ function isDetailLogger(logger) {
|
|
|
92
92
|
class LoggerBase {
|
|
93
93
|
constructor(logLevel) {
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
95
|
+
* The level of logging to be used.
|
|
96
96
|
*/
|
|
97
97
|
this.logLevel = 'info';
|
|
98
98
|
this.logLevel = logLevel !== null && logLevel !== void 0 ? logLevel : 'info';
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
|
-
*
|
|
101
|
+
* Logs a detail message.
|
|
102
|
+
* @param message - The message to log.
|
|
103
|
+
* @param parameters - The parameters to log.
|
|
104
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
105
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
102
106
|
*/
|
|
103
107
|
detail(message, ...parameters) {
|
|
104
108
|
return this.log('detail', message, ...parameters);
|
|
105
109
|
}
|
|
106
110
|
/**
|
|
107
|
-
*
|
|
111
|
+
* Logs an info message.
|
|
112
|
+
* @param message - The message to log.
|
|
113
|
+
* @param parameters - The parameters to log.
|
|
114
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
115
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
108
116
|
*/
|
|
109
117
|
info(message, ...parameters) {
|
|
110
118
|
return this.log('info', message, ...parameters);
|
|
111
119
|
}
|
|
112
120
|
/**
|
|
113
|
-
*
|
|
121
|
+
* Logs a warning message.
|
|
122
|
+
* @param message - The message to log.
|
|
123
|
+
* @param parameters - The parameters to log.
|
|
124
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
125
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
114
126
|
*/
|
|
115
127
|
warn(message, ...parameters) {
|
|
116
128
|
return this.log('warning', message, ...parameters);
|
|
117
129
|
}
|
|
118
130
|
/**
|
|
119
|
-
*
|
|
131
|
+
* Logs an error message.
|
|
132
|
+
* @param message - The message to log.
|
|
133
|
+
* @param parameters - The parameters to log.
|
|
134
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
135
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
120
136
|
*/
|
|
121
137
|
error(message, ...parameters) {
|
|
122
138
|
return this.log('error', message, ...parameters);
|
|
123
139
|
}
|
|
124
140
|
/**
|
|
125
|
-
*
|
|
141
|
+
* Logs a short error summary at `error` level, then emits `detail` at `detail` level.
|
|
142
|
+
* @param message - Short human-readable summary.
|
|
143
|
+
* @param detail - Full detail (e.g. raw converter error) logged at `detail` level.
|
|
126
144
|
*/
|
|
127
145
|
errorWithDetail(message, detail) {
|
|
128
146
|
this.detail(detail);
|
|
129
147
|
return this.error(message);
|
|
130
148
|
}
|
|
131
149
|
/**
|
|
132
|
-
*
|
|
150
|
+
* Logs a short warning summary at `warning` level, then emits `detail` at `detail` level.
|
|
151
|
+
* @param message - Short human-readable summary.
|
|
152
|
+
* @param detail - Full detail logged at `detail` level.
|
|
133
153
|
*/
|
|
134
154
|
warnWithDetail(message, detail) {
|
|
135
155
|
this.detail(detail);
|
|
136
156
|
return this.warn(message);
|
|
137
157
|
}
|
|
138
158
|
/**
|
|
139
|
-
*
|
|
159
|
+
* Logs a message at the given level.
|
|
160
|
+
* @param level - The level of the message.
|
|
161
|
+
* @param message - The message to log.
|
|
162
|
+
* @param parameters - The parameters to log.
|
|
163
|
+
* @returns `Success` with the logged message if the level is enabled, or
|
|
164
|
+
* `Success` with `undefined` if the message is suppressed.
|
|
140
165
|
*/
|
|
141
166
|
log(level, message, ...parameters) {
|
|
142
167
|
if (shouldLog(level, this.logLevel)) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/packlets/logging/logger.ts"],"names":[],"mappings":";;;AAoCA,8BAmBC;AASD,8CAcC;AAyFD,wCAKC;AA5KD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,kCAA2E;AAQ3E;;;;;;GAMG;AACH,SAAgB,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,iCA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C;QACD,OAAO,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF;AA9BD,sCA8BC;AAED;;;GAGG;AACH,MAAa,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,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF;AAjBD,gCAiBC","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';\n\n/**\n * The level of logging to be used.\n * @public\n */\nexport type ReporterLogLevel = 'all' | 'detail' | 'info' | 'warning' | 'error' | 'silent';\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 * 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\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 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 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 @@
|
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/array.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAQ,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAEhF;;;GAGG;AAEH,MAAM,WAAW,+BAA+B,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAC9D,SAAQ,8BAA8B,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;IAC/C,eAAe,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;CACnC;AAED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gB,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBAC7D,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;oBACxB,OAAO,IAAA,WAAI,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAA,WAAI,EAAM,IAAI,IAAI,iBAAiB,CAAC,CAAC;IAC9C,CAAC;CACF;AA1CD,wCA0CC","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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/boolean.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAQ,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AAEzF;;;GAGG;AACH,MAAM,MAAM,iCAAiC,CAAC,EAAE,GAAG,OAAO,IAAI,iCAAiC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAE7G;;;GAGG;AACH,qBAAa,gBAAgB,CAAC,EAAE,GAAG,OAAO,CAAE,SAAQ,gBAAgB,CAAC,OAAO,EAAE,EAAE,CAAC;IAC/E;;;;OAIG;gBACgB,MAAM,CAAC,EAAE,iCAAiC,CAAC,EAAE,CAAC;IASjE;;;;;OAKG;WACW,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CAMzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../src/packlets/validation/boolean.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,yDAAyF;AAQzF;;;GAGG;AACH,MAAa,gBAA+B,SAAQ,mCAA6B;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,IAAA,WAAI,EAAC,IAAI,IAAI,kBAAkB,CAAC,CAAC;IAC1C,CAAC;CACF;AA3BD,4CA2BC","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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/classes.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,iCAAiC,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,qCAAqC,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EACL,eAAe,EACf,eAAe,EACf,gCAAgC,EAChC,sBAAsB,EACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classes.js","sourceRoot":"","sources":["../../../src/packlets/validation/classes.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,qBAAqB;AAErB,iCAA0E;AAAjE,uGAAA,cAAc,OAAA;AACvB,qCAAgF;AAAvE,2GAAA,gBAAgB,OAAA;AACzB,6CAA4F;AAAnF,mHAAA,oBAAoB,OAAA;AAC7B,mCAA6E;AAApE,yGAAA,eAAe,OAAA;AACxB,mCAKkB;AAHhB,yGAAA,eAAe,OAAA;AAIjB,iCAA0E;AAAjE,uGAAA,cAAc,OAAA;AACvB,mCAA6E;AAApE,yGAAA,eAAe,OAAA;AACxB,yCAAsF;AAA7E,+GAAA,kBAAkB,OAAA;AAE3B,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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/common.ts"],"names":[],"mappings":"AAsBA;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC"}
|
|
@@ -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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/compositeId.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAQ,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAEhF;;;GAGG;AACH,MAAM,WAAW,qCAAqC,CACpD,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,aAAa,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AAE,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,cAAO,CAAC,IAAI,CAAI,GAAG,KAAK,4BAA4B,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3G,CAAC;CACF;AA/CD,oDA+CC","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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/field.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAA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QACpG,CAAC;QACD,0CAA0C;QAC1C,OAAO,IAAA,WAAI,EAAC,0BAA0B,IAAI,CAAC,SAAS,sBAAsB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrG,CAAC;CACF;AA1DD,wCA0DC","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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/genericValidator.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,KAAK,EAAW,MAAM,EAAiB,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EACL,UAAU,EACV,wBAAwB,EACxB,SAAS,EACT,aAAa,EACb,gBAAgB,EACjB,MAAM,aAAa,CA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AC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,EAAE,CAAC,KAAuB;QAC/B,OAAO,IAAI,gBAAgB,CAAQ;YACjC,SAAS,EAAE,CAAC,IAAa,EAAE,OAAY,EAAE,MAAyB,EAAwB,EAAE;gBAC1F,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;oBACjE,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,MAAM,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;gBACjE,OAAO,WAAW,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC;YACtD,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACO,QAAQ,CAAC,eAAoB;QACrC,OAAO,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;IACzD,CAAC;CACF;AA3KD,4CA2KC","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, 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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/index.ts"],"names":[],"mappings":"AAsBA,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/validation/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,2CAAyB;AACzB,8CAA4B;AAE5B,mDAAqC;AAItB,0BAAO;AAHtB,yDAA2C;AAGlC,oBAAI;AAFb,yDAA2C;AAEnB,gCAAU","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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/number.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAQ,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AAEzF;;;GAGG;AACH,MAAM,MAAM,gCAAgC,CAC1C,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,EAAE,GAAG,OAAO,IACV,iCAAiC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAE7C;;;GAGG;AACH,qBAAa,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,OAAO,CAAE,SAAQ,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC;IACnG;;;;OAIG;gBACgB,MAAM,CAAC,EAAE,gCAAgC,CAAC,CAAC,EAAE,EAAE,CAAC;IASnE;;;;;OAKG;WACW,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAMpF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../../src/packlets/validation/number.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,yDAAyF;AAWzF;;;GAGG;AACH,MAAa,eAAyD,SAAQ,mCAAuB;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,IAAA,WAAI,EAAI,IAAI,IAAI,iBAAiB,CAAC,CAAC;IAC5C,CAAC;CACF;AA3BD,0CA2BC","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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/object.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAQ,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAIhF;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,IAAI;KAAG,GAAG,IAAI,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;CAAE,CAAC;AAE3F;;;GAGG;AAEH,MAAM,WAAW,sBAAsB,CAAC,CAAC,EAAE,EAAE,CAAE,SAAQ,gBAAgB,CAAC,EAAE,CAAC;IACzE;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;IAC7B;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;GAGG;AAEH,MAAM,WAAW,gCAAgC,CAAC,CAAC,EAAE,EAAE,CAAE,SAAQ,8BAA8B,CAAC,CAAC,EAAE,EAAE,CAAC;IACpG;;;;OAIG;IACH,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IAC3B;;;OAGG;IACH,OAAO,CAAC,EAAE,sBAAsB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;CACzC;AAED;;;;;;;GAOG;AACH,qBAAa,eAAe,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC;IACxE;;;OAGG;IACH,SAAgB,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IAC3C;;;OAGG;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AM,CAAC,SAAS,EAAE,EAAE,CAAC;oBAC9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,OAAO,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,IAAA,WAAI,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF;AA9HD,0CA8HC","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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/oneOf.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAQ,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,E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AU,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,IAAA,WAAI,EAAC,UAAU,IAAI,iCAAiC,CAAC,CAAC;IAC/D,CAAC;CACF;AApCD,wCAoCC","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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/string.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAQ,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AAEzF;;;GAGG;AACH,MAAM,MAAM,gCAAgC,CAC1C,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,EAAE,GAAG,OAAO,IACV,iCAAiC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAE7C;;;GAGG;AACH,qBAAa,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,OAAO,CAAE,SAAQ,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC;IACnG;;;;OAIG;gBACgB,MAAM,CAAC,EAAE,gCAAgC,CAAC,CAAC,EAAE,EAAE,CAAC;IASnE;;;;;OAKG;WACW,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAMpF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../../src/packlets/validation/string.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,yDAAyF;AAWzF;;;GAGG;AACH,MAAa,eAAyD,SAAQ,mCAAuB;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,IAAA,WAAI,EAAI,IAAI,IAAI,iBAAiB,CAAC,CAAC;IAC5C,CAAC;CACF;AA3BD,0CA2BC","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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/traits.ts"],"names":[],"mappings":"AAsBA;;;;;GAKG;AAEH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEtD;;;GAGG;AAEH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,eAAe,EAAE,CAAC;CACzC;AAED;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,oBAGpC,CAAC;AAEF;;;GAGG;AACH,qBAAa,eAAgB,YAAW,oBAAoB;IAC1D;;OAEG;IACH,SAAgB,UAAU,EAAE,OAAO,CAAC;IAEpC;;OAEG;IACH,SAAgB,KAAK,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,SAAgB,WAAW,EAAE,eAAe,EAAE,CAAC;IAE/C;;;;;;;OAOG;gBACgB,IAAI,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,EAAE,IAAI,CAAC,EAAE,oBAAoB;CAWrF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traits.js","sourceRoot":"","sources":["../../../src/packlets/validation/traits.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AA4CH;;;GAGG;AACU,QAAA,sBAAsB,GAAyB;IAC1D,UAAU,EAAE,KAAK;IACjB,WAAW,EAAE,EAAE;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAa,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,8BAAsB,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,8BAAsB,CAAC,KAAK,CAAC;QACxE,IAAI,CAAC,WAAW,GAAG;YACjB,GAAG,8BAAsB,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;AAnCD,0CAmCC","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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/typeGuard.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAQ,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAEhF,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE1D;;;GAGG;AAEH,MAAM,WAAW,mCAAmC,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAClE,SAAQ,8BAA8B,CAAC,CAAC,EAAE,EAAE,CAAC;IAC7C,KAAK,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,qBAAa,kBAAkB,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC;IAC3E;;;OAGG;IACH,SAAgB,OAAO,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC9C,SAAgB,WAAW,EAAE,MAAM,CAAC;IAEpC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEvD;;;;OAIG;gBACgB,MAAM,EAAE,mCAAmC,CAAC,CAAC,EAAE,EAAE,CAAC;IAOrE;;;;;;;;;OASG;IACH,SAAS,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAMhG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeGuard.js","sourceRoot":"","sources":["../../../src/packlets/validation/typeGuard.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,mDAAgF;AAgBhF;;;;GAIG;AACH,MAAa,kBAAoC,SAAQ,6BAAoB;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,IAAA,WAAI,EAAC,WAAW,IAAI,CAAC,WAAW,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvE,CAAC;CACF;AAtCD,gDAsCC","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.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/validator.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,EAAE,IAAI,CACjC,IAAI,EAAE,OAAO,EACb,OAAO,CAAC,EAAE,EAAE,EACZ,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,KACpB,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE1B;;;GAGG;AAEH,MAAM,WAAW,gBAAgB,CAAC,EAAE;IAClC,cAAc,CAAC,EAAE,EAAE,CAAC;CACrB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,MAAM,wBAAwB,CAAC,EAAE,GAAG,OAAO,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,KAAK,MAAM,CAAC;AAE9G;;;;GAIG;AAEH,MAAM,WAAW,SAAS,CA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;;OAKG;IACH,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;CAC/C"}
|
|
@@ -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"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GenericValidator, GenericValidatorConstructorParams } from './genericValidator';
|
|
2
|
+
import { Validator } from './validator';
|
|
2
3
|
import { Failure } from '../base';
|
|
3
4
|
/**
|
|
4
5
|
* @internal
|
|
@@ -24,6 +25,6 @@ export declare abstract class ValidatorBase<T, TC = unknown> extends GenericVali
|
|
|
24
25
|
* with an error message if `from` is invalid.
|
|
25
26
|
* @internal
|
|
26
27
|
*/
|
|
27
|
-
protected abstract _validate(from: unknown, context?: TC, self?:
|
|
28
|
+
protected abstract _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T>;
|
|
28
29
|
}
|
|
29
30
|
//# sourceMappingURL=validatorBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatorBase.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/validatorBase.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,gBAAgB,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;GAEG;AACH,MAAM,MAAM,8BAA8B,CAAC,CAAC,EAAE,EAAE,IAAI,IAAI,CACtD,iCAAiC,CAAC,CAAC,EAAE,EAAE,CAAC,EACxC,WAAW,CACZ,CAAC;AAEF;;;GAGG;AACH,8BAAsB,aAAa,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAAE,SAAQ,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC;IAClF;;;;OAIG;IACH,SAAS,aAAa,MAAM,EAAE,OAAO,CAAC,8BAA8B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAO5E;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CACzG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatorBase.js","sourceRoot":"","sources":["../../../src/packlets/validation/validatorBase.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,yDAAyF;AAazF;;;GAGG;AACH,MAAsB,aAA+B,SAAQ,mCAAuB;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;AAvBD,sCAuBC","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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/validators.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,qCAAqC,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC;AAGtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGhD,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAE1E,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEvD;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,SAAS,CAAC,MAAM,CAAyB,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,SAAS,CAAC,MAAM,CAAyB,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,OAAO,EAAE,SAAS,CAAC,OAAO,CAA0B,CAAC;AAElE;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,EACpC,MAAM,EAAE,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,EAC9B,MAAM,CAAC,EAAE,IAAI,CAAC,gCAAgC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,GAC/D,eAAe,CAAC,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AAC,EAAE,CAAC,CAAC;QAC9F,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,WAAW,CAMzB,MAA4E;IAE5E,OAAO,IAAI,kCAAoB,CAAgC,MAAM,CAAC,CAAC;AACzE,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,KAAK,CACnB,UAAmC,EACnC,MAAmE;IAEnE,OAAO,IAAI,sBAAc,iCAAa,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,KAAE,UAAU,IAAG,CAAC;AACtE,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,GAAG,CACjB,WAAmB,EACnB,KAAkC,EAClC,MAAkF;IAElF,OAAO,IAAI,8BAAkB,iBAAG,WAAW,EAAE,KAAK,IAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EAAG,CAAC;AAC3E,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,OAAO,CAAkB,SAA+B;IACtE,OAAO,IAAI,mCAAgB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/*\n * Copyright (c) 2023 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, MessageAggregator } from '../base';\nimport { ArrayValidator, ArrayValidatorConstructorParams } from './array';\nimport { CompositeIdValidator, CompositeIdValidatorConstructorParams } from './compositeId';\nimport { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams } from './object';\nimport { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';\n\nimport { BooleanValidator } from './boolean';\nimport { TypeGuardWithContext } from './common';\nimport { GenericValidator } from './genericValidator';\nimport { NumberValidator } from './number';\nimport { OneOfValidator, OneOfValidatorConstructorParams } from './oneOf';\nimport { StringValidator } from './string';\nimport { Validator, ValidatorFunc } from './validator';\n\n/**\n * A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.\n * @public\n */\nexport const string: Validator<string> = new StringValidator();\n\n/**\n * A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.\n * @public\n */\nexport const number: Validator<number> = new NumberValidator();\n\n/**\n * A {@link Validation.Classes.BooleanValidator | BooleanValidator} which validates a boolean in place.\n * @public\n */\nexport const boolean: Validator<boolean> = new BooleanValidator();\n\n/**\n * Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates\n * an object in place.\n * @param fields - A {@link Validation.Classes.FieldValidators | field validator definition}\n * describing the validations to be applied.\n * @param params - Optional {@link Validation.Classes.ObjectValidatorConstructorParams | parameters}\n * to refine the behavior of the resulting {@link Validation.Validator | validator}.\n * @returns A new {@link Validation.Validator | Validator} which validates the desired\n * object in place.\n * @public\n */\nexport function object<T, TC = unknown>(\n fields: FieldValidators<T, TC>,\n params?: Omit<ObjectValidatorConstructorParams<T, TC>, 'fields'>\n): ObjectValidator<T, TC> {\n return new ObjectValidator({ fields, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.ArrayValidator | ArrayValidator} which\n * validates an array in place.\n * @param validateElement - A {@link Validation.Validator | validator} which validates each element.\n * @returns A new {@link Validation.Classes.ArrayValidator | ArrayValidator } which validates the desired\n * array in place.\n * @public\n */\nexport function arrayOf<T, TC>(\n validateElement: Validator<T, TC>,\n params?: Omit<ArrayValidatorConstructorParams<T, TC>, 'validateElement'>\n): ArrayValidator<T, TC> {\n return new ArrayValidator({ validateElement, ...(params ?? {}) });\n}\n\n/**\n * Options for {@link Validators.recordOf} helper function.\n * @public\n */\nexport interface IRecordOfValidatorOptions<TK extends string = string, TC = unknown> {\n /**\n * If `onError` is `'fail'` (default), then the entire validation fails if any key or element\n * cannot be validated. If `onError` is `'ignore'`, failing elements are silently ignored.\n */\n onError?: 'fail' | 'ignore';\n /**\n * If present, `keyValidator` is used to validate the source object property names.\n * @remarks\n * Can be used to validate key names to supported values and/or strong types.\n */\n keyValidator?: Validator<TK, TC>;\n}\n\n/**\n * A helper function to create a {@link Validation.Validator | Validator} which validates the `string`-keyed properties\n * using a supplied {@link Validation.Validator | Validator<T, TC>} to produce a `Record<TK, T>`.\n * @remarks\n * If present, the supplied {@link Validators.IRecordOfValidatorOptions | options} can provide a strongly-typed\n * validator for keys and/or control the handling of elements that fail validation.\n * @param validator - {@link Validation.Validator | Validator} used for each item in the source object.\n * @param options - Optional {@link Validators.IRecordOfValidatorOptions | IRecordOfValidatorOptions<TK, TC>} which\n * supplies a key validator and/or error-handling options.\n * @returns A {@link Validation.Validator | Validator} which validates `Record<TK, T>`.\n * @public\n */\nexport function recordOf<T, TC = unknown, TK extends string = string>(\n validator: Validator<T, TC>,\n options?: IRecordOfValidatorOptions<TK, TC>\n): Validator<Record<TK, T>, TC> {\n const opts: IRecordOfValidatorOptions<TK, TC> = { onError: 'fail', ...options };\n\n return new GenericValidator({\n validator: (\n from: unknown,\n context?: TC,\n self?: Validator<Record<TK, T>, TC>\n ): boolean | Failure<Record<TK, T>> => {\n if (typeof from !== 'object' || from === null || Array.isArray(from)) {\n return fail(`Not a string-keyed object: ${JSON.stringify(from)}`);\n }\n\n const errors = new MessageAggregator();\n\n for (const key in from) {\n if (isKeyOf(key, from)) {\n // Validate key if keyValidator is provided\n if (opts.keyValidator) {\n const keyResult = opts.keyValidator.validate(key, context);\n if (!keyResult.isSuccess()) {\n if (opts.onError === 'ignore') {\n continue;\n }\n errors.addMessage(`Key \"${key}\": ${keyResult.message}`);\n if (opts.onError === 'fail') {\n return fail(keyResult.message);\n }\n }\n }\n\n // Validate value\n const valueResult = validator.validate(from[key] as unknown, context);\n if (!valueResult.isSuccess()) {\n if (opts.onError === 'ignore') {\n continue;\n }\n errors.addMessage(`Property \"${key}\": ${valueResult.message}`);\n if (opts.onError === 'fail') {\n return fail(valueResult.message);\n }\n }\n }\n }\n\n /* c8 ignore next 1 - defense in depth */\n return errors.hasMessages ? fail(errors.toString()) : true;\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates an enumerated\n * value in place.\n * @public\n */\nexport function enumeratedValue<T extends string>(values: ReadonlyArray<T>): Validator<T, ReadonlyArray<T>> {\n return new GenericValidator({\n validator: (\n from: unknown,\n context?: ReadonlyArray<T>,\n self?: Validator<T, ReadonlyArray<T>>\n ): boolean | Failure<T> => {\n if (typeof from === 'string') {\n const v = context ?? values;\n const index = v.indexOf(from as T);\n return index >= 0 ? true : fail(`Invalid enumerated value \"${from}\" - expected: (${v.join(', ')})`);\n }\n return fail(`Not a string: \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates a literal value.\n * @param value - the literal value to be validated\n * @public\n */\nexport function literal<T extends string | number | boolean | symbol | null | undefined>(\n value: T\n): Validator<T> {\n return new GenericValidator({\n validator: (from: unknown, context?: unknown, self?: Validator<T>): boolean | Failure<T> => {\n return from === value\n ? true\n : fail(`Expected literal ${String(value)}, found \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/** Helper function to create a {@link Validation.Validator | Validator} which validates a\n * strongly-typed composite ID.\n * @param params - {@link Validation.Classes.CompositeIdValidatorConstructorParams | params}\n * used to construct the validator.\n * @returns A new {@link Validation.Validator | Validator} which validates the desired\n * composite ID in place.\n * @public\n */\nexport function compositeId<\n T extends string = string,\n TCOLLECTIONID extends string = string,\n TITEMID extends string = string,\n TC = unknown\n>(\n params: CompositeIdValidatorConstructorParams<T, TCOLLECTIONID, TITEMID, TC>\n): CompositeIdValidator<T, TCOLLECTIONID, TITEMID, TC> {\n return new CompositeIdValidator<T, TCOLLECTIONID, TITEMID, TC>(params);\n}\n\n/**\n * Helper function to create a {@link Validation.Validator | Validator} which validates one\n * of several possible validated values.\n * @param validators - the {@link Validation.Validator | validators} to be considered.\n * @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | params} used to construct the validator.\n * @returns A new {@link Validator | Validator} which validates values that match any of\n * the supplied validators.\n * @public\n */\nexport function oneOf<T, TC = unknown>(\n validators: Array<Validator<T, TC>>,\n params?: Omit<OneOfValidatorConstructorParams<T, TC>, 'validators'>\n): OneOfValidator<T, TC> {\n return new OneOfValidator<T, TC>({ ...(params ?? {}), validators });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator} which\n * validates a value or object in place.\n * @param description - a description of the thing to be validated for use in error messages\n * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.\n * @returns A new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator } which validates\n * the values using the supplied type guard.\n * @public\n */\nexport function isA<T, TC = unknown>(\n description: string,\n guard: TypeGuardWithContext<T, TC>,\n params?: Omit<TypeGuardValidatorConstructorParams<T, TC>, 'description' | 'guard'>\n): TypeGuardValidator<T, TC> {\n return new TypeGuardValidator({ description, guard, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator | Validator} using a\n * supplied {@link Validation.ValidatorFunc | validator function}.\n * @param validator - A {@link Validation.ValidatorFunc | validator function} that a\n * supplied unknown value matches some condition.\n * @returns A new {@link Validation.Validator | Validator} which validates the desired\n * value using the supplied function.\n * @public\n */\nexport function generic<T, TC = unknown>(validator: ValidatorFunc<T, TC>): Validator<T, TC> {\n return new GenericValidator({ validator });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-utils",
|
|
3
|
-
"version": "5.1.0-
|
|
3
|
+
"version": "5.1.0-21",
|
|
4
4
|
"description": "Assorted Typescript Utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -13,18 +13,6 @@
|
|
|
13
13
|
"default": "./lib/index.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "heft build --clean",
|
|
18
|
-
"clean": "heft clean",
|
|
19
|
-
"test": "heft test --clean",
|
|
20
|
-
"build-docs": "typedoc --options ./config/typedoc.json",
|
|
21
|
-
"build-all": "rushx build; rushx build-docs",
|
|
22
|
-
"test-handles": "jest --runInBand --detectOpenHandles",
|
|
23
|
-
"clean-jest": "jest --clear-cache",
|
|
24
|
-
"coverage": "jest --coverage",
|
|
25
|
-
"lint": "eslint src --ext .ts",
|
|
26
|
-
"fixlint": "eslint src --ext .ts --fix"
|
|
27
|
-
},
|
|
28
16
|
"sideEffects": false,
|
|
29
17
|
"keywords": [
|
|
30
18
|
"typescript",
|
|
@@ -37,7 +25,6 @@
|
|
|
37
25
|
},
|
|
38
26
|
"homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#readme",
|
|
39
27
|
"devDependencies": {
|
|
40
|
-
"@fgv/heft-dual-rig": "workspace:*",
|
|
41
28
|
"@jest/expect-utils": "^29.7.0",
|
|
42
29
|
"@microsoft/api-documenter": "^7.28.2",
|
|
43
30
|
"@microsoft/api-extractor": "^7.55.2",
|
|
@@ -60,15 +47,30 @@
|
|
|
60
47
|
"typescript": "5.9.3",
|
|
61
48
|
"eslint-plugin-n": "^17.23.1",
|
|
62
49
|
"jest-snapshot": "~29.7.0",
|
|
63
|
-
"@rushstack/heft": "1.2.
|
|
64
|
-
"@rushstack/heft-node-rig": "2.11.
|
|
50
|
+
"@rushstack/heft": "1.2.7",
|
|
51
|
+
"@rushstack/heft-node-rig": "2.11.27",
|
|
65
52
|
"@rushstack/eslint-config": "4.6.4",
|
|
66
53
|
"@types/heft-jest": "1.0.6",
|
|
67
54
|
"@rushstack/heft-jest-plugin": "1.2.6",
|
|
68
|
-
"eslint-plugin-tsdoc": "~0.5.2"
|
|
55
|
+
"eslint-plugin-tsdoc": "~0.5.2",
|
|
56
|
+
"typedoc": "~0.28.16",
|
|
57
|
+
"@fgv/heft-dual-rig": "5.1.0-21",
|
|
58
|
+
"@fgv/typedoc-compact-theme": "5.1.0-21"
|
|
69
59
|
},
|
|
70
60
|
"repository": {
|
|
71
61
|
"type": "git",
|
|
72
62
|
"url": "https://github.com/ErikFortune/fgv.git"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "heft build --clean",
|
|
66
|
+
"clean": "heft clean",
|
|
67
|
+
"test": "heft test --clean",
|
|
68
|
+
"build-docs": "typedoc --options ./config/typedoc.json",
|
|
69
|
+
"build-all": "rushx build; rushx build-docs",
|
|
70
|
+
"test-handles": "jest --runInBand --detectOpenHandles",
|
|
71
|
+
"clean-jest": "jest --clear-cache",
|
|
72
|
+
"coverage": "jest --coverage",
|
|
73
|
+
"lint": "eslint src --ext .ts",
|
|
74
|
+
"fixlint": "eslint src --ext .ts --fix"
|
|
73
75
|
}
|
|
74
|
-
}
|
|
76
|
+
}
|