@digitaldefiance/i18n-lib 1.3.13 → 1.3.14

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 (243) hide show
  1. package/README.md +4 -0
  2. package/package.json +4 -3
  3. package/src/active-context.d.ts +30 -0
  4. package/src/active-context.d.ts.map +1 -0
  5. package/src/active-context.js +3 -0
  6. package/src/active-context.js.map +1 -0
  7. package/src/component-definition.d.ts +12 -0
  8. package/src/component-definition.d.ts.map +1 -0
  9. package/src/component-definition.js +3 -0
  10. package/src/component-definition.js.map +1 -0
  11. package/src/component-registration.d.ts +10 -0
  12. package/src/component-registration.d.ts.map +1 -0
  13. package/src/component-registration.js +3 -0
  14. package/src/component-registration.js.map +1 -0
  15. package/src/component-registry.d.ts +69 -0
  16. package/src/component-registry.d.ts.map +1 -0
  17. package/src/component-registry.js +248 -0
  18. package/src/component-registry.js.map +1 -0
  19. package/src/context-error-type.d.ts +4 -0
  20. package/src/context-error-type.d.ts.map +1 -0
  21. package/src/context-error-type.js +8 -0
  22. package/src/context-error-type.js.map +1 -0
  23. package/src/context-error.d.ts +7 -0
  24. package/src/context-error.d.ts.map +1 -0
  25. package/src/context-error.js +18 -0
  26. package/src/context-error.js.map +1 -0
  27. package/src/context-manager.d.ts +34 -0
  28. package/src/context-manager.d.ts.map +1 -0
  29. package/src/context-manager.js +60 -0
  30. package/src/context-manager.js.map +1 -0
  31. package/src/context.d.ts +45 -0
  32. package/src/context.d.ts.map +1 -0
  33. package/src/context.js +70 -0
  34. package/src/context.js.map +1 -0
  35. package/src/core-i18n.d.ts +63 -0
  36. package/src/core-i18n.d.ts.map +1 -0
  37. package/src/core-i18n.js +478 -0
  38. package/src/core-i18n.js.map +1 -0
  39. package/src/core-string-key.d.ts +43 -0
  40. package/src/core-string-key.d.ts.map +1 -0
  41. package/src/core-string-key.js +51 -0
  42. package/src/core-string-key.js.map +1 -0
  43. package/src/create-translation-adapter.d.ts +21 -0
  44. package/src/create-translation-adapter.d.ts.map +1 -0
  45. package/src/create-translation-adapter.js +37 -0
  46. package/src/create-translation-adapter.js.map +1 -0
  47. package/src/currency-code.d.ts +20 -0
  48. package/src/currency-code.d.ts.map +1 -0
  49. package/src/currency-code.js +37 -0
  50. package/src/currency-code.js.map +1 -0
  51. package/src/{currency-format.ts → currency-format.d.ts} +5 -5
  52. package/src/currency-format.d.ts.map +1 -0
  53. package/src/currency-format.js +3 -0
  54. package/src/currency-format.js.map +1 -0
  55. package/src/currency.d.ts +12 -0
  56. package/src/currency.d.ts.map +1 -0
  57. package/src/currency.js +49 -0
  58. package/src/currency.js.map +1 -0
  59. package/src/default-config.d.ts +33 -0
  60. package/src/default-config.d.ts.map +1 -0
  61. package/src/default-config.js +102 -0
  62. package/src/default-config.js.map +1 -0
  63. package/src/enum-registry.d.ts +45 -0
  64. package/src/enum-registry.d.ts.map +1 -0
  65. package/src/enum-registry.js +103 -0
  66. package/src/enum-registry.js.map +1 -0
  67. package/src/global-active-context.d.ts +51 -0
  68. package/src/global-active-context.d.ts.map +1 -0
  69. package/src/global-active-context.js +179 -0
  70. package/src/global-active-context.js.map +1 -0
  71. package/src/handleable.d.ts +14 -0
  72. package/src/handleable.d.ts.map +1 -0
  73. package/src/handleable.js +66 -0
  74. package/src/handleable.js.map +1 -0
  75. package/src/i-global-active-context.d.ts +23 -0
  76. package/src/i-global-active-context.d.ts.map +1 -0
  77. package/src/i-global-active-context.js +3 -0
  78. package/src/i-global-active-context.js.map +1 -0
  79. package/src/i-handleable-error-options.d.ts +7 -0
  80. package/src/i-handleable-error-options.d.ts.map +1 -0
  81. package/src/i-handleable-error-options.js +3 -0
  82. package/src/i-handleable-error-options.js.map +1 -0
  83. package/src/i-handleable.d.ts +6 -0
  84. package/src/i-handleable.d.ts.map +1 -0
  85. package/src/i-handleable.js +3 -0
  86. package/src/i-handleable.js.map +1 -0
  87. package/src/i18n-config.d.ts +21 -0
  88. package/src/i18n-config.d.ts.map +1 -0
  89. package/src/i18n-config.js +3 -0
  90. package/src/i18n-config.js.map +1 -0
  91. package/src/{i18n-context.ts → i18n-context.d.ts} +7 -7
  92. package/src/i18n-context.d.ts.map +1 -0
  93. package/src/i18n-context.js +3 -0
  94. package/src/i18n-context.js.map +1 -0
  95. package/src/i18n-engine.d.ts +179 -0
  96. package/src/i18n-engine.d.ts.map +1 -0
  97. package/src/i18n-engine.js +355 -0
  98. package/src/i18n-engine.js.map +1 -0
  99. package/src/{index.ts → index.d.ts} +2 -10
  100. package/src/index.d.ts.map +1 -0
  101. package/src/index.js +71 -0
  102. package/src/index.js.map +1 -0
  103. package/src/{language-codes.ts → language-codes.d.ts} +12 -23
  104. package/src/language-codes.d.ts.map +1 -0
  105. package/src/language-codes.js +32 -0
  106. package/src/language-codes.js.map +1 -0
  107. package/src/language-definition.d.ts +14 -0
  108. package/src/language-definition.d.ts.map +1 -0
  109. package/src/language-definition.js +3 -0
  110. package/src/language-definition.js.map +1 -0
  111. package/src/language-registry.d.ts +114 -0
  112. package/src/language-registry.d.ts.map +1 -0
  113. package/src/language-registry.js +217 -0
  114. package/src/language-registry.js.map +1 -0
  115. package/src/plugin-i18n-engine.d.ts +147 -0
  116. package/src/plugin-i18n-engine.d.ts.map +1 -0
  117. package/src/plugin-i18n-engine.js +369 -0
  118. package/src/plugin-i18n-engine.js.map +1 -0
  119. package/src/plugin-translatable-generic-error.d.ts +30 -0
  120. package/src/plugin-translatable-generic-error.d.ts.map +1 -0
  121. package/src/plugin-translatable-generic-error.js +72 -0
  122. package/src/plugin-translatable-generic-error.js.map +1 -0
  123. package/src/plugin-translatable-handleable-generic.d.ts +29 -0
  124. package/src/plugin-translatable-handleable-generic.d.ts.map +1 -0
  125. package/src/plugin-translatable-handleable-generic.js +44 -0
  126. package/src/plugin-translatable-handleable-generic.js.map +1 -0
  127. package/src/plugin-typed-handleable.d.ts +15 -0
  128. package/src/plugin-typed-handleable.d.ts.map +1 -0
  129. package/src/plugin-typed-handleable.js +51 -0
  130. package/src/plugin-typed-handleable.js.map +1 -0
  131. package/src/registry-config.d.ts +15 -0
  132. package/src/registry-config.d.ts.map +1 -0
  133. package/src/registry-config.js +3 -0
  134. package/src/registry-config.js.map +1 -0
  135. package/src/registry-error-type.d.ts +13 -0
  136. package/src/registry-error-type.d.ts.map +1 -0
  137. package/src/registry-error-type.js +17 -0
  138. package/src/registry-error-type.js.map +1 -0
  139. package/src/registry-error.d.ts +19 -0
  140. package/src/registry-error.d.ts.map +1 -0
  141. package/src/registry-error.js +48 -0
  142. package/src/registry-error.js.map +1 -0
  143. package/src/strict-types.d.ts +19 -0
  144. package/src/strict-types.d.ts.map +1 -0
  145. package/src/strict-types.js +18 -0
  146. package/src/strict-types.js.map +1 -0
  147. package/src/template.d.ts +13 -0
  148. package/src/template.d.ts.map +1 -0
  149. package/src/template.js +31 -0
  150. package/src/template.js.map +1 -0
  151. package/src/timezone.d.ts +12 -0
  152. package/src/timezone.d.ts.map +1 -0
  153. package/src/timezone.js +24 -0
  154. package/src/timezone.js.map +1 -0
  155. package/src/translatable.d.ts +6 -0
  156. package/src/translatable.d.ts.map +1 -0
  157. package/src/translatable.js +12 -0
  158. package/src/translatable.js.map +1 -0
  159. package/src/translation-engine.d.ts +9 -0
  160. package/src/translation-engine.d.ts.map +1 -0
  161. package/src/translation-engine.js +3 -0
  162. package/src/translation-engine.js.map +1 -0
  163. package/src/translation-request.d.ts +10 -0
  164. package/src/translation-request.d.ts.map +1 -0
  165. package/src/translation-request.js +3 -0
  166. package/src/translation-request.js.map +1 -0
  167. package/src/translation-response.d.ts +9 -0
  168. package/src/translation-response.d.ts.map +1 -0
  169. package/src/translation-response.js +3 -0
  170. package/src/translation-response.js.map +1 -0
  171. package/src/typed-error.d.ts +73 -0
  172. package/src/typed-error.d.ts.map +1 -0
  173. package/src/typed-error.js +267 -0
  174. package/src/typed-error.js.map +1 -0
  175. package/src/typed-handleable.d.ts +15 -0
  176. package/src/typed-handleable.d.ts.map +1 -0
  177. package/src/typed-handleable.js +46 -0
  178. package/src/typed-handleable.js.map +1 -0
  179. package/src/{types.ts → types.d.ts} +21 -75
  180. package/src/types.d.ts.map +1 -0
  181. package/src/types.js +19 -0
  182. package/src/types.js.map +1 -0
  183. package/src/unified-translator.d.ts +31 -0
  184. package/src/unified-translator.d.ts.map +1 -0
  185. package/src/unified-translator.js +71 -0
  186. package/src/unified-translator.js.map +1 -0
  187. package/src/utils.d.ts +65 -0
  188. package/src/utils.d.ts.map +1 -0
  189. package/src/utils.js +129 -0
  190. package/src/utils.js.map +1 -0
  191. package/src/validation-config.d.ts +12 -0
  192. package/src/validation-config.d.ts.map +1 -0
  193. package/src/validation-config.js +3 -0
  194. package/src/validation-config.js.map +1 -0
  195. package/src/validation-result.d.ts +13 -0
  196. package/src/validation-result.d.ts.map +1 -0
  197. package/src/validation-result.js +3 -0
  198. package/src/validation-result.js.map +1 -0
  199. package/LICENSE +0 -21
  200. package/src/active-context.ts +0 -30
  201. package/src/component-definition.ts +0 -11
  202. package/src/component-registration.ts +0 -13
  203. package/src/component-registry.ts +0 -392
  204. package/src/context-error-type.ts +0 -3
  205. package/src/context-error.ts +0 -16
  206. package/src/context-manager.ts +0 -71
  207. package/src/context.ts +0 -90
  208. package/src/core-i18n.ts +0 -609
  209. package/src/core-string-key.ts +0 -49
  210. package/src/create-translation-adapter.ts +0 -47
  211. package/src/currency-code.ts +0 -35
  212. package/src/currency.ts +0 -52
  213. package/src/default-config.ts +0 -199
  214. package/src/enum-registry.ts +0 -138
  215. package/src/global-active-context.ts +0 -255
  216. package/src/handleable.ts +0 -79
  217. package/src/i-global-active-context.ts +0 -59
  218. package/src/i-handleable-error-options.ts +0 -6
  219. package/src/i-handleable.ts +0 -5
  220. package/src/i18n-config.ts +0 -29
  221. package/src/i18n-engine.ts +0 -491
  222. package/src/language-definition.ts +0 -13
  223. package/src/language-registry.ts +0 -292
  224. package/src/plugin-i18n-engine.ts +0 -520
  225. package/src/plugin-translatable-generic-error.ts +0 -106
  226. package/src/plugin-translatable-handleable-generic.ts +0 -60
  227. package/src/plugin-typed-handleable.ts +0 -77
  228. package/src/registry-config.ts +0 -15
  229. package/src/registry-error-type.ts +0 -12
  230. package/src/registry-error.ts +0 -74
  231. package/src/strict-types.ts +0 -35
  232. package/src/template.ts +0 -63
  233. package/src/timezone.ts +0 -20
  234. package/src/translatable.ts +0 -15
  235. package/src/translation-engine.ts +0 -8
  236. package/src/translation-request.ts +0 -12
  237. package/src/translation-response.ts +0 -8
  238. package/src/typed-error.ts +0 -384
  239. package/src/typed-handleable.ts +0 -70
  240. package/src/unified-translator.ts +0 -96
  241. package/src/utils.ts +0 -213
  242. package/src/validation-config.ts +0 -11
  243. package/src/validation-result.ts +0 -12
