@opra/common 1.8.0 → 1.9.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.
Files changed (43) hide show
  1. package/browser/index.cjs +5 -5
  2. package/browser/index.mjs +5 -5
  3. package/cjs/document/data-type/enum-type.js +2 -2
  4. package/cjs/document/decorators/http-operation-entity-create.decorator.js +58 -0
  5. package/cjs/document/decorators/http-operation-entity-delete-many.decorator.js +41 -0
  6. package/cjs/document/decorators/http-operation-entity-delete.decorator.js +41 -0
  7. package/cjs/document/decorators/http-operation-entity-find-many.decorator.js +85 -0
  8. package/cjs/document/decorators/http-operation-entity-get.decorator.js +56 -0
  9. package/cjs/document/decorators/http-operation-entity-replace.decorator.js +56 -0
  10. package/cjs/document/decorators/http-operation-entity-update-many.decorator.js +50 -0
  11. package/cjs/document/decorators/http-operation-entity-update.decorator.js +66 -0
  12. package/cjs/document/decorators/http-operation-entity.decorator.js +83 -525
  13. package/cjs/document/http/http-parameter.js +1 -0
  14. package/cjs/document/index.js +9 -1
  15. package/cjs/filter/filter-rules.js +2 -1
  16. package/esm/document/data-type/enum-type.js +2 -2
  17. package/esm/document/decorators/http-operation-entity-create.decorator.js +56 -0
  18. package/esm/document/decorators/http-operation-entity-delete-many.decorator.js +39 -0
  19. package/esm/document/decorators/http-operation-entity-delete.decorator.js +39 -0
  20. package/esm/document/decorators/http-operation-entity-find-many.decorator.js +83 -0
  21. package/esm/document/decorators/http-operation-entity-get.decorator.js +54 -0
  22. package/esm/document/decorators/http-operation-entity-replace.decorator.js +54 -0
  23. package/esm/document/decorators/http-operation-entity-update-many.decorator.js +48 -0
  24. package/esm/document/decorators/http-operation-entity-update.decorator.js +64 -0
  25. package/esm/document/decorators/http-operation-entity.decorator.js +79 -525
  26. package/esm/document/http/http-parameter.js +1 -0
  27. package/esm/document/index.js +9 -1
  28. package/esm/filter/filter-rules.js +2 -1
  29. package/package.json +1 -1
  30. package/types/document/data-type/enum-type.d.ts +3 -3
  31. package/types/document/decorators/http-operation-entity-create.decorator.d.ts +1 -0
  32. package/types/document/decorators/http-operation-entity-delete-many.decorator.d.ts +1 -0
  33. package/types/document/decorators/http-operation-entity-delete.decorator.d.ts +1 -0
  34. package/types/document/decorators/http-operation-entity-find-many.decorator.d.ts +1 -0
  35. package/types/document/decorators/http-operation-entity-get.decorator.d.ts +1 -0
  36. package/types/document/decorators/http-operation-entity-replace.decorator.d.ts +1 -0
  37. package/types/document/decorators/http-operation-entity-update-many.decorator.d.ts +1 -0
  38. package/types/document/decorators/http-operation-entity-update.decorator.d.ts +1 -0
  39. package/types/document/decorators/http-operation-entity.decorator.d.ts +32 -4
  40. package/types/document/http/http-parameter.d.ts +3 -0
  41. package/types/document/index.d.ts +9 -1
  42. package/types/filter/ast/expressions/comparison-expression.d.ts +1 -0
  43. package/types/filter/filter-rules.d.ts +1 -0
@@ -1,94 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_js_1 = require("../../enums/index.js");
3
+ exports.getDataTypeName = getDataTypeName;
4
+ exports.createKeyParamDecorator = createKeyParamDecorator;
5
+ exports.createSortFieldsDecorator = createSortFieldsDecorator;
6
+ exports.createFilterDecorator = createFilterDecorator;
4
7
  const filter_rules_js_1 = require("../../filter/filter-rules.js");
5
8
  const constants_js_1 = require("../constants.js");
6
- const index_js_2 = require("../data-type/extended-types/index.js");
7
- const index_js_3 = require("../data-type/primitive-types/index.js");
9
+ const complex_type_base_js_1 = require("../data-type/complex-type-base.js");
10
+ const enum_type_js_1 = require("../data-type/enum-type.js");
11
+ const index_js_1 = require("../data-type/extended-types/index.js");
8
12
  const http_operation_js_1 = require("../http/http-operation.js");
9
- const http_operation_decorator_js_1 = require("./http-operation.decorator.js");
10
13
  /** Implementation **/
11
14
  http_operation_js_1.HttpOperation.Entity = {};
12
15
  /**
13
- * HttpOperation.Entity.Create
16
+ *
17
+ * @param typ
14
18
  */
15
- http_operation_js_1.HttpOperation.Entity.Create = function (arg0, arg1) {
16
- let args;
17
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
18
- args = arg0;
19
- }
20
- else
21
- args = { ...arg1, type: arg0 };
22
- /** Initialize the decorator and the chain */
23
- const decoratorChain = [];
24
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
25
- method: 'POST',
26
- ...args,
27
- composition: 'Entity.Create',
28
- requestBody: {
29
- immediateFetch: true,
30
- ...args.requestBody,
31
- required: true,
32
- },
33
- });
34
- decorator
35
- .QueryParam('projection', {
36
- description: 'Determines fields projection',
37
- type: new index_js_2.FieldPathType({
38
- dataType: args.type,
39
- allowSigns: 'each',
40
- }),
41
- isArray: true,
42
- arraySeparator: ',',
43
- })
44
- .RequestContent(args.requestBody?.type || args.type)
45
- .Response(index_js_1.HttpStatusCode.CREATED, {
46
- description: 'Operation is successful. Returns OperationResult with "payload" field that contains the created resource.',
47
- contentType: index_js_1.MimeTypes.opra_response_json,
48
- type: args.type,
49
- partial: 'deep',
50
- })
51
- .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
52
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
53
- contentType: index_js_1.MimeTypes.opra_response_json,
54
- });
55
- decoratorChain.push((operationMeta) => {
56
- const compositionOptions = (operationMeta.compositionOptions =
57
- operationMeta.compositionOptions || {});
58
- compositionOptions.type = getDataTypeName(args.type);
59
- });
60
- return decorator;
61
- };
19
+ function getDataTypeName(typ) {
20
+ if (typeof typ === 'string')
21
+ return typ;
22
+ const metadata = Reflect.getMetadata(constants_js_1.DATATYPE_METADATA, typ);
23
+ if (!metadata)
24
+ throw new TypeError(`Type (${typ}) is not decorated with any datatype decorators`);
25
+ if (metadata?.name)
26
+ return metadata.name;
27
+ throw new TypeError(`You should provide named data type but embedded one found`);
28
+ }
62
29
  /**
63
- * HttpOperation.Entity.Delete
30
+ *
64
31
  */
