@bitcobblers/wod-wiki-storage 0.55.2206 → 0.56.2210

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.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Membership, Note, Session, BlockRevision } from '@bitcobblers/wod-wiki-core';
2
2
  export { AnalyticsDataPoint, Attachment, BlockEffort, BlockEquipment, BlockIndexRow, BlockRevision, EventGrain, EventRecord, Membership, Note, NoteBlock, NoteBlockKind, NoteKind, NoteProvenance, NoteTag, NotebookLink, NotebookLinkTargetKind, OverridePropertyKind, Page, PageNote, ResultOrigin, ScopedPropertyOverride, Session, Tag, TagType, TagTypeRecord } from '@bitcobblers/wod-wiki-core';
3
- import { S as StoreName, I as IStorage, e as StoreDef, a as IReadOnlyStore, b as StoreType, c as IReadWriteStore, D as DomainQuery, f as DomainQueryResult, d as IStorageTransaction } from './wire-DPD-vJPP.js';
4
- export { C as COLUMN_TYPES, g as DB_VERSION, h as DOMAIN_PROJECTION_VERSION, i as DomainDetail, j as DomainOrder, k as DomainPredicate, l as IndexDef, K as KeyDTO, R as RangeDTO, m as STORE_DEFS, n as Scalar, o as StorageColumnType, p as StorageSchema, T as TxOp, q as compareKeys, r as encodeKey, s as extractKeyPart, t as isRange, u as keyFromValue, v as keyInRange, w as parseDomainQueryResult, x as rangeFromIDB } from './wire-DPD-vJPP.js';
5
- export { a as USER_DELETED_SEED_PREFIX, U as UserScopeContext, c as collectUserScopeContext, i as isSeedMetaKey, b as isUserOwnedRow, u as userDeletedSeedKey, d as userDeletedSeedNoteId } from './policy-HlkmPine.js';
3
+ import { S as StoreName, I as IStorage, e as StoreDef, a as IReadOnlyStore, b as StoreType, c as IReadWriteStore, D as DomainQuery, f as DomainQueryResult, d as IStorageTransaction } from './wire-sRdblNjM.js';
4
+ export { C as COLUMN_TYPES, g as DB_VERSION, h as DOMAIN_PROJECTION_VERSION, i as DomainDetail, j as DomainOrder, k as DomainPredicate, l as IndexDef, K as KeyDTO, R as RangeDTO, m as STORE_DEFS, n as Scalar, o as StorageColumnType, p as StorageSchema, T as TxOp, q as compareKeys, r as encodeKey, s as extractKeyPart, t as isRange, u as keyFromValue, v as keyInRange, w as parseDomainQueryResult, x as rangeFromIDB } from './wire-sRdblNjM.js';
5
+ export { a as USER_DELETED_SEED_PREFIX, U as UserScopeContext, c as collectUserScopeContext, i as isSeedMetaKey, b as isUserOwnedRow, u as userDeletedSeedKey, d as userDeletedSeedNoteId } from './policy-JQg92EFM.js';
6
6
  import '@bitcobblers/wod-wiki-lang';
7
7
 
