hono-takibi 0.11.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 +20 -0
- package/dist/cli.js +3 -3
- package/dist/core/hooks/index.d.ts +50 -1
- package/dist/core/hooks/index.js +1 -1
- package/dist/{core-CpzC5kSm.js → core-BtueRJN7.js} +1 -1
- package/dist/{hooks-6j2Z-MPl.js → hooks-CZkcozjK.js} +121 -40
- package/dist/{openapi-CzAVsFDt.js → openapi-DQRxq2_O.js} +10 -19
- package/dist/{shared-BJ4A07Yx.js → shared-BgsMAfDf.js} +2 -2
- package/dist/vite-plugin/index.js +2 -2
- package/package.json +1 -1
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
|
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-
|
|
72
|
+
import("./openapi-DQRxq2_O.js").then((n) => n.t),
|
|
73
73
|
import("./format-Bm9LZ_ki.js").then((n) => n.r),
|
|
74
|
-
import("./shared-
|
|
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-
|
|
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;
|
|
@@ -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:
|
|
156
|
+
readonly hasMutationOptionsHelper: true;
|
|
108
157
|
readonly hasInfiniteQueryOptionsHelper: true;
|
|
109
158
|
readonly infiniteQueryFn: 'injectInfiniteQuery';
|
|
110
159
|
readonly useInfiniteQueryOptionsType: 'CreateInfiniteQueryOptions';
|
package/dist/core/hooks/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as hooks } from "../../hooks-
|
|
1
|
+
import { t as hooks } from "../../hooks-CZkcozjK.js";
|
|
2
2
|
export { hooks };
|
|
@@ -5,7 +5,7 @@ import { A as isOperation, B as isRefObject, D as isMediaWithSchema, F as isPara
|
|
|
5
5
|
import { t as emit } from "./emit-B_3fXoto.js";
|
|
6
6
|
import { s as GenerateError } from "./rpc-D_eeOVGa.js";
|
|
7
7
|
import { S as makeModuleSpec, _ as makeRef, a as responsesCode, b as makeExportConst, c as headersCode, d as ast, f as zodToOpenAPI, g as makePathItem, h as makeOperationResponses, i as schemasCode, l as makeSplitSchemaFile, m as makeCallbacks, n as routeCode, o as requestBodiesCode, p as makeCallback, r as componentsCode, s as parametersCode, t as zodOpenAPIHono, u as analyzeCircularSchemas, v as makeRequest, x as makeImports, y as makeConst } from "./openapi-DhxrYmuQ.js";
|
|
8
|
-
import { t as hooks } from "./hooks-
|
|
8
|
+
import { t as hooks } from "./hooks-CZkcozjK.js";
|
|
9
9
|
import { t as docs } from "./docs-C1_fNNJ-.js";
|
|
10
10
|
import { rpc } from "./core/rpc/index.js";
|
|
11
11
|
import { type } from "./core/type/index.js";
|
|
@@ -4,13 +4,25 @@ import { a as parsePathItem, i as operationHasArgs, n as hasNoContentResponse, o
|
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
//#region src/helper/query.ts
|
|
7
|
+
function makeHookTail(tail, kind) {
|
|
8
|
+
return tail ? {
|
|
9
|
+
sig: `,${tail.name}?:${tail[kind]}`,
|
|
10
|
+
arg: `,${tail.name}`
|
|
11
|
+
} : {
|
|
12
|
+
sig: "",
|
|
13
|
+
arg: ""
|
|
14
|
+
};
|
|
15
|
+
}
|
|
7
16
|
function wrapOptionsType(optionsType, unwrapAccessor) {
|
|
8
17
|
return unwrapAccessor ? `ReturnType<${optionsType}>` : optionsType;
|
|
9
18
|
}
|
|
10
19
|
const QUERY_OMIT_KEYS = `'queryKey'|'queryFn'`;
|
|
11
20
|
const INFINITE_OMIT_KEYS = `'queryKey'|'queryFn'|'initialPageParam'|'getNextPageParam'`;
|
|
12
|
-
|
|
13
|
-
|
|
21
|
+
const MUTATION_OMIT_KEYS = `'mutationFn'`;
|
|
22
|
+
const VUE_QUERY_MEMBER = `{queryKey:unknown}`;
|
|
23
|
+
const VUE_MUTATION_MEMBER = `{mutationFn?:unknown}`;
|
|
24
|
+
function omitInjectedKeys(optionsType, keys, vueMember) {
|
|
25
|
+
return `Omit<${vueMember ? `Extract<${optionsType},${vueMember}>` : optionsType},${keys}>`;
|
|
14
26
|
}
|
|
15
27
|
function makeHookName(method, pathStr, prefix) {
|
|
16
28
|
const funcName = methodPath(method, pathStr);
|
|
@@ -33,14 +45,24 @@ function makeQueryKeyGetterName(method, pathStr, isSWR) {
|
|
|
33
45
|
if (isSWR) return `get${capitalize(methodPath(method, pathStr))}Key`;
|
|
34
46
|
return `get${capitalize(methodPath("", pathStr))}QueryKey`;
|
|
35
47
|
}
|
|
48
|
+
function makeMutationKeyGetterName(method, pathStr, isSWR) {
|
|
49
|
+
if (isSWR) return `get${capitalize(methodPath(method, pathStr))}Key`;
|
|
50
|
+
return `get${capitalize(methodPath(method, pathStr))}MutationKey`;
|
|
51
|
+
}
|
|
52
|
+
function makeMutationKeyGetterCode(keyGetterName, method, honoPath) {
|
|
53
|
+
return `export function ${keyGetterName}(){return['${honoPath.replace(/^\//u, "").split("/")[0]}','${honoPath}','${method.toUpperCase()}']as const}`;
|
|
54
|
+
}
|
|
36
55
|
function makeInfiniteQueryKeyGetterName(method, pathStr, isSWR) {
|
|
37
56
|
if (isSWR) return `get${capitalize(methodPath(method, pathStr))}InfiniteKey`;
|
|
38
57
|
return `get${capitalize(methodPath("", pathStr))}InfiniteQueryKey`;
|
|
39
58
|
}
|
|
59
|
+
function vueReactiveKey(keyCall) {
|
|
60
|
+
return `computed(()=>${keyCall})`;
|
|
61
|
+
}
|
|
40
62
|
function makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, hasHeader = false) {
|
|
41
63
|
const prefix = honoPath.replace(/^\//u, "").split("/")[0];
|
|
42
64
|
if (config.isVueQuery) {
|
|
43
|
-
if (hasArgs) return `export function ${keyGetterName}(args:MaybeRefOrGetter<${argsType}>){${hasHeader ? "const{header:_,...keyArgs}=toValue(args);return" : "return"}['${prefix}','${honoPath}',${hasHeader ? "keyArgs" : "args"}]as const}`;
|
|
65
|
+
if (hasArgs) return `export function ${keyGetterName}(args:MaybeRefOrGetter<${argsType}>){${hasHeader ? "const{header:_,...keyArgs}=toValue(args);return" : "return"}['${prefix}','${honoPath}',${hasHeader ? "keyArgs" : "toValue(args)"}]as const}`;
|
|
44
66
|
return `export function ${keyGetterName}(){return['${prefix}','${honoPath}']as const}`;
|
|
45
67
|
}
|
|
46
68
|
if (hasArgs) return `export function ${keyGetterName}(args:${argsType}){${hasHeader ? `const{header:_,...keyArgs}=args;return['${prefix}','${honoPath}',keyArgs]as const` : `return['${prefix}','${honoPath}',args]as const`}}`;
|
|
@@ -49,10 +71,10 @@ function makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, conf
|
|
|
49
71
|
function makeInfiniteQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, hasHeader = false) {
|
|
50
72
|
const prefix = honoPath.replace(/^\//u, "").split("/")[0];
|
|
51
73
|
if (config.isVueQuery) {
|
|
52
|
-
if (hasArgs) return `export function ${keyGetterName}(args:MaybeRefOrGetter<${argsType}>){${hasHeader ? "const{header:_,...keyArgs}=toValue(args);return" : "return"}['${prefix}','${honoPath}',${hasHeader ? "keyArgs" : "args"}
|
|
74
|
+
if (hasArgs) return `export function ${keyGetterName}(args:MaybeRefOrGetter<${argsType}>){${hasHeader ? "const{header:_,...keyArgs}=toValue(args);return" : "return"}['${prefix}','${honoPath}','infinite',${hasHeader ? "keyArgs" : "toValue(args)"}]as const}`;
|
|
53
75
|
return `export function ${keyGetterName}(){return['${prefix}','${honoPath}','infinite']as const}`;
|
|
54
76
|
}
|
|
55
|
-
if (hasArgs) return `export function ${keyGetterName}(args:${argsType}){${hasHeader ? `const{header:_,...keyArgs}=args;return['${prefix}','${honoPath}',
|
|
77
|
+
if (hasArgs) return `export function ${keyGetterName}(args:${argsType}){${hasHeader ? `const{header:_,...keyArgs}=args;return['${prefix}','${honoPath}','infinite',keyArgs]as const` : `return['${prefix}','${honoPath}','infinite',args]as const`}}`;
|
|
56
78
|
return `export function ${keyGetterName}(){return['${prefix}','${honoPath}','infinite']as const}`;
|
|
57
79
|
}
|
|
58
80
|
/**
|
|
@@ -68,7 +90,8 @@ function makeQueryOptionsGetterCode(optionsGetterName, keyGetterName, hasArgs, a
|
|
|
68
90
|
const queryKeyCall = hasArgs ? `${keyGetterName}(args)` : `${keyGetterName}()`;
|
|
69
91
|
const queryFnSig = config.hasQueryOptionsHelper ? "{signal}" : "{signal}:QueryFunctionContext";
|
|
70
92
|
if (config.isVueQuery && hasArgs) {
|
|
71
|
-
const
|
|
93
|
+
const fetcherCall = `parseResponse(${runtimeAccess}(toValue(args),{...options,init:{...options?.init,signal}}))`;
|
|
94
|
+
const bodyContent = `queryKey:${vueReactiveKey(queryKeyCall)},queryFn(${queryFnSig}){return ${fetcherCall}}`;
|
|
72
95
|
return `export function ${optionsGetterName}(args:MaybeRefOrGetter<${argsType}>,options?:ClientRequestOptions){return ${config.hasQueryOptionsHelper ? `queryOptions({${bodyContent}})` : `{${bodyContent}}`}}`;
|
|
73
96
|
}
|
|
74
97
|
const bodyContent = `queryKey:${queryKeyCall},queryFn(${queryFnSig}){return ${hasArgs ? `parseResponse(${runtimeAccess}(args,{...options,init:{...options?.init,signal}}))` : `parseResponse(${runtimeAccess}(undefined,{...options,init:{...options?.init,signal}}))`}}`;
|
|
@@ -87,24 +110,30 @@ function makePaginationParam(hasArgs, argsType, responseType) {
|
|
|
87
110
|
}
|
|
88
111
|
function makeInfiniteQueryOptionsGetterCode(optionsGetterName, infiniteKeyGetterName, hasArgs, argsType, runtimeAccess, responseType, config) {
|
|
89
112
|
const queryKeyCall = hasArgs ? `${infiniteKeyGetterName}(args)` : `${infiniteKeyGetterName}()`;
|
|
90
|
-
const
|
|
113
|
+
const queryKeyType = `ReturnType<typeof ${infiniteKeyGetterName}>`;
|
|
114
|
+
const queryFnSig = config.isVueQuery ? "{pageParam,signal}:QueryFunctionContext<readonly unknown[],TPageParam>" : `{pageParam,signal}:QueryFunctionContext<${queryKeyType},TPageParam>`;
|
|
91
115
|
const requestArgsCall = makeRequestArgsCall(hasArgs);
|
|
92
116
|
if (config.hasInfiniteQueryOptionsHelper) {
|
|
93
117
|
const paginationParam = makePaginationParam(hasArgs, argsType, responseType);
|
|
94
|
-
if (config.isVueQuery && hasArgs)
|
|
118
|
+
if (config.isVueQuery && hasArgs) {
|
|
119
|
+
const fetcherCall = `parseResponse(${runtimeAccess}(${requestArgsCall("toValue(args)")},{...options,init:{...options?.init,signal}}))`;
|
|
120
|
+
return `export function ${optionsGetterName}<TPageParam=unknown>(args:MaybeRefOrGetter<${argsType}>,${paginationParam},options?:ClientRequestOptions){return infiniteQueryOptions({${`queryKey:${vueReactiveKey(queryKeyCall)},queryFn(${queryFnSig}){return ${fetcherCall}},initialPageParam:pagination.initialPageParam,getNextPageParam:pagination.getNextPageParam`}})}`;
|
|
121
|
+
}
|
|
95
122
|
const body = `queryKey:${queryKeyCall},queryFn(${queryFnSig}){return ${`parseResponse(${runtimeAccess}(${requestArgsCall("args")},{...options,init:{...options?.init,signal}}))`}},initialPageParam:pagination.initialPageParam,getNextPageParam:pagination.getNextPageParam`;
|
|
96
123
|
if (hasArgs) return `export function ${optionsGetterName}<TPageParam=unknown>(args:${argsType},${paginationParam},options?:ClientRequestOptions){return infiniteQueryOptions({${body}})}`;
|
|
97
124
|
return `export function ${optionsGetterName}<TPageParam=unknown>(${paginationParam},options?:ClientRequestOptions){return infiniteQueryOptions({${body}})}`;
|
|
98
125
|
}
|
|
99
126
|
const vuePaginationParam = `pagination:{${makeGetRequestArgsField(hasArgs, argsType)}}`;
|
|
100
|
-
if (config.isVueQuery && hasArgs)
|
|
127
|
+
if (config.isVueQuery && hasArgs) {
|
|
128
|
+
const fetcherCall = `parseResponse(${runtimeAccess}(${requestArgsCall("toValue(args)")},{...options,init:{...options?.init,signal}}))`;
|
|
129
|
+
return `export function ${optionsGetterName}<TPageParam=unknown>(args:MaybeRefOrGetter<${argsType}>,${vuePaginationParam},options?:ClientRequestOptions){return {${`queryKey:${vueReactiveKey(queryKeyCall)},queryFn(${queryFnSig}){return ${fetcherCall}}`}}}`;
|
|
130
|
+
}
|
|
101
131
|
const bodyContent = `queryKey:${queryKeyCall},queryFn(${queryFnSig}){return ${`parseResponse(${runtimeAccess}(${requestArgsCall("args")},{...options,init:{...options?.init,signal}}))`}}`;
|
|
102
132
|
if (hasArgs) return `export function ${optionsGetterName}<TPageParam=unknown>(args:${argsType},${vuePaginationParam},options?:ClientRequestOptions){return {${bodyContent}}}`;
|
|
103
133
|
return `export function ${optionsGetterName}<TPageParam=unknown>(${vuePaginationParam},options?:ClientRequestOptions){return {${bodyContent}}}`;
|
|
104
134
|
}
|
|
105
|
-
function makeMutationOptionsGetterCode(optionsGetterName, hasArgs, argsType, runtimeAccess,
|
|
106
|
-
const
|
|
107
|
-
const inlineKey = `['${honoPath.replace(/^\//u, "").split("/")[0]}','${honoPath}','${methodUpper}']as const`;
|
|
135
|
+
function makeMutationOptionsGetterCode(optionsGetterName, keyGetterName, hasArgs, argsType, runtimeAccess, responseType, hasNoContent, config) {
|
|
136
|
+
const inlineKey = `${keyGetterName}()`;
|
|
108
137
|
const errorType = config.errorType ?? "unknown";
|
|
109
138
|
const tErrorGeneric = config.hasMutationOptionsHelper ? `<TError=${errorType},TOnMutateResult=unknown>` : "";
|
|
110
139
|
const typeArgs = `<${hasNoContent ? `${responseType}|undefined` : responseType},TError,${hasArgs ? argsType : "void"},TOnMutateResult>`;
|
|
@@ -140,7 +169,7 @@ function makeSWRInfiniteHookCode(hookName, infiniteKeyGetterName, hasArgs, argsT
|
|
|
140
169
|
const tErrorGeneric = `<TError=${errorType}>`;
|
|
141
170
|
const keyCall = hasArgs ? `${infiniteKeyGetterName}(args)` : `${infiniteKeyGetterName}()`;
|
|
142
171
|
const loaderKeyType = `readonly[...${`ReturnType<typeof ${infiniteKeyGetterName}>`},number]`;
|
|
143
|
-
return `export function ${hookName}${tErrorGeneric}(${argsSig}${`options:{swr?:${`SWRInfiniteConfiguration<${responseType},TError>&{swrKey?:(index:number,previousPageData:${responseType}|null)=>${loaderKeyType}}`};options?:ClientRequestOptions;pagination:{${hasArgs ? `getRequestArgs:(args:${argsType},index:number)=>${argsType}` : `getRequestArgs:(index:number)=>${argsType}`}}}`}){const{swr:swrOptions,options:clientOptions,pagination}=options;const{swrKey:customKeyLoader,...restSwrOptions}=swrOptions??{};const keyLoader=customKeyLoader??((index:number)=>[...${keyCall},index]as const);return useSWRInfinite(keyLoader,(${`[${",".repeat(hasArgs ? 4 : 3)}index]:${loaderKeyType}`})=>parseResponse(${runtimeAccess}(${hasArgs ? `pagination.getRequestArgs(args,index)` : `pagination.getRequestArgs(index)`},clientOptions)),restSwrOptions)}`;
|
|
172
|
+
return `export function ${hookName}${tErrorGeneric}(${argsSig}${`options:{swr?:${`SWRInfiniteConfiguration<${responseType},TError>&{swrKey?:(index:number,previousPageData:${responseType}|null)=>${loaderKeyType}|null}`};options?:ClientRequestOptions;pagination:{${hasArgs ? `getRequestArgs:(args:${argsType},index:number)=>${argsType}` : `getRequestArgs:(index:number)=>${argsType}`}}}`}){const{swr:swrOptions,options:clientOptions,pagination}=options;const{swrKey:customKeyLoader,...restSwrOptions}=swrOptions??{};const keyLoader=customKeyLoader??((index:number)=>[...${keyCall},index]as const);return useSWRInfinite(keyLoader,(${`[${",".repeat(hasArgs ? 4 : 3)}index]:${loaderKeyType}`})=>parseResponse(${runtimeAccess}(${hasArgs ? `pagination.getRequestArgs(args,index)` : `pagination.getRequestArgs(index)`},clientOptions)),restSwrOptions)}`;
|
|
144
173
|
}
|
|
145
174
|
/**
|
|
146
175
|
* Generates a query hook with inline queryKey + queryFn. The hook builds its own
|
|
@@ -164,22 +193,24 @@ function makeSWRInfiniteHookCode(hookName, infiniteKeyGetterName, hasArgs, argsT
|
|
|
164
193
|
function makeQueryHookCode(hookName, keyGetterName, runtimeAccess, hasArgs, argsType, responseType, config) {
|
|
165
194
|
const generics = `<TData=${responseType},TError=${config.errorType ?? "unknown"}>`;
|
|
166
195
|
const optionsTypeArgs = config.isVueQuery ? `${responseType},TError,TData,${responseType},ReturnType<typeof ${keyGetterName}>` : `${responseType},TError,TData`;
|
|
167
|
-
const optionsType = `{query?:${omitInjectedKeys(wrapOptionsType(`${config.useQueryOptionsType}<${optionsTypeArgs}>`, config.unwrapOptionsAccessor), QUERY_OMIT_KEYS, config.isVueQuery)};options?:ClientRequestOptions}`;
|
|
196
|
+
const optionsType = `{query?:${omitInjectedKeys(wrapOptionsType(`${config.useQueryOptionsType}<${optionsTypeArgs}>`, config.unwrapOptionsAccessor), QUERY_OMIT_KEYS, config.isVueQuery ? VUE_QUERY_MEMBER : void 0)};options?:ClientRequestOptions}`;
|
|
168
197
|
const keyCall = hasArgs ? `${keyGetterName}(args)` : `${keyGetterName}()`;
|
|
198
|
+
const tail = makeHookTail(config.hookTail, "query");
|
|
169
199
|
if (config.useThunk) {
|
|
170
200
|
const argsSig = hasArgs ? `args:()=>${argsType},` : "";
|
|
171
201
|
const svelteKeyCall = hasArgs ? `${keyGetterName}(args())` : `${keyGetterName}()`;
|
|
172
202
|
const fetcherCall = hasArgs ? `parseResponse(${runtimeAccess}(args(),{...clientOptions,init:{...clientOptions?.init,signal}}))` : `parseResponse(${runtimeAccess}(undefined,{...clientOptions,init:{...clientOptions?.init,signal}}))`;
|
|
173
|
-
return `export function ${hookName}${generics}(${argsSig}options?:()=>${optionsType}){return ${config.queryFn}(()=>{const{query,options:clientOptions}=options?.()??{};return{...query,queryKey:${svelteKeyCall},queryFn({signal}:QueryFunctionContext){return ${fetcherCall}}}})}`;
|
|
203
|
+
return `export function ${hookName}${generics}(${argsSig}options?:()=>${optionsType}${tail.sig}){return ${config.queryFn}(()=>{const{query,options:clientOptions}=options?.()??{};return{...query,queryKey:${svelteKeyCall},queryFn({signal}:QueryFunctionContext){return ${fetcherCall}}}}${tail.arg})}`;
|
|
174
204
|
}
|
|
175
205
|
if (config.isVueQuery) {
|
|
176
206
|
const argsSig = hasArgs ? `args:MaybeRefOrGetter<${argsType}>,` : "";
|
|
177
207
|
const fetcherCall = hasArgs ? `parseResponse(${runtimeAccess}(toValue(args),{...clientOptions,init:{...clientOptions?.init,signal}}))` : `parseResponse(${runtimeAccess}(undefined,{...clientOptions,init:{...clientOptions?.init,signal}}))`;
|
|
178
|
-
|
|
208
|
+
const vueKeyCall = hasArgs ? vueReactiveKey(keyCall) : keyCall;
|
|
209
|
+
return `export function ${hookName}${generics}(${argsSig}options?:${optionsType}${tail.sig}){const{query:queryOptions,options:clientOptions}=options??{};return ${config.queryFn}({...queryOptions,queryKey:${vueKeyCall},queryFn({signal}){return ${fetcherCall}}}${tail.arg})}`;
|
|
179
210
|
}
|
|
180
211
|
const argsSig = hasArgs ? `args:${argsType},` : "";
|
|
181
212
|
const fetcherCall = hasArgs ? `parseResponse(${runtimeAccess}(args,{...clientOptions,init:{...clientOptions?.init,signal}}))` : `parseResponse(${runtimeAccess}(undefined,{...clientOptions,init:{...clientOptions?.init,signal}}))`;
|
|
182
|
-
return `export function ${hookName}${generics}(${argsSig}options?:${optionsType}){const{query:queryOptions,options:clientOptions}=options??{};return ${config.queryFn}({...queryOptions,queryKey:${keyCall},queryFn({signal}:QueryFunctionContext){return ${fetcherCall}}})}`;
|
|
213
|
+
return `export function ${hookName}${generics}(${argsSig}options?:${optionsType}${tail.sig}){const{query:queryOptions,options:clientOptions}=options??{};return ${config.queryFn}({...queryOptions,queryKey:${keyCall},queryFn({signal}:QueryFunctionContext){return ${fetcherCall}}}${tail.arg})}`;
|
|
183
214
|
}
|
|
184
215
|
/**
|
|
185
216
|
* Builds the inline body for an infinite query hook (queryKey + queryFn + optional pagination).
|
|
@@ -200,34 +231,37 @@ function makeInfiniteHookBody(keyCall, fetcherCall, useHelper, queryKeyType, isV
|
|
|
200
231
|
function makeInfiniteQueryHookCode(hookName, runtimeAccess, infiniteKeyGetterName, infiniteOptionsGetterName, hasArgs, argsType, responseType, config) {
|
|
201
232
|
const errorType = config.errorType ?? "unknown";
|
|
202
233
|
const useHelper = config.hasInfiniteQueryOptionsHelper === true;
|
|
203
|
-
const generics = `<TData=${
|
|
234
|
+
const generics = `<TData=${`InfiniteData<${responseType}>`},TError=${errorType},TPageParam=unknown>`;
|
|
204
235
|
const queryKeyType = `ReturnType<typeof ${infiniteKeyGetterName}>`;
|
|
205
|
-
const queryOptionsType = omitInjectedKeys(wrapOptionsType(`${config.useInfiniteQueryOptionsType}<${responseType},TError,TData,${queryKeyType},TPageParam>`, config.unwrapOptionsAccessor), useHelper ? INFINITE_OMIT_KEYS : QUERY_OMIT_KEYS, config.isVueQuery);
|
|
236
|
+
const queryOptionsType = omitInjectedKeys(wrapOptionsType(`${config.useInfiniteQueryOptionsType}<${responseType},TError,TData,${queryKeyType},TPageParam>`, config.unwrapOptionsAccessor), useHelper ? INFINITE_OMIT_KEYS : QUERY_OMIT_KEYS, config.isVueQuery ? VUE_QUERY_MEMBER : void 0);
|
|
206
237
|
const optionsType = useHelper ? `{query?:${queryOptionsType};options?:ClientRequestOptions}` : `{query:${queryOptionsType};options?:ClientRequestOptions}`;
|
|
207
238
|
const requestArgsCall = makeRequestArgsCall(hasArgs);
|
|
208
239
|
const paginationParam = makePaginationParam(hasArgs, argsType, responseType);
|
|
209
240
|
const paginationSig = useHelper ? `${paginationParam},` : "";
|
|
210
241
|
const vuePaginationParam = `pagination:{${makeGetRequestArgsField(hasArgs, argsType)}}`;
|
|
242
|
+
const tail = makeHookTail(config.hookTail, "infinite");
|
|
211
243
|
if (config.isVueQuery && useHelper) {
|
|
212
244
|
const argsSig = hasArgs ? `args:MaybeRefOrGetter<${argsType}>,` : "";
|
|
213
245
|
const optionsCall = hasArgs ? `${infiniteOptionsGetterName}(args,pagination,clientOptions)` : `${infiniteOptionsGetterName}(pagination,clientOptions)`;
|
|
214
|
-
return `export function ${hookName}${generics}(${argsSig}${paginationParam},options?:${optionsType}){const{query:queryOptions,options:clientOptions}=options??{};return ${config.infiniteQueryFn}({...queryOptions,...${optionsCall}})}`;
|
|
246
|
+
return `export function ${hookName}${generics}(${argsSig}${paginationParam},options?:${optionsType}${tail.sig}){const{query:queryOptions,options:clientOptions}=options??{};return ${config.infiniteQueryFn}({...queryOptions,...${optionsCall}}${tail.arg})}`;
|
|
215
247
|
}
|
|
216
248
|
if (config.useThunk) {
|
|
217
249
|
const argsSig = hasArgs ? `args:()=>${argsType},` : "";
|
|
218
250
|
const body = makeInfiniteHookBody(hasArgs ? `${infiniteKeyGetterName}(args())` : `${infiniteKeyGetterName}()`, `parseResponse(${runtimeAccess}(${requestArgsCall("args()")},{...clientOptions,init:{...clientOptions?.init,signal}}))`, useHelper, queryKeyType);
|
|
219
251
|
const optionsTypeSig = useHelper ? `options?:()=>${optionsType}` : `options:()=>${optionsType}`;
|
|
220
252
|
const destructure = useHelper ? `options?.()??{}` : "options()";
|
|
221
|
-
return `export function ${hookName}${generics}(${argsSig}${paginationSig}${optionsTypeSig}){return ${config.infiniteQueryFn}(()=>{const{query,options:clientOptions}=${destructure};return{...query,${body}}})}`;
|
|
253
|
+
return `export function ${hookName}${generics}(${argsSig}${paginationSig}${optionsTypeSig}${tail.sig}){return ${config.infiniteQueryFn}(()=>{const{query,options:clientOptions}=${destructure};return{...query,${body}}}${tail.arg})}`;
|
|
222
254
|
}
|
|
223
255
|
if (config.isVueQuery) {
|
|
224
256
|
const argsSig = hasArgs ? `args:MaybeRefOrGetter<${argsType}>,` : "";
|
|
225
|
-
const body = makeInfiniteHookBody(hasArgs ? `${infiniteKeyGetterName}(args)` : `${infiniteKeyGetterName}()`, `parseResponse(${runtimeAccess}(${requestArgsCall("toValue(args)")},{...clientOptions,init:{...clientOptions?.init,signal}}))`, useHelper, queryKeyType, true);
|
|
226
|
-
return `export function ${hookName}${generics}(${argsSig}${vuePaginationParam},options:${optionsType}){const{query:queryOptions,options:clientOptions}=options;return ${config.infiniteQueryFn}({...queryOptions,${body}})}`;
|
|
257
|
+
const body = makeInfiniteHookBody(hasArgs ? vueReactiveKey(`${infiniteKeyGetterName}(args)`) : `${infiniteKeyGetterName}()`, `parseResponse(${runtimeAccess}(${requestArgsCall("toValue(args)")},{...clientOptions,init:{...clientOptions?.init,signal}}))`, useHelper, queryKeyType, true);
|
|
258
|
+
return `export function ${hookName}${generics}(${argsSig}${vuePaginationParam},options:${optionsType}${tail.sig}){const{query:queryOptions,options:clientOptions}=options;return ${config.infiniteQueryFn}({...queryOptions,${body}}${tail.arg})}`;
|
|
227
259
|
}
|
|
228
260
|
const argsSig = hasArgs ? `args:${argsType},` : "";
|
|
229
261
|
const body = makeInfiniteHookBody(hasArgs ? `${infiniteKeyGetterName}(args)` : `${infiniteKeyGetterName}()`, `parseResponse(${runtimeAccess}(${requestArgsCall("args")},{...clientOptions,init:{...clientOptions?.init,signal}}))`, useHelper, queryKeyType);
|
|
230
|
-
|
|
262
|
+
const optionsTypeSig = useHelper ? `options?:${optionsType}` : `options:${optionsType}`;
|
|
263
|
+
const destructure = useHelper ? "options??{}" : "options";
|
|
264
|
+
return `export function ${hookName}${generics}(${argsSig}${paginationSig}${optionsTypeSig}${tail.sig}){const{query:queryOptions,options:clientOptions}=${destructure};return ${config.infiniteQueryFn}({...queryOptions,${body}}${tail.arg})}`;
|
|
231
265
|
}
|
|
232
266
|
/**
|
|
233
267
|
* Generates prefix key getter function code.
|
|
@@ -260,7 +294,7 @@ function makeSWRHeader(importPath, clientName, hasQuery, hasMutation, hasAnyArgs
|
|
|
260
294
|
const lines = [];
|
|
261
295
|
if (hasQuery) {
|
|
262
296
|
lines.push("import useSWR from'swr'", "import useSWRImmutable from'swr/immutable'", "import type{Key,SWRConfiguration}from'swr'");
|
|
263
|
-
if (hasInfiniteQuery) lines.push("import useSWRInfinite from'swr/infinite'", "import type{SWRInfiniteConfiguration
|
|
297
|
+
if (hasInfiniteQuery) lines.push("import useSWRInfinite from'swr/infinite'", "import type{SWRInfiniteConfiguration}from'swr/infinite'");
|
|
264
298
|
} else if (hasMutation) lines.push("import type{Key}from'swr'");
|
|
265
299
|
if (hasMutation) lines.push("import useSWRMutation from'swr/mutation'", "import type{SWRMutationConfiguration}from'swr/mutation'");
|
|
266
300
|
const honoTypeImports = ["ClientRequestOptions", ...hasAnyArgs || hasInfiniteQuery ? ["InferRequestType"] : []];
|
|
@@ -275,22 +309,24 @@ function makeSWRHeader(importPath, clientName, hasQuery, hasMutation, hasAnyArgs
|
|
|
275
309
|
* - fetcher: (_: Key, { arg }) => Promise<Data>
|
|
276
310
|
* - options: SWRMutationConfiguration
|
|
277
311
|
*/
|
|
278
|
-
function makeSWRMutationHookCode(hookName,
|
|
312
|
+
function makeSWRMutationHookCode(hookName, keyCall, hasArgs, argsType, responseType, runtimeAccess, hasNoContent, errorType = "unknown") {
|
|
279
313
|
const variablesType = hasArgs ? argsType : "undefined";
|
|
280
314
|
const responseTypeWithUndefined = hasNoContent ? `${responseType}|undefined` : responseType;
|
|
281
315
|
const tErrorGeneric = `<TError=${errorType}>`;
|
|
282
|
-
const optionsSig = `options?:{mutation?:${`SWRMutationConfiguration<${responseTypeWithUndefined},TError,Key,${variablesType}>`}&{swrKey?:Key};options?:ClientRequestOptions}`;
|
|
283
|
-
if (hasArgs) return `export function ${hookName}${tErrorGeneric}(${optionsSig}){const{mutation:mutationOptions,options:clientOptions}=options??{};const{swrKey:customKey,...restMutationOptions}=mutationOptions??{};const swrKey=customKey??${
|
|
284
|
-
return `export function ${hookName}${tErrorGeneric}(${optionsSig}){const{mutation:mutationOptions,options:clientOptions}=options??{};const{swrKey:customKey,...restMutationOptions}=mutationOptions??{};const swrKey=customKey??${
|
|
316
|
+
const optionsSig = `options?:{mutation?:${`SWRMutationConfiguration<${responseTypeWithUndefined},TError,Key,${variablesType}>`}&{swrKey?:Key;throwOnError?:boolean};options?:ClientRequestOptions}`;
|
|
317
|
+
if (hasArgs) return `export function ${hookName}${tErrorGeneric}(${optionsSig}){const{mutation:mutationOptions,options:clientOptions}=options??{};const{swrKey:customKey,...restMutationOptions}=mutationOptions??{};const swrKey=customKey??${keyCall};return{swrKey,...useSWRMutation(swrKey,async(_:Key,{arg}:{arg:${argsType}})=>parseResponse(${runtimeAccess}(arg,clientOptions)),restMutationOptions)}}`;
|
|
318
|
+
return `export function ${hookName}${tErrorGeneric}(${optionsSig}){const{mutation:mutationOptions,options:clientOptions}=options??{};const{swrKey:customKey,...restMutationOptions}=mutationOptions??{};const swrKey=customKey??${keyCall};return{swrKey,...useSWRMutation(swrKey,async()=>parseResponse(${runtimeAccess}(undefined,clientOptions)),restMutationOptions)}}`;
|
|
285
319
|
}
|
|
286
320
|
function makeMutationHookCode(hookName, optionsGetterName, hasArgs, argsType, responseType, config, hasNoContent) {
|
|
287
321
|
const variablesType = hasArgs ? argsType : "void";
|
|
288
322
|
const tErrorGeneric = `<TError=${config.errorType ?? "unknown"},TOnMutateResult=unknown>`;
|
|
289
323
|
const dataType = hasNoContent ? `${responseType}|undefined` : responseType;
|
|
290
|
-
const
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
324
|
+
const fullOptionsType = wrapOptionsType(`${config.useMutationOptionsType}<${dataType},TError,${variablesType},TOnMutateResult>`, config.unwrapOptionsAccessor);
|
|
325
|
+
const factoryCall = `${optionsGetterName}${config.hasMutationOptionsHelper ? "<TError,TOnMutateResult>" : ""}(clientOptions)`;
|
|
326
|
+
const tail = makeHookTail(config.hookTail, "mutation");
|
|
327
|
+
const optionsType = `{mutation?:${omitInjectedKeys(fullOptionsType, MUTATION_OMIT_KEYS, config.isVueQuery ? VUE_MUTATION_MEMBER : void 0)};options?:ClientRequestOptions}`;
|
|
328
|
+
if (config.useThunk) return `export function ${hookName}${tErrorGeneric}(options?:()=>${optionsType}${tail.sig}){return ${config.mutationFn}(()=>{const{mutation,options:clientOptions}=options?.()??{};const mutationDefaults=${factoryCall};return{...mutation,...mutationDefaults,mutationKey:mutation?.mutationKey??mutationDefaults.mutationKey}}${tail.arg})}`;
|
|
329
|
+
return `export function ${hookName}${tErrorGeneric}(options?:${optionsType}${tail.sig}){const{mutation:mutationOptions,options:clientOptions}=options??{};const mutationDefaults=${factoryCall};return ${config.mutationFn}({...mutationOptions,...mutationDefaults,mutationKey:mutationOptions?.mutationKey??mutationDefaults.mutationKey}${tail.arg})}`;
|
|
294
330
|
}
|
|
295
331
|
function makeHookCode(pathStr, method, item, deps, config, clientName) {
|
|
296
332
|
const op = item[method];
|
|
@@ -332,8 +368,9 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
|
|
|
332
368
|
operationFileName
|
|
333
369
|
};
|
|
334
370
|
}
|
|
371
|
+
const mutationKeyGetterName = makeMutationKeyGetterName(method, pathStr, true);
|
|
335
372
|
return {
|
|
336
|
-
code:
|
|
373
|
+
code: `${makeMutationKeyGetterCode(mutationKeyGetterName, method, honoPath)}\n\n${makeSWRMutationHookCode(hookName, `${mutationKeyGetterName}()`, hasArgs, argsType, responseType, runtimeAccess, hasNoContent, config.errorType)}`,
|
|
337
374
|
isQuery: false,
|
|
338
375
|
hasArgs,
|
|
339
376
|
hasInfinite: false,
|
|
@@ -364,6 +401,7 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
|
|
|
364
401
|
...config.useThunk ? { useThunk: true } : {},
|
|
365
402
|
...config.isVueQuery ? { isVueQuery: true } : {},
|
|
366
403
|
...config.errorType ? { errorType: config.errorType } : {},
|
|
404
|
+
...config.hookTail ? { hookTail: config.hookTail } : {},
|
|
367
405
|
...config.unwrapOptionsAccessor ? { unwrapOptionsAccessor: true } : {}
|
|
368
406
|
}) : null;
|
|
369
407
|
const infiniteHookName = `${config.hookPrefix}Infinite${capitalize(pathFuncName)}`;
|
|
@@ -374,6 +412,7 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
|
|
|
374
412
|
...config.isVueQuery ? { isVueQuery: true } : {},
|
|
375
413
|
...config.hasInfiniteQueryOptionsHelper ? { hasInfiniteQueryOptionsHelper: true } : {},
|
|
376
414
|
...config.errorType ? { errorType: config.errorType } : {},
|
|
415
|
+
...config.hookTail ? { hookTail: config.hookTail } : {},
|
|
377
416
|
...config.unwrapOptionsAccessor ? { unwrapOptionsAccessor: true } : {}
|
|
378
417
|
}) : null;
|
|
379
418
|
const suspenseInfiniteHookName = `${config.hookPrefix}SuspenseInfinite${capitalize(pathFuncName)}`;
|
|
@@ -391,6 +430,7 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
|
|
|
391
430
|
useInfiniteQueryOptionsType: config.useSuspenseInfiniteQueryOptionsType,
|
|
392
431
|
...config.useThunk ? { useThunk: true } : {},
|
|
393
432
|
...config.isVueQuery ? { isVueQuery: true } : {},
|
|
433
|
+
...config.hookTail ? { hookTail: config.hookTail } : {},
|
|
394
434
|
...config.hasInfiniteQueryOptionsHelper ? { hasInfiniteQueryOptionsHelper: true } : {},
|
|
395
435
|
...config.errorType ? { errorType: config.errorType } : {},
|
|
396
436
|
...config.unwrapOptionsAccessor ? { unwrapOptionsAccessor: true } : {}
|
|
@@ -403,8 +443,9 @@ function makeHookCode(pathStr, method, item, deps, config, clientName) {
|
|
|
403
443
|
};
|
|
404
444
|
}
|
|
405
445
|
const optionsGetterName = `get${capitalize(methodPath(method, pathStr))}MutationOptions`;
|
|
446
|
+
const mutationKeyGetterName = makeMutationKeyGetterName(method, pathStr);
|
|
406
447
|
return {
|
|
407
|
-
code: `${makeMutationOptionsGetterCode(optionsGetterName, hasArgs, argsType, runtimeAccess,
|
|
448
|
+
code: `${makeMutationKeyGetterCode(mutationKeyGetterName, method, honoPath)}\n\n${makeMutationOptionsGetterCode(optionsGetterName, mutationKeyGetterName, hasArgs, argsType, runtimeAccess, responseType, hasNoContent, config)}\n\n${makeMutationHookCode(hookName, optionsGetterName, hasArgs, argsType, responseType, config, hasNoContent)}`,
|
|
408
449
|
isQuery: false,
|
|
409
450
|
hasArgs,
|
|
410
451
|
hasInfinite: false,
|
|
@@ -462,15 +503,17 @@ function makeHeader(importPath, clientName, hasQuery, hasMutation, hasAnyArgs, c
|
|
|
462
503
|
...hasQuery && config.useSuspenseQueryOptionsType ? [config.useSuspenseQueryOptionsType] : [],
|
|
463
504
|
...hasInfiniteQuery && config.useInfiniteQueryOptionsType ? [config.useInfiniteQueryOptionsType] : [],
|
|
464
505
|
...hasInfiniteQuery && config.useSuspenseInfiniteQueryOptionsType ? [config.useSuspenseInfiniteQueryOptionsType] : [],
|
|
465
|
-
...hasInfiniteQuery
|
|
466
|
-
...hasMutation ? [config.useMutationOptionsType] : []
|
|
506
|
+
...hasInfiniteQuery ? ["InfiniteData"] : [],
|
|
507
|
+
...hasMutation ? [config.useMutationOptionsType] : [],
|
|
508
|
+
...config.errorType ? [config.errorType] : [],
|
|
509
|
+
...config.hookTail?.imports ?? []
|
|
467
510
|
];
|
|
468
511
|
const needsVueImports = config.isVueQuery && hasQueryWithArgs;
|
|
469
512
|
const honoTypeImports = ["ClientRequestOptions", ...hasAnyArgs || hasInfiniteQuery ? ["InferRequestType"] : []];
|
|
470
513
|
return `${[
|
|
471
514
|
...queryImports.length > 0 ? [`import{${queryImports.join(",")}}from'${config.packageName}'`] : [],
|
|
472
|
-
...typeImports.length > 0 ? [`import type{${typeImports.join(",")}}from'${config.packageName}'`] : [],
|
|
473
|
-
...needsVueImports ? ["import{toValue}from'vue'", "import type{MaybeRefOrGetter}from'vue'"] : [],
|
|
515
|
+
...typeImports.length > 0 ? [`import type{${[...new Set(typeImports)].join(",")}}from'${config.packageName}'`] : [],
|
|
516
|
+
...needsVueImports ? ["import{computed,toValue}from'vue'", "import type{MaybeRefOrGetter}from'vue'"] : [],
|
|
474
517
|
`import type{${honoTypeImports.join(",")}}from'hono/client'`,
|
|
475
518
|
`import{parseResponse}from'hono/client'`,
|
|
476
519
|
`import{${clientName}}from'${importPath}'`
|
|
@@ -517,6 +560,21 @@ function makeQueryHooks(openAPI, output, importPath, config, split, clientName =
|
|
|
517
560
|
}
|
|
518
561
|
//#endregion
|
|
519
562
|
//#region src/core/hooks/index.ts
|
|
563
|
+
const DEFAULT_ERROR = "DefaultError";
|
|
564
|
+
const QUERY_CLIENT_TAIL = {
|
|
565
|
+
name: "queryClient",
|
|
566
|
+
query: "QueryClient",
|
|
567
|
+
infinite: "QueryClient",
|
|
568
|
+
mutation: "QueryClient",
|
|
569
|
+
imports: ["QueryClient"]
|
|
570
|
+
};
|
|
571
|
+
const QUERY_CLIENT_ACCESSOR_TAIL = {
|
|
572
|
+
name: "queryClient",
|
|
573
|
+
query: "()=>QueryClient",
|
|
574
|
+
infinite: "()=>QueryClient",
|
|
575
|
+
mutation: "()=>QueryClient",
|
|
576
|
+
imports: ["QueryClient"]
|
|
577
|
+
};
|
|
520
578
|
const HOOK_CONFIGS = {
|
|
521
579
|
swr: {
|
|
522
580
|
packageName: "swr",
|
|
@@ -532,6 +590,8 @@ const HOOK_CONFIGS = {
|
|
|
532
590
|
useInfiniteQueryOptionsType: "SWRInfiniteConfiguration"
|
|
533
591
|
},
|
|
534
592
|
"tanstack-query": {
|
|
593
|
+
errorType: DEFAULT_ERROR,
|
|
594
|
+
hookTail: QUERY_CLIENT_TAIL,
|
|
535
595
|
packageName: "@tanstack/react-query",
|
|
536
596
|
frameworkName: "TanStack Query",
|
|
537
597
|
hookPrefix: "use",
|
|
@@ -550,6 +610,8 @@ const HOOK_CONFIGS = {
|
|
|
550
610
|
useSuspenseQueryOptionsType: "UseSuspenseQueryOptions"
|
|
551
611
|
},
|
|
552
612
|
"preact-query": {
|
|
613
|
+
errorType: DEFAULT_ERROR,
|
|
614
|
+
hookTail: QUERY_CLIENT_TAIL,
|
|
553
615
|
packageName: "@tanstack/preact-query",
|
|
554
616
|
frameworkName: "Preact Query",
|
|
555
617
|
hookPrefix: "use",
|
|
@@ -568,6 +630,8 @@ const HOOK_CONFIGS = {
|
|
|
568
630
|
useSuspenseQueryOptionsType: "UseSuspenseQueryOptions"
|
|
569
631
|
},
|
|
570
632
|
"solid-query": {
|
|
633
|
+
errorType: DEFAULT_ERROR,
|
|
634
|
+
hookTail: QUERY_CLIENT_ACCESSOR_TAIL,
|
|
571
635
|
packageName: "@tanstack/solid-query",
|
|
572
636
|
frameworkName: "Solid Query",
|
|
573
637
|
hookPrefix: "create",
|
|
@@ -584,6 +648,8 @@ const HOOK_CONFIGS = {
|
|
|
584
648
|
unwrapOptionsAccessor: true
|
|
585
649
|
},
|
|
586
650
|
"vue-query": {
|
|
651
|
+
errorType: DEFAULT_ERROR,
|
|
652
|
+
hookTail: QUERY_CLIENT_TAIL,
|
|
587
653
|
packageName: "@tanstack/vue-query",
|
|
588
654
|
frameworkName: "Vue Query",
|
|
589
655
|
hookPrefix: "use",
|
|
@@ -597,6 +663,8 @@ const HOOK_CONFIGS = {
|
|
|
597
663
|
useInfiniteQueryOptionsType: "UseInfiniteQueryOptions"
|
|
598
664
|
},
|
|
599
665
|
"svelte-query": {
|
|
666
|
+
errorType: DEFAULT_ERROR,
|
|
667
|
+
hookTail: QUERY_CLIENT_ACCESSOR_TAIL,
|
|
600
668
|
packageName: "@tanstack/svelte-query",
|
|
601
669
|
frameworkName: "Svelte Query",
|
|
602
670
|
hookPrefix: "create",
|
|
@@ -606,11 +674,24 @@ const HOOK_CONFIGS = {
|
|
|
606
674
|
useQueryOptionsType: "CreateQueryOptions",
|
|
607
675
|
useMutationOptionsType: "CreateMutationOptions",
|
|
608
676
|
hasQueryOptionsHelper: true,
|
|
677
|
+
hasMutationOptionsHelper: true,
|
|
609
678
|
infiniteQueryFn: "createInfiniteQuery",
|
|
610
679
|
useInfiniteQueryOptionsType: "CreateInfiniteQueryOptions",
|
|
611
680
|
hasInfiniteQueryOptionsHelper: true
|
|
612
681
|
},
|
|
613
682
|
"angular-query": {
|
|
683
|
+
errorType: DEFAULT_ERROR,
|
|
684
|
+
hookTail: {
|
|
685
|
+
name: "injectOptions",
|
|
686
|
+
query: "InjectQueryOptions",
|
|
687
|
+
infinite: "InjectInfiniteQueryOptions",
|
|
688
|
+
mutation: "InjectMutationOptions",
|
|
689
|
+
imports: [
|
|
690
|
+
"InjectQueryOptions",
|
|
691
|
+
"InjectInfiniteQueryOptions",
|
|
692
|
+
"InjectMutationOptions"
|
|
693
|
+
]
|
|
694
|
+
},
|
|
614
695
|
packageName: "@tanstack/angular-query-experimental",
|
|
615
696
|
frameworkName: "Angular Query",
|
|
616
697
|
hookPrefix: "inject",
|
|
@@ -619,7 +700,7 @@ const HOOK_CONFIGS = {
|
|
|
619
700
|
useQueryOptionsType: "CreateQueryOptions",
|
|
620
701
|
useMutationOptionsType: "CreateMutationOptions",
|
|
621
702
|
hasQueryOptionsHelper: true,
|
|
622
|
-
hasMutationOptionsHelper:
|
|
703
|
+
hasMutationOptionsHelper: true,
|
|
623
704
|
hasInfiniteQueryOptionsHelper: true,
|
|
624
705
|
infiniteQueryFn: "injectInfiniteQuery",
|
|
625
706
|
useInfiniteQueryOptionsType: "CreateInfiniteQueryOptions",
|
|
@@ -12,30 +12,21 @@ import { getOpenAPI3 } from "@typespec/openapi3";
|
|
|
12
12
|
*
|
|
13
13
|
* @see https://apitools.dev/swagger-parser/docs/
|
|
14
14
|
*/
|
|
15
|
-
var openapi_exports = /* @__PURE__ */ __exportAll({
|
|
16
|
-
OpenAPIError: () => OpenAPIError,
|
|
17
|
-
parseOpenAPI: () => parseOpenAPI
|
|
18
|
-
});
|
|
19
|
-
/** The document could not be read, compiled or parsed into an OpenAPI object. */
|
|
15
|
+
var openapi_exports = /* @__PURE__ */ __exportAll({ parseOpenAPI: () => parseOpenAPI });
|
|
20
16
|
var OpenAPIError = class extends Data.TaggedError("OpenAPIError") {};
|
|
21
|
-
/** Parses `input` into an OpenAPI document. */
|
|
22
17
|
function parseOpenAPI(input) {
|
|
23
18
|
return Effect.tryPromise({
|
|
24
|
-
try: () =>
|
|
19
|
+
try: async () => {
|
|
20
|
+
if (!input.endsWith(".tsp")) return await SwaggerParser.bundle(input);
|
|
21
|
+
const program = await compile(NodeHost, path.resolve(input), { noEmit: true });
|
|
22
|
+
if (program.diagnostics.length > 0) throw new Error(`TypeSpec compile failed:\n${program.diagnostics.map((d) => d.message).join("\n")}`);
|
|
23
|
+
const [record] = await getOpenAPI3(program);
|
|
24
|
+
const document = record && ("document" in record ? record.document : record.versions[0]?.document);
|
|
25
|
+
if (!document) throw new Error(`TypeSpec emitted no OpenAPI document: ${input}`);
|
|
26
|
+
return document;
|
|
27
|
+
},
|
|
25
28
|
catch: (error) => new OpenAPIError({ message: error instanceof Error ? error.message : String(error) })
|
|
26
29
|
});
|
|
27
30
|
}
|
|
28
|
-
async function readOpenAPI(input) {
|
|
29
|
-
if (typeof input === "string" && input.endsWith(".tsp")) {
|
|
30
|
-
const program = await compile(NodeHost, path.resolve(input), { noEmit: true });
|
|
31
|
-
if (program.diagnostics.length > 0) {
|
|
32
|
-
const errors = program.diagnostics.map((d) => d.message).join("\n");
|
|
33
|
-
throw new Error(`TypeSpec compile failed:\n${errors}`);
|
|
34
|
-
}
|
|
35
|
-
const [record] = await getOpenAPI3(program);
|
|
36
|
-
return "document" in record ? record.document : record.versions[0].document;
|
|
37
|
-
}
|
|
38
|
-
return await SwaggerParser.bundle(input);
|
|
39
|
-
}
|
|
40
31
|
//#endregion
|
|
41
32
|
export { parseOpenAPI as n, openapi_exports as t };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
2
|
import { a as unlink, i as readdir } from "./file-CwKqigE9.js";
|
|
3
3
|
import { s as GenerateError } from "./rpc-D_eeOVGa.js";
|
|
4
|
-
import { _ as links, a as defineTemplate, b as callbacks, c as mock, d as responses, f as requestBodies, g as mediaTypes, h as components, i as template, l as securitySchemes, m as parameters, n as webhooks, o as takibi, p as pathItems, r as test, s as route, u as schemas, v as headers, y as examples } from "./core-
|
|
5
|
-
import { t as hooks } from "./hooks-
|
|
4
|
+
import { _ as links, a as defineTemplate, b as callbacks, c as mock, d as responses, f as requestBodies, g as mediaTypes, h as components, i as template, l as securitySchemes, m as parameters, n as webhooks, o as takibi, p as pathItems, r as test, s as route, u as schemas, v as headers, y as examples } from "./core-BtueRJN7.js";
|
|
5
|
+
import { t as hooks } from "./hooks-CZkcozjK.js";
|
|
6
6
|
import { t as docs } from "./docs-C1_fNNJ-.js";
|
|
7
7
|
import { rpc } from "./core/rpc/index.js";
|
|
8
8
|
import { type } from "./core/type/index.js";
|
|
@@ -2,8 +2,8 @@ import { parseConfig } from "../index.js";
|
|
|
2
2
|
import { t as fileSystemLayer } from "../file-CwKqigE9.js";
|
|
3
3
|
import { t as FormatOptions } from "../format-Bm9LZ_ki.js";
|
|
4
4
|
import { z as isRecord } from "../utils-DEFpxBMu.js";
|
|
5
|
-
import { n as parseOpenAPI } from "../openapi-
|
|
6
|
-
import { n as cleanSplitOutputs, r as makeJob, t as appEntryOutput } from "../shared-
|
|
5
|
+
import { n as parseOpenAPI } from "../openapi-DQRxq2_O.js";
|
|
6
|
+
import { n as cleanSplitOutputs, r as makeJob, t as appEntryOutput } from "../shared-BgsMAfDf.js";
|
|
7
7
|
import { Effect, FileSystem, Option, Result } from "effect";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import crypto from "node:crypto";
|