keyv-github 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +43 -0
- package/README.md +45 -9
- package/bun.lock +885 -0
- package/dist/index.d.mts +15 -3
- package/dist/index.mjs +56 -29
- package/examples/hello-today.ts +14 -12
- package/package.json +30 -25
- package/src/index.test.ts +578 -411
- package/src/index.ts +390 -295
- package/tsconfig.json +24 -24
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Release workflow
|
|
2
|
+
|
|
3
|
+
# check https://www.npmjs.com/package/[package-name]/access for OIDC setup
|
|
4
|
+
# 1. repo = this repo
|
|
5
|
+
# 2. package-name = package to publish
|
|
6
|
+
|
|
7
|
+
name: Release
|
|
8
|
+
description: "Release workflow for publishing package"
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
pull_request:
|
|
12
|
+
branches:
|
|
13
|
+
- main
|
|
14
|
+
push:
|
|
15
|
+
tags:
|
|
16
|
+
- 'v*.*.*'
|
|
17
|
+
branches:
|
|
18
|
+
- main
|
|
19
|
+
- beta
|
|
20
|
+
|
|
21
|
+
permissions:
|
|
22
|
+
id-token: write # required for OIDC
|
|
23
|
+
contents: write # read and write access to repository contents
|
|
24
|
+
issues: write
|
|
25
|
+
|
|
26
|
+
jobs:
|
|
27
|
+
build-test-release:
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/checkout@v5
|
|
31
|
+
- uses: actions/setup-node@v6
|
|
32
|
+
with: {node-version: latest} #[semantic-release]: node version >=20.8.1 is required. Found v18.20.5.
|
|
33
|
+
- uses: oven-sh/setup-bun@v2
|
|
34
|
+
- run: bun i
|
|
35
|
+
- run: bunx biofix
|
|
36
|
+
- run: bun run build
|
|
37
|
+
- run: bun run test
|
|
38
|
+
- if: github.event_name == 'push'
|
|
39
|
+
run: bunx semantic-release
|
|
40
|
+
env:
|
|
41
|
+
# reminder to setup read/write permission for this token
|
|
42
|
+
# here: REPO_URL/settings/actions
|
|
43
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ import Keyv from "keyv";
|
|
|
29
29
|
import KeyvGithub from "keyv-github";
|
|
30
30
|
|
|
31
31
|
const store = new KeyvGithub("https://github.com/owner/repo/tree/main", {
|
|
32
|
-
client: new Octokit({ auth: process.env.GITHUB_TOKEN }),
|
|
32
|
+
client: new Octokit({ auth: process.env.GITHUB_TOKEN }), // only required if you want .set(), or .get() in private repo
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
const kv = new Keyv({ store });
|
|
@@ -45,11 +45,38 @@ await kv.delete("data/hello.txt");
|
|
|
45
45
|
new KeyvGithub(repoUrl, options?)
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
| Option
|
|
49
|
-
|
|
50
|
-
| `branch` | `string`
|
|
51
|
-
| `client` | `Octokit`
|
|
52
|
-
| `msg`
|
|
48
|
+
| Option | Type | Default | Description |
|
|
49
|
+
| -------- | ------------------------ | ----------------------------------- | -------------------------------------------------------- |
|
|
50
|
+
| `branch` | `string` | parsed from URL or `"main"` | Target branch |
|
|
51
|
+
| `client` | `Octokit` | `new Octokit()` | Authenticated Octokit instance |
|
|
52
|
+
| `msg` | `(key, value) => string` | `"update <key>"` / `"delete <key>"` | Customize commit messages; `value` is `null` for deletes |
|
|
53
|
+
| `prefix` | `string` | `""` | Path prefix prepended to every key (e.g. `"data/"`) |
|
|
54
|
+
| `suffix` | `string` | `""` | Path suffix appended to every key (e.g. `".json"`) |
|
|
55
|
+
|
|
56
|
+
### Store limitations
|
|
57
|
+
|
|
58
|
+
When using `KeyvGithub` directly (without wrapping in `Keyv`):
|
|
59
|
+
|
|
60
|
+
- **Values must be strings** — objects, arrays, and numbers will throw an error
|
|
61
|
+
- **TTL is not supported** — passing a TTL parameter throws an error
|
|
62
|
+
|
|
63
|
+
To store non-string values or use TTL, wrap the store with `new Keyv(store)`:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
// Direct usage: strings only, no TTL
|
|
67
|
+
await store.set("key", "string value"); // ✓
|
|
68
|
+
await store.set("key", { obj: true }); // ✗ throws error
|
|
69
|
+
await store.set("key", "value", 1000); // ✗ throws error
|
|
70
|
+
|
|
71
|
+
// With Keyv wrapper: any serializable value, TTL supported
|
|
72
|
+
const kv = new Keyv({ store });
|
|
73
|
+
await kv.set("key", { obj: true }); // ✓ serialized automatically
|
|
74
|
+
await kv.set("key", "value", 1000); // ✓ TTL handled by Keyv
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### TTL
|
|
78
|
+
|
|
79
|
+
TTL is **not enforced at the adapter level** — GitHub has no native file expiry. If you pass a `ttl` to `new Keyv({ store, ttl })`, Keyv handles it by wrapping values as `{"value":…,"expires":…}` and filtering on read. Expired files remain in the repo as inert files until overwritten or deleted. This adapter is best suited for long-lived or permanent storage.
|
|
53
80
|
|
|
54
81
|
### URL formats accepted
|
|
55
82
|
|
|
@@ -66,9 +93,7 @@ owner/repo/tree/my-branch
|
|
|
66
93
|
```ts
|
|
67
94
|
const store = new KeyvGithub("owner/repo", {
|
|
68
95
|
msg: (key, value) =>
|
|
69
|
-
value === null
|
|
70
|
-
? `chore: delete ${key}`
|
|
71
|
-
: `chore: update ${key} → ${value.slice(0, 40)}`,
|
|
96
|
+
value === null ? `chore: delete ${key}` : `chore: update ${key} → ${value.slice(0, 40)}`,
|
|
72
97
|
});
|
|
73
98
|
```
|
|
74
99
|
|
|
@@ -84,6 +109,17 @@ Keys must be valid relative file paths:
|
|
|
84
109
|
|
|
85
110
|
Invalid keys throw synchronously before any API request.
|
|
86
111
|
|
|
112
|
+
## See Also
|
|
113
|
+
|
|
114
|
+
Other Keyv storage adapters by the same author:
|
|
115
|
+
|
|
116
|
+
- [keyv-sqlite](https://github.com/snomiao/keyv-sqlite) — SQLite storage adapter
|
|
117
|
+
- [keyv-mongodb-store](https://github.com/snomiao/keyv-mongodb-store) — MongoDB storage adapter
|
|
118
|
+
- [keyv-nedb-store](https://github.com/snomiao/keyv-nedb-store) — NeDB embedded file-based adapter
|
|
119
|
+
- [keyv-dir-store](https://github.com/snomiao/keyv-dir-store) — file-per-key directory adapter with TTL via mtime
|
|
120
|
+
- [keyv-cache-proxy](https://github.com/snomiao/keyv-cache-proxy) — transparent caching proxy that wraps any object
|
|
121
|
+
- [keyv-nest](https://github.com/snomiao/keyv-nest) — hierarchical multi-layer caching adapter
|
|
122
|
+
|
|
87
123
|
## License
|
|
88
124
|
|
|
89
125
|
MIT
|