@uiwwsw/react-query-helper 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -237,6 +237,57 @@ const config: AutoQueryConfig = {
237
237
  };
238
238
  ```
239
239
 
240
+ 더 강하게 커스터마이징하려면 외부 모듈도 연결할 수 있습니다.
241
+
242
+ ```ts
243
+ const config: AutoQueryConfig = {
244
+ sourceDir: "./libs",
245
+ outputDir: "./src/options",
246
+ customAnalyzerPath: "./rqh.analyzer.mjs",
247
+ customTemplatePath: "./rqh.template.mjs",
248
+ };
249
+ ```
250
+
251
+ - `customAnalyzerPath`: 파일을 읽고 원하는 함수 메타 목록을 직접 반환
252
+ - `customTemplatePath`: 최종 생성 코드 문자열을 직접 반환
253
+
254
+ 예시 `rqh.analyzer.mjs`:
255
+
256
+ ```js
257
+ export function analyzeFile(filePath, config) {
258
+ // 여기서 AST를 직접 파싱하거나,
259
+ // 파일명 규칙 / 함수명 규칙을 자유롭게 적용할 수 있습니다.
260
+ return [
261
+ {
262
+ name: "getUser",
263
+ parameters: ["params"],
264
+ isAsync: true,
265
+ isExported: true,
266
+ },
267
+ ];
268
+ }
269
+ ```
270
+
271
+ 예시 `rqh.template.mjs`:
272
+
273
+ ```js
274
+ export function generateOptionsCode({ functionInfos, importPath }) {
275
+ const names = functionInfos.map((info) => info.name).join(", ");
276
+ return `import { ${names} } from "${importPath}";\nexport const customGenerated = true;\n`;
277
+ }
278
+ ```
279
+
280
+ 언제 custom analyzer를 쓰면 되냐면:
281
+ - built-in analyzer 설정만으로 충분한 경우
282
+ - `exported-only`, `async-only`, 이름 include/exclude, 아티팩트 on/off 정도
283
+ - custom analyzer가 필요한 경우
284
+ - 함수 선언이 래핑되어 있거나
285
+ - factory/higher-order 구조를 쓰거나
286
+ - 팀 전용 규칙으로 함수 후보를 뽑아야 하거나
287
+ - 기본 AST 규칙보다 더 복잡한 generic 패턴을 강제하고 싶을 때
288
+
289
+ 즉 이제는 기본 규칙을 조금 바꾸는 수준이 아니라, 팀 전용 생성기처럼 확장할 수 있습니다.
290
+
240
291
  ```ts
241
292
  const config: AutoQueryConfig = {
242
293
  sourceDir: "./libs",
package/dist/cli.js CHANGED
@@ -1580,6 +1580,7 @@ import {
1580
1580
  sep
1581
1581
  } from "path";
1582
1582
  import { writeFileSync, existsSync as existsSync2, mkdirSync, unlinkSync } from "fs";
1583
+ import { pathToFileURL as pathToFileURL2 } from "url";
1583
1584
 
1584
1585
  // src/core/analyzer.ts
1585
1586
  import ts from "typescript";
@@ -1604,6 +1605,26 @@ function shouldIncludeFunction(info, config = {}) {
1604
1605
  }
1605
1606
  return true;
1606
1607
  }
