Skip to content

Commit

Permalink
refactor(netlify-blobs): update to v7 (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Mar 14, 2024
1 parent 85bdbb7 commit 4187d88
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
41 changes: 34 additions & 7 deletions docs/2.drivers/netlify.md
Expand Up @@ -6,14 +6,13 @@ icon: teenyicons:netlify-solid

> Store data in Netlify Blobs.
## 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.
Store data in a [Netlify Blobs](https://docs.netlify.com/blobs/overview/) store This is supported in both [edge](#using-in-netlify-edge) and Node.js function runtimes, as well at during builds.

::warning
Netlify Blobs are in beta.
::read-more{title="Netlify Blobs" to="https://docs.netlify.com/blobs/overview/"}
::

## Usage

```js
import { createStorage } from "unstorage";
import netlifyBlobsDriver from "unstorage/drivers/netlify-blobs";
Expand All @@ -25,7 +24,7 @@ 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.
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 +42,7 @@ To use, you will need to install `@netlify/blobs` as dependency or devDependency
```json
{
"devDependencies": {
"@netlify/blobs": "*"
"@netlify/blobs": "latest"
}
}
```
Expand All @@ -61,3 +60,31 @@ These are not normally needed, but are available for advanced use cases or for u

- `apiURL`
- `edgeURL`

## Using in netlify edge

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";
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",
}),
});

// ...
}
```

## 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 @@ -63,7 +63,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",
"@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

0 comments on commit 4187d88

Please sign in to comment.