@bitcobblers/wod-wiki-storage 0.60.2258 → 0.62.2260

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.
@@ -1,7 +1,7 @@
1
1
  import { IDBPDatabase, IDBPTransaction } from 'idb';
2
- import { I as IStorage, S as StoreName, a as IReadOnlyStore, b as StoreType, c as IReadWriteStore, d as IStorageTransaction } from '../wire-sRdblNjM.cjs';
3
- import { U as UserScopeContext } from '../policy-BrDCt3IU.cjs';
4
- import { S as SyncMutation, a as SyncEntry } from '../sync-Dnogcmm_.cjs';
2
+ import { I as IStorage, S as StoreName, a as IReadOnlyStore, b as StoreType, c as IReadWriteStore, d as IStorageTransaction } from '../wire-CerODSdR.cjs';
3
+ import { U as UserScopeContext } from '../policy-BW92ljIY.cjs';
4
+ import { S as SyncMutation, a as SyncEntry } from '../sync-DJYfvXeH.cjs';
5
5
  import { D as Database } from '../connection-DxuCLpRc.cjs';
6
6
  import '@bitcobblers/wod-wiki-core';
7
7
  import '@bitcobblers/wod-wiki-lang';
@@ -1,7 +1,7 @@
1
1
  import { IDBPDatabase, IDBPTransaction } from 'idb';
2
- import { I as IStorage, S as StoreName, a as IReadOnlyStore, b as StoreType, c as IReadWriteStore, d as IStorageTransaction } from '../wire-sRdblNjM.js';
3
- import { U as UserScopeContext } from '../policy-JQg92EFM.js';
4
- import { S as SyncMutation, a as SyncEntry } from '../sync-BeNNJq5-.js';
2
+ import { I as IStorage, S as StoreName, a as IReadOnlyStore, b as StoreType, c as IReadWriteStore, d as IStorageTransaction } from '../wire-CerODSdR.js';
3
+ import { U as UserScopeContext } from '../policy-DI2euDls.js';
4
+ import { S as SyncMutation, a as SyncEntry } from '../sync-Bl-3Hr1W.js';
5
5
  import { D as Database } from '../connection-DxuCLpRc.js';
6
6
  import '@bitcobblers/wod-wiki-core';
7
7
  import '@bitcobblers/wod-wiki-lang';
@@ -1,6 +1,6 @@
1
1
  import { collectUserScopeContext, isUserOwnedRow, USER_DELETED_SEED_PREFIX } from '../chunk-AK7366MO.mjs';
2
- import { readLegacyRows, readRawSyncOps } from '../chunk-6WNKSMMW.mjs';
3
- import { STORE_DEFS, DB_VERSION, stampUserOwned, validateStoredPins, validateStorageRow, rowsEqual, USER_OWNED_STORES, keyFromValue, validateNoteWrite, validateSessionWrite } from '../chunk-W4J74CHN.mjs';
2
+ import { readLegacyRows, readRawSyncOps } from '../chunk-62HQFP3B.mjs';
3
+ import { STORE_DEFS, DB_VERSION, stampUserOwned, validateStoredPins, validateStorageRow, rowsEqual, USER_OWNED_STORES, keyFromValue, validateNoteWrite, validateSessionWrite } from '../chunk-WPWAMGAW.mjs';
4
4
  import '../chunk-XRQKLSOT.mjs';
5
5
  import { openDB } from 'idb';
6
6
  import { parseDocumentSections, KNOWN_SECTION_WIDGETS, actionableSectionKind, matchDialectFence } from '@bitcobblers/wod-wiki-core';
@@ -85,10 +85,11 @@ function mutationBytes(op) {
85
85
  }
86
86
  var SNAPSHOT_OP_ORDER = [
87
87
  "block_revisions",
88
+ "note_revisions",
88
89
  "notes",
89
90
  "sessions",
90
91
  ...NON_SYSTEM_STORES.filter(
91
- (name) => name !== "block_revisions" && name !== "notes" && name !== "sessions"
92
+ (name) => name !== "block_revisions" && name !== "note_revisions" && name !== "notes" && name !== "sessions"
92
93
  )
93
94
  ];
