swaggular 0.1.0
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/LICENSE +21 -0
- package/README.md +66 -0
- package/dist/app/get-parse-args.js +48 -0
- package/dist/app/parse-variables.js +24 -0
- package/dist/builders/build-comments.js +25 -0
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.js +48 -0
- package/dist/cli/variables.d.ts +2 -0
- package/dist/cli/variables.js +23 -0
- package/dist/core/state/interface-state.d.ts +17 -0
- package/dist/core/state/interface-state.js +21 -0
- package/dist/core/state/service-state.d.ts +9 -0
- package/dist/core/state/service-state.js +18 -0
- package/dist/core/state/swagger-state.d.ts +14 -0
- package/dist/core/state/swagger-state.js +36 -0
- package/dist/examples/services/get.example.js +1 -0
- package/dist/generators/generate-comments.js +40 -0
- package/dist/generators/generate-interface.js +219 -0
- package/dist/generators/generate-service.js +302 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +45 -0
- package/dist/models/file-content.js +2 -0
- package/dist/models/grouped-paths.js +2 -0
- package/dist/models/interface-data.js +2 -0
- package/dist/models/parsed-args.js +2 -0
- package/dist/models/service-data.js +2 -0
- package/dist/models/types.js +29 -0
- package/dist/parsers/path-grouper.d.ts +17 -0
- package/dist/parsers/path-grouper.js +207 -0
- package/dist/parsers/swagger-parser.d.ts +4 -0
- package/dist/parsers/swagger-parser.js +53 -0
- package/dist/renderers/generate-comments.d.ts +3 -0
- package/dist/renderers/generate-comments.js +40 -0
- package/dist/renderers/generate-interface.d.ts +12 -0
- package/dist/renderers/generate-interface.js +209 -0
- package/dist/renderers/generate-service.d.ts +9 -0
- package/dist/renderers/generate-service.js +178 -0
- package/dist/stores/interface-data-store.js +62 -0
- package/dist/stores/services-store.js +18 -0
- package/dist/stores/swagger-store.js +324 -0
- package/dist/templates/angular-template.js +23 -0
- package/dist/templates/paged-request-template.js +22 -0
- package/dist/templates/paged-result-template.js +13 -0
- package/dist/templates/services/angular-template.d.ts +15 -0
- package/dist/templates/services/angular-template.js +24 -0
- package/dist/templates/services/http-params-handler.d.ts +2 -0
- package/dist/templates/services/http-params-handler.js +12 -0
- package/dist/templates/types/extends-from-types.d.ts +3 -0
- package/dist/templates/types/extends-from-types.js +72 -0
- package/dist/templates/types/generic-types.d.ts +4 -0
- package/dist/templates/types/generic-types.js +72 -0
- package/dist/translators/add-import-to-interface.js +21 -0
- package/dist/translators/generate-interfaces.js +134 -0
- package/dist/translators/generate-services.js +192 -0
- package/dist/translators/join-with-templates.js +16 -0
- package/dist/translators/splitPaths.js +8 -0
- package/dist/types/file-content.d.ts +6 -0
- package/dist/types/file-content.js +2 -0
- package/dist/types/grouped-paths.d.ts +7 -0
- package/dist/types/grouped-paths.js +2 -0
- package/dist/types/interface-data.d.ts +13 -0
- package/dist/types/interface-data.js +2 -0
- package/dist/types/parsed-args.d.ts +9 -0
- package/dist/types/parsed-args.js +2 -0
- package/dist/types/service-data.d.ts +21 -0
- package/dist/types/service-data.js +2 -0
- package/dist/types/types.d.ts +23 -0
- package/dist/types/types.js +29 -0
- package/dist/utils/build-types.d.ts +2 -0
- package/dist/utils/build-types.js +66 -0
- package/dist/utils/create-file.d.ts +7 -0
- package/dist/utils/create-file.js +74 -0
- package/dist/utils/generate-imports.js +33 -0
- package/dist/utils/grouping-paths.js +68 -0
- package/dist/utils/method-builders.js +77 -0
- package/dist/utils/object-utils.d.ts +1 -0
- package/dist/utils/object-utils.js +11 -0
- package/dist/utils/path-utils.d.ts +7 -0
- package/dist/utils/path-utils.js +61 -0
- package/dist/utils/string-utils.d.ts +13 -0
- package/dist/utils/string-utils.js +47 -0
- package/dist/utils/to-case.js +47 -0
- package/dist/utils/type-guard.d.ts +5 -0
- package/dist/utils/type-guard.js +35 -0
- package/package.json +64 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.swaggerStore = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const path_utils_1 = require("../utils/path-utils");
|
|
40
|
+
const string_utils_1 = require("../utils/string-utils");
|
|
41
|
+
class SwaggerStore {
|
|
42
|
+
swagger = undefined;
|
|
43
|
+
pathsGroupedByScope = undefined;
|
|
44
|
+
addSwagger(filePath, options = { mode: "tags" }) {
|
|
45
|
+
const absolutePath = path.resolve(filePath);
|
|
46
|
+
const content = fs.readFileSync(absolutePath, { encoding: "utf8" });
|
|
47
|
+
this.swagger = JSON.parse(content);
|
|
48
|
+
if (!this.swagger)
|
|
49
|
+
return;
|
|
50
|
+
this.groupByScopes(this.swagger, options);
|
|
51
|
+
}
|
|
52
|
+
getSwagger() {
|
|
53
|
+
return this.swagger;
|
|
54
|
+
}
|
|
55
|
+
getPaths() {
|
|
56
|
+
return this.swagger?.paths;
|
|
57
|
+
}
|
|
58
|
+
getSchemas() {
|
|
59
|
+
return this.swagger?.components?.schemas;
|
|
60
|
+
}
|
|
61
|
+
getPathsGroupedByScope() {
|
|
62
|
+
return this.pathsGroupedByScope;
|
|
63
|
+
}
|
|
64
|
+
getGroupByPath(path) {
|
|
65
|
+
if (!this.pathsGroupedByScope)
|
|
66
|
+
return;
|
|
67
|
+
for (const value of Object.values(this.pathsGroupedByScope)) {
|
|
68
|
+
if (value.paths.includes(path))
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
groupByScopes(swagger, options) {
|
|
74
|
+
this.pathsGroupedByScope = this.groupPaths(swagger.paths, options);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Groups OpenAPI paths based on the specified mode (tags or path).
|
|
78
|
+
*
|
|
79
|
+
* @param paths - The OpenAPI paths object to group.
|
|
80
|
+
* @param options - Configuration for grouping:
|
|
81
|
+
* - `mode`: 'tags' to group by OpenAPI tags, or 'path' to group by path segments.
|
|
82
|
+
* - `segmentsToIgnore`: (mode 'path' only) Array of path segments to skip during normalization.
|
|
83
|
+
* - `ignoreVariables`: (mode 'path' only) Whether to ignore template variables like {id} during grouping.
|
|
84
|
+
* @returns A record where keys are group names and values are GroupedPath objects.
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* When in 'path' mode, it creates primary groups using the first non-ignored segment.
|
|
88
|
+
* If a group contains more than 8 HTTP methods across all its paths, it attempts to
|
|
89
|
+
* create subgroups for paths that have at least 2 HTTP methods and additional segments.
|
|
90
|
+
*/
|
|
91
|
+
groupPaths(paths, options = { mode: "tags" }) {
|
|
92
|
+
if (options.mode === "tags") {
|
|
93
|
+
return this.groupByTags(paths, options);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return this.groupByPath(paths, options);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
groupByTags(paths, options) {
|
|
100
|
+
const tagGroups = {};
|
|
101
|
+
const methods = [
|
|
102
|
+
"get",
|
|
103
|
+
"put",
|
|
104
|
+
"post",
|
|
105
|
+
"delete",
|
|
106
|
+
"options",
|
|
107
|
+
"head",
|
|
108
|
+
"patch",
|
|
109
|
+
"trace",
|
|
110
|
+
];
|
|
111
|
+
for (const [pathKey, pathItem] of Object.entries(paths)) {
|
|
112
|
+
if (!pathItem)
|
|
113
|
+
continue;
|
|
114
|
+
const tags = new Set();
|
|
115
|
+
for (const method of methods) {
|
|
116
|
+
const operation = pathItem[method];
|
|
117
|
+
if (operation?.tags && operation.tags.length > 0) {
|
|
118
|
+
operation.tags.forEach((tag) => tags.add((0, string_utils_1.removeAllWhitespace)(tag)));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (tags.size === 0) {
|
|
122
|
+
const groupKey = "Default";
|
|
123
|
+
if (!tagGroups[groupKey])
|
|
124
|
+
tagGroups[groupKey] = [];
|
|
125
|
+
tagGroups[groupKey].push(pathKey);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
tags.forEach((tag) => {
|
|
129
|
+
if (!tagGroups[tag])
|
|
130
|
+
tagGroups[tag] = [];
|
|
131
|
+
tagGroups[tag].push(pathKey);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const finalGroups = {};
|
|
136
|
+
const sortedTags = Object.keys(tagGroups).sort();
|
|
137
|
+
for (const tagName of sortedTags) {
|
|
138
|
+
const pathKeys = tagGroups[tagName].sort();
|
|
139
|
+
const totalMethods = pathKeys.reduce((sum, pk) => sum + this.getMethodCount(paths[pk]), 0);
|
|
140
|
+
if (totalMethods <= 8) {
|
|
141
|
+
const groupName = (0, string_utils_1.toPascalCase)([tagName]);
|
|
142
|
+
finalGroups[groupName] = {
|
|
143
|
+
groupName,
|
|
144
|
+
baseSegments: this.getCommonSegments(pathKeys),
|
|
145
|
+
paths: pathKeys,
|
|
146
|
+
baseUrl: (0, path_utils_1.findCommonBaseUrl)(pathKeys),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
// Find common segments of this tag group to start splitting from a meaningful depth
|
|
151
|
+
const commonSegs = this.getCommonSegments(pathKeys);
|
|
152
|
+
// But we want the group names to start with the TagName
|
|
153
|
+
this.splitRecursively(paths, pathKeys, commonSegs, options, finalGroups, commonSegs.length, tagName);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return finalGroups;
|
|
157
|
+
}
|
|
158
|
+
groupByPath(paths, options) {
|
|
159
|
+
const finalGroups = {};
|
|
160
|
+
const pathKeys = Object.keys(paths).filter((k) => !!paths[k]);
|
|
161
|
+
// 1. Initial primary grouping by the first non-ignored segment
|
|
162
|
+
const initialBuckets = {};
|
|
163
|
+
for (const pk of pathKeys) {
|
|
164
|
+
const normalized = this.getNormalizedSegments(pk, options);
|
|
165
|
+
const first = normalized.length > 0 ? normalized[0] : "Default";
|
|
166
|
+
if (!initialBuckets[first])
|
|
167
|
+
initialBuckets[first] = [];
|
|
168
|
+
initialBuckets[first].push(pk);
|
|
169
|
+
}
|
|
170
|
+
const sortedPrimaryKeys = Object.keys(initialBuckets).sort();
|
|
171
|
+
for (const primaryKey of sortedPrimaryKeys) {
|
|
172
|
+
const pathsInBucket = initialBuckets[primaryKey];
|
|
173
|
+
const prefix = primaryKey === "Default" ? [] : [primaryKey];
|
|
174
|
+
this.splitRecursively(paths, pathsInBucket, prefix, options, finalGroups, 0);
|
|
175
|
+
}
|
|
176
|
+
// Ensure the resulting groups are deterministic
|
|
177
|
+
const sortedResult = {};
|
|
178
|
+
const sortedGroupNames = Object.keys(finalGroups).sort();
|
|
179
|
+
for (const name of sortedGroupNames) {
|
|
180
|
+
sortedResult[name] = finalGroups[name];
|
|
181
|
+
}
|
|
182
|
+
return sortedResult;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Recursively splits a group of paths based on their segments if the method count threshold is exceeded.
|
|
186
|
+
*/
|
|
187
|
+
splitRecursively(allPaths, currentPaths, currentPrefix, options, finalGroups, initialDepth, customNamePrefix) {
|
|
188
|
+
const totalMethods = currentPaths.reduce((sum, pk) => sum + this.getMethodCount(allPaths[pk]), 0);
|
|
189
|
+
const depth = currentPrefix.length;
|
|
190
|
+
// Condition 1: If small enough, keep as one group.
|
|
191
|
+
if (totalMethods <= 8) {
|
|
192
|
+
this.addToFinalGroups(currentPaths, currentPrefix, finalGroups, initialDepth, customNamePrefix);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
// Attempt to split.
|
|
196
|
+
const stayers = [];
|
|
197
|
+
const branchMap = {};
|
|
198
|
+
for (const pk of currentPaths) {
|
|
199
|
+
const normalized = this.getNormalizedSegments(pk, options);
|
|
200
|
+
if (normalized.length > depth) {
|
|
201
|
+
const next = normalized[depth];
|
|
202
|
+
if (!branchMap[next])
|
|
203
|
+
branchMap[next] = [];
|
|
204
|
+
branchMap[next].push(pk);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
stayers.push(pk);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const nextSegs = Object.keys(branchMap);
|
|
211
|
+
// If no possible split (no more segments), stop.
|
|
212
|
+
if (nextSegs.length === 0) {
|
|
213
|
+
this.addToFinalGroups(currentPaths, currentPrefix, finalGroups, initialDepth, customNamePrefix);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
// Identify which branches can move.
|
|
217
|
+
// A path (or group of paths) can move ONLY if it has >= 2 methods.
|
|
218
|
+
const movingBranches = [];
|
|
219
|
+
const remainingToStay = [...stayers];
|
|
220
|
+
for (const seg of nextSegs) {
|
|
221
|
+
const paths = branchMap[seg];
|
|
222
|
+
const count = paths.reduce((sum, pk) => sum + this.getMethodCount(allPaths[pk]), 0);
|
|
223
|
+
if (count >= 2) {
|
|
224
|
+
movingBranches.push({ seg, paths });
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
remainingToStay.push(...paths);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// If no branches can move according to the 2-method rule, stop and keep everything here.
|
|
231
|
+
if (movingBranches.length === 0) {
|
|
232
|
+
this.addToFinalGroups(currentPaths, currentPrefix, finalGroups, initialDepth, customNamePrefix);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
// Optimization: If only one branch can move and no stayers, zip prefix.
|
|
236
|
+
if (movingBranches.length === 1 && remainingToStay.length === 0) {
|
|
237
|
+
this.splitRecursively(allPaths, currentPaths, [...currentPrefix, movingBranches[0].seg], options, finalGroups, initialDepth, customNamePrefix);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
// Otherwise, split: remainingToStay form the group at current level, movingBranches recurse.
|
|
241
|
+
if (remainingToStay.length > 0) {
|
|
242
|
+
this.addToFinalGroups(remainingToStay, currentPrefix, finalGroups, initialDepth, customNamePrefix);
|
|
243
|
+
}
|
|
244
|
+
for (const branch of movingBranches.sort((a, b) => a.seg.localeCompare(b.seg))) {
|
|
245
|
+
this.splitRecursively(allPaths, branch.paths, [...currentPrefix, branch.seg], options, finalGroups, initialDepth, customNamePrefix);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
addToFinalGroups(paths, prefix, finalGroups, initialDepth, customNamePrefix) {
|
|
249
|
+
let groupName;
|
|
250
|
+
if (customNamePrefix) {
|
|
251
|
+
const trailing = prefix.slice(initialDepth);
|
|
252
|
+
groupName = (0, string_utils_1.toPascalCase)([customNamePrefix, ...trailing]);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
groupName = prefix.length > 0 ? (0, string_utils_1.toPascalCase)(prefix) : "Default";
|
|
256
|
+
}
|
|
257
|
+
if (finalGroups[groupName]) {
|
|
258
|
+
const existing = finalGroups[groupName];
|
|
259
|
+
existing.paths = [...new Set([...existing.paths, ...paths])].sort();
|
|
260
|
+
existing.baseSegments = this.getCommonSegments(existing.paths);
|
|
261
|
+
existing.baseUrl = (0, path_utils_1.findCommonBaseUrl)(existing.paths);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
finalGroups[groupName] = {
|
|
265
|
+
groupName,
|
|
266
|
+
baseSegments: this.getCommonSegments(paths),
|
|
267
|
+
paths: paths.sort(),
|
|
268
|
+
baseUrl: (0, path_utils_1.findCommonBaseUrl)(paths),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
getNormalizedSegments(path, options) {
|
|
273
|
+
const segments = path.split("/").filter((s) => s);
|
|
274
|
+
const result = [];
|
|
275
|
+
for (const segment of segments) {
|
|
276
|
+
if (options.segmentsToIgnore?.includes(segment))
|
|
277
|
+
continue;
|
|
278
|
+
if (options.ignoreVariables && (0, path_utils_1.isVariable)(segment))
|
|
279
|
+
continue;
|
|
280
|
+
result.push(segment);
|
|
281
|
+
}
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
getMethodCount(pathItem) {
|
|
285
|
+
const methods = [
|
|
286
|
+
"get",
|
|
287
|
+
"put",
|
|
288
|
+
"post",
|
|
289
|
+
"delete",
|
|
290
|
+
"options",
|
|
291
|
+
"head",
|
|
292
|
+
"patch",
|
|
293
|
+
"trace",
|
|
294
|
+
];
|
|
295
|
+
let count = 0;
|
|
296
|
+
for (const method of methods) {
|
|
297
|
+
if (pathItem[method]) {
|
|
298
|
+
count++;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return count;
|
|
302
|
+
}
|
|
303
|
+
getCommonSegments(paths) {
|
|
304
|
+
if (paths.length === 0)
|
|
305
|
+
return [];
|
|
306
|
+
const pathSegments = paths.map((p) => p
|
|
307
|
+
.replace(/^\/+api\/+/, "")
|
|
308
|
+
.split("/")
|
|
309
|
+
.filter((s) => s));
|
|
310
|
+
const firstPath = pathSegments[0];
|
|
311
|
+
const common = [];
|
|
312
|
+
for (let i = 0; i < firstPath.length; i++) {
|
|
313
|
+
const segment = firstPath[i];
|
|
314
|
+
if (pathSegments.every((ps) => ps[i] === segment)) {
|
|
315
|
+
common.push(segment);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return common;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
exports.swaggerStore = new SwaggerStore();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.angularServiceTemplate = void 0;
|
|
4
|
+
const angularServiceTemplate = (params) => {
|
|
5
|
+
return `
|
|
6
|
+
import { HttpClient } from "@angular/common/http";
|
|
7
|
+
import { Observable } from "rxjs";
|
|
8
|
+
import { inject, Injectable } from '@angular/core';
|
|
9
|
+
import { ${params.imports} } from '../../models';
|
|
10
|
+
import { HttpHelper } from '@umss/shared/utils';
|
|
11
|
+
|
|
12
|
+
@Injectable({
|
|
13
|
+
providedIn: "root"
|
|
14
|
+
})
|
|
15
|
+
export class ${params.name}Service {
|
|
16
|
+
|
|
17
|
+
private readonly baseUrl = "${params.baseUrl}";
|
|
18
|
+
private readonly http = inject(HttpClient);
|
|
19
|
+
|
|
20
|
+
${params.methods}
|
|
21
|
+
}`;
|
|
22
|
+
};
|
|
23
|
+
exports.angularServiceTemplate = angularServiceTemplate;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pagedRequestTemplate = void 0;
|
|
4
|
+
exports.pagedRequestTemplate = `
|
|
5
|
+
export interface PagedRequestDto {
|
|
6
|
+
/**
|
|
7
|
+
* format: int32
|
|
8
|
+
* maximum: 2147483647
|
|
9
|
+
* minimum: 1
|
|
10
|
+
*/
|
|
11
|
+
pageNumber?: number;
|
|
12
|
+
/**
|
|
13
|
+
* format: int32
|
|
14
|
+
* maximum: 100
|
|
15
|
+
* minimum: 1
|
|
16
|
+
*/
|
|
17
|
+
pageSize?: number;
|
|
18
|
+
searchTerm?: string | null;
|
|
19
|
+
sortBy?: string | null;
|
|
20
|
+
sortDescending?: boolean;
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pagedResultTemplate = void 0;
|
|
4
|
+
exports.pagedResultTemplate = `
|
|
5
|
+
export interface PagedResultDto<T> {
|
|
6
|
+
items: T[];
|
|
7
|
+
totalCount: number;
|
|
8
|
+
pageNumber: number;
|
|
9
|
+
pageSize: number;
|
|
10
|
+
totalPages: number;
|
|
11
|
+
hasPreviousPage: boolean;
|
|
12
|
+
hasNextPage: boolean;
|
|
13
|
+
}`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface AngularServiceTemplate {
|
|
2
|
+
name: string;
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
methods: string;
|
|
5
|
+
imports: string;
|
|
6
|
+
hasHttpParamsHandler: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface AngularServiceResult {
|
|
9
|
+
forTemplate: AngularServiceTemplate[];
|
|
10
|
+
parametersTypes: Record<string, {
|
|
11
|
+
method: string;
|
|
12
|
+
parameterType: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
export declare const angularTemplate: (params: AngularServiceTemplate) => string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.angularTemplate = void 0;
|
|
4
|
+
const http_params_handler_1 = require("./http-params-handler");
|
|
5
|
+
const angularTemplate = (params) => {
|
|
6
|
+
return `
|
|
7
|
+
import { HttpClient } from "@angular/common/http";
|
|
8
|
+
import { Observable } from "rxjs";
|
|
9
|
+
import { inject, Injectable } from '@angular/core';
|
|
10
|
+
import { ${params.imports} } from '../../models';
|
|
11
|
+
${params.hasHttpParamsHandler ? (0, http_params_handler_1.httpParamsHandlerImport)() : ''}
|
|
12
|
+
|
|
13
|
+
@Injectable({
|
|
14
|
+
providedIn: "root"
|
|
15
|
+
})
|
|
16
|
+
export class ${params.name}Service {
|
|
17
|
+
|
|
18
|
+
private readonly baseUrl = "${params.baseUrl}";
|
|
19
|
+
private readonly http = inject(HttpClient);
|
|
20
|
+
|
|
21
|
+
${params.methods}
|
|
22
|
+
}`;
|
|
23
|
+
};
|
|
24
|
+
exports.angularTemplate = angularTemplate;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.httpParamsHandler = httpParamsHandler;
|
|
4
|
+
exports.httpParamsHandlerImport = httpParamsHandlerImport;
|
|
5
|
+
function httpParamsHandler(params) {
|
|
6
|
+
return `
|
|
7
|
+
const params = HttpHelper.toHttpParams(${params} || {})
|
|
8
|
+
`;
|
|
9
|
+
}
|
|
10
|
+
function httpParamsHandlerImport() {
|
|
11
|
+
return `import { HttpHelper } from '@umss/shared/utils';`;
|
|
12
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extendsFromTypes = void 0;
|
|
4
|
+
exports.computeExtendsFromType = computeExtendsFromType;
|
|
5
|
+
exports.extendsFromTypes = [
|
|
6
|
+
{
|
|
7
|
+
name: 'PagedRequestDto',
|
|
8
|
+
type: 'interface',
|
|
9
|
+
imports: [],
|
|
10
|
+
properties: [
|
|
11
|
+
{
|
|
12
|
+
name: 'pageNumber',
|
|
13
|
+
type: 'number',
|
|
14
|
+
optional: true,
|
|
15
|
+
comments: `/**
|
|
16
|
+
* maximum: 2147483647,
|
|
17
|
+
* minimum: 1,
|
|
18
|
+
* format: "int32"
|
|
19
|
+
*/`,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'pageSize',
|
|
23
|
+
type: 'number',
|
|
24
|
+
optional: true,
|
|
25
|
+
comments: `/**
|
|
26
|
+
* maximum: 100,
|
|
27
|
+
* minimum: 1,
|
|
28
|
+
* format: "int32"
|
|
29
|
+
*/`,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'searchTerm',
|
|
33
|
+
type: 'string',
|
|
34
|
+
optional: true,
|
|
35
|
+
comments: '',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'sortBy',
|
|
39
|
+
type: 'string',
|
|
40
|
+
optional: true,
|
|
41
|
+
comments: '',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'sortDescending',
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
optional: true,
|
|
47
|
+
comments: '',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
function computeExtendsFromType(newInterface) {
|
|
53
|
+
for (const extendsFromType of exports.extendsFromTypes) {
|
|
54
|
+
const newinterfacePropertiesReq = newInterface.properties
|
|
55
|
+
.filter((p) => !p.optional)
|
|
56
|
+
.map((p) => p.name);
|
|
57
|
+
const extendsFromTypePropertiesReq = extendsFromType.properties
|
|
58
|
+
.filter((p) => !p.optional)
|
|
59
|
+
.map((p) => p.name);
|
|
60
|
+
if (extendsFromTypePropertiesReq.some((p) => !newinterfacePropertiesReq.includes(p))) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const extensionProperties = extendsFromType.properties.map((p) => p.name.toLowerCase());
|
|
64
|
+
return {
|
|
65
|
+
...newInterface,
|
|
66
|
+
properties: newInterface.properties.filter((p) => !extensionProperties.includes(p.name.toLowerCase())),
|
|
67
|
+
imports: [...newInterface.imports, extendsFromType.name],
|
|
68
|
+
extendsFrom: [...(newInterface.extendsFrom ?? []), extendsFromType.name],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return newInterface;
|
|
72
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { InterfaceData } from '../../types/interface-data';
|
|
2
|
+
export declare const genericTypesData: InterfaceData[];
|
|
3
|
+
export declare function isGenericType(newInterface: InterfaceData): InterfaceData | undefined;
|
|
4
|
+
export declare function computeGenericType(newInterface: InterfaceData, genericType: InterfaceData): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genericTypesData = void 0;
|
|
4
|
+
exports.isGenericType = isGenericType;
|
|
5
|
+
exports.computeGenericType = computeGenericType;
|
|
6
|
+
exports.genericTypesData = [
|
|
7
|
+
{
|
|
8
|
+
name: 'PagedResultDto',
|
|
9
|
+
imports: [],
|
|
10
|
+
type: 'interface',
|
|
11
|
+
properties: [
|
|
12
|
+
{
|
|
13
|
+
name: 'items',
|
|
14
|
+
type: 'T[]',
|
|
15
|
+
optional: false,
|
|
16
|
+
comments: '',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'totalCount',
|
|
20
|
+
type: 'number',
|
|
21
|
+
optional: false,
|
|
22
|
+
comments: '',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'pageNumber',
|
|
26
|
+
type: 'number',
|
|
27
|
+
optional: false,
|
|
28
|
+
comments: '',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'pageSize',
|
|
32
|
+
type: 'number',
|
|
33
|
+
optional: false,
|
|
34
|
+
comments: '',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'totalPages',
|
|
38
|
+
type: 'number',
|
|
39
|
+
optional: false,
|
|
40
|
+
comments: '',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'hasPreviousPage',
|
|
44
|
+
type: 'boolean',
|
|
45
|
+
optional: false,
|
|
46
|
+
comments: '',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'hasNextPage',
|
|
50
|
+
type: 'boolean',
|
|
51
|
+
optional: false,
|
|
52
|
+
comments: '',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
function isGenericType(newInterface) {
|
|
58
|
+
for (const genericType of exports.genericTypesData) {
|
|
59
|
+
if (genericType.properties.length !== newInterface.properties.length)
|
|
60
|
+
continue;
|
|
61
|
+
const newinterfaceProperties = newInterface.properties.map((p) => p.name);
|
|
62
|
+
const genericTypeProperties = genericType.properties.map((p) => p.name);
|
|
63
|
+
if (genericTypeProperties.some((p) => !newinterfaceProperties.includes(p)))
|
|
64
|
+
continue;
|
|
65
|
+
return genericType;
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
function computeGenericType(newInterface, genericType) {
|
|
70
|
+
const newName = newInterface.name.replaceAll(genericType.name, '');
|
|
71
|
+
return `${genericType.name}<${newName}>`;
|
|
72
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addImportToInterface = addImportToInterface;
|
|
4
|
+
function addImportToInterface(interfaceString, imports, commons, modelInPath) {
|
|
5
|
+
const commonImports = commons.filter((c) => imports.includes(c));
|
|
6
|
+
let commonImportString = "";
|
|
7
|
+
if (commonImports.length > 0) {
|
|
8
|
+
commonImportString = `import { ${commonImports.join(", ")} } from "../../common";`;
|
|
9
|
+
}
|
|
10
|
+
const dtosImports = [];
|
|
11
|
+
for (const [model, path] of Object.entries(modelInPath)) {
|
|
12
|
+
if (!path)
|
|
13
|
+
continue;
|
|
14
|
+
if (!imports.includes(model))
|
|
15
|
+
continue;
|
|
16
|
+
const [outerKey, innerKey] = path;
|
|
17
|
+
const modelName = innerKey.replace(".dto.ts", "");
|
|
18
|
+
dtosImports.push(`import { ${modelName} } from "../${outerKey}/${innerKey}";`);
|
|
19
|
+
}
|
|
20
|
+
return `${commonImportString.length > 0 ? commonImportString + "\n" : ""}${dtosImports.join("\n")}\n${interfaceString}`;
|
|
21
|
+
}
|