@fgv/ts-utils 5.0.2 → 5.1.0-0

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.
Files changed (104) hide show
  1. package/README.md +152 -84
  2. package/dist/index.js +2 -2
  3. package/dist/packlets/base/messageAggregator.js +6 -6
  4. package/dist/packlets/base/result.js +39 -39
  5. package/dist/packlets/base/utils.js +47 -0
  6. package/dist/packlets/collections/aggregatedResultMap.js +722 -0
  7. package/dist/packlets/collections/collector.js +9 -9
  8. package/dist/packlets/collections/collectorValidator.js +4 -4
  9. package/dist/packlets/collections/converters.js +39 -0
  10. package/dist/packlets/collections/convertingCollectorValidator.js +3 -3
  11. package/dist/packlets/collections/convertingResultMap.js +208 -0
  12. package/dist/packlets/collections/index.js +4 -0
  13. package/dist/packlets/collections/keyValueConverters.js +1 -4
  14. package/dist/packlets/collections/readOnlyConvertingResultMap.js +193 -0
  15. package/dist/packlets/collections/resultMapValidator.js +50 -6
  16. package/dist/packlets/collections/validatingConvertingResultMap.js +78 -0
  17. package/dist/packlets/conversion/advancedConverters.js +249 -0
  18. package/dist/packlets/conversion/baseConverter.js +23 -16
  19. package/dist/packlets/conversion/basicConverters.js +571 -0
  20. package/dist/packlets/conversion/converters.js +3 -617
  21. package/dist/packlets/conversion/defaultingConverter.js +21 -15
  22. package/dist/packlets/logging/bootLogger.js +122 -0
  23. package/dist/packlets/logging/index.js +1 -0
  24. package/dist/packlets/logging/logReporter.js +32 -1
  25. package/dist/packlets/logging/logger.js +25 -5
  26. package/dist/packlets/validation/classes.js +1 -0
  27. package/dist/packlets/validation/compositeId.js +60 -0
  28. package/dist/packlets/validation/field.js +1 -1
  29. package/dist/packlets/validation/genericValidator.js +24 -10
  30. package/dist/packlets/validation/object.js +3 -6
  31. package/dist/packlets/validation/validators.js +12 -0
  32. package/dist/ts-utils.d.ts +1633 -200
  33. package/dist/tsdoc-metadata.json +1 -1
  34. package/lib/index.d.ts +2 -2
  35. package/lib/index.js +2 -1
  36. package/lib/packlets/base/mapResults.d.ts +3 -3
  37. package/lib/packlets/base/messageAggregator.d.ts +6 -6
  38. package/lib/packlets/base/messageAggregator.js +6 -6
  39. package/lib/packlets/base/result.d.ts +74 -51
  40. package/lib/packlets/base/result.js +39 -39
  41. package/lib/packlets/base/utils.d.ts +42 -0
  42. package/lib/packlets/base/utils.js +52 -0
  43. package/lib/packlets/collections/aggregatedResultMap.d.ts +433 -0
  44. package/lib/packlets/collections/aggregatedResultMap.js +728 -0
  45. package/lib/packlets/collections/collector.d.ts +11 -10
  46. package/lib/packlets/collections/collector.js +9 -9
  47. package/lib/packlets/collections/collectorValidator.d.ts +12 -10
  48. package/lib/packlets/collections/collectorValidator.js +4 -4
  49. package/lib/packlets/collections/converters.d.ts +18 -0
  50. package/lib/packlets/collections/converters.js +42 -0
  51. package/lib/packlets/collections/convertingCollector.d.ts +4 -4
  52. package/lib/packlets/collections/convertingCollectorValidator.d.ts +10 -7
  53. package/lib/packlets/collections/convertingCollectorValidator.js +3 -3
  54. package/lib/packlets/collections/convertingResultMap.d.ts +176 -0
  55. package/lib/packlets/collections/convertingResultMap.js +213 -0
  56. package/lib/packlets/collections/index.d.ts +4 -0
  57. package/lib/packlets/collections/index.js +4 -0
  58. package/lib/packlets/collections/keyValueConverters.d.ts +1 -4
  59. package/lib/packlets/collections/keyValueConverters.js +1 -4
  60. package/lib/packlets/collections/readOnlyConvertingResultMap.d.ts +153 -0
  61. package/lib/packlets/collections/readOnlyConvertingResultMap.js +197 -0
  62. package/lib/packlets/collections/readonlyResultMap.d.ts +7 -7
  63. package/lib/packlets/collections/resultMap.d.ts +108 -2
  64. package/lib/packlets/collections/resultMapValidator.d.ts +45 -11
  65. package/lib/packlets/collections/resultMapValidator.js +52 -7
  66. package/lib/packlets/collections/validatingCollector.d.ts +5 -5
  67. package/lib/packlets/collections/validatingConvertingCollector.d.ts +3 -3
  68. package/lib/packlets/collections/validatingConvertingResultMap.d.ts +102 -0
  69. package/lib/packlets/collections/validatingConvertingResultMap.js +83 -0
  70. package/lib/packlets/collections/validatingResultMap.d.ts +1 -1
  71. package/lib/packlets/conversion/advancedConverters.d.ts +170 -0
  72. package/lib/packlets/conversion/advancedConverters.js +258 -0
  73. package/lib/packlets/conversion/baseConverter.d.ts +39 -23
  74. package/lib/packlets/conversion/baseConverter.js +23 -16
  75. package/lib/packlets/conversion/basicConverters.d.ts +470 -0
  76. package/lib/packlets/conversion/basicConverters.js +595 -0
  77. package/lib/packlets/conversion/converter.d.ts +7 -0
  78. package/lib/packlets/conversion/converters.d.ts +2 -535
  79. package/lib/packlets/conversion/converters.js +17 -639
  80. package/lib/packlets/conversion/defaultingConverter.d.ts +20 -16
  81. package/lib/packlets/conversion/defaultingConverter.js +21 -15
  82. package/lib/packlets/logging/bootLogger.d.ts +84 -0
  83. package/lib/packlets/logging/bootLogger.js +126 -0
  84. package/lib/packlets/logging/index.d.ts +1 -0
  85. package/lib/packlets/logging/index.js +1 -0
  86. package/lib/packlets/logging/logReporter.d.ts +18 -3
  87. package/lib/packlets/logging/logReporter.js +31 -0
  88. package/lib/packlets/logging/logger.d.ts +39 -6
  89. package/lib/packlets/logging/logger.js +26 -5
  90. package/lib/packlets/validation/classes.d.ts +1 -0
  91. package/lib/packlets/validation/classes.js +3 -1
  92. package/lib/packlets/validation/compositeId.d.ts +29 -0
  93. package/lib/packlets/validation/compositeId.js +64 -0
  94. package/lib/packlets/validation/field.d.ts +1 -1
  95. package/lib/packlets/validation/field.js +1 -1
  96. package/lib/packlets/validation/genericValidator.d.ts +15 -11
  97. package/lib/packlets/validation/genericValidator.js +24 -10
  98. package/lib/packlets/validation/object.d.ts +3 -6
  99. package/lib/packlets/validation/object.js +3 -6
  100. package/lib/packlets/validation/traits.d.ts +3 -3
  101. package/lib/packlets/validation/validator.d.ts +7 -0
  102. package/lib/packlets/validation/validators.d.ts +10 -0
  103. package/lib/packlets/validation/validators.js +13 -0
  104. package/package.json +14 -14
