Skip to content

Commit

Permalink
Fix TypeScript type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Mar 6, 2022
1 parent 3f84880 commit d5db420
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
54 changes: 51 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand All @@ -24,6 +38,21 @@ export class BrowserLevel<KDefault = string, VDefault = string>
*/
constructor (location: string, options?: DatabaseOptions<KDefault, VDefault> | 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}.
*/
Expand All @@ -42,14 +71,14 @@ export interface DatabaseOptions<K, V> extends AbstractDatabaseOptions<K, V> {
*
* @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}.
Expand All @@ -61,3 +90,22 @@ export interface DatabaseOptions<K, V> extends AbstractDatabaseOptions<K, V> {
*/
errorIfExists?: boolean
}

// Export types so that consumers don't have to guess whether they're extended
export type OpenOptions = AbstractOpenOptions
export type GetOptions<K, V> = AbstractGetOptions<K, V>
export type GetManyOptions<K, V> = AbstractGetManyOptions<K, V>
export type PutOptions<K, V> = AbstractPutOptions<K, V>
export type DelOptions<K> = AbstractDelOptions<K>

export type BatchOptions<K, V> = AbstractBatchOptions<K, V>
export type BatchOperation<TDatabase, K, V> = AbstractBatchOperation<TDatabase, K, V>
export type ChainedBatch<TDatabase, K, V> = AbstractChainedBatch<TDatabase, K, V>

export type Iterator<TDatabase, K, V> = AbstractIterator<TDatabase, K, V>
export type KeyIterator<TDatabase, K> = AbstractKeyIterator<TDatabase, K>
export type ValueIterator<TDatabase, K, V> = AbstractValueIterator<TDatabase, K, V>

export type IteratorOptions<K, V> = AbstractIteratorOptions<K, V>
export type KeyIteratorOptions<K> = AbstractKeyIteratorOptions<K>
export type ValueIteratorOptions<K, V> = AbstractValueIteratorOptions<K, V>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d5db420

Please sign in to comment.