8
8
  /**
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  export { USER_DELETED_SEED_PREFIX, collectUserScopeContext, isSeedMetaKey, isUserOwnedRow, userDeletedSeedKey, userDeletedSeedNoteId } from './chunk-AK7366MO.mjs';
2
- import { parseDomainQueryResult, bufferToOps, isDirty, bufferedGet, bufferSlot, overlayRows } from './chunk-SGZMJ4UK.mjs';
3
- export { DOMAIN_PROJECTION_VERSION, parseDomainQueryResult } from './chunk-SGZMJ4UK.mjs';
4
- import { STORE_DEFS, isRange, rangeFromIDB, keyFromValue, stampUserOwned, rowsEqual, encodeKey } from './chunk-SYGE26AO.mjs';
5
- export { COLUMN_TYPES, DB_VERSION, DEFAULT_MEMBERSHIP_ID, STORE_DEFS, USER_OWNED_STORES, compareKeys, createDefaultMembership, encodeKey, extractKeyPart, isRange, keyFromValue, keyInRange, rangeFromIDB, rowsEqual, stampUserOwned, validateNoteWrite, validateSessionWrite, validateStorageRow, validateStoredPins } from './chunk-SYGE26AO.mjs';
2
+ import { parseDomainQueryResult, bufferToOps, isDirty, bufferedGet, bufferSlot, overlayRows } from './chunk-S5RXBUSQ.mjs';
3
+ export { DOMAIN_PROJECTION_VERSION, parseDomainQueryResult } from './chunk-S5RXBUSQ.mjs';
4
+ import { STORE_DEFS, isRange, rangeFromIDB, keyFromValue, stampUserOwned, rowsEqual, encodeKey } from './chunk-325UJL7V.mjs';
5
+ export { COLUMN_TYPES, DB_VERSION, DEFAULT_MEMBERSHIP_ID, STORE_DEFS, USER_OWNED_STORES, compareKeys, createDefaultMembership, encodeKey, extractKeyPart, isRange, keyFromValue, keyInRange, rangeFromIDB, rowsEqual, stampUserOwned, validateNoteWrite, validateSessionWrite, validateStorageRow, validateStoredPins } from './chunk-325UJL7V.mjs';
6
6
  import './chunk-XRQKLSOT.mjs';
7
7
 
8
8
  // src/api.ts
@@ -1,4 +1,4 @@
1
- import { S as StoreName } from './wire-DPD-vJPP.cjs';
1
+ import { S as StoreName } from './wire-sRdblNjM.cjs';
2
2
 
3
3
  /**
4
4
  * Shared user-scope sync policy (the backup/restore contract in
@@ -1,4 +1,4 @@
1
- import { S as StoreName } from './wire-DPD-vJPP.js';
1
+ import { S as StoreName } from './wire-sRdblNjM.js';
2
2
 
3
3
  /**
4
4
  * Shared user-scope sync policy (the backup/restore contract in
@@ -124,7 +124,7 @@ function decodeRowJson(text2, binaryField) {
124
124
  }
125
125
 
126
126
  // src/schema.ts
127
- var DB_VERSION = 33;
127
+ var DB_VERSION = 34;
128
128
  var COLUMN_TYPES = {
129
129
  notes: { date: "number", createdAt: "number" },
130
130
  page: { createdAt: "number" },
@@ -182,6 +182,7 @@ var STORE_DEFS = [
182
182
  { name: "notes", keyPath: ["id"], indexes: [
183
183
  { name: "by-date", keyPath: ["date"] },
184
184
  { name: "by-created", keyPath: ["createdAt"] },
185
+ { name: "by-type", keyPath: ["type"] },
185
186
  { name: "by-user", keyPath: ["userId"] }
186
187
  ] },
187
188
  // 2. page
@@ -883,13 +884,28 @@ async function wipeRows(conn) {
883
884
  function tableListSql(dialect) {
884
885
  return dialect === "sqlite" ? `SELECT "name" FROM "sqlite_master" WHERE "type" = 'table'` : `SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = current_schema()`;
885
886
  }
887
+ async function existingColumnSet(conn, dialect, tableName) {
888
+ if (dialect === "sqlite") {
889
+ const rows2 = await conn.query(`PRAGMA table_info("${tableName}")`);
890
+ return new Set(rows2.map((r) => String(r.name)));
891
+ }
892
+ const rows = await conn.query(
893
+ `SELECT "column_name" FROM "information_schema"."columns" WHERE "table_schema" = current_schema() AND "table_name" = ?`,
894
+ [tableName]
895
+ );
896
+ return new Set(rows.map((r) => String(r.column_name)));
897
+ }
886
898
  async function ensureStoreTables(conn, dialect, def) {
887
899
  const keys = keyCols(def);
888
900
  const cols = keys.map((k, i) => [k, colSql(dialect, pathType(def, def.keyPath[i]))]);
901
+ const indexedParts = [];
889
902
  for (const idx of def.indexes) {
890
903
  if (idx.multiEntry) continue;
891
904
  idx.keyPath.forEach((path, part) => {
892
- cols.push([indexCol(idx.name, part), colSql(dialect, pathType(def, path))]);
905
+ const col = indexCol(idx.name, part);
906
+ const typeSql = colSql(dialect, pathType(def, path));
907
+ cols.push([col, typeSql]);
908
+ indexedParts.push({ col, path, typeSql });
893
909
  });
894
910
  }
895
911
  cols.push(["data", " TEXT NOT NULL"]);
@@ -897,6 +913,26 @@ async function ensureStoreTables(conn, dialect, def) {
897
913
  await conn.exec(
898
914
  `CREATE TABLE IF NOT EXISTS "${def.name}" (${colDefs.join(", ")}, PRIMARY KEY (${keys.map((k) => `"${k}"`).join(", ")}))`
899
915
  );
916
+ if (indexedParts.length > 0) {
917
+ const existingCols = await existingColumnSet(conn, dialect, def.name);
918
+ const addedParts = indexedParts.filter((p) => !existingCols.has(p.col));
919
+ if (addedParts.length > 0) {
920
+ for (const part of addedParts) {
921
+ await conn.exec(`ALTER TABLE "${def.name}" ADD COLUMN "${part.col}"${part.typeSql}`);
922
+ }
923
+ const keySelect = keys.map((k) => `"${k}"`).join(", ");
924
+ const keyWhere = keys.map((k) => `"${k}" = ?`).join(" AND ");
925
+ const setClause = addedParts.map((p) => `"${p.col}" = ?`).join(", ");
926
+ const rows = await conn.query(`SELECT ${keySelect}, "data" FROM "${def.name}"`);
927
+ for (const row of rows) {
928
+ const decoded = decodeRowJson(String(row.data), binaryFieldOf(def));
929
+ const values = addedParts.map((p) => toSqlScalar(extractKeyPart(decoded, p.path)));
930
+ if (values.every((v) => v === null)) continue;
931
+ const keyValues = keys.map((k) => toSqlScalar(row[k]));
932
+ await conn.exec(`UPDATE "${def.name}" SET ${setClause} WHERE ${keyWhere}`, [...values, ...keyValues]);
933
+ }
934
+ }
935
+ }
900
936
  for (const idx of def.indexes) {
901
937
  if (idx.multiEntry) continue;
902
938
  const parts = idx.keyPath.map((_, part) => `"${indexCol(idx.name, part)}"`).join(", ");