Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(netlify): support @netlify/blobs v8 and improve options types #486

Merged
merged 4 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"server.d.ts"
],
"scripts": {
"bench": "jiti test/server.bench.ts",
"build": "unbuild",
"demo": "vite demo",
"dev": "vitest",
Expand All @@ -39,7 +40,6 @@
"prepack": "pnpm build",
"release": "pnpm test && changelogen --release && git push --follow-tags && pnpm publish",
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
"bench": "jiti test/server.bench.ts",
"test:types": "tsc --noEmit --skipLibCheck",
"unstorage": "pnpm jiti src/cli"
},
Expand All @@ -64,7 +64,7 @@
"@azure/storage-blob": "^12.25.0",
"@capacitor/preferences": "^6.0.2",
"@cloudflare/workers-types": "^4.20241011.0",
"@netlify/blobs": "^7.4.0",
"@netlify/blobs": "^8.1.0",
"@planetscale/database": "^1.19.0",
"@types/ioredis-mock": "^8.2.5",
"@types/jsdom": "^21.1.7",
Expand Down Expand Up @@ -105,7 +105,7 @@
"@azure/keyvault-secrets": "^4.8.0",
"@azure/storage-blob": "^12.24.0",
"@capacitor/preferences": "^6.0.2",
"@netlify/blobs": "^6.5.0 || ^7.0.0",
"@netlify/blobs": "^6.5.0 || ^7.0.0 || ^8.1.0",
"@planetscale/database": "^1.19.0",
"@upstash/redis": "^1.34.0",
"@vercel/kv": "^1.0.1",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 16 additions & 14 deletions src/drivers/netlify-blobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,42 @@ import type {
BlobResponseType,
SetOptions,
ListOptions,
GetStoreOptions,
GetDeployStoreOptions,
} from "@netlify/blobs";
import { fetch } from "ofetch";

const DRIVER_NAME = "netlify-blobs";

type GetOptions = { type?: BlobResponseType };

export interface NetlifyBaseStoreOptions {
/** The name of the store to use. It is created if needed. This is required except for deploy-scoped stores. */
name?: string;
export interface ExtraOptions {
/** If set to `true`, the store is scoped to the deploy. This means that it is only available from that deploy, and will be deleted or rolled-back alongside it. */
deployScoped?: boolean;
/** Required during builds, where it is available as `constants.SITE_ID`. At runtime this is set automatically. */
siteID?: string;
/** Required during builds, where it is available as `constants.NETLIFY_API_TOKEN`. At runtime this is set automatically. */
token?: string;
/** Used for advanced use cases and unit tests */
apiURL?: string;
/** Used for advanced use cases and unit tests */
edgeURL?: string;
}

export interface NetlifyDeployStoreOptions extends NetlifyBaseStoreOptions {
export interface NetlifyDeployStoreOptions
extends GetDeployStoreOptions,
ExtraOptions {
name?: never;
deployScoped: true;
deployID?: string;
}

export interface NetlifyNamedStoreOptions extends NetlifyBaseStoreOptions {
export interface NetlifyDeployStoreLegacyOptions
extends NetlifyDeployStoreOptions {
// Added in v8.0.0. This ensures TS compatibility for older versions.
region?: never;
}

export interface NetlifyNamedStoreOptions
extends GetStoreOptions,
ExtraOptions {
name: string;
deployScoped?: false;
}

export type NetlifyStoreOptions =
| NetlifyDeployStoreLegacyOptions
| NetlifyDeployStoreOptions
| NetlifyNamedStoreOptions;

Expand Down
2 changes: 2 additions & 0 deletions test/drivers/netlify-blobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ describe("drivers: netlify-blobs", async () => {
token,
siteID,
deployID: "test",
// Usually defaulted via the environment; only required in a test environment like this
region: "us-east-1",
serhalp marked this conversation as resolved.
Show resolved Hide resolved
}),
});

Expand Down
Loading