hono-takibi 0.10.0 → 0.11.1

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 CHANGED
@@ -312,6 +312,26 @@ paths:
312
312
  x-pagination: true
313
313
  ```
314
314
 
315
+ ### Generated hooks
316
+
317
+ Every GET operation yields a key getter, an options factory, and a hook; every other method yields a mutation key getter, a `mutationOptions` factory, and a mutation hook.
318
+
319
+ ```ts
320
+ getUsersKey() // ['users'] — one per path prefix
321
+ getUsersIdQueryKey(args) // ['users', '/users/:id', args] — header params are left out
322
+ getItemsInfiniteQueryKey(args) // ['items', '/items', 'infinite', args]
323
+ getPostUsersMutationKey() // ['users', '/users', 'POST']
324
+
325
+ useUsersId(args, { query: { staleTime: 1_000 }, options: { headers } }, queryClient)
326
+ usePostUsers({ mutation: { mutationKey: ['custom'], onSuccess } }, queryClient)
327
+ ```
328
+
329
+ - `options.query` is the library's options type without `queryKey` / `queryFn` (the hook supplies both); `options.mutation` leaves out `mutationFn`, and a `mutationKey` you pass wins over the generated one.
330
+ - `options.options` is Hono's `ClientRequestOptions` (headers, fetch, init).
331
+ - The trailing argument is the framework's own: a `QueryClient` (an accessor of one in Solid and Svelte), or `{ injector }` in Angular.
332
+ - Vue hooks accept `Ref` / getter arguments and re-key the query when they change.
333
+ - SWR mutations revalidate only their own key; pass `swrKey: getGetUsersKey()` to revalidate the list instead.
334
+
315
335
  ## Test & Mock Generation
316
336
 
317
337
  ### Test Generation
@@ -338,6 +358,17 @@ export default defineConfig({
338
358
  })
339
359
  ```
340
360
 
