@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
@@ -30,6 +30,7 @@ export interface IReadOnlyCollector<TITEM extends ICollectible<any, any>> extend
30
30
  * @public
31
31
  */
32
32
  export interface ICollectorConstructorParams<TITEM extends ICollectible<any, any>> {
33
+ /** Optional initial items to populate the collector. */
33
34
  items?: TITEM[];
34
35
  }
35
36
  /**
@@ -45,7 +46,7 @@ export declare class Collector<TITEM extends ICollectible<any, any>> implements
45
46
  private readonly _byKey;
46
47
  private readonly _byIndex;
47
48
  /**
48
- * {@inheritdoc Collections.ResultMap.size}
49
+ * {@inheritDoc Collections.ResultMap.size}
49
50
  */
50
51
  get size(): number;
51
52
  /**
@@ -72,19 +73,19 @@ export declare class Collector<TITEM extends ICollectible<any, any>> implements
72
73
  */
73
74
  add(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
74
75
  /**
75
- * {@inheritdoc Collections.ResultMap.entries}
76
+ * {@inheritDoc Collections.ResultMap.entries}
76
77
  */
77
78
  entries(): IterableIterator<KeyValueEntry<CollectibleKey<TITEM>, TITEM>>;
78
79
  /**
79
- * {@inheritdoc Collections.ResultMap.forEach}
80
+ * {@inheritDoc Collections.ResultMap.forEach}
80
81
  */
81
82
  forEach(callback: ResultMapForEachCb<CollectibleKey<TITEM>, TITEM>, arg?: unknown): void;
82
83
  /**
83
- * {@inheritdoc Collections.ResultMap.get}
84
+ * {@inheritDoc Collections.ResultMap.get}
84
85
  */
85
86
  get(key: CollectibleKey<TITEM>): DetailedResult<TITEM, ResultMapResultDetail>;
86
87
  /**
87
- * {@inheritdoc Collections.IReadOnlyCollector.getAt}
88
+ * {@inheritDoc Collections.IReadOnlyCollector.getAt}
88
89
  */
89
90
  getAt(index: number): Result<TITEM>;
90
91
  /**
@@ -101,7 +102,7 @@ export declare class Collector<TITEM extends ICollectible<any, any>> implements
101
102
  * Gets an existing item with a key matching the supplied key, or adds a new item to the collector
102
103
  * using a factory callback if no item with that key exists.
103
104
  * @param key - The key of the item to add.
104
- * @param callback - The factory callback to create the item.
105
+ * @param factory - The factory callback to create the item.
105
106
  * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -
106
107
  * detail `exists` indicates that an existing item return and detail `added` indicates that the
107
108
  * item was added. Returns {@link DetailedFailure | Failure} with an error and appropriate
@@ -109,19 +110,19 @@ export declare class Collector<TITEM extends ICollectible<any, any>> implements
109
110
  */
110
111
  getOrAdd(key: CollectibleKey<TITEM>, factory: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
111
112
  /**
112
- * {@inheritdoc Collections.ResultMap.has}
113
+ * {@inheritDoc Collections.ResultMap.has}
113
114
  */
114
115
  has(key: CollectibleKey<TITEM>): boolean;
115
116
  /**
116
- * {@inheritdoc Collections.ResultMap.keys}
117
+ * {@inheritDoc Collections.ResultMap.keys}
117
118
  */
118
119
  keys(): IterableIterator<CollectibleKey<TITEM>>;
119
120
  /**
120
- * {@inheritdoc Collections.ResultMap.values}
121
+ * {@inheritDoc Collections.ResultMap.values}
121
122
  */
122
123
  values(): IterableIterator<TITEM>;
123
124
  /**
124
- * {@inheritdoc Collections.IReadOnlyCollector.valuesByIndex}
125
+ * {@inheritDoc Collections.IReadOnlyCollector.valuesByIndex}
125
126
  */
126
127
  valuesByIndex(): ReadonlyArray<TITEM>;
127
128
  /**
@@ -34,7 +34,7 @@ const base_1 = require("../base");
34
34
  */
35
35
  class Collector {
36
36
  /**
37
- * {@inheritdoc Collections.ResultMap.size}
37
+ * {@inheritDoc Collections.ResultMap.size}
38
38
  */
39
39
  get size() {
40
40
  return this._byIndex.length;
@@ -90,13 +90,13 @@ class Collector {
90
90
  return (0, base_1.succeedWithDetail)(item, 'added');
91
91
  }
92
92
  /**
93
- * {@inheritdoc Collections.ResultMap.entries}
93
+ * {@inheritDoc Collections.ResultMap.entries}
94
94
  */
95
95
  entries() {
96
96
  return this._byKey.entries();
97
97
  }
98
98
  /**
99
- * {@inheritdoc Collections.ResultMap.forEach}
99
+ * {@inheritDoc Collections.ResultMap.forEach}
100
100
  */
101
101
  forEach(callback, arg) {
102
102
  for (const [key, value] of this._byKey.entries()) {
@@ -104,14 +104,14 @@ class Collector {
104
104
  }
105
105
  }
106
106
  /**
107
- * {@inheritdoc Collections.ResultMap.get}
107
+ * {@inheritDoc Collections.ResultMap.get}
108
108
  */
109
109
  get(key) {
110
110
  const item = this._byKey.get(key);
111
111
  return item ? (0, base_1.succeedWithDetail)(item, 'exists') : (0, base_1.failWithDetail)(`${key}: not found`, 'not-found');
112
112
  }
113
113
  /**
114
- * {@inheritdoc Collections.IReadOnlyCollector.getAt}
114
+ * {@inheritDoc Collections.IReadOnlyCollector.getAt}
115
115
  */
116
116
  getAt(index) {
117
117
  if (typeof index !== 'number') {
@@ -149,25 +149,25 @@ class Collector {
149
149
  });
150
150
  }
151
151
  /**
152
- * {@inheritdoc Collections.ResultMap.has}
152
+ * {@inheritDoc Collections.ResultMap.has}
153
153
  */
154
154
  has(key) {
155
155
  return this._byKey.has(key);
156
156
  }
157
157
  /**
158
- * {@inheritdoc Collections.ResultMap.keys}
158
+ * {@inheritDoc Collections.ResultMap.keys}
159
159
  */
160
160
  keys() {
161
161
  return this._byKey.keys();
162
162
  }
163
163
  /**
164
- * {@inheritdoc Collections.ResultMap.values}
164
+ * {@inheritDoc Collections.ResultMap.values}
165
165
  */
166
166
  values() {
167
167
  return this._byKey.values();
168
168
  }
169
169
  /**
170
- * {@inheritdoc Collections.IReadOnlyCollector.valuesByIndex}
170
+ * {@inheritDoc Collections.IReadOnlyCollector.valuesByIndex}
171
171
  */
172
172
  valuesByIndex() {
173
173
  return this._byIndex;
@@ -12,19 +12,19 @@ import { CollectibleKey, ICollectible } from './collectible';
12
12
  */
13
13
  export interface IReadOnlyCollectorValidator<TITEM extends ICollectible<any, any>> extends IReadOnlyResultMapValidator<CollectibleKey<TITEM>, TITEM> {
14
14
  /**
15
- * {@inheritdoc Collections.ConvertingCollectorValidator.map}
15
+ * {@inheritDoc Collections.ReadOnlyResultMapValidator.map}
16
16
  */
17
17
  readonly map: IReadOnlyResultMap<CollectibleKey<TITEM>, TITEM>;
18
18
  /**
19
- * {@inheritdoc Collections.Collector.get}
19
+ * {@inheritDoc Collections.Collector.get}
20
20
  */
21
21
  get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
22
22
  /**
23
- * {@inheritdoc Collections.ResultMap.has}
23
+ * {@inheritDoc Collections.ResultMap.has}
24
24
  */
25
25
  has(key: string): boolean;
26
26
  /**
27
- * {@inheritdoc Collections.Collector.(getOrAdd:2)}
27
+ * {@inheritDoc Collections.Collector.getOrAdd}
28
28
  */
29
29
  getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
30
30
  }
@@ -33,7 +33,9 @@ export interface IReadOnlyCollectorValidator<TITEM extends ICollectible<any, any
33
33
  * @public
34
34
  */
35
35
  export interface ICollectorValidatorCreateParams<TITEM extends ICollectible<any, any>> {
36
+ /** The collector to validate access to. */
36
37
  readonly collector: Collector<TITEM>;
38
+ /** The key-value converters for validation. */
37
39
  readonly converters: KeyValueConverters<CollectibleKey<TITEM>, TITEM>;
38
40
  }
39
41
  /**
@@ -51,28 +53,28 @@ export declare class CollectorValidator<TITEM extends ICollectible<any, any>> im
51
53
  */
52
54
  constructor(params: ICollectorValidatorCreateParams<TITEM>);
53
55
  /**
54
- * {@inheritdoc Collections.Collector.add}
56
+ * {@inheritDoc Collections.Collector.add}
55
57
  */
56
58
  add(item: unknown): DetailedResult<TITEM, CollectorResultDetail>;
57
59
  /**
58
- * {@inheritdoc Collections.Collector.get}
60
+ * {@inheritDoc Collections.Collector.get}
59
61
  */
60
62
  get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
61
63
  /**
62
- * {@inheritdoc Collections.Collector.(getOrAdd:2)}
64
+ * {@inheritDoc Collections.Collector.getOrAdd}
63
65
  */
64
66
  getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
65
67
  /**
66
- * {@inheritdoc Collections.Collector.(getOrAdd:1)}
68
+ * {@inheritDoc Collections.Collector.getOrAdd}
67
69
  * @param item - The item to add to the collector.
68
70
  */
69
71
  getOrAdd(item: unknown): DetailedResult<TITEM, CollectorResultDetail>;
70
72
  /**
71
- * {@inheritdoc Collections.ResultMap.has}
73
+ * {@inheritDoc Collections.ResultMap.has}
72
74
  */
73
75
  has(key: string): boolean;
74
76
  /**
75
- * {@inheritdoc Collections.Collector.toReadOnly}
77
+ * {@inheritDoc Collections.Collector.toReadOnly}
76
78
  */
77
79
  toReadOnly(): IReadOnlyCollectorValidator<TITEM>;
78
80
  /**
@@ -40,7 +40,7 @@ class CollectorValidator {
40
40
  this.converters = params.converters;
41
41
  }
42
42
  /**
43
- * {@inheritdoc Collections.Collector.add}
43
+ * {@inheritDoc Collections.Collector.add}
44
44
  */
45
45
  add(item) {
46
46
  return this._convertValue(item).onSuccess((i) => {
@@ -48,7 +48,7 @@ class CollectorValidator {
48
48
  });
49
49
  }
50
50
  /**
51
- * {@inheritdoc Collections.Collector.get}
51
+ * {@inheritDoc Collections.Collector.get}
52
52
  */
53
53
  get(key) {
54
54
  return this.converters.convertKey(key).onSuccess((k) => {
@@ -67,13 +67,13 @@ class CollectorValidator {
67
67
  }
68
68
  }
69
69
  /**
70
- * {@inheritdoc Collections.ResultMap.has}
70
+ * {@inheritDoc Collections.ResultMap.has}
71
71
  */
72
72
  has(key) {
73
73
  return this._collector.has(key);
74
74
  }
75
75
  /**
76
- * {@inheritdoc Collections.Collector.toReadOnly}
76
+ * {@inheritDoc Collections.Collector.toReadOnly}
77
77
  */
78
78
  toReadOnly() {
79
79
  return this;
@@ -0,0 +1,18 @@
1
+ import { Converter } from '../conversion';
2
+ import { KeyValueEntry } from './common';
3
+ /**
4
+ * Initialization parameters for the {@link Collections.Converters.keyValueEntry | keyValueEntry} converter.
5
+ * @public
6
+ */
7
+ export interface IKeyValueEntryConverterParams<TK extends string, TV> {
8
+ key: Converter<TK, unknown>;
9
+ value: Converter<TV, unknown>;
10
+ }
11
+ /**
12
+ * A {@link Converter | Converter} for {@link Collections.KeyValueEntry | KeyValueEntry} instances.
13
+ * @param params - Conversion parameters.
14
+ * @returns A converter for which validates key value entries using the supplied validators.
15
+ * @public
16
+ */
17
+ export declare function keyValueEntry<TK extends string, TV>(params: IKeyValueEntryConverterParams<TK, TV>): Converter<KeyValueEntry<TK, TV>, unknown>;
18
+ //# sourceMappingURL=converters.d.ts.map
@@ -0,0 +1,42 @@
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.keyValueEntry = keyValueEntry;
25
+ const base_1 = require("../base");
26
+ const conversion_1 = require("../conversion");
27
+ /**
28
+ * A {@link Converter | Converter} for {@link Collections.KeyValueEntry | KeyValueEntry} instances.
29
+ * @param params - Conversion parameters.
30
+ * @returns A converter for which validates key value entries using the supplied validators.
31
+ * @public
32
+ */
33
+ function keyValueEntry(params) {
34
+ return conversion_1.Converters.generic((from) => {
35
+ return params.key.convert(from).onSuccess((key) => {
36
+ return params.value.convert(from).onSuccess((value) => {
37
+ return base_1.Success.with([key, value]);
38
+ });
39
+ });
40
+ });
41
+ }
42
+ //# sourceMappingURL=converters.js.map
@@ -37,7 +37,7 @@ export declare class ConvertingCollector<TITEM extends ICollectible<any, any>, T
37
37
  */
38
38
  static createConvertingCollector<TITEM extends ICollectible<any, any>, TSRC = TITEM>(params: IConvertingCollectorConstructorParams<TITEM, TSRC>): Result<ConvertingCollector<TITEM, TSRC>>;
39
39
  /**
40
- * {@inheritdoc Collections.Collector.add}
40
+ * {@inheritDoc Collections.Collector.add}
41
41
  */
42
42
  add(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
43
43
  /**
@@ -54,17 +54,17 @@ export declare class ConvertingCollector<TITEM extends ICollectible<any, any>, T
54
54
  * Adds an item to the collector using a supplied {@link Collections.CollectibleFactoryCallback | factory callback}
55
55
  * at a specified key, failing if an item with that key already exists or if the created item is invalid.
56
56
  * @param key - The key of the item to add.
57
- * @param callback - The factory callback to create the item.
57
+ * @param cb - The factory callback to create the item.
58
58
  * @returns Returns {@link Success | Success} with the item if it is added, or {@link Failure | Failure} with
59
59
  * an error if the item cannot be created and indexed.
60
60
  */
61
61
  add(key: CollectibleKey<TITEM>, cb: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
62
62
  /**
63
- * {@inheritdoc Collections.Collector.(getOrAdd:1)}
63
+ * {@inheritDoc Collections.Collector.getOrAdd}
64
64
  */
65
65
  getOrAdd(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;
66
66
  /**
67
- * {@inheritdoc Collections.Collector.(getOrAdd:2)}
67
+ * {@inheritDoc Collections.Collector.getOrAdd}
68
68
  */
69
69
  getOrAdd(key: CollectibleKey<TITEM>, callback: CollectibleFactoryCallback<TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
70
70
  /**
@@ -11,7 +11,9 @@ import { IReadOnlyCollectorValidator } from './collectorValidator';
11
11
  * @public
12
12
  */
13
13
  export interface IConvertingCollectorValidatorCreateParams<TITEM extends ICollectible<any, any>, TSRC = TITEM> {
14
+ /** The converting collector to validate access to. */
14
15
  collector: ConvertingCollector<TITEM, TSRC>;
16
+ /** The key-value converters for validation. */
15
17
  converters: KeyValueConverters<CollectibleKey<TITEM>, TSRC>;
16
18
  }
17
19
  /**
@@ -30,31 +32,32 @@ export declare class ConvertingCollectorValidator<TITEM extends ICollectible<any
30
32
  */
31
33
  constructor(params: IConvertingCollectorValidatorCreateParams<TITEM, TSRC>);
32
34
  /**
33
- * {@inheritdoc Collections.ConvertingCollector.(add:1)}
35
+ * {@inheritDoc Collections.ConvertingCollector.add}
34
36
  */
35
37
  add(key: string, value: unknown): DetailedResult<TITEM, CollectorResultDetail>;
36
38
  /**
37
- * {@inheritdoc Collections.ConvertingCollector.(add:2)}
39
+ * Adds an item to the collector using a supplied factory callback
40
+ * at a specified key, validating the key first.
38
41
  */
39
42
  add(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
40
43
  /**
41
- * {@inheritdoc Collections.Collector.get}
44
+ * {@inheritDoc Collections.Collector.get}
42
45
  */
43
46
  get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;
44
47
  /**
45
- * {@inheritdoc Collections.ConvertingCollector.(getOrAdd:3)}
48
+ * {@inheritDoc Collections.ConvertingCollector.getOrAdd}
46
49
  */
47
50
  getOrAdd(key: string, value: unknown): DetailedResult<TITEM, CollectorResultDetail>;
48
51
  /**
49
- * {@inheritdoc Collections.Collector.(getOrAdd:2)}
52
+ * {@inheritDoc Collections.Collector.getOrAdd}
50
53
  */
51
54
  getOrAdd(key: string, factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>): DetailedResult<TITEM, CollectorResultDetail>;
52
55
  /**
53
- * {@inheritdoc Collections.ResultMap.has}
56
+ * {@inheritDoc Collections.ResultMap.has}
54
57
  */
55
58
  has(key: string): boolean;
56
59
  /**
57
- * {@inheritdoc Collections.Collector.toReadOnly}
60
+ * {@inheritDoc Collections.Collector.toReadOnly}
58
61
  */
59
62
  toReadOnly(): IReadOnlyCollectorValidator<TITEM>;
60
63
  /**
@@ -48,7 +48,7 @@ class ConvertingCollectorValidator {
48
48
  return this.getOrAdd(key, valueOrFactory);
49
49
  }
50
50
  /**
51
- * {@inheritdoc Collections.Collector.get}
51
+ * {@inheritDoc Collections.Collector.get}
52
52
  */
53
53
  get(key) {
54
54
  return this.converters.convertKey(key).onSuccess((k) => {
@@ -73,13 +73,13 @@ class ConvertingCollectorValidator {
73
73
  }
74
74
  }
75
75
  /**
76
- * {@inheritdoc Collections.ResultMap.has}
76
+ * {@inheritDoc Collections.ResultMap.has}
77
77
  */
78
78
  has(key) {
79
79
  return this._collector.has(key);
80
80
  }
81
81
  /**
82
- * {@inheritdoc Collections.Collector.toReadOnly}
82
+ * {@inheritDoc Collections.Collector.toReadOnly}
83
83
  */
84
84
  toReadOnly() {
85
85
  return this;
@@ -0,0 +1,176 @@
1
+ import { DetailedResult, Result } from '../base';
2
+ import { KeyValueEntry } from './common';
3
+ import { IReadOnlyResultMap, ResultMapForEachCb, ResultMapResultDetail } from './readonlyResultMap';
4
+ import { ReadOnlyConvertingResultMap, ConvertingResultMapValueConverter } from './readOnlyConvertingResultMap';
5
+ import { IResultMap, ResultMapValueFactory } from './resultMap';
6
+ /**
7
+ * Parameters for constructing a {@link Collections.ConvertingResultMap | ConvertingResultMap}.
8
+ * @public
9
+ */
10
+ export interface IConvertingResultMapConstructorParams<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>> {
11
+ /**
12
+ * The inner map containing source values.
13
+ */
14
+ inner: TSRCMAP;
15
+ /**
16
+ * The converter function to transform source values to target values.
17
+ */
18
+ converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;
19
+ }
20
+ /**
21
+ * A wrapper around a mutable result map that invalidates cache entries
22
+ * in the parent {@link Collections.ConvertingResultMap | ConvertingResultMap} when mutations occur.
23
+ * @public
24
+ */
25
+ export declare class CacheInvalidatingResultMapWrapper<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>> implements IResultMap<TK, TSRC> {
26
+ private readonly _inner;
27
+ private readonly _parent;
28
+ /**
29
+ * Constructs a new cache-invalidating wrapper.
30
+ * @param inner - The inner map to wrap.
31
+ * @param parent - The parent converting map whose cache should be invalidated.
32
+ */
33
+ constructor(inner: TSRCMAP, parent: ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>);
34
+ /**
35
+ * The number of entries in the map.
36
+ */
37
+ get size(): number;
38
+ /**
39
+ * Adds a key/value pair to the map if the key does not already exist.
40
+ * Invalidates the cache entry for the key.
41
+ * @param key - The key to add.
42
+ * @param value - The value to add.
43
+ * @returns The result of the add operation.
44
+ */
45
+ add(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail>;
46
+ /**
47
+ * Sets a key/value pair in the map.
48
+ * Invalidates the cache entry for the key.
49
+ * @param key - The key to set.
50
+ * @param value - The value to set.
51
+ * @returns The result of the set operation.
52
+ */
53
+ set(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail>;
54
+ /**
55
+ * Updates an existing key in the map.
56
+ * Invalidates the cache entry for the key.
57
+ * @param key - The key to update.
58
+ * @param value - The new value.
59
+ * @returns The result of the update operation.
60
+ */
61
+ update(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail>;
62
+ /**
63
+ * Deletes a key from the map.
64
+ * Invalidates the cache entry for the key.
65
+ * @param key - The key to delete.
66
+ * @returns The result of the delete operation.
67
+ */
68
+ delete(key: TK): DetailedResult<TSRC, ResultMapResultDetail>;
69
+ /**
70
+ * Gets a value from the map.
71
+ * @param key - The key to retrieve.
72
+ * @returns The result of the get operation.
73
+ */
74
+ get(key: TK): DetailedResult<TSRC, ResultMapResultDetail>;
75
+ /**
76
+ * Gets a value from the map, or adds a supplied value if it does not exist.
77
+ * Invalidates the cache entry for the key if a new value is added.
78
+ * @param key - The key to retrieve or add.
79
+ * @param value - The value to add if the key does not exist.
80
+ * @returns The result of the operation.
81
+ */
82
+ getOrAdd(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail>;
83
+ /**
84
+ * Gets a value from the map, or adds a value created by a factory if it does not exist.
85
+ * Invalidates the cache entry for the key if a new value is added.
86
+ * @param key - The key to retrieve or add.
87
+ * @param factory - A factory function to create the value if the key does not exist.
88
+ * @returns The result of the operation.
89
+ */
90
+ getOrAdd(key: TK, factory: ResultMapValueFactory<TK, TSRC>): DetailedResult<TSRC, ResultMapResultDetail>;
91
+ /**
92
+ * Checks if the map contains a key.
93
+ * @param key - The key to check.
94
+ * @returns `true` if the key exists, `false` otherwise.
95
+ */
96
+ has(key: TK): boolean;
97
+ /**
98
+ * Clears all entries from the map.
99
+ * Clears the entire cache.
100
+ */
101
+ clear(): void;
102
+ /**
103
+ * Returns an iterator over the map entries.
104
+ * @returns An iterator over the map entries.
105
+ */
106
+ entries(): IterableIterator<KeyValueEntry<TK, TSRC>>;
107
+ /**
108
+ * Returns an iterator over the map keys.
109
+ * @returns An iterator over the map keys.
110
+ */
111
+ keys(): IterableIterator<TK>;
112
+ /**
113
+ * Returns an iterator over the map values.
114
+ * @returns An iterator over the map values.
115
+ */
116
+ values(): IterableIterator<TSRC>;
117
+ /**
118
+ * Calls a callback for each entry in the map.
119
+ * @param cb - The callback to call for each entry.
120
+ * @param thisArg - Optional `this` argument for the callback.
121
+ */
122
+ forEach(cb: ResultMapForEachCb<TK, TSRC>, thisArg?: unknown): void;
123
+ /**
124
+ * Gets an iterator over the map entries.
125
+ * @returns An iterator over the map entries.
126
+ */
127
+ [Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TSRC>>;
128
+ /**
129
+ * Gets a read-only version of this map.
130
+ * @returns A read-only version of this map.
131
+ */
132
+ toReadOnly(): IReadOnlyResultMap<TK, TSRC>;
133
+ }
134
+ /**
135
+ * A result map that wraps an inner {@link Collections.IResultMap | IResultMap} of source type
136
+ * and returns lazily-converted, cached values of a target type. Exposes the inner map
137
+ * via a {@link Collections.CacheInvalidatingResultMapWrapper | source} property that
138
+ * invalidates cache entries when mutations occur.
139
+ * @public
140
+ */
141
+ export declare class ConvertingResultMap<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>> extends ReadOnlyConvertingResultMap<TK, TSRC, TTARGET> {
142
+ /**
143
+ * A wrapper around the inner map that invalidates cache entries when mutations occur.
144
+ * Use this property to add, update, or delete source values.
145
+ */
146
+ readonly source: CacheInvalidatingResultMapWrapper<TK, TSRC, TTARGET, TSRCMAP>;
147
+ /**
148
+ * The inner map, typed as the specific source map type.
149
+ */
150
+ protected readonly _typedInner: TSRCMAP;
151
+ /**
152
+ * Constructs a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.
153
+ * @param params - Parameters for constructing the map.
154
+ */
155
+ constructor(params: IConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>);
156
+ /**
157
+ * Creates a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.
158
+ * @param params - Parameters for constructing the map.
159
+ * @returns `Success` with the new map, or `Failure` with error details if an error occurred.
160
+ */
161
+ static create<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>>(params: IConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>): Result<ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>>;
162
+ /**
163
+ * Clears a single entry from the cache.
164
+ * This method is public to allow the cache-invalidating wrapper to call it.
165
+ * @param key - The key to clear from the cache.
166
+ * @internal
167
+ */
168
+ _clearCacheEntry(key: TK): void;
169
+ /**
170
+ * Clears all entries from the cache.
171
+ * This method is public to allow the cache-invalidating wrapper to call it.
172
+ * @internal
173
+ */
174
+ _clearCache(): void;
175
+ }
176
+ //# sourceMappingURL=convertingResultMap.d.ts.map