@orval/angular 6.19.1 → 6.21.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/dist/index.js +194 -21
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
builder: () => builder,
|
|
24
|
+
default: () => src_default,
|
|
25
|
+
generateAngular: () => generateAngular,
|
|
26
|
+
generateAngularFooter: () => generateAngularFooter,
|
|
27
|
+
generateAngularHeader: () => generateAngularHeader,
|
|
28
|
+
generateAngularTitle: () => generateAngularTitle,
|
|
29
|
+
getAngularDependencies: () => getAngularDependencies
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(src_exports);
|
|
32
|
+
var import_core = require("@orval/core");
|
|
33
|
+
var ANGULAR_DEPENDENCIES = [
|
|
34
|
+
{
|
|
35
|
+
exports: [
|
|
36
|
+
{ name: "HttpClient", values: true },
|
|
37
|
+
{ name: "HttpHeaders" },
|
|
38
|
+
{ name: "HttpParams" },
|
|
39
|
+
{ name: "HttpContext" }
|
|
40
|
+
],
|
|
41
|
+
dependency: "@angular/common/http"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
exports: [{ name: "Injectable", values: true }],
|
|
45
|
+
dependency: "@angular/core"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
exports: [{ name: "Observable", values: true }],
|
|
49
|
+
dependency: "rxjs"
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
var returnTypesToWrite = /* @__PURE__ */ new Map();
|
|
53
|
+
var getAngularDependencies = () => ANGULAR_DEPENDENCIES;
|
|
54
|
+
var generateAngularTitle = (title) => {
|
|
55
|
+
const sanTitle = (0, import_core.sanitize)(title);
|
|
56
|
+
return `${(0, import_core.pascal)(sanTitle)}Service`;
|
|
57
|
+
};
|
|
58
|
+
var generateAngularHeader = ({
|
|
59
|
+
title,
|
|
60
|
+
isRequestOptions,
|
|
61
|
+
isMutator,
|
|
62
|
+
isGlobalMutator,
|
|
63
|
+
provideIn
|
|
64
|
+
}) => `
|
|
65
|
+
${isRequestOptions && !isGlobalMutator ? `type HttpClientOptions = {
|
|
3
66
|
headers?: HttpHeaders | {
|
|
4
67
|
[header: string]: string | string[];
|
|
5
68
|
};
|
|
@@ -11,35 +74,145 @@ ${t&&!r?`type HttpClientOptions = {
|
|
|
11
74
|
reportProgress?: boolean;
|
|
12
75
|
responseType?: any;
|
|
13
76
|
withCredentials?: boolean;
|
|
14
|
-
}
|
|
77
|
+
};` : ""}
|
|
15
78
|
|
|
16
|
-
${
|
|
79
|
+
${isRequestOptions && isMutator ? `// eslint-disable-next-line
|
|
17
80
|
type ThirdParameter<T extends (...args: any) => any> = T extends (
|
|
18
81
|
config: any,
|
|
19
82
|
httpClient: any,
|
|
20
83
|
args: infer P,
|
|
21
84
|
) => any
|
|
22
85
|
? P
|
|
23
|
-
: never
|
|
86
|
+
: never;` : ""}
|
|
24
87
|
|
|
25
|
-
@Injectable(${
|
|
26
|
-
export class ${
|
|
88
|
+
@Injectable(${provideIn ? `{ providedIn: '${(0, import_core.isBoolean)(provideIn) ? "root" : provideIn}' }` : ""})
|
|
89
|
+
export class ${title} {
|
|
27
90
|
constructor(
|
|
28
91
|
private http: HttpClient,
|
|
29
|
-
) {}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
92
|
+
) {}`;
|
|
93
|
+
var generateAngularFooter = ({
|
|
94
|
+
operationNames
|
|
95
|
+
}) => {
|
|
96
|
+
let footer = "};\n\n";
|
|
97
|
+
operationNames.forEach((operationName) => {
|
|
98
|
+
if (returnTypesToWrite.has(operationName)) {
|
|
99
|
+
footer += returnTypesToWrite.get(operationName) + "\n";
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return footer;
|
|
103
|
+
};
|
|
104
|
+
var generateImplementation = ({
|
|
105
|
+
headers,
|
|
106
|
+
queryParams,
|
|
107
|
+
operationName,
|
|
108
|
+
response,
|
|
109
|
+
mutator,
|
|
110
|
+
body,
|
|
111
|
+
props,
|
|
112
|
+
verb,
|
|
113
|
+
override,
|
|
114
|
+
formData,
|
|
115
|
+
formUrlEncoded,
|
|
116
|
+
paramsSerializer
|
|
117
|
+
}, { route, context }) => {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
const isRequestOptions = (override == null ? void 0 : override.requestOptions) !== false;
|
|
120
|
+
const isFormData = (override == null ? void 0 : override.formData) !== false;
|
|
121
|
+
const isFormUrlEncoded = (override == null ? void 0 : override.formUrlEncoded) !== false;
|
|
122
|
+
const isExactOptionalPropertyTypes = !!((_b = (_a = context.tsconfig) == null ? void 0 : _a.compilerOptions) == null ? void 0 : _b.exactOptionalPropertyTypes);
|
|
123
|
+
const isBodyVerb = import_core.VERBS_WITH_BODY.includes(verb);
|
|
124
|
+
const bodyForm = (0, import_core.generateFormDataAndUrlEncodedFunction)({
|
|
125
|
+
formData,
|
|
126
|
+
formUrlEncoded,
|
|
127
|
+
body,
|
|
128
|
+
isFormData,
|
|
129
|
+
isFormUrlEncoded
|
|
130
|
+
});
|
|
131
|
+
const dataType = response.definition.success || "unknown";
|
|
132
|
+
returnTypesToWrite.set(
|
|
133
|
+
operationName,
|
|
134
|
+
`export type ${(0, import_core.pascal)(
|
|
135
|
+
operationName
|
|
136
|
+
)}ClientResult = NonNullable<${dataType}>`
|
|
137
|
+
);
|
|
138
|
+
if (mutator) {
|
|
139
|
+
const mutatorConfig = (0, import_core.generateMutatorConfig)({
|
|
140
|
+
route,
|
|
141
|
+
body,
|
|
142
|
+
headers,
|
|
143
|
+
queryParams,
|
|
144
|
+
response,
|
|
145
|
+
verb,
|
|
146
|
+
isFormData,
|
|
147
|
+
isFormUrlEncoded,
|
|
148
|
+
hasSignal: false,
|
|
149
|
+
isBodyVerb,
|
|
150
|
+
isExactOptionalPropertyTypes
|
|
151
|
+
});
|
|
152
|
+
const requestOptions = isRequestOptions ? (0, import_core.generateMutatorRequestOptions)(
|
|
153
|
+
override == null ? void 0 : override.requestOptions,
|
|
154
|
+
mutator.hasThirdArg
|
|
155
|
+
) : "";
|
|
156
|
+
const propsImplementation = mutator.bodyTypeName && body.definition ? (0, import_core.toObjectString)(props, "implementation").replace(
|
|
157
|
+
new RegExp(`(\\w*):\\s?${body.definition}`),
|
|
158
|
+
`$1: ${mutator.bodyTypeName}<${body.definition}>`
|
|
159
|
+
) : (0, import_core.toObjectString)(props, "implementation");
|
|
160
|
+
return ` ${operationName}<TData = ${dataType}>(
|
|
161
|
+
${propsImplementation}
|
|
162
|
+
${isRequestOptions && mutator.hasThirdArg ? `options?: ThirdParameter<typeof ${mutator.name}>` : ""}) {${bodyForm}
|
|
163
|
+
return ${mutator.name}<TData>(
|
|
164
|
+
${mutatorConfig},
|
|
37
165
|
this.http,
|
|
38
|
-
${
|
|
166
|
+
${requestOptions});
|
|
39
167
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
168
|
+
`;
|
|
169
|
+
}
|
|
170
|
+
const options = (0, import_core.generateOptions)({
|
|
171
|
+
route,
|
|
172
|
+
body,
|
|
173
|
+
headers,
|
|
174
|
+
queryParams,
|
|
175
|
+
response,
|
|
176
|
+
verb,
|
|
177
|
+
requestOptions: override == null ? void 0 : override.requestOptions,
|
|
178
|
+
isFormData,
|
|
179
|
+
isFormUrlEncoded,
|
|
180
|
+
paramsSerializer,
|
|
181
|
+
paramsSerializerOptions: override == null ? void 0 : override.paramsSerializerOptions,
|
|
182
|
+
isAngular: true,
|
|
183
|
+
isExactOptionalPropertyTypes,
|
|
184
|
+
hasSignal: false
|
|
185
|
+
});
|
|
186
|
+
return ` ${operationName}<TData = ${dataType}>(
|
|
187
|
+
${(0, import_core.toObjectString)(
|
|
188
|
+
props,
|
|
189
|
+
"implementation"
|
|
190
|
+
)} ${isRequestOptions ? `options?: HttpClientOptions
|
|
191
|
+
` : ""} ): Observable<TData> {${bodyForm}
|
|
192
|
+
return this.http.${verb}<TData>(${options});
|
|
44
193
|
}
|
|
45
|
-
|
|
194
|
+
`;
|
|
195
|
+
};
|
|
196
|
+
var generateAngular = (verbOptions, options) => {
|
|
197
|
+
const imports = (0, import_core.generateVerbImports)(verbOptions);
|
|
198
|
+
const implementation = generateImplementation(verbOptions, options);
|
|
199
|
+
return { implementation, imports };
|
|
200
|
+
};
|
|
201
|
+
var angularClientBuilder = {
|
|
202
|
+
client: generateAngular,
|
|
203
|
+
header: generateAngularHeader,
|
|
204
|
+
dependencies: getAngularDependencies,
|
|
205
|
+
footer: generateAngularFooter,
|
|
206
|
+
title: generateAngularTitle
|
|
207
|
+
};
|
|
208
|
+
var builder = () => () => angularClientBuilder;
|
|
209
|
+
var src_default = builder;
|
|
210
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
211
|
+
0 && (module.exports = {
|
|
212
|
+
builder,
|
|
213
|
+
generateAngular,
|
|
214
|
+
generateAngularFooter,
|
|
215
|
+
generateAngularHeader,
|
|
216
|
+
generateAngularTitle,
|
|
217
|
+
getAngularDependencies
|
|
218
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orval/angular",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.21.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "tsup ./src/index.ts --target node12 --
|
|
11
|
+
"build": "tsup ./src/index.ts --target node12 --clean --dts",
|
|
12
12
|
"dev": "tsup ./src/index.ts --target node12 --clean --watch src",
|
|
13
13
|
"lint": "eslint src/**/*.ts"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@orval/core": "6.
|
|
16
|
+
"@orval/core": "6.21.0"
|
|
17
17
|
}
|
|
18
18
|
}
|