preact-missing-hooks 3.0.0 → 4.0.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.
Files changed (79) hide show
  1. package/.husky/pre-commit +1 -0
  2. package/.husky/pre-push +1 -0
  3. package/.prettierignore +3 -0
  4. package/.prettierrc +6 -0
  5. package/Readme.md +179 -131
  6. package/dist/entry.cjs +21 -0
  7. package/dist/entry.js +2 -0
  8. package/dist/entry.js.map +1 -0
  9. package/dist/entry.modern.mjs +2 -0
  10. package/dist/entry.modern.mjs.map +1 -0
  11. package/dist/entry.module.js +2 -0
  12. package/dist/entry.module.js.map +1 -0
  13. package/dist/entry.umd.js +2 -0
  14. package/dist/entry.umd.js.map +1 -0
  15. package/dist/index.d.ts +13 -12
  16. package/dist/index.js +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.modern.mjs +2 -0
  19. package/dist/index.modern.mjs.map +1 -0
  20. package/dist/index.module.js +1 -1
  21. package/dist/index.module.js.map +1 -1
  22. package/dist/index.umd.js +1 -1
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/indexedDB/dbController.d.ts +2 -2
  25. package/dist/indexedDB/index.d.ts +6 -6
  26. package/dist/indexedDB/openDB.d.ts +1 -1
  27. package/dist/indexedDB/tableController.d.ts +1 -1
  28. package/dist/indexedDB/types.d.ts +1 -2
  29. package/dist/react.js +1 -0
  30. package/dist/react.modern.mjs +1 -0
  31. package/dist/react.module.js +1 -0
  32. package/dist/react.umd.js +1 -0
  33. package/dist/useEventBus.d.ts +1 -1
  34. package/dist/useIndexedDB.d.ts +3 -3
  35. package/dist/useMutationObserver.d.ts +1 -1
  36. package/dist/useNetworkState.d.ts +3 -3
  37. package/dist/usePreferredTheme.d.ts +1 -1
  38. package/dist/useRageClick.d.ts +1 -1
  39. package/dist/useThreadedWorker.d.ts +1 -1
  40. package/dist/useTransition.d.ts +4 -1
  41. package/dist/useWorkerNotifications.d.ts +57 -0
  42. package/dist/useWrappedChildren.d.ts +3 -3
  43. package/{demo → docs}/index.html +56 -0
  44. package/{demo → docs}/main.js +437 -312
  45. package/eslint.config.mjs +10 -0
  46. package/package.json +65 -6
  47. package/scripts/generate-entry.cjs +34 -0
  48. package/src/index.ts +13 -12
  49. package/src/indexedDB/dbController.ts +101 -92
  50. package/src/indexedDB/index.ts +16 -11
  51. package/src/indexedDB/openDB.ts +49 -49
  52. package/src/indexedDB/requestToPromise.ts +17 -16
  53. package/src/indexedDB/tableController.ts +331 -257
  54. package/src/indexedDB/types.ts +35 -35
  55. package/src/useClipboard.ts +99 -97
  56. package/src/useEventBus.ts +39 -36
  57. package/src/useIndexedDB.ts +111 -111
  58. package/src/useMutationObserver.ts +26 -26
  59. package/src/useNetworkState.ts +124 -122
  60. package/src/usePreferredTheme.ts +68 -68
  61. package/src/useRageClick.ts +103 -103
  62. package/src/useThreadedWorker.ts +165 -165
  63. package/src/useTransition.ts +22 -19
  64. package/src/useWasmCompute.ts +209 -204
  65. package/src/useWebRTCIP.ts +181 -176
  66. package/src/useWorkerNotifications.ts +203 -0
  67. package/src/useWrappedChildren.ts +72 -58
  68. package/tests/react-adapter.tsx +12 -0
  69. package/tests/setup-react.ts +4 -0
  70. package/tests/useClipboard.test.tsx +4 -2
  71. package/tests/useThreadedWorker.test.tsx +3 -1
  72. package/tests/useWasmCompute.test.tsx +1 -1
  73. package/tests/useWebRTCIP.test.tsx +3 -1
  74. package/tests/useWorkerNotifications.test.tsx +170 -0
  75. package/vite.config.ts +11 -4
  76. package/vitest.config.preact.ts +20 -0
  77. package/vitest.config.react.ts +36 -0
  78. package/vitest.workspace.ts +6 -0
  79. /package/{demo → docs}/add.wasm +0 -0
