@shaxpir/duiduidui-models 1.9.3 → 1.9.4

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.
@@ -27,9 +27,27 @@ export interface ShareSyncOptions {
27
27
  }
28
28
  export declare class ShareSyncFactory {
29
29
  private static INSTANCE;
30
+ private static TEST_INSTANCE;
30
31
  static initialize(encryption: Encryption, options: ShareSyncOptions): void;
32
+ static isInitialized(): boolean;
31
33
  static get(): ShareSync;
32
34
  static shutdown(): void;
35
+ /**
36
+ * Set a test instance that will be returned by get() instead of the real instance.
37
+ * This allows tests to inject mock/configured ShareSync instances.
38
+ *
39
+ * @param instance The ShareSync instance to use for testing
40
+ */
41
+ static setTestInstance(instance: ShareSync): void;
42
+ /**
43
+ * Clear the test instance, reverting to normal behavior.
44
+ */
45
+ static clearTestInstance(): void;
46
+ /**
47
+ * Reset all state for testing. Clears both production and test instances.
48
+ * Does NOT call shutdown() to avoid side effects - just clears the references.
49
+ */
50
+ static resetForTesting(): void;
33
51
  }
34
52
  export declare class ShareSync {
35
53
  private _debug;
@@ -64,7 +64,14 @@ class ShareSyncFactory {
64
64
  static initialize(encryption, options) {
65
65
  ShareSyncFactory.INSTANCE = new ShareSync(encryption, options);
66
66
  }
67
+ static isInitialized() {
68
+ return ShareSyncFactory.INSTANCE !== null || ShareSyncFactory.TEST_INSTANCE !== null;
69
+ }
67
70
  static get() {
71
+ // Test instance takes precedence
72
+ if (ShareSyncFactory.TEST_INSTANCE !== null) {
73
+ return ShareSyncFactory.TEST_INSTANCE;
74
+ }
68
75
  return ShareSyncFactory.INSTANCE;
69
76
  }
70
77
  static shutdown() {
@@ -73,9 +80,37 @@ class ShareSyncFactory {
73
80
  ShareSyncFactory.INSTANCE = null;
74
81
  }
75
82
  }
83
+ // ============================================================
84
+ // Test helper methods
85
+ // ============================================================
86
+ /**
87
+ * Set a test instance that will be returned by get() instead of the real instance.
88
+ * This allows tests to inject mock/configured ShareSync instances.
89
+ *
90
+ * @param instance The ShareSync instance to use for testing
91
+ */
92
+ static setTestInstance(instance) {
93
+ ShareSyncFactory.TEST_INSTANCE = instance;
94
+ }
95
+ /**
96
+ * Clear the test instance, reverting to normal behavior.
97
+ */
98
+ static clearTestInstance() {
99
+ ShareSyncFactory.TEST_INSTANCE = null;
100
+ }
101
+ /**
102
+ * Reset all state for testing. Clears both production and test instances.
103
+ * Does NOT call shutdown() to avoid side effects - just clears the references.
104
+ */
105
+ static resetForTesting() {
106
+ ShareSyncFactory.INSTANCE = null;
107
+ ShareSyncFactory.TEST_INSTANCE = null;
108
+ }
76
109
  }
77
110
  exports.ShareSyncFactory = ShareSyncFactory;
78
111
  ShareSyncFactory.INSTANCE = null;
112
+ // For tests: allow injecting a custom instance
113
+ ShareSyncFactory.TEST_INSTANCE = null;
79
114
  class ShareSync {
80
115
  constructor(encryption, options) {
81
116
  this._modelCache = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.9.3",
3
+ "version": "1.9.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"