@fgv/ts-utils
Advanced tools
Comparing version 3.0.1-alpha.0 to 3.0.1-alpha.1
@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard. | ||
"packageName": "@microsoft/api-extractor", | ||
"packageVersion": "7.39.1" | ||
"packageVersion": "7.39.4" | ||
} | ||
] | ||
} |
@@ -59,6 +59,2 @@ import { Brand, Result } from '../base'; | ||
/** | ||
* {@inheritdoc Converter.convalidate} | ||
*/ | ||
convalidate(from: unknown, context?: TC): Result<T>; | ||
/** | ||
* {@inheritdoc Converter.convertOptional} | ||
@@ -65,0 +61,0 @@ */ |
@@ -68,8 +68,2 @@ "use strict"; | ||
/** | ||
* {@inheritdoc Converter.convalidate} | ||
*/ | ||
convalidate(from, context) { | ||
return this._converter(from, this, context !== null && context !== void 0 ? context : this._defaultContext); | ||
} | ||
/** | ||
* {@inheritdoc Converter.convertOptional} | ||
@@ -76,0 +70,0 @@ */ |
import { Brand, Result, Success } from '../base'; | ||
import { Convalidator } from '../validation'; | ||
/** | ||
@@ -33,3 +32,3 @@ * Action to take on conversion failures. | ||
*/ | ||
export interface Converter<T, TC = undefined> extends ConverterTraits, Convalidator<T, TC> { | ||
export interface Converter<T, TC = undefined> extends ConverterTraits { | ||
/** | ||
@@ -54,6 +53,2 @@ * Indicates whether this element is explicitly optional. | ||
/** | ||
* {@inheritdoc Validation.Convalidator.convalidate} | ||
*/ | ||
convalidate(from: unknown, context?: TC): Result<T>; | ||
/** | ||
* Converts from `unknown` to `<T>` or `undefined`, as appropriate. | ||
@@ -198,7 +193,3 @@ * | ||
convert(from: unknown, ctx?: TC): Success<T | TD>; | ||
/** | ||
* {@inheritdoc Converter.convalidate} | ||
*/ | ||
convalidate(from: unknown, ctx?: TC): Success<T | TD>; | ||
} | ||
//# sourceMappingURL=converter.d.ts.map |
@@ -278,3 +278,3 @@ "use strict"; | ||
for (const converter of converters) { | ||
const result = converter.convalidate(from, context); | ||
const result = converter.convert(from, context); | ||
if (result.isSuccess() && result.value !== undefined) { | ||
@@ -313,3 +313,3 @@ return result; | ||
for (const item of from) { | ||
const result = converter.convalidate(item, context); | ||
const result = converter.convert(item, context); | ||
if (result.isSuccess() && result.value !== undefined) { | ||
@@ -359,6 +359,6 @@ successes.push(result.value); | ||
if ((0, base_1.isKeyOf)(key, from)) { | ||
const writeKeyResult = (_b = (_a = options.keyConverter) === null || _a === void 0 ? void 0 : _a.convalidate(key, context)) !== null && _b !== void 0 ? _b : (0, base_1.succeed)(key); | ||
const writeKeyResult = (_b = (_a = options.keyConverter) === null || _a === void 0 ? void 0 : _a.convert(key, context)) !== null && _b !== void 0 ? _b : (0, base_1.succeed)(key); | ||
writeKeyResult | ||
.onSuccess((writeKey) => { | ||
return converter.convalidate(from[key], context).onSuccess((value) => { | ||
return converter.convert(from[key], context).onSuccess((value) => { | ||
record[writeKey] = value; | ||
@@ -395,6 +395,6 @@ return (0, base_1.succeed)(true); | ||
if ((0, base_1.isKeyOf)(key, from)) { | ||
const writeKeyResult = (_b = (_a = options.keyConverter) === null || _a === void 0 ? void 0 : _a.convalidate(key, context)) !== null && _b !== void 0 ? _b : (0, base_1.succeed)(key); | ||
const writeKeyResult = (_b = (_a = options.keyConverter) === null || _a === void 0 ? void 0 : _a.convert(key, context)) !== null && _b !== void 0 ? _b : (0, base_1.succeed)(key); | ||
writeKeyResult | ||
.onSuccess((writeKey) => { | ||
return converter.convalidate(from[key], context).onSuccess((value) => { | ||
return converter.convert(from[key], context).onSuccess((value) => { | ||
map.set(writeKey, value); | ||
@@ -456,3 +456,3 @@ return (0, base_1.succeed)(true); | ||
} | ||
return converter.convalidate(from[index], context); | ||
return converter.convert(from[index], context); | ||
}); | ||
@@ -484,3 +484,3 @@ } | ||
} | ||
return converter.convalidate(from[index], context); | ||
return converter.convert(from[index], context); | ||
}); | ||
@@ -505,3 +505,3 @@ } | ||
if ((0, base_1.isKeyOf)(name, from)) { | ||
return converter.convalidate(from[name], context).onFailure((message) => { | ||
return converter.convert(from[name], context).onFailure((message) => { | ||
return (0, base_1.fail)(`Field ${name}: ${message}`); | ||
@@ -532,3 +532,3 @@ }); | ||
if ((0, base_1.isKeyOf)(name, from)) { | ||
const result = converter.convalidate(from[name], context).onFailure((message) => { | ||
const result = converter.convert(from[name], context).onFailure((message) => { | ||
return (0, base_1.fail)(`${name}: ${message}`); | ||
@@ -597,3 +597,3 @@ }); | ||
} | ||
return converter.convalidate(from); | ||
return converter.convert(from); | ||
}); | ||
@@ -629,3 +629,3 @@ } | ||
if (properties[key]) { | ||
const result = properties[key].convalidate(from, context); | ||
const result = properties[key].convert(from, context); | ||
if (result.isSuccess() && result.value !== undefined) { | ||
@@ -676,3 +676,3 @@ converted[key] = result.value; | ||
if ((0, base_1.isKeyOf)(srcKey, from)) { | ||
const result = converter.convalidate(from[srcKey], context); | ||
const result = converter.convert(from[srcKey], context); | ||
if (result.isSuccess() && result.value !== undefined) { | ||
@@ -679,0 +679,0 @@ converted[destinationKey] = result.value; |
@@ -33,6 +33,2 @@ import { Brand, Result, Success } from '../base'; | ||
/** | ||
* {@inheritdoc Converter.convalidate} | ||
*/ | ||
convalidate(from: unknown, ctx?: TC | undefined): Success<T | TD>; | ||
/** | ||
* {@inheritdoc Converter.convertOptional} | ||
@@ -39,0 +35,0 @@ */ |
@@ -60,8 +60,2 @@ "use strict"; | ||
/** | ||
* {@inheritdoc Converter.convalidate} | ||
*/ | ||
convalidate(from, ctx) { | ||
return this.convert(from, ctx); | ||
} | ||
/** | ||
* {@inheritdoc Converter.convertOptional} | ||
@@ -68,0 +62,0 @@ */ |
@@ -56,5 +56,5 @@ import { Brand, Failure, Result } from '../base'; | ||
/** | ||
* {@inheritdoc Validation.Validator.convalidate} | ||
* {@inheritdoc Validation.Validator.convert} | ||
*/ | ||
convalidate(from: unknown, context?: TC): Result<T>; | ||
convert(from: unknown, context?: TC): Result<T>; | ||
/** | ||
@@ -61,0 +61,0 @@ * {@inheritdoc Validation.Validator.validateOptional} |
@@ -69,5 +69,5 @@ "use strict"; | ||
/** | ||
* {@inheritdoc Validation.Validator.convalidate} | ||
* {@inheritdoc Validation.Validator.convert} | ||
*/ | ||
convalidate(from, context) { | ||
convert(from, context) { | ||
const result = this._validator(from, this._context(context)); | ||
@@ -74,0 +74,0 @@ if (typeof result === 'boolean') { |
export * from './common'; | ||
export * from './convalidator'; | ||
export * from './traits'; | ||
@@ -4,0 +3,0 @@ export * from './validator'; |
@@ -52,3 +52,2 @@ "use strict"; | ||
__exportStar(require("./common"), exports); | ||
__exportStar(require("./convalidator"), exports); | ||
__exportStar(require("./traits"), exports); | ||
@@ -55,0 +54,0 @@ __exportStar(require("./validator"), exports); |
import { Brand, Failure, Result } from '../base'; | ||
import { Convalidator } from './convalidator'; | ||
import { ConstraintTrait, ValidatorTraits } from './traits'; | ||
@@ -24,3 +23,3 @@ /** | ||
*/ | ||
export interface Validator<T, TC = undefined> extends Convalidator<T, TC> { | ||
export interface Validator<T, TC = undefined> { | ||
/** | ||
@@ -48,5 +47,11 @@ * {@link Validation.ValidatorTraits | Traits} describing this validation. | ||
/** | ||
* {@inheritdoc Validation.Convalidator.convalidate} | ||
* Tests to see if a supplied 'unknown' value matches this validation. In | ||
* contrast to {@link Validator.validate | validate}, makes no guarantees | ||
* about the identity of the returned value. | ||
* @param from - The `unknown` value to be tested. | ||
* @param context - Optional validation context. | ||
* @returns {@link Success} with the typed, conversion value, | ||
* or {@link Failure} with an error message if conversion fails. | ||
*/ | ||
convalidate(from: unknown, context?: TC): Result<T>; | ||
convert(from: unknown, context?: TC): Result<T>; | ||
/** | ||
@@ -53,0 +58,0 @@ * Tests to see if a supplied `unknown` value matches this |
{ | ||
"name": "@fgv/ts-utils", | ||
"version": "3.0.1-alpha.0", | ||
"version": "3.0.1-alpha.1", | ||
"description": "Assorted Typescript Utilities", | ||
@@ -32,10 +32,10 @@ "main": "lib/index.js", | ||
"@jest/expect-utils": "^29.7.0", | ||
"@microsoft/api-documenter": "^7.23.17", | ||
"@microsoft/api-extractor": "^7.39.1", | ||
"@types/jest": "^29.5.11", | ||
"@types/luxon": "^3.4.1", | ||
"@microsoft/api-documenter": "^7.23.20", | ||
"@microsoft/api-extractor": "^7.39.4", | ||
"@types/jest": "^29.5.12", | ||
"@types/luxon": "^3.4.2", | ||
"@types/mustache": "^4.2.5", | ||
"@types/node": "^20.11.5", | ||
"@typescript-eslint/eslint-plugin": "^6.19.0", | ||
"@typescript-eslint/parser": "^6.19.0", | ||
"@types/node": "^20.11.16", | ||
"@typescript-eslint/eslint-plugin": "^6.20.0", | ||
"@typescript-eslint/parser": "^6.20.0", | ||
"eslint": "^8.56.0", | ||
@@ -50,3 +50,3 @@ "eslint-config-standard": "^17.1.0", | ||
"rimraf": "^5.0.5", | ||
"ts-jest": "^29.1.1", | ||
"ts-jest": "^29.1.2", | ||
"ts-node": "^10.9.2", | ||
@@ -56,7 +56,7 @@ "typescript": "^5.3.3", | ||
"jest-snapshot": "~29.7.0", | ||
"@rushstack/heft": "~0.64.0", | ||
"@rushstack/heft-node-rig": "~2.4.0", | ||
"@rushstack/eslint-config": "~3.6.0", | ||
"@rushstack/heft": "~0.64.3", | ||
"@rushstack/heft-node-rig": "~2.4.5", | ||
"@rushstack/eslint-config": "~3.6.2", | ||
"@types/heft-jest": "1.0.6", | ||
"@rushstack/heft-jest-plugin": "~0.11.0", | ||
"@rushstack/heft-jest-plugin": "~0.11.3", | ||
"eslint-plugin-tsdoc": "~0.2.17" | ||
@@ -63,0 +63,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
759086
139
9211