@fgv/ts-utils 3.0.1-alpha.4 → 3.0.1-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ts-utils.d.ts +1221 -1116
- package/lib/packlets/base/index.d.ts +1 -0
- package/lib/packlets/base/index.d.ts.map +1 -1
- package/lib/packlets/base/index.js +1 -0
- package/lib/packlets/base/index.js.map +1 -1
- package/lib/packlets/base/mapResults.d.ts +8 -8
- package/lib/packlets/base/mapResults.d.ts.map +1 -1
- package/lib/packlets/base/mapResults.js +6 -6
- package/lib/packlets/base/mapResults.js.map +1 -1
- package/lib/packlets/base/messageAggregator.d.ts +56 -0
- package/lib/packlets/base/messageAggregator.d.ts.map +1 -0
- package/lib/packlets/base/messageAggregator.js +108 -0
- package/lib/packlets/base/messageAggregator.js.map +1 -0
- package/lib/packlets/base/result.d.ts +49 -0
- package/lib/packlets/base/result.d.ts.map +1 -1
- package/lib/packlets/base/result.js +13 -0
- package/lib/packlets/base/result.js.map +1 -1
- package/package.json +1 -1
package/dist/ts-utils.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* messages from all failed elements.
|
|
10
10
|
* @public
|
|
11
11
|
*/
|
|
12
|
-
export declare function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T, aggregatedErrors?:
|
|
12
|
+
export declare function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T, aggregatedErrors?: IMessageAggregator): Result<T>;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* A helper function to create a {@link Converter | Converter} which converts `unknown` to an array of `<T>`.
|
|
@@ -826,6 +826,10 @@ export declare class Failure<T> implements IResult<T> {
|
|
|
826
826
|
* {@inheritdoc IResult.withDetail}
|
|
827
827
|
*/
|
|
828
828
|
withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD>;
|
|
829
|
+
/**
|
|
830
|
+
* {@inheritdoc IResult.aggregateError}
|
|
831
|
+
*/
|
|
832
|
+
aggregateError(errors: IMessageAggregator): this;
|
|
829
833
|
/**
|
|
830
834
|
* Get a 'friendly' string representation of this object.
|
|
831
835
|
* @remarks
|
|
@@ -1146,6 +1150,41 @@ declare class HashingNormalizer extends Normalizer {
|
|
|
1146
1150
|
protected _normalizeLiteralToString(from: string | number | bigint | boolean | symbol | undefined | Date | RegExp | null): Result<string>;
|
|
1147
1151
|
}
|
|
1148
1152
|
|
|
1153
|
+
/**
|
|
1154
|
+
* Simple error aggregator to simplify collecting all errors in
|
|
1155
|
+
* a flow.
|
|
1156
|
+
* @public
|
|
1157
|
+
*/
|
|
1158
|
+
export declare interface IMessageAggregator {
|
|
1159
|
+
/**
|
|
1160
|
+
* Indicates whether any messages have been aggregated.
|
|
1161
|
+
*/
|
|
1162
|
+
readonly hasMessages: boolean;
|
|
1163
|
+
/**
|
|
1164
|
+
* The aggregated messages.
|
|
1165
|
+
*/
|
|
1166
|
+
readonly messages: ReadonlyArray<string>;
|
|
1167
|
+
/**
|
|
1168
|
+
* Adds a message to the aggregator, if defined.
|
|
1169
|
+
* @param message - The message to add - pass `undefined`
|
|
1170
|
+
* or the empty string to continue without adding a message.
|
|
1171
|
+
*/
|
|
1172
|
+
addMessage(message: string | undefined): this;
|
|
1173
|
+
/**
|
|
1174
|
+
* Adds multiple messages to the aggregator.
|
|
1175
|
+
* @param messages - the messages to add.
|
|
1176
|
+
*/
|
|
1177
|
+
addMessages(messages: string[] | undefined): this;
|
|
1178
|
+
/**
|
|
1179
|
+
* Returns all messages as a single string joined
|
|
1180
|
+
* using the optionally-supplied `separator`, or
|
|
1181
|
+
* newline if no separator is specified.
|
|
1182
|
+
* @param separator - The optional separator used
|
|
1183
|
+
* to join strings.
|
|
1184
|
+
*/
|
|
1185
|
+
toString(separator?: string): string;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1149
1188
|
/**
|
|
1150
1189
|
* Infers the type that will be returned by an instantiated converter. Works
|
|
1151
1190
|
* for complex as well as simple types.
|
|
@@ -1294,6 +1333,13 @@ export declare interface IResult<T> {
|
|
|
1294
1333
|
* appropriate added detail.
|
|
1295
1334
|
*/
|
|
1296
1335
|
withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;
|
|
1336
|
+
/**
|
|
1337
|
+
* Propagates interior result, appending any error message to the
|
|
1338
|
+
* supplied errors array.
|
|
1339
|
+
* @param errors - {@link IMessageAggregator | Error aggregator} in which
|
|
1340
|
+
* errors will be aggregated.
|
|
1341
|
+
*/
|
|
1342
|
+
aggregateError(errors: IMessageAggregator): this;
|
|
1297
1343
|
}
|
|
1298
1344
|
|
|
1299
1345
|
/**
|
|
@@ -1447,7 +1493,7 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
1447
1493
|
* error messages.
|
|
1448
1494
|
* @public
|
|
1449
1495
|
*/
|
|
1450
|
-
export declare function mapDetailedResults<T, TD>(results: Iterable<DetailedResult<T, TD>>, ignore: TD[], aggregatedErrors?:
|
|
1496
|
+
export declare function mapDetailedResults<T, TD>(results: Iterable<DetailedResult<T, TD>>, ignore: TD[], aggregatedErrors?: IMessageAggregator): Result<T[]>;
|
|
1451
1497
|
|
|
1452
1498
|
/**
|
|
1453
1499
|
* Aggregates error messages from a collection of {@link Result | Result<T>}.
|
|
@@ -1460,7 +1506,7 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
1460
1506
|
* results and returns an empty array if there were no errors.
|
|
1461
1507
|
* @public
|
|
1462
1508
|
*/
|
|
1463
|
-
export declare function mapFailures<T>(results: Iterable<Result<T>>, aggregatedErrors?:
|
|
1509
|
+
export declare function mapFailures<T>(results: Iterable<Result<T>>, aggregatedErrors?: IMessageAggregator): string[];
|
|
1464
1510
|
|
|
1465
1511
|
/**
|
|
1466
1512
|
* A helper function to create a {@link Converter | Converter} which converts the `string`-keyed properties
|
|
@@ -1533,7 +1579,7 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
1533
1579
|
* {@link Failure} with a concatenated summary of all error messages.
|
|
1534
1580
|
* @public
|
|
1535
1581
|
*/
|
|
1536
|
-
export declare function mapResults<T>(results: Iterable<Result<T>>, aggregatedErrors?:
|
|
1582
|
+
export declare function mapResults<T>(results: Iterable<Result<T>>, aggregatedErrors?: IMessageAggregator): Result<T[]>;
|
|
1537
1583
|
|
|
1538
1584
|
/**
|
|
1539
1585
|
* Aggregates successful results from a a collection of {@link Result | Result<T>}.
|
|
@@ -1546,7 +1592,7 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
1546
1592
|
* summary of all error messages.
|
|
1547
1593
|
* @public
|
|
1548
1594
|
*/
|
|
1549
|
-
export declare function mapSuccess<T>(results: Iterable<Result<T>>, aggregatedErrors?:
|
|
1595
|
+
export declare function mapSuccess<T>(results: Iterable<Result<T>>, aggregatedErrors?: IMessageAggregator): Result<T[]>;
|
|
1550
1596
|
|
|
1551
1597
|
/**
|
|
1552
1598
|
* Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.
|
|
@@ -1559,1297 +1605,1356 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
1559
1605
|
export declare function mapToRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS>, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD>>;
|
|
1560
1606
|
|
|
1561
1607
|
/**
|
|
1608
|
+
* A simple error aggregator to simplify collecting and reporting all errors in
|
|
1609
|
+
* a flow.
|
|
1562
1610
|
* @public
|
|
1563
1611
|
*/
|
|
1564
|
-
declare class
|
|
1565
|
-
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
/**
|
|
1569
|
-
* Normalizes an arbitrary JSON object
|
|
1570
|
-
* @public
|
|
1571
|
-
*/
|
|
1572
|
-
export declare class Normalizer {
|
|
1573
|
-
/**
|
|
1574
|
-
* Normalizes the supplied value
|
|
1575
|
-
*
|
|
1576
|
-
* @param from - The value to be normalized
|
|
1577
|
-
* @returns A normalized version of the value
|
|
1578
|
-
*/
|
|
1579
|
-
normalize<T>(from: T): Result<T>;
|
|
1580
|
-
/**
|
|
1581
|
-
* Compares two property names from some object being normalized.
|
|
1582
|
-
* @param k1 - First key to be compared.
|
|
1583
|
-
* @param k2 - Second key to be compared.
|
|
1584
|
-
* @returns `1` if `k1` is greater, `-1` if `k2` is greater and
|
|
1585
|
-
* `0` if they are equal.
|
|
1586
|
-
* @internal
|
|
1587
|
-
*/
|
|
1588
|
-
protected _compareKeys(k1: unknown, k2: unknown): number;
|
|
1589
|
-
/**
|
|
1590
|
-
* Normalizes an array of object property entries (e.g. as returned by `Object.entries()`).
|
|
1591
|
-
* @remarks
|
|
1592
|
-
* Converts property names (entry key) to string and then sorts as string.
|
|
1593
|
-
* @param entries - The entries to be normalized.
|
|
1594
|
-
* @returns A normalized sorted array of entries.
|
|
1595
|
-
*/
|
|
1596
|
-
normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[];
|
|
1597
|
-
protected _normalizeArray(from: unknown[]): Result<unknown[]>;
|
|
1598
|
-
/**
|
|
1599
|
-
* Normalizes the supplied literal value
|
|
1600
|
-
* @param from - The literal value to be normalized.
|
|
1601
|
-
* @returns A normalized value for the literal.
|
|
1602
|
-
*/
|
|
1603
|
-
normalizeLiteral<T>(from: T): Result<T>;
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
/**
|
|
1607
|
-
* A {@link Converter | Converter} which converts `unknown` to a `number`.
|
|
1608
|
-
* @remarks
|
|
1609
|
-
* Numbers and strings with a numeric format succeed. Anything else fails.
|
|
1610
|
-
* @public
|
|
1611
|
-
*/
|
|
1612
|
-
declare const number: Converter<number, undefined>;
|
|
1613
|
-
|
|
1614
|
-
/**
|
|
1615
|
-
* A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.
|
|
1616
|
-
* @public
|
|
1617
|
-
*/
|
|
1618
|
-
declare const number_2: Validator<number>;
|
|
1619
|
-
|
|
1620
|
-
/**
|
|
1621
|
-
* {@link Converter | Converter} to convert an `unknown` to an array of `number`.
|
|
1622
|
-
* @remarks
|
|
1623
|
-
* Returns {@link Success | Success} with the the supplied value if it as an array
|
|
1624
|
-
* of numbers, returns {@link Failure | Failure} with an error message otherwise.
|
|
1625
|
-
* @public
|
|
1626
|
-
*/
|
|
1627
|
-
declare const numberArray: Converter<number[]>;
|
|
1628
|
-
|
|
1629
|
-
/**
|
|
1630
|
-
* An in-place {@link Validation.Validator | Validator} for `number` values.
|
|
1631
|
-
* @public
|
|
1632
|
-
*/
|
|
1633
|
-
declare class NumberValidator<T extends number = number, TC = unknown> extends GenericValidator<T, TC> {
|
|
1634
|
-
/**
|
|
1635
|
-
* Constructs a new {@link Validation.Classes.NumberValidator | NumberValidator}.
|
|
1636
|
-
* @param params - Optional {@link Validation.Classes.NumberValidatorConstructorParams | init params} for the
|
|
1637
|
-
* new {@link Validation.Classes.NumberValidator | NumberValidator}.
|
|
1638
|
-
*/
|
|
1639
|
-
constructor(params?: NumberValidatorConstructorParams<T, TC>);
|
|
1640
|
-
/**
|
|
1641
|
-
* Static method which validates that a supplied `unknown` value is a `number`.
|
|
1642
|
-
* @param from - The `unknown` value to be tested.
|
|
1643
|
-
* @returns Returns `true` if `from` is a `number`, or {@link Failure} with an error
|
|
1644
|
-
* message if not.
|
|
1645
|
-
*/
|
|
1646
|
-
static validateNumber<T extends number>(from: unknown): boolean | Failure<T>;
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
/**
|
|
1650
|
-
* Parameters used to construct a {@link Validation.Classes.NumberValidator | NumberValidator}.
|
|
1651
|
-
* @public
|
|
1652
|
-
*/
|
|
1653
|
-
declare type NumberValidatorConstructorParams<T extends number = number, TC = unknown> = GenericValidatorConstructorParams<T, TC>;
|
|
1654
|
-
|
|
1655
|
-
/**
|
|
1656
|
-
* Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter<T>} which converts an object
|
|
1657
|
-
* without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
|
|
1658
|
-
* {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} to further refine conversion behavior.
|
|
1659
|
-
* @remarks
|
|
1660
|
-
* By default, if all of the requested fields exist and can be converted, returns {@link Success | Success}
|
|
1661
|
-
* with a new object that contains the converted values under the original key names. If any required properties
|
|
1662
|
-
* do not exist or cannot be converted, the entire conversion fails, returning {@link Failure | Failure} with additional
|
|
1663
|
-
* error information.
|
|
1664
|
-
*
|
|
1665
|
-
* Fields that succeed but convert to undefined are omitted from the result object but do not
|
|
1666
|
-
* fail the conversion.
|
|
1667
|
-
* @param properties - An {@link Conversion.FieldConverters | FieldConverters<T>} defining the shape of the
|
|
1668
|
-
* source object and {@link Converter | converters} to be applied to each properties.
|
|
1669
|
-
* @param options - An {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} containing options
|
|
1670
|
-
* for the object converter.
|
|
1671
|
-
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
|
|
1672
|
-
* {@label WITH_OPTIONS}
|
|
1673
|
-
* @public
|
|
1674
|
-
*/
|
|
1675
|
-
declare function object<T>(properties: FieldConverters<T>, options?: ObjectConverterOptions<T>): ObjectConverter<T>;
|
|
1676
|
-
|
|
1677
|
-
/**
|
|
1678
|
-
* Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter<T>} which converts an object
|
|
1679
|
-
* without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T>} and a set of
|
|
1680
|
-
* optional properties.
|
|
1681
|
-
* @remarks
|
|
1682
|
-
* By default, if all of the requested fields exist and can be converted, returns {@link Success | Success}
|
|
1683
|
-
* with a new object that contains the converted values under the original key names. If any required properties
|
|
1684
|
-
* do not exist or cannot be converted, the entire conversion fails, returning {@link Failure | Failure} with additional
|
|
1685
|
-
* error information.
|
|
1686
|
-
*
|
|
1687
|
-
* Fields that succeed but convert to undefined are omitted from the result object but do not
|
|
1688
|
-
* fail the conversion.
|
|
1689
|
-
* @param properties - An {@link Conversion.FieldConverters | FieldConverters<T>} defining the shape of the
|
|
1690
|
-
* source object and {@link Converter | converters} to be applied to each properties.
|
|
1691
|
-
* @param optional - An array of `(keyof T)` listing the keys to be considered optional.
|
|
1692
|
-
* {@label WITH_KEYS}
|
|
1693
|
-
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
|
|
1694
|
-
* @public
|
|
1695
|
-
* @deprecated Use {@link Converters.(object:1) | Converters.object(fields, options)} instead.
|
|
1696
|
-
*/
|
|
1697
|
-
declare function object<T>(properties: FieldConverters<T>, optional: (keyof T)[]): ObjectConverter<T>;
|
|
1698
|
-
|
|
1699
|
-
/**
|
|
1700
|
-
* Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates
|
|
1701
|
-
* an object in place.
|
|
1702
|
-
* @param fields - A {@link Validation.Classes.FieldValidators | field validator definition}
|
|
1703
|
-
* describing the validations to be applied.
|
|
1704
|
-
* @param params - Optional {@link Validation.Classes.ObjectValidatorConstructorParams | parameters}
|
|
1705
|
-
* to refine the behavior of the resulting {@link Validation.Validator | validator}.
|
|
1706
|
-
* @returns A new {@link Validation.Validator | Validator} which validates the desired
|
|
1707
|
-
* object in place.
|
|
1708
|
-
* @public
|
|
1709
|
-
*/
|
|
1710
|
-
declare function object_2<T, TC = unknown>(fields: FieldValidators<T, TC>, params?: Omit<ObjectValidatorConstructorParams<T, TC>, 'fields'>): ObjectValidator<T, TC>;
|
|
1711
|
-
|
|
1712
|
-
/**
|
|
1713
|
-
* A {@link Converter} which converts an object of type `<T>` without changing shape, given
|
|
1714
|
-
* a {@link Conversion.FieldConverters | FieldConverters<T>} for the fields in the object.
|
|
1715
|
-
* @remarks
|
|
1716
|
-
* By default, if all of the required fields exist and can be converted, returns a new object with
|
|
1717
|
-
* the converted values under the original key names. If any required fields do not exist or cannot
|
|
1718
|
-
* be converted, the entire conversion fails. See {@link Conversion.ObjectConverterOptions | ObjectConverterOptions}
|
|
1719
|
-
* for other conversion options.
|
|
1720
|
-
* @public
|
|
1721
|
-
*/
|
|
1722
|
-
export declare class ObjectConverter<T, TC = unknown> extends BaseConverter<T, TC> {
|
|
1612
|
+
export declare class MessageAggregator implements IMessageAggregator {
|
|
1613
|
+
private readonly _messages;
|
|
1723
1614
|
/**
|
|
1724
|
-
*
|
|
1615
|
+
* Constructs a new {@link MessageAggregator | ErrorAggregator} with an
|
|
1616
|
+
* optionally specified initial set of error messages.
|
|
1617
|
+
* @param errors - optional array of errors to be included
|
|
1618
|
+
* in the aggregation.
|
|
1725
1619
|
*/
|
|
1726
|
-
|
|
1620
|
+
constructor(errors?: string[]);
|
|
1727
1621
|
/**
|
|
1728
|
-
*
|
|
1622
|
+
* {@inheritdoc IMessageAggregator.hasMessages}
|
|
1729
1623
|
*/
|
|
1730
|
-
|
|
1624
|
+
get hasMessages(): boolean;
|
|
1731
1625
|
/**
|
|
1732
|
-
*
|
|
1733
|
-
* supplied in a {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>}.
|
|
1734
|
-
* @param fields - A {@link Conversion.FieldConverters | FieldConverters<T>} containing
|
|
1735
|
-
* a {@link Converter} for each field
|
|
1736
|
-
* @param options - An optional @see ObjectConverterOptions to configure the conversion
|
|
1737
|
-
* {@label WITH_OPTIONS}
|
|
1626
|
+
* {@inheritdoc IMessageAggregator.messages}
|
|
1738
1627
|
*/
|
|
1739
|
-
|
|
1628
|
+
get messages(): string[];
|
|
1740
1629
|
/**
|
|
1741
|
-
*
|
|
1742
|
-
* properties specified as an array of `keyof T`.
|
|
1743
|
-
* @param fields - A {@link Conversion.FieldConverters | FieldConverters<T>} containing
|
|
1744
|
-
* a {@link Converter} for each field.
|
|
1745
|
-
* @param optional - An array of `keyof T` listing fields that are not required.
|
|
1746
|
-
* {@label WITH_KEYS}
|
|
1630
|
+
* {@inheritdoc IMessageAggregator.addMessage}
|
|
1747
1631
|
*/
|
|
1748
|
-
|
|
1632
|
+
addMessage(message: string | undefined): this;
|
|
1749
1633
|
/**
|
|
1750
|
-
*
|
|
1751
|
-
* new optional properties as specified by a supplied {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>}.
|
|
1752
|
-
* @param options - The {@link Conversion.ObjectConverterOptions | options} to be applied to the new
|
|
1753
|
-
* converter.
|
|
1754
|
-
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source properties.
|
|
1755
|
-
* {@label WITH_OPTIONS}
|
|
1634
|
+
* {@inheritdoc IMessageAggregator.addMessages}
|
|
1756
1635
|
*/
|
|
1757
|
-
|
|
1636
|
+
addMessages(messages: string[] | undefined): this;
|
|
1758
1637
|
/**
|
|
1759
|
-
*
|
|
1760
|
-
* new optional properties as specified by a supplied array of `keyof T`.
|
|
1761
|
-
* @param optional - The keys of the source object properties to be made optional.
|
|
1762
|
-
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source
|
|
1763
|
-
* properties.
|
|
1764
|
-
* {@label WITH_KEYS}
|
|
1638
|
+
* {@inheritdoc IMessageAggregator.toString}
|
|
1765
1639
|
*/
|
|
1766
|
-
|
|
1640
|
+
toString(separator?: string): string;
|
|
1767
1641
|
/**
|
|
1768
|
-
*
|
|
1769
|
-
*
|
|
1770
|
-
*
|
|
1771
|
-
*
|
|
1772
|
-
*
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1642
|
+
* If any error messages have been aggregated, returns
|
|
1643
|
+
* {@link Failure | Failure<T>} with the aggregated
|
|
1644
|
+
* messages concatenated using the optionally-supplied
|
|
1645
|
+
* separator, or newline. If the supplied {@link Result | Result<T>}
|
|
1646
|
+
* contains an error message that has not already been aggregated,
|
|
1647
|
+
* it will be included in the aggregated messages.
|
|
1648
|
+
*
|
|
1649
|
+
* If no error messages have been aggregated, returns
|
|
1650
|
+
* the supplied {@link Result | Result<T>}.
|
|
1651
|
+
* @param result - The {@link Result | Result<T>} to be returned
|
|
1652
|
+
* if no messages have been aggregated.
|
|
1653
|
+
* @param separator - Optional string separator used to construct
|
|
1654
|
+
* the error message.
|
|
1655
|
+
* @returns {@link Failure | Failure<T>} with an aggregated message
|
|
1656
|
+
* if any error messages were collected, the supplied
|
|
1657
|
+
* {@link Result | Result<T>} otherwise.
|
|
1658
|
+
*/
|
|
1659
|
+
returnOrReport<T>(result: Result<T>, separator?: string): Result<T>;
|
|
1660
|
+
}
|
|
1776
1661
|
|
|
1777
|
-
/**
|
|
1778
|
-
* Options for an {@link Conversion.ObjectConverter | ObjectConverter}.
|
|
1779
|
-
* @public
|
|
1780
|
-
*/
|
|
1781
|
-
declare interface ObjectConverterOptions<T> {
|
|
1782
|
-
/**
|
|
1783
|
-
* If present, lists optional fields. Missing non-optional fields cause an error.
|
|
1784
|
-
*/
|
|
1785
|
-
optionalFields?: (keyof T)[];
|
|
1786
|
-
/**
|
|
1787
|
-
* If true, unrecognized fields yield an error. If false or undefined (default),
|
|
1788
|
-
* unrecognized fields are ignored.
|
|
1789
|
-
*/
|
|
1790
|
-
strict?: boolean;
|
|
1791
1662
|
/**
|
|
1792
|
-
*
|
|
1663
|
+
* @public
|
|
1793
1664
|
*/
|
|
1794
|
-
|
|
1795
|
-
|
|
1665
|
+
declare class NoOpLogger extends LoggerBase {
|
|
1666
|
+
protected _innerLog(message: string): Success<string | undefined>;
|
|
1667
|
+
}
|
|
1796
1668
|
|
|
1797
|
-
/**
|
|
1798
|
-
* In-place {@link Validation.Validator | Validator} for an object of type `<T>`.
|
|
1799
|
-
* @remarks
|
|
1800
|
-
* By default, succeeds if all of the required fields exist and are validate, and fails if
|
|
1801
|
-
* any required fields do not exist or are invalid. See {@link Validation.Classes.ObjectValidatorOptions}
|
|
1802
|
-
* for other validation options.
|
|
1803
|
-
* @public
|
|
1804
|
-
*/
|
|
1805
|
-
declare class ObjectValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
|
|
1806
|
-
/**
|
|
1807
|
-
* A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a
|
|
1808
|
-
* {@link Validation.Validator | Validator} for each of the expected properties
|
|
1809
|
-
*/
|
|
1810
|
-
readonly fields: FieldValidators<T>;
|
|
1811
1669
|
/**
|
|
1812
|
-
*
|
|
1813
|
-
*
|
|
1814
|
-
*/
|
|
1815
|
-
readonly options: ObjectValidatorOptions<T, TC>;
|
|
1816
|
-
/**
|
|
1817
|
-
* @internal
|
|
1818
|
-
*/
|
|
1819
|
-
protected readonly _innerValidators: FieldValidators<T>;
|
|
1820
|
-
/**
|
|
1821
|
-
* @internal
|
|
1822
|
-
*/
|
|
1823
|
-
protected readonly _allowedFields?: Set<keyof T>;
|
|
1824
|
-
/**
|
|
1825
|
-
* Constructs a new {@link Validation.Classes.ObjectValidator | ObjectValidator<T>}.
|
|
1826
|
-
* @param fields - A {@link Validation.Classes.FieldValidators | FieldValidators<T>} containing
|
|
1827
|
-
* a {@link Validation.Validator | Validator} for each field.
|
|
1828
|
-
* @param options - An optional {@link Validation.Classes.ObjectValidatorOptions} to configure
|
|
1829
|
-
* validation.
|
|
1670
|
+
* Normalizes an arbitrary JSON object
|
|
1671
|
+
* @public
|
|
1830
1672
|
*/
|
|
1831
|
-
|
|
1673
|
+
export declare class Normalizer {
|
|
1674
|
+
/**
|
|
1675
|
+
* Normalizes the supplied value
|
|
1676
|
+
*
|
|
1677
|
+
* @param from - The value to be normalized
|
|
1678
|
+
* @returns A normalized version of the value
|
|
1679
|
+
*/
|
|
1680
|
+
normalize<T>(from: T): Result<T>;
|
|
1681
|
+
/**
|
|
1682
|
+
* Compares two property names from some object being normalized.
|
|
1683
|
+
* @param k1 - First key to be compared.
|
|
1684
|
+
* @param k2 - Second key to be compared.
|
|
1685
|
+
* @returns `1` if `k1` is greater, `-1` if `k2` is greater and
|
|
1686
|
+
* `0` if they are equal.
|
|
1687
|
+
* @internal
|
|
1688
|
+
*/
|
|
1689
|
+
protected _compareKeys(k1: unknown, k2: unknown): number;
|
|
1690
|
+
/**
|
|
1691
|
+
* Normalizes an array of object property entries (e.g. as returned by `Object.entries()`).
|
|
1692
|
+
* @remarks
|
|
1693
|
+
* Converts property names (entry key) to string and then sorts as string.
|
|
1694
|
+
* @param entries - The entries to be normalized.
|
|
1695
|
+
* @returns A normalized sorted array of entries.
|
|
1696
|
+
*/
|
|
1697
|
+
normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[];
|
|
1698
|
+
protected _normalizeArray(from: unknown[]): Result<unknown[]>;
|
|
1699
|
+
/**
|
|
1700
|
+
* Normalizes the supplied literal value
|
|
1701
|
+
* @param from - The literal value to be normalized.
|
|
1702
|
+
* @returns A normalized value for the literal.
|
|
1703
|
+
*/
|
|
1704
|
+
normalizeLiteral<T>(from: T): Result<T>;
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1832
1707
|
/**
|
|
1833
|
-
*
|
|
1834
|
-
*
|
|
1835
|
-
*
|
|
1836
|
-
* @
|
|
1837
|
-
* in to the constructor.
|
|
1838
|
-
* @param options - The {@link Validation.Classes.ObjectValidatorOptions | object validator options}
|
|
1839
|
-
* passed in to the constructor.
|
|
1840
|
-
* @returns A new {@link Validation.Classes.FieldValidators | FieldValidators} with the fully-configured
|
|
1841
|
-
* individual {@link Validation.Validator | field validators} to be applied.
|
|
1842
|
-
* @internal
|
|
1708
|
+
* A {@link Converter | Converter} which converts `unknown` to a `number`.
|
|
1709
|
+
* @remarks
|
|
1710
|
+
* Numbers and strings with a numeric format succeed. Anything else fails.
|
|
1711
|
+
* @public
|
|
1843
1712
|
*/
|
|
1844
|
-
|
|
1713
|
+
declare const number: Converter<number, undefined>;
|
|
1714
|
+
|
|
1845
1715
|
/**
|
|
1846
|
-
*
|
|
1847
|
-
*
|
|
1848
|
-
* {@link Validation.Classes.ObjectValidatorOptions | ObjectValidatorOptions<T>}.
|
|
1849
|
-
* @param options - The {@link Validation.Classes.ObjectValidatorOptions | options} to be applied to the new
|
|
1850
|
-
* {@link Validation.Classes.ObjectValidator | validator}.
|
|
1851
|
-
* @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional
|
|
1852
|
-
* source properties.
|
|
1716
|
+
* A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.
|
|
1717
|
+
* @public
|
|
1853
1718
|
*/
|
|
1854
|
-
|
|
1719
|
+
declare const number_2: Validator<number>;
|
|
1720
|
+
|
|
1855
1721
|
/**
|
|
1856
|
-
*
|
|
1857
|
-
*
|
|
1858
|
-
* @
|
|
1859
|
-
*
|
|
1860
|
-
*
|
|
1722
|
+
* {@link Converter | Converter} to convert an `unknown` to an array of `number`.
|
|
1723
|
+
* @remarks
|
|
1724
|
+
* Returns {@link Success | Success} with the the supplied value if it as an array
|
|
1725
|
+
* of numbers, returns {@link Failure | Failure} with an error message otherwise.
|
|
1726
|
+
* @public
|
|
1861
1727
|
*/
|
|
1862
|
-
|
|
1728
|
+
declare const numberArray: Converter<number[]>;
|
|
1729
|
+
|
|
1863
1730
|
/**
|
|
1864
|
-
* {@
|
|
1865
|
-
* @
|
|
1731
|
+
* An in-place {@link Validation.Validator | Validator} for `number` values.
|
|
1732
|
+
* @public
|
|
1866
1733
|
*/
|
|
1867
|
-
|
|
1868
|
-
|
|
1734
|
+
declare class NumberValidator<T extends number = number, TC = unknown> extends GenericValidator<T, TC> {
|
|
1735
|
+
/**
|
|
1736
|
+
* Constructs a new {@link Validation.Classes.NumberValidator | NumberValidator}.
|
|
1737
|
+
* @param params - Optional {@link Validation.Classes.NumberValidatorConstructorParams | init params} for the
|
|
1738
|
+
* new {@link Validation.Classes.NumberValidator | NumberValidator}.
|
|
1739
|
+
*/
|
|
1740
|
+
constructor(params?: NumberValidatorConstructorParams<T, TC>);
|
|
1741
|
+
/**
|
|
1742
|
+
* Static method which validates that a supplied `unknown` value is a `number`.
|
|
1743
|
+
* @param from - The `unknown` value to be tested.
|
|
1744
|
+
* @returns Returns `true` if `from` is a `number`, or {@link Failure} with an error
|
|
1745
|
+
* message if not.
|
|
1746
|
+
*/
|
|
1747
|
+
static validateNumber<T extends number>(from: unknown): boolean | Failure<T>;
|
|
1748
|
+
}
|
|
1869
1749
|
|
|
1870
|
-
/**
|
|
1871
|
-
* Options for the {@link Validation.Classes.ObjectValidator | ObjectValidator} constructor.
|
|
1872
|
-
* @public
|
|
1873
|
-
*/
|
|
1874
|
-
declare interface ObjectValidatorConstructorParams<T, TC> extends ValidatorBaseConstructorParams<T, TC> {
|
|
1875
1750
|
/**
|
|
1876
|
-
*
|
|
1877
|
-
*
|
|
1878
|
-
* of a result object.
|
|
1751
|
+
* Parameters used to construct a {@link Validation.Classes.NumberValidator | NumberValidator}.
|
|
1752
|
+
* @public
|
|
1879
1753
|
*/
|
|
1880
|
-
|
|
1754
|
+
declare type NumberValidatorConstructorParams<T extends number = number, TC = unknown> = GenericValidatorConstructorParams<T, TC>;
|
|
1755
|
+
|
|
1881
1756
|
/**
|
|
1882
|
-
*
|
|
1883
|
-
*
|
|
1757
|
+
* Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter<T>} which converts an object
|
|
1758
|
+
* without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
|
|
1759
|
+
* {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} to further refine conversion behavior.
|
|
1760
|
+
* @remarks
|
|
1761
|
+
* By default, if all of the requested fields exist and can be converted, returns {@link Success | Success}
|
|
1762
|
+
* with a new object that contains the converted values under the original key names. If any required properties
|
|
1763
|
+
* do not exist or cannot be converted, the entire conversion fails, returning {@link Failure | Failure} with additional
|
|
1764
|
+
* error information.
|
|
1765
|
+
*
|
|
1766
|
+
* Fields that succeed but convert to undefined are omitted from the result object but do not
|
|
1767
|
+
* fail the conversion.
|
|
1768
|
+
* @param properties - An {@link Conversion.FieldConverters | FieldConverters<T>} defining the shape of the
|
|
1769
|
+
* source object and {@link Converter | converters} to be applied to each properties.
|
|
1770
|
+
* @param options - An {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} containing options
|
|
1771
|
+
* for the object converter.
|
|
1772
|
+
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
|
|
1773
|
+
* {@label WITH_OPTIONS}
|
|
1774
|
+
* @public
|
|
1884
1775
|
*/
|
|
1885
|
-
options?:
|
|
1886
|
-
}
|
|
1776
|
+
declare function object<T>(properties: FieldConverters<T>, options?: ObjectConverterOptions<T>): ObjectConverter<T>;
|
|
1887
1777
|
|
|
1888
|
-
/**
|
|
1889
|
-
* Options for an {@link Validation.Classes.ObjectValidator | ObjectValidator}.
|
|
1890
|
-
* @public
|
|
1891
|
-
*/
|
|
1892
|
-
declare interface ObjectValidatorOptions<T, TC> extends ValidatorOptions<TC> {
|
|
1893
1778
|
/**
|
|
1894
|
-
*
|
|
1779
|
+
* Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter<T>} which converts an object
|
|
1780
|
+
* without changing shape, given a {@link Conversion.FieldConverters | FieldConverters<T>} and a set of
|
|
1781
|
+
* optional properties.
|
|
1782
|
+
* @remarks
|
|
1783
|
+
* By default, if all of the requested fields exist and can be converted, returns {@link Success | Success}
|
|
1784
|
+
* with a new object that contains the converted values under the original key names. If any required properties
|
|
1785
|
+
* do not exist or cannot be converted, the entire conversion fails, returning {@link Failure | Failure} with additional
|
|
1786
|
+
* error information.
|
|
1787
|
+
*
|
|
1788
|
+
* Fields that succeed but convert to undefined are omitted from the result object but do not
|
|
1789
|
+
* fail the conversion.
|
|
1790
|
+
* @param properties - An {@link Conversion.FieldConverters | FieldConverters<T>} defining the shape of the
|
|
1791
|
+
* source object and {@link Converter | converters} to be applied to each properties.
|
|
1792
|
+
* @param optional - An array of `(keyof T)` listing the keys to be considered optional.
|
|
1793
|
+
* {@label WITH_KEYS}
|
|
1794
|
+
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
|
|
1795
|
+
* @public
|
|
1796
|
+
* @deprecated Use {@link Converters.(object:1) | Converters.object(fields, options)} instead.
|
|
1895
1797
|
*/
|
|
1896
|
-
|
|
1798
|
+
declare function object<T>(properties: FieldConverters<T>, optional: (keyof T)[]): ObjectConverter<T>;
|
|
1799
|
+
|
|
1897
1800
|
/**
|
|
1898
|
-
*
|
|
1899
|
-
*
|
|
1801
|
+
* Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates
|
|
1802
|
+
* an object in place.
|
|
1803
|
+
* @param fields - A {@link Validation.Classes.FieldValidators | field validator definition}
|
|
1804
|
+
* describing the validations to be applied.
|
|
1805
|
+
* @param params - Optional {@link Validation.Classes.ObjectValidatorConstructorParams | parameters}
|
|
1806
|
+
* to refine the behavior of the resulting {@link Validation.Validator | validator}.
|
|
1807
|
+
* @returns A new {@link Validation.Validator | Validator} which validates the desired
|
|
1808
|
+
* object in place.
|
|
1809
|
+
* @public
|
|
1900
1810
|
*/
|
|
1901
|
-
|
|
1902
|
-
}
|
|
1903
|
-
|
|
1904
|
-
/**
|
|
1905
|
-
* Simple implicit omit function, which picks all of the properties from a supplied
|
|
1906
|
-
* object except those specified for exclusion.
|
|
1907
|
-
* @param from - The object from which keys are to be picked.
|
|
1908
|
-
* @param exclude - The keys of the properties to be excluded from the returned object.
|
|
1909
|
-
* @returns A new object containing all of the properties from `from` that were not
|
|
1910
|
-
* explicitly excluded.
|
|
1911
|
-
* @public
|
|
1912
|
-
*/
|
|
1913
|
-
export declare function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K>;
|
|
1914
|
-
|
|
1915
|
-
/**
|
|
1916
|
-
* A helper function to create a {@link Converter | Converter} for polymorphic values.
|
|
1917
|
-
* Returns a converter which invokes the wrapped converters in sequence, returning the
|
|
1918
|
-
* first successful result. Returns an error if none of the supplied converters can
|
|
1919
|
-
* convert the value.
|
|
1920
|
-
* @remarks
|
|
1921
|
-
* If `onError` is `ignoreErrors` (default), then errors from any of the
|
|
1922
|
-
* converters are ignored provided that some converter succeeds. If
|
|
1923
|
-
* onError is `failOnError`, then an error from any converter fails the entire
|
|
1924
|
-
* conversion.
|
|
1925
|
-
*
|
|
1926
|
-
* @param converters - An ordered list of {@link Converter | converters} or {@link Validator | validators}
|
|
1927
|
-
* to be considered.
|
|
1928
|
-
* @param onError - Specifies treatment of unconvertible elements.
|
|
1929
|
-
* @returns A new {@link Converter | Converter} which yields a value from the union of the types returned
|
|
1930
|
-
* by the wrapped converters.
|
|
1931
|
-
* @public
|
|
1932
|
-
*/
|
|
1933
|
-
declare function oneOf<T, TC = unknown>(converters: Array<Converter<T, TC> | Validator<T, TC>>, onError?: OnError): Converter<T, TC>;
|
|
1934
|
-
|
|
1935
|
-
/**
|
|
1936
|
-
* Helper function to create a {@link Validation.Validator | Validator} which validates one
|
|
1937
|
-
* of several possible validated values.
|
|
1938
|
-
* @param validators - the {@link Validation.Validator | validators} to be considered.
|
|
1939
|
-
* @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | params} used to construct the validator.
|
|
1940
|
-
* @returns A new {@link Validator | Validator} which validates values that match any of
|
|
1941
|
-
* the supplied validators.
|
|
1942
|
-
* @public
|
|
1943
|
-
*/
|
|
1944
|
-
declare function oneOf_2<T, TC = unknown>(validators: Array<Validator<T, TC>>, params?: Omit<OneOfValidatorConstructorParams<T, TC>, 'validators'>): OneOfValidator<T, TC>;
|
|
1811
|
+
declare function object_2<T, TC = unknown>(fields: FieldValidators<T, TC>, params?: Omit<ObjectValidatorConstructorParams<T, TC>, 'fields'>): ObjectValidator<T, TC>;
|
|
1945
1812
|
|
|
1946
|
-
/**
|
|
1947
|
-
* An in-place {@link Validator | Validator} which validates that a supplied
|
|
1948
|
-
* value matches one of several other validators.
|
|
1949
|
-
* @public
|
|
1950
|
-
*/
|
|
1951
|
-
declare class OneOfValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
|
|
1952
1813
|
/**
|
|
1953
|
-
* {@link
|
|
1954
|
-
*
|
|
1814
|
+
* A {@link Converter} which converts an object of type `<T>` without changing shape, given
|
|
1815
|
+
* a {@link Conversion.FieldConverters | FieldConverters<T>} for the fields in the object.
|
|
1816
|
+
* @remarks
|
|
1817
|
+
* By default, if all of the required fields exist and can be converted, returns a new object with
|
|
1818
|
+
* the converted values under the original key names. If any required fields do not exist or cannot
|
|
1819
|
+
* be converted, the entire conversion fails. See {@link Conversion.ObjectConverterOptions | ObjectConverterOptions}
|
|
1820
|
+
* for other conversion options.
|
|
1821
|
+
* @public
|
|
1955
1822
|
*/
|
|
1956
|
-
|
|
1957
|
-
|
|
1823
|
+
export declare class ObjectConverter<T, TC = unknown> extends BaseConverter<T, TC> {
|
|
1824
|
+
/**
|
|
1825
|
+
* Fields converted by this {@link Conversion.ObjectConverter | ObjectConverter}.
|
|
1826
|
+
*/
|
|
1827
|
+
readonly fields: FieldConverters<T>;
|
|
1828
|
+
/**
|
|
1829
|
+
* Options used to initialize this {@link Conversion.ObjectConverter | ObjectConverter}.
|
|
1830
|
+
*/
|
|
1831
|
+
readonly options: ObjectConverterOptions<T>;
|
|
1832
|
+
/**
|
|
1833
|
+
* Constructs a new {@link Conversion.ObjectConverter | ObjectConverter<T>} using options
|
|
1834
|
+
* supplied in a {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>}.
|
|
1835
|
+
* @param fields - A {@link Conversion.FieldConverters | FieldConverters<T>} containing
|
|
1836
|
+
* a {@link Converter} for each field
|
|
1837
|
+
* @param options - An optional @see ObjectConverterOptions to configure the conversion
|
|
1838
|
+
* {@label WITH_OPTIONS}
|
|
1839
|
+
*/
|
|
1840
|
+
constructor(fields: FieldConverters<T, TC>, options?: ObjectConverterOptions<T>);
|
|
1841
|
+
/**
|
|
1842
|
+
* Constructs a new {@link Conversion.ObjectConverter | ObjectConverter<T>} with optional
|
|
1843
|
+
* properties specified as an array of `keyof T`.
|
|
1844
|
+
* @param fields - A {@link Conversion.FieldConverters | FieldConverters<T>} containing
|
|
1845
|
+
* a {@link Converter} for each field.
|
|
1846
|
+
* @param optional - An array of `keyof T` listing fields that are not required.
|
|
1847
|
+
* {@label WITH_KEYS}
|
|
1848
|
+
*/
|
|
1849
|
+
constructor(fields: FieldConverters<T, TC>, optional?: (keyof T)[]);
|
|
1850
|
+
/**
|
|
1851
|
+
* Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with
|
|
1852
|
+
* new optional properties as specified by a supplied {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>}.
|
|
1853
|
+
* @param options - The {@link Conversion.ObjectConverterOptions | options} to be applied to the new
|
|
1854
|
+
* converter.
|
|
1855
|
+
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source properties.
|
|
1856
|
+
* {@label WITH_OPTIONS}
|
|
1857
|
+
*/
|
|
1858
|
+
partial(options: ObjectConverterOptions<T>): ObjectConverter<Partial<T>, TC>;
|
|
1859
|
+
/**
|
|
1860
|
+
* Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with
|
|
1861
|
+
* new optional properties as specified by a supplied array of `keyof T`.
|
|
1862
|
+
* @param optional - The keys of the source object properties to be made optional.
|
|
1863
|
+
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source
|
|
1864
|
+
* properties.
|
|
1865
|
+
* {@label WITH_KEYS}
|
|
1866
|
+
*/
|
|
1867
|
+
partial(optional?: (keyof T)[]): ObjectConverter<Partial<T>, TC>;
|
|
1868
|
+
/**
|
|
1869
|
+
* Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with
|
|
1870
|
+
* new optional properties as specified by a supplied array of `keyof T`.
|
|
1871
|
+
* @param addOptionalProperties - The keys to be made optional.
|
|
1872
|
+
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source
|
|
1873
|
+
* properties.
|
|
1874
|
+
*/
|
|
1875
|
+
addPartial(addOptionalProperties: (keyof T)[]): ObjectConverter<Partial<T>, TC>;
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1958
1878
|
/**
|
|
1959
|
-
*
|
|
1960
|
-
* @
|
|
1961
|
-
* new {@link Validation.Classes.OneOfValidator | OneOfValidator}.
|
|
1879
|
+
* Options for an {@link Conversion.ObjectConverter | ObjectConverter}.
|
|
1880
|
+
* @public
|
|
1962
1881
|
*/
|
|
1963
|
-
|
|
1882
|
+
declare interface ObjectConverterOptions<T> {
|
|
1883
|
+
/**
|
|
1884
|
+
* If present, lists optional fields. Missing non-optional fields cause an error.
|
|
1885
|
+
*/
|
|
1886
|
+
optionalFields?: (keyof T)[];
|
|
1887
|
+
/**
|
|
1888
|
+
* If true, unrecognized fields yield an error. If false or undefined (default),
|
|
1889
|
+
* unrecognized fields are ignored.
|
|
1890
|
+
*/
|
|
1891
|
+
strict?: boolean;
|
|
1892
|
+
/**
|
|
1893
|
+
* Optional description to be included in error messages.
|
|
1894
|
+
*/
|
|
1895
|
+
description?: string;
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1964
1898
|
/**
|
|
1965
|
-
*
|
|
1966
|
-
*
|
|
1967
|
-
*
|
|
1968
|
-
*
|
|
1969
|
-
*
|
|
1970
|
-
*
|
|
1899
|
+
* In-place {@link Validation.Validator | Validator} for an object of type `<T>`.
|
|
1900
|
+
* @remarks
|
|
1901
|
+
* By default, succeeds if all of the required fields exist and are validate, and fails if
|
|
1902
|
+
* any required fields do not exist or are invalid. See {@link Validation.Classes.ObjectValidatorOptions}
|
|
1903
|
+
* for other validation options.
|
|
1904
|
+
* @public
|
|
1971
1905
|
*/
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
1906
|
+
declare class ObjectValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
|
|
1907
|
+
/**
|
|
1908
|
+
* A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a
|
|
1909
|
+
* {@link Validation.Validator | Validator} for each of the expected properties
|
|
1910
|
+
*/
|
|
1911
|
+
readonly fields: FieldValidators<T>;
|
|
1912
|
+
/**
|
|
1913
|
+
* {@link Validation.Classes.ObjectValidatorOptions | Options} which apply to this
|
|
1914
|
+
* validator.
|
|
1915
|
+
*/
|
|
1916
|
+
readonly options: ObjectValidatorOptions<T, TC>;
|
|
1917
|
+
/**
|
|
1918
|
+
* @internal
|
|
1919
|
+
*/
|
|
1920
|
+
protected readonly _innerValidators: FieldValidators<T>;
|
|
1921
|
+
/**
|
|
1922
|
+
* @internal
|
|
1923
|
+
*/
|
|
1924
|
+
protected readonly _allowedFields?: Set<keyof T>;
|
|
1925
|
+
/**
|
|
1926
|
+
* Constructs a new {@link Validation.Classes.ObjectValidator | ObjectValidator<T>}.
|
|
1927
|
+
* @param fields - A {@link Validation.Classes.FieldValidators | FieldValidators<T>} containing
|
|
1928
|
+
* a {@link Validation.Validator | Validator} for each field.
|
|
1929
|
+
* @param options - An optional {@link Validation.Classes.ObjectValidatorOptions} to configure
|
|
1930
|
+
* validation.
|
|
1931
|
+
*/
|
|
1932
|
+
constructor(params: ObjectValidatorConstructorParams<T, TC>);
|
|
1933
|
+
/**
|
|
1934
|
+
* Creates the actual {@link Validation.Classes.FieldValidators | FieldValidators<T>} to be
|
|
1935
|
+
* used by this converter by applying any options or traits defined in the options
|
|
1936
|
+
* to the field converters passed to the constructor.
|
|
1937
|
+
* @param fields - The base {@link Validation.Classes.FieldValidators | FieldValidators<T>} passed
|
|
1938
|
+
* in to the constructor.
|
|
1939
|
+
* @param options - The {@link Validation.Classes.ObjectValidatorOptions | object validator options}
|
|
1940
|
+
* passed in to the constructor.
|
|
1941
|
+
* @returns A new {@link Validation.Classes.FieldValidators | FieldValidators} with the fully-configured
|
|
1942
|
+
* individual {@link Validation.Validator | field validators} to be applied.
|
|
1943
|
+
* @internal
|
|
1944
|
+
*/
|
|
1945
|
+
protected static _resolveValidators<T, TC>(fields: FieldValidators<T, TC>, options?: ObjectValidatorOptions<T, TC>): FieldValidators<T, TC>;
|
|
1946
|
+
/**
|
|
1947
|
+
* Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with
|
|
1948
|
+
* new optional properties as specified by a supplied
|
|
1949
|
+
* {@link Validation.Classes.ObjectValidatorOptions | ObjectValidatorOptions<T>}.
|
|
1950
|
+
* @param options - The {@link Validation.Classes.ObjectValidatorOptions | options} to be applied to the new
|
|
1951
|
+
* {@link Validation.Classes.ObjectValidator | validator}.
|
|
1952
|
+
* @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional
|
|
1953
|
+
* source properties.
|
|
1954
|
+
*/
|
|
1955
|
+
partial(options?: ObjectValidatorOptions<T, TC>): ObjectValidator<Partial<T>, TC>;
|
|
1956
|
+
/**
|
|
1957
|
+
* Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with
|
|
1958
|
+
* new optional properties as specified by a supplied array of `keyof T`.
|
|
1959
|
+
* @param addOptionalProperties - The keys to be made optional.
|
|
1960
|
+
* @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional
|
|
1961
|
+
* source properties.
|
|
1962
|
+
*/
|
|
1963
|
+
addPartial(addOptionalFields: (keyof T)[]): ObjectValidator<Partial<T>, TC>;
|
|
1964
|
+
/**
|
|
1965
|
+
* {@inheritdoc Validation.ValidatorBase._validate}
|
|
1966
|
+
* @internal
|
|
1967
|
+
*/
|
|
1968
|
+
protected _validate(from: unknown, context?: TC): boolean | Failure<T>;
|
|
1969
|
+
}
|
|
2026
1970
|
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
* @param src - The `ReadonlyMap` object to be converted, or `undefined`.
|
|
2030
|
-
* @param factory - The factory method used to convert elements.
|
|
2031
|
-
* @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.
|
|
2032
|
-
* Returns {@link Failure} with a message if an error occurs.
|
|
1971
|
+
/**
|
|
1972
|
+
* Options for the {@link Validation.Classes.ObjectValidator | ObjectValidator} constructor.
|
|
2033
1973
|
* @public
|
|
2034
1974
|
*/
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
* A {@link Converter | Converter} which converts an optional `number` value.
|
|
2049
|
-
* @remarks
|
|
2050
|
-
* Values of type `number` or numeric strings are converted and returned.
|
|
2051
|
-
* Anything else returns {@link Success | Success} with value `undefined`.
|
|
2052
|
-
* @public
|
|
2053
|
-
*/
|
|
2054
|
-
declare const optionalNumber: Converter<number | undefined>;
|
|
2055
|
-
|
|
2056
|
-
/**
|
|
2057
|
-
* Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.
|
|
2058
|
-
* @param src - The `Record` to be converted, or undefined.
|
|
2059
|
-
* @param factory - The factory method used to convert elements.
|
|
2060
|
-
* @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`
|
|
2061
|
-
* if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.
|
|
2062
|
-
* @public
|
|
2063
|
-
*/
|
|
2064
|
-
export declare function optionalRecordToMap<TS, TD, TK extends string = string>(src: Record<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD> | undefined>;
|
|
2065
|
-
|
|
2066
|
-
/**
|
|
2067
|
-
* Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`
|
|
2068
|
-
* @param src - The `Record` to be converted, or `undefined`.
|
|
2069
|
-
* @param factory - The factory method used to convert elements.
|
|
2070
|
-
* @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.
|
|
2071
|
-
* Returns {@link Failure} with a message if an error occurs.
|
|
2072
|
-
* @public
|
|
2073
|
-
*/
|
|
2074
|
-
export declare function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(src: Record<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD>>;
|
|
1975
|
+
declare interface ObjectValidatorConstructorParams<T, TC> extends ValidatorBaseConstructorParams<T, TC> {
|
|
1976
|
+
/**
|
|
1977
|
+
* A {@link Validation.Classes.FieldValidators | FieldValidators} object specifying a
|
|
1978
|
+
* {@link Validation.Validator | Validator} for each of the expected properties
|
|
1979
|
+
* of a result object.
|
|
1980
|
+
*/
|
|
1981
|
+
fields: FieldValidators<T>;
|
|
1982
|
+
/**
|
|
1983
|
+
* Optional additional {@link Validation.Classes.ObjectValidatorOptions | ValidatorOptions} to
|
|
1984
|
+
* configure validation.
|
|
1985
|
+
*/
|
|
1986
|
+
options?: ObjectValidatorOptions<T, TC>;
|
|
1987
|
+
}
|
|
2075
1988
|
|
|
2076
1989
|
/**
|
|
2077
|
-
*
|
|
2078
|
-
* `string` are returned. Anything else returns {@link Success | Success} with value `undefined`.
|
|
1990
|
+
* Options for an {@link Validation.Classes.ObjectValidator | ObjectValidator}.
|
|
2079
1991
|
* @public
|
|
2080
1992
|
*/
|
|
2081
|
-
declare
|
|
1993
|
+
declare interface ObjectValidatorOptions<T, TC> extends ValidatorOptions<TC> {
|
|
1994
|
+
/**
|
|
1995
|
+
* If present, lists optional fields. Missing non-optional fields cause an error.
|
|
1996
|
+
*/
|
|
1997
|
+
optionalFields?: (keyof T)[];
|
|
1998
|
+
/**
|
|
1999
|
+
* If true, unrecognized fields yield an error. If false or undefined (default),
|
|
2000
|
+
* unrecognized fields are ignored.
|
|
2001
|
+
*/
|
|
2002
|
+
strict?: boolean;
|
|
2003
|
+
}
|
|
2082
2004
|
|
|
2083
2005
|
/**
|
|
2084
|
-
* Simple implicit
|
|
2085
|
-
* object
|
|
2006
|
+
* Simple implicit omit function, which picks all of the properties from a supplied
|
|
2007
|
+
* object except those specified for exclusion.
|
|
2086
2008
|
* @param from - The object from which keys are to be picked.
|
|
2087
|
-
* @param
|
|
2088
|
-
* @returns A new object containing the
|
|
2009
|
+
* @param exclude - The keys of the properties to be excluded from the returned object.
|
|
2010
|
+
* @returns A new object containing all of the properties from `from` that were not
|
|
2011
|
+
* explicitly excluded.
|
|
2089
2012
|
* @public
|
|
2090
2013
|
*/
|
|
2091
|
-
export declare function
|
|
2014
|
+
export declare function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K>;
|
|
2092
2015
|
|
|
2093
2016
|
/**
|
|
2094
|
-
*
|
|
2095
|
-
* Returns
|
|
2096
|
-
*
|
|
2097
|
-
*
|
|
2098
|
-
*
|
|
2099
|
-
*
|
|
2100
|
-
*
|
|
2101
|
-
*
|
|
2102
|
-
*
|
|
2103
|
-
*
|
|
2017
|
+
* A helper function to create a {@link Converter | Converter} for polymorphic values.
|
|
2018
|
+
* Returns a converter which invokes the wrapped converters in sequence, returning the
|
|
2019
|
+
* first successful result. Returns an error if none of the supplied converters can
|
|
2020
|
+
* convert the value.
|
|
2021
|
+
* @remarks
|
|
2022
|
+
* If `onError` is `ignoreErrors` (default), then errors from any of the
|
|
2023
|
+
* converters are ignored provided that some converter succeeds. If
|
|
2024
|
+
* onError is `failOnError`, then an error from any converter fails the entire
|
|
2025
|
+
* conversion.
|
|
2026
|
+
*
|
|
2027
|
+
* @param converters - An ordered list of {@link Converter | converters} or {@link Validator | validators}
|
|
2028
|
+
* to be considered.
|
|
2029
|
+
* @param onError - Specifies treatment of unconvertible elements.
|
|
2030
|
+
* @returns A new {@link Converter | Converter} which yields a value from the union of the types returned
|
|
2031
|
+
* by the wrapped converters.
|
|
2104
2032
|
* @public
|
|
2105
2033
|
*/
|
|
2106
|
-
|
|
2034
|
+
declare function oneOf<T, TC = unknown>(converters: Array<Converter<T, TC> | Validator<T, TC>>, onError?: OnError): Converter<T, TC>;
|
|
2107
2035
|
|
|
2108
2036
|
/**
|
|
2109
|
-
*
|
|
2110
|
-
*
|
|
2111
|
-
*
|
|
2112
|
-
* @param
|
|
2113
|
-
*
|
|
2114
|
-
*
|
|
2115
|
-
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
2116
|
-
* appended. Each error is appended as an individual string.
|
|
2037
|
+
* Helper function to create a {@link Validation.Validator | Validator} which validates one
|
|
2038
|
+
* of several possible validated values.
|
|
2039
|
+
* @param validators - the {@link Validation.Validator | validators} to be considered.
|
|
2040
|
+
* @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | params} used to construct the validator.
|
|
2041
|
+
* @returns A new {@link Validator | Validator} which validates values that match any of
|
|
2042
|
+
* the supplied validators.
|
|
2117
2043
|
* @public
|
|
2118
|
-
* {@label WITH_ORDER}
|
|
2119
|
-
* @deprecated Pass {@link PopulateObjectOptions} instead.
|
|
2120
2044
|
*/
|
|
2121
|
-
|
|
2045
|
+
declare function oneOf_2<T, TC = unknown>(validators: Array<Validator<T, TC>>, params?: Omit<OneOfValidatorConstructorParams<T, TC>, 'validators'>): OneOfValidator<T, TC>;
|
|
2122
2046
|
|
|
2123
2047
|
/**
|
|
2124
|
-
*
|
|
2048
|
+
* An in-place {@link Validator | Validator} which validates that a supplied
|
|
2049
|
+
* value matches one of several other validators.
|
|
2125
2050
|
* @public
|
|
2126
2051
|
*/
|
|
2127
|
-
|
|
2052
|
+
declare class OneOfValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
|
|
2053
|
+
/**
|
|
2054
|
+
* {@link Validation.ValidatorOptions | Options} which apply to this
|
|
2055
|
+
* validator.
|
|
2056
|
+
*/
|
|
2057
|
+
readonly options: ValidatorOptions<TC>;
|
|
2058
|
+
protected readonly _validators: Validator<T, TC>[];
|
|
2128
2059
|
/**
|
|
2129
|
-
*
|
|
2130
|
-
*
|
|
2131
|
-
*
|
|
2132
|
-
* are evaluated in indeterminate order.
|
|
2060
|
+
* Constructs a new {@link Validation.Classes.OneOfValidator | OneOfValidator}.
|
|
2061
|
+
* @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | init params} for the
|
|
2062
|
+
* new {@link Validation.Classes.OneOfValidator | OneOfValidator}.
|
|
2133
2063
|
*/
|
|
2134
|
-
|
|
2064
|
+
constructor(params: OneOfValidatorConstructorParams<T, TC>);
|
|
2135
2065
|
/**
|
|
2136
|
-
*
|
|
2137
|
-
*
|
|
2138
|
-
*
|
|
2139
|
-
*
|
|
2140
|
-
*
|
|
2066
|
+
* Static method which validates that a supplied `unknown` value matches at least one
|
|
2067
|
+
* of the configured validators.
|
|
2068
|
+
* @param from - The `unknown` value to be tested.
|
|
2069
|
+
* @param context - Optional validation context will be propagated to element validator.
|
|
2070
|
+
* @returns Returns `true` if `from` is an `array` of valid elements, or
|
|
2071
|
+
* {@link Failure} with an error message if not.
|
|
2141
2072
|
*/
|
|
2142
|
-
|
|
2073
|
+
protected _validate<T>(from: unknown, context?: TC): boolean | Failure<T>;
|
|
2143
2074
|
}
|
|
2144
2075
|
|
|
2145
2076
|
/**
|
|
2146
|
-
*
|
|
2147
|
-
* event details as appropriate.
|
|
2148
|
-
* @param result - The {@link Result} to be propagated.
|
|
2149
|
-
* @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.
|
|
2150
|
-
* @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`
|
|
2151
|
-
* is omitted or `undefined`, then `detail` will be applied to {@link Success} results.
|
|
2152
|
-
* @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error
|
|
2153
|
-
* message from the original `result` but with the specified detail added.
|
|
2077
|
+
* Parameters used to construct a {@link Validation.Classes.OneOfValidator | OneOfValidator}.
|
|
2154
2078
|
* @public
|
|
2155
2079
|
*/
|
|
2156
|
-
|
|
2080
|
+
declare interface OneOfValidatorConstructorParams<T, TC = unknown> extends ValidatorBaseConstructorParams<T, TC> {
|
|
2081
|
+
validators: Validator<T, TC>[];
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
/**
|
|
2085
|
+
* Action to take on conversion failures.
|
|
2086
|
+
* @public
|
|
2087
|
+
*/
|
|
2088
|
+
declare type OnError = 'failOnError' | 'ignoreErrors';
|
|
2157
2089
|
|
|
2158
2090
|
/**
|
|
2159
|
-
* A
|
|
2160
|
-
* properties using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to
|
|
2161
|
-
* produce a `Record<string, T>`.
|
|
2091
|
+
* A {@link Converter | Converter} to convert an optional `boolean` value.
|
|
2162
2092
|
* @remarks
|
|
2163
|
-
*
|
|
2164
|
-
*
|
|
2165
|
-
*
|
|
2166
|
-
* @returns A {@link Converter | Converter} which returns `Record<string, T>`.
|
|
2167
|
-
* {@label WITH_DEFAULT}
|
|
2093
|
+
* Values of type `boolean` or strings that match (case-insensitive) `'true'`
|
|
2094
|
+
* or `'false'` are converted and returned. Anything else returns {@link Success | Success}
|
|
2095
|
+
* with value `undefined`.
|
|
2168
2096
|
* @public
|
|
2169
2097
|
*/
|
|
2170
|
-
declare
|
|
2098
|
+
declare const optionalBoolean: Converter<boolean | undefined>;
|
|
2171
2099
|
|
|
2172
2100
|
/**
|
|
2173
|
-
* A helper function to create a {@link Converter | Converter} which converts
|
|
2174
|
-
* using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce a
|
|
2175
|
-
* `Record<string, T>` and optionally specified handling of elements that cannot be converted.
|
|
2101
|
+
* A helper function to create a {@link Converter | Converter} which extracts and converts an optional element from an array.
|
|
2176
2102
|
* @remarks
|
|
2177
|
-
*
|
|
2178
|
-
*
|
|
2179
|
-
*
|
|
2180
|
-
* the
|
|
2181
|
-
* @
|
|
2182
|
-
* {@
|
|
2103
|
+
* The resulting {@link Converter | Converter} returns {@link Success | Success} with the converted value if the element exists
|
|
2104
|
+
* in the supplied array and can be converted. Returns {@link Success | Success} with value `undefined` if the parameter
|
|
2105
|
+
* is an array but the index is out of range. Returns {@link Failure | Failure} with a message if the supplied parameter
|
|
2106
|
+
* is not an array, if the requested index is negative, or if the element cannot be converted.
|
|
2107
|
+
* @param index - The index of the element to be extracted.
|
|
2108
|
+
* @param converter - A {@link Converter | Converter} or {@link Validator | Validator} used for the extracted element.
|
|
2109
|
+
* @returns A {@link Converter | Converter<T>} which extracts the specified element from an array.
|
|
2183
2110
|
* @public
|
|
2184
2111
|
*/
|
|
2185
|
-
declare function
|
|
2112
|
+
declare function optionalElement<T, TC = undefined>(index: number, converter: Converter<T, TC> | Validator<T, TC>): Converter<T | undefined, TC>;
|
|
2186
2113
|
|
|
2187
2114
|
/**
|
|
2188
|
-
* A helper function to create a {@link Converter | Converter}
|
|
2189
|
-
*
|
|
2190
|
-
* `Record<TK, T>`.
|
|
2115
|
+
* A helper function to create a {@link Converter | Converter} which extracts and convert a property specified
|
|
2116
|
+
* by name from an object.
|
|
2191
2117
|
* @remarks
|
|
2192
|
-
*
|
|
2193
|
-
*
|
|
2194
|
-
*
|
|
2195
|
-
*
|
|
2196
|
-
*
|
|
2197
|
-
* @
|
|
2198
|
-
* {@label WITH_OPTIONS}
|
|
2118
|
+
* The resulting {@link Converter | Converter} returns {@link Success | Success} with the converted value of
|
|
2119
|
+
* the corresponding object property if the field exists and can be converted. Returns {@link Success | Success}
|
|
2120
|
+
* with `undefined` if the supplied parameter is an object but the named field is not present.
|
|
2121
|
+
* Returns {@link Failure | Failure} with an error message otherwise.
|
|
2122
|
+
* @param name - The name of the field to be extracted.
|
|
2123
|
+
* @param converter - {@link Converter | Converter} or {@link Validator | Validator} to use for the extracted field.
|
|
2199
2124
|
* @public
|
|
2200
2125
|
*/
|
|
2201
|
-
declare function
|
|
2126
|
+
declare function optionalField<T, TC = undefined>(name: string, converter: Converter<T, TC> | Validator<T, TC>): Converter<T | undefined, TC>;
|
|
2202
2127
|
|
|
2203
2128
|
/**
|
|
2204
|
-
* Applies a factory method to convert
|
|
2205
|
-
* @param src - The `
|
|
2129
|
+
* Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`
|
|
2130
|
+
* @param src - The `ReadonlyMap` object to be converted, or `undefined`.
|
|
2206
2131
|
* @param factory - The factory method used to convert elements.
|
|
2207
|
-
* @returns {@link Success} with the resulting
|
|
2208
|
-
* message if an error occurs.
|
|
2132
|
+
* @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.
|
|
2133
|
+
* Returns {@link Failure} with a message if an error occurs.
|
|
2209
2134
|
* @public
|
|
2210
2135
|
*/
|
|
2211
|
-
export declare function
|
|
2136
|
+
export declare function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD>>;
|
|
2212
2137
|
|
|
2213
2138
|
/**
|
|
2214
|
-
*
|
|
2215
|
-
* @
|
|
2216
|
-
*
|
|
2217
|
-
*
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2139
|
+
* Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.
|
|
2140
|
+
* @param src - The `Map` object to be converted, or `undefined`.
|
|
2141
|
+
* @param factory - The factory method used to convert elements.
|
|
2142
|
+
* @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if
|
|
2143
|
+
* `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.
|
|
2144
|
+
* @public
|
|
2145
|
+
*/
|
|
2146
|
+
export declare function optionalMapToRecord<TS, TD, TK extends string = string>(src: ReadonlyMap<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Record<TK, TD> | undefined>;
|
|
2221
2147
|
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2148
|
+
/**
|
|
2149
|
+
* A {@link Converter | Converter} which converts an optional `number` value.
|
|
2150
|
+
* @remarks
|
|
2151
|
+
* Values of type `number` or numeric strings are converted and returned.
|
|
2152
|
+
* Anything else returns {@link Success | Success} with value `undefined`.
|
|
2153
|
+
* @public
|
|
2154
|
+
*/
|
|
2155
|
+
declare const optionalNumber: Converter<number | undefined>;
|
|
2156
|
+
|
|
2157
|
+
/**
|
|
2158
|
+
* Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.
|
|
2159
|
+
* @param src - The `Record` to be converted, or undefined.
|
|
2160
|
+
* @param factory - The factory method used to convert elements.
|
|
2161
|
+
* @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`
|
|
2162
|
+
* if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.
|
|
2163
|
+
* @public
|
|
2164
|
+
*/
|
|
2165
|
+
export declare function optionalRecordToMap<TS, TD, TK extends string = string>(src: Record<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD> | undefined>;
|
|
2166
|
+
|
|
2167
|
+
/**
|
|
2168
|
+
* Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`
|
|
2169
|
+
* @param src - The `Record` to be converted, or `undefined`.
|
|
2170
|
+
* @param factory - The factory method used to convert elements.
|
|
2171
|
+
* @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.
|
|
2172
|
+
* Returns {@link Failure} with a message if an error occurs.
|
|
2173
|
+
* @public
|
|
2174
|
+
*/
|
|
2175
|
+
export declare function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(src: Record<TK, TS> | undefined, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD>>;
|
|
2227
2176
|
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2177
|
+
/**
|
|
2178
|
+
* A {@link Converter | Converter} which converts an optional `string` value. Values of type
|
|
2179
|
+
* `string` are returned. Anything else returns {@link Success | Success} with value `undefined`.
|
|
2180
|
+
* @public
|
|
2181
|
+
*/
|
|
2182
|
+
declare const optionalString: Converter<string | undefined, unknown>;
|
|
2233
2183
|
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
*
|
|
2244
|
-
* The conversion fails if any unexpected fields are encountered.
|
|
2245
|
-
*
|
|
2246
|
-
* @param properties - An object containing defining the shape and converters to be applied.
|
|
2247
|
-
* @param options - An optional @see StrictObjectConverterOptions<T> containing options for the object converter.
|
|
2248
|
-
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
|
|
2249
|
-
* {@label WITH_OPTIONS}
|
|
2250
|
-
* @public
|
|
2251
|
-
*/
|
|
2252
|
-
declare function strictObject<T>(properties: FieldConverters<T>, options?: StrictObjectConverterOptions<T>): ObjectConverter<T>;
|
|
2184
|
+
/**
|
|
2185
|
+
* Simple implicit pick function, which picks a set of properties from a supplied
|
|
2186
|
+
* object. Ignores picked properties that do not exist regardless of type signature.
|
|
2187
|
+
* @param from - The object from which keys are to be picked.
|
|
2188
|
+
* @param include - The keys of the properties to be picked from `from`.
|
|
2189
|
+
* @returns A new object containing the requested properties from `from`, where present.
|
|
2190
|
+
* @public
|
|
2191
|
+
*/
|
|
2192
|
+
export declare function pick<T extends object, K extends keyof T>(from: T, include: K[]): Pick<T, K>;
|
|
2253
2193
|
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
|
|
2269
|
-
* {@label WITH_KEYS}
|
|
2270
|
-
* @deprecated Use {@link Converters.(strictObject:1) | Converters.strictObject(options)} instead.
|
|
2271
|
-
* @public
|
|
2272
|
-
*/
|
|
2273
|
-
declare function strictObject<T>(properties: FieldConverters<T>, optional: (keyof T)[]): ObjectConverter<T>;
|
|
2194
|
+
/**
|
|
2195
|
+
* Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.
|
|
2196
|
+
* Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a
|
|
2197
|
+
* concatenated list of all error messages.
|
|
2198
|
+
* @param initializers - An object with the shape of the target but with initializer functions for
|
|
2199
|
+
* each property.
|
|
2200
|
+
* @param options - An optional {@link PopulateObjectOptions | set of options} which
|
|
2201
|
+
* modify the behavior of this call.
|
|
2202
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
2203
|
+
* appended. Each error is appended as an individual string.
|
|
2204
|
+
* {@label WITH_OPTIONS}
|
|
2205
|
+
* @public
|
|
2206
|
+
*/
|
|
2207
|
+
export declare function populateObject<T>(initializers: FieldInitializers<T>, options?: PopulateObjectOptions<T>, aggregatedErrors?: IMessageAggregator): Result<T>;
|
|
2274
2208
|
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2209
|
+
/**
|
|
2210
|
+
* Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.
|
|
2211
|
+
* Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a
|
|
2212
|
+
* concatenated list of all error messages.
|
|
2213
|
+
* @param initializers - An object with the shape of the target but with initializer functions for
|
|
2214
|
+
* each property.
|
|
2215
|
+
* @param order - Optional order in which keys should be written.
|
|
2216
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
2217
|
+
* appended. Each error is appended as an individual string.
|
|
2218
|
+
* @public
|
|
2219
|
+
* {@label WITH_ORDER}
|
|
2220
|
+
* @deprecated Pass {@link PopulateObjectOptions} instead.
|
|
2221
|
+
*/
|
|
2222
|
+
export declare function populateObject<T>(initializers: FieldInitializers<T>, order: (keyof T)[] | undefined, aggregatedErrors?: IMessageAggregator): Result<T>;
|
|
2280
2223
|
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2224
|
+
/**
|
|
2225
|
+
* Options for the {@link (populateObject:1)} function.
|
|
2226
|
+
* @public
|
|
2227
|
+
*/
|
|
2228
|
+
export declare interface PopulateObjectOptions<T> {
|
|
2229
|
+
/**
|
|
2230
|
+
* If present, specifies the order in which property values should
|
|
2231
|
+
* be evaluated. Any keys not listed are evaluated after all listed
|
|
2232
|
+
* keys in indeterminate order. If 'order' is not present, keys
|
|
2233
|
+
* are evaluated in indeterminate order.
|
|
2234
|
+
*/
|
|
2235
|
+
order?: (keyof T)[];
|
|
2236
|
+
/**
|
|
2237
|
+
* Specify handling of `undefined` values. By default, successful
|
|
2238
|
+
* `undefined` results are written to the result object. If this value
|
|
2239
|
+
* is `true` then `undefined` results are suppressed for all properties.
|
|
2240
|
+
* If this value is an array of property keys then `undefined` results
|
|
2241
|
+
* are suppressed for those properties only.
|
|
2242
|
+
*/
|
|
2243
|
+
suppressUndefined?: boolean | (keyof T)[];
|
|
2244
|
+
}
|
|
2287
2245
|
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2246
|
+
/**
|
|
2247
|
+
* Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied
|
|
2248
|
+
* event details as appropriate.
|
|
2249
|
+
* @param result - The {@link Result} to be propagated.
|
|
2250
|
+
* @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.
|
|
2251
|
+
* @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`
|
|
2252
|
+
* is omitted or `undefined`, then `detail` will be applied to {@link Success} results.
|
|
2253
|
+
* @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error
|
|
2254
|
+
* message from the original `result` but with the specified detail added.
|
|
2255
|
+
* @public
|
|
2256
|
+
*/
|
|
2257
|
+
export declare function propagateWithDetail<T, TD>(result: Result<T>, detail: TD, successDetail?: TD): DetailedResult<T, TD>;
|
|
2293
2258
|
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2259
|
+
/**
|
|
2260
|
+
* A helper function to create a {@link Converter | Converter} which converts the `string`-keyed
|
|
2261
|
+
* properties using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to
|
|
2262
|
+
* produce a `Record<string, T>`.
|
|
2263
|
+
* @remarks
|
|
2264
|
+
* The resulting converter fails conversion if any element cannot be converted.
|
|
2265
|
+
* @param converter - {@link Converter | Converter} or {@link Validator | Validator} used for each
|
|
2266
|
+
* item in the source object.
|
|
2267
|
+
* @returns A {@link Converter | Converter} which returns `Record<string, T>`.
|
|
2268
|
+
* {@label WITH_DEFAULT}
|
|
2269
|
+
* @public
|
|
2270
|
+
*/
|
|
2271
|
+
declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>): Converter<Record<TK, T>, TC>;
|
|
2272
|
+
|
|
2273
|
+
/**
|
|
2274
|
+
* A helper function to create a {@link Converter | Converter} which converts the `string`-keyed properties
|
|
2275
|
+
* using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce a
|
|
2276
|
+
* `Record<string, T>` and optionally specified handling of elements that cannot be converted.
|
|
2277
|
+
* @remarks
|
|
2278
|
+
* if `onError` is `'fail'` (default), then the entire conversion fails if any key or element
|
|
2279
|
+
* cannot be converted. If `onError` is `'ignore'`, failing elements are silently ignored.
|
|
2280
|
+
* @param converter - {@link Converter | Converter} or {@link Validator | Validator} for each item in
|
|
2281
|
+
* the source object.
|
|
2282
|
+
* @returns A {@link Converter | Converter} which returns `Record<string, T>`.
|
|
2283
|
+
* {@label WITH_ON_ERROR}
|
|
2284
|
+
* @public
|
|
2285
|
+
*/
|
|
2286
|
+
declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>, onError: 'fail' | 'ignore'): Converter<Record<TK, T>, TC>;
|
|
2287
|
+
|
|
2288
|
+
/**
|
|
2289
|
+
* A helper function to create a {@link Converter | Converter} or which converts the `string`-keyed properties
|
|
2290
|
+
* using a supplied {@link Converter | Converter<T>} or {@link Validator | Validator<T>} to produce a
|
|
2291
|
+
* `Record<TK, T>`.
|
|
2292
|
+
* @remarks
|
|
2293
|
+
* If present, the supplied {@link Converters.KeyedConverterOptions | options} can provide a strongly-typed
|
|
2294
|
+
* converter for keys and/or control the handling of elements that fail conversion.
|
|
2295
|
+
* @param converter - {@link Converter | Converter} or {@link Validator | Validator} used for each item in the source object.
|
|
2296
|
+
* @param options - Optional {@link Converters.KeyedConverterOptions | KeyedConverterOptions<TK, TC>} which
|
|
2297
|
+
* supplies a key converter and/or error-handling options.
|
|
2298
|
+
* @returns A {@link Converter | Converter} which returns `Record<TK, T>`.
|
|
2299
|
+
* {@label WITH_OPTIONS}
|
|
2300
|
+
* @public
|
|
2301
|
+
*/
|
|
2302
|
+
declare function recordOf<T, TC = undefined, TK extends string = string>(converter: Converter<T, TC> | Validator<T, TC>, options: KeyedConverterOptions<TK, TC>): Converter<Record<TK, T>, TC>;
|
|
2303
|
+
|
|
2304
|
+
/**
|
|
2305
|
+
* Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.
|
|
2306
|
+
* @param src - The `Record` to be converted.
|
|
2307
|
+
* @param factory - The factory method used to convert elements.
|
|
2308
|
+
* @returns {@link Success} with the resulting map on success, or {@link Failure} with a
|
|
2309
|
+
* message if an error occurs.
|
|
2310
|
+
* @public
|
|
2311
|
+
*/
|
|
2312
|
+
export declare function recordToMap<TS, TD, TK extends string = string>(src: Record<TK, TS>, factory: KeyedThingFactory<TS, TD, TK>): Result<Map<TK, TD>>;
|
|
2302
2313
|
|
|
2303
|
-
/**
|
|
2304
|
-
* The {@link Conversion.StringConverter | StringConverter} class extends
|
|
2305
|
-
* {@link Conversion.BaseConverter | BaseConverter} to provide string-specific
|
|
2306
|
-
* helper methods.
|
|
2307
|
-
* @public
|
|
2308
|
-
*/
|
|
2309
|
-
export declare class StringConverter<T extends string = string, TC = unknown> extends BaseConverter<T, TC> {
|
|
2310
2314
|
/**
|
|
2311
|
-
*
|
|
2312
|
-
* @
|
|
2313
|
-
* @
|
|
2314
|
-
* @
|
|
2315
|
+
* Represents the {@link IResult | result} of some operation or sequence of operations.
|
|
2316
|
+
* @remarks
|
|
2317
|
+
* {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common
|
|
2318
|
+
* contract {@link IResult}, enabling commingled discriminated usage.
|
|
2319
|
+
* @public
|
|
2315
2320
|
*/
|
|
2316
|
-
|
|
2321
|
+
export declare type Result<T> = Success<T> | Failure<T>;
|
|
2322
|
+
|
|
2317
2323
|
/**
|
|
2318
|
-
* @
|
|
2324
|
+
* Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.
|
|
2325
|
+
* @beta
|
|
2319
2326
|
*/
|
|
2320
|
-
|
|
2327
|
+
export declare type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;
|
|
2328
|
+
|
|
2321
2329
|
/**
|
|
2322
|
-
* @
|
|
2330
|
+
* Type inference to determine the result type of an {@link Result}.
|
|
2331
|
+
* @beta
|
|
2323
2332
|
*/
|
|
2324
|
-
|
|
2333
|
+
export declare type ResultValueType<T> = T extends Result<infer TV> ? TV : never;
|
|
2334
|
+
|
|
2325
2335
|
/**
|
|
2326
|
-
*
|
|
2327
|
-
* a
|
|
2328
|
-
* @
|
|
2329
|
-
*
|
|
2330
|
-
*
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
matching(match: string[], options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
|
|
2345
|
-
/**
|
|
2346
|
-
* Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
|
|
2347
|
-
* one of a supplied `Set` of strings.
|
|
2348
|
-
* @param match - The `Set` of allowed strings.
|
|
2349
|
-
* @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.
|
|
2350
|
-
* @returns {@link Success} with a matching string or {@link Failure} with an informative
|
|
2351
|
-
* error if the string does not match.
|
|
2352
|
-
* {@label WITH_SET}
|
|
2353
|
-
*/
|
|
2354
|
-
matching(match: Set<T>, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
|
|
2355
|
-
/**
|
|
2356
|
-
* Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
|
|
2357
|
-
* a supplied regular expression.
|
|
2358
|
-
* @param match - The regular expression to be used as a constraint.
|
|
2359
|
-
* @param options - Optional {@link Conversion.StringMatchOptions} for this conversion
|
|
2360
|
-
* @returns {@link Success} with a matching string or {@link Failure} with an informative
|
|
2361
|
-
* error if the string does not match.
|
|
2362
|
-
* {@label WITH_REGEXP}
|
|
2363
|
-
*/
|
|
2364
|
-
matching(match: RegExp, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
|
|
2365
|
-
}
|
|
2336
|
+
* Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter} which converts an object
|
|
2337
|
+
* without changing shape, a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
|
|
2338
|
+
* {@link Converters.StrictObjectConverterOptions | StrictObjectConverterOptions<T>} to further refine
|
|
2339
|
+
* conversion behavior.
|
|
2340
|
+
*
|
|
2341
|
+
* @remarks
|
|
2342
|
+
* Fields that succeed but convert to undefined are omitted from the result object but do not
|
|
2343
|
+
* fail the conversion.
|
|
2344
|
+
*
|
|
2345
|
+
* The conversion fails if any unexpected fields are encountered.
|
|
2346
|
+
*
|
|
2347
|
+
* @param properties - An object containing defining the shape and converters to be applied.
|
|
2348
|
+
* @param options - An optional @see StrictObjectConverterOptions<T> containing options for the object converter.
|
|
2349
|
+
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
|
|
2350
|
+
* {@label WITH_OPTIONS}
|
|
2351
|
+
* @public
|
|
2352
|
+
*/
|
|
2353
|
+
declare function strictObject<T>(properties: FieldConverters<T>, options?: StrictObjectConverterOptions<T>): ObjectConverter<T>;
|
|
2366
2354
|
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2355
|
+
/**
|
|
2356
|
+
* Helper function to create a {@link Conversion.ObjectConverter | ObjectConverter} which converts an object
|
|
2357
|
+
* without changing shape, a {@link Conversion.FieldConverters | FieldConverters<T>} and an optional
|
|
2358
|
+
* {@link Converters.StrictObjectConverterOptions | StrictObjectConverterOptions<T>} to further refine
|
|
2359
|
+
* conversion behavior.
|
|
2360
|
+
*
|
|
2361
|
+
* @remarks
|
|
2362
|
+
* Fields that succeed but convert to undefined are omitted from the result object but do not
|
|
2363
|
+
* fail the conversion.
|
|
2364
|
+
*
|
|
2365
|
+
* The conversion fails if any unexpected fields are encountered.
|
|
2366
|
+
*
|
|
2367
|
+
* @param properties - An object containing defining the shape and converters to be applied.
|
|
2368
|
+
* @param optional - An array of `keyof T` containing keys to be considered optional.
|
|
2369
|
+
* @returns A new {@link Conversion.ObjectConverter | ObjectConverter} which applies the specified conversions.
|
|
2370
|
+
* {@label WITH_KEYS}
|
|
2371
|
+
* @deprecated Use {@link Converters.(strictObject:1) | Converters.strictObject(options)} instead.
|
|
2372
|
+
* @public
|
|
2373
|
+
*/
|
|
2374
|
+
declare function strictObject<T>(properties: FieldConverters<T>, optional: (keyof T)[]): ObjectConverter<T>;
|
|
2379
2375
|
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
/**
|
|
2386
|
-
* Constructs a new {@link Validation.Classes.StringValidator | StringValidator}.
|
|
2387
|
-
* @param params - Optional {@link Validation.Classes.StringValidatorConstructorParams | init params}
|
|
2388
|
-
* for the new {@link Validation.Classes.StringValidator | StringValidator}.
|
|
2389
|
-
*/
|
|
2390
|
-
constructor(params?: StringValidatorConstructorParams<T, TC>);
|
|
2391
|
-
/**
|
|
2392
|
-
* Static method which validates that a supplied `unknown` value is a `string`.
|
|
2393
|
-
* @param from - The `unknown` value to be tested.
|
|
2394
|
-
* @returns Returns `true` if `from` is a `string`, or {@link Failure} with an error
|
|
2395
|
-
* message if not.
|
|
2396
|
-
*/
|
|
2397
|
-
static validateString<T extends string>(from: unknown): boolean | Failure<T>;
|
|
2398
|
-
}
|
|
2376
|
+
/**
|
|
2377
|
+
* Options for the {@link Converters.(strictObject:1)} helper function.
|
|
2378
|
+
* @public
|
|
2379
|
+
*/
|
|
2380
|
+
declare type StrictObjectConverterOptions<T> = Omit<ObjectConverterOptions<T>, 'strict'>;
|
|
2399
2381
|
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2382
|
+
/**
|
|
2383
|
+
* A converter to convert unknown to string. Values of type
|
|
2384
|
+
* string succeed. Anything else fails.
|
|
2385
|
+
* @public
|
|
2386
|
+
*/
|
|
2387
|
+
declare const string: StringConverter;
|
|
2405
2388
|
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
export declare function succeed<T>(value: T): Success<T>;
|
|
2389
|
+
/**
|
|
2390
|
+
* A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.
|
|
2391
|
+
* @public
|
|
2392
|
+
*/
|
|
2393
|
+
declare const string_2: Validator<string>;
|
|
2412
2394
|
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
*/
|
|
2422
|
-
export declare function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
|
|
2395
|
+
/**
|
|
2396
|
+
* {@link Converter | Converter} to convert an `unknown` to an array of `string`.
|
|
2397
|
+
* @remarks
|
|
2398
|
+
* Returns {@link Success | Success} with the the supplied value if it as an array
|
|
2399
|
+
* of strings, returns {@link Failure | Failure} with an error message otherwise.
|
|
2400
|
+
* @public
|
|
2401
|
+
*/
|
|
2402
|
+
declare const stringArray: Converter<string[]>;
|
|
2423
2403
|
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2404
|
+
/**
|
|
2405
|
+
* The {@link Conversion.StringConverter | StringConverter} class extends
|
|
2406
|
+
* {@link Conversion.BaseConverter | BaseConverter} to provide string-specific
|
|
2407
|
+
* helper methods.
|
|
2408
|
+
* @public
|
|
2409
|
+
*/
|
|
2410
|
+
export declare class StringConverter<T extends string = string, TC = unknown> extends BaseConverter<T, TC> {
|
|
2411
|
+
/**
|
|
2412
|
+
* Construct a new {@link Conversion.StringConverter | StringConverter}.
|
|
2413
|
+
* @param defaultContext - Optional context used by the conversion.
|
|
2414
|
+
* @param traits - Optional traits to be applied to the conversion.
|
|
2415
|
+
* @param converter - Optional conversion function to be used for the conversion.
|
|
2416
|
+
*/
|
|
2417
|
+
constructor(defaultContext?: TC, traits?: ConverterTraits, converter?: (from: unknown, self: Converter<T, TC>, context?: TC) => Result<T>);
|
|
2418
|
+
/**
|
|
2419
|
+
* @internal
|
|
2420
|
+
*/
|
|
2421
|
+
protected static _convert<T extends string>(from: unknown): Result<T>;
|
|
2422
|
+
/**
|
|
2423
|
+
* @internal
|
|
2424
|
+
*/
|
|
2425
|
+
protected static _wrap<T extends string, TC>(wrapped: StringConverter<T, TC>, converter: (from: T) => Result<T>, traits?: ConverterTraits): StringConverter<T, TC>;
|
|
2426
|
+
/**
|
|
2427
|
+
* Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
|
|
2428
|
+
* a supplied string.
|
|
2429
|
+
* @param match - The string to be matched
|
|
2430
|
+
* @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.
|
|
2431
|
+
* @returns {@link Success} with a matching string or {@link Failure} with an informative
|
|
2432
|
+
* error if the string does not match.
|
|
2433
|
+
* {@label WITH_STRING}
|
|
2434
|
+
*/
|
|
2435
|
+
matching(match: string, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
|
|
2436
|
+
/**
|
|
2437
|
+
* Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
|
|
2438
|
+
* one of a supplied array of strings.
|
|
2439
|
+
* @param match - The array of allowed strings.
|
|
2440
|
+
* @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.
|
|
2441
|
+
* @returns {@link Success} with a matching string or {@link Failure} with an informative
|
|
2442
|
+
* error if the string does not match.
|
|
2443
|
+
* {@label WITH_ARRAY}
|
|
2444
|
+
*/
|
|
2445
|
+
matching(match: string[], options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
|
|
2446
|
+
/**
|
|
2447
|
+
* Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
|
|
2448
|
+
* one of a supplied `Set` of strings.
|
|
2449
|
+
* @param match - The `Set` of allowed strings.
|
|
2450
|
+
* @param options - Optional {@link Conversion.StringMatchOptions} for this conversion.
|
|
2451
|
+
* @returns {@link Success} with a matching string or {@link Failure} with an informative
|
|
2452
|
+
* error if the string does not match.
|
|
2453
|
+
* {@label WITH_SET}
|
|
2454
|
+
*/
|
|
2455
|
+
matching(match: Set<T>, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
|
|
2447
2456
|
/**
|
|
2448
|
-
* {@
|
|
2449
|
-
|
|
2450
|
-
|
|
2457
|
+
* Returns a {@link Conversion.StringConverter | StringConverter} which constrains the result to match
|
|
2458
|
+
* a supplied regular expression.
|
|
2459
|
+
* @param match - The regular expression to be used as a constraint.
|
|
2460
|
+
* @param options - Optional {@link Conversion.StringMatchOptions} for this conversion
|
|
2461
|
+
* @returns {@link Success} with a matching string or {@link Failure} with an informative
|
|
2462
|
+
* error if the string does not match.
|
|
2463
|
+
* {@label WITH_REGEXP}
|
|
2464
|
+
*/
|
|
2465
|
+
matching(match: RegExp, options?: Partial<StringMatchOptions>): StringConverter<T, TC>;
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2451
2468
|
/**
|
|
2452
|
-
* {@
|
|
2469
|
+
* Options for {@link Conversion.StringConverter | StringConverter}
|
|
2470
|
+
* matching method
|
|
2471
|
+
* @public
|
|
2453
2472
|
*/
|
|
2454
|
-
|
|
2473
|
+
declare interface StringMatchOptions {
|
|
2474
|
+
/**
|
|
2475
|
+
* An optional message to be displayed if a non-matching string
|
|
2476
|
+
* is encountered.
|
|
2477
|
+
*/
|
|
2478
|
+
message?: string;
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2455
2481
|
/**
|
|
2456
|
-
* {@
|
|
2482
|
+
* An in-place {@link Validation.Validator | Validator} for `string` values.
|
|
2483
|
+
* @public
|
|
2457
2484
|
*/
|
|
2458
|
-
|
|
2485
|
+
declare class StringValidator<T extends string = string, TC = unknown> extends GenericValidator<T, TC> {
|
|
2486
|
+
/**
|
|
2487
|
+
* Constructs a new {@link Validation.Classes.StringValidator | StringValidator}.
|
|
2488
|
+
* @param params - Optional {@link Validation.Classes.StringValidatorConstructorParams | init params}
|
|
2489
|
+
* for the new {@link Validation.Classes.StringValidator | StringValidator}.
|
|
2490
|
+
*/
|
|
2491
|
+
constructor(params?: StringValidatorConstructorParams<T, TC>);
|
|
2492
|
+
/**
|
|
2493
|
+
* Static method which validates that a supplied `unknown` value is a `string`.
|
|
2494
|
+
* @param from - The `unknown` value to be tested.
|
|
2495
|
+
* @returns Returns `true` if `from` is a `string`, or {@link Failure} with an error
|
|
2496
|
+
* message if not.
|
|
2497
|
+
*/
|
|
2498
|
+
static validateString<T extends string>(from: unknown): boolean | Failure<T>;
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2459
2501
|
/**
|
|
2460
|
-
* {@
|
|
2502
|
+
* Parameters used to construct a {@link Validation.Classes.StringValidator | StringValidator}.
|
|
2503
|
+
* @public
|
|
2461
2504
|
*/
|
|
2462
|
-
|
|
2505
|
+
declare type StringValidatorConstructorParams<T extends string = string, TC = unknown> = GenericValidatorConstructorParams<T, TC>;
|
|
2506
|
+
|
|
2463
2507
|
/**
|
|
2464
|
-
* {@
|
|
2508
|
+
* Returns {@link Success | Success<T>} with the supplied result value.
|
|
2509
|
+
* @param value - The successful result value to be returned
|
|
2510
|
+
* @public
|
|
2465
2511
|
*/
|
|
2466
|
-
|
|
2512
|
+
export declare function succeed<T>(value: T): Success<T>;
|
|
2513
|
+
|
|
2467
2514
|
/**
|
|
2468
|
-
* {@
|
|
2469
|
-
*
|
|
2515
|
+
* Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional
|
|
2516
|
+
* detail.
|
|
2517
|
+
* @param value - The value of type `<T>` to be returned.
|
|
2518
|
+
* @param detail - An optional detail of type `<TD>` to be returned.
|
|
2519
|
+
* @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value
|
|
2520
|
+
* and detail, if supplied.
|
|
2521
|
+
* @public
|
|
2470
2522
|
*/
|
|
2471
|
-
|
|
2523
|
+
export declare function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
|
|
2524
|
+
|
|
2472
2525
|
/**
|
|
2473
|
-
* {@
|
|
2474
|
-
*
|
|
2526
|
+
* Reports a successful {@link IResult | result} from some operation and the
|
|
2527
|
+
* corresponding value.
|
|
2528
|
+
* @public
|
|
2475
2529
|
*/
|
|
2476
|
-
|
|
2530
|
+
export declare class Success<T> implements IResult<T> {
|
|
2531
|
+
/**
|
|
2532
|
+
* {@inheritdoc IResult.success}
|
|
2533
|
+
*/
|
|
2534
|
+
readonly success: true;
|
|
2535
|
+
/**
|
|
2536
|
+
* @internal
|
|
2537
|
+
*/
|
|
2538
|
+
private readonly _value;
|
|
2539
|
+
/**
|
|
2540
|
+
* Constructs a {@link Success} with the supplied value.
|
|
2541
|
+
* @param value - The value to be returned.
|
|
2542
|
+
*/
|
|
2543
|
+
constructor(value: T);
|
|
2544
|
+
/**
|
|
2545
|
+
* The result value returned by the successful operation.
|
|
2546
|
+
*/
|
|
2547
|
+
get value(): T;
|
|
2548
|
+
/**
|
|
2549
|
+
* {@inheritdoc IResult.isSuccess}
|
|
2550
|
+
*/
|
|
2551
|
+
isSuccess(): this is Success<T>;
|
|
2552
|
+
/**
|
|
2553
|
+
* {@inheritdoc IResult.isFailure}
|
|
2554
|
+
*/
|
|
2555
|
+
isFailure(): this is Failure<T>;
|
|
2556
|
+
/**
|
|
2557
|
+
* {@inheritdoc IResult.orThrow}
|
|
2558
|
+
*/
|
|
2559
|
+
orThrow(__logger?: IResultLogger): T;
|
|
2560
|
+
/**
|
|
2561
|
+
* {@inheritdoc IResult.(orDefault:1)}
|
|
2562
|
+
*/
|
|
2563
|
+
orDefault(dflt: T): T;
|
|
2564
|
+
/**
|
|
2565
|
+
* {@inheritdoc IResult.(orDefault:2)}
|
|
2566
|
+
*/
|
|
2567
|
+
orDefault(): T | undefined;
|
|
2568
|
+
/**
|
|
2569
|
+
* {@inheritdoc IResult.getValueOrThrow}
|
|
2570
|
+
* @deprecated Use {@link Success.orThrow | orThrow} instead.
|
|
2571
|
+
*/
|
|
2572
|
+
getValueOrThrow(__logger?: IResultLogger): T;
|
|
2573
|
+
/**
|
|
2574
|
+
* {@inheritdoc IResult.getValueOrDefault}
|
|
2575
|
+
* @deprecated Use {@link Success.(orDefault:1) | orDefault(T)} or {@link Success.(orDefault:2) | orDefault()} instead.
|
|
2576
|
+
*/
|
|
2577
|
+
getValueOrDefault(dflt?: T): T | undefined;
|
|
2578
|
+
/**
|
|
2579
|
+
* {@inheritdoc IResult.onSuccess}
|
|
2580
|
+
*/
|
|
2581
|
+
onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;
|
|
2582
|
+
/**
|
|
2583
|
+
* {@inheritdoc IResult.onFailure}
|
|
2584
|
+
*/
|
|
2585
|
+
onFailure(__: FailureContinuation<T>): Result<T>;
|
|
2586
|
+
/**
|
|
2587
|
+
* {@inheritdoc IResult.withFailureDetail}
|
|
2588
|
+
*/
|
|
2589
|
+
withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD>;
|
|
2590
|
+
/**
|
|
2591
|
+
* {@inheritdoc IResult.withDetail}
|
|
2592
|
+
*/
|
|
2593
|
+
withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;
|
|
2594
|
+
/**
|
|
2595
|
+
* {@inheritdoc IResult.aggregateError}
|
|
2596
|
+
*/
|
|
2597
|
+
aggregateError(errors: IMessageAggregator): this;
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2477
2600
|
/**
|
|
2478
|
-
*
|
|
2601
|
+
* Continuation callback to be called in the event that an
|
|
2602
|
+
* {@link Result} is successful.
|
|
2603
|
+
* @public
|
|
2479
2604
|
*/
|
|
2480
|
-
|
|
2605
|
+
export declare type SuccessContinuation<T, TN> = (value: T) => Result<TN>;
|
|
2606
|
+
|
|
2481
2607
|
/**
|
|
2482
|
-
* {@
|
|
2608
|
+
* Helper function to create a {@link Conversion.StringConverter | StringConverter} which converts
|
|
2609
|
+
* `unknown` to `string`, applying template conversions supplied at construction time or at
|
|
2610
|
+
* runtime as context.
|
|
2611
|
+
* @remarks
|
|
2612
|
+
* Template conversions are applied using `mustache` syntax.
|
|
2613
|
+
* @param defaultContext - Optional default context to use for template values.
|
|
2614
|
+
* @returns A new {@link Converter | Converter} returning `string`.
|
|
2615
|
+
* @public
|
|
2483
2616
|
*/
|
|
2484
|
-
|
|
2617
|
+
declare function templateString(defaultContext?: unknown): StringConverter<string, unknown>;
|
|
2618
|
+
|
|
2485
2619
|
/**
|
|
2486
|
-
* {@
|
|
2620
|
+
* Helper to create a {@link Converter | Converter} which converts a source object to a new object with a
|
|
2621
|
+
* different shape.
|
|
2622
|
+
*
|
|
2623
|
+
* @remarks
|
|
2624
|
+
* On successful conversion, the resulting {@link Converter | Converter} returns {@link Success | Success} with a new
|
|
2625
|
+
* object, which contains the converted values under the key names specified at initialization time.
|
|
2626
|
+
* It returns {@link Failure | Failure} with an error message if any fields to be extracted do not exist
|
|
2627
|
+
* or cannot be converted.
|
|
2628
|
+
*
|
|
2629
|
+
* Fields that succeed but convert to undefined are omitted from the result object but do not
|
|
2630
|
+
* fail the conversion.
|
|
2631
|
+
*
|
|
2632
|
+
* @param properties - An object with key names that correspond to the target object and an
|
|
2633
|
+
* appropriate {@link Conversion.FieldConverters | FieldConverter} which extracts and converts
|
|
2634
|
+
* a single filed from the source object.
|
|
2635
|
+
* @returns A {@link Converter | Converter} with the specified conversion behavior.
|
|
2636
|
+
* @public
|
|
2487
2637
|
*/
|
|
2488
|
-
|
|
2638
|
+
declare function transform<T, TC = unknown>(properties: FieldConverters<T, TC>): Converter<T, TC>;
|
|
2639
|
+
|
|
2489
2640
|
/**
|
|
2490
|
-
* {@
|
|
2641
|
+
* Helper to create a strongly-typed {@link Converter | Converter} which converts a source object to a
|
|
2642
|
+
* new object with a different shape.
|
|
2643
|
+
*
|
|
2644
|
+
* @remarks
|
|
2645
|
+
* On successful conversion, the resulting {@link Converter | Converter} returns {@link Success | Success} with a new
|
|
2646
|
+
* object, which contains the converted values under the key names specified at initialization time.
|
|
2647
|
+
*
|
|
2648
|
+
* It returns {@link Failure | Failure} with an error message if any fields to be extracted do not exist
|
|
2649
|
+
* or cannot be converted.
|
|
2650
|
+
*
|
|
2651
|
+
* @param destinationFields - An object with key names that correspond to the target object and an
|
|
2652
|
+
* appropriate {@link Converters.FieldTransformers | FieldTransformers} which specifies the name
|
|
2653
|
+
* of the corresponding property in the source object, the converter or validator used for each source
|
|
2654
|
+
* property and any other configuration to guide the conversion.
|
|
2655
|
+
* @param options - Options which affect the transformation.
|
|
2656
|
+
*
|
|
2657
|
+
* @returns A {@link Converter | Converter} with the specified conversion behavior.
|
|
2658
|
+
* @public
|
|
2491
2659
|
*/
|
|
2492
|
-
|
|
2493
|
-
}
|
|
2660
|
+
declare function transformObject<TSRC, TDEST, TC = unknown>(destinationFields: FieldTransformers<TSRC, TDEST, TC>, options?: TransformObjectOptions<TSRC>): Converter<TDEST, TC>;
|
|
2494
2661
|
|
|
2495
|
-
/**
|
|
2496
|
-
* Continuation callback to be called in the event that an
|
|
2497
|
-
* {@link Result} is successful.
|
|
2498
|
-
* @public
|
|
2499
|
-
*/
|
|
2500
|
-
export declare type SuccessContinuation<T, TN> = (value: T) => Result<TN>;
|
|
2501
|
-
|
|
2502
|
-
/**
|
|
2503
|
-
* Helper function to create a {@link Conversion.StringConverter | StringConverter} which converts
|
|
2504
|
-
* `unknown` to `string`, applying template conversions supplied at construction time or at
|
|
2505
|
-
* runtime as context.
|
|
2506
|
-
* @remarks
|
|
2507
|
-
* Template conversions are applied using `mustache` syntax.
|
|
2508
|
-
* @param defaultContext - Optional default context to use for template values.
|
|
2509
|
-
* @returns A new {@link Converter | Converter} returning `string`.
|
|
2510
|
-
* @public
|
|
2511
|
-
*/
|
|
2512
|
-
declare function templateString(defaultContext?: unknown): StringConverter<string, unknown>;
|
|
2513
|
-
|
|
2514
|
-
/**
|
|
2515
|
-
* Helper to create a {@link Converter | Converter} which converts a source object to a new object with a
|
|
2516
|
-
* different shape.
|
|
2517
|
-
*
|
|
2518
|
-
* @remarks
|
|
2519
|
-
* On successful conversion, the resulting {@link Converter | Converter} returns {@link Success | Success} with a new
|
|
2520
|
-
* object, which contains the converted values under the key names specified at initialization time.
|
|
2521
|
-
* It returns {@link Failure | Failure} with an error message if any fields to be extracted do not exist
|
|
2522
|
-
* or cannot be converted.
|
|
2523
|
-
*
|
|
2524
|
-
* Fields that succeed but convert to undefined are omitted from the result object but do not
|
|
2525
|
-
* fail the conversion.
|
|
2526
|
-
*
|
|
2527
|
-
* @param properties - An object with key names that correspond to the target object and an
|
|
2528
|
-
* appropriate {@link Conversion.FieldConverters | FieldConverter} which extracts and converts
|
|
2529
|
-
* a single filed from the source object.
|
|
2530
|
-
* @returns A {@link Converter | Converter} with the specified conversion behavior.
|
|
2531
|
-
* @public
|
|
2532
|
-
*/
|
|
2533
|
-
declare function transform<T, TC = unknown>(properties: FieldConverters<T, TC>): Converter<T, TC>;
|
|
2534
|
-
|
|
2535
|
-
/**
|
|
2536
|
-
* Helper to create a strongly-typed {@link Converter | Converter} which converts a source object to a
|
|
2537
|
-
* new object with a different shape.
|
|
2538
|
-
*
|
|
2539
|
-
* @remarks
|
|
2540
|
-
* On successful conversion, the resulting {@link Converter | Converter} returns {@link Success | Success} with a new
|
|
2541
|
-
* object, which contains the converted values under the key names specified at initialization time.
|
|
2542
|
-
*
|
|
2543
|
-
* It returns {@link Failure | Failure} with an error message if any fields to be extracted do not exist
|
|
2544
|
-
* or cannot be converted.
|
|
2545
|
-
*
|
|
2546
|
-
* @param destinationFields - An object with key names that correspond to the target object and an
|
|
2547
|
-
* appropriate {@link Converters.FieldTransformers | FieldTransformers} which specifies the name
|
|
2548
|
-
* of the corresponding property in the source object, the converter or validator used for each source
|
|
2549
|
-
* property and any other configuration to guide the conversion.
|
|
2550
|
-
* @param options - Options which affect the transformation.
|
|
2551
|
-
*
|
|
2552
|
-
* @returns A {@link Converter | Converter} with the specified conversion behavior.
|
|
2553
|
-
* @public
|
|
2554
|
-
*/
|
|
2555
|
-
declare function transformObject<TSRC, TDEST, TC = unknown>(destinationFields: FieldTransformers<TSRC, TDEST, TC>, options?: TransformObjectOptions<TSRC>): Converter<TDEST, TC>;
|
|
2556
|
-
|
|
2557
|
-
/**
|
|
2558
|
-
* Options for a {@link Converters.transformObject} call.
|
|
2559
|
-
* @public
|
|
2560
|
-
*/
|
|
2561
|
-
declare interface TransformObjectOptions<TSRC> {
|
|
2562
2662
|
/**
|
|
2563
|
-
*
|
|
2564
|
-
*
|
|
2663
|
+
* Options for a {@link Converters.transformObject} call.
|
|
2664
|
+
* @public
|
|
2565
2665
|
*/
|
|
2566
|
-
|
|
2666
|
+
declare interface TransformObjectOptions<TSRC> {
|
|
2667
|
+
/**
|
|
2668
|
+
* If `strict` is `true` then unused properties in the source object cause
|
|
2669
|
+
* an error, otherwise they are ignored.
|
|
2670
|
+
*/
|
|
2671
|
+
strict: true;
|
|
2672
|
+
/**
|
|
2673
|
+
* An optional list of source properties to be ignored when strict mode
|
|
2674
|
+
* is enabled.
|
|
2675
|
+
*/
|
|
2676
|
+
ignore?: (keyof TSRC)[];
|
|
2677
|
+
/**
|
|
2678
|
+
* An optional description of this transform to be used for error messages.
|
|
2679
|
+
*/
|
|
2680
|
+
description?: string;
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2567
2683
|
/**
|
|
2568
|
-
* An
|
|
2569
|
-
*
|
|
2684
|
+
* An in-place {@link Validation.Validator | Validator} that can be instantiated using a type guard
|
|
2685
|
+
* function.
|
|
2686
|
+
* @public
|
|
2570
2687
|
*/
|
|
2571
|
-
|
|
2688
|
+
declare class TypeGuardValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
|
|
2689
|
+
/**
|
|
2690
|
+
* {@link Validation.ValidatorOptions | Options} which apply to this
|
|
2691
|
+
* validator.
|
|
2692
|
+
*/
|
|
2693
|
+
readonly options: ValidatorOptions<TC>;
|
|
2694
|
+
readonly description: string;
|
|
2695
|
+
protected readonly _guard: TypeGuardWithContext<T, TC>;
|
|
2696
|
+
/**
|
|
2697
|
+
* Constructs a new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.
|
|
2698
|
+
* @param params - Optional {@link Validation.Classes.TypeGuardValidatorConstructorParams | init params} for the
|
|
2699
|
+
* new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator}.
|
|
2700
|
+
*/
|
|
2701
|
+
constructor(params: TypeGuardValidatorConstructorParams<T, TC>);
|
|
2702
|
+
/**
|
|
2703
|
+
* Static method which validates that a supplied `unknown` value matches the supplied
|
|
2704
|
+
* type guard, returning a `Failure<T>` containing more information about a failure.
|
|
2705
|
+
* @param from - Value to be converted.
|
|
2706
|
+
* @param context - Optional validation context.
|
|
2707
|
+
* @returns `true` if `from` is valid, {@link Failure | Failure<T>}
|
|
2708
|
+
* with an error message if `from` is invalid.
|
|
2709
|
+
* @internal
|
|
2710
|
+
*/
|
|
2711
|
+
protected _validate(from: unknown, context?: TC): boolean | Failure<T>;
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2572
2714
|
/**
|
|
2573
|
-
*
|
|
2715
|
+
* Parameters used to construct a {@link Validation.Classes.TypeGuardValidator}.
|
|
2716
|
+
* @public
|
|
2574
2717
|
*/
|
|
2575
|
-
|
|
2576
|
-
|
|
2718
|
+
declare interface TypeGuardValidatorConstructorParams<T, TC = unknown> extends ValidatorBaseConstructorParams<T, TC> {
|
|
2719
|
+
guard: TypeGuardWithContext<T, TC>;
|
|
2720
|
+
description: string;
|
|
2721
|
+
}
|
|
2577
2722
|
|
|
2578
|
-
/**
|
|
2579
|
-
* An in-place {@link Validation.Validator | Validator} that can be instantiated using a type guard
|
|
2580
|
-
* function.
|
|
2581
|
-
* @public
|
|
2582
|
-
*/
|
|
2583
|
-
declare class TypeGuardValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
|
|
2584
2723
|
/**
|
|
2585
|
-
*
|
|
2586
|
-
*
|
|
2724
|
+
* A type guard function which validates a specific type, with an optional context
|
|
2725
|
+
* that can be used to shape the validation.
|
|
2726
|
+
* @public
|
|
2587
2727
|
*/
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
protected readonly _guard: TypeGuardWithContext<T, TC>;
|
|
2728
|
+
declare type TypeGuardWithContext<T, TC = unknown> = (from: unknown, context?: TC) => from is T;
|
|
2729
|
+
|
|
2591
2730
|
/**
|
|
2592
|
-
*
|
|
2593
|
-
* @param
|
|
2594
|
-
*
|
|
2731
|
+
* Helper function to create a {@link Converter | Converter} from any {@link Validation.Validator}
|
|
2732
|
+
* @param validator - the validator to be wrapped
|
|
2733
|
+
* @returns A {@link Converter | Converter} which uses the supplied validator.
|
|
2734
|
+
* @public
|
|
2595
2735
|
*/
|
|
2596
|
-
|
|
2736
|
+
declare function validated<T, TC = unknown>(validator: Validator<T, TC>): Converter<T, TC>;
|
|
2737
|
+
|
|
2597
2738
|
/**
|
|
2598
|
-
*
|
|
2599
|
-
* type
|
|
2600
|
-
* @
|
|
2601
|
-
* @
|
|
2602
|
-
*
|
|
2603
|
-
*
|
|
2604
|
-
* @
|
|
2739
|
+
* Helper function to create a {@link Converter | Converter} which validates that a supplied value is
|
|
2740
|
+
* of a type validated by a supplied validator function and returns it.
|
|
2741
|
+
* @remarks
|
|
2742
|
+
* If `validator` succeeds, this {@link Converter | Converter} returns {@link Success | Success} with the supplied
|
|
2743
|
+
* value of `from` coerced to type `<T>`. Returns a {@link Failure | Failure} with additional
|
|
2744
|
+
* information otherwise.
|
|
2745
|
+
* @param validator - A validator function to determine if the converted value is valid.
|
|
2746
|
+
* @param description - A description of the validated type for use in error messages.
|
|
2747
|
+
* @returns A new {@link Converter | Converter<T>} which applies the supplied validation.
|
|
2748
|
+
* @public
|
|
2605
2749
|
*/
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
declare type TypeGuardWithContext<T, TC = unknown> = (from: unknown, context?: TC) => from is T;
|
|
2624
|
-
|
|
2625
|
-
/**
|
|
2626
|
-
* Helper function to create a {@link Converter | Converter} from any {@link Validation.Validator}
|
|
2627
|
-
* @param validator - the validator to be wrapped
|
|
2628
|
-
* @returns A {@link Converter | Converter} which uses the supplied validator.
|
|
2629
|
-
* @public
|
|
2630
|
-
*/
|
|
2631
|
-
declare function validated<T, TC = unknown>(validator: Validator<T, TC>): Converter<T, TC>;
|
|
2632
|
-
|
|
2633
|
-
/**
|
|
2634
|
-
* Helper function to create a {@link Converter | Converter} which validates that a supplied value is
|
|
2635
|
-
* of a type validated by a supplied validator function and returns it.
|
|
2636
|
-
* @remarks
|
|
2637
|
-
* If `validator` succeeds, this {@link Converter | Converter} returns {@link Success | Success} with the supplied
|
|
2638
|
-
* value of `from` coerced to type `<T>`. Returns a {@link Failure | Failure} with additional
|
|
2639
|
-
* information otherwise.
|
|
2640
|
-
* @param validator - A validator function to determine if the converted value is valid.
|
|
2641
|
-
* @param description - A description of the validated type for use in error messages.
|
|
2642
|
-
* @returns A new {@link Converter | Converter<T>} which applies the supplied validation.
|
|
2643
|
-
* @public
|
|
2644
|
-
*/
|
|
2645
|
-
declare function validateWith<T, TC = undefined>(validator: (from: unknown) => from is T, description?: string): Converter<T, TC>;
|
|
2646
|
-
|
|
2647
|
-
declare namespace Validation {
|
|
2648
|
-
export {
|
|
2649
|
-
Base,
|
|
2650
|
-
Classes,
|
|
2651
|
-
Validators,
|
|
2652
|
-
TypeGuardWithContext,
|
|
2653
|
-
FunctionConstraintTrait,
|
|
2654
|
-
ConstraintTrait,
|
|
2655
|
-
ValidatorTraitValues,
|
|
2656
|
-
defaultValidatorTraits,
|
|
2657
|
-
ValidatorTraits,
|
|
2658
|
-
ValidatorOptions,
|
|
2659
|
-
Constraint,
|
|
2660
|
-
Validator
|
|
2750
|
+
declare function validateWith<T, TC = undefined>(validator: (from: unknown) => from is T, description?: string): Converter<T, TC>;
|
|
2751
|
+
|
|
2752
|
+
declare namespace Validation {
|
|
2753
|
+
export {
|
|
2754
|
+
Base,
|
|
2755
|
+
Classes,
|
|
2756
|
+
Validators,
|
|
2757
|
+
TypeGuardWithContext,
|
|
2758
|
+
FunctionConstraintTrait,
|
|
2759
|
+
ConstraintTrait,
|
|
2760
|
+
ValidatorTraitValues,
|
|
2761
|
+
defaultValidatorTraits,
|
|
2762
|
+
ValidatorTraits,
|
|
2763
|
+
ValidatorOptions,
|
|
2764
|
+
Constraint,
|
|
2765
|
+
Validator
|
|
2766
|
+
}
|
|
2661
2767
|
}
|
|
2662
|
-
|
|
2663
|
-
export { Validation }
|
|
2768
|
+
export { Validation }
|
|
2664
2769
|
|
|
2665
|
-
/**
|
|
2666
|
-
* In-place validation that a supplied unknown matches some
|
|
2667
|
-
* required characteristics (type, values, etc).
|
|
2668
|
-
* @public
|
|
2669
|
-
*/
|
|
2670
|
-
export declare interface Validator<T, TC = undefined> {
|
|
2671
|
-
/**
|
|
2672
|
-
* {@link Validation.ValidatorTraits | Traits} describing this validation.
|
|
2673
|
-
*/
|
|
2674
|
-
readonly traits: ValidatorTraits;
|
|
2675
|
-
/**
|
|
2676
|
-
* Indicates whether this element is explicitly optional.
|
|
2677
|
-
*/
|
|
2678
|
-
readonly isOptional: boolean;
|
|
2679
2770
|
/**
|
|
2680
|
-
*
|
|
2771
|
+
* In-place validation that a supplied unknown matches some
|
|
2772
|
+
* required characteristics (type, values, etc).
|
|
2773
|
+
* @public
|
|
2681
2774
|
*/
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
* validate calls are guaranteed to return the entity passed in on Success.
|
|
2686
|
-
* @param from - The `unknown` value to be tested.
|
|
2687
|
-
* @param context - Optional validation context.
|
|
2688
|
-
* @returns {@link Success} with the typed, validated value,
|
|
2689
|
-
* or {@link Failure} with an error message if validation fails.
|
|
2775
|
+
export declare interface Validator<T, TC = undefined> {
|
|
2776
|
+
/**
|
|
2777
|
+
* {@link Validation.ValidatorTraits | Traits} describing this validation.
|
|
2690
2778
|
*/
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
* which is derived from this one but which also matches `undefined`.
|
|
2720
|
-
*/
|
|
2721
|
-
optional(): Validator<T | undefined, TC>;
|
|
2722
|
-
/**
|
|
2723
|
-
* Creates an {@link Validation.Validator | in-place validator}
|
|
2724
|
-
* which is derived from this one but which applies additional constraints.
|
|
2725
|
-
* @param constraint - the constraint to be applied
|
|
2726
|
-
* @param trait - As optional {@link Validation.ConstraintTrait | ConstraintTrait}
|
|
2727
|
-
* to be applied to the resulting {@link Validation.Validator | Validator}.
|
|
2728
|
-
* @returns A new {@link Validation.Validator | Validator}.
|
|
2729
|
-
*/
|
|
2730
|
-
withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC>;
|
|
2731
|
-
/**
|
|
2732
|
-
* Creates a new {@link Validation.Validator | in-place validator} which
|
|
2733
|
-
* is derived from this one but which matches a branded result.
|
|
2734
|
-
* @param brand - The brand to be applied.
|
|
2735
|
-
*/
|
|
2736
|
-
withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC>;
|
|
2737
|
-
}
|
|
2738
|
-
|
|
2739
|
-
/**
|
|
2740
|
-
* Abstract base helper class for specific validator implementations
|
|
2741
|
-
* @internal
|
|
2742
|
-
*/
|
|
2743
|
-
declare abstract class ValidatorBase<T, TC = undefined> extends GenericValidator<T, TC> {
|
|
2744
|
-
/**
|
|
2745
|
-
* Inner constructor
|
|
2746
|
-
* @param params - Initialization params.
|
|
2747
|
-
* @internal
|
|
2748
|
-
*/
|
|
2749
|
-
protected constructor(params: Partial<ValidatorBaseConstructorParams<T, TC>>);
|
|
2779
|
+
readonly traits: ValidatorTraits;
|
|
2780
|
+
/**
|
|
2781
|
+
* Indicates whether this element is explicitly optional.
|
|
2782
|
+
*/
|
|
2783
|
+
readonly isOptional: boolean;
|
|
2784
|
+
/**
|
|
2785
|
+
* The brand for a branded type.
|
|
2786
|
+
*/
|
|
2787
|
+
readonly brand: string | undefined;
|
|
2788
|
+
/**
|
|
2789
|
+
* Tests to see if a supplied `unknown` value matches this validation. All
|
|
2790
|
+
* validate calls are guaranteed to return the entity passed in on Success.
|
|
2791
|
+
* @param from - The `unknown` value to be tested.
|
|
2792
|
+
* @param context - Optional validation context.
|
|
2793
|
+
* @returns {@link Success} with the typed, validated value,
|
|
2794
|
+
* or {@link Failure} with an error message if validation fails.
|
|
2795
|
+
*/
|
|
2796
|
+
validate(from: unknown, context?: TC): Result<T>;
|
|
2797
|
+
/**
|
|
2798
|
+
* Tests to see if a supplied 'unknown' value matches this validation. In
|
|
2799
|
+
* contrast to {@link Validator.validate | validate}, makes no guarantees
|
|
2800
|
+
* about the identity of the returned value.
|
|
2801
|
+
* @param from - The `unknown` value to be tested.
|
|
2802
|
+
* @param context - Optional validation context.
|
|
2803
|
+
* @returns {@link Success} with the typed, conversion value,
|
|
2804
|
+
* or {@link Failure} with an error message if conversion fails.
|
|
2805
|
+
*/
|
|
2806
|
+
convert(from: unknown, context?: TC): Result<T>;
|
|
2750
2807
|
/**
|
|
2751
|
-
*
|
|
2752
|
-
*
|
|
2808
|
+
* Tests to see if a supplied `unknown` value matches this
|
|
2809
|
+
* validation. Accepts `undefined`.
|
|
2810
|
+
* @param from - The `unknown` value to be tested.
|
|
2753
2811
|
* @param context - Optional validation context.
|
|
2754
|
-
* @returns
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
object_2 as object,
|
|
2785
|
-
arrayOf_2 as arrayOf,
|
|
2786
|
-
enumeratedValue_2 as enumeratedValue,
|
|
2787
|
-
literal_2 as literal,
|
|
2788
|
-
oneOf_2 as oneOf,
|
|
2789
|
-
isA_2 as isA,
|
|
2790
|
-
string_2 as string,
|
|
2791
|
-
number_2 as number,
|
|
2792
|
-
boolean_2 as boolean
|
|
2812
|
+
* @returns {@link Success} with the typed, validated value,
|
|
2813
|
+
* or {@link Failure} with an error message if validation fails.
|
|
2814
|
+
*/
|
|
2815
|
+
validateOptional(from: unknown, context?: TC): Result<T | undefined>;
|
|
2816
|
+
/**
|
|
2817
|
+
* Non-throwing type guard
|
|
2818
|
+
* @param from - The value to be tested.
|
|
2819
|
+
* @param context - Optional validation context.
|
|
2820
|
+
*/
|
|
2821
|
+
guard(from: unknown, context?: TC): from is T;
|
|
2822
|
+
/**
|
|
2823
|
+
* Creates an {@link Validation.Validator | in-place validator}
|
|
2824
|
+
* which is derived from this one but which also matches `undefined`.
|
|
2825
|
+
*/
|
|
2826
|
+
optional(): Validator<T | undefined, TC>;
|
|
2827
|
+
/**
|
|
2828
|
+
* Creates an {@link Validation.Validator | in-place validator}
|
|
2829
|
+
* which is derived from this one but which applies additional constraints.
|
|
2830
|
+
* @param constraint - the constraint to be applied
|
|
2831
|
+
* @param trait - As optional {@link Validation.ConstraintTrait | ConstraintTrait}
|
|
2832
|
+
* to be applied to the resulting {@link Validation.Validator | Validator}.
|
|
2833
|
+
* @returns A new {@link Validation.Validator | Validator}.
|
|
2834
|
+
*/
|
|
2835
|
+
withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC>;
|
|
2836
|
+
/**
|
|
2837
|
+
* Creates a new {@link Validation.Validator | in-place validator} which
|
|
2838
|
+
* is derived from this one but which matches a branded result.
|
|
2839
|
+
* @param brand - The brand to be applied.
|
|
2840
|
+
*/
|
|
2841
|
+
withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC>;
|
|
2793
2842
|
}
|
|
2794
|
-
}
|
|
2795
|
-
export { Validators }
|
|
2796
2843
|
|
|
2797
|
-
/**
|
|
2798
|
-
* Generic implementation of {@link Validation.ValidatorTraitValues | ValidatorTraitValues}.
|
|
2799
|
-
* @public
|
|
2800
|
-
*/
|
|
2801
|
-
declare class ValidatorTraits implements ValidatorTraitValues {
|
|
2802
2844
|
/**
|
|
2803
|
-
*
|
|
2845
|
+
* Abstract base helper class for specific validator implementations
|
|
2846
|
+
* @internal
|
|
2804
2847
|
*/
|
|
2805
|
-
|
|
2848
|
+
declare abstract class ValidatorBase<T, TC = undefined> extends GenericValidator<T, TC> {
|
|
2849
|
+
/**
|
|
2850
|
+
* Inner constructor
|
|
2851
|
+
* @param params - Initialization params.
|
|
2852
|
+
* @internal
|
|
2853
|
+
*/
|
|
2854
|
+
protected constructor(params: Partial<ValidatorBaseConstructorParams<T, TC>>);
|
|
2855
|
+
/**
|
|
2856
|
+
* Abstract validation method to me implemented by derived classes.
|
|
2857
|
+
* @param from - Value to be converted.
|
|
2858
|
+
* @param context - Optional validation context.
|
|
2859
|
+
* @returns `true` if `from` is valid, {@link Failure | Failure<T>}
|
|
2860
|
+
* with an error message if `from` is invalid.
|
|
2861
|
+
* @internal
|
|
2862
|
+
*/
|
|
2863
|
+
protected abstract _validate(from: unknown, context?: TC): boolean | Failure<T>;
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2806
2866
|
/**
|
|
2807
|
-
*
|
|
2867
|
+
* @internal
|
|
2808
2868
|
*/
|
|
2809
|
-
|
|
2869
|
+
declare type ValidatorBaseConstructorParams<T, TC> = Omit<GenericValidatorConstructorParams<T, TC>, 'validator'>;
|
|
2870
|
+
|
|
2810
2871
|
/**
|
|
2811
|
-
*
|
|
2872
|
+
* Type for a validation function, which validates that a supplied `unknown`
|
|
2873
|
+
* value is a valid value of type `<T>`, possibly as influenced by
|
|
2874
|
+
* an optionally-supplied validation context of type `<TC>`.
|
|
2875
|
+
* @public
|
|
2812
2876
|
*/
|
|
2813
|
-
|
|
2877
|
+
declare type ValidatorFunc<T, TC> = (from: unknown, context?: TC) => boolean | Failure<T>;
|
|
2878
|
+
|
|
2814
2879
|
/**
|
|
2815
|
-
*
|
|
2816
|
-
*
|
|
2817
|
-
* @remarks
|
|
2818
|
-
* Initial values take priority over base values, which fall back to the global default values.
|
|
2819
|
-
* @param init - Partial initial values to be set in the resulting {@link Validation.Validator | Validator}.
|
|
2820
|
-
* @param base - Base values to be used when no initial values are present.
|
|
2880
|
+
* Options that apply to any {@link Validation.Validator | Validator}.
|
|
2881
|
+
* @public
|
|
2821
2882
|
*/
|
|
2822
|
-
|
|
2823
|
-
|
|
2883
|
+
declare interface ValidatorOptions<TC> {
|
|
2884
|
+
defaultContext?: TC;
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
declare namespace Validators {
|
|
2888
|
+
export {
|
|
2889
|
+
object_2 as object,
|
|
2890
|
+
arrayOf_2 as arrayOf,
|
|
2891
|
+
enumeratedValue_2 as enumeratedValue,
|
|
2892
|
+
literal_2 as literal,
|
|
2893
|
+
oneOf_2 as oneOf,
|
|
2894
|
+
isA_2 as isA,
|
|
2895
|
+
string_2 as string,
|
|
2896
|
+
number_2 as number,
|
|
2897
|
+
boolean_2 as boolean
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2900
|
+
export { Validators }
|
|
2824
2901
|
|
|
2825
|
-
/**
|
|
2826
|
-
* Interface describing the supported validator traits.
|
|
2827
|
-
* @public
|
|
2828
|
-
*/
|
|
2829
|
-
declare interface ValidatorTraitValues {
|
|
2830
2902
|
/**
|
|
2831
|
-
*
|
|
2832
|
-
*
|
|
2903
|
+
* Generic implementation of {@link Validation.ValidatorTraitValues | ValidatorTraitValues}.
|
|
2904
|
+
* @public
|
|
2833
2905
|
*/
|
|
2834
|
-
|
|
2906
|
+
declare class ValidatorTraits implements ValidatorTraitValues {
|
|
2907
|
+
/**
|
|
2908
|
+
* {@inheritdoc Validation.ValidatorTraitValues.isOptional}
|
|
2909
|
+
*/
|
|
2910
|
+
readonly isOptional: boolean;
|
|
2911
|
+
/**
|
|
2912
|
+
* {@inheritdoc Validation.ValidatorTraitValues.brand}
|
|
2913
|
+
*/
|
|
2914
|
+
readonly brand?: string;
|
|
2915
|
+
/**
|
|
2916
|
+
* {@inheritdoc Validation.ValidatorTraitValues.constraints}
|
|
2917
|
+
*/
|
|
2918
|
+
readonly constraints: ConstraintTrait[];
|
|
2919
|
+
/**
|
|
2920
|
+
* Constructs a new {@link Validation.ValidatorTraits | ValidatorTraits} optionally
|
|
2921
|
+
* initialized with the supplied base and initial values.
|
|
2922
|
+
* @remarks
|
|
2923
|
+
* Initial values take priority over base values, which fall back to the global default values.
|
|
2924
|
+
* @param init - Partial initial values to be set in the resulting {@link Validation.Validator | Validator}.
|
|
2925
|
+
* @param base - Base values to be used when no initial values are present.
|
|
2926
|
+
*/
|
|
2927
|
+
constructor(init?: Partial<ValidatorTraitValues>, base?: ValidatorTraitValues);
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2835
2930
|
/**
|
|
2836
|
-
*
|
|
2837
|
-
*
|
|
2931
|
+
* Interface describing the supported validator traits.
|
|
2932
|
+
* @public
|
|
2838
2933
|
*/
|
|
2839
|
-
|
|
2934
|
+
declare interface ValidatorTraitValues {
|
|
2935
|
+
/**
|
|
2936
|
+
* Indicates whether the validator accepts `undefined` as
|
|
2937
|
+
* a valid value.
|
|
2938
|
+
*/
|
|
2939
|
+
readonly isOptional: boolean;
|
|
2940
|
+
/**
|
|
2941
|
+
* If present, indicates that the result will be branded
|
|
2942
|
+
* with the corresponding brand.
|
|
2943
|
+
*/
|
|
2944
|
+
readonly brand?: string;
|
|
2945
|
+
/**
|
|
2946
|
+
* Zero or more additional {@link Validation.ConstraintTrait | ConstraintTrait}s
|
|
2947
|
+
* describing additional constraints applied by this {@link Validation.Validator | Validator}.
|
|
2948
|
+
*/
|
|
2949
|
+
readonly constraints: ConstraintTrait[];
|
|
2950
|
+
}
|
|
2951
|
+
|
|
2840
2952
|
/**
|
|
2841
|
-
*
|
|
2842
|
-
*
|
|
2953
|
+
* Deprecated alias for @see literal
|
|
2954
|
+
* @param value - The value to be compared.
|
|
2955
|
+
* @deprecated Use {@link Converters.literal} instead.
|
|
2956
|
+
* @internal
|
|
2843
2957
|
*/
|
|
2844
|
-
|
|
2845
|
-
}
|
|
2846
|
-
|
|
2847
|
-
/**
|
|
2848
|
-
* Deprecated alias for @see literal
|
|
2849
|
-
* @param value - The value to be compared.
|
|
2850
|
-
* @deprecated Use {@link Converters.literal} instead.
|
|
2851
|
-
* @internal
|
|
2852
|
-
*/
|
|
2853
|
-
declare const value: typeof literal;
|
|
2958
|
+
declare const value: typeof literal;
|
|
2854
2959
|
|
|
2855
|
-
|
|
2960
|
+
export { }
|