taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 8b089c98d46bd446ad19731c2bac4a1cf010e17f
parent 1d38c8e57dff7dd60e600d71e48664d72d544fdd
Author: Florian Dold <florian@dold.me>
Date:   Tue, 13 Feb 2024 11:38:12 +0100

wallet-core: implement getAll for object stores

Diffstat:
Mpackages/taler-wallet-core/src/util/query.ts | 31+++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/packages/taler-wallet-core/src/util/query.ts b/packages/taler-wallet-core/src/util/query.ts @@ -23,20 +23,19 @@ /** * Imports. */ -import { openPromise } from "./promiseUtils.js"; import { - IDBRequest, - IDBTransaction, - IDBValidKey, + IDBCursor, IDBDatabase, IDBFactory, - IDBVersionChangeEvent, - IDBCursor, IDBKeyPath, IDBKeyRange, - IDBOpenDBRequest, + IDBRequest, + IDBTransaction, + IDBValidKey, + IDBVersionChangeEvent, } from "@gnu-taler/idb-bridge"; -import { Codec, Logger, j2s } from "@gnu-taler/taler-util"; +import { Codec, Logger } from "@gnu-taler/taler-util"; +import { openPromise } from "./promiseUtils.js"; const logger = new Logger("query.ts"); @@ -374,6 +373,10 @@ type GetIndexReadWriteAccess<RecordType, IndexMap> = { export interface StoreReadOnlyAccessor<RecordType, IndexMap> { get(key: IDBValidKey): Promise<RecordType | undefined>; + getAll( + query?: IDBKeyRange | IDBValidKey, + count?: number, + ): Promise<RecordType[]>; iter(query?: IDBValidKey): ResultStream<RecordType>; indexes: GetIndexReadOnlyAccess<RecordType, IndexMap>; } @@ -387,6 +390,10 @@ export interface InsertResponse { export interface StoreReadWriteAccessor<RecordType, IndexMap> { get(key: IDBValidKey): Promise<RecordType | undefined>; + getAll( + query?: IDBKeyRange | IDBValidKey, + count?: number, + ): Promise<RecordType[]>; iter(query?: IDBValidKey): ResultStream<RecordType>; put(r: RecordType, key?: IDBValidKey): Promise<InsertResponse>; add(r: RecordType, key?: IDBValidKey): Promise<InsertResponse>; @@ -717,6 +724,10 @@ function makeReadContext( const req = tx.objectStore(storeName).get(key); return requestToPromise(req); }, + getAll(query, count) { + const req = tx.objectStore(storeName).getAll(query, count); + return requestToPromise(req); + }, iter(query) { const req = tx.objectStore(storeName).openCursor(query); return new ResultStream<any>(req); @@ -770,6 +781,10 @@ function makeWriteContext( const req = tx.objectStore(storeName).get(key); return requestToPromise(req); }, + getAll(query, count) { + const req = tx.objectStore(storeName).getAll(query, count); + return requestToPromise(req); + }, iter(query) { const req = tx.objectStore(storeName).openCursor(query); return new ResultStream<any>(req);