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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/ts-res.d.ts +83 -13
  2. package/lib/packlets/conditions/condition.d.ts +26 -0
  3. package/lib/packlets/conditions/condition.d.ts.map +1 -1
  4. package/lib/packlets/conditions/condition.js +43 -0
  5. package/lib/packlets/conditions/condition.js.map +1 -1
  6. package/lib/packlets/conditions/conditionDecls.d.ts +2 -7
  7. package/lib/packlets/conditions/conditionDecls.d.ts.map +1 -1
  8. package/lib/packlets/conditions/conditionDecls.js.map +1 -1
  9. package/lib/packlets/conditions/conditionSet.d.ts +13 -0
  10. package/lib/packlets/conditions/conditionSet.d.ts.map +1 -1
  11. package/lib/packlets/conditions/conditionSet.js +18 -0
  12. package/lib/packlets/conditions/conditionSet.js.map +1 -1
  13. package/lib/packlets/conditions/convert/decls.d.ts +2 -2
  14. package/lib/packlets/conditions/convert/decls.d.ts.map +1 -1
  15. package/lib/packlets/resource-json/helpers.d.ts +15 -5
  16. package/lib/packlets/resource-json/helpers.d.ts.map +1 -1
  17. package/lib/packlets/resource-json/helpers.js.map +1 -1
  18. package/lib/packlets/resources/resource.d.ts +13 -0
  19. package/lib/packlets/resources/resource.d.ts.map +1 -1
  20. package/lib/packlets/resources/resource.js +21 -4
  21. package/lib/packlets/resources/resource.js.map +1 -1
  22. package/lib/packlets/resources/resourceCandidate.d.ts +14 -0
  23. package/lib/packlets/resources/resourceCandidate.d.ts.map +1 -1
  24. package/lib/packlets/resources/resourceCandidate.js +22 -0
  25. package/lib/packlets/resources/resourceCandidate.js.map +1 -1
  26. package/lib/packlets/resources/resourceManager.d.ts.map +1 -1
  27. package/lib/packlets/resources/resourceManager.js +17 -9
  28. package/lib/packlets/resources/resourceManager.js.map +1 -1
  29. package/package.json +20 -20
package/dist/ts-res.d.ts CHANGED
@@ -348,6 +348,31 @@ declare class Condition implements IValidatedConditionDecl {
348
348
  * @public
349
349
  */
350
350
  toString(): string;
351
+ /**
352
+ * Gets the {@link ResourceJson.Json.IChildConditionDecl | child condition declaration} for this condition.
353
+ * @param options - The {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the child
354
+ * condition declaration.
355
+ * @returns The {@link ResourceJson.Json.IChildConditionDecl | child condition declaration} for this condition.
356
+ * @public
357
+ */
358
+ toChildConditionDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.IChildConditionDecl;
359
+ /**
360
+ * Gets the value for this condition, or the {@link ResourceJson.Json.IChildConditionDecl | child condition declaration}
361
+ * if the condition has non-default operator, priority or a score as default.
362
+ * @param options - The {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the child
363
+ * condition declaration.
364
+ * @returns A string value for this condition, or the {@link ResourceJson.Json.IChildConditionDecl | child condition declaration}
365
+ * if the condition has non-default operator, priority or a score as default.
366
+ */
367
+ toValueOrChildConditionDecl(options?: ResourceJson.Helpers.IDeclarationOptions): string | ResourceJson.Json.IChildConditionDecl;
368
+ /**
369
+ * Gets the {@link ResourceJson.Json.ILooseConditionDecl | loose condition declaration} for this condition.
370
+ * @param options - The {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the loose
371
+ * condition declaration.
372
+ * @returns The {@link ResourceJson.Json.ILooseConditionDecl | loose condition declaration} for this condition.
373
+ * @public
374
+ */
375
+ toLooseConditionDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.ILooseConditionDecl;
351
376
  /**
352
377
  * Gets the {@link ConditionKey | condition key} for a supplied {@link Conditions.IValidatedConditionDecl | condition declaration}.
353
378
  * @param decl - The {@link Conditions.IValidatedConditionDecl | condition declaration} for which to get the key.
@@ -391,7 +416,7 @@ declare class ConditionCollector extends ValidatingCollector<Condition> {
391
416
  * Converter for a {@link Conditions.IConditionDecl | condition declaration}.
392
417
  * @public
393
418
  */
394
- declare const conditionDecl: ObjectConverter<IConditionDecl, unknown>;
419
+ declare const conditionDecl: ObjectConverter<ILooseConditionDecl, unknown>;
395
420
 
396
421
  /**
397
422
  * Branded number representing a validated condition index.
@@ -565,6 +590,18 @@ declare class ConditionSet implements IValidatedConditionSetDecl {
565
590
  * @returns A string representation of this condition set.
566
591
  */
567
592
  toString(): string;
593
+ /**
594
+ * Gets the {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.
595
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.
596
+ * @returns The {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.
597
+ */
598
+ toConditionSetRecordDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.ConditionSetDeclAsRecord;
599
+ /**
600
+ * Gets the {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.
601
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.
602
+ * @returns The {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.
603
+ */
604
+ toConditionSetArrayDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.ConditionSetDeclAsArray;
568
605
  }
569
606
 
570
607
  /**
@@ -1130,7 +1167,8 @@ declare namespace Helpers_2 {
1130
1167
  mergeLooseCandidate,
1131
1168
  mergeChildCandidate,
1132
1169
  mergeLooseResource,
1133
- mergeChildResource
1170
+ mergeChildResource,
1171
+ IDeclarationOptions
1134
1172
  }
1135
1173
  }
1136
1174
 
@@ -1313,13 +1351,7 @@ declare interface IConditionCollectorCreateParams {
1313
1351
  * Non-validated declaration of a {@link Conditions.Condition | condition}.
1314
1352
  * @public
1315
1353
  */
1316
- declare interface IConditionDecl {
1317
- qualifierName: string;
1318
- value: string;
1319
- operator?: ConditionOperator;
1320
- priority?: number;
1321
- scoreAsDefault?: number;
1322
- }
1354
+ declare type IConditionDecl = ResourceJson.Json.ILooseConditionDecl;
1323
1355
 
1324
1356
  /**
1325
1357
  * Conversion context to uses when converting
@@ -1407,6 +1439,18 @@ declare interface IDecisionCreateParams<TVALUE extends JsonValue = JsonValue> {
1407
1439
  index?: number;
1408
1440
  }
1409
1441
 
1442
+ /**
1443
+ * Common options when creating or displaying declarations.
1444
+ * @public
1445
+ */
1446
+ declare interface IDeclarationOptions {
1447
+ /**
1448
+ * If `true`, properties with default values will be included in the
1449
+ * output. IF omitted or `false`, properties with default values will be omitted.
1450
+ */
1451
+ showDefaults?: boolean;
1452
+ }
1453
+
1410
1454
  /**
1411
1455
  * @internal
1412
1456
  */
@@ -2766,7 +2810,7 @@ export declare const MaxConditionPriority: ConditionPriority;
2766
2810
  * @returns `Success` with the merged candidate if successful, otherwise `Failure`.
2767
2811
  * @public
2768
2812
  */
2769
- declare function mergeChildCandidate(candidate: Normalized.IChildResourceCandidateDecl, baseConditions?: ReadonlyArray<Json.ILooseConditionDecl | Conditions.IConditionDecl>): Result<Normalized.IChildResourceCandidateDecl>;
2813
+ declare function mergeChildCandidate(candidate: Normalized.IChildResourceCandidateDecl, baseConditions?: ReadonlyArray<Json.ILooseConditionDecl>): Result<Normalized.IChildResourceCandidateDecl>;
2770
2814
 
2771
2815
  /**
2772
2816
  * Helper method to merge a child resource with a parent name and conditions.
@@ -2777,7 +2821,7 @@ declare function mergeChildCandidate(candidate: Normalized.IChildResourceCandida
2777
2821
  * @returns `Success` with the merged resource if successful, otherwise `Failure`.
2778
2822
  * @public
2779
2823
  */
2780
- declare function mergeChildResource(resource: Normalized.IChildResourceDecl, name: string, parentName?: string, parentConditions?: ReadonlyArray<Json.ILooseConditionDecl | Conditions.IConditionDecl>): Result<Normalized.ILooseResourceDecl>;
2824
+ declare function mergeChildResource(resource: Normalized.IChildResourceDecl, name: string, parentName?: string, parentConditions?: ReadonlyArray<Json.ILooseConditionDecl>): Result<Normalized.ILooseResourceDecl>;
2781
2825
 
2782
2826
  /**
2783
2827
  * Helper method to merge a loose candidate with a base name and conditions.
@@ -2787,7 +2831,7 @@ declare function mergeChildResource(resource: Normalized.IChildResourceDecl, nam
2787
2831
  * @returns `Success` with the merged candidate if successful, otherwise `Failure`.
2788
2832
  * @public
2789
2833
  */
2790
- declare function mergeLooseCandidate(candidate: Normalized.ILooseResourceCandidateDecl, baseName?: string, baseConditions?: ReadonlyArray<Json.ILooseConditionDecl | Conditions.IConditionDecl>): Result<Normalized.ILooseResourceCandidateDecl>;
2834
+ declare function mergeLooseCandidate(candidate: Normalized.ILooseResourceCandidateDecl, baseName?: string, baseConditions?: ReadonlyArray<Json.ILooseConditionDecl>): Result<Normalized.ILooseResourceCandidateDecl>;
2791
2835
 
2792
2836
  /**
2793
2837
  * Helper method to merge a loose resource with a base name and conditions.
@@ -2797,7 +2841,7 @@ declare function mergeLooseCandidate(candidate: Normalized.ILooseResourceCandida
2797
2841
  * @returns `Success` with the merged resource if successful, otherwise `Failure`.
2798
2842
  * @public
2799
2843
  */
2800
- declare function mergeLooseResource(resource: Normalized.ILooseResourceDecl, baseName?: string, baseConditions?: ReadonlyArray<Json.ILooseConditionDecl | Conditions.IConditionDecl>): Result<Normalized.ILooseResourceDecl>;
2844
+ declare function mergeLooseResource(resource: Normalized.ILooseResourceDecl, baseName?: string, baseConditions?: ReadonlyArray<Json.ILooseConditionDecl>): Result<Normalized.ILooseResourceDecl>;
2801
2845
 
2802
2846
  /**
2803
2847
  * Minimum valid priority for a condition.
@@ -3337,6 +3381,18 @@ declare class Resource {
3337
3381
  * @public
3338
3382
  */
3339
3383
  static create(params: IResourceCreateParams): Result<Resource>;
3384
+ /**
3385
+ * Gets the {@link ResourceJson.Json.IChildResourceDecl | child resource declaration} for this resource.
3386
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.
3387
+ * @returns The {@link ResourceJson.Json.IChildResourceDecl | child resource declaration}.
3388
+ */
3389
+ toChildResourceDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.IChildResourceDecl;
3390
+ /**
3391
+ * Gets the {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration} for this resource.
3392
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.
3393
+ * @returns The {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration}.
3394
+ */
3395
+ toLooseResourceDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.ILooseResourceDecl;
3340
3396
  /**
3341
3397
  * Validates that all candidates have the same id as the resource.
3342
3398
  * @param resourceId - The expected id of the resource.
@@ -3500,6 +3556,20 @@ declare class ResourceCandidate {
3500
3556
  * @public
3501
3557
  */
3502
3558
  static create(params: IResourceCandidateCreateParams): Result<ResourceCandidate>;
3559
+ /**
3560
+ * Gets the {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}
3561
+ * for this candidate.
3562
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the declaration.
3563
+ * @returns The {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}.
3564
+ */
3565
+ toChildResourceCandidateDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.IChildResourceCandidateDecl;
3566
+ /**
3567
+ * Gets the {@link ResourceJson.Json.ILooseResourceCandidateDecl | loose resource candidate declaration}
3568
+ * for this candidate.
3569
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the declaration.
3570
+ * @returns The {@link ResourceJson.Json.ILooseResourceCandidateDecl | loose resource candidate declaration}.
3571
+ */
3572
+ toLooseResourceCandidateDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.ILooseResourceCandidateDecl;
3503
3573
  /**
3504
3574
  * Extracts the {@link ResourceTypes.ResourceType | resource type} from a list of {@link Resources.ResourceCandidate | resource candidates},
3505
3575
  * if present.
@@ -2,6 +2,7 @@ import { Collections, Result } from '@fgv/ts-utils';
2
2
  import { ConditionIndex, ConditionKey, ConditionOperator, ConditionPriority, ConditionToken, QualifierConditionValue, QualifierMatchScore } from '../common';
3
3
  import { Qualifier } from '../qualifiers';
4
4
  import { IValidatedConditionDecl } from './conditionDecls';
5
+ import * as ResourceJson from '../resource-json';
5
6
  /**
6
7
  * Represents a single condition applied to some resource instance.
7
8
  * @public
@@ -80,6 +81,31 @@ export declare class Condition implements IValidatedConditionDecl {
80
81
  * @public
81
82
  */
82
83
  toString(): string;