@@ -21,12 +21,14 @@
21
21
  * SOFTWARE.
22
22
  */
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.TypeGuardValidator = exports.StringValidator = exports.OneOfValidator = exports.ObjectValidator = exports.NumberValidator = exports.BooleanValidator = exports.ArrayValidator = void 0;
24
+ exports.TypeGuardValidator = exports.StringValidator = exports.OneOfValidator = exports.ObjectValidator = exports.NumberValidator = exports.CompositeIdValidator = exports.BooleanValidator = exports.ArrayValidator = void 0;
25
25
  /* c8 ignore start */
26
26
  var array_1 = require("./array");
27
27
  Object.defineProperty(exports, "ArrayValidator", { enumerable: true, get: function () { return array_1.ArrayValidator; } });
28
28
  var boolean_1 = require("./boolean");
29
29
  Object.defineProperty(exports, "BooleanValidator", { enumerable: true, get: function () { return boolean_1.BooleanValidator; } });
30
+ var compositeId_1 = require("./compositeId");
31
+ Object.defineProperty(exports, "CompositeIdValidator", { enumerable: true, get: function () { return compositeId_1.CompositeIdValidator; } });
30
32
  var number_1 = require("./number");
31
33
  Object.defineProperty(exports, "NumberValidator", { enumerable: true, get: function () { return number_1.NumberValidator; } });
