@opra/common 1.0.0-alpha.1 → 1.0.0-alpha.2

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.
Files changed (28) hide show
  1. package/package.json +1 -1
  2. package/cjs/document/data-type/decorators/api-field-decorator.js +0 -26
  3. package/cjs/document/data-type/decorators/complex-type.decorator.js +0 -33
  4. package/cjs/document/data-type/decorators/simple-type.decorator.js +0 -67
  5. package/cjs/document/http/decorators/http-controller.decorator.js +0 -117
  6. package/cjs/document/http/decorators/http-operation-entity.decorator.js +0 -461
  7. package/cjs/document/http/decorators/http-operation.decorator.js +0 -183
  8. package/cjs/helpers/is-url-string.js +0 -12
  9. package/cjs/http/opra-url-path.js +0 -266
  10. package/cjs/http/opra-url.js +0 -253
  11. package/esm/document/data-type/decorators/api-field-decorator.js +0 -22
  12. package/esm/document/data-type/decorators/complex-type.decorator.js +0 -28
  13. package/esm/document/data-type/decorators/simple-type.decorator.js +0 -61
  14. package/esm/document/http/decorators/http-controller.decorator.js +0 -112
  15. package/esm/document/http/decorators/http-operation-entity.decorator.js +0 -459
  16. package/esm/document/http/decorators/http-operation.decorator.js +0 -178
  17. package/esm/helpers/is-url-string.js +0 -7
  18. package/esm/http/opra-url-path.js +0 -260
  19. package/esm/http/opra-url.js +0 -249
  20. package/types/document/data-type/decorators/api-field-decorator.d.ts +0 -5
  21. package/types/document/data-type/decorators/complex-type.decorator.d.ts +0 -2
  22. package/types/document/data-type/decorators/simple-type.decorator.d.ts +0 -20
  23. package/types/document/http/decorators/http-controller.decorator.d.ts +0 -14
  24. package/types/document/http/decorators/http-operation-entity.decorator.d.ts +0 -100
  25. package/types/document/http/decorators/http-operation.decorator.d.ts +0 -30
  26. package/types/helpers/is-url-string.d.ts +0 -2
  27. package/types/http/opra-url-path.d.ts +0 -55
  28. package/types/http/opra-url.d.ts +0 -66