65
- http_operation_js_1.HttpOperation.Entity.Delete = function (arg0, arg1) {
66
- let args;
67
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
68
- args = arg0;
69
- }
70
- else
71
- args = { ...arg1, type: arg0 };
72
- /** Initialize the decorator and the chain */
73
- const decoratorChain = [];
74
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
75
- method: 'DELETE',
76
- ...args,
77
- composition: 'Entity.Delete',
78
- });
79
- decorator
80
- .Response(index_js_1.HttpStatusCode.OK, {
81
- description: 'Operation is successful. Returns OperationResult with "affected" field.',
82
- contentType: index_js_1.MimeTypes.opra_response_json,
83
- })
84
- .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
85
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
86
- contentType: index_js_1.MimeTypes.opra_response_json,
87
- });
88
- /**
89
- *
90
- */
91
- decorator.KeyParam = (name, prmOptions) => {
32
+ function createKeyParamDecorator(decorator, decoratorChain) {
33
+ return (name, prmOptions) => {
92
34
  const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
93
35
  ? {
94
36
  name,
@@ -110,468 +52,84 @@ http_operation_js_1.HttpOperation.Entity.Delete = function (arg0, arg1) {
110
52
  });
111
53
  return decorator;
112
54
  };
113
- decoratorChain.push((operationMeta) => {
114
- const compositionOptions = (operationMeta.compositionOptions =
115
- operationMeta.compositionOptions || {});
116
- compositionOptions.type = getDataTypeName(args.type);
117
- });
118
- return decorator;
119
- };
120
- /**
121
- * HttpOperation.Entity.DeleteMany
122
- */
123
- http_operation_js_1.HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
124
- let args;
125
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
126
- args = arg0;
127
- }
128
- else
129
- args = { ...arg1, type: arg0 };
130
- /** Initialize the decorator and the chain */
131
- const decoratorChain = [];
132
- const filterRules = new filter_rules_js_1.FilterRules();
133
- const filterType = new index_js_2.FilterType({ dataType: args.type });
134
- filterType.rules = {};
135
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
136
- method: 'DELETE',
137
- ...args,
138
- composition: 'Entity.DeleteMany',
139
- });
140
- decorator
141
- .Response(index_js_1.HttpStatusCode.OK, {
142
- description: 'Operation is successful. Returns OperationResult with "affected" field.',
143
- contentType: index_js_1.MimeTypes.opra_response_json,
144
- })
145
- .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
146
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
147
- contentType: index_js_1.MimeTypes.opra_response_json,
148
- })
149
- .QueryParam('filter', {
150
- type: filterType,
151
- description: 'Determines filter fields',
152
- });
153
- decoratorChain.push((operationMeta) => {
154
- const compositionOptions = (operationMeta.compositionOptions =
155
- operationMeta.compositionOptions || {});
156
- compositionOptions.type = getDataTypeName(args.type);
157
- });
158
- decorator.Filter = (field, operators, description) => {
159
- decoratorChain.push(() => {
160
- filterRules.set(field, { operators, description });
161
- filterType.rules = filterRules.toJSON();
162
- });
163
- return decorator;
164
- };
165
- return decorator;
166
- };
55
+ }
167
56
  /**
168
- * HttpOperation.Entity.FindMany
57
+ *
169
58
  */
