@mengine/storage 2.0.1-alpha.2 → 2.0.1-alpha.3

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.
Files changed (2) hide show
  1. package/dist/idb.js +23 -21
  2. package/package.json +3 -3
package/dist/idb.js CHANGED
@@ -118,28 +118,29 @@ var IndexedDBDocStorage = class extends BaseDocStorage {
118
118
  "updates",
119
119
  "sequences"
120
120
  ], "readwrite");
121
- if (!await trx.objectStore("snapshots").get(update.docId)) {
122
- await trx.objectStore("snapshots").put({
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
- 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
- });
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
- if (this.docUpdateListener === 0) this.channel.addEventListener("message", this.handleChannelMessage);
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) this.channel.removeEventListener("message", this.handleChannelMessage);
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.0.1-alpha.2",
3
+ "version": "2.0.1-alpha.3",
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.13.6",
28
- "@mengine/utils": "2.0.1-alpha.2"
27
+ "loro-crdt": "^1.16.1",
28
+ "@mengine/utils": "2.0.1-alpha.3"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@testcontainers/postgresql": "^12.0.1",