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

docs: add docs website #166

Merged
merged 8 commits into from
Feb 28, 2023
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
93 changes: 20 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,23 @@
[![Codecov][codecov-src]][codecov-href]
[![bundle][bundle-src]][bundle-href]

> 💾 Universal Storage Layer

**Why ❓**

Typically, we choose one or more data storages based on our use-cases like a filesystem, a database like Redis, Mongo, or LocalStorage for browsers but it will soon start to be lots of trouble for supporting and combining more than one or switching between them. For javascript library authors, this usually means they have to decide how many platforms they support and implement storage for each.

💡 Unstorage solution is a unified and powerful Key-Value (KV) interface that allows combining drivers that are either built-in or can be implemented via a super simple interface and adding conventional features like mounting, watching, and working with metadata.

Comparing to similar solutions like [localforage](https://localforage.github.io/localForage/), unstorage core is almost 6x smaller (28.9 kB vs 4.7 kB), using modern ESM/Typescript/Async syntax and many more features to be used universally.

<br>
✅ Designed to work in all environments (Browser, NodeJS, and Workers) <br>
✅ Multiple built-in drivers (Memory, FS, LocalStorage, HTTP, Redis) <br>
✅ Asynchronous API <br>
✅ Unix-style driver mounting to combine storages<br>
✅ Default in-memory storage <br>
✅ Tree-shakable utils and tiny core <br>
✅ Driver native and user provided metadata <br>
✅ Native aware value serialization and deserialization <br>
✅ Restore initial state (hydration) <br>
✅ State snapshot <br>
✅ Driver agnostic watcher <br>
✅ HTTP Storage server (cli and programmatic) <br>
✅ Namespaced storage <br>
✅ Overlay storage (copy-on-write) <br>
✅ Binary and raw operations support (experimental) <br>
<br>
💾 Unstorage provides an async Key-Value storage API with conventional features like multi driver mounting, watching and working with metadata, dozens of built-in drivers and a [tiny core](https://bundlephobia.com/package/unstorage).

👉 [documentation](https://unstorage.unjs.io)

## Features

- Designed for all environments: Browser, NodeJS, and Workers
- Lots of Built-in drivers
- Asynchronous API
- Unix-style driver mounting to combine storages
- Default [in-memory](/drivers/memory) storage
- Tree-shakable utils and tiny core
- Auto JSON value serialization and deserialization
- Banary and raw value support
- State [snapshots](/utils#snapshots) and hydration
- Storage watcher
- HTTP Storage with [built-in server](/server)

## Usage

Expand All @@ -41,11 +31,12 @@ Install `unstorage` npm package:
```sh
# yarn
yarn add unstorage

# npm
npm install unstorage

# pnpm
pnpm add unstorage

```

```js
Expand All @@ -56,51 +47,7 @@ const storage = createStorage(/* opts */);
await storage.getItem("foo:bar"); // or storage.getItem('/foo/bar')
```

**Options:**

- `driver`: Default driver (using memory if not provided)

## Storage Interface

Check out [storage interface](./docs/storage.md) for storage interface usage.

## Storage Utilities

Check out [storage utils](./docs/utils.md) for available extra storage utilities.

## Storage Drivers

Unstorage has several built-in storage drivers you can instantiate and mount.

Local:

- [Filesystem](./docs/drivers/node-fs.md)
- [Memory](./docs/drivers/memory.md)
- [LRU Cache](./docs/drivers/lru-cache.md)
- [Localstorage](./docs/drivers/localstorage.md)

Special:

- [HTTP](./docs/drivers/http.md)
- [Overlay](./docs/drivers/overlay.md)
- [Custom Driver](./docs/drivers/custom.md)

Database:

- [MongoDB](./docs/drivers/mongodb.md)
- [Redis](./docs/drivers/redis.md)

Providers:

- [Azure App Configuration](./docs/drivers/azure-app-configuration.md)
- [Azure Key Vault](./docs/drivers/azure-key-vault.md)
- [Azure Cosmos](./docs//drivers/azure-cosmos.md)
- [Azure Storage Block](./docs/drivers/azure-storage-blod.md)
- [Azure Storage Table](./docs/drivers//azure-storage-table.md)
- [Cloudflare KV Binding](./docs/drivers/cloudflare-kv-binding.md)
- [Cloudflare KV HTTP](./docs/drivers/cloudflare-kv-http.md)
- [Github](./docs/drivers/github.md)
- [Planetscale](./docs/drivers/planetscale.md)
👉 Check out the [the documentation](https://unstorage.unjs.io) for usage information.

## Contribution

Expand Down
12 changes: 12 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
*.iml
.idea
*.log*
.nuxt
.vscode
.DS_Store
coverage
dist
sw.*
.env
.output
2 changes: 2 additions & 0 deletions docs/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shamefully-hoist=true
strict-peer-dependencies=false
19 changes: 19 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Documentation

Docs are powered by [Docus](https://docus.dev).

## Local Development

Install dependencies:

```bash
pnpm install
```

Start development server with:

```bash
npm run dev
```

Start editing [conent](./content) directory!
26 changes: 26 additions & 0 deletions docs/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default defineAppConfig({
docus: {
title: "💾 Unstorage",
description: "Universal Storage Layer.",
header: {
logo: false,
},
socials: {
twitter: "unjsio",
github: "unjs/unstorage",
},
aside: {
level: 0,
exclude: [],
},
footer: {
iconLinks: [
{
href: "https://unjs.io",
icon: "vscode-icons:file-type-js-official",
label: "UnJS",
},
],
},
},
});
27 changes: 27 additions & 0 deletions docs/content/1.index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
navigation.title: Introduction
---

# Introduction

Unstorage provides an async Key-Value storage API with conventional features like multi driver mounting, watching and working with metadata, dozens of built-in drivers and a [tiny core](https://bundlephobia.com/package/unstorage).

## Why?

We usually choose one or more storage backends based on our use-cases such as filesystem, a database or LocalStorage for browsers. It soon starts to be create troubles for supporting and combining more than one or switching between them. For JavaScript library authors, this usually means they have to decide how many platforms they support and implement storage for each.

## Features

::list

- Designed for all environments: Browser, NodeJS, and Workers
- Lots of Built-in drivers
- Asynchronous API
- Unix-style driver mounting to combine storages
- Default [in-memory](/drivers/memory) storage
- Tree-shakable utils and tiny core
- Auto JSON value serialization and deserialization
- Banary and raw value support
- State [snapshots](/utils#snapshots) and hydration
- Storage watcher
- HTTP Storage with [built-in server](/server)
68 changes: 51 additions & 17 deletions docs/storage.md → docs/content/2.usage.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
# Storage Interface
# Usage

### `storage.hasItem(key)`
Discover how to use `unstorage` in your project.

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
```

::

```js [my-storage.js]
import { createStorage } from "unstorage";

const storage = createStorage(/* opts */);

await storage.getItem("foo:bar"); // or storage.getItem('/foo/bar')
```

**Options:**

- `driver`: Default driver, using [memory](/drivers/memory) if not provided

## Interface

### `hasItem(key)`

Checks if storage contains a key. Resolves to either `true` or `false`.

```js
await storage.hasItem("foo:bar");
```

### `storage.getItem(key)`
### `getItem(key)`

Gets the value of a key in storage. Resolves to either a javascript primitive value or `undefined`.

```js
await storage.getItem("foo:bar");
```

### `storage.getItemRaw(key)`
### `getItemRaw(key)`

**Note:** This is an experimental feature. Please check [unjs/unstorage#142](https://github.com/unjs/unstorage/issues/142) for more information.

Expand All @@ -27,7 +61,7 @@ Gets the value of a key in storage in raw format.
const value = await storage.getItemRaw("foo:bar.bin");
```

### `storage.setItem(key, value)`
### `setItem(key, value)`

Add/Update a value to the storage.

Expand All @@ -39,7 +73,7 @@ If value is `undefined`, it is same as calling `removeItem(key)`.
await storage.setItem("foo:bar", "baz");
```

### `storage.setItemRaw(key, value)`
### `setItemRaw(key, value)`

**Note:** This is an experimental feature. Please check [unjs/unstorage#142](https://github.com/unjs/unstorage/issues/142) for more information.

Expand All @@ -51,15 +85,15 @@ If value is `undefined`, it is same as calling `removeItem(key)`.
await storage.setItemRaw("data/test.bin", new Uint8Array([1, 2, 3]));
```

### `storage.removeItem(key, removeMeta = true)`
### `removeItem(key, removeMeta = true)`

Remove a value (and it's meta) from storage.

```js
await storage.removeItem("foo:bar");
```

### `storage.getMeta(key, nativeOnly?)`
### `getMeta(key, nativeOnly?)`

Get metadata object for a specific key.

Expand All @@ -72,7 +106,7 @@ This data is fetched from two sources:
await storage.getMeta("foo:bar"); // For fs driver returns an object like { mtime, atime, size }
```

### `storage.setMeta(key)`
### `setMeta(key)`

Set custom meta for a specific key by adding a `$` suffix.

Expand All @@ -81,7 +115,7 @@ await storage.setMeta("foo:bar", { flag: 1 });
// Same as storage.setItem('foo:bar$', { flag: 1 })
```

### `storage.removeMeta(key)`
### `removeMeta(key)`

Remove meta for a specific key by adding a `$` suffix.

Expand All @@ -90,7 +124,7 @@ await storage.removeMeta("foo:bar");
// Same as storage.removeItem('foo:bar$')
```

### `storage.getKeys(base?)`
### `getKeys(base?)`

Get all keys. Returns an array of strings.

Expand All @@ -102,15 +136,15 @@ If a base is provided, only keys starting with the base will be returned also on
await storage.getKeys();
```

### `storage.clear(base?)`
### `clear(base?)`

Removes all stored key/values. If a base is provided, only mounts matching base will be cleared.

```js
await storage.clear();
```

### `storage.dispose()`
### `dispose()`

Disposes all mounted storages to ensure there are no open-handles left. Call it before exiting process.

Expand All @@ -120,7 +154,7 @@ Disposes all mounted storages to ensure there are no open-handles left. Call it
await storage.dispose();
```

### `storage.mount(mountpoint, driver)`
### `mount(mountpoint, driver)`

By default, everything is stored in memory. We can mount additional storage space in a Unix-like fashion.

Expand All @@ -144,15 +178,15 @@ await storage.setItem("/output/test", "works");
await storage.setItem("/foo", "bar");
```

### `storage.unmount(mountpoint, dispose = true)`
### `unmount(mountpoint, dispose = true)`

Unregisters a mountpoint. Has no effect if mountpoint is not found or is root.

```js
await storage.unmount("/output");
```

### `storage.watch(callback)`
### `watch(callback)`

Starts watching on all mountpoints. If driver does not supports watching, only emits even when `storage.*` methods are called.

Expand All @@ -162,7 +196,7 @@ const unwatch = await storage.watch((event, key) => {});
await unwatch();
```

### `storage.unwatch()`
### `unwatch()`

Stop all watchers on all mountpoints.

Expand Down
Loading