170
- http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
171
- let args;
172
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
173
- args = arg0;
174
- }
175
- else
176
- args = { ...arg1, type: arg0 };
177
- /** Initialize the decorator and the chain */
178
- const decoratorChain = [];
179
- const filterRules = new filter_rules_js_1.FilterRules();
180
- const filterType = new index_js_2.FilterType({ dataType: args.type });
181
- filterType.rules = {};
182
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
183
- method: 'GET',
184
- ...args,
185
- composition: 'Entity.FindMany',
186
- });
187
- decorator
188
- .Response(index_js_1.HttpStatusCode.OK, {
189
- description: 'Operation is successful. Returns OperationResult with "payload" field that contains list of resources.',
190
- contentType: index_js_1.MimeTypes.opra_response_json,
191
- type: args.type,
192
- partial: 'deep',
193
- isArray: true,
194
- })
195
- .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
196
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
197
- contentType: index_js_1.MimeTypes.opra_response_json,
198
- })
199
- .QueryParam('limit', {
200
- description: 'Determines number of returning instances',
201
- type: new index_js_3.IntegerType({ minValue: 1, maxValue: args.maxLimit }),
202
- })
203
- .QueryParam('skip', {
204
- description: 'Determines number of returning instances',
205
- type: new index_js_3.IntegerType({ minValue: 1 }),
206
- })
207
- .QueryParam('count', {
208
- description: 'Counts all matching instances if enabled',
209
- type: Boolean,
210
- })
211
- .QueryParam('projection', {
212
- description: 'Determines fields projection',
213
- type: new index_js_2.FieldPathType({
214
- dataType: args.type,
215
- allowSigns: 'each',
216
- }),
217
- isArray: true,
218
- arraySeparator: ',',
219
- })
220
- .QueryParam('filter', {
221
- type: filterType,
222
- description: 'Determines filter fields',
223
- })
224
- .QueryParam('sort', {
225
- description: 'Determines sort fields',
226
- type: new index_js_2.FieldPathType({
227
- dataType: args.type,
228
- allowSigns: 'first',
229
- }),
230
- isArray: true,
231
- arraySeparator: ',',
232
- });
233
- decoratorChain.push((operationMeta) => {
234
- const compositionOptions = (operationMeta.compositionOptions =
235
- operationMeta.compositionOptions || {});
236
- compositionOptions.type = getDataTypeName(args.type);
237
- if (args.defaultLimit)
238
- compositionOptions.defaultLimit = args.defaultLimit;
239
- if (args.defaultProjection)
240
- compositionOptions.defaultProjection = args.defaultProjection;
241
- if (args.maxLimit)
242
- compositionOptions.maxLimit = args.maxLimit;
243
- });
244
- decorator.DefaultSort = (...fields) => {
245
- decoratorChain.push((operationMeta) => {
246
- const compositionOptions = (operationMeta.compositionOptions =
247
- operationMeta.compositionOptions || {});
248
- compositionOptions.defaultSort = fields;
249
- });
250
- return decorator;
251
- };
252
- decorator.SortFields = (...fields) => {
59
+ function createSortFieldsDecorator(decorator, decoratorChain) {
60
+ return (...varargs) => {
61
+ const defObj = typeof varargs[0] === 'object'
62
+ ? varargs[0]
63
+ : varargs.reduce((acc, k) => {
64
+ const a = k.split(':');
65
+ acc[a[0]] = a[1] || a[0];
66
+ return acc;
67
+ }, {});
68
+ const fieldsMap = Object.keys(defObj).reduce((acc, k) => {
69
+ const m1 = complex_type_base_js_1.FIELD_PATH_PATTERN.exec(k);
70
+ const m2 = complex_type_base_js_1.FIELD_PATH_PATTERN.exec(defObj[k]);
71
+ if (m1 && m2) {
72
+ acc[m1[2]] = m2[2];
73
+ }
74
+ return acc;
75
+ }, {});
76
+ const prmEnum = Object.keys(defObj).reduce((acc, k) => {
77
+ const m = complex_type_base_js_1.FIELD_PATH_PATTERN.exec(k);
78
+ if (m) {
79
+ if (m[1] != '-')
80
+ acc[m[2]] = m[2];
81
+ if (m[1] != '+')
82
+ acc['-' + m[2]] = '-' + m[2];
83
+ }
84
+ return acc;
85
+ }, {});
253
86
  decoratorChain.push((operationMeta) => {
254
87
  const compositionOptions = (operationMeta.compositionOptions =
255
88
  operationMeta.compositionOptions || {});
256
- compositionOptions.sortFields = fields;
257
- });
258
- return decorator;
259
- };
260
- decorator.Filter = (field, operators, description) => {
261
- decoratorChain.push(() => {
262
- filterRules.set(field, { operators, description });
263
- filterType.rules = filterRules.toJSON();
89
+ compositionOptions.sortFields = fieldsMap;
264
90
  });
265
- return decorator;
266
- };
267
- return decorator;
268
- };
269
- /**
270
- * HttpOperation.Entity.Get
271
- */
272
- http_operation_js_1.HttpOperation.Entity.Get = function (arg0, arg1) {
273
- let args;
274
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
275
- args = arg0;
276
- }
277
- else
278
- args = { ...arg1, type: arg0 };
279
- /** Initialize the decorator and the chain */
280
- const decoratorChain = [];
281
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
282
- method: 'GET',
283
- ...args,
284
- composition: 'Entity.Get',
285
- });
286
- decorator
287
- .QueryParam('projection', {
288
- description: 'Determines fields projection',
289
- type: new index_js_2.FieldPathType({
290
- dataType: args.type,
291
- allowSigns: 'each',
292
- }),
293
- isArray: true,
294
- arraySeparator: ',',
295
- })
296
- .Response(index_js_1.HttpStatusCode.OK, {
297
- description: 'Operation is successful. Returns OperationResult with "payload" field that contains the resource asked for.',
298
- contentType: index_js_1.MimeTypes.opra_response_json,
299
- type: args.type,
300
- partial: 'deep',
301
- })
302
- .Response(index_js_1.HttpStatusCode.NO_CONTENT, {
303
- description: 'Operation is successful but no resource found',
304
- })
305
- .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
306
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
307
- contentType: index_js_1.MimeTypes.opra_response_json,
308
- });
309
- /**
310
- *
311
- */
312
- decorator.KeyParam = (name, prmOptions) => {
313
- const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
314
- ? {
315
- name,
316
- location: 'path',
317
- type: prmOptions,
318
- keyParam: true,
319
- }
320
- : {
321
- ...prmOptions,
322
- name,
323
- location: 'path',
324
- keyParam: true,
325
- };
326
- decorator.PathParam(name, paramMeta);
327
- decoratorChain.push((meta) => {
328
- if (!meta.path?.includes(':' + name))
329
- meta.path = (meta.path || '') + '@:' + name;
330
- meta.mergePath = true;
91
+ decorator.QueryParam('sort', {
92
+ description: 'Determines sort fields',
93
+ type: (0, enum_type_js_1.EnumType)(prmEnum),
94
+ isArray: true,
95
+ arraySeparator: ',',
96
+ parser: (v) => v.map(x => {
97
+ const m = complex_type_base_js_1.FIELD_PATH_PATTERN.exec(x);
98
+ return m ? (m[1] || '') + fieldsMap[m[2]] : x;
99
+ }),
331
100
  });
332
101
  return decorator;
333
102
  };
334
- decoratorChain.push((operationMeta) => {
335
- const compositionOptions = (operationMeta.compositionOptions =
336
- operationMeta.compositionOptions || {});
337
- compositionOptions.type = getDataTypeName(args.type);
338
- });
339
- return decorator;
340
- };
103
+ }
341
104
  /**
342
- * HttpOperation.Entity.Replace
105
+ *
343
106
  */
