@fgv/ts-res-ui-components 5.0.0-10

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 (231) hide show
  1. package/.rush/temp/03c8b056281d9db0a97d8a6e25eea798a160d393.tar.log +271 -0
  2. package/.rush/temp/chunked-rush-logs/ts-res-ui-components.build.chunks.jsonl +9 -0
  3. package/.rush/temp/operation/build/all.log +9 -0
  4. package/.rush/temp/operation/build/log-chunks.jsonl +9 -0
  5. package/.rush/temp/operation/build/state.json +3 -0
  6. package/.rush/temp/shrinkwrap-deps.json +1111 -0
  7. package/README.md +18 -0
  8. package/REFACTORING_PLAN.md +171 -0
  9. package/config/jest.config.json +16 -0
  10. package/config/jest.setup.js +64 -0
  11. package/config/rig.json +16 -0
  12. package/lib/components/common/QualifierContextControl.d.ts +14 -0
  13. package/lib/components/common/QualifierContextControl.d.ts.map +1 -0
  14. package/lib/components/common/QualifierContextControl.js +78 -0
  15. package/lib/components/common/QualifierContextControl.js.map +1 -0
  16. package/lib/components/common/ResourceListView.d.ts +11 -0
  17. package/lib/components/common/ResourceListView.d.ts.map +1 -0
  18. package/lib/components/common/ResourceListView.js +20 -0
  19. package/lib/components/common/ResourceListView.js.map +1 -0
  20. package/lib/components/common/ResourceTreeView.d.ts +12 -0
  21. package/lib/components/common/ResourceTreeView.d.ts.map +1 -0
  22. package/lib/components/common/ResourceTreeView.js +162 -0
  23. package/lib/components/common/ResourceTreeView.js.map +1 -0
  24. package/lib/components/forms/HierarchyEditor.d.ts +10 -0
  25. package/lib/components/forms/HierarchyEditor.d.ts.map +1 -0
  26. package/lib/components/forms/HierarchyEditor.js +106 -0
  27. package/lib/components/forms/HierarchyEditor.js.map +1 -0
  28. package/lib/components/forms/QualifierEditForm.d.ts +11 -0
  29. package/lib/components/forms/QualifierEditForm.d.ts.map +1 -0
  30. package/lib/components/forms/QualifierEditForm.js +181 -0
  31. package/lib/components/forms/QualifierEditForm.js.map +1 -0
  32. package/lib/components/forms/QualifierTypeEditForm.d.ts +10 -0
  33. package/lib/components/forms/QualifierTypeEditForm.d.ts.map +1 -0
  34. package/lib/components/forms/QualifierTypeEditForm.js +172 -0
  35. package/lib/components/forms/QualifierTypeEditForm.js.map +1 -0
  36. package/lib/components/forms/ResourceTypeEditForm.d.ts +10 -0
  37. package/lib/components/forms/ResourceTypeEditForm.d.ts.map +1 -0
  38. package/lib/components/forms/ResourceTypeEditForm.js +188 -0
  39. package/lib/components/forms/ResourceTypeEditForm.js.map +1 -0
  40. package/lib/components/forms/index.d.ts +9 -0
  41. package/lib/components/forms/index.d.ts.map +1 -0
  42. package/lib/components/forms/index.js +5 -0
  43. package/lib/components/forms/index.js.map +1 -0
  44. package/lib/components/orchestrator/ResourceOrchestrator.d.ts +14 -0
  45. package/lib/components/orchestrator/ResourceOrchestrator.d.ts.map +1 -0
  46. package/lib/components/orchestrator/ResourceOrchestrator.js +278 -0
  47. package/lib/components/orchestrator/ResourceOrchestrator.js.map +1 -0
  48. package/lib/components/views/CompiledView/index.d.ts +5 -0
  49. package/lib/components/views/CompiledView/index.d.ts.map +1 -0
  50. package/lib/components/views/CompiledView/index.js +595 -0
  51. package/lib/components/views/CompiledView/index.js.map +1 -0
  52. package/lib/components/views/ConfigurationView/index.d.ts +5 -0
  53. package/lib/components/views/ConfigurationView/index.d.ts.map +1 -0
  54. package/lib/components/views/ConfigurationView/index.js +363 -0
  55. package/lib/components/views/ConfigurationView/index.js.map +1 -0
  56. package/lib/components/views/FilterView/index.d.ts +5 -0
  57. package/lib/components/views/FilterView/index.d.ts.map +1 -0
  58. package/lib/components/views/FilterView/index.js +463 -0
  59. package/lib/components/views/FilterView/index.js.map +1 -0
  60. package/lib/components/views/ImportView/index.d.ts +5 -0
  61. package/lib/components/views/ImportView/index.d.ts.map +1 -0
  62. package/lib/components/views/ImportView/index.js +514 -0
  63. package/lib/components/views/ImportView/index.js.map +1 -0
  64. package/lib/components/views/ResolutionView/EditableJsonView.d.ts +21 -0
  65. package/lib/components/views/ResolutionView/EditableJsonView.d.ts.map +1 -0
  66. package/lib/components/views/ResolutionView/EditableJsonView.js +109 -0
  67. package/lib/components/views/ResolutionView/EditableJsonView.js.map +1 -0
  68. package/lib/components/views/ResolutionView/ResolutionEditControls.d.ts +19 -0
  69. package/lib/components/views/ResolutionView/ResolutionEditControls.d.ts.map +1 -0
  70. package/lib/components/views/ResolutionView/ResolutionEditControls.js +82 -0
  71. package/lib/components/views/ResolutionView/ResolutionEditControls.js.map +1 -0
  72. package/lib/components/views/ResolutionView/index.d.ts +5 -0
  73. package/lib/components/views/ResolutionView/index.d.ts.map +1 -0
  74. package/lib/components/views/ResolutionView/index.js +255 -0
  75. package/lib/components/views/ResolutionView/index.js.map +1 -0
  76. package/lib/components/views/SourceView/index.d.ts +5 -0
  77. package/lib/components/views/SourceView/index.d.ts.map +1 -0
  78. package/lib/components/views/SourceView/index.js +316 -0
  79. package/lib/components/views/SourceView/index.js.map +1 -0
  80. package/lib/components/views/ZipLoaderView/index.d.ts +5 -0
  81. package/lib/components/views/ZipLoaderView/index.d.ts.map +1 -0
  82. package/lib/components/views/ZipLoaderView/index.js +313 -0
  83. package/lib/components/views/ZipLoaderView/index.js.map +1 -0
  84. package/lib/hooks/useConfigurationState.d.ts +46 -0
  85. package/lib/hooks/useConfigurationState.d.ts.map +1 -0
  86. package/lib/hooks/useConfigurationState.js +239 -0
  87. package/lib/hooks/useConfigurationState.js.map +1 -0
  88. package/lib/hooks/useFilterState.d.ts +7 -0
  89. package/lib/hooks/useFilterState.d.ts.map +1 -0
  90. package/lib/hooks/useFilterState.js +80 -0
  91. package/lib/hooks/useFilterState.js.map +1 -0
  92. package/lib/hooks/useResolutionState.d.ts +8 -0
  93. package/lib/hooks/useResolutionState.d.ts.map +1 -0
  94. package/lib/hooks/useResolutionState.js +253 -0
  95. package/lib/hooks/useResolutionState.js.map +1 -0
  96. package/lib/hooks/useResourceData.d.ts +19 -0
  97. package/lib/hooks/useResourceData.d.ts.map +1 -0
  98. package/lib/hooks/useResourceData.js +368 -0
  99. package/lib/hooks/useResourceData.js.map +1 -0
  100. package/lib/hooks/useViewState.d.ts +10 -0
  101. package/lib/hooks/useViewState.d.ts.map +1 -0
  102. package/lib/hooks/useViewState.js +29 -0
  103. package/lib/hooks/useViewState.js.map +1 -0
  104. package/lib/index.d.ts +27 -0
  105. package/lib/index.d.ts.map +1 -0
  106. package/lib/index.js +34 -0
  107. package/lib/index.js.map +1 -0
  108. package/lib/test/helpers/testDataLoader.d.ts +37 -0
  109. package/lib/test/helpers/testDataLoader.d.ts.map +1 -0
  110. package/lib/test/helpers/testDataLoader.js +171 -0
  111. package/lib/test/helpers/testDataLoader.js.map +1 -0
  112. package/lib/test/unit/utils/configurationUtils.test.d.ts +2 -0
  113. package/lib/test/unit/utils/configurationUtils.test.d.ts.map +1 -0
  114. package/lib/test/unit/utils/configurationUtils.test.js +497 -0
  115. package/lib/test/unit/utils/configurationUtils.test.js.map +1 -0
  116. package/lib/test/unit/utils/fileProcessing.test.d.ts +2 -0
  117. package/lib/test/unit/utils/fileProcessing.test.d.ts.map +1 -0
  118. package/lib/test/unit/utils/fileProcessing.test.js +321 -0
  119. package/lib/test/unit/utils/fileProcessing.test.js.map +1 -0
  120. package/lib/test/unit/utils/filterResources.test.d.ts +2 -0
  121. package/lib/test/unit/utils/filterResources.test.d.ts.map +1 -0
  122. package/lib/test/unit/utils/filterResources.test.js +403 -0
  123. package/lib/test/unit/utils/filterResources.test.js.map +1 -0
  124. package/lib/test/unit/utils/resolutionEditing.test.d.ts +2 -0
  125. package/lib/test/unit/utils/resolutionEditing.test.d.ts.map +1 -0
  126. package/lib/test/unit/utils/resolutionEditing.test.js +439 -0
  127. package/lib/test/unit/utils/resolutionEditing.test.js.map +1 -0
  128. package/lib/test/unit/utils/resolutionUtils.test.d.ts +2 -0
  129. package/lib/test/unit/utils/resolutionUtils.test.d.ts.map +1 -0
  130. package/lib/test/unit/utils/resolutionUtils.test.js +397 -0
  131. package/lib/test/unit/utils/resolutionUtils.test.js.map +1 -0
  132. package/lib/test/unit/utils/tsResIntegration.test.d.ts +2 -0
  133. package/lib/test/unit/utils/tsResIntegration.test.d.ts.map +1 -0
  134. package/lib/test/unit/utils/tsResIntegration.test.js +376 -0
  135. package/lib/test/unit/utils/tsResIntegration.test.js.map +1 -0
  136. package/lib/types/index.d.ts +251 -0
  137. package/lib/types/index.d.ts.map +1 -0
  138. package/lib/types/index.js +2 -0
  139. package/lib/types/index.js.map +1 -0
  140. package/lib/utils/configurationUtils.d.ts +74 -0
  141. package/lib/utils/configurationUtils.d.ts.map +1 -0
  142. package/lib/utils/configurationUtils.js +359 -0
  143. package/lib/utils/configurationUtils.js.map +1 -0
  144. package/lib/utils/fileProcessing.d.ts +18 -0
  145. package/lib/utils/fileProcessing.d.ts.map +1 -0
  146. package/lib/utils/fileProcessing.js +142 -0
  147. package/lib/utils/fileProcessing.js.map +1 -0
  148. package/lib/utils/filterResources.d.ts +38 -0
  149. package/lib/utils/filterResources.d.ts.map +1 -0
  150. package/lib/utils/filterResources.js +153 -0
  151. package/lib/utils/filterResources.js.map +1 -0
  152. package/lib/utils/resolutionEditing.d.ts +58 -0
  153. package/lib/utils/resolutionEditing.d.ts.map +1 -0
  154. package/lib/utils/resolutionEditing.js +246 -0
  155. package/lib/utils/resolutionEditing.js.map +1 -0
  156. package/lib/utils/resolutionUtils.d.ts +28 -0
  157. package/lib/utils/resolutionUtils.d.ts.map +1 -0
  158. package/lib/utils/resolutionUtils.js +216 -0
  159. package/lib/utils/resolutionUtils.js.map +1 -0
  160. package/lib/utils/tsResIntegration.d.ts +71 -0
  161. package/lib/utils/tsResIntegration.d.ts.map +1 -0
  162. package/lib/utils/tsResIntegration.js +294 -0
  163. package/lib/utils/tsResIntegration.js.map +1 -0
  164. package/lib/utils/zipLoader/browserZipLoader.d.ts +48 -0
  165. package/lib/utils/zipLoader/browserZipLoader.d.ts.map +1 -0
  166. package/lib/utils/zipLoader/browserZipLoader.js +247 -0
  167. package/lib/utils/zipLoader/browserZipLoader.js.map +1 -0
  168. package/lib/utils/zipLoader/index.d.ts +8 -0
  169. package/lib/utils/zipLoader/index.d.ts.map +1 -0
  170. package/lib/utils/zipLoader/index.js +13 -0
  171. package/lib/utils/zipLoader/index.js.map +1 -0
  172. package/lib/utils/zipLoader/nodeZipBuilder.d.ts +55 -0
  173. package/lib/utils/zipLoader/nodeZipBuilder.d.ts.map +1 -0
  174. package/lib/utils/zipLoader/nodeZipBuilder.js +98 -0
  175. package/lib/utils/zipLoader/nodeZipBuilder.js.map +1 -0
  176. package/lib/utils/zipLoader/types.d.ts +139 -0
  177. package/lib/utils/zipLoader/types.d.ts.map +1 -0
  178. package/lib/utils/zipLoader/types.js +2 -0
  179. package/lib/utils/zipLoader/types.js.map +1 -0
  180. package/lib/utils/zipLoader/zipUtils.d.ts +53 -0
  181. package/lib/utils/zipLoader/zipUtils.d.ts.map +1 -0
  182. package/lib/utils/zipLoader/zipUtils.js +229 -0
  183. package/lib/utils/zipLoader/zipUtils.js.map +1 -0
  184. package/package.json +69 -0
  185. package/rush-logs/ts-res-ui-components.build.cache.log +3 -0
  186. package/rush-logs/ts-res-ui-components.build.log +9 -0
  187. package/src/components/common/QualifierContextControl.tsx +151 -0
  188. package/src/components/common/ResourceListView.tsx +63 -0
  189. package/src/components/common/ResourceTreeView.tsx +271 -0
  190. package/src/components/forms/HierarchyEditor.tsx +204 -0
  191. package/src/components/forms/QualifierEditForm.tsx +355 -0
  192. package/src/components/forms/QualifierTypeEditForm.tsx +347 -0
  193. package/src/components/forms/ResourceTypeEditForm.tsx +331 -0
  194. package/src/components/forms/index.ts +11 -0
  195. package/src/components/orchestrator/ResourceOrchestrator.tsx +372 -0
  196. package/src/components/views/CompiledView/index.tsx +922 -0
  197. package/src/components/views/ConfigurationView/index.tsx +800 -0
  198. package/src/components/views/FilterView/index.tsx +825 -0
  199. package/src/components/views/ImportView/index.tsx +717 -0
  200. package/src/components/views/ResolutionView/EditableJsonView.tsx +214 -0
  201. package/src/components/views/ResolutionView/ResolutionEditControls.tsx +170 -0
  202. package/src/components/views/ResolutionView/index.tsx +591 -0
  203. package/src/components/views/SourceView/index.tsx +536 -0
  204. package/src/components/views/ZipLoaderView/index.tsx +485 -0
  205. package/src/hooks/useConfigurationState.ts +374 -0
  206. package/src/hooks/useFilterState.ts +97 -0
  207. package/src/hooks/useResolutionState.ts +355 -0
  208. package/src/hooks/useResourceData.ts +467 -0
  209. package/src/hooks/useViewState.ts +44 -0
  210. package/src/index.ts +45 -0
  211. package/src/test/helpers/testDataLoader.ts +195 -0
  212. package/src/test/unit/utils/configurationUtils.test.ts +630 -0
  213. package/src/test/unit/utils/fileProcessing.test.ts +391 -0
  214. package/src/test/unit/utils/filterResources.test.ts +574 -0
  215. package/src/test/unit/utils/resolutionEditing.test.ts +556 -0
  216. package/src/test/unit/utils/resolutionUtils.test.ts +521 -0
  217. package/src/test/unit/utils/tsResIntegration.test.ts +433 -0
  218. package/src/types/index.ts +322 -0
  219. package/src/utils/configurationUtils.ts +424 -0
  220. package/src/utils/fileProcessing.ts +160 -0
  221. package/src/utils/filterResources.ts +206 -0
  222. package/src/utils/resolutionEditing.ts +319 -0
  223. package/src/utils/resolutionUtils.ts +289 -0
  224. package/src/utils/tsResIntegration.ts +440 -0
  225. package/src/utils/zipLoader/browserZipLoader.ts +319 -0
  226. package/src/utils/zipLoader/index.ts +26 -0
  227. package/src/utils/zipLoader/nodeZipBuilder.ts +153 -0
  228. package/src/utils/zipLoader/types.ts +175 -0
  229. package/src/utils/zipLoader/zipUtils.ts +266 -0
  230. package/temp/build/typescript/ts_gZid87Hu.json +1 -0
  231. package/tsconfig.json +15 -0