package/README.md CHANGED
@@ -2274,6 +2274,10 @@ For issues, questions, or contributions:
2274
2274
 
2275
2275
  ## ChangeLog
2276
2276
 
2277
+ ### Version 1.3.14
2278
+
2279
+ - Re-export with js again
2280
+
2277
2281
  ### Version 1.3.13
2278
2282
 
2279
2283
  - Migrate to es2022/nx monorepo
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/i18n-lib",
3
- "version": "1.3.13",
3
+ "version": "1.3.14",
4
4
  "description": "i18n library with enum translation support",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -33,5 +33,6 @@
33
33
  "dependencies": {
34
34
  "moment": "^2.30.1",
35
35
  "moment-timezone": "^0.6.0"
36
- }
37
- }
36
+ },
37
+ "type": "commonjs"
38
+ }
@@ -0,0 +1,30 @@
1
+ import { CurrencyCode } from './currency-code';
2
+ import { Timezone } from './timezone';
3
+ import { LanguageContextSpace } from './types';
4
+ export interface IActiveContext<TLanguage extends string> {
5
+ /**
6
+ * The default language for the user facing application
7
+ */
8
+ language: TLanguage;
9
+ /**
10
+ * The default language for the admin interface
11
+ */
12
+ adminLanguage: TLanguage;
13
+ /**
14
+ * The default currency code for the user facing application
15
+ */
16
+ currencyCode: CurrencyCode;
17
+ /**
18
+ * The default language context for the current context
19
+ */
20
+ currentContext: LanguageContextSpace;
21
+ /**
22
+ * The default timezone for the user facing application
23
+ */
24
+ timezone: Timezone;
25
+ /**
26
+ * The default timezone for the admin interface
27
+ */
28
+ adminTimezone: Timezone;
29
+ }
30
+ //# sourceMappingURL=active-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"active-context.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/active-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,WAAW,cAAc,CAAC,SAAS,SAAS,MAAM;IACtD;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IACpB;;OAEG;IACH,aAAa,EAAE,SAAS,CAAC;IACzB;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;IAC3B;;OAEG;IACH,cAAc,EAAE,oBAAoB,CAAC;IACrC;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;IACnB;;OAEG;IACH,aAAa,EAAE,QAAQ,CAAC;CACzB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=active-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"active-context.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/active-context.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Component definition with its string keys
3
+ */
4
+ export interface ComponentDefinition<TStringKeys extends string> {
5
+ /** Unique identifier for the component */
6
+ readonly id: string;
7
+ /** Human-readable name for the component */
8
+ readonly name: string;
9
+ /** Array of all string keys this component requires */
10
+ readonly stringKeys: readonly TStringKeys[];
11
+ }
12
+ //# sourceMappingURL=component-definition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-definition.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/component-definition.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,WAAW,SAAS,MAAM;IAC7D,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,4CAA4C;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,QAAQ,CAAC,UAAU,EAAE,SAAS,WAAW,EAAE,CAAC;CAC7C"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=component-definition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-definition.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/component-definition.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { ComponentDefinition } from './component-definition';
2
+ import { PartialComponentLanguageStrings } from './types';
3
+ /**
4
+ * Registration payload for a component with its strings
5
+ */
6
+ export interface ComponentRegistration<TStringKeys extends string, TLanguages extends string> {
7
+ readonly component: ComponentDefinition<TStringKeys>;
8
+ readonly strings: PartialComponentLanguageStrings<TStringKeys, TLanguages>;
9
+ }
10
+ //# sourceMappingURL=component-registration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-registration.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/component-registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,qBAAqB,CACpC,WAAW,SAAS,MAAM,EAC1B,UAAU,SAAS,MAAM;IAEzB,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACrD,QAAQ,CAAC,OAAO,EAAE,+BAA+B,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;CAC5E"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=component-registration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-registration.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/component-registration.ts"],"names":[],"mappings":""}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Component registry for managing internationalization components and their string translations
3
+ */
4
+ import { ComponentDefinition } from './component-definition';
5
+ import { ComponentRegistration } from './component-registration';
6
+ import { TranslationRequest } from './translation-request';
7
+ import { TranslationResponse } from './translation-response';
8
+ import { ComponentLanguageStrings, PartialComponentLanguageStrings } from './types';
9
+ import { ValidationConfig } from './validation-config';
10
+ import { ValidationResult } from './validation-result';
11
+ /**
12
+ * Registry for managing components and their translations
13
+ */
14
+ export declare class ComponentRegistry<TLanguages extends string> {
15
+ private readonly components;
16
+ private readonly componentStrings;
17
+ private readonly validationConfig;
18
+ private readonly registeredLanguages;
19
+ constructor(languages: readonly TLanguages[], validationConfig: ValidationConfig);
20
+ /**
21
+ * Update the set of registered languages (for dynamic language addition)
22
+ */
23
+ updateRegisteredLanguages(languages: readonly TLanguages[]): void;
24
+ /**
25
+ * Register a new component with its translations
26
+ */
27
+ registerComponent<TStringKeys extends string>(registration: ComponentRegistration<TStringKeys, TLanguages>): ValidationResult;
28
+ /**
29
+ * Update strings for an existing component
30
+ */
31
+ updateComponentStrings<TStringKeys extends string>(componentId: string, strings: PartialComponentLanguageStrings<TStringKeys, TLanguages>): ValidationResult;
32
+ /**
33
+ * Get a translation for a specific component, string key, and language
34
+ */
35
+ getTranslation<TStringKeys extends string>(request: TranslationRequest<TStringKeys, TLanguages>): TranslationResponse;
36
+ /**
37
+ * Get all registered components
38
+ */
39
+ getComponents(): ReadonlyArray<ComponentDefinition<any>>;
40
+ /**
41
+ * Get a specific component by ID
42
+ */
43
+ getComponent<TStringKeys extends string>(componentId: string): ComponentDefinition<TStringKeys> | undefined;
44
+ /**
45
+ * Check if a component is registered
46
+ */
47
+ hasComponent(componentId: string): boolean;
48
+ /**
49
+ * Get all strings for a component in all languages
50
+ */
51
+ getComponentStrings<TStringKeys extends string>(componentId: string): ComponentLanguageStrings<TStringKeys, TLanguages> | undefined;
52
+ /**
53
+ * Validate a component registration
54
+ */
55
+ private validateComponentRegistration;
56
+ /**
57
+ * Complete missing strings with fallbacks
58
+ */
59
+ private completeStringsWithFallbacks;
60
+ /**
61
+ * Merge existing strings with new strings
62
+ */
63
+ private mergeStrings;
64
+ /**
65
+ * Clear all components and their strings (useful for testing)
66
+ */
67
+ clearAllComponents(): void;
68
+ }
69
+ //# sourceMappingURL=component-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-registry.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/component-registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAGjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EACL,wBAAwB,EAExB,+BAA+B,EAEhC,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;GAEG;AACH,qBAAa,iBAAiB,CAAC,UAAU,SAAS,MAAM;IACtD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA+C;IAC1E,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAG7B;IACJ,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAmB;IACpD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAkB;gBAGpD,SAAS,EAAE,SAAS,UAAU,EAAE,EAChC,gBAAgB,EAAE,gBAAgB;IAMpC;;OAEG;IACI,yBAAyB,CAAC,SAAS,EAAE,SAAS,UAAU,EAAE,GAAG,IAAI;IAKxE;;OAEG;IACI,iBAAiB,CAAC,WAAW,SAAS,MAAM,EACjD,YAAY,EAAE,qBAAqB,CAAC,WAAW,EAAE,UAAU,CAAC,GAC3D,gBAAgB;IA6CnB;;OAEG;IACI,sBAAsB,CAAC,WAAW,SAAS,MAAM,EACtD,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,+BAA+B,CAAC,WAAW,EAAE,UAAU,CAAC,GAChE,gBAAgB;IAoCnB;;OAEG;IACI,cAAc,CAAC,WAAW,SAAS,MAAM,EAC9C,OAAO,EAAE,kBAAkB,CAAC,WAAW,EAAE,UAAU,CAAC,GACnD,mBAAmB;IAwEtB;;OAEG;IACI,aAAa,IAAI,aAAa,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAI/D;;OAEG;IACI,YAAY,CAAC,WAAW,SAAS,MAAM,EAC5C,WAAW,EAAE,MAAM,GAClB,mBAAmB,CAAC,WAAW,CAAC,GAAG,SAAS;IAM/C;;OAEG;IACI,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAIjD;;OAEG;IACI,mBAAmB,CAAC,WAAW,SAAS,MAAM,EACnD,WAAW,EAAE,MAAM,GAClB,wBAAwB,CAAC,WAAW,EAAE,UAAU,CAAC,GAAG,SAAS;IAMhE;;OAEG;IACH,OAAO,CAAC,6BAA6B;IAyDrC;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAkCpC;;OAEG;IACH,OAAO,CAAC,YAAY;IA+BpB;;OAEG;IACI,kBAAkB,IAAI,IAAI;CAIlC"}
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ /**
3
+ * Component registry for managing internationalization components and their string translations
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ComponentRegistry = void 0;
7
+ const registry_error_1 = require("./registry-error");
8
+ const registry_error_type_1 = require("./registry-error-type");
9
+ const utils_1 = require("./utils");
10
+ /**
11
+ * Registry for managing components and their translations
12
+ */
13
+ class ComponentRegistry {
14
+ components = new Map();
15
+ componentStrings = new Map();
16
+ validationConfig;
17
+ registeredLanguages;
18
+ constructor(languages, validationConfig) {
19
+ this.registeredLanguages = new Set(languages);
20
+ this.validationConfig = validationConfig;
21
+ }
22
+ /**
23
+ * Update the set of registered languages (for dynamic language addition)
24
+ */
25
+ updateRegisteredLanguages(languages) {
26
+ this.registeredLanguages.clear();
27
+ languages.forEach((lang) => this.registeredLanguages.add(lang));
28
+ }
29
+ /**
30
+ * Register a new component with its translations
31
+ */
32
+ registerComponent(registration) {
33
+ const { component, strings } = registration;
34
+ // Check for duplicate component
35
+ if (this.components.has(component.id)) {
36
+ throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.DuplicateComponent, `Component '${component.id}' is already registered`, { componentId: component.id });
37
+ }
38
+ // Validate the registration
39
+ const validationResult = this.validateComponentRegistration(registration);
40
+ if (!validationResult.isValid &&
41
+ !this.validationConfig.allowPartialRegistration) {
42
+ throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.ValidationFailed, `Component registration validation failed: ${validationResult.errors.join(', ')}`, {
43
+ componentId: component.id,
44
+ missingKeys: validationResult.missingKeys,
45
+ errors: validationResult.errors,
46
+ });
47
+ }
48
+ // Complete missing strings with fallbacks if partial registration is allowed
49
+ const completeStrings = this.completeStringsWithFallbacks(component, strings);
50
+ // Register the component
51
+ this.components.set(component.id, component);
52
+ this.componentStrings.set(component.id, completeStrings);
53
+ return validationResult;
54
+ }
55
+ /**
56
+ * Update strings for an existing component
57
+ */
58
+ updateComponentStrings(componentId, strings) {
59
+ const component = this.components.get(componentId);
60
+ if (!component) {
61
+ throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.ComponentNotFound, `Component with ID '${componentId}' not found`, { componentId });
62
+ }
63
+ const registration = {
64
+ component: component,
65
+ strings,
66
+ };
67
+ const validationResult = this.validateComponentRegistration(registration);
68
+ if (validationResult.isValid ||
69
+ this.validationConfig.allowPartialRegistration) {
70
+ const existingStrings = this.componentStrings.get(componentId) ||
71
+ {};
72
+ const updatedStrings = this.mergeStrings(existingStrings, strings);
73
+ const completeStrings = this.completeStringsWithFallbacks(component, updatedStrings);
74
+ this.componentStrings.set(componentId, completeStrings);
75
+ }
76
+ return validationResult;
77
+ }
78
+ /**
79
+ * Get a translation for a specific component, string key, and language
80
+ */
81
+ getTranslation(request) {
82
+ const { componentId, stringKey, language, variables } = request;
83
+ // Check if component exists
84
+ if (!this.components.has(componentId)) {
85
+ throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.ComponentNotFound, `Component '${componentId}' not found`, { componentId });
86
+ }
87
+ const componentStrings = this.componentStrings.get(componentId);
88
+ if (!componentStrings) {
89
+ throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.StringKeyNotFound, `No strings registered for component '${componentId}'`, { componentId });
90
+ }
91
+ const targetLanguage = language || this.validationConfig.fallbackLanguageId;
92
+ let actualLanguage = targetLanguage;
93
+ let wasFallback = false;
94
+ // Try to get the string in the requested language
95
+ let languageStrings = componentStrings[targetLanguage];
96
+ // If not found and different from fallback, try fallback language
97
+ if (!languageStrings &&
98
+ targetLanguage !== this.validationConfig.fallbackLanguageId) {
99
+ languageStrings =
100
+ componentStrings[this.validationConfig.fallbackLanguageId];
101
+ actualLanguage = this.validationConfig.fallbackLanguageId;
102
+ wasFallback = true;
103
+ }
104
+ if (!languageStrings) {
105
+ throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.LanguageNotFound, `No strings found for language '${targetLanguage}' in component '${componentId}'`, { componentId, language: targetLanguage });
106
+ }
107
+ const translation = languageStrings[stringKey];
108
+ if (!translation) {
109
+ throw registry_error_1.RegistryError.createSimple(registry_error_type_1.RegistryErrorType.StringKeyNotFound, `String key '${stringKey}' not found for component '${componentId}' in language '${actualLanguage}'`, { componentId, stringKey, language: actualLanguage });
110
+ }
111
+ // Process variables if the string key indicates it's a template
112
+ let processedTranslation = translation;
113
+ if (variables && (0, utils_1.isTemplate)(stringKey)) {
114
+ processedTranslation = (0, utils_1.replaceVariables)(translation, variables);
115
+ }
116
+ return {
117
+ translation: processedTranslation,
118
+ actualLanguage,
119
+ wasFallback,
120
+ };
121
+ }
122
+ /**
123
+ * Get all registered components
124
+ */
125
+ getComponents() {
126
+ return Array.from(this.components.values());
127
+ }
128
+ /**
129
+ * Get a specific component by ID
130
+ */
131
+ getComponent(componentId) {
132
+ return this.components.get(componentId);
133
+ }
134
+ /**
135
+ * Check if a component is registered
136
+ */
137
+ hasComponent(componentId) {
138
+ return this.components.has(componentId);
139
+ }
140
+ /**
141
+ * Get all strings for a component in all languages
142
+ */
143
+ getComponentStrings(componentId) {
144
+ return this.componentStrings.get(componentId);
145
+ }
146
+ /**
147
+ * Validate a component registration
148
+ */
149
+ validateComponentRegistration(registration) {
150
+ const { component, strings } = registration;
151
+ const missingKeys = [];
152
+ const errors = [];
153
+ // Check if all required string keys are provided for each language
154
+ for (const languageId of this.registeredLanguages) {
155
+ const languageStrings = strings[languageId];
156
+ if (!languageStrings) {
157
+ if (this.validationConfig.requireCompleteStrings) {
158
+ errors.push(`Missing all strings for language '${languageId}' in component '${component.id}'`);
159
+ }
160
+ // Add all missing keys for this language
161
+ for (const stringKey of component.stringKeys) {
162
+ missingKeys.push({
163
+ languageId,
164
+ componentId: component.id,
165
+ stringKey,
166
+ });
167
+ }
168
+ continue;
169
+ }
170
+ // Check individual string keys
171
+ for (const stringKey of component.stringKeys) {
172
+ if (!languageStrings[stringKey]) {
173
+ missingKeys.push({
174
+ languageId,
175
+ componentId: component.id,
176
+ stringKey,
177
+ });
178
+ if (this.validationConfig.requireCompleteStrings) {
179
+ errors.push(`Missing string key '${stringKey}' for language '${languageId}' in component '${component.id}'`);
180
+ }
181
+ }
182
+ }
183
+ }
184
+ return {
185
+ isValid: missingKeys.length === 0,
186
+ missingKeys,
187
+ errors,
188
+ };
189
+ }
190
+ /**
191
+ * Complete missing strings with fallbacks
192
+ */
193
+ completeStringsWithFallbacks(component, strings) {
194
+ const result = {};
195
+ const fallbackLanguage = this.validationConfig
196
+ .fallbackLanguageId;
197
+ const fallbackStrings = strings[fallbackLanguage];
198
+ // Ensure all languages have all required keys
199
+ for (const languageId of this.registeredLanguages) {
200
+ const existingLanguageStrings = strings[languageId] || {};
201
+ const languageStrings = {};
202
+ for (const stringKey of component.stringKeys) {
203
+ if (existingLanguageStrings[stringKey]) {
204
+ languageStrings[stringKey] = existingLanguageStrings[stringKey];
205
+ }
206
+ else if (fallbackStrings && fallbackStrings[stringKey]) {
207
+ // Try to use fallback language
208
+ languageStrings[stringKey] = fallbackStrings[stringKey];
209
+ }
210
+ else {
211
+ // Last resort: use a placeholder
212
+ languageStrings[stringKey] = `[${component.id}.${stringKey}]`;
213
+ }
214
+ }
215
+ result[languageId] = languageStrings;
216
+ }
217
+ return result;
218
+ }
219
+ /**
220
+ * Merge existing strings with new strings
221
+ */
222
+ mergeStrings(existing, updates) {
223
+ const result = {};
224
+ // Copy existing strings
225
+ for (const [languageId, languageStrings] of Object.entries(existing)) {
226
+ result[languageId] = { ...languageStrings };
227
+ }
228
+ // Apply updates
229
+ for (const [languageId, languageStrings] of Object.entries(updates)) {
230
+ if (languageStrings) {
231
+ result[languageId] = {
232
+ ...result[languageId],
233
+ ...languageStrings,
234
+ };
235
+ }
236
+ }
237
+ return result;
238
+ }
239
+ /**
240
+ * Clear all components and their strings (useful for testing)
241
+ */
242
+ clearAllComponents() {
243
+ this.components.clear();
244
+ this.componentStrings.clear();
245
+ }
246
+ }
247
+ exports.ComponentRegistry = ComponentRegistry;
248
+ //# sourceMappingURL=component-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-registry.js","sourceRoot":"","sources":["../../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YAAY,CAClB,QAA2D,EAC3D,OAAiE;QAEjE,MAAM,MAAM,GACV,EAAE,CAAC;QAEL,wBAAwB;QACxB,KAAK,MAAM,CAAC,UAAU,EAAE,eAAe,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAGhE,EAAE,CAAC;YACJ,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,eAAe,EAAE,CAAC;QAC9C,CAAC;QAED,gBAAgB;QAChB,KAAK,MAAM,CAAC,UAAU,EAAE,eAAe,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAG/D,EAAE,CAAC;YACJ,IAAI,eAAe,EAAE,CAAC;gBACpB,MAAM,CAAC,UAAU,CAAC,GAAG;oBACnB,GAAG,MAAM,CAAC,UAAU,CAAC;oBACrB,GAAG,eAAe;iBACnB,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,kBAAkB;QACvB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACF;AAhXD,8CAgXC"}
@@ -0,0 +1,4 @@
1
+ export declare enum ContextErrorType {
2
+ InvalidContext = "InvalidContext"
3
+ }
4
+ //# sourceMappingURL=context-error-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-error-type.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/context-error-type.ts"],"names":[],"mappings":"AAAA,oBAAY,gBAAgB;IAC1B,cAAc,mBAAmB;CAClC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContextErrorType = void 0;
4
+ var ContextErrorType;
5
+ (function (ContextErrorType) {
6
+ ContextErrorType["InvalidContext"] = "InvalidContext";
7
+ })(ContextErrorType || (exports.ContextErrorType = ContextErrorType = {}));
8
+ //# sourceMappingURL=context-error-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-error-type.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/context-error-type.ts"],"names":[],"mappings":";;;AAAA,IAAY,gBAEX;AAFD,WAAY,gBAAgB;IAC1B,qDAAiC,CAAA;AACnC,CAAC,EAFW,gBAAgB,gCAAhB,gBAAgB,QAE3B"}
@@ -0,0 +1,7 @@
1
+ import { ContextErrorType } from './context-error-type';
2
+ export declare class ContextError extends Error {
3
+ readonly type: ContextErrorType;
4
+ readonly contextKey?: string;
5
+ constructor(type: ContextErrorType, contextKey?: string);
6
+ }
7
+ //# sourceMappingURL=context-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-error.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/context-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAE,gBAAgB,CAAC;IACvC,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;gBAExB,IAAI,EAAE,gBAAgB,EAAE,UAAU,CAAC,EAAE,MAAM;CASxD"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContextError = void 0;
4
+ class ContextError extends Error {
5
+ type;
6
+ contextKey;
7
+ constructor(type, contextKey) {
8
+ const message = contextKey
9
+ ? `Invalid context: ${contextKey}`
10
+ : 'Invalid context';
11
+ super(message);
12
+ this.name = 'ContextError';
13
+ this.type = type;
14
+ this.contextKey = contextKey;
15
+ }
16
+ }
17
+ exports.ContextError = ContextError;
18
+ //# sourceMappingURL=context-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-error.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/context-error.ts"],"names":[],"mappings":";;;AAEA,MAAa,YAAa,SAAQ,KAAK;IACrB,IAAI,CAAmB;IACvB,UAAU,CAAU;IAEpC,YAAY,IAAsB,EAAE,UAAmB;QACrD,MAAM,OAAO,GAAG,UAAU;YACxB,CAAC,CAAC,oBAAoB,UAAU,EAAE;YAClC,CAAC,CAAC,iBAAiB,CAAC;QACtB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAbD,oCAaC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Context change management for i18n systems
3
+ */
4
+ export type ContextChangeListener<T = any> = (property: string, oldValue: T, newValue: T) => void;
5
+ /**
6
+ * Manages context changes and notifies listeners.
7
+ */
8
+ export declare class ContextManager<TContext extends Record<string, any>> {
9
+ protected listeners: ContextChangeListener[];
10
+ /**
11
+ * Adds a listener to be notified of context changes.
12
+ * @param listener - The listener function to add
13
+ */
14
+ addListener(listener: ContextChangeListener): void;
15
+ /**
16
+ * Removes a listener from the notification list.
17
+ * @param listener - The listener function to remove
18
+ */
19
+ removeListener(listener: ContextChangeListener): void;
20
+ /**
21
+ * Notifies all listeners of a context change.
22
+ * @param property - The property that changed
23
+ * @param oldValue - The old value of the property
24
+ * @param newValue - The new value of the property
25
+ */
26
+ notifyChange<K extends keyof TContext>(property: K, oldValue: TContext[K], newValue: TContext[K]): void;
27
+ /**
28
+ * Creates a proxy for the given context to automatically notify listeners on changes.
29
+ * @param context - The context object to proxy
30
+ * @returns A proxied version of the context object
31
+ */
32
+ createProxy(context: TContext): TContext;
33
+ }
34
+ //# sourceMappingURL=context-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-manager.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/context-manager.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,GAAG,IAAI,CAC3C,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,CAAC,EACX,QAAQ,EAAE,CAAC,KACR,IAAI,CAAC;AAEV;;GAEG;AACH,qBAAa,cAAc,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAC9D,SAAS,CAAC,SAAS,EAAE,qBAAqB,EAAE,CAAM;IAElD;;;OAGG;IACI,WAAW,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI;IAIzD;;;OAGG;IACI,cAAc,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI;IAO5D;;;;;OAKG;IACI,YAAY,CAAC,CAAC,SAAS,MAAM,QAAQ,EAC1C,QAAQ,EAAE,CAAC,EACX,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GACpB,IAAI;IAUP;;;;OAIG;IACI,WAAW,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ;CAWhD"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContextManager = void 0;
4
+ /**
5
+ * Manages context changes and notifies listeners.
6
+ */
7
+ class ContextManager {
8
+ listeners = [];
9
+ /**
10
+ * Adds a listener to be notified of context changes.
11
+ * @param listener - The listener function to add
12
+ */
13
+ addListener(listener) {
14
+ this.listeners.push(listener);
15
+ }
16
+ /**
17
+ * Removes a listener from the notification list.
18
+ * @param listener - The listener function to remove
19
+ */
20
+ removeListener(listener) {
21
+ const index = this.listeners.indexOf(listener);
22
+ if (index > -1) {
23
+ this.listeners.splice(index, 1);
24
+ }
25
+ }
26
+ /**
27
+ * Notifies all listeners of a context change.
28
+ * @param property - The property that changed
29
+ * @param oldValue - The old value of the property
30
+ * @param newValue - The new value of the property
31
+ */
32
+ notifyChange(property, oldValue, newValue) {
33
+ this.listeners.forEach((listener) => {
34
+ try {
35
+ listener(property, oldValue, newValue);
36
+ }
37
+ catch (error) {
38
+ console.error('Error in context change listener:', error);
39
+ }
40
+ });
41
+ }
42
+ /**
43
+ * Creates a proxy for the given context to automatically notify listeners on changes.
44
+ * @param context - The context object to proxy
45
+ * @returns A proxied version of the context object
46
+ */
47
+ createProxy(context) {
48
+ const manager = this;
49
+ return new Proxy(context, {
50
+ set(target, property, value) {
51
+ const oldValue = target[property];
52
+ target[property] = value;
53
+ manager.notifyChange(property, oldValue, value);
54
+ return true;
55
+ },
56
+ });
57
+ }
58
+ }
59
+ exports.ContextManager = ContextManager;
60
+ //# sourceMappingURL=context-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-manager.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-i18n-lib/src/context-manager.ts"],"names":[],"mappings":";;;AASA;;GAEG;AACH,MAAa,cAAc;IACf,SAAS,GAA4B,EAAE,CAAC;IAElD;;;OAGG;IACI,WAAW,CAAC,QAA+B;QAChD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED;;;OAGG;IACI,cAAc,CAAC,QAA+B;QACnD,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;YACf,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,YAAY,CACjB,QAAW,EACX,QAAqB,EACrB,QAAqB;QAErB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAClC,IAAI,CAAC;gBACH,QAAQ,CAAC,QAAkB,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACnD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,mCA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