Skip to content

Commit

Permalink
Merge branch 'main' into docs/docus-2
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Jun 27, 2023
2 parents bccf10a + 1668051 commit b4da81e
Show file tree
Hide file tree
Showing 31 changed files with 1,977 additions and 1,401 deletions.
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
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,41 @@

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.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)
Expand Down
68 changes: 68 additions & 0 deletions docs/content/2.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,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
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"devDependencies": {
"@nuxt-themes/docus": "^2.0.0-beta.12",
"@nuxtjs/plausible": "^0.2.1",
"nuxt": "^3.5.3"
"nuxt": "^3.6.1"
}
}
Loading

0 comments on commit b4da81e

Please sign in to comment.