generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
i.e. if a developer provides their own `createLevelDatabase` then we will use that instead of `'level'` in order to support this for both node and browser, we need to switch to using dynamic `import` (instead of `require`, as that's not defined for node when `"type": "module"`) most of this commit is changing sync logic to `async` for that purpose (though it also allows for more flexibility when providing a custom `createLevelDatabase`)
- Loading branch information
Showing
6 changed files
with
47 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import type { AbstractDatabaseOptions, AbstractLevel } from 'abstract-level'; | ||
|
||
import { Level } from 'level'; | ||
|
||
export type LevelDatabase<K, V> = AbstractLevel<string | Buffer | Uint8Array, K, V>; | ||
|
||
export type LevelDatabaseOptions<K, V> = AbstractDatabaseOptions<K, V>; | ||
|
||
export function createLevelDatabase<K, V>(location: string, options?: LevelDatabaseOptions<K, V>): LevelDatabase<K, V> { | ||
export async function createLevelDatabase<K, V>(location: string, options?: LevelDatabaseOptions<K, V>): Promise<LevelDatabase<K, V>> { | ||
// Only import `'level'` when it's actually necessary (i.e. only when the default `createLevelDatabase` is used). | ||
// Overriding `createLevelDatabase` will prevent this from happening. | ||
const { Level } = await import('level'); | ||
return new Level(location, options); | ||
} |
This file contains 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 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 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