84
+ /**
85
+ * Gets the {@link ResourceJson.Json.IChildConditionDecl | child condition declaration} for this condition.
86
+ * @param options - The {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the child
87
+ * condition declaration.
88
+ * @returns The {@link ResourceJson.Json.IChildConditionDecl | child condition declaration} for this condition.
89
+ * @public
90
+ */
91
+ toChildConditionDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.IChildConditionDecl;
92
+ /**
93
+ * Gets the value for this condition, or the {@link ResourceJson.Json.IChildConditionDecl | child condition declaration}
94
+ * if the condition has non-default operator, priority or a score as default.
95
+ * @param options - The {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the child
96
+ * condition declaration.
97
+ * @returns A string value for this condition, or the {@link ResourceJson.Json.IChildConditionDecl | child condition declaration}
98
+ * if the condition has non-default operator, priority or a score as default.
99
+ */
100
+ toValueOrChildConditionDecl(options?: ResourceJson.Helpers.IDeclarationOptions): string | ResourceJson.Json.IChildConditionDecl;
101
+ /**
102
+ * Gets the {@link ResourceJson.Json.ILooseConditionDecl | loose condition declaration} for this condition.
103
+ * @param options - The {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the loose
104
+ * condition declaration.
105
+ * @returns The {@link ResourceJson.Json.ILooseConditionDecl | loose condition declaration} for this condition.
106
+ * @public
107
+ */
108
+ toLooseConditionDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.ILooseConditionDecl;
83
109
  /**
84
110
  * Gets the {@link ConditionKey | condition key} for a supplied {@link Conditions.IValidatedConditionDecl | condition declaration}.
85
111
  * @param decl - The {@link Conditions.IValidatedConditionDecl | condition declaration} for which to get the key.
@@ -1 +1 @@
1
- {"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../../../src/packlets/conditions/condition.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAiB,WAAW,EAAE,MAAM,EAAQ,MAAM,eAAe,CAAC;AACzE,OAAO,EAEL,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EAEpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAK3D;;;GAGG;AACH,qBAAa,SAAU,YAAW,uBAAuB;IACvD;;OAEG;IACH,SAAgB,SAAS,EAAE,SAAS,CAAC;IAErC;;OAEG;IACH,SAAgB,KAAK,EAAE,uBAAuB,CAAC;IAE/C;;OAEG;IACH,SAAgB,QAAQ,EAAE,iBAAiB,CAAC;IAE5C;;OAEG;IACH,SAAgB,QAAQ,EAAE,iBAAiB,CAAC;IAE5C;;OAEG;IACH,SAAgB,cAAc,CAAC,EAAE,mBAAmB,CAAC;IAErD,SAAS,CAAC,YAAY,EAAE,WAAW,CAAC,WAAW,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IAE9E;;;;;;;OAOG;IACH,SAAS,aAAa,EACpB,SAAS,EACT,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,KAAK,EACN,EAAE,uBAAuB;IAa1B,IAAW,GAAG,IAAI,YAAY,CAE7B;IAED,IAAW,KAAK,IAAI,cAAc,GAAG,SAAS,CAE7C;IAEM,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;IAI9D;;;;;;;;OAQG;WACW,MAAM,CAAC,IAAI,EAAE,uBAAuB,GAAG,MAAM,CAAC,SAAS,CAAC;IAItE;;;;;;;OAOG;WACW,OAAO,CAAC,EAAE,EAAE,SAAS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,EACN,EAAE,uBAAuB;IAa1B,IAAW,GAAG,IAAI,YAAY,CAE7B;IAED,IAAW,KAAK,IAAI,cAAc,GAAG,SAAS,CAE7C;IAEM,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;IAI9D;;;;;;;;OAQG;WACW,MAAM,CAAC,IAAI,EAAE,uBAAuB,GAAG,MAAM,CAAC,SAAS,CAAC;IAItE;;;;;;;OAOG;WACW,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,GAAG,MAAM;IAQ3D;;;;;;;;OAQG;IACI,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC;IAgBvD;;;OAGG;IACI,KAAK,IAAI,YAAY;IAI5B;;;;OAIG;IACI,QAAQ,IAAI,MAAM;IAIzB;;;;;;OAMG;IACI,oBAAoB,CACzB,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,mBAAmB,GACjD,YAAY,CAAC,IAAI,CAAC,mBAAmB;IAaxC;;;;;;;OAOG;IACI,2BAA2B,CAChC,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,mBAAmB,GACjD,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,mBAAmB;IAYjD;;;;;;OAMG;IACI,oBAAoB,CACzB,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,mBAAmB,GACjD,YAAY,CAAC,IAAI,CAAC,mBAAmB;IAcxC;;;;;OAKG;WACW,aAAa,CAAC,IAAI,EAAE,uBAAuB,GAAG,MAAM,CAAC,YAAY,CAAC;CAQjF"}
@@ -128,6 +128,49 @@ class Condition {
128
128
  toString() {
129
129
  return this.toKey();
130
130
  }
131
+ /**
132
+ * Gets the {@link ResourceJson.Json.IChildConditionDecl | child condition declaration} for this condition.
133
+ * @param options - The {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the child
134
+ * condition declaration.
135
+ * @returns The {@link ResourceJson.Json.IChildConditionDecl | child condition declaration} for this condition.
136
+ * @public
137
+ */
138
+ toChildConditionDecl(options) {
139
+ const showDefaults = (options === null || options === void 0 ? void 0 : options.showDefaults) === true;
140
+ return Object.assign(Object.assign(Object.assign({ value: this.value }, (showDefaults || this.operator !== 'matches' ? { operator: this.operator } : {})), (showDefaults || this.priority !== this.qualifier.defaultPriority
141
+ ? { priority: this.priority }
142
+ : {})), (this.scoreAsDefault ? { scoreAsDefault: this.scoreAsDefault } : {}));
143
+ }
144
+ /**
145
+ * Gets the value for this condition, or the {@link ResourceJson.Json.IChildConditionDecl | child condition declaration}
146
+ * if the condition has non-default operator, priority or a score as default.
147
+ * @param options - The {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the child
148
+ * condition declaration.
149
+ * @returns A string value for this condition, or the {@link ResourceJson.Json.IChildConditionDecl | child condition declaration}
150
+ * if the condition has non-default operator, priority or a score as default.
151
+ */
152
+ toValueOrChildConditionDecl(options) {
153
+ if ((options === null || options === void 0 ? void 0 : options.showDefaults) !== true &&
154
+ this.operator === 'matches' &&
155
+ this.priority === this.qualifier.defaultPriority &&
156
+ this.scoreAsDefault === undefined) {
157
+ return this.value;
158
+ }
159
+ return this.toChildConditionDecl(options);
160
+ }
161
+ /**
162
+ * Gets the {@link ResourceJson.Json.ILooseConditionDecl | loose condition declaration} for this condition.
163
+ * @param options - The {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the loose
164
+ * condition declaration.
165
+ * @returns The {@link ResourceJson.Json.ILooseConditionDecl | loose condition declaration} for this condition.
166
+ * @public
167
+ */
168
+ toLooseConditionDecl(options) {
169
+ const showDefaults = (options === null || options === void 0 ? void 0 : options.showDefaults) === true;
170
+ return Object.assign(Object.assign(Object.assign({ qualifierName: this.qualifier.name, value: this.value }, (showDefaults || this.operator !== 'matches' ? { operator: this.operator } : {})), (showDefaults || this.priority !== this.qualifier.defaultPriority
171
+ ? { priority: this.priority }
172
+ : {})), (this.scoreAsDefault ? { scoreAsDefault: this.scoreAsDefault } : {}));
173
+ }
131
174
  /**
132
175
  * Gets the {@link ConditionKey | condition key} for a supplied {@link Conditions.IValidatedConditionDecl | condition declaration}.
133
176
  * @param decl - The {@link Conditions.IValidatedConditionDecl | condition declaration} for which to get the key.
@@ -1 +1 @@
1
- {"version":3,"file":"condition.js","sourceRoot":"","sources":["../../../src/packlets/conditions/condition.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAyE;AACzE,sCAUmB;AAInB,kDAAkD;AAClD,MAAM,cAAc,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,qBAAqB,EAAE,CAAC,EAAE,qBAAqB,EAAE,CAAC,EAAE,CAAC,CAAC;AAE9G;;;GAGG;AACH,MAAa,SAAS;IA4BpB;;;;;;;OAOG;IACH,YAAsB,EACpB,SAAS,EACT,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,KAAK,EACmB;QACxB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;QACzE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,IAAI,sBAAW,CAAC,WAAW,CAAC;YAC9C,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE;YACjB,KAAK;YACL,cAAc,EAAE,gBAAa,CAAC,cAAc;SAC7C,CAAC,CAAC;IACL,CAAC;IAED,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;IAC/B,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC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AG,CAAC,CAAC;IACtC,CAAC;CACF;AAzJD,8BAyJC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Collections, Result, fail } from '@fgv/ts-utils';\nimport {\n Convert as CommonConvert,\n ConditionIndex,\n ConditionKey,\n ConditionOperator,\n ConditionPriority,\n ConditionToken,\n QualifierConditionValue,\n QualifierMatchScore,\n Validate\n} from '../common';\nimport { Qualifier } from '../qualifiers';\nimport { IValidatedConditionDecl } from './conditionDecls';\n\n// eslint-disable-next-line @rushstack/typedef-var\nconst scoreFormatter = new Intl.NumberFormat('en-US', { minimumFractionDigits: 0, maximumFractionDigits: 3 });\n\n/**\n * Represents a single condition applied to some resource instance.\n * @public\n */\nexport class Condition implements IValidatedConditionDecl {\n /**\n * The {@link Qualifiers.Qualifier | qualifier} used in this condition.\n */\n public readonly qualifier: Qualifier;\n\n /**\n * The value to be matched in this condition.\n */\n public readonly value: QualifierConditionValue;\n\n /**\n * The {@link ConditionOperator | operator} used when matching context value to condition value.\n */\n public readonly operator: ConditionOperator;\n\n /**\n * The {@link ConditionPriority | relative priority} of this condition.\n */\n public readonly priority: ConditionPriority;\n\n /**\n * The {@link QualifierMatchScore | score} to be used when this condition is the default.\n */\n public readonly scoreAsDefault?: QualifierMatchScore;\n\n protected _collectible: Collections.Collectible<ConditionKey, ConditionIndex>;\n\n /**\n * Constructs a new {@link Conditions.Condition | Condition} object.\n * @param qualifier - The {@link Qualifiers.Qualifier | qualifier} used in this condition.\n * @param value - The value to be matched in this condition.\n * @param operator - The {@link ConditionOperator | operator} used when matching context value to condition value.\n * @param priority - The {@link ConditionPriority | relative priority} of this condition.\n * @public\n */\n protected constructor({\n qualifier,\n value,\n operator,\n priority,\n scoreAsDefault,\n index\n }: IValidatedConditionDecl) {\n this.qualifier = qualifier;\n this.operator = operator;\n this.value = qualifier.type.validateCondition(value, operator).orThrow();\n this.priority = priority;\n this.scoreAsDefault = scoreAsDefault;\n this._collectible = new Collections.Collectible({\n key: this.toKey(),\n index,\n indexConverter: CommonConvert.conditionIndex\n });\n }\n\n public get key(): ConditionKey {\n return this._collectible.key;\n }\n\n public get index(): ConditionIndex | undefined {\n return this._collectible.index;\n }\n\n public setIndex(index: ConditionIndex): Result<ConditionIndex> {\n return this._collectible.setIndex(index);\n }\n\n /**\n * Creates a new {@link Conditions.Condition | Condition} object from the supplied\n * {@link Conditions.IValidatedConditionDecl | validated condition declaration}.\n * @param decl - The {@link Conditions.IValidatedConditionDecl | validated condition declaration}\n * describing the condition to create.\n * @returns `Success` with the new {@link Conditions.Condition | Condition} if successful,\n * `Failure` otherwise.\n * @public\n */\n public static create(decl: IValidatedConditionDecl): Result<Condition> {\n return captureResult(() => new Condition(decl));\n }\n\n /**\n * Compares two conditions for sorting purposes.\n * @param c1 - The first {@link Conditions.Condition | condition} to compare.\n * @param c2 - The second {@link Conditions.Condition | condition} to compare.\n * @returns A negative number if c1 should come before c2, a positive number\n * if c2 should come before c1, or zero if they are equivalent.\n * @public\n */\n public static compare(c1: Condition, c2: Condition): number {\n let diff = c1.priority - c2.priority;\n diff = diff === 0 ? (c1.scoreAsDefault ?? 0) - (c2.scoreAsDefault ?? 0) : diff;\n diff = diff === 0 ? c1.qualifier.name.localeCompare(c2.qualifier.name) : diff;\n diff = diff === 0 ? c1.value.localeCompare(c2.value) : diff;\n return diff;\n }\n\n /**\n * Gets a {@link ConditionToken | condition token} for this condition, if possible.\n * It is not possible to get a token for a condition with an operator other than `matches`,\n * with other-than-default priority, or with a name or value that contains other than alphanumeric\n * characters, underscore or non-leading hyphen.\n * @param terse - if `true` and if the qualifier token is optional, the token will be omitted\n * from the generated {@link ConditionToken | condition token}.\n * @returns\n */\n public toToken(terse?: boolean): Result<ConditionToken> {\n /* c8 ignore next 3 - defense in depth very difficult to induce */\n if (this.operator !== 'matches') {\n return fail(`${this.operator}: cannot create condition token for operator other than 'matches'`);\n }\n if (this.priority !== this.qualifier.defaultPriority) {\n return fail(`${this.priority}: cannot create condition token for non-default priority`);\n }\n if (terse && this.qualifier.tokenIsOptional) {\n return Validate.toConditionToken(this.value);\n }\n /* c8 ignore next 1 - coverage having a bad day */\n const name = this.qualifier.token ?? this.qualifier.name;\n return Validate.toConditionToken(`${name}=${this.value}`);\n }\n\n /**\n * Gets the {@link ConditionKey | key} for this condition.\n * @returns -\n */\n public toKey(): ConditionKey {\n return Condition.getKeyForDecl(this).orThrow();\n }\n\n /**\n * Get a human-readable string representation of the condition.\n * @returns A string representation of the condition.\n * @public\n */\n public toString(): string {\n return this.toKey();\n }\n\n /**\n * Gets the {@link ConditionKey | condition key} for a supplied {@link Conditions.IValidatedConditionDecl | condition declaration}.\n * @param decl - The {@link Conditions.IValidatedConditionDecl | condition declaration} for which to get the key.\n * @returns `Success` with the condition key if successful, `Failure` otherwise.\n * @public\n */\n public static getKeyForDecl(decl: IValidatedConditionDecl): Result<ConditionKey> {\n const scoreAsDefault = decl.scoreAsDefault ? `(${scoreFormatter.format(decl.scoreAsDefault)})` : '';\n const key =\n decl.operator === 'matches'\n ? `${decl.qualifier.name}-[${decl.value}]@${decl.priority}${scoreAsDefault}`\n : `${decl.qualifier.name}-${decl.operator}-[${decl.value}]@${decl.priority}${scoreAsDefault}`;\n return Validate.toConditionKey(key);\n }\n}\n"]}
1
+ {"version":3,"file":"condition.js","sourceRoot":"","sources":["../../../src/packlets/conditions/condition.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAyE;AACzE,sCAUmB;AAKnB,kDAAkD;AAClD,MAAM,cAAc,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,qBAAqB,EAAE,CAAC,EAAE,qBAAqB,EAAE,CAAC,EAAE,CAAC,CAAC;AAE9G;;;GAGG;AACH,MAAa,SAAS;IA4BpB;;;;;;;OAOG;IACH,YAAsB,EACpB,SAAS,EACT,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,cAAc,EACd,KAAK,EACmB;QACxB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;QACzE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,IAAI,sBAAW,CAAC,WAAW,CAAC;YAC9C,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE;YACjB,KAAK;YACL,cAAc,EAAE,gBAAa,CAAC,cAAc;SAC7C,CAAC,CAAC;IACL,CAAC;IAED,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;IAC/B,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,YAAY,CAAC,K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,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACpG,MAAM,GAAG,GACP,IAAI,CAAC,QAAQ,KAAK,SAAS;YACzB,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,QAAQ,GAAG,cAAc,EAAE;YAC5E,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,QAAQ,GAAG,cAAc,EAAE,CAAC;QAClG,OAAO,iBAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;CACF;AA5ND,8BA4NC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Collections, Result, fail } from '@fgv/ts-utils';\nimport {\n Convert as CommonConvert,\n ConditionIndex,\n ConditionKey,\n ConditionOperator,\n ConditionPriority,\n ConditionToken,\n QualifierConditionValue,\n QualifierMatchScore,\n Validate\n} from '../common';\nimport { Qualifier } from '../qualifiers';\nimport { IValidatedConditionDecl } from './conditionDecls';\nimport * as ResourceJson from '../resource-json';\n\n// eslint-disable-next-line @rushstack/typedef-var\nconst scoreFormatter = new Intl.NumberFormat('en-US', { minimumFractionDigits: 0, maximumFractionDigits: 3 });\n\n/**\n * Represents a single condition applied to some resource instance.\n * @public\n */\nexport class Condition implements IValidatedConditionDecl {\n /**\n * The {@link Qualifiers.Qualifier | qualifier} used in this condition.\n */\n public readonly qualifier: Qualifier;\n\n /**\n * The value to be matched in this condition.\n */\n public readonly value: QualifierConditionValue;\n\n /**\n * The {@link ConditionOperator | operator} used when matching context value to condition value.\n */\n public readonly operator: ConditionOperator;\n\n /**\n * The {@link ConditionPriority | relative priority} of this condition.\n */\n public readonly priority: ConditionPriority;\n\n /**\n * The {@link QualifierMatchScore | score} to be used when this condition is the default.\n */\n public readonly scoreAsDefault?: QualifierMatchScore;\n\n protected _collectible: Collections.Collectible<ConditionKey, ConditionIndex>;\n\n /**\n * Constructs a new {@link Conditions.Condition | Condition} object.\n * @param qualifier - The {@link Qualifiers.Qualifier | qualifier} used in this condition.\n * @param value - The value to be matched in this condition.\n * @param operator - The {@link ConditionOperator | operator} used when matching context value to condition value.\n * @param priority - The {@link ConditionPriority | relative priority} of this condition.\n * @public\n */\n protected constructor({\n qualifier,\n value,\n operator,\n priority,\n scoreAsDefault,\n index\n }: IValidatedConditionDecl) {\n this.qualifier = qualifier;\n this.operator = operator;\n this.value = qualifier.type.validateCondition(value, operator).orThrow();\n this.priority = priority;\n this.scoreAsDefault = scoreAsDefault;\n this._collectible = new Collections.Collectible({\n key: this.toKey(),\n index,\n indexConverter: CommonConvert.conditionIndex\n });\n }\n\n public get key(): ConditionKey {\n return this._collectible.key;\n }\n\n public get index(): ConditionIndex | undefined {\n return this._collectible.index;\n }\n\n public setIndex(index: ConditionIndex): Result<ConditionIndex> {\n return this._collectible.setIndex(index);\n }\n\n /**\n * Creates a new {@link Conditions.Condition | Condition} object from the supplied\n * {@link Conditions.IValidatedConditionDecl | validated condition declaration}.\n * @param decl - The {@link Conditions.IValidatedConditionDecl | validated condition declaration}\n * describing the condition to create.\n * @returns `Success` with the new {@link Conditions.Condition | Condition} if successful,\n * `Failure` otherwise.\n * @public\n */\n public static create(decl: IValidatedConditionDecl): Result<Condition> {\n return captureResult(() => new Condition(decl));\n }\n\n /**\n * Compares two conditions for sorting purposes.\n * @param c1 - The first {@link Conditions.Condition | condition} to compare.\n * @param c2 - The second {@link Conditions.Condition | condition} to compare.\n * @returns A negative number if c1 should come before c2, a positive number\n * if c2 should come before c1, or zero if they are equivalent.\n * @public\n */\n public static compare(c1: Condition, c2: Condition): number {\n let diff = c1.priority - c2.priority;\n diff = diff === 0 ? (c1.scoreAsDefault ?? 0) - (c2.scoreAsDefault ?? 0) : diff;\n diff = diff === 0 ? c1.qualifier.name.localeCompare(c2.qualifier.name) : diff;\n diff = diff === 0 ? c1.value.localeCompare(c2.value) : diff;\n return diff;\n }\n\n /**\n * Gets a {@link ConditionToken | condition token} for this condition, if possible.\n * It is not possible to get a token for a condition with an operator other than `matches`,\n * with other-than-default priority, or with a name or value that contains other than alphanumeric\n * characters, underscore or non-leading hyphen.\n * @param terse - if `true` and if the qualifier token is optional, the token will be omitted\n * from the generated {@link ConditionToken | condition token}.\n * @returns\n */\n public toToken(terse?: boolean): Result<ConditionToken> {\n /* c8 ignore next 3 - defense in depth very difficult to induce */\n if (this.operator !== 'matches') {\n return fail(`${this.operator}: cannot create condition token for operator other than 'matches'`);\n }\n if (this.priority !== this.qualifier.defaultPriority) {\n return fail(`${this.priority}: cannot create condition token for non-default priority`);\n }\n if (terse && this.qualifier.tokenIsOptional) {\n return Validate.toConditionToken(this.value);\n }\n /* c8 ignore next 1 - coverage having a bad day */\n const name = this.qualifier.token ?? this.qualifier.name;\n return Validate.toConditionToken(`${name}=${this.value}`);\n }\n\n /**\n * Gets the {@link ConditionKey | key} for this condition.\n * @returns -\n */\n public toKey(): ConditionKey {\n return Condition.getKeyForDecl(this).orThrow();\n }\n\n /**\n * Get a human-readable string representation of the condition.\n * @returns A string representation of the condition.\n * @public\n */\n public toString(): string {\n return this.toKey();\n }\n\n /**\n * Gets the {@link ResourceJson.Json.IChildConditionDecl | child condition declaration} for this condition.\n * @param options - The {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the child\n * condition declaration.\n * @returns The {@link ResourceJson.Json.IChildConditionDecl | child condition declaration} for this condition.\n * @public\n */\n public toChildConditionDecl(\n options?: ResourceJson.Helpers.IDeclarationOptions\n ): ResourceJson.Json.IChildConditionDecl {\n const showDefaults = options?.showDefaults === true;\n return {\n value: this.value,\n /* c8 ignore next 1 - not really possible to reproduce right now */\n ...(showDefaults || this.operator !== 'matches' ? { operator: this.operator } : {}),\n ...(showDefaults || this.priority !== this.qualifier.defaultPriority\n ? { priority: this.priority }\n : {}),\n ...(this.scoreAsDefault ? { scoreAsDefault: this.scoreAsDefault } : {})\n };\n }\n\n /**\n * Gets the value for this condition, or the {@link ResourceJson.Json.IChildConditionDecl | child condition declaration}\n * if the condition has non-default operator, priority or a score as default.\n * @param options - The {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the child\n * condition declaration.\n * @returns A string value for this condition, or the {@link ResourceJson.Json.IChildConditionDecl | child condition declaration}\n * if the condition has non-default operator, priority or a score as default.\n */\n public toValueOrChildConditionDecl(\n options?: ResourceJson.Helpers.IDeclarationOptions\n ): string | ResourceJson.Json.IChildConditionDecl {\n if (\n options?.showDefaults !== true &&\n this.operator === 'matches' &&\n this.priority === this.qualifier.defaultPriority &&\n this.scoreAsDefault === undefined\n ) {\n return this.value;\n }\n return this.toChildConditionDecl(options);\n }\n\n /**\n * Gets the {@link ResourceJson.Json.ILooseConditionDecl | loose condition declaration} for this condition.\n * @param options - The {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the loose\n * condition declaration.\n * @returns The {@link ResourceJson.Json.ILooseConditionDecl | loose condition declaration} for this condition.\n * @public\n */\n public toLooseConditionDecl(\n options?: ResourceJson.Helpers.IDeclarationOptions\n ): ResourceJson.Json.ILooseConditionDecl {\n const showDefaults = options?.showDefaults === true;\n return {\n qualifierName: this.qualifier.name,\n value: this.value,\n /* c8 ignore next 1 - not really possible to reproduce right now */\n ...(showDefaults || this.operator !== 'matches' ? { operator: this.operator } : {}),\n ...(showDefaults || this.priority !== this.qualifier.defaultPriority\n ? { priority: this.priority }\n : {}),\n ...(this.scoreAsDefault ? { scoreAsDefault: this.scoreAsDefault } : {})\n };\n }\n\n /**\n * Gets the {@link ConditionKey | condition key} for a supplied {@link Conditions.IValidatedConditionDecl | condition declaration}.\n * @param decl - The {@link Conditions.IValidatedConditionDecl | condition declaration} for which to get the key.\n * @returns `Success` with the condition key if successful, `Failure` otherwise.\n * @public\n */\n public static getKeyForDecl(decl: IValidatedConditionDecl): Result<ConditionKey> {\n const scoreAsDefault = decl.scoreAsDefault ? `(${scoreFormatter.format(decl.scoreAsDefault)})` : '';\n const key =\n decl.operator === 'matches'\n ? `${decl.qualifier.name}-[${decl.value}]@${decl.priority}${scoreAsDefault}`\n : `${decl.qualifier.name}-${decl.operator}-[${decl.value}]@${decl.priority}${scoreAsDefault}`;\n return Validate.toConditionKey(key);\n }\n}\n"]}
@@ -1,16 +1,11 @@
1
1
  import { ConditionIndex, ConditionOperator, ConditionPriority, QualifierConditionValue, QualifierMatchScore } from '../common';
