@bitcobblers/wod-wiki-storage 0.35.2115 → 0.35.2117

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,5 +1,5 @@
1
1
  import { Client } from '@libsql/client';
2
- import { a as StoreDef, R as RangeDTO, K as KeyDTO, e as DomainQueryResult, E as TxOp, I as IStorage, S as StoreName, b as IReadOnlyStore, c as StoreType, d as IReadWriteStore, D as DomainQuery, f as IStorageTransaction } from '../wire-C7ZtlBKe.cjs';
2
+ import { a as StoreDef, R as RangeDTO, K as KeyDTO, e as DomainQueryResult, T as TxOp, I as IStorage, S as StoreName, b as IReadOnlyStore, c as StoreType, d as IReadWriteStore, D as DomainQuery, f as IStorageTransaction } from '../wire-Cfvz-I0h.cjs';
3
3
  import '@bitcobblers/wod-wiki-core';
4
4
  import '@bitcobblers/wod-wiki-lang';
5
5
 
@@ -30,9 +30,14 @@ declare class StorageError extends Error {
30
30
 
31
31
  type SqlValue = string | number | null;
32
32
  type SqlRow = Record<string, unknown>;
33
+ interface SqlStatement {
34
+ sql: string;
35
+ params?: SqlValue[];
36
+ }
33
37
  interface SqlConnection {
34
38
  query(sql: string, params?: SqlValue[]): Promise<SqlRow[]>;
35
39
  exec(sql: string, params?: SqlValue[]): Promise<void>;
40
+ batch?(statements: SqlStatement[]): Promise<SqlRow[][]>;
36
41
  }
37
42
  interface Database extends SqlConnection {
38
43
  readonly dialect: 'sqlite' | 'postgres';
@@ -57,8 +62,6 @@ declare function libsqlDatabase(client: LibsqlClient): Database;
57
62
  * is typed `ArrayBuffer | string`; strings pass through, and only the exact
58
63
  * two-key tag revives.
59
64
  */
60
- /** Serialize a row; when `binaryField` is set and holds an ArrayBuffer, it is
61
- * replaced by the lossless tag (shallow copy — the input row is untouched). */
62
65
  declare function encodeRowJson(value: unknown, binaryField?: string): string;
63
66
  /** Parse a row; when `binaryField` is set, a tagged value there revives as an
64
67
  * ArrayBuffer. Every other value — including tag-shaped data in other fields
@@ -76,55 +79,24 @@ declare function decodeRowJson<T = unknown>(text: string, binaryField?: string):
76
79
  declare const SCHEMA_TABLE = "_wodwiki_schema";
77
80
  declare function storeDefinition(name: string): StoreDef;
78
81
  declare function getRow(conn: SqlConnection, def: StoreDef, key: KeyDTO): Promise<unknown | undefined>;
82
+ declare function getRows(conn: SqlConnection, def: StoreDef, keys: KeyDTO[]): Promise<(unknown | undefined)[]>;
83
+ declare function listRowsFromIndexMany(conn: SqlConnection, def: StoreDef, indexName: string, keys: KeyDTO[]): Promise<unknown[][]>;
79
84
  declare function listRows(conn: SqlConnection, def: StoreDef, range?: RangeDTO, count?: number, indexName?: string): Promise<unknown[]>;
80
85
  declare function countRows(conn: SqlConnection, def: StoreDef, range?: RangeDTO, indexName?: string): Promise<number>;
86
+ declare function putRows(conn: SqlConnection, def: StoreDef, values: unknown[], changedKeys?: KeyDTO[]): Promise<KeyDTO[]>;
81
87
  declare function putRow(conn: SqlConnection, def: StoreDef, value: unknown): Promise<KeyDTO>;
82
88
  declare function deleteRows(conn: SqlConnection, def: StoreDef, keyOrRange: KeyDTO | RangeDTO): Promise<void>;
83
- declare function clearRows(conn: SqlConnection, def: StoreDef): Promise<void>;
89
+ declare function clearRows(conn: SqlConnection, def: StoreDef, wipe?: boolean): Promise<void>;
84
90
  /** Wipe all user stores; system stores (memberships) survive and the internal
85
91
  * schema metadata table is not a store, so the version guard is untouched. */
86
92
  declare function wipeRows(conn: SqlConnection): Promise<void>;
87
93
  /** Internal schema metadata is not exposed or cleared by the store API. */
88
94
  declare function initializeStore(db: Database): Promise<void>;
89
95
 
90
- /**
91
- * Domain read models + incremental projection refresh over the shared SQL
92
- * store tables.
93
- *
94
- * Three derived tables, rebuilt from the per-store source tables (source of
95
- * truth) when incompatible and refreshed per affected key inside the same
96
- * transaction as every mutation:
97
- * domain_note — note metadata selector + original payload
98
- * query_block — one occurrence row per block_index row, parent resolved by
99
- * exact noteId or sourcePath (ambiguous/orphan → NULL parent,
100
- * which gates ALL domain reads with 409 until healed)
101
- * segment_head — MAX(version) per segment id taken BEFORE the isHistory
102
- * filter, so a superseded revision can never resurrect
103
- *
104
- * Rebuilds are guarded: a `_wodwiki_schema` row stamps the projection
105
- * version, so repeated ready()/boot cycles skip the rebuild while the
106
- * derived shape is already compatible.
107
- *
108
- * Query plans are fixed and fully validated: every value is a bound parameter,
109
- * names come from this module, counts run before paging, and text matching is
110
- * a literal substring over JS-lowercased materialized columns (Unicode-exact;
111
- * instr/strpos never treat % or _ as wildcards).
112
- *
113
- * `journal` is materialized in JS (sourceMatches from the wql package — the
114
- * exact predicate the app applies) so no SQL regex re-implementation exists.
115
- */
96
+ /** Current Note and actionable-block SQL projections. */
116
97
 
117
- /**
118
- * Applies ops in order, collecting projection impact per affected key, then
119
- * refreshes derived rows — all on the caller's transaction. Returns one entry
120
- * per op: the put key, or null for delete/clear. `opts.deferProjection`
121
- * skips the per-key refresh pass; the caller MUST rebuild derived state in
122
- * the same transaction afterwards (see rebuildProjections) or reads will
123
- * operate on stale projections behind a valid guard.
124
- */
125
- declare function refreshDomain(conn: SqlConnection, ops: TxOp[], opts?: {
126
- deferProjection?: boolean;
127
- }): Promise<(KeyDTO | null)[]>;
98
+ /** Checks precede mutations; pins and projections commit with source rows. */
99
+ declare function refreshDomain(conn: SqlConnection, ops: TxOp[]): Promise<(KeyDTO | null)[]>;
128
100
  /**
129
101
  * Rebuild the derived tables from the source-of-truth store rows and stamp
130
102
  * the projection guard. Caller owns the transaction (atomicity) — the guard
@@ -141,20 +113,7 @@ declare const MAX_BODY: number;
141
113
  * SqlStorage.queryDomain share this entry). */
142
114
  declare function handleDomainQuery(db: Database, body: unknown): Promise<DomainQueryResult>;
143
115
 
144
- /**
145
- * SqlStorage — IStorage over the shared SQL store operations (server or
146
- * browser). Transactions buffer writes and flush them as one refreshDomain
147
- * pass inside a real SQL transaction: throw → rollback, success → commit,
148
- * and buffered reads overlay committed rows (read-your-writes). Projections
149
- * refresh inside the same transaction; bulkTransaction() batches a migration
150
- * into one rebuild instead of per-key refreshes. verifyWritable() proves the
151
- * backend accepts writes with a real INSERT that is rolled back.
152
- *
153
- * BrowserTursoStorage opens a direct-to-Turso backend via @libsql/client/web;
154
- * the constructor only builds the client (HTTP is connectionless), `ready()`
155
- * initializes schema + projections and every operation awaits it, so a
156
- * transient init failure never wedges the backend — ready() retries.
157
- */
116
+ /** SQL storage with atomic, change-scoped projections and buffered reads. */
158
117
 
159
118
  interface SqlStorageOptions {
160
119
  /** Rows in user-owned stores are stamped with this userId on write. Omit
@@ -182,11 +141,7 @@ declare class SqlStorage implements IStorage {
182
141
  readwrite<K extends StoreName>(store: K): IReadWriteStore<StoreType<K>>;
183
142
  queryDomain(query: DomainQuery): Promise<DomainQueryResult | undefined>;
184
143
  transaction<K extends StoreName, R>(stores: K[], mode: 'readonly' | 'readwrite', fn: (tx: IStorageTransaction) => Promise<R>): Promise<R>;
185
- /**
186
- * Bulk load for migration destinations: like transaction(), but the
187
- * buffered writes skip per-key projection refresh and derived state is
188
- * rebuilt once — everything inside one SQL transaction (throw → rollback).
189
- */
144
+ /** Bulk writes use the same affected-key refresh as ordinary transactions. */
190
145
  bulkTransaction<K extends StoreName, R>(stores: K[], fn: (tx: IStorageTransaction) => Promise<R>): Promise<R>;
191
146
  private runTx;
192
147
  /**
@@ -217,4 +172,4 @@ declare class BrowserTursoStorage extends SqlStorage {
217
172
  constructor(settings: TursoSettings, options?: SqlStorageOptions);
218
173
  }
219
174
 
220
- export { BrowserTursoStorage, type Database, type LibsqlClient, MAX_BODY, SCHEMA_TABLE, type SqlConnection, type SqlRow, SqlStorage, type SqlStorageOptions, type SqlValue, StorageError, type TursoSettings, clearRows, countRows, decodeRowJson, deleteRows, encodeRowJson, getRow, handleDomainQuery, initializeDomain, initializeStore, libsqlDatabase, listRows, putRow, rebuildProjections, refreshDomain, storeDefinition, validateTursoUrl, wipeDomain, wipeRows };
175
+ export { BrowserTursoStorage, type Database, type LibsqlClient, MAX_BODY, SCHEMA_TABLE, type SqlConnection, type SqlRow, type SqlStatement, SqlStorage, type SqlStorageOptions, type SqlValue, StorageError, type TursoSettings, clearRows, countRows, decodeRowJson, deleteRows, encodeRowJson, getRow, getRows, handleDomainQuery, initializeDomain, initializeStore, libsqlDatabase, listRows, listRowsFromIndexMany, putRow, putRows, rebuildProjections, refreshDomain, storeDefinition, validateTursoUrl, wipeDomain, wipeRows };
@@ -1,5 +1,5 @@
1
1
  import { Client } from '@libsql/client';
2
- import { a as StoreDef, R as RangeDTO, K as KeyDTO, e as DomainQueryResult, E as TxOp, I as IStorage, S as StoreName, b as IReadOnlyStore, c as StoreType, d as IReadWriteStore, D as DomainQuery, f as IStorageTransaction } from '../wire-C7ZtlBKe.js';
2
+ import { a as StoreDef, R as RangeDTO, K as KeyDTO, e as DomainQueryResult, T as TxOp, I as IStorage, S as StoreName, b as IReadOnlyStore, c as StoreType, d as IReadWriteStore, D as DomainQuery, f as IStorageTransaction } from '../wire-Cfvz-I0h.js';
3
3
  import '@bitcobblers/wod-wiki-core';
4
4
  import '@bitcobblers/wod-wiki-lang';
5
5
 
@@ -30,9 +30,14 @@ declare class StorageError extends Error {
30
30
 
31
31
  type SqlValue = string | number | null;
32
32
  type SqlRow = Record<string, unknown>;
33
+ interface SqlStatement {
34
+ sql: string;
35
+ params?: SqlValue[];
36
+ }
33
37
  interface SqlConnection {
34
38
  query(sql: string, params?: SqlValue[]): Promise<SqlRow[]>;
35
39
  exec(sql: string, params?: SqlValue[]): Promise<void>;
40
+ batch?(statements: SqlStatement[]): Promise<SqlRow[][]>;
36
41
  }
37
42
  interface Database extends SqlConnection {
38
43
  readonly dialect: 'sqlite' | 'postgres';
@@ -57,8 +62,6 @@ declare function libsqlDatabase(client: LibsqlClient): Database;
57
62
  * is typed `ArrayBuffer | string`; strings pass through, and only the exact
58
63
  * two-key tag revives.
59
64
  */
60
- /** Serialize a row; when `binaryField` is set and holds an ArrayBuffer, it is
61
- * replaced by the lossless tag (shallow copy — the input row is untouched). */
62
65
  declare function encodeRowJson(value: unknown, binaryField?: string): string;
63
66
  /** Parse a row; when `binaryField` is set, a tagged value there revives as an
64
67
  * ArrayBuffer. Every other value — including tag-shaped data in other fields
@@ -76,55 +79,24 @@ declare function decodeRowJson<T = unknown>(text: string, binaryField?: string):
76
79
  declare const SCHEMA_TABLE = "_wodwiki_schema";
77
80
  declare function storeDefinition(name: string): StoreDef;
78
81
  declare function getRow(conn: SqlConnection, def: StoreDef, key: KeyDTO): Promise<unknown | undefined>;
82
+ declare function getRows(conn: SqlConnection, def: StoreDef, keys: KeyDTO[]): Promise<(unknown | undefined)[]>;
83
+ declare function listRowsFromIndexMany(conn: SqlConnection, def: StoreDef, indexName: string, keys: KeyDTO[]): Promise<unknown[][]>;
79
84
  declare function listRows(conn: SqlConnection, def: StoreDef, range?: RangeDTO, count?: number, indexName?: string): Promise<unknown[]>;
80
85
  declare function countRows(conn: SqlConnection, def: StoreDef, range?: RangeDTO, indexName?: string): Promise<number>;
86
+ declare function putRows(conn: SqlConnection, def: StoreDef, values: unknown[], changedKeys?: KeyDTO[]): Promise<KeyDTO[]>;
81
87
  declare function putRow(conn: SqlConnection, def: StoreDef, value: unknown): Promise<KeyDTO>;
82
88
  declare function deleteRows(conn: SqlConnection, def: StoreDef, keyOrRange: KeyDTO | RangeDTO): Promise<void>;
83
- declare function clearRows(conn: SqlConnection, def: StoreDef): Promise<void>;
89
+ declare function clearRows(conn: SqlConnection, def: StoreDef, wipe?: boolean): Promise<void>;
84
90
  /** Wipe all user stores; system stores (memberships) survive and the internal
85
91
  * schema metadata table is not a store, so the version guard is untouched. */
86
92
  declare function wipeRows(conn: SqlConnection): Promise<void>;
87
93
  /** Internal schema metadata is not exposed or cleared by the store API. */
88
94
  declare function initializeStore(db: Database): Promise<void>;
89
95
 
90
- /**
91
- * Domain read models + incremental projection refresh over the shared SQL
92
- * store tables.
93
- *
94
- * Three derived tables, rebuilt from the per-store source tables (source of
95
- * truth) when incompatible and refreshed per affected key inside the same
96
- * transaction as every mutation:
97
- * domain_note — note metadata selector + original payload
98
- * query_block — one occurrence row per block_index row, parent resolved by
99
- * exact noteId or sourcePath (ambiguous/orphan → NULL parent,
100
- * which gates ALL domain reads with 409 until healed)
101
- * segment_head — MAX(version) per segment id taken BEFORE the isHistory
102
- * filter, so a superseded revision can never resurrect
103
- *
104
- * Rebuilds are guarded: a `_wodwiki_schema` row stamps the projection
105
- * version, so repeated ready()/boot cycles skip the rebuild while the
106
- * derived shape is already compatible.
107
- *
108
- * Query plans are fixed and fully validated: every value is a bound parameter,
109
- * names come from this module, counts run before paging, and text matching is
110
- * a literal substring over JS-lowercased materialized columns (Unicode-exact;
111
- * instr/strpos never treat % or _ as wildcards).
112
- *
113
- * `journal` is materialized in JS (sourceMatches from the wql package — the
114
- * exact predicate the app applies) so no SQL regex re-implementation exists.
115
- */
96
+ /** Current Note and actionable-block SQL projections. */
116
97
 
117
- /**
118
- * Applies ops in order, collecting projection impact per affected key, then
119
- * refreshes derived rows — all on the caller's transaction. Returns one entry
120
- * per op: the put key, or null for delete/clear. `opts.deferProjection`
121
- * skips the per-key refresh pass; the caller MUST rebuild derived state in
122
- * the same transaction afterwards (see rebuildProjections) or reads will
123
- * operate on stale projections behind a valid guard.
124
- */
125
- declare function refreshDomain(conn: SqlConnection, ops: TxOp[], opts?: {
126
- deferProjection?: boolean;
127
- }): Promise<(KeyDTO | null)[]>;
98
+ /** Checks precede mutations; pins and projections commit with source rows. */
99
+ declare function refreshDomain(conn: SqlConnection, ops: TxOp[]): Promise<(KeyDTO | null)[]>;
128
100
  /**
129
101
  * Rebuild the derived tables from the source-of-truth store rows and stamp
130
102
  * the projection guard. Caller owns the transaction (atomicity) — the guard
@@ -141,20 +113,7 @@ declare const MAX_BODY: number;
141
113
  * SqlStorage.queryDomain share this entry). */
142
114
  declare function handleDomainQuery(db: Database, body: unknown): Promise<DomainQueryResult>;
143
115
 
144
- /**
145
- * SqlStorage — IStorage over the shared SQL store operations (server or
146
- * browser). Transactions buffer writes and flush them as one refreshDomain
147
- * pass inside a real SQL transaction: throw → rollback, success → commit,
148
- * and buffered reads overlay committed rows (read-your-writes). Projections
149
- * refresh inside the same transaction; bulkTransaction() batches a migration
150
- * into one rebuild instead of per-key refreshes. verifyWritable() proves the
151
- * backend accepts writes with a real INSERT that is rolled back.
152
- *
153
- * BrowserTursoStorage opens a direct-to-Turso backend via @libsql/client/web;
154
- * the constructor only builds the client (HTTP is connectionless), `ready()`
155
- * initializes schema + projections and every operation awaits it, so a
156
- * transient init failure never wedges the backend — ready() retries.
157
- */
116
+ /** SQL storage with atomic, change-scoped projections and buffered reads. */
158
117
 
159
118
  interface SqlStorageOptions {
160
119
  /** Rows in user-owned stores are stamped with this userId on write. Omit
@@ -182,11 +141,7 @@ declare class SqlStorage implements IStorage {
182
141
  readwrite<K extends StoreName>(store: K): IReadWriteStore<StoreType<K>>;
183
142
  queryDomain(query: DomainQuery): Promise<DomainQueryResult | undefined>;
184
143
  transaction<K extends StoreName, R>(stores: K[], mode: 'readonly' | 'readwrite', fn: (tx: IStorageTransaction) => Promise<R>): Promise<R>;
185
- /**
186
- * Bulk load for migration destinations: like transaction(), but the
187
- * buffered writes skip per-key projection refresh and derived state is
188
- * rebuilt once — everything inside one SQL transaction (throw → rollback).
189
- */
144
+ /** Bulk writes use the same affected-key refresh as ordinary transactions. */
190
145
  bulkTransaction<K extends StoreName, R>(stores: K[], fn: (tx: IStorageTransaction) => Promise<R>): Promise<R>;
191
146
  private runTx;
192
147
  /**
@@ -217,4 +172,4 @@ declare class BrowserTursoStorage extends SqlStorage {
217
172
  constructor(settings: TursoSettings, options?: SqlStorageOptions);
218
173
  }
219
174
 
220
- export { BrowserTursoStorage, type Database, type LibsqlClient, MAX_BODY, SCHEMA_TABLE, type SqlConnection, type SqlRow, SqlStorage, type SqlStorageOptions, type SqlValue, StorageError, type TursoSettings, clearRows, countRows, decodeRowJson, deleteRows, encodeRowJson, getRow, handleDomainQuery, initializeDomain, initializeStore, libsqlDatabase, listRows, putRow, rebuildProjections, refreshDomain, storeDefinition, validateTursoUrl, wipeDomain, wipeRows };
175
+ export { BrowserTursoStorage, type Database, type LibsqlClient, MAX_BODY, SCHEMA_TABLE, type SqlConnection, type SqlRow, type SqlStatement, SqlStorage, type SqlStorageOptions, type SqlValue, StorageError, type TursoSettings, clearRows, countRows, decodeRowJson, deleteRows, encodeRowJson, getRow, getRows, handleDomainQuery, initializeDomain, initializeStore, libsqlDatabase, listRows, listRowsFromIndexMany, putRow, putRows, rebuildProjections, refreshDomain, storeDefinition, validateTursoUrl, wipeDomain, wipeRows };