@fgv/ts-res 4.5.0-2 → 4.5.0-3

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/dist/ts-res.d.ts CHANGED
@@ -3910,7 +3910,7 @@ declare abstract class ResourceType<T = unknown> implements ICollectible<Resourc
3910
3910
  * `Failure` with an error message otherwise.
3911
3911
  * @public
3912
3912
  */
3913
- abstract validate(json: JsonValue, isPartial: true): Result<T>;
3913
+ abstract validate(json: JsonValue, isPartial: true): Result<Partial<T>>;
3914
3914
  /**
3915
3915
  * Validates a JSON value for use as a complete resource instance value.
3916
3916
  * @param json - The JSON value to validate.
@@ -3919,7 +3919,7 @@ declare abstract class ResourceType<T = unknown> implements ICollectible<Resourc
3919
3919
  * `Failure` with an error message otherwise.
3920
3920
  * @public
3921
3921
  */
3922
- abstract validate(json: JsonValue, isPartial: false): Result<Partial<T>>;
3922
+ abstract validate(json: JsonValue, isPartial: false): Result<T>;
3923
3923
  /**
3924
3924
  * Validates a JSON value for use as a full or partial resource instance value.
3925
3925
  * @param json - The JSON value to validate.
@@ -1 +1 @@
1
- {"version":3,"file":"concreteDecision.d.ts","sourceRoot":"","sources":["../../../src/packlets/decisions/concreteDecision.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAa,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAA0C,MAAM,EAAW,MAAM,eAAe,CAAC;AAExF,OAAO,EAA4B,aAAa,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGjF;;;;;GAKG;AACH,MAAM,WAAW,6BAA6B,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS;IACjF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AS,SAAS,GAAG,SAAS,EACvD,MAAM,EAAE,6BAA6B,CAAC,MAAM,CAAC,GAC5C,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAgCnC;;;;OAIG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;CAGtD"}
@@ -83,13 +83,13 @@ class ConcreteDecision {
83
83
  const getBase = params.decisions.validating.getOrAdd(conditionSets);
84
84
  /* c8 ignore next 3 - defense in depth against internal error hard to repro */
85
85
  if (getBase.isFailure()) {
86
- return fail(getBase.message);
86
+ return (0, ts_utils_1.fail)(getBase.message);
87
87
  }
88
88
  const baseDecision = getBase.value;
