From d5db4201f3727d6667d136aa6c846665cd9a9d84 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sun, 6 Mar 2022 14:40:56 +0100 Subject: [PATCH] Fix TypeScript type declarations --- index.d.ts | 54 +++++++++++++++++++++++++++++++++++++++++++++++++--- package.json | 2 +- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index f5351f0..1cdbc92 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,7 +1,21 @@ import { AbstractLevel, AbstractDatabaseOptions, - NodeCallback + NodeCallback, + AbstractOpenOptions, + AbstractGetOptions, + AbstractGetManyOptions, + AbstractPutOptions, + AbstractDelOptions, + AbstractBatchOptions, + AbstractChainedBatch, + AbstractIterator, + AbstractKeyIterator, + AbstractValueIterator, + AbstractIteratorOptions, + AbstractKeyIteratorOptions, + AbstractValueIteratorOptions, + AbstractBatchOperation } from 'abstract-level' /** @@ -24,6 +38,21 @@ export class BrowserLevel */ constructor (location: string, options?: DatabaseOptions | undefined) + /** + * Location that was passed to the constructor. + */ + get location (): string + + /** + * Database name prefix that was passed to the constructor (as `prefix`). + */ + get namePrefix (): string + + /** + * Version that was passed to the constructor. + */ + get version (): number + /** * Delete the IndexedDB database at the given {@link location}. */ @@ -42,14 +71,14 @@ export interface DatabaseOptions extends AbstractDatabaseOptions { * * @defaultValue `'level-js-'` */ - prefix: string + prefix?: string /** * The version to open the `IDBDatabase` with. * * @defaultValue `1` */ - version: number | string + version?: number | string /** * An {@link AbstractLevel} option that has no effect on {@link BrowserLevel}. @@ -61,3 +90,22 @@ export interface DatabaseOptions extends AbstractDatabaseOptions { */ errorIfExists?: boolean } + +// Export types so that consumers don't have to guess whether they're extended +export type OpenOptions = AbstractOpenOptions +export type GetOptions = AbstractGetOptions +export type GetManyOptions = AbstractGetManyOptions +export type PutOptions = AbstractPutOptions +export type DelOptions = AbstractDelOptions + +export type BatchOptions = AbstractBatchOptions +export type BatchOperation = AbstractBatchOperation +export type ChainedBatch = AbstractChainedBatch + +export type Iterator = AbstractIterator +export type KeyIterator = AbstractKeyIterator +export type ValueIterator = AbstractValueIterator + +export type IteratorOptions = AbstractIteratorOptions +export type KeyIteratorOptions = AbstractKeyIteratorOptions +export type ValueIteratorOptions = AbstractValueIteratorOptions diff --git a/package.json b/package.json index 2735c74..56b320b 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "sauce-labs.svg" ], "dependencies": { - "abstract-level": "^1.0.1", + "abstract-level": "^1.0.2", "catering": "^2.1.1", "module-error": "^1.0.2", "run-parallel-limit": "^1.1.0"