api-core-lib 12.0.44 → 12.0.46
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/dist/cli.cjs +27 -19
- package/package.json +3 -1
package/dist/cli.cjs
CHANGED
|
@@ -55,7 +55,7 @@ function parseSpecToModules(spec) {
|
|
|
55
55
|
const moduleName = tagName.replace(/[^a-zA-Z0-9]/g, "").replace(/Central|Tenant/g, "") + "Api";
|
|
56
56
|
if (!modules[moduleName]) {
|
|
57
57
|
const commonPath = apiPath.substring(0, apiPath.lastIndexOf("/"));
|
|
58
|
-
modules[moduleName] = { baseEndpoint: commonPath || "/", actions: {} };
|
|
58
|
+
modules[moduleName] = { baseEndpoint: commonPath || "/", actions: {}, types: /* @__PURE__ */ new Set() };
|
|
59
59
|
}
|
|
60
60
|
const requestBody = endpoint.requestBody?.content?.["application/json"]?.schema;
|
|
61
61
|
const successResponse = endpoint.responses["200"] || endpoint.responses["201"];
|
|
@@ -78,6 +78,11 @@ function parseSpecToModules(spec) {
|
|
|
78
78
|
} else if ((endpoint.parameters || []).some((p) => p.in === "query")) {
|
|
79
79
|
inputType = "QueryOptions";
|
|
80
80
|
}
|
|
81
|
+
[inputType, outputType].forEach((t) => {
|
|
82
|
+
if (t && t !== "unknown" && t !== "undefined" && t !== "any" && t !== "QueryOptions") {
|
|
83
|
+
modules[moduleName].types.add(t.replace("[]", ""));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
81
86
|
const actionName = sanitizeActionName(endpoint.operationId);
|
|
82
87
|
const relativePath = apiPath.replace(modules[moduleName].baseEndpoint, "") || "/";
|
|
83
88
|
modules[moduleName].actions[actionName] = {
|
|
@@ -154,39 +159,42 @@ README.md`;
|
|
|
154
159
|
if (!import_fs.default.existsSync(modulesOutputPath)) {
|
|
155
160
|
import_fs.default.mkdirSync(modulesOutputPath, { recursive: true });
|
|
156
161
|
}
|
|
157
|
-
const allModelTypes = /* @__PURE__ */ new Set();
|
|
158
|
-
Object.values(modules).forEach((mod) => {
|
|
159
|
-
Object.values(mod.actions).forEach((action) => {
|
|
160
|
-
if (action._inputType && !["unknown", "undefined", "QueryOptions"].includes(action._inputType)) allModelTypes.add(action._inputType.replace("[]", ""));
|
|
161
|
-
if (action._outputType && !["unknown"].includes(action._outputType)) allModelTypes.add(action._outputType.replace("[]", ""));
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
162
|
for (const moduleName in modules) {
|
|
165
163
|
const moduleData = modules[moduleName];
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
const moduleFolderPath = import_path.default.join(modulesOutputPath, moduleName);
|
|
165
|
+
if (!import_fs.default.existsSync(moduleFolderPath)) {
|
|
166
|
+
import_fs.default.mkdirSync(moduleFolderPath, { recursive: true });
|
|
167
|
+
}
|
|
168
|
+
const typesFilePath = import_path.default.join(moduleFolderPath, "types.ts");
|
|
169
|
+
const typesContent = moduleData.types.size ? `export type { ${[...moduleData.types].join(", ")} } from '../../types';` : `// No types used in this module`;
|
|
170
|
+
import_fs.default.writeFileSync(typesFilePath, typesContent);
|
|
171
|
+
const actionsTypeParts = Object.entries(moduleData.actions).map(
|
|
172
|
+
([actionName, actionData]) => ` ${actionName}: ActionConfigModule<${actionData._inputType}, ${actionData._outputType}>;`
|
|
173
|
+
);
|
|
169
174
|
const actionsTypeDefinition = `{
|
|
170
175
|
${actionsTypeParts.join("\n")}
|
|
171
176
|
}`;
|
|
172
|
-
const actionsValueParts = Object.entries(moduleData.actions).map(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
177
|
+
const actionsValueParts = Object.entries(moduleData.actions).map(
|
|
178
|
+
([actionName, actionData]) => {
|
|
179
|
+
const { _inputType, _outputType, ...config } = actionData;
|
|
180
|
+
return ` ${actionName}: ${JSON.stringify(config, null, 2).replace(/\n/g, "\n ")}`;
|
|
181
|
+
}
|
|
182
|
+
);
|
|
176
183
|
const actionsValueDefinition = `{
|
|
177
184
|
${actionsValueParts.join(",\n")}
|
|
178
185
|
}`;
|
|
179
|
-
const
|
|
186
|
+
const configFilePath = import_path.default.join(moduleFolderPath, "config.ts");
|
|
187
|
+
const configContent = `
|
|
180
188
|
import type { ApiModuleConfig, ActionConfigModule, QueryOptions } from 'api-core-lib';
|
|
181
|
-
import type { ${[...
|
|
189
|
+
import type { ${[...moduleData.types].join(", ")} } from './types';
|
|
182
190
|
|
|
183
191
|
export const ${moduleName}Module: ApiModuleConfig<${actionsTypeDefinition}> = {
|
|
184
192
|
baseEndpoint: '${moduleData.baseEndpoint}',
|
|
185
193
|
actions: ${actionsValueDefinition},
|
|
186
194
|
};
|
|
187
195
|
`;
|
|
188
|
-
import_fs.default.writeFileSync(
|
|
189
|
-
console.log(import_chalk.default.green(`\u2713 Module generated: ${
|
|
196
|
+
import_fs.default.writeFileSync(configFilePath, configContent);
|
|
197
|
+
console.log(import_chalk.default.green(`\u2713 Module generated: ${moduleName}/`));
|
|
190
198
|
}
|
|
191
199
|
console.log(import_chalk.default.green("\u2713 All custom modules generated."));
|
|
192
200
|
console.log(import_chalk.default.bold.green("\n\u{1F389} API generation complete! All files are located in:"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "api-core-lib",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.46",
|
|
4
4
|
"description": "A flexible and powerful API client library for modern web applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -42,12 +42,14 @@
|
|
|
42
42
|
"commander": "^9.4.1",
|
|
43
43
|
"dotenv": "^16.0.3",
|
|
44
44
|
"fast-deep-equal": "^3.1.3",
|
|
45
|
+
"fs-extra": "^11.3.1",
|
|
45
46
|
"openapi-typescript": "^6.2.4",
|
|
46
47
|
"path": "^0.12.7",
|
|
47
48
|
"uuid": "^9.0.1"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"@openapitools/openapi-generator-cli": "^2.23.1",
|
|
52
|
+
"@types/fs-extra": "^11.0.4",
|
|
51
53
|
"@types/jest": "^30.0.0",
|
|
52
54
|
"@types/node": "^24.2.1",
|
|
53
55
|
"@types/react": "^18.3.2",
|