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-blobs): update to v7 #407

Merged
merged 5 commits into from Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 28 additions & 7 deletions docs/2.drivers/netlify.md
Expand Up @@ -8,11 +8,7 @@ icon: teenyicons:netlify-solid

## Usage

Store data in a [Netlify Blobs](https://docs.netlify.com/blobs/overview/) store. This is supported in both edge and Node.js runtimes, as well at during builds.

::warning
Netlify Blobs are in beta.
::
Store data in a [Netlify Blobs](https://docs.netlify.com/blobs/overview/) store. This is supported in both edge and Node.js function runtimes, as well at during builds.

```js
import { createStorage } from "unstorage";
Expand All @@ -25,7 +21,25 @@ const storage = createStorage({
});
```

You can create a deploy-scoped store by settings `deployScoped` option to `true`. This will mean that the deploy only has access to its own store. The store is managed alongside the deploy, with the same deploy previews, deletes, and rollbacks.
When using Unstorage in a Netlify edge function you should use a URL import. This does not apply if you are compiling your code in a framework - just if you are creating your own edge functions.

```js
import { createStorage } from "https://esm.sh/unstorage";
pi0 marked this conversation as resolved.
Show resolved Hide resolved
import netlifyBlobsDriver from "https://esm.sh/unstorage/drivers/netlify-blobs";

export default async function handler(request: Request) {

const storage = createStorage({
driver: netlifyBlobsDriver({
name: "blob-store-name",
}),
});

// ...
}
```

You can create a deploy-scoped store by settings `deployScoped` option to `true`. This will mean that the deploy only has access to its own store. The store is managed alongside the deploy, with the same deploy previews, deletes, and rollbacks. This is required during builds, which only have access to deploy-scoped stores.

```js
import { createStorage } from "unstorage";
Expand All @@ -43,7 +57,7 @@ To use, you will need to install `@netlify/blobs` as dependency or devDependency
```json
{
"devDependencies": {
"@netlify/blobs": "*"
"@netlify/blobs": "latest"
pi0 marked this conversation as resolved.
Show resolved Hide resolved
}
}
```
Expand All @@ -61,3 +75,10 @@ These are not normally needed, but are available for advanced use cases or for u

- `apiURL`
- `edgeURL`

## Updating stores from Netlify Blobs beta
There has been a change in the way global blob stores are stored in `@netlify/blobs` version `7.0.0` which means that you will not be able to access objects in global stores created by older versions until you migrate them. This does not affect deploy-scoped stores, nor does it affect objects created with the new version. You can migrate objects in your old stores by running the following command in the project directory using the latest version of the Netlify CLI:

```sh
netlify recipes blobs-migrate <name of store>
```
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -64,7 +64,7 @@
"@azure/storage-blob": "^12.17.0",
"@capacitor/preferences": "^5.0.7",
"@cloudflare/workers-types": "^4.20240222.0",
"@netlify/blobs": "^6.5.0",
"@netlify/blobs": "^7.0.0",
"@planetscale/database": "^1.16.0",
"@types/ioredis-mock": "^8.2.5",
"@types/jsdom": "^21.1.6",
Expand Down Expand Up @@ -103,7 +103,7 @@
"@azure/keyvault-secrets": "^4.8.0",
"@azure/storage-blob": "^12.17.0",
"@capacitor/preferences": "^5.0.7",
"@netlify/blobs": "^6.5.0",
"@netlify/blobs": "^6.5.0 || ^7.0.0",
pi0 marked this conversation as resolved.
Show resolved Hide resolved
"@planetscale/database": "^1.16.0",
"@upstash/redis": "^1.28.4",
"@vercel/kv": "^0.2.4",
Expand Down
13 changes: 9 additions & 4 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions test/drivers/netlify-blobs.test.ts
@@ -1,11 +1,11 @@
import { afterAll, beforeAll, describe } from "vitest";
import driver from "../../src/drivers/netlify-blobs";
import { testDriver } from "./utils";
import { BlobsServer } from "@netlify/blobs";
import { BlobsServer } from "@netlify/blobs/server";
import { resolve } from "path";
import { rm, mkdir } from "node:fs/promises";

describe.skip("drivers: netlify-blobs", async () => {
describe("drivers: netlify-blobs", async () => {
const dataDir = resolve(__dirname, "tmp/netlify-blobs");
await rm(dataDir, { recursive: true, force: true }).catch(() => {});
await mkdir(dataDir, { recursive: true });
Expand Down