2
2
  import { Qualifier } from '../qualifiers';
3
+ import * as ResourceJson from '../resource-json';
3
4
  /**
4
5
  * Non-validated declaration of a {@link Conditions.Condition | condition}.
5
6
  * @public
6
7
  */
7
- export interface IConditionDecl {
8
- qualifierName: string;
9
- value: string;
10
- operator?: ConditionOperator;
11
- priority?: number;
12
- scoreAsDefault?: number;
13
- }
8
+ export type IConditionDecl = ResourceJson.Json.ILooseConditionDecl;
14
9
  /**
15
10
  * Validated declaration of a {@link Conditions.Condition | condition} with all defaults applied.
16
11
  * @public
@@ -1 +1 @@
1
- {"version":3,"file":"conditionDecls.d.ts","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionDecls.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,uBAAuB,CAAC;IAC/B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB"}
1
+ {"version":3,"file":"conditionDecls.d.ts","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionDecls.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AAEjD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC;AAEnE;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,uBAAuB,CAAC;IAC/B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"conditionDecls.js","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionDecls.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","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 ConditionIndex,\n ConditionOperator,\n ConditionPriority,\n QualifierConditionValue,\n QualifierMatchScore\n} from '../common';\nimport { Qualifier } from '../qualifiers';\n\n/**\n * Non-validated declaration of a {@link Conditions.Condition | condition}.\n * @public\n */\nexport interface IConditionDecl {\n qualifierName: string;\n value: string;\n operator?: ConditionOperator;\n priority?: number;\n scoreAsDefault?: number;\n}\n\n/**\n * Validated declaration of a {@link Conditions.Condition | condition} with all defaults applied.\n * @public\n */\nexport interface IValidatedConditionDecl {\n qualifier: Qualifier;\n value: QualifierConditionValue;\n operator: ConditionOperator;\n priority: ConditionPriority;\n scoreAsDefault?: QualifierMatchScore;\n index?: ConditionIndex;\n}\n"]}
1
+ {"version":3,"file":"conditionDecls.js","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionDecls.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","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 ConditionIndex,\n ConditionOperator,\n ConditionPriority,\n QualifierConditionValue,\n QualifierMatchScore\n} from '../common';\nimport { Qualifier } from '../qualifiers';\nimport * as ResourceJson from '../resource-json';\n\n/**\n * Non-validated declaration of a {@link Conditions.Condition | condition}.\n * @public\n */\nexport type IConditionDecl = ResourceJson.Json.ILooseConditionDecl;\n\n/**\n * Validated declaration of a {@link Conditions.Condition | condition} with all defaults applied.\n * @public\n */\nexport interface IValidatedConditionDecl {\n qualifier: Qualifier;\n value: QualifierConditionValue;\n operator: ConditionOperator;\n priority: ConditionPriority;\n scoreAsDefault?: QualifierMatchScore;\n index?: ConditionIndex;\n}\n"]}
@@ -2,6 +2,7 @@ import { Collections, Result } from '@fgv/ts-utils';
2
2
  import { Condition } from './condition';
3
3
  import { ConditionSetIndex, ConditionSetKey } from '../common';
4
4
  import { IValidatedConditionSetDecl } from './conditionSetDecls';
5
+ import * as ResourceJson from '../resource-json';
5
6
  /**
6
7
  * Represents a set of {@link Conditions.Condition | conditions} that must all be met in some runtime
7
8
  * context for a resource instance to be valid.
@@ -95,5 +96,17 @@ export declare class ConditionSet implements IValidatedConditionSetDecl {
95
96
  * @returns A string representation of this condition set.
96
97
  */
97
98
  toString(): string;
99
+ /**
100
+ * Gets the {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.
101
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.
102
+ * @returns The {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.
103
+ */
104
+ toConditionSetRecordDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.ConditionSetDeclAsRecord;
105
+ /**
106
+ * Gets the {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.
107
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.
108
+ * @returns The {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.
109
+ */
110
+ toConditionSetArrayDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.ConditionSetDeclAsArray;
98
111
  }
99
112
  //# sourceMappingURL=conditionSet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"conditionSet.d.ts","sourceRoot":"","sources":["../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CAAC,IAAI,EAAE,0BAA0B,GAAG,MAAM,CAAC,eAAe,CAAC;IAItF;;;;;;;;OAQG;IACI,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IAM/C;;;OAGG;IACI,KAAK,IAAI,eAAe;IAI/B;;;;;OAKG;IACI,MAAM,IAAI,MAAM;IAIvB;;;OAGG;IACI,QAAQ,IAAI,MAAM;IAIzB;;;;OAIG;IACI,wBAAwB,CAC7B,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,mBAAmB,GACjD,YAAY,CAAC,IAAI,CAAC,wBAAwB;IAQ7C;;;;OAIG;IACI,uBAAuB,CAC5B,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,mBAAmB,GACjD,YAAY,CAAC,IAAI,CAAC,uBAAuB;CAG7C"}
@@ -155,6 +155,24 @@ class ConditionSet {
155
155
  toString() {
156
156
  return this.toKey();
157
157
  }
158
+ /**
159
+ * Gets the {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.
160
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.
161
+ * @returns The {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.
162
+ */
163
+ toConditionSetRecordDecl(options) {
164
+ return Object.fromEntries(this.conditions.map((c) => {
165
+ return [c.qualifier.name, c.toValueOrChildConditionDecl(options)];
166
+ }));
167
+ }
168
+ /**
169
+ * Gets the {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.
170
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.
171
+ * @returns The {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.
172
+ */
173
+ toConditionSetArrayDecl(options) {
174
+ return this.conditions.map((c) => c.toLooseConditionDecl(options));
175
+ }
158
176
  }
159
177
  exports.ConditionSet = ConditionSet;
