@digitaldefiance/i18n-lib 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -721,6 +721,52 @@ yarn test enum-registry.spec.ts
721
721
  yarn test i18n-engine.spec.ts
722
722
  ```
723
723
 
724
+ ### Test Cleanup and Instance Management
725
+
726
+ For proper test isolation when using the plugin-based architecture, use the cleanup utilities:
727
+
728
+ ```typescript
729
+ import { PluginI18nEngine, resetAllI18nEngines } from '@digitaldefiance/i18n-lib';
730
+
731
+ describe('My tests', () => {
732
+ beforeEach(() => {
733
+ // Clean up any existing instances before each test
734
+ PluginI18nEngine.clearAllInstances();
735
+ });
736
+
737
+ afterEach(() => {
738
+ // Or use the convenience function
739
+ resetAllI18nEngines();
740
+ });
741
+
742
+ // Or use specific cleanup methods
743
+ it('should manage instances', () => {
744
+ const engine1 = PluginI18nEngine.createInstance('app1', [englishLang]);
745
+ const engine2 = PluginI18nEngine.createInstance('app2', [frenchLang]);
746
+
747
+ // Check if instances exist
748
+ expect(PluginI18nEngine.hasInstance('app1')).toBe(true);
749
+ expect(PluginI18nEngine.hasInstance('app2')).toBe(true);
750
+
751
+ // Remove specific instance
752
+ PluginI18nEngine.removeInstance('app1');
753
+ expect(PluginI18nEngine.hasInstance('app1')).toBe(false);
754
+
755
+ // Clear all instances and component registrations
756
+ PluginI18nEngine.resetAll();
757
+ expect(PluginI18nEngine.hasInstance('app2')).toBe(false);
758
+ });
759
+ });
760
+ ```
761
+
762
+ #### Available Cleanup Methods
763
+
764
+ - `PluginI18nEngine.clearAllInstances()` - Remove all engine instances
765
+ - `PluginI18nEngine.removeInstance(key?)` - Remove specific instance by key
766
+ - `PluginI18nEngine.hasInstance(key?)` - Check if instance exists
767
+ - `PluginI18nEngine.resetAll()` - Clear instances and component registrations
768
+ - `resetAllI18nEngines()` - Convenience function that calls `resetAll()`
769
+
724
770
  ## Extensible Configuration
725
771
 
726
772
  The library supports layered extension across multiple libraries using TypeScript module augmentation:
@@ -890,6 +936,11 @@ Part of the DigitalBurnbag project - a secure file sharing and automated protoco
890
936
 
891
937
  ## ChangeLog
892
938
 
939
+ ### Version 1.1.2
940
+
941
+ - Sat Oct 11 2025 19:25:00 GMT-0700 (Pacific Daylight Time)
942
+ - Added cleanup mechanisms for other modules to deregister, etc.
943
+
893
944
  ### Version 1.1.1
894
945
 
895
946
  - Sat Oct 11 2025 17:47:00 GMT-0700 (Pacific Daylight Time)
@@ -61,4 +61,8 @@ export declare class ComponentRegistry<TLanguages extends string> {
61
61
  * Merge existing strings with new strings
62
62
  */
63
63
  private mergeStrings;
64
+ /**
65
+ * Clear all components and their strings (useful for testing)
66
+ */
67
+ clearAllComponents(): void;
64
68
  }
@@ -234,5 +234,12 @@ class ComponentRegistry {
234
234
  }
235
235
  return result;
236
236
  }
237
+ /**
238
+ * Clear all components and their strings (useful for testing)
239
+ */
240
+ clearAllComponents() {
241
+ this.components.clear();
242
+ this.componentStrings.clear();
243
+ }
237
244
  }
238
245
  exports.ComponentRegistry = ComponentRegistry;
package/dist/index.d.ts CHANGED
@@ -33,3 +33,8 @@ export * from './translation-response';
33
33
  export { createCoreI18nEngine as createCoreI18n } from './core-i18n';
34
34
  export { I18nEngine as I18n } from './i18n-engine';
35
35
  export { PluginI18nEngine as PluginI18n } from './plugin-i18n-engine';
36
+ /**
37
+ * Reset all I18n engines and clear component registrations
38
+ * Useful for test cleanup
39
+ */
40
+ export declare function resetAllI18nEngines(): void;
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.PluginI18n = exports.I18n = exports.createCoreI18n = void 0;
18
+ exports.resetAllI18nEngines = resetAllI18nEngines;
18
19
  // Legacy exports (for backwards compatibility)
19
20
  __exportStar(require("./active-context"), exports);
20
21
  __exportStar(require("./component-definition"), exports);
@@ -55,3 +56,12 @@ var i18n_engine_1 = require("./i18n-engine");
55
56
  Object.defineProperty(exports, "I18n", { enumerable: true, get: function () { return i18n_engine_1.I18nEngine; } });
56
57
  var plugin_i18n_engine_1 = require("./plugin-i18n-engine");
57
58
  Object.defineProperty(exports, "PluginI18n", { enumerable: true, get: function () { return plugin_i18n_engine_1.PluginI18nEngine; } });
59
+ // Testing utilities
60
+ const plugin_i18n_engine_2 = require("./plugin-i18n-engine");
61
+ /**
62
+ * Reset all I18n engines and clear component registrations
63
+ * Useful for test cleanup
64
+ */
65
+ function resetAllI18nEngines() {
66
+ plugin_i18n_engine_2.PluginI18nEngine.resetAll();
67
+ }
@@ -123,4 +123,25 @@ export declare class PluginI18nEngine<TLanguages extends string> {
123
123
  errors: string[];
124
124
  warnings: string[];
125
125
  };
126
+ /**
127
+ * Clear all component registrations for this instance (useful for testing)
128
+ */
129
+ clearAllComponents(): void;
130
+ /**
131
+ * Clear all named instances (useful for testing)
132
+ */
133
+ static clearAllInstances(): void;
134
+ /**
135
+ * Remove a specific named instance
136
+ */
137
+ static removeInstance(key?: string): boolean;
138
+ /**
139
+ * Check if an instance exists
140
+ */
141
+ static hasInstance(key?: string): boolean;
142
+ /**
143
+ * Reset all plugin engines and clear component registrations
144
+ * Useful for test cleanup
145
+ */
146
+ static resetAll(): void;
126
147
  }
@@ -49,6 +49,11 @@ class PluginI18nEngine {
49
49
  timezone: this.config.timezone,
50
50
  adminTimezone: this.config.adminTimezone,
51
51
  };
52
+ // Auto-register as default instance if none exists
53
+ if (!PluginI18nEngine._defaultKey) {
54
+ PluginI18nEngine._instances.set(PluginI18nEngine.DefaultInstanceKey, this);
55
+ PluginI18nEngine._defaultKey = PluginI18nEngine.DefaultInstanceKey;
56
+ }
52
57
  }
53
58
  /**
54
59
  * Create a new instance with a specific key
@@ -256,6 +261,50 @@ class PluginI18nEngine {
256
261
  }
257
262
  return { isValid, errors, warnings };
258
263
  }
264
+ /**
265
+ * Clear all component registrations for this instance (useful for testing)
266
+ */
267
+ clearAllComponents() {
268
+ this.componentRegistry.clearAllComponents();
269
+ }
270
+ /**
271
+ * Clear all named instances (useful for testing)
272
+ */
273
+ static clearAllInstances() {
274
+ PluginI18nEngine._instances.clear();
275
+ PluginI18nEngine._defaultKey = null;
276
+ }
277
+ /**
278
+ * Remove a specific named instance
279
+ */
280
+ static removeInstance(key) {
281
+ const instanceKey = key || PluginI18nEngine.DefaultInstanceKey;
282
+ const removed = PluginI18nEngine._instances.delete(instanceKey);
283
+ // If we removed the default instance, clear the default key
284
+ if (removed && PluginI18nEngine._defaultKey === instanceKey) {
285
+ PluginI18nEngine._defaultKey = null;
286
+ }
287
+ return removed;
288
+ }
289
+ /**
290
+ * Check if an instance exists
291
+ */
292
+ static hasInstance(key) {
293
+ const instanceKey = key || PluginI18nEngine.DefaultInstanceKey;
294
+ return PluginI18nEngine._instances.has(instanceKey);
295
+ }
296
+ /**
297
+ * Reset all plugin engines and clear component registrations
298
+ * Useful for test cleanup
299
+ */
300
+ static resetAll() {
301
+ for (const [key, engine] of PluginI18nEngine._instances) {
302
+ // Clear component registrations for each engine
303
+ engine.clearAllComponents();
304
+ }
305
+ PluginI18nEngine._instances.clear();
306
+ PluginI18nEngine._defaultKey = null;
307
+ }
259
308
  }
260
309
  exports.PluginI18nEngine = PluginI18nEngine;
261
310
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/i18n-lib",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Generic i18n library with enum translation support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",