Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unstorage

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unstorage - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

dist/drivers/cloudflare-kv-binding.cjs

22

dist/index.d.ts

@@ -1,3 +0,3 @@

import { D as Driver, S as Storage, a as StorageValue } from './types-20f3bd04.js';
export { D as Driver, S as Storage, c as StorageMeta, a as StorageValue, b as WatchCallback, W as WatchEvent } from './types-20f3bd04.js';
import { D as Driver, S as Storage, a as StorageValue } from './types-ba4f7911.js';
export { D as Driver, S as Storage, c as StorageMeta, a as StorageValue, b as WatchCallback, W as WatchEvent } from './types-ba4f7911.js';

@@ -13,5 +13,5 @@ interface CreateStorageOptions {

declare function prefixStorage(storage: Storage, base: string): Storage;
declare function normalizeKey(key: string | undefined): string;
declare function normalizeKey(key?: string): string;
declare function joinKeys(...keys: string[]): string;
declare function normalizeBaseKey(base: string | undefined): string;
declare function normalizeBaseKey(base?: string): string;

@@ -21,2 +21,14 @@ declare type DriverFactory<T> = (opts?: T) => Driver;

export { CreateStorageOptions, Snapshot, createStorage, defineDriver, joinKeys, normalizeBaseKey, normalizeKey, prefixStorage, restoreSnapshot, snapshot };
declare const builtinDrivers: {
cloudflareKVHTTP: string;
cloudflareKVBinding: string;
fs: string;
github: string;
http: string;
localStorage: string;
memory: string;
overlay: string;
redis: string;
};
export { CreateStorageOptions, Snapshot, builtinDrivers, createStorage, defineDriver, joinKeys, normalizeBaseKey, normalizeKey, prefixStorage, restoreSnapshot, snapshot };
import { RequestListener } from 'http';
import { S as Storage } from './types-20f3bd04.js';
import { S as Storage } from './types-ba4f7911.js';

@@ -4,0 +4,0 @@ interface StorageServerOptions {

{
"name": "unstorage",
"version": "0.4.1",
"version": "0.5.0",
"description": "Universal Storage Layer",

@@ -34,9 +34,9 @@ "repository": "unjs/unstorage",

"destr": "^1.1.1",
"h3": "^0.7.6",
"ioredis": "^5.0.4",
"h3": "^0.7.9",
"ioredis": "^5.0.6",
"listhen": "^0.2.11",
"mri": "^1.2.0",
"ohmyfetch": "^0.4.16",
"ufo": "^0.8.3",
"ws": "^8.6.0"
"ohmyfetch": "^0.4.18",
"ufo": "^0.8.4",
"ws": "^8.8.0"
},

@@ -52,3 +52,3 @@ "devDependencies": {

"@vue/compiler-sfc": "latest",
"c8": "^7.11.2",
"c8": "^7.11.3",
"doctoc": "latest",

@@ -60,2 +60,3 @@ "eslint": "latest",

"monaco-editor": "latest",
"msw": "^0.42.1",
"standard-version": "latest",

@@ -66,6 +67,6 @@ "types-cloudflare-worker": "^1.2.0",

"vite": "latest",
"vitest": "^0.10.2",
"vue": "^3.2.33"
"vitest": "^0.14.2",
"vue": "^3.2.37"
},
"packageManager": "pnpm@7.0.0",
"packageManager": "pnpm@7.2.1",
"scripts": {

@@ -72,0 +73,0 @@ "build": "unbuild",

@@ -34,4 +34,4 @@ # unstorage

✔️ Namespaced storage <br>
✔️ Overlay storage (copy-on-write) <br>
<br>
🚧 Overlay storage (copy-on-write) <br>
🚧 Virtual `fs` interface <br>

@@ -73,3 +73,5 @@ 🚧 Cached storage <br>

- [`redis`](#redis)
- [`cloudflare-kv`](#cloudflare-kv)
- [`cloudflare-kv-http`](#cloudflare-kv-http)
- [`cloudflare-kv-binding`](#cloudflare-kv-binding)
- [`github`](#github)
- [Making custom drivers](#making-custom-drivers)

@@ -308,3 +310,3 @@ - [Contribution](#contribution)

- `PUT`: Maps to `storage.setItem`. Value is read from body and returns `OK` if operation succeeded.
- `DELETE`: Maps to `storage.removeIterm`. Returns `OK` if operation succeeded.
- `DELETE`: Maps to `storage.removeItem`. Returns `OK` if operation succeeded.

@@ -380,3 +382,3 @@ ## Drivers

import { createStorage } from 'unstorage'
import overlay from 'unstorage/drivers/memory'
import overlay from 'unstorage/drivers/overlay'
import memory from 'unstorage/drivers/memory'

@@ -419,3 +421,3 @@ import fs from 'unstorage/drivers/fs'

- `setItem`: Maps to http `PUT`. Sends serialized value using body
- `removeIterm`: Maps to `DELETE`
- `removeItem`: Maps to `DELETE`
- `clear`: Not supported

@@ -447,7 +449,68 @@

### `cloudflare-kv-http`
### `cloudflare-kv`
Store data in [Cloudflare KV](https://developers.cloudflare.com/workers/learning/how-kv-works/) using the [Cloudflare API v4](https://api.cloudflare.com/).
Store data in [Cloudflare KV](https://developers.cloudflare.com/workers/runtime-apis/kv).
You need to create a KV namespace. See [KV Bindings](https://developers.cloudflare.com/workers/runtime-apis/kv#kv-bindings) for more information.
**Note:** This driver uses native fetch and works universally! For using directly in a cloudflare worker environemnt, please use `cloudflare-kv-binding` driver for best performance!
```js
import { createStorage } from 'unstorage'
import cloudflareKVHTTPDriver from 'unstorage/drivers/cloudflare-kv-http'
// Using `apiToken`
const storage = createStorage({
driver: cloudflareKVHTTPDriver({
accountId: 'my-account-id',
namespaceId: 'my-kv-namespace-id',
apiToken: 'supersecret-api-token',
}),
})
// Using `email` and `apiKey`
const storage = createStorage({
driver: cloudflareKVHTTPDriver({
accountId: 'my-account-id',
namespaceId: 'my-kv-namespace-id',
email: 'me@example.com',
apiKey: 'my-api-key',
}),
})
// Using `userServiceKey`
const storage = createStorage({
driver: cloudflareKVHTTPDriver({
accountId: 'my-account-id',
namespaceId: 'my-kv-namespace-id',
userServiceKey: 'v1.0-my-service-key',
}),
})
```
**Options:**
- `accountId`: Cloudflare account ID.
- `namespaceId`: The ID of the KV namespace to target. **Note:** be sure to use the namespace's ID, and not the name or binding used in a worker environment.
- `apiToken`: API Token generated from the [User Profile 'API Tokens' page](https://dash.cloudflare.com/profile/api-tokens).
- `email`: Email address associated with your account. May be used along with `apiKey` to authenticate in place of `apiToken`.
- `apiKey`: API key generated on the "My Account" page of the Cloudflare console. May be used along with `email` to authenticate in place of `apiToken`.
- `userServiceKey`: A special Cloudflare API key good for a restricted set of endpoints. Always begins with "v1.0-", may vary in length. May be used to authenticate in place of `apiToken` or `apiKey` and `email`.
- `apiURL`: Custom API URL. Default is `https://api.cloudflare.com`.
**Supported methods:**
- `getItem`: Maps to [Read key-value pair](https://api.cloudflare.com/#workers-kv-namespace-read-key-value-pair) `GET accounts/:account_identifier/storage/kv/namespaces/:namespace_identifier/values/:key_name`
- `hasItem`: Maps to [Read key-value pair](https://api.cloudflare.com/#workers-kv-namespace-read-key-value-pair) `GET accounts/:account_identifier/storage/kv/namespaces/:namespace_identifier/values/:key_name`. Returns `true` if `<parsed response body>.success` is `true`.
- `setItem`: Maps to [Write key-value pair](https://api.cloudflare.com/#workers-kv-namespace-write-key-value-pair) `PUT accounts/:account_identifier/storage/kv/namespaces/:namespace_identifier/values/:key_name`
- `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-kv-binding`
Store data in [Cloudflare KV](https://developers.cloudflare.com/workers/runtime-apis/kv) and access from worker bindings.
**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.

@@ -457,7 +520,7 @@

import { createStorage } from 'unstorage'
import cloudflareKVDriver from 'unstorage/drivers/cloudflare-kv'
import cloudflareKVBindingDriver from 'unstorage/drivers/cloudflare-kv-binding'
// Using binding name to be picked from globalThis
const storage = createStorage({
driver: cloudflareKVDriver({ binding: 'STORAGE' })
driver: cloudflareKVBindingDriver({ binding: 'STORAGE' })
})

@@ -467,3 +530,3 @@

const storage = createStorage({
driver: cloudflareKVDriver({ binding: globalThis.STORAGE })
driver: cloudflareKVBindingDriver({ binding: globalThis.STORAGE })
})

@@ -473,7 +536,7 @@

const storage = createStorage({
driver: cloudflareKVDriver({ binding: this.env.STORAGE })
driver: cloudflareKVBindingDriver({ binding: this.env.STORAGE })
})
// Using outside of Cloudflare Workers (like Node.js)
// Not supported Yet!
// Use cloudflare-kv-http!
```

@@ -485,3 +548,31 @@

### `github`
Map files from a remote github repository. (readonly)
This driver fetches all possible keys once and keep it in cache for 10 minutes. Because of github rate limit, it is highly recommanded to provide a token. It only applies to fetching keys.
```js
import { createStorage } from 'unstorage'
import githubDriver from 'unstorage/drivers/github'
const storage = createStorage({
driver: githubDriver({
repo: 'nuxt/framework',
branch: 'main',
dir: '/docs/content'
})
})
```
**Options:**
- **`repo`**: Github repository. Format is `username/repo` or `org/repo`. (Required!)
- **`token`**: Github API token. (Recommended!)
- `branch`: Target branch. Default is `main`
- `dir`: Use a directory as driver root.
- `ttl`: Filenames cache revalidate time. Default is `600` seconds (10 minutes)
- `apiURL`: Github API domain. Default is `https://api.github.com`
- `cdnURL`: Github RAW CDN Url. Default is `https://raw.githubusercontent.com`
## Making custom drivers

@@ -488,0 +579,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc