chore: update docs

This commit is contained in:
Pooya Parsa
2024-02-23 19:42:35 +01:00
parent bfbf423615
commit f78ffc463b
38 changed files with 596 additions and 10526 deletions

47
docs/.config/docs.yaml Normal file
View File

@@ -0,0 +1,47 @@
# yaml-language-server: $schema=https://unpkg.com/undocs/schema/config.json
name: unstorage
shortDescription: Universal Key-Value Storage.
description: Unstorage is TypeScript library that provides an async key-value storage API with conventional features like multi driver mounting, watching, working with metadata and has 20+ built-in drivers.
github: unjs/unstorage
themeColor: amber
url: https://unstorage.unjs.io
redirects:
"/usage": "/getting-started/usage"
"/utils": "/getting-started/utils"
"/http-server": "/getting-started/http-server"
"/custom-driver": "/getting-started/custom-driver"
"/drivers/azure-app-configuration": "/divers/azure"
"/drivers/azure-cosmos": "/divers/azure"
"/drivers/azure-key-vault": "/divers/azure"
"/drivers/azure-storage-block": "/divers/azure"
"/drivers/azure-storage-table": "/divers/azure"
"/drivers/cloudflare-kv-binding": "/drivers/cloudflare"
"/drivers/cloudflare-kv-http": "/drivers/cloudflare"
"/drivers/cloudflare-r2-binding": "/drivers/cloudflare"
"/drivers/vercel-kv": "/drivers/vercel"
"/drivers/netlify-blobs": "/drivers/netlify"
"/drivers/localstorage": "/drivers/browser"
"/drivers/indexedb": "/drivers/browser"
"/drivers/session-storage": "/drivers/browser"
landing:
contributors: true
featuresTitle: A simple, small, and fast key-value storage library for JavaScript.
features:
- title: "Runtime Agnostic"
description: "Your code will work on any JavaScript runtime including Node.js, Bun, Deno and Workers."
icon: "i-material-symbols-lock-open-right-outline-rounded"
- title: "Built-in drivers"
description: "Unstorage is shipped with 20+ built-in drivers for different platforms: Memory (default), FS, Redis, Memory, MongoDB, CloudFlare, GitHub..."
icon: "i-material-symbols-usb"
- title: "Snapshots"
description: "Expand your server and add capabilities. Your codebase will scale with your project."
icon: "i-material-symbols-add-a-photo-outline"
- title: "Multi Storages"
description: "Unix-style driver mounting to combine storages on different mounts."
icon: "i-material-symbols-view-list-outline"
- title: "JSON friendly"
description: "Unstorage automatically serialization and deserialization JSON values."
icon: "i-material-symbols-magic-button"
- title: "Binary Support"
description: "Store binary and raw data like images, videos, audio files, etc."
icon: "i-material-symbols-audio-file"

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -1,2 +0,0 @@
shamefully-hoist=true
ignore-workspace-root-check=true

View File

