@fgv/ts-utils 4.3.0 → 4.4.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 (36) hide show
  1. package/CHANGELOG.json +6 -0
  2. package/CHANGELOG.md +6 -1
  3. package/dist/ts-utils.d.ts +175 -70
  4. package/lib/index.d.ts +2 -2
  5. package/lib/index.d.ts.map +1 -1
  6. package/lib/index.js +2 -1
  7. package/lib/index.js.map +1 -1
  8. package/lib/packlets/collections/collectible.d.ts +37 -5
  9. package/lib/packlets/collections/collectible.d.ts.map +1 -1
  10. package/lib/packlets/collections/collectible.js +42 -8
  11. package/lib/packlets/collections/collectible.js.map +1 -1
  12. package/lib/packlets/collections/collector.d.ts +77 -13
  13. package/lib/packlets/collections/collector.d.ts.map +1 -1
  14. package/lib/packlets/collections/collector.js +44 -2
  15. package/lib/packlets/collections/collector.js.map +1 -1
  16. package/lib/packlets/collections/collectorConverter.d.ts +31 -4
  17. package/lib/packlets/collections/collectorConverter.d.ts.map +1 -1
  18. package/lib/packlets/collections/collectorConverter.js +18 -6
  19. package/lib/packlets/collections/collectorConverter.js.map +1 -1
  20. package/lib/packlets/collections/collectors.d.ts +0 -1
  21. package/lib/packlets/collections/collectors.d.ts.map +1 -1
  22. package/lib/packlets/collections/collectors.js +1 -4
  23. package/lib/packlets/collections/collectors.js.map +1 -1
  24. package/lib/packlets/collections/convertingCollector.d.ts +19 -13
  25. package/lib/packlets/collections/convertingCollector.d.ts.map +1 -1
  26. package/lib/packlets/collections/convertingCollector.js +0 -10
  27. package/lib/packlets/collections/convertingCollector.js.map +1 -1
  28. package/lib/packlets/collections/convertingResultMap.d.ts +4 -24
  29. package/lib/packlets/collections/convertingResultMap.d.ts.map +1 -1
  30. package/lib/packlets/collections/convertingResultMap.js +0 -41
  31. package/lib/packlets/collections/convertingResultMap.js.map +1 -1
  32. package/lib/packlets/collections/keyValueConverters.d.ts +1 -17
  33. package/lib/packlets/collections/keyValueConverters.d.ts.map +1 -1
  34. package/lib/packlets/collections/keyValueConverters.js +1 -8
  35. package/lib/packlets/collections/keyValueConverters.js.map +1 -1
  36. package/package.json +1 -1