32
34
  var object_1 = require("./object");
@@ -0,0 +1,29 @@
1
+ import { Failure } from '../base';
2
+ import { Validator } from './validator';
3
+ import { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';
4
+ /**
5
+ * Parameters used to construct a {@link Validation.Classes.StringValidator | StringValidator}.
6
+ * @public
7
+ */
8
+ export interface CompositeIdValidatorConstructorParams<T extends string = string, TCOLLECTIONID extends string = string, TITEMID extends string = string, TC = unknown> extends ValidatorBaseConstructorParams<T, TC> {
9
+ readonly collectionId: Validator<TCOLLECTIONID, TC>;
10
+ readonly separator: string;
11
+ readonly itemId: Validator<TITEMID, TC>;
12
+ }
13
+ /**
14
+ * An in-place {@link Validation.Validator | Validator} for a strongly-typed composite ID.
15
+ * @public
16
+ */
17
+ export declare class CompositeIdValidator<T extends string = string, TCOLLECTIONID extends string = string, TITEMID extends string = string, TC = unknown> extends ValidatorBase<T, TC> {
18
+ protected readonly _collectionIdValidator: Validator<TCOLLECTIONID, TC>;
19
+ protected readonly _itemIdValidator: Validator<TITEMID, TC>;
20
+ protected readonly _separator: string;
21
+ /**
22
+ * Constructs a new {@link Validation.Classes.StringValidator | StringValidator}.
23
+ * @param params - Optional {@link Validation.Classes.StringValidatorConstructorParams | init params}
24
+ * for the new {@link Validation.Classes.StringValidator | StringValidator}.
25
+ */
26
+ constructor(params: CompositeIdValidatorConstructorParams<T, TCOLLECTIONID, TITEMID, TC>);
27
+ protected _validate(value: unknown, context?: TC): boolean | Failure<T>;
28
+ }
29
+ //# sourceMappingURL=compositeId.d.ts.map
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.CompositeIdValidator = void 0;
25
+ const base_1 = require("../base");
26
+ const validatorBase_1 = require("./validatorBase");
27
+ /**
28
+ * An in-place {@link Validation.Validator | Validator} for a strongly-typed composite ID.
29
+ * @public
30
+ */
31
+ class CompositeIdValidator extends validatorBase_1.ValidatorBase {
32
+ /**
33
+ * Constructs a new {@link Validation.Classes.StringValidator | StringValidator}.
34
+ * @param params - Optional {@link Validation.Classes.StringValidatorConstructorParams | init params}
35
+ * for the new {@link Validation.Classes.StringValidator | StringValidator}.
36
+ */
37
+ constructor(params) {
38
+ /* c8 ignore next */
39
+ super(Object.assign({}, params));
40
+ const { collectionId, separator, itemId } = params;
41
+ this._collectionIdValidator = collectionId.withFormattedError((value, err) => `${value}: invalid composite collection ID (${err}).`);
42
+ this._itemIdValidator = itemId.withFormattedError((value, err) => `${value}: invalid composite item ID (${err}).`);
43
+ this._separator = separator;
44
+ }
45
+ _validate(value, context) {
46
+ if (typeof value !== 'string') {
47
+ return (0, base_1.fail)(`${value}: invalid non-string composite ID.`);
48
+ }
49
+ const parts = value.split(this._separator);
50
+ if (parts.length < 2) {
51
+ return (0, base_1.fail)(`${value}: invalid composite ID - separator '${this._separator}' not found.`);
52
+ }
53
+ else if (parts.length > 2) {
54
+ return (0, base_1.fail)(`${value}: invalid composite ID - multiple separators '${this._separator}.' found.`);
55
+ }
56
+ const [collectionId, itemId] = parts;
57
+ const result = this._collectionIdValidator
58
+ .validate(collectionId, context)
59
+ .onSuccess(() => this._itemIdValidator.validate(itemId, context));
60
+ return result.isSuccess() ? true : base_1.Failure.with(`${value}: invalid composite ID - ${result.message}`);
61
+ }
62
+ }
63
+ exports.CompositeIdValidator = CompositeIdValidator;
64
+ //# sourceMappingURL=compositeId.js.map
@@ -36,7 +36,7 @@ export declare class FieldValidator<T, TC = unknown> extends ValidatorBase<T, TC
36
36
  */
37
37
  constructor(fieldName: string, fieldValidator: Validator<T, TC>, options?: FieldValidatorOptions<TC>);
38
38
  /**
39
- * {@inheritdoc Validation.ValidatorBase._validate}
39
+ * {@inheritDoc Validation.ValidatorBase._validate}
40
40
  */
41
41
  protected _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T>;
42
42
  }
