Skip to content

Commit

Permalink
fix: expose useStorage with types (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Mar 6, 2023
1 parent d2b34e0 commit b495675
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
10 changes: 1 addition & 9 deletions src/rollup/plugins/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@ import { assets } from '#internal/nitro/virtual/server-assets'
${driverImports.map((i) => genImport(i, genSafeVariableName(i))).join("\n")}
const storage = createStorage({})
export const useStorage = (base = '') => {
if (base) {
return prefixStorage(storage, base)
}
return storage
}
export const storage = createStorage({})
storage.mount('/assets', assets)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "h3";
import type { H3Event } from "h3";
import { parseURL } from "ufo";
import { useStorage } from "#internal/nitro/virtual/storage";
import { useStorage } from "./storage";

export interface CacheEntry<T = any> {
value?: T;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { useStorage } from "#internal/nitro/virtual/storage";
export { useRuntimeConfig, useAppConfig } from "./config";
export * from "./cache";
export { useNitroApp } from "./app";
export * from "./plugin";
export * from "./renderer";
export { getRouteRules } from "./route-rules";
export { useStorage } from "./storage";
7 changes: 7 additions & 0 deletions src/runtime/storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Storage } from "unstorage";
import { prefixStorage } from "unstorage";
import { storage } from "#internal/nitro/virtual/storage";

export function useStorage(base = ""): Storage {
return base ? prefixStorage(storage, base) : storage;
}
2 changes: 1 addition & 1 deletion src/runtime/virtual/storage.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { Storage } from "unstorage";

export declare const useStorage: (base?: string) => Storage;
export declare const storage: Storage;

0 comments on commit b495675

Please sign in to comment.