@fgv/ts-res 5.0.1-9 → 5.0.2-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/index.browser.js +53 -0
  2. package/dist/index.js +45 -0
  3. package/dist/packlets/bundle/bundleBuilder.js +130 -0
  4. package/dist/packlets/bundle/bundleLoader.js +101 -0
  5. package/dist/packlets/bundle/bundleNormalizer.js +138 -0
  6. package/dist/packlets/bundle/bundleUtils.js +113 -0
  7. package/dist/packlets/bundle/convert.js +75 -0
  8. package/dist/packlets/bundle/index.js +42 -0
  9. package/dist/packlets/bundle/model.js +23 -0
  10. package/dist/packlets/common/conditions.js +47 -0
  11. package/dist/packlets/common/convert.js +172 -0
  12. package/dist/packlets/common/helpers/conditions.js +66 -0
  13. package/dist/packlets/common/helpers/context.js +70 -0
  14. package/dist/packlets/common/helpers/index.js +26 -0
  15. package/dist/packlets/common/helpers/qualifierDefaultValues.js +66 -0
  16. package/dist/packlets/common/helpers/resources.js +93 -0
  17. package/dist/packlets/common/index.js +28 -0
  18. package/dist/packlets/common/resources.js +27 -0
  19. package/dist/packlets/common/validate/conditions.js +544 -0
  20. package/dist/packlets/common/validate/index.js +26 -0
  21. package/dist/packlets/common/validate/regularExpressions.js +84 -0
  22. package/dist/packlets/common/validate/resources.js +209 -0
  23. package/dist/packlets/conditions/condition.js +252 -0
  24. package/dist/packlets/conditions/conditionCollector.js +69 -0
  25. package/dist/packlets/conditions/conditionDecls.js +23 -0
  26. package/dist/packlets/conditions/conditionSet.js +247 -0
  27. package/dist/packlets/conditions/conditionSetCollector.js +89 -0
  28. package/dist/packlets/conditions/conditionSetDecls.js +23 -0
  29. package/dist/packlets/conditions/conditionToken.js +147 -0
  30. package/dist/packlets/conditions/convert/conditionSetDecls.js +51 -0
  31. package/dist/packlets/conditions/convert/decls.js +75 -0
  32. package/dist/packlets/conditions/convert/index.js +24 -0
  33. package/dist/packlets/conditions/index.js +31 -0
  34. package/dist/packlets/config/common.js +78 -0
  35. package/dist/packlets/config/configInitFactory.js +258 -0
  36. package/dist/packlets/config/convert.js +56 -0
  37. package/dist/packlets/config/index.browser.js +34 -0
  38. package/dist/packlets/config/index.js +28 -0
  39. package/dist/packlets/config/json.js +23 -0
  40. package/dist/packlets/config/predefined/default.js +138 -0
  41. package/dist/packlets/config/predefined/extended.js +190 -0
  42. package/dist/packlets/config/predefined/index.js +25 -0
  43. package/dist/packlets/config/systemConfiguration.js +147 -0
  44. package/dist/packlets/context/contextDecls.js +23 -0
  45. package/dist/packlets/context/contextToken.js +202 -0
  46. package/dist/packlets/context/convert/decls.js +91 -0
  47. package/dist/packlets/context/convert/index.js +23 -0
  48. package/dist/packlets/context/index.js +26 -0
  49. package/dist/packlets/decisions/abstractDecision.js +68 -0
  50. package/dist/packlets/decisions/abstractDecisionCollector.js +90 -0
  51. package/dist/packlets/decisions/candidate.js +76 -0
  52. package/dist/packlets/decisions/common.js +23 -0
  53. package/dist/packlets/decisions/concreteDecision.js +111 -0
  54. package/dist/packlets/decisions/decision.js +126 -0
  55. package/dist/packlets/decisions/index.js +28 -0
  56. package/dist/packlets/import/fsItem.js +134 -0
  57. package/dist/packlets/import/importContext.js +129 -0
  58. package/dist/packlets/import/importManager.js +129 -0
  59. package/dist/packlets/import/importable.js +32 -0
  60. package/dist/packlets/import/importers/collectionImporter.js +118 -0
  61. package/dist/packlets/import/importers/fsItemImporter.js +116 -0
  62. package/dist/packlets/import/importers/importer.js +23 -0
  63. package/dist/packlets/import/importers/index.browser.js +29 -0
  64. package/dist/packlets/import/importers/index.js +27 -0
  65. package/dist/packlets/import/importers/jsonImporter.js +94 -0
  66. package/dist/packlets/import/importers/pathImporter.js +84 -0
  67. package/dist/packlets/import/index.browser.js +34 -0
  68. package/dist/packlets/import/index.js +28 -0
  69. package/dist/packlets/qualifier-types/config/convert.js +124 -0
  70. package/dist/packlets/qualifier-types/config/index.js +25 -0
  71. package/dist/packlets/qualifier-types/config/json.js +32 -0
  72. package/dist/packlets/qualifier-types/convert.js +56 -0
  73. package/dist/packlets/qualifier-types/helpers.js +82 -0
  74. package/dist/packlets/qualifier-types/index.js +32 -0
  75. package/dist/packlets/qualifier-types/languageQualifierType.js +142 -0
  76. package/dist/packlets/qualifier-types/literalQualifierType.js +200 -0
  77. package/dist/packlets/qualifier-types/literalValueHierarchy.js +236 -0
  78. package/dist/packlets/qualifier-types/qualifierType.js +184 -0
  79. package/dist/packlets/qualifier-types/qualifierTypeCollector.js +66 -0
  80. package/dist/packlets/qualifier-types/territoryQualifierType.js +200 -0
  81. package/dist/packlets/qualifiers/convert/decls.js +70 -0
  82. package/dist/packlets/qualifiers/convert/index.js +24 -0
  83. package/dist/packlets/qualifiers/convert/qualifier.js +40 -0
  84. package/dist/packlets/qualifiers/index.js +29 -0
  85. package/dist/packlets/qualifiers/qualifier.js +108 -0
  86. package/dist/packlets/qualifiers/qualifierCollector.js +123 -0
  87. package/dist/packlets/qualifiers/qualifierDecl.js +23 -0
  88. package/dist/packlets/qualifiers/qualifierDefaultValueDecls.js +23 -0
  89. package/dist/packlets/qualifiers/qualifierDefaultValueToken.js +175 -0
  90. package/dist/packlets/resource-json/compiled/common.js +23 -0
  91. package/dist/packlets/resource-json/compiled/convert.js +132 -0
  92. package/dist/packlets/resource-json/compiled/index.js +26 -0
  93. package/dist/packlets/resource-json/compiled/json.js +2 -0
  94. package/dist/packlets/resource-json/convert.js +171 -0
  95. package/dist/packlets/resource-json/helpers.js +241 -0
  96. package/dist/packlets/resource-json/index.js +31 -0
  97. package/dist/packlets/resource-json/json.js +36 -0
  98. package/dist/packlets/resource-json/normalized.js +23 -0
  99. package/dist/packlets/resource-json/resourceDeclCollection.js +88 -0
  100. package/dist/packlets/resource-json/resourceDeclContainer.js +23 -0
  101. package/dist/packlets/resource-json/resourceDeclTree.js +94 -0
  102. package/dist/packlets/resource-types/config/convert.js +35 -0
  103. package/dist/packlets/resource-types/config/index.js +25 -0
  104. package/dist/packlets/resource-types/config/json.js +23 -0
  105. package/dist/packlets/resource-types/helpers.js +42 -0
  106. package/dist/packlets/resource-types/index.js +28 -0
  107. package/dist/packlets/resource-types/jsonResourceType.js +66 -0
  108. package/dist/packlets/resource-types/resourceType.js +95 -0
  109. package/dist/packlets/resource-types/resourceTypeCollector.js +61 -0
  110. package/dist/packlets/resources/candidateReducer.js +246 -0
  111. package/dist/packlets/resources/candidateValue.js +92 -0
  112. package/dist/packlets/resources/candidateValueCollector.js +94 -0
  113. package/dist/packlets/resources/common.js +23 -0
  114. package/dist/packlets/resources/deltaGenerator.js +338 -0
  115. package/dist/packlets/resources/index.js +31 -0
  116. package/dist/packlets/resources/resource.js +207 -0
  117. package/dist/packlets/resources/resourceBuilder.js +183 -0
  118. package/dist/packlets/resources/resourceCandidate.js +216 -0
  119. package/dist/packlets/resources/resourceManagerBuilder.js +890 -0
  120. package/dist/packlets/runtime/cacheListener.js +58 -0
  121. package/dist/packlets/runtime/cacheMetrics.js +149 -0
  122. package/dist/packlets/runtime/compiledResourceCollection.js +473 -0
  123. package/dist/packlets/runtime/conditionSetResolutionResult.js +134 -0
  124. package/dist/packlets/runtime/context/contextQualifierProvider.js +29 -0
  125. package/dist/packlets/runtime/context/contextQualifierProviderValidator.js +146 -0
  126. package/dist/packlets/runtime/context/index.js +26 -0
  127. package/dist/packlets/runtime/context/simpleContextQualifierProvider.js +196 -0
  128. package/dist/packlets/runtime/context/validatingSimpleContextQualifierProvider.js +60 -0
  129. package/dist/packlets/runtime/iResourceManager.js +23 -0
  130. package/dist/packlets/runtime/index.js +34 -0
  131. package/dist/packlets/runtime/resource-tree/common.js +23 -0
  132. package/dist/packlets/runtime/resource-tree/index.js +26 -0
  133. package/dist/packlets/runtime/resource-tree/readOnlyResourceTree.js +216 -0
  134. package/dist/packlets/runtime/resource-tree/resourceTreeChildren.js +97 -0
  135. package/dist/packlets/runtime/resource-tree/resourceTreeChildrenValidator.js +161 -0
  136. package/dist/packlets/runtime/resourceResolver.js +481 -0
  137. package/dist/packlets/runtime/resourceTreeResolver.js +220 -0
  138. package/dist/packlets/runtime/validate.js +47 -0
  139. package/dist/packlets/zip-archive/convert.js +100 -0
  140. package/dist/packlets/zip-archive/index.browser.js +54 -0
  141. package/dist/packlets/zip-archive/index.js +47 -0
  142. package/dist/packlets/zip-archive/json.js +23 -0
  143. package/dist/packlets/zip-archive/types.js +36 -0
  144. package/dist/packlets/zip-archive/zipArchiveCreator.js +191 -0
  145. package/dist/packlets/zip-archive/zipArchiveFormat.js +140 -0
  146. package/dist/packlets/zip-archive/zipArchiveLoader.js +282 -0
  147. package/dist/test/data/sample.json +32 -0
  148. package/dist/test/unit/qualifier-types/testQualifierType.js +76 -0
  149. package/dist/test/unit/resource-types/testDerivedResourceType.js +109 -0
  150. package/dist/test/unit/resources/deltaGenerator.helpers.js +282 -0
  151. package/dist/tsdoc-metadata.json +1 -1
  152. package/lib/index.browser.d.ts +24 -0
  153. package/lib/index.browser.js +116 -0
  154. package/lib/packlets/config/index.browser.d.ts +7 -0
  155. package/lib/packlets/config/index.browser.js +74 -0
  156. package/lib/packlets/import/importers/index.browser.d.ts +4 -0
  157. package/lib/packlets/import/importers/index.browser.js +45 -0
  158. package/lib/packlets/import/index.browser.d.ts +7 -0
  159. package/lib/packlets/import/index.browser.js +74 -0
  160. package/lib/packlets/zip-archive/index.browser.d.ts +27 -0
  161. package/lib/packlets/zip-archive/index.browser.js +102 -0
  162. package/package.json +25 -7