160
178
  /**
@@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,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACrF,CAAC;IAED;;;;;;;;OAQG;IACI,OAAO,CAAC,KAAe;QAC5B,OAAO,IAAA,qBAAU,EAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACnF,OAAO,iBAAQ,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACI,KAAK;QACV,OAAO,YAAY,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;IACpD,CAAC;IAED;;;;;OAKG;IACI,MAAM;QACX,OAAO,eAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACrE,CAAC;IAED;;;OAGG;IACI,QAAQ;QACb,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;;AAvJH,oCAwJC;AA1HC;;GAEG;AACW,6BAAgB,GAAoB,iBAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Collections, Hash, mapResults, Result } from '@fgv/ts-utils';\nimport { Condition } from './condition';\nimport {\n Convert as CommonConvert,\n ConditionSetIndex,\n ConditionSetKey,\n QualifierName,\n Validate\n} from '../common';\nimport { IValidatedConditionSetDecl } from './conditionSetDecls';\n\n/**\n * Represents a set of {@link Conditions.Condition | conditions} that must all be met in some runtime\n * context for a resource instance to be valid.\n * @public\n */\nexport class ConditionSet implements IValidatedConditionSetDecl {\n protected readonly _collectible: Collections.Collectible<ConditionSetKey, ConditionSetIndex>;\n /**\n * The {@link Conditions.Condition | conditions} that make up this condition\n * set.\n * @public\n */\n public readonly conditions: ReadonlyArray<Condition>;\n\n /**\n * The key for this condition set.\n */\n public get key(): ConditionSetKey {\n return this._collectible.key;\n }\n\n /**\n * The number of conditions in this condition set.\n */\n public get size(): number {\n return this.conditions.length;\n }\n\n /**\n * The index for this condition set.\n */\n public get index(): ConditionSetIndex | undefined {\n return this._collectible.index;\n }\n\n /**\n * The key for an unconditional condition set.\n */\n public static UnconditionalKey: ConditionSetKey = Validate.toConditionSetKey('').orThrow();\n\n /**\n * Constructor for a {@link Conditions.ConditionSet | ConditionSet} object.\n * @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}\n * used to create the condition set.\n */\n protected constructor(params: IValidatedConditionSetDecl) {\n const qualifiers = new Map<QualifierName, Condition>();\n for (const condition of params.conditions) {\n if (qualifiers.has(condition.qualifier.name)) {\n /* c8 ignore next */\n const existing = qualifiers.get(condition.qualifier.name)?.toString() ?? 'unknown';\n throw new Error(\n `${\n condition.qualifier.name\n }: Duplicate conditions ${existing} and ${condition.toString()} are not supported.`\n );\n }\n qualifiers.set(condition.qualifier.name, condition);\n }\n this.conditions = Array.from(params.conditions).sort(Condition.compare).reverse();\n this._collectible = new Collections.Collectible({\n key: this.toKey(),\n index: params.index,\n indexConverter: CommonConvert.conditionSetIndex\n });\n }\n\n /**\n * Creates a new {@link Conditions.ConditionSet | ConditionSet} object.\n * @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}\n * used to create the condition set.\n * @returns `Success` with the new {@link Conditions.ConditionSet | ConditionSet} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IValidatedConditionSetDecl): Result<ConditionSet> {\n return captureResult(() => new ConditionSet(params));\n }\n\n /**\n * Compares two {@link Conditions.ConditionSet | ConditionSets} for sorting purposes.\n * @param cs1 - The first {@link Conditions.ConditionSet | ConditionSet} to compare.\n * @param cs2 - The second {@link Conditions.ConditionSet | ConditionSet} to compare.\n * @returns A negative number if `cs1` should come before `cs2`, a positive\n * number if `cs1` should come after `cs2`, or zero if they are equivalent.\n * @public\n */\n public static compare(cs1: ConditionSet, cs2: ConditionSet): number {\n const len = Math.min(cs1.conditions.length, cs2.conditions.length);\n for (let i = 0; i < len; i++) {\n const diff = Condition.compare(cs1.conditions[i], cs2.conditions[i]);\n if (diff !== 0) {\n return diff;\n }\n }\n return cs1.conditions.length - cs2.conditions.length;\n }\n\n /**\n * Sets the global index for this condition set. Once set, the index cannot be changed.\n * @param index - The index to set for this condition set.\n * @returns `Success` with the index if successful, `Failure` otherwise.\n */\n public setIndex(index: number): Result<ConditionSetIndex> {\n return this._collectible.setIndex(index);\n }\n\n /**\n * Gets the {@link ConditionSetKey | key} for a supplied {@link Conditions.IValidatedConditionSetDecl | condition set declaration}.\n * @param decl - The {@link Conditions.IValidatedConditionSetDecl | condition set declaration} for which to get the key.\n * @returns `Success` with the condition set key if successful, `Failure` otherwise.\n * @public\n */\n public static getKeyForDecl(decl: IValidatedConditionSetDecl): Result<ConditionSetKey> {\n return Validate.toConditionSetKey(decl.conditions.map((c) => c.toKey()).join('+'));\n }\n\n /**\n * Gets a {@link ConditionSetToken | condition set token} for this condition set,\n * if possible.\n * @param terse - If true, the token will be terse, omitting qualifier names where\n * possible.\n * @returns `Success` with the {@link ConditionSetToken | condition set token} if successful,\n * `Failure` with an error message otherwise.\n * @public\n */\n public toToken(terse?: boolean): Result<string> {\n return mapResults(this.conditions.map((c) => c.toToken(terse))).onSuccess((tokens) => {\n return Validate.toConditionSetToken(tokens.join(','));\n });\n }\n\n /**\n * Gets the {@link ConditionSetKey | key} for this condition set.\n * @returns The key for this condition set.\n */\n public toKey(): ConditionSetKey {\n return ConditionSet.getKeyForDecl(this).orThrow();\n }\n\n /**\n * Gets a hash of this condition set.\n * @returns A hash of this condition\n * set key.\n * @public\n */\n public toHash(): string {\n return Hash.Crc32Normalizer.crc32Hash([this.key]).padStart(8, '0');\n }\n\n /**\n * Gets a human-readable string representation of this condition set.\n * @returns A string representation of this condition set.\n */\n public toString(): string {\n return this.toKey();\n }\n}\n"]}
1
+ {"version":3,"file":"conditionSet.js","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionSet.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAqF;AACrF,2CAAwC;AACxC,sCAMmB;AAInB;;;;GAIG;AACH,MAAa,YAAY;IASvB;;OAEG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,YAAY,CA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CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACI,KAAK;QACV,OAAO,YAAY,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;IACpD,CAAC;IAED;;;;;OAKG;IACI,MAAM;QACX,OAAO,eAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACrE,CAAC;IAED;;;OAGG;IACI,QAAQ;QACb,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACI,wBAAwB,CAC7B,OAAkD;QAElD,OAAO,MAAM,CAAC,WAAW,CACvB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAA4D,EAAE;YAClF,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC,CAAC;QACpE,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACI,uBAAuB,CAC5B,OAAkD;QAElD,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;IACrE,CAAC;;AAjLH,oCAkLC;AApJC;;GAEG;AACW,6BAAgB,GAAoB,iBAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Collections, Hash, mapResults, Result } from '@fgv/ts-utils';\nimport { Condition } from './condition';\nimport {\n Convert as CommonConvert,\n ConditionSetIndex,\n ConditionSetKey,\n QualifierName,\n Validate\n} from '../common';\nimport { IValidatedConditionSetDecl } from './conditionSetDecls';\nimport * as ResourceJson from '../resource-json';\n\n/**\n * Represents a set of {@link Conditions.Condition | conditions} that must all be met in some runtime\n * context for a resource instance to be valid.\n * @public\n */\nexport class ConditionSet implements IValidatedConditionSetDecl {\n protected readonly _collectible: Collections.Collectible<ConditionSetKey, ConditionSetIndex>;\n /**\n * The {@link Conditions.Condition | conditions} that make up this condition\n * set.\n * @public\n */\n public readonly conditions: ReadonlyArray<Condition>;\n\n /**\n * The key for this condition set.\n */\n public get key(): ConditionSetKey {\n return this._collectible.key;\n }\n\n /**\n * The number of conditions in this condition set.\n */\n public get size(): number {\n return this.conditions.length;\n }\n\n /**\n * The index for this condition set.\n */\n public get index(): ConditionSetIndex | undefined {\n return this._collectible.index;\n }\n\n /**\n * The key for an unconditional condition set.\n */\n public static UnconditionalKey: ConditionSetKey = Validate.toConditionSetKey('').orThrow();\n\n /**\n * Constructor for a {@link Conditions.ConditionSet | ConditionSet} object.\n * @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}\n * used to create the condition set.\n */\n protected constructor(params: IValidatedConditionSetDecl) {\n const qualifiers = new Map<QualifierName, Condition>();\n for (const condition of params.conditions) {\n if (qualifiers.has(condition.qualifier.name)) {\n /* c8 ignore next */\n const existing = qualifiers.get(condition.qualifier.name)?.toString() ?? 'unknown';\n throw new Error(\n `${\n condition.qualifier.name\n }: Duplicate conditions ${existing} and ${condition.toString()} are not supported.`\n );\n }\n qualifiers.set(condition.qualifier.name, condition);\n }\n this.conditions = Array.from(params.conditions).sort(Condition.compare).reverse();\n this._collectible = new Collections.Collectible({\n key: this.toKey(),\n index: params.index,\n indexConverter: CommonConvert.conditionSetIndex\n });\n }\n\n /**\n * Creates a new {@link Conditions.ConditionSet | ConditionSet} object.\n * @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}\n * used to create the condition set.\n * @returns `Success` with the new {@link Conditions.ConditionSet | ConditionSet} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IValidatedConditionSetDecl): Result<ConditionSet> {\n return captureResult(() => new ConditionSet(params));\n }\n\n /**\n * Compares two {@link Conditions.ConditionSet | ConditionSets} for sorting purposes.\n * @param cs1 - The first {@link Conditions.ConditionSet | ConditionSet} to compare.\n * @param cs2 - The second {@link Conditions.ConditionSet | ConditionSet} to compare.\n * @returns A negative number if `cs1` should come before `cs2`, a positive\n * number if `cs1` should come after `cs2`, or zero if they are equivalent.\n * @public\n */\n public static compare(cs1: ConditionSet, cs2: ConditionSet): number {\n const len = Math.min(cs1.conditions.length, cs2.conditions.length);\n for (let i = 0; i < len; i++) {\n const diff = Condition.compare(cs1.conditions[i], cs2.conditions[i]);\n if (diff !== 0) {\n return diff;\n }\n }\n return cs1.conditions.length - cs2.conditions.length;\n }\n\n /**\n * Sets the global index for this condition set. Once set, the index cannot be changed.\n * @param index - The index to set for this condition set.\n * @returns `Success` with the index if successful, `Failure` otherwise.\n */\n public setIndex(index: number): Result<ConditionSetIndex> {\n return this._collectible.setIndex(index);\n }\n\n /**\n * Gets the {@link ConditionSetKey | key} for a supplied {@link Conditions.IValidatedConditionSetDecl | condition set declaration}.\n * @param decl - The {@link Conditions.IValidatedConditionSetDecl | condition set declaration} for which to get the key.\n * @returns `Success` with the condition set key if successful, `Failure` otherwise.\n * @public\n */\n public static getKeyForDecl(decl: IValidatedConditionSetDecl): Result<ConditionSetKey> {\n return Validate.toConditionSetKey(decl.conditions.map((c) => c.toKey()).join('+'));\n }\n\n /**\n * Gets a {@link ConditionSetToken | condition set token} for this condition set,\n * if possible.\n * @param terse - If true, the token will be terse, omitting qualifier names where\n * possible.\n * @returns `Success` with the {@link ConditionSetToken | condition set token} if successful,\n * `Failure` with an error message otherwise.\n * @public\n */\n public toToken(terse?: boolean): Result<string> {\n return mapResults(this.conditions.map((c) => c.toToken(terse))).onSuccess((tokens) => {\n return Validate.toConditionSetToken(tokens.join(','));\n });\n }\n\n /**\n * Gets the {@link ConditionSetKey | key} for this condition set.\n * @returns The key for this condition set.\n */\n public toKey(): ConditionSetKey {\n return ConditionSet.getKeyForDecl(this).orThrow();\n }\n\n /**\n * Gets a hash of this condition set.\n * @returns A hash of this condition\n * set key.\n * @public\n */\n public toHash(): string {\n return Hash.Crc32Normalizer.crc32Hash([this.key]).padStart(8, '0');\n }\n\n /**\n * Gets a human-readable string representation of this condition set.\n * @returns A string representation of this condition set.\n */\n public toString(): string {\n return this.toKey();\n }\n\n /**\n * Gets the {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.\n * @returns The {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.\n */\n public toConditionSetRecordDecl(\n options?: ResourceJson.Helpers.IDeclarationOptions\n ): ResourceJson.Json.ConditionSetDeclAsRecord {\n return Object.fromEntries(\n this.conditions.map((c): [string, ResourceJson.Json.IChildConditionDecl | string] => {\n return [c.qualifier.name, c.toValueOrChildConditionDecl(options)];\n })\n );\n }\n\n /**\n * Gets the {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.\n * @returns The {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.\n */\n public toConditionSetArrayDecl(\n options?: ResourceJson.Helpers.IDeclarationOptions\n ): ResourceJson.Json.ConditionSetDeclAsArray {\n return this.conditions.map((c) => c.toLooseConditionDecl(options));\n }\n}\n"]}
@@ -1,10 +1,10 @@
1
- import { IConditionDecl, IValidatedConditionDecl } from '../conditionDecls';
1
+ import { IValidatedConditionDecl } from '../conditionDecls';
2
2
  import { IReadOnlyQualifierCollector } from '../../qualifiers';
3
3
  /**
4
4
  * Converter for a {@link Conditions.IConditionDecl | condition declaration}.
5
5
  * @public
6
6
  */
7
- export declare const conditionDecl: import("@fgv/ts-utils").ObjectConverter<IConditionDecl, unknown>;
7
+ export declare const conditionDecl: import("@fgv/ts-utils").ObjectConverter<import("../../resource-json/json").ILooseConditionDecl, unknown>;
8
8
  /**
9
9
  * Conversion context to uses when converting
10
10
  * a {@link Conditions.IValidatedConditionDecl | validated condition declaration}.
@@ -1 +1 @@
1
- {"version":3,"file":"decls.d.ts","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/decls.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAI/D;;;GAGG;AACH,eAAO,MAAM,aAAa,kEAMxB,CAAC;AAEH;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,UAAU,EAAE,2BAA2B,CAAC;IACjD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,0FAqCjC,CAAC"}
1
+ {"version":3,"file":"decls.d.ts","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/decls.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAkB,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAI/D;;;GAGG;AACH,eAAO,MAAM,aAAa,0GAMxB,CAAC;AAEH;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,UAAU,EAAE,2BAA2B,CAAC;IACjD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,0FAqCjC,CAAC"}
@@ -1,7 +1,17 @@
1
1
  import { Result } from '@fgv/ts-utils';
2
2
  import * as Normalized from './normalized';
3
3
  import * as Json from './json';
4
- import * as Conditions from '../conditions';
4
+ /**
5
+ * Common options when creating or displaying declarations.
6
+ * @public
7
+ */
8
+ export interface IDeclarationOptions {
9
+ /**
10
+ * If `true`, properties with default values will be included in the
11
+ * output. IF omitted or `false`, properties with default values will be omitted.
12
+ */
13
+ showDefaults?: boolean;
14
+ }
5
15
  /**
6
16
  * Helper method to merge a loose candidate with a base name and conditions.
7
17
  * @param candidate - The candidate to merge.
@@ -10,7 +20,7 @@ import * as Conditions from '../conditions';
10
20
  * @returns `Success` with the merged candidate if successful, otherwise `Failure`.
11
21
  * @public
12
22
  */