@@ -46,7 +46,7 @@ class FieldValidator extends validatorBase_1.ValidatorBase {
46
46
  this._fieldOptions = options !== null && options !== void 0 ? options : {};
47
47
  }
48
48
  /**
49
- * {@inheritdoc Validation.ValidatorBase._validate}
49
+ * {@inheritDoc Validation.ValidatorBase._validate}
50
50
  */
51
51
  _validate(from, context, self) {
52
52
  if (typeof from === 'object' && !Array.isArray(from) && from !== null) {
@@ -16,7 +16,7 @@ export interface GenericValidatorConstructorParams<T, TC> {
16
16
  */
17
17
  export declare class GenericValidator<T, TC = unknown> implements Validator<T, TC> {
18
18
  /**
19
- * {@inheritdoc Validation.Validator.traits}
19
+ * {@inheritDoc Validation.Validator.traits}
20
20
  */
21
21
  readonly traits: ValidatorTraits;
22
22
  /**
@@ -34,45 +34,49 @@ export declare class GenericValidator<T, TC = unknown> implements Validator<T, T
34
34
  */
35
35
  constructor(params: Partial<GenericValidatorConstructorParams<T, TC>>);
36
36
  /**
37
- * {@inheritdoc Validation.Validator.isOptional}
37
+ * {@inheritDoc Validation.Validator.isOptional}
38
38
  */
39
39
  get isOptional(): boolean;
40
40
  /**
41
- * {@inheritdoc Validation.Validator.brand}
41
+ * {@inheritDoc Validation.Validator.brand}
42
42
  */
43
43
  get brand(): string | undefined;
44
44
  /**
45
- * {@inheritdoc Validation.Validator.validate}
45
+ * {@inheritDoc Validation.Validator.validate}
46
46
  */
47
47
  validate(from: unknown, context?: TC): Result<T>;
48
48
  /**
49
- * {@inheritdoc Validation.Validator.convert}
49
+ * {@inheritDoc Validation.Validator.convert}
50
50
  */
51
51
  convert(from: unknown, context?: TC): Result<T>;
52
52
  /**
53
- * {@inheritdoc Validation.Validator.validateOptional}
53
+ * {@inheritDoc Validation.Validator.validateOptional}
54
54
  */
55
55
  validateOptional(from: unknown, context?: TC): Result<T | undefined>;
56
56
  /**
57
- * {@inheritdoc Validation.Validator.guard}
57
+ * {@inheritDoc Validation.Validator.guard}
58
58
  */
59
59
  guard(from: unknown, context?: TC): from is T;
60
60
  /**
61
- * {@inheritdoc Validation.Validator.optional}
61
+ * {@inheritDoc Validation.Validator.optional}
62
62
  */
63
63
  optional(): Validator<T | undefined, TC>;
64
64
  /**
65
- * {@inheritdoc Validation.Validator.withConstraint}
65
+ * {@inheritDoc Validation.Validator.withConstraint}
66
66
  */
67
67
  withConstraint(constraint: Constraint<T>, trait?: ConstraintTrait): Validator<T, TC>;
68
68
  /**
69
- * {@inheritdoc Validation.Validator.brand}
69
+ * {@inheritDoc Validation.Validator.brand}
70
70
  */
71
71
  withBrand<B extends string>(brand: B): Validator<Brand<T, B>, TC>;
72
72
  /**
73
- * {@inheritdoc Validation.Validator.withFormattedError}
73
+ * {@inheritDoc Validation.Validator.withFormattedError}
74
74
  */
75
75
  withFormattedError(formatter: ValidationErrorFormatter<TC>): Validator<T, TC>;
76
+ /**
77
+ * {@inheritDoc Validation.Validator.or}
78
+ */
79
+ or(other: Validator<T, TC>): Validator<T, TC>;
76
80
  /**
77
81
  * Gets a default or explicit context.
78
82
  * @param explicitContext - Optional explicit context.
@@ -44,19 +44,19 @@ class GenericValidator {
44
44
  this.traits = new traits_1.ValidatorTraits(params.traits);
45
45
  }
46
46
  /**
47
- * {@inheritdoc Validation.Validator.isOptional}
47
+ * {@inheritDoc Validation.Validator.isOptional}
48
48
  */
49
49
  get isOptional() {
50
50
  return this.traits.isOptional;
51
51
  }
52
52
  /**
53
- * {@inheritdoc Validation.Validator.brand}
53
+ * {@inheritDoc Validation.Validator.brand}
54
54
  */
55
55
  get brand() {
56
56
  return this.traits.brand;
57
57
  }
58
58
  /**
59
- * {@inheritdoc Validation.Validator.validate}
59
+ * {@inheritDoc Validation.Validator.validate}
60
60
  */
61
61
  validate(from, context) {
62
62
  const result = this._validator(from, this._context(context), this);
@@ -66,7 +66,7 @@ class GenericValidator {
66
66
  return result;
67
67
  }
68
68
  /**
69
- * {@inheritdoc Validation.Validator.convert}
69
+ * {@inheritDoc Validation.Validator.convert}
70
70
  */
71
71
  convert(from, context) {
72
72
  const result = this._validator(from, this._context(context), this);
@@ -76,19 +76,19 @@ class GenericValidator {
76
76
  return result;
77
77
  }
78
78
  /**
79
- * {@inheritdoc Validation.Validator.validateOptional}
79
+ * {@inheritDoc Validation.Validator.validateOptional}
80
80
  */
81
81
  validateOptional(from, context) {
82
82
  return from === undefined ? (0, base_1.succeed)(undefined) : this.validate(from, context);
83
83
  }
84
84
  /**
85
- * {@inheritdoc Validation.Validator.guard}
85
+ * {@inheritDoc Validation.Validator.guard}
86
86
  */
87
87
  guard(from, context) {
88
88
  return this._validator(from, this._context(context), this) === true;
89
89
  }
90
90
  /**
91
- * {@inheritdoc Validation.Validator.optional}
91
+ * {@inheritDoc Validation.Validator.optional}
92
92
  */
93
93
  optional() {
94
94
  return new GenericValidator({
@@ -99,7 +99,7 @@ class GenericValidator {
99
99
  });
100
100
  }
101
101
  /**
102
- * {@inheritdoc Validation.Validator.withConstraint}
102
+ * {@inheritDoc Validation.Validator.withConstraint}
103
103
  */
104
104
  withConstraint(constraint, trait) {
105
105
  trait = trait !== null && trait !== void 0 ? trait : { type: 'function' };
@@ -121,7 +121,7 @@ class GenericValidator {
121
121
  });
122
122
  }
123
123
  /**
124
- * {@inheritdoc Validation.Validator.brand}
124
+ * {@inheritDoc Validation.Validator.brand}
125
125
  */
126
126
  withBrand(brand) {
127
127
  if (this.brand) {
@@ -135,7 +135,7 @@ class GenericValidator {
135
135
  });
136
136
  }
137
137
  /**
138
- * {@inheritdoc Validation.Validator.withFormattedError}
138
+ * {@inheritDoc Validation.Validator.withFormattedError}
139
139
  */
140
140
  withFormattedError(formatter) {
141
141
  return new GenericValidator({
@@ -150,6 +150,20 @@ class GenericValidator {
150
150
  }
151
151
  });
152
152
  }
153
+ /**
154
+ * {@inheritDoc Validation.Validator.or}
155
+ */
156
+ or(other) {
157
+ return new GenericValidator({
158
+ validator: (from, context, __self) => {
159
+ if (this._validator(from, this._context(context), this) === true) {
160
+ return true;
161
+ }
162
+ const otherResult = other.validate(from, this._context(context));
163
+ return otherResult.isSuccess() ? true : otherResult;
164
+ }
165
+ });
166
+ }
153
167
  /**
154
168
  * Gets a default or explicit context.
155
169
  * @param explicitContext - Optional explicit context.
@@ -69,10 +69,7 @@ export declare class ObjectValidator<T, TC = unknown> extends ValidatorBase<T, T
69
69
  protected readonly _allowedFields?: Set<keyof T>;
70
70
  /**
71
71
  * Constructs a new {@link Validation.Classes.ObjectValidator | ObjectValidator<T>}.
72
- * @param fields - A {@link Validation.Classes.FieldValidators | FieldValidators<T>} containing
73
- * a {@link Validation.Validator | Validator} for each field.
74
- * @param options - An optional {@link Validation.Classes.ObjectValidatorOptions} to configure
75
- * validation.
72
+ * @param params - Construction parameters including field validators and options.
76
73
  */
77
74
  constructor(params: ObjectValidatorConstructorParams<T, TC>);
78
75
  /**
@@ -101,13 +98,13 @@ export declare class ObjectValidator<T, TC = unknown> extends ValidatorBase<T, T
101
98
  /**
102
99
  * Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with
103
100
  * new optional properties as specified by a supplied array of `keyof T`.
104
- * @param addOptionalProperties - The keys to be made optional.
101
+ * @param addOptionalFields - The keys to be made optional.
105
102
  * @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional
106
103
  * source properties.
107
104
  */
108
105
  addPartial(addOptionalFields: (keyof T)[]): ObjectValidator<Partial<T>, TC>;
109
106
  /**
110
- * {@inheritdoc Validation.ValidatorBase._validate}
107
+ * {@inheritDoc Validation.ValidatorBase._validate}
111
108
  * @internal
112
109
  */
113
110
  protected _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T>;
@@ -36,10 +36,7 @@ const field_1 = require("./field");
36
36
  class ObjectValidator extends validatorBase_1.ValidatorBase {
37
37
  /**
38
38
  * Constructs a new {@link Validation.Classes.ObjectValidator | ObjectValidator<T>}.
39
- * @param fields - A {@link Validation.Classes.FieldValidators | FieldValidators<T>} containing
40
- * a {@link Validation.Validator | Validator} for each field.
41
- * @param options - An optional {@link Validation.Classes.ObjectValidatorOptions} to configure
42
- * validation.
39
+ * @param params - Construction parameters including field validators and options.
43
40
  */
44
41
  constructor(params) {
45
42
  var _a;
@@ -95,7 +92,7 @@ class ObjectValidator extends validatorBase_1.ValidatorBase {
95
92
  /**
96
93
  * Creates a new {@link Validation.Classes.ObjectValidator | ObjectValidator} derived from this one but with
97
94
  * new optional properties as specified by a supplied array of `keyof T`.
98
- * @param addOptionalProperties - The keys to be made optional.
95
+ * @param addOptionalFields - The keys to be made optional.
99
96
  * @returns A new {@link Validation.Classes.ObjectValidator | ObjectValidator} with the additional optional
100
97
  * source properties.
101
98
  */
@@ -106,7 +103,7 @@ class ObjectValidator extends validatorBase_1.ValidatorBase {
106
103
  });
107
104
  }
108
105
  /**
109
- * {@inheritdoc Validation.ValidatorBase._validate}
106
+ * {@inheritDoc Validation.ValidatorBase._validate}
110
107
  * @internal
111
108
  */
112
109
  _validate(from, context, self) {
@@ -44,15 +44,15 @@ export declare const defaultValidatorTraits: ValidatorTraitValues;
44
44
  */
45
45
  export declare class ValidatorTraits implements ValidatorTraitValues {
46
46
  /**
47
- * {@inheritdoc Validation.ValidatorTraitValues.isOptional}
47
+ * {@inheritDoc Validation.ValidatorTraitValues.isOptional}
48
48
  */
49
49
  readonly isOptional: boolean;
50
50
  /**
51
- * {@inheritdoc Validation.ValidatorTraitValues.brand}
51
+ * {@inheritDoc Validation.ValidatorTraitValues.brand}
52
52
  */
53
53
  readonly brand?: string;
54
54
  /**
55
- * {@inheritdoc Validation.ValidatorTraitValues.constraints}
55
+ * {@inheritDoc Validation.ValidatorTraitValues.constraints}
56
56
  */
57
57
  readonly constraints: ConstraintTrait[];
58
58
  /**
@@ -111,5 +111,12 @@ export interface Validator<T, TC = unknown> {
111
111
  * @returns A new {@link Validation.Validator | Validator}.
112
112
  */
113
113
  withFormattedError(formatter: ValidationErrorFormatter<TC>): Validator<T, TC>;
114
+ /**
115
+ * Chains this validator with another of the same type, to be attempted if this
116
+ * validator fails.
117
+ * @param other - The other {@link Validation.Validator | Validator} to be attempted
118
+ * if this one fails.
119
+ */
120
+ or(other: Validator<T, TC>): Validator<T, TC>;
114
121
  }
115
122
  //# sourceMappingURL=validator.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { ArrayValidator, ArrayValidatorConstructorParams } from './array';
2
+ import { CompositeIdValidator, CompositeIdValidatorConstructorParams } from './compositeId';
2
3
  import { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams } from './object';
3
4
  import { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';
4
5
  import { TypeGuardWithContext } from './common';
@@ -82,6 +83,15 @@ export declare function enumeratedValue<T extends string>(values: ReadonlyArray<
82
83
  * @public
83
84
  */
84
85
  export declare function literal<T extends string | number | boolean | symbol | null | undefined>(value: T): Validator<T>;
86
+ /** Helper function to create a {@link Validation.Validator | Validator} which validates a
87
+ * strongly-typed composite ID.
88
+ * @param params - {@link Validation.Classes.CompositeIdValidatorConstructorParams | params}
89
+ * used to construct the validator.
90
+ * @returns A new {@link Validation.Validator | Validator} which validates the desired
91
+ * composite ID in place.
92
+ * @public
93
+ */
94
+ export declare function compositeId<T extends string = string, TCOLLECTIONID extends string = string, TITEMID extends string = string, TC = unknown>(params: CompositeIdValidatorConstructorParams<T, TCOLLECTIONID, TITEMID, TC>): CompositeIdValidator<T, TCOLLECTIONID, TITEMID, TC>;
85
95
  /**
86
96
  * Helper function to create a {@link Validation.Validator | Validator} which validates one
87
97
  * of several possible validated values.
@@ -27,11 +27,13 @@ exports.arrayOf = arrayOf;
27
27
  exports.recordOf = recordOf;
28
28
  exports.enumeratedValue = enumeratedValue;
29
29
  exports.literal = literal;
30
+ exports.compositeId = compositeId;
30
31
  exports.oneOf = oneOf;
31
32
  exports.isA = isA;
32
33
  exports.generic = generic;
33
34
  const base_1 = require("../base");
34
35
  const array_1 = require("./array");
36
+ const compositeId_1 = require("./compositeId");
35
37
  const object_1 = require("./object");
36
38
  const typeGuard_1 = require("./typeGuard");
37
39
  const boolean_1 = require("./boolean");
@@ -163,6 +165,17 @@ function literal(value) {
163
165
  }
164
166
  });
165
167
  }
168
+ /** Helper function to create a {@link Validation.Validator | Validator} which validates a
169
+ * strongly-typed composite ID.
170
+ * @param params - {@link Validation.Classes.CompositeIdValidatorConstructorParams | params}
171
+ * used to construct the validator.
172
+ * @returns A new {@link Validation.Validator | Validator} which validates the desired
173
+ * composite ID in place.
174
+ * @public
175
+ */
176
+ function compositeId(params) {
177
+ return new compositeId_1.CompositeIdValidator(params);
178
+ }
166
179
  /**
167
180
  * Helper function to create a {@link Validation.Validator | Validator} which validates one
168
181
  * of several possible validated values.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-utils",
3
- "version": "5.0.2",
3
+ "version": "5.1.0-0",
4
4
  "description": "Assorted Typescript Utilities",
5
5
  "main": "lib/index.js",
6
6
  "module": "dist/index.js",
@@ -26,33 +26,33 @@
26
26
  "homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#readme",
27
27
  "devDependencies": {
28
28
  "@jest/expect-utils": "^29.7.0",
29
- "@microsoft/api-documenter": "^7.27.3",
30
- "@microsoft/api-extractor": "^7.53.3",
29
+ "@microsoft/api-documenter": "^7.28.2",
30
+ "@microsoft/api-extractor": "^7.55.2",
31
31
  "@types/jest": "^29.5.14",
32
32
  "@types/luxon": "^3.7.1",
33
33
  "@types/mustache": "^4.2.5",
34
34
  "@types/node": "^20.14.9",
35
- "@typescript-eslint/eslint-plugin": "^8.46.2",
36
- "@typescript-eslint/parser": "^8.46.2",
37
- "eslint": "^9.39.0",
35
+ "@typescript-eslint/eslint-plugin": "^8.52.0",
36
+ "@typescript-eslint/parser": "^8.52.0",
37
+ "eslint": "^9.39.2",
38
38
  "eslint-plugin-import": "^2.32.0",
39
39
  "eslint-plugin-node": "^11.1.0",
40
40
  "eslint-plugin-promise": "^7.2.1",
41
41
  "jest": "^29.7.0",
42
42
  "jest-extended": "^4.0.2",
43
43
  "jest-matcher-utils": "^29.7.0",
44
- "rimraf": "^6.1.0",
45
- "ts-jest": "^29.4.5",
44
+ "rimraf": "^6.1.2",
45
+ "ts-jest": "^29.4.6",
46
46
  "ts-node": "^10.9.2",
47
47
  "typescript": "5.9.3",
48
48
  "eslint-plugin-n": "^17.23.1",
49
49
  "jest-snapshot": "~29.7.0",
50
- "@rushstack/heft": "1.1.3",
51
- "@rushstack/heft-node-rig": "2.11.4",
52
- "@rushstack/eslint-config": "4.5.3",
50
+ "@rushstack/heft": "1.2.6",
51
+ "@rushstack/heft-node-rig": "2.11.26",
52
+ "@rushstack/eslint-config": "4.6.4",
53
53
  "@types/heft-jest": "1.0.6",
54
- "@rushstack/heft-jest-plugin": "1.1.3",
55
- "eslint-plugin-tsdoc": "~0.4.0",
54
+ "@rushstack/heft-jest-plugin": "1.2.6",
55
+ "eslint-plugin-tsdoc": "~0.5.2",
56
56
  "@fgv/heft-dual-rig": "0.1.0"
57
57
  },
58
58
  "repository": {
@@ -63,7 +63,7 @@
63
63
  "build": "heft build --clean",
64
64
  "clean": "heft clean",
65
65
  "test": "heft test --clean",
66
- "build-docs": "api-documenter markdown --input-folder ./temp --output-folder docs",
66
+ "build-docs": "typedoc --options ./config/typedoc.json",
67
67
  "build-all": "rushx build; rushx build-docs",
68
68
  "test-handles": "jest --runInBand --detectOpenHandles",
69
69
  "clean-jest": "jest --clear-cache",