344
- http_operation_js_1.HttpOperation.Entity.Replace = function (arg0, arg1) {
345
- let args;
346
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
347
- args = arg0;
107
+ function createFilterDecorator(decorator, decoratorChain, dataType) {
108
+ let filterRules = Reflect.getMetadata('FilterRules', decorator);
109
+ if (!filterRules) {
110
+ filterRules = new filter_rules_js_1.FilterRules();
111
+ Reflect.defineMetadata('FilterRules', filterRules, decorator);
348
112
  }
349
- else
350
- args = { ...arg1, type: arg0 };
351
- /** Initialize the decorator and the chain */
352
- const decoratorChain = [];
353
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
354
- method: 'POST',
355
- ...args,
356
- composition: 'Entity.Replace',
357
- });
358
- decorator
359
- .QueryParam('projection', {
360
- description: 'Determines fields projection',
361
- type: new index_js_2.FieldPathType({
362
- dataType: args.type,
363
- allowSigns: 'each',
364
- }),
365
- isArray: true,
366
- arraySeparator: ',',
367
- })
368
- .Response(index_js_1.HttpStatusCode.OK, {
369
- description: 'Operation is successful. Returns OperationResult with "payload" field that contains the resource asked for.',
370
- contentType: index_js_1.MimeTypes.opra_response_json,
371
- type: args.type,
372
- partial: 'deep',
373
- })
374
- .Response(index_js_1.HttpStatusCode.NO_CONTENT, {
375
- description: 'Operation is successful but no resource found',
376
- })
377
- .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
378
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
379
- contentType: index_js_1.MimeTypes.opra_response_json,
380
- });
381
- /**
382
- *
383
- */
384
- decorator.KeyParam = (name, prmOptions) => {
385
- const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
386
- ? {
387
- name,
388
- location: 'path',
389
- type: prmOptions,
390
- keyParam: true,
391
- }
392
- : {
393
- ...prmOptions,
394
- name,
395
- location: 'path',
396
- keyParam: true,
397
- };
398
- decorator.PathParam(name, paramMeta);
399
- decoratorChain.push((meta) => {
400
- if (!meta.path?.includes(':' + name))
401
- meta.path = (meta.path || '') + '@:' + name;
402
- meta.mergePath = true;
403
- });
404
- return decorator;
405
- };
406
- decoratorChain.push((operationMeta) => {
407
- const compositionOptions = (operationMeta.compositionOptions =
408
- operationMeta.compositionOptions || {});
409
- compositionOptions.type = getDataTypeName(args.type);
410
- });
411
- return decorator;
412
- };
413
- /**
414
- * HttpOperation.Entity.UpdateMany
415
- */
416
- http_operation_js_1.HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
417
- let args;
418
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
419
- args = arg0;
113
+ let filterType = Reflect.getMetadata('FilterType', decorator);
114
+ if (!filterType) {
115
+ filterType = new index_js_1.FilterType({ dataType });
116
+ filterType.rules = {};
117
+ Reflect.defineMetadata('FilterType', filterType, decorator);
420
118
  }