@@ -38,7 +38,7 @@ class SimpleCollector extends collector_1.Collector {
38
38
  constructor(params) {
39
39
  var _a;
40
40
  const entries = (_a = params === null || params === void 0 ? void 0 : params.items) === null || _a === void 0 ? void 0 : _a.map((item) => [item.key, item]);
41
- super({ factory: SimpleCollector._factory, entries });
41
+ super({ factory: collector_1.Collector._simpleFactory, entries });
42
42
  }
43
43
  /**
44
44
  * Creates a new {@link SimpleCollector | simple collector}.
@@ -49,9 +49,6 @@ class SimpleCollector extends collector_1.Collector {
49
49
  static createSimpleCollector(params) {
50
50
  return (0, base_1.captureResult)(() => new SimpleCollector(params));
51
51
  }
52
- static _factory(key, index, item) {
53
- return item.setIndex(index).onSuccess(() => (0, base_1.succeed)(item));
54
- }
55
52
  }
56
53
  exports.SimpleCollector = SimpleCollector;
57
54
  //# sourceMappingURL=collectors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"collectors.js","sourceRoot":"","sources":["../../../src/packlets/collections/collectors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAyD;AAEzD,2CAAwC;AAUxC;;;;;GAKG;AACH,MAAa,eAA4D,SAAQ,qBAKhF;IACC;;;OAGG;IACH,YAAmB,MAA4C;;QAC7D,MAAM,OAAO,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,0CAAE,GAAG,CAAC,CAAC,IAAI,EAAmB,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;QAChF,KAAK,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IACxD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,qBAAqB,CACjC,MAA4C;QAE5C,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1D,CAAC;IAEO,MAAM,CAAC,QAAQ,CACrB,GAAW,EACX,KAAa,EACb,IAAW;QAEX,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC;IAC7D,CAAC;CACF;AAlCD,0CAkCC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult, succeed } from '../base';\nimport { ICollectible } from './collectible';\nimport { Collector } from './collector';\n\n/**\n * Parameters for creating a {@link SimpleCollector | simple collector}.\n * @public\n */\nexport interface ISimpleCollectorCreateParams<TITEM extends ICollectible<string, number>> {\n items?: TITEM[];\n}\n\n/**\n * A simple {@link Collector | collector} that collects {@link Collections.ICollectible | ICollectible items}\n * with non-branded `string` key and `number` index, and with no transformation other than index assignment\n * on addition.\n * @public\n */\nexport class SimpleCollector<TITEM extends ICollectible<string, number>> extends Collector<\n string,\n number,\n TITEM,\n TITEM\n> {\n /**\n * Constructs a new {@link SimpleCollector | simple collector}.\n * @param params - {@link Collections.ISimpleCollectorCreateParams | Creation parameters} for the collector.\n */\n public constructor(params?: ISimpleCollectorCreateParams<TITEM>) {\n const entries = params?.items?.map((item): [string, TITEM] => [item.key, item]);\n super({ factory: SimpleCollector._factory, entries });\n }\n\n /**\n * Creates a new {@link SimpleCollector | simple collector}.\n * @param params - {@link Collections.ISimpleCollectorCreateParams | Creation parameters} for the collector.\n * @returns {@link Success | Success} if the collector is created successfully, or {@link Failure | Failure} if not.\n * @public\n */\n public static createSimpleCollector<TITEM extends ICollectible<string, number>>(\n params?: ISimpleCollectorCreateParams<TITEM>\n ): Result<SimpleCollector<TITEM>> {\n return captureResult(() => new SimpleCollector(params));\n }\n\n private static _factory<TITEM extends ICollectible<string, number>>(\n key: string,\n index: number,\n item: TITEM\n ): Result<TITEM> {\n return item.setIndex(index).onSuccess(() => succeed(item));\n }\n}\n"]}
1
+ {"version":3,"file":"collectors.js","sourceRoot":"","sources":["../../../src/packlets/collections/collectors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAgD;AAEhD,2CAAwC;AAUxC;;;;;GAKG;AACH,MAAa,eAA4D,SAAQ,qBAKhF;IACC;;;OAGG;IACH,YAAmB,MAA4C;;QAC7D,MAAM,OAAO,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,0CAAE,GAAG,CAAC,CAAC,IAAI,EAAmB,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;QAChF,KAAK,CAAC,EAAE,OAAO,EAAE,qBAAS,CAAC,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC;IACxD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,qBAAqB,CACjC,MAA4C;QAE5C,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1D,CAAC;CACF;AA1BD,0CA0BC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult } from '../base';\nimport { ICollectible } from './collectible';\nimport { Collector } from './collector';\n\n/**\n * Parameters for creating a {@link SimpleCollector | simple collector}.\n * @public\n */\nexport interface ISimpleCollectorCreateParams<TITEM extends ICollectible<string, number>> {\n items?: TITEM[];\n}\n\n/**\n * A simple {@link Collector | collector} that collects {@link Collections.ICollectible | ICollectible items}\n * with non-branded `string` key and `number` index, and with no transformation other than index assignment\n * on addition.\n * @public\n */\nexport class SimpleCollector<TITEM extends ICollectible<string, number>> extends Collector<\n string,\n number,\n TITEM,\n TITEM\n> {\n /**\n * Constructs a new {@link SimpleCollector | simple collector}.\n * @param params - {@link Collections.ISimpleCollectorCreateParams | Creation parameters} for the collector.\n */\n public constructor(params?: ISimpleCollectorCreateParams<TITEM>) {\n const entries = params?.items?.map((item): [string, TITEM] => [item.key, item]);\n super({ factory: Collector._simpleFactory, entries });\n }\n\n /**\n * Creates a new {@link SimpleCollector | simple collector}.\n * @param params - {@link Collections.ISimpleCollectorCreateParams | Creation parameters} for the collector.\n * @returns {@link Success | Success} if the collector is created successfully, or {@link Failure | Failure} if not.\n * @public\n */\n public static createSimpleCollector<TITEM extends ICollectible<string, number>>(\n params?: ISimpleCollectorCreateParams<TITEM>\n ): Result<SimpleCollector<TITEM>> {\n return captureResult(() => new SimpleCollector(params));\n }\n}\n"]}
@@ -1,11 +1,25 @@
1
- import { DetailedResult, Result } from '../base';
2
- import { CollectibleFactory, CollectibleFactoryCallback, ICollectible } from './collectible';
1
+ import { Result } from '../base';
2
+ import { CollectibleFactory, ICollectible } from './collectible';
3
3
  import { Collector } from './collector';
4
- import { CollectorConverter } from './collectorConverter';
4
+ import { CollectorConverter, IReadOnlyCollectorConverter } from './collectorConverter';
5
5
  import { KeyValueEntry } from './common';
6
6
  import { IReadOnlyConvertingResultMap } from './convertingResultMap';
7
7
  import { KeyValueConverters } from './keyValueConverters';
8
- import { ResultMapResultDetail } from './readonlyResultMap';
8
+ /**
9
+ * A read-only interface exposing non-mutating methods of a
10
+ * {@link Collections.ConvertingCollector | ConvertingCollector}.
11
+ * @public
12
+ */
13
+ export interface IReadOnlyConvertingCollector<TKEY extends string = string, TINDEX extends number = number, TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>> extends IReadOnlyConvertingResultMap<TKEY, TITEM> {
14
+ /**
15
+ * {@inheritdoc Collections.ConvertingCollector.converting}
16
+ */
17
+ readonly converting: IReadOnlyCollectorConverter<TKEY, TINDEX, TITEM>;
18
+ /**
19
+ * {@inheritdoc Collections.Collector.getAt}
20
+ */
21
+ readonly getAt: (index: number) => Result<TITEM>;
22
+ }
9
23
  /**
10
24
  * Parameters for constructing a {@link Collections.ConvertingCollector | ConvertingCollector}.
11
25
  * @public
@@ -49,19 +63,11 @@ export declare class ConvertingCollector<TKEY extends string = string, TINDEX ex
49
63
  * @returns {@link Success} with the new collector if successful, {@link Failure} otherwise.
50
64
  */
51
65
  static createConvertingCollector<TKEY extends string = string, TINDEX extends number = number, TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>, TSRC = TITEM>(params: IConvertingCollectorConstructorParams<TKEY, TINDEX, TITEM, TSRC>): Result<ConvertingCollector<TKEY, TINDEX, TITEM, TSRC>>;
52
- /**
53
- * {@inheritdoc Collections.Collector.(getOrAdd:1)}
54
- */
55
- getOrAdd(key: TKEY, item: TSRC): DetailedResult<TITEM, ResultMapResultDetail>;
56
- /**
57
- * {@inheritdoc Collections.Collector.(getOrAdd:2)}
58
- */
59
- getOrAdd(key: TKEY, cb: CollectibleFactoryCallback<TKEY, TINDEX, TITEM>): DetailedResult<TITEM, ResultMapResultDetail>;
60
66
  /**
61
67
  * Gets a read-only version of this collector as a
62
68
  * {@link Collections.IReadOnlyConvertingResultMap | read-only map}.
63
69
  * @returns
64
70
  */
65
- toReadOnly(): IReadOnlyConvertingResultMap<TKEY, TITEM>;
71
+ toReadOnly(): IReadOnlyConvertingCollector<TKEY, TINDEX, TITEM>;
66
72
  }
67
73
  //# sourceMappingURL=convertingCollector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"convertingCollector.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/convertingCollector.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAiB,cAAc,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,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AI,GAAG,KAAK,CACZ,SAAQ,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC;IAC5C;;;OAGG;IACH,SAAgB,UAAU,EAAE,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAE1E,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAE/D;;;;OAIG;gBACgB,MAAM,EAAE,qCAAqC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC;IAS3F;;;;;OAKG;WACW,yBAAyB,CACrC,IAAI,SAAS,MAAM,GAAG,MAAM,EAC5B,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,KAAK,SAAS,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,EACrE,IAAI,GAAG,KAAK,EAEZ,MAAM,EAAE,qCAAqC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,GACvE,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAIzD;;;;OAIG;IACI,UAAU,IAAI,4BAA4B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC;CAGvE"}