@@ -0,0 +1,171 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ import { Converters, mapResults, fail } from '@fgv/ts-utils';
23
+ import { Convert as CommonConvert } from '../common';
24
+ import { isJsonObject, Converters as JsonConverters } from '@fgv/ts-json-base';
25
+ /**
26
+ * `Converter` for a normalized {@link ResourceJson.Json.ILooseConditionDecl | loose condition declaration}.
27
+ * @public
28
+ */
29
+ export const looseConditionDecl = Converters.strictObject({
30
+ qualifierName: CommonConvert.qualifierName,
31
+ value: Converters.string,
32
+ operator: CommonConvert.conditionOperator.optional(),
33
+ priority: CommonConvert.conditionPriority.optional(),
34
+ scoreAsDefault: Converters.number.optional()
35
+ });
36
+ /**
37
+ * `Converter` for a normalized {@link ResourceJson.Json.IChildConditionDecl | child condition declaration}.
38
+ * @public
39
+ */
40
+ export const childConditionDecl = Converters.strictObject({
41
+ value: Converters.string,
42
+ operator: CommonConvert.conditionOperator.optional(),
43
+ priority: CommonConvert.conditionPriority.optional(),
44
+ scoreAsDefault: Converters.number.optional()
45
+ });
46
+ function _isConditionSetRecord(from) {
47
+ return isJsonObject(from);
48
+ }
49
+ const conditionSetDeclFromArray = Converters.arrayOf(looseConditionDecl);
50
+ const conditionSetDeclFromRecord = Converters.generic((from, __self, context) => {
51
+ /* c8 ignore next 3 - this is tested but coverage is confused */
52
+ if (!_isConditionSetRecord(from)) {
53
+ return fail('Expected an object');
54
+ }
55
+ return mapResults(Array.from(Object.entries(from)).map(([qualifierName, value]) => {
56
+ const toConvert = typeof value === 'string' ? { qualifierName, value } : Object.assign({ qualifierName }, value);
57
+ return looseConditionDecl.convert(toConvert, context);
58
+ }));
59
+ });
60
+ /**
61
+ * `Converter` for a normalized {@link ResourceJson.Normalized.ConditionSetDecl | condition set declaration}.
62
+ * @public
63
+ */
64
+ export const conditionSetDecl = Converters.oneOf([conditionSetDeclFromArray, conditionSetDeclFromRecord]);
65
+ /**
66
+ * `Converter` for a normalized {@link ResourceJson.Json.ILooseResourceCandidateDecl | loose resource candidate declaration}.
67
+ * @public
68
+ */
69
+ export const looseResourceCandidateDecl = Converters.strictObject({
70
+ id: CommonConvert.resourceId,
71
+ json: JsonConverters.jsonObject,
72
+ conditions: conditionSetDecl.optional(),
73
+ mergeMethod: CommonConvert.resourceValueMergeMethod.optional(),
74
+ isPartial: Converters.boolean.optional(),
75
+ resourceTypeName: CommonConvert.resourceTypeName.optional()
76
+ });
77
+ /**
78
+ * `Converter` for a normalized {@link ResourceJson.Normalized.IImporterResourceCandidateDecl | importer resource candidate declaration}.
79
+ * @public
80
+ */
81
+ export const importerResourceCandidateDecl = Converters.strictObject({
82
+ id: CommonConvert.resourceId.optional(),
83
+ json: JsonConverters.jsonObject,
84
+ conditions: conditionSetDecl.optional(),
85
+ mergeMethod: CommonConvert.resourceValueMergeMethod.optional(),
86
+ isPartial: Converters.boolean.optional(),
87
+ resourceTypeName: CommonConvert.resourceTypeName.optional()
88
+ });
89
+ /**
90
+ * `Converter` for a normalized {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}.
91
+ * @public
92
+ */
93
+ export const childResourceCandidateDecl = Converters.strictObject({
94
+ json: JsonConverters.jsonObject,
95
+ conditions: conditionSetDecl.optional(),
96
+ isPartial: Converters.boolean.optional(),
97
+ mergeMethod: CommonConvert.resourceValueMergeMethod.optional()
98
+ });
99
+ /**
100
+ * `Converter` for a normalized {@link ResourceJson.Normalized.ILooseResourceDecl | loose resource declaration}.
101
+ * @public
102
+ */
103
+ export const looseResourceDecl = Converters.strictObject({
104
+ id: CommonConvert.resourceId,
105
+ resourceTypeName: CommonConvert.resourceTypeName,
106
+ candidates: Converters.arrayOf(childResourceCandidateDecl).optional()
107
+ });
108
+ /**
109
+ * `Converter` for a normalized {@link ResourceJson.Normalized.IChildResourceDecl | child resource declaration}.
110
+ * @public
111
+ */
112
+ export const childResourceDecl = Converters.strictObject({
113
+ resourceTypeName: CommonConvert.resourceTypeName,
114
+ candidates: Converters.arrayOf(childResourceCandidateDecl).optional()
115
+ });
116
+ /**
117
+ * `Converter` for a normalized {@link ResourceJson.Normalized.IContainerContextDecl | resource context declaration}.
118
+ * @public
119
+ */
120
+ export const containerContextDecl = Converters.strictObject({
121
+ baseId: Converters.oneOf([CommonConvert.resourceId, Converters.literal('')]).optional(),
122
+ conditions: conditionSetDecl.optional(),
123
+ mergeMethod: CommonConvert.resourceValueMergeMethod.optional()
124
+ });
125
+ /**
126
+ * `Converter` for a normalized {@link ResourceJson.Normalized.IResourceTreeChildNodeDecl | resource tree child node declaration}.
127
+ * @public
128
+ */
129
+ export const resourceTreeChildNodeDecl = Converters.generic((from, self, context) => {
130
+ return Converters.strictObject({
131
+ resources: Converters.recordOf(childResourceDecl).optional(),
132
+ children: Converters.recordOf(self).optional()
133
+ }).convert(from, context);
134
+ });
135
+ /**
136
+ * `Converter` for a normalized {@link ResourceJson.Normalized.IResourceTreeRootDecl | resource tree root declaration}.
137
+ * @public
138
+ */
139
+ export const resourceTreeRootDecl = Converters.strictObject({
140
+ context: containerContextDecl.optional(),
141
+ resources: Converters.recordOf(childResourceDecl).optional(),
142
+ children: Converters.recordOf(resourceTreeChildNodeDecl).optional()
143
+ });
144
+ /**
145
+ * `Converter` for a normalized {@link ResourceJson.Normalized.IResourceCollectionDecl | resource collection declaration}.
146
+ * @public
147
+ */
148
+ export const resourceCollectionDecl = Converters.generic((from, self, context) => {
149
+ return Converters.strictObject({
150
+ context: containerContextDecl.optional(),
151
+ candidates: Converters.arrayOf(looseResourceCandidateDecl).optional(),
152
+ resources: Converters.arrayOf(looseResourceDecl).optional(),
153
+ collections: Converters.arrayOf(self).optional(),
154
+ metadata: JsonConverters.jsonObject.optional()
155
+ }).convert(from, context);
156
+ });
157
+ /**
158
+ * `Converter` for a normalized {@link ResourceJson.Normalized.IImporterResourceCollectionDecl | importer resource collection declaration}.
159
+ * This allows for a mix of loose and child resource declarations.
160
+ * @public
161
+ */
162
+ export const importerResourceCollectionDecl = Converters.generic((from, self, context) => {
163
+ return Converters.strictObject({
164
+ context: containerContextDecl.optional(),
165
+ candidates: Converters.arrayOf(importerResourceCandidateDecl).optional(),
166
+ resources: Converters.arrayOf(Converters.oneOf([looseResourceDecl, childResourceDecl])).optional(),
167
+ collections: Converters.arrayOf(self).optional(),
168
+ metadata: JsonConverters.jsonObject.optional()
169
+ }).convert(from, context);
170
+ });
171
+ //# sourceMappingURL=convert.js.map
@@ -0,0 +1,241 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ import { mapResults, fail, succeed } from '@fgv/ts-utils';
23
+ import * as Json from './json';
24
+ import { Helpers as CommonHelpers } from '../common';
25
+ import { sanitizeJsonObject } from '@fgv/ts-json-base';
26
+ /**
27
+ * Helper method to merge a resource context declaration with a parent name and conditions.
28
+ * @param decl - The resource context declaration to merge.
29
+ * @param parentName - The name of the parent resource.
30
+ * @param parentConditions - The conditions of the parent resource.
31
+ * @returns `Success` with the merged resource context declaration if successful, otherwise `Failure`.
32
+ * @public
33
+ */
34
+ export function mergeContextDecl(decl, parentName, parentConditions) {
35
+ var _a, _b, _c;
36
+ if (!decl) {
37
+ return sanitizeJsonObject({ baseId: parentName, conditions: parentConditions });
38
+ }
39
+ else if (!parentName && !parentConditions) {
40
+ return succeed(decl);
41
+ }
42
+ switch ((_a = decl.mergeMethod) !== null && _a !== void 0 ? _a : 'augment') {
43
+ case 'augment':
44
+ return CommonHelpers.joinResourceIds(parentName, decl.baseId).onSuccess((baseId) => {
45
+ var _a;
46
+ /* c8 ignore next 1 - defense in depth */
47
+ const conditions = [...(parentConditions !== null && parentConditions !== void 0 ? parentConditions : []), ...((_a = decl.conditions) !== null && _a !== void 0 ? _a : [])];
48
+ return sanitizeJsonObject({ baseId, conditions });
49
+ });
50
+ case 'replace': {
51
+ const baseId = (_b = decl.baseId) !== null && _b !== void 0 ? _b : parentName;
52
+ const conditions = (_c = decl.conditions) !== null && _c !== void 0 ? _c : parentConditions;
53
+ return sanitizeJsonObject({ baseId, conditions });
54
+ }
55
+ case 'delete': {
56
+ return sanitizeJsonObject({});
57
+ }
58
+ }
59
+ }
60
+ /**
61
+ * Helper method to merge a loose candidate with a base name and conditions.
62
+ * @param candidate - The candidate to merge.
63
+ * @param baseName - The base name to merge with the candidate.
64
+ * @param baseConditions - The base conditions to merge with the candidate.
65
+ * @returns `Success` with the merged candidate if successful, otherwise `Failure`.
66
+ * @public
67
+ */
68
+ export function mergeLooseCandidate(candidate, baseName, baseConditions) {
69
+ const candidateId = Json.isLooseResourceCandidateDecl(candidate) ? candidate.id : '';
70
+ if (!Json.isLooseResourceCandidateDecl(candidate) && !baseName) {
71
+ return fail('id is required in mergeLooseCandidate');
72
+ }
73
+ /* c8 ignore next 7 - functional code tested but coverage intermittently missed */
74
+ return CommonHelpers.joinResourceIds(baseName, candidateId).onSuccess((id) => {
75
+ var _a;
76
+ /* c8 ignore next 1 - defense in depth */
77
+ const conditions = [...(baseConditions !== null && baseConditions !== void 0 ? baseConditions : []), ...((_a = candidate.conditions) !== null && _a !== void 0 ? _a : [])];
78
+ return succeed(Object.assign(Object.assign({}, candidate), { id, conditions }));
79
+ });
80
+ }
81
+ /**
82
+ * Helper method to merge a resource candidate with a base name and conditions from import context.
83
+ * This function enables name inheritance for resource candidates, similar to resources.
84
+ *
85
+ * @param candidate - The candidate to merge. Can have an optional ID that will be joined with baseName.
86
+ * @param baseName - The base name from import context to merge with the candidate.
87
+ * When provided, this will be used as the parent component of the candidate ID.
88
+ * @param baseConditions - The base conditions from import context to merge with the candidate's conditions.
89
+ * @returns `Success` with the merged candidate if successful, otherwise `Failure`.
90
+ *
91
+ * @remarks
92
+ * This function supports name inheritance for candidates:
93
+ * - Joins baseName with candidate's existing ID using dot notation
94
+ * - If candidate has no ID, uses baseName as the full ID
95
+ * - Always merges base conditions with candidate's existing conditions
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * // Candidate inherits full name from import context
100
+ * const candidate = { value: "Hello", conditions: [...] }; // No id field
101
+ * const result = mergeImporterCandidate(candidate, "pages.home.greeting", []);
102
+ * // Result: { id: "pages.home.greeting", value: "Hello", conditions: [...] }
103
+ * ```
104
+ *
105
+ * @public
106
+ */
107
+ export function mergeImporterCandidate(candidate, baseName, baseConditions) {
108
+ var _a;
109
+ if (baseName || Json.isLooseResourceCandidateDecl(candidate)) {
110
+ const candidateId = 'id' in candidate ? candidate.id : '';
111
+ return CommonHelpers.joinResourceIds(baseName, candidateId).onSuccess((id) => {
112
+ var _a;
113
+ /* c8 ignore next 1 - defense in depth */
114
+ const conditions = [...(baseConditions !== null && baseConditions !== void 0 ? baseConditions : []), ...((_a = candidate.conditions) !== null && _a !== void 0 ? _a : [])];
115
+ return succeed(Object.assign(Object.assign({}, candidate), { id, conditions }));
116
+ });
117
+ }
118
+ else {
119
+ /* c8 ignore next 5 - functional code tested but coverage intermittently missed */
120
+ /* c8 ignore next 1 - defense in depth */
121
+ const conditions = [...(baseConditions !== null && baseConditions !== void 0 ? baseConditions : []), ...((_a = candidate.conditions) !== null && _a !== void 0 ? _a : [])];
122
+ return succeed(Object.assign(Object.assign({}, candidate), { conditions }));
123
+ }
124
+ }
125
+ /**
126
+ * Helper method to merge a child candidate with base conditions.
127
+ * @param candidate - The candidate to merge.
128
+ * @param baseConditions - The base conditions to merge with the candidate.
129
+ * @returns `Success` with the merged candidate if successful, otherwise `Failure`.
130
+ * @public
131
+ */
132
+ export function mergeChildCandidate(candidate, baseConditions) {
133
+ var _a;
134
+ /* c8 ignore next 1 - defense in depth */
135
+ const conditions = [...(baseConditions !== null && baseConditions !== void 0 ? baseConditions : []), ...((_a = candidate.conditions) !== null && _a !== void 0 ? _a : [])];
136
+ return succeed(Object.assign(Object.assign({}, candidate), { conditions }));
137
+ }
138
+ /**
139
+ * Helper method to merge a loose resource with a base name and conditions.
140
+ * @param resource - The resource to merge.
141
+ * @param baseName - The base name to merge with the resource.
142
+ * @param baseConditions - The base conditions to merge with the resource.
143
+ * @returns `Success` with the merged resource if successful, otherwise `Failure`.
144
+ * @public
145
+ */
146
+ export function mergeLooseResource(resource, baseName, baseConditions) {
147
+ /* c8 ignore next 1 - defense in depth */
148
+ const resourceId = Json.isLooseResourceDecl(resource) ? resource.id : '';
149
+ if (!baseName && !Json.isLooseResourceDecl(resource)) {
150
+ return fail('id is required in mergeLooseResource');
151
+ }
152
+ /* c8 ignore next 10 - functional code tested but coverage intermittently missed */
153
+ return CommonHelpers.joinResourceIds(baseName, resourceId).onSuccess((id) => {
154
+ var _a;
155
+ return mapResults(
156
+ /* c8 ignore next 1 - defense in depth */
157
+ ((_a = resource.candidates) !== null && _a !== void 0 ? _a : []).map((candidate) => mergeChildCandidate(candidate, baseConditions))).onSuccess((candidates) => {
158
+ return succeed(Object.assign(Object.assign({}, resource), { id, candidates }));
159
+ });
160
+ });
161
+ }
162
+ /**
163
+ * Helper method to merge a resource with a base name and conditions from import context.
164
+ * This function enables name inheritance where resources can automatically inherit their
165
+ * resource ID from the import context when no explicit ID is provided in the resource declaration.
166
+ *
167
+ * @param resource - The resource to merge. Can be either a loose resource (with optional ID)
168
+ * or a child resource (without ID).
169
+ * @param baseName - The base name from import context to merge with the resource.
170
+ * When provided, this will be used as the parent component of the resource ID.
171
+ * @param baseConditions - The base conditions from import context to merge with the resource's conditions.
172
+ * @returns `Success` with the merged resource if successful, otherwise `Failure`.
173
+ *
174
+ * @remarks
175
+ * This function supports several scenarios for name inheritance:
176
+ * - **Explicit ID + Base Name**: Joins baseName.resourceId (e.g., "pages.home" + "greeting" = "pages.home.greeting")
177
+ * - **No ID + Base Name**: Uses baseName as the resource ID (enables name inheritance from import context)
178
+ * - **Explicit ID + No Base Name**: Uses the resource's existing ID
179
+ * - **No ID + No Base Name**: Returns resource without ID (for child resources)
180
+ *
181
+ * Base conditions are always merged with the resource's existing conditions.
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * // Resource without ID inherits name from import context
186
+ * const resource = { candidates: [...] }; // No id field
187
+ * const result = mergeImporterResource(resource, "pages.home", []);
188
+ * // Result: { id: "pages.home", candidates: [...] }
189
+ *
190
+ * // Resource with ID gets joined with base name
191
+ * const resource = { id: "greeting", candidates: [...] };
192
+ * const result = mergeImporterResource(resource, "pages.home", []);
193
+ * // Result: { id: "pages.home.greeting", candidates: [...] }
194
+ * ```
195
+ *
196
+ * @public
197
+ */
198
+ export function mergeImporterResource(resource, baseName, baseConditions) {
199
+ var _a;
200
+ if (baseName || `id` in resource) {
201
+ const resourceId = 'id' in resource ? resource.id : '';
202
+ // If we have a base name or the resource has no id, we can just
203
+ return CommonHelpers.joinResourceIds(baseName, resourceId).onSuccess((id) => {
204
+ var _a;
205
+ return mapResults(
206
+ /* c8 ignore next 1 - defense in depth */
207
+ ((_a = resource.candidates) !== null && _a !== void 0 ? _a : []).map((candidate) => mergeChildCandidate(candidate, baseConditions))).onSuccess((candidates) => {
208
+ return succeed(Object.assign(Object.assign({}, resource), { id, candidates }));
209
+ });
210
+ });
211
+ }
212
+ else {
213
+ /* c8 ignore next 8 - functional code tested but coverage intermittently missed */
214
+ return mapResults(
215
+ /* c8 ignore next 1 - defense in depth */
216
+ ((_a = resource.candidates) !== null && _a !== void 0 ? _a : []).map((candidate) => mergeChildCandidate(candidate, baseConditions))).onSuccess((candidates) => {
217
+ return succeed(Object.assign(Object.assign({}, resource), { candidates }));
218
+ });
219
+ }
220
+ }
221
+ /**
222
+ * Helper method to merge a child resource with a parent name and conditions.
223
+ * @param resource - The resource to merge.
224
+ * @param name - The name of the resource.
225
+ *
226
+ * @param parentName - The name of the parent resource.
227
+ * @param parentConditions - The conditions of the parent resource.
228
+ * @returns `Success` with the merged resource if successful, otherwise `Failure`.
229
+ * @public
230
+ */
231
+ export function mergeChildResource(resource, name, parentName, parentConditions) {
232
+ return CommonHelpers.joinResourceIds(parentName, name).onSuccess((id) => {
233
+ var _a;
234
+ return mapResults(
235
+ /* c8 ignore next 1 - defense in depth */
236
+ ((_a = resource.candidates) !== null && _a !== void 0 ? _a : []).map((candidate) => mergeChildCandidate(candidate, parentConditions))).onSuccess((candidates) => {
237
+ return succeed(Object.assign(Object.assign({}, resource), { id, candidates }));
238
+ });
239
+ });
240
+ }
241
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ import * as Compiled from './compiled';
23
+ import * as Convert from './convert';
24
+ import * as Helpers from './helpers';
25
+ import * as Json from './json';
26
+ import * as Normalized from './normalized';
27
+ export { Compiled, Convert, Helpers, Json, Normalized };
28
+ export * from './resourceDeclContainer';
29
+ export * from './resourceDeclCollection';
30
+ export * from './resourceDeclTree';
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ /**
23
+ * Type guard function to check if a resource candidate declaration is a loose resource candidate declaration.
24
+ * @public
25
+ */
26
+ export function isLooseResourceCandidateDecl(decl) {
27
+ return 'id' in decl;
28
+ }
29
+ /**
30
+ * Type guard function to check if a resource declaration is a loose resource declaration.
31
+ * @public
32
+ */
33
+ export function isLooseResourceDecl(decl) {
34
+ return 'id' in decl;
35
+ }
36
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ export {};
23
+ //# sourceMappingURL=normalized.js.map
@@ -0,0 +1,88 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ import { captureResult, mapResults, MessageAggregator, succeed } from '@fgv/ts-utils';
23
+ import * as Convert from './convert';
24
+ import { mergeContextDecl, mergeImporterCandidate, mergeImporterResource } from './helpers';
25
+ /**
26
+ * Class that extracts resources and candidates from a
27
+ * {@link ResourceJson.Json.IResourceCollectionDecl | resource collection declaration}.
28
+ * @public
29
+ */
30
+ export class ResourceDeclCollection {
31
+ /**
32
+ * {@inheritdoc ResourceJson.IResourceDeclContainer.context}
33
+ */
34
+ get context() {
35
+ return this.collection.context;
36
+ }
37
+ constructor(collection) {
38
+ this._resources = [];
39
+ this._candidates = [];
40
+ this.collection = collection;
41
+ this._extract(collection).orThrow();
42
+ }
43
+ /**
44
+ * Creates a new {@link ResourceJson.ResourceDeclCollection | ResourceDeclCollection} from an
45
+ * untyped {@link ResourceJson.Json.IResourceCollectionDecl | resource collection declaration}.
46
+ * @param from - The JSON object to convert.
47
+ * @returns `Success` with the new collection if the JSON object is valid, otherwise `Failure`.
48
+ */
49
+ static create(from) {
50
+ return Convert.importerResourceCollectionDecl
51
+ .convert(from)
52
+ .withErrorFormat((err) => `Invalid resource collection: ${err}`)
53
+ .onSuccess((decl) => {
54
+ return captureResult(() => new ResourceDeclCollection(decl));
55
+ });
56
+ }
57
+ /**
58
+ * Gets the importer resources extracted from the collection.
59
+ * @returns The {@link ResourceJson.Normalized.IImporterResourceDecl | importer resource declarations}
60
+ * extracted from the collection.
61
+ */
62
+ getImporterResources() {
63
+ return this._resources;
64
+ }
65
+ /**
66
+ * Gets the importer candidates extracted from the collection.
67
+ * @returns The {@link ResourceJson.Normalized.IImporterResourceCandidateDecl | importer resource candidate declarations}
68
+ * extracted from the collection.
69
+ */
70
+ getImporterCandidates() {
71
+ return this._candidates;
72
+ }
73
+ _extract(collection, parentName, parentConditions) {
74
+ const errors = new MessageAggregator();
75
+ return mergeContextDecl(collection.context, parentName, parentConditions).onSuccess(({ baseId: baseName, conditions: baseConditions }) => {
76
+ var _a, _b, _c, _d, _e;
77
+ const mergedCandidates = (_b = (_a = collection.candidates) === null || _a === void 0 ? void 0 : _a.map((candidate) => mergeImporterCandidate(candidate, baseName, baseConditions))) !== null && _b !== void 0 ? _b : [];
78
+ this._candidates.push(...mapResults(mergedCandidates).aggregateError(errors).orDefault([]));
79
+ const mergedResources = (_d = (_c = collection.resources) === null || _c === void 0 ? void 0 : _c.map((resource) => mergeImporterResource(resource, baseName, baseConditions))) !== null && _d !== void 0 ? _d : [];
80
+ this._resources.push(...mapResults(mergedResources).aggregateError(errors).orDefault([]));
81
+ (_e = collection.collections) === null || _e === void 0 ? void 0 : _e.forEach((subCollection) => {
82
+ this._extract(subCollection, baseName, baseConditions).aggregateError(errors);
83
+ });
84
+ return errors.returnOrReport(succeed(this));
85
+ });
86
+ }
87
+ }
88
+ //# sourceMappingURL=resourceDeclCollection.js.map
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ export {};
23
+ //# sourceMappingURL=resourceDeclContainer.js.map