13
- export declare function mergeLooseCandidate(candidate: Normalized.ILooseResourceCandidateDecl, baseName?: string, baseConditions?: ReadonlyArray<Json.ILooseConditionDecl | Conditions.IConditionDecl>): Result<Normalized.ILooseResourceCandidateDecl>;
23
+ export declare function mergeLooseCandidate(candidate: Normalized.ILooseResourceCandidateDecl, baseName?: string, baseConditions?: ReadonlyArray<Json.ILooseConditionDecl>): Result<Normalized.ILooseResourceCandidateDecl>;
14
24
  /**
15
25
  * Helper method to merge a child candidate with base conditions.
16
26
  * @param candidate - The candidate to merge.
@@ -18,7 +28,7 @@ export declare function mergeLooseCandidate(candidate: Normalized.ILooseResource
18
28
  * @returns `Success` with the merged candidate if successful, otherwise `Failure`.
19
29
  * @public
20
30
  */
21
- export declare function mergeChildCandidate(candidate: Normalized.IChildResourceCandidateDecl, baseConditions?: ReadonlyArray<Json.ILooseConditionDecl | Conditions.IConditionDecl>): Result<Normalized.IChildResourceCandidateDecl>;
31
+ export declare function mergeChildCandidate(candidate: Normalized.IChildResourceCandidateDecl, baseConditions?: ReadonlyArray<Json.ILooseConditionDecl>): Result<Normalized.IChildResourceCandidateDecl>;
22
32
  /**
23
33
  * Helper method to merge a loose resource with a base name and conditions.
24
34
  * @param resource - The resource to merge.
@@ -27,7 +37,7 @@ export declare function mergeChildCandidate(candidate: Normalized.IChildResource
27
37
  * @returns `Success` with the merged resource if successful, otherwise `Failure`.
28
38
  * @public
29
39
  */
30
- export declare function mergeLooseResource(resource: Normalized.ILooseResourceDecl, baseName?: string, baseConditions?: ReadonlyArray<Json.ILooseConditionDecl | Conditions.IConditionDecl>): Result<Normalized.ILooseResourceDecl>;
40
+ export declare function mergeLooseResource(resource: Normalized.ILooseResourceDecl, baseName?: string, baseConditions?: ReadonlyArray<Json.ILooseConditionDecl>): Result<Normalized.ILooseResourceDecl>;
31
41
  /**
32
42
  * Helper method to merge a child resource with a parent name and conditions.
33
43
  * @param resource - The resource to merge.
@@ -37,5 +47,5 @@ export declare function mergeLooseResource(resource: Normalized.ILooseResourceDe
37
47
  * @returns `Success` with the merged resource if successful, otherwise `Failure`.
38
48
  * @public
39
49
  */
