@mengine/storage 2.1.1-dsl.1 → 2.1.1-dsl.10
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/dist/idb.js +23 -21
- package/package.json +2 -2
package/dist/idb.js
CHANGED
|
@@ -118,28 +118,29 @@ var IndexedDBDocStorage = class extends BaseDocStorage {
|
|
|
118
118
|
"updates",
|
|
119
119
|
"sequences"
|
|
120
120
|
], "readwrite");
|
|
121
|
-
|
|
122
|
-
await trx.objectStore("snapshots").
|
|
121
|
+
await Promise.all([(async () => {
|
|
122
|
+
if (!await trx.objectStore("snapshots").get(update.docId)) {
|
|
123
|
+
await trx.objectStore("snapshots").put({
|
|
124
|
+
docId: update.docId,
|
|
125
|
+
data: update.data,
|
|
126
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
127
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const seq = await trx.objectStore("sequences").get(update.docId) ?? {
|
|
123
132
|
docId: update.docId,
|
|
133
|
+
seq: 0
|
|
134
|
+
};
|
|
135
|
+
seq.seq++;
|
|
136
|
+
await trx.objectStore("sequences").put(seq);
|
|
137
|
+
await trx.objectStore("updates").put({
|
|
138
|
+
docId: update.docId,
|
|
139
|
+
seq: seq.seq,
|
|
124
140
|
data: update.data,
|
|
125
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
126
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
141
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
127
142
|
});
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
let seq = await trx.objectStore("sequences").get(update.docId);
|
|
131
|
-
if (!seq) seq = {
|
|
132
|
-
docId: update.docId,
|
|
133
|
-
seq: 0
|
|
134
|
-
};
|
|
135
|
-
seq.seq++;
|
|
136
|
-
await trx.objectStore("sequences").put(seq);
|
|
137
|
-
await trx.objectStore("updates").put({
|
|
138
|
-
docId: update.docId,
|
|
139
|
-
seq: seq.seq,
|
|
140
|
-
data: update.data,
|
|
141
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
142
|
-
});
|
|
143
|
+
})(), trx.done]);
|
|
143
144
|
this.event.emit("update", {
|
|
144
145
|
update: {
|
|
145
146
|
docId: update.docId,
|
|
@@ -206,13 +207,14 @@ var IndexedDBDocStorage = class extends BaseDocStorage {
|
|
|
206
207
|
}
|
|
207
208
|
docUpdateListener = 0;
|
|
208
209
|
subscribeDocUpdate(callback) {
|
|
209
|
-
|
|
210
|
+
const channel = this.channel;
|
|
211
|
+
if (this.docUpdateListener === 0) channel.addEventListener("message", this.handleChannelMessage);
|
|
210
212
|
this.docUpdateListener++;
|
|
211
213
|
const dispose = super.subscribeDocUpdate(callback);
|
|
212
214
|
return () => {
|
|
213
215
|
dispose();
|
|
214
216
|
this.docUpdateListener--;
|
|
215
|
-
if (this.docUpdateListener === 0)
|
|
217
|
+
if (this.docUpdateListener === 0) channel.removeEventListener("message", this.handleChannelMessage);
|
|
216
218
|
};
|
|
217
219
|
}
|
|
218
220
|
handleChannelMessage = (event) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mengine/storage",
|
|
3
|
-
"version": "2.1.1-dsl.
|
|
3
|
+
"version": "2.1.1-dsl.10",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"drizzle-orm": "^0.45.2",
|
|
26
26
|
"lodash-es": "^4.18.1",
|
|
27
27
|
"loro-crdt": "^1.16.1",
|
|
28
|
-
"@mengine/utils": "2.1.1-dsl.
|
|
28
|
+
"@mengine/utils": "2.1.1-dsl.10"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@testcontainers/postgresql": "^12.0.1",
|