94
95
  async function policySnapshotOps(readAll) {
@@ -186,7 +187,7 @@ var IDBStore = class _IDBStore {
186
187
  async put(value, _key) {
187
188
  if (!this.mutable) throw new Error("read-only store");
188
189
  if (!this.tx) {
189
- const scope = this.name === "notes" ? [this.name, "block_revisions"] : [this.name, "block_revisions", "notes"];
190
+ const scope = this.name === "notes" ? [this.name, "block_revisions", "note_revisions"] : [this.name, "block_revisions", "note_revisions", "notes"];
190
191
  return this.owner.transaction([...scope], "readwrite", (tx) => tx.readwrite(this.name).put(value));
191
192
  }
192
193
  const stored = this.owner.stamp(this.name, value);
@@ -195,7 +196,9 @@ var IDBStore = class _IDBStore {
195
196
  const key = keyFromValue(def, stored);
196
197
  const store = this.tx.objectStore(this.name);
197
198
  const previous = await store.get(key);
198
- if (this.name === "block_revisions" && previous !== void 0 && !rowsEqual(previous, stored)) throw new Error("immutable block revision collision");
199
+ if ((this.name === "block_revisions" || this.name === "note_revisions") && previous !== void 0 && !rowsEqual(previous, stored)) {
200
+ throw new Error(this.name === "note_revisions" ? "immutable note revision collision" : "immutable block revision collision");
201
+ }
199
202
  if (this.name === "notes") validateNoteWrite(previous, stored);
200
203
  if (this.name === "sessions") validateSessionWrite(previous, stored);
201
204
  if (rowsEqual(previous, stored)) return key;
@@ -209,10 +212,18 @@ var IDBStore = class _IDBStore {
209
212
  for (const revision of await this.tx.objectStore("block_revisions").index("by-note").getAll(String(stored.id))) {
210
213
  this.journal.ops.push({ op: "put", store: "block_revisions", key: [revision.noteId, revision.blockId, revision.version], value: revision });
211
214
  }
215
+ for (const noteRevision of await this.tx.objectStore("note_revisions").index("by-note").getAll(String(stored.id))) {
216
+ this.journal.ops.push({ op: "put", store: "note_revisions", key: [noteRevision.noteId, noteRevision.version], value: noteRevision });
217
+ }
212
218
  } else if (this.name === "sessions" && stored !== null && typeof stored === "object" && "noteId" in stored && "blockId" in stored && "blockVersion" in stored) {
213
219
  const revisionKey = [stored.noteId, stored.blockId, stored.blockVersion];
214
220
  const revision = await this.tx.objectStore("block_revisions").get(revisionKey);
215
221
  if (revision) this.journal.ops.push({ op: "put", store: "block_revisions", key: revisionKey, value: revision });
222
+ if ("noteSourceRevision" in stored && typeof stored.noteSourceRevision === "number") {
223
+ const noteRevisionKey = [stored.noteId, stored.noteSourceRevision];
224
+ const noteRevision = await this.tx.objectStore("note_revisions").get(noteRevisionKey);
225
+ if (noteRevision) this.journal.ops.push({ op: "put", store: "note_revisions", key: noteRevisionKey, value: noteRevision });
226
+ }
216
227
  }
217
228
  this.journal.ops.push({ op: "put", store: this.name, key, value: stored });
218
229
  } else if (wasUser) this.journal.ops.push({ op: "delete", store: this.name, key });
@@ -225,7 +236,7 @@ var IDBStore = class _IDBStore {
225
236
  async putMany(values, keys) {
226
237
  if (keys && keys.length !== values.length) throw new Error("putMany key count mismatch");
227
238
  if (!this.tx) {
228
- const scope = this.name === "notes" ? [this.name, "block_revisions"] : [this.name, "block_revisions", "notes"];
239
+ const scope = this.name === "notes" ? [this.name, "block_revisions", "note_revisions"] : [this.name, "block_revisions", "note_revisions", "notes"];
229
240
  return this.owner.transaction([...scope], "readwrite", (tx) => tx.readwrite(this.name).putMany(values, keys));
230
241
  }
231
242
  const out = [];
@@ -234,7 +245,7 @@ var IDBStore = class _IDBStore {
234
245
  }
235
246
  async delete(key) {
236
247
  if (!this.mutable) throw new Error("read-only store");
237
- if (this.name === "block_revisions") throw new Error("block history requires explicit wipe");
248
+ if (this.name === "block_revisions" || this.name === "note_revisions") throw new Error("block history requires explicit wipe");
238
249
  if (!this.tx) {
239
250
  const scope = this.name === "notes" ? [this.name] : [this.name, "notes"];
240
251
  return this.owner.transaction([...scope], "readwrite", (tx) => tx.readwrite(this.name).delete(key));
@@ -279,7 +290,7 @@ var IDBStore = class _IDBStore {
279
290
  */
280
291
  async clear() {
281
292
  if (!this.mutable) throw new Error("read-only store");
282
- if (this.name === "block_revisions") throw new Error("block history requires explicit wipe");
293
+ if (this.name === "block_revisions" || this.name === "note_revisions") throw new Error("block history requires explicit wipe");
283
294
  if (!this.tx) {
284
295
  const scope = this.name === "notes" ? ["notes", "block_index", "block_efforts"] : [this.name, "notes"];
285
296
  return this.owner.transaction([...scope], "readwrite", (tx) => tx.readwrite(this.name).clear());
@@ -391,6 +402,7 @@ var IndexedDBStorage = class {
391
402
  const scope = new Set(stores);
392
403
  if (mode === "readwrite") {
393
404
  scope.add("block_revisions");
405
+ scope.add("note_revisions");
394
406
  scope.add(OUTBOX_STORE);
395
407
  scope.add("notes");
396
408
  if (scope.has("notes")) {
@@ -437,7 +449,7 @@ var IndexedDBStorage = class {
437
449
  }
438
450
  }
439
451
  async wipeUserData() {
440
- const names = STORE_DEFS.filter((def) => !def.system && def.name !== "block_revisions").map((def) => def.name);
452
+ const names = STORE_DEFS.filter((def) => !def.system && def.name !== "block_revisions" && def.name !== "note_revisions").map((def) => def.name);
441
453
  await this.transaction(names, "readwrite", async (tx) => {
442
454
  for (const name of names) await tx.readwrite(name).clear();
443
455
  });
@@ -526,7 +538,7 @@ var IndexedDBStorage = class {
526
538
  };
527
539
  for (const op of await policySnapshotOps((store) => tx.objectStore(store).getAll())) {
528
540
  if (clearedStores.has(op.store)) continue;
529
- if (op.store !== "block_revisions" && pendingKeys.has(`${op.store}:${JSON.stringify(op.key)}`)) continue;
541
+ if (op.store !== "block_revisions" && op.store !== "note_revisions" && pendingKeys.has(`${op.store}:${JSON.stringify(op.key)}`)) continue;
530
542
  const size = mutationBytes(op);
531
543
  if (ops.length > 0 && (ops.length >= BOOTSTRAP_MAX_OPS || bytes + size > BOOTSTRAP_MAX_BYTES)) flush();
532
544
  ops.push(op);
@@ -616,7 +628,7 @@ var IndexedDBStorage = class {
616
628
  }
617
629
  if (mutation.store === "memberships") return;
618
630
  if (mutation.op === "clear") {
619
- if (mutation.store === "block_revisions") return;
631
+ if (mutation.store === "block_revisions" || mutation.store === "note_revisions") return;
620
632
  const store2 = tx.objectStore(mutation.store);
621
633
  const ctx = collectUserScopeContext(await tx.objectStore("notes").getAll());
622
634
  for (const row of await store2.getAll()) {
@@ -635,18 +647,26 @@ var IndexedDBStorage = class {
635
647
  for (const id of await store2.index("by-note").getAllKeys(noteId)) await store2.delete(id);
636
648
  }
637
649
  }
638
- if (mutation.store !== "block_revisions") await tx.objectStore(mutation.store).delete(mutation.key);
650
+ if (mutation.store !== "block_revisions" && mutation.store !== "note_revisions") await tx.objectStore(mutation.store).delete(mutation.key);
639
651
  return;
640
652
  }
641
653
  const store = tx.objectStore(mutation.store);
642
- if (mutation.store === "block_revisions") {
654
+ if (mutation.store === "block_revisions" || mutation.store === "note_revisions") {
643
655
  const existing = await store.get(mutation.key);
644
656
  if (existing !== void 0 && !rowsEqual(existing, mutation.value) && !preferLocal) {
645
- const incoming = mutation.value;
646
- const existingRow = existing;
647
- let version = existingRow.version + 1;
648
- while (await store.get([incoming.noteId, incoming.blockId, version]) !== void 0) version += 1;
649
- await store.put({ ...incoming, version });
657
+ if (mutation.store === "block_revisions") {
658
+ const incoming = mutation.value;
659
+ const existingRow = existing;
660
+ let version = existingRow.version + 1;
661
+ while (await store.get([incoming.noteId, incoming.blockId, version]) !== void 0) version += 1;
662
+ await store.put({ ...incoming, version });
663
+ } else {
664
+ const incoming = mutation.value;
665
+ const existingRow = existing;
666
+ let version = existingRow.version + 1;
667
+ while (await store.get([incoming.noteId, version]) !== void 0) version += 1;
668
+ await store.put({ ...incoming, version });
669
+ }
650
670
  return;
651
671
  }
652
672
  if (existing === void 0 || !rowsEqual(existing, mutation.value)) await store.put(mutation.value);
@@ -1032,9 +1052,9 @@ async function migrateSchema(db, oldVersion, tx) {
1032
1052
  for (const mutation of group.ops) {
1033
1053
  if (mutation.op === "wipe") {
1034
1054
  for (const name of NON_SYSTEM_STORES) {
1035
- if (name !== "block_revisions") ops.push({ op: "clear", store: name });
1055
+ if (name !== "block_revisions" && name !== "note_revisions") ops.push({ op: "clear", store: name });
1036
1056
  }
1037
- } else if (mutation.op !== "put" && mutation.store !== "memberships" && mutation.store !== "block_revisions") {
1057
+ } else if (mutation.op !== "put" && mutation.store !== "memberships" && mutation.store !== "block_revisions" && mutation.store !== "note_revisions") {
1038
1058
  ops.push(mutation);
1039
1059
  }
1040
1060
  }
@@ -1049,6 +1069,33 @@ async function migrateSchema(db, oldVersion, tx) {
1049
1069
  }
1050
1070
  }
1051
1071
  }
1072
+ if (oldVersion > 0 && oldVersion < 35 && db.objectStoreNames.contains("page_notes") && db.objectStoreNames.contains("page") && db.objectStoreNames.contains("schedule_items")) {
1073
+ const pages = await store("page").getAll();
1074
+ const dateByPage = /* @__PURE__ */ new Map();
1075
+ for (const p of pages) {
1076
+ if (p.date) dateByPage.set(p.id, p.date);
1077
+ }
1078
+ const pageNotes = await store("page_notes").getAll();
1079
+ const schedStore = store("schedule_items");
1080
+ for (const pn of pageNotes) {
1081
+ const date = dateByPage.get(pn.pageId);
1082
+ if (!date) continue;
1083
+ const id = `sched-${pn.id}`;
1084
+ const existing = await schedStore.get(id);
1085
+ if (existing) continue;
1086
+ const createdAt = pn.createdAt ?? Date.now();
1087
+ await schedStore.put({
1088
+ id,
1089
+ date,
1090
+ noteId: pn.noteId,
1091
+ pageId: pn.pageId,
1092
+ position: pn.position ?? 0,
1093
+ status: "planned",
1094
+ createdAt,
1095
+ updatedAt: createdAt
1096
+ });
1097
+ }
1098
+ }
1052
1099
  }
1053
1100
  async function migrateSegmentsToBlocks(db, tx) {
1054
1101
  const store = (name) => tx.objectStore(name);