@shaxpir/duiduidui-models 1.5.9 → 1.5.11

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.
@@ -6,18 +6,27 @@ import { ConditionFilters } from './Condition';
6
6
  export interface LastSync {
7
7
  at_utc_time: CompactDateTime | null;
8
8
  }
9
+ export interface AudioDownloadQueueItem {
10
+ text: string;
11
+ added_at: CompactDateTime;
12
+ retry_count: number;
13
+ next_retry_at?: CompactDateTime;
14
+ last_error?: string;
15
+ }
9
16
  export interface DevicePayload {
10
17
  last_sync?: LastSync;
11
18
  chinese_font?: string;
12
19
  raw_search_text?: string;
13
20
  star_filter?: boolean;
14
21
  conditions?: ConditionFilters;
22
+ audio_download_queue?: AudioDownloadQueueItem[];
15
23
  }
16
24
  export interface DeviceBody extends ContentBody {
17
25
  meta: ContentMeta;
18
26
  payload: DevicePayload;
19
27
  }
20
28
  export declare class Device extends Content {
29
+ private _audioDownloadQueueView;
21
30
  static create(userId: ContentId, deviceId: ContentId): Device;
22
31
  constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
23
32
  get payload(): DevicePayload;
@@ -25,4 +34,9 @@ export declare class Device extends Content {
25
34
  setLastSyncAtUtcTime(value: CompactDateTime): void;
26
35
  get chineseFont(): string;
27
36
  setChineseFont(value: string): void;
37
+ get audioDownloadQueue(): AudioDownloadQueueItem[];
38
+ get audioDownloadQueueLength(): number;
39
+ addToAudioDownloadQueue(text: string): void;
40
+ removeFromAudioDownloadQueue(text: string): void;
41
+ updateAudioDownloadQueueItem(text: string, updates: Partial<AudioDownloadQueueItem>): void;
28
42
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Device = void 0;
4
4
  const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
5
5
  const repo_1 = require("../repo");
6
+ const ArrayView_1 = require("./ArrayView");
6
7
  const Content_1 = require("./Content");
7
8
  const ContentKind_1 = require("./ContentKind");
8
9
  const Operation_1 = require("./Operation");
@@ -19,12 +20,14 @@ class Device extends Content_1.Content {
19
20
  updated_at: now
20
21
  },
21
22
  payload: {
22
- last_sync: { at_utc_time: null }
23
+ last_sync: { at_utc_time: null },
24
+ audio_download_queue: []
23
25
  }
24
26
  });
25
27
  }
26
28
  constructor(doc, shouldAcquire, shareSync) {
27
29
  super(doc, shouldAcquire, shareSync);
30
+ this._audioDownloadQueueView = new ArrayView_1.ArrayView(this, ['payload', 'audio_download_queue']);
28
31
  }
29
32
  get payload() {
30
33
  this.checkDisposed("Device.payload");
@@ -54,5 +57,50 @@ class Device extends Content_1.Content {
54
57
  batch.commit();
55
58
  }
56
59
  }
60
+ get audioDownloadQueue() {
61
+ this.checkDisposed("Device.audioDownloadQueue");
62
+ return this._audioDownloadQueueView.values;
63
+ }
64
+ get audioDownloadQueueLength() {
65
+ this.checkDisposed("Device.audioDownloadQueueLength");
66
+ return this._audioDownloadQueueView.length;
67
+ }
68
+ addToAudioDownloadQueue(text) {
69
+ this.checkDisposed("Device.addToAudioDownloadQueue");
70
+ // Check if item already exists in queue
71
+ const existingIndex = this._audioDownloadQueueView.values.findIndex(item => item.text === text);
72
+ if (existingIndex !== -1) {
73
+ console.log(`Audio download already queued for: ${text}`);
74
+ return;
75
+ }
76
+ const now = shaxpir_common_1.ClockService.getClock().utc();
77
+ const newItem = {
78
+ text,
79
+ added_at: now,
80
+ retry_count: 0
81
+ };
82
+ this._audioDownloadQueueView.push(newItem);
83
+ console.log(`Added to audio download queue: ${text}`);
84
+ }
85
+ removeFromAudioDownloadQueue(text) {
86
+ this.checkDisposed("Device.removeFromAudioDownloadQueue");
87
+ // Find the item index
88
+ const itemIndex = this._audioDownloadQueueView.values.findIndex(item => item.text === text);
89
+ if (itemIndex !== -1) {
90
+ this._audioDownloadQueueView.removeAt(itemIndex);
91
+ console.log(`Removed from audio download queue: ${text}`);
92
+ }
93
+ }
94
+ updateAudioDownloadQueueItem(text, updates) {
95
+ this.checkDisposed("Device.updateAudioDownloadQueueItem");
96
+ const itemIndex = this._audioDownloadQueueView.values.findIndex(item => item.text === text);
97
+ if (itemIndex !== -1) {
98
+ // Update each field in the updates object
99
+ for (const [key, value] of Object.entries(updates)) {
100
+ this._audioDownloadQueueView.setObjectValueAtIndex(itemIndex, key, value);
101
+ }
102
+ console.log(`Updated audio download queue item: ${text}`, updates);
103
+ }
104
+ }
57
105
  }