@@ -1,461 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const filter_rules_js_1 = require("../../../filter/filter-rules.js");
4
- const index_js_1 = require("../../../helpers/index.js");
5
- const index_js_2 = require("../../../http/index.js");
6
- const constants_js_1 = require("../../constants.js");
7
- const index_js_3 = require("../../data-type/extended-types/index.js");
8
- const index_js_4 = require("../../data-type/primitive-types/index.js");
9
- const http_operation_js_1 = require("../http-operation.js");
10
- const http_operation_decorator_js_1 = require("./http-operation.decorator.js");
11
- /** Implementation **/
12
- http_operation_js_1.HttpOperation.Entity = {};
13
- /**
14
- * HttpOperation.Entity.Create
15
- */
16
- http_operation_js_1.HttpOperation.Entity.Create = function (arg0, arg1) {
17
- let args;
18
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
19
- args = arg0;
20
- }
21
- else
22
- args = { ...arg1, type: arg0 };
23
- /** Initialize the decorator and the chain */
24
- const decoratorChain = [];
25
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
26
- description: args.description,
27
- method: 'POST',
28
- composition: 'Entity.Create',
29
- requestBody: {
30
- immediateFetch: true,
31
- ...args.requestBody,
32
- required: true,
33
- },
34
- }));
35
- decorator
36
- .QueryParam('projection', {
37
- description: 'Determines fields projection',
38
- type: new index_js_3.FieldPathType({
39
- dataType: args.type,
40
- allowSigns: 'each',
41
- }),
42
- isArray: true,
43
- arraySeparator: ',',
44
- })
45
- .RequestContent(args.requestBody?.type || args.type)
46
- .Response(index_js_2.HttpStatusCode.CREATED, {
47
- description: 'Operation is successful. Returns OperationResult with "payload" field that contains the created resource.',
48
- contentType: index_js_2.MimeTypes.opra_response_json,
49
- type: args.type,
50
- partial: 'deep',
51
- })
52
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
53
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
54
- contentType: index_js_2.MimeTypes.opra_response_json,
55
- });
56
- if (typeof args.type === 'function')
57
- decorator.UseType(args.type);
58
- decoratorChain.push((operationMeta) => {
59
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
60
- compositionOptions.type = getDataTypeName(args.type);
61
- });
62
- return decorator;
63
- };
64
- /**
65
- * HttpOperation.Entity.Delete
66
- */
67
- http_operation_js_1.HttpOperation.Entity.Delete = function (arg0, arg1) {
68
- let args;
69
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
70
- args = arg0;
71
- }
72
- else
73
- args = { ...arg1, type: arg0 };
74
- /** Initialize the decorator and the chain */
75
- const decoratorChain = [];
76
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
77
- description: args.description,
78
- method: 'DELETE',
79
- composition: 'Entity.Delete',
80
- }));
81
- decorator
82
- .Response(index_js_2.HttpStatusCode.OK, {
83
- description: 'Operation is successful. Returns OperationResult with "affected" field.',
84
- contentType: index_js_2.MimeTypes.opra_response_json,
85
- })
86
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
87
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
88
- contentType: index_js_2.MimeTypes.opra_response_json,
89
- });
90
- if (typeof args.type === 'function')
91
- decorator.UseType(args.type);
92
- /**
93
- *
94
- */
95
- decorator.KeyParam = (name, prmOptions) => {
96
- decorator.PathParam(name, prmOptions);
97
- decoratorChain.push((meta) => {
98
- meta.path = (meta.path || '') + '@:' + name;
99
- meta.compositionOptions = meta.compositionOptions || {};
100
- meta.compositionOptions.keyParameter = name;
101
- });
102
- return decorator;
103
- };
104
- decoratorChain.push((operationMeta) => {
105
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
106
- compositionOptions.type = getDataTypeName(args.type);
107
- });
108
- return decorator;
109
- };
110
- /**
111
- * HttpOperation.Entity.DeleteMany
112
- */
113
- http_operation_js_1.HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
114
- let args;
115
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
116
- args = arg0;
117
- }
118
- else
119
- args = { ...arg1, type: arg0 };
120
- /** Initialize the decorator and the chain */
121
- const decoratorChain = [];
122
- const filterRules = new filter_rules_js_1.FilterRules();
123
- const filterType = new index_js_3.FilterType({ dataType: args.type });
124
- filterType.rules = {};
125
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
126
- description: args.description,
127
- method: 'DELETE',
128
- composition: 'Entity.DeleteMany',
129
- }));
130
- decorator
131
- .Response(index_js_2.HttpStatusCode.OK, {
132
- description: 'Operation is successful. Returns OperationResult with "affected" field.',
133
- contentType: index_js_2.MimeTypes.opra_response_json,
134
- })
135
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
136
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
137
- contentType: index_js_2.MimeTypes.opra_response_json,
138
- })
139
- .QueryParam('filter', {
140
- type: filterType,
141
- description: 'Determines filter fields',
142
- });
143
- if (typeof args.type === 'function')
144
- decorator.UseType(args.type);
145
- decoratorChain.push((operationMeta) => {
146
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
147
- compositionOptions.type = getDataTypeName(args.type);
148
- });
149
- decorator.Filter = (field, operators, description) => {
150
- decoratorChain.push(() => {
151
- filterRules.set(field, { operators, description });
152
- filterType.rules = filterRules.toJSON();
153
- });
154
- return decorator;
155
- };
156
- return decorator;
157
- };
158
- /**
159
- * HttpOperation.Entity.FindMany
160
- */
161
- http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
162
- let args;
163
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
164
- args = arg0;
165
- }
166
- else
167
- args = { ...arg1, type: arg0 };
168
- /** Initialize the decorator and the chain */
169
- const decoratorChain = [];
170
- const filterRules = new filter_rules_js_1.FilterRules();
171
- const filterType = new index_js_3.FilterType({ dataType: args.type });
172
- filterType.rules = {};
173
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
174
- description: args.description,
175
- method: 'GET',
176
- composition: 'Entity.FindMany',
177
- }));
178
- decorator
179
- .Response(index_js_2.HttpStatusCode.OK, {
180
- description: 'Operation is successful. Returns OperationResult with "payload" field that contains list of resources.',
181
- contentType: index_js_2.MimeTypes.opra_response_json,
182
- type: args.type,
183
- partial: 'deep',
184
- isArray: true,
185
- })
186
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
187
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
188
- contentType: index_js_2.MimeTypes.opra_response_json,
189
- })
190
- .QueryParam('limit', {
191
- description: 'Determines number of returning instances',
192
- type: new index_js_4.IntegerType({ minValue: 1 }),
193
- })
194
- .QueryParam('skip', {
195
- description: 'Determines number of returning instances',
196
- type: new index_js_4.IntegerType({ minValue: 1 }),
197
- })
198
- .QueryParam('count', {
199
- description: 'Counts all matching instances if enabled',
200
- type: Boolean,
201
- })
202
- .QueryParam('projection', {
203
- description: 'Determines fields projection',
204
- type: new index_js_3.FieldPathType({
205
- dataType: args.type,
206
- allowSigns: 'each',
207
- }),
208
- isArray: true,
209
- arraySeparator: ',',
210
- })
211
- .QueryParam('filter', {
212
- type: filterType,
213
- description: 'Determines filter fields',
214
- })
215
- .QueryParam('sort', {
216
- description: 'Determines sort fields',
217
- type: new index_js_3.FieldPathType({
218
- dataType: args.type,
219
- allowSigns: 'first',
220
- }),
221
- isArray: true,
222
- arraySeparator: ',',
223
- });
224
- if (typeof args.type === 'function')
225
- decorator.UseType(args.type);
226
- decoratorChain.push((operationMeta) => {
227
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
228
- compositionOptions.type = getDataTypeName(args.type);
229
- });
230
- decorator.DefaultSort = (...fields) => {
231
- decoratorChain.push((operationMeta) => {
232
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
233
- compositionOptions.defaultSort = fields;
234
- });
235
- return decorator;
236
- };
237
- decorator.SortFields = (...fields) => {
238
- decoratorChain.push((operationMeta) => {
239
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
240
- compositionOptions.sortFields = fields;
241
- });
242
- return decorator;
243
- };
244
- decorator.Filter = (field, operators, description) => {
245
- decoratorChain.push(() => {
246
- filterRules.set(field, { operators, description });
247
- filterType.rules = filterRules.toJSON();
248
- });
249
- return decorator;
250
- };
251
- return decorator;
252
- };
253
- /**
254
- * HttpOperation.Entity.Get
255
- */
256
- http_operation_js_1.HttpOperation.Entity.Get = function (arg0, arg1) {
257
- let args;
258
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
259
- args = arg0;
260
- }
261
- else
262
- args = { ...arg1, type: arg0 };
263
- /** Initialize the decorator and the chain */
264
- const decoratorChain = [];
265
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
266
- description: args.description,
267
- method: 'GET',
268
- composition: 'Entity.Get',
269
- }));
270
- decorator
271
- .QueryParam('projection', {
272
- description: 'Determines fields projection',
273
- type: new index_js_3.FieldPathType({
274
- dataType: args.type,
275
- allowSigns: 'each',
276
- }),
277
- isArray: true,
278
- arraySeparator: ',',
279
- })
280
- .Response(index_js_2.HttpStatusCode.OK, {
281
- description: 'Operation is successful. Returns OperationResult with "payload" field that contains the resource asked for.',
282
- contentType: index_js_2.MimeTypes.opra_response_json,
283
- type: args.type,
284
- partial: 'deep',
285
- })
286
- .Response(index_js_2.HttpStatusCode.NO_CONTENT, {
287
- description: 'Operation is successful but no resource found',
288
- })
289
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
290
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
291
- contentType: index_js_2.MimeTypes.opra_response_json,
292
- });
293
- if (typeof args.type === 'function')
294
- decorator.UseType(args.type);
295
- /**
296
- *
297
- */
298
- decorator.KeyParam = (name, prmOptions) => {
299
- decorator.PathParam(name, prmOptions);
300
- decoratorChain.push((meta) => {
301
- meta.path = (meta.path || '') + '@:' + name;
302
- meta.compositionOptions = meta.compositionOptions || {};
303
- meta.compositionOptions.keyParameter = name;
304
- });
305
- return decorator;
306
- };
307
- decoratorChain.push((operationMeta) => {
308
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
309
- compositionOptions.type = getDataTypeName(args.type);
310
- });
311
- return decorator;
312
- };
313
- /**
314
- * HttpOperation.Entity.UpdateMany
315
- */
316
- http_operation_js_1.HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
317
- let args;
318
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
319
- args = arg0;
320
- }
321
- else
322
- args = { ...arg1, type: arg0 };
323
- /** Initialize the decorator and the chain */
324
- const decoratorChain = [];
325
- const filterType = new index_js_3.FilterType({ dataType: args.type });
326
- filterType.rules = {};
327
- const filterRules = new filter_rules_js_1.FilterRules();
328
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
329
- description: args.description,
330
- method: 'PATCH',
331
- composition: 'Entity.UpdateMany',
332
- requestBody: {
333
- immediateFetch: true,
334
- partial: 'deep',
335
- ...args.requestBody,
336
- required: true,
337
- },
338
- }));
339
- decorator.RequestContent(args.requestBody?.type || args.type);
340
- if (typeof args.type === 'function')
341
- decorator.UseType(args.type);
342
- decorator
343
- .Response(index_js_2.HttpStatusCode.OK, {
344
- description: 'Operation is successful. Returns OperationResult with "affected" field.',
345
- contentType: index_js_2.MimeTypes.opra_response_json,
346
- })
347
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
348
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
349
- contentType: index_js_2.MimeTypes.opra_response_json,
350
- })
351
- .QueryParam('filter', {
352
- type: filterType,
353
- description: 'Determines filter fields',
354
- });
355
- decoratorChain.push((operationMeta) => {
356
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
357
- compositionOptions.type = getDataTypeName(args.type);
358
- });
359
- decorator.Filter = (field, operators, description) => {
360
- decoratorChain.push(() => {
361
- filterRules.set(field, { operators, description });
362
- filterType.rules = filterRules.toJSON();
363
- });
364
- return decorator;
365
- };
366
- return decorator;
367
- };
368
- /**
369
- * HttpOperation.Entity.Update
370
- */
371
- http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
372
- let args;
373
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
374
- args = arg0;
375
- }
376
- else
377
- args = { ...arg1, type: arg0 };
378
- /** Initialize the decorator and the chain */
379
- const decoratorChain = [];
380
- const filterRules = new filter_rules_js_1.FilterRules();
381
- const filterType = new index_js_3.FilterType({ dataType: args.type });
382
- filterType.rules = {};
383
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, (0, index_js_1.omitUndefined)({
384
- description: args.description,
385
- method: 'PATCH',
386
- composition: 'Entity.Update',
387
- requestBody: {
388
- partial: 'deep',
389
- ...args.requestBody,
390
- required: true,
391
- },
392
- }));
393
- decorator
394
- .QueryParam('projection', {
395
- description: 'Determines fields projection',
396
- type: new index_js_3.FieldPathType({
397
- dataType: args.type,
398
- allowSigns: 'each',
399
- }),
400
- isArray: true,
401
- arraySeparator: ',',
402
- })
403
- .QueryParam('filter', {
404
- type: filterType,
405
- description: 'Determines filter fields',
406
- })
407
- .RequestContent(args.requestBody?.type || args.type)
408
- .Response(index_js_2.HttpStatusCode.OK, {
409
- description: 'Operation is successful. Returns OperationResult with "payload" field that contains updated resource.',
410
- contentType: index_js_2.MimeTypes.opra_response_json,
411
- type: args.type,
412
- partial: 'deep',
413
- })
414
- .Response(index_js_2.HttpStatusCode.NO_CONTENT, {
415
- description: 'Operation is successful but no resource found',
416
- })
417
- .Response(index_js_2.HttpStatusCode.UNPROCESSABLE_ENTITY, {
418
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
419
- contentType: index_js_2.MimeTypes.opra_response_json,
420
- });
421
- if (typeof args.type === 'function')
422
- decorator.UseType(args.type);
423
- /**
424
- *
425
- */
426
- decorator.KeyParam = (name, prmOptions) => {
427
- decorator.PathParam(name, prmOptions);
428
- decoratorChain.push((meta) => {
429
- meta.path = (meta.path || '') + '@:' + name;
430
- meta.compositionOptions = meta.compositionOptions || {};
431
- meta.compositionOptions.keyParameter = name;
432
- });
433
- return decorator;
434
- };
435
- decoratorChain.push((operationMeta) => {
436
- const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
437
- compositionOptions.type = getDataTypeName(args.type);
438
- });
439
- decorator.Filter = (field, operators, description) => {
440
- decoratorChain.push(() => {
441
- filterRules.set(field, { operators, description });
442
- filterType.rules = filterRules.toJSON();
443
- });
444
- return decorator;
445
- };
446
- return decorator;
447
- };
448
- /**
449
- *
450
- * @param typ
451
- */
452
- function getDataTypeName(typ) {
453
- if (typeof typ === 'string')
454
- return typ;
455
- const metadata = Reflect.getMetadata(constants_js_1.DATATYPE_METADATA, typ);
456
- if (!metadata)
457
- throw new TypeError(`Type (${typ}) is not decorated with any datatype decorators`);
458
- if (metadata?.name)
459
- return metadata.name;
460
- throw new TypeError(`You should provide named data type but embedded one found`);
461
- }
@@ -1,183 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpOperationDecoratorFactory = void 0;
4
- const tslib_1 = require("tslib");
5
- const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
6
- const index_js_1 = require("../../../http/index.js");
7
- const index_js_2 = require("../../../schema/index.js");
8
- const constants_js_1 = require("../../constants.js");
9
- function HttpOperationDecoratorFactory(decoratorChain, options) {
10
- /**
11
- *
12
- */
13
- const decorator = ((target, propertyKey) => {
14
- if (typeof propertyKey !== 'string')
15
- throw new TypeError(`Symbol properties can not be decorated`);
16
- const operationMetadata = {
17
- kind: index_js_2.OpraSchema.HttpOperation.Kind,
18
- ...(0, lodash_omit_1.default)(options, ['kind']),
19
- };
20
- const resourceMetadata = (Reflect.getOwnMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, target.constructor) ||
21
- {});
22
- resourceMetadata.operations = resourceMetadata.operations || {};
23
- resourceMetadata.operations[propertyKey] = operationMetadata;
24
- for (const fn of decoratorChain)
25
- fn(operationMetadata);
26
- Reflect.defineMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, resourceMetadata, target.constructor);
27
- });
28
- /**
29
- *
30
- */
31
- decorator.Cookie = (name, arg1) => {
32
- decoratorChain.push((meta) => {
33
- const paramMeta = typeof arg1 === 'string' || typeof arg1 === 'function'
34
- ? {
35
- name,
36
- location: 'cookie',
37
- type: arg1,
38
- }
39
- : { ...arg1, name, location: 'cookie' };
40
- if (meta.parameters)
41
- meta.parameters = meta.parameters.filter(p => !(p.location === 'cookie' && String(p.name) === String(name)));
42
- else
43
- meta.parameters = [];
44
- meta.parameters.push(paramMeta);
45
- });
46
- return decorator;
47
- };
48
- /**
49
- *
50
- */
51
- decorator.Header = (name, arg1) => {
52
- decoratorChain.push((meta) => {
53
- const paramMeta = typeof arg1 === 'string' || typeof arg1 === 'function'
54
- ? {
55
- name,
56
- location: 'header',
57
- type: arg1,
58
- }
59
- : { ...arg1, name, location: 'header' };
60
- if (meta.parameters)
61
- meta.parameters = meta.parameters.filter(p => !(p.location === 'header' && String(p.name) === String(name)));
62
- else
63
- meta.parameters = [];
64
- meta.parameters.push(paramMeta);
65
- });
66
- return decorator;
67
- };
68
- /**
69
- *
70
- */
71
- decorator.QueryParam = (name, arg1) => {
72
- decoratorChain.push((meta) => {
73
- const paramMeta = typeof arg1 === 'string' || typeof arg1 === 'function'
74
- ? {
75
- name,
76
- location: 'query',
77
- type: arg1,
78
- }
79
- : { ...arg1, name, location: 'query' };
80
- if (meta.parameters)
81
- meta.parameters = meta.parameters.filter(p => !(p.location === 'query' && String(p.name) === String(name)));
82
- else
83
- meta.parameters = [];
84
- meta.parameters.push(paramMeta);
85
- });
86
- return decorator;
87
- };
88
- /**
89
- *
90
- */
91
- decorator.PathParam = (name, arg1) => {
92
- decoratorChain.push((meta) => {
93
- const paramMeta = typeof arg1 === 'string' || typeof arg1 === 'function'
94
- ? {
95
- name,
96
- location: 'path',
97
- type: arg1,
98
- }
99
- : { ...arg1, name, location: 'path' };
100
- if (meta.parameters)
101
- meta.parameters = meta.parameters.filter(p => !(p.location === 'path' && String(p.name) === String(name)));
102
- else
103
- meta.parameters = [];
104
- meta.parameters.push(paramMeta);
105
- });
106
- return decorator;
107
- };
108
- /**
109
- *
110
- */
111
- decorator.Response = (statusCode, responseOptions) => {
112
- const responseMeta = { ...responseOptions, statusCode };
113
- if (responseMeta.type) {
114
- responseMeta.contentType = responseMeta.contentType || index_js_1.MimeTypes.opra_response_json;
115
- responseMeta.contentEncoding = responseMeta.contentEncoding || 'utf-8';
116
- }
117
- decoratorChain.push((meta) => {
118
- meta.responses = meta.responses || [];
119
- meta.responses.push(responseMeta);
120
- });
121
- return decorator;
122
- };
123
- decorator.RequestContent = function (arg0) {
124
- const contentMeta = typeof arg0 === 'object' ? arg0 : { type: arg0 };
125
- if (contentMeta.type) {
126
- contentMeta.contentType = contentMeta.contentType || index_js_1.MimeTypes.json;
127
- contentMeta.contentEncoding = contentMeta.contentEncoding || 'utf-8';
128
- }
129
- decoratorChain.push((operationMetadata) => {
130
- operationMetadata.requestBody = operationMetadata.requestBody || { required: true, content: [] };
131
- operationMetadata.requestBody.content = operationMetadata.requestBody.content || [];
132
- operationMetadata.requestBody.content.push(contentMeta);
133
- });
134
- return decorator;
135
- };
136
- decorator.MultipartContent = function (contentOpts, subInit) {
137
- const contentMetadata = {
138
- ...contentOpts,
139
- contentType: contentOpts?.contentType || 'multipart/form-data',
140
- };
141
- decoratorChain.push((operationMetadata) => {
142
- operationMetadata.requestBody = operationMetadata.requestBody || { required: true, content: [] };
143
- operationMetadata.requestBody.content = operationMetadata.requestBody.content || [];
144
- operationMetadata.requestBody.content.push(contentMetadata);
145
- });
146
- if (subInit) {
147
- const configScope = {
148
- Field(fieldName, opts) {
149
- contentMetadata.multipartFields = contentMetadata.multipartFields || [];
150
- contentMetadata.multipartFields.push({
151
- fieldName,
152
- fieldType: 'field',
153
- ...opts,
154
- });
155
- return configScope;
156
- },
157
- File(fieldName, opts) {
158
- contentMetadata.multipartFields = contentMetadata.multipartFields || [];
159
- contentMetadata.multipartFields.push({
160
- fieldName,
161
- fieldType: 'file',
162
- ...opts,
163
- });
164
- return configScope;
165
- },
166
- };
167
- subInit(configScope);
168
- }
169
- return decorator;
170
- };
171
- /**
172
- *
173
- */
174
- decorator.UseType = (...type) => {
175
- decoratorChain.push((meta) => {
176
- meta.types = meta.types || [];
177
- meta.types.push(...type);
178
- });
179
- return decorator;
180
- };
181
- return decorator;
182
- }
183
- exports.HttpOperationDecoratorFactory = HttpOperationDecoratorFactory;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isAbsoluteUrl = exports.isUrlString = void 0;
4
- const URL_PATTERN = /^(https?:\/\/.)[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/i;
5
- function isUrlString(url) {
6
- return URL_PATTERN.test(url);
7
- }
8
- exports.isUrlString = isUrlString;
9
- const isAbsoluteUrl = (urlString) => {
10
- return !urlString.includes('://') && new URL(urlString, 'http://tempuri.org/').host !== 'tempuri.org';
11
- };
12
- exports.isAbsoluteUrl = isAbsoluteUrl;