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