@@ -1,257 +1,331 @@
1
- /**
2
- * Table controller: insert, update, delete, exists, query, upsert, bulkInsert, clear, count.
3
- * Works in standalone mode (opens its own transaction per op) or bound to a transaction.
4
- * @module indexedDB/tableController
5
- */
6
-
7
- import type { OperationCallbacks } from './types';
8
- import { requestToPromise } from './requestToPromise';
9
-
10
- /** Runs optional callbacks and returns the result. */
11
- function withCallbacks<T>(
12
- promise: Promise<T>,
13
- options?: OperationCallbacks<T>
14
- ): Promise<T> {
15
- if (!options) return promise;
16
- return promise
17
- .then((result) => {
18
- options.onSuccess?.(result);
19
- return result;
20
- })
21
- .catch((err: DOMException) => {
22
- options.onError?.(err);
23
- throw err;
24
- });
25
- }
26
-
27
- /**
28
- * Standalone table controller: opens a new transaction for each operation.
29
- */
30
- function createStandaloneController(db: IDBDatabase, tableName: string): ITableController {
31
- function getStore(mode: IDBTransactionMode): IDBObjectStore {
32
- const tx = db.transaction([tableName], mode);
33
- return tx.objectStore(tableName);
34
- }
35
-
36
- return {
37
- insert<T>(data: T, options?: OperationCallbacks<IDBValidKey>): Promise<IDBValidKey> {
38
- const store = getStore('readwrite');
39
- return withCallbacks(requestToPromise(store.add(data)), options);
40
- },
41
-
42
- update<T>(key: IDBValidKey, updates: Partial<T>, options?: OperationCallbacks<void>): Promise<void> {
43
- const store = getStore('readwrite');
44
- const getReq = store.get(key);
45
- return withCallbacks(
46
- requestToPromise(getReq).then((existing) => {
47
- if (existing === undefined) {
48
- throw new DOMException('Key not found', 'NotFoundError');
49
- }
50
- const merged = { ...existing, ...updates } as T;
51
- return requestToPromise(store.put(merged));
52
- }).then(() => undefined),
53
- options
54
- );
55
- },
56
-
57
- delete(key: IDBValidKey, options?: OperationCallbacks<void>): Promise<void> {
58
- const store = getStore('readwrite');
59
- return withCallbacks(
60
- requestToPromise(store.delete(key)).then(() => undefined),
61
- options
62
- );
63
- },
64
-
65
- exists(key: IDBValidKey): Promise<boolean> {
66
- const store = getStore('readonly');
67
- return requestToPromise(store.getKey(key)).then((k) => k !== undefined);
68
- },
69
-
70
- query<T>(filterFn: (item: T) => boolean, options?: OperationCallbacks<T[]>): Promise<T[]> {
71
- const store = getStore('readonly');
72
- const request = store.openCursor();
73
- const results: T[] = [];
74
- return withCallbacks(
75
- new Promise<T[]>((resolve, reject) => {
76
- request.onsuccess = () => {
77
- const cursor = request.result;
78
- if (cursor) {
79
- if (filterFn(cursor.value as T)) results.push(cursor.value as T);
80
- cursor.continue();
81
- } else {
82
- resolve(results);
83
- }
84
- };
85
- request.onerror = () => reject(request.error ?? new DOMException('Unknown error'));
86
- }),
87
- options
88
- );
89
- },
90
-
91
- upsert<T>(data: T, options?: OperationCallbacks<IDBValidKey>): Promise<IDBValidKey> {
92
- const store = getStore('readwrite');
93
- return withCallbacks(requestToPromise(store.put(data)), options);
94
- },
95
-
96
- bulkInsert<T>(items: T[], options?: OperationCallbacks<IDBValidKey[]>): Promise<IDBValidKey[]> {
97
- const store = getStore('readwrite');
98
- const keys: IDBValidKey[] = [];
99
- if (items.length === 0) {
100
- return withCallbacks(Promise.resolve(keys), options);
101
- }
102
- let completed = 0;
103
- const promise = new Promise<IDBValidKey[]>((resolve, reject) => {
104
- const onDone = () => {
105
- completed++;
106
- if (completed === items.length) resolve(keys);
107
- };
108
- items.forEach((item, i) => {
109
- const req = store.add(item);
110
- req.onsuccess = () => {
111
- keys[i] = req.result;
112
- onDone();
113
- };
114
- req.onerror = () => reject(req.error ?? new DOMException('Unknown error'));
115
- });
116
- });
117
- return withCallbacks(promise, options);
118
- },
119
-
120
- clear(options?: OperationCallbacks<void>): Promise<void> {
121
- const store = getStore('readwrite');
122
- return withCallbacks(
123
- requestToPromise(store.clear()).then(() => undefined),
124
- options
125
- );
126
- },
127
-
128
- count(options?: OperationCallbacks<number>): Promise<number> {
129
- const store = getStore('readonly');
130
- return withCallbacks(requestToPromise(store.count()), options ?? {});
131
- },
132
- };
133
- }
134
-
135
- /**
136
- * Transaction-scoped table controller: uses the given transaction (no new transaction).
137
- */
138
- function createTransactionController(tx: IDBTransaction, tableName: string): ITableController {
139
- function getStore(): IDBObjectStore {
140
- return tx.objectStore(tableName);
141
- }
142
-
143
- return {
144
- insert<T>(data: T, options?: OperationCallbacks<IDBValidKey>): Promise<IDBValidKey> {
145
- const store = getStore();
146
- return withCallbacks(requestToPromise(store.add(data)), options);
147
- },
148
-
149
- update<T>(key: IDBValidKey, updates: Partial<T>, options?: OperationCallbacks<void>): Promise<void> {
150
- const store = getStore();
151
- return withCallbacks(
152
- requestToPromise(store.get(key)).then((existing) => {
153
- if (existing === undefined) {
154
- throw new DOMException('Key not found', 'NotFoundError');
155
- }
156
- const merged = { ...existing, ...updates } as T;
157
- return requestToPromise(store.put(merged));
158
- }).then(() => undefined),
159
- options
160
- );
161
- },
162
-
163
- delete(key: IDBValidKey, options?: OperationCallbacks<void>): Promise<void> {
164
- const store = getStore();
165
- return withCallbacks(
166
- requestToPromise(store.delete(key)).then(() => undefined),
167
- options
168
- );
169
- },
170
-
171
- exists(key: IDBValidKey): Promise<boolean> {
172
- const store = getStore();
173
- return requestToPromise(store.getKey(key)).then((k) => k !== undefined);
174
- },
175
-
176
- query<T>(filterFn: (item: T) => boolean, options?: OperationCallbacks<T[]>): Promise<T[]> {
177
- const store = getStore();
178
- const request = store.openCursor();
179
- const results: T[] = [];
180
- return withCallbacks(
181
- new Promise<T[]>((resolve, reject) => {
182
- request.onsuccess = () => {
183
- const cursor = request.result;
184
- if (cursor) {
185
- if (filterFn(cursor.value as T)) results.push(cursor.value as T);
186
- cursor.continue();
187
- } else {
188
- resolve(results);
189
- }
190
- };
191
- request.onerror = () => reject(request.error ?? new DOMException('Unknown error'));
192
- }),
193
- options
194
- );
195
- },
196
-
197
- upsert<T>(data: T, options?: OperationCallbacks<IDBValidKey>): Promise<IDBValidKey> {
198
- const store = getStore();
199
- return withCallbacks(requestToPromise(store.put(data)), options);
200
- },
201
-
202
- bulkInsert<T>(items: T[], options?: OperationCallbacks<IDBValidKey[]>): Promise<IDBValidKey[]> {
203
- const store = getStore();
204
- const keys: IDBValidKey[] = [];
205
- if (items.length === 0) {
206
- return withCallbacks(Promise.resolve(keys), options);
207
- }
208
- let completed = 0;
209
- const promise = new Promise<IDBValidKey[]>((resolve, reject) => {
210
- items.forEach((item, i) => {
211
- const req = store.add(item);
212
- req.onsuccess = () => {
213
- keys[i] = req.result;
214
- completed++;
215
- if (completed === items.length) resolve(keys);
216
- };
217
- req.onerror = () => reject(req.error ?? new DOMException('Unknown error'));
218
- });
219
- });
220
- return withCallbacks(promise, options);
221
- },
222
-
223
- clear(options?: OperationCallbacks<void>): Promise<void> {
224
- const store = getStore();
225
- return withCallbacks(
226
- requestToPromise(store.clear()).then(() => undefined),
227
- options
228
- );
229
- },
230
-
231
- count(options?: OperationCallbacks<number>): Promise<number> {
232
- const store = getStore();
233
- return withCallbacks(requestToPromise(store.count()), options ?? {});
234
- },
235
- };
236
- }
237
-
238
- /** Public interface for a table controller (standalone or transaction-scoped). */
239
- export interface ITableController {
240
- insert<T>(data: T, options?: OperationCallbacks<IDBValidKey>): Promise<IDBValidKey>;
241
- update<T>(key: IDBValidKey, updates: Partial<T>, options?: OperationCallbacks<void>): Promise<void>;
242
- delete(key: IDBValidKey, options?: OperationCallbacks<void>): Promise<void>;
243
- exists(key: IDBValidKey): Promise<boolean>;
244
- query<T>(filterFn: (item: T) => boolean, options?: OperationCallbacks<T[]>): Promise<T[]>;
245
- upsert<T>(data: T, options?: OperationCallbacks<IDBValidKey>): Promise<IDBValidKey>;
246
- bulkInsert<T>(items: T[], options?: OperationCallbacks<IDBValidKey[]>): Promise<IDBValidKey[]>;
247
- clear(options?: OperationCallbacks<void>): Promise<void>;
248
- count(options?: OperationCallbacks<number>): Promise<number>;
249
- }
250
-
251
- export function createTableController(db: IDBDatabase, tableName: string): ITableController {
252
- return createStandaloneController(db, tableName);
253
- }
254
-
255
- export function createTransactionTableController(tx: IDBTransaction, tableName: string): ITableController {
256
- return createTransactionController(tx, tableName);
257
- }
1
+ /**
2
+ * Table controller: insert, update, delete, exists, query, upsert, bulkInsert, clear, count.
3
+ * Works in standalone mode (opens its own transaction per op) or bound to a transaction.
4
+ * @module indexedDB/tableController
5
+ */
6
+
7
+ import type { OperationCallbacks } from "./types";
8
+ import { requestToPromise } from "./requestToPromise";
9
+
10
+ /** Runs optional callbacks and returns the result. */
11
+ function withCallbacks<T>(
12
+ promise: Promise<T>,
13
+ options?: OperationCallbacks<T>
14
+ ): Promise<T> {
15
+ if (!options) return promise;
16
+ return promise
17
+ .then((result) => {
18
+ options.onSuccess?.(result);
19
+ return result;
20
+ })
21
+ .catch((err: DOMException) => {
22
+ options.onError?.(err);
23
+ throw err;
24
+ });
25
+ }
26
+
27
+ /**
28
+ * Standalone table controller: opens a new transaction for each operation.
29
+ */
30
+ function createStandaloneController(
31
+ db: IDBDatabase,
32
+ tableName: string
33
+ ): ITableController {
34
+ function getStore(mode: IDBTransactionMode): IDBObjectStore {
35
+ const tx = db.transaction([tableName], mode);
36
+ return tx.objectStore(tableName);
37
+ }
38
+
39
+ return {
40
+ insert<T>(
41
+ data: T,
42
+ options?: OperationCallbacks<IDBValidKey>
43
+ ): Promise<IDBValidKey> {
44
+ const store = getStore("readwrite");
45
+ return withCallbacks(requestToPromise(store.add(data)), options);
46
+ },
47
+
48
+ update<T>(
49
+ key: IDBValidKey,
50
+ updates: Partial<T>,
51
+ options?: OperationCallbacks<void>
52
+ ): Promise<void> {
53
+ const store = getStore("readwrite");
54
+ const getReq = store.get(key);
55
+ return withCallbacks(
56
+ requestToPromise(getReq)
57
+ .then((existing) => {
58
+ if (existing === undefined) {
59
+ throw new DOMException("Key not found", "NotFoundError");
60
+ }
61
+ const merged = { ...existing, ...updates } as T;
62
+ return requestToPromise(store.put(merged));
63
+ })
64
+ .then(() => undefined),
65
+ options
66
+ );
67
+ },
68
+
69
+ delete(
70
+ key: IDBValidKey,
71
+ options?: OperationCallbacks<void>
72
+ ): Promise<void> {
73
+ const store = getStore("readwrite");
74
+ return withCallbacks(
75
+ requestToPromise(store.delete(key)).then(() => undefined),
76
+ options
77
+ );
78
+ },
79
+
80
+ exists(key: IDBValidKey): Promise<boolean> {
81
+ const store = getStore("readonly");
82
+ return requestToPromise(store.getKey(key)).then((k) => k !== undefined);
83
+ },
84
+
85
+ query<T>(
86
+ filterFn: (item: T) => boolean,
87
+ options?: OperationCallbacks<T[]>
88
+ ): Promise<T[]> {
89
+ const store = getStore("readonly");
90
+ const request = store.openCursor();
91
+ const results: T[] = [];
92
+ return withCallbacks(
93
+ new Promise<T[]>((resolve, reject) => {
94
+ request.onsuccess = () => {
95
+ const cursor = request.result;
96
+ if (cursor) {
97
+ if (filterFn(cursor.value as T)) results.push(cursor.value as T);
98
+ cursor.continue();
99
+ } else {
100
+ resolve(results);
101
+ }
102
+ };
103
+ request.onerror = () =>
104
+ reject(request.error ?? new DOMException("Unknown error"));
105
+ }),
106
+ options
107
+ );
108
+ },
109
+
110
+ upsert<T>(
111
+ data: T,
112
+ options?: OperationCallbacks<IDBValidKey>
113
+ ): Promise<IDBValidKey> {
114
+ const store = getStore("readwrite");
115
+ return withCallbacks(requestToPromise(store.put(data)), options);
116
+ },
117
+
118
+ bulkInsert<T>(
119
+ items: T[],
120
+ options?: OperationCallbacks<IDBValidKey[]>
121
+ ): Promise<IDBValidKey[]> {
122
+ const store = getStore("readwrite");
123
+ const keys: IDBValidKey[] = [];
124
+ if (items.length === 0) {
125
+ return withCallbacks(Promise.resolve(keys), options);
126
+ }
127
+ let completed = 0;
128
+ const promise = new Promise<IDBValidKey[]>((resolve, reject) => {
129
+ const onDone = () => {
130
+ completed++;
131
+ if (completed === items.length) resolve(keys);
132
+ };
133
+ items.forEach((item, i) => {
134
+ const req = store.add(item);
135
+ req.onsuccess = () => {
136
+ keys[i] = req.result;
137
+ onDone();
138
+ };
139
+ req.onerror = () =>
140
+ reject(req.error ?? new DOMException("Unknown error"));
141
+ });
142
+ });
143
+ return withCallbacks(promise, options);
144
+ },
145
+
146
+ clear(options?: OperationCallbacks<void>): Promise<void> {
147
+ const store = getStore("readwrite");
148
+ return withCallbacks(
149
+ requestToPromise(store.clear()).then(() => undefined),
150
+ options
151
+ );
152
+ },
153
+
154
+ count(options?: OperationCallbacks<number>): Promise<number> {
155
+ const store = getStore("readonly");
156
+ return withCallbacks(requestToPromise(store.count()), options ?? {});
157
+ },
158
+ };
159
+ }
160
+
161
+ /**
162
+ * Transaction-scoped table controller: uses the given transaction (no new transaction).
163
+ */
164
+ function createTransactionController(
165
+ tx: IDBTransaction,
166
+ tableName: string
167
+ ): ITableController {
168
+ function getStore(): IDBObjectStore {
169
+ return tx.objectStore(tableName);
170
+ }
171
+
172
+ return {
173
+ insert<T>(
174
+ data: T,
175
+ options?: OperationCallbacks<IDBValidKey>
176
+ ): Promise<IDBValidKey> {
177
+ const store = getStore();
178
+ return withCallbacks(requestToPromise(store.add(data)), options);
179
+ },
180
+
181
+ update<T>(
182
+ key: IDBValidKey,
183
+ updates: Partial<T>,
184
+ options?: OperationCallbacks<void>
185
+ ): Promise<void> {
186
+ const store = getStore();
187
+ return withCallbacks(
188
+ requestToPromise(store.get(key))
189
+ .then((existing) => {
190
+ if (existing === undefined) {
191
+ throw new DOMException("Key not found", "NotFoundError");
192
+ }
193
+ const merged = { ...existing, ...updates } as T;
194
+ return requestToPromise(store.put(merged));
195
+ })
196
+ .then(() => undefined),
197
+ options
198
+ );
199
+ },
200
+
201
+ delete(
202
+ key: IDBValidKey,
203
+ options?: OperationCallbacks<void>
204
+ ): Promise<void> {
205
+ const store = getStore();
206
+ return withCallbacks(
207
+ requestToPromise(store.delete(key)).then(() => undefined),
208
+ options
209
+ );
210
+ },
211
+
212
+ exists(key: IDBValidKey): Promise<boolean> {
213
+ const store = getStore();
214
+ return requestToPromise(store.getKey(key)).then((k) => k !== undefined);
215
+ },
216
+
217
+ query<T>(
218
+ filterFn: (item: T) => boolean,
219
+ options?: OperationCallbacks<T[]>
220
+ ): Promise<T[]> {
221
+ const store = getStore();
222
+ const request = store.openCursor();
223
+ const results: T[] = [];
224
+ return withCallbacks(
225
+ new Promise<T[]>((resolve, reject) => {
226
+ request.onsuccess = () => {
227
+ const cursor = request.result;
228
+ if (cursor) {
229
+ if (filterFn(cursor.value as T)) results.push(cursor.value as T);
230
+ cursor.continue();
231
+ } else {
232
+ resolve(results);
233
+ }
234
+ };
235
+ request.onerror = () =>
236
+ reject(request.error ?? new DOMException("Unknown error"));
237
+ }),
238
+ options
239
+ );
240
+ },
241
+
242
+ upsert<T>(
243
+ data: T,
244
+ options?: OperationCallbacks<IDBValidKey>
245
+ ): Promise<IDBValidKey> {
246
+ const store = getStore();
247
+ return withCallbacks(requestToPromise(store.put(data)), options);
248
+ },
249
+
250
+ bulkInsert<T>(
251
+ items: T[],
252
+ options?: OperationCallbacks<IDBValidKey[]>
253
+ ): Promise<IDBValidKey[]> {
254
+ const store = getStore();
255
+ const keys: IDBValidKey[] = [];
256
+ if (items.length === 0) {
257
+ return withCallbacks(Promise.resolve(keys), options);
258
+ }
259
+ let completed = 0;
260
+ const promise = new Promise<IDBValidKey[]>((resolve, reject) => {
261
+ items.forEach((item, i) => {
262
+ const req = store.add(item);
263
+ req.onsuccess = () => {
264
+ keys[i] = req.result;
265
+ completed++;
266
+ if (completed === items.length) resolve(keys);
267
+ };
268
+ req.onerror = () =>
269
+ reject(req.error ?? new DOMException("Unknown error"));
270
+ });
271
+ });
272
+ return withCallbacks(promise, options);
273
+ },
274
+
275
+ clear(options?: OperationCallbacks<void>): Promise<void> {
276
+ const store = getStore();
277
+ return withCallbacks(
278
+ requestToPromise(store.clear()).then(() => undefined),
279
+ options
280
+ );
281
+ },
282
+
283
+ count(options?: OperationCallbacks<number>): Promise<number> {
284
+ const store = getStore();
285
+ return withCallbacks(requestToPromise(store.count()), options ?? {});
286
+ },
287
+ };
288
+ }
289
+
290
+ /** Public interface for a table controller (standalone or transaction-scoped). */
291
+ export interface ITableController {
292
+ insert<T>(
293
+ data: T,
294
+ options?: OperationCallbacks<IDBValidKey>
295
+ ): Promise<IDBValidKey>;
296
+ update<T>(
297
+ key: IDBValidKey,
298
+ updates: Partial<T>,
299
+ options?: OperationCallbacks<void>
300
+ ): Promise<void>;
301
+ delete(key: IDBValidKey, options?: OperationCallbacks<void>): Promise<void>;
302
+ exists(key: IDBValidKey): Promise<boolean>;
303
+ query<T>(
304
+ filterFn: (item: T) => boolean,
305
+ options?: OperationCallbacks<T[]>
306
+ ): Promise<T[]>;
307
+ upsert<T>(
308
+ data: T,
309
+ options?: OperationCallbacks<IDBValidKey>
310
+ ): Promise<IDBValidKey>;
311
+ bulkInsert<T>(
312
+ items: T[],
313
+ options?: OperationCallbacks<IDBValidKey[]>
314
+ ): Promise<IDBValidKey[]>;
315
+ clear(options?: OperationCallbacks<void>): Promise<void>;
316
+ count(options?: OperationCallbacks<number>): Promise<number>;
317
+ }
318
+
319
+ export function createTableController(
320
+ db: IDBDatabase,
321
+ tableName: string
322
+ ): ITableController {
323
+ return createStandaloneController(db, tableName);
324
+ }
325
+
326
+ export function createTransactionTableController(
327
+ tx: IDBTransaction,
328
+ tableName: string
329
+ ): ITableController {
330
+ return createTransactionController(tx, tableName);
331
+ }
@@ -1,35 +1,35 @@
1
- /**
2
- * IndexedDB hook system – shared types.
3
- * @module indexedDB/types
4
- */
5
-
6
- /** Table schema for a single object store. */
7
- export interface TableSchema {
8
- /** Key path (e.g. `"id"` or `["a", "b"]`). */
9
- keyPath: string | string[];
10
- /** Use auto-increment primary key. */
11
- autoIncrement?: boolean;
12
- /** Optional index names to create (each indexes the keyPath by default). */
13
- indexes?: string[];
14
- }
15
-
16
- /** Configuration passed to useIndexedDB. */
17
- export interface IndexedDBConfig {
18
- /** Database name. */
19
- name: string;
20
- /** Schema version (increment to trigger onupgradeneeded). */
21
- version: number;
22
- /** Map of table name → store schema (keyPath, autoIncrement, indexes). */
23
- tables: {
24
- [tableName: string]: TableSchema;
25
- };
26
- }
27
-
28
- /** Optional callbacks for any operation. */
29
- export interface OperationCallbacks<T = unknown> {
30
- onSuccess?: (result: T) => void;
31
- onError?: (error: DOMException) => void;
32
- }
33
-
34
- /** Options for transaction. */
35
- export interface TransactionOptions extends OperationCallbacks<void> { }
1
+ /**
2
+ * IndexedDB hook system – shared types.
3
+ * @module indexedDB/types
4
+ */
5
+
6
+ /** Table schema for a single object store. */
7
+ export interface TableSchema {
8
+ /** Key path (e.g. `"id"` or `["a", "b"]`). */
9
+ keyPath: string | string[];
10
+ /** Use auto-increment primary key. */
11
+ autoIncrement?: boolean;
12
+ /** Optional index names to create (each indexes the keyPath by default). */
13
+ indexes?: string[];
14
+ }
15
+
16
+ /** Configuration passed to useIndexedDB. */
17
+ export interface IndexedDBConfig {
18
+ /** Database name. */
19
+ name: string;
20
+ /** Schema version (increment to trigger onupgradeneeded). */
21
+ version: number;
22
+ /** Map of table name → store schema (keyPath, autoIncrement, indexes). */
23
+ tables: {
24
+ [tableName: string]: TableSchema;
25
+ };
26
+ }
27
+
28
+ /** Optional callbacks for any operation. */
29
+ export interface OperationCallbacks<T = unknown> {
30
+ onSuccess?: (result: T) => void;
31
+ onError?: (error: DOMException) => void;
32
+ }
33
+
34
+ /** Options for transaction. */
35
+ export type TransactionOptions = OperationCallbacks<void>;