@mengine/storage 2.0.1-alpha.1 → 2.0.1

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 +21 -23
  2. package/package.json +2 -2
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 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) ?? {
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
- })(), trx.done]);
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
- const channel = this.channel;
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.1",
3
+ "version": "2.0.1",
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.0.1-alpha.1"
28
+ "@mengine/utils": "2.0.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@testcontainers/postgresql": "^12.0.1",