@reddb-io/browser 0.6.0 → 0.7.0

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/README.md CHANGED
@@ -12,7 +12,7 @@ RedDB server, account, CDN or external API. Applications bundle the JS, worker
12
12
  and WASM assets and make them available locally or through their own offline
13
13
  application cache. Sync is optional and must never gate local reads or writes.
14
14
 
15
- Version `0.6.0` adds local database sessions for Dart/Flutter Web and retains reusable Worker sessions. Native `.rdb` backup export and restore remain available. It exposes local table SELECT, CREATE TABLE, INSERT, UPDATE, DELETE
15
+ Version `0.7.0` adds persisted catalog inspection and read-only, host-scoped SELECT, retaining local Dart/Flutter Web database sessions and reusable Workers. Native `.rdb` backup export and restore remain available. It exposes local table SELECT, CREATE TABLE, INSERT, UPDATE, DELETE
16
16
  and explicit BEGIN/COMMIT/ROLLBACK transactions through `openDatabase`.
17
17
  Other models, synchronization, conflict
18
18
  resolution and forwarding between tabs remain pending. The browser package
@@ -504,3 +504,22 @@ internal fixtures remain separate from application entrypoints.
504
504
  pending intent, identity separation, offline assets and the storage-status UI.
505
505
  5. Validate two-device sync and engine conformance, Safari/iOS on real devices,
506
506
  quota/failure cases, bundle size, startup, memory and query performance.
507
+
508
+ ## Embedded explorers and scoped reads
509
+
510
+ `database.catalog()` returns the persisted columns `table_name`, `column_name`,
511
+ `data_type` and `nullable`. It reads real contracts, including empty tables.
512
+
513
+ ```ts
514
+ const scopes = [{ table: 'files', field: 'tenant_id', value: 'campaign-1' }]
515
+ const result = await database.readQuery('SELECT name, body FROM files', [], scopes)
516
+ ```
517
+
518
+ The host supplies the allowed table and equality predicate. The canonical engine
519
+ filters source records before the caller's WHERE, ordering and limit. Only SELECT
520
+ is admitted; SQL cannot remove this filter or address an unlisted table. Empty
521
+ scopes deny all tables. This is a local inspection boundary, not a server user
522
+ session or RLS. The browser's file owner can still use the ordinary full SQL API.
523
+ Catalogs and scoped reads honor the same I/O health fence; an aborted explicit
524
+ transaction must roll back first. Source filtering uses canonical record
525
+ materialization and may temporarily allocate one record for each candidate.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reddb-io/browser",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "RedDB local browser table SQL, transactions and offline OPFS persistence through a shared Rust/WASM engine.",
package/src/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export interface RuntimeInfo {
16
16
  readonly transactions: boolean
17
17
  readonly queryParameters?: boolean
18
18
  readonly databaseBackups?: boolean
19
+ readonly databaseInspection?: boolean
19
20
  readonly sync: boolean
20
21
  }
21
22
  }