361
+ Each route answers its success response by default. Like [Prism](https://stoplight.io/open-source/prism), a request can pick any response or named example the document declares with the `Prefer` header (or the `__code` / `__example` query):
362
+
363
+ ```bash
364
+ curl -H 'Prefer: code=404' http://localhost:3000/orders/1 # the 404 response
365
+ curl -H 'Prefer: example=pending' http://localhost:3000/orders/1 # a named example
366
+ curl -H 'Prefer: code=404, example=gone' http://localhost:3000/orders/1
367
+ curl 'http://localhost:3000/orders/1?__code=503'
368
+ ```
369
+
370
+ A code falls back to its `4XX` range, then `default`. A code or example the operation does not declare answers `500` with an `application/problem+json` body saying what is missing.
371
+
341
372
  ## API Reference Docs
342
373
 
343
374
  Generate API reference Markdown with [hono-cli](https://github.com/honojs/cli) `hono request` commands:
@@ -552,8 +583,9 @@ export default defineConfig({
552
583
 
553
584
  mock: {
554
585
  output: './src/mock.ts',
555
- useExamples: true,
586
+ useExamples: true, // true: response examples | 'all': also schema/property examples | false
556
587
  locale: 'en',
588
+ seed: 42, // optional: same body per route on every request (snapshot-friendly)
557
589
  delay: false,
558
590
  arrayMin: 1,
559
591
  arrayMax: 10,
package/dist/cli.js CHANGED
@@ -69,9 +69,9 @@ function runConfigPass(configPath, reload) {
69
69
  return Effect.gen(function* () {
70
70
  const [{ readConfig }, { parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob }] = yield* Effect.promise(() => Promise.all([
71
71
  import("./index.js"),
72
- import("./openapi-CzAVsFDt.js").then((n) => n.t),
72
+ import("./openapi-DQRxq2_O.js").then((n) => n.t),
73
73
  import("./format-Bm9LZ_ki.js").then((n) => n.r),
74
- import("./shared-Ck7P2pO5.js").then((n) => n.i)
74
+ import("./shared-BgsMAfDf.js").then((n) => n.i)
75
75
  ]));
76
76
  const config = yield* readConfig(configPath, reload);
77
77
  const jobs = makeJob(yield* parseOpenAPI(config.input), config);
@@ -204,7 +204,7 @@ function generate(args) {
204
204
  });
205
205
  }
206
206
  if (input !== void 0 && output !== void 0) {
207
- const [{ parseOpenAPI }, { takibi }] = yield* Effect.promise(() => Promise.all([import("./openapi-CzAVsFDt.js").then((n) => n.t), import("./core-BdG_5KX8.js").then((n) => n.t)]));
207
+ const [{ parseOpenAPI }, { takibi }] = yield* Effect.promise(() => Promise.all([import("./openapi-DQRxq2_O.js").then((n) => n.t), import("./core-BtueRJN7.js").then((n) => n.t)]));
208
208
  return yield* Console.log(yield* takibi(yield* parseOpenAPI(input), output, ONE_SHOT_COMPONENTS));
209
209
  }
210
210
  const resolvedConfig = configPath ?? DEFAULT_CONFIG_FILE;
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../index-B2QvGO4j.js";
1
+ import { t as OpenAPI } from "../../index-Dw-w92xu.js";
2
2
  import { Effect } from "effect";
3
3
  //#region src/core/docs/index.d.ts
4
4
  declare function docs(openAPI: OpenAPI, output: string, entry?: string, basePath?: string, curl?: boolean, baseUrl?: string): Effect.Effect<string, import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
@@ -1,2 +1,2 @@
1
- import { t as docs } from "../../docs-MzhmjfNS.js";
1
+ import { t as docs } from "../../docs-C1_fNNJ-.js";
2
2
  export { docs };
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../index-B2QvGO4j.js";
1
+ import { t as OpenAPI } from "../../index-Dw-w92xu.js";
2
2
  import { t as FormatError } from "../../index-wD0wV6VQ.js";
3
3
  import { t as GenerateError } from "../../index-6-_xlYFY.js";
4
4
  //#region src/core/hooks/index.d.ts
@@ -17,6 +17,14 @@ declare const HOOK_CONFIGS: {
17
17
  readonly useInfiniteQueryOptionsType: 'SWRInfiniteConfiguration';
18
18
  };
19
19
  readonly 'tanstack-query': {
20
+ readonly errorType: "DefaultError";
21
+ readonly hookTail: {
22
+ readonly name: 'queryClient';
23
+ readonly query: 'QueryClient';
24
+ readonly infinite: 'QueryClient';
25
+ readonly mutation: 'QueryClient';
26
+ readonly imports: readonly ['QueryClient'];
27
+ };
20
28
  readonly packageName: '@tanstack/react-query';
21
29
  readonly frameworkName: 'TanStack Query';
22
30
  readonly hookPrefix: 'use';
@@ -35,6 +43,14 @@ declare const HOOK_CONFIGS: {
35
43
  readonly useSuspenseQueryOptionsType: 'UseSuspenseQueryOptions';
36
44
  };
37
45
  readonly 'preact-query': {
46
+ readonly errorType: "DefaultError";
47
+ readonly hookTail: {
48
+ readonly name: 'queryClient';
49
+ readonly query: 'QueryClient';
50
+ readonly infinite: 'QueryClient';
51
+ readonly mutation: 'QueryClient';
52
+ readonly imports: readonly ['QueryClient'];
53
+ };
38
54
  readonly packageName: '@tanstack/preact-query';
39
55
  readonly frameworkName: 'Preact Query';
40
56
  readonly hookPrefix: 'use';
@@ -53,6 +69,14 @@ declare const HOOK_CONFIGS: {
53
69
  readonly useSuspenseQueryOptionsType: 'UseSuspenseQueryOptions';
54
70
  };
55
71
  readonly 'solid-query': {
72
+ readonly errorType: "DefaultError";
73
+ readonly hookTail: {
74
+ readonly name: 'queryClient';
75
+ readonly query: '()=>QueryClient';
76
+ readonly infinite: '()=>QueryClient';
77
+ readonly mutation: '()=>QueryClient';
78
+ readonly imports: readonly ['QueryClient'];
79
+ };
56
80
  readonly packageName: '@tanstack/solid-query';
57
81
  readonly frameworkName: 'Solid Query';
58
82
  readonly hookPrefix: 'create';
@@ -69,6 +93,14 @@ declare const HOOK_CONFIGS: {
69
93
  readonly unwrapOptionsAccessor: true;
70
94
  };
71
95
  readonly 'vue-query': {
96
+ readonly errorType: "DefaultError";
97
+ readonly hookTail: {
98
+ readonly name: 'queryClient';
99
+ readonly query: 'QueryClient';
100
+ readonly infinite: 'QueryClient';
101
+ readonly mutation: 'QueryClient';
102
+ readonly imports: readonly ['QueryClient'];
103
+ };
72
104
  readonly packageName: '@tanstack/vue-query';
73
105
  readonly frameworkName: 'Vue Query';
74
106
  readonly hookPrefix: 'use';
@@ -82,6 +114,14 @@ declare const HOOK_CONFIGS: {
82
114
  readonly useInfiniteQueryOptionsType: 'UseInfiniteQueryOptions';
83
115
  };
84
116
  readonly 'svelte-query': {
117
+ readonly errorType: "DefaultError";
118
+ readonly hookTail: {
119
+ readonly name: 'queryClient';
120
+ readonly query: '()=>QueryClient';
121
+ readonly infinite: '()=>QueryClient';
122
+ readonly mutation: '()=>QueryClient';
123
+ readonly imports: readonly ['QueryClient'];
124
+ };
85
125
  readonly packageName: '@tanstack/svelte-query';
86
126
  readonly frameworkName: 'Svelte Query';
87
127
  readonly hookPrefix: 'create';
@@ -91,11 +131,20 @@ declare const HOOK_CONFIGS: {
91
131
  readonly useQueryOptionsType: 'CreateQueryOptions';
92
132
  readonly useMutationOptionsType: 'CreateMutationOptions';
93
133
  readonly hasQueryOptionsHelper: true;
134
+ readonly hasMutationOptionsHelper: true;
94
135
  readonly infiniteQueryFn: 'createInfiniteQuery';
95
136
  readonly useInfiniteQueryOptionsType: 'CreateInfiniteQueryOptions';
96
137
  readonly hasInfiniteQueryOptionsHelper: true;
97
138
  };
98
139
  readonly 'angular-query': {
140
+ readonly errorType: "DefaultError";
141
+ readonly hookTail: {
142
+ readonly name: 'injectOptions';
143
+ readonly query: 'InjectQueryOptions';
144
+ readonly infinite: 'InjectInfiniteQueryOptions';
145
+ readonly mutation: 'InjectMutationOptions';
146
+ readonly imports: readonly ['InjectQueryOptions', 'InjectInfiniteQueryOptions', 'InjectMutationOptions'];
147
+ };
99
148
  readonly packageName: '@tanstack/angular-query-experimental';
100
149
  readonly frameworkName: 'Angular Query';
101
150
  readonly hookPrefix: 'inject';
@@ -104,7 +153,7 @@ declare const HOOK_CONFIGS: {
104
153
  readonly useQueryOptionsType: 'CreateQueryOptions';
105
154
  readonly useMutationOptionsType: 'CreateMutationOptions';
106
155
  readonly hasQueryOptionsHelper: true;
107
- readonly hasMutationOptionsHelper: false;
156
+ readonly hasMutationOptionsHelper: true;
108
157
  readonly hasInfiniteQueryOptionsHelper: true;
109
158
  readonly infiniteQueryFn: 'injectInfiniteQuery';
110
159
  readonly useInfiniteQueryOptionsType: 'CreateInfiniteQueryOptions';
@@ -1,2 +1,2 @@
1
- import { t as hooks } from "../../hooks-iffNFEYy.js";
1
+ import { t as hooks } from "../../hooks-CZkcozjK.js";
2
2
  export { hooks };
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../index-B2QvGO4j.js";
1
+ import { t as OpenAPI } from "../../index-Dw-w92xu.js";
2
2
  import { t as FormatError } from "../../index-wD0wV6VQ.js";
3
3
  import { t as GenerateError } from "../../index-6-_xlYFY.js";
4
4
  import { Effect } from "effect";
@@ -1,6 +1,6 @@
1
- import { A as isOperationLike, O as isOpenAPIPaths, R as isRecord, d as methodPath, l as makeInferRequestType } from "../../utils-BDa05U34.js";
1
+ import { f as methodPath, j as isOperationLike, k as isOpenAPIPaths, l as makeInferRequestType, z as isRecord } from "../../utils-DEFpxBMu.js";
2
2
  import { t as emit } from "../../emit-B_3fXoto.js";
3
- import { a as parsePathItem, i as operationHasArgs, o as resolveSplitOutDir, r as makeOperationDeps, s as GenerateError, t as formatPath } from "../../rpc-B95CYct5.js";
3
+ import { a as parsePathItem, i as operationHasArgs, o as resolveSplitOutDir, r as makeOperationDeps, s as GenerateError, t as formatPath } from "../../rpc-D_eeOVGa.js";
4
4
  import { Effect } from "effect";
5
5
  import { dirname, join } from "node:path";
6
6
  //#region src/core/rpc/index.ts
@@ -1,4 +1,4 @@
1
- import { t as OpenAPI } from "../../index-B2QvGO4j.js";
1
+ import { t as OpenAPI } from "../../index-Dw-w92xu.js";
2
2
  import { t as FormatError } from "../../index-wD0wV6VQ.js";
3
3
  import { Effect } from "effect";
4
4
  //#region src/core/type/index.d.ts
@@ -1,4 +1,4 @@
1
- import { E as isMediaWithSchema, M as isParameterArray, O as isOpenAPIPaths, U as isSchemaArray, V as isRequestBody, Y as isStringRef, h as statusCodeToNumber, j as isParameter, k as isOperation, u as makeSafeKey, w as isHttpMethod } from "../../utils-BDa05U34.js";
1
+ import { A as isOperation, D as isMediaWithSchema, H as isRequestBody, M as isParameter, N as isParameterArray, T as isHttpMethod, W as isSchemaArray, X as isStringRef, g as statusCodeToNumber, k as isOpenAPIPaths, u as makeSafeKey } from "../../utils-DEFpxBMu.js";
2
2
  import { t as emit } from "../../emit-B_3fXoto.js";
3
3
  import { Effect } from "effect";
4
4
  import path from "node:path";