@@ -1,6 +1,10 @@
# Usage
---
icon: ph:book-open-duotone
---
Learn how to setup and use unstorage in your project.
# Getting Started
> Learn how to setup and use unstorage in your project.
## Introduction
@@ -10,21 +14,7 @@ We usually choose one or more storage backends based on our use-cases such as fi
Install [`unstorage`](https://npmjs.com/package/unstorage) npm package:
::code-group
```sh [npm]
npm install unstorage
```
```sh [Yarn]
yarn add unstorage
```
```sh [pnpm]
pnpm add unstorage
```
::
:pm-install{name="unstorage"}
## Usage
@@ -260,7 +250,7 @@ storage.getMounts("cache:sub", { parents: true });
// => [{ base: "cache:sub", driver }, { base: "cache:", driver }, { base: "", driver }]
```
## Generic Types
## Generic types
**Type `getItem` return value:**

View File

@@ -1,6 +1,10 @@
# Extra Utilities
---
icon: et:tools-2
---
Unstorage exposes several utilities. You can individually import them and add only needed bytes to your bundle.
# Utilities
> Unstorage exposes several utilities. You can individually import them and add only needed bytes to your bundle.
## Namespace

View File

@@ -1,6 +1,10 @@
---
icon: ic:baseline-http
---
# HTTP Server
We can expose unstorage instance to an http server to allow remote connections.
> We can expose unstorage instance to an http server to allow remote connections.
Request url is mapped to key and method/body mapped to function. See below for supported http methods.

View File

@@ -1,6 +1,10 @@
---
icon: carbon:area-custom
---
# Custom Driver
It is possible to extend `unstorage` by creating a custom driver.
> It is possible to extend `unstorage` by creating a custom driver.
Explore [src/drivers](https://github.com/unjs/unstorage/tree/main/src/drivers) to inspire how to implement them. Methods can
@@ -28,7 +32,6 @@ const storage = createStorage({
```
Some important notes:
::list{type="warning"}
- Keys should be normalized following `foo:bar` convention
- Remove any open watcher and handlers in `dispose()`
@@ -36,4 +39,3 @@ Some important notes:
- You don't have acces to the mount base
- Value returned by `getItem` can be a serializable `object` or `string`
- When setting `watch` method, unstorage default handler will be disabled. You are responsible to emit event on `getItem`, `setItem` and `removeItem`.
::

13
docs/2.drivers/0.index.md Normal file
View File

@@ -0,0 +1,13 @@
----
icon: icon-park-outline:hard-disk
---
# Drivers
> Unstorage has several built-in drivers
See next sections for guide about using each driver.
::read-more{to="/guide#mountmountpoint-driver"}
See [`driver.mount()`] to learn about how to
::

253
docs/2.drivers/azure.md Normal file
View File

@@ -0,0 +1,253 @@
----
icon: mdi:microsoft-azure
---
# Azure
## Azure App Configuration
Store data in the key value store of Azure App Configuration.
### Usage
::note{to="https://learn.microsoft.com/en-us/azure/azure-app-configuration/overview"}
Learn more about Azure App Configuration.
::
This driver uses the configuration store as a key value store. It uses the `key` as the name and the `value` as content. You can also use labels to differentiate between different environments (dev, prod, etc.) and use prefixes to differentiate between different applications (app01, app02, etc.).
To use it, you will need to install `@azure/app-configuration` and `@azure/identity` in your project:
```bash
npm i @azure/app-configuration @azure/identity
```
Usage:
```js
import { createStorage } from "unstorage";
import azureAppConfiguration from "unstorage/drivers/azure-app-configuration";
const storage = createStorage({
driver: azureAppConfiguration({
appConfigName: "unstoragetest",
label: "dev",
prefix: "app01",
}),
});
```
**Authentication:**
The driver supports the following authentication methods:
- **`DefaultAzureCredential`**: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate. <br>
⚠️ Make sure that your Managed Identity or personal account has the `App Configuration Data Owner` role assigned to it, even if you already are `Contributor` or `Owner` on the app configuration resource.
- **`connectionString`**: The app configuration connection string. Not recommended for use in production.
**Options:**
- `appConfigName`: The name of the app configuration resource.
- `endpoint`: The endpoint of the app configuration resource.
- `connectionString`: The connection string of the app configuration resource.
- `prefix`: Optional prefix for keys. This can be used to isolate keys from different applications in the same Azure App Configuration instance. E.g. "app01" results in keys like "app01:foo" and "app01:bar".
- `label`: Optional label for keys. If not provided, all keys will be created and listed without labels. This can be used to isolate keys from different environments in the same Azure App Configuration instance. E.g. "dev" results in keys like "foo" and "bar" with the label "dev".
## Azure Cosmos DB
Store data in Azure Cosmos DB NoSQL API documents.
### Usage
::note{to="https://azure.microsoft.com/en-us/services/cosmos-db/"}
Learn more about Azure Cosmos DB.
::
This driver stores KV information in a NoSQL API Cosmos DB collection as documents. It uses the `id` field as the key and adds `value` and `modified` fields to the document.
To use it, you will need to install `@azure/cosmos` and `@azure/identity` in your project:
```bash
npm i @azure/cosmos @azure/identity
```
Usage:
```js
import { createStorage } from "unstorage";
import azureCosmos from "unstorage/drivers/azure-cosmos";
const storage = createStorage({
driver: azureCosmos({
endpoint: "ENDPOINT",
accountKey: "ACCOUNT_KEY",
}),
});
```
**Authentication:**
- **`DefaultAzureCredential`**: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate. <br>
⚠️ Make sure that your Managed Identity or personal account has at least `Cosmos DB Built-in Data Contributor` role assigned to it. If you already are `Contributor` or `Owner` on the resource it should also be enough, but does not accomplish a model of least privilege.
- **`accountKey`**: CosmosDB account key. If not provided, the driver will use the DefaultAzureCredential (recommended).
**Options:**
- **`endpoint`** (required): CosmosDB endpoint in the format of `https://<account>.documents.azure.com:443/`.
- `accountKey`: CosmosDB account key. If not provided, the driver will use the DefaultAzureCredential (recommended).
- `databaseName`: The name of the database to use. Defaults to `unstorage`.
- `containerName`: The name of the container to use. Defaults to `unstorage`.
## Azure Key Vault
Store data in a Azure Key Vault secrets.
### Usage
::note{to="https://docs.microsoft.com/en-us/azure/key-vault/secrets/about-secrets"}
Learn more about Azure Key Vault secrets.
::
This driver stores KV information in Azure Key Vault secrets by using the key as secret id and the value as secret content.
Please be aware that key vault secrets don't have the fastest access time and are not designed for high throughput. You also have to disable purge protection for your key vault to be able to delete secrets. This implementation deletes and purges a secret when it is deleted to avoid conflicts with soft delete.
⚠️ Be aware that this driver stores the keys of your `key:value` pairs in an encoded way in Key Vault to avoid conflicts with naming requirements for secrets. This means that you will not be able to access manually (outside of unstorage) created secrets inside your Key Vault, as long as they are not encoded in the same way.
To use it, you will need to install `@azure/keyvault-secrets` and `@azure/identity` in your project:
```bash
npm i @azure/keyvault-secrets @azure/identity
```
Usage:
```js
import { createStorage } from "unstorage";
import azureKeyVault from "unstorage/drivers/azure-key-vault";
const storage = createStorage({
driver: azureKeyVault({
vaultName: "testunstoragevault",
}),
});
```
**Authentication:**
The driver supports the following authentication methods:
- **`DefaultAzureCredential`**: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate.
⚠️ Make sure that your Managed Identity or personal account has either the `Key Vault Secrets Officer` (or `Key Vault Secrets User` for read-only) RBAC role assigned or is a member of an access policy that grants `Get`, `List`, `Set`, `Delete` and `Purge` secret permissions.
**Options:**
- **`vaultName`** (required): The name of the key vault to use.
- `serviceVersion`: Version of the Azure Key Vault service to use. Defaults to 7.3.
- `pageSize`: The number of entries to retrieve per request. Impacts getKeys() and clear() performance. Maximum value is 25.
## Azure Blob Storage
Store data in a Azure blob storage.
### Usage
::note{to="https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-blob"}
Learn more about Azure blob storage.
::
This driver stores KV information in a Azure blob storage blob. The same container is used for all entries. Each entry is stored in a separate blob with the key as the blob name and the value as the blob content.
To use it, you will need to install `@azure/storage-blob` and `@azure/identity` in your project:
```bash
npm i @azure/storage-blob @azure/identity
```
Please make sure that the container you want to use exists in your storage account.
```js
import { createStorage } from "unstorage";
import azureStorageBlobDriver from "unstorage/drivers/azure-storage-blob";
const storage = createStorage({
driver: azureStorageBlobDriver({
accountName: "myazurestorageaccount",
}),
});
```
**Authentication:**
The driver supports the following authentication methods:
- **`DefaultAzureCredential`**: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate. <br>
⚠️ Make sure that your Managed Identity or personal account has the `Storage Blob Data Contributor` role assigned to it, even if you already are `Contributor` or `Owner` on the storage account.
- **`AzureNamedKeyCredential`** (only available in Node.js runtime): This will use the `accountName` and `accountKey` to authenticate the request.
- **`AzureSASCredential`**: This will use the `accountName` and `sasToken` to authenticate the request.
- **connection string** (only available in Node.js runtime): This will use the `connectionString` to authenticate the request. This is not recommended as it will expose your account key in plain text.
**Options:**
- **`accountName`** (required): The name of your storage account.
- `containerName`: The name of the blob container to use. Defaults to `unstorage`.
- `accountKey`: The account key to use for authentication. This is only required if you are using `AzureNamedKeyCredential`.
- `sasKey`: The SAS token to use for authentication. This is only required if you are using `AzureSASCredential`.
- `connectionString`: The storage accounts' connection string. `accountKey` and `sasKey` take precedence.
## Azure Table Storage
Store data in a Azure table storage.
### Usage
::note{to="https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/tables/data-tables"}
Learn more about Azure table storage.
::
::warning
This driver is currently not compatible with edge workers like Cloudflare Workers or Vercel Edge Functions. There may be a http based driver in the future.
::
Store data in a [data-tables]().
This driver stores KV information in a Azure table storage. The same partition key is used for all keys and the field `unstorageValue` is used to store the value.
To use it, you will need to install `@azure/data-table` and `@azure/identity` in your project:
```bash
npm i @azure/data-table @azure/identity
```
Please make sure that the table you want to use exists in your storage account.
```js
import { createStorage } from "unstorage";
import azureStorageTableDriver from "unstorage/drivers/azure-storage-table";
const storage = createStorage({
driver: azureStorageTableDriver({
accountName: "myazurestorageaccount",
}),
});
```
**Authentication:**
The driver supports the following authentication methods:
- **`DefaultAzureCredential`**: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate.
⚠️ Make sure that your Managed Identity or personal account has the `Storage Table Data Contributor` role assigned to it, even if you already are `Contributor` or `Owner` on the storage account.
- **`AzureNamedKeyCredential`** (only available in Node.js runtime): This will use the `accountName` and `accountKey` to authenticate the request.
- **`AzureSASCredential`**: This will use the `accountName` and `sasToken` to authenticate the request.
- **connection string** (only available in Node.js runtime): This will use the `connectionString` to authenticate the request. This is not recommended as it will expose your account key in plain text.
**Options:**
- **`accountName`** (required): The name of your storage account.
- `tableName`: The name of the table to use. Defaults to `unstorage`.
- `partitionKey`: The partition key to use. Defaults to `unstorage`.
- `accountKey`: The account key to use for authentication. This is only required if you are using `AzureNamedKeyCredential`.
-

92
docs/2.drivers/browser.md Normal file
View File

@@ -0,0 +1,92 @@
----
icon: ph:browser-thin
---
# Browser
> Browser based storages
## Local Storage
Store data in localStorage.
### Usage
::read-more{to="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage"}
Learn more about localStorage.
::
```js
import { createStorage } from "unstorage";
import localStorageDriver from "unstorage/drivers/localstorage";
const storage = createStorage({
driver: localStorageDriver({ base: "app:" }),
});
```
**Options:**
- `base`: Add `${base}:` to all keys to avoid collision
- `localStorage`: Optionally provide `localStorage` object
- `window`: Optionally provide `window` object
## Session Storage
> Store data in sessionStorage.
::read-more{to="https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage"}
Learn more about sessionStorage.
::
```js
import { createStorage } from "unstorage";
import sessionStorageDriver from "unstorage/drivers/session-storage";
const storage = createStorage({
driver: sessionStorageDriver({ base: "app:" }),
});
```
**Options:**
- `base`: Add `${base}:` to all keys to avoid collision
- `sessionStorage`: Optionally provide `sessionStorage` object
- `window`: Optionally provide `window` object
## IndexedDB
Store key-value in IndexedDB.
### Usage
::read-more{to="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API"}
Learn more about IndexedDB.
::
To use it, you will need to install [`idb-keyval`](https://github.com/jakearchibald/idb-keyval) in your project:
```bash [Terminal]
npm i idb-keyval
```
Usage:
```js
import { createStorage } from "unstorage";
import indexedDbDriver from "unstorage/drivers/indexedb";
const storage = createStorage({
driver: indexedDbDriver({ base: "app:" }),
});
```
**Options:**
- `base`: Add `${base}:` to all keys to avoid collision
- `dbName`: Custom name for database. Defaults to `keyval-store`
- `storeName`: Custom name for store. Defaults to `keyval`
::note
IndexedDB is a browser database. avoid using this preset on server environments.
::

View File

@@ -1,13 +1,17 @@
---
icon: nonicons:capacitor-16
---
# Capacitor Preferences
Stores data via Capacitor Preferences API on mobile devices or the local storage on the web.
> Stores data via Capacitor Preferences API on mobile devices or the local storage on the web.
## Usage
::note{to="https://capacitorjs.com/docs/apis/preferences"}
::read-more{to="https://capacitorjs.com/docs/apis/preferences"}
Learn more about Capacitor Preferences API.
::
## Usage
To use this driver, you need to install and sync `@capacitor/preferences` inside your capacitor project:
::code-group

View File

@@ -1,10 +1,60 @@
# Cloudflare KV (http)
---
icon: devicon-plain:cloudflareworkers
---
Store data in Cloudflare KV using the Cloudflare API v4.
# Cloudflare
## Usage
> Store data in Cloudflare KV or R2 storage.
::note{to="https://developers.cloudflare.com/api/operations/workers-kv-namespace-list-namespaces"}
## CloudFlare KV (binding)
> Store data in Cloudflare KV and access from worker bindings.
### Usage
::read-more{to="https://developers.cloudflare.com/workers/runtime-apis/kv"}
Learn more about Cloudflare KV.
::
**Note:** This driver only works in a cloudflare worker environment, use `cloudflare-kv-http` for other environments.
You need to create and assign a KV. See [KV Bindings](https://developers.cloudflare.com/workers/runtime-apis/kv#kv-bindings) for more information.
```js
import { createStorage } from "unstorage";
import cloudflareKVBindingDriver from "unstorage/drivers/cloudflare-kv-binding";
// Using binding name to be picked from globalThis
const storage = createStorage({
driver: cloudflareKVBindingDriver({ binding: "STORAGE" }),
});
// Directly setting binding
const storage = createStorage({
driver: cloudflareKVBindingDriver({ binding: globalThis.STORAGE }),
});
// Using from Durable Objects and Workers using Modules Syntax
const storage = createStorage({
driver: cloudflareKVBindingDriver({ binding: this.env.STORAGE }),
});
// Using outside of Cloudflare Workers (like Node.js)
// Use cloudflare-kv-http
```
**Options:**
- `binding`: KV binding or name of namespace. Default is `STORAGE`.
- `base`: Adds prefix to all stored keys
## Cloudflare KV (http)
> Store data in Cloudflare KV using the Cloudflare API v4.
### Usage
::read-more{to="https://developers.cloudflare.com/api/operations/workers-kv-namespace-list-namespaces"}
Learn more about Cloudflare KV API.
::
@@ -64,3 +114,42 @@ const storage = createStorage({
- `removeItem`: Maps to [Delete key-value pair](https://api.cloudflare.com/#workers-kv-namespace-delete-key-value-pair) `DELETE accounts/:account_identifier/storage/kv/namespaces/:namespace_identifier/values/:key_name`
- `getKeys`: Maps to [List a Namespace's Keys](https://api.cloudflare.com/#workers-kv-namespace-list-a-namespace-s-keys) `GET accounts/:account_identifier/storage/kv/namespaces/:namespace_identifier/keys`
- `clear`: Maps to [Delete key-value pair](https://api.cloudflare.com/#workers-kv-namespace-delete-multiple-key-value-pairs) `DELETE accounts/:account_identifier/storage/kv/namespaces/:namespace_identifier/bulk`
## CloudFlare R2 (binding)
> Store data in Cloudflare R2 buckets and access from worker bindings.
::warning
This is an experimental driver! This driver only works in a cloudflare worker environment and cannot be used in other runtime environments such as Node.js (r2-http driver is coming soon)
::
::read-more{to="https://developers.cloudflare.com/r2/api/workers/workers-api-reference/"}
Learn more about Cloudflare R2 buckets.
::
You need to create and assign a R2 bucket. See [R2 Bindings](https://developers.cloudflare.com/r2/api/workers/workers-api-reference/#create-a-binding) for more information.
```js
import { createStorage } from "unstorage";
import cloudflareR2BindingDriver from "unstorage/drivers/cloudflare-r2-binding";
// Using binding name to be picked from globalThis
const storage = createStorage({
driver: cloudflareR2BindingDriver({ binding: "BUCKET" }),
});
// Directly setting binding
const storage = createStorage({
driver: cloudflareR2BindingDriver({ binding: globalThis.BUCKET }),
});
// Using from Durable Objects and Workers using Modules Syntax
const storage = createStorage({
driver: cloudflareR2BindingDriver({ binding: this.env.BUCKET }),
});
```
**Options:**
- `binding`: Bucket binding or name. Default is `BUCKET`.
- `base`: Prefix all keys with base.

View File

@@ -1,6 +1,10 @@
# Node.js Filesystem
---
icon: ph:file-light
---
Store data in the real filesystem using Node.js API.
# Filesystem (Node.js)
> Store data in the filesystem using Node.js API.
## Usage

View File

@@ -1,6 +1,10 @@
---
icon: mdi:github
---
# GitHub
Map files from a remote github repository (readonly).
> Map files from a remote github repository (readonly).
## Usage

View File

@@ -1,6 +1,10 @@
---
icon: ic:baseline-http
---
# HTTP
Use a remote HTTP/HTTPS endpoint as data storage.
> Use a remote HTTP/HTTPS endpoint as data storage.
## Usage

View File

@@ -1,6 +1,10 @@
---
icon: material-symbols:cached-rounded
---
# LRU Cache
Keeps cached data in memory using LRU Cache.
> Keeps cached data in memory using LRU Cache.
## Usage

View File

@@ -1,12 +1,16 @@
---
title: Memory
description: Keeps data in memory using Map.
navigation.badge: Default
icon: bi:memory
---
Keeps data in memory using [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map).
# Memory
> Keep data in memory.
Keeps data in memory using [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map). (default storage)
::note
By default it is mounted to top level so it is unlikely you need to mount it again.
::
```js
import { createStorage } from "unstorage";

View File

@@ -1,10 +1,14 @@
---
icon: teenyicons:mongodb-outline
---
# MongoDB
Store data in MongoDB using Node.js mongodb package.
> Store data in MongoDB using Node.js mongodb package.
## Usage
::note{to="https://www.mongodb.com/"}
::read-more{to="https://www.mongodb.com/"}
Learn more about MongoDB.
::

View File

@@ -1,6 +1,10 @@
---
icon: teenyicons:netlify-solid
---
# Netlify Blobs
Store data in Netlify Blobs.
> Store data in Netlify Blobs.
## Usage

View File

@@ -1,3 +1,7 @@
---
icon: carbon:overlay
---
# Overlay
This is a special driver that creates a multi-layer overlay driver.

View File

@@ -1,10 +1,14 @@
---
icon: simple-icons:planetscale
---
# PlanetScale
Stores data in MySQL database via PlanetScale.
> Store data in MySQL database via PlanetScale.
## Usage
::note{to="https://docs.microsoft.com/en-us/azure/key-vault/secrets/about-secrets"}
::read-more{to="https://docs.microsoft.com/en-us/azure/key-vault/secrets/about-secrets"}
Learn more about PlanetScale.
::
@@ -20,7 +24,7 @@ To use, you will need to install `@planetscale/database` in your project:
}
```
Then you can create a table to store your data by running the following query in your Planetscale database, where <storage> is the name of the table you want to use:
Then you can create a table to store your data by running the following query in your Planetscale database, where `<storage>` is the name of the table you want to use:
```
create table <storage> (

View File

@@ -1,10 +1,14 @@
---
icon: simple-icons:redis
---
# Redis
Store data in a Redis.
> Store data in a Redis.
## Usage
::note{to="https://redis.com"}
::read-more{to="https://redis.com"}
Learn more about Redis.
::

View File

@@ -1,8 +1,12 @@
---
icon: gg:vercel
---
# Vercel KV
Store data in a Vercel KV Store.
> Store data in a Vercel KV Store.
::note{to="https://vercel.com/docs/storage/vercel-kv"}
::read-more{to="https://vercel.com/docs/storage/vercel-kv"}
Learn more about Vercel KV.
::

BIN
docs/bun.lockb Executable file

Binary file not shown.

View File

@@ -1,48 +0,0 @@
# Azure App Configuration
Store data in the key value store of Azure App Configuration.
## Usage
::note{to="https://learn.microsoft.com/en-us/azure/azure-app-configuration/overview"}
Learn more about Azure App Configuration.
::
This driver uses the configuration store as a key value store. It uses the `key` as the name and the `value` as content. You can also use labels to differentiate between different environments (dev, prod, etc.) and use prefixes to differentiate between different applications (app01, app02, etc.).
To use it, you will need to install `@azure/app-configuration` and `@azure/identity` in your project:
```bash
npm i @azure/app-configuration @azure/identity
```
Usage:
```js
import { createStorage } from "unstorage";
import azureAppConfiguration from "unstorage/drivers/azure-app-configuration";
const storage = createStorage({
driver: azureAppConfiguration({
appConfigName: "unstoragetest",
label: "dev",
prefix: "app01",
}),
});
```
**Authentication:**
The driver supports the following authentication methods:
- **`DefaultAzureCredential`**: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate. <br>
⚠️ Make sure that your Managed Identity or personal account has the `App Configuration Data Owner` role assigned to it, even if you already are `Contributor` or `Owner` on the app configuration resource.
- **`connectionString`**: The app configuration connection string. Not recommended for use in production.
**Options:**
- `appConfigName`: The name of the app configuration resource.
- `endpoint`: The endpoint of the app configuration resource.
- `connectionString`: The connection string of the app configuration resource.
- `prefix`: Optional prefix for keys. This can be used to isolate keys from different applications in the same Azure App Configuration instance. E.g. "app01" results in keys like "app01:foo" and "app01:bar".
- `label`: Optional label for keys. If not provided, all keys will be created and listed without labels. This can be used to isolate keys from different environments in the same Azure App Configuration instance. E.g. "dev" results in keys like "foo" and "bar" with the label "dev".

View File

@@ -1,44 +0,0 @@
# Azure Cosmos DB
Store data in Azure Cosmos DB NoSQL API documents.
## Usage
::note{to="https://azure.microsoft.com/en-us/services/cosmos-db/"}
Learn more about Azure Cosmos DB.
::
This driver stores KV information in a NoSQL API Cosmos DB collection as documents. It uses the `id` field as the key and adds `value` and `modified` fields to the document.
To use it, you will need to install `@azure/cosmos` and `@azure/identity` in your project:
```bash
npm i @azure/cosmos @azure/identity
```
Usage:
```js
import { createStorage } from "unstorage";
import azureCosmos from "unstorage/drivers/azure-cosmos";
const storage = createStorage({
driver: azureCosmos({
endpoint: "ENDPOINT",
accountKey: "ACCOUNT_KEY",
}),
});
```
**Authentication:**
- **`DefaultAzureCredential`**: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate. <br>
⚠️ Make sure that your Managed Identity or personal account has at least `Cosmos DB Built-in Data Contributor` role assigned to it. If you already are `Contributor` or `Owner` on the resource it should also be enough, but does not accomplish a model of least privilege.
- **`accountKey`**: CosmosDB account key. If not provided, the driver will use the DefaultAzureCredential (recommended).
**Options:**
- **`endpoint`** (required): CosmosDB endpoint in the format of `https://<account>.documents.azure.com:443/`.
- `accountKey`: CosmosDB account key. If not provided, the driver will use the DefaultAzureCredential (recommended).
- `databaseName`: The name of the database to use. Defaults to `unstorage`.
- `containerName`: The name of the container to use. Defaults to `unstorage`.

View File

@@ -1,47 +0,0 @@
# Azure Key Vault
Store data in a Azure Key Vault secrets.
## Usage
::note{to="https://docs.microsoft.com/en-us/azure/key-vault/secrets/about-secrets"}
Learn more about Azure Key Vault secrets.
::
This driver stores KV information in Azure Key Vault secrets by using the key as secret id and the value as secret content.
Please be aware that key vault secrets don't have the fastest access time and are not designed for high throughput. You also have to disable purge protection for your key vault to be able to delete secrets. This implementation deletes and purges a secret when it is deleted to avoid conflicts with soft delete.
⚠️ Be aware that this driver stores the keys of your `key:value` pairs in an encoded way in Key Vault to avoid conflicts with naming requirements for secrets. This means that you will not be able to access manually (outside of unstorage) created secrets inside your Key Vault, as long as they are not encoded in the same way.
To use it, you will need to install `@azure/keyvault-secrets` and `@azure/identity` in your project:
```bash
npm i @azure/keyvault-secrets @azure/identity
```
Usage:
```js
import { createStorage } from "unstorage";
import azureKeyVault from "unstorage/drivers/azure-key-vault";
const storage = createStorage({
driver: azureKeyVault({
vaultName: "testunstoragevault",
}),
});
```
**Authentication:**
The driver supports the following authentication methods:
- **`DefaultAzureCredential`**: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate.
⚠️ Make sure that your Managed Identity or personal account has either the `Key Vault Secrets Officer` (or `Key Vault Secrets User` for read-only) RBAC role assigned or is a member of an access policy that grants `Get`, `List`, `Set`, `Delete` and `Purge` secret permissions.
**Options:**
- **`vaultName`** (required): The name of the key vault to use.
- `serviceVersion`: Version of the Azure Key Vault service to use. Defaults to 7.3.
- `pageSize`: The number of entries to retrieve per request. Impacts getKeys() and clear() performance. Maximum value is 25.

View File

@@ -1,48 +0,0 @@
# Azure Blob Storage
Store data in a Azure blob storage.
## Usage
::note{to="https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-blob"}
Learn more about Azure blob storage.
::
This driver stores KV information in a Azure blob storage blob. The same container is used for all entries. Each entry is stored in a separate blob with the key as the blob name and the value as the blob content.
To use it, you will need to install `@azure/storage-blob` and `@azure/identity` in your project:
```bash
npm i @azure/storage-blob @azure/identity
```
Please make sure that the container you want to use exists in your storage account.
```js
import { createStorage } from "unstorage";
import azureStorageBlobDriver from "unstorage/drivers/azure-storage-blob";
const storage = createStorage({
driver: azureStorageBlobDriver({
accountName: "myazurestorageaccount",
}),
});
```
**Authentication:**
The driver supports the following authentication methods:
- **`DefaultAzureCredential`**: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate. <br>
⚠️ Make sure that your Managed Identity or personal account has the `Storage Blob Data Contributor` role assigned to it, even if you already are `Contributor` or `Owner` on the storage account.
- **`AzureNamedKeyCredential`** (only available in Node.js runtime): This will use the `accountName` and `accountKey` to authenticate the request.
- **`AzureSASCredential`**: This will use the `accountName` and `sasToken` to authenticate the request.
- **connection string** (only available in Node.js runtime): This will use the `connectionString` to authenticate the request. This is not recommended as it will expose your account key in plain text.
**Options:**
- **`accountName`** (required): The name of your storage account.
- `containerName`: The name of the blob container to use. Defaults to `unstorage`.
- `accountKey`: The account key to use for authentication. This is only required if you are using `AzureNamedKeyCredential`.
- `sasKey`: The SAS token to use for authentication. This is only required if you are using `AzureSASCredential`.
- `connectionString`: The storage accounts' connection string. `accountKey` and `sasKey` take precedence.

View File

@@ -1,56 +0,0 @@
# Azure Table Storage
Store data in a Azure table storage.
## Usage
::note{to="https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/tables/data-tables"}
Learn more about Azure table storage.
::
::warning
This driver is currently not compatible with edge workers like Cloudflare Workers or Vercel Edge Functions. There may be a http based driver in the future.
::
Store data in a [data-tables]().
This driver stores KV information in a Azure table storage. The same partition key is used for all keys and the field `unstorageValue` is used to store the value.
To use it, you will need to install `@azure/data-table` and `@azure/identity` in your project:
```bash
npm i @azure/data-table @azure/identity
```
Please make sure that the table you want to use exists in your storage account.
```js
import { createStorage } from "unstorage";
import azureStorageTableDriver from "unstorage/drivers/azure-storage-table";
const storage = createStorage({
driver: azureStorageTableDriver({
accountName: "myazurestorageaccount",
}),
});
```
**Authentication:**
The driver supports the following authentication methods:
- **`DefaultAzureCredential`**: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate.
⚠️ Make sure that your Managed Identity or personal account has the `Storage Table Data Contributor` role assigned to it, even if you already are `Contributor` or `Owner` on the storage account.
- **`AzureNamedKeyCredential`** (only available in Node.js runtime): This will use the `accountName` and `accountKey` to authenticate the request.
- **`AzureSASCredential`**: This will use the `accountName` and `sasToken` to authenticate the request.
- **connection string** (only available in Node.js runtime): This will use the `connectionString` to authenticate the request. This is not recommended as it will expose your account key in plain text.
**Options:**
- **`accountName`** (required): The name of your storage account.
- `tableName`: The name of the table to use. Defaults to `unstorage`.
- `partitionKey`: The partition key to use. Defaults to `unstorage`.
- `accountKey`: The account key to use for authentication. This is only required if you are using `AzureNamedKeyCredential`.
-

View File

@@ -1,41 +0,0 @@
# CloudFlare KV (binding)
Store data in Cloudflare KV and access from worker bindings.
## Usage
::note{to="https://developers.cloudflare.com/workers/runtime-apis/kv"}
Learn more about Cloudflare KV.
::
**Note:** This driver only works in a cloudflare worker environment, use [`cloudflare-kv-http`](/drivers/cloudflare-kv-http) for other environments.
You need to create and assign a KV. See [KV Bindings](https://developers.cloudflare.com/workers/runtime-apis/kv#kv-bindings) for more information.
```js
import { createStorage } from "unstorage";
import cloudflareKVBindingDriver from "unstorage/drivers/cloudflare-kv-binding";
// Using binding name to be picked from globalThis
const storage = createStorage({
driver: cloudflareKVBindingDriver({ binding: "STORAGE" }),
});
// Directly setting binding
const storage = createStorage({
driver: cloudflareKVBindingDriver({ binding: globalThis.STORAGE }),
});
// Using from Durable Objects and Workers using Modules Syntax
const storage = createStorage({
driver: cloudflareKVBindingDriver({ binding: this.env.STORAGE }),
});
// Using outside of Cloudflare Workers (like Node.js)
// Use cloudflare-kv-http
```
**Options:**
- `binding`: KV binding or name of namespace. Default is `STORAGE`.
- `base`: Adds prefix to all stored keys

View File

@@ -1,38 +0,0 @@
# CloudFlare R2 (binding)
Store data in Cloudflare R2 buckets and access from worker bindings.
::warning
This is an experimental driver! This driver only works in a cloudflare worker environment and cannot be used in other runtime environments such as Node.js (r2-http driver is coming soon)
::
::note{to="https://developers.cloudflare.com/r2/api/workers/workers-api-reference/"}
Learn more about Cloudflare R2 buckets.
::
You need to create and assign a R2 bucket. See [R2 Bindings](https://developers.cloudflare.com/r2/api/workers/workers-api-reference/#create-a-binding) for more information.
```js
import { createStorage } from "unstorage";
import cloudflareR2BindingDriver from "unstorage/drivers/cloudflare-r2-binding";
// Using binding name to be picked from globalThis
const storage = createStorage({
driver: cloudflareR2BindingDriver({ binding: "BUCKET" }),
});
// Directly setting binding
const storage = createStorage({
driver: cloudflareR2BindingDriver({ binding: globalThis.BUCKET }),
});
// Using from Durable Objects and Workers using Modules Syntax
const storage = createStorage({
driver: cloudflareR2BindingDriver({ binding: this.env.BUCKET }),
});
```
**Options:**
- `binding`: Bucket binding or name. Default is `BUCKET`.
- `base`: Prefix all keys with base.

View File

@@ -1,36 +0,0 @@
# IndexedDB
Store key-value in IndexedDB.
## Usage
::note{to="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API"}
Learn more about IndexedDB.
::
To use it, you will need to install [`idb-keyval`](https://github.com/jakearchibald/idb-keyval) in your project:
```bash [Terminal]
npm i idb-keyval
```
Usage:
```js
import { createStorage } from "unstorage";
import indexedDbDriver from "unstorage/drivers/indexedb";
const storage = createStorage({
driver: indexedDbDriver({ base: "app:" }),
});
```
**Options:**
- `base`: Add `${base}:` to all keys to avoid collision
- `dbName`: Custom name for database. Defaults to `keyval-store`
- `storeName`: Custom name for store. Defaults to `keyval`
::note
IndexedDB is a browser database. avoid using this preset on server environments.
::

View File

@@ -1,24 +0,0 @@
# Local Storage
Store data in localStorage.
## Usage
::note{to="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage"}
Learn more about localStorage.
::
```js
import { createStorage } from "unstorage";
import localStorageDriver from "unstorage/drivers/localstorage";
const storage = createStorage({
driver: localStorageDriver({ base: "app:" }),
});
```
**Options:**
- `base`: Add `${base}:` to all keys to avoid collision
- `localStorage`: Optionally provide `localStorage` object
- `window`: Optionally provide `window` object

View File

@@ -1,24 +0,0 @@
# Session Storage
Store data in sessionStorage.
# Session Storage
::note{to="https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage"}
Learn more about sessionStorage.
::
```js
import { createStorage } from "unstorage";
import sessionStorageDriver from "unstorage/drivers/session-storage";
const storage = createStorage({
driver: sessionStorageDriver({ base: "app:" }),
});
```
**Options:**
- `base`: Add `${base}:` to all keys to avoid collision
- `sessionStorage`: Optionally provide `sessionStorage` object
- `window`: Optionally provide `window` object

View File

@@ -1,57 +0,0 @@
title: "Unstorage: The Universal Key-Value Storage."
description: "Unstorage is TypeScript library that provides an async key-value storage API with conventional features like multi driver mounting, watching, working with metadata and has 20+ built-in drivers."
navigation: false
hero:
title: "[Unstorage]{.text-primary} :br [The Universal Key-Value Storage.]{.text-4xl}"
description: "Unstorage is TypeScript library that provides an async key-value storage API with conventional features like multi driver mounting, watching, working with metadata and has 20+ built-in drivers."
orientation: horizontal
links:
- label: "Get started"
icon: "i-heroicons-rocket-launch"
to: "/getting-started/usage"
size: lg
- label: "Contribute on GitHub"
icon: "i-simple-icons-github"
color: "white"
to: "https://github.com/unjs/unstorage"
target: "_blank"
size: lg
code: |
```ts [app.ts]
import { createStorage } from "unstorage";
const storage = createStorage(/* opts */);
await storage.setItem("foo:bar", "baz");
const fooBar = await storage.getItem("foo:bar");
// or storage.getItem('/foo/bar')
```
features:
title: "Shipped with many Features"
links:
- label: "Get started"
icon: "i-heroicons-rocket-launch"
trailingIcon: "i-heroicons-arrow-right-20-solid"
color: "gray"
to: "/getting-started/usage"
size: lg
items:
- title: "Runtime Agnostic"
description: "Your code will work on any JavaScript runtime including Node.js, Bun, Deno and Workers."
icon: "i-material-symbols-lock-open-right-outline-rounded"
- title: "Built-in drivers"
description: "Unstorage is shipped with 20+ built-in drivers for different platforms: Memory (default), FS, Redis, Memory, MongoDB, CloudFlare, GitHub..."
icon: "i-material-symbols-usb"
- title: "Snapshots"
description: "Expand your server and add capabilities. Your codebase will scale with your project."
icon: "i-material-symbols-add-a-photo-outline"
- title: "Multi Storages"
description: "Unix-style driver mounting to combine storages on different mounts."
icon: "i-material-symbols-view-list-outline"
- title: "JSON friendly"
description: "Unstorage automatically serialization and deserialization JSON values."
icon: "i-material-symbols-magic-button"
- title: "Binary Support"
description: "Store binary and raw data like images, videos, audio files, etc."
icon: "i-material-symbols-audio-file"

View File

@@ -1,15 +0,0 @@
import { defineDocsConfig } from "unjs-docs/config";
export default defineDocsConfig({
name: "Unstorage",
description:
"A simple, small, and fast key-value storage library for JavaScript.",
github: "unjs/unstorage",
redirects: {
"/usage": "/getting-started/usage",
"/utils": "/getting-started/utils",
"/http-server": "/getting-started/http-server",
"/custom-driver": "/getting-started/custom-driver",
},
themeColor: '#f98007',
});

View File

@@ -1,12 +1,10 @@
{
"name": "unstorage-docs",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "unjs-docs build",
"dev": "unjs-docs dev"
"build": "undocs build",
"dev": "undocs dev"
},
"devDependencies": {
"unjs-docs": "^0.1.8"
"undocs": "^0.2.16"
}
}

9990
docs/pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff