@7nohe/openapi-react-query-codegen 4.0.0-beta.2 → 4.0.0-beta.4
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/AGENTS.md +4 -4
- package/README.md +3 -2
- package/dist/client/operations.mjs +6 -1
- package/dist/client/tsconfig.d.mts +1 -2
- package/dist/client/tsconfig.mjs +118 -22
- package/dist/createSource.mjs +1 -1
- package/dist/format.d.mts +0 -1
- package/dist/format.mjs +0 -20
- package/dist/generate.mjs +1 -2
- package/dist/{tsmorph → hooks}/buildCommon.d.mts +11 -11
- package/dist/{tsmorph → hooks}/buildCommon.mjs +22 -63
- package/dist/{tsmorph → hooks}/buildMutationHooks.d.mts +2 -2
- package/dist/{tsmorph → hooks}/buildMutationHooks.mjs +5 -12
- package/dist/{tsmorph → hooks}/buildQueryHooks.d.mts +8 -8
- package/dist/{tsmorph → hooks}/buildQueryHooks.mjs +30 -67
- package/dist/{tsmorph → hooks}/buildQueryOptions.d.mts +3 -3
- package/dist/{tsmorph → hooks}/buildQueryOptions.mjs +10 -23
- package/dist/{tsmorph → hooks}/generateFiles.d.mts +1 -1
- package/dist/{tsmorph → hooks}/generateFiles.mjs +29 -33
- package/dist/{tsmorph/projectFactory.d.mts → hooks/imports.d.mts} +29 -16
- package/dist/{tsmorph/projectFactory.mjs → hooks/imports.mjs} +54 -26
- package/dist/{tsmorph → hooks}/index.d.mts +0 -1
- package/dist/{tsmorph → hooks}/index.mjs +0 -1
- package/dist/hooks/statement.d.mts +34 -0
- package/dist/hooks/statement.mjs +58 -0
- package/package.json +3 -6
- /package/dist/{tsmorph → hooks}/operationNames.d.mts +0 -0
- /package/dist/{tsmorph → hooks}/operationNames.mjs +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** The declaration itself, without its JSDoc. */
|
|
2
|
+
export function statementCode(statement) {
|
|
3
|
+
if (statement.kind === "const") {
|
|
4
|
+
return `export const ${statement.name} = ${statement.initializer};`;
|
|
5
|
+
}
|
|
6
|
+
const typeParameters = statement.typeParameters?.length
|
|
7
|
+
? `<${statement.typeParameters
|
|
8
|
+
.map((parameter) => `${parameter.name} = ${parameter.default}`)
|
|
9
|
+
.join(", ")}>`
|
|
10
|
+
: "";
|
|
11
|
+
return `export type ${statement.name}${typeParameters} = ${statement.type};`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* One statement per line, with a blank line wherever a `const` follows a type
|
|
15
|
+
* alias or the other way round.
|
|
16
|
+
*/
|
|
17
|
+
export function printStatements(statements) {
|
|
18
|
+
let text = "";
|
|
19
|
+
statements.forEach((statement, index) => {
|
|
20
|
+
if (index > 0 && statements[index - 1].kind !== statement.kind) {
|
|
21
|
+
text += "\n";
|
|
22
|
+
}
|
|
23
|
+
if (statement.kind === "const" && statement.jsDoc) {
|
|
24
|
+
text += `${statement.jsDoc}\n`;
|
|
25
|
+
}
|
|
26
|
+
text += `${statementCode(statement)}\n`;
|
|
27
|
+
});
|
|
28
|
+
return text;
|
|
29
|
+
}
|
|
30
|
+
// A string literal, a spread, a member access, an identifier, or any other
|
|
31
|
+
// character. The last one only matters as what comes before an identifier.
|
|
32
|
+
const TOKEN = /"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'|`(?:[^`\\]|\\.)*`|\.\.\.|\.\s*[\p{ID_Start}_$][\p{ID_Continue}$]*|[\p{ID_Start}_$][\p{ID_Continue}$]*|\S/gu;
|
|
33
|
+
const IDENTIFIER_START = /^[\p{ID_Start}_$]/u;
|
|
34
|
+
/** What follows the key of a property or the name of a parameter. */
|
|
35
|
+
const KEY_END = /\s*\??:/y;
|
|
36
|
+
/**
|
|
37
|
+
* The identifiers a piece of generated code refers to. Three places hold a
|
|
38
|
+
* name without referring to anything a file could import, and are left out:
|
|
39
|
+
* a string literal, the name after the dot of a member access, and the key of
|
|
40
|
+
* a property or the name of a parameter (`{ page: 1 }`, `(options?: T)`).
|
|
41
|
+
*/
|
|
42
|
+
export function referencedNames(code) {
|
|
43
|
+
const names = new Set();
|
|
44
|
+
let previous = "";
|
|
45
|
+
for (const match of code.matchAll(TOKEN)) {
|
|
46
|
+
const [token] = match;
|
|
47
|
+
if (IDENTIFIER_START.test(token)) {
|
|
48
|
+
KEY_END.lastIndex = match.index + token.length;
|
|
49
|
+
const isKey = (previous === "{" || previous === "," || previous === "(") &&
|
|
50
|
+
KEY_END.test(code);
|
|
51
|
+
if (!isKey) {
|
|
52
|
+
names.add(token);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
previous = token;
|
|
56
|
+
}
|
|
57
|
+
return names;
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@7nohe/openapi-react-query-codegen",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.4",
|
|
4
4
|
"description": "OpenAPI React Query Codegen",
|
|
5
5
|
"bin": {
|
|
6
6
|
"openapi-rq": "dist/cli.mjs"
|
|
@@ -51,19 +51,16 @@
|
|
|
51
51
|
"axios": "1.20.0",
|
|
52
52
|
"commander": "^15.0.0",
|
|
53
53
|
"lefthook": "^2.1.10",
|
|
54
|
-
"ts-morph": "^28.0.0",
|
|
55
54
|
"typescript": "^6.0.3",
|
|
56
55
|
"vite": "^7.3.7",
|
|
57
56
|
"vitest": "^4.1.12"
|
|
58
57
|
},
|
|
59
58
|
"peerDependencies": {
|
|
60
59
|
"@tanstack/react-query": "^5.0.0",
|
|
61
|
-
"commander": "12.x || 13.x || 14.x || 15.x"
|
|
62
|
-
"ts-morph": "28.x",
|
|
63
|
-
"typescript": "5.x || 6.x"
|
|
60
|
+
"commander": "12.x || 13.x || 14.x || 15.x"
|
|
64
61
|
},
|
|
65
62
|
"engines": {
|
|
66
|
-
"node": ">=
|
|
63
|
+
"node": ">=24.0.0",
|
|
67
64
|
"pnpm": ">=9"
|
|
68
65
|
},
|
|
69
66
|
"scripts": {
|
|
File without changes
|
|
File without changes
|