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 a909ea6 commit a79fe82
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
34 changes: 23 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
AbstractBatchOperation,
AbstractBatchOptions,
AbstractChainedBatch,
AbstractChainedBatchWriteOptions,
AbstractIteratorOptions,
AbstractIterator,
AbstractKeyIterator,
Expand Down Expand Up @@ -70,20 +71,20 @@ declare class ClassicLevel<KDefault = string, VDefault = string>
del<K = KDefault> (key: K, options: DelOptions<K>): Promise<void>
del<K = KDefault> (key: K, options: DelOptions<K>, callback: NodeCallback<void>): void

batch (operations: Array<AbstractBatchOperation<typeof this, KDefault, VDefault>>): Promise<void>
batch (operations: Array<AbstractBatchOperation<typeof this, KDefault, VDefault>>, callback: NodeCallback<void>): void
batch<K = KDefault, V = VDefault> (operations: Array<AbstractBatchOperation<typeof this, K, V>>, options: BatchOptions<K, V>): Promise<void>
batch<K = KDefault, V = VDefault> (operations: Array<AbstractBatchOperation<typeof this, K, V>>, options: BatchOptions<K, V>, callback: NodeCallback<void>): void
batch (operations: Array<BatchOperation<typeof this, KDefault, VDefault>>): Promise<void>
batch (operations: Array<BatchOperation<typeof this, KDefault, VDefault>>, callback: NodeCallback<void>): void
batch<K = KDefault, V = VDefault> (operations: Array<BatchOperation<typeof this, K, V>>, options: BatchOptions<K, V>): Promise<void>
batch<K = KDefault, V = VDefault> (operations: Array<BatchOperation<typeof this, K, V>>, options: BatchOptions<K, V>, callback: NodeCallback<void>): void
batch (): ChainedBatch<typeof this, KDefault, VDefault>

iterator (): AbstractIterator<typeof this, KDefault, VDefault>
iterator<K = KDefault, V = VDefault> (options: AbstractIteratorOptions<K, V> & AdditionalIteratorOptions): AbstractIterator<typeof this, K, V>
iterator (): Iterator<typeof this, KDefault, VDefault>
iterator<K = KDefault, V = VDefault> (options: IteratorOptions<K, V>): Iterator<typeof this, K, V>

keys (): AbstractKeyIterator<typeof this, KDefault>
keys<K = KDefault> (options: AbstractKeyIteratorOptions<K> & AdditionalIteratorOptions): AbstractKeyIterator<typeof this, K>
keys (): KeyIterator<typeof this, KDefault>
keys<K = KDefault> (options: KeyIteratorOptions<K>): KeyIterator<typeof this, K>

values (): AbstractValueIterator<typeof this, KDefault, VDefault>
values<K = KDefault, V = VDefault> (options: AbstractValueIteratorOptions<K, V> & AdditionalIteratorOptions): AbstractValueIterator<typeof this, K, V>
values (): ValueIterator<typeof this, KDefault, VDefault>
values<K = KDefault, V = VDefault> (options: ValueIteratorOptions<K, V>): ValueIterator<typeof this, K, V>

/**
* Get the approximate number of bytes of file system space used by the range
Expand Down Expand Up @@ -297,7 +298,7 @@ export interface BatchOptions<K, V> extends AbstractBatchOptions<K, V>, WriteOpt
/**
* Options for the {@link ChainedBatch.write} method.
*/
export interface ChainedBatchWriteOptions extends WriteOptions {}
export interface ChainedBatchWriteOptions extends AbstractChainedBatchWriteOptions, WriteOptions {}

export class ChainedBatch<TDatabase, KDefault, VDefault> extends AbstractChainedBatch<TDatabase, KDefault, VDefault> {
write (): Promise<void>
Expand All @@ -316,3 +317,14 @@ export interface StartEndOptions<K> {
*/
keyEncoding?: string | Transcoder.PartialEncoder<K> | undefined
}

// Export remaining types so that consumers don't have to guess whether they're extended
export type BatchOperation<TDatabase, K, V> = AbstractBatchOperation<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> & AdditionalIteratorOptions
export type KeyIteratorOptions<K> = AbstractKeyIteratorOptions<K> & AdditionalIteratorOptions
export type ValueIteratorOptions<K, V> = AbstractValueIteratorOptions<K, V> & AdditionalIteratorOptions
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"prebuild-win32-x64": "prebuildify -t 8.14.0 --napi --strip"
},
"dependencies": {
"abstract-level": "^1.0.1",
"abstract-level": "^1.0.2",
"catering": "^2.1.0",
"module-error": "^1.0.1",
"napi-macros": "~2.0.0",
Expand Down

0 comments on commit a79fe82

Please sign in to comment.