@uiwwsw/react-query-helper 1.2.4 → 1.2.5
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 +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -229
- package/package.json +13 -1
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ npm exec react-query-helper -- --init
|
|
|
87
87
|
|
|
88
88
|
```ts
|
|
89
89
|
// rqh.config.ts
|
|
90
|
-
import type { AutoQueryConfig } from "@uiwwsw/react-query-helper";
|
|
90
|
+
import type { AutoQueryConfig } from "@uiwwsw/react-query-helper/config";
|
|
91
91
|
|
|
92
92
|
const config: AutoQueryConfig = {
|
|
93
93
|
sourceDir: "./libs", // API 함수들이 위치한 경로
|
package/dist/cli.js
CHANGED
|
@@ -1814,7 +1814,7 @@ var config;
|
|
|
1814
1814
|
var customAnalyzerModule = null;
|
|
1815
1815
|
var customTemplateModule = null;
|
|
1816
1816
|
var DEFAULT_CONFIG_FILE_NAME = "rqh.config.ts";
|
|
1817
|
-
var DEFAULT_CONFIG_TEMPLATE = `import type { AutoQueryConfig } from "@uiwwsw/react-query-helper";
|
|
1817
|
+
var DEFAULT_CONFIG_TEMPLATE = `import type { AutoQueryConfig } from "@uiwwsw/react-query-helper/config";
|
|
1818
1818
|
|
|
1819
1819
|
const config: AutoQueryConfig = {
|
|
1820
1820
|
sourceDir: "./libs",
|
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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,226 +1,3 @@
|
|
|
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
|
-
// src/core/generator.ts
|
|
68
|
-
var DEFAULT_IMPORT_NAMES = {
|
|
69
|
-
query: "queryOption",
|
|
70
|
-
mutation: "mutationOption",
|
|
71
|
-
infinite: "infiniteOption"
|
|
72
|
-
};
|
|
73
|
-
var DEFAULT_OUTPUT_NAMES = {
|
|
74
|
-
query: "QueryOption",
|
|
75
|
-
mutation: "MutationOption",
|
|
76
|
-
infinite: "InfiniteQueryOption"
|
|
77
|
-
};
|
|
78
|
-
function getKeySegments(info, fileName, keySegments, keyStyle) {
|
|
79
|
-
switch (keyStyle) {
|
|
80
|
-
case "function-only":
|
|
81
|
-
return [info.name];
|
|
82
|
-
case "file-only":
|
|
83
|
-
return [fileName, info.name];
|
|
84
|
-
case "path":
|
|
85
|
-
default:
|
|
86
|
-
return [...keySegments, info.name];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function generateOptionsCode(functionInfos, importPath, { keySegments, fileName, templateImportPath, template }) {
|
|
90
|
-
if (functionInfos.length === 0) {
|
|
91
|
-
return "";
|
|
92
|
-
}
|
|
93
|
-
const enabledArtifacts = template?.enabledArtifacts?.length ? template.enabledArtifacts : ["query", "mutation", "infinite"];
|
|
94
|
-
const importNames = {
|
|
95
|
-
...DEFAULT_IMPORT_NAMES,
|
|
96
|
-
...template?.importNames
|
|
97
|
-
};
|
|
98
|
-
const outputNames = {
|
|
99
|
-
...DEFAULT_OUTPUT_NAMES,
|
|
100
|
-
...template?.outputNames
|
|
101
|
-
};
|
|
102
|
-
const helperImports = enabledArtifacts.map((artifact) => importNames[artifact]);
|
|
103
|
-
const functionNames = functionInfos.map((info) => info.name);
|
|
104
|
-
const keyStyle = template?.keyStyle ?? "path";
|
|
105
|
-
let newContent = `import { ${functionNames.join(", ")} } from "${importPath}";
|
|
106
|
-
`;
|
|
107
|
-
newContent += `import { ${helperImports.join(", ")} } from "${templateImportPath}";
|
|
108
|
-
|
|
109
|
-
`;
|
|
110
|
-
functionInfos.forEach((info) => {
|
|
111
|
-
const keyArray = JSON.stringify(getKeySegments(info, fileName, keySegments, keyStyle));
|
|
112
|
-
const keyName = `${info.name}Key`;
|
|
113
|
-
newContent += `export const ${keyName} = ${keyArray} as const;
|
|
114
|
-
`;
|
|
115
|
-
enabledArtifacts.forEach((artifact) => {
|
|
116
|
-
newContent += `export const ${info.name}${outputNames[artifact]} = ${importNames[artifact]}(${keyName}, ${info.name});
|
|
117
|
-
`;
|
|
118
|
-
});
|
|
119
|
-
newContent += `
|
|
120
|
-
`;
|
|
121
|
-
});
|
|
122
|
-
return newContent;
|
|
123
|
-
}
|
|
124
|
-
// src/config.ts
|
|
125
|
-
import { existsSync } from "fs";
|
|
126
|
-
import { readFile, unlink, writeFile } from "fs/promises";
|
|
127
|
-
import { randomUUID } from "crypto";
|
|
128
|
-
import { dirname, extname, join, resolve } from "path";
|
|
129
|
-
import { pathToFileURL } from "url";
|
|
130
|
-
import ts2 from "typescript";
|
|
131
|
-
|
|
132
|
-
class ConfigLoadError extends Error {
|
|
133
|
-
configPath;
|
|
134
|
-
cause;
|
|
135
|
-
constructor(message, configPath, cause) {
|
|
136
|
-
super(message);
|
|
137
|
-
this.configPath = configPath;
|
|
138
|
-
this.cause = cause;
|
|
139
|
-
this.name = "ConfigLoadError";
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
var defaultConfig = {
|
|
143
|
-
sourceDir: "./libs",
|
|
144
|
-
outputDir: "./src/options",
|
|
145
|
-
ignoredFiles: ["domain.ts", "adaptor.ts"],
|
|
146
|
-
templateDir: "@uiwwsw/react-query-helper"
|
|
147
|
-
};
|
|
148
|
-
var CONFIG_FILE_NAMES = [
|
|
149
|
-
"rqh.config.ts",
|
|
150
|
-
"rqh.config.mts",
|
|
151
|
-
"rqh.config.cts",
|
|
152
|
-
"rqh.config.js",
|
|
153
|
-
"rqh.config.mjs",
|
|
154
|
-
"rqh.config.cjs"
|
|
155
|
-
];
|
|
156
|
-
var TYPESCRIPT_CONFIG_EXTENSIONS = new Set([".ts", ".mts", ".cts"]);
|
|
157
|
-
async function importTypeScriptConfig(configPath) {
|
|
158
|
-
const source = await readFile(configPath, "utf8");
|
|
159
|
-
const transpiled = ts2.transpileModule(source, {
|
|
160
|
-
compilerOptions: {
|
|
161
|
-
module: ts2.ModuleKind.ESNext,
|
|
162
|
-
target: ts2.ScriptTarget.ES2020,
|
|
163
|
-
moduleResolution: ts2.ModuleResolutionKind.Bundler,
|
|
164
|
-
esModuleInterop: true
|
|
165
|
-
},
|
|
166
|
-
fileName: configPath
|
|
167
|
-
});
|
|
168
|
-
const tempFilePath = join(dirname(configPath), `.rqh.config.${randomUUID()}.mjs`);
|
|
169
|
-
await writeFile(tempFilePath, transpiled.outputText, "utf8");
|
|
170
|
-
try {
|
|
171
|
-
return await import(pathToFileURL(tempFilePath).href);
|
|
172
|
-
} finally {
|
|
173
|
-
await unlink(tempFilePath).catch(() => {
|
|
174
|
-
return;
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
async function importConfig(configPath) {
|
|
179
|
-
if (TYPESCRIPT_CONFIG_EXTENSIONS.has(extname(configPath).toLowerCase())) {
|
|
180
|
-
return importTypeScriptConfig(configPath);
|
|
181
|
-
}
|
|
182
|
-
return import(pathToFileURL(configPath).href);
|
|
183
|
-
}
|
|
184
|
-
function resolveConfigPath(cwd = process.cwd()) {
|
|
185
|
-
return CONFIG_FILE_NAMES.map((fileName) => join(cwd, fileName)).find((configPath) => existsSync(configPath));
|
|
186
|
-
}
|
|
187
|
-
async function loadConfig() {
|
|
188
|
-
const configPath = resolveConfigPath();
|
|
189
|
-
if (configPath) {
|
|
190
|
-
const importedConfig = await importConfig(configPath).catch((error) => {
|
|
191
|
-
throw new ConfigLoadError(`Failed to load config from ${configPath}.`, configPath, error);
|
|
192
|
-
});
|
|
193
|
-
const userConfig = importedConfig.default ?? importedConfig;
|
|
194
|
-
if (!userConfig || typeof userConfig !== "object") {
|
|
195
|
-
throw new ConfigLoadError(`Config at ${configPath} must export an object.`, configPath);
|
|
196
|
-
}
|
|
197
|
-
const mergedConfig = {
|
|
198
|
-
...defaultConfig,
|
|
199
|
-
...userConfig
|
|
200
|
-
};
|
|
201
|
-
const configDir2 = dirname(configPath);
|
|
202
|
-
return {
|
|
203
|
-
...mergedConfig,
|
|
204
|
-
configPath,
|
|
205
|
-
configDir: configDir2,
|
|
206
|
-
resolvedSourceDir: resolve(configDir2, mergedConfig.sourceDir),
|
|
207
|
-
resolvedOutputDir: resolve(configDir2, mergedConfig.outputDir),
|
|
208
|
-
resolvedTemplateDir: mergedConfig.templateDir && mergedConfig.templateDir.startsWith(".") ? resolve(configDir2, mergedConfig.templateDir) : mergedConfig.templateDir,
|
|
209
|
-
resolvedCustomAnalyzerPath: mergedConfig.customAnalyzerPath && mergedConfig.customAnalyzerPath.startsWith(".") ? resolve(configDir2, mergedConfig.customAnalyzerPath) : mergedConfig.customAnalyzerPath,
|
|
210
|
-
resolvedCustomTemplatePath: mergedConfig.customTemplatePath && mergedConfig.customTemplatePath.startsWith(".") ? resolve(configDir2, mergedConfig.customTemplatePath) : mergedConfig.customTemplatePath
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
const configDir = process.cwd();
|
|
214
|
-
return {
|
|
215
|
-
...defaultConfig,
|
|
216
|
-
configDir,
|
|
217
|
-
resolvedSourceDir: resolve(configDir, defaultConfig.sourceDir),
|
|
218
|
-
resolvedOutputDir: resolve(configDir, defaultConfig.outputDir),
|
|
219
|
-
resolvedTemplateDir: defaultConfig.templateDir,
|
|
220
|
-
resolvedCustomAnalyzerPath: undefined,
|
|
221
|
-
resolvedCustomTemplatePath: undefined
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
1
|
// src/utils/query.ts
|
|
225
2
|
var queryOption = (key, fn) => {
|
|
226
3
|
return (...payload) => ({
|
|
@@ -257,12 +34,7 @@ var infiniteOption = (key, fn) => {
|
|
|
257
34
|
});
|
|
258
35
|
};
|
|
259
36
|
export {
|
|
260
|
-
resolveConfigPath,
|
|
261
37
|
queryOption,
|
|
262
38
|
mutationOption,
|
|
263
|
-
|
|
264
|
-
infiniteOption,
|
|
265
|
-
generateOptionsCode,
|
|
266
|
-
analyzeFile,
|
|
267
|
-
ConfigLoadError
|
|
39
|
+
infiniteOption
|
|
268
40
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiwwsw/react-query-helper",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"module": "dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,6 +40,18 @@
|
|
|
40
40
|
".": {
|
|
41
41
|
"import": "./dist/index.js",
|
|
42
42
|
"types": "./dist/index.d.ts"
|
|
43
|
+
},
|
|
44
|
+
"./config": {
|
|
45
|
+
"import": "./dist/config.js",
|
|
46
|
+
"types": "./dist/config.d.ts"
|
|
47
|
+
},
|
|
48
|
+
"./core/analyzer": {
|
|
49
|
+
"import": "./dist/core/analyzer.js",
|
|
50
|
+
"types": "./dist/core/analyzer.d.ts"
|
|
51
|
+
},
|
|
52
|
+
"./core/generator": {
|
|
53
|
+
"import": "./dist/core/generator.js",
|
|
54
|
+
"types": "./dist/core/generator.d.ts"
|
|
43
55
|
}
|
|
44
56
|
},
|
|
45
57
|
"scripts": {
|