@@ -54,16 +54,6 @@ class ConvertingCollector extends collector_1.Collector {
54
54
  static createConvertingCollector(params) {
55
55
  return (0, base_1.captureResult)(() => new ConvertingCollector(params));
56
56
  }
57
- getOrAdd(key, itemOrCb) {
58
- if (this._isFactoryCB(itemOrCb)) {
59
- return this.converting.converters.convertKey(key).onSuccess((k) => {
60
- return super.getOrAdd(k, itemOrCb);
61
- });
62
- }
63
- return this.converting.converters.convertEntry([key, itemOrCb]).onSuccess(([k, v]) => {
64
- return super.getOrAdd(k, v);
65
- });
66
- }
67
57
  /**
68
58
  * Gets a read-only version of this collector as a
69
59
  * {@link Collections.IReadOnlyConvertingResultMap | read-only map}.
@@ -1 +1 @@
1
- {"version":3,"file":"convertingCollector.js","sourceRoot":"","sources":["../../../src/packlets/collections/convertingCollector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAgE;AAEhE,2CAAwC;AACxC,6DAA0D;AAgC1D;;;;GAIG;AACH,MAAa,mBAKX,SAAQ,qBAAoC;IAS5C;;;;OAIG;IACH,YAAmB,MAAwE;;QACzF,KAAK,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,IAAI,uCAAkB,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAC7F,KAAK,MAAM,KAAK,IAAI,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,EAAE,CAAC;YACzC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,yBAAyB,CAMrC,MAAwE;QAExE,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IAcM,QAAQ,CACb,GAAS,EACT,QAAgE;QAEhE,IAAI,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;gBAChE,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;YACrC,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE;YACnF,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA/ED,kDA+EC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, DetailedResult, Result } from '../base';\nimport { CollectibleFactory, CollectibleFactoryCallback, ICollectible } from './collectible';\nimport { Collector } from './collector';\nimport { CollectorConverter } from './collectorConverter';\nimport { KeyValueEntry } from './common';\nimport { IReadOnlyConvertingResultMap } from './convertingResultMap';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { ResultMapResultDetail } from './readonlyResultMap';\n\n/**\n * Parameters for constructing a {@link Collections.ConvertingCollector | ConvertingCollector}.\n * @public\n */\nexport interface IConvertingCollectorConstructorParams<\n TKEY extends string = string,\n TINDEX extends number = number,\n TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>,\n TSRC = TITEM\n> {\n /**\n * {@inheritdoc Collections.ICollectorConstructorParams.factory}\n */\n factory: CollectibleFactory<TKEY, TINDEX, TITEM, TSRC>;\n\n /**\n * {@inheritdoc Collections.ICollectorConverterCreateParams.converters}\n */\n converters: KeyValueConverters<TKEY, TSRC>;\n\n /**\n * {@inheritdoc Collections.ICollectorConstructorParams.entries}\n */\n entries?: KeyValueEntry<TKEY, TSRC>[];\n}\n\n/**\n * A {@link Collections.Collector | Collector} with a {@link Collections.CollectorConverter | CollectorConverter}\n * property that enables validated use of the underlying map with weakly-typed keys and values.\n * @public\n */\nexport class ConvertingCollector<\n TKEY extends string = string,\n TINDEX extends number = number,\n TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>,\n TSRC = TITEM\n> extends Collector<TKEY, TINDEX, TITEM, TSRC> {\n /**\n * A {@link Collections.CollectorConverter | CollectorConverter} which validates keys and values\n * before inserting them into this collector.\n */\n public readonly converting: CollectorConverter<TKEY, TINDEX, TITEM, TSRC>;\n\n protected readonly _converters: KeyValueConverters<TKEY, TSRC>;\n\n /**\n * Constructs a new {@link Collections.ConvertingCollector | ConvertingCollector}\n * from the supplied {@link Collections.IConvertingCollectorConstructorParams | parameters}.\n * @param params - Required parameters for constructing the collector.\n */\n public constructor(params: IConvertingCollectorConstructorParams<TKEY, TINDEX, TITEM, TSRC>) {\n super({ factory: params.factory });\n this._converters = params.converters;\n this.converting = new CollectorConverter({ collector: this, converters: params.converters });\n for (const entry of params.entries ?? []) {\n this.getOrAdd(entry[0], entry[1]).orThrow();\n }\n }\n\n /**\n * Creates a new {@link Collections.ConvertingCollector | ConvertingCollector} instance from\n * the supplied {@link Collections.IConvertingCollectorConstructorParams | parameters}.\n * @param params - Required parameters for constructing the collector.\n * @returns {@link Success} with the new collector if successful, {@link Failure} otherwise.\n */\n public static createConvertingCollector<\n TKEY extends string = string,\n TINDEX extends number = number,\n TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>,\n TSRC = TITEM\n >(\n params: IConvertingCollectorConstructorParams<TKEY, TINDEX, TITEM, TSRC>\n ): Result<ConvertingCollector<TKEY, TINDEX, TITEM, TSRC>> {\n return captureResult(() => new ConvertingCollector(params));\n }\n\n /**\n * {@inheritdoc Collections.Collector.(getOrAdd:1)}\n */\n public getOrAdd(key: TKEY, item: TSRC): DetailedResult<TITEM, ResultMapResultDetail>;\n\n /**\n * {@inheritdoc Collections.Collector.(getOrAdd:2)}\n */\n public getOrAdd(\n key: TKEY,\n cb: CollectibleFactoryCallback<TKEY, TINDEX, TITEM>\n ): DetailedResult<TITEM, ResultMapResultDetail>;\n public getOrAdd(\n key: TKEY,\n itemOrCb: TSRC | CollectibleFactoryCallback<TKEY, TINDEX, TITEM>\n ): DetailedResult<TITEM, ResultMapResultDetail> {\n if (this._isFactoryCB(itemOrCb)) {\n return this.converting.converters.convertKey(key).onSuccess((k) => {\n return super.getOrAdd(k, itemOrCb);\n });\n }\n return this.converting.converters.convertEntry([key, itemOrCb]).onSuccess(([k, v]) => {\n return super.getOrAdd(k, v);\n });\n }\n\n /**\n * Gets a read-only version of this collector as a\n * {@link Collections.IReadOnlyConvertingResultMap | read-only map}.\n * @returns\n */\n public toReadOnly(): IReadOnlyConvertingResultMap<TKEY, TITEM> {\n return this;\n }\n}\n"]}
1
+ {"version":3,"file":"convertingCollector.js","sourceRoot":"","sources":["../../../src/packlets/collections/convertingCollector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAgD;AAEhD,2CAAwC;AACxC,6DAAuF;AAqDvF;;;;GAIG;AACH,MAAa,mBAKX,SAAQ,qBAAoC;IAS5C;;;;OAIG;IACH,YAAmB,MAAwE;;QACzF,KAAK,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,IAAI,uCAAkB,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAC7F,KAAK,MAAM,KAAK,IAAI,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,EAAE,CAAC;YACzC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,yBAAyB,CAMrC,MAAwE;QAExE,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED;;;;OAIG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AArDD,kDAqDC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Result } from '../base';\nimport { CollectibleFactory, ICollectible } from './collectible';\nimport { Collector } from './collector';\nimport { CollectorConverter, IReadOnlyCollectorConverter } from './collectorConverter';\nimport { KeyValueEntry } from './common';\nimport { IReadOnlyConvertingResultMap } from './convertingResultMap';\nimport { KeyValueConverters } from './keyValueConverters';\n\n/**\n * A read-only interface exposing non-mutating methods of a\n * {@link Collections.ConvertingCollector | ConvertingCollector}.\n * @public\n */\n\nexport interface IReadOnlyConvertingCollector<\n TKEY extends string = string,\n TINDEX extends number = number,\n TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>\n> extends IReadOnlyConvertingResultMap<TKEY, TITEM> {\n /**\n * {@inheritdoc Collections.ConvertingCollector.converting}\n */\n readonly converting: IReadOnlyCollectorConverter<TKEY, TINDEX, TITEM>;\n\n /**\n * {@inheritdoc Collections.Collector.getAt}\n */\n readonly getAt: (index: number) => Result<TITEM>;\n}\n\n/**\n * Parameters for constructing a {@link Collections.ConvertingCollector | ConvertingCollector}.\n * @public\n */\nexport interface IConvertingCollectorConstructorParams<\n TKEY extends string = string,\n TINDEX extends number = number,\n TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>,\n TSRC = TITEM\n> {\n /**\n * {@inheritdoc Collections.ICollectorConstructorParams.factory}\n */\n factory: CollectibleFactory<TKEY, TINDEX, TITEM, TSRC>;\n\n /**\n * {@inheritdoc Collections.ICollectorConverterCreateParams.converters}\n */\n converters: KeyValueConverters<TKEY, TSRC>;\n\n /**\n * {@inheritdoc Collections.ICollectorConstructorParams.entries}\n */\n entries?: KeyValueEntry<TKEY, TSRC>[];\n}\n\n/**\n * A {@link Collections.Collector | Collector} with a {@link Collections.CollectorConverter | CollectorConverter}\n * property that enables validated use of the underlying map with weakly-typed keys and values.\n * @public\n */\nexport class ConvertingCollector<\n TKEY extends string = string,\n TINDEX extends number = number,\n TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>,\n TSRC = TITEM\n> extends Collector<TKEY, TINDEX, TITEM, TSRC> {\n /**\n * A {@link Collections.CollectorConverter | CollectorConverter} which validates keys and values\n * before inserting them into this collector.\n */\n public readonly converting: CollectorConverter<TKEY, TINDEX, TITEM, TSRC>;\n\n protected readonly _converters: KeyValueConverters<TKEY, TSRC>;\n\n /**\n * Constructs a new {@link Collections.ConvertingCollector | ConvertingCollector}\n * from the supplied {@link Collections.IConvertingCollectorConstructorParams | parameters}.\n * @param params - Required parameters for constructing the collector.\n */\n public constructor(params: IConvertingCollectorConstructorParams<TKEY, TINDEX, TITEM, TSRC>) {\n super({ factory: params.factory });\n this._converters = params.converters;\n this.converting = new CollectorConverter({ collector: this, converters: params.converters });\n for (const entry of params.entries ?? []) {\n this.getOrAdd(entry[0], entry[1]).orThrow();\n }\n }\n\n /**\n * Creates a new {@link Collections.ConvertingCollector | ConvertingCollector} instance from\n * the supplied {@link Collections.IConvertingCollectorConstructorParams | parameters}.\n * @param params - Required parameters for constructing the collector.\n * @returns {@link Success} with the new collector if successful, {@link Failure} otherwise.\n */\n public static createConvertingCollector<\n TKEY extends string = string,\n TINDEX extends number = number,\n TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>,\n TSRC = TITEM\n >(\n params: IConvertingCollectorConstructorParams<TKEY, TINDEX, TITEM, TSRC>\n ): Result<ConvertingCollector<TKEY, TINDEX, TITEM, TSRC>> {\n return captureResult(() => new ConvertingCollector(params));\n }\n\n /**\n * Gets a read-only version of this collector as a\n * {@link Collections.IReadOnlyConvertingResultMap | read-only map}.\n * @returns\n */\n public toReadOnly(): IReadOnlyConvertingCollector<TKEY, TINDEX, TITEM> {\n return this;\n }\n}\n"]}
@@ -1,9 +1,9 @@
1
- import { DetailedResult, Result } from '../base';
1
+ import { Result } from '../base';
2
2
  import { KeyValueEntry } from './common';
3
- import { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';
4
- import { ResultMap, ResultMapValueFactory } from './resultMap';
5
- import { IReadOnlyResultMapConverter, ResultMapConverter } from './resultMapConverter';
6
3
  import { KeyValueConverters } from './keyValueConverters';
4
+ import { IReadOnlyResultMap } from './readonlyResultMap';
5
+ import { ResultMap } from './resultMap';
6
+ import { IReadOnlyResultMapConverter, ResultMapConverter } from './resultMapConverter';
7
7
  /**
8
8
  * A read-only interface exposing non-mutating methods of a {@link Collections.ConvertingResultMap | ConvertingResultMap}.
9
9
  * @public
@@ -45,26 +45,6 @@ export declare class ConvertingResultMap<TK extends string = string, TV = unknow
45
45
  * @public
46
46
  */
47
47
  static createConvertingResultMap<TK extends string = string, TV = unknown>(params: IConvertingResultMapConstructorParams<TK, TV>): Result<ConvertingResultMap<TK, TV>>;
48
- /**
49
- * {@inheritdoc Collections.ResultMap.add}
50
- */
51
- add(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
52
- /**
53
- * {@inheritdoc Collections.ResultMap.(getOrAdd:1)}
54
- */
55
- getOrAdd(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
56
- /**
57
- * {@inheritdoc Collections.ResultMap.(getOrAdd:2)}
58
- */
59
- getOrAdd(key: TK, factory: ResultMapValueFactory<TK, TV>): DetailedResult<TV, ResultMapResultDetail>;
60
- /**
61
- * {@inheritdoc Collections.ResultMap.set}
62
- */
63
- set(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
64
- /**
65
- * {@inheritdoc Collections.ResultMap.update}
66
- */
67
- update(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
68
48
  /**
69
49
  * Gets a read-only version of this map.
70
50
  */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,CAAC;IAItC;;OAEG;IACI,UAAU,IAAI,4BAA4B,CAAC,EAAE,EAAE,EAAE,CAAC;CAG1D"}
@@ -50,47 +50,6 @@ class ConvertingResultMap extends resultMap_1.ResultMap {
50
50
  static createConvertingResultMap(params) {
51
51
  return (0, base_1.captureResult)(() => new ConvertingResultMap(params));
52
52
  }
53
- /**
54
- * {@inheritdoc Collections.ResultMap.add}
55
- */
56
- add(key, value) {
57
- return this.converting.converters.convertEntry([key, value]).onSuccess((entry) => {
58
- return super.add(entry[0], entry[1]);
59
- });
60
- }
61
- getOrAdd(key, valueOrFactory) {
62
- if (!this._isResultMapValueFactory(valueOrFactory)) {
63
- return this.converting.converters.convertEntry([key, valueOrFactory]).onSuccess((entry) => {
64
- return super.getOrAdd(entry[0], entry[1]);
65
- });
66
- }
67
- else {
68
- return super.get(key).onFailure(() => {
69
- const value = valueOrFactory(key)
70
- .onSuccess((value) => this.converting.converters.convertEntry([key, value]))
71
- .onSuccess(([__key, value]) => (0, base_1.succeed)(value));
72
- return value.success
73
- ? super.add(key, value.value)
74
- : (0, base_1.failWithDetail)(value.message, 'invalid-value');
75
- });
76
- }
77
- }
78
- /**
79
- * {@inheritdoc Collections.ResultMap.set}
80
- */
81
- set(key, value) {
82
- return this.converting.converters.convertEntry([key, value]).onSuccess((entry) => {
83
- return super.set(entry[0], entry[1]);
84
- });
85
- }
86
- /**
87
- * {@inheritdoc Collections.ResultMap.update}
88
- */
89
- update(key, value) {
90
- return this.converting.converters.convertEntry([key, value]).onSuccess((entry) => {
91
- return super.update(entry[0], entry[1]);
92
- });
93
- }
94
53
  /**
95
54
  * Gets a read-only version of this map.
96
55
  */
@@ -1 +1 @@
1
- {"version":3,"file":"convertingResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/convertingResultMap.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAyF;AAGzF,2CAA+D;AAC/D,6DAAuF;AAwBvF;;;;GAIG;AACH,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AAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA7FD,kDA6FC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, DetailedResult, failWithDetail, Result, succeed } from '../base';\nimport { KeyValueEntry } from './common';\nimport { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';\nimport { ResultMap, ResultMapValueFactory } from './resultMap';\nimport { IReadOnlyResultMapConverter, ResultMapConverter } from './resultMapConverter';\nimport { KeyValueConverters } from './keyValueConverters';\n\n/**\n * A read-only interface exposing non-mutating methods of a {@link Collections.ConvertingResultMap | ConvertingResultMap}.\n * @public\n */\nexport interface IReadOnlyConvertingResultMap<TK extends string = string, TV = unknown>\n extends IReadOnlyResultMap<TK, TV> {\n /**\n * {@inheritdoc Collections.ConvertingResultMap.converting}\n */\n readonly converting: IReadOnlyResultMapConverter<TK, TV>;\n}\n\n/**\n * Parameters for constructing a {@link Collections.ResultMap | ResultMap}.\n * @public\n */\nexport interface IConvertingResultMapConstructorParams<TK extends string = string, TV = unknown> {\n entries?: Iterable<KeyValueEntry<string, unknown>>;\n converters: KeyValueConverters<TK, TV>;\n}\n\n/**\n * A {@link Collections.ResultMap | ResultMap} with a {@link Collections.ResultMapConverter | validator}\n * property that enables validated use of the underlying map with weakly-typed keys and values.\n * @public\n */\nexport class ConvertingResultMap<TK extends string = string, TV = unknown>\n extends ResultMap<TK, TV>\n implements IReadOnlyConvertingResultMap<TK, TV>\n{\n /**\n * A {@link Collections.ResultMapConverter | ResultMapConverter} which validates keys and values\n * before inserting them into this collection.\n */\n public readonly converting: ResultMapConverter<TK, TV>;\n\n /**\n * Constructs a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.\n * @param params - Required parameters for constructing the map.\n */\n public constructor(params: IConvertingResultMapConstructorParams<TK, TV>) {\n const entries = params.converters.convertEntries([...(params.entries ?? [])]).orThrow();\n super({ entries });\n this.converting = new ResultMapConverter<TK, TV>({ map: this, converters: params.converters });\n }\n\n /**\n * Creates a new {@link Collections.ConvertingResultMap | ConvertingResultMap} instance.\n * @param params - Required parameters for constructing the map.\n * @returns `Success` with the new map if successful, `Failure` otherwise.\n * @public\n */\n public static createConvertingResultMap<TK extends string = string, TV = unknown>(\n params: IConvertingResultMapConstructorParams<TK, TV>\n ): Result<ConvertingResultMap<TK, TV>> {\n return captureResult(() => new ConvertingResultMap(params));\n }\n\n /**\n * {@inheritdoc Collections.ResultMap.add}\n */\n public add(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail> {\n return this.converting.converters.convertEntry([key, value]).onSuccess((entry) => {\n return super.add(entry[0], entry[1]);\n });\n }\n\n /**\n * {@inheritdoc Collections.ResultMap.(getOrAdd:1)}\n */\n public getOrAdd(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;\n /**\n * {@inheritdoc Collections.ResultMap.(getOrAdd:2)}\n */\n public getOrAdd(key: TK, factory: ResultMapValueFactory<TK, TV>): DetailedResult<TV, ResultMapResultDetail>;\n public getOrAdd(\n key: TK,\n valueOrFactory: TV | ResultMapValueFactory<TK, TV>\n ): DetailedResult<TV, ResultMapResultDetail> {\n if (!this._isResultMapValueFactory(valueOrFactory)) {\n return this.converting.converters.convertEntry([key, valueOrFactory]).onSuccess((entry) => {\n return super.getOrAdd(entry[0], entry[1]);\n });\n } else {\n return super.get(key).onFailure(() => {\n const value = valueOrFactory(key)\n .onSuccess((value) => this.converting.converters.convertEntry([key, value]))\n .onSuccess(([__key, value]) => succeed(value));\n return value.success\n ? super.add(key, value.value)\n : failWithDetail<TV, ResultMapResultDetail>(value.message, 'invalid-value');\n });\n }\n }\n\n /**\n * {@inheritdoc Collections.ResultMap.set}\n */\n public set(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail> {\n return this.converting.converters.convertEntry([key, value]).onSuccess((entry) => {\n return super.set(entry[0], entry[1]);\n });\n }\n\n /**\n * {@inheritdoc Collections.ResultMap.update}\n */\n public update(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail> {\n return this.converting.converters.convertEntry([key, value]).onSuccess((entry) => {\n return super.update(entry[0], entry[1]);\n });\n }\n\n /**\n * Gets a read-only version of this map.\n */\n public toReadOnly(): IReadOnlyConvertingResultMap<TK, TV> {\n return this;\n }\n}\n"]}
1
+ {"version":3,"file":"convertingResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/convertingResultMap.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAgD;AAIhD,2CAAwC;AACxC,6DAAuF;AAuBvF;;;;GAIG;AACH,MAAa,mBACX,SAAQ,qBAAiB;IASzB;;;OAGG;IACH,YAAmB,MAAqD;;QACtE,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACxF,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,IAAI,uCAAkB,CAAS,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IACjG,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,yBAAyB,CACrC,MAAqD;QAErD,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAtCD,kDAsCC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Result } from '../base';\nimport { KeyValueEntry } from './common';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { IReadOnlyResultMap } from './readonlyResultMap';\nimport { ResultMap } from './resultMap';\nimport { IReadOnlyResultMapConverter, ResultMapConverter } from './resultMapConverter';\n\n/**\n * A read-only interface exposing non-mutating methods of a {@link Collections.ConvertingResultMap | ConvertingResultMap}.\n * @public\n */\nexport interface IReadOnlyConvertingResultMap<TK extends string = string, TV = unknown>\n extends IReadOnlyResultMap<TK, TV> {\n /**\n * {@inheritdoc Collections.ConvertingResultMap.converting}\n */\n readonly converting: IReadOnlyResultMapConverter<TK, TV>;\n}\n\n/**\n * Parameters for constructing a {@link Collections.ResultMap | ResultMap}.\n * @public\n */\nexport interface IConvertingResultMapConstructorParams<TK extends string = string, TV = unknown> {\n entries?: Iterable<KeyValueEntry<string, unknown>>;\n converters: KeyValueConverters<TK, TV>;\n}\n\n/**\n * A {@link Collections.ResultMap | ResultMap} with a {@link Collections.ResultMapConverter | validator}\n * property that enables validated use of the underlying map with weakly-typed keys and values.\n * @public\n */\nexport class ConvertingResultMap<TK extends string = string, TV = unknown>\n extends ResultMap<TK, TV>\n implements IReadOnlyConvertingResultMap<TK, TV>\n{\n /**\n * A {@link Collections.ResultMapConverter | ResultMapConverter} which validates keys and values\n * before inserting them into this collection.\n */\n public readonly converting: ResultMapConverter<TK, TV>;\n\n /**\n * Constructs a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.\n * @param params - Required parameters for constructing the map.\n */\n public constructor(params: IConvertingResultMapConstructorParams<TK, TV>) {\n const entries = params.converters.convertEntries([...(params.entries ?? [])]).orThrow();\n super({ entries });\n this.converting = new ResultMapConverter<TK, TV>({ map: this, converters: params.converters });\n }\n\n /**\n * Creates a new {@link Collections.ConvertingResultMap | ConvertingResultMap} instance.\n * @param params - Required parameters for constructing the map.\n * @returns `Success` with the new map if successful, `Failure` otherwise.\n * @public\n */\n public static createConvertingResultMap<TK extends string = string, TV = unknown>(\n params: IConvertingResultMapConstructorParams<TK, TV>\n ): Result<ConvertingResultMap<TK, TV>> {\n return captureResult(() => new ConvertingResultMap(params));\n }\n\n /**\n * Gets a read-only version of this map.\n */\n public toReadOnly(): IReadOnlyConvertingResultMap<TK, TV> {\n return this;\n }\n}\n"]}
@@ -18,13 +18,6 @@ export interface IKeyValueConverterConstructorParams<TK extends string = string,
18
18
  * or {@link Conversion.ConverterFunc | converter function}.
19
19
  */
20
20
  value: Validator<TV, unknown> | Converter<TV, unknown> | ConverterFunc<TV, unknown>;
21
- /**
22
- * Optional entry {@link Validator | validator}, {@link Converter | converter},
23
- * or {@link Conversion.ConverterFunc | converter function}.
24
- * If no entry validator is provided, an entry is considered valid if both key and
25
- * value are valid.
26
- */
27
- entry?: Validator<KeyValueEntry<TK, TV>, unknown> | Converter<KeyValueEntry<TK, TV>, unknown> | ConverterFunc<KeyValueEntry<TK, TV>, unknown>;
28
21
  }
29
22
  /**
30
23
  * Helper class for converting strongly-typed keys, values, or entries
@@ -40,23 +33,14 @@ export declare class KeyValueConverters<TK extends string = string, TV = unknown
40
33
  * Required value {@link Validator | validator} or {@link Converter | converter}.
41
34
  */
42
35
  readonly value: Validator<TV, unknown> | Converter<TV, unknown>;
43
- /**
44
- * Optional entry {@link Validator | validator} or {@link Converter | converter}.
45
- * If no entry validator is provided, an entry is considered valid if both key and
46
- * value are valid.
47
- */
48
- readonly entry?: Validator<KeyValueEntry<TK, TV>, unknown> | Converter<KeyValueEntry<TK, TV>, unknown>;
49
36
  /**
50
37
  * Constructs a new key-value validator.
51
38
  * @param key - Required key {@link Validator | validator}, {@link Converter | converter},
52
39
  * or {@link Conversion.ConverterFunc | converter function}.
53
40
  * @param value - Required value {@link Validator | validator}, {@link Converter | converter},
54
41
  * or {@link Conversion.ConverterFunc | converter function}.
55
- * @param entry - Optional entry {@link Validator | validator}, {@link Converter | converter},
56
- * or {@link Conversion.ConverterFunc | converter function}.. If no entry validator is provided,
57
- * an entry is considered valid if both key and value are valid.
58
42
  */
59
- constructor({ key, value, entry }: IKeyValueConverterConstructorParams<TK, TV>);
43
+ constructor({ key, value }: IKeyValueConverterConstructorParams<TK, TV>);
60
44
  /**
61
45
  * Converts a supplied unknown to a valid key value of type `<TK>`.
62
46
  * @param key - The unknown to be converted.
@@ -1 +1 @@
1
- {"version":3,"file":"keyValueConverters.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/keyValueConverters.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,cAAc,EAGd,MAAM,EAGP,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAc,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;GAGG;AACH,MAAM,WAAW,mCAAmC,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,OAAO;IAC3F;;;OAGG;IACH,GAAG,EAAE,SAAS,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAElF;;;OAGG;IACH,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAEpF;;;;;OAKG;IACH,KAAK,CAAC,EACF,SAAS,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,GACzC,SAAS,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,GACzC,aAAa,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;CACnD;AAED;;;;GAIG;AACH,qBAAa,kBAAkB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AAc,CAAC,EAAE,EAAE,qBAAqB,CAAC;IAI5E;;;;;;OAMG;IACI,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,qBAAqB,CAAC;IAejG;;;;;OAKG;IACI,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;CAanF"}
@@ -36,14 +36,10 @@ class KeyValueConverters {
36
36
  * or {@link Conversion.ConverterFunc | converter function}.
37
37
  * @param value - Required value {@link Validator | validator}, {@link Converter | converter},
38
38
  * or {@link Conversion.ConverterFunc | converter function}.
39
- * @param entry - Optional entry {@link Validator | validator}, {@link Converter | converter},
40
- * or {@link Conversion.ConverterFunc | converter function}.. If no entry validator is provided,
41
- * an entry is considered valid if both key and value are valid.
42
39
  */
43
- constructor({ key, value, entry }) {
40
+ constructor({ key, value }) {
44
41
  this.key = typeof key === 'function' ? conversion_1.Converters.generic(key) : key;
45
42
  this.value = typeof value === 'function' ? conversion_1.Converters.generic(value) : value;
46
- this.entry = entry ? (typeof entry === 'function' ? conversion_1.Converters.generic(entry) : entry) : undefined;
47
43
  }
48
44
  /**
49
45
  * Converts a supplied unknown to a valid key value of type `<TK>`.
@@ -71,9 +67,6 @@ class KeyValueConverters {
71
67
  * the entry is invalid
72
68
  */
73
69
  convertEntry(entry) {
74
- if (this.entry) {
75
- return this.entry.convert(entry).withFailureDetail('invalid-value');
76
- }
77
70
  if (Array.isArray(entry) && entry.length === 2) {
78
71
  const errors = new base_1.MessageAggregator();
79
72
  const key = this.convertKey(entry[0]).aggregateError(errors).orDefault();
@@ -1 +1 @@
1
- {"version":3,"file":"keyValueConverters.js","sourceRoot":"","sources":["../../../src/packlets/collections/keyValueConverters.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAOiB;AACjB,8C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A,cAAO,EAAC,SAAS,CAAC,CAAC,CAAC;IACnD,CAAC;CACF;AAnGD,gDAmGC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n DetailedResult,\n failWithDetail,\n MessageAggregator,\n Result,\n succeed,\n succeedWithDetail\n} from '../base';\nimport { Converter, ConverterFunc, Converters } from '../conversion';\nimport { Validator } from '../validation';\nimport { KeyValueEntry } from './common';\nimport { ResultMapResultDetail } from './readonlyResultMap';\n\n/**\n * Parameters for constructing a {@link Collections.KeyValueConverters | KeyValueConverters} instance.\n * @public\n */\nexport interface IKeyValueConverterConstructorParams<TK extends string = string, TV = unknown> {\n /**\n * Required key {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n */\n key: Validator<TK, unknown> | Converter<TK, unknown> | ConverterFunc<TK, unknown>;\n\n /**\n * Required value {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n */\n value: Validator<TV, unknown> | Converter<TV, unknown> | ConverterFunc<TV, unknown>;\n\n /**\n * Optional entry {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n * If no entry validator is provided, an entry is considered valid if both key and\n * value are valid.\n */\n entry?:\n | Validator<KeyValueEntry<TK, TV>, unknown>\n | Converter<KeyValueEntry<TK, TV>, unknown>\n | ConverterFunc<KeyValueEntry<TK, TV>, unknown>;\n}\n\n/**\n * Helper class for converting strongly-typed keys, values, or entries\n * from unknown values.\n * @public\n */\nexport class KeyValueConverters<TK extends string = string, TV = unknown> {\n /**\n * Required key {@link Validator | validator} or {@link Converter | converter}.\n */\n public readonly key: Validator<TK, unknown> | Converter<TK, unknown>;\n /**\n * Required value {@link Validator | validator} or {@link Converter | converter}.\n */\n public readonly value: Validator<TV, unknown> | Converter<TV, unknown>;\n\n /**\n * Optional entry {@link Validator | validator} or {@link Converter | converter}.\n * If no entry validator is provided, an entry is considered valid if both key and\n * value are valid.\n */\n public readonly entry?:\n | Validator<KeyValueEntry<TK, TV>, unknown>\n | Converter<KeyValueEntry<TK, TV>, unknown>;\n\n /**\n * Constructs a new key-value validator.\n * @param key - Required key {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n * @param value - Required value {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n * @param entry - Optional entry {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.. If no entry validator is provided,\n * an entry is considered valid if both key and value are valid.\n */\n public constructor({ key, value, entry }: IKeyValueConverterConstructorParams<TK, TV>) {\n this.key = typeof key === 'function' ? Converters.generic(key) : key;\n this.value = typeof value === 'function' ? Converters.generic(value) : value;\n this.entry = entry ? (typeof entry === 'function' ? Converters.generic(entry) : entry) : undefined;\n }\n\n /**\n * Converts a supplied unknown to a valid key value of type `<TK>`.\n * @param key - The unknown to be converted.\n * @returns `Success` with the converted key value and 'success' detail if the key is valid,\n * or `Failure` with an error message and 'invalid-key' detail if the key is invalid.\n */\n public convertKey(key: unknown): DetailedResult<TK, ResultMapResultDetail> {\n return this.key.convert(key).withFailureDetail('invalid-key');\n }\n\n /**\n * Converts a supplied unknown to a valid value of type `<TV>`.\n * @param key - The unknown to be converted.\n * @returns `Success` with the converted value and 'success' detail if the value is valid,\n * or `Failure` with an error message and 'invalid-value' detail if the value is invalid.\n */\n public convertValue(key: unknown): DetailedResult<TV, ResultMapResultDetail> {\n return this.value.convert(key).withFailureDetail('invalid-value');\n }\n\n /**\n * Converts a supplied unknown to a valid entry of type `[<TK>, <TV>]`.\n * @param entry - The unknown to be converted.\n * @returns `Success` with the converted entry and 'success' detail if the entry\n * is valid, or `Failure` with an error message and 'invalid-key' or 'invalid-value' detail if\n * the entry is invalid\n */\n public convertEntry(entry: unknown): DetailedResult<KeyValueEntry<TK, TV>, ResultMapResultDetail> {\n if (this.entry) {\n return this.entry.convert(entry).withFailureDetail('invalid-value');\n }\n if (Array.isArray(entry) && entry.length === 2) {\n const errors = new MessageAggregator();\n const key = this.convertKey(entry[0]).aggregateError(errors).orDefault();\n const value = this.convertValue(entry[1]).aggregateError(errors).orDefault();\n if (key && value) {\n return succeedWithDetail([key, value], 'success');\n }\n const detail = key ? 'invalid-value' : 'invalid-key';\n return failWithDetail(`invalid entry: ${errors.toString()}`, detail);\n }\n /* c8 ignore next 2 */\n return failWithDetail(`malformed entry: \"${JSON.stringify(entry)}\"`, 'invalid-value');\n }\n\n /**\n * Converts a supplied iterable of unknowns to valid key-value pairs.\n * @param entries - The iterable of unknowns to be converted.\n * @returns `Success` with an array of converted key-value pairs if all entries are valid,\n * or `Failure` with an error message if any entry is invalid.\n */\n public convertEntries(entries: Iterable<unknown>): Result<KeyValueEntry<TK, TV>[]> {\n const errors = new MessageAggregator();\n const converted: KeyValueEntry<TK, TV>[] = [];\n for (const element of entries) {\n this.convertEntry(element)\n .onSuccess((e) => {\n converted.push(e);\n return succeedWithDetail(e, 'success');\n })\n .aggregateError(errors);\n }\n return errors.returnOrReport(succeed(converted));\n }\n}\n"]}
1
+ {"version":3,"file":"keyValueConverters.js","sourceRoot":"","sources":["../../../src/packlets/collections/keyValueConverters.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAOiB;AACjB,8CAAqE;AAuBrE;;;;GAIG;AACH,MAAa,kBAAkB;IAU7B;;;;;;OAMG;IACH,YAAmB,EAAE,GAAG,EAAE,KAAK,EAA+C;QAC5E,IAAI,CAAC,GAAG,GAAG,OAAO,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,uBAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACrE,IAAI,CAAC,KAAK,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,uBAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC/E,CAAC;IAED;;;;;OAKG;IACI,UAAU,CAAC,GAAY;QAC5B,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;IAChE,CAAC;IAED;;;;;OAKG;IACI,YAAY,CAAC,GAAY;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;OAMG;IACI,YAAY,CAAC,KAAc;QAChC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/C,MAAM,MAAM,GAAG,IAAI,wBAAiB,EAAE,CAAC;YACvC,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,SAAS,EA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copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n DetailedResult,\n failWithDetail,\n MessageAggregator,\n Result,\n succeed,\n succeedWithDetail\n} from '../base';\nimport { Converter, ConverterFunc, Converters } from '../conversion';\nimport { Validator } from '../validation';\nimport { KeyValueEntry } from './common';\nimport { ResultMapResultDetail } from './readonlyResultMap';\n\n/**\n * Parameters for constructing a {@link Collections.KeyValueConverters | KeyValueConverters} instance.\n * @public\n */\nexport interface IKeyValueConverterConstructorParams<TK extends string = string, TV = unknown> {\n /**\n * Required key {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n */\n key: Validator<TK, unknown> | Converter<TK, unknown> | ConverterFunc<TK, unknown>;\n\n /**\n * Required value {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n */\n value: Validator<TV, unknown> | Converter<TV, unknown> | ConverterFunc<TV, unknown>;\n}\n\n/**\n * Helper class for converting strongly-typed keys, values, or entries\n * from unknown values.\n * @public\n */\nexport class KeyValueConverters<TK extends string = string, TV = unknown> {\n /**\n * Required key {@link Validator | validator} or {@link Converter | converter}.\n */\n public readonly key: Validator<TK, unknown> | Converter<TK, unknown>;\n /**\n * Required value {@link Validator | validator} or {@link Converter | converter}.\n */\n public readonly value: Validator<TV, unknown> | Converter<TV, unknown>;\n\n /**\n * Constructs a new key-value validator.\n * @param key - Required key {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n * @param value - Required value {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n */\n public constructor({ key, value }: IKeyValueConverterConstructorParams<TK, TV>) {\n this.key = typeof key === 'function' ? Converters.generic(key) : key;\n this.value = typeof value === 'function' ? Converters.generic(value) : value;\n }\n\n /**\n * Converts a supplied unknown to a valid key value of type `<TK>`.\n * @param key - The unknown to be converted.\n * @returns `Success` with the converted key value and 'success' detail if the key is valid,\n * or `Failure` with an error message and 'invalid-key' detail if the key is invalid.\n */\n public convertKey(key: unknown): DetailedResult<TK, ResultMapResultDetail> {\n return this.key.convert(key).withFailureDetail('invalid-key');\n }\n\n /**\n * Converts a supplied unknown to a valid value of type `<TV>`.\n * @param key - The unknown to be converted.\n * @returns `Success` with the converted value and 'success' detail if the value is valid,\n * or `Failure` with an error message and 'invalid-value' detail if the value is invalid.\n */\n public convertValue(key: unknown): DetailedResult<TV, ResultMapResultDetail> {\n return this.value.convert(key).withFailureDetail('invalid-value');\n }\n\n /**\n * Converts a supplied unknown to a valid entry of type `[<TK>, <TV>]`.\n * @param entry - The unknown to be converted.\n * @returns `Success` with the converted entry and 'success' detail if the entry\n * is valid, or `Failure` with an error message and 'invalid-key' or 'invalid-value' detail if\n * the entry is invalid\n */\n public convertEntry(entry: unknown): DetailedResult<KeyValueEntry<TK, TV>, ResultMapResultDetail> {\n if (Array.isArray(entry) && entry.length === 2) {\n const errors = new MessageAggregator();\n const key = this.convertKey(entry[0]).aggregateError(errors).orDefault();\n const value = this.convertValue(entry[1]).aggregateError(errors).orDefault();\n if (key && value) {\n return succeedWithDetail([key, value], 'success');\n }\n const detail = key ? 'invalid-value' : 'invalid-key';\n return failWithDetail(`invalid entry: ${errors.toString()}`, detail);\n }\n /* c8 ignore next 2 */\n return failWithDetail(`malformed entry: \"${JSON.stringify(entry)}\"`, 'invalid-value');\n }\n\n /**\n * Converts a supplied iterable of unknowns to valid key-value pairs.\n * @param entries - The iterable of unknowns to be converted.\n * @returns `Success` with an array of converted key-value pairs if all entries are valid,\n * or `Failure` with an error message if any entry is invalid.\n */\n public convertEntries(entries: Iterable<unknown>): Result<KeyValueEntry<TK, TV>[]> {\n const errors = new MessageAggregator();\n const converted: KeyValueEntry<TK, TV>[] = [];\n for (const element of entries) {\n this.convertEntry(element)\n .onSuccess((e) => {\n converted.push(e);\n return succeedWithDetail(e, 'success');\n })\n .aggregateError(errors);\n }\n return errors.returnOrReport(succeed(converted));\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-utils",
3
- "version": "4.3.0",
3
+ "version": "4.4.0",
4
4
  "description": "Assorted Typescript Utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "dist/ts-utils.d.ts",