@shaxpir/duiduidui-models 1.4.17 → 1.4.19

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.
@@ -10,7 +10,7 @@ class Billing extends Content_1.Content {
10
10
  return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.BILLING);
11
11
  }
12
12
  static create(userId, payload, createdAt) {
13
- const now = shaxpir_common_1.MultiClock.now();
13
+ const now = shaxpir_common_1.ClockService.getClock().now();
14
14
  // If the createdAt time is not provided, use the current time
15
15
  createdAt ??= now;
16
16
  const billingId = Billing.makeBillingId(userId);
@@ -8,7 +8,7 @@ const ContentKind_1 = require("./ContentKind");
8
8
  const Operation_1 = require("./Operation");
9
9
  class Device extends Content_1.Content {
10
10
  static create(userId, deviceId) {
11
- const now = shaxpir_common_1.MultiClock.now();
11
+ const now = shaxpir_common_1.ClockService.getClock().now();
12
12
  return repo_1.ShareSyncFactory.get().createContent({
13
13
  meta: {
14
14
  ref: deviceId,
@@ -14,7 +14,7 @@ class Media extends Content_1.Content {
14
14
  return this.doc.data.payload;
15
15
  }
16
16
  static create(userId, mediaId, payload) {
17
- const now = shaxpir_common_1.MultiClock.now();
17
+ const now = shaxpir_common_1.ClockService.getClock().now();
18
18
  return repo_1.ShareSyncFactory.get().createContent({
19
19
  meta: {
20
20
  ref: mediaId,
@@ -35,7 +35,7 @@ class Metric extends Content_1.Content {
35
35
  maxDate = date;
36
36
  }
37
37
  }
38
- const now = shaxpir_common_1.MultiClock.now();
38
+ const now = shaxpir_common_1.ClockService.getClock().now();
39
39
  return repo_1.ShareSyncFactory.get().createContent({
40
40
  meta: {
41
41
  ref: metricId,
@@ -77,7 +77,7 @@ class BatchOperation {
77
77
  this.time = time;
78
78
  }
79
79
  else {
80
- this.time = shaxpir_common_1.MultiClock.now();
80
+ this.time = shaxpir_common_1.ClockService.getClock().now();
81
81
  }
82
82
  this.ops = [];
83
83
  }
@@ -11,7 +11,7 @@ class Profile extends Content_1.Content {
11
11
  return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.PROFILE);
12
12
  }
13
13
  static create(userId) {
14
- const now = shaxpir_common_1.MultiClock.now();
14
+ const now = shaxpir_common_1.ClockService.getClock().now();
15
15
  const profileId = Profile.makeProfileId(userId);
16
16
  return repo_1.ShareSyncFactory.get().createContent({
17
17
  meta: {
@@ -11,7 +11,7 @@ class Progress extends Content_1.Content {
11
11
  return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.PROGRESS);
12
12
  }
13
13
  static create(userId) {
14
- const now = shaxpir_common_1.MultiClock.now();
14
+ const now = shaxpir_common_1.ClockService.getClock().now();
15
15
  const progressId = Progress.makeProgressId(userId);
16
16
  return repo_1.ShareSyncFactory.get().createContent({
17
17
  meta: {
@@ -22,7 +22,7 @@ class Session extends Content_1.Content {
22
22
  return `${sessionId}_${at.utc_time}`;
23
23
  }
24
24
  static create(userId, deviceId) {
25
- let now = shaxpir_common_1.MultiClock.now();
25
+ let now = shaxpir_common_1.ClockService.getClock().now();
26
26
  let sessionId = Session.makeSessionId(userId);
27
27
  let sessionRef = Session.makeSessionRef(userId, now);
28
28
  return repo_1.ShareSyncFactory.get().createContent({
@@ -16,7 +16,7 @@ class Term extends Content_1.Content {
16
16
  this._reviewsView = new ArrayView_1.ArrayView(this, ['payload', 'reviews']);
17
17
  }
18
18
  static forUserPhrase(userId, textOrPhrase, senseRank, learnRank, phraseId) {
19
- const now = shaxpir_common_1.MultiClock.now();
19
+ const now = shaxpir_common_1.ClockService.getClock().now();
20
20
  // Handle overloaded parameters
21
21
  let phrase;
22
22
  if (typeof textOrPhrase === 'string') {
@@ -72,7 +72,7 @@ class Term extends Content_1.Content {
72
72
  });
73
73
  }
74
74
  static forBuiltinPhrase(userId, phrase) {
75
- const now = shaxpir_common_1.MultiClock.now();
75
+ const now = shaxpir_common_1.ClockService.getClock().now();
76
76
  const termId = Term.makeTermId(userId, phrase.text, phrase.sense_rank);
77
77
  return repo_1.ShareSyncFactory.get().createContent({
78
78
  meta: {
@@ -18,7 +18,7 @@ class User extends Content_1.Content {
18
18
  }
19
19
  static create(userId, payload, createdAt) {
20
20
  // User creation always happens in UTC time
21
- const now = shaxpir_common_1.MultiClock.utcNow();
21
+ const now = shaxpir_common_1.ClockService.getClock().now();
22
22
  // If the createdAt time is not provided, use the current time
23
23
  createdAt ??= now;
24
24
  return repo_1.ShareSyncFactory.get().createContent({
@@ -25,7 +25,7 @@ class Workspace extends Content_1.Content {
25
25
  return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.WORKSPACE);
26
26
  }
27
27
  static create(userId, payload) {
28
- const now = shaxpir_common_1.MultiClock.now();
28
+ const now = shaxpir_common_1.ClockService.getClock().now();
29
29
  const workspaceId = Workspace.makeWorkspaceId(userId);
30
30
  return repo_1.ShareSyncFactory.get().createContent({
31
31
  meta: {
@@ -23,6 +23,7 @@ export interface ShareSyncOptions {
23
23
  webSocketConstructor?: any;
24
24
  enableDurableStore?: boolean;
25
25
  storageFactory?: () => Promise<any>;
26
+ maxBatchSize?: number;
26
27
  }
27
28
  export declare class ShareSyncFactory {
28
29
  private static INSTANCE;
@@ -71,4 +72,10 @@ export declare class ShareSync {
71
72
  dispose(model: Model): void;
72
73
  onOperationError(opError: any): void;
73
74
  private wrap;
75
+ /**
76
+ * Flush control methods for optimizing bulk write operations
77
+ */
78
+ setAutoBatchEnabled(enabled: boolean): void;
79
+ isAutoBatchEnabled(): boolean;
80
+ flush(): void;
74
81
  }
@@ -149,6 +149,7 @@ class ShareSync {
149
149
  durableStore: {
150
150
  storage: this._storage,
151
151
  debug: this._debug,
152
+ maxBatchSize: options.maxBatchSize || 25, // Default 25 for better bulk write performance
152
153
  extVersionDecoder: (docData) => {
153
154
  if (docData &&
154
155
  docData.meta &&
@@ -428,5 +429,24 @@ class ShareSync {
428
429
  }
429
430
  throw new Error(`can't wrap content ${kind}/${doc.id}`);
430
431
  }
432
+ /**
433
+ * Flush control methods for optimizing bulk write operations
434
+ */
435
+ setAutoBatchEnabled(enabled) {
436
+ if (this._durableStore && typeof this._durableStore.setAutoBatchEnabled === 'function') {
437
+ this._durableStore.setAutoBatchEnabled(enabled);
438
+ }
439
+ }
440
+ isAutoBatchEnabled() {
441
+ if (this._durableStore && typeof this._durableStore.isAutoBatchEnabled === 'function') {
442
+ return this._durableStore.isAutoBatchEnabled();
443
+ }
444
+ return true; // Default to enabled if DurableStore doesn't support it
445
+ }
446
+ flush() {
447
+ if (this._durableStore && typeof this._durableStore.flush === 'function') {
448
+ this._durableStore.flush();
449
+ }
450
+ }
431
451
  }
432
452
  exports.ShareSync = ShareSync;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.4.17",
3
+ "version": "1.4.19",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@shaxpir/duiduidui-models": "^1.4.14",
20
20
  "@shaxpir/sharedb": "^6.0.6",
21
- "@shaxpir/shaxpir-common": "1.3.0",
21
+ "@shaxpir/shaxpir-common": "1.4.0",
22
22
  "ot-json1": "1.0.1",
23
23
  "ot-text-unicode": "4.0.0",
24
24
  "reconnecting-websocket": "4.4.0"