@fgv/ts-utils 4.3.0 → 4.5.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.
- package/CHANGELOG.json +6 -0
- package/CHANGELOG.md +6 -1
- package/dist/ts-utils.d.ts +4248 -3531
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -3
- package/lib/index.js.map +1 -1
- package/lib/packlets/base/utils.d.ts.map +1 -1
- package/lib/packlets/base/utils.js +0 -1
- package/lib/packlets/base/utils.js.map +1 -1
- package/lib/packlets/collections/collectible.d.ts +82 -8
- package/lib/packlets/collections/collectible.d.ts.map +1 -1
- package/lib/packlets/collections/collectible.js +36 -11
- package/lib/packlets/collections/collectible.js.map +1 -1
- package/lib/packlets/collections/collector.d.ts +78 -79
- package/lib/packlets/collections/collector.d.ts.map +1 -1
- package/lib/packlets/collections/collector.js +83 -52
- package/lib/packlets/collections/collector.js.map +1 -1
- package/lib/packlets/collections/collectorValidator.d.ts +89 -0
- package/lib/packlets/collections/collectorValidator.d.ts.map +1 -0
- package/lib/packlets/collections/collectorValidator.js +98 -0
- package/lib/packlets/collections/collectorValidator.js.map +1 -0
- package/lib/packlets/collections/convertingCollector.d.ts +77 -36
- package/lib/packlets/collections/convertingCollector.d.ts.map +1 -1
- package/lib/packlets/collections/convertingCollector.js +71 -26
- package/lib/packlets/collections/convertingCollector.js.map +1 -1
- package/lib/packlets/collections/convertingCollectorValidator.d.ts +69 -0
- package/lib/packlets/collections/convertingCollectorValidator.d.ts.map +1 -0
- package/lib/packlets/collections/{collectorConverter.js → convertingCollectorValidator.js} +28 -15
- package/lib/packlets/collections/convertingCollectorValidator.js.map +1 -0
- package/lib/packlets/collections/index.d.ts +7 -5
- package/lib/packlets/collections/index.d.ts.map +1 -1
- package/lib/packlets/collections/index.js +7 -5
- package/lib/packlets/collections/index.js.map +1 -1
- package/lib/packlets/collections/keyValueConverters.d.ts +1 -17
- package/lib/packlets/collections/keyValueConverters.d.ts.map +1 -1
- package/lib/packlets/collections/keyValueConverters.js +1 -8
- package/lib/packlets/collections/keyValueConverters.js.map +1 -1
- package/lib/packlets/collections/readonlyResultMap.d.ts +0 -4
- package/lib/packlets/collections/readonlyResultMap.d.ts.map +1 -1
- package/lib/packlets/collections/readonlyResultMap.js.map +1 -1
- package/lib/packlets/collections/resultMap.d.ts +0 -4
- package/lib/packlets/collections/resultMap.d.ts.map +1 -1
- package/lib/packlets/collections/resultMap.js +0 -6
- package/lib/packlets/collections/resultMap.js.map +1 -1
- package/lib/packlets/collections/{resultMapConverter.d.ts → resultMapValidator.d.ts} +11 -11
- package/lib/packlets/collections/{resultMapConverter.d.ts.map → resultMapValidator.d.ts.map} +1 -1
- package/lib/packlets/collections/{resultMapConverter.js → resultMapValidator.js} +6 -6
- package/lib/packlets/collections/{resultMapConverter.js.map → resultMapValidator.js.map} +1 -1
- package/lib/packlets/collections/validatingCollector.d.ts +69 -0
- package/lib/packlets/collections/validatingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/validatingCollector.js +67 -0
- package/lib/packlets/collections/validatingCollector.js.map +1 -0
- package/lib/packlets/collections/validatingConvertingCollector.d.ts +59 -0
- package/lib/packlets/collections/validatingConvertingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/validatingConvertingCollector.js +68 -0
- package/lib/packlets/collections/validatingConvertingCollector.js.map +1 -0
- package/lib/packlets/collections/validatingResultMap.d.ts +53 -0
- package/lib/packlets/collections/validatingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/validatingResultMap.js +61 -0
- package/lib/packlets/collections/validatingResultMap.js.map +1 -0
- package/lib/packlets/file-tree/directoryItem.d.ts +47 -0
- package/lib/packlets/file-tree/directoryItem.d.ts.map +1 -0
- package/lib/packlets/file-tree/directoryItem.js +71 -0
- package/lib/packlets/file-tree/directoryItem.js.map +1 -0
- package/lib/packlets/file-tree/fileItem.d.ts +64 -0
- package/lib/packlets/file-tree/fileItem.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileItem.js +93 -0
- package/lib/packlets/file-tree/fileItem.js.map +1 -0
- package/lib/packlets/file-tree/fileTree.d.ts +84 -0
- package/lib/packlets/file-tree/fileTree.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileTree.js +135 -0
- package/lib/packlets/file-tree/fileTree.js.map +1 -0
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts +134 -0
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts.map +1 -0
- package/lib/packlets/file-tree/fileTreeAccessors.js +24 -0
- package/lib/packlets/file-tree/fileTreeAccessors.js.map +1 -0
- package/lib/packlets/file-tree/fsTree.d.ts +45 -0
- package/lib/packlets/file-tree/fsTree.d.ts.map +1 -0
- package/lib/packlets/file-tree/fsTree.js +116 -0
- package/lib/packlets/file-tree/fsTree.js.map +1 -0
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +67 -0
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts.map +1 -0
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js +150 -0
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js.map +1 -0
- package/lib/packlets/file-tree/in-memory/index.d.ts +2 -0
- package/lib/packlets/file-tree/in-memory/index.d.ts.map +1 -0
- package/lib/packlets/file-tree/in-memory/index.js +39 -0
- package/lib/packlets/file-tree/in-memory/index.js.map +1 -0
- package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts +106 -0
- package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts.map +1 -0
- package/lib/packlets/file-tree/in-memory/treeBuilder.js +170 -0
- package/lib/packlets/file-tree/in-memory/treeBuilder.js.map +1 -0
- package/lib/packlets/file-tree/index.d.ts +8 -0
- package/lib/packlets/file-tree/index.d.ts.map +1 -0
- package/lib/packlets/file-tree/index.js +46 -0
- package/lib/packlets/file-tree/index.js.map +1 -0
- package/lib/packlets/hash/crcNormalizer.js +1 -1
- package/lib/packlets/hash/crcNormalizer.js.map +1 -1
- package/package.json +15 -15
- package/lib/packlets/collections/collectorConverter.d.ts +0 -59
- package/lib/packlets/collections/collectorConverter.d.ts.map +0 -1
- package/lib/packlets/collections/collectorConverter.js.map +0 -1
- package/lib/packlets/collections/collectors.d.ts +0 -32
- package/lib/packlets/collections/collectors.d.ts.map +0 -1
- package/lib/packlets/collections/collectors.js +0 -57
- package/lib/packlets/collections/collectors.js.map +0 -1
- package/lib/packlets/collections/convertingResultMap.d.ts +0 -73
- package/lib/packlets/collections/convertingResultMap.d.ts.map +0 -1
- package/lib/packlets/collections/convertingResultMap.js +0 -102
- package/lib/packlets/collections/convertingResultMap.js.map +0 -1
package/dist/tsdoc-metadata.json
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as Collections from './packlets/collections';
|
|
2
2
|
import * as Conversion from './packlets/conversion';
|
|
3
3
|
import * as Hash from './packlets/hash';
|
|
4
|
+
import * as FileTree from './packlets/file-tree';
|
|
4
5
|
import * as Validation from './packlets/validation';
|
|
5
|
-
import {
|
|
6
|
+
import { Collector, ICollectible, ConvertingCollector, IReadOnlyResultMap, ResultMap, ValidatingCollector, ValidatingConvertingCollector, ValidatingResultMap } from './packlets/collections';
|
|
6
7
|
import { Converter, Converters, ObjectConverter, StringConverter } from './packlets/conversion';
|
|
7
8
|
import { Validator, Validators } from './packlets/validation';
|
|
8
9
|
export * from './packlets/base';
|
|
9
|
-
export { Collections, Collector, Conversion, Converter, Converters, Hash,
|
|
10
|
+
export { Collections, Collector, ConvertingCollector, Conversion, Converter, Converters, FileTree, Hash, ICollectible, IReadOnlyResultMap, ObjectConverter, ResultMap, StringConverter, ValidatingCollector, ValidatingConvertingCollector, ValidatingResultMap, Validation, Validator, Validators };
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AACjD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EACL,SAAS,EACT,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,SAAS,EACT,mBAAmB,EACnB,6BAA6B,EAC7B,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE9D,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,WAAW,EACX,SAAS,EACT,mBAAmB,EACnB,UAAU,EACV,SAAS,EACT,UAAU,EACV,QAAQ,EACR,IAAI,EACJ,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,6BAA6B,EAC7B,mBAAmB,EACnB,UAAU,EACV,SAAS,EACT,UAAU,EACX,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -57,20 +57,24 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
57
57
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
58
58
|
};
|
|
59
59
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
-
exports.Validators = exports.Validation = exports.
|
|
60
|
+
exports.Validators = exports.Validation = exports.ValidatingResultMap = exports.ValidatingConvertingCollector = exports.ValidatingCollector = exports.StringConverter = exports.ResultMap = exports.ObjectConverter = exports.Hash = exports.FileTree = exports.Converters = exports.Conversion = exports.ConvertingCollector = exports.Collector = exports.Collections = void 0;
|
|
61
61
|
const Collections = __importStar(require("./packlets/collections"));
|
|
62
62
|
exports.Collections = Collections;
|
|
63
63
|
const Conversion = __importStar(require("./packlets/conversion"));
|
|
64
64
|
exports.Conversion = Conversion;
|
|
65
65
|
const Hash = __importStar(require("./packlets/hash"));
|
|
66
66
|
exports.Hash = Hash;
|
|
67
|
+
const FileTree = __importStar(require("./packlets/file-tree"));
|
|
68
|
+
exports.FileTree = FileTree;
|
|
67
69
|
const Validation = __importStar(require("./packlets/validation"));
|
|
68
70
|
exports.Validation = Validation;
|
|
69
71
|
const collections_1 = require("./packlets/collections");
|
|
70
72
|
Object.defineProperty(exports, "Collector", { enumerable: true, get: function () { return collections_1.Collector; } });
|
|
73
|
+
Object.defineProperty(exports, "ConvertingCollector", { enumerable: true, get: function () { return collections_1.ConvertingCollector; } });
|
|
71
74
|
Object.defineProperty(exports, "ResultMap", { enumerable: true, get: function () { return collections_1.ResultMap; } });
|
|
72
|
-
Object.defineProperty(exports, "
|
|
73
|
-
Object.defineProperty(exports, "
|
|
75
|
+
Object.defineProperty(exports, "ValidatingCollector", { enumerable: true, get: function () { return collections_1.ValidatingCollector; } });
|
|
76
|
+
Object.defineProperty(exports, "ValidatingConvertingCollector", { enumerable: true, get: function () { return collections_1.ValidatingConvertingCollector; } });
|
|
77
|
+
Object.defineProperty(exports, "ValidatingResultMap", { enumerable: true, get: function () { return collections_1.ValidatingResultMap; } });
|
|
74
78
|
const conversion_1 = require("./packlets/conversion");
|
|
75
79
|
Object.defineProperty(exports, "Converters", { enumerable: true, get: function () { return conversion_1.Converters; } });
|
|
76
80
|
Object.defineProperty(exports, "ObjectConverter", { enumerable: true, get: function () { return conversion_1.ObjectConverter; } });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oEAAsD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oEAAsD;AAqBpD,kCAAW;AApBb,kEAAoD;AAuBlD,gCAAU;AAtBZ,sDAAwC;AA0BtC,oBAAI;AAzBN,+DAAiD;AAwB/C,4BAAQ;AAvBV,kEAAoD;AAiClD,gCAAU;AA/BZ,wDASgC;AAO9B,0FAfA,uBAAS,OAeA;AACT,oGAdA,iCAAmB,OAcA;AASnB,0FArBA,uBAAS,OAqBA;AAET,oGAtBA,iCAAmB,OAsBA;AACnB,8GAtBA,2CAA6B,OAsBA;AAC7B,oGAtBA,iCAAmB,OAsBA;AApBrB,sDAAgG;AAU9F,2FAVkB,uBAAU,OAUlB;AAKV,gGAf8B,4BAAe,OAe9B;AAEf,gGAjB+C,4BAAe,OAiB/C;AAhBjB,sDAA8D;AAsB5D,2FAtBkB,uBAAU,OAsBlB;AApBZ,kDAAgC","sourcesContent":["/*\n * Copyright (c) 2020 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 * as Collections from './packlets/collections';\nimport * as Conversion from './packlets/conversion';\nimport * as Hash from './packlets/hash';\nimport * as FileTree from './packlets/file-tree';\nimport * as Validation from './packlets/validation';\n\nimport {\n Collector,\n ICollectible,\n ConvertingCollector,\n IReadOnlyResultMap,\n ResultMap,\n ValidatingCollector,\n ValidatingConvertingCollector,\n ValidatingResultMap\n} from './packlets/collections';\nimport { Converter, Converters, ObjectConverter, StringConverter } from './packlets/conversion';\nimport { Validator, Validators } from './packlets/validation';\n\nexport * from './packlets/base';\nexport {\n Collections,\n Collector,\n ConvertingCollector,\n Conversion,\n Converter,\n Converters,\n FileTree,\n Hash,\n ICollectible,\n IReadOnlyResultMap,\n ObjectConverter,\n ResultMap,\n StringConverter,\n ValidatingCollector,\n ValidatingConvertingCollector,\n ValidatingResultMap,\n Validation,\n Validator,\n Validators\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAiB,MAAM,UAAU,CAAC;AAEjD;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],"mappings":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MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC;YACpC,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAA,aAAI,EAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAA,gBAAO,EAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CACjC,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAA,gBAAO,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,gCAAgC,CAC9C,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAA,gBAAO,EAAC,EAAoB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/*\r\n * Copyright (c) 2020 Erik Fortune\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\nimport { Result, fail, succeed } from './result';\r\n\r\n/**\r\n * Helper type-guard function to report whether a specified key is present in\r\n * a supplied object.\r\n * @param key - The key to be tested.\r\n * @param item - The object to be tested.\r\n * @returns Returns `true` if the key is present, `false` otherwise.\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/ban-types\r\nexport function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T {\r\n return item.hasOwnProperty(key);\r\n}\r\n\r\n/**\r\n * Simple implicit pick function, which picks a set of properties from a supplied\r\n * object. Ignores picked properties that do not exist regardless of type signature.\r\n * @param from - The object from which keys are to be picked.\r\n * @param include - The keys of the properties to be picked from `from`.\r\n * @returns A new object containing the requested properties from `from`, where present.\r\n * @public\r\n */\r\nexport function pick<T extends object, K extends keyof T>(from: T, include: K[]): Pick<T, K> {\r\n const rtrn: Partial<Pick<T, K>> = {};\r\n for (const key of include) {\r\n if (key in from) {\r\n rtrn[key] = from[key];\r\n }\r\n }\r\n return rtrn as Pick<T, K>;\r\n}\r\n\r\n/**\r\n * Simple implicit omit function, which picks all of the properties from a supplied\r\n * object except those specified for exclusion.\r\n * @param from - The object from which keys are to be picked.\r\n * @param exclude - The keys of the properties to be excluded from the returned object.\r\n * @returns A new object containing all of the properties from `from` that were not\r\n * explicitly excluded.\r\n * @public\r\n */\r\nexport function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K> {\r\n const rtrn: Partial<Omit<T, K>> = {};\r\n for (const entry of Object.entries(from).filter((e) => !exclude.includes(e[0] as keyof T as K))) {\r\n rtrn[entry[0] as unknown as keyof Omit<T, K>] = entry[1];\r\n }\r\n\r\n return rtrn as Omit<T, K>;\r\n}\r\n\r\n/**\r\n * Gets the value of a property specified by key from an arbitrary object,\r\n * or a default value if the property does not exist.\r\n * @param key - The key specifying the property to be retrieved.\r\n * @param item - The object from which the property is to be retrieved.\r\n * @param defaultValue - An optional default value to be returned if the property\r\n * is not present (default `undefined`).\r\n * @returns The value of the requested property, or the default value if the\r\n * requested property does not exist.\r\n * @public\r\n */\r\nexport function getValueOfPropertyOrDefault<T extends object>(\r\n key: string | number | symbol,\r\n item: T,\r\n defaultValue?: unknown\r\n): unknown | undefined {\r\n return isKeyOf(key, item) ? item[key] : defaultValue;\r\n}\r\n\r\n/**\r\n * Gets the type of a property specified by key from an arbitrary object.\r\n * @param key - The key specifying the property to be tested.\r\n * @param item - The object from which the property is to be tested.\r\n * @returns The type of the requested property, or `undefined` if the\r\n * property does not exist.\r\n * @example\r\n * Returns `'undefined'` (a string) if the property exists but has the value\r\n * undefined but `undefined` (the literal) if the property does not exist.\r\n * @public\r\n */\r\nexport function getTypeOfProperty<T extends object>(\r\n key: string | number | symbol,\r\n item: T\r\n):\r\n | 'string'\r\n | 'number'\r\n | 'bigint'\r\n | 'boolean'\r\n | 'symbol'\r\n | 'undefined'\r\n | 'undefined'\r\n | 'object'\r\n | 'function'\r\n | undefined {\r\n return isKeyOf(key, item) ? typeof item[key] : undefined;\r\n}\r\n\r\n/**\r\n * Type for factory methods which convert a key-value pair to a new unique value.\r\n * @public\r\n */\r\ntype KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;\r\n\r\n/**\r\n * Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.\r\n * @param src - The `Record` to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map on success, or {@link Failure} with a\r\n * message if an error occurs.\r\n * @public\r\n */\r\nexport function recordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n const map = new Map<TK, TD>();\r\n for (const key in src) {\r\n if (src[key] !== undefined) {\r\n const itemResult = factory(key, src[key]);\r\n if (itemResult.isSuccess()) {\r\n map.set(key, itemResult.value);\r\n } else {\r\n return fail(`${key}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(map);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.\r\n * @param src - The `Record` to be converted, or undefined.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`\r\n * if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`\r\n * @param src - The `Record` to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n return src === undefined ? succeed(new Map<TK, TD>()) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.\r\n * @param src - The `Map` object to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or\r\n * {@link Failure} with an error message if an error occurs.\r\n * @public\r\n */\r\nexport function mapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n const record: Record<TK, TD> = {} as Record<TK, TD>;\r\n for (const kvp of src) {\r\n if (kvp[1] !== undefined) {\r\n const itemResult = factory(kvp[0], kvp[1]);\r\n if (itemResult.isSuccess()) {\r\n record[kvp[0]] = itemResult.value;\r\n } else {\r\n return fail(`${kvp[0]}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(record);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.\r\n * @param src - The `Map` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if\r\n * `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : mapToRecord(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`\r\n * @param src - The `ReadonlyMap` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n return src === undefined ? succeed({} as Record<TK, TD>) : mapToRecord(src, factory);\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../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AE,OAAO,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/*\r\n * Copyright (c) 2020 Erik Fortune\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\nimport { Result, fail, succeed } from './result';\r\n\r\n/**\r\n * Helper type-guard function to report whether a specified key is present in\r\n * a supplied object.\r\n * @param key - The key to be tested.\r\n * @param item - The object to be tested.\r\n * @returns Returns `true` if the key is present, `false` otherwise.\r\n * @public\r\n */\r\nexport function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T {\r\n return item.hasOwnProperty(key);\r\n}\r\n\r\n/**\r\n * Simple implicit pick function, which picks a set of properties from a supplied\r\n * object. Ignores picked properties that do not exist regardless of type signature.\r\n * @param from - The object from which keys are to be picked.\r\n * @param include - The keys of the properties to be picked from `from`.\r\n * @returns A new object containing the requested properties from `from`, where present.\r\n * @public\r\n */\r\nexport function pick<T extends object, K extends keyof T>(from: T, include: K[]): Pick<T, K> {\r\n const rtrn: Partial<Pick<T, K>> = {};\r\n for (const key of include) {\r\n if (key in from) {\r\n rtrn[key] = from[key];\r\n }\r\n }\r\n return rtrn as Pick<T, K>;\r\n}\r\n\r\n/**\r\n * Simple implicit omit function, which picks all of the properties from a supplied\r\n * object except those specified for exclusion.\r\n * @param from - The object from which keys are to be picked.\r\n * @param exclude - The keys of the properties to be excluded from the returned object.\r\n * @returns A new object containing all of the properties from `from` that were not\r\n * explicitly excluded.\r\n * @public\r\n */\r\nexport function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K> {\r\n const rtrn: Partial<Omit<T, K>> = {};\r\n for (const entry of Object.entries(from).filter((e) => !exclude.includes(e[0] as keyof T as K))) {\r\n rtrn[entry[0] as unknown as keyof Omit<T, K>] = entry[1];\r\n }\r\n\r\n return rtrn as Omit<T, K>;\r\n}\r\n\r\n/**\r\n * Gets the value of a property specified by key from an arbitrary object,\r\n * or a default value if the property does not exist.\r\n * @param key - The key specifying the property to be retrieved.\r\n * @param item - The object from which the property is to be retrieved.\r\n * @param defaultValue - An optional default value to be returned if the property\r\n * is not present (default `undefined`).\r\n * @returns The value of the requested property, or the default value if the\r\n * requested property does not exist.\r\n * @public\r\n */\r\nexport function getValueOfPropertyOrDefault<T extends object>(\r\n key: string | number | symbol,\r\n item: T,\r\n defaultValue?: unknown\r\n): unknown | undefined {\r\n return isKeyOf(key, item) ? item[key] : defaultValue;\r\n}\r\n\r\n/**\r\n * Gets the type of a property specified by key from an arbitrary object.\r\n * @param key - The key specifying the property to be tested.\r\n * @param item - The object from which the property is to be tested.\r\n * @returns The type of the requested property, or `undefined` if the\r\n * property does not exist.\r\n * @example\r\n * Returns `'undefined'` (a string) if the property exists but has the value\r\n * undefined but `undefined` (the literal) if the property does not exist.\r\n * @public\r\n */\r\nexport function getTypeOfProperty<T extends object>(\r\n key: string | number | symbol,\r\n item: T\r\n):\r\n | 'string'\r\n | 'number'\r\n | 'bigint'\r\n | 'boolean'\r\n | 'symbol'\r\n | 'undefined'\r\n | 'undefined'\r\n | 'object'\r\n | 'function'\r\n | undefined {\r\n return isKeyOf(key, item) ? typeof item[key] : undefined;\r\n}\r\n\r\n/**\r\n * Type for factory methods which convert a key-value pair to a new unique value.\r\n * @public\r\n */\r\ntype KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;\r\n\r\n/**\r\n * Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.\r\n * @param src - The `Record` to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map on success, or {@link Failure} with a\r\n * message if an error occurs.\r\n * @public\r\n */\r\nexport function recordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n const map = new Map<TK, TD>();\r\n for (const key in src) {\r\n if (src[key] !== undefined) {\r\n const itemResult = factory(key, src[key]);\r\n if (itemResult.isSuccess()) {\r\n map.set(key, itemResult.value);\r\n } else {\r\n return fail(`${key}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(map);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.\r\n * @param src - The `Record` to be converted, or undefined.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`\r\n * if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`\r\n * @param src - The `Record` to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n return src === undefined ? succeed(new Map<TK, TD>()) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.\r\n * @param src - The `Map` object to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or\r\n * {@link Failure} with an error message if an error occurs.\r\n * @public\r\n */\r\nexport function mapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n const record: Record<TK, TD> = {} as Record<TK, TD>;\r\n for (const kvp of src) {\r\n if (kvp[1] !== undefined) {\r\n const itemResult = factory(kvp[0], kvp[1]);\r\n if (itemResult.isSuccess()) {\r\n record[kvp[0]] = itemResult.value;\r\n } else {\r\n return fail(`${kvp[0]}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(record);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.\r\n * @param src - The `Map` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if\r\n * `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : mapToRecord(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`\r\n * @param src - The `ReadonlyMap` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n return src === undefined ? succeed({} as Record<TK, TD>) : mapToRecord(src, factory);\r\n}\r\n"]}
|
|
@@ -1,24 +1,60 @@
|
|
|
1
1
|
import { Result } from '../base';
|
|
2
|
+
import { Converter, ConverterFunc } from '../conversion';
|
|
3
|
+
import { Validator } from '../validation';
|
|
2
4
|
/**
|
|
3
|
-
* An item that can be collected by some {@link
|
|
5
|
+
* An item that can be collected by some {@link ConvertingCollector | Collector}.
|
|
4
6
|
* @public
|
|
5
7
|
*/
|
|
6
8
|
export interface ICollectible<TKEY extends string = string, TINDEX extends number = number> {
|
|
7
9
|
readonly key: TKEY;
|
|
8
10
|
readonly index: TINDEX | undefined;
|
|
9
|
-
setIndex(index:
|
|
11
|
+
setIndex(index: number): Result<TINDEX>;
|
|
10
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Infer the key type from an {@link Collections.ICollectible | ICollectible} type.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export type CollectibleKey<TITEM extends ICollectible> = TITEM extends ICollectible<infer TKEY> ? TKEY : never;
|
|
18
|
+
/**
|
|
19
|
+
* Infer the index type from an {@link Collections.ICollectible | ICollectible} type.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export type CollectibleIndex<TITEM extends ICollectible> = TITEM extends ICollectible<any, infer TINDEX> ? TINDEX : never;
|
|
11
23
|
/**
|
|
12
24
|
* Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key, an index and a source representation
|
|
13
25
|
* of the item to be added.
|
|
14
26
|
* @public
|
|
15
27
|
*/
|
|
16
|
-
export type CollectibleFactory<
|
|
28
|
+
export type CollectibleFactory<TITEM extends ICollectible<any, any>, TSRC> = (key: CollectibleKey<TITEM>, index: number, item: TSRC) => Result<TITEM>;
|
|
17
29
|
/**
|
|
18
30
|
* Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key and an index.
|
|
19
31
|
* @public
|
|
20
32
|
*/
|
|
21
|
-
export type CollectibleFactoryCallback<
|
|
33
|
+
export type CollectibleFactoryCallback<TITEM extends ICollectible<any, any>> = (key: CollectibleKey<TITEM>, index: number) => Result<TITEM>;
|
|
34
|
+
/**
|
|
35
|
+
* Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance with
|
|
36
|
+
* a defined, strongly-typed index.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export interface ICollectibleConstructorParamsWithIndex<TKEY extends string = string, TINDEX extends number = number> {
|
|
40
|
+
key: TKEY;
|
|
41
|
+
index: TINDEX;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance with an
|
|
45
|
+
* index converter.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export interface ICollectibleConstructorParamsWithConverter<TKEY extends string = string, TINDEX extends number = number> {
|
|
49
|
+
key: TKEY;
|
|
50
|
+
index?: number;
|
|
51
|
+
indexConverter: Validator<TINDEX, unknown> | Converter<TINDEX, unknown> | ConverterFunc<TINDEX, undefined>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export type ICollectibleConstructorParams<TKEY extends string = string, TINDEX extends number = number> = ICollectibleConstructorParamsWithIndex<TKEY, TINDEX> | ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>;
|
|
22
58
|
/**
|
|
23
59
|
* Simple implementation of {@link Collections.ICollectible | ICollectible} which does not allow the index to be
|
|
24
60
|
* changed once set.
|
|
@@ -34,15 +70,53 @@ export declare class Collectible<TKEY extends string = string, TINDEX extends nu
|
|
|
34
70
|
*/
|
|
35
71
|
get index(): TINDEX | undefined;
|
|
36
72
|
protected _index: TINDEX | undefined;
|
|
73
|
+
protected readonly _indexConverter?: Validator<TINDEX, unknown> | Converter<TINDEX, unknown>;
|
|
74
|
+
/**
|
|
75
|
+
* Constructs a new {@link Collections.Collectible | Collectible} instance
|
|
76
|
+
* with a defined, strongly-typed index.
|
|
77
|
+
* @param params - {@link Collections.ICollectibleConstructorParamsWithIndex | Parameters} for constructing
|
|
78
|
+
* the collectible.
|
|
79
|
+
*/
|
|
80
|
+
constructor(params: ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>);
|
|
81
|
+
/**
|
|
82
|
+
* Constructs a new {@link Collections.Collectible | Collectible} instance with
|
|
83
|
+
* an undefined index and an index converter to validate te index when it is set.
|
|
84
|
+
* @param params - {@link Collections.ICollectibleConstructorParamsWithConverter | Parameters} for constructing
|
|
85
|
+
* the collectible.
|
|
86
|
+
*/
|
|
87
|
+
constructor(params: ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>);
|
|
37
88
|
/**
|
|
38
89
|
* Constructs a new {@link Collections.Collectible | Collectible} instance.
|
|
39
|
-
* @param
|
|
40
|
-
*
|
|
90
|
+
* @param params - {@link Collections.ICollectibleConstructorParams | Parameters} for constructing
|
|
91
|
+
* the collectible.
|
|
92
|
+
*/
|
|
93
|
+
constructor(params: ICollectibleConstructorParams<TKEY, TINDEX>);
|
|
94
|
+
/**
|
|
95
|
+
* Creates a new {@link Collections.Collectible | Collectible} instance with a defined, strongly-typed index.
|
|
96
|
+
* @param params - {@link Collections.ICollectibleConstructorParamsWithIndex | Parameters} for constructing
|
|
97
|
+
* the collectible.
|
|
98
|
+
* @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise.
|
|
99
|
+
*/
|
|
100
|
+
static createCollectible<TKEY extends string = string, TINDEX extends number = number>(params: ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>): Result<Collectible<TKEY, TINDEX>>;
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new {@link Collections.Collectible | Collectible} instance with an undefined index and an index
|
|
103
|
+
* converter to validate the index when it is set.
|
|
104
|
+
* @param params - {@link Collections.ICollectibleConstructorParamsWithConverter | Parameters} for constructing
|
|
105
|
+
* the collectible.
|
|
106
|
+
* @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise.
|
|
107
|
+
*/
|
|
108
|
+
static createCollectible<TKEY extends string = string, TINDEX extends number = number>(params: ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>): Result<Collectible<TKEY, TINDEX>>;
|
|
109
|
+
/**
|
|
110
|
+
* Creates a new {@link Collections.Collectible | Collectible} instance.
|
|
111
|
+
* @param params - {@link Collections.ICollectibleConstructorParams | Parameters} for constructing
|
|
112
|
+
* the collectible.
|
|
113
|
+
* @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise
|
|
114
|
+
* @public
|
|
41
115
|
*/
|
|
42
|
-
|
|
116
|
+
static createCollectible<TKEY extends string = string, TINDEX extends number = number>(params: ICollectibleConstructorParams<TKEY, TINDEX>): Result<Collectible<TKEY, TINDEX>>;
|
|
43
117
|
/**
|
|
44
118
|
* {@link Collections.ICollectible.setIndex}
|
|
45
119
|
*/
|
|
46
|
-
setIndex(index:
|
|
120
|
+
setIndex(index: number): Result<TINDEX>;
|
|
47
121
|
}
|
|
48
122
|
//# sourceMappingURL=collectible.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collectible.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/collectible.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"collectible.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AC,IAAI,EAAE,MAAM,CAAC;IAE/E;;;;;OAKG;gBACgB,MAAM,EAAE,0CAA0C,CAAC,IAAI,EAAE,MAAM,CAAC;IAEnF;;;;OAIG;gBACgB,MAAM,EAAE,6BAA6B,CAAC,IAAI,EAAE,MAAM,CAAC;IAgBtE;;;;;OAKG;WACW,iBAAiB,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM,EAC1F,MAAM,EAAE,sCAAsC,CAAC,IAAI,EAAE,MAAM,CAAC,GAC3D,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAEpC;;;;;;OAMG;WACW,iBAAiB,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM,EAC1F,MAAM,EAAE,0CAA0C,CAAC,IAAI,EAAE,MAAM,CAAC,GAC/D,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAEpC;;;;;;OAMG;WACW,iBAAiB,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM,EAC1F,MAAM,EAAE,6BAA6B,CAAC,IAAI,EAAE,MAAM,CAAC,GAClD,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAQpC;;OAEG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;CAwB/C"}
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.Collectible = void 0;
|
|
25
25
|
const base_1 = require("../base");
|
|
26
|
+
const conversion_1 = require("../conversion");
|
|
26
27
|
/**
|
|
27
28
|
* Simple implementation of {@link Collections.ICollectible | ICollectible} which does not allow the index to be
|
|
28
29
|
* changed once set.
|
|
@@ -35,24 +36,48 @@ class Collectible {
|
|
|
35
36
|
get index() {
|
|
36
37
|
return this._index;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
constructor(params) {
|
|
40
|
+
this.key = params.key;
|
|
41
|
+
if ('indexConverter' in params) {
|
|
42
|
+
this._indexConverter =
|
|
43
|
+
typeof params.indexConverter === 'function'
|
|
44
|
+
? conversion_1.Converters.generic(params.indexConverter)
|
|
45
|
+
: params.indexConverter;
|
|
46
|
+
if (params.index !== undefined) {
|
|
47
|
+
this._index = this._indexConverter.convert(params.index).orThrow();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this._index = params.index;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static createCollectible(params) {
|
|
55
|
+
return (0, base_1.captureResult)(() => new Collectible(params));
|
|
46
56
|
}
|
|
47
57
|
/**
|
|
48
58
|
* {@link Collections.ICollectible.setIndex}
|
|
49
59
|
*/
|
|
50
60
|
setIndex(index) {
|
|
51
|
-
|
|
61
|
+
let converted;
|
|
62
|
+
if (this._indexConverter) {
|
|
63
|
+
const { value, message } = this._indexConverter.convert(index);
|
|
64
|
+
if (message) {
|
|
65
|
+
return (0, base_1.fail)(message);
|
|
66
|
+
}
|
|
67
|
+
converted = value;
|
|
68
|
+
}
|
|
69
|
+
if (index === this.index) {
|
|
70
|
+
return (0, base_1.succeed)(this.index);
|
|
71
|
+
}
|
|
72
|
+
else if (this._index !== undefined) {
|
|
52
73
|
return (0, base_1.fail)(`index ${this.index} is immutable and cannot be changed to ${index}`);
|
|
53
74
|
}
|
|
54
|
-
|
|
55
|
-
|
|
75
|
+
/* c8 ignore next 3 - should be impossible */
|
|
76
|
+
if (converted === undefined) {
|
|
77
|
+
return (0, base_1.fail)(`index ${index} cannot be set on a Collectible without an index converter`);
|
|
78
|
+
}
|
|
79
|
+
this._index = converted;
|
|
80
|
+
return (0, base_1.succeed)(converted);
|
|
56
81
|
}
|
|
57
82
|
}
|
|
58
83
|
exports.Collectible = Collectible;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collectible.js","sourceRoot":"","sources":["../../../src/packlets/collections/collectible.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAgD;AAkChD;;;;GAIG;AACH,MAAa,WAAW;IAQtB;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAID;;;;OAIG;IACH,YAAmB,GAAS,EAAE,KAAc;QAC1C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,KAAa;QAC3B,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;YACtD,OAAO,IAAA,WAAI,EAAC,SAAS,IAAI,CAAC,KAAK,0CAA0C,KAAK,EAAE,CAAC,CAAC;QACpF,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF;AArCD,kCAqCC","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, fail, succeed } from '../base';\n\n/**\n * An item that can be collected by some {@link Collector | Collector}.\n * @public\n */\nexport interface ICollectible<TKEY extends string = string, TINDEX extends number = number> {\n readonly key: TKEY;\n readonly index: TINDEX | undefined;\n setIndex(index: TINDEX): Result<TINDEX>;\n}\n\n/**\n * Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key, an index and a source representation\n * of the item to be added.\n * @public\n */\nexport type CollectibleFactory<\n TKEY extends string = string,\n TINDEX extends number = number,\n TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>,\n TSRC = TITEM\n> = (key: TKEY, index: number, item: TSRC) => Result<TITEM>;\n\n/**\n * Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key and an index.\n * @public\n */\nexport type CollectibleFactoryCallback<\n TKEY extends string = string,\n TINDEX extends number = number,\n TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>\n> = (key: TKEY, index: number) => Result<TITEM>;\n\n/**\n * Simple implementation of {@link Collections.ICollectible | ICollectible} which does not allow the index to be\n * changed once set.\n * @public\n */\nexport class Collectible<TKEY extends string = string, TINDEX extends number = number>\n implements ICollectible<TKEY, TINDEX>\n{\n /**\n * {@link Collections.ICollectible.key}\n */\n public readonly key: TKEY;\n\n /**\n * {@link Collections.ICollectible.index}\n */\n public get index(): TINDEX | undefined {\n return this._index;\n }\n\n protected _index: TINDEX | undefined;\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance.\n * @param key - The key of the item to be collected.\n * @param index - Optional index of the item to be collected.\n */\n public constructor(key: TKEY, index?: TINDEX) {\n this.key = key;\n this._index = index;\n }\n\n /**\n * {@link Collections.ICollectible.setIndex}\n */\n public setIndex(index: TINDEX): Result<TINDEX> {\n if (this._index !== undefined && index !== this.index) {\n return fail(`index ${this.index} is immutable and cannot be changed to ${index}`);\n }\n this._index = index;\n return succeed(this._index);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"collectible.js","sourceRoot":"","sources":["../../../src/packlets/collections/collectible.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAA+D;AAC/D,8CAAqE;AAuFrE;;;;GAIG;AACH,MAAa,WAAW;IAQtB;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IA2BD,YAAmB,MAAmD;QACpE,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,IAAI,gBAAgB,IAAI,MAAM,EAAE,CAAC;YAC/B,IAAI,CAAC,eAAe;gBAClB,OAAO,MAAM,CAAC,cAAc,KAAK,UAAU;oBACzC,CAAC,CAAC,uBAAU,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;oBAC3C,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;YAC5B,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;YACrE,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC7B,CAAC;IACH,CAAC;IAkCM,MAAM,CAAC,iBAAiB,CAC7B,MAAmD;QAEnD,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,KAAa;QAC3B,IAAI,SAA6B,CAAC;QAClC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC/D,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,IAAA,WAAI,EAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YACD,SAAS,GAAG,KAAK,CAAC;QACpB,CAAC;QAED,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;YACzB,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;aAAM,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACrC,OAAO,IAAA,WAAI,EAAC,SAAS,IAAI,CAAC,KAAK,0CAA0C,KAAK,EAAE,CAAC,CAAC;QACpF,CAAC;QAED,6CAA6C;QAC7C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,IAAA,WAAI,EAAC,SAAS,KAAK,4DAA4D,CAAC,CAAC;QAC1F,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,OAAO,IAAA,cAAO,EAAC,SAAS,CAAC,CAAC;IAC5B,CAAC;CACF;AAxHD,kCAwHC","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, fail, succeed } from '../base';\nimport { Converter, ConverterFunc, Converters } from '../conversion';\nimport { Validator } from '../validation';\n\n/**\n * An item that can be collected by some {@link ConvertingCollector | Collector}.\n * @public\n */\nexport interface ICollectible<TKEY extends string = string, TINDEX extends number = number> {\n readonly key: TKEY;\n readonly index: TINDEX | undefined;\n setIndex(index: number): Result<TINDEX>;\n}\n\n/**\n * Infer the key type from an {@link Collections.ICollectible | ICollectible} type.\n * @public\n */\nexport type CollectibleKey<TITEM extends ICollectible> = TITEM extends ICollectible<infer TKEY>\n ? TKEY\n : never;\n\n/**\n * Infer the index type from an {@link Collections.ICollectible | ICollectible} type.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CollectibleIndex<TITEM extends ICollectible> = TITEM extends ICollectible<any, infer TINDEX>\n ? TINDEX\n : never;\n\n/**\n * Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key, an index and a source representation\n * of the item to be added.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CollectibleFactory<TITEM extends ICollectible<any, any>, TSRC> = (\n key: CollectibleKey<TITEM>,\n index: number,\n item: TSRC\n) => Result<TITEM>;\n\n/**\n * Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key and an index.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CollectibleFactoryCallback<TITEM extends ICollectible<any, any>> = (\n key: CollectibleKey<TITEM>,\n index: number\n) => Result<TITEM>;\n\n/**\n * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance with\n * a defined, strongly-typed index.\n * @public\n */\nexport interface ICollectibleConstructorParamsWithIndex<\n TKEY extends string = string,\n TINDEX extends number = number\n> {\n key: TKEY;\n index: TINDEX;\n}\n\n/**\n * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance with an\n * index converter.\n * @public\n */\nexport interface ICollectibleConstructorParamsWithConverter<\n TKEY extends string = string,\n TINDEX extends number = number\n> {\n key: TKEY;\n index?: number;\n indexConverter: Validator<TINDEX, unknown> | Converter<TINDEX, unknown> | ConverterFunc<TINDEX, undefined>;\n}\n\n/**\n * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance.\n * @public\n */\nexport type ICollectibleConstructorParams<TKEY extends string = string, TINDEX extends number = number> =\n | ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>\n | ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>;\n\n/**\n * Simple implementation of {@link Collections.ICollectible | ICollectible} which does not allow the index to be\n * changed once set.\n * @public\n */\nexport class Collectible<TKEY extends string = string, TINDEX extends number = number>\n implements ICollectible<TKEY, TINDEX>\n{\n /**\n * {@link Collections.ICollectible.key}\n */\n public readonly key: TKEY;\n\n /**\n * {@link Collections.ICollectible.index}\n */\n public get index(): TINDEX | undefined {\n return this._index;\n }\n\n protected _index: TINDEX | undefined;\n protected readonly _indexConverter?: Validator<TINDEX, unknown> | Converter<TINDEX, unknown>;\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance\n * with a defined, strongly-typed index.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithIndex | Parameters} for constructing\n * the collectible.\n */\n public constructor(params: ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>);\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance with\n * an undefined index and an index converter to validate te index when it is set.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithConverter | Parameters} for constructing\n * the collectible.\n */\n public constructor(params: ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>);\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance.\n * @param params - {@link Collections.ICollectibleConstructorParams | Parameters} for constructing\n * the collectible.\n */\n public constructor(params: ICollectibleConstructorParams<TKEY, TINDEX>);\n public constructor(params: ICollectibleConstructorParams<TKEY, TINDEX>) {\n this.key = params.key;\n if ('indexConverter' in params) {\n this._indexConverter =\n typeof params.indexConverter === 'function'\n ? Converters.generic(params.indexConverter)\n : params.indexConverter;\n if (params.index !== undefined) {\n this._index = this._indexConverter.convert(params.index).orThrow();\n }\n } else {\n this._index = params.index;\n }\n }\n\n /**\n * Creates a new {@link Collections.Collectible | Collectible} instance with a defined, strongly-typed index.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithIndex | Parameters} for constructing\n * the collectible.\n * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise.\n */\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>>;\n\n /**\n * Creates a new {@link Collections.Collectible | Collectible} instance with an undefined index and an index\n * converter to validate the index when it is set.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithConverter | Parameters} for constructing\n * the collectible.\n * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise.\n */\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>>;\n\n /**\n * Creates a new {@link Collections.Collectible | Collectible} instance.\n * @param params - {@link Collections.ICollectibleConstructorParams | Parameters} for constructing\n * the collectible.\n * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise\n * @public\n */\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParams<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>>;\n\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParams<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>> {\n return captureResult(() => new Collectible(params));\n }\n\n /**\n * {@link Collections.ICollectible.setIndex}\n */\n public setIndex(index: number): Result<TINDEX> {\n let converted: TINDEX | undefined;\n if (this._indexConverter) {\n const { value, message } = this._indexConverter.convert(index);\n if (message) {\n return fail(message);\n }\n converted = value;\n }\n\n if (index === this.index) {\n return succeed(this.index);\n } else if (this._index !== undefined) {\n return fail(`index ${this.index} is immutable and cannot be changed to ${index}`);\n }\n\n /* c8 ignore next 3 - should be impossible */\n if (converted === undefined) {\n return fail(`index ${index} cannot be set on a Collectible without an index converter`);\n }\n\n this._index = converted;\n return succeed(converted);\n }\n}\n"]}
|