89
89
  return (0, ts_utils_1.mapResults)(params.candidates.map((candidate, index) => {
90
90
  /* c8 ignore next 5 - defense in depth against internal error hard to repro */
91
91
  if (candidate.conditionSet.key !== baseDecision.candidates[index].conditionSet.key) {
92
- return fail(`${candidate.conditionSet.key}: Candidate does not match base decision ${candidate.conditionSet.key}`);
92
+ return (0, ts_utils_1.fail)(`${candidate.conditionSet.key}: Candidate does not match base decision ${candidate.conditionSet.key}`);
93
93
  }
94
94
  return (0, ts_utils_1.succeed)(candidate.value);
95
95
  })).onSuccess((values) => {
@@ -1 +1 @@
1
- {"version":3,"file":"concreteDecision.js","sourceRoot":"","sources":["../../../src/packlets/decisions/concreteDecision.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,2CAAoD;AAIpD,4CAAwF;AACxF,8CAA6C;AAC7C,sCAAiF;AACjF,yCAAsC;AA0BtC;;;;;;GAMG;AACH,MAAa,gBAAgB;IAK3B;;;OAGG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACjC,CAAC;IAID;;;;;OAKG;IACH,YAAsB,MAAk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CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YACzC,8EAA8E;YAC9E,IAAI,SAAS,CAAC,YAAY,CAAC,GAAG,KAAK,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;gBACnF,OAAO,IAAI,CACT,GAAG,SAAS,CAAC,YAAY,CAAC,GAAG,4CAA4C,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,CACtG,CAAC;YACJ,CAAC;YACD,OAAO,IAAA,kBAAO,EAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC,CAAC,CACH,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACrB,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjB,OAAO,gBAAa,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;oBAC3E,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;gBACpF,CAAC,CAAC,CAAC;YACL,CAAC;YACD,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QAC7E,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,QAAQ,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF;AA5FD,4CA4FC","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 { JsonValue } from '@fgv/ts-json-base';\nimport { Candidate, ICandidate } from './candidate';\nimport { IDecision } from './common';\nimport { AbstractDecisionCollector } from './abstractDecisionCollector';\nimport { AbstractDecision } from './abstractDecision';\nimport { captureResult, Collections, mapResults, Result, succeed } from '@fgv/ts-utils';\nimport { ConditionSet } from '../conditions';\nimport { Convert as CommonConvert, DecisionIndex, DecisionKey } from '../common';\nimport { Decision } from './decision';\n\n/**\n * Parameters used to create a new {@link Decisions.ConcreteDecision | ConcreteDecision},\n * given an {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} and a\n * list of {@link Decisions.ICandidate | candidates}.\n * @public\n */\nexport interface IConcreteDecisionCreateParams<TVALUE extends JsonValue = JsonValue> {\n decisions: AbstractDecisionCollector;\n candidates: ReadonlyArray<ICandidate<TVALUE>>;\n index?: number;\n}\n\n/**\n * Protected constructor parameters for {@link Decisions.ConcreteDecision | ConcreteDecision},\n * used to create a new concrete decision from an existing {@link Decisions.AbstractDecision | AbstractDecision}\n * and a list of values.\n * @public\n */\nexport interface IConcreteDecisionConstructorParams<TVALUE extends JsonValue = JsonValue> {\n baseDecision: AbstractDecision;\n values: TVALUE[];\n index?: DecisionIndex;\n}\n\n/**\n * A {@link Decisions.ConcreteDecision | concrete decision} is a {@link Decisions.IDecision | decision}\n * implemented as a reference to a common {@link Decisions.AbstractDecision | abstract decision} and a list of\n * values that correspond to the candidates in the abstract decision. This allows us to represent a large\n * number of related decisions with a single abstract decision and a list of values.\n * @public\n */\nexport class ConcreteDecision<TVALUE extends JsonValue = JsonValue> implements IDecision<TVALUE> {\n public readonly baseDecision: AbstractDecision;\n public readonly values: TVALUE[];\n public readonly candidates: ReadonlyArray<ICandidate<TVALUE>>;\n\n /**\n * Unique global key for this decision, derived from the condition set and\n * candidate values.\n */\n public get key(): DecisionKey {\n return this._collectible.key;\n }\n\n /**\n * Unique global index for this decision.\n */\n public get index(): DecisionIndex | undefined {\n return this._collectible.index;\n }\n\n private _collectible: Collections.Collectible<DecisionKey, DecisionIndex>;\n\n /**\n * Constructor for a {@link Decisions.ConcreteDecision | ConcreteDecision} object.\n * @param params - {@link Decisions.IConcreteDecisionConstructorParams | Parameters}\n * used to create the decision.\n * @public\n */\n protected constructor(params: IConcreteDecisionConstructorParams<TVALUE>) {\n this.baseDecision = params.baseDecision;\n this.values = params.values;\n this.candidates = this.baseDecision.candidates.map((candidate) => {\n const value = this.values[candidate.value];\n return Candidate.createCandidate({ conditionSet: candidate.conditionSet, value }).orThrow();\n });\n this._collectible = new Collections.Collectible({\n key: Decision.getKey(this.candidates),\n index: params.index,\n indexConverter: CommonConvert.decisionIndex\n });\n }\n\n /**\n * Creates a new {@link Decisions.ConcreteDecision | ConcreteDecision} object.\n * @param params - {@link Decisions.IConcreteDecisionCreateParams | Parameters}\n * used to create the decision.\n * @returns `Success` with the new decision if successful, or `Failure` with an\n * error message if not.\n * @public\n */\n public static create<TVALUE extends JsonValue = JsonValue>(\n params: IConcreteDecisionCreateParams<TVALUE>\n ): Result<ConcreteDecision<TVALUE>> {\n const conditionSets = params.candidates\n .map((candidate) => candidate.conditionSet)\n .sort(ConditionSet.compare)\n .reverse();\n\n const getBase = params.decisions.validating.getOrAdd(conditionSets);\n /* c8 ignore next 3 - defense in depth against internal error hard to repro */\n if (getBase.isFailure()) {\n return fail(getBase.message);\n }\n const baseDecision = getBase.value;\n return mapResults(\n params.candidates.map((candidate, index) => {\n /* c8 ignore next 5 - defense in depth against internal error hard to repro */\n if (candidate.conditionSet.key !== baseDecision.candidates[index].conditionSet.key) {\n return fail(\n `${candidate.conditionSet.key}: Candidate does not match base decision ${candidate.conditionSet.key}`\n );\n }\n return succeed(candidate.value);\n })\n ).onSuccess((values) => {\n if (params.index) {\n return CommonConvert.decisionIndex.convert(params.index).onSuccess((index) => {\n return captureResult(() => new ConcreteDecision({ baseDecision, values, index }));\n });\n }\n return captureResult(() => new ConcreteDecision({ baseDecision, values }));\n });\n }\n\n /**\n * Sets the index for this decision. Once set, index is immutable.\n * @param index - The index to set.\n * @returns `Success` with the new index if successful, or `Failure` with an error message if not.\n */\n public setIndex(index: number): Result<DecisionIndex> {\n return this._collectible.setIndex(index);\n }\n}\n"]}
1
+ {"version":3,"file":"concreteDecision.js","sourceRoot":"","sources":["../../../src/packlets/decisions/concreteDecision.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,2CAAoD;AAIpD,4CAA8F;AAC9F,8CAA6C;AAC7C,sCAAiF;AACjF,yCAAsC;AA0BtC;;;;;;GAMG;AACH,MAAa,gBAAgB;IAK3B;;;OAGG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACjC,CAAC;IAID;;;;;OAKG;IACH,YAAsB,MAAkD;QACtE,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,IAAI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,KAAK,CAAC,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;gBACnF,OAAO,IAAA,eAAI,EACT,GAAG,SAAS,CAAC,YAAY,CAAC,GAAG,4CAA4C,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,CACtG,CAAC;YACJ,CAAC;YACD,OAAO,IAAA,kBAAO,EAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC,CAAC,CACH,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACrB,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjB,OAAO,gBAAa,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;oBAC3E,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;gBACpF,CAAC,CAAC,CAAC;YACL,CAAC;YACD,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QAC7E,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,QAAQ,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF;AA5FD,4CA4FC","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 { JsonValue } from '@fgv/ts-json-base';\nimport { Candidate, ICandidate } from './candidate';\nimport { IDecision } from './common';\nimport { AbstractDecisionCollector } from './abstractDecisionCollector';\nimport { AbstractDecision } from './abstractDecision';\nimport { captureResult, Collections, mapResults, Result, fail, succeed } from '@fgv/ts-utils';\nimport { ConditionSet } from '../conditions';\nimport { Convert as CommonConvert, DecisionIndex, DecisionKey } from '../common';\nimport { Decision } from './decision';\n\n/**\n * Parameters used to create a new {@link Decisions.ConcreteDecision | ConcreteDecision},\n * given an {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} and a\n * list of {@link Decisions.ICandidate | candidates}.\n * @public\n */\nexport interface IConcreteDecisionCreateParams<TVALUE extends JsonValue = JsonValue> {\n decisions: AbstractDecisionCollector;\n candidates: ReadonlyArray<ICandidate<TVALUE>>;\n index?: number;\n}\n\n/**\n * Protected constructor parameters for {@link Decisions.ConcreteDecision | ConcreteDecision},\n * used to create a new concrete decision from an existing {@link Decisions.AbstractDecision | AbstractDecision}\n * and a list of values.\n * @public\n */\nexport interface IConcreteDecisionConstructorParams<TVALUE extends JsonValue = JsonValue> {\n baseDecision: AbstractDecision;\n values: TVALUE[];\n index?: DecisionIndex;\n}\n\n/**\n * A {@link Decisions.ConcreteDecision | concrete decision} is a {@link Decisions.IDecision | decision}\n * implemented as a reference to a common {@link Decisions.AbstractDecision | abstract decision} and a list of\n * values that correspond to the candidates in the abstract decision. This allows us to represent a large\n * number of related decisions with a single abstract decision and a list of values.\n * @public\n */\nexport class ConcreteDecision<TVALUE extends JsonValue = JsonValue> implements IDecision<TVALUE> {\n public readonly baseDecision: AbstractDecision;\n public readonly values: TVALUE[];\n public readonly candidates: ReadonlyArray<ICandidate<TVALUE>>;\n\n /**\n * Unique global key for this decision, derived from the condition set and\n * candidate values.\n */\n public get key(): DecisionKey {\n return this._collectible.key;\n }\n\n /**\n * Unique global index for this decision.\n */\n public get index(): DecisionIndex | undefined {\n return this._collectible.index;\n }\n\n private _collectible: Collections.Collectible<DecisionKey, DecisionIndex>;\n\n /**\n * Constructor for a {@link Decisions.ConcreteDecision | ConcreteDecision} object.\n * @param params - {@link Decisions.IConcreteDecisionConstructorParams | Parameters}\n * used to create the decision.\n * @public\n */\n protected constructor(params: IConcreteDecisionConstructorParams<TVALUE>) {\n this.baseDecision = params.baseDecision;\n this.values = params.values;\n this.candidates = this.baseDecision.candidates.map((candidate) => {\n const value = this.values[candidate.value];\n return Candidate.createCandidate({ conditionSet: candidate.conditionSet, value }).orThrow();\n });\n this._collectible = new Collections.Collectible({\n key: Decision.getKey(this.candidates),\n index: params.index,\n indexConverter: CommonConvert.decisionIndex\n });\n }\n\n /**\n * Creates a new {@link Decisions.ConcreteDecision | ConcreteDecision} object.\n * @param params - {@link Decisions.IConcreteDecisionCreateParams | Parameters}\n * used to create the decision.\n * @returns `Success` with the new decision if successful, or `Failure` with an\n * error message if not.\n * @public\n */\n public static create<TVALUE extends JsonValue = JsonValue>(\n params: IConcreteDecisionCreateParams<TVALUE>\n ): Result<ConcreteDecision<TVALUE>> {\n const conditionSets = params.candidates\n .map((candidate) => candidate.conditionSet)\n .sort(ConditionSet.compare)\n .reverse();\n\n const getBase = params.decisions.validating.getOrAdd(conditionSets);\n /* c8 ignore next 3 - defense in depth against internal error hard to repro */\n if (getBase.isFailure()) {\n return fail<ConcreteDecision<TVALUE>>(getBase.message);\n }\n const baseDecision = getBase.value;\n return mapResults(\n params.candidates.map((candidate, index) => {\n /* c8 ignore next 5 - defense in depth against internal error hard to repro */\n if (candidate.conditionSet.key !== baseDecision.candidates[index].conditionSet.key) {\n return fail<TVALUE>(\n `${candidate.conditionSet.key}: Candidate does not match base decision ${candidate.conditionSet.key}`\n );\n }\n return succeed(candidate.value);\n })\n ).onSuccess((values) => {\n if (params.index) {\n return CommonConvert.decisionIndex.convert(params.index).onSuccess((index) => {\n return captureResult(() => new ConcreteDecision({ baseDecision, values, index }));\n });\n }\n return captureResult(() => new ConcreteDecision({ baseDecision, values }));\n });\n }\n\n /**\n * Sets the index for this decision. Once set, index is immutable.\n * @param index - The index to set.\n * @returns `Success` with the new index if successful, or `Failure` with an error message if not.\n */\n public setIndex(index: number): Result<DecisionIndex> {\n return this._collectible.setIndex(index);\n }\n}\n"]}
@@ -60,7 +60,7 @@ export declare abstract class ResourceType<T = unknown> implements ICollectible<
60
60
  * `Failure` with an error message otherwise.
61
61
  * @public
62
62
  */
63
- abstract validate(json: JsonValue, isPartial: true): Result<T>;
63
+ abstract validate(json: JsonValue, isPartial: true): Result<Partial<T>>;
64
64
  /**
65
65
  * Validates a JSON value for use as a complete resource instance value.
66
66
  * @param json - The JSON value to validate.
@@ -69,7 +69,7 @@ export declare abstract class ResourceType<T = unknown> implements ICollectible<
69
69
  * `Failure` with an error message otherwise.
70
70
  * @public
71
71
  */
72
- abstract validate(json: JsonValue, isPartial: false): Result<Partial<T>>;
72
+ abstract validate(json: JsonValue, isPartial: false): Result<T>;
73
73
  /**
74
74
  * Validates a JSON value for use as a full or partial resource instance value.
75
75
  * @param json - The JSON value to validate.
@@ -1 +1 @@
1
- {"version":3,"file":"resourceType.d.ts","sourceRoot":"","sources":["../../../src/packlets/resource-types/resourceType.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAe,YAAY,EAAE,MAAM,EAAE,MAAM,eAAe,CAA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GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAE/E;;;;;;;OAOG;aACa,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAErF;;OAEG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC;CAG1D"}
1
+ {"version":3,"file":"resourceType.d.ts","sourceRoot":"","sources":["../../../src/packlets/resource-types/resourceType.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAe,YAAY,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAGL,iBAAiB,EACjB,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,WAAW,CAAC;AAEnB;;;;;GAKG;AACH,8BAAsB,YAAY,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,YAAY,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;IAC1G,OAAO,CAAC,YAAY,CAA+D;IACnF;;OAEG;IACH,IAAW,GAAG,IAAI,gBAAgB,CAEjC;IAED;;OAEG;IACH,IAAW,KAAK,IAAI,iBAAiB,GAAG,SAAS,CAEhD;IAED,SAAS,aAAa,GAAG,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,MAAM;IAS3D;;;;;;;;;OASG;aACa,mBAAmB,CACjC,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,IAAI,EACf,WAAW,CAAC,EAAE,wBAAwB,GACrC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAErB;;;;;;;;;OASG;aACa,mBAAmB,CACjC,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,KAAK,EAChB,WAAW,CAAC,EAAE,wBAAwB,GACrC,MAAM,CAAC,CAAC,CAAC;IAEZ;;;;;;;;;OASG;aACa,mBAAmB,CACjC,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ACnF,GAAG;YACH,qDAAqD;YACrD,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,iBAAQ,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS;YACtF,cAAc,EAAE,gBAAa,CAAC,iBAAiB;SAChD,CAAC,CAAC;IACL,CAAC;IAsFD;;OAEG;IACI,QAAQ,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF;AAnHD,oCAmHC","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 { JsonValue } from '@fgv/ts-json-base';\nimport { Collections, ICollectible, Result } from '@fgv/ts-utils';\nimport {\n Convert as CommonConvert,\n Validate,\n ResourceTypeIndex,\n ResourceTypeName,\n ResourceValueMergeMethod\n} from '../common';\n\n/**\n * Abstract base class for resource types which are responsible for\n * validating and converting JSON values into the appropriate strongly-typed\n * resource value.\n * @public\n */\nexport abstract class ResourceType<T = unknown> implements ICollectible<ResourceTypeName, ResourceTypeIndex> {\n private _collectible: Collections.Collectible<ResourceTypeName, ResourceTypeIndex>;\n /**\n * The key for this resource type.\n */\n public get key(): ResourceTypeName {\n return this._collectible.key;\n }\n\n /**\n * The index for this resource type.\n */\n public get index(): ResourceTypeIndex | undefined {\n return this._collectible.index;\n }\n\n protected constructor(key: ResourceTypeName, index?: number) {\n this._collectible = new Collections.Collectible<ResourceTypeName, ResourceTypeIndex>({\n key,\n /* c8 ignore next 1 - coverage having a rough time */\n index: index !== undefined ? Validate.toResourceTypeIndex(index).orThrow() : undefined,\n indexConverter: CommonConvert.resourceTypeIndex\n });\n }\n\n /**\n * Validates a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration} for\n * a partial resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - `true` indicates that the value is expected to be incomplete.\n * @param mergeMethod - The method to use when merging with previously resolved values.\n * @returns `Success` with the strongly-typed resource value if the JSON and merge\n * method are valid, `Failure` with an error message otherwise.\n * @public\n */\n public abstract validateDeclaration(\n json: JsonValue,\n isPartial: true,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<Partial<T>>;\n\n /**\n * Validates a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration} for\n * a complete resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - `false` indicates that the value is expected to be complete.\n * @param mergeMethod - The method to use when merging with previously resolved values.\n * @returns `Success` with the strongly-typed resource value if the JSON and merge method\n * are valid, `Failure` with an error message otherwise.\n * @public\n */\n public abstract validateDeclaration(\n json: JsonValue,\n isPartial: false,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<T>;\n\n /**\n * Validates a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration} for\n * a resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - Indicates whether the value is expected to be incomplete.\n * @param mergeMethod - The method to use when merging with previously resolved values.\n * @returns `Success` with the strongly-typed resource value if the JSON and merge method\n * are valid, `Failure` with an error message otherwise.\n * @public\n */\n public abstract validateDeclaration(\n json: JsonValue,\n isPartial: boolean,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<T | Partial<T>>;\n\n public abstract validateDeclaration(\n json: JsonValue,\n isPartial: boolean,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<T | Partial<T>>;\n\n /**\n * Validates a JSON value for use as a partial resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - `true` indicates that the value is expected to be partial.\n * @returns `Success` with the strongly-typed partial resource value if the JSON is valid,\n * `Failure` with an error message otherwise.\n * @public\n */\n public abstract validate(json: JsonValue, isPartial: true): Result<T>;\n\n /**\n * Validates a JSON value for use as a complete resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - `false` indicates that the value is expected to be complete.\n * @returns `Success` with the strongly-typed resource value if the JSON is valid,\n * `Failure` with an error message otherwise.\n * @public\n */\n public abstract validate(json: JsonValue, isPartial: false): Result<Partial<T>>;\n\n /**\n * Validates a JSON value for use as a full or partial resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - Indicates whether the value is expected to be partial.\n * @returns `Success` with the strongly-typed full or partial resource value if\n * the JSON is valid, `Failure` with an error message otherwise.\n * @public\n */\n public abstract validate(json: JsonValue, isPartial: boolean): Result<T | Partial<T>>;\n\n /**\n * Sets the index for this resource type. Once set, the index cannot be changed.\n */\n public setIndex(index: number): Result<ResourceTypeIndex> {\n return this._collectible.setIndex(index);\n }\n}\n"]}
1
+ {"version":3,"file":"resourceType.js","sourceRoot":"","sources":["../../../src/packlets/resource-types/resourceType.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,4CAAkE;AAClE,sCAMmB;AAEnB;;;;;GAKG;AACH,MAAsB,YAAY;IAEhC;;OAEG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACjC,CAAC;IAED,YAAsB,GAAqB,EAAE,KAAc;QACzD,IAAI,CAAC,YAAY,GAAG,IAAI,sBAAW,CAAC,WAAW,CAAsC;YACnF,GAAG;YACH,qDAAqD;YACrD,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,iBAAQ,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS;YACtF,cAAc,EAAE,gBAAa,CAAC,iBAAiB;SAChD,CAAC,CAAC;IACL,CAAC;IAsFD;;OAEG;IACI,QAAQ,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF;AAnHD,oCAmHC","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 { JsonValue } from '@fgv/ts-json-base';\nimport { Collections, ICollectible, Result } from '@fgv/ts-utils';\nimport {\n Convert as CommonConvert,\n Validate,\n ResourceTypeIndex,\n ResourceTypeName,\n ResourceValueMergeMethod\n} from '../common';\n\n/**\n * Abstract base class for resource types which are responsible for\n * validating and converting JSON values into the appropriate strongly-typed\n * resource value.\n * @public\n */\nexport abstract class ResourceType<T = unknown> implements ICollectible<ResourceTypeName, ResourceTypeIndex> {\n private _collectible: Collections.Collectible<ResourceTypeName, ResourceTypeIndex>;\n /**\n * The key for this resource type.\n */\n public get key(): ResourceTypeName {\n return this._collectible.key;\n }\n\n /**\n * The index for this resource type.\n */\n public get index(): ResourceTypeIndex | undefined {\n return this._collectible.index;\n }\n\n protected constructor(key: ResourceTypeName, index?: number) {\n this._collectible = new Collections.Collectible<ResourceTypeName, ResourceTypeIndex>({\n key,\n /* c8 ignore next 1 - coverage having a rough time */\n index: index !== undefined ? Validate.toResourceTypeIndex(index).orThrow() : undefined,\n indexConverter: CommonConvert.resourceTypeIndex\n });\n }\n\n /**\n * Validates a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration} for\n * a partial resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - `true` indicates that the value is expected to be incomplete.\n * @param mergeMethod - The method to use when merging with previously resolved values.\n * @returns `Success` with the strongly-typed resource value if the JSON and merge\n * method are valid, `Failure` with an error message otherwise.\n * @public\n */\n public abstract validateDeclaration(\n json: JsonValue,\n isPartial: true,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<Partial<T>>;\n\n /**\n * Validates a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration} for\n * a complete resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - `false` indicates that the value is expected to be complete.\n * @param mergeMethod - The method to use when merging with previously resolved values.\n * @returns `Success` with the strongly-typed resource value if the JSON and merge method\n * are valid, `Failure` with an error message otherwise.\n * @public\n */\n public abstract validateDeclaration(\n json: JsonValue,\n isPartial: false,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<T>;\n\n /**\n * Validates a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration} for\n * a resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - Indicates whether the value is expected to be incomplete.\n * @param mergeMethod - The method to use when merging with previously resolved values.\n * @returns `Success` with the strongly-typed resource value if the JSON and merge method\n * are valid, `Failure` with an error message otherwise.\n * @public\n */\n public abstract validateDeclaration(\n json: JsonValue,\n isPartial: boolean,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<T | Partial<T>>;\n\n public abstract validateDeclaration(\n json: JsonValue,\n isPartial: boolean,\n mergeMethod?: ResourceValueMergeMethod\n ): Result<T | Partial<T>>;\n\n /**\n * Validates a JSON value for use as a partial resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - `true` indicates that the value is expected to be partial.\n * @returns `Success` with the strongly-typed partial resource value if the JSON is valid,\n * `Failure` with an error message otherwise.\n * @public\n */\n public abstract validate(json: JsonValue, isPartial: true): Result<Partial<T>>;\n\n /**\n * Validates a JSON value for use as a complete resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - `false` indicates that the value is expected to be complete.\n * @returns `Success` with the strongly-typed resource value if the JSON is valid,\n * `Failure` with an error message otherwise.\n * @public\n */\n public abstract validate(json: JsonValue, isPartial: false): Result<T>;\n\n /**\n * Validates a JSON value for use as a full or partial resource instance value.\n * @param json - The JSON value to validate.\n * @param isPartial - Indicates whether the value is expected to be partial.\n * @returns `Success` with the strongly-typed full or partial resource value if\n * the JSON is valid, `Failure` with an error message otherwise.\n * @public\n */\n public abstract validate(json: JsonValue, isPartial: boolean): Result<T | Partial<T>>;\n\n /**\n * Sets the index for this resource type. Once set, the index cannot be changed.\n */\n public setIndex(index: number): Result<ResourceTypeIndex> {\n return this._collectible.setIndex(index);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"resourceManager.d.ts","sourceRo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AC,CAAC;IAChF,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,mBAAmB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC9E,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;IAE1B;;;;OAIG;IACH,IAAW,UAAU,IAAI,0BAA0B,CAElD;IAED;;;;OAIG;IACH,IAAW,aAAa,IAAI,6BAA6B,CAExD;IAED;;;;OAIG;IACH,IAAW,SAAS,IAAI,iCAAiC,CAExD;IAED;;OAEG;IACH,IAAW,SAAS,IAAI,WAAW,CAAC,4BAA4B,CAAC,UAAU,EAAE,eAAe,CAAC,CAE5F;IAED;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;;;OAIG;IACH,SAAS,aAAa,MAAM,EAAE,4BAA4B;IAwB1D;;;;;;OAMG;WACW,MAAM,CAAC,MAAM,EAAE,4BAA4B,GAAG,MAAM,CAAC,eAAe,CAAC;IAInF;;;;;;OAMG;IACI,iBAAiB,CACtB,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,2BAA2B,GAClD,cAAc,CAAC,iBAAiB,EAAE,2BAA2B,CAAC;IA2B1D,WAAW,CAChB,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,kBAAkB,GACzC,cAAc,CAAC,eAAe,EAAE,2BAA2B,CAAC;IAsC/D;;;;;OAKG;IACI,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;IAMrD;;;;;OAKG;IACI,KAAK,IAAI,MAAM,CAAC,WAAW,CAAC,4BAA4B,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;CAcvF"}
1
+ {"version":3,"file":"resourceManager.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/resourceManager.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,WAAW,EACX,cAAc,EAKd,MAAM,EAGN,mBAAmB,EACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,E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IAAI,0BAA0B,CAElD;IAED;;;;OAIG;IACH,IAAW,aAAa,IAAI,6BAA6B,CAExD;IAED;;;;OAIG;IACH,IAAW,SAAS,IAAI,iCAAiC,CAExD;IAED;;OAEG;IACH,IAAW,SAAS,IAAI,WAAW,CAAC,4BAA4B,CAAC,UAAU,EAAE,eAAe,CAAC,CAE5F;IAED;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;;;OAIG;IACH,SAAS,aAAa,MAAM,EAAE,4BAA4B;IAwB1D;;;;;;OAMG;WACW,MAAM,CAAC,MAAM,EAAE,4BAA4B,GAAG,MAAM,CAAC,eAAe,CAAC;IAInF;;;;;;OAMG;IACI,iBAAiB,CACtB,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,2BAA2B,GAClD,cAAc,CAAC,iBAAiB,EAAE,2BAA2B,CAAC;IA2B1D,WAAW,CAChB,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,kBAAkB,GACzC,cAAc,CAAC,eAAe,EAAE,2BAA2B,CAAC;IAsC/D;;;;;OAKG;IACI,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;IAMrD;;;;;OAKG;IACI,KAAK,IAAI,MAAM,CAAC,WAAW,CAAC,4BAA4B,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;CAcvF"}
@@ -87,14 +87,14 @@ class ResourceManager {
87
87
  converters: new ts_utils_1.Collections.KeyValueConverters({
88
88
  key: common_1.Convert.resourceId,
89
89
  /* c8 ignore next 2 - defense in depth against internal error */
90
- value: (from) => from instanceof resourceBuilder_1.ResourceBuilder ? (0, ts_utils_1.succeed)(from) : fail('not a resource builder')
90
+ value: (from) => from instanceof resourceBuilder_1.ResourceBuilder ? (0, ts_utils_1.succeed)(from) : (0, ts_utils_1.fail)('not a resource builder')
91
91
  })
92
92
  });
93
93
  this._builtResources = new ts_utils_1.ValidatingResultMap({
94
94
  converters: new ts_utils_1.Collections.KeyValueConverters({
95
95
  key: common_1.Convert.resourceId,
96
96
  /* c8 ignore next 1 - defense in depth against internal error */
97
- value: (from) => (from instanceof resource_1.Resource ? (0, ts_utils_1.succeed)(from) : fail('not a resource'))
97
+ value: (from) => (from instanceof resource_1.Resource ? (0, ts_utils_1.succeed)(from) : (0, ts_utils_1.fail)('not a resource'))
98
98
  })
99
99
  });
100
100
  this._built = false;
@@ -190,7 +190,7 @@ class ResourceManager {
190
190
  });
191
191
  /* c8 ignore next 3 - defense in depth against internal error */
192
192
  if (errors.hasMessages) {
193
- return fail(`build failed: ${errors.toString()}`);
193
+ return (0, ts_utils_1.fail)(`build failed: ${errors.toString()}`);
194
194
  }
195
195
  this._built = true;
196
196
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resourceManager.js","sourceRoot":"","sources":["../../../src/packlets/resources/resourceManager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAWuB;AACvB,8CAKuB;AACvB,4CAA4F;AAG5F,sCAA0D;AAC1D,uDAAiF;AACjF,yCAAsC;AAmBtC;;;;;;GAMG;AACH,MAAa,eAAe;IAW1B;;;;OAIG;IACH,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACH,YAAsB,MAAoC;QACxD,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,MAAM,C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QAC1B,CAAC,CAAC;aACD,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACI,gBAAgB,CAAC,EAAU;QAChC,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU;aAC9B,GAAG,CAAC,EAAE,CAAC;aACP,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACjG,CAAC;IAED;;;;;OAKG;IACI,KAAK;QACV,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,MAAM,GAAsB,IAAI,4BAAiB,EAAE,CAAC;YAC1D,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE;gBAChC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YAC5E,CAAC,CAAC,CAAC;YACH,gEAAgE;YAChE,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;gBACvB,OAAO,IAAI,CAAC,iBAAiB,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACpD,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;QACD,OAAO,IAAA,kBAAO,EAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACvC,CAAC;CACF;AAxMD,0CAwMC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n captureResult,\n Collections,\n DetailedResult,\n failWithDetail,\n mapResults,\n MessageAggregator,\n Result,\n succeed,\n succeedWithDetail,\n ValidatingResultMap\n} from '@fgv/ts-utils';\nimport {\n ConditionCollector,\n ConditionSetCollector,\n ReadOnlyConditionCollector,\n ReadOnlyConditionSetCollector\n} from '../conditions';\nimport { AbstractDecisionCollector, ReadOnlyAbstractDecisionCollector } from '../decisions';\nimport { IReadOnlyQualifierCollector } from '../qualifiers';\nimport { ReadOnlyResourceTypeCollector } from '../resource-types';\nimport { Convert, ResourceId, Validate } from '../common';\nimport { ResourceBuilder, ResourceBuilderResultDetail } from './resourceBuilder';\nimport { Resource } from './resource';\nimport { ResourceCandidate } from './resourceCandidate';\nimport * as ResourceJson from '../resource-json';\n\n/**\n * Interface for parameters to the {@link Resources.ResourceManager.create | ResourceManager create method}.\n * @public\n */\nexport interface IResourceManagerCreateParams {\n qualifiers: IReadOnlyQualifierCollector;\n resourceTypes: ReadOnlyResourceTypeCollector;\n}\n\n/**\n * Error details that can be returned by a {@link Resources.ResourceManager | ResourceManager}.\n * @public\n */\nexport type ResourceManagerResultDetail = Collections.ResultMapResultDetail | ResourceBuilderResultDetail;\n\n/**\n * Represents a manager for a collection of {@link Resources.Resource | resources}. Collects\n * {@link Resources.ResourceCandidate | candidates} for each resource into a\n * {@link Resources.ResourceBuilder | ResourceBuilder} per resource, validates them against each other,\n * and builds a collection of {@link Resources.Resource | resources} once all candidates are collected.\n * @public\n */\nexport class ResourceManager {\n public readonly qualifiers: IReadOnlyQualifierCollector;\n public readonly resourceTypes: ReadOnlyResourceTypeCollector;\n\n protected readonly _conditions: ConditionCollector;\n protected readonly _conditionSets: ConditionSetCollector;\n protected readonly _decisions: AbstractDecisionCollector;\n protected readonly _resources: ValidatingResultMap<ResourceId, ResourceBuilder>;\n protected readonly _builtResources: ValidatingResultMap<ResourceId, Resource>;\n protected _built: boolean;\n\n /**\n * A {@link Conditions.ConditionCollector | ConditionCollector} which\n * contains the {@link Conditions.Condition | conditions} used so far by\n * the {@link Resources.ResourceCandidate | resource candidates} in this manager.\n */\n public get conditions(): ReadOnlyConditionCollector {\n return this._conditions;\n }\n\n /**\n * A {@link Conditions.ConditionSetCollector | ConditionSetCollector} which\n * contains the {@link Conditions.ConditionSet | condition sets} used so far by\n * the {@link Resources.ResourceCandidate | resource candidates} in this manager.\n */\n public get conditionSets(): ReadOnlyConditionSetCollector {\n return this._conditionSets;\n }\n\n /**\n * A {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} which\n * contains the {@link Decisions.Decision | abstract decisions} used so far by\n * the {@link Resources.ResourceCandidate | resource candidates} in this manager.\n */\n public get decisions(): ReadOnlyAbstractDecisionCollector {\n return this._decisions;\n }\n\n /**\n * A read-only map of {@link Resources.ResourceBuilder | resource builders} used by the manager.\n */\n public get resources(): Collections.IReadOnlyValidatingResultMap<ResourceId, ResourceBuilder> {\n return this._resources;\n }\n\n /**\n * The number of {@link Resources.Resource | resources} contained by the manager.\n */\n public get size(): number {\n return this._resources.size;\n }\n\n /**\n * Constructor for a {@link Resources.ResourceManager | ResourceManager} object.\n * @param params - Parameters to create a new {@link Resources.ResourceManager | ResourceManager}.\n * @public\n */\n protected constructor(params: IResourceManagerCreateParams) {\n this.qualifiers = params.qualifiers;\n this.resourceTypes = params.resourceTypes;\n this._conditions = ConditionCollector.create({ qualifiers: params.qualifiers }).orThrow();\n this._conditionSets = ConditionSetCollector.create({ conditions: this._conditions }).orThrow();\n this._decisions = AbstractDecisionCollector.create({ conditionSets: this._conditionSets }).orThrow();\n this._resources = new ValidatingResultMap({\n converters: new Collections.KeyValueConverters<ResourceId, ResourceBuilder>({\n key: Convert.resourceId,\n /* c8 ignore next 2 - defense in depth against internal error */\n value: (from: unknown) =>\n from instanceof ResourceBuilder ? succeed(from) : fail('not a resource builder')\n })\n });\n this._builtResources = new ValidatingResultMap({\n converters: new Collections.KeyValueConverters<ResourceId, Resource>({\n key: Convert.resourceId,\n /* c8 ignore next 1 - defense in depth against internal error */\n value: (from: unknown) => (from instanceof Resource ? succeed(from) : fail('not a resource'))\n })\n });\n this._built = false;\n }\n\n /**\n * Creates a new {@link Resources.ResourceManager | ResourceManager} object.\n * @param params - Parameters to create a new {@link Resources.ResourceManager | ResourceManager}.\n * @returns `Success` with the new {@link Resources.ResourceManager | ResourceManager} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IResourceManagerCreateParams): Result<ResourceManager> {\n return captureResult(() => new ResourceManager(params));\n }\n\n /**\n * Given a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration}, builds and adds\n * a {@link Resources.ResourceCandidate | candidate} to the manager.\n * @param candidate - The {@link Resources.ResourceCandidate | candidate} to add.\n * @returns `Success` with the candidate if successful, or `Failure` with an error message if not.\n * @public\n */\n public addLooseCandidate(\n decl: ResourceJson.Json.ILooseResourceCandidateDecl\n ): DetailedResult<ResourceCandidate, ResourceManagerResultDetail> {\n const { value: id, message } = Validate.toResourceId(decl.id);\n if (message !== undefined) {\n return failWithDetail(`${id}: invalid id - ${message}`, 'failure');\n }\n\n const builderResult = this._resources.getOrAdd(id, () =>\n ResourceBuilder.create({\n id,\n resourceTypes: this.resourceTypes,\n conditionSets: this._conditionSets\n })\n );\n /* c8 ignore next 6 - defense in depth against internal error */\n if (builderResult.isFailure()) {\n return failWithDetail(\n `${id}: unable to get or add resource\\n${builderResult.message}`,\n builderResult.detail\n );\n }\n return builderResult.value.addLooseCandidate(decl).onSuccess((c, d) => {\n this._builtResources.delete(id);\n this._built = false;\n return succeedWithDetail(c, d);\n });\n }\n\n public addResource(\n decl: ResourceJson.Json.ILooseResourceDecl\n ): DetailedResult<ResourceBuilder, ResourceManagerResultDetail> {\n const { value: id, message } = Validate.toResourceId(decl.id);\n if (message !== undefined) {\n return failWithDetail(`${id}: invalid id - ${message}`, 'failure');\n }\n\n const {\n value: builder,\n message: getOrAddMessage,\n detail\n } = this._resources.getOrAdd(id, () =>\n ResourceBuilder.create({\n id,\n typeName: decl.resourceTypeName,\n resourceTypes: this.resourceTypes,\n conditionSets: this._conditionSets\n })\n );\n /* c8 ignore next 3 - defense in depth against internal error */\n if (getOrAddMessage !== undefined) {\n return failWithDetail(`${id}: unable to get or add resource\\n${getOrAddMessage}`, detail);\n }\n\n if (detail === 'exists') {\n const { message } = builder.setResourceType(decl.resourceTypeName);\n if (message !== undefined) {\n return failWithDetail(`${id}: unable to set resource type\\n${message}`, 'type-mismatch');\n }\n }\n\n const candidates = decl.candidates ?? [];\n return mapResults(candidates.map((c) => builder.addChildCandidate(c)))\n .onSuccess(() => {\n return succeed(builder);\n })\n .withDetail('failure', detail);\n }\n\n /**\n * Gets an individual {@link Resources.Resource | built resource} from the manager.\n * @param id - The {@link ResourceId | id} of the resource to get.\n * @returns `Success` with the resource if successful, or `Failure` with an error message if not.\n * @public\n */\n public getBuiltResource(id: string): Result<Resource> {\n return this._resources.validating\n .get(id)\n .onSuccess((builder) => this._builtResources.validating.getOrAdd(id, () => builder.build()));\n }\n\n /**\n * Builds the {@link Resources.Resource | resources} from the collected {@link Resources.ResourceCandidate | candidates}.\n * @returns `Success` with a read-only map of {@link Resources.Resource | resources} if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public build(): Result<Collections.IReadOnlyValidatingResultMap<ResourceId, Resource>> {\n if (!this._built) {\n const errors: MessageAggregator = new MessageAggregator();\n this._resources.forEach((r, id) => {\n this._builtResources.getOrAdd(id, () => r.build()).aggregateError(errors);\n });\n /* c8 ignore next 3 - defense in depth against internal error */\n if (errors.hasMessages) {\n return fail(`build failed: ${errors.toString()}`);\n }\n this._built = true;\n }\n return succeed(this._builtResources);\n }\n}\n"]}
1
+ {"version":3,"file":"resourceManager.js","sourceRoot":"","sources":["../../../src/packlets/resources/resourceManager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAYuB;AACvB,8CAKuB;AACvB,4CAA4F;AAG5F,sCAA0D;AAC1D,uDAAiF;AACjF,yCAAsC;AAmBtC;;;;;;GAMG;AACH,MAAa,eAAe;IAW1B;;;;OAIG;IACH,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACH,YAAsB,MAAoC;QACxD,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,+BAAkB,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QAC1F,IAAI,CAAC,cAAc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U;aAC9B,GAAG,CAAC,EAAE,CAAC;aACP,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACjG,CAAC;IAED;;;;;OAKG;IACI,KAAK;QACV,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,MAAM,GAAsB,IAAI,4BAAiB,EAAE,CAAC;YAC1D,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE;gBAChC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YAC5E,CAAC,CAAC,CAAC;YACH,gEAAgE;YAChE,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;gBACvB,OAAO,IAAA,eAAI,EAAC,iBAAiB,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YACpD,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;QACD,OAAO,IAAA,kBAAO,EAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACvC,CAAC;CACF;AAxMD,0CAwMC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n captureResult,\n Collections,\n DetailedResult,\n fail,\n failWithDetail,\n mapResults,\n MessageAggregator,\n Result,\n succeed,\n succeedWithDetail,\n ValidatingResultMap\n} from '@fgv/ts-utils';\nimport {\n ConditionCollector,\n ConditionSetCollector,\n ReadOnlyConditionCollector,\n ReadOnlyConditionSetCollector\n} from '../conditions';\nimport { AbstractDecisionCollector, ReadOnlyAbstractDecisionCollector } from '../decisions';\nimport { IReadOnlyQualifierCollector } from '../qualifiers';\nimport { ReadOnlyResourceTypeCollector } from '../resource-types';\nimport { Convert, ResourceId, Validate } from '../common';\nimport { ResourceBuilder, ResourceBuilderResultDetail } from './resourceBuilder';\nimport { Resource } from './resource';\nimport { ResourceCandidate } from './resourceCandidate';\nimport * as ResourceJson from '../resource-json';\n\n/**\n * Interface for parameters to the {@link Resources.ResourceManager.create | ResourceManager create method}.\n * @public\n */\nexport interface IResourceManagerCreateParams {\n qualifiers: IReadOnlyQualifierCollector;\n resourceTypes: ReadOnlyResourceTypeCollector;\n}\n\n/**\n * Error details that can be returned by a {@link Resources.ResourceManager | ResourceManager}.\n * @public\n */\nexport type ResourceManagerResultDetail = Collections.ResultMapResultDetail | ResourceBuilderResultDetail;\n\n/**\n * Represents a manager for a collection of {@link Resources.Resource | resources}. Collects\n * {@link Resources.ResourceCandidate | candidates} for each resource into a\n * {@link Resources.ResourceBuilder | ResourceBuilder} per resource, validates them against each other,\n * and builds a collection of {@link Resources.Resource | resources} once all candidates are collected.\n * @public\n */\nexport class ResourceManager {\n public readonly qualifiers: IReadOnlyQualifierCollector;\n public readonly resourceTypes: ReadOnlyResourceTypeCollector;\n\n protected readonly _conditions: ConditionCollector;\n protected readonly _conditionSets: ConditionSetCollector;\n protected readonly _decisions: AbstractDecisionCollector;\n protected readonly _resources: ValidatingResultMap<ResourceId, ResourceBuilder>;\n protected readonly _builtResources: ValidatingResultMap<ResourceId, Resource>;\n protected _built: boolean;\n\n /**\n * A {@link Conditions.ConditionCollector | ConditionCollector} which\n * contains the {@link Conditions.Condition | conditions} used so far by\n * the {@link Resources.ResourceCandidate | resource candidates} in this manager.\n */\n public get conditions(): ReadOnlyConditionCollector {\n return this._conditions;\n }\n\n /**\n * A {@link Conditions.ConditionSetCollector | ConditionSetCollector} which\n * contains the {@link Conditions.ConditionSet | condition sets} used so far by\n * the {@link Resources.ResourceCandidate | resource candidates} in this manager.\n */\n public get conditionSets(): ReadOnlyConditionSetCollector {\n return this._conditionSets;\n }\n\n /**\n * A {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} which\n * contains the {@link Decisions.Decision | abstract decisions} used so far by\n * the {@link Resources.ResourceCandidate | resource candidates} in this manager.\n */\n public get decisions(): ReadOnlyAbstractDecisionCollector {\n return this._decisions;\n }\n\n /**\n * A read-only map of {@link Resources.ResourceBuilder | resource builders} used by the manager.\n */\n public get resources(): Collections.IReadOnlyValidatingResultMap<ResourceId, ResourceBuilder> {\n return this._resources;\n }\n\n /**\n * The number of {@link Resources.Resource | resources} contained by the manager.\n */\n public get size(): number {\n return this._resources.size;\n }\n\n /**\n * Constructor for a {@link Resources.ResourceManager | ResourceManager} object.\n * @param params - Parameters to create a new {@link Resources.ResourceManager | ResourceManager}.\n * @public\n */\n protected constructor(params: IResourceManagerCreateParams) {\n this.qualifiers = params.qualifiers;\n this.resourceTypes = params.resourceTypes;\n this._conditions = ConditionCollector.create({ qualifiers: params.qualifiers }).orThrow();\n this._conditionSets = ConditionSetCollector.create({ conditions: this._conditions }).orThrow();\n this._decisions = AbstractDecisionCollector.create({ conditionSets: this._conditionSets }).orThrow();\n this._resources = new ValidatingResultMap({\n converters: new Collections.KeyValueConverters<ResourceId, ResourceBuilder>({\n key: Convert.resourceId,\n /* c8 ignore next 2 - defense in depth against internal error */\n value: (from: unknown) =>\n from instanceof ResourceBuilder ? succeed(from) : fail('not a resource builder')\n })\n });\n this._builtResources = new ValidatingResultMap({\n converters: new Collections.KeyValueConverters<ResourceId, Resource>({\n key: Convert.resourceId,\n /* c8 ignore next 1 - defense in depth against internal error */\n value: (from: unknown) => (from instanceof Resource ? succeed(from) : fail('not a resource'))\n })\n });\n this._built = false;\n }\n\n /**\n * Creates a new {@link Resources.ResourceManager | ResourceManager} object.\n * @param params - Parameters to create a new {@link Resources.ResourceManager | ResourceManager}.\n * @returns `Success` with the new {@link Resources.ResourceManager | ResourceManager} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IResourceManagerCreateParams): Result<ResourceManager> {\n return captureResult(() => new ResourceManager(params));\n }\n\n /**\n * Given a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration}, builds and adds\n * a {@link Resources.ResourceCandidate | candidate} to the manager.\n * @param candidate - The {@link Resources.ResourceCandidate | candidate} to add.\n * @returns `Success` with the candidate if successful, or `Failure` with an error message if not.\n * @public\n */\n public addLooseCandidate(\n decl: ResourceJson.Json.ILooseResourceCandidateDecl\n ): DetailedResult<ResourceCandidate, ResourceManagerResultDetail> {\n const { value: id, message } = Validate.toResourceId(decl.id);\n if (message !== undefined) {\n return failWithDetail(`${id}: invalid id - ${message}`, 'failure');\n }\n\n const builderResult = this._resources.getOrAdd(id, () =>\n ResourceBuilder.create({\n id,\n resourceTypes: this.resourceTypes,\n conditionSets: this._conditionSets\n })\n );\n /* c8 ignore next 6 - defense in depth against internal error */\n if (builderResult.isFailure()) {\n return failWithDetail(\n `${id}: unable to get or add resource\\n${builderResult.message}`,\n builderResult.detail\n );\n }\n return builderResult.value.addLooseCandidate(decl).onSuccess((c, d) => {\n this._builtResources.delete(id);\n this._built = false;\n return succeedWithDetail(c, d);\n });\n }\n\n public addResource(\n decl: ResourceJson.Json.ILooseResourceDecl\n ): DetailedResult<ResourceBuilder, ResourceManagerResultDetail> {\n const { value: id, message } = Validate.toResourceId(decl.id);\n if (message !== undefined) {\n return failWithDetail(`${id}: invalid id - ${message}`, 'failure');\n }\n\n const {\n value: builder,\n message: getOrAddMessage,\n detail\n } = this._resources.getOrAdd(id, () =>\n ResourceBuilder.create({\n id,\n typeName: decl.resourceTypeName,\n resourceTypes: this.resourceTypes,\n conditionSets: this._conditionSets\n })\n );\n /* c8 ignore next 3 - defense in depth against internal error */\n if (getOrAddMessage !== undefined) {\n return failWithDetail(`${id}: unable to get or add resource\\n${getOrAddMessage}`, detail);\n }\n\n if (detail === 'exists') {\n const { message } = builder.setResourceType(decl.resourceTypeName);\n if (message !== undefined) {\n return failWithDetail(`${id}: unable to set resource type\\n${message}`, 'type-mismatch');\n }\n }\n\n const candidates = decl.candidates ?? [];\n return mapResults(candidates.map((c) => builder.addChildCandidate(c)))\n .onSuccess(() => {\n return succeed(builder);\n })\n .withDetail('failure', detail);\n }\n\n /**\n * Gets an individual {@link Resources.Resource | built resource} from the manager.\n * @param id - The {@link ResourceId | id} of the resource to get.\n * @returns `Success` with the resource if successful, or `Failure` with an error message if not.\n * @public\n */\n public getBuiltResource(id: string): Result<Resource> {\n return this._resources.validating\n .get(id)\n .onSuccess((builder) => this._builtResources.validating.getOrAdd(id, () => builder.build()));\n }\n\n /**\n * Builds the {@link Resources.Resource | resources} from the collected {@link Resources.ResourceCandidate | candidates}.\n * @returns `Success` with a read-only map of {@link Resources.Resource | resources} if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public build(): Result<Collections.IReadOnlyValidatingResultMap<ResourceId, Resource>> {\n if (!this._built) {\n const errors: MessageAggregator = new MessageAggregator();\n this._resources.forEach((r, id) => {\n this._builtResources.getOrAdd(id, () => r.build()).aggregateError(errors);\n });\n /* c8 ignore next 3 - defense in depth against internal error */\n if (errors.hasMessages) {\n return fail(`build failed: ${errors.toString()}`);\n }\n this._built = true;\n }\n return succeed(this._builtResources);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-res",
3
- "version": "4.5.0-2",
3
+ "version": "4.5.0-3",
4
4
  "description": "Multi-dimensional Resource Runtime",
5
5
  "main": "lib/index.js",
6
6
  "types": "dist/ts-res.d.ts",
@@ -18,10 +18,10 @@
18
18
  "homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-res#readme",
19
19
  "sideEffects": false,
20
20
  "devDependencies": {
21
- "@fgv/ts-utils": "4.5.0-2",
22
- "@fgv/ts-utils-jest": "4.5.0-2",
23
- "@fgv/ts-extras": "4.5.0-2",
24
- "@fgv/ts-json-base": "4.5.0-2",
21
+ "@fgv/ts-utils": "4.5.0-3",
22
+ "@fgv/ts-utils-jest": "4.5.0-3",
23
+ "@fgv/ts-extras": "4.5.0-3",
24
+ "@fgv/ts-json-base": "4.5.0-3",
25
25
  "@microsoft/api-documenter": "^7.26.17",
26
26
  "@microsoft/api-extractor": "^7.52.1",
27
27
  "@types/jest": "^29.5.14",
@@ -48,18 +48,18 @@
48
48
  "@rushstack/heft-node-rig": "~2.8.2",
49
49
  "@types/heft-jest": "1.0.6",
50
50
  "eslint-plugin-tsdoc": "~0.4.0",
51
- "@fgv/ts-bcp47": "4.5.0-2",
52
- "@fgv/ts-json": "4.5.0-2"
51
+ "@fgv/ts-bcp47": "4.5.0-3",
52
+ "@fgv/ts-json": "4.5.0-3"
53
53
  },
54
54
  "dependencies": {
55
55
  "luxon": "^3.5.0"
56
56
  },
57
57
  "peerDependencies": {
58
- "@fgv/ts-utils": "4.5.0-2",
59
- "@fgv/ts-extras": "4.5.0-2",
60
- "@fgv/ts-json-base": "4.5.0-2",
61
- "@fgv/ts-bcp47": "4.5.0-2",
62
- "@fgv/ts-json": "4.5.0-2"
58
+ "@fgv/ts-utils": "4.5.0-3",
59
+ "@fgv/ts-extras": "4.5.0-3",
60
+ "@fgv/ts-json-base": "4.5.0-3",
61
+ "@fgv/ts-bcp47": "4.5.0-3",
62
+ "@fgv/ts-json": "4.5.0-3"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "heft build --clean",