diff --git a/packages/interface-blockstore/src/index.ts b/packages/interface-blockstore/src/index.ts index 861f0ada..b19875e8 100644 --- a/packages/interface-blockstore/src/index.ts +++ b/packages/interface-blockstore/src/index.ts @@ -1,20 +1,22 @@ import type { - Options as StoreOptions, + AbortOptions, AwaitIterable, Store } from 'interface-store' import type { CID } from 'multiformats/cid' -export interface Options extends StoreOptions { - -} - export interface Pair { cid: CID block: Uint8Array } -export interface Blockstore extends Store { +export interface Blockstore extends Store { /** * Retrieve all cid/block pairs from the blockstore as an unordered iterable * @@ -26,5 +28,5 @@ export interface Blockstore extends Store { * } * ``` */ - getAll: (options?: Options) => AwaitIterable + getAll: (options?: AbortOptions & GetAllOptionsExtension) => AwaitIterable } diff --git a/packages/interface-datastore/src/index.ts b/packages/interface-datastore/src/index.ts index 042dd338..7dffd133 100644 --- a/packages/interface-datastore/src/index.ts +++ b/packages/interface-datastore/src/index.ts @@ -1,26 +1,32 @@ import type { - Options as StoreOptions, Await, - Store + AwaitIterable, + Store, + AbortOptions } from 'interface-store' import { Key } from './key.js' -export interface Options extends StoreOptions { - -} - export interface Pair { key: Key value: Uint8Array } -export interface Batch { +export interface Batch { put: (key: Key, value: Uint8Array) => void delete: (key: Key) => void - commit: (options?: Options) => Await + commit: (options?: AbortOptions & BatchOptionsExtension) => Await } -export interface Datastore extends Store { +export interface Datastore extends Store { /** * This will return an object with which you can chain multiple operations together, with them only being executed on calling `commit`. * @@ -36,7 +42,7 @@ export interface Datastore extends Store { * console.log('put 100 values') * ``` */ - batch: () => Batch + batch: () => Batch /** * Query the datastore. @@ -51,7 +57,7 @@ export interface Datastore extends Store { * console.log('ALL THE VALUES', list) * ``` */ - query: (query: Query, options?: Options) => AsyncIterable + query: (query: Query, options?: AbortOptions & QueryOptionsExtension) => AwaitIterable /** * Query the datastore. @@ -66,7 +72,7 @@ export interface Datastore extends Store { * console.log('ALL THE KEYS', key) * ``` */ - queryKeys: (query: KeyQuery, options?: Options) => AsyncIterable + queryKeys: (query: KeyQuery, options?: AbortOptions & QueryKeysOptionsExtension) => AwaitIterable } export interface QueryFilter { (item: Pair): boolean } diff --git a/packages/interface-store/src/index.ts b/packages/interface-store/src/index.ts index 5a4597ba..33fa2d6c 100644 --- a/packages/interface-store/src/index.ts +++ b/packages/interface-store/src/index.ts @@ -1,15 +1,25 @@ +/** + * An iterable or async iterable of values + */ export type AwaitIterable = Iterable | AsyncIterable + +/** + * A value or a promise of a value + */ export type Await = Promise | T /** * Options for async operations. */ -export interface Options { +export interface AbortOptions { signal?: AbortSignal } -export interface Store { +export interface Store { /** * Check for the existence of a value for the passed key * @@ -24,7 +34,7 @@ export interface Store { *} *``` */ - has: (key: Key, options?: Options) => Await + has: (key: Key, options?: AbortOptions & HasOptionsExtension) => Await /** * Store the passed value under the passed key @@ -35,7 +45,7 @@ export interface Store { * await store.put([{ key: new Key('awesome'), value: new Uint8Array([0, 1, 2, 3]) }]) * ``` */ - put: (key: Key, val: Value, options?: Options) => Await + put: (key: Key, val: Value, options?: AbortOptions & PutOptionsExtension) => Await /** * Store the given key/value pairs @@ -51,7 +61,7 @@ export interface Store { */ putMany: ( source: AwaitIterable, - options?: Options + options?: AbortOptions & PutManyOptionsExtension ) => AwaitIterable /** @@ -64,7 +74,7 @@ export interface Store { * // => got content: datastore * ``` */ - get: (key: Key, options?: Options) => Await + get: (key: Key, options?: AbortOptions & GetOptionsExtension) => Await /** * Retrieve values for the passed keys @@ -79,7 +89,7 @@ export interface Store { */ getMany: ( source: AwaitIterable, - options?: Options + options?: AbortOptions & GetManyOptionsExtension ) => AwaitIterable /** @@ -92,7 +102,7 @@ export interface Store { * console.log('deleted awesome content :(') * ``` */ - delete: (key: Key, options?: Options) => Await + delete: (key: Key, options?: AbortOptions & DeleteOptionsExtension) => Await /** * Remove values for the passed keys @@ -109,6 +119,6 @@ export interface Store { */ deleteMany: ( source: AwaitIterable, - options?: Options + options?: AbortOptions & DeleteManyOptionsExtension ) => AwaitIterable }