@bitcobblers/wod-wiki-storage 0.61.2259 → 0.62.2261

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/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  var wodWikiCore = require('@bitcobblers/wod-wiki-core');
4
4
 
5
5
  // src/schema.ts
6
- var DB_VERSION = 34;
6
+ var DB_VERSION = 35;
7
7
  var COLUMN_TYPES = {
8
8
  notes: { date: "number", createdAt: "number" },
9
9
  page: { createdAt: "number" },
@@ -13,6 +13,8 @@ var COLUMN_TYPES = {
13
13
  tag_types: { createdAt: "number" },
14
14
  note_tags: {},
15
15
  block_revisions: { version: "number", savedAt: "number" },
16
+ note_revisions: { version: "number", savedAt: "number" },
17
+ schedule_items: { position: "number", createdAt: "number", updatedAt: "number" },
16
18
  sessions: {
17
19
  blockVersion: "number",
18
20
  startTime: "number",
@@ -99,6 +101,9 @@ var STORE_DEFS = [
99
101
  { name: "by-note", keyPath: ["noteId"] },
100
102
  { name: "by-block", keyPath: ["noteId", "blockId"] }
101
103
  ] },
104
+ { name: "note_revisions", keyPath: ["noteId", "version"], indexes: [
105
+ { name: "by-note", keyPath: ["noteId"] }
106
+ ] },
102
107
  // 6. sessions
103
108
  { name: "sessions", keyPath: ["id"], indexes: [
104
109
  { name: "by-note", keyPath: ["noteId"] },
@@ -106,6 +111,8 @@ var STORE_DEFS = [
106
111
  { name: "by-content", keyPath: ["blockContentId"] },
107
112
  { name: "by-block", keyPath: ["blockId"] },
108
113
  { name: "by-page", keyPath: ["pageId"] },
114
+ { name: "by-session-date", keyPath: ["sessionDate"] },
115
+ { name: "by-schedule-item", keyPath: ["scheduleItemId"] },
109
116
  { name: "by-origin", keyPath: ["origin"] },
110
117
  { name: "by-user", keyPath: ["userId"] }
111
118
  ] },
@@ -185,6 +192,14 @@ var STORE_DEFS = [
185
192
  { name: "by-owner-note", keyPath: ["ownerNoteId"] },
186
193
  { name: "by-user", keyPath: ["userId"] }
187
194
  ] },
195
+ // 13e. schedule_items (V35) — M:N scheduling link from calendar dates to Notes
196
+ { name: "schedule_items", keyPath: ["id"], indexes: [
197
+ { name: "by-date", keyPath: ["date"] },
198
+ { name: "by-note", keyPath: ["noteId"] },
199
+ { name: "by-page", keyPath: ["pageId"] },
200
+ { name: "by-date-note", keyPath: ["date", "noteId"] },
201
+ { name: "by-user", keyPath: ["userId"] }
202
+ ] },
188
203
  // 14. meta
189
204
  { name: "meta", keyPath: ["key"], indexes: [] },
190
205
  // 15. memberships (V25, system — survives wipe; truth lives in
@@ -213,7 +228,8 @@ var USER_OWNED_STORES = [
213
228
  "equipment",
214
229
  "block_equipment",
215
230
  "notebook_links",
216
- "property_overrides"
231
+ "property_overrides",
232
+ "schedule_items"
217
233
  ];
218
234
  var STAMPABLE = Object.fromEntries(
219
235
  USER_OWNED_STORES.map((s) => [s, true])
@@ -300,7 +316,7 @@ function keyInRange(key, range) {
300
316
  }
301
317
  return true;
302
318
  }
303
- var DOMAIN_PROJECTION_VERSION = 4;
319
+ var DOMAIN_PROJECTION_VERSION = 5;
304
320
  function isObject(value) {
305
321
  return typeof value === "object" && value !== null && !Array.isArray(value);
306
322
  }
@@ -458,7 +474,7 @@ function record(value) {
458
474
  return value;
459
475
  }
460
476
  function validateStorageRow(store, value) {
461
- if (store !== "notes" && store !== "block_revisions" && store !== "sessions" && store !== "block_index") return;
477
+ if (store !== "notes" && store !== "block_revisions" && store !== "note_revisions" && store !== "sessions" && store !== "block_index" && store !== "schedule_items") return;
462
478
  const row = record(value);
463
479
  const positive = (field) => typeof row[field] === "number" && Number.isSafeInteger(row[field]) && row[field] > 0;
464
480
  const required = (field) => typeof row[field] === "string" && row[field].length > 0;
@@ -487,8 +503,23 @@ function validateStorageRow(store, value) {
487
503
  } catch (error) {
488
504
  throw new StorageError(400, error instanceof Error ? error.message : "invalid revision source", "invalid_note_blocks");
489
505
  }
506
+ } else if (store === "note_revisions") {
507
+ if (!required("noteId") || !positive("version") || typeof row.title !== "string" || typeof row.rawContent !== "string" || typeof row.savedAt !== "number" || !Number.isFinite(row.savedAt) || row.tags !== void 0 && (!Array.isArray(row.tags) || !row.tags.every((tag) => typeof tag === "string")) || row.notebookIds !== void 0 && (!Array.isArray(row.notebookIds) || !row.notebookIds.every((nb) => typeof nb === "string")) || row.type !== void 0 && typeof row.type !== "string") {
508
+ throw new StorageError(400, "invalid note revision", "invalid_note_blocks");
509
+ }
510
+ try {
511
+ wodWikiCore.validateNoteBlocks(row.rawContent, record(row.blocks), row.version);
512
+ } catch (error) {
513
+ throw new StorageError(400, error instanceof Error ? error.message : "invalid note revision blocks", "invalid_note_blocks");
514
+ }
515
+ } else if (store === "schedule_items") {
516
+ if (!required("id") || !required("date") || !required("noteId") || typeof row.position !== "number" || !Number.isFinite(row.position) || !["planned", "completed", "skipped", "moved"].includes(String(row.status)) || typeof row.createdAt !== "number" || !Number.isFinite(row.createdAt) || typeof row.updatedAt !== "number" || !Number.isFinite(row.updatedAt) || ["pageId", "sourceNotebookId", "fallbackTitle", "blockId", "slot", "notes", "movedFromDate"].some(
517
+ (field) => row[field] !== void 0 && typeof row[field] !== "string"
518
+ )) {
519
+ throw new StorageError(400, "invalid schedule item", "invalid_schedule_item");
520
+ }
490
521
  } else if (store === "sessions") {
491
- if (!required("noteId") || !required("blockId") || !positive("blockVersion") || row.public !== void 0 && typeof row.public !== "boolean" || row.notebookIds !== void 0 && (!Array.isArray(row.notebookIds) || !row.notebookIds.every((nb) => typeof nb === "string")) || ["segmentId", "segmentVersion", "version", "rawContent", "script", "serializedScript", "source", "data", "logs"].some((field) => field in row)) {
522
+ if (!required("noteId") || !required("blockId") || !positive("blockVersion") || row.noteSourceRevision !== void 0 && !positive("noteSourceRevision") || row.sessionDate !== void 0 && typeof row.sessionDate !== "string" || row.scheduleItemId !== void 0 && typeof row.scheduleItemId !== "string" || row.public !== void 0 && typeof row.public !== "boolean" || row.notebookIds !== void 0 && (!Array.isArray(row.notebookIds) || !row.notebookIds.every((nb) => typeof nb === "string")) || ["segmentId", "segmentVersion", "version", "rawContent", "script", "serializedScript", "source", "data", "logs"].some((field) => field in row)) {
492
523
  throw new StorageError(400, "Session requires immutable block pin", "invalid_session_pin");
493
524
  }
494
525
  } else if (!required("noteId") || !required("blockId") || !positive("blockVersion") || !positive("sourceRevision") || row.id !== `${row.noteId}:${row.blockId}` || !Number.isSafeInteger(row.from) || !Number.isSafeInteger(row.to) || "segmentId" in row || "segmentVersion" in row || !["wod", "query", "widget", "embed"].includes(String(row.dataType)) || typeof row.rawContent !== "string" || typeof row.noteTitle !== "string" || typeof row.from !== "number" || typeof row.to !== "number" || row.from < 0 || row.to <= row.from) {
@@ -714,9 +745,11 @@ var ApiStore = class {
714
745
  const userId = this.getUserId?.();
715
746
  const stored = userId ? stampUserOwned(this.store, value, userId) : value;
716
747
  const key = keyFromValue(this.def, stored);
717
- if (this.store === "block_revisions") {
748
+ if (this.store === "block_revisions" || this.store === "note_revisions") {
718
749
  const previous = this.buffer?.get(bufferSlot(this.store, key));
719
- if (previous?.kind === "put" && !rowsEqual(previous.value, stored)) throw new Error("immutable block revision collision");
750
+ if (previous?.kind === "put" && !rowsEqual(previous.value, stored)) {
751
+ throw new Error(this.store === "note_revisions" ? "immutable note revision collision" : "immutable block revision collision");
752
+ }
720
753
  }
721
754
  if (this.buffer) {
722
755
  this.buffer.set(bufferSlot(this.store, key), { kind: "put", value: stored });
@@ -739,7 +772,7 @@ var ApiStore = class {
739
772
  }
740
773
  async delete(key) {
741
774
  if (!this.mutable) throw new Error("read-only store");
742
- if (this.store === "block_revisions") throw new Error("block history requires explicit wipe");
775
+ if (this.store === "block_revisions" || this.store === "note_revisions") throw new Error("block history requires explicit wipe");
743
776
  const range = isRange(key) ? key : void 0;
744
777
  if (range) {
745
778
  if (this.buffer) {
@@ -762,7 +795,7 @@ var ApiStore = class {
762
795
  }
763
796
  async clear() {
764
797
  if (!this.mutable) throw new Error("read-only store");
765
- if (this.store === "block_revisions") throw new Error("block history requires explicit wipe");
798
+ if (this.store === "block_revisions" || this.store === "note_revisions") throw new Error("block history requires explicit wipe");
766
799
  if (this.buffer) {
767
800
  this.cleared?.add(this.store);
768
801
  const prefix = `${this.store}\0`;
@@ -886,7 +919,9 @@ var InMemoryStore = class {
886
919
  validateStorageRow(this.name, stored);
887
920
  const key = keyFromValue(this.def, stored), slot = JSON.stringify(key);
888
921
  const previous = this.rows.get(slot);
889
- if (this.name === "block_revisions" && previous !== void 0 && !rowsEqual(previous, stored)) throw new Error("immutable block revision collision");
922
+ if ((this.name === "block_revisions" || this.name === "note_revisions") && previous !== void 0 && !rowsEqual(previous, stored)) {
923
+ throw new Error(this.name === "note_revisions" ? "immutable note revision collision" : "immutable block revision collision");
924
+ }
890
925
  if (this.name === "notes") validateNoteWrite(previous, stored);
891
926
  if (this.name === "sessions") validateSessionWrite(previous, stored);
892
927
  if (rowsEqual(previous, stored)) return key;
@@ -910,7 +945,7 @@ var InMemoryStore = class {
910
945
  }
911
946
  async delete(key) {
912
947
  if (!this.mutable) throw new Error("read-only store");
913
- if (this.name === "block_revisions") throw new Error("block history requires explicit wipe");
948
+ if (this.name === "block_revisions" || this.name === "note_revisions") throw new Error("block history requires explicit wipe");
914
949
  if (this.commit) {
915
950
  await this.commit((store) => store.delete(key));
916
951
  return;
@@ -920,7 +955,7 @@ var InMemoryStore = class {
920
955
  }
921
956
  async clear() {
922
957
  if (!this.mutable) throw new Error("read-only store");
923
- if (this.name === "block_revisions") throw new Error("block history requires explicit wipe");
958
+ if (this.name === "block_revisions" || this.name === "note_revisions") throw new Error("block history requires explicit wipe");
924
959
  if (this.commit) {
925
960
  await this.commit((store) => store.clear());
926
961
  return;
@@ -961,7 +996,7 @@ var InMemoryStorage = class {
961
996
  this.options.getUserId,
962
997
  rows,
963
998
  true,
964
- (operation) => this.transaction([name, "block_revisions"], "readwrite", (tx) => operation(tx.readwrite(name)))
999
+ (operation) => this.transaction([name, "block_revisions", "note_revisions"], "readwrite", (tx) => operation(tx.readwrite(name)))
965
1000
  );
966
1001
  }
967
1002
  transaction(stores, mode, fn) {