@shaxpir/duiduidui-models 1.9.3 → 1.9.6

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.
@@ -30,6 +30,11 @@ export declare class Workspace extends Content {
30
30
  get payload(): WorkspacePayload;
31
31
  getGlobalConditions(): ConditionFilters;
32
32
  static makeWorkspaceId(userId: ContentId): ContentId;
33
+ /**
34
+ * Validate that a WorkspacePayload has all required fields.
35
+ * Throws an error if validation fails.
36
+ */
37
+ static validatePayload(payload: WorkspacePayload): void;
33
38
  static create(userId: ContentId, payload: WorkspacePayload): Workspace;
34
39
  get sessions(): ArrayView<MultiTime>;
35
40
  get devices(): ArrayView<ContentId>;
@@ -25,7 +25,32 @@ class Workspace extends Content_1.Content {
25
25
  static makeWorkspaceId(userId) {
26
26
  return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.WORKSPACE);
27
27
  }
28
+ /**
29
+ * Validate that a WorkspacePayload has all required fields.
30
+ * Throws an error if validation fails.
31
+ */
32
+ static validatePayload(payload) {
33
+ if (!payload || typeof payload !== 'object') {
34
+ throw new Error('Workspace.create: payload must be an object');
35
+ }
36
+ if (!Array.isArray(payload.devices)) {
37
+ throw new Error('Workspace.create: payload.devices must be an array');
38
+ }
39
+ if (!Array.isArray(payload.sessions)) {
40
+ throw new Error('Workspace.create: payload.sessions must be an array');
41
+ }
42
+ if (!payload.journey || typeof payload.journey !== 'object' || Array.isArray(payload.journey)) {
43
+ throw new Error('Workspace.create: payload.journey must be an object');
44
+ }
45
+ if (!payload.global_conditions || typeof payload.global_conditions !== 'object' || Array.isArray(payload.global_conditions)) {
46
+ throw new Error('Workspace.create: payload.global_conditions must be an object');
47
+ }
48
+ if (!Array.isArray(payload.uploaded_avatars)) {
49
+ throw new Error('Workspace.create: payload.uploaded_avatars must be an array');
50
+ }
51
+ }
28
52
  static create(userId, payload) {
53
+ Workspace.validatePayload(payload);
29
54
  const now = shaxpir_common_1.ClockService.getClock().now();
30
55
  const workspaceId = Workspace.makeWorkspaceId(userId);
31
56
  return repo_1.ShareSyncFactory.get().createContent({
@@ -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.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"