@procedures/store 0.17.1 → 0.17.3

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.
@@ -28,8 +28,8 @@ export interface IdbDatabaseLike {
28
28
  createObjectStore(name: string, options?: {
29
29
  keyPath?: string;
30
30
  autoIncrement?: boolean;
31
- }): unknown;
32
- transaction(names: string, mode?: "readonly" | "readwrite"): IdbTransactionLike;
31
+ }): IdbObjectStoreLike;
32
+ transaction(names: string | string[], mode?: "readonly" | "readwrite"): IdbTransactionLike;
33
33
  close(): void;
34
34
  onversionchange: ((event: any) => void) | null;
35
35
  }
@@ -51,6 +51,30 @@ export interface IdbObjectStoreLike {
51
51
  add(value: unknown, key?: string): IdbRequestLike<unknown>;
52
52
  delete(key: string): IdbRequestLike<unknown>;
53
53
  clear(): IdbRequestLike<unknown>;
54
+ index(name: string): IdbIndexLike;
55
+ createIndex(name: string, keyPath: string, options?: {
56
+ unique?: boolean;
57
+ }): unknown;
58
+ }
59
+ /**
60
+ * An index of an object store. The results follow the order of the keys of the index. A record
61
+ * without the key path of the index is not in the index.
62
+ */
63
+ export interface IdbIndexLike {
64
+ /** The records, the first `count` of them when `count` is given. */
65
+ getAll(query?: null, count?: number): IdbRequestLike<unknown[]>;
66
+ /** The primary keys of the records, without their values. */
67
+ getAllKeys(query?: null, count?: number): IdbRequestLike<unknown[]>;
68
+ count(): IdbRequestLike<number>;
69
+ /** A cursor over the records. `"prev"` starts at the highest key of the index. */
70
+ openCursor(query?: null, direction?: "next" | "prev"): IdbRequestLike<IdbCursorLike | null>;
71
+ }
72
+ /** A cursor of an index, with the value of its record. */
73
+ export interface IdbCursorLike {
74
+ /** The key of the index. */
75
+ readonly key: unknown;
76
+ readonly value: unknown;
77
+ continue(): void;
54
78
  }
55
79
  /** The options of the IndexedDB stores. */
