@b3-business/cherry 0.2.6 → 0.2.7
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/README.md +21 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,10 +10,11 @@ A tree-shakeable, minimal API client factory. Import only the routes you need
|
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
## Latest Changelog - 0.2.
|
|
13
|
+
## Latest Changelog - 0.2.7
|
|
14
14
|
|
|
15
|
-
-
|
|
16
|
-
-
|
|
15
|
+
- README: Reconcile documentation with actual API (`createCherryClient`, `route`, `path` tagged template)
|
|
16
|
+
- README: Remove unimplemented OpenAPI generator section
|
|
17
|
+
- Example: JSONPlaceholder now uses sub-namespaced routes (`posts.list`, `users.get`)
|
|
17
18
|
|
|
18
19
|
See [CHANGELOG.md](https://github.com/b3-business/cherry/blob/main/packages/cherry/CHANGELOG.md) for full history.
|
|
19
20
|
|
|
@@ -24,10 +25,10 @@ See [CHANGELOG.md](https://github.com/b3-business/cherry/blob/main/packages/cher
|
|
|
24
25
|
Cherry is a lightweight API client library that separates **route definitions** from the **client runtime**. Routes are plain objects with validation schemas — import only what you use, bundle only what you import.
|
|
25
26
|
|
|
26
27
|
```ts
|
|
27
|
-
import {
|
|
28
|
+
import { createCherryClient } from "@b3b/cherry";
|
|
28
29
|
import { listZones, getZone } from "./routes/cloudflare";
|
|
29
30
|
|
|
30
|
-
const cf =
|
|
31
|
+
const cf = createCherryClient({
|
|
31
32
|
baseUrl: "https://api.cloudflare.com/client/v4",
|
|
32
33
|
headers: () => ({ Authorization: `Bearer ${process.env.CF_TOKEN}` }),
|
|
33
34
|
routes: { listZones, getZone },
|
|
@@ -96,12 +97,12 @@ deno add jsr:@b3b/cherry
|
|
|
96
97
|
|
|
97
98
|
```ts
|
|
98
99
|
import * as v from "valibot";
|
|
99
|
-
import {
|
|
100
|
+
import { route, path, param } from "@b3b/cherry";
|
|
100
101
|
|
|
101
|
-
export const listZones =
|
|
102
|
+
export const listZones = route({
|
|
102
103
|
method: "GET",
|
|
103
|
-
path:
|
|
104
|
-
|
|
104
|
+
path: path`/zones`,
|
|
105
|
+
queryParams: v.object({
|
|
105
106
|
account_id: v.string(),
|
|
106
107
|
page: v.optional(v.number()),
|
|
107
108
|
}),
|
|
@@ -114,10 +115,10 @@ export const listZones = defineRoute({
|
|
|
114
115
|
### 2. Create a Client
|
|
115
116
|
|
|
116
117
|
```ts
|
|
117
|
-
import {
|
|
118
|
+
import { createCherryClient } from "@b3b/cherry";
|
|
118
119
|
import { listZones, getZone, createDnsRecord } from "./routes/cloudflare";
|
|
119
120
|
|
|
120
|
-
const cf =
|
|
121
|
+
const cf = createCherryClient({
|
|
121
122
|
baseUrl: "https://api.cloudflare.com/client/v4",
|
|
122
123
|
headers: () => ({ Authorization: `Bearer ${process.env.CF_TOKEN}` }),
|
|
123
124
|
routes: { listZones, getZone, createDnsRecord },
|
|
@@ -141,10 +142,10 @@ const zones = await cf.call(listZones, { account_id: "abc" });
|
|
|
141
142
|
### Dynamic Path Parameters
|
|
142
143
|
|
|
143
144
|
```ts
|
|
144
|
-
export const getZone =
|
|
145
|
+
export const getZone = route({
|
|
145
146
|
method: "GET",
|
|
146
|
-
path:
|
|
147
|
-
|
|
147
|
+
path: path`/zones/${param("zone_id")}`,
|
|
148
|
+
pathParams: v.object({ zone_id: v.string() }),
|
|
148
149
|
response: v.object({ /* ... */ }),
|
|
149
150
|
});
|
|
150
151
|
```
|
|
@@ -154,7 +155,7 @@ export const getZone = defineRoute({
|
|
|
154
155
|
Replace the underlying fetch logic for logging, retries, auth refresh, etc.
|
|
155
156
|
|
|
156
157
|
```ts
|
|
157
|
-
|
|
158
|
+
createCherryClient({
|
|
158
159
|
baseUrl: "...",
|
|
159
160
|
fetcher: async (req) => {
|
|
160
161
|
console.log(`→ ${req.init.method} ${req.url}`);
|
|
@@ -187,8 +188,11 @@ const withLogging = (fetcher: Fetcher): Fetcher =>
|
|
|
187
188
|
return fetcher(req);
|
|
188
189
|
};
|
|
189
190
|
|
|
190
|
-
|
|
191
|
-
|
|
191
|
+
const baseFetcher: Fetcher = (req) => fetch(req.url, req.init);
|
|
192
|
+
|
|
193
|
+
createCherryClient({
|
|
194
|
+
baseUrl: "...",
|
|
195
|
+
fetcher: withLogging(withRetry(baseFetcher)),
|
|
192
196
|
});
|
|
193
197
|
```
|
|
194
198
|
|
|
@@ -204,18 +208,6 @@ createClient({
|
|
|
204
208
|
|
|
205
209
|
---
|
|
206
210
|
|
|
207
|
-
## Generating Routes from OpenAPI
|
|
208
|
-
|
|
209
|
-
Cherry includes a generator that transforms OpenAPI 3.x specs into route definitions:
|
|
210
|
-
|
|
211
|
-
```bash
|
|
212
|
-
cherry generate --input ./openapi.json --output ./routes/
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
See [ARCHITECTURE.md](./agent/ARCHITECTURE.md) for generator implementation details.
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
211
|
## Stack
|
|
220
212
|
|
|
221
213
|
- **Runtime:** Bun
|