-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #24 Write prompt state cache to local level DB
- Loading branch information
1 parent
c60da12
commit c0b8392
Showing
28 changed files
with
1,330 additions
and
632 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
declare module "level-auto-index" { | ||
import { LevelUp } from "levelup"; | ||
function AutoIndex<T>( | ||
db: LevelUp, | ||
idb: LevelUp, | ||
reduce: (value: T) => string, | ||
opts: unknown, | ||
): AutoIndex.IndexedDB; | ||
|
||
export = AutoIndex; | ||
namespace AutoIndex { | ||
interface IndexedDB { | ||
get(key: string, opts: unknown): Promise<unknown>; | ||
} | ||
} | ||
} |
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
File renamed without changes.
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { LevelUp } from "levelup"; | ||
|
||
export async function saveJSONRecord( | ||
db: LevelUp, | ||
key: string, | ||
value: unknown, | ||
): Promise<void> { | ||
await db.put(key, JSON.stringify(value)); | ||
} | ||
|
||
export async function getJSONRecord<T>( | ||
db: LevelUp, | ||
key: string, | ||
): Promise<{ record: T } | null> { | ||
const recordString = await db | ||
.get(key) | ||
.catch((error) => (error.notFound ? null : Promise.reject(error))); | ||
if (recordString) { | ||
return { record: JSON.parse(recordString) }; | ||
} else { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.