@uiwwsw/react-query-helper 1.2.6 → 1.3.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/README.md +96 -7
- package/dist/cli.js +53 -3
- package/dist/core/analyzer.js +69 -0
- package/dist/core/generator.d.ts +2 -0
- package/dist/core/generator.d.ts.map +1 -1
- package/dist/core/generator.js +109 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +100 -29
- package/dist/utils/query.d.ts +56 -4
- package/dist/utils/query.d.ts.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -52,8 +52,10 @@
|
|
|
52
52
|
- **런타임/개발 분리**: generate/watch/config 로딩은 개발 시점 전용이고, 생성된 결과가 참조하는 런타임 helper 엔트리에는 `fs` 같은 Node 전용 코드가 포함되지 않도록 분리되어 있습니다.
|
|
53
53
|
- **Watch & Generate 모드**: 개발 중 실시간 감시(`--watch`), 초기 세팅이나 재생성 시 일괄 생성(`--generate`)을 모두 지원합니다.
|
|
54
54
|
- **일관된 옵션 관리**: `queryOption`, `mutationOption`, `infiniteOption` 유틸리티로 전역 캐싱 전략과 에러 핸들링을 통일할 수 있습니다.
|
|
55
|
+
- **런타임 override 지원**: 생성된 옵션 팩토리의 `.withOptions(...)`로 헤더, queryKey, pageParam 매핑, mutation 변수 변환 등을 호출부에서 안전하게 조정할 수 있습니다.
|
|
55
56
|
- **Prettier 통합**: 생성된 파일은 자동으로 포맷팅되어 코드 리뷰 시 불필요한 변경을 줄입니다.
|
|
56
57
|
- **헬퍼 import 경로 커스터마이징**: `templateDir`로 생성 코드가 참조할 헬퍼 모듈 경로를 바꿀 수 있습니다.
|
|
58
|
+
- **스마트 아티팩트 추론**: 기본값으로 함수 이름을 보고 query / mutation / infinite 생성을 구분해 `createUserQueryOption` 같은 어색한 결과를 줄입니다.
|
|
57
59
|
- **보수적인 infinite 기본값**: `infiniteOption`은 안전한 기본 옵션만 제공하고, 실제 `pageParam` 처리 규칙은 호출부에서 override 하도록 설계되어 있습니다.
|
|
58
60
|
|
|
59
61
|
## 빠른 시작
|
|
@@ -104,6 +106,7 @@ const config: AutoQueryConfig = {
|
|
|
104
106
|
},
|
|
105
107
|
template: {
|
|
106
108
|
enabledArtifacts: ["query", "mutation", "infinite"],
|
|
109
|
+
artifactStrategy: "smart",
|
|
107
110
|
keyStyle: "path",
|
|
108
111
|
},
|
|
109
112
|
};
|
|
@@ -154,6 +157,16 @@ npm exec react-query-helper -- --generate
|
|
|
154
157
|
| `analyzer` | ❌ | 어떤 함수를 읽을지 필터링하는 설정 (`exported-only`, `async-only`, include/exclude 등) |
|
|
155
158
|
| `template` | ❌ | 어떤 아티팩트를 생성할지와 이름 규칙을 제어하는 설정 |
|
|
156
159
|
|
|
160
|
+
### 스마트 생성 규칙
|
|
161
|
+
|
|
162
|
+
기본 `artifactStrategy: "smart"`는 함수 이름을 보고 생성 대상을 추론합니다.
|
|
163
|
+
|
|
164
|
+
- `getUsers`, `fetchPost`, `listComments` → `query` + `infinite`
|
|
165
|
+
- `createUser`, `updateProfile`, `deleteComment` → `mutation`
|
|
166
|
+
- 그 외 애매한 이름 → `query` + `mutation` (`infinite` 제외)
|
|
167
|
+
|
|
168
|
+
원한다면 `artifactStrategy: "all"`로 예전처럼 모든 아티팩트를 강제로 생성할 수 있습니다.
|
|
169
|
+
|
|
157
170
|
## Infinite Query 기본값
|
|
158
171
|
|
|
159
172
|
`infiniteOption`은 API마다 페이지네이션 규칙이 다르기 때문에, 기본 구현에서는 `pageParam`을 자동 병합하지 않습니다.
|
|
@@ -169,6 +182,70 @@ const usersInfinite = {
|
|
|
169
182
|
};
|
|
170
183
|
```
|
|
171
184
|
|
|
185
|
+
더 복잡한 케이스에서는 `.withOptions(...)`를 쓰면 헤더나 `pageParam` 매핑도 한 곳에서 처리할 수 있습니다.
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
const usersInfinite = getUsersInfiniteQueryOption.withOptions(
|
|
189
|
+
{
|
|
190
|
+
initialPageParam: 1,
|
|
191
|
+
pageParamToArgs: (pageParam, [params]) => [{
|
|
192
|
+
...params,
|
|
193
|
+
page: pageParam,
|
|
194
|
+
headers: {
|
|
195
|
+
...params.headers,
|
|
196
|
+
Authorization: `Bearer ${token}`,
|
|
197
|
+
},
|
|
198
|
+
}],
|
|
199
|
+
getNextPageParam: (lastPage) => lastPage.nextPage,
|
|
200
|
+
},
|
|
201
|
+
{ page: 1, headers: {} }
|
|
202
|
+
);
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Mutation도 호출 방식에 따라 자연스럽게 맞춰집니다.
|
|
206
|
+
|
|
207
|
+
- API 함수가 인자 1개면 기존처럼 `mutate(body)` / `mutateAsync(body)`
|
|
208
|
+
- API 함수가 인자 여러 개면 생성 코드가 object payload 타입을 만들어 `mutate({ body, headers })` / `mutateAsync({ body, headers })`
|
|
209
|
+
|
|
210
|
+
간단한 커스텀 매핑이 필요하면 `withOptions(...)`로도 연결할 수 있습니다.
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
const updateUserMutation = updateUserMutationOption.withOptions({
|
|
214
|
+
mapVariablesToArgs: ({ id, body }) => [
|
|
215
|
+
id,
|
|
216
|
+
body,
|
|
217
|
+
{ Authorization: `Bearer ${token}` },
|
|
218
|
+
],
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
API 함수가 여러 인자를 받으면, 생성 코드가 `mutate` / `mutateAsync`에서 바로 쓰기 좋은 object payload 타입도 함께 만들어 줍니다.
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
export type createUserMutationVariables = {
|
|
226
|
+
body: Parameters<typeof createUser>[0];
|
|
227
|
+
headers: Parameters<typeof createUser>[1];
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export const createUserMutationOption = mutationOption<
|
|
231
|
+
Parameters<typeof createUser>,
|
|
232
|
+
Awaited<ReturnType<typeof createUser>>,
|
|
233
|
+
createUserMutationVariables
|
|
234
|
+
>(createUserKey, createUser, {
|
|
235
|
+
mapVariablesToArgs: (variables) => [variables.body, variables.headers],
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
mutate({
|
|
239
|
+
body: { name: "matthew" },
|
|
240
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
await mutateAsync({
|
|
244
|
+
body: { name: "matthew" },
|
|
245
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
172
249
|
## 배포 방식
|
|
173
250
|
|
|
174
251
|
GitHub Actions의 npm 배포는 이제 `main` 푸시가 아니라 `v*` 태그 푸시 또는 수동 실행에서만 동작합니다.
|
|
@@ -188,8 +265,11 @@ export const getUser = async (id: string) => {
|
|
|
188
265
|
return { id, name: `User ${id}` };
|
|
189
266
|
};
|
|
190
267
|
|
|
191
|
-
export const createUser = async (
|
|
192
|
-
|
|
268
|
+
export const createUser = async (
|
|
269
|
+
body: { name: string },
|
|
270
|
+
headers?: Record<string, string>
|
|
271
|
+
) => {
|
|
272
|
+
return { id: Date.now().toString(), name: body.name, headers };
|
|
193
273
|
};
|
|
194
274
|
```
|
|
195
275
|
|
|
@@ -204,15 +284,24 @@ import {
|
|
|
204
284
|
|
|
205
285
|
export const getUserKey = ["users", "getUser"] as const;
|
|
206
286
|
export const getUserQueryOption = queryOption(getUserKey, getUser);
|
|
207
|
-
export const getUserMutationOption = mutationOption(getUserKey, getUser);
|
|
208
287
|
export const getUserInfiniteQueryOption = infiniteOption(getUserKey, getUser);
|
|
209
288
|
|
|
210
289
|
export const createUserKey = ["users", "createUser"] as const;
|
|
211
|
-
export
|
|
212
|
-
|
|
213
|
-
|
|
290
|
+
export type createUserMutationVariables = {
|
|
291
|
+
body: Parameters<typeof createUser>[0];
|
|
292
|
+
headers: Parameters<typeof createUser>[1];
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export const createUserMutationOption = mutationOption<
|
|
296
|
+
Parameters<typeof createUser>,
|
|
297
|
+
Awaited<ReturnType<typeof createUser>>,
|
|
298
|
+
createUserMutationVariables
|
|
299
|
+
>(
|
|
214
300
|
createUserKey,
|
|
215
|
-
createUser
|
|
301
|
+
createUser,
|
|
302
|
+
{
|
|
303
|
+
mapVariablesToArgs: (variables) => [variables.body, variables.headers],
|
|
304
|
+
}
|
|
216
305
|
);
|
|
217
306
|
```
|
|
218
307
|
|
package/dist/cli.js
CHANGED
|
@@ -1660,6 +1660,45 @@ var DEFAULT_OUTPUT_NAMES = {
|
|
|
1660
1660
|
mutation: "MutationOption",
|
|
1661
1661
|
infinite: "InfiniteQueryOption"
|
|
1662
1662
|
};
|
|
1663
|
+
var MUTATION_NAME_PATTERN = /^(create|post|add|update|put|patch|delete|remove|set|send|upload|signIn|signOut|login|logout|mutate)/i;
|
|
1664
|
+
var QUERY_NAME_PATTERN = /^(get|list|fetch|find|read|load|search|retrieve|detail|details)/i;
|
|
1665
|
+
function isSimpleParameterName(name) {
|
|
1666
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
|
|
1667
|
+
}
|
|
1668
|
+
function getMutationVariablesTypeName(functionName) {
|
|
1669
|
+
return `${functionName}MutationVariables`;
|
|
1670
|
+
}
|
|
1671
|
+
function buildMutationVariablesType(info) {
|
|
1672
|
+
if (info.parameters.length <= 1 || !info.parameters.every(isSimpleParameterName)) {
|
|
1673
|
+
return null;
|
|
1674
|
+
}
|
|
1675
|
+
const lines = info.parameters.map((parameterName, index) => ` ${parameterName}: Parameters<typeof ${info.name}>[${index}];`);
|
|
1676
|
+
return `export type ${getMutationVariablesTypeName(info.name)} = {
|
|
1677
|
+
${lines.join(`
|
|
1678
|
+
`)}
|
|
1679
|
+
};
|
|
1680
|
+
`;
|
|
1681
|
+
}
|
|
1682
|
+
function buildMutationOptionExpression(info, importName, keyName) {
|
|
1683
|
+
if (info.parameters.length <= 1 || !info.parameters.every(isSimpleParameterName)) {
|
|
1684
|
+
return `${importName}(${keyName}, ${info.name})`;
|
|
1685
|
+
}
|
|
1686
|
+
const variablesTypeName = getMutationVariablesTypeName(info.name);
|
|
1687
|
+
const argumentMapping = info.parameters.map((parameterName) => `variables.${parameterName}`).join(", ");
|
|
1688
|
+
return `${importName}<Parameters<typeof ${info.name}>, Awaited<ReturnType<typeof ${info.name}>>, ${variablesTypeName}>(${keyName}, ${info.name}, { mapVariablesToArgs: (variables) => [${argumentMapping}] })`;
|
|
1689
|
+
}
|
|
1690
|
+
function resolveArtifacts(info, enabledArtifacts, strategy) {
|
|
1691
|
+
if (strategy === "all") {
|
|
1692
|
+
return enabledArtifacts;
|
|
1693
|
+
}
|
|
1694
|
+
if (MUTATION_NAME_PATTERN.test(info.name)) {
|
|
1695
|
+
return enabledArtifacts.filter((artifact) => artifact === "mutation");
|
|
1696
|
+
}
|
|
1697
|
+
if (QUERY_NAME_PATTERN.test(info.name)) {
|
|
1698
|
+
return enabledArtifacts.filter((artifact) => artifact === "query" || artifact === "infinite");
|
|
1699
|
+
}
|
|
1700
|
+
return enabledArtifacts.filter((artifact) => artifact !== "infinite");
|
|
1701
|
+
}
|
|
1663
1702
|
function getKeySegments(info, fileName, keySegments, keyStyle) {
|
|
1664
1703
|
switch (keyStyle) {
|
|
1665
1704
|
case "function-only":
|
|
@@ -1684,7 +1723,8 @@ function generateOptionsCode(functionInfos, importPath, { keySegments, fileName,
|
|
|
1684
1723
|
...DEFAULT_OUTPUT_NAMES,
|
|
1685
1724
|
...template?.outputNames
|
|
1686
1725
|
};
|
|
1687
|
-
const
|
|
1726
|
+
const artifactStrategy = template?.artifactStrategy ?? "smart";
|
|
1727
|
+
const helperImports = [...new Set(enabledArtifacts.map((artifact) => importNames[artifact]))];
|
|
1688
1728
|
const functionNames = functionInfos.map((info) => info.name);
|
|
1689
1729
|
const keyStyle = template?.keyStyle ?? "path";
|
|
1690
1730
|
let newContent = `import { ${functionNames.join(", ")} } from "${importPath}";
|
|
@@ -1693,12 +1733,21 @@ function generateOptionsCode(functionInfos, importPath, { keySegments, fileName,
|
|
|
1693
1733
|
|
|
1694
1734
|
`;
|
|
1695
1735
|
functionInfos.forEach((info) => {
|
|
1736
|
+
const resolvedArtifacts = resolveArtifacts(info, enabledArtifacts, artifactStrategy);
|
|
1737
|
+
if (resolvedArtifacts.length === 0) {
|
|
1738
|
+
return;
|
|
1739
|
+
}
|
|
1696
1740
|
const keyArray = JSON.stringify(getKeySegments(info, fileName, keySegments, keyStyle));
|
|
1697
1741
|
const keyName = `${info.name}Key`;
|
|
1742
|
+
const mutationVariablesType = buildMutationVariablesType(info);
|
|
1743
|
+
if (mutationVariablesType && resolvedArtifacts.includes("mutation")) {
|
|
1744
|
+
newContent += mutationVariablesType;
|
|
1745
|
+
}
|
|
1698
1746
|
newContent += `export const ${keyName} = ${keyArray} as const;
|
|
1699
1747
|
`;
|
|
1700
|
-
|
|
1701
|
-
|
|
1748
|
+
resolvedArtifacts.forEach((artifact) => {
|
|
1749
|
+
const optionExpression = artifact === "mutation" ? buildMutationOptionExpression(info, importNames[artifact], keyName) : `${importNames[artifact]}(${keyName}, ${info.name})`;
|
|
1750
|
+
newContent += `export const ${info.name}${outputNames[artifact]} = ${optionExpression};
|
|
1702
1751
|
`;
|
|
1703
1752
|
});
|
|
1704
1753
|
newContent += `
|
|
@@ -1830,6 +1879,7 @@ const config: AutoQueryConfig = {
|
|
|
1830
1879
|
},
|
|
1831
1880
|
template: {
|
|
1832
1881
|
enabledArtifacts: ["query", "mutation", "infinite"],
|
|
1882
|
+
artifactStrategy: "smart",
|
|
1833
1883
|
keyStyle: "path",
|
|
1834
1884
|
importNames: {
|
|
1835
1885
|
query: "queryOption",
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/core/analyzer.ts
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { readFileSync } from "fs";
|
|
4
|
+
function shouldIncludeFunction(info, config = {}) {
|
|
5
|
+
const exportFilter = config.exportFilter ?? "exported-only";
|
|
6
|
+
const functionMatchMode = config.functionMatchMode ?? "all";
|
|
7
|
+
if (exportFilter === "exported-only" && !info.isExported) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (functionMatchMode === "async-only" && !info.isAsync) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (functionMatchMode === "sync-only" && info.isAsync) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (config.includeNames?.length && !config.includeNames.includes(info.name)) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (config.excludeNames?.includes(info.name)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
function unwrapFunctionLike(node) {
|
|
25
|
+
if (!node) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
29
|
+
return node;
|
|
30
|
+
}
|
|
31
|
+
if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isTypeAssertionExpression(node) || ts.isSatisfiesExpression(node) || ts.isNonNullExpression(node)) {
|
|
32
|
+
return unwrapFunctionLike(node.expression);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
function getFunctionInfo(name, parameters, isAsync, isExported, sourceFile) {
|
|
37
|
+
return {
|
|
38
|
+
name,
|
|
39
|
+
parameters: parameters.map((param) => param.name.getText(sourceFile)),
|
|
40
|
+
isAsync,
|
|
41
|
+
isExported
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function analyzeFile(filePath, config = {}) {
|
|
45
|
+
const sourceCode = readFileSync(filePath, "utf8");
|
|
46
|
+
const scriptKind = filePath.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
|
|
47
|
+
const sourceFile = ts.createSourceFile(filePath, sourceCode, ts.ScriptTarget.Latest, true, scriptKind);
|
|
48
|
+
const functionInfos = [];
|
|
49
|
+
const hasExportModifier = (node) => ts.canHaveModifiers(node) && !!ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
|
|
50
|
+
ts.forEachChild(sourceFile, (node) => {
|
|
51
|
+
if (ts.isVariableStatement(node)) {
|
|
52
|
+
const isExported = hasExportModifier(node);
|
|
53
|
+
node.declarationList.declarations.forEach((declaration) => {
|
|
54
|
+
if (ts.isVariableDeclaration(declaration) && ts.isIdentifier(declaration.name)) {
|
|
55
|
+
const initializer = unwrapFunctionLike(declaration.initializer);
|
|
56
|
+
if (initializer) {
|
|
57
|
+
functionInfos.push(getFunctionInfo(declaration.name.text, initializer.parameters, !!initializer.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword), isExported, sourceFile));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
} else if (ts.isFunctionDeclaration(node) && node.name) {
|
|
62
|
+
functionInfos.push(getFunctionInfo(node.name.text, node.parameters, !!node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword), hasExportModifier(node), sourceFile));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return functionInfos.filter((info) => shouldIncludeFunction(info, config));
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
analyzeFile
|
|
69
|
+
};
|
package/dist/core/generator.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { FunctionInfo } from "./analyzer";
|
|
2
2
|
export type GeneratedArtifact = "query" | "mutation" | "infinite";
|
|
3
3
|
export type KeyStyle = "path" | "file-only" | "function-only";
|
|
4
|
+
export type ArtifactStrategy = "all" | "smart";
|
|
4
5
|
export interface TemplateConfig {
|
|
5
6
|
importNames?: Partial<Record<GeneratedArtifact, string>>;
|
|
6
7
|
outputNames?: Partial<Record<GeneratedArtifact, string>>;
|
|
7
8
|
enabledArtifacts?: GeneratedArtifact[];
|
|
8
9
|
keyStyle?: KeyStyle;
|
|
10
|
+
artifactStrategy?: ArtifactStrategy;
|
|
9
11
|
}
|
|
10
12
|
interface GenerateOptionsParams {
|
|
11
13
|
keySegments: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/core/generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;AAClE,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/core/generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;AAClE,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,eAAe,CAAC;AAC9D,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,OAAO,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAC;IACzD,WAAW,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAC;IACzD,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACvC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC;AAED,UAAU,qBAAqB;IAC7B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAmGD,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,YAAY,EAAE,EAC7B,UAAU,EAAE,MAAM,EAClB,EAAE,WAAW,EAAE,QAAQ,EAAE,kBAAkB,EAAE,QAAQ,EAAE,EAAE,qBAAqB,GAC7E,MAAM,CAgER"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// src/core/generator.ts
|
|
2
|
+
var DEFAULT_IMPORT_NAMES = {
|
|
3
|
+
query: "queryOption",
|
|
4
|
+
mutation: "mutationOption",
|
|
5
|
+
infinite: "infiniteOption"
|
|
6
|
+
};
|
|
7
|
+
var DEFAULT_OUTPUT_NAMES = {
|
|
8
|
+
query: "QueryOption",
|
|
9
|
+
mutation: "MutationOption",
|
|
10
|
+
infinite: "InfiniteQueryOption"
|
|
11
|
+
};
|
|
12
|
+
var MUTATION_NAME_PATTERN = /^(create|post|add|update|put|patch|delete|remove|set|send|upload|signIn|signOut|login|logout|mutate)/i;
|
|
13
|
+
var QUERY_NAME_PATTERN = /^(get|list|fetch|find|read|load|search|retrieve|detail|details)/i;
|
|
14
|
+
function isSimpleParameterName(name) {
|
|
15
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
|
|
16
|
+
}
|
|
17
|
+
function getMutationVariablesTypeName(functionName) {
|
|
18
|
+
return `${functionName}MutationVariables`;
|
|
19
|
+
}
|
|
20
|
+
function buildMutationVariablesType(info) {
|
|
21
|
+
if (info.parameters.length <= 1 || !info.parameters.every(isSimpleParameterName)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const lines = info.parameters.map((parameterName, index) => ` ${parameterName}: Parameters<typeof ${info.name}>[${index}];`);
|
|
25
|
+
return `export type ${getMutationVariablesTypeName(info.name)} = {
|
|
26
|
+
${lines.join(`
|
|
27
|
+
`)}
|
|
28
|
+
};
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
31
|
+
function buildMutationOptionExpression(info, importName, keyName) {
|
|
32
|
+
if (info.parameters.length <= 1 || !info.parameters.every(isSimpleParameterName)) {
|
|
33
|
+
return `${importName}(${keyName}, ${info.name})`;
|
|
34
|
+
}
|
|
35
|
+
const variablesTypeName = getMutationVariablesTypeName(info.name);
|
|
36
|
+
const argumentMapping = info.parameters.map((parameterName) => `variables.${parameterName}`).join(", ");
|
|
37
|
+
return `${importName}<Parameters<typeof ${info.name}>, Awaited<ReturnType<typeof ${info.name}>>, ${variablesTypeName}>(${keyName}, ${info.name}, { mapVariablesToArgs: (variables) => [${argumentMapping}] })`;
|
|
38
|
+
}
|
|
39
|
+
function resolveArtifacts(info, enabledArtifacts, strategy) {
|
|
40
|
+
if (strategy === "all") {
|
|
41
|
+
return enabledArtifacts;
|
|
42
|
+
}
|
|
43
|
+
if (MUTATION_NAME_PATTERN.test(info.name)) {
|
|
44
|
+
return enabledArtifacts.filter((artifact) => artifact === "mutation");
|
|
45
|
+
}
|
|
46
|
+
if (QUERY_NAME_PATTERN.test(info.name)) {
|
|
47
|
+
return enabledArtifacts.filter((artifact) => artifact === "query" || artifact === "infinite");
|
|
48
|
+
}
|
|
49
|
+
return enabledArtifacts.filter((artifact) => artifact !== "infinite");
|
|
50
|
+
}
|
|
51
|
+
function getKeySegments(info, fileName, keySegments, keyStyle) {
|
|
52
|
+
switch (keyStyle) {
|
|
53
|
+
case "function-only":
|
|
54
|
+
return [info.name];
|
|
55
|
+
case "file-only":
|
|
56
|
+
return [fileName, info.name];
|
|
57
|
+
case "path":
|
|
58
|
+
default:
|
|
59
|
+
return [...keySegments, info.name];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function generateOptionsCode(functionInfos, importPath, { keySegments, fileName, templateImportPath, template }) {
|
|
63
|
+
if (functionInfos.length === 0) {
|
|
64
|
+
return "";
|
|
65
|
+
}
|
|
66
|
+
const enabledArtifacts = template?.enabledArtifacts?.length ? template.enabledArtifacts : ["query", "mutation", "infinite"];
|
|
67
|
+
const importNames = {
|
|
68
|
+
...DEFAULT_IMPORT_NAMES,
|
|
69
|
+
...template?.importNames
|
|
70
|
+
};
|
|
71
|
+
const outputNames = {
|
|
72
|
+
...DEFAULT_OUTPUT_NAMES,
|
|
73
|
+
...template?.outputNames
|
|
74
|
+
};
|
|
75
|
+
const artifactStrategy = template?.artifactStrategy ?? "smart";
|
|
76
|
+
const helperImports = [...new Set(enabledArtifacts.map((artifact) => importNames[artifact]))];
|
|
77
|
+
const functionNames = functionInfos.map((info) => info.name);
|
|
78
|
+
const keyStyle = template?.keyStyle ?? "path";
|
|
79
|
+
let newContent = `import { ${functionNames.join(", ")} } from "${importPath}";
|
|
80
|
+
`;
|
|
81
|
+
newContent += `import { ${helperImports.join(", ")} } from "${templateImportPath}";
|
|
82
|
+
|
|
83
|
+
`;
|
|
84
|
+
functionInfos.forEach((info) => {
|
|
85
|
+
const resolvedArtifacts = resolveArtifacts(info, enabledArtifacts, artifactStrategy);
|
|
86
|
+
if (resolvedArtifacts.length === 0) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const keyArray = JSON.stringify(getKeySegments(info, fileName, keySegments, keyStyle));
|
|
90
|
+
const keyName = `${info.name}Key`;
|
|
91
|
+
const mutationVariablesType = buildMutationVariablesType(info);
|
|
92
|
+
if (mutationVariablesType && resolvedArtifacts.includes("mutation")) {
|
|
93
|
+
newContent += mutationVariablesType;
|
|
94
|
+
}
|
|
95
|
+
newContent += `export const ${keyName} = ${keyArray} as const;
|
|
96
|
+
`;
|
|
97
|
+
resolvedArtifacts.forEach((artifact) => {
|
|
98
|
+
const optionExpression = artifact === "mutation" ? buildMutationOptionExpression(info, importNames[artifact], keyName) : `${importNames[artifact]}(${keyName}, ${info.name})`;
|
|
99
|
+
newContent += `export const ${info.name}${outputNames[artifact]} = ${optionExpression};
|
|
100
|
+
`;
|
|
101
|
+
});
|
|
102
|
+
newContent += `
|
|
103
|
+
`;
|
|
104
|
+
});
|
|
105
|
+
return newContent;
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
generateOptionsCode
|
|
109
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,108 @@
|
|
|
1
1
|
// src/utils/query.ts
|
|
2
|
+
function resolveArgs(payload, overrides) {
|
|
3
|
+
const baseArgs = overrides?.args ?? payload;
|
|
4
|
+
return overrides?.mapArgs ? overrides.mapArgs(baseArgs) : baseArgs;
|
|
5
|
+
}
|
|
6
|
+
function resolveKey(baseKey, appendKey, overrideKey) {
|
|
7
|
+
if (overrideKey) {
|
|
8
|
+
return [...overrideKey];
|
|
9
|
+
}
|
|
10
|
+
return [...baseKey, ...appendKey ?? []];
|
|
11
|
+
}
|
|
12
|
+
function toArgs(variables) {
|
|
13
|
+
if (Array.isArray(variables)) {
|
|
14
|
+
return variables;
|
|
15
|
+
}
|
|
16
|
+
if (typeof variables === "undefined") {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
return [variables];
|
|
20
|
+
}
|
|
2
21
|
var queryOption = (key, fn) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
22
|
+
const buildOptions = (payload, overrides) => {
|
|
23
|
+
const args = resolveArgs(payload, overrides);
|
|
24
|
+
const queryKey = resolveKey([...key, ...args], overrides?.appendQueryKey, overrides?.queryKey);
|
|
25
|
+
const { appendQueryKey: _appendQueryKey, args: _args, mapArgs: _mapArgs, queryFn: overrideQueryFn, queryKey: _queryKey, ...restOverrides } = overrides ?? {};
|
|
26
|
+
return {
|
|
27
|
+
queryKey,
|
|
28
|
+
queryFn: (context) => {
|
|
29
|
+
if (overrideQueryFn) {
|
|
30
|
+
return Promise.resolve(overrideQueryFn({
|
|
31
|
+
queryKey: context.queryKey,
|
|
32
|
+
signal: context.signal,
|
|
33
|
+
meta: context.meta,
|
|
34
|
+
args
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return Promise.resolve(fn(...args));
|
|
38
|
+
},
|
|
39
|
+
gcTime: Infinity,
|
|
40
|
+
refetchOnWindowFocus: false,
|
|
41
|
+
...restOverrides
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const factory = (...payload) => buildOptions(payload);
|
|
45
|
+
factory.withOptions = (overrides, ...payload) => buildOptions(payload, overrides);
|
|
46
|
+
return factory;
|
|
9
47
|
};
|
|
10
|
-
var mutationOption = (key, fn) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
48
|
+
var mutationOption = (key, fn, config) => {
|
|
49
|
+
const buildOptions = (overrides) => {
|
|
50
|
+
const {
|
|
51
|
+
appendMutationKey: _appendMutationKey,
|
|
52
|
+
mutationKey: overrideMutationKey,
|
|
53
|
+
mapVariablesToArgs,
|
|
54
|
+
mutationFn: overrideMutationFn,
|
|
55
|
+
...restOverrides
|
|
56
|
+
} = overrides ?? {};
|
|
57
|
+
return {
|
|
58
|
+
mutationKey: resolveKey(key, _appendMutationKey, overrideMutationKey),
|
|
59
|
+
mutationFn: (variables) => {
|
|
60
|
+
const args = mapVariablesToArgs ? mapVariablesToArgs(variables) : config?.mapVariablesToArgs ? config.mapVariablesToArgs(variables) : toArgs(variables);
|
|
61
|
+
if (overrideMutationFn) {
|
|
62
|
+
return Promise.resolve(overrideMutationFn({ variables, args }));
|
|
63
|
+
}
|
|
64
|
+
return Promise.resolve(fn(...args));
|
|
65
|
+
},
|
|
66
|
+
...restOverrides
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
const factory = () => buildOptions();
|
|
70
|
+
factory.withOptions = (overrides) => buildOptions(overrides);
|
|
71
|
+
return factory;
|
|
23
72
|
};
|
|
24
73
|
var infiniteOption = (key, fn) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
74
|
+
const buildOptions = (payload, overrides) => {
|
|
75
|
+
const args = resolveArgs(payload, overrides);
|
|
76
|
+
const queryKey = resolveKey([...key, ...args], overrides?.appendQueryKey, overrides?.queryKey);
|
|
77
|
+
const { appendQueryKey: _appendQueryKey, args: _args, mapArgs: _mapArgs, pageParamToArgs, queryFn: overrideQueryFn, queryKey: _queryKey, ...restOverrides } = overrides ?? {};
|
|
78
|
+
return {
|
|
79
|
+
queryKey,
|
|
80
|
+
queryFn: (context) => {
|
|
81
|
+
if (overrideQueryFn) {
|
|
82
|
+
return Promise.resolve(overrideQueryFn({
|
|
83
|
+
queryKey: context.queryKey,
|
|
84
|
+
signal: context.signal,
|
|
85
|
+
meta: context.meta,
|
|
86
|
+
pageParam: context.pageParam,
|
|
87
|
+
direction: context.direction,
|
|
88
|
+
args
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
const resolvedArgs = pageParamToArgs ? pageParamToArgs(context.pageParam, args) : args;
|
|
92
|
+
return Promise.resolve(fn(...resolvedArgs));
|
|
93
|
+
},
|
|
94
|
+
getNextPageParam: () => {
|
|
95
|
+
return;
|
|
96
|
+
},
|
|
97
|
+
initialPageParam: undefined,
|
|
98
|
+
staleTime: Infinity,
|
|
99
|
+
refetchOnWindowFocus: false,
|
|
100
|
+
...restOverrides
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
const factory = (...payload) => buildOptions(payload);
|
|
104
|
+
factory.withOptions = (overrides, ...payload) => buildOptions(payload, overrides);
|
|
105
|
+
return factory;
|
|
35
106
|
};
|
|
36
107
|
export {
|
|
37
108
|
queryOption,
|
package/dist/utils/query.d.ts
CHANGED
|
@@ -1,10 +1,62 @@
|
|
|
1
|
-
import type { UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
1
|
+
import type { QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
2
2
|
type MaybePromise<T> = T | Promise<T>;
|
|
3
3
|
type AnyFn<TArgs extends unknown[] = unknown[], TResult = unknown> = (...payload: TArgs) => MaybePromise<TResult>;
|
|
4
4
|
type MutationVariables<TArgs extends unknown[]> = TArgs extends [] ? void : TArgs extends [infer Only] ? Only : TArgs;
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
|
|
5
|
+
type BaseQueryKey = readonly unknown[];
|
|
6
|
+
type QueryOptionOverrides<TArgs extends unknown[], TResult> = Omit<UseQueryOptions<TResult, unknown, TResult, BaseQueryKey>, "queryKey" | "queryFn"> & {
|
|
7
|
+
queryKey?: QueryKey;
|
|
8
|
+
appendQueryKey?: readonly unknown[];
|
|
9
|
+
args?: TArgs;
|
|
10
|
+
mapArgs?: (args: TArgs) => TArgs;
|
|
11
|
+
queryFn?: (context: {
|
|
12
|
+
queryKey: BaseQueryKey;
|
|
13
|
+
signal: AbortSignal;
|
|
14
|
+
meta: Record<string, unknown> | undefined;
|
|
15
|
+
args: TArgs;
|
|
16
|
+
}) => MaybePromise<TResult>;
|
|
17
|
+
};
|
|
18
|
+
type MutationOptionOverrides<TArgs extends unknown[], TResult, TVariables = MutationVariables<TArgs>> = Omit<UseMutationOptions<TResult, unknown, TVariables, unknown>, "mutationKey" | "mutationFn"> & {
|
|
19
|
+
mutationKey?: QueryKey;
|
|
20
|
+
appendMutationKey?: readonly unknown[];
|
|
21
|
+
mapVariablesToArgs?: (variables: TVariables) => TArgs;
|
|
22
|
+
mutationFn?: (context: {
|
|
23
|
+
variables: TVariables;
|
|
24
|
+
args: TArgs;
|
|
25
|
+
}) => MaybePromise<TResult>;
|
|
26
|
+
};
|
|
27
|
+
type InfiniteOptionOverrides<TArgs extends unknown[], TResult, TPageParam = unknown> = Omit<UseInfiniteQueryOptions<TResult, unknown, TResult, BaseQueryKey, TPageParam>, "queryKey" | "queryFn"> & {
|
|
28
|
+
queryKey?: QueryKey;
|
|
29
|
+
appendQueryKey?: readonly unknown[];
|
|
30
|
+
args?: TArgs;
|
|
31
|
+
mapArgs?: (args: TArgs) => TArgs;
|
|
32
|
+
pageParamToArgs?: (pageParam: TPageParam, args: TArgs) => TArgs;
|
|
33
|
+
queryFn?: (context: {
|
|
34
|
+
queryKey: BaseQueryKey;
|
|
35
|
+
signal: AbortSignal;
|
|
36
|
+
meta: Record<string, unknown> | undefined;
|
|
37
|
+
pageParam: TPageParam;
|
|
38
|
+
direction: unknown;
|
|
39
|
+
args: TArgs;
|
|
40
|
+
}) => MaybePromise<TResult>;
|
|
41
|
+
};
|
|
42
|
+
interface QueryOptionFactory<TArgs extends unknown[], TResult> {
|
|
43
|
+
(...payload: TArgs): UseQueryOptions<TResult, unknown, TResult, BaseQueryKey>;
|
|
44
|
+
withOptions: (overrides: QueryOptionOverrides<TArgs, TResult>, ...payload: TArgs) => UseQueryOptions<TResult, unknown, TResult, BaseQueryKey>;
|
|
45
|
+
}
|
|
46
|
+
interface MutationOptionFactory<TArgs extends unknown[], TResult, TVariables = MutationVariables<TArgs>> {
|
|
47
|
+
(): UseMutationOptions<TResult, unknown, TVariables, unknown>;
|
|
48
|
+
withOptions: (overrides?: MutationOptionOverrides<TArgs, TResult, TVariables>) => UseMutationOptions<TResult, unknown, TVariables, unknown>;
|
|
49
|
+
}
|
|
50
|
+
interface MutationOptionConfig<TArgs extends unknown[], TVariables = MutationVariables<TArgs>> {
|
|
51
|
+
mapVariablesToArgs?: (variables: TVariables) => TArgs;
|
|
52
|
+
}
|
|
53
|
+
interface InfiniteOptionFactory<TArgs extends unknown[], TResult, TPageParam = unknown> {
|
|
54
|
+
(...payload: TArgs): UseInfiniteQueryOptions<TResult, unknown, TResult, BaseQueryKey, TPageParam>;
|
|
55
|
+
withOptions: (overrides: InfiniteOptionOverrides<TArgs, TResult, TPageParam>, ...payload: TArgs) => UseInfiniteQueryOptions<TResult, unknown, TResult, BaseQueryKey, TPageParam>;
|
|
56
|
+
}
|
|
57
|
+
type QueryOptionType = <T extends unknown[], J>(key: readonly unknown[], fn: AnyFn<T, J>) => QueryOptionFactory<T, J>;
|
|
58
|
+
type MutationOptionType = <TArgs extends unknown[], TResult, TVariables = MutationVariables<TArgs>>(key: readonly unknown[], fn: AnyFn<TArgs, TResult>, config?: MutationOptionConfig<TArgs, TVariables>) => MutationOptionFactory<TArgs, TResult, TVariables>;
|
|
59
|
+
type InfiniteOptionType = <T extends unknown[], K>(key: readonly unknown[], fn: AnyFn<T, K>) => InfiniteOptionFactory<T, K>;
|
|
8
60
|
export declare const queryOption: QueryOptionType;
|
|
9
61
|
export declare const mutationOption: MutationOptionType;
|
|
10
62
|
export declare const infiniteOption: InfiniteOptionType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/utils/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAE/B,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AACtC,KAAK,KAAK,CAAC,KAAK,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,EAAE,OAAO,GAAG,OAAO,IAAI,CACnE,GAAG,OAAO,EAAE,KAAK,KACd,YAAY,CAAC,OAAO,CAAC,CAAC;AAC3B,KAAK,iBAAiB,CAAC,KAAK,SAAS,OAAO,EAAE,IAAI,KAAK,SAAS,EAAE,GAC9D,IAAI,GACJ,KAAK,SAAS,CA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 -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiwwsw/react-query-helper",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"module": "dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -57,9 +57,10 @@
|
|
|
57
57
|
"sideEffects": false,
|
|
58
58
|
"scripts": {
|
|
59
59
|
"start": "bun run src/index.ts",
|
|
60
|
-
"build": "tsc && bun build src/cli.ts --outdir dist --target node --external typescript --external prettier && bun build src/index.ts --outdir dist --target node --external typescript --external prettier && bun build src/config.ts --outdir dist --target node --external typescript --external prettier && node scripts/prepend-shebang.cjs dist/cli.js",
|
|
60
|
+
"build": "tsc && bun build src/cli.ts --outdir dist --target node --external typescript --external prettier && bun build src/index.ts --outdir dist --target node --external typescript --external prettier && bun build src/config.ts --outdir dist --target node --external typescript --external prettier && bun build src/core/analyzer.ts --outdir dist/core --target node --external typescript --external prettier && bun build src/core/generator.ts --outdir dist/core --target node --external typescript --external prettier && node scripts/prepend-shebang.cjs dist/cli.js",
|
|
61
61
|
"dev": "bun run src/cli.ts --watch",
|
|
62
|
-
"generate": "bun run src/cli.ts --generate"
|
|
62
|
+
"generate": "bun run src/cli.ts --generate",
|
|
63
|
+
"test": "npm run build && node --test test/**/*.test.mjs"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
66
|
"@types/bun": "latest",
|
|
@@ -75,6 +76,6 @@
|
|
|
75
76
|
"typescript": "^5.8.3"
|
|
76
77
|
},
|
|
77
78
|
"engines": {
|
|
78
|
-
"node": ">=
|
|
79
|
+
"node": ">=22"
|
|
79
80
|
}
|
|
80
81
|
}
|