1608
+ function unwrapFunctionLike(node) {
1609
+ if (!node) {
1610
+ return;
1611
+ }
1612
+ if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
1613
+ return node;
1614
+ }
1615
+ if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isTypeAssertionExpression(node) || ts.isSatisfiesExpression(node) || ts.isNonNullExpression(node)) {
1616
+ return unwrapFunctionLike(node.expression);
1617
+ }
1618
+ return;
1619
+ }
1620
+ function getFunctionInfo(name, parameters, isAsync, isExported, sourceFile) {
1621
+ return {
1622
+ name,
1623
+ parameters: parameters.map((param) => param.name.getText(sourceFile)),
1624
+ isAsync,
1625
+ isExported
1626
+ };
1627
+ }
1607
1628
  function analyzeFile(filePath, config = {}) {
1608
1629
  const sourceCode = readFileSync(filePath, "utf8");
1609
1630
  const scriptKind = filePath.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
@@ -1615,23 +1636,14 @@ function analyzeFile(filePath, config = {}) {
1615
1636
  const isExported = hasExportModifier(node);
1616
1637
  node.declarationList.declarations.forEach((declaration) => {
1617
1638
  if (ts.isVariableDeclaration(declaration) && ts.isIdentifier(declaration.name)) {
1618
- const initializer = declaration.initializer;
1619
- if (initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer))) {
1620
- const name = declaration.name.text;
1621
- const parameters = initializer.parameters.map((param) => param.name.getText(sourceFile));
1622
- const isAsync = initializer.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword) || false;
1623
- functionInfos.push({ name, parameters, isAsync, isExported });
1639
+ const initializer = unwrapFunctionLike(declaration.initializer);
1640
+ if (initializer) {
1641
+ functionInfos.push(getFunctionInfo(declaration.name.text, initializer.parameters, !!initializer.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword), isExported, sourceFile));
1624
1642
  }
1625
1643
  }
1626
1644
  });
1627
- } else if (ts.isFunctionDeclaration(node)) {
1628
- if (node.name) {
1629
- const name = node.name.text;
1630
- const parameters = node.parameters.map((param) => param.name.getText(sourceFile));
1631
- const isAsync = node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword) || false;
1632
- const isExported = hasExportModifier(node);
1633
- functionInfos.push({ name, parameters, isAsync, isExported });
1634
- }
1645
+ } else if (ts.isFunctionDeclaration(node) && node.name) {
1646
+ functionInfos.push(getFunctionInfo(node.name.text, node.parameters, !!node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword), hasExportModifier(node), sourceFile));
1635
1647
  }
1636
1648
  });
1637
1649
  return functionInfos.filter((info) => shouldIncludeFunction(info, config));
@@ -1779,7 +1791,9 @@ async function loadConfig() {
1779
1791
  configDir: configDir2,
1780
1792
  resolvedSourceDir: resolve3(configDir2, mergedConfig.sourceDir),
1781
1793
  resolvedOutputDir: resolve3(configDir2, mergedConfig.outputDir),
1782
- resolvedTemplateDir: mergedConfig.templateDir && mergedConfig.templateDir.startsWith(".") ? resolve3(configDir2, mergedConfig.templateDir) : mergedConfig.templateDir
1794
+ resolvedTemplateDir: mergedConfig.templateDir && mergedConfig.templateDir.startsWith(".") ? resolve3(configDir2, mergedConfig.templateDir) : mergedConfig.templateDir,
1795
+ resolvedCustomAnalyzerPath: mergedConfig.customAnalyzerPath && mergedConfig.customAnalyzerPath.startsWith(".") ? resolve3(configDir2, mergedConfig.customAnalyzerPath) : mergedConfig.customAnalyzerPath,
1796
+ resolvedCustomTemplatePath: mergedConfig.customTemplatePath && mergedConfig.customTemplatePath.startsWith(".") ? resolve3(configDir2, mergedConfig.customTemplatePath) : mergedConfig.customTemplatePath
1783
1797
  };
1784
1798
  }
1785
1799
  const configDir = process.cwd();
@@ -1788,13 +1802,17 @@ async function loadConfig() {
1788
1802
  configDir,
1789
1803
  resolvedSourceDir: resolve3(configDir, defaultConfig.sourceDir),
1790
1804
  resolvedOutputDir: resolve3(configDir, defaultConfig.outputDir),
1791
- resolvedTemplateDir: defaultConfig.templateDir
1805
+ resolvedTemplateDir: defaultConfig.templateDir,
1806
+ resolvedCustomAnalyzerPath: undefined,
1807
+ resolvedCustomTemplatePath: undefined
1792
1808
  };
