Skip to content

Commit

Permalink
feat: allow driver getKey to receive base key (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz authored Sep 29, 2021
1 parent fe941c2 commit 9fd89b1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ export function createStorage (opts: CreateStorageOptions = {}): Storage {

const getMounts = (base: string) => {
return ctx.mountpoints
.filter(mountpoint => base!.length < mountpoint.length || base!.startsWith(mountpoint))
.filter(mountpoint => mountpoint.startsWith(base) || base!.startsWith(mountpoint))
.map(mountpoint => ({
relativeBase: base.length > mountpoint.length ? base!.substr(mountpoint.length) : undefined,
mountpoint,
driver: ctx.mounts[mountpoint]
}))
Expand Down Expand Up @@ -131,7 +132,7 @@ export function createStorage (opts: CreateStorageOptions = {}): Storage {
async getKeys (base) {
base = normalizeBase(base)
const keyGroups = await Promise.all(getMounts(base).map(async (mount) => {
const rawKeys = await asyncCall(mount.driver.getKeys)
const rawKeys = await asyncCall(mount.driver.getKeys, mount.relativeBase)
return rawKeys.map(key => mount.mountpoint + normalizeKey(key))
}))
const keys = keyGroups.flat()
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface Driver {
setItem?: (key: string, value: string) => void | Promise<void>
removeItem?: (key: string) => void | Promise<void>
getMeta?: (key: string) => StorageMeta | Promise<StorageMeta>
getKeys: () => string[] | Promise<string[]>
getKeys: (base?: string) => string[] | Promise<string[]>
clear?: () => void | Promise<void>
dispose?: () => void | Promise<void>
watch?: (callback: WatchCallback) => void | Promise<void>
Expand Down

0 comments on commit 9fd89b1

Please sign in to comment.