@goast/typescript 0.3.1 → 0.3.3
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 +2 -0
- package/assets/client/k6/request-builder.js +411 -0
- package/cjs/lib/ast/nodes/method.js +9 -6
- package/cjs/lib/ast/nodes/reference.js +9 -4
- package/cjs/lib/ast/references/index.js +2 -1
- package/cjs/lib/ast/references/k6.js +9 -0
- package/cjs/lib/file-builder.js +9 -4
- package/cjs/lib/generators/index.js +2 -1
- package/cjs/lib/generators/models/model-generator.js +1 -1
- package/cjs/lib/generators/services/k6-clients/index.js +6 -0
- package/cjs/lib/generators/services/k6-clients/k6-client-generator.js +311 -0
- package/cjs/lib/generators/services/k6-clients/k6-clients-generator.js +116 -0
- package/cjs/lib/generators/services/k6-clients/models.js +28 -0
- package/cjs/lib/generators/services/k6-clients/refs.js +12 -0
- package/cjs/lib/import-collection.js +49 -7
- package/esm/lib/ast/nodes/method.js +9 -6
- package/esm/lib/ast/nodes/reference.js +9 -4
- package/esm/lib/ast/references/index.js +2 -0
- package/esm/lib/ast/references/k6.js +6 -0
- package/esm/lib/file-builder.js +9 -4
- package/esm/lib/generators/index.js +2 -1
- package/esm/lib/generators/models/model-generator.js +1 -1
- package/esm/lib/generators/services/k6-clients/index.js +3 -0
- package/esm/lib/generators/services/k6-clients/k6-client-generator.js +307 -0
- package/esm/lib/generators/services/k6-clients/k6-clients-generator.js +112 -0
- package/esm/lib/generators/services/k6-clients/models.js +25 -0
- package/esm/lib/generators/services/k6-clients/refs.js +9 -0
- package/esm/lib/import-collection.js +49 -7
- package/package.json +3 -3
- package/types/lib/ast/nodes/method.d.ts +2 -0
- package/types/lib/ast/nodes/reference.d.ts +8 -2
- package/types/lib/ast/references/angular.d.ts +21 -7
- package/types/lib/ast/references/easy-network-stub.d.ts +12 -4
- package/types/lib/ast/references/index.d.ts +1 -0
- package/types/lib/ast/references/k6.d.ts +24 -0
- package/types/lib/ast/references/rxjs.d.ts +15 -5
- package/types/lib/ast/references/typescript.d.ts +87 -29
- package/types/lib/common-results.d.ts +2 -0
- package/types/lib/file-builder.d.ts +3 -3
- package/types/lib/generators/index.d.ts +2 -1
- package/types/lib/generators/services/angular-services/refs.d.ts +21 -7
- package/types/lib/generators/services/easy-network-stub/refs.d.ts +27 -9
- package/types/lib/generators/services/fetch-clients/refs.d.ts +9 -3
- package/types/lib/generators/services/k6-clients/index.d.ts +3 -0
- package/types/lib/generators/services/k6-clients/k6-client-generator.d.ts +39 -0
- package/types/lib/generators/services/k6-clients/k6-clients-generator.d.ts +27 -0
- package/types/lib/generators/services/k6-clients/models.d.ts +118 -0
- package/types/lib/generators/services/k6-clients/refs.d.ts +20 -0
- package/types/lib/import-collection.d.ts +10 -3
package/README.md
CHANGED
|
@@ -35,6 +35,8 @@ main();
|
|
|
35
35
|
- Depends on the output of the `TypeScriptModelsGenerator` generator.
|
|
36
36
|
- [`TypeScriptEasyNetworkStubsGenerator`](https://github.com/MaSch0212/goast/wiki/TypeScript%20Easy%20Network%20Stubs%20Generator): Generates [easy-network-stub](https://github.com/LoaderB0T/easy-network-stub) classes from paths in the OpenAPI specification(s).
|
|
37
37
|
- Depends on the output of the `TypeScriptModelsGenerator` generator.
|
|
38
|
+
- [`TypeScriptK6ClientsGenerator`](https://github.com/MaSch0212/goast/wiki/TypeScript%20K6%20Clients%20Generator): Generates [k6](https://k6.io/) clients from paths in the OpenAPI specification(s).
|
|
39
|
+
- Depends on the output of the `TypeScriptModelsGenerator` generator.
|
|
38
40
|
|
|
39
41
|
## API Documentation 📖
|
|
40
42
|
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import http from 'k6/http';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Defines the options for appending a parameter
|
|
7
|
+
* @typedef {object} ParameterOptions
|
|
8
|
+
* @property {string} [style]
|
|
9
|
+
* @property {boolean} [explode]
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Base class for a parameter
|
|
14
|
+
* @abstract
|
|
15
|
+
* @property {string} name
|
|
16
|
+
* @property {*} value
|
|
17
|
+
* @property {ParameterOptions} options
|
|
18
|
+
*/
|
|
19
|
+
class Parameter {
|
|
20
|
+
/**
|
|
21
|
+
* @param {string} name
|
|
22
|
+
* @param {*} value
|
|
23
|
+
* @param {ParameterOptions} options
|
|
24
|
+
* @param {string} defaultStyle
|
|
25
|
+
* @param {boolean} defaultExplode
|
|
26
|
+
*/
|
|
27
|
+
constructor(name, value, options, defaultStyle, defaultExplode) {
|
|
28
|
+
this.name = name;
|
|
29
|
+
this.value = value;
|
|
30
|
+
this.options = options || {};
|
|
31
|
+
if (this.options.style === null || this.options.style === undefined) {
|
|
32
|
+
this.options.style = defaultStyle;
|
|
33
|
+
}
|
|
34
|
+
if (this.options.explode === null || this.options.explode === undefined) {
|
|
35
|
+
this.options.explode = defaultExplode;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {*} value
|
|
41
|
+
* @param {string} separator
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
serializeValue(value, separator = ',') {
|
|
45
|
+
if (value === null || value === undefined) {
|
|
46
|
+
return '';
|
|
47
|
+
} else if (value instanceof Array) {
|
|
48
|
+
return value
|
|
49
|
+
.map((v) => this.serializeValue(v).split(separator).join(encodeURIComponent(separator)))
|
|
50
|
+
.join(separator);
|
|
51
|
+
} else if (typeof value === 'object') {
|
|
52
|
+
/** @type {string[]} */
|
|
53
|
+
const array = [];
|
|
54
|
+
for (const key of Object.keys(value)) {
|
|
55
|
+
let propVal = value[key];
|
|
56
|
+
if (propVal !== null && propVal !== undefined) {
|
|
57
|
+
propVal = this.serializeValue(propVal).split(separator).join(encodeURIComponent(separator));
|
|
58
|
+
if (this.options.explode) {
|
|
59
|
+
array.push(`${key}=${propVal}`);
|
|
60
|
+
} else {
|
|
61
|
+
array.push(key);
|
|
62
|
+
array.push(propVal);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return array.join(separator);
|
|
67
|
+
} else {
|
|
68
|
+
return String(value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A parameter in the operation path
|
|
75
|
+
* @param {string} name
|
|
76
|
+
* @param {*} value
|
|
77
|
+
* @param {ParameterOptions} options
|
|
78
|
+
*/
|
|
79
|
+
class PathParameter extends Parameter {
|
|
80
|
+
/**
|
|
81
|
+
* @param {string} name
|
|
82
|
+
* @param {*} value
|
|
83
|
+
* @param {ParameterOptions} options
|
|
84
|
+
*/
|
|
85
|
+
constructor(name, value, options) {
|
|
86
|
+
super(name, value, options, 'simple', false);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {string} path
|
|
91
|
+
* @returns {string}
|
|
92
|
+
*/
|
|
93
|
+
append(path) {
|
|
94
|
+
let value = this.value;
|
|
95
|
+
if (value === null || value === undefined) {
|
|
96
|
+
value = '';
|
|
97
|
+
}
|
|
98
|
+
let prefix = this.options.style === 'label' ? '.' : '';
|
|
99
|
+
const separator = this.options.explode ? (prefix === '' ? ',' : prefix) : ',';
|
|
100
|
+
let alreadySerialized = false;
|
|
101
|
+
if (this.options.style === 'matrix') {
|
|
102
|
+
// The parameter name is just used as prefix, except in some cases...
|
|
103
|
+
prefix = `;${this.name}=`;
|
|
104
|
+
if (this.options.explode && typeof value === 'object') {
|
|
105
|
+
prefix = ';';
|
|
106
|
+
if (value instanceof Array) {
|
|
107
|
+
// For arrays we have to repeat the name for each element
|
|
108
|
+
value = value.map((v) => `${this.name}=${this.serializeValue(v, ';')}`);
|
|
109
|
+
value = value.join(';');
|
|
110
|
+
alreadySerialized = true;
|
|
111
|
+
} else {
|
|
112
|
+
// For objects we have to put each the key / value pairs
|
|
113
|
+
value = this.serializeValue(value, ';');
|
|
114
|
+
alreadySerialized = true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
value = prefix + (alreadySerialized ? value : this.serializeValue(value, separator));
|
|
119
|
+
// Replace both the plain variable and the corresponding variant taking in the prefix and explode into account
|
|
120
|
+
path = path.replace(`{${this.name}}`, value);
|
|
121
|
+
path = path.replace(`{${prefix}${this.name}${this.options.explode ? '*' : ''}}`, value);
|
|
122
|
+
return path;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @param {*} value
|
|
127
|
+
* @param {string} separator
|
|
128
|
+
* @returns {string}
|
|
129
|
+
*/
|
|
130
|
+
serializeValue(value, separator = ',') {
|
|
131
|
+
let result = typeof value === 'string' ? encodeURIComponent(value) : super.serializeValue(value, separator);
|
|
132
|
+
result = result.replace(/%3D/g, '=');
|
|
133
|
+
result = result.replace(/%3B/g, ';');
|
|
134
|
+
result = result.replace(/%2C/g, ',');
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* A parameter in the query
|
|
141
|
+
* @param {string} name
|
|
142
|
+
* @param {*} value
|
|
143
|
+
* @param {ParameterOptions} options
|
|
144
|
+
*/
|
|
145
|
+
class QueryParameter extends Parameter {
|
|
146
|
+
/**
|
|
147
|
+
* @param {string} name
|
|
148
|
+
* @param {*} value
|
|
149
|
+
* @param {ParameterOptions} options
|
|
150
|
+
*/
|
|
151
|
+
constructor(name, value, options) {
|
|
152
|
+
super(name, value, options, 'form', true);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @param {string} params
|
|
157
|
+
* @returns {string}
|
|
158
|
+
*/
|
|
159
|
+
append(params) {
|
|
160
|
+
if (this.value instanceof Array) {
|
|
161
|
+
// Array serialization
|
|
162
|
+
if (this.options.explode) {
|
|
163
|
+
for (const v of this.value) {
|
|
164
|
+
params = `${params}${params ? '&' : '?'}${encodeURIComponent(this.name)}=${this.serializeValue(v)}`;
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
const separator =
|
|
168
|
+
this.options.style === 'spaceDelimited' ? ' ' : this.options.style === 'pipeDelimited' ? '|' : ',';
|
|
169
|
+
return `${params}${params ? '&' : '?'}${encodeURIComponent(this.name)}=${this.serializeValue(this.value, separator)}`;
|
|
170
|
+
}
|
|
171
|
+
} else if (this.value !== null && typeof this.value === 'object') {
|
|
172
|
+
// Object serialization
|
|
173
|
+
if (this.options.style === 'deepObject') {
|
|
174
|
+
// Append a parameter for each key, in the form `name[key]`
|
|
175
|
+
for (const key of Object.keys(this.value)) {
|
|
176
|
+
const propVal = this.value[key];
|
|
177
|
+
if (propVal !== null && propVal !== undefined) {
|
|
178
|
+
params = `${params}${params ? '&' : '?'}${encodeURIComponent(this.name)}[${encodeURIComponent(
|
|
179
|
+
key,
|
|
180
|
+
)}]=${this.serializeValue(propVal)}`;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
} else if (this.options.explode) {
|
|
184
|
+
// Append a parameter for each key without using the parameter name
|
|
185
|
+
for (const key of Object.keys(this.value)) {
|
|
186
|
+
const propVal = this.value[key];
|
|
187
|
+
if (propVal !== null && propVal !== undefined) {
|
|
188
|
+
params = `${params}${params ? '&' : '?'}${encodeURIComponent(key)}=${this.serializeValue(propVal)}`;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
// Append a single parameter whose values are a comma-separated list of key,value,key,value...
|
|
193
|
+
const array = [];
|
|
194
|
+
for (const key of Object.keys(this.value)) {
|
|
195
|
+
const propVal = this.value[key];
|
|
196
|
+
if (propVal !== null && propVal !== undefined) {
|
|
197
|
+
array.push(key);
|
|
198
|
+
array.push(propVal);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
params = `${params}${params ? '&' : '?'}${encodeURIComponent(this.name)}=${this.serializeValue(array)}`;
|
|
202
|
+
}
|
|
203
|
+
} else if (this.value !== null && this.value !== undefined) {
|
|
204
|
+
// Plain value
|
|
205
|
+
params = `${params}${params ? '&' : '?'}${encodeURIComponent(this.name)}=${this.serializeValue(this.value)}`;
|
|
206
|
+
}
|
|
207
|
+
return params;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* A parameter in the HTTP request header
|
|
213
|
+
*/
|
|
214
|
+
class HeaderParameter extends Parameter {
|
|
215
|
+
/**
|
|
216
|
+
* @param {string} name
|
|
217
|
+
* @param {*} value
|
|
218
|
+
* @param {ParameterOptions} options
|
|
219
|
+
*/
|
|
220
|
+
constructor(name, value, options) {
|
|
221
|
+
super(name, value, options, 'simple', false);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* @param {Object.<string, string>} headers
|
|
226
|
+
* @returns {Object.<string, string>}
|
|
227
|
+
*/
|
|
228
|
+
append(headers) {
|
|
229
|
+
if (this.value !== null && this.value !== undefined) {
|
|
230
|
+
if (this.value instanceof Array) {
|
|
231
|
+
throw new Error('Array header values are not supported');
|
|
232
|
+
} else {
|
|
233
|
+
headers[this.name] = this.serializeValue(this.value);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return headers;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Helper to build http requests from parameters
|
|
242
|
+
* @property {string} rootUrl
|
|
243
|
+
* @property {string} operationPath
|
|
244
|
+
* @property {string} method
|
|
245
|
+
*/
|
|
246
|
+
export class RequestBuilder {
|
|
247
|
+
/**
|
|
248
|
+
* @param {string} rootUrl
|
|
249
|
+
* @param {string} operationPath
|
|
250
|
+
* @param {string} method
|
|
251
|
+
*/
|
|
252
|
+
constructor(rootUrl, operationPath, method) {
|
|
253
|
+
this.rootUrl = rootUrl;
|
|
254
|
+
this.operationPath = operationPath;
|
|
255
|
+
this.method = method;
|
|
256
|
+
this._path = new Map();
|
|
257
|
+
this._query = new Map();
|
|
258
|
+
this._header = new Map();
|
|
259
|
+
this._bodyContent = null;
|
|
260
|
+
this._bodyContentType = undefined;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Sets a path parameter
|
|
265
|
+
* @param {string} name
|
|
266
|
+
* @param {*} value
|
|
267
|
+
* @param {ParameterOptions} [options]
|
|
268
|
+
*/
|
|
269
|
+
path(name, value, options) {
|
|
270
|
+
this._path.set(name, new PathParameter(name, value, options || {}));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Sets a query parameter
|
|
275
|
+
* @param {string} name
|
|
276
|
+
* @param {*} value
|
|
277
|
+
* @param {ParameterOptions} [options]
|
|
278
|
+
*/
|
|
279
|
+
query(name, value, options) {
|
|
280
|
+
this._query.set(name, new QueryParameter(name, value, options || {}));
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Sets a header parameter
|
|
285
|
+
* @param {string} name
|
|
286
|
+
* @param {*} value
|
|
287
|
+
* @param {ParameterOptions} [options]
|
|
288
|
+
*/
|
|
289
|
+
header(name, value, options) {
|
|
290
|
+
this._header.set(name, new HeaderParameter(name, value, options || {}));
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Sets the body content, along with the content type
|
|
295
|
+
* @param {*} value
|
|
296
|
+
* @param {string} [contentType]
|
|
297
|
+
*/
|
|
298
|
+
body(value, contentType = 'application/json') {
|
|
299
|
+
this._bodyContentType = contentType;
|
|
300
|
+
if (this._bodyContentType === 'application/x-www-form-urlencoded' && value !== null && typeof value === 'object') {
|
|
301
|
+
// Handle URL-encoded data
|
|
302
|
+
/** @type {[string, string][]} */
|
|
303
|
+
const pairs = [];
|
|
304
|
+
for (const key of Object.keys(value)) {
|
|
305
|
+
let val = value[key];
|
|
306
|
+
if (!(val instanceof Array)) {
|
|
307
|
+
val = [val];
|
|
308
|
+
}
|
|
309
|
+
for (const v of val) {
|
|
310
|
+
const formValue = this.formDataValue(v);
|
|
311
|
+
if (formValue !== null) {
|
|
312
|
+
pairs.push([key, formValue]);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
this._bodyContent = pairs.map((p) => `${encodeURIComponent(p[0])}=${encodeURIComponent(p[1])}`).join('&');
|
|
317
|
+
} else if (this._bodyContentType.indexOf('json') !== -1 && value !== null && typeof value === 'object') {
|
|
318
|
+
this._bodyContent = JSON.stringify(value);
|
|
319
|
+
} else {
|
|
320
|
+
// The body is the plain content
|
|
321
|
+
this._bodyContent = value;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* @private
|
|
327
|
+
* @param {*} value
|
|
328
|
+
* @returns {*}
|
|
329
|
+
*/
|
|
330
|
+
formDataValue(value) {
|
|
331
|
+
if (value === null || value === undefined) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
if (typeof value === 'object') {
|
|
335
|
+
return JSON.stringify(value);
|
|
336
|
+
}
|
|
337
|
+
return String(value);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* @typedef {object} BuildOptions
|
|
342
|
+
* @property {string} [accept]
|
|
343
|
+
* @property {import('k6/http').Params} [params]
|
|
344
|
+
*/
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Builds the request with the current set parameters
|
|
348
|
+
* @param {BuildOptions} [options]
|
|
349
|
+
* @returns {import('k6/http').Response}
|
|
350
|
+
*/
|
|
351
|
+
build(options) {
|
|
352
|
+
// Perform the request
|
|
353
|
+
return http.request(...this.buildRequestParams(options));
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Builds the request with the current set parameters
|
|
358
|
+
* @param {BuildOptions} [options]
|
|
359
|
+
* @returns {Promise<import('k6/http').Response>}
|
|
360
|
+
*/
|
|
361
|
+
buildAsync(options) {
|
|
362
|
+
// Perform the request
|
|
363
|
+
return http.asyncRequest(...this.buildRequestParams(options));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* @private
|
|
368
|
+
* @param {BuildOptions} [options]
|
|
369
|
+
* @returns {Parameters<typeof import('k6/http').request>}
|
|
370
|
+
*/
|
|
371
|
+
buildRequestParams(options) {
|
|
372
|
+
options = options || {};
|
|
373
|
+
|
|
374
|
+
// Path parameters
|
|
375
|
+
let path = this.operationPath;
|
|
376
|
+
for (const pathParam of this._path.values()) {
|
|
377
|
+
path = pathParam.append(path);
|
|
378
|
+
}
|
|
379
|
+
const url = this.rootUrl + path;
|
|
380
|
+
|
|
381
|
+
// Query parameters
|
|
382
|
+
let httpParams = '';
|
|
383
|
+
for (const queryParam of this._query.values()) {
|
|
384
|
+
httpParams = queryParam.append(httpParams);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// Header parameters
|
|
388
|
+
/** @type {Object.<string, string>} */
|
|
389
|
+
let httpHeaders = {};
|
|
390
|
+
if (options.accept) {
|
|
391
|
+
httpHeaders['Accept'] = options.accept;
|
|
392
|
+
}
|
|
393
|
+
for (const headerParam of this._header.values()) {
|
|
394
|
+
httpHeaders = headerParam.append(httpHeaders);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Request content headers
|
|
398
|
+
if (this._bodyContentType) {
|
|
399
|
+
httpHeaders['Content-Type'] = this._bodyContentType;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return [
|
|
403
|
+
this.method.toUpperCase(),
|
|
404
|
+
url + httpParams,
|
|
405
|
+
this._bodyContent,
|
|
406
|
+
Object.assign({}, options.params, {
|
|
407
|
+
headers: Object.assign({}, httpHeaders, options.params ? options.params.headers : {}),
|
|
408
|
+
}),
|
|
409
|
+
];
|
|
410
|
+
}
|
|
411
|
+
}
|
|
@@ -11,7 +11,7 @@ const node_1 = require("../node");
|
|
|
11
11
|
const write_ts_nodes_1 = require("../utils/write-ts-nodes");
|
|
12
12
|
class TsMethod extends node_1.TsNode {
|
|
13
13
|
constructor(options) {
|
|
14
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
14
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
15
15
|
super(options);
|
|
16
16
|
this.doc = (_a = options.doc) !== null && _a !== void 0 ? _a : null;
|
|
17
17
|
this.decorators = (_c = (_b = options.decorators) === null || _b === void 0 ? void 0 : _b.filter(core_1.notNullish)) !== null && _c !== void 0 ? _c : [];
|
|
@@ -19,12 +19,13 @@ class TsMethod extends node_1.TsNode {
|
|
|
19
19
|
this.static = (_e = options.static) !== null && _e !== void 0 ? _e : false;
|
|
20
20
|
this.abstract = (_f = options.abstract) !== null && _f !== void 0 ? _f : false;
|
|
21
21
|
this.override = (_g = options.override) !== null && _g !== void 0 ? _g : false;
|
|
22
|
+
this.async = (_h = options.async) !== null && _h !== void 0 ? _h : false;
|
|
22
23
|
this.name = options.name;
|
|
23
|
-
this.optional = (
|
|
24
|
-
this.generics = (
|
|
25
|
-
this.parameters = (
|
|
26
|
-
this.returnType = (
|
|
27
|
-
this.body = (
|
|
24
|
+
this.optional = (_j = options.optional) !== null && _j !== void 0 ? _j : false;
|
|
25
|
+
this.generics = (_l = (_k = options.generics) === null || _k === void 0 ? void 0 : _k.filter(core_1.notNullish)) !== null && _l !== void 0 ? _l : [];
|
|
26
|
+
this.parameters = (_o = (_m = options.parameters) === null || _m === void 0 ? void 0 : _m.filter(core_1.notNullish)) !== null && _o !== void 0 ? _o : [];
|
|
27
|
+
this.returnType = (_p = options.returnType) !== null && _p !== void 0 ? _p : null;
|
|
28
|
+
this.body = (_q = options.body) !== null && _q !== void 0 ? _q : null;
|
|
28
29
|
}
|
|
29
30
|
onWrite(builder) {
|
|
30
31
|
const isInObjectDeclaration = this.getParentNode(builder) instanceof object_1.TsObject;
|
|
@@ -43,6 +44,8 @@ class TsMethod extends node_1.TsNode {
|
|
|
43
44
|
builder.append('abstract ');
|
|
44
45
|
if (this.override)
|
|
45
46
|
builder.append('override ');
|
|
47
|
+
if (this.async)
|
|
48
|
+
builder.append('async ');
|
|
46
49
|
builder.append(this.inject.afterModifiers);
|
|
47
50
|
builder.append(this.inject.beforeName, this.name, this.inject.afterName);
|
|
48
51
|
if (this.optional)
|
|
@@ -8,11 +8,12 @@ const write_ts_generic_parameters_1 = require("../utils/write-ts-generic-paramet
|
|
|
8
8
|
const write_ts_nodes_1 = require("../utils/write-ts-nodes");
|
|
9
9
|
class TsReference extends node_1.TsNode {
|
|
10
10
|
constructor(options) {
|
|
11
|
-
var _a, _b, _c;
|
|
11
|
+
var _a, _b, _c, _d;
|
|
12
12
|
super(options);
|
|
13
13
|
this.name = options.name;
|
|
14
14
|
this.moduleNameOrfilePath = (_a = options.moduleNameOrfilePath) !== null && _a !== void 0 ? _a : null;
|
|
15
15
|
this.generics = (_c = (_b = options.generics) === null || _b === void 0 ? void 0 : _b.filter(core_1.notNullish)) !== null && _c !== void 0 ? _c : [];
|
|
16
|
+
this.importType = (_d = options.importType) !== null && _d !== void 0 ? _d : 'import';
|
|
16
17
|
}
|
|
17
18
|
onWrite(builder) {
|
|
18
19
|
builder.append(this.name);
|
|
@@ -33,12 +34,16 @@ exports.TsReference = TsReference;
|
|
|
33
34
|
TsReference.addImportHandlers = [
|
|
34
35
|
{
|
|
35
36
|
builderClass: file_builder_1.TypeScriptFileBuilder,
|
|
36
|
-
handler: (builder, reference) =>
|
|
37
|
+
handler: (builder, reference) => {
|
|
38
|
+
if (reference.moduleNameOrfilePath) {
|
|
39
|
+
builder.addImport(reference.name, reference.moduleNameOrfilePath, { type: reference.importType });
|
|
40
|
+
}
|
|
41
|
+
},
|
|
37
42
|
},
|
|
38
43
|
];
|
|
39
44
|
const createReference = (name, moduleNameOrfilePath, options) => new TsReference({ ...options, name, moduleNameOrfilePath });
|
|
40
45
|
function _createFactory(name, moduleNameOrfilePath) {
|
|
41
|
-
return Object.assign(() => createReference(name, moduleNameOrfilePath), {
|
|
46
|
+
return Object.assign((options) => createReference(name, moduleNameOrfilePath, options), {
|
|
42
47
|
refName: name,
|
|
43
48
|
moduleNameOrfilePath,
|
|
44
49
|
});
|
|
@@ -47,7 +52,7 @@ function createFactory(name, moduleNameOrfilePath) {
|
|
|
47
52
|
return _createFactory(name, moduleNameOrfilePath);
|
|
48
53
|
}
|
|
49
54
|
function _createGenericFactory(name, moduleNameOrfilePath) {
|
|
50
|
-
return Object.assign((generics) => createReference(name, moduleNameOrfilePath, { generics }), {
|
|
55
|
+
return Object.assign((generics, options) => createReference(name, moduleNameOrfilePath, { ...options, generics }), {
|
|
51
56
|
refName: name,
|
|
52
57
|
moduleNameOrfilePath,
|
|
53
58
|
infer: () => createReference(name, moduleNameOrfilePath),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rxjs = exports.angular = exports.easyNetworkStub = void 0;
|
|
3
|
+
exports.k6 = exports.rxjs = exports.angular = exports.easyNetworkStub = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
exports.easyNetworkStub = tslib_1.__importStar(require("./easy-network-stub"));
|
|
6
6
|
exports.angular = tslib_1.__importStar(require("./angular"));
|
|
7
7
|
exports.rxjs = tslib_1.__importStar(require("./rxjs"));
|
|
8
|
+
exports.k6 = tslib_1.__importStar(require("./k6"));
|
|
8
9
|
tslib_1.__exportStar(require("./typescript"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.params = exports.response = exports.jsonValue = void 0;
|
|
4
|
+
const reference_1 = require("../nodes/reference");
|
|
5
|
+
// k6
|
|
6
|
+
exports.jsonValue = reference_1.tsReference.factory('JSONValue', 'k6');
|
|
7
|
+
// h6/http
|
|
8
|
+
exports.response = reference_1.tsReference.factory('Response', 'k6/http');
|
|
9
|
+
exports.params = reference_1.tsReference.factory('Params', 'k6/http');
|
package/cjs/lib/file-builder.js
CHANGED
|
@@ -24,8 +24,8 @@ class TypeScriptFileBuilder extends core_1.SourceBuilder {
|
|
|
24
24
|
useSingleQuotes: this.options.useSingleQuotes,
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
addImport(name, moduleNameOrfilePath) {
|
|
28
|
-
this.imports.addImport(name, moduleNameOrfilePath);
|
|
27
|
+
addImport(name, moduleNameOrfilePath, options) {
|
|
28
|
+
this.imports.addImport(name, moduleNameOrfilePath, options);
|
|
29
29
|
return this;
|
|
30
30
|
}
|
|
31
31
|
addExport(name, filePath) {
|
|
@@ -37,7 +37,12 @@ class TypeScriptFileBuilder extends core_1.SourceBuilder {
|
|
|
37
37
|
this.imports.clear();
|
|
38
38
|
}
|
|
39
39
|
toString(addPadding = true) {
|
|
40
|
+
var _a;
|
|
40
41
|
const builder = new core_1.SourceBuilder(this.options);
|
|
42
|
+
if ((_a = this.filePath) === null || _a === void 0 ? void 0 : _a.match(/\.[cm]?js$/)) {
|
|
43
|
+
builder.appendLine('// @ts-check');
|
|
44
|
+
}
|
|
45
|
+
builder.ensurePreviousLineEmpty();
|
|
41
46
|
this.imports.writeTo(builder);
|
|
42
47
|
const baseString = super.toString();
|
|
43
48
|
if (baseString && addPadding) {
|
|
@@ -55,10 +60,10 @@ class TypeScriptFileBuilder extends core_1.SourceBuilder {
|
|
|
55
60
|
value.write(this);
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
|
-
appendModelUsage(type) {
|
|
63
|
+
appendModelUsage(type, options) {
|
|
59
64
|
this.append(type.component);
|
|
60
65
|
for (const i of type.imports) {
|
|
61
|
-
this.addImport(i.name, i.modulePath);
|
|
66
|
+
this.addImport(i.name, i.modulePath, options);
|
|
62
67
|
}
|
|
63
68
|
return this;
|
|
64
69
|
}
|
|
@@ -4,5 +4,6 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
tslib_1.__exportStar(require("./file-generator"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./models"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./services/angular-services"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./services/fetch-clients"), exports);
|
|
8
7
|
tslib_1.__exportStar(require("./services/easy-network-stub"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./services/fetch-clients"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./services/k6-clients"), exports);
|
|
@@ -21,7 +21,7 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
|
|
|
21
21
|
return {
|
|
22
22
|
component: name,
|
|
23
23
|
filePath,
|
|
24
|
-
imports: [{ kind: 'file', name, modulePath: filePath }],
|
|
24
|
+
imports: [{ kind: 'file', name, modulePath: filePath, type: 'import' }],
|
|
25
25
|
additionalExports: fileContent.values
|
|
26
26
|
.filter((x) => typeof x === 'object' && x !== null && 'export' in x && x.export === true && 'name' in x)
|
|
27
27
|
.filter((x) => x.name !== name)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./k6-client-generator"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./k6-clients-generator"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./models"), exports);
|