From 7ef8126b0e359d5d2ada53af22060e01e3ec62fa Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Fri, 22 Nov 2024 13:10:55 +0000 Subject: [PATCH] fix: re-export unstorage drivers --- package.json | 3 ++- packages/astro/package.json | 1 + packages/astro/src/core/session.ts | 6 ++++-- .../src/storage/drivers/azureAppConfiguration.js | 2 ++ packages/astro/src/storage/drivers/azureCosmos.js | 2 ++ packages/astro/src/storage/drivers/azureKeyVault.js | 2 ++ .../astro/src/storage/drivers/azureStorageBlob.js | 2 ++ .../astro/src/storage/drivers/azureStorageTable.js | 2 ++ .../src/storage/drivers/cloudflare-kv-binding.js | 2 ++ .../astro/src/storage/drivers/cloudflare-kv-http.js | 2 ++ .../src/storage/drivers/cloudflareKVBinding.js | 2 ++ .../astro/src/storage/drivers/cloudflareKVHTTP.js | 2 ++ .../src/storage/drivers/cloudflareR2Binding.js | 2 ++ packages/astro/src/storage/drivers/fs.js | 2 ++ packages/astro/src/storage/drivers/fsLite.js | 2 ++ packages/astro/src/storage/drivers/github.js | 2 ++ packages/astro/src/storage/drivers/http.js | 2 ++ packages/astro/src/storage/drivers/indexedb.js | 2 ++ packages/astro/src/storage/drivers/localStorage.js | 2 ++ packages/astro/src/storage/drivers/lruCache.js | 2 ++ packages/astro/src/storage/drivers/memory.js | 2 ++ packages/astro/src/storage/drivers/mongodb.js | 2 ++ packages/astro/src/storage/drivers/netlifyBlobs.js | 2 ++ packages/astro/src/storage/drivers/null.js | 2 ++ packages/astro/src/storage/drivers/overlay.js | 2 ++ packages/astro/src/storage/drivers/planetscale.js | 2 ++ packages/astro/src/storage/drivers/redis.js | 2 ++ .../astro/src/storage/drivers/sessionStorage.js | 2 ++ packages/astro/src/storage/drivers/vercelKV.js | 2 ++ pnpm-lock.yaml | 3 +++ scripts/deps/update-storage-reexports.js | 13 +++++++++++++ 31 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 packages/astro/src/storage/drivers/azureAppConfiguration.js create mode 100644 packages/astro/src/storage/drivers/azureCosmos.js create mode 100644 packages/astro/src/storage/drivers/azureKeyVault.js create mode 100644 packages/astro/src/storage/drivers/azureStorageBlob.js create mode 100644 packages/astro/src/storage/drivers/azureStorageTable.js create mode 100644 packages/astro/src/storage/drivers/cloudflare-kv-binding.js create mode 100644 packages/astro/src/storage/drivers/cloudflare-kv-http.js create mode 100644 packages/astro/src/storage/drivers/cloudflareKVBinding.js create mode 100644 packages/astro/src/storage/drivers/cloudflareKVHTTP.js create mode 100644 packages/astro/src/storage/drivers/cloudflareR2Binding.js create mode 100644 packages/astro/src/storage/drivers/fs.js create mode 100644 packages/astro/src/storage/drivers/fsLite.js create mode 100644 packages/astro/src/storage/drivers/github.js create mode 100644 packages/astro/src/storage/drivers/http.js create mode 100644 packages/astro/src/storage/drivers/indexedb.js create mode 100644 packages/astro/src/storage/drivers/localStorage.js create mode 100644 packages/astro/src/storage/drivers/lruCache.js create mode 100644 packages/astro/src/storage/drivers/memory.js create mode 100644 packages/astro/src/storage/drivers/mongodb.js create mode 100644 packages/astro/src/storage/drivers/netlifyBlobs.js create mode 100644 packages/astro/src/storage/drivers/null.js create mode 100644 packages/astro/src/storage/drivers/overlay.js create mode 100644 packages/astro/src/storage/drivers/planetscale.js create mode 100644 packages/astro/src/storage/drivers/redis.js create mode 100644 packages/astro/src/storage/drivers/sessionStorage.js create mode 100644 packages/astro/src/storage/drivers/vercelKV.js create mode 100644 scripts/deps/update-storage-reexports.js diff --git a/package.json b/package.json index d46517228e..99b57d2117 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,8 @@ "publint": "^0.2.12", "turbo": "^2.2.3", "typescript": "~5.6.3", - "typescript-eslint": "^8.13.0" + "typescript-eslint": "^8.13.0", + "unstorage": "^1.12.0" }, "pnpm": { "overrides": { diff --git a/packages/astro/package.json b/packages/astro/package.json index e1d5a7e428..2424f6ad78 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -67,6 +67,7 @@ "./assets/services/noop": "./dist/assets/services/noop.js", "./loaders": "./dist/content/loaders/index.js", "./content/runtime": "./dist/content/runtime.js", + "./internal/storage/drivers/*": "./dist/storage/drivers/*.js", "./content/runtime-assets": "./dist/content/runtime-assets.js", "./debug": "./components/Debug.astro", "./package.json": "./package.json", diff --git a/packages/astro/src/core/session.ts b/packages/astro/src/core/session.ts index 23cdf9b4f7..014e6ebc06 100644 --- a/packages/astro/src/core/session.ts +++ b/packages/astro/src/core/session.ts @@ -344,7 +344,7 @@ export class AstroSession { * Ensures the storage is initialized. * This is called automatically when a storage operation is needed. */ - async #ensureStorage():Promise { + async #ensureStorage(): Promise { if (this.#storage) { return this.#storage; } @@ -364,7 +364,9 @@ export class AstroSession { let driver: ((config: SessionConfig['options']) => Driver) | null = null; const entry = - builtinDrivers[this.#config.driver as keyof typeof builtinDrivers] || this.#config.driver; + this.#config.driver in builtinDrivers + ? `astro/internal/storage/drivers/${this.#config.driver}` + : this.#config.driver; try { // Try to load the driver from the built-in unstorage drivers. // Otherwise, assume it's a custom driver and load by name. diff --git a/packages/astro/src/storage/drivers/azureAppConfiguration.js b/packages/astro/src/storage/drivers/azureAppConfiguration.js new file mode 100644 index 0000000000..f5429371fe --- /dev/null +++ b/packages/astro/src/storage/drivers/azureAppConfiguration.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/azure-app-configuration"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/azureCosmos.js b/packages/astro/src/storage/drivers/azureCosmos.js new file mode 100644 index 0000000000..5f43a4e631 --- /dev/null +++ b/packages/astro/src/storage/drivers/azureCosmos.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/azure-cosmos"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/azureKeyVault.js b/packages/astro/src/storage/drivers/azureKeyVault.js new file mode 100644 index 0000000000..4dee8559a6 --- /dev/null +++ b/packages/astro/src/storage/drivers/azureKeyVault.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/azure-key-vault"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/azureStorageBlob.js b/packages/astro/src/storage/drivers/azureStorageBlob.js new file mode 100644 index 0000000000..b637e27671 --- /dev/null +++ b/packages/astro/src/storage/drivers/azureStorageBlob.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/azure-storage-blob"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/azureStorageTable.js b/packages/astro/src/storage/drivers/azureStorageTable.js new file mode 100644 index 0000000000..65dc157799 --- /dev/null +++ b/packages/astro/src/storage/drivers/azureStorageTable.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/azure-storage-table"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/cloudflare-kv-binding.js b/packages/astro/src/storage/drivers/cloudflare-kv-binding.js new file mode 100644 index 0000000000..86df1278b6 --- /dev/null +++ b/packages/astro/src/storage/drivers/cloudflare-kv-binding.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/cloudflare-kv-binding"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/cloudflare-kv-http.js b/packages/astro/src/storage/drivers/cloudflare-kv-http.js new file mode 100644 index 0000000000..002d8d26af --- /dev/null +++ b/packages/astro/src/storage/drivers/cloudflare-kv-http.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/cloudflare-kv-http"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/cloudflareKVBinding.js b/packages/astro/src/storage/drivers/cloudflareKVBinding.js new file mode 100644 index 0000000000..86df1278b6 --- /dev/null +++ b/packages/astro/src/storage/drivers/cloudflareKVBinding.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/cloudflare-kv-binding"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/cloudflareKVHTTP.js b/packages/astro/src/storage/drivers/cloudflareKVHTTP.js new file mode 100644 index 0000000000..002d8d26af --- /dev/null +++ b/packages/astro/src/storage/drivers/cloudflareKVHTTP.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/cloudflare-kv-http"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/cloudflareR2Binding.js b/packages/astro/src/storage/drivers/cloudflareR2Binding.js new file mode 100644 index 0000000000..f7eff8ee79 --- /dev/null +++ b/packages/astro/src/storage/drivers/cloudflareR2Binding.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/cloudflare-r2-binding"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/fs.js b/packages/astro/src/storage/drivers/fs.js new file mode 100644 index 0000000000..cefa6462ac --- /dev/null +++ b/packages/astro/src/storage/drivers/fs.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/fs"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/fsLite.js b/packages/astro/src/storage/drivers/fsLite.js new file mode 100644 index 0000000000..ed4c3148b5 --- /dev/null +++ b/packages/astro/src/storage/drivers/fsLite.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/fs-lite"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/github.js b/packages/astro/src/storage/drivers/github.js new file mode 100644 index 0000000000..6f364e978c --- /dev/null +++ b/packages/astro/src/storage/drivers/github.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/github"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/http.js b/packages/astro/src/storage/drivers/http.js new file mode 100644 index 0000000000..9ae16c4f94 --- /dev/null +++ b/packages/astro/src/storage/drivers/http.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/http"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/indexedb.js b/packages/astro/src/storage/drivers/indexedb.js new file mode 100644 index 0000000000..35114538f0 --- /dev/null +++ b/packages/astro/src/storage/drivers/indexedb.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/indexedb"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/localStorage.js b/packages/astro/src/storage/drivers/localStorage.js new file mode 100644 index 0000000000..81caab0ded --- /dev/null +++ b/packages/astro/src/storage/drivers/localStorage.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/localstorage"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/lruCache.js b/packages/astro/src/storage/drivers/lruCache.js new file mode 100644 index 0000000000..ae83fc4cf0 --- /dev/null +++ b/packages/astro/src/storage/drivers/lruCache.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/lru-cache"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/memory.js b/packages/astro/src/storage/drivers/memory.js new file mode 100644 index 0000000000..eb558cd95e --- /dev/null +++ b/packages/astro/src/storage/drivers/memory.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/memory"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/mongodb.js b/packages/astro/src/storage/drivers/mongodb.js new file mode 100644 index 0000000000..5363733055 --- /dev/null +++ b/packages/astro/src/storage/drivers/mongodb.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/mongodb"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/netlifyBlobs.js b/packages/astro/src/storage/drivers/netlifyBlobs.js new file mode 100644 index 0000000000..11b3afc7a7 --- /dev/null +++ b/packages/astro/src/storage/drivers/netlifyBlobs.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/netlify-blobs"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/null.js b/packages/astro/src/storage/drivers/null.js new file mode 100644 index 0000000000..f43aebee57 --- /dev/null +++ b/packages/astro/src/storage/drivers/null.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/null"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/overlay.js b/packages/astro/src/storage/drivers/overlay.js new file mode 100644 index 0000000000..5946fc6de9 --- /dev/null +++ b/packages/astro/src/storage/drivers/overlay.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/overlay"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/planetscale.js b/packages/astro/src/storage/drivers/planetscale.js new file mode 100644 index 0000000000..5d4749dc81 --- /dev/null +++ b/packages/astro/src/storage/drivers/planetscale.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/planetscale"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/redis.js b/packages/astro/src/storage/drivers/redis.js new file mode 100644 index 0000000000..93817530e4 --- /dev/null +++ b/packages/astro/src/storage/drivers/redis.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/redis"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/sessionStorage.js b/packages/astro/src/storage/drivers/sessionStorage.js new file mode 100644 index 0000000000..b04d704af3 --- /dev/null +++ b/packages/astro/src/storage/drivers/sessionStorage.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/session-storage"; \ No newline at end of file diff --git a/packages/astro/src/storage/drivers/vercelKV.js b/packages/astro/src/storage/drivers/vercelKV.js new file mode 100644 index 0000000000..7e6a96889d --- /dev/null +++ b/packages/astro/src/storage/drivers/vercelKV.js @@ -0,0 +1,2 @@ +// Auto-generated file. Do not edit +export { default } from "unstorage/drivers/vercel-kv"; \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7c68411103..8439020688 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -64,6 +64,9 @@ importers: typescript-eslint: specifier: ^8.13.0 version: 8.13.0(eslint@9.14.0(jiti@2.4.0))(typescript@5.6.3) + unstorage: + specifier: ^1.12.0 + version: 1.13.1 benchmark: dependencies: diff --git a/scripts/deps/update-storage-reexports.js b/scripts/deps/update-storage-reexports.js new file mode 100644 index 0000000000..5b97a848fa --- /dev/null +++ b/scripts/deps/update-storage-reexports.js @@ -0,0 +1,13 @@ +// @ts-check +import { builtinDrivers } from 'unstorage'; +import { promises as fs } from 'node:fs'; + +async function generateStorageReexports() { + await fs.mkdir(new URL('../../packages/astro/src/storage/drivers', import.meta.url), { recursive: true }); + for (const key in builtinDrivers) { + const exports = `// Auto-generated file. Do not edit\nexport { default } from "${builtinDrivers[key]}";`; + await fs.writeFile(new URL(`../../packages/astro/src/storage/drivers/${key}.js`, import.meta.url), exports); + } +} + +generateStorageReexports();