@fgv/ts-utils 4.2.1 → 4.3.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 +24 -0
- package/CHANGELOG.md +15 -1
- package/dist/ts-utils.d.ts +3080 -2627
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -2
- package/lib/index.js.map +1 -1
- package/lib/packlets/base/messageAggregator.d.ts +4 -0
- package/lib/packlets/base/messageAggregator.d.ts.map +1 -1
- package/lib/packlets/base/messageAggregator.js +6 -0
- package/lib/packlets/base/messageAggregator.js.map +1 -1
- package/lib/packlets/base/result.d.ts +55 -0
- package/lib/packlets/base/result.d.ts.map +1 -1
- package/lib/packlets/base/result.js +32 -0
- package/lib/packlets/base/result.js.map +1 -1
- package/lib/packlets/collections/collectible.d.ts +48 -0
- package/lib/packlets/collections/collectible.d.ts.map +1 -0
- package/lib/packlets/collections/collectible.js +59 -0
- package/lib/packlets/collections/collectible.js.map +1 -0
- package/lib/packlets/collections/collector.d.ts +130 -0
- package/lib/packlets/collections/collector.d.ts.map +1 -0
- package/lib/packlets/collections/collector.js +147 -0
- package/lib/packlets/collections/collector.js.map +1 -0
- package/lib/packlets/collections/collectorConverter.d.ts +59 -0
- package/lib/packlets/collections/collectorConverter.d.ts.map +1 -0
- package/lib/packlets/collections/collectorConverter.js +86 -0
- package/lib/packlets/collections/collectorConverter.js.map +1 -0
- package/lib/packlets/collections/collectors.d.ts +32 -0
- package/lib/packlets/collections/collectors.d.ts.map +1 -0
- package/lib/packlets/collections/collectors.js +57 -0
- package/lib/packlets/collections/collectors.js.map +1 -0
- package/lib/packlets/collections/convertingCollector.d.ts +67 -0
- package/lib/packlets/collections/convertingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/convertingCollector.js +77 -0
- package/lib/packlets/collections/convertingCollector.js.map +1 -0
- package/lib/packlets/collections/{validatingResultMap.d.ts → convertingResultMap.d.ts} +18 -18
- package/lib/packlets/collections/convertingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/{validatingResultMap.js → convertingResultMap.js} +18 -18
- package/lib/packlets/collections/convertingResultMap.js.map +1 -0
- package/lib/packlets/collections/index.d.ts +8 -2
- package/lib/packlets/collections/index.d.ts.map +1 -1
- package/lib/packlets/collections/index.js +8 -2
- package/lib/packlets/collections/index.js.map +1 -1
- package/lib/packlets/collections/keyValueConverters.d.ts +90 -0
- package/lib/packlets/collections/keyValueConverters.d.ts.map +1 -0
- package/lib/packlets/collections/keyValueConverters.js +111 -0
- package/lib/packlets/collections/keyValueConverters.js.map +1 -0
- package/lib/packlets/collections/readonlyResultMap.d.ts +1 -1
- package/lib/packlets/collections/readonlyResultMap.d.ts.map +1 -1
- package/lib/packlets/collections/readonlyResultMap.js.map +1 -1
- package/lib/packlets/collections/{resultMapValidator.d.ts → resultMapConverter.d.ts} +14 -18
- package/lib/packlets/collections/resultMapConverter.d.ts.map +1 -0
- package/lib/packlets/collections/{resultMapValidator.js → resultMapConverter.js} +15 -15
- package/lib/packlets/collections/resultMapConverter.js.map +1 -0
- package/lib/packlets/collections/utils.d.ts +0 -61
- package/lib/packlets/collections/utils.d.ts.map +1 -1
- package/lib/packlets/collections/utils.js +0 -82
- package/lib/packlets/collections/utils.js.map +1 -1
- package/lib/packlets/conversion/baseConverter.d.ts +12 -7
- package/lib/packlets/conversion/baseConverter.d.ts.map +1 -1
- package/lib/packlets/conversion/baseConverter.js +12 -8
- package/lib/packlets/conversion/baseConverter.js.map +1 -1
- package/lib/packlets/conversion/converter.d.ts +6 -6
- package/lib/packlets/conversion/converter.d.ts.map +1 -1
- package/lib/packlets/conversion/converter.js.map +1 -1
- package/lib/packlets/conversion/converters.d.ts +8 -0
- package/lib/packlets/conversion/converters.d.ts.map +1 -1
- package/lib/packlets/conversion/converters.js +11 -0
- package/lib/packlets/conversion/converters.js.map +1 -1
- package/lib/packlets/conversion/objectConverter.d.ts +1 -1
- package/lib/packlets/conversion/objectConverter.d.ts.map +1 -1
- package/lib/packlets/conversion/objectConverter.js.map +1 -1
- package/lib/packlets/validation/common.d.ts +8 -0
- package/lib/packlets/validation/common.d.ts.map +1 -1
- package/lib/packlets/validation/common.js.map +1 -1
- package/lib/packlets/validation/genericValidator.d.ts +4 -6
- package/lib/packlets/validation/genericValidator.d.ts.map +1 -1
- package/lib/packlets/validation/genericValidator.js.map +1 -1
- package/lib/packlets/validation/number.d.ts.map +1 -1
- package/lib/packlets/validation/number.js +3 -1
- package/lib/packlets/validation/number.js.map +1 -1
- package/lib/packlets/validation/string.d.ts.map +1 -1
- package/lib/packlets/validation/string.js +3 -1
- package/lib/packlets/validation/string.js.map +1 -1
- package/lib/packlets/validation/validators.d.ts +12 -2
- package/lib/packlets/validation/validators.d.ts.map +1 -1
- package/lib/packlets/validation/validators.js +13 -0
- package/lib/packlets/validation/validators.js.map +1 -1
- package/package.json +1 -1
- package/lib/packlets/collections/resultMapValidator.d.ts.map +0 -1
- package/lib/packlets/collections/resultMapValidator.js.map +0 -1
- package/lib/packlets/collections/validatingResultMap.d.ts.map +0 -1
- package/lib/packlets/collections/validatingResultMap.js.map +0 -1
package/lib/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import * as Collections from './packlets/collections';
|
|
|
2
2
|
import * as Conversion from './packlets/conversion';
|
|
3
3
|
import * as Hash from './packlets/hash';
|
|
4
4
|
import * as Validation from './packlets/validation';
|
|
5
|
-
import { IReadOnlyResultMap, ResultMap,
|
|
5
|
+
import { ICollector, Collector, IReadOnlyResultMap, ResultMap, SimpleCollector, ConvertingResultMap } from './packlets/collections';
|
|
6
6
|
import { Converter, Converters, ObjectConverter, StringConverter } from './packlets/conversion';
|
|
7
7
|
import { Validator, Validators } from './packlets/validation';
|
|
8
8
|
export * from './packlets/base';
|
|
9
|
-
export { Collections, Conversion, Converter, Converters, Hash, IReadOnlyResultMap, ObjectConverter, ResultMap, StringConverter,
|
|
9
|
+
export { Collections, Collector, Conversion, Converter, Converters, Hash, ICollector, IReadOnlyResultMap, ObjectConverter, ResultMap, SimpleCollector, StringConverter, ConvertingResultMap, Validation, Validator, Validators };
|
|
10
10
|
//# 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,
|
|
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,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,SAAS,EACT,eAAe,EACf,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,UAAU,EACV,SAAS,EACT,UAAU,EACV,IAAI,EACJ,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,SAAS,EACT,UAAU,EACX,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -57,7 +57,7 @@ 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.ConvertingResultMap = exports.StringConverter = exports.SimpleCollector = exports.ResultMap = exports.ObjectConverter = exports.Hash = exports.Converters = exports.Conversion = 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"));
|
|
@@ -67,8 +67,10 @@ exports.Hash = Hash;
|
|
|
67
67
|
const Validation = __importStar(require("./packlets/validation"));
|
|
68
68
|
exports.Validation = Validation;
|
|
69
69
|
const collections_1 = require("./packlets/collections");
|
|
70
|
+
Object.defineProperty(exports, "Collector", { enumerable: true, get: function () { return collections_1.Collector; } });
|
|
70
71
|
Object.defineProperty(exports, "ResultMap", { enumerable: true, get: function () { return collections_1.ResultMap; } });
|
|
71
|
-
Object.defineProperty(exports, "
|
|
72
|
+
Object.defineProperty(exports, "SimpleCollector", { enumerable: true, get: function () { return collections_1.SimpleCollector; } });
|
|
73
|
+
Object.defineProperty(exports, "ConvertingResultMap", { enumerable: true, get: function () { return collections_1.ConvertingResultMap; } });
|
|
72
74
|
const conversion_1 = require("./packlets/conversion");
|
|
73
75
|
Object.defineProperty(exports, "Converters", { enumerable: true, get: function () { return conversion_1.Converters; } });
|
|
74
76
|
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;AAkBpD,kCAAW;AAjBb,kEAAoD;AAmBlD,gCAAU;AAlBZ,sDAAwC;AAqBtC,oBAAI;AApBN,kEAAoD;AA4BlD,gCAAU;AA1BZ,wDAOgC;AAO9B,0FAZA,uBAAS,OAYA;AAQT,0FAlBA,uBAAS,OAkBA;AACT,gGAlBA,6BAAe,OAkBA;AAEf,oGAnBA,iCAAmB,OAmBA;AAjBrB,sDAAgG;AAS9F,2FATkB,uBAAU,OASlB;AAIV,gGAb8B,4BAAe,OAa9B;AAGf,gGAhB+C,4BAAe,OAgB/C;AAfjB,sDAA8D;AAmB5D,2FAnBkB,uBAAU,OAmBlB;AAjBZ,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 Validation from './packlets/validation';\n\nimport {\n ICollector,\n Collector,\n IReadOnlyResultMap,\n ResultMap,\n SimpleCollector,\n ConvertingResultMap\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 Conversion,\n Converter,\n Converters,\n Hash,\n ICollector,\n IReadOnlyResultMap,\n ObjectConverter,\n ResultMap,\n SimpleCollector,\n StringConverter,\n ConvertingResultMap,\n Validation,\n Validator,\n Validators\n};\n"]}
|
|
@@ -17,6 +17,10 @@ export declare class MessageAggregator implements IMessageAggregator {
|
|
|
17
17
|
* {@inheritdoc IMessageAggregator.hasMessages}
|
|
18
18
|
*/
|
|
19
19
|
get hasMessages(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* {@inheritdoc IMessageAggregator.numMessages}
|
|
22
|
+
*/
|
|
23
|
+
get numMessages(): number;
|
|
20
24
|
/**
|
|
21
25
|
* {@inheritdoc IMessageAggregator.messages}
|
|
22
26
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageAggregator.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/messageAggregator.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAQ,MAAM,UAAU,CAAC;AAE5D;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,kBAAkB;IAC1D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IAErC;;;;;OAKG;gBACgB,MAAM,CAAC,EAAE,MAAM,EAAE;IAIpC;;OAEG;IACH,IAAW,WAAW,IAAI,OAAO,CAEhC;IAED;;OAEG;IACH,IAAW,QAAQ,IAAI,MAAM,E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AAC,CAAC;CAW3E"}
|
|
@@ -44,6 +44,12 @@ class MessageAggregator {
|
|
|
44
44
|
get hasMessages() {
|
|
45
45
|
return this._messages.length > 0;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* {@inheritdoc IMessageAggregator.numMessages}
|
|
49
|
+
*/
|
|
50
|
+
get numMessages() {
|
|
51
|
+
return this._messages.length;
|
|
52
|
+
}
|
|
47
53
|
/**
|
|
48
54
|
* {@inheritdoc IMessageAggregator.messages}
|
|
49
55
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageAggregator.js","sourceRoot":"","sources":["../../../src/packlets/base/messageAggregator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,qCAA4D;AAE5D;;;;GAIG;AACH,MAAa,iBAAiB;IAG5B;;;;;OAKG;IACH,YAAmB,MAAiB;QAClC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACI,UAAU,CAAC,OAA2B;QAC3C,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACI,WAAW,CAAC,QAA8B;QAC/C,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;QACnC,CAAC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CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;QACD,OAAO,IAAA,aAAI,EAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IACxC,CAAC;CACF;AA1FD,8CA0FC","sourcesContent":["/*\n * Copyright (c) 2024 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 { IMessageAggregator, Result, fail } from './result';\n\n/**\n * A simple error aggregator to simplify collecting and reporting all errors in\n * a flow.\n * @public\n */\nexport class MessageAggregator implements IMessageAggregator {\n private readonly _messages: string[];\n\n /**\n * Constructs a new {@link MessageAggregator | ErrorAggregator} with an\n * optionally specified initial set of error messages.\n * @param errors - optional array of errors to be included\n * in the aggregation.\n */\n public constructor(errors?: string[]) {\n this._messages = errors ? Array.from(errors) : [];\n }\n\n /**\n * {@inheritdoc IMessageAggregator.hasMessages}\n */\n public get hasMessages(): boolean {\n return this._messages.length > 0;\n }\n\n /**\n * {@inheritdoc IMessageAggregator.numMessages}\n */\n public get numMessages(): number {\n return this._messages.length;\n }\n\n /**\n * {@inheritdoc IMessageAggregator.messages}\n */\n public get messages(): string[] {\n return this._messages;\n }\n\n /**\n * {@inheritdoc IMessageAggregator.addMessage}\n */\n public addMessage(message: string | undefined): this {\n if (message) {\n this._messages.push(message);\n }\n return this;\n }\n\n /**\n * {@inheritdoc IMessageAggregator.addMessages}\n */\n public addMessages(messages: string[] | undefined): this {\n if (messages && messages.length > 0) {\n this._messages.push(...messages);\n }\n return this;\n }\n\n /**\n * {@inheritdoc IMessageAggregator.toString}\n */\n public toString(separator?: string): string {\n return this._messages.join(separator ?? '\\n');\n }\n\n /**\n * If any error messages have been aggregated, returns\n * {@link Failure | Failure<T>} with the aggregated\n * messages concatenated using the optionally-supplied\n * separator, or newline. If the supplied {@link Result | Result<T>}\n * contains an error message that has not already been aggregated,\n * it will be included in the aggregated messages.\n *\n * If no error messages have been aggregated, returns\n * the supplied {@link Result | Result<T>}.\n * @param result - The {@link Result | Result<T>} to be returned\n * if no messages have been aggregated.\n * @param separator - Optional string separator used to construct\n * the error message.\n * @returns {@link Failure | Failure<T>} with an aggregated message\n * if any error messages were collected, the supplied\n * {@link Result | Result<T>} otherwise.\n */\n public returnOrReport<T>(result: Result<T>, separator?: string): Result<T> {\n if (!this.hasMessages) {\n return result;\n }\n if (!result.success) {\n if (!this._messages.find((s) => s === result.message)) {\n return fail([...this._messages, result.message].join(separator ?? '\\n'));\n }\n }\n return fail(this.toString(separator));\n }\n}\n"]}
|
|
@@ -23,6 +23,13 @@ export type FailureContinuation<T> = (message: string) => Result<T>;
|
|
|
23
23
|
* @beta
|
|
24
24
|
*/
|
|
25
25
|
export type ResultValueType<T> = T extends Result<infer TV> ? TV : never;
|
|
26
|
+
/**
|
|
27
|
+
* Formats an error message.
|
|
28
|
+
* @param message - The error message to be formatted.
|
|
29
|
+
* @param detail - An optional detail to be included in the formatted message.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export type ErrorFormatter<TD = unknown> = (message: string, detail?: TD) => string;
|
|
26
33
|
/**
|
|
27
34
|
* Simple logger interface used by {@link IResult.orThrow}.
|
|
28
35
|
* @public
|
|
@@ -44,6 +51,10 @@ export interface IMessageAggregator {
|
|
|
44
51
|
* Indicates whether any messages have been aggregated.
|
|
45
52
|
*/
|
|
46
53
|
readonly hasMessages: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* The number of messages aggregated.
|
|
56
|
+
*/
|
|
57
|
+
readonly numMessages: number;
|
|
47
58
|
/**
|
|
48
59
|
* The aggregated messages.
|
|
49
60
|
*/
|
|
@@ -80,6 +91,16 @@ export interface IResult<T> {
|
|
|
80
91
|
* Indicates whether the operation was successful.
|
|
81
92
|
*/
|
|
82
93
|
readonly success: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Value returned by a successful operation, undefined
|
|
96
|
+
* for a failed operation.
|
|
97
|
+
*/
|
|
98
|
+
readonly value: T | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Error message returned by a failed operation, undefined
|
|
101
|
+
* for a successful operation.
|
|
102
|
+
*/
|
|
103
|
+
readonly message: string | undefined;
|
|
83
104
|
/**
|
|
84
105
|
* Indicates whether this operation was successful. Functions
|
|
85
106
|
* as a type guard for {@link Success | Success<T>}.
|
|
@@ -169,6 +190,16 @@ export interface IResult<T> {
|
|
|
169
190
|
* was successful, propagates the result value from the successful event.
|
|
170
191
|
*/
|
|
171
192
|
onFailure(cb: FailureContinuation<T>): Result<T>;
|
|
193
|
+
/**
|
|
194
|
+
* Calls a supplied {@link ErrorFormatter | error formatter} if
|
|
195
|
+
* the operation failed.
|
|
196
|
+
* @param cb - The {@link ErrorFormatter | error formatter} to
|
|
197
|
+
* be called in the event of failure.
|
|
198
|
+
* @returns If this operation failed, returns the returns {@link Failure | Failure}
|
|
199
|
+
* with the message returned by the formatter. If this result
|
|
200
|
+
* was successful, propagates the result value from the successful event.
|
|
201
|
+
*/
|
|
202
|
+
withErrorFormat(cb: ErrorFormatter): Result<T>;
|
|
172
203
|
/**
|
|
173
204
|
* Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},
|
|
174
205
|
* adding a supplied detail if the operation failed.
|
|
@@ -207,6 +238,10 @@ export declare class Success<T> implements IResult<T> {
|
|
|
207
238
|
* {@inheritdoc IResult.success}
|
|
208
239
|
*/
|
|
209
240
|
readonly success: true;
|
|
241
|
+
/**
|
|
242
|
+
* For a successful operation, the error message is always `undefined`.
|
|
243
|
+
*/
|
|
244
|
+
readonly message: undefined;
|
|
210
245
|
/**
|
|
211
246
|
* @internal
|
|
212
247
|
*/
|
|
@@ -258,6 +293,10 @@ export declare class Success<T> implements IResult<T> {
|
|
|
258
293
|
* {@inheritdoc IResult.onFailure}
|
|
259
294
|
*/
|
|
260
295
|
onFailure(__: FailureContinuation<T>): Result<T>;
|
|
296
|
+
/**
|
|
297
|
+
* {@inheritdoc IResult.withErrorFormat}
|
|
298
|
+
*/
|
|
299
|
+
withErrorFormat(__cb: ErrorFormatter): Result<T>;
|
|
261
300
|
/**
|
|
262
301
|
* {@inheritdoc IResult.withFailureDetail}
|
|
263
302
|
*/
|
|
@@ -280,6 +319,10 @@ export declare class Failure<T> implements IResult<T> {
|
|
|
280
319
|
* {@inheritdoc IResult.success}
|
|
281
320
|
*/
|
|
282
321
|
readonly success: false;
|
|
322
|
+
/**
|
|
323
|
+
* Failed operation always returns undefined for value.
|
|
324
|
+
*/
|
|
325
|
+
readonly value: undefined;
|
|
283
326
|
/**
|
|
284
327
|
* @internal
|
|
285
328
|
*/
|
|
@@ -331,6 +374,10 @@ export declare class Failure<T> implements IResult<T> {
|
|
|
331
374
|
* {@inheritdoc IResult.onFailure}
|
|
332
375
|
*/
|
|
333
376
|
onFailure(cb: FailureContinuation<T>): Result<T>;
|
|
377
|
+
/**
|
|
378
|
+
* {@inheritdoc IResult.withErrorFormat}
|
|
379
|
+
*/
|
|
380
|
+
withErrorFormat(cb: ErrorFormatter): Result<T>;
|
|
334
381
|
/**
|
|
335
382
|
* {@inheritdoc IResult.withFailureDetail}
|
|
336
383
|
*/
|
|
@@ -429,6 +476,10 @@ export declare class DetailedSuccess<T, TD> extends Success<T> {
|
|
|
429
476
|
* @returns `this`
|
|
430
477
|
*/
|
|
431
478
|
onFailure(__cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD>;
|
|
479
|
+
/**
|
|
480
|
+
* {@inheritdoc Success.withErrorFormat}
|
|
481
|
+
*/
|
|
482
|
+
withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD>;
|
|
432
483
|
}
|
|
433
484
|
/**
|
|
434
485
|
* A {@link DetailedFailure} extends {@link Failure} to report optional failure details in
|
|
@@ -478,6 +529,10 @@ export declare class DetailedFailure<T, TD> extends Failure<T> {
|
|
|
478
529
|
* @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.
|
|
479
530
|
*/
|
|
480
531
|
onFailure(cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD>;
|
|
532
|
+
/**
|
|
533
|
+
* {@inheritdoc IResult.withErrorFormat}
|
|
534
|
+
*/
|
|
535
|
+
withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD>;
|
|
481
536
|
}
|
|
482
537
|
/**
|
|
483
538
|
* Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":"AAuBA;;;;;;GAMG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAChD;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/result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
|
|
@@ -43,6 +43,10 @@ class Success {
|
|
|
43
43
|
* {@inheritdoc IResult.success}
|
|
44
44
|
*/
|
|
45
45
|
this.success = true;
|
|
46
|
+
/**
|
|
47
|
+
* For a successful operation, the error message is always `undefined`.
|
|
48
|
+
*/
|
|
49
|
+
this.message = undefined;
|
|
46
50
|
this._value = value;
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
@@ -100,6 +104,12 @@ class Success {
|
|
|
100
104
|
onFailure(__) {
|
|
101
105
|
return this;
|
|
102
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* {@inheritdoc IResult.withErrorFormat}
|
|
109
|
+
*/
|
|
110
|
+
withErrorFormat(__cb) {
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
103
113
|
/**
|
|
104
114
|
* {@inheritdoc IResult.withFailureDetail}
|
|
105
115
|
*/
|
|
@@ -134,6 +144,10 @@ class Failure {
|
|
|
134
144
|
* {@inheritdoc IResult.success}
|
|
135
145
|
*/
|
|
136
146
|
this.success = false;
|
|
147
|
+
/**
|
|
148
|
+
* Failed operation always returns undefined for value.
|
|
149
|
+
*/
|
|
150
|
+
this.value = undefined;
|
|
137
151
|
this._message = message;
|
|
138
152
|
}
|
|
139
153
|
/**
|
|
@@ -195,6 +209,12 @@ class Failure {
|
|
|
195
209
|
onFailure(cb) {
|
|
196
210
|
return cb(this.message);
|
|
197
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* {@inheritdoc IResult.withErrorFormat}
|
|
214
|
+
*/
|
|
215
|
+
withErrorFormat(cb) {
|
|
216
|
+
return fail(cb(this.message));
|
|
217
|
+
}
|
|
198
218
|
/**
|
|
199
219
|
* {@inheritdoc IResult.withFailureDetail}
|
|
200
220
|
*/
|
|
@@ -298,6 +318,12 @@ class DetailedSuccess extends Success {
|
|
|
298
318
|
onFailure(__cb) {
|
|
299
319
|
return this;
|
|
300
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* {@inheritdoc Success.withErrorFormat}
|
|
323
|
+
*/
|
|
324
|
+
withErrorFormat(cb) {
|
|
325
|
+
return this;
|
|
326
|
+
}
|
|
301
327
|
}
|
|
302
328
|
exports.DetailedSuccess = DetailedSuccess;
|
|
303
329
|
/**
|
|
@@ -355,6 +381,12 @@ class DetailedFailure extends Failure {
|
|
|
355
381
|
onFailure(cb) {
|
|
356
382
|
return cb(this.message, this._detail);
|
|
357
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* {@inheritdoc IResult.withErrorFormat}
|
|
386
|
+
*/
|
|
387
|
+
withErrorFormat(cb) {
|
|
388
|
+
return failWithDetail(cb(this.message, this._detail), this._detail);
|
|
389
|
+
}
|
|
358
390
|
}
|
|
359
391
|
exports.DetailedFailure = DetailedFailure;
|
|
360
392
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AA0dH,0BAEC;AAOD,oBAEC;AA+KD,8CAEC;AAUD,wCAEC;AAaD,kDAQC;AAWD,sCAMC;AA1eD;;;;GAIG;AACH,MAAa,OAAO;IAUlB;;;OAGG;IACH,YAAmB,KAAQ;QAb3B;;WAEG;QACa,YAAO,GAAS,IAAI,CAAC;QAWnC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACI,SAAS;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACI,SAAS;QACd,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,QAAwB;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAUM,SAAS,CAAC,IAAQ;;QACvB,OAAO,MAAA,IAAI,CAAC,MAAM,mCAAI,IAAI,CAAC;IAC7B,CAAC;IAED;;;OA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,CAAC;IACxC,CAAC;CACF;AA3DD,0CA2DC;AAcD;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAAQ,KAAQ,EAAE,MAAW;IAC5D,OAAO,IAAI,eAAe,CAAQ,KAAK,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAQ,OAAe,EAAE,MAAU;IAC/D,OAAO,IAAI,eAAe,CAAQ,OAAO,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CACjC,MAAiB,EACjB,MAAU,EACV,aAAkB;IAElB,OAAO,MAAM,CAAC,SAAS,EAAE;QACvB,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,MAAM,CAAC;QAC1D,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAI,IAAa;IAC5C,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACzB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,IAAI,CAAE,GAAa,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC","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\n/* eslint-disable no-use-before-define */\n/**\n * Represents the {@link IResult | result} of some operation or sequence of operations.\n * @remarks\n * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common\n * contract {@link IResult}, enabling commingled discriminated usage.\n * @public\n */\nexport type Result<T> = Success<T> | Failure<T>;\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} is successful.\n * @public\n */\nexport type SuccessContinuation<T, TN> = (value: T) => Result<TN>;\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} fails.\n * @public\n */\nexport type FailureContinuation<T> = (message: string) => Result<T>;\n/**\n * Type inference to determine the result type of an {@link Result}.\n * @beta\n */\nexport type ResultValueType<T> = T extends Result<infer TV> ? TV : never;\n\n/**\n * Simple logger interface used by {@link IResult.orThrow}.\n * @public\n */\nexport interface IResultLogger {\n /**\n * Log an error message.\n * @param message - The message to be logged.\n */\n error(message: string): void;\n}\n\n/**\n * Simple error aggregator to simplify collecting all errors in\n * a flow.\n * @public\n */\nexport interface IMessageAggregator {\n /**\n * Indicates whether any messages have been aggregated.\n */\n readonly hasMessages: boolean;\n\n /**\n * The aggregated messages.\n */\n readonly messages: ReadonlyArray<string>;\n\n /**\n * Adds a message to the aggregator, if defined.\n * @param message - The message to add - pass `undefined`\n * or the empty string to continue without adding a message.\n */\n addMessage(message: string | undefined): this;\n\n /**\n * Adds multiple messages to the aggregator.\n * @param messages - the messages to add.\n */\n addMessages(messages: string[] | undefined): this;\n\n /**\n * Returns all messages as a single string joined\n * using the optionally-supplied `separator`, or\n * newline if no separator is specified.\n * @param separator - The optional separator used\n * to join strings.\n */\n toString(separator?: string): string;\n}\n\n/**\n * Represents the result of some operation of sequence of operations.\n * @remarks\n * This common contract enables commingled discriminated usage of {@link Success | Success<T>}\n * and {@link Failure | Failure<T>}.\n * @public\n */\nexport interface IResult<T> {\n /**\n * Indicates whether the operation was successful.\n */\n readonly success: boolean;\n\n /**\n * Indicates whether this operation was successful. Functions\n * as a type guard for {@link Success | Success<T>}.\n */\n isSuccess(): this is Success<T>;\n\n /**\n * Indicates whether this operation failed. Functions\n * as a type guard for {@link Failure | Failure<T>}.\n */\n isFailure(): this is Failure<T>;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n *\n * Note that `getValueOrThrow` is being superseded by `orThrow` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * @deprecated Use {@link IResult.orThrow | orThrow} instead.\n */\n getValueOrThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed (default is\n * `undefined`).\n *\n * Note that `getValueOrDefault` is being superseded by `orDefault` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @returns The return value, if the operation was successful. Returns\n * the supplied default value or `undefined` if no default is supplied.\n * @deprecated Use {@link IResult.(orDefault:1) | orDefault(T)} or {@link IResult.(orDefault:2) | orDefault()} instead.\n */\n getValueOrDefault(dflt?: T): T | undefined;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n */\n orThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed.\n * @returns The return value, if the operation was successful. Returns\n * the supplied default if an error occurred.\n * {@label SUPPLIED}\n */\n orDefault(dflt: T): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @returns The return value, if the operation was successful, or\n * `undefined` if an error occurs.\n * {@label MISSING}\n */\n orDefault(): T | undefined;\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the operation was a success.\n * @remarks\n * The {@link SuccessContinuation | success continuation} might return a\n * different result type than {@link IResult} on which it is invoked. This\n * enables chaining of operations with heterogenous return types.\n *\n * @param cb - The {@link SuccessContinuation | success continuation} to\n * be called in the event of success.\n * @returns If this operation was successful, returns the value returned\n * by the {@link SuccessContinuation | success continuation}. If this result\n * failed, propagates the error message from this failure.\n */\n onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;\n\n /**\n * Calls a supplied {@link FailureContinuation | failed continuation} if\n * the operation failed.\n * @param cb - The {@link FailureContinuation | failure continuation} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the value returned by the\n * {@link FailureContinuation | failure continuation}. If this result\n * was successful, propagates the result value from the successful event.\n */\n onFailure(cb: FailureContinuation<T>): Result<T>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding a supplied detail if the operation failed.\n * @param detail - The detail to be added if this operation failed.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult}, with\n * the supplied detail (if this event failed) or detail `undefined` (if\n * this result succeeded).\n */\n withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding supplied details.\n * @param detail - The default detail to be added to the new {@link DetailedResult}.\n * @param successDetail - An optional detail to be added if this result was successful.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult} and the\n * appropriate added detail.\n */\n withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;\n\n /**\n * Propagates interior result, appending any error message to the\n * supplied errors array.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n */\n aggregateError(errors: IMessageAggregator): this;\n}\n\n/**\n * Reports a successful {@link IResult | result} from some operation and the\n * corresponding value.\n * @public\n */\nexport class Success<T> implements IResult<T> {\n /**\n * {@inheritdoc IResult.success}\n */\n public readonly success: true = true;\n /**\n * @internal\n */\n private readonly _value: T;\n\n /**\n * Constructs a {@link Success} with the supplied value.\n * @param value - The value to be returned.\n */\n public constructor(value: T) {\n this._value = value;\n }\n\n /**\n * The result value returned by the successful operation.\n */\n public get value(): T {\n return this._value;\n }\n\n /**\n * {@inheritdoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return true;\n }\n\n /**\n * {@inheritdoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return false;\n }\n\n /**\n * {@inheritdoc IResult.orThrow}\n */\n public orThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritdoc IResult.(orDefault:1)}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritdoc IResult.(orDefault:2)}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritdoc IResult.getValueOrThrow}\n * @deprecated Use {@link Success.orThrow | orThrow} instead.\n */\n public getValueOrThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritdoc IResult.getValueOrDefault}\n * @deprecated Use {@link Success.(orDefault:1) | orDefault(T)} or {@link Success.(orDefault:2) | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritdoc IResult.onSuccess}\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN> {\n return cb(this.value);\n }\n\n /**\n * {@inheritdoc IResult.onFailure}\n */\n public onFailure(__: FailureContinuation<T>): Result<T> {\n return this;\n }\n\n /**\n * {@inheritdoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this.value);\n }\n\n /**\n * {@inheritdoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this.value, successDetail ?? detail);\n }\n\n /**\n * {@inheritdoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator): this {\n return this;\n }\n}\n\n/**\n * Reports a failed {@link IResult | result} from some operation, with an error message.\n * @public\n */\nexport class Failure<T> implements IResult<T> {\n /**\n * {@inheritdoc IResult.success}\n */\n public readonly success: false = false;\n\n /**\n * @internal\n */\n private readonly _message: string;\n\n /**\n * Constructs a {@link Failure} with the supplied message.\n * @param message - Error message to be reported.\n */\n public constructor(message: string) {\n this._message = message;\n }\n\n /**\n * Gets the error message associated with this error.\n */\n public get message(): string {\n return this._message;\n }\n\n /**\n * {@inheritdoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return false;\n }\n\n /**\n * {@inheritdoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return true;\n }\n\n /**\n * {@inheritdoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritdoc IResult.(orDefault:1)}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritdoc IResult.(orDefault:2)}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritdoc IResult.getValueOrThrow}\n * @deprecated Use {@link Failure.orThrow | orThrow} instead.\n */\n public getValueOrThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritdoc IResult.getValueOrDefault}\n * @deprecated Use {@link Failure.(orDefault:1) | orDefault(T)} or {@link Failure.(orDefault:2) | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritdoc IResult.onSuccess}\n */\n public onSuccess<TN>(__: SuccessContinuation<T, TN>): Result<TN> {\n return new Failure(this.message);\n }\n\n /**\n * {@inheritdoc IResult.onFailure}\n */\n public onFailure(cb: FailureContinuation<T>): Result<T> {\n return cb(this.message);\n }\n\n /**\n * {@inheritdoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(detail: TD): DetailedResult<T, TD> {\n return failWithDetail(this.message, detail);\n }\n\n /**\n * {@inheritdoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD> {\n return failWithDetail(this.message, detail);\n }\n\n /**\n * {@inheritdoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator): this {\n errors.addMessage(this.message);\n return this;\n }\n\n /**\n * Get a 'friendly' string representation of this object.\n * @remarks\n * The string representation of a {@link Failure} value is the error message.\n * @returns A string representing this object.\n */\n public toString(): string {\n return this.message;\n }\n}\n\n/**\n * Returns {@link Success | Success<T>} with the supplied result value.\n * @param value - The successful result value to be returned\n * @public\n */\nexport function succeed<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * Returns {@link Failure | Failure<T>} with the supplied error message.\n * @param message - Error message to be returned.\n * @public\n */\nexport function fail<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * Callback to be called when a {@link DetailedResult} encounters success.\n * @remarks\n * A success callback can return a different result type than it receives, allowing\n * success results to chain through intermediate result types.\n * @public\n */\nexport type DetailedSuccessContinuation<T, TD, TN> = (value: T, detail?: TD) => DetailedResult<TN, TD>;\n\n/**\n * Callback to be called when a {@link DetailedResult} encounters a failure.\n * @remarks\n * A failure callback can change {@link Failure} to {@link Success} (e.g. by returning a default value)\n * or it can change or embellish the error message, but it cannot change the success return type.\n * @public\n */\nexport type DetailedFailureContinuation<T, TD> = (message: string, detail: TD) => DetailedResult<T, TD>;\n\n/**\n * A {@link DetailedSuccess} extends {@link Success} to report optional success details in\n * addition to the error message.\n * @public\n */\nexport class DetailedSuccess<T, TD> extends Success<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied\n * value and detail.\n * @param value - The value to be returned.\n * @param detail - An optional successful detail to be returned. If omitted, detail\n * will be `undefined`.\n */\n public constructor(value: T, detail?: TD) {\n super(value);\n this._detail = detail;\n }\n\n /**\n * The success detail associated with this {@link DetailedSuccess}, or `undefined` if\n * no detail was supplied.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedSuccess} is a success.\n * @remarks\n * Always true for {@link DetailedSuccess} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isSuccess(): this is DetailedSuccess<T, TD> {\n return true;\n }\n\n /**\n * Invokes the supplied {@link DetailedSuccessContinuation | success callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<TN, TD>}.\n * @remarks\n * The success callback mutates the return type from `<T>` to `<TN>`.\n * @param cb - The {@link DetailedSuccessContinuation | success callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the success callback.\n */\n public onSuccess<TN>(cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return cb(this.value, this._detail);\n }\n\n /**\n * Propagates this {@link DetailedSuccess}.\n * @remarks\n * Failure does not mutate return type so we can return this event directly.\n * @param _cb - {@link DetailedFailureContinuation | Failure callback} to be called\n * on a {@link DetailedResult} in case of failure (ignored).\n * @returns `this`\n */\n public onFailure(__cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return this;\n }\n}\n\n/**\n * A {@link DetailedFailure} extends {@link Failure} to report optional failure details in\n * addition to the error message.\n * @public\n */\nexport class DetailedFailure<T, TD> extends Failure<T> {\n /**\n * @internal\n */\n protected _detail: TD;\n\n /**\n * Constructs a new {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * message and detail.\n * @param message - The message to be returned.\n * @param detail - The error detail to be returned.\n */\n public constructor(message: string, detail: TD) {\n super(message);\n this._detail = detail;\n }\n\n /**\n * The error detail associated with this {@link DetailedFailure}.\n */\n public get detail(): TD {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedFailure} is a failure.\n * @remarks\n * Always true for {@link DetailedFailure} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isFailure(): this is DetailedFailure<T, TD> {\n return true;\n }\n\n /**\n * Propagates the error message and detail from this result.\n * @remarks\n * Mutates the success type as the success callback would have, but does not\n * call the success callback.\n * @param _cb - {@link DetailedSuccessContinuation | Success callback} to be called\n * on a {@link DetailedResult} in case of success (ignored).\n * @returns A new {@link DetailedFailure | DetailedFailure<TN, TD>} which contains\n * the error message and detail from this one.\n */\n public onSuccess<TN>(__cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return new DetailedFailure<TN, TD>(this.message, this._detail);\n }\n\n /**\n * Invokes the supplied {@link DetailedFailureContinuation | failure callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<T, TD>}.\n * @param cb - The {@link DetailedFailureContinuation | failure callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.\n */\n public onFailure(cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return cb(this.message, this._detail);\n }\n}\n\n/**\n * Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type DetailedResult<T, TD> = DetailedSuccess<T, TD> | DetailedFailure<T, TD>;\n\n/**\n * Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;\n\n/**\n * Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional\n * detail.\n * @param value - The value of type `<T>` to be returned.\n * @param detail - An optional detail of type `<TD>` to be returned.\n * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value\n * and detail, if supplied.\n * @public\n */\nexport function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.\n * @param message - The error message to be returned.\n * @param detail - The event detail to be returned.\n * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error\n * message and detail.\n * @public\n */\nexport function failWithDetail<T, TD>(message: string, detail: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied\n * event details as appropriate.\n * @param result - The {@link Result} to be propagated.\n * @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.\n * @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`\n * is omitted or `undefined`, then `detail` will be applied to {@link Success} results.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error\n * message from the original `result` but with the specified detail added.\n * @public\n */\nexport function propagateWithDetail<T, TD>(\n result: Result<T>,\n detail: TD,\n successDetail?: TD\n): DetailedResult<T, TD> {\n return result.isSuccess()\n ? succeedWithDetail(result.value, successDetail ?? detail)\n : failWithDetail(result.message, detail);\n}\n\n/**\n * Wraps a function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The function to be captured.\n * @returns Returns {@link Success} with a value of type `<T>` on\n * success , or {@link Failure} with the thrown error message if\n * `func` throws an `Error`.\n * @public\n */\nexport function captureResult<T>(func: () => T): Result<T> {\n try {\n return succeed(func());\n } catch (err) {\n return fail((err as Error).message);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAwhBH,0BAEC;AAOD,oBAEC;AA6LD,8CAEC;AAUD,wCAEC;AAaD,kDAQC;AAWD,sCAMC;AAhhBD;;;;GAIG;AACH,MAAa,OAAO;IAgBlB;;;OAGG;IACH,YAAmB,KAAQ;QAnB3B;;WAEG;QACa,YAAO,GAAS,IAAI,CAAC;QAErC;;WAEG;QACa,YAAO,GAAc,SAAS,CAAC;QAY7C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACI,SAAS;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACI,SAAS;QACd,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,QAAwB;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAUM,SAAS,CAAC,IAAQ;;QACvB,OAAO,MAAA,IAAI,CAAC,MAAM,mCAAI,IAAI,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,QAAwB;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;OAGG;IACI,iBAAiB,CAAC,IAAQ;;QAC/B,OAAO,MAAA,IAAI,CAAC,MAAM,mCAAI,IAAI,CAAC;IAC7B,CAAC;IAED;;OAEG;IACI,SAAS,CAAK,EAA8B;QACjD,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,EAA0B;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACI,eAAe,CAAC,IAAoB;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;O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C,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACtE,CAAC;CACF;AAlED,0CAkEC;AAcD;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAAQ,KAAQ,EAAE,MAAW;IAC5D,OAAO,IAAI,eAAe,CAAQ,KAAK,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAQ,OAAe,EAAE,MAAU;IAC/D,OAAO,IAAI,eAAe,CAAQ,OAAO,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CACjC,MAAiB,EACjB,MAAU,EACV,aAAkB;IAElB,OAAO,MAAM,CAAC,SAAS,EAAE;QACvB,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,MAAM,CAAC;QAC1D,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAI,IAAa;IAC5C,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACzB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,IAAI,CAAE,GAAa,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC","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\n/* eslint-disable no-use-before-define */\n/**\n * Represents the {@link IResult | result} of some operation or sequence of operations.\n * @remarks\n * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common\n * contract {@link IResult}, enabling commingled discriminated usage.\n * @public\n */\nexport type Result<T> = Success<T> | Failure<T>;\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} is successful.\n * @public\n */\nexport type SuccessContinuation<T, TN> = (value: T) => Result<TN>;\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} fails.\n * @public\n */\nexport type FailureContinuation<T> = (message: string) => Result<T>;\n\n/**\n * Type inference to determine the result type of an {@link Result}.\n * @beta\n */\nexport type ResultValueType<T> = T extends Result<infer TV> ? TV : never;\n\n/**\n * Formats an error message.\n * @param message - The error message to be formatted.\n * @param detail - An optional detail to be included in the formatted message.\n * @public\n */\nexport type ErrorFormatter<TD = unknown> = (message: string, detail?: TD) => string;\n\n/**\n * Simple logger interface used by {@link IResult.orThrow}.\n * @public\n */\nexport interface IResultLogger {\n /**\n * Log an error message.\n * @param message - The message to be logged.\n */\n error(message: string): void;\n}\n\n/**\n * Simple error aggregator to simplify collecting all errors in\n * a flow.\n * @public\n */\nexport interface IMessageAggregator {\n /**\n * Indicates whether any messages have been aggregated.\n */\n readonly hasMessages: boolean;\n\n /**\n * The number of messages aggregated.\n */\n readonly numMessages: number;\n\n /**\n * The aggregated messages.\n */\n readonly messages: ReadonlyArray<string>;\n\n /**\n * Adds a message to the aggregator, if defined.\n * @param message - The message to add - pass `undefined`\n * or the empty string to continue without adding a message.\n */\n addMessage(message: string | undefined): this;\n\n /**\n * Adds multiple messages to the aggregator.\n * @param messages - the messages to add.\n */\n addMessages(messages: string[] | undefined): this;\n\n /**\n * Returns all messages as a single string joined\n * using the optionally-supplied `separator`, or\n * newline if no separator is specified.\n * @param separator - The optional separator used\n * to join strings.\n */\n toString(separator?: string): string;\n}\n\n/**\n * Represents the result of some operation of sequence of operations.\n * @remarks\n * This common contract enables commingled discriminated usage of {@link Success | Success<T>}\n * and {@link Failure | Failure<T>}.\n * @public\n */\nexport interface IResult<T> {\n /**\n * Indicates whether the operation was successful.\n */\n readonly success: boolean;\n\n /**\n * Value returned by a successful operation, undefined\n * for a failed operation.\n */\n readonly value: T | undefined;\n\n /**\n * Error message returned by a failed operation, undefined\n * for a successful operation.\n */\n readonly message: string | undefined;\n\n /**\n * Indicates whether this operation was successful. Functions\n * as a type guard for {@link Success | Success<T>}.\n */\n isSuccess(): this is Success<T>;\n\n /**\n * Indicates whether this operation failed. Functions\n * as a type guard for {@link Failure | Failure<T>}.\n */\n isFailure(): this is Failure<T>;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n *\n * Note that `getValueOrThrow` is being superseded by `orThrow` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * @deprecated Use {@link IResult.orThrow | orThrow} instead.\n */\n getValueOrThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed (default is\n * `undefined`).\n *\n * Note that `getValueOrDefault` is being superseded by `orDefault` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @returns The return value, if the operation was successful. Returns\n * the supplied default value or `undefined` if no default is supplied.\n * @deprecated Use {@link IResult.(orDefault:1) | orDefault(T)} or {@link IResult.(orDefault:2) | orDefault()} instead.\n */\n getValueOrDefault(dflt?: T): T | undefined;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n */\n orThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed.\n * @returns The return value, if the operation was successful. Returns\n * the supplied default if an error occurred.\n * {@label SUPPLIED}\n */\n orDefault(dflt: T): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @returns The return value, if the operation was successful, or\n * `undefined` if an error occurs.\n * {@label MISSING}\n */\n orDefault(): T | undefined;\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the operation was a success.\n * @remarks\n * The {@link SuccessContinuation | success continuation} might return a\n * different result type than {@link IResult} on which it is invoked. This\n * enables chaining of operations with heterogenous return types.\n *\n * @param cb - The {@link SuccessContinuation | success continuation} to\n * be called in the event of success.\n * @returns If this operation was successful, returns the value returned\n * by the {@link SuccessContinuation | success continuation}. If this result\n * failed, propagates the error message from this failure.\n */\n onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;\n\n /**\n * Calls a supplied {@link FailureContinuation | failed continuation} if\n * the operation failed.\n * @param cb - The {@link FailureContinuation | failure continuation} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the value returned by the\n * {@link FailureContinuation | failure continuation}. If this result\n * was successful, propagates the result value from the successful event.\n */\n onFailure(cb: FailureContinuation<T>): Result<T>;\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the returns {@link Failure | Failure}\n * with the message returned by the formatter. If this result\n * was successful, propagates the result value from the successful event.\n */\n withErrorFormat(cb: ErrorFormatter): Result<T>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding a supplied detail if the operation failed.\n * @param detail - The detail to be added if this operation failed.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult}, with\n * the supplied detail (if this event failed) or detail `undefined` (if\n * this result succeeded).\n */\n withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding supplied details.\n * @param detail - The default detail to be added to the new {@link DetailedResult}.\n * @param successDetail - An optional detail to be added if this result was successful.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult} and the\n * appropriate added detail.\n */\n withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;\n\n /**\n * Propagates interior result, appending any error message to the\n * supplied errors array.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n */\n aggregateError(errors: IMessageAggregator): this;\n}\n\n/**\n * Reports a successful {@link IResult | result} from some operation and the\n * corresponding value.\n * @public\n */\nexport class Success<T> implements IResult<T> {\n /**\n * {@inheritdoc IResult.success}\n */\n public readonly success: true = true;\n\n /**\n * For a successful operation, the error message is always `undefined`.\n */\n public readonly message: undefined = undefined;\n\n /**\n * @internal\n */\n private readonly _value: T;\n\n /**\n * Constructs a {@link Success} with the supplied value.\n * @param value - The value to be returned.\n */\n public constructor(value: T) {\n this._value = value;\n }\n\n /**\n * The result value returned by the successful operation.\n */\n public get value(): T {\n return this._value;\n }\n\n /**\n * {@inheritdoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return true;\n }\n\n /**\n * {@inheritdoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return false;\n }\n\n /**\n * {@inheritdoc IResult.orThrow}\n */\n public orThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritdoc IResult.(orDefault:1)}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritdoc IResult.(orDefault:2)}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritdoc IResult.getValueOrThrow}\n * @deprecated Use {@link Success.orThrow | orThrow} instead.\n */\n public getValueOrThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritdoc IResult.getValueOrDefault}\n * @deprecated Use {@link Success.(orDefault:1) | orDefault(T)} or {@link Success.(orDefault:2) | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritdoc IResult.onSuccess}\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN> {\n return cb(this.value);\n }\n\n /**\n * {@inheritdoc IResult.onFailure}\n */\n public onFailure(__: FailureContinuation<T>): Result<T> {\n return this;\n }\n\n /**\n * {@inheritdoc IResult.withErrorFormat}\n */\n public withErrorFormat(__cb: ErrorFormatter): Result<T> {\n return this;\n }\n\n /**\n * {@inheritdoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this.value);\n }\n\n /**\n * {@inheritdoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this.value, successDetail ?? detail);\n }\n\n /**\n * {@inheritdoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator): this {\n return this;\n }\n}\n\n/**\n * Reports a failed {@link IResult | result} from some operation, with an error message.\n * @public\n */\nexport class Failure<T> implements IResult<T> {\n /**\n * {@inheritdoc IResult.success}\n */\n public readonly success: false = false;\n /**\n * Failed operation always returns undefined for value.\n */\n public readonly value: undefined = undefined;\n\n /**\n * @internal\n */\n private readonly _message: string;\n\n /**\n * Constructs a {@link Failure} with the supplied message.\n * @param message - Error message to be reported.\n */\n public constructor(message: string) {\n this._message = message;\n }\n\n /**\n * Gets the error message associated with this error.\n */\n public get message(): string {\n return this._message;\n }\n\n /**\n * {@inheritdoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return false;\n }\n\n /**\n * {@inheritdoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return true;\n }\n\n /**\n * {@inheritdoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritdoc IResult.(orDefault:1)}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritdoc IResult.(orDefault:2)}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritdoc IResult.getValueOrThrow}\n * @deprecated Use {@link Failure.orThrow | orThrow} instead.\n */\n public getValueOrThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritdoc IResult.getValueOrDefault}\n * @deprecated Use {@link Failure.(orDefault:1) | orDefault(T)} or {@link Failure.(orDefault:2) | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritdoc IResult.onSuccess}\n */\n public onSuccess<TN>(__: SuccessContinuation<T, TN>): Result<TN> {\n return new Failure(this.message);\n }\n\n /**\n * {@inheritdoc IResult.onFailure}\n */\n public onFailure(cb: FailureContinuation<T>): Result<T> {\n return cb(this.message);\n }\n\n /**\n * {@inheritdoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): Result<T> {\n return fail(cb(this.message));\n }\n\n /**\n * {@inheritdoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(detail: TD): DetailedResult<T, TD> {\n return failWithDetail(this.message, detail);\n }\n\n /**\n * {@inheritdoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD> {\n return failWithDetail(this.message, detail);\n }\n\n /**\n * {@inheritdoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator): this {\n errors.addMessage(this.message);\n return this;\n }\n\n /**\n * Get a 'friendly' string representation of this object.\n * @remarks\n * The string representation of a {@link Failure} value is the error message.\n * @returns A string representing this object.\n */\n public toString(): string {\n return this.message;\n }\n}\n\n/**\n * Returns {@link Success | Success<T>} with the supplied result value.\n * @param value - The successful result value to be returned\n * @public\n */\nexport function succeed<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * Returns {@link Failure | Failure<T>} with the supplied error message.\n * @param message - Error message to be returned.\n * @public\n */\nexport function fail<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * Callback to be called when a {@link DetailedResult} encounters success.\n * @remarks\n * A success callback can return a different result type than it receives, allowing\n * success results to chain through intermediate result types.\n * @public\n */\nexport type DetailedSuccessContinuation<T, TD, TN> = (value: T, detail?: TD) => DetailedResult<TN, TD>;\n\n/**\n * Callback to be called when a {@link DetailedResult} encounters a failure.\n * @remarks\n * A failure callback can change {@link Failure} to {@link Success} (e.g. by returning a default value)\n * or it can change or embellish the error message, but it cannot change the success return type.\n * @public\n */\nexport type DetailedFailureContinuation<T, TD> = (message: string, detail: TD) => DetailedResult<T, TD>;\n\n/**\n * A {@link DetailedSuccess} extends {@link Success} to report optional success details in\n * addition to the error message.\n * @public\n */\nexport class DetailedSuccess<T, TD> extends Success<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied\n * value and detail.\n * @param value - The value to be returned.\n * @param detail - An optional successful detail to be returned. If omitted, detail\n * will be `undefined`.\n */\n public constructor(value: T, detail?: TD) {\n super(value);\n this._detail = detail;\n }\n\n /**\n * The success detail associated with this {@link DetailedSuccess}, or `undefined` if\n * no detail was supplied.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedSuccess} is a success.\n * @remarks\n * Always true for {@link DetailedSuccess} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isSuccess(): this is DetailedSuccess<T, TD> {\n return true;\n }\n\n /**\n * Invokes the supplied {@link DetailedSuccessContinuation | success callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<TN, TD>}.\n * @remarks\n * The success callback mutates the return type from `<T>` to `<TN>`.\n * @param cb - The {@link DetailedSuccessContinuation | success callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the success callback.\n */\n public onSuccess<TN>(cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return cb(this.value, this._detail);\n }\n\n /**\n * Propagates this {@link DetailedSuccess}.\n * @remarks\n * Failure does not mutate return type so we can return this event directly.\n * @param _cb - {@link DetailedFailureContinuation | Failure callback} to be called\n * on a {@link DetailedResult} in case of failure (ignored).\n * @returns `this`\n */\n public onFailure(__cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return this;\n }\n\n /**\n * {@inheritdoc Success.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD> {\n return this;\n }\n}\n\n/**\n * A {@link DetailedFailure} extends {@link Failure} to report optional failure details in\n * addition to the error message.\n * @public\n */\nexport class DetailedFailure<T, TD> extends Failure<T> {\n /**\n * @internal\n */\n protected _detail: TD;\n\n /**\n * Constructs a new {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * message and detail.\n * @param message - The message to be returned.\n * @param detail - The error detail to be returned.\n */\n public constructor(message: string, detail: TD) {\n super(message);\n this._detail = detail;\n }\n\n /**\n * The error detail associated with this {@link DetailedFailure}.\n */\n public get detail(): TD {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedFailure} is a failure.\n * @remarks\n * Always true for {@link DetailedFailure} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isFailure(): this is DetailedFailure<T, TD> {\n return true;\n }\n\n /**\n * Propagates the error message and detail from this result.\n * @remarks\n * Mutates the success type as the success callback would have, but does not\n * call the success callback.\n * @param _cb - {@link DetailedSuccessContinuation | Success callback} to be called\n * on a {@link DetailedResult} in case of success (ignored).\n * @returns A new {@link DetailedFailure | DetailedFailure<TN, TD>} which contains\n * the error message and detail from this one.\n */\n public onSuccess<TN>(__cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return new DetailedFailure<TN, TD>(this.message, this._detail);\n }\n\n /**\n * Invokes the supplied {@link DetailedFailureContinuation | failure callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<T, TD>}.\n * @param cb - The {@link DetailedFailureContinuation | failure callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.\n */\n public onFailure(cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return cb(this.message, this._detail);\n }\n\n /**\n * {@inheritdoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD> {\n return failWithDetail(cb(this.message, this._detail), this._detail);\n }\n}\n\n/**\n * Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type DetailedResult<T, TD> = DetailedSuccess<T, TD> | DetailedFailure<T, TD>;\n\n/**\n * Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;\n\n/**\n * Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional\n * detail.\n * @param value - The value of type `<T>` to be returned.\n * @param detail - An optional detail of type `<TD>` to be returned.\n * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value\n * and detail, if supplied.\n * @public\n */\nexport function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.\n * @param message - The error message to be returned.\n * @param detail - The event detail to be returned.\n * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error\n * message and detail.\n * @public\n */\nexport function failWithDetail<T, TD>(message: string, detail: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied\n * event details as appropriate.\n * @param result - The {@link Result} to be propagated.\n * @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.\n * @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`\n * is omitted or `undefined`, then `detail` will be applied to {@link Success} results.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error\n * message from the original `result` but with the specified detail added.\n * @public\n */\nexport function propagateWithDetail<T, TD>(\n result: Result<T>,\n detail: TD,\n successDetail?: TD\n): DetailedResult<T, TD> {\n return result.isSuccess()\n ? succeedWithDetail(result.value, successDetail ?? detail)\n : failWithDetail(result.message, detail);\n}\n\n/**\n * Wraps a function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The function to be captured.\n * @returns Returns {@link Success} with a value of type `<T>` on\n * success , or {@link Failure} with the thrown error message if\n * `func` throws an `Error`.\n * @public\n */\nexport function captureResult<T>(func: () => T): Result<T> {\n try {\n return succeed(func());\n } catch (err) {\n return fail((err as Error).message);\n }\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Result } from '../base';
|
|
2
|
+
/**
|
|
3
|
+
* An item that can be collected by some {@link Collector | Collector}.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface ICollectible<TKEY extends string = string, TINDEX extends number = number> {
|
|
7
|
+
readonly key: TKEY;
|
|
8
|
+
readonly index: TINDEX | undefined;
|
|
9
|
+
setIndex(index: TINDEX): Result<TINDEX>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key, an index and a source representation
|
|
13
|
+
* of the item to be added.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export type CollectibleFactory<TKEY extends string = string, TINDEX extends number = number, TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>, TSRC = TITEM> = (key: TKEY, index: number, item: TSRC) => Result<TITEM>;
|
|
17
|
+
/**
|
|
18
|
+
* Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key and an index.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export type CollectibleFactoryCallback<TKEY extends string = string, TINDEX extends number = number, TITEM extends ICollectible<TKEY, TINDEX> = ICollectible<TKEY, TINDEX>> = (key: TKEY, index: number) => Result<TITEM>;
|
|
22
|
+
/**
|
|
23
|
+
* Simple implementation of {@link Collections.ICollectible | ICollectible} which does not allow the index to be
|
|
24
|
+
* changed once set.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare class Collectible<TKEY extends string = string, TINDEX extends number = number> implements ICollectible<TKEY, TINDEX> {
|
|
28
|
+
/**
|
|
29
|
+
* {@link Collections.ICollectible.key}
|
|
30
|
+
*/
|
|
31
|
+
readonly key: TKEY;
|
|
32
|
+
/**
|
|
33
|
+
* {@link Collections.ICollectible.index}
|
|
34
|
+
*/
|
|
35
|
+
get index(): TINDEX | undefined;
|
|
36
|
+
protected _index: TINDEX | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Constructs a new {@link Collections.Collectible | Collectible} instance.
|
|
39
|
+
* @param key - The key of the item to be collected.
|
|
40
|
+
* @param index - Optional index of the item to be collected.
|
|
41
|
+
*/
|
|
42
|
+
constructor(key: TKEY, index?: TINDEX);
|
|
43
|
+
/**
|
|
44
|
+
* {@link Collections.ICollectible.setIndex}
|
|
45
|
+
*/
|
|
46
|
+
setIndex(index: TINDEX): Result<TINDEX>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=collectible.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectible.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/collectible.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAiB,MAAM,SAAS,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM;IACxF,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;CACzC;AAED;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAC5B,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,IACV,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,0BAA0B,CACpC,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,IACnE,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC;AAEhD;;;;GAIG;AACH,qBAAa,WAAW,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM,CACnF,YAAW,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC;IAErC;;OAEG;IACH,SAAgB,GAAG,EAAE,IAAI,CAAC;IAE1B;;OAEG;IACH,IAAW,KAAK,IAAI,MAAM,GAAG,SAAS,CAErC;IAED,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAErC;;;;OAIG;gBACgB,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM;IAK5C;;OAEG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;CAO/C"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.Collectible = void 0;
|
|
25
|
+
const base_1 = require("../base");
|
|
26
|
+
/**
|
|
27
|
+
* Simple implementation of {@link Collections.ICollectible | ICollectible} which does not allow the index to be
|
|
28
|
+
* changed once set.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
class Collectible {
|
|
32
|
+
/**
|
|
33
|
+
* {@link Collections.ICollectible.index}
|
|
34
|
+
*/
|
|
35
|
+
get index() {
|
|
36
|
+
return this._index;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Constructs a new {@link Collections.Collectible | Collectible} instance.
|
|
40
|
+
* @param key - The key of the item to be collected.
|
|
41
|
+
* @param index - Optional index of the item to be collected.
|
|
42
|
+
*/
|
|
43
|
+
constructor(key, index) {
|
|
44
|
+
this.key = key;
|
|
45
|
+
this._index = index;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* {@link Collections.ICollectible.setIndex}
|
|
49
|
+
*/
|
|
50
|
+
setIndex(index) {
|
|
51
|
+
if (this._index !== undefined && index !== this.index) {
|
|
52
|
+
return (0, base_1.fail)(`index ${this.index} is immutable and cannot be changed to ${index}`);
|
|
53
|
+
}
|
|
54
|
+
this._index = index;
|
|
55
|
+
return (0, base_1.succeed)(this._index);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.Collectible = Collectible;
|
|
59
|
+
//# sourceMappingURL=collectible.js.map
|
|
@@ -0,0 +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"]}
|