1793
1809
  }
1794
1810
 
1795
1811
  // src/cli.ts
1796
1812
  import prettier from "prettier";
1797
1813
  var config;
1814
+ var customAnalyzerModule = null;
1815
+ var customTemplateModule = null;
1798
1816
  var DEFAULT_CONFIG_FILE_NAME = "rqh.config.ts";
1799
1817
  var DEFAULT_CONFIG_TEMPLATE = `import type { AutoQueryConfig } from "@uiwwsw/react-query-helper";
1800
1818
 
@@ -1823,6 +1841,8 @@ const config: AutoQueryConfig = {
1823
1841
  infinite: "InfiniteQueryOption",
1824
1842
  },
1825
1843
  },
1844
+ customAnalyzerPath: "./rqh.analyzer.ts",
1845
+ customTemplatePath: "./rqh.template.ts",
1826
1846
  };
1827
1847
 
1828
1848
  export default config;
@@ -1864,7 +1884,8 @@ function runInit() {
1864
1884
  console.log(`✅ Created ${configPath}`);
1865
1885
  console.log("Next steps:");
1866
1886
  console.log("1. Update sourceDir/outputDir if needed.");
1867
- console.log("2. Run `react-query-helper --generate`.");
1887
+ console.log("2. Remove customAnalyzerPath/customTemplatePath if you don't need plugin hooks.");
1888
+ console.log("3. Run `react-query-helper --generate`.");
1868
1889
  }
1869
1890
  async function loadConfigOrExit() {
1870
1891
  try {
@@ -1882,6 +1903,39 @@ async function loadConfigOrExit() {
1882
1903
  return null;
1883
1904
  }
1884
1905
  }
1906
+ async function loadPluginModules() {
1907
+ customAnalyzerModule = null;
1908
+ customTemplateModule = null;
1909
+ if (config.resolvedCustomAnalyzerPath) {
1910
+ const imported = await import(pathToFileURL2(config.resolvedCustomAnalyzerPath).href);
1911
+ customAnalyzerModule = imported.default ?? imported;
1912
+ }
1913
+ if (config.resolvedCustomTemplatePath) {
1914
+ const imported = await import(pathToFileURL2(config.resolvedCustomTemplatePath).href);
1915
+ customTemplateModule = imported.default ?? imported;
1916
+ }
1917
+ }
1918
+ async function collectFunctionInfos(filePath) {
1919
+ if (customAnalyzerModule?.analyzeFile) {
1920
+ const result = await customAnalyzerModule.analyzeFile(filePath, config);
1921
+ return Array.isArray(result) ? result : [];
1922
+ }
1923
+ return analyzeFile(filePath, config.analyzer);
1924
+ }
1925
+ async function renderOptionsCode(params) {
1926
+ if (customTemplateModule?.generateOptionsCode) {
1927
+ return await customTemplateModule.generateOptionsCode({
1928
+ ...params,
1929
+ config
1930
+ });
1931
+ }
1932
+ return generateOptionsCode(params.functionInfos, params.importPath, {
1933
+ keySegments: params.keySegments,
1934
+ fileName: params.fileName,
1935
+ templateImportPath: params.templateImportPath,
1936
+ template: config.template
1937
+ });
1938
+ }
1885
1939
  async function processFile(filePath) {
1886
1940
  if (!shouldProcess(filePath)) {
1887
1941
  return;
@@ -1900,18 +1954,19 @@ async function processFile(filePath) {
1900
1954
  return;
1901
1955
  }
1902
1956
  try {
1903
- const functionInfos = analyzeFile(filePath, config.analyzer);
1957
+ const functionInfos = await collectFunctionInfos(filePath);
1904
1958
  if (functionInfos.length === 0) {
1905
1959
  console.log(`No exported functions found in ${filePath}. Skipping code generation.`);
1906
1960
  return;
1907
1961
  }
1908
1962
  const outputFolder = relativeDir === "." ? outputRoot : join4(outputRoot, relativeDir);
1909
1963
  const outputFile = join4(outputFolder, `${fileName}Options.ts`);
1910
- const generatedCode = generateOptionsCode(functionInfos, normalizeModulePath(relative3(dirname4(outputFile), filePath.replace(new RegExp(`${extname3(filePath)}$`), "")) || ".", true), {
1964
+ const generatedCode = await renderOptionsCode({
1965
+ functionInfos,
1966
+ importPath: normalizeModulePath(relative3(dirname4(outputFile), filePath.replace(new RegExp(`${extname3(filePath)}$`), "")) || ".", true),
1911
1967
  keySegments: relativeDir === "." ? [fileName] : relativeDir.split(sep).filter(Boolean),
1912
1968
  fileName,
1913
- templateImportPath: config.resolvedTemplateDir && config.templateDir?.startsWith(".") ? normalizeModulePath(relative3(dirname4(outputFile), config.resolvedTemplateDir) || ".", true) : config.resolvedTemplateDir ?? "@uiwwsw/react-query-helper",
1914
- template: config.template
1969
+ templateImportPath: config.resolvedTemplateDir && config.templateDir?.startsWith(".") ? normalizeModulePath(relative3(dirname4(outputFile), config.resolvedTemplateDir) || ".", true) : config.resolvedTemplateDir ?? "@uiwwsw/react-query-helper"
1915
1970
  });
1916
1971
  if (!existsSync2(outputFolder)) {
1917
1972
  mkdirSync(outputFolder, { recursive: true });
@@ -1932,6 +1987,7 @@ async function runGenerate() {
1932
1987
  return;
1933
1988
  }
1934
1989
  config = loadedConfig;
1990
+ await loadPluginModules();
1935
1991
  const sourcePath = config.resolvedSourceDir;
1936
1992
  const outputRootPath = config.resolvedOutputDir;
1937
1993
  ensureDirectory(outputRootPath);
@@ -1962,6 +2018,7 @@ async function runWatch() {
1962
2018
  return;
1963
2019
  }
1964
2020
  config = loadedConfig;
2021
+ await loadPluginModules();
1965
2022
  const sourcePath = config.resolvedSourceDir;
1966
2023
  const outputRootPath = config.resolvedOutputDir;
1967
2024
  ensureDirectory(outputRootPath);
package/dist/config.d.ts CHANGED
@@ -12,6 +12,21 @@ export interface AutoQueryConfig {
12
12
  ignoredFiles?: string[];
13
13
  analyzer?: AnalyzerConfig;
14
14
  template?: TemplateConfig;
15
+ customAnalyzerPath?: string;
16
+ customTemplatePath?: string;
17
+ }
18
+ export interface CustomAnalyzerModule {
19
+ analyzeFile: (filePath: string, config: ResolvedAutoQueryConfig) => Promise<unknown> | unknown;
20
+ }
21
+ export interface CustomTemplateModule {
22
+ generateOptionsCode: (params: {
23
+ functionInfos: unknown[];
24
+ importPath: string;
25
+ keySegments: string[];
26
+ fileName: string;
27
+ templateImportPath: string;
28
+ config: ResolvedAutoQueryConfig;
29
+ }) => Promise<string> | string;
15
30
  }
16
31
  export interface ResolvedAutoQueryConfig extends AutoQueryConfig {
17
32
  configPath?: string;
@@ -19,6 +34,8 @@ export interface ResolvedAutoQueryConfig extends AutoQueryConfig {
19
34
  resolvedSourceDir: string;
20
35
  resolvedOutputDir: string;
21
36
  resolvedTemplateDir?: string;
37
+ resolvedCustomAnalyzerPath?: string;
38
+ resolvedCustomTemplatePath?: string;
22
39
  }
23
40
  export declare function resolveConfigPath(cwd?: string): string | undefined;
24
41
  export declare function loadConfig(): Promise<ResolvedAutoQueryConfig>;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAOA,qBAAa,eAAgB,SAAQ,KAAK;aAGtB,UAAU,CAAC,EAAE,MAAM;aACnB,KAAK,CAAC,EAAE,OAAO;gBAF/B,OAAO,EAAE,MAAM,EACC,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,KAAK,CAAC,EAAE,OAAO,YAAA;CAKlC;AAED,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;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,OAAO,CAAC;CACrB;AAgCD,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,cAAmB,GAC1B,YAAY,EAAE,CAwDhB"}
1
+ {"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../../src/core/analyzer.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,KAAK,CAAC;AACnD,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,YAAY,GAAG,WAAW,CAAC;AAEnE,MAAM,WAAW,cAAc;IAC7B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;CACrB;AAuED,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,cAAmB,GAC1B,YAAY,EAAE,CAyDhB"}
package/dist/index.js CHANGED
@@ -21,6 +21,26 @@ function shouldIncludeFunction(info, config = {}) {
21
21
  }
22
22
  return true;
23
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
+ }
24
44
  function analyzeFile(filePath, config = {}) {
25
45
  const sourceCode = readFileSync(filePath, "utf8");
26
46
  const scriptKind = filePath.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
@@ -32,23 +52,14 @@ function analyzeFile(filePath, config = {}) {
32
52
  const isExported = hasExportModifier(node);
33
53
  node.declarationList.declarations.forEach((declaration) => {
34
54
  if (ts.isVariableDeclaration(declaration) && ts.isIdentifier(declaration.name)) {
35
- const initializer = declaration.initializer;
36
- if (initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer))) {
37
- const name = declaration.name.text;
38
- const parameters = initializer.parameters.map((param) => param.name.getText(sourceFile));
39
- const isAsync = initializer.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword) || false;
40
- functionInfos.push({ name, parameters, isAsync, isExported });
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));
41
58
  }
42
59
  }
43
60
  });
44
- } else if (ts.isFunctionDeclaration(node)) {
45
- if (node.name) {
46
- const name = node.name.text;
47
- const parameters = node.parameters.map((param) => param.name.getText(sourceFile));
48
- const isAsync = node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword) || false;
49
- const isExported = hasExportModifier(node);
50
- functionInfos.push({ name, parameters, isAsync, isExported });
51
- }
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));
52
63
  }
53
64
  });
54
65
  return functionInfos.filter((info) => shouldIncludeFunction(info, config));
@@ -194,7 +205,9 @@ async function loadConfig() {
194
205
  configDir: configDir2,
195
206
  resolvedSourceDir: resolve(configDir2, mergedConfig.sourceDir),
196
207
  resolvedOutputDir: resolve(configDir2, mergedConfig.outputDir),
197
- resolvedTemplateDir: mergedConfig.templateDir && mergedConfig.templateDir.startsWith(".") ? resolve(configDir2, mergedConfig.templateDir) : mergedConfig.templateDir
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
198
211
  };
199
212
  }
200
213
  const configDir = process.cwd();
@@ -203,7 +216,9 @@ async function loadConfig() {
203
216
  configDir,
204
217
  resolvedSourceDir: resolve(configDir, defaultConfig.sourceDir),
205
218
  resolvedOutputDir: resolve(configDir, defaultConfig.outputDir),
206
- resolvedTemplateDir: defaultConfig.templateDir
219
+ resolvedTemplateDir: defaultConfig.templateDir,
220
+ resolvedCustomAnalyzerPath: undefined,
221
+ resolvedCustomTemplatePath: undefined
207
222
  };
208
223
  }
209
224
  // src/utils/query.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiwwsw/react-query-helper",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "module": "dist/index.js",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",