@fgv/ts-utils 3.0.1-alpha.3 → 3.0.1-alpha.5

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