@fgv/ts-utils 3.0.1-alpha.4 → 3.0.1-alpha.6

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