421
- else
422
- args = { ...arg1, type: arg0 };
423
- /** Initialize the decorator and the chain */
424
- const decoratorChain = [];
425
- const filterType = new index_js_2.FilterType({ dataType: args.type });
426
- filterType.rules = {};
427
- const filterRules = new filter_rules_js_1.FilterRules();
428
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
429
- method: 'PATCH',
430
- ...args,
431
- composition: 'Entity.UpdateMany',
432
- requestBody: {
433
- immediateFetch: true,
434
- partial: 'deep',
435
- allowPatchOperators: true,
436
- keepKeyFields: true,
437
- ...args.requestBody,
438
- required: true,
439
- },
440
- });
441
- decorator
442
- .RequestContent(args.requestBody?.type || args.type)
443
- .Response(index_js_1.HttpStatusCode.OK, {
444
- description: 'Operation is successful. Returns OperationResult with "affected" field.',
445
- contentType: index_js_1.MimeTypes.opra_response_json,
446
- })
447
- .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
448
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
449
- contentType: index_js_1.MimeTypes.opra_response_json,
450
- })
451
- .QueryParam('filter', {
452
- type: filterType,
453
- description: 'Determines filter fields',
454
- });
455
- decoratorChain.push((operationMeta) => {
456
- const compositionOptions = (operationMeta.compositionOptions =
457
- operationMeta.compositionOptions || {});
458
- compositionOptions.type = getDataTypeName(args.type);
459
- });
460
- decorator.Filter = (field, operators, description) => {
119
+ return (field, arg0) => {
120
+ const filterOptions = (Array.isArray(arg0)
121
+ ? { operators: arg0 }
122
+ : typeof arg0 === 'string'
123
+ ? { operators: [arg0] }
124
+ : arg0) || {};
461
125
  decoratorChain.push(() => {
462
- filterRules.set(field, { operators, description });
126
+ filterRules.set(field, filterOptions);
463
127
  filterType.rules = filterRules.toJSON();
464
128
  });
465
- return decorator;
466
- };
467
- return decorator;
468
- };
469
- /**
470
- * HttpOperation.Entity.Update
471
- */
472
- http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
473
- let args;
474
- if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
475
- args = arg0;
476
- }
477
- else
478
- args = { ...arg1, type: arg0 };
479
- /** Initialize the decorator and the chain */
480
- const decoratorChain = [];
481
- const filterRules = new filter_rules_js_1.FilterRules();
482
- const filterType = new index_js_2.FilterType({ dataType: args.type });
483
- filterType.rules = {};
484
- const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
485
- method: 'PATCH',
486
- ...args,
487
- composition: 'Entity.Update',
488
- requestBody: {
489
- partial: 'deep',
490
- immediateFetch: true,
491
- allowPatchOperators: true,
492
- keepKeyFields: true,
493
- ...args.requestBody,
494
- required: true,
495
- },
496
- });
497
- decorator
498
- .QueryParam('projection', {
499
- description: 'Determines fields projection',
500
- type: new index_js_2.FieldPathType({
501
- dataType: args.type,
502
- allowSigns: 'each',
503
- }),
504
- isArray: true,
505
- arraySeparator: ',',
506
- })
507
- .QueryParam('filter', {
508
- type: filterType,
509
- description: 'Determines filter fields',
510
- })
511
- .RequestContent(args.requestBody?.type || args.type)
512
- .Response(index_js_1.HttpStatusCode.OK, {
513
- description: 'Operation is successful. Returns OperationResult with "payload" field that contains updated resource.',
514
- contentType: index_js_1.MimeTypes.opra_response_json,
515
- type: args.type,
516
- partial: 'deep',
517
- })
518
- .Response(index_js_1.HttpStatusCode.NO_CONTENT, {
519
- description: 'Operation is successful but no resource found',
520
- })
521
- .Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
522
- description: 'The request was well-formed but was unable to process operation due to one or many errors.',
523
- contentType: index_js_1.MimeTypes.opra_response_json,
524
- });
525
- /**
526
- *
527
- */
528
- decorator.KeyParam = (name, prmOptions) => {
529
- const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
530
- ? {
531
- name,
532
- location: 'path',
533
- type: prmOptions,
534
- keyParam: true,
535
- }
536
- : {
537
- ...prmOptions,
538
- name,
539
- location: 'path',
540
- keyParam: true,
541
- };
542
- decorator.PathParam(name, paramMeta);
543
- decoratorChain.push((meta) => {
544
- if (!meta.path?.includes(':' + name))
545
- meta.path = (meta.path || '') + '@:' + name;
546
- meta.mergePath = true;
547
- });
548
- return decorator;
549
- };
550
- decoratorChain.push((operationMeta) => {
551
- const compositionOptions = (operationMeta.compositionOptions =
552
- operationMeta.compositionOptions || {});
553
- compositionOptions.type = getDataTypeName(args.type);
554
- });
555
- decorator.Filter = (field, operators, description) => {
556
- decoratorChain.push(() => {
557
- filterRules.set(field, { operators, description });
558
- filterType.rules = filterRules.toJSON();
129
+ decorator.QueryParam('filter', {
130
+ type: filterType,
131
+ description: 'Determines filter fields',
559
132
  });
560
133
  return decorator;
561
134
  };
562
- return decorator;
563
- };
564
- /**
565
- *
566
- * @param typ
567
- */
568
- function getDataTypeName(typ) {
569
- if (typeof typ === 'string')
570
- return typ;
571
- const metadata = Reflect.getMetadata(constants_js_1.DATATYPE_METADATA, typ);
572
- if (!metadata)
573
- throw new TypeError(`Type (${typ}) is not decorated with any datatype decorators`);
574
- if (metadata?.name)
575
- return metadata.name;
576
- throw new TypeError(`You should provide named data type but embedded one found`);
577
135
  }
@@ -28,6 +28,7 @@ exports.HttpParameter = function (owner, initArgs) {
28
28
  _this.required = true;
29
29
  _this.arraySeparator = initArgs.arraySeparator;
30
30
  _this.keyParam = initArgs.keyParam;
31
+ _this.parser = initArgs.parser;
31
32
  };
32
33
  /**
33
34
  * @class HttpParameter
@@ -3,6 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.classes = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  require("reflect-metadata");
6
+ require("./decorators/http-operation-entity.decorator.js");
7
+ require("./decorators/http-operation-entity-create.decorator.js");
8
+ require("./decorators/http-operation-entity-delete.decorator.js");
9
+ require("./decorators/http-operation-entity-delete-many.decorator.js");
10
+ require("./decorators/http-operation-entity-find-many.decorator.js");
11
+ require("./decorators/http-operation-entity-get.decorator.js");
12
+ require("./decorators/http-operation-entity-replace.decorator.js");
13
+ require("./decorators/http-operation-entity-update.decorator.js");
14
+ require("./decorators/http-operation-entity-update-many.decorator.js");
6
15
  const RpcControllerDecorator_ = tslib_1.__importStar(require("./decorators/rpc-controller.decorator.js"));
7
16
  const RpcOperationDecorator_ = tslib_1.__importStar(require("./decorators/rpc-operation.decorator.js"));
8
17
  const DataTypeFactory_ = tslib_1.__importStar(require("./factory/data-type.factory.js"));
@@ -28,7 +37,6 @@ tslib_1.__exportStar(require("./data-type/pick-type.js"), exports);
28
37
  tslib_1.__exportStar(require("./data-type/primitive-types/index.js"), exports);
29
38
  tslib_1.__exportStar(require("./data-type/required-type.js"), exports);
30
39
  tslib_1.__exportStar(require("./data-type/simple-type.js"), exports);
31
- tslib_1.__exportStar(require("./decorators/http-operation-entity.decorator.js"), exports);
32
40
  tslib_1.__exportStar(require("./factory/api-document.factory.js"), exports);
33
41
  tslib_1.__exportStar(require("./http/http-api.js"), exports);
34
42
  tslib_1.__exportStar(require("./http/http-controller.js"), exports);