58
106
  exports.Device = Device;
@@ -18,6 +18,7 @@ export interface TermSummary {
18
18
  review_count: number;
19
19
  implied_review_count: number;
20
20
  last_review_utc: CompactDateTime;
21
+ tag_count: number;
21
22
  }
22
23
  export interface TermPayload extends BayesianScore {
23
24
  text: string;
@@ -30,6 +31,7 @@ export interface TermPayload extends BayesianScore {
30
31
  theta: number;
31
32
  uncertainty: number;
32
33
  tags: string[];
34
+ tag_count: number;
33
35
  reviews: ReviewLike[];
34
36
  review_count: number;
35
37
  last_review_utc: CompactDateTime;
@@ -68,6 +70,8 @@ export declare class Term extends Content {
68
70
  get uncertainty(): number;
69
71
  get starredAt(): CompactDateTime | null;
70
72
  get tags(): string[];
73
+ get tagCount(): number;
74
+ private _updateTagCount;
71
75
  addTag(value: string): void;
72
76
  removeTag(value: string): void;
73
77
  get lastReviewUtc(): CompactDateTime | null;
@@ -66,6 +66,7 @@ class Term extends Content_1.Content {
66
66
  examples: phrase.examples,
67
67
  keywords: phrase.keywords,
68
68
  tags: phrase.tags,
69
+ tag_count: phrase.tags.length,
69
70
  starred_at: null,
70
71
  alpha: 0.5,
71
72
  beta: 0.5,
@@ -98,6 +99,7 @@ class Term extends Content_1.Content {
98
99
  phrase_id: phrase.id,
99
100
  starred_at: null,
100
101
  tags: [],
102
+ tag_count: 0,
101
103
  alpha: 0.5,
102
104
  beta: 0.5,
103
105
  theta: 0.5,
@@ -150,11 +152,24 @@ class Term extends Content_1.Content {
150
152
  this.checkDisposed("Term.tags");
151
153
  return this._tagsView.values;
152
154
  }
155
+ get tagCount() {
156
+ this.checkDisposed("Term.tagCount");
157
+ return this.payload.tag_count;
158
+ }
159
+ _updateTagCount() {
160
+ const newCount = this._tagsView.length;
161
+ if (this.payload.tag_count !== newCount) {
162
+ const batch = new Operation_1.BatchOperation(this);
163
+ batch.setPathValue(['payload', 'tag_count'], newCount);
164
+ batch.commit();
165
+ }
166
+ }
153
167
  addTag(value) {
154
168
  this.checkDisposed("Term.addTag");
155
169
  const index = this._tagsView.indexOf(value);
156
170
  if (index === -1) {
157
171
  this._tagsView.push(value);
172
+ this._updateTagCount();
158
173
  }
159
174
  }
160
175
  removeTag(value) {
@@ -162,6 +177,7 @@ class Term extends Content_1.Content {
162
177
  const index = this._tagsView.indexOf(value);
163
178
  if (index !== -1) {
164
179
  this._tagsView.removeAt(index);
180
+ this._updateTagCount();
165
181
  }
166
182
  }
167
183
  get lastReviewUtc() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.5.9",
3
+ "version": "1.5.11",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"