@@ -0,0 +1,440 @@
1
+ import { Result, succeed, fail, FileTree } from '@fgv/ts-utils';
2
+ import {
3
+ QualifierTypes,
4
+ Qualifiers,
5
+ ResourceTypes,
6
+ Resources,
7
+ Import,
8
+ Runtime,
9
+ ResourceJson,
10
+ Config
11
+ } from '@fgv/ts-res';
12
+ import { ImportedDirectory, ImportedFile } from '../types';
13
+
14
+ /**
15
+ * Get the default system configuration from ts-res library
16
+ */
17
+ export function getDefaultSystemConfiguration(): Config.Model.ISystemConfiguration {
18
+ return Config.getPredefinedDeclaration('default').orDefault({
19
+ // Fallback configuration if predefined default is not available
20
+ name: 'Browser Default Configuration',
21
+ description: 'Fallback default configuration for ts-res browser tool',
22
+ qualifierTypes: [
23
+ {
24
+ name: 'language',
25
+ systemType: 'language',
26
+ configuration: {
27
+ allowContextList: true
28
+ }
29
+ },
30
+ {
31
+ name: 'territory',
32
+ systemType: 'territory',
33
+ configuration: {
34
+ allowContextList: false
35
+ }
36
+ }
37
+ ],
38
+ qualifiers: [
39
+ {
40
+ name: 'currentTerritory',
41
+ token: 'geo',
42
+ typeName: 'territory',
43
+ defaultPriority: 850
44
+ },
45
+ {
46
+ name: 'language',
47
+ token: 'lang',
48
+ typeName: 'language',
49
+ defaultPriority: 800
50
+ }
51
+ ],
52
+ resourceTypes: [
53
+ {
54
+ name: 'json',
55
+ typeName: 'json'
56
+ }
57
+ ]
58
+ });
59
+ }
60
+
61
+ /**
62
+ * Create a simple context provider from qualifier values
63
+ */
64
+ export function createSimpleContext(
65
+ qualifiers: Qualifiers.IReadOnlyQualifierCollector,
66
+ values: Record<string, string | undefined>
67
+ ): Result<Runtime.ValidatingSimpleContextQualifierProvider> {
68
+ return Runtime.ValidatingSimpleContextQualifierProvider.create({
69
+ qualifiers
70
+ }).withErrorFormat((e) => `Failed to create context: ${e}`);
71
+ }
72
+
73
+ /**
74
+ * Convert ImportedDirectory to FileTree format
75
+ */
76
+ export function convertImportedDirectoryToFileTree(directory: ImportedDirectory): FileTree.FileTree {
77
+ // Convert files to IInMemoryFile format and flatten the directory structure
78
+ const flattenFiles = (
79
+ dir: ImportedDirectory,
80
+ parentPath: string = ''
81
+ ): Array<{ path: string; contents: string }> => {
82
+ const files: Array<{ path: string; contents: string }> = [];
83
+
84
+ // Add files from current directory
85
+ if (dir.files) {
86
+ dir.files.forEach((file) => {
87
+ const filePath = parentPath ? `${parentPath}/${file.name}` : file.name;
88
+ files.push({
89
+ path: filePath,
90
+ contents: file.content
91
+ });
92
+ });
93
+ }
94
+
95
+ // Recursively process subdirectories
96
+ if (dir.subdirectories) {
97
+ dir.subdirectories.forEach((subdir) => {
98
+ const subdirPath = parentPath ? `${parentPath}/${subdir.name}` : subdir.name;
99
+ files.push(...flattenFiles(subdir, subdirPath));
100
+ });
101
+ }
102
+
103
+ return files;
104
+ };
105
+
106
+ const inMemoryFiles = flattenFiles(directory);
107
+
108
+ console.log('[convertImportedDirectoryToFileTree] Converting directory to FileTree:', {
109
+ directoryName: directory.name,
110
+ directoryPath: directory.path,
111
+ numFiles: directory.files?.length || 0,
112
+ numSubdirs: directory.subdirectories?.length || 0,
113
+ totalFlattenedFiles: inMemoryFiles.length,
114
+ sampleFiles: inMemoryFiles.slice(0, 3).map((f) => f.path)
115
+ });
116
+
117
+ // Use ts-res's inMemory FileTree utility
118
+ return FileTree.inMemory(inMemoryFiles).orThrow((msg) => `Failed to create file tree: ${msg}`);
119
+ }
120
+
121
+ /**
122
+ * Create ts-res system from configuration
123
+ */
124
+ export function createTsResSystemFromConfig(systemConfig?: Config.Model.ISystemConfiguration): Result<{
125
+ qualifierTypes: QualifierTypes.ReadOnlyQualifierTypeCollector;
126
+ qualifiers: Qualifiers.IReadOnlyQualifierCollector;
127
+ resourceTypes: ResourceTypes.ReadOnlyResourceTypeCollector;
128
+ resourceManager: Resources.ResourceManagerBuilder;
129
+ importManager: Import.ImportManager;
130
+ contextQualifierProvider: Runtime.ValidatingSimpleContextQualifierProvider;
131
+ }> {
132
+ const configToUse = systemConfig ?? getDefaultSystemConfiguration();
133
+
134
+ return Config.SystemConfiguration.create(configToUse)
135
+ .onSuccess((systemConfiguration) => {
136
+ return Resources.ResourceManagerBuilder.create({
137
+ qualifiers: systemConfiguration.qualifiers,
138
+ resourceTypes: systemConfiguration.resourceTypes
139
+ })
140
+ .withErrorFormat((e) => `Failed to create resource manager: ${e}`)
141
+ .onSuccess((resourceManager) => {
142
+ return Import.ImportManager.create({
143
+ resources: resourceManager
144
+ })
145
+ .withErrorFormat((e) => `Failed to create import manager: ${e}`)
146
+ .onSuccess((importManager) => {
147
+ return Runtime.ValidatingSimpleContextQualifierProvider.create({
148
+ qualifiers: systemConfiguration.qualifiers
149
+ })
150
+ .withErrorFormat((e) => `Failed to create context qualifier provider: ${e}`)
151
+ .onSuccess((contextQualifierProvider) => {
152
+ return succeed({
153
+ qualifierTypes: systemConfiguration.qualifierTypes,
154
+ qualifiers: systemConfiguration.qualifiers,
155
+ resourceTypes: systemConfiguration.resourceTypes,
156
+ resourceManager,
157
+ importManager,
158
+ contextQualifierProvider
159
+ });
160
+ });
161
+ });
162
+ });
163
+ })
164
+ .withErrorFormat((e) => `Failed to create ts-res system: ${e}`);
165
+ }
166
+
167
+ /**
168
+ * Process imported files using the ts-res system
169
+ */
170
+ export function processImportedFiles(
171
+ files: ImportedFile[],
172
+ systemConfig?: Config.Model.ISystemConfiguration
173
+ ): Result<{
174
+ system: {
175
+ qualifierTypes: QualifierTypes.ReadOnlyQualifierTypeCollector;
176
+ qualifiers: Qualifiers.IReadOnlyQualifierCollector;
177
+ resourceTypes: ResourceTypes.ReadOnlyResourceTypeCollector;
178
+ resourceManager: Resources.ResourceManagerBuilder;
179
+ importManager: Import.ImportManager;
180
+ contextQualifierProvider: Runtime.ValidatingSimpleContextQualifierProvider;
181
+ };
182
+ compiledCollection: ResourceJson.Compiled.ICompiledResourceCollection;
183
+ resolver: Runtime.ResourceResolver;
184
+ resourceCount: number;
185
+ summary: {
186
+ totalResources: number;
187
+ resourceIds: string[];
188
+ errorCount: number;
189
+ warnings: string[];
190
+ };
191
+ }> {
192
+ if (files.length === 0) {
193
+ return fail('No files provided for processing');
194
+ }
195
+
196
+ return createTsResSystemFromConfig(systemConfig)
197
+ .onSuccess<{
198
+ system: {
199
+ qualifierTypes: QualifierTypes.ReadOnlyQualifierTypeCollector;
200
+ qualifiers: Qualifiers.IReadOnlyQualifierCollector;
201
+ resourceTypes: ResourceTypes.ReadOnlyResourceTypeCollector;
202
+ resourceManager: Resources.ResourceManagerBuilder;
203
+ importManager: Import.ImportManager;
204
+ contextQualifierProvider: Runtime.ValidatingSimpleContextQualifierProvider;
205
+ };
206
+ compiledCollection: ResourceJson.Compiled.ICompiledResourceCollection;
207
+ resolver: Runtime.ResourceResolver;
208
+ resourceCount: number;
209
+ summary: {
210
+ totalResources: number;
211
+ resourceIds: string[];
212
+ errorCount: number;
213
+ warnings: string[];
214
+ };
215
+ }>((tsResSystem) => {
216
+ // Convert ImportedFile[] to IInMemoryFile[] format
217
+ const inMemoryFiles = files.map((file) => ({
218
+ path: file.path || file.name,
219
+ contents: file.content
220
+ }));
221
+
222
+ return FileTree.inMemory(inMemoryFiles)
223
+ .onSuccess((fileTree) => {
224
+ return Import.ImportManager.create({
225
+ fileTree,
226
+ resources: tsResSystem.resourceManager
227
+ });
228
+ })
229
+ .onSuccess((importManager) => {
230
+ // Import each file using its filesystem path
231
+ for (const file of files) {
232
+ const importResult = importManager.importFromFileSystem(file.path || file.name);
233
+ if (importResult.isFailure()) {
234
+ return fail(`Failed to import file ${file.path || file.name}: ${importResult.message}`);
235
+ }
236
+ }
237
+
238
+ // Finalize processing
239
+ const updatedSystem = {
240
+ ...tsResSystem,
241
+ importManager
242
+ };
243
+ return finalizeProcessing(updatedSystem);
244
+ });
245
+ })
246
+ .withErrorFormat((message) => `processImportedFiles failed: ${message}`);
247
+ }
248
+
249
+ /**
250
+ * Process imported directory using the ts-res system
251
+ */
252
+ export function processImportedDirectory(
253
+ directory: ImportedDirectory,
254
+ systemConfig?: Config.Model.ISystemConfiguration
255
+ ): Result<{
256
+ system: {
257
+ qualifierTypes: QualifierTypes.ReadOnlyQualifierTypeCollector;
258
+ qualifiers: Qualifiers.IReadOnlyQualifierCollector;
259
+ resourceTypes: ResourceTypes.ReadOnlyResourceTypeCollector;
260
+ resourceManager: Resources.ResourceManagerBuilder;
261
+ importManager: Import.ImportManager;
262
+ contextQualifierProvider: Runtime.ValidatingSimpleContextQualifierProvider;
263
+ };
264
+ compiledCollection: ResourceJson.Compiled.ICompiledResourceCollection;
265
+ resolver: Runtime.ResourceResolver;
266
+ resourceCount: number;
267
+ summary: {
268
+ totalResources: number;
269
+ resourceIds: string[];
270
+ errorCount: number;
271
+ warnings: string[];
272
+ };
273
+ }> {
274
+ return createTsResSystemFromConfig(systemConfig)
275
+ .onSuccess<{
276
+ system: {
277
+ qualifierTypes: QualifierTypes.ReadOnlyQualifierTypeCollector;
278
+ qualifiers: Qualifiers.IReadOnlyQualifierCollector;
279
+ resourceTypes: ResourceTypes.ReadOnlyResourceTypeCollector;
280
+ resourceManager: Resources.ResourceManagerBuilder;
281
+ importManager: Import.ImportManager;
282
+ contextQualifierProvider: Runtime.ValidatingSimpleContextQualifierProvider;
283
+ };
284
+ compiledCollection: ResourceJson.Compiled.ICompiledResourceCollection;
285
+ resolver: Runtime.ResourceResolver;
286
+ resourceCount: number;
287
+ summary: {
288
+ totalResources: number;
289
+ resourceIds: string[];
290
+ errorCount: number;
291
+ warnings: string[];
292
+ };
293
+ }>((tsResSystem) => {
294
+ // Convert directory to file tree
295
+ const fileTree = convertImportedDirectoryToFileTree(directory);
296
+
297
+ return Import.ImportManager.create({
298
+ fileTree,
299
+ resources: tsResSystem.resourceManager
300
+ }).onSuccess((importManager) => {
301
+ // Simply try to import from the filesystem root
302
+ // The ImportManager will handle finding and importing all resources
303
+ console.log('[tsResIntegration] Starting resource import from FileTree');
304
+
305
+ const importResult = importManager.importFromFileSystem('/');
306
+ if (importResult.isFailure()) {
307
+ console.warn(`[tsResIntegration] Failed to import from root, trying individual files`);
308
+
309
+ // If root import fails, try to import files individually
310
+ // We'll recursively traverse the tree using the FileTree API
311
+ let importedCount = 0;
312
+ const failedImports: Array<{ file: string; error: string }> = [];
313
+
314
+ const importDirectory = (dirPath: string): void => {
315
+ const dirResult = fileTree.getDirectory(dirPath);
316
+ if (dirResult.isSuccess()) {
317
+ const dir = dirResult.value;
318
+ const childrenResult = dir.getChildren();
319
+ if (childrenResult.isSuccess()) {
320
+ for (const child of childrenResult.value) {
321
+ if (child.type === 'file' && child.name.endsWith('.json')) {
322
+ console.log(`[tsResIntegration] Importing file: ${child.absolutePath}`);
323
+ const fileImportResult = importManager.importFromFileSystem(child.absolutePath);
324
+ if (fileImportResult.isSuccess()) {
325
+ importedCount++;
326
+ console.log(`[tsResIntegration] Successfully imported ${child.absolutePath}`);
327
+ } else {
328
+ console.warn(
329
+ `[tsResIntegration] Failed to import ${child.absolutePath}: ${fileImportResult.message}`
330
+ );
331
+ failedImports.push({ file: child.absolutePath, error: fileImportResult.message });
332
+ }
333
+ } else if (child.type === 'directory') {
334
+ importDirectory(child.absolutePath);
335
+ }
336
+ }
337
+ }
338
+ }
339
+ };
340
+
341
+ // Start from root
342
+ importDirectory('/');
343
+
344
+ // Also try without leading slash
345
+ if (importedCount === 0) {
346
+ importDirectory('');
347
+ }
348
+
349
+ console.log(`[tsResIntegration] Import complete. Imported ${importedCount} files`);
350
+
351
+ if (importedCount === 0 && failedImports.length > 0) {
352
+ // Create a summary of unique errors
353
+ const errorSummary = new Map<string, string[]>();
354
+ failedImports.forEach(({ file, error }) => {
355
+ // Extract the main error (e.g., "invalid item: role: not found")
356
+ const mainError = error.split('\n')[0];
357
+ if (!errorSummary.has(mainError)) {
358
+ errorSummary.set(mainError, []);
359
+ }
360
+ errorSummary.get(mainError)!.push(file);
361
+ });
362
+
363
+ let errorMessage = `Failed to import resources. Missing qualifiers in configuration:\n`;
364
+ errorSummary.forEach((files, error) => {
365
+ errorMessage += `- ${error} (${files.length} file${files.length > 1 ? 's' : ''})\n`;
366
+ });
367
+
368
+ return fail(errorMessage);
369
+ } else if (importedCount === 0) {
370
+ return fail(`No resource files found in ${directory.name}`);
371
+ }
372
+ } else {
373
+ console.log('[tsResIntegration] Successfully imported resources from root');
374
+ }
375
+
376
+ // Finalize processing
377
+ const updatedSystem = {
378
+ ...tsResSystem,
379
+ importManager
380
+ };
381
+ return finalizeProcessing(updatedSystem);
382
+ });
383
+ })
384
+ .withErrorFormat((message) => `processImportedDirectory failed: ${message}`);
385
+ }
386
+
387
+ /**
388
+ * Finalizes processing and creates compiled resources
389
+ */
390
+ function finalizeProcessing(system: {
391
+ qualifierTypes: QualifierTypes.ReadOnlyQualifierTypeCollector;
392
+ qualifiers: Qualifiers.IReadOnlyQualifierCollector;
393
+ resourceTypes: ResourceTypes.ReadOnlyResourceTypeCollector;
394
+ resourceManager: Resources.ResourceManagerBuilder;
395
+ importManager: Import.ImportManager;
396
+ contextQualifierProvider: Runtime.ValidatingSimpleContextQualifierProvider;
397
+ }): Result<{
398
+ system: typeof system;
399
+ compiledCollection: ResourceJson.Compiled.ICompiledResourceCollection;
400
+ resolver: Runtime.ResourceResolver;
401
+ resourceCount: number;
402
+ summary: {
403
+ totalResources: number;
404
+ resourceIds: string[];
405
+ errorCount: number;
406
+ warnings: string[];
407
+ };
408
+ }> {
409
+ return system.resourceManager
410
+ .getCompiledResourceCollection({ includeMetadata: true })
411
+ .onSuccess((compiledCollection: ResourceJson.Compiled.ICompiledResourceCollection) => {
412
+ // Create resolver directly without CompiledResourceCollection manager
413
+ return Runtime.ResourceResolver.create({
414
+ resourceManager: system.resourceManager,
415
+ qualifierTypes: system.qualifierTypes,
416
+ contextQualifierProvider: system.contextQualifierProvider
417
+ }).onSuccess((resolver) => {
418
+ // Create summary
419
+ const resourceIds = Array.from(system.resourceManager.resources.keys());
420
+ const summary = {
421
+ totalResources: resourceIds.length,
422
+ resourceIds,
423
+ errorCount: 0,
424
+ warnings: [] as string[]
425
+ };
426
+
427
+ return succeed({
428
+ system,
429
+ compiledCollection,
430
+ resolver,
431
+ resourceCount: resourceIds.length,
432
+ summary
433
+ });
434
+ });
435
+ })
436
+ .withErrorFormat((message) => `Failed to finalize processing: ${message}`);
437
+ }
438
+
439
+ // Note: createCompiledResourceCollectionManager was removed as part of the refactoring
440
+ // We now always use ResourceManagerBuilder as the primary data structure