@@ -70,6 +71,10 @@ export function openArtifact(options: {
70
71
  export type QueryParameter = null | boolean | number | string | bigint
71
72
 
72
73
  export interface Database extends Runtime {
74
+ /** Persisted catalog columns: table_name, column_name, data_type, nullable. */
75
+ catalog(): Promise<{ columns: string[]; rows: unknown[][] }>
76
+ /** SELECT only, over the host's allowed tables and equality-filtered source rows. */
77
+ readQuery(sql: string, params: readonly QueryParameter[], scopes: readonly {table: string; field: string; value: QueryParameter}[]): Promise<{ columns: string[]; rows: unknown[][] }>
73
78
  /** SELECT and table SQL mutations; mutations return an affectedRows column. */
74
79
  query(sql: string, params?: readonly QueryParameter[]): Promise<{ columns: string[]; rows: unknown[][] }>
75
80
  /** Complete native .rdb image of committed state, at most 256 MiB. Pending SQL changes are excluded. */
package/src/index.js CHANGED
@@ -304,6 +304,11 @@ export async function restoreDatabase(options) {
304
304
  function databaseMethods(client) {
305
305
  return {
306
306
  ...runtimeMethods(client),
307
+ catalog: () => client.call('catalog'),
308
+ readQuery(sql, params, scopes) {
309
+ if (typeof sql !== 'string' || !Array.isArray(params) || params.length > MAX_QUERY_PARAMETERS || !Array.isArray(scopes) || scopes.length > 64) return Promise.reject(new BrowserError('INVALID_ARGUMENT', 'Expected SQL, parameters and at most 64 inspection scopes'))
310
+ return client.call('readQuery', { sql, params, scopes })
311
+ },
307
312
  query(sql, params) {
308
313
  if (typeof sql !== 'string') return Promise.reject(new BrowserError('INVALID_ARGUMENT', 'Expected an RQL string'))
309
314
  if (params === undefined) return client.call('query', { sql })
@@ -29,11 +29,13 @@ export class BrowserDatabase {
29
29
  private constructor();
30
30
  free(): void;
31
31
  [Symbol.dispose](): void;
32
+ catalog(): any;
32
33
  checkHealthy(): void;
33
34
  static create(handle: any, name: string, now_ms: number): BrowserDatabase;
34
35
  static open(handle: any, name: string): BrowserDatabase;
35
36
  query(sql: string, now_ms: number): any;
36
37
  queryWithParams(sql: string, params: Array<any>, now_ms: number): any;
38
+ readQuery(sql: string, params: Array<any>, scopes: Array<any>): any;
37
39
  }
38
40
 
39
41
  /**
@@ -61,11 +63,13 @@ export interface InitOutput {
61
63
  readonly browserartifact_open: (a: any, b: number, c: number) => [number, number, number];
62
64
  readonly browserartifact_readSnapshot: (a: number) => [number, number, number, number];
63
65
  readonly browserartifact_readWal: (a: number) => [number, number, number];
66
+ readonly browserdatabase_catalog: (a: number) => [number, number, number];
64
67
  readonly browserdatabase_checkHealthy: (a: number) => [number, number];
65
68
  readonly browserdatabase_create: (a: any, b: number, c: number, d: number) => [number, number, number];
66
69
  readonly browserdatabase_open: (a: any, b: number, c: number) => [number, number, number];
67
70
  readonly browserdatabase_query: (a: number, b: number, c: number, d: number) => [number, number, number];
68
71
  readonly browserdatabase_queryWithParams: (a: number, b: number, c: number, d: any, e: number) => [number, number, number];
72
+ readonly browserdatabase_readQuery: (a: number, b: number, c: number, d: any, e: any) => [number, number, number];
69
73
  readonly executeScalar: (a: number, b: number) => [number, number, number];
70
74
  readonly runtimeInfo: () => [number, number, number];
71
75
  readonly validateQuery: (a: number, b: number) => [number, number];
@@ -142,6 +142,16 @@ export class BrowserDatabase {
142
142
  const ptr = this.__destroy_into_raw();
143
143
  wasm.__wbg_browserdatabase_free(ptr, 0);
144
144
  }
145
+ /**
146
+ * @returns {any}
147
+ */
148
+ catalog() {
149
+ const ret = wasm.browserdatabase_catalog(this.__wbg_ptr);
150
+ if (ret[2]) {
151
+ throw takeFromExternrefTable0(ret[1]);
152
+ }
153
+ return takeFromExternrefTable0(ret[0]);
154
+ }
145
155
  checkHealthy() {
146
156
  const ret = wasm.browserdatabase_checkHealthy(this.__wbg_ptr);
147
157
  if (ret[1]) {
@@ -206,6 +216,21 @@ export class BrowserDatabase {
206
216
  }
207
217
  return takeFromExternrefTable0(ret[0]);
208
218
  }
219
+ /**
220
+ * @param {string} sql
221
+ * @param {Array<any>} params
222
+ * @param {Array<any>} scopes
223
+ * @returns {any}
224
+ */
225
+ readQuery(sql, params, scopes) {
226
+ const ptr0 = passStringToWasm0(sql, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
227
+ const len0 = WASM_VECTOR_LEN;
228
+ const ret = wasm.browserdatabase_readQuery(this.__wbg_ptr, ptr0, len0, params, scopes);
229
+ if (ret[2]) {
230
+ throw takeFromExternrefTable0(ret[1]);
231
+ }
232
+ return takeFromExternrefTable0(ret[0]);
233
+ }
209
234
  }
210
235
  if (Symbol.dispose) BrowserDatabase.prototype[Symbol.dispose] = BrowserDatabase.prototype.free;
211
236
 
@@ -287,6 +312,10 @@ function __wbg_get_imports() {
287
312
  const ret = arg0.getSize();
288
313
  return ret;
289
314
  }, arguments); },
315
+ __wbg_get_41476db20fef99a8: function() { return handleError(function (arg0, arg1) {
316
+ const ret = Reflect.get(arg0, arg1);
317
+ return ret;
318
+ }, arguments); },
290
319
  __wbg_get_unchecked_be562b1421656321: function(arg0, arg1) {
291
320
  const ret = arg0[arg1 >>> 0];
292
321
  return ret;
Binary file
@@ -10,11 +10,13 @@ export const browserartifact_generation: (a: number) => [number, number, number,
10
10
  export const browserartifact_open: (a: any, b: number, c: number) => [number, number, number];
11
11
  export const browserartifact_readSnapshot: (a: number) => [number, number, number, number];
12
12
  export const browserartifact_readWal: (a: number) => [number, number, number];
13
+ export const browserdatabase_catalog: (a: number) => [number, number, number];
13
14
  export const browserdatabase_checkHealthy: (a: number) => [number, number];
14
15
  export const browserdatabase_create: (a: any, b: number, c: number, d: number) => [number, number, number];
15
16
  export const browserdatabase_open: (a: any, b: number, c: number) => [number, number, number];
16
17
  export const browserdatabase_query: (a: number, b: number, c: number, d: number) => [number, number, number];
17
18
  export const browserdatabase_queryWithParams: (a: number, b: number, c: number, d: any, e: number) => [number, number, number];
19
+ export const browserdatabase_readQuery: (a: number, b: number, c: number, d: any, e: any) => [number, number, number];
18
20
  export const executeScalar: (a: number, b: number) => [number, number, number];
19
21
  export const runtimeInfo: () => [number, number, number];
20
22
  export const validateQuery: (a: number, b: number) => [number, number];
package/src/worker.js CHANGED
@@ -163,6 +163,15 @@ async function execute(method, params) {
163
163
  }
164
164
  if (!artifact && !database) throw error('CLOSED', 'The file is not open')
165
165
  if (database) {
166
+ if (method === 'catalog') {
167
+ if (typeof database.catalog !== 'function') throw error('VERSION_MISMATCH', 'WASM catalog inspection is missing')
168
+ return database.catalog()
169
+ }
170
+ if (method === 'readQuery') {
171
+ if (typeof params.sql !== 'string' || !Array.isArray(params.params) || params.params.length > MAX_QUERY_PARAMETERS || !Array.isArray(params.scopes) || params.scopes.length > 64) throw error('INVALID_ARGUMENT', 'Expected SQL, parameters and at most 64 inspection scopes')
172
+ if (typeof database.readQuery !== 'function') throw error('VERSION_MISMATCH', 'WASM scoped reads are missing')
173
+ return database.readQuery(params.sql, params.params, params.scopes)
174
+ }
166
175
  if (method === 'exportBackup') {
167
176
  try { return exportBackup() }
168
177
  catch (failure) {