56
80
  export interface IndexedDbOptions {
@@ -66,21 +90,72 @@ export interface IndexedDbOptions {
66
90
  */
67
91
  export declare function hasIndexedDb(): boolean;
68
92
  /**
69
- * One object store in its own database, version 1. The connection opens at the first operation,
93
+ * This function calls `then` with the result of the request when the request succeeds. An error of
94
+ * `then` goes to `fail`, which aborts the transaction. Thus a check in a step of a transaction
95
+ * undoes each request of the transaction.
96
+ */
97
+ export declare function onResult<R>(request: IdbRequestLike<R>, fail: (error: unknown) => void, then: (result: R) => void): void;
98
+ /** An object store of a database, with its indexes. */
99
+ export interface IdbStoreSchema {
100
+ readonly name: string;
101
+ readonly options?: {
102
+ keyPath?: string;
103
+ autoIncrement?: boolean;
104
+ };
105
+ readonly indexes?: ReadonlyArray<{
106
+ readonly name: string;
107
+ readonly keyPath: string;
108
+ readonly unique?: boolean;
109
+ }>;
110
+ }
111
+ /**
112
+ * The work of one transaction. It makes the requests, and it gives a function that reads their
113
+ * results after the commit. `fail` aborts the transaction: the promise of the transaction then
114
+ * rejects with the error of `fail`, and each request is undone.
115
+ */
116
+ export type IdbWork<R> = (transaction: IdbTransactionLike, fail: (error: unknown) => void) => () => R;
117
+ /**
118
+ * One database, version 1, with its object stores. The connection opens at the first operation,
70
119
  * and a failed open tries again at the next operation.
71
120
  */
72
- export declare class IdbStoreConnection {
121
+ export declare class IdbConnection {
73
122
  /** The name of the database. */
74
123
  readonly database: string;
75
- /** The name of the object store. */
76
- readonly store: string;
77
- private readonly storeOptions;
124
+ /** The object stores of the database. */
125
+ private readonly stores;
78
126
  private readonly factory;
127
+ /** The function that writes the first records when the open makes the object stores. */
128
+ private readonly onCreate?;
79
129
  private connection;
80
130
  private closed;
81
131
  constructor(
82
132
  /** The name of the database. */
83
133
  database: string,
134
+ /** The object stores of the database. */
135
+ stores: readonly IdbStoreSchema[], factory: IdbFactoryLike | undefined,
136
+ /** The function that writes the first records when the open makes the object stores. */
137
+ onCreate?: ((store: (name: string) => IdbObjectStoreLike) => void) | undefined);
138
+ /**
139
+ * This method runs work in one transaction over the object stores of `names`. The promise resolves
140
+ * after the transaction commits, so a write is durable when the promise resolves. An error of a
141
+ * request, a throw of the work and a call of `fail` abort the transaction: each request is undone.
142
+ */
143
+ transaction<R>(mode: "readonly" | "readwrite", names: readonly string[], work: IdbWork<R>): Promise<R>;
144
+ /** This method closes the connection. A later operation throws. */
145
+ close(): Promise<void>;
146
+ private open;
147
+ private connect;
148
+ }
149
+ /** One object store in its own database, version 1. The stores of programs, queues and sync states use it. */
150
+ export declare class IdbStoreConnection {
151
+ /** The name of the database. */
152
+ readonly database: string;
153
+ /** The name of the object store. */
154
+ readonly store: string;
155
+ private readonly connection;
156
+ constructor(
157
+ /** The name of the database. */
158
+ database: string,
84
159
  /** The name of the object store. */
85
160
  store: string, storeOptions: {
86
161
  keyPath?: string;
@@ -94,7 +169,5 @@ export declare class IdbStoreConnection {
94
169
  run<R>(mode: "readonly" | "readwrite", work: (store: IdbObjectStoreLike) => () => R): Promise<R>;
95
170
  /** This method closes the connection. A later operation throws. */
96
171
  close(): Promise<void>;
97
- private open;
98
- private connect;
99
172
  }
100
173
  //# sourceMappingURL=idb.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"idb.d.ts","sourceRoot":"","sources":["../../src/indexeddb/idb.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,8BAA8B;AAC9B,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,SAAS,EAAE,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACzC,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CACxC;AAED,yCAAyC;AACzC,MAAM,WAAW,kBAAmB,SAAQ,cAAc,CAAC,eAAe,CAAC;IACzE,eAAe,EAAE,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CAChD;AAED,8DAA8D;AAC9D,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O,CAAC,CAAC,CAAC,CAuC3G;IAED,mEAAmE;IAC7D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAU3B;IAED,OAAO,CAAC,IAAI;IAYZ,OAAO,CAAC,OAAO;CA8ChB;AAED,8GAA8G;AAC9G,qBAAa,kBAAkB;IAI3B,gCAAgC;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,oCAAoC;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM;IANxB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAE3C;IACE,gCAAgC;IACvB,QAAQ,EAAE,MAAM;IACzB,oCAAoC;IAC3B,KAAK,EAAE,MAAM,EACtB,YAAY,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,OAAO,CAAA;KAAE,EAC3D,OAAO,EAAE,cAAc,GAAG,SAAS,EAGpC;IAED;;;;OAIG;IACH,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,GAAG,WAAW,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE/F;IAED,mEAAmE;IACnE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAErB;CACF"}
@@ -21,45 +21,80 @@ function errorOf(cause, message) {
21
21
  return cause instanceof Error ? cause : new Error(message, { cause });
22
22
  }
23
23
  /**
24
- * One object store in its own database, version 1. The connection opens at the first operation,
24
+ * This function calls `then` with the result of the request when the request succeeds. An error of
25
+ * `then` goes to `fail`, which aborts the transaction. Thus a check in a step of a transaction
26
+ * undoes each request of the transaction.
27
+ */
28
+ export function onResult(request, fail, then) {
29
+ request.onsuccess = () => {
30
+ try {
31
+ then(request.result);
32
+ }
33
+ catch (error) {
34
+ fail(error);
35
+ }
36
+ };
37
+ }
38
+ /**
39
+ * One database, version 1, with its object stores. The connection opens at the first operation,
25
40
  * and a failed open tries again at the next operation.
26
41
  */
27
- export class IdbStoreConnection {
42
+ export class IdbConnection {
28
43
  database;
29
- store;
30
- storeOptions;
44
+ stores;
31
45
  factory;
46
+ onCreate;
32
47
  connection;
33
48
  closed = false;
34
49
  constructor(
35
50
  /** The name of the database. */
36
51
  database,
37
- /** The name of the object store. */
38
- store, storeOptions, factory) {
52
+ /** The object stores of the database. */
53
+ stores, factory,
54
+ /** The function that writes the first records when the open makes the object stores. */
55
+ onCreate) {
39
56
  this.database = database;
40
- this.store = store;
41
- this.storeOptions = storeOptions;
57
+ this.stores = stores;
42
58
  this.factory = factory;
59
+ this.onCreate = onCreate;
43
60
  }
44
61
  /**
45
- * This method runs work in one transaction. The work makes the requests, and it gives a function that reads
46
- * their results. The promise resolves after the transaction commits, so a write is durable when
47
- * the promise resolves. An error of a request aborts the transaction: each request is undone.
62
+ * This method runs work in one transaction over the object stores of `names`. The promise resolves
63
+ * after the transaction commits, so a write is durable when the promise resolves. An error of a
64
+ * request, a throw of the work and a call of `fail` abort the transaction: each request is undone.
48
65
  */
49
- async run(mode, work) {
66
+ async transaction(mode, names, work) {
50
67
  const db = await this.open();
51
68
  return new Promise((resolve, reject) => {
52
69
  let transaction;
70
+ let failure;
71
+ const abort = () => {
72
+ try {
73
+ transaction?.abort();
74
+ }
75
+ catch {
76
+ // The transaction ended already
77
+ }
78
+ };
79
+ const fail = (error) => {
80
+ if (failure)
81
+ return;
82
+ failure = { error };
83
+ abort();
84
+ reject(error);
85
+ };
53
86
  let read;
54
87
  try {
55
- transaction = db.transaction(this.store, mode);
56
- read = work(transaction.objectStore(this.store));
88
+ transaction = db.transaction(names.length === 1 ? names[0] : [...names], mode);
89
+ read = work(transaction, fail);
57
90
  }
58
91
  catch (error) {
59
- reject(error);
92
+ // A request that the work made before the throw does not commit
93
+ fail(error);
60
94
  return;
61
95
  }
62
- transaction.oncomplete = () => {
96
+ const current = transaction;
97
+ current.oncomplete = () => {
63
98
  try {
64
99
  resolve(read());
65
100
  }
@@ -67,8 +102,8 @@ export class IdbStoreConnection {
67
102
  reject(error);
68
103
  }
69
104
  };
70
- transaction.onerror = () => reject(errorOf(transaction.error, `The IndexedDB transaction on ${this.database} failed`));
71
- transaction.onabort = () => reject(errorOf(transaction.error, `The IndexedDB transaction on ${this.database} was aborted`));
105
+ current.onerror = (event) => reject(failure ? failure.error : errorOf(event?.target?.error ?? current.error, `The IndexedDB transaction on ${this.database} failed`));
106
+ current.onabort = () => reject(failure ? failure.error : errorOf(current.error, `The IndexedDB transaction on ${this.database} was aborted`));
72
107
  });
73
108
  }
74
109
  /** This method closes the connection. A later operation throws. */
@@ -113,14 +148,30 @@ export class IdbStoreConnection {
113
148
  }
114
149
  request.onupgradeneeded = () => {
115
150
  const db = request.result;
116
- if (!db.objectStoreNames.contains(this.store))
117
- db.createObjectStore(this.store, this.storeOptions);
151
+ const created = new Map();
152
+ for (const schema of this.stores) {
153
+ if (db.objectStoreNames.contains(schema.name))
154
+ continue;
155
+ const store = db.createObjectStore(schema.name, schema.options ?? {});
156
+ for (const index of schema.indexes ?? [])
157
+ store.createIndex(index.name, index.keyPath, { unique: index.unique ?? false });
158
+ created.set(schema.name, store);
159
+ }
160
+ if (this.onCreate && created.size > 0) {
161
+ this.onCreate((name) => {
162
+ const store = created.get(name);
163
+ if (!store)
164
+ throw new Error(`The object store ${name} of ${this.database} existed before the open`);
165
+ return store;
166
+ });
167
+ }
118
168
  };
119
169
  request.onsuccess = () => {
120
170
  const db = request.result;
121
- if (!db.objectStoreNames.contains(this.store)) {
171
+ const missing = this.stores.find((schema) => !db.objectStoreNames.contains(schema.name));
172
+ if (missing) {
122
173
  db.close();
123
- reject(new Error(`The IndexedDB database ${this.database} exists, and it has no object store ${this.store}`));
174
+ reject(new Error(`The IndexedDB database ${this.database} exists, and it has no object store ${missing.name}`));
124
175
  return;
125
176
  }
126
177
  // Another tab wants a new version: close this connection, so the upgrade can run
@@ -134,4 +185,31 @@ export class IdbStoreConnection {
134
185
  });
135
186
  }
136
187
  }
188
+ /** One object store in its own database, version 1. The stores of programs, queues and sync states use it. */
189
+ export class IdbStoreConnection {
190
+ database;
191
+ store;
192
+ connection;
193
+ constructor(
194
+ /** The name of the database. */
195
+ database,
196
+ /** The name of the object store. */
197
+ store, storeOptions, factory) {
198
+ this.database = database;
199
+ this.store = store;
200
+ this.connection = new IdbConnection(database, [{ name: store, options: storeOptions }], factory);
201
+ }
202
+ /**
203
+ * This method runs work in one transaction. The work makes the requests, and it gives a function that reads
204
+ * their results. The promise resolves after the transaction commits, so a write is durable when
205
+ * the promise resolves. An error of a request aborts the transaction: each request is undone.
206
+ */
207
+ run(mode, work) {
208
+ return this.connection.transaction(mode, [this.store], (transaction) => work(transaction.objectStore(this.store)));
209
+ }
210
+ /** This method closes the connection. A later operation throws. */
211
+ close() {
212
+ return this.connection.close();
213
+ }
214
+ }
137
215
  //# sourceMappingURL=idb.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"idb.js","sourceRoot":"","sources":["../../src/indexeddb/idb.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA8DH,sGAAsG;AACtG,SAAS,aAAa;IACpB,OAAQ,UAA6C,CAAC,SAAS,IAAI,SAAS,CAAC;AAC/E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,aAAa,EAAE,KAAK,SAAS,CAAC;AACvC,CAAC;AAED,8DAA8D;AAC9D,SAAS,OAAO,CAAC,KAAc,EAAE,OAAe;IAC9C,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AACxE,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAMlB,QAAQ;IAER,KAAK;IACG,YAAY;IACZ,OAAO;IATlB,UAAU,CAAuC;IACjD,MAAM,GAAG,KAAK,CAAC;IAEvB;IACE,gCAAgC;IACvB,QAAgB;IACzB,oCAAoC;IAC3B,KAAa,EACL,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C;IAC3B,KAAa,EACtB,YAA2D,EAC3D,OAAmC;wBAJ1B,QAAQ;qBAER,KAAK;QAId,IAAI,CAAC,UAAU,GAAG,IAAI,aAAa,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IACnG,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAI,IAA8B,EAAE,IAA4C;QACjF,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACrH,CAAC;IAED,mEAAmE;IACnE,KAAK;QACH,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IACjC,CAAC;CACF"}
@@ -1,16 +1,21 @@
1
1
  /**
2
2
  * The entry `@procedures/store/indexeddb`: the stores of a browser (roadmap R45).
3
3
  *
4
+ * - `IndexedDbStorage` is a collection storage in IndexedDB (roadmap CLI-22). It is the durable
5
+ * local copy of a `HybridStorage` in a browser app without SignalDB.
4
6
  * - `IndexedDbProgramStore` keeps programs in IndexedDB.
5
7
  * - `IndexedDbQueueStore` keeps the queue of a `HybridStorage` in IndexedDB.
6
8
  * - `IndexedDbSyncStateStore` keeps the sync state of a `HybridStorage` in IndexedDB: the cursor
7
9
  * and the base versions (roadmap CLI-21).
8
10
  * - `MemoryProgramStore`, `MemoryQueueStore` and `MemorySyncStateStore` are the fallbacks for a
9
- * browser without IndexedDB. `hasIndexedDb()` tells which one to use.
11
+ * browser without IndexedDB. `hasIndexedDb()` tells which one to use. `InMemoryStorage` of
12
+ * `@procedures/collections` is the fallback of `IndexedDbStorage`.
10
13
  *
11
- * The package root does not import this entry, and this entry does not import the client or zod:
12
- * a page that loads it gets only these stores.
14
+ * The package root does not import this entry. This entry does not import the root of the client or
15
+ * zod: a page that loads it gets only these stores. It imports `@procedures/client/query`, a module
16
+ * without imports, and `@procedures/collections` (the contract of the storages and its listeners).
13
17
  */
18
+ export { IndexedDbStorage, type IndexedDbStorageOptions } from "./indexeddb/document-storage.js";
14
19
  export { IndexedDbProgramStore, DEFAULT_PROGRAM_DATABASE } from "./indexeddb/program-store.js";
15
20
  export { IndexedDbQueueStore } from "./indexeddb/queue-store.js";
16
21
  export { IndexedDbSyncStateStore } from "./indexeddb/sync-state-store.js";
@@ -1 +1 @@
1
- {"version":3,"file":"indexeddb.d.ts","sourceRoot":"","sources":["../src/indexeddb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC1F,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC5E,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"indexeddb.d.ts","sourceRoot":"","sources":["../src/indexeddb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AACjG,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC1F,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC5E,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/indexeddb.js CHANGED
@@ -1,16 +1,21 @@
1
1
  /**
2
2
  * The entry `@procedures/store/indexeddb`: the stores of a browser (roadmap R45).
3
3
  *
4
+ * - `IndexedDbStorage` is a collection storage in IndexedDB (roadmap CLI-22). It is the durable
5
+ * local copy of a `HybridStorage` in a browser app without SignalDB.
4
6
  * - `IndexedDbProgramStore` keeps programs in IndexedDB.
5
7
  * - `IndexedDbQueueStore` keeps the queue of a `HybridStorage` in IndexedDB.
6
8
  * - `IndexedDbSyncStateStore` keeps the sync state of a `HybridStorage` in IndexedDB: the cursor
7
9
  * and the base versions (roadmap CLI-21).
8
10
  * - `MemoryProgramStore`, `MemoryQueueStore` and `MemorySyncStateStore` are the fallbacks for a
9
- * browser without IndexedDB. `hasIndexedDb()` tells which one to use.
11
+ * browser without IndexedDB. `hasIndexedDb()` tells which one to use. `InMemoryStorage` of
12
+ * `@procedures/collections` is the fallback of `IndexedDbStorage`.
10
13
  *
11
- * The package root does not import this entry, and this entry does not import the client or zod:
12
- * a page that loads it gets only these stores.
14
+ * The package root does not import this entry. This entry does not import the root of the client or
15
+ * zod: a page that loads it gets only these stores. It imports `@procedures/client/query`, a module
16
+ * without imports, and `@procedures/collections` (the contract of the storages and its listeners).
13
17
  */
18
+ export { IndexedDbStorage } from "./indexeddb/document-storage.js";
14
19
  export { IndexedDbProgramStore, DEFAULT_PROGRAM_DATABASE } from "./indexeddb/program-store.js";
15
20
  export { IndexedDbQueueStore } from "./indexeddb/queue-store.js";
16
21
  export { IndexedDbSyncStateStore } from "./indexeddb/sync-state-store.js";
@@ -1 +1 @@
1
- {"version":3,"file":"indexeddb.js","sourceRoot":"","sources":["../src/indexeddb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAA8C,MAAM,oBAAoB,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"indexeddb.js","sourceRoot":"","sources":["../src/indexeddb.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,gBAAgB,EAAgC,MAAM,iCAAiC,CAAC;AACjG,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAA8C,MAAM,oBAAoB,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@procedures/store",
4
- "version": "0.17.1",
4
+ "version": "0.17.3",
5
5
  "description": "A program store for procedure-as-data: save the programs that procedure.define makes, load them back after a restart, in memory, a JSON file, IndexedDB or a remote collection storage.",
6
6
  "keywords": [
7
7
  "program-store",
@@ -78,12 +78,12 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "@mark1russell7/service": "^0.5.1",
81
- "@procedures/client": "0.17.1",
82
- "@procedures/collections": "0.17.1",
81
+ "@procedures/client": "0.17.3",
82
+ "@procedures/collections": "0.17.3",
83
83
  "zod": "^4.6.5"
84
84
  },
85
85
  "devDependencies": {
86
- "@procedures/fs": "0.17.1",
86
+ "@procedures/fs": "0.17.3",
87
87
  "@mark1russell7/cue": "^1.0.0",
88
88
  "@types/node": "^22.0.0",
89
89
  "fake-indexeddb": "^6.2.5",
package/src/browser.ts CHANGED
@@ -5,8 +5,8 @@
5
5
  * - `HybridStorage` keeps a local copy in front of a remote storage, with its errors and its types.
6
6
  * - `ApiStorage` is the remote storage over the collection procedures of a server.
7
7
  * - `EventsChangeFeed` pushes the remote changes to a `HybridStorage`.
8
- * - The entry also has all of `@procedures/store/indexeddb`: the IndexedDB stores and their
9
- * fallbacks in memory.
8
+ * - The entry also has all of `@procedures/store/indexeddb`: `IndexedDbStorage`, the IndexedDB
9
+ * stores and their fallbacks in memory.
10
10
  *
11
11
  * No module of this entry imports a module of Node, directly or through another module. The
12
12
  * modules import `@procedures/client/browser` and not the root of the client, because the root