This repository was archived by the owner on Dec 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 264
feat: restore typings + testing #499
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { EventEmitter } from 'events'; | ||
import * as levelerrors from 'level-errors'; | ||
import { AbstractLevelDOWN, AbstractIteratorOptions, Batch } from 'abstract-leveldown'; | ||
|
||
declare global { | ||
namespace Level { | ||
export interface UP<K, V, O, PO, GO, DO, IO, BO, TB> { | ||
} | ||
} | ||
} | ||
|
||
export interface LevelUp<K=any, V=any, O={}, PO={}, GO={}, DO={}, IO={}, BO={}, TB=Batch<K, V>> | ||
extends Level.UP<K, V, O, PO, GO, DO, IO, BO, TB>, | ||
EventEmitter { | ||
|
||
open(): Promise<void>; | ||
open(callback?: (err: any) => any): void; | ||
close(): Promise<void>; | ||
close(callback?: (err: any) => any): void; | ||
|
||
put(key: K, value: V, options?: PO): Promise<void>; | ||
put(key: K, value: V, options: PO, callback: (err: any) => any): void; | ||
put(key: K, value: V, callback: (err: any) => any): void; | ||
|
||
get(key: K, options?: GO): Promise<any>; | ||
get(key: K, options: GO, callback: (err: any, value: any) => any): void; | ||
get(key: K, callback: (err: any, value: any) => any): void; | ||
|
||
del(key: K, options?: DO): Promise<void> | ||
del(key: K, options: DO, callback: (err: any) => any): void; | ||
del(key: K, callback: (err: any) => any): void; | ||
|
||
batch(array: TB[], options?: BO): Promise<void>; | ||
batch(array: TB[], options: BO, callback: (err?: any) => any): void; | ||
batch(array: TB[], callback: (err?: any) => any): void; | ||
|
||
batch(): LevelUpChain<K, V>; | ||
|
||
isOpen(): boolean; | ||
isClosed(): boolean; | ||
|
||
createReadStream(options?: IO & AbstractIteratorOptions<K>): NodeJS.ReadableStream; | ||
createKeyStream(options?: IO & AbstractIteratorOptions<K>): NodeJS.ReadableStream; | ||
createValueStream(options?: IO & AbstractIteratorOptions<K>): NodeJS.ReadableStream; | ||
|
||
/**emitted when a new value is 'put' */ | ||
on(event: 'put', cb: (key: K, value: V) => void): this | ||
/**emitted when a value is deleted*/ | ||
on(event: 'del', cb: (key: K) => void) | ||
/**emitted when a batch operation has executed */ | ||
on(event: 'batch', cb: (ary: any[]) => void) | ||
/**emitted when the database has opened ('open' is synonym) */ | ||
on(event: 'ready', cb: () => void) | ||
/**emitted when the database has opened */ | ||
on(event: 'open', cb: () => void) | ||
/** emitted when the database has closed*/ | ||
on(event: 'closed', cb: () => void) | ||
/** emitted when the database is opening */ | ||
on(event: 'opening', cb: () => void) | ||
/** emitted when the database is closing */ | ||
on(event: 'closing', cb: () => void) | ||
} | ||
|
||
interface LevelUpConstructor { | ||
<K=any, V=any, O=any, PO={}, GO={}, DO={}, IO={}, BO={}, B = Batch<K, V>>( | ||
db: AbstractLevelDOWN<any, any, O, PO, GO, DO, IO, BO>, | ||
options: O, | ||
cb?: (err: Error) => void): LevelUp<K, V, O, PO, GO, DO, IO, BO, B>; | ||
<K=any, V=any, O=any, PO={}, GO={}, DO={}, IO={}, BO={}, B = Batch<K, V>>( | ||
db: AbstractLevelDOWN<any, any, O, PO, GO, DO, IO, BO>, | ||
cb?: (err: Error) => void): LevelUp<K, V, O, PO, GO, DO, IO, BO, B>; | ||
|
||
new <K=any, V=any, O=any, PO={}, GO={}, DO={}, IO={}, BO={}, B = Batch<K, V>>( | ||
db: AbstractLevelDOWN<any, any, O, PO, GO, DO, IO, BO>, | ||
options: O, | ||
cb?: (err?: Error) => void): LevelUp<K, V, O, PO, GO, DO, IO, BO, B>; | ||
new <K=any, V=any, O=any, PO={}, GO={}, DO={}, IO={}, BO={}, B = Batch<K, V>>( | ||
db: AbstractLevelDOWN<any, any, O, PO, GO, DO, IO, BO>, | ||
cb?: (err?: Error) => void): LevelUp<K, V, O, PO, GO, DO, IO, BO, B>; | ||
|
||
errors: typeof levelerrors; | ||
} | ||
|
||
export interface LevelUpChain<K=any, V=any> { | ||
readonly length: number; | ||
put(key: K, value: V): this; | ||
del(key: K): this; | ||
clear(): this; | ||
write(callback: (err?: any) => any): this; | ||
write(): Promise<this>; | ||
} | ||
|
||
export var errors: typeof levelerrors; | ||
|
||
declare const LevelUp: LevelUpConstructor; | ||
export default LevelUp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2015", | ||
"moduleResolution": "node", | ||
"checkJs": true, | ||
"allowJs": true | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is not necessary because we had exported both
LevelUP
anddefault
.See:
levelup/lib/levelup.js
Line 294 in f93790f
That will make sure the code will pass the following assertion:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its down to typescript - you cannot have both
export default
andexport =
in the typings. So the typings have gone with thedefault
export exclusively for typescript users.It means when you run the normal js through the typescript compiler it will complain if you don't use the
default
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, understand.
Then how about we do a
module.exports = LevelUP.default = LevelUP.LevelUP = LevelUP
?Then we will be able to do a
var { LevelUP } = require('../lib/levelup.js')
, which would be better thanrequire('...').default
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of
require('...').default
- but because it's only in the tests, I prefer it over more hacks inlib/levelup.js
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I don't think we need more hacks to the export; Its just for the test here because we're pushing the (mostly) unadulterated js through the compiler. normal javascript users:
const levelup = require('levelup')
normal ts users:
import levelup from 'levelup'
you can always do
const {default:levelup} = require('levelup');
but I suspect we might run into issues if we're still testing on an older node.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with
default
too because it's just unit test script.