40
- export declare function mergeChildResource(resource: Normalized.IChildResourceDecl, name: string, parentName?: string, parentConditions?: ReadonlyArray<Json.ILooseConditionDecl | Conditions.IConditionDecl>): Result<Normalized.ILooseResourceDecl>;
50
+ export declare function mergeChildResource(resource: Normalized.IChildResourceDecl, name: string, parentName?: string, parentConditions?: ReadonlyArray<Json.ILooseConditionDecl>): Result<Normalized.ILooseResourceDecl>;
41
51
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"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"helpers.d.ts","sourceRoot":"","sources":["../../../src/packlets/resource-json/helpers.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAc,MAAM,EAAW,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAG/B;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,UAAU,CAAC,2BAA2B,EACjD,QAAQ,CAAC,EAAE,MAAM,EACjB,cAAc,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,mBAAmB,CAAC,GACvD,MAAM,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAMhD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,UAAU,CAAC,2BAA2B,EACjD,cAAc,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,mBAAmB,CAAC,GACvD,MAAM,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAIhD;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,UAAU,CAAC,kBAAkB,EACvC,QAAQ,CAAC,EAAE,MAAM,EACjB,cAAc,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,mBAAmB,CAAC,GACvD,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,CASvC;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,UAAU,CAAC,kBAAkB,EACvC,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,EACnB,gBAAgB,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,mBAAmB,CAAC,GACzD,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,CASvC"}
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sour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,MAAA,QAAQ,CAAC,UAAU,mCAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,mBAAmB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAC/F,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE;YACzB,OAAO,IAAA,kBAAO,kCAAM,QAAQ,KAAE,EAAE,EAAE,UAAU,IAAG,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAChC,QAAuC,EACvC,IAAY,EACZ,UAAmB,EACnB,gBAAsF;IAEtF,OAAO,gBAAa,CAAC,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE;;QACtE,OAAO,IAAA,qBAAU;QACf,yCAAyC;QACzC,CAAC,MAAA,QAAQ,CAAC,UAAU,mCAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,mBAAmB,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC,CACjG,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE;YACzB,OAAO,IAAA,kBAAO,kCAAM,QAAQ,KAAE,EAAE,EAAE,UAAU,IAAG,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","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 { mapResults, Result, succeed } from '@fgv/ts-utils';\nimport * as Normalized from './normalized';\nimport * as Json from './json';\nimport { Helpers as CommonHelpers } from '../common';\nimport * as Conditions from '../conditions';\n\n/**\n * Helper method to merge a loose candidate with a base name and conditions.\n * @param candidate - The candidate to merge.\n * @param baseName - The base name to merge with the candidate.\n * @param baseConditions - The base conditions to merge with the candidate.\n * @returns `Success` with the merged candidate if successful, otherwise `Failure`.\n * @public\n */\nexport function mergeLooseCandidate(\n candidate: Normalized.ILooseResourceCandidateDecl,\n baseName?: string,\n baseConditions?: ReadonlyArray<Json.ILooseConditionDecl | Conditions.IConditionDecl>\n): Result<Normalized.ILooseResourceCandidateDecl> {\n return CommonHelpers.joinResourceIds(baseName, candidate.id).onSuccess((id) => {\n /* c8 ignore next 1 - defense in depth */\n const conditions = [...(baseConditions ?? []), ...(candidate.conditions ?? [])];\n return succeed({ ...candidate, id, conditions });\n });\n}\n\n/**\n * Helper method to merge a child candidate with base conditions.\n * @param candidate - The candidate to merge.\n * @param baseConditions - The base conditions to merge with the candidate.\n * @returns `Success` with the merged candidate if successful, otherwise `Failure`.\n * @public\n */\nexport function mergeChildCandidate(\n candidate: Normalized.IChildResourceCandidateDecl,\n baseConditions?: ReadonlyArray<Json.ILooseConditionDecl | Conditions.IConditionDecl>\n): Result<Normalized.IChildResourceCandidateDecl> {\n /* c8 ignore next 1 - defense in depth */\n const conditions = [...(baseConditions ?? []), ...(candidate.conditions ?? [])];\n return succeed({ ...candidate, conditions });\n}\n\n/**\n * Helper method to merge a loose resource with a base name and conditions.\n * @param resource - The resource to merge.\n * @param baseName - The base name to merge with the resource.\n * @param baseConditions - The base conditions to merge with the resource.\n * @returns `Success` with the merged resource if successful, otherwise `Failure`.\n * @public\n */\nexport function mergeLooseResource(\n resource: Normalized.ILooseResourceDecl,\n baseName?: string,\n baseConditions?: ReadonlyArray<Json.ILooseConditionDecl | Conditions.IConditionDecl>\n): Result<Normalized.ILooseResourceDecl> {\n return CommonHelpers.joinResourceIds(baseName, resource.id).onSuccess((id) => {\n return mapResults(\n /* c8 ignore next 1 - defense in depth */\n (resource.candidates ?? []).map((candidate) => mergeChildCandidate(candidate, baseConditions))\n ).onSuccess((candidates) => {\n return succeed({ ...resource, id, candidates });\n });\n });\n}\n\n/**\n * Helper method to merge a child resource with a parent name and conditions.\n * @param resource - The resource to merge.\n * @param name - The name of the resource.\n * @param parentName - The name of the parent resource.\n * @param parentConditions - The conditions of the parent resource.\n * @returns `Success` with the merged resource if successful, otherwise `Failure`.\n * @public\n */\nexport function mergeChildResource(\n resource: Normalized.IChildResourceDecl,\n name: string,\n parentName?: string,\n parentConditions?: ReadonlyArray<Json.ILooseConditionDecl | Conditions.IConditionDecl>\n): Result<Normalized.ILooseResourceDecl> {\n return CommonHelpers.joinResourceIds(parentName, name).onSuccess((id) => {\n return mapResults(\n /* c8 ignore next 1 - defense in depth */\n (resource.candidates ?? []).map((candidate) => mergeChildCandidate(candidate, parentConditions))\n ).onSuccess((candidates) => {\n return succeed({ ...resource, id, candidates });\n });\n });\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/packlets/resource-json/helpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AA2BH,kDAUC;AASD,kDAOC;AAUD,gDAaC;AAWD,gDAcC;AAnGD,4CAA4D;AAG5D,sCAAqD;AAcrD;;;;;;;GAOG;AACH,SAAgB,mB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kCAAM,QAAQ,KAAE,EAAE,EAAE,UAAU,IAAG,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAChC,QAAuC,EACvC,IAAY,EACZ,UAAmB,EACnB,gBAA0D;IAE1D,OAAO,gBAAa,CAAC,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE;;QACtE,OAAO,IAAA,qBAAU;QACf,yCAAyC;QACzC,CAAC,MAAA,QAAQ,CAAC,UAAU,mCAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,mBAAmB,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC,CACjG,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE;YACzB,OAAO,IAAA,kBAAO,kCAAM,QAAQ,KAAE,EAAE,EAAE,UAAU,IAAG,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","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 { mapResults, Result, succeed } from '@fgv/ts-utils';\nimport * as Normalized from './normalized';\nimport * as Json from './json';\nimport { Helpers as CommonHelpers } from '../common';\n\n/**\n * Common options when creating or displaying declarations.\n * @public\n */\nexport interface IDeclarationOptions {\n /**\n * If `true`, properties with default values will be included in the\n * output. IF omitted or `false`, properties with default values will be omitted.\n */\n showDefaults?: boolean;\n}\n\n/**\n * Helper method to merge a loose candidate with a base name and conditions.\n * @param candidate - The candidate to merge.\n * @param baseName - The base name to merge with the candidate.\n * @param baseConditions - The base conditions to merge with the candidate.\n * @returns `Success` with the merged candidate if successful, otherwise `Failure`.\n * @public\n */\nexport function mergeLooseCandidate(\n candidate: Normalized.ILooseResourceCandidateDecl,\n baseName?: string,\n baseConditions?: ReadonlyArray<Json.ILooseConditionDecl>\n): Result<Normalized.ILooseResourceCandidateDecl> {\n return CommonHelpers.joinResourceIds(baseName, candidate.id).onSuccess((id) => {\n /* c8 ignore next 1 - defense in depth */\n const conditions = [...(baseConditions ?? []), ...(candidate.conditions ?? [])];\n return succeed({ ...candidate, id, conditions });\n });\n}\n\n/**\n * Helper method to merge a child candidate with base conditions.\n * @param candidate - The candidate to merge.\n * @param baseConditions - The base conditions to merge with the candidate.\n * @returns `Success` with the merged candidate if successful, otherwise `Failure`.\n * @public\n */\nexport function mergeChildCandidate(\n candidate: Normalized.IChildResourceCandidateDecl,\n baseConditions?: ReadonlyArray<Json.ILooseConditionDecl>\n): Result<Normalized.IChildResourceCandidateDecl> {\n /* c8 ignore next 1 - defense in depth */\n const conditions = [...(baseConditions ?? []), ...(candidate.conditions ?? [])];\n return succeed({ ...candidate, conditions });\n}\n\n/**\n * Helper method to merge a loose resource with a base name and conditions.\n * @param resource - The resource to merge.\n * @param baseName - The base name to merge with the resource.\n * @param baseConditions - The base conditions to merge with the resource.\n * @returns `Success` with the merged resource if successful, otherwise `Failure`.\n * @public\n */\nexport function mergeLooseResource(\n resource: Normalized.ILooseResourceDecl,\n baseName?: string,\n baseConditions?: ReadonlyArray<Json.ILooseConditionDecl>\n): Result<Normalized.ILooseResourceDecl> {\n return CommonHelpers.joinResourceIds(baseName, resource.id).onSuccess((id) => {\n return mapResults(\n /* c8 ignore next 1 - defense in depth */\n (resource.candidates ?? []).map((candidate) => mergeChildCandidate(candidate, baseConditions))\n ).onSuccess((candidates) => {\n return succeed({ ...resource, id, candidates });\n });\n });\n}\n\n/**\n * Helper method to merge a child resource with a parent name and conditions.\n * @param resource - The resource to merge.\n * @param name - The name of the resource.\n * @param parentName - The name of the parent resource.\n * @param parentConditions - The conditions of the parent resource.\n * @returns `Success` with the merged resource if successful, otherwise `Failure`.\n * @public\n */\nexport function mergeChildResource(\n resource: Normalized.IChildResourceDecl,\n name: string,\n parentName?: string,\n parentConditions?: ReadonlyArray<Json.ILooseConditionDecl>\n): Result<Normalized.ILooseResourceDecl> {\n return CommonHelpers.joinResourceIds(parentName, name).onSuccess((id) => {\n return mapResults(\n /* c8 ignore next 1 - defense in depth */\n (resource.candidates ?? []).map((candidate) => mergeChildCandidate(candidate, parentConditions))\n ).onSuccess((candidates) => {\n return succeed({ ...resource, id, candidates });\n });\n });\n}\n"]}
@@ -2,6 +2,7 @@ import { Result } from '@fgv/ts-utils';
2
2
  import { ResourceId } from '../common';
3
3
  import { ResourceCandidate } from './resourceCandidate';
4
4
  import { ResourceType } from '../resource-types';
5
+ import * as ResourceJson from '../resource-json';
5
6
  /**
6
7
  * Parameters used to create a {@link Resources.Resource | Resource} object.
7
8
  * @public
@@ -53,6 +54,18 @@ export declare class Resource {
53
54
  * @public
54
55
  */
55
56
  static create(params: IResourceCreateParams): Result<Resource>;
57
+ /**
58
+ * Gets the {@link ResourceJson.Json.IChildResourceDecl | child resource declaration} for this resource.
59
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.
60
+ * @returns The {@link ResourceJson.Json.IChildResourceDecl | child resource declaration}.
61
+ */
62
+ toChildResourceDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.IChildResourceDecl;
63
+ /**
64
+ * Gets the {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration} for this resource.
65
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.
66
+ * @returns The {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration}.
67
+ */
68
+ toLooseResourceDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.ILooseResourceDecl;
56
69
  /**
57
70
  * Validates that all candidates have the same id as the resource.
58
71
  * @param resourceId - The expected id of the resource.
@@ -1 +1 @@
1
- {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/resource.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAqB,MAAM,EAAgC,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,UAAU,EAAY,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;OAEG;IACH,UAAU,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;CAC9C;AAED;;;;GAIG;AACH,qBAAa,QAAQ;IACnB;;OAEG;IACH,SAAgB,EAAE,EAAE,UAAU,CAAC;IAC/B;;OAEG;IACH,SAAgB,YAAY,EAAE,YAAY,CAAC;IAC3C;;OAEG;IACH,SAAgB,UAAU,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAE7D;;;;OAIG;IACH,SAAS,aAAa,MAAM,EAAE,qBAAqB;IAmBnD;;;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mBAAmB,CACxB,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,mBAAmB,GACjD,YAAY,CAAC,IAAI,CAAC,kBAAkB;IASvC;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,6BAA6B;IAgB5C;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,+BAA+B;CAqB/C"}
@@ -37,10 +37,6 @@ class Resource {
37
37
  * @public
38
38
  */
39
39
  constructor(params) {
40
- var _a;
41
- if (params.candidates.length === 0) {
42
- throw new Error(`${(_a = params.id) !== null && _a !== void 0 ? _a : 'resource constructor'}: no candidates specified.`);
43
- }
44
40
  const id = params.id ? common_1.Validate.toResourceId(params.id).orThrow() : undefined;
45
41
  this.id = Resource._validateCandidateResourceIds(id, params.candidates).orThrow();
46
42
  this.resourceType = resourceCandidate_1.ResourceCandidate.validateResourceTypes(params.candidates, params.resourceType)
@@ -63,6 +59,24 @@ class Resource {
63
59
  static create(params) {
64
60
  return (0, ts_utils_1.captureResult)(() => new Resource(params));
65
61
  }
62
+ /**
63
+ * Gets the {@link ResourceJson.Json.IChildResourceDecl | child resource declaration} for this resource.
64
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.
65
+ * @returns The {@link ResourceJson.Json.IChildResourceDecl | child resource declaration}.
66
+ */
67
+ toChildResourceDecl(options) {
68
+ const candidates = this.candidates.map((c) => c.toChildResourceCandidateDecl(options));
69
+ return Object.assign({ resourceTypeName: this.resourceType.key }, (candidates.length > 0 ? { candidates } : {}));
70
+ }
71
+ /**
72
+ * Gets the {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration} for this resource.
73
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.
74
+ * @returns The {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration}.
75
+ */
76
+ toLooseResourceDecl(options) {
77
+ const candidates = this.candidates.map((c) => c.toChildResourceCandidateDecl(options));
78
+ return Object.assign({ id: this.id, resourceTypeName: this.resourceType.key }, (candidates.length > 0 ? { candidates } : {}));
79
+ }
66
80
  /**
67
81
  * Validates that all candidates have the same id as the resource.
68
82
  * @param resourceId - The expected id of the resource.
@@ -72,6 +86,9 @@ class Resource {
72
86
  * @internal
73
87
  */
74
88
  static _validateCandidateResourceIds(resourceId, candidates) {
89
+ if (!resourceId && candidates.length === 0) {
90
+ return (0, ts_utils_1.fail)('unknown: no resource id and no candidates.');
91
+ }
75
92
  resourceId = resourceId !== null && resourceId !== void 0 ? resourceId : candidates[0].id;
76
93
  const mismatched = candidates.filter((c) => c.id !== resourceId).map((c) => c.id);
77
94
  if (mismatched.length > 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../src/packlets/resources/resource.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAwF;AACxF,sCAAiD;AACjD,2DAAwD;AAuBxD;;;;GAIG;AACH,MAAa,QAAQ;IAcnB;;;;OAIG;IACH,YAAsB,MAA6B;;QACjD,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,GAAG,MAAA,MAAM,CAAC,EAAE,mCAAI,sBAAsB,4BAA4B,CAAC,CAAC;QACtF,CAAC;QAED,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9E,IAAI,CAAC,EAAE,GAAG,QAAQ,CAAC,6BAA6B,CAAC,EAAE,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;QAClF,IAAI,CAAC,YAAY,GAAG,qCAAiB,CAAC,qBAAqB,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,YAAY,CAAC;aAChG,SAAS,CAAC,CAAC,CAAC,E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AmC,IAAI,GAAG,EAAE,CAAC;QAE5D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,kBAAkB,GAAG,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;YAC3D,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACnD,IAAI,QAAQ,EAAE,CAAC;gBACb,IAAI,CAAC,qCAAiB,CAAC,KAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC;oBAClD,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,EAAE,8BAA8B,kBAAkB,GAAG,CAAC,CAAC;gBACxF,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,GAAG,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,cAAc,CAC1B,IAAA,kBAAO,EAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,qCAAiB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,CAClF,CAAC;IACJ,CAAC;CACF;AAnGD,4BAmGC","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 { MessageAggregator, Result, captureResult, fail, succeed } from '@fgv/ts-utils';\nimport { ResourceId, Validate } from '../common';\nimport { ResourceCandidate } from './resourceCandidate';\nimport { ResourceType } from '../resource-types';\n\n/**\n * Parameters used to create a {@link Resources.Resource | Resource} object.\n * @public\n */\nexport interface IResourceCreateParams {\n /**\n * The id of the resource.\n */\n id?: string;\n /**\n * Optional {@link ResourceTypes.ResourceType | type} of the resource. If not specified, the type will be inferred\n * from the candidates.\n */\n resourceType?: ResourceType;\n /**\n * Array of {@link Resources.ResourceCandidate | candidates} for the resource.\n */\n candidates: ReadonlyArray<ResourceCandidate>;\n}\n\n/**\n * Represents a single logical resource, with a unique id and a set of possible\n * candidate instances.\n * @public\n */\nexport class Resource {\n /**\n * The unique {@link ResourceId | id} of the resource.\n */\n public readonly id: ResourceId;\n /**\n * The {@link ResourceTypes.ResourceType | type} of the resource.\n */\n public readonly resourceType: ResourceType;\n /**\n * The array of {@link Resources.ResourceCandidate | candidates} for the resource.\n */\n public readonly candidates: ReadonlyArray<ResourceCandidate>;\n\n /**\n * Constructor for a {@link Resources.Resource | Resource} object.\n * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.\n * @public\n */\n protected constructor(params: IResourceCreateParams) {\n if (params.candidates.length === 0) {\n throw new Error(`${params.id ?? 'resource constructor'}: no candidates specified.`);\n }\n\n const id = params.id ? Validate.toResourceId(params.id).orThrow() : undefined;\n this.id = Resource._validateCandidateResourceIds(id, params.candidates).orThrow();\n this.resourceType = ResourceCandidate.validateResourceTypes(params.candidates, params.resourceType)\n .onSuccess((t) => {\n if (t === undefined) {\n return fail<ResourceType>(`${params.id}: no type specified and no candidates with types.`);\n }\n return succeed(t);\n })\n .orThrow();\n\n this.candidates = Resource._validateAndNormalizeCandidates(params.candidates).orThrow();\n }\n\n /**\n * Creates a new {@link Resources.Resource | Resource} object.\n * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.\n * @returns `Success` with the new {@link Resources.Resource | Resource} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IResourceCreateParams): Result<Resource> {\n return captureResult(() => new Resource(params));\n }\n\n /**\n * Validates that all candidates have the same id as the resource.\n * @param resourceId - The expected id of the resource.\n * @param candidates - The array of candidates to validate.\n * @returns `Success` with the resource id if all candidates have the same id,\n * `Failure` with an error message otherwise.\n * @internal\n */\n private static _validateCandidateResourceIds(\n resourceId: ResourceId | undefined,\n candidates: ReadonlyArray<ResourceCandidate>\n ): Result<ResourceId> {\n resourceId = resourceId ?? candidates[0].id;\n\n const mismatched = candidates.filter((c) => c.id !== resourceId).map((c) => c.id);\n if (mismatched.length > 0) {\n return fail(`${resourceId}: candidates with mismatched ids ${mismatched.join(', ')}.`);\n }\n return succeed(resourceId);\n }\n\n /**\n * Validates and normalizes an array of {@link Resources.ResourceCandidate | candidates}. Fails if there\n * are multiple candidates for the same set of conditions.\n * @param candidates - The array of candidates to validate.\n * @returns `Success` with the validated and sorted array of candidates if successful,\n * `Failure` with an error message otherwise.\n * @internal\n */\n private static _validateAndNormalizeCandidates(\n candidates: ReadonlyArray<ResourceCandidate>\n ): Result<ReadonlyArray<ResourceCandidate>> {\n const errors = new MessageAggregator();\n const validated: Map<string, ResourceCandidate> = new Map();\n\n for (const candidate of candidates) {\n const conditionSetString = candidate.conditions.toString();\n const existing = validated.get(conditionSetString);\n if (existing) {\n if (!ResourceCandidate.equal(candidate, existing)) {\n errors.addMessage(`${candidate.id}: duplicate candidates for ${conditionSetString}.`);\n }\n } else {\n validated.set(conditionSetString, candidate);\n }\n }\n return errors.returnOrReport(\n succeed(Array.from(validated.values()).sort(ResourceCandidate.compare).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M,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAA,eAAI,EAAC,GAAG,UAAU,oCAAoC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,IAAA,kBAAO,EAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACK,MAAM,CAAC,+BAA+B,CAC5C,UAA4C;QAE5C,MAAM,MAAM,GAAG,IAAI,4BAAiB,EAAE,CAAC;QACvC,MAAM,SAAS,GAAmC,IAAI,GAAG,EAAE,CAAC;QAE5D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,kBAAkB,GAAG,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;YAC3D,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACnD,IAAI,QAAQ,EAAE,CAAC;gBACb,IAAI,CAAC,qCAAiB,CAAC,KAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC;oBAClD,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,EAAE,8BAA8B,kBAAkB,GAAG,CAAC,CAAC;gBACxF,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,GAAG,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,cAAc,CAC1B,IAAA,kBAAO,EAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,qCAAiB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,CAClF,CAAC;IACJ,CAAC;CACF;AAjID,4BAiIC","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 { MessageAggregator, Result, captureResult, fail, succeed } from '@fgv/ts-utils';\nimport { ResourceId, Validate } from '../common';\nimport { ResourceCandidate } from './resourceCandidate';\nimport { ResourceType } from '../resource-types';\nimport * as ResourceJson from '../resource-json';\n\n/**\n * Parameters used to create a {@link Resources.Resource | Resource} object.\n * @public\n */\nexport interface IResourceCreateParams {\n /**\n * The id of the resource.\n */\n id?: string;\n /**\n * Optional {@link ResourceTypes.ResourceType | type} of the resource. If not specified, the type will be inferred\n * from the candidates.\n */\n resourceType?: ResourceType;\n /**\n * Array of {@link Resources.ResourceCandidate | candidates} for the resource.\n */\n candidates: ReadonlyArray<ResourceCandidate>;\n}\n\n/**\n * Represents a single logical resource, with a unique id and a set of possible\n * candidate instances.\n * @public\n */\nexport class Resource {\n /**\n * The unique {@link ResourceId | id} of the resource.\n */\n public readonly id: ResourceId;\n /**\n * The {@link ResourceTypes.ResourceType | type} of the resource.\n */\n public readonly resourceType: ResourceType;\n /**\n * The array of {@link Resources.ResourceCandidate | candidates} for the resource.\n */\n public readonly candidates: ReadonlyArray<ResourceCandidate>;\n\n /**\n * Constructor for a {@link Resources.Resource | Resource} object.\n * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.\n * @public\n */\n protected constructor(params: IResourceCreateParams) {\n const id = params.id ? Validate.toResourceId(params.id).orThrow() : undefined;\n this.id = Resource._validateCandidateResourceIds(id, params.candidates).orThrow();\n this.resourceType = ResourceCandidate.validateResourceTypes(params.candidates, params.resourceType)\n .onSuccess((t) => {\n if (t === undefined) {\n return fail<ResourceType>(`${params.id}: no type specified and no candidates with types.`);\n }\n return succeed(t);\n })\n .orThrow();\n\n this.candidates = Resource._validateAndNormalizeCandidates(params.candidates).orThrow();\n }\n\n /**\n * Creates a new {@link Resources.Resource | Resource} object.\n * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.\n * @returns `Success` with the new {@link Resources.Resource | Resource} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IResourceCreateParams): Result<Resource> {\n return captureResult(() => new Resource(params));\n }\n\n /**\n * Gets the {@link ResourceJson.Json.IChildResourceDecl | child resource declaration} for this resource.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.\n * @returns The {@link ResourceJson.Json.IChildResourceDecl | child resource declaration}.\n */\n public toChildResourceDecl(\n options?: ResourceJson.Helpers.IDeclarationOptions\n ): ResourceJson.Json.IChildResourceDecl {\n const candidates = this.candidates.map((c) => c.toChildResourceCandidateDecl(options));\n return {\n resourceTypeName: this.resourceType.key,\n ...(candidates.length > 0 ? { candidates } : {})\n };\n }\n\n /**\n * Gets the {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration} for this resource.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.\n * @returns The {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration}.\n */\n public toLooseResourceDecl(\n options?: ResourceJson.Helpers.IDeclarationOptions\n ): ResourceJson.Json.ILooseResourceDecl {\n const candidates = this.candidates.map((c) => c.toChildResourceCandidateDecl(options));\n return {\n id: this.id,\n resourceTypeName: this.resourceType.key,\n ...(candidates.length > 0 ? { candidates } : {})\n };\n }\n\n /**\n * Validates that all candidates have the same id as the resource.\n * @param resourceId - The expected id of the resource.\n * @param candidates - The array of candidates to validate.\n * @returns `Success` with the resource id if all candidates have the same id,\n * `Failure` with an error message otherwise.\n * @internal\n */\n private static _validateCandidateResourceIds(\n resourceId: ResourceId | undefined,\n candidates: ReadonlyArray<ResourceCandidate>\n ): Result<ResourceId> {\n if (!resourceId && candidates.length === 0) {\n return fail('unknown: no resource id and no candidates.');\n }\n resourceId = resourceId ?? candidates[0].id;\n\n const mismatched = candidates.filter((c) => c.id !== resourceId).map((c) => c.id);\n if (mismatched.length > 0) {\n return fail(`${resourceId}: candidates with mismatched ids ${mismatched.join(', ')}.`);\n }\n return succeed(resourceId);\n }\n\n /**\n * Validates and normalizes an array of {@link Resources.ResourceCandidate | candidates}. Fails if there\n * are multiple candidates for the same set of conditions.\n * @param candidates - The array of candidates to validate.\n * @returns `Success` with the validated and sorted array of candidates if successful,\n * `Failure` with an error message otherwise.\n * @internal\n */\n private static _validateAndNormalizeCandidates(\n candidates: ReadonlyArray<ResourceCandidate>\n ): Result<ReadonlyArray<ResourceCandidate>> {\n const errors = new MessageAggregator();\n const validated: Map<string, ResourceCandidate> = new Map();\n\n for (const candidate of candidates) {\n const conditionSetString = candidate.conditions.toString();\n const existing = validated.get(conditionSetString);\n if (existing) {\n if (!ResourceCandidate.equal(candidate, existing)) {\n errors.addMessage(`${candidate.id}: duplicate candidates for ${conditionSetString}.`);\n }\n } else {\n validated.set(conditionSetString, candidate);\n }\n }\n return errors.returnOrReport(\n succeed(Array.from(validated.values()).sort(ResourceCandidate.compare).reverse())\n );\n }\n}\n"]}
@@ -62,6 +62,20 @@ export declare class ResourceCandidate {
62
62
  * @public
63
63
  */
64
64
  static create(params: IResourceCandidateCreateParams): Result<ResourceCandidate>;
65
+ /**
66
+ * Gets the {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}
67
+ * for this candidate.
68
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the declaration.
69
+ * @returns The {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}.
70
+ */
71
+ toChildResourceCandidateDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.IChildResourceCandidateDecl;
72
+ /**
73
+ * Gets the {@link ResourceJson.Json.ILooseResourceCandidateDecl | loose resource candidate declaration}
74
+ * for this candidate.
75
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the declaration.
76
+ * @returns The {@link ResourceJson.Json.ILooseResourceCandidateDecl | loose resource candidate declaration}.
77
+ */
78
+ toLooseResourceCandidateDecl(options?: ResourceJson.Helpers.IDeclarationOptions): ResourceJson.Json.ILooseResourceCandidateDecl;
65
79
  /**
66
80
  * Extracts the {@link ResourceTypes.ResourceType | resource type} from a list of {@link Resources.ResourceCandidate | resource candidates},
67
81
  * if present.
@@ -1 +1 @@
1
- {"version":3,"file":"resourceCandidate.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/resourceCandidate.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAY,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAsD,MAAM,EAAiB,MAAM,eAAe,CAAC;AAE1G;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,2BAA2B,CAAC;IACpD,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,gBAAgB,CAAC,EAAE,aAAa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U,EAAE,aAAa,CAAC,iBAAiB,CAAC,EAC5C,YAAY,CAAC,EAAE,YAAY,GAC1B,MAAM,CAAC,YAAY,GAAG,SAAS,CAAC;IAenC;;;;;;;OAOG;WACW,OAAO,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,GAAG,MAAM;IAI7E;;;;;;OAMG;WACW,KAAK,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,GAAG,OAAO;IAkB5E;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;CA2BhC"}
@@ -93,6 +93,28 @@ class ResourceCandidate {
93
93
  static create(params) {
94
94
  return (0, ts_utils_1.captureResult)(() => new ResourceCandidate(params));
95
95
  }
96
+ /**
97
+ * Gets the {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}
98
+ * for this candidate.
99
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the declaration.
100
+ * @returns The {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}.
101
+ */
102
+ toChildResourceCandidateDecl(options) {
103
+ const showDefaults = (options === null || options === void 0 ? void 0 : options.showDefaults) === true;
104
+ return Object.assign(Object.assign({ json: this.json, conditions: this.conditions.toConditionSetRecordDecl(options) }, (showDefaults || this.isPartial ? { isPartial: this.isPartial } : {})), (showDefaults || this.mergeMethod !== 'augment' ? { mergeMethod: this.mergeMethod } : {}));
105
+ }
106
+ /**
107
+ * Gets the {@link ResourceJson.Json.ILooseResourceCandidateDecl | loose resource candidate declaration}
108
+ * for this candidate.
109
+ * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the declaration.
110
+ * @returns The {@link ResourceJson.Json.ILooseResourceCandidateDecl | loose resource candidate declaration}.
111
+ */
112
+ toLooseResourceCandidateDecl(options) {
113
+ var _a;
114
+ const showDefaults = (options === null || options === void 0 ? void 0 : options.showDefaults) === true;
115
+ const resourceTypeName = (_a = this.resourceType) === null || _a === void 0 ? void 0 : _a.key;
116
+ return Object.assign(Object.assign(Object.assign({ id: this.id.toString(), json: this.json, conditions: this.conditions.toConditionSetRecordDecl(options) }, (showDefaults || this.isPartial ? { isPartial: this.isPartial } : {})), (showDefaults || this.mergeMethod !== 'augment' ? { mergeMethod: this.mergeMethod } : {})), (resourceTypeName ? { resourceTypeName } : {}));
117
+ }
96
118
  /**
97
119
  * Extracts the {@link ResourceTypes.ResourceType | resource type} from a list of {@link Resources.ResourceCandidate | resource candidates},
98
120
  * if present.
@@ -1 +1 @@
1
- {"version":3,"file":"resourceCandidate.js","sourceRoot":"","sources":["../../../src/packlets/resources/resourceCandidate.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,sCAA2E;AAC3E,8CAA+E;AAC/E,+DAAiD;AAEjD,4CAA0G;AAc1G;;;;;GAKG;AACH,MAAa,iBAAiB;IAiC5B;;;;OAIG;IACH,YAAsB,MAAsC;;QAC1D,IAAI,CAAC,EAAE,GAAG,iBAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACrD,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC,gBAAgB,CAClD,MAAM,CAAC,aAAa,EACpB,MAAM,CAAC,IAAI,CAAC,UAAU,EACtB,MAAM,CAAC,gBAAgB,CACxB,CAAC,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC,SAAS,GAAG,MAAA,MAAM,CAAC,IAAI,CAAC,SAAS,mCAAI,KAAK,CAAC;QAChD,IAAI,CAAC,WAAW,GAAG,MAAA,MAAM,CAAC,IAAI,CAAC,WAAW,mCAAI,SAAS,CAAC;QACxD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,IAAI,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kEAAkE;QAClE,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CACjF,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,EAAE;YACjC,4EAA4E;YAC5E,OAAO,IAAA,qBAAU,EAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAClF,CAAC,gBAAgB,EAAE,EAAE;gBACnB,MAAM,UAAU,GAAG,CAAC,GAAG,gBAAgB,EAAE,GAAG,kBAAkB,CAAC,CAAC;gBAChE,OAAO,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YACvD,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AApKD,8CAoKC","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 { ResourceId, ResourceValueMergeMethod, Validate } from '../common';\nimport { Condition, ConditionSet, ConditionSetCollector } from '../conditions';\nimport * as ResourceJson from '../resource-json';\nimport { ResourceType } from '../resource-types';\nimport { captureResult, mapResults, Hash, MessageAggregator, Result, fail, succeed } from '@fgv/ts-utils';\n\n/**\n * Parameters to create a {@link Resources.ResourceCandidate | ResourceCandidate}.\n * @public\n */\nexport interface IResourceCandidateCreateParams {\n id: string;\n decl: ResourceJson.Json.IChildResourceCandidateDecl;\n resourceType?: ResourceType;\n parentConditions?: ReadonlyArray<Condition>;\n conditionSets: ConditionSetCollector;\n}\n\n/**\n * A {@link Resources.ResourceCandidate | resource candidate} represents a single possible\n * instance value for some resource, with the conditions under which it applies\n * and instructions on how to merge it with other instances.\n * @public\n */\nexport class ResourceCandidate {\n /**\n * The unique identifier of the resource for which this candidate\n * is a possible instance.\n */\n public readonly id: ResourceId;\n\n /**\n * The JSON representation of the instance data to be applied.\n */\n public readonly json: JsonValue;\n\n /**\n * The conditions under which this candidate applies.\n */\n public readonly conditions: ConditionSet;\n\n /**\n * True if this candidate is a partial instance.\n */\n public readonly isPartial: boolean;\n\n /**\n * The method to use when merging this candidate with other instances.\n */\n public readonly mergeMethod: ResourceValueMergeMethod;\n\n /**\n * The {@link ResourceTypes.ResourceType | resource type} for the resource to which\n * this candidate belongs.\n */\n public readonly resourceType: ResourceType | undefined;\n\n /**\n * Constructor for a {@link Resources.ResourceCandidate | ResourceCandidate} object.\n * @param params - Parameters to create a new {@link Resources.ResourceCandidate | ResourceCandidate}.\n * @public\n */\n protected constructor(params: IResourceCandidateCreateParams) {\n this.id = Validate.toResourceId(params.id).orThrow();\n this.json = params.decl.json;\n this.conditions = ResourceCandidate._mergeConditions(\n params.conditionSets,\n params.decl.conditions,\n params.parentConditions\n ).orThrow();\n this.isPartial = params.decl.isPartial ?? false;\n this.mergeMethod = params.decl.mergeMethod ?? 'augment';\n this.resourceType = params.resourceType;\n if (this.resourceType) {\n this.resourceType.validateDeclaration(this.json, this.isPartial, this.mergeMethod).orThrow();\n }\n }\n\n /**\n * Creates a new {@link Resources.ResourceCandidate | ResourceCandidate} object.\n * @param params - Parameters to create a new {@link Resources.ResourceCandidate | ResourceCandidate}.\n * @returns `Success` with the new {@link Resources.ResourceCandidate | ResourceCandidate} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IResourceCandidateCreateParams): Result<ResourceCandidate> {\n return captureResult(() => new ResourceCandidate(params));\n }\n\n /**\n * Extracts the {@link ResourceTypes.ResourceType | resource type} from a list of {@link Resources.ResourceCandidate | resource candidates},\n * if present.\n * @param candidates - The list of candidates from which to extract the resource type.\n * @returns `Success` with the resource type if successful, `Success` with `undefined` if none of the candidates\n * specify a resource tap, and `Failure` with an error message if clients specify conflicting resource types.\n * @public\n */\n public static validateResourceTypes(\n candidates: ReadonlyArray<ResourceCandidate>,\n expectedType?: ResourceType\n ): Result<ResourceType | undefined> {\n const errors = new MessageAggregator();\n let selectedType: ResourceType | undefined = expectedType;\n for (const candidate of candidates) {\n if (selectedType === undefined) {\n selectedType = candidate.resourceType;\n } else if (candidate.resourceType && selectedType !== candidate.resourceType) {\n errors.addMessage(\n `${candidate.id}: resource type mismatch (${selectedType.key} != ${candidate.resourceType.key})`\n );\n }\n }\n return errors.returnOrReport(succeed(selectedType));\n }\n\n /**\n * Compares two {@link Resources.ResourceCandidate | ResourceCandidates} for sorting purposes.\n * @param rc1 - The first candidate to compare.\n * @param rc2 - The second candidate to compare.\n * @returns A negative number if `rc1` should come before `rc2`, a positive number if `rc2` should come before `rc1`,\n * or zero if they are equivalent.\n * @public\n */\n public static compare(rc1: ResourceCandidate, rc2: ResourceCandidate): number {\n return ConditionSet.compare(rc1.conditions, rc2.conditions);\n }\n\n /**\n * Compares two {@link Resources.ResourceCandidate | ResourceCandidates} for equality.\n * @param rc1 - The first candidate to compare.\n * @param rc2 - The second candidate to compare.\n * @returns `true` if the candidates are equal, `false` otherwise.\n * @public\n */\n public static equal(rc1: ResourceCandidate, rc2: ResourceCandidate): boolean {\n if (rc1 === rc2) {\n return true;\n }\n let equal =\n rc1.id === rc2.id &&\n rc1.isPartial === rc2.isPartial &&\n rc1.mergeMethod === rc2.mergeMethod &&\n ConditionSet.compare(rc1.conditions, rc2.conditions) === 0;\n if (equal) {\n const normalizer = new Hash.Crc32Normalizer();\n const n1 = normalizer.computeHash(rc1.json).orDefault('(n1 normalization failed)');\n const n2 = normalizer.computeHash(rc2.json).orDefault('(n2 normalization failed)');\n equal = n1 === n2;\n }\n return equal;\n }\n\n /**\n * Validates declared conditions and merges them with parent conditions.\n * @param conditionSets - The {@link Conditions.ConditionSetCollector | condition set collector}\n * to use for this candidate.\n * @param declared - The declared conditions for the candidate.\n * @param parent - The parent conditions to merge with the declared conditions.\n * @returns `Success` with the merged conditions if successful, `Failure` otherwise.\n * @internal\n */\n private static _mergeConditions(\n conditionSets: ConditionSetCollector,\n declared: ResourceJson.Json.ConditionSetDecl | undefined,\n parent: ReadonlyArray<Condition> | undefined\n ): Result<ConditionSet> {\n /* c8 ignore next 2 - code coverage is flaky */\n declared = declared ?? {};\n parent = parent ?? [];\n\n const { value: conditionDecls, message } = ResourceJson.Convert.conditionSetDecl.convert(declared);\n if (message !== undefined) {\n return fail(message);\n }\n\n return mapResults(\n // get or add all declared conditions from our condition collector\n conditionDecls.map((decl) => conditionSets.conditions.validating.getOrAdd(decl))\n ).onSuccess((declaredConditions) => {\n // make sure our parent conditions all come from our condition collector too\n return mapResults(parent.map((c) => conditionSets.conditions.getOrAdd(c))).onSuccess(\n (parentConditions) => {\n const conditions = [...parentConditions, ...declaredConditions];\n return conditionSets.validating.getOrAdd(conditions);\n }\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"resourceCandidate.js","sourceRoot":"","sources":["../../../src/packlets/resources/resourceCandidate.ts"],"names":[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C,SAAS,CAClF,CAAC,gBAAgB,EAAE,EAAE;gBACnB,MAAM,UAAU,GAAG,CAAC,GAAG,gBAAgB,EAAE,GAAG,kBAAkB,CAAC,CAAC;gBAChE,OAAO,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YACvD,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA3MD,8CA2MC","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 { JsonObject, JsonValue } from '@fgv/ts-json-base';\nimport { ResourceId, ResourceValueMergeMethod, Validate } from '../common';\nimport { Condition, ConditionSet, ConditionSetCollector } from '../conditions';\nimport * as ResourceJson from '../resource-json';\nimport { ResourceType } from '../resource-types';\nimport { captureResult, mapResults, Hash, MessageAggregator, Result, fail, succeed } from '@fgv/ts-utils';\n\n/**\n * Parameters to create a {@link Resources.ResourceCandidate | ResourceCandidate}.\n * @public\n */\nexport interface IResourceCandidateCreateParams {\n id: string;\n decl: ResourceJson.Json.IChildResourceCandidateDecl;\n resourceType?: ResourceType;\n parentConditions?: ReadonlyArray<Condition>;\n conditionSets: ConditionSetCollector;\n}\n\n/**\n * A {@link Resources.ResourceCandidate | resource candidate} represents a single possible\n * instance value for some resource, with the conditions under which it applies\n * and instructions on how to merge it with other instances.\n * @public\n */\nexport class ResourceCandidate {\n /**\n * The unique identifier of the resource for which this candidate\n * is a possible instance.\n */\n public readonly id: ResourceId;\n\n /**\n * The JSON representation of the instance data to be applied.\n */\n public readonly json: JsonValue;\n\n /**\n * The conditions under which this candidate applies.\n */\n public readonly conditions: ConditionSet;\n\n /**\n * True if this candidate is a partial instance.\n */\n public readonly isPartial: boolean;\n\n /**\n * The method to use when merging this candidate with other instances.\n */\n public readonly mergeMethod: ResourceValueMergeMethod;\n\n /**\n * The {@link ResourceTypes.ResourceType | resource type} for the resource to which\n * this candidate belongs.\n */\n public readonly resourceType: ResourceType | undefined;\n\n /**\n * Constructor for a {@link Resources.ResourceCandidate | ResourceCandidate} object.\n * @param params - Parameters to create a new {@link Resources.ResourceCandidate | ResourceCandidate}.\n * @public\n */\n protected constructor(params: IResourceCandidateCreateParams) {\n this.id = Validate.toResourceId(params.id).orThrow();\n this.json = params.decl.json;\n this.conditions = ResourceCandidate._mergeConditions(\n params.conditionSets,\n params.decl.conditions,\n params.parentConditions\n ).orThrow();\n this.isPartial = params.decl.isPartial ?? false;\n this.mergeMethod = params.decl.mergeMethod ?? 'augment';\n this.resourceType = params.resourceType;\n if (this.resourceType) {\n this.resourceType.validateDeclaration(this.json, this.isPartial, this.mergeMethod).orThrow();\n }\n }\n\n /**\n * Creates a new {@link Resources.ResourceCandidate | ResourceCandidate} object.\n * @param params - Parameters to create a new {@link Resources.ResourceCandidate | ResourceCandidate}.\n * @returns `Success` with the new {@link Resources.ResourceCandidate | ResourceCandidate} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IResourceCandidateCreateParams): Result<ResourceCandidate> {\n return captureResult(() => new ResourceCandidate(params));\n }\n\n /**\n * Gets the {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}\n * for this candidate.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the declaration.\n * @returns The {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}.\n */\n public toChildResourceCandidateDecl(\n options?: ResourceJson.Helpers.IDeclarationOptions\n ): ResourceJson.Json.IChildResourceCandidateDecl {\n const showDefaults = options?.showDefaults === true;\n return {\n json: this.json as JsonObject,\n conditions: this.conditions.toConditionSetRecordDecl(options),\n ...(showDefaults || this.isPartial ? { isPartial: this.isPartial } : {}),\n ...(showDefaults || this.mergeMethod !== 'augment' ? { mergeMethod: this.mergeMethod } : {})\n };\n }\n\n /**\n * Gets the {@link ResourceJson.Json.ILooseResourceCandidateDecl | loose resource candidate declaration}\n * for this candidate.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} to use when creating the declaration.\n * @returns The {@link ResourceJson.Json.ILooseResourceCandidateDecl | loose resource candidate declaration}.\n */\n public toLooseResourceCandidateDecl(\n options?: ResourceJson.Helpers.IDeclarationOptions\n ): ResourceJson.Json.ILooseResourceCandidateDecl {\n const showDefaults = options?.showDefaults === true;\n const resourceTypeName = this.resourceType?.key;\n return {\n id: this.id.toString(),\n json: this.json as JsonObject,\n conditions: this.conditions.toConditionSetRecordDecl(options),\n ...(showDefaults || this.isPartial ? { isPartial: this.isPartial } : {}),\n ...(showDefaults || this.mergeMethod !== 'augment' ? { mergeMethod: this.mergeMethod } : {}),\n ...(resourceTypeName ? { resourceTypeName } : {})\n };\n }\n\n /**\n * Extracts the {@link ResourceTypes.ResourceType | resource type} from a list of {@link Resources.ResourceCandidate | resource candidates},\n * if present.\n * @param candidates - The list of candidates from which to extract the resource type.\n * @returns `Success` with the resource type if successful, `Success` with `undefined` if none of the candidates\n * specify a resource tap, and `Failure` with an error message if clients specify conflicting resource types.\n * @public\n */\n public static validateResourceTypes(\n candidates: ReadonlyArray<ResourceCandidate>,\n expectedType?: ResourceType\n ): Result<ResourceType | undefined> {\n const errors = new MessageAggregator();\n let selectedType: ResourceType | undefined = expectedType;\n for (const candidate of candidates) {\n if (selectedType === undefined) {\n selectedType = candidate.resourceType;\n } else if (candidate.resourceType && selectedType !== candidate.resourceType) {\n errors.addMessage(\n `${candidate.id}: resource type mismatch (${selectedType.key} != ${candidate.resourceType.key})`\n );\n }\n }\n return errors.returnOrReport(succeed(selectedType));\n }\n\n /**\n * Compares two {@link Resources.ResourceCandidate | ResourceCandidates} for sorting purposes.\n * @param rc1 - The first candidate to compare.\n * @param rc2 - The second candidate to compare.\n * @returns A negative number if `rc1` should come before `rc2`, a positive number if `rc2` should come before `rc1`,\n * or zero if they are equivalent.\n * @public\n */\n public static compare(rc1: ResourceCandidate, rc2: ResourceCandidate): number {\n return ConditionSet.compare(rc1.conditions, rc2.conditions);\n }\n\n /**\n * Compares two {@link Resources.ResourceCandidate | ResourceCandidates} for equality.\n * @param rc1 - The first candidate to compare.\n * @param rc2 - The second candidate to compare.\n * @returns `true` if the candidates are equal, `false` otherwise.\n * @public\n */\n public static equal(rc1: ResourceCandidate, rc2: ResourceCandidate): boolean {\n if (rc1 === rc2) {\n return true;\n }\n let equal =\n rc1.id === rc2.id &&\n rc1.isPartial === rc2.isPartial &&\n rc1.mergeMethod === rc2.mergeMethod &&\n ConditionSet.compare(rc1.conditions, rc2.conditions) === 0;\n if (equal) {\n const normalizer = new Hash.Crc32Normalizer();\n const n1 = normalizer.computeHash(rc1.json).orDefault('(n1 normalization failed)');\n const n2 = normalizer.computeHash(rc2.json).orDefault('(n2 normalization failed)');\n equal = n1 === n2;\n }\n return equal;\n }\n\n /**\n * Validates declared conditions and merges them with parent conditions.\n * @param conditionSets - The {@link Conditions.ConditionSetCollector | condition set collector}\n * to use for this candidate.\n * @param declared - The declared conditions for the candidate.\n * @param parent - The parent conditions to merge with the declared conditions.\n * @returns `Success` with the merged conditions if successful, `Failure` otherwise.\n * @internal\n */\n private static _mergeConditions(\n conditionSets: ConditionSetCollector,\n declared: ResourceJson.Json.ConditionSetDecl | undefined,\n parent: ReadonlyArray<Condition> | undefined\n ): Result<ConditionSet> {\n /* c8 ignore next 2 - code coverage is flaky */\n declared = declared ?? {};\n parent = parent ?? [];\n\n const { value: conditionDecls, message } = ResourceJson.Convert.conditionSetDecl.convert(declared);\n if (message !== undefined) {\n return fail(message);\n }\n\n return mapResults(\n // get or add all declared conditions from our condition collector\n conditionDecls.map((decl) => conditionSets.conditions.validating.getOrAdd(decl))\n ).onSuccess((declaredConditions) => {\n // make sure our parent conditions all come from our condition collector too\n return mapResults(parent.map((c) => conditionSets.conditions.getOrAdd(c))).onSuccess(\n (parentConditions) => {\n const conditions = [...parentConditions, ...declaredConditions];\n return conditionSets.validating.getOrAdd(conditions);\n }\n );\n });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"resourceManager.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/resourceManager.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,WAAW,EACX,cAAc,EAGd,MAAM,EAGN,mBAAmB,EACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,0BAA0B,EAC1B,6BAA6B,EAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,yBAAyB,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAW,UAAU,EAAY,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;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e,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"}
@@ -137,25 +137,33 @@ class ResourceManager {
137
137
  });
138
138
  }
139
139
  addResource(decl) {
140
+ var _a;
140
141
  const { value: id, message } = common_1.Validate.toResourceId(decl.id);
141
142
  if (message !== undefined) {
142
143
  return (0, ts_utils_1.failWithDetail)(`${id}: invalid id - ${message}`, 'failure');
143
144
  }
144
- return this._resources.getOrAdd(id, () => resourceBuilder_1.ResourceBuilder.create({
145
+ const { value: builder, message: getOrAddMessage, detail } = this._resources.getOrAdd(id, () => resourceBuilder_1.ResourceBuilder.create({
145
146
  id,
146
147
  typeName: decl.resourceTypeName,
147
148
  resourceTypes: this.resourceTypes,
148
149
  conditionSets: this._conditionSets
149
- })
150
- .onSuccess((builder) => {
151
- return builder.setResourceType(decl.resourceTypeName);
152
- })
153
- .onSuccess((builder) => {
154
- if (decl.candidates) {
155
- decl.candidates.forEach((c) => builder.addChildCandidate(c));
150
+ }));
151
+ /* c8 ignore next 3 - defense in depth against internal error */
152
+ if (getOrAddMessage !== undefined) {
153
+ return (0, ts_utils_1.failWithDetail)(`${id}: unable to get or add resource\n${getOrAddMessage}`, detail);
154
+ }
155
+ if (detail === 'exists') {
156
+ const { message } = builder.setResourceType(decl.resourceTypeName);
157
+ if (message !== undefined) {
158
+ return (0, ts_utils_1.failWithDetail)(`${id}: unable to set resource type\n${message}`, 'type-mismatch');
156
159
  }
160
+ }
161
+ const candidates = (_a = decl.candidates) !== null && _a !== void 0 ? _a : [];
162
+ return (0, ts_utils_1.mapResults)(candidates.map((c) => builder.addChildCandidate(c)))
163
+ .onSuccess(() => {
157
164
  return (0, ts_utils_1.succeed)(builder);
158
- }));
165
+ })
166
+ .withDetail('failure', detail);
159
167
  }
160
168
  /**
161
169
  * Gets an individual {@link Resources.Resource | built resource} from the manager.
@@ -1 +1 @@
1
- {"version":3,"file":"resourceManager.js","sourceRoot":"","sources":["../../../src/packlets/resources/resourceManager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAUuB;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,GAAG,kCAAqB,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QAC/F,IAAI,CAAC,UAAU,GAAG,qCAAyB,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,IAAI,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AO,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;AA3LD,0CA2LC","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 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 return this._resources.getOrAdd(id, () =>\n ResourceBuilder.create({\n id,\n typeName: decl.resourceTypeName,\n resourceTypes: this.resourceTypes,\n conditionSets: this._conditionSets\n })\n .onSuccess((builder) => {\n return builder.setResourceType(decl.resourceTypeName);\n })\n .onSuccess((builder) => {\n if (decl.candidates) {\n decl.candidates.forEach((c) => builder.addChildCandidate(c));\n }\n return succeed(builder);\n })\n );\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,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,GAA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AC,CAAC;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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-res",
3
- "version": "4.5.0-0",
3
+ "version": "4.5.0-2",
4
4
  "description": "Multi-dimensional Resource Runtime",
5
5
  "main": "lib/index.js",
6
6
  "types": "dist/ts-res.d.ts",
@@ -18,19 +18,12 @@
18
18
  "homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-res#readme",
19
19
  "sideEffects": false,
20
20
  "devDependencies": {
21
- "@fgv/ts-bcp47": "4.5.0-0",
22
- "@fgv/ts-extras": "4.5.0-0",
23
- "@fgv/ts-json": "4.5.0-0",
24
- "@fgv/ts-json-base": "4.5.0-0",
25
- "@fgv/ts-utils": "4.5.0-0",
26
- "@fgv/ts-utils-jest": "4.5.0-0",
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",
27
25
  "@microsoft/api-documenter": "^7.26.17",
28
26
  "@microsoft/api-extractor": "^7.52.1",
29
- "@rushstack/eslint-config": "~4.3.0",
30
- "@rushstack/heft": "~0.71.0",
31
- "@rushstack/heft-jest-plugin": "~0.15.2",
32
- "@rushstack/heft-node-rig": "~2.8.2",
33
- "@types/heft-jest": "1.0.6",
34
27
  "@types/jest": "^29.5.14",
35
28
  "@types/luxon": "^3.4.2",
36
29
  "@types/node": "^22.13.11",
@@ -39,27 +32,34 @@
39
32
  "eslint": "^8.57.0",
40
33
  "eslint-config-prettier": "^10.1.1",
41
34
  "eslint-plugin-import": "^2.31.0",
42
- "eslint-plugin-n": "^17.16.2",
43
35
  "eslint-plugin-node": "^11.1.0",
44
36
  "eslint-plugin-prettier": "^5.2.3",
45
37
  "eslint-plugin-promise": "^7.2.1",
46
- "eslint-plugin-tsdoc": "~0.4.0",
47
38
  "jest": "^29.7.0",
48
39
  "prettier": "^3.5.3",
49
40
  "rimraf": "^6.0.1",
50
41
  "ts-jest": "^29.2.6",
51
42
  "ts-node": "^10.9.2",
52
- "typescript": "^5.8.2"
43
+ "typescript": "^5.8.2",
44
+ "eslint-plugin-n": "^17.16.2",
45
+ "@rushstack/eslint-config": "~4.3.0",
46
+ "@rushstack/heft": "~0.71.0",
47
+ "@rushstack/heft-jest-plugin": "~0.15.2",
48
+ "@rushstack/heft-node-rig": "~2.8.2",
49
+ "@types/heft-jest": "1.0.6",
50
+ "eslint-plugin-tsdoc": "~0.4.0",
51
+ "@fgv/ts-bcp47": "4.5.0-2",
52
+ "@fgv/ts-json": "4.5.0-2"
53
53
  },
54
54
  "dependencies": {
55
55
  "luxon": "^3.5.0"
56
56
  },
57
57
  "peerDependencies": {
58
- "@fgv/ts-bcp47": "4.5.0-0",
59
- "@fgv/ts-extras": "4.5.0-0",
60
- "@fgv/ts-json": "4.5.0-0",
61
- "@fgv/ts-json-base": "4.5.0-0",
62
- "@fgv/ts-utils": "4.5.0-0"
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"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "heft build --clean",