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

Write Deno Kv Testcode #10

Merged
merged 31 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d5e639b
fix(prefixStorage): prefix `getItemRaw` and `setItemRaw` (#232)
maou-shonen May 24, 2023
7afac4c
fix(github): fetchFiles should return files (#229)
and-cesbo May 24, 2023
492f4ac
chore(deps): update all non-major dependencies (#220)
renovate[bot] May 24, 2023
4591831
chore: update eslint
pi0 May 24, 2023
33bc9c0
test: skip cloudflare-kv-http on node >= 18
pi0 May 24, 2023
271b7c9
chore(release): v1.6.1
pi0 May 24, 2023
97b8a87
docs: add social share image
atinux May 25, 2023
bcf9385
chore: update deps
pi0 May 26, 2023
7520633
docs: fix typo (#239)
neelansh15 Jun 2, 2023
ba82bf0
chore: update dependencies
pi0 Jun 21, 2023
8ad15c1
feat: generic type support (#237)
maou-shonen Jun 21, 2023
b42deef
refactor: fix issues with typescript strict (#250)
pi0 Jun 21, 2023
57e6901
chore: add type check to ci
pi0 Jun 21, 2023
24cfbd7
ci: skip flaky azure tests
pi0 Jun 21, 2023
843a9ba
chore(release): v1.7.0
pi0 Jun 21, 2023
9e2566d
chore(deps): update all non-major dependencies
renovate[bot] Jun 22, 2023
5800553
docs: fix typo (#252)
xlanex6 Jun 24, 2023
1668051
chore(deps): update all non-major dependencies
renovate[bot] Jun 26, 2023
8353c6d
test: add test for `github` driver (#259)
Hebilicious Jul 4, 2023
cb8577b
feat: experimental operation batching (#240)
Hebilicious Jul 4, 2023
34f14f8
feat(cloudflare-kv): support `base` option for keys (#261)
pi0 Jul 4, 2023
4386798
feat: `cloudflare-r2-binding` driver (#235)
pi0 Jul 4, 2023
48d6842
fix: add missing `cloudflareR2Binding` to the `builtinDrivers`
pi0 Jul 4, 2023
ba44aed
chore: update dev dependencies
pi0 Jul 4, 2023
c392d45
chore(release): v1.8.0
pi0 Jul 4, 2023
6d3f283
Merge pull request #1 from so1ve/feat/deno-kv
nakasyou Jul 7, 2023
1fa3aa5
Fix typescript checks
nakasyou Jul 8, 2023
5f35d3b
add typehint
nakasyou Jul 8, 2023
db8abd9
Install execa
nakasyou Jul 8, 2023
eccfe01
Write test code
nakasyou Jul 8, 2023
cd61b8b
Remove not using import
nakasyou Jul 8, 2023
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
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"rules": {
"unicorn/no-null": 0,
"unicorn/prevent-abbreviations": 0,
"@typescript-eslint/no-non-null-assertion": 0
"@typescript-eslint/no-non-null-assertion": 0,
"unicorn/prefer-string-replace-all": 0
}
}
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
cache: "pnpm"
- run: pnpm install
- run: pnpm lint
- run: pnpm test:types
- run: pnpm build
- run: pnpm vitest --coverage
- uses: codecov/codecov-action@v3
95 changes: 95 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,101 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## v1.8.0

[compare changes](https://github.com/unjs/unstorage/compare/v1.7.0...v1.8.0)

### 🚀 Enhancements

- Experimental operation batching ([#240](https://github.com/unjs/unstorage/pull/240))
- **cloudflare-kv:** Support `base` option for keys ([#261](https://github.com/unjs/unstorage/pull/261))
- `cloudflare-r2-binding` driver ([#235](https://github.com/unjs/unstorage/pull/235))

### 🩹 Fixes

- Add missing `cloudflareR2Binding` to the `builtinDrivers` ([48d6842](https://github.com/unjs/unstorage/commit/48d6842))

### 📖 Documentation

- Fix typo ([#252](https://github.com/unjs/unstorage/pull/252))

### 🏡 Chore

- Update dev dependencies ([ba44aed](https://github.com/unjs/unstorage/commit/ba44aed))

### ✅ Tests

- Add test for `github` driver ([#259](https://github.com/unjs/unstorage/pull/259))

### ❤️ Contributors

- Pooya Parsa ([@pi0](http://github.com/pi0))
- Hebilicious ([@Hebilicious](http://github.com/Hebilicious))
- Alex Duval ([@xlanex6](http://github.com/xlanex6))

## v1.7.0

[compare changes](https://github.com/unjs/unstorage/compare/v1.6.1...v1.7.0)


### 🚀 Enhancements

- Generic type support ([#237](https://github.com/unjs/unstorage/pull/237))

### 💅 Refactors

- Fix issues with typescript strict ([#250](https://github.com/unjs/unstorage/pull/250))

### 📖 Documentation

- Add social share image ([97b8a87](https://github.com/unjs/unstorage/commit/97b8a87))
- Fix typo ([#239](https://github.com/unjs/unstorage/pull/239))

### 🏡 Chore

- Update deps ([bcf9385](https://github.com/unjs/unstorage/commit/bcf9385))
- Update dependencies ([ba82bf0](https://github.com/unjs/unstorage/commit/ba82bf0))
- Add type check to ci ([57e6901](https://github.com/unjs/unstorage/commit/57e6901))

### 🤖 CI

- Skip flaky azure tests ([24cfbd7](https://github.com/unjs/unstorage/commit/24cfbd7))

### ❤️ Contributors

- Pooya Parsa ([@pi0](http://github.com/pi0))
- 魔王少年 ([@maou-shonen](http://github.com/maou-shonen))
- Neelansh Mathur
- Sébastien Chopin ([@Atinux](http://github.com/Atinux))

## v1.6.1

[compare changes](https://github.com/unjs/unstorage/compare/v1.6.0...v1.6.1)


### 🩹 Fixes

- **prefixStorage:** Prefix `getItemRaw` and `setItemRaw` ([#232](https://github.com/unjs/unstorage/pull/232))
- **github:** FetchFiles should return files ([#229](https://github.com/unjs/unstorage/pull/229))

### 💅 Refactors

- Remove unused variable ([97d3e3e](https://github.com/unjs/unstorage/commit/97d3e3e))

### 🏡 Chore

- Update eslint ([4591831](https://github.com/unjs/unstorage/commit/4591831))

### ✅ Tests

- Skip cloudflare-kv-http on node >= 18 ([33bc9c0](https://github.com/unjs/unstorage/commit/33bc9c0))

### ❤️ Contributors

- Pooya Parsa ([@pi0](http://github.com/pi0))
- Andrei Dyldin <and@cesbo.com>
- 魔王少年 <q267009886.work@gmail.com>

## v1.6.0

[compare changes](https://github.com/unjs/unstorage/compare/v1.5.0...v1.6.0)
Expand Down
1 change: 1 addition & 0 deletions docs/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default defineAppConfig({
docus: {
title: "💾 Unstorage",
description: "Universal Storage Layer.",
image: 'https://github.com/unjs/unstorage/assets/904724/3709bb3d-7abe-4c4f-9d55-55cf2f46594e',
header: {
logo: false,
},
Expand Down
84 changes: 84 additions & 0 deletions docs/content/2.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ Gets the value of a key in storage. Resolves to either a javascript primitive va
await storage.getItem("foo:bar");
```

### `getItems(items, opts)`

(Experimental) Gets the value of a multiple keys in storage in parallel.

Each item in array can be either a string or an object with`{ key, options? }` format.

Returned value is a Promise resolving to an array of objects with `{ key, value }` format.

### `getItemRaw(key, opts?)`

**Note:** This is an experimental feature. Please check [unjs/unstorage#142](https://github.com/unjs/unstorage/issues/142) for more information.
Expand All @@ -77,6 +85,14 @@ If value is `undefined`, it is same as calling `removeItem(key)`.
await storage.setItem("foo:bar", "baz");
```

### `setItems(items, opts)`

(Experimental) Add/Update items in parallel to the storage.

Each item in `items` array should be in `{ key, value, options? }` format.

Returned value is a Promise resolving to an array of objects with `{ key, value }` format.

### `setItemRaw(key, value, opts?)`

**Note:** This is an experimental feature. Please check [unjs/unstorage#142](https://github.com/unjs/unstorage/issues/142) for more information.
Expand Down Expand Up @@ -238,3 +254,71 @@ storage.getMounts("");
storage.getMounts("cache:sub", { parents: true });
// => [{ base: "cache:sub", driver }, { base: "cache:", driver }, { base: "", driver }]
```

## Generic Types

**Type `getItem` return value:**

```ts
await storage.getItem<string>("k"); // => <string>

await storage.getItemRaw<Buffer>("k"); // => <Buffer>
```

**Type check `setItem` parameters:**

```ts
storage.setItem<string>("k", "val"); // check ok
storage.setItemRaw<string>("k", "val"); // check ok

storage.setItem<string>("k", 123); // ts error
storage.setItemRaw<string>("k", 123); // ts error
```

**Typed storage instance:**

```ts
const storage = createStorage<string>();

await storage.getItem("k"); // => <string>

storage.setItem("k", "val"); // Check ok
storage.setItem("k", 123); // TS error
```

::alert{type="info"}
Forward references use inheritance instead of overriding types.
::

```ts
const storage = createStorage<string>();

storage.setItem<number>("k", 123); // TS error: <number> is not compatible with <string>
```

**Typing a sub set using `prefixStorage`:**

```ts
const storage = createStorage();

const htmlStorage = prefixStorage<string>(storage, "assets:html");

await htmlStorage.getItem("foo.html"); // => <string>

type Post = {
title: string;
content: string;
};

const postStorage = prefixStorage<Post>(storage, "assets:posts");

await postStorage.getItem("foo.json"); // => <Post>
```

In [strict mode](https://www.typescriptlang.org/tsconfig#strict), will also return the undefined type to help you handle the case when miss `getItem`.

```ts
"use strict";

await storage.getItem<string>("k"); // => <string | null>
```
2 changes: 1 addition & 1 deletion docs/content/3.utils.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Extra Utilities

Unstorage exposes several utilities. You can individually import them and add only needed bytes to your budnle.
Unstorage exposes several utilities. You can individually import them and add only needed bytes to your bundle.

## Namespace

Expand Down
1 change: 1 addition & 0 deletions docs/content/6.drivers/cloudflare-kv-binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ const storage = createStorage({
**Options:**

- `binding`: KV binding or name of namespace. Default is `STORAGE`.
- `base`: Adds prefix to all stored keys
3 changes: 2 additions & 1 deletion docs/content/6.drivers/cloudflare-kv-http.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Store data in [Cloudflare KV](https://developers.cloudflare.com/workers/learning

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!
**Note:** This driver uses native fetch and works universally! For using directly in a cloudflare worker environment, please use `cloudflare-kv-binding` driver for best performance!

```js
import { createStorage } from "unstorage";
Expand Down Expand Up @@ -48,6 +48,7 @@ const storage = createStorage({
- `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`.
- `base`: Adds prefix to all stored keys

**Supported methods:**

Expand Down
29 changes: 29 additions & 0 deletions docs/content/6.drivers/cloudflare-r2-binding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# CloudFlare R2 (binding)

::alert
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)
::

Store data in [Cloudflare R2](https://developers.cloudflare.com/r2/api/workers/workers-api-reference/) buckets and access from worker bindings.

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

// Directly setting binding
const storage = createStorage({
driver: cloudflareR2BindingDriver({ binding: globalThis.MY_BUCKET }),
});
```

**Options:**

- `binding`: Bucket binding or name.
- `base`: Prefix all keys with base.
6 changes: 3 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"preview": "nuxi preview"
},
"devDependencies": {
"@nuxt-themes/docus": "^1.11.1",
"@nuxtjs/plausible": "^0.2.0",
"nuxt": "^3.4.3"
"@nuxt-themes/docus": "^1.12.3",
"@nuxtjs/plausible": "^0.2.1",
"nuxt": "^3.6.1"
}
}
Loading