@uiwwsw/react-query-helper 1.2.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
@@ -251,6 +251,41 @@ const config: AutoQueryConfig = {
251
251
  - `customAnalyzerPath`: 파일을 읽고 원하는 함수 메타 목록을 직접 반환
252
252
  - `customTemplatePath`: 최종 생성 코드 문자열을 직접 반환
253
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
+
254
289
  즉 이제는 기본 규칙을 조금 바꾸는 수준이 아니라, 팀 전용 생성기처럼 확장할 수 있습니다.
255
290
 
256
291
  ```ts
package/dist/cli.js CHANGED
@@ -1605,6 +1605,26 @@ function shouldIncludeFunction(info, config = {}) {
1605
1605
  }
1606
1606
  return true;
1607
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
+ }
1608
1628
  function analyzeFile(filePath, config = {}) {
1609
1629
  const sourceCode = readFileSync(filePath, "utf8");
1610
1630
  const scriptKind = filePath.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
@@ -1616,23 +1636,14 @@ function analyzeFile(filePath, config = {}) {
1616
1636
  const isExported = hasExportModifier(node);
1617
1637
  node.declarationList.declarations.forEach((declaration) => {
1618
1638
  if (ts.isVariableDeclaration(declaration) && ts.isIdentifier(declaration.name)) {
1619
- const initializer = declaration.initializer;
1620
- if (initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer))) {
1621
- const name = declaration.name.text;
1622
- const parameters = initializer.parameters.map((param) => param.name.getText(sourceFile));
1623
- const isAsync = initializer.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword) || false;
1624
- 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));
1625
1642
  }
1626
1643
  }
1627
1644
  });
1628
- } else if (ts.isFunctionDeclaration(node)) {
1629
- if (node.name) {
1630
- const name = node.name.text;
1631
- const parameters = node.parameters.map((param) => param.name.getText(sourceFile));
1632
- const isAsync = node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword) || false;
1633
- const isExported = hasExportModifier(node);
1634
- functionInfos.push({ name, parameters, isAsync, isExported });
1635
- }
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));
1636
1647
  }
1637
1648
  });
1638
1649
  return functionInfos.filter((info) => shouldIncludeFunction(info, config));
@@ -1 +1 @@
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;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));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiwwsw/react-query-helper",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "module": "dist/index.js",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",