@opra/common 1.0.0-alpha.29 → 1.0.0-alpha.30
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/browser.js +170 -161
- package/cjs/document/api-document.js +2 -0
- package/cjs/document/common/api-base.js +1 -0
- package/cjs/document/data-type/api-field.js +8 -7
- package/cjs/document/data-type/complex-type-base.js +3 -1
- package/cjs/document/data-type/simple-type.js +1 -6
- package/cjs/document/decorators/api-field-decorator.js +3 -4
- package/cjs/document/decorators/http-operation-entity.decorator.js +58 -59
- package/cjs/exception/opra-exception.js +1 -0
- package/cjs/helpers/object-utils.js +2 -2
- package/esm/document/api-document.js +2 -0
- package/esm/document/common/api-base.js +1 -0
- package/esm/document/data-type/api-field.js +8 -7
- package/esm/document/data-type/complex-type-base.js +3 -1
- package/esm/document/data-type/simple-type.js +1 -6
- package/esm/document/decorators/api-field-decorator.js +1 -2
- package/esm/document/decorators/http-operation-entity.decorator.js +14 -15
- package/esm/exception/opra-exception.js +1 -0
- package/esm/helpers/object-utils.js +2 -2
- package/package.json +3 -2
- package/types/document/data-type/api-field.d.ts +10 -0
- package/types/document/data-type/data-type.d.ts +1 -0
- package/types/document/http/http-parameter.d.ts +1 -1
|
@@ -18,6 +18,8 @@ class ApiDocument extends document_element_js_1.DocumentElement {
|
|
|
18
18
|
constructor() {
|
|
19
19
|
super(null);
|
|
20
20
|
this[_a] = new WeakMap();
|
|
21
|
+
this.id = '';
|
|
22
|
+
this.info = {};
|
|
21
23
|
this.references = new index_js_1.ResponsiveMap();
|
|
22
24
|
this.types = new data_type_map_js_1.DataTypeMap();
|
|
23
25
|
this.node[constants_js_1.kDataTypeMap] = this.types;
|
|
@@ -40,6 +40,7 @@ exports.ApiField = function (...args) {
|
|
|
40
40
|
_this.readonly = initArgs.readonly;
|
|
41
41
|
_this.writeonly = initArgs.writeonly;
|
|
42
42
|
_this.examples = initArgs.examples;
|
|
43
|
+
_this.hidden = initArgs.hidden;
|
|
43
44
|
};
|
|
44
45
|
/**
|
|
45
46
|
*
|
|
@@ -51,15 +52,15 @@ class ApiFieldClass extends document_element_js_1.DocumentElement {
|
|
|
51
52
|
return (0, index_js_1.omitUndefined)({
|
|
52
53
|
type: typeName ? typeName : this.type?.toJSON(),
|
|
53
54
|
description: this.description,
|
|
54
|
-
isArray: this.isArray,
|
|
55
|
+
isArray: this.isArray || undefined,
|
|
55
56
|
default: this.default,
|
|
56
57
|
fixed: this.fixed,
|
|
57
|
-
required: this.required,
|
|
58
|
-
exclusive: this.exclusive,
|
|
59
|
-
translatable: this.translatable,
|
|
60
|
-
deprecated: this.deprecated,
|
|
61
|
-
readonly: this.readonly,
|
|
62
|
-
writeonly: this.writeonly,
|
|
58
|
+
required: this.required || undefined,
|
|
59
|
+
exclusive: this.exclusive || undefined,
|
|
60
|
+
translatable: this.translatable || undefined,
|
|
61
|
+
deprecated: this.deprecated || undefined,
|
|
62
|
+
readonly: this.readonly || undefined,
|
|
63
|
+
writeonly: this.writeonly || undefined,
|
|
63
64
|
examples: this.examples,
|
|
64
65
|
});
|
|
65
66
|
}
|
|
@@ -147,7 +147,9 @@ class ComplexTypeBaseClass extends data_type_js_1.DataType {
|
|
|
147
147
|
// Process fields
|
|
148
148
|
let fieldName;
|
|
149
149
|
for (const field of this.fields.values()) {
|
|
150
|
-
if ((context.ignoreReadonlyFields && field.readonly) ||
|
|
150
|
+
if ((context.ignoreReadonlyFields && field.readonly) ||
|
|
151
|
+
(context.ignoreWriteonlyFields && field.writeonly) ||
|
|
152
|
+
(context.ignoreHiddenFields && field.hidden)) {
|
|
151
153
|
schema[field.name] = valgen_1.vg.isUndefined({ coerce: true });
|
|
152
154
|
continue;
|
|
153
155
|
}
|
|
@@ -86,12 +86,7 @@ class SimpleTypeClass extends data_type_js_1.DataType {
|
|
|
86
86
|
properties = this.properties.toJSON(this.properties, this.owner);
|
|
87
87
|
}
|
|
88
88
|
else
|
|
89
|
-
properties = this.properties
|
|
90
|
-
properties = Object.keys(this.attributes).reduce((o, k) => {
|
|
91
|
-
if (properties[k] !== undefined)
|
|
92
|
-
o[k] = properties[k];
|
|
93
|
-
return o;
|
|
94
|
-
}, {});
|
|
89
|
+
properties = this.properties ? (0, index_js_1.cloneObject)(this.properties) : {};
|
|
95
90
|
const baseName = this.base ? this.node.getDataTypeNameWithNs(this.base) : undefined;
|
|
96
91
|
const out = (0, index_js_1.omitUndefined)({
|
|
97
92
|
...data_type_js_1.DataType.prototype.toJSON.apply(this),
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ApiFieldDecorator = ApiFieldDecorator;
|
|
4
|
-
const index_js_1 = require("../../
|
|
5
|
-
const index_js_2 = require("../../schema/index.js");
|
|
4
|
+
const index_js_1 = require("../../schema/index.js");
|
|
6
5
|
const constants_js_1 = require("../constants.js");
|
|
7
6
|
function ApiFieldDecorator(options) {
|
|
8
7
|
return function (target, propertyKey) {
|
|
9
8
|
if (typeof propertyKey !== 'string')
|
|
10
9
|
throw new TypeError(`Symbol properties can't be used as a field`);
|
|
11
10
|
const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) || {};
|
|
12
|
-
metadata.kind =
|
|
11
|
+
metadata.kind = index_js_1.OpraSchema.ComplexType.Kind;
|
|
13
12
|
metadata.fields = metadata.fields || {};
|
|
14
13
|
const designType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
15
14
|
const elemMeta = (metadata.fields[propertyKey] = {
|
|
@@ -20,6 +19,6 @@ function ApiFieldDecorator(options) {
|
|
|
20
19
|
}
|
|
21
20
|
else
|
|
22
21
|
elemMeta.type = elemMeta.type || designType;
|
|
23
|
-
Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA,
|
|
22
|
+
Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, metadata, target.constructor);
|
|
24
23
|
};
|
|
25
24
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const filter_rules_js_1 = require("../../filter/filter-rules.js");
|
|
4
|
-
const index_js_1 = require("../../
|
|
5
|
-
const index_js_2 = require("../../http/index.js");
|
|
4
|
+
const index_js_1 = require("../../http/index.js");
|
|
6
5
|
const constants_js_1 = require("../constants.js");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
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
8
|
const http_operation_js_1 = require("../http/http-operation.js");
|
|
10
9
|
const http_operation_decorator_js_1 = require("./http-operation.decorator.js");
|
|
11
10
|
/** Implementation **/
|
|
@@ -22,7 +21,7 @@ http_operation_js_1.HttpOperation.Entity.Create = function (arg0, arg1) {
|
|
|
22
21
|
args = { ...arg1, type: arg0 };
|
|
23
22
|
/** Initialize the decorator and the chain */
|
|
24
23
|
const decoratorChain = [];
|
|
25
|
-
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain,
|
|
24
|
+
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
|
|
26
25
|
method: 'POST',
|
|
27
26
|
...args,
|
|
28
27
|
composition: 'Entity.Create',
|
|
@@ -31,11 +30,11 @@ http_operation_js_1.HttpOperation.Entity.Create = function (arg0, arg1) {
|
|
|
31
30
|
...args.requestBody,
|
|
32
31
|
required: true,
|
|
33
32
|
},
|
|
34
|
-
})
|
|
33
|
+
});
|
|
35
34
|
decorator
|
|
36
35
|
.QueryParam('projection', {
|
|
37
36
|
description: 'Determines fields projection',
|
|
38
|
-
type: new
|
|
37
|
+
type: new index_js_2.FieldPathType({
|
|
39
38
|
dataType: args.type,
|
|
40
39
|
allowSigns: 'each',
|
|
41
40
|
}),
|
|
@@ -43,15 +42,15 @@ http_operation_js_1.HttpOperation.Entity.Create = function (arg0, arg1) {
|
|
|
43
42
|
arraySeparator: ',',
|
|
44
43
|
})
|
|
45
44
|
.RequestContent(args.requestBody?.type || args.type)
|
|
46
|
-
.Response(
|
|
45
|
+
.Response(index_js_1.HttpStatusCode.CREATED, {
|
|
47
46
|
description: 'Operation is successful. Returns OperationResult with "payload" field that contains the created resource.',
|
|
48
|
-
contentType:
|
|
47
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
49
48
|
type: args.type,
|
|
50
49
|
partial: 'deep',
|
|
51
50
|
})
|
|
52
|
-
.Response(
|
|
51
|
+
.Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
53
52
|
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
54
|
-
contentType:
|
|
53
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
55
54
|
});
|
|
56
55
|
decoratorChain.push((operationMeta) => {
|
|
57
56
|
const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
|
|
@@ -71,19 +70,19 @@ http_operation_js_1.HttpOperation.Entity.Delete = function (arg0, arg1) {
|
|
|
71
70
|
args = { ...arg1, type: arg0 };
|
|
72
71
|
/** Initialize the decorator and the chain */
|
|
73
72
|
const decoratorChain = [];
|
|
74
|
-
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain,
|
|
73
|
+
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
|
|
75
74
|
method: 'DELETE',
|
|
76
75
|
...args,
|
|
77
76
|
composition: 'Entity.Delete',
|
|
78
|
-
})
|
|
77
|
+
});
|
|
79
78
|
decorator
|
|
80
|
-
.Response(
|
|
79
|
+
.Response(index_js_1.HttpStatusCode.OK, {
|
|
81
80
|
description: 'Operation is successful. Returns OperationResult with "affected" field.',
|
|
82
|
-
contentType:
|
|
81
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
83
82
|
})
|
|
84
|
-
.Response(
|
|
83
|
+
.Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
85
84
|
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
86
|
-
contentType:
|
|
85
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
87
86
|
});
|
|
88
87
|
/**
|
|
89
88
|
*
|
|
@@ -129,21 +128,21 @@ http_operation_js_1.HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
|
|
|
129
128
|
/** Initialize the decorator and the chain */
|
|
130
129
|
const decoratorChain = [];
|
|
131
130
|
const filterRules = new filter_rules_js_1.FilterRules();
|
|
132
|
-
const filterType = new
|
|
131
|
+
const filterType = new index_js_2.FilterType({ dataType: args.type });
|
|
133
132
|
filterType.rules = {};
|
|
134
|
-
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain,
|
|
133
|
+
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
|
|
135
134
|
method: 'DELETE',
|
|
136
135
|
...args,
|
|
137
136
|
composition: 'Entity.DeleteMany',
|
|
138
|
-
})
|
|
137
|
+
});
|
|
139
138
|
decorator
|
|
140
|
-
.Response(
|
|
139
|
+
.Response(index_js_1.HttpStatusCode.OK, {
|
|
141
140
|
description: 'Operation is successful. Returns OperationResult with "affected" field.',
|
|
142
|
-
contentType:
|
|
141
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
143
142
|
})
|
|
144
|
-
.Response(
|
|
143
|
+
.Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
145
144
|
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
146
|
-
contentType:
|
|
145
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
147
146
|
})
|
|
148
147
|
.QueryParam('filter', {
|
|
149
148
|
type: filterType,
|
|
@@ -175,32 +174,32 @@ http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
|
|
|
175
174
|
/** Initialize the decorator and the chain */
|
|
176
175
|
const decoratorChain = [];
|
|
177
176
|
const filterRules = new filter_rules_js_1.FilterRules();
|
|
178
|
-
const filterType = new
|
|
177
|
+
const filterType = new index_js_2.FilterType({ dataType: args.type });
|
|
179
178
|
filterType.rules = {};
|
|
180
|
-
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain,
|
|
179
|
+
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
|
|
181
180
|
method: 'GET',
|
|
182
181
|
...args,
|
|
183
182
|
composition: 'Entity.FindMany',
|
|
184
|
-
})
|
|
183
|
+
});
|
|
185
184
|
decorator
|
|
186
|
-
.Response(
|
|
185
|
+
.Response(index_js_1.HttpStatusCode.OK, {
|
|
187
186
|
description: 'Operation is successful. Returns OperationResult with "payload" field that contains list of resources.',
|
|
188
|
-
contentType:
|
|
187
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
189
188
|
type: args.type,
|
|
190
189
|
partial: 'deep',
|
|
191
190
|
isArray: true,
|
|
192
191
|
})
|
|
193
|
-
.Response(
|
|
192
|
+
.Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
194
193
|
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
195
|
-
contentType:
|
|
194
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
196
195
|
})
|
|
197
196
|
.QueryParam('limit', {
|
|
198
197
|
description: 'Determines number of returning instances',
|
|
199
|
-
type: new
|
|
198
|
+
type: new index_js_3.IntegerType({ minValue: 1, maxValue: args.maxLimit }),
|
|
200
199
|
})
|
|
201
200
|
.QueryParam('skip', {
|
|
202
201
|
description: 'Determines number of returning instances',
|
|
203
|
-
type: new
|
|
202
|
+
type: new index_js_3.IntegerType({ minValue: 1 }),
|
|
204
203
|
})
|
|
205
204
|
.QueryParam('count', {
|
|
206
205
|
description: 'Counts all matching instances if enabled',
|
|
@@ -208,7 +207,7 @@ http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
|
|
|
208
207
|
})
|
|
209
208
|
.QueryParam('projection', {
|
|
210
209
|
description: 'Determines fields projection',
|
|
211
|
-
type: new
|
|
210
|
+
type: new index_js_2.FieldPathType({
|
|
212
211
|
dataType: args.type,
|
|
213
212
|
allowSigns: 'each',
|
|
214
213
|
}),
|
|
@@ -221,7 +220,7 @@ http_operation_js_1.HttpOperation.Entity.FindMany = function (arg0, arg1) {
|
|
|
221
220
|
})
|
|
222
221
|
.QueryParam('sort', {
|
|
223
222
|
description: 'Determines sort fields',
|
|
224
|
-
type: new
|
|
223
|
+
type: new index_js_2.FieldPathType({
|
|
225
224
|
dataType: args.type,
|
|
226
225
|
allowSigns: 'first',
|
|
227
226
|
}),
|
|
@@ -273,33 +272,33 @@ http_operation_js_1.HttpOperation.Entity.Get = function (arg0, arg1) {
|
|
|
273
272
|
args = { ...arg1, type: arg0 };
|
|
274
273
|
/** Initialize the decorator and the chain */
|
|
275
274
|
const decoratorChain = [];
|
|
276
|
-
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain,
|
|
275
|
+
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
|
|
277
276
|
method: 'GET',
|
|
278
277
|
...args,
|
|
279
278
|
composition: 'Entity.Get',
|
|
280
|
-
})
|
|
279
|
+
});
|
|
281
280
|
decorator
|
|
282
281
|
.QueryParam('projection', {
|
|
283
282
|
description: 'Determines fields projection',
|
|
284
|
-
type: new
|
|
283
|
+
type: new index_js_2.FieldPathType({
|
|
285
284
|
dataType: args.type,
|
|
286
285
|
allowSigns: 'each',
|
|
287
286
|
}),
|
|
288
287
|
isArray: true,
|
|
289
288
|
arraySeparator: ',',
|
|
290
289
|
})
|
|
291
|
-
.Response(
|
|
290
|
+
.Response(index_js_1.HttpStatusCode.OK, {
|
|
292
291
|
description: 'Operation is successful. Returns OperationResult with "payload" field that contains the resource asked for.',
|
|
293
|
-
contentType:
|
|
292
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
294
293
|
type: args.type,
|
|
295
294
|
partial: 'deep',
|
|
296
295
|
})
|
|
297
|
-
.Response(
|
|
296
|
+
.Response(index_js_1.HttpStatusCode.NO_CONTENT, {
|
|
298
297
|
description: 'Operation is successful but no resource found',
|
|
299
298
|
})
|
|
300
|
-
.Response(
|
|
299
|
+
.Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
301
300
|
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
302
|
-
contentType:
|
|
301
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
303
302
|
});
|
|
304
303
|
/**
|
|
305
304
|
*
|
|
@@ -344,10 +343,10 @@ http_operation_js_1.HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
|
|
|
344
343
|
args = { ...arg1, type: arg0 };
|
|
345
344
|
/** Initialize the decorator and the chain */
|
|
346
345
|
const decoratorChain = [];
|
|
347
|
-
const filterType = new
|
|
346
|
+
const filterType = new index_js_2.FilterType({ dataType: args.type });
|
|
348
347
|
filterType.rules = {};
|
|
349
348
|
const filterRules = new filter_rules_js_1.FilterRules();
|
|
350
|
-
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain,
|
|
349
|
+
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
|
|
351
350
|
method: 'PATCH',
|
|
352
351
|
...args,
|
|
353
352
|
composition: 'Entity.UpdateMany',
|
|
@@ -357,16 +356,16 @@ http_operation_js_1.HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
|
|
|
357
356
|
...args.requestBody,
|
|
358
357
|
required: true,
|
|
359
358
|
},
|
|
360
|
-
})
|
|
359
|
+
});
|
|
361
360
|
decorator
|
|
362
361
|
.RequestContent(args.requestBody?.type || args.type)
|
|
363
|
-
.Response(
|
|
362
|
+
.Response(index_js_1.HttpStatusCode.OK, {
|
|
364
363
|
description: 'Operation is successful. Returns OperationResult with "affected" field.',
|
|
365
|
-
contentType:
|
|
364
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
366
365
|
})
|
|
367
|
-
.Response(
|
|
366
|
+
.Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
368
367
|
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
369
|
-
contentType:
|
|
368
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
370
369
|
})
|
|
371
370
|
.QueryParam('filter', {
|
|
372
371
|
type: filterType,
|
|
@@ -398,9 +397,9 @@ http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
|
398
397
|
/** Initialize the decorator and the chain */
|
|
399
398
|
const decoratorChain = [];
|
|
400
399
|
const filterRules = new filter_rules_js_1.FilterRules();
|
|
401
|
-
const filterType = new
|
|
400
|
+
const filterType = new index_js_2.FilterType({ dataType: args.type });
|
|
402
401
|
filterType.rules = {};
|
|
403
|
-
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain,
|
|
402
|
+
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
|
|
404
403
|
method: 'PATCH',
|
|
405
404
|
...args,
|
|
406
405
|
composition: 'Entity.Update',
|
|
@@ -410,11 +409,11 @@ http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
|
410
409
|
...args.requestBody,
|
|
411
410
|
required: true,
|
|
412
411
|
},
|
|
413
|
-
})
|
|
412
|
+
});
|
|
414
413
|
decorator
|
|
415
414
|
.QueryParam('projection', {
|
|
416
415
|
description: 'Determines fields projection',
|
|
417
|
-
type: new
|
|
416
|
+
type: new index_js_2.FieldPathType({
|
|
418
417
|
dataType: args.type,
|
|
419
418
|
allowSigns: 'each',
|
|
420
419
|
}),
|
|
@@ -426,18 +425,18 @@ http_operation_js_1.HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
|
426
425
|
description: 'Determines filter fields',
|
|
427
426
|
})
|
|
428
427
|
.RequestContent(args.requestBody?.type || args.type)
|
|
429
|
-
.Response(
|
|
428
|
+
.Response(index_js_1.HttpStatusCode.OK, {
|
|
430
429
|
description: 'Operation is successful. Returns OperationResult with "payload" field that contains updated resource.',
|
|
431
|
-
contentType:
|
|
430
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
432
431
|
type: args.type,
|
|
433
432
|
partial: 'deep',
|
|
434
433
|
})
|
|
435
|
-
.Response(
|
|
434
|
+
.Response(index_js_1.HttpStatusCode.NO_CONTENT, {
|
|
436
435
|
description: 'Operation is successful but no resource found',
|
|
437
436
|
})
|
|
438
|
-
.Response(
|
|
437
|
+
.Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
439
438
|
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
440
|
-
contentType:
|
|
439
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
441
440
|
});
|
|
442
441
|
/**
|
|
443
442
|
*
|
|
@@ -9,6 +9,7 @@ const index_js_2 = require("../i18n/index.js");
|
|
|
9
9
|
class OpraException extends Error {
|
|
10
10
|
constructor(issue, cause) {
|
|
11
11
|
super('Unknown error');
|
|
12
|
+
this.severity = 'error';
|
|
12
13
|
cause = cause || (issue instanceof Error ? issue : undefined);
|
|
13
14
|
if (issue instanceof Error)
|
|
14
15
|
cause = issue;
|
|
@@ -10,10 +10,10 @@ const constants_js_1 = require("../document/constants.js");
|
|
|
10
10
|
function cloneObject(obj, jsonOnly) {
|
|
11
11
|
return (0, putil_merge_1.default)({}, obj, {
|
|
12
12
|
deep: v => (0, putil_isplainobject_1.default)(v) && !v[constants_js_1.DATATYPE_METADATA],
|
|
13
|
+
descriptor: true,
|
|
13
14
|
filter: (source, key) => {
|
|
14
15
|
const v = source[key];
|
|
15
|
-
return (
|
|
16
|
-
(typeof v !== 'function' && (typeof v !== 'object' || (0, putil_isplainobject_1.default)(v) || Array.isArray(v))));
|
|
16
|
+
return !jsonOnly || (typeof v !== 'function' && (typeof v !== 'object' || (0, putil_isplainobject_1.default)(v) || Array.isArray(v)));
|
|
17
17
|
},
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -14,6 +14,8 @@ export class ApiDocument extends DocumentElement {
|
|
|
14
14
|
constructor() {
|
|
15
15
|
super(null);
|
|
16
16
|
this[_a] = new WeakMap();
|
|
17
|
+
this.id = '';
|
|
18
|
+
this.info = {};
|
|
17
19
|
this.references = new ResponsiveMap();
|
|
18
20
|
this.types = new DataTypeMap();
|
|
19
21
|
this.node[kDataTypeMap] = this.types;
|
|
@@ -37,6 +37,7 @@ export const ApiField = function (...args) {
|
|
|
37
37
|
_this.readonly = initArgs.readonly;
|
|
38
38
|
_this.writeonly = initArgs.writeonly;
|
|
39
39
|
_this.examples = initArgs.examples;
|
|
40
|
+
_this.hidden = initArgs.hidden;
|
|
40
41
|
};
|
|
41
42
|
/**
|
|
42
43
|
*
|
|
@@ -48,15 +49,15 @@ class ApiFieldClass extends DocumentElement {
|
|
|
48
49
|
return omitUndefined({
|
|
49
50
|
type: typeName ? typeName : this.type?.toJSON(),
|
|
50
51
|
description: this.description,
|
|
51
|
-
isArray: this.isArray,
|
|
52
|
+
isArray: this.isArray || undefined,
|
|
52
53
|
default: this.default,
|
|
53
54
|
fixed: this.fixed,
|
|
54
|
-
required: this.required,
|
|
55
|
-
exclusive: this.exclusive,
|
|
56
|
-
translatable: this.translatable,
|
|
57
|
-
deprecated: this.deprecated,
|
|
58
|
-
readonly: this.readonly,
|
|
59
|
-
writeonly: this.writeonly,
|
|
55
|
+
required: this.required || undefined,
|
|
56
|
+
exclusive: this.exclusive || undefined,
|
|
57
|
+
translatable: this.translatable || undefined,
|
|
58
|
+
deprecated: this.deprecated || undefined,
|
|
59
|
+
readonly: this.readonly || undefined,
|
|
60
|
+
writeonly: this.writeonly || undefined,
|
|
60
61
|
examples: this.examples,
|
|
61
62
|
});
|
|
62
63
|
}
|
|
@@ -144,7 +144,9 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
144
144
|
// Process fields
|
|
145
145
|
let fieldName;
|
|
146
146
|
for (const field of this.fields.values()) {
|
|
147
|
-
if ((context.ignoreReadonlyFields && field.readonly) ||
|
|
147
|
+
if ((context.ignoreReadonlyFields && field.readonly) ||
|
|
148
|
+
(context.ignoreWriteonlyFields && field.writeonly) ||
|
|
149
|
+
(context.ignoreHiddenFields && field.hidden)) {
|
|
148
150
|
schema[field.name] = vg.isUndefined({ coerce: true });
|
|
149
151
|
continue;
|
|
150
152
|
}
|
|
@@ -83,12 +83,7 @@ class SimpleTypeClass extends DataType {
|
|
|
83
83
|
properties = this.properties.toJSON(this.properties, this.owner);
|
|
84
84
|
}
|
|
85
85
|
else
|
|
86
|
-
properties = this.properties
|
|
87
|
-
properties = Object.keys(this.attributes).reduce((o, k) => {
|
|
88
|
-
if (properties[k] !== undefined)
|
|
89
|
-
o[k] = properties[k];
|
|
90
|
-
return o;
|
|
91
|
-
}, {});
|
|
86
|
+
properties = this.properties ? cloneObject(this.properties) : {};
|
|
92
87
|
const baseName = this.base ? this.node.getDataTypeNameWithNs(this.base) : undefined;
|
|
93
88
|
const out = omitUndefined({
|
|
94
89
|
...DataType.prototype.toJSON.apply(this),
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { omitUndefined } from '../../helpers/index.js';
|
|
2
1
|
import { OpraSchema } from '../../schema/index.js';
|
|
3
2
|
import { DATATYPE_METADATA } from '../constants.js';
|
|
4
3
|
export function ApiFieldDecorator(options) {
|
|
@@ -17,6 +16,6 @@ export function ApiFieldDecorator(options) {
|
|
|
17
16
|
}
|
|
18
17
|
else
|
|
19
18
|
elemMeta.type = elemMeta.type || designType;
|
|
20
|
-
Reflect.defineMetadata(DATATYPE_METADATA,
|
|
19
|
+
Reflect.defineMetadata(DATATYPE_METADATA, metadata, target.constructor);
|
|
21
20
|
};
|
|
22
21
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { FilterRules } from '../../filter/filter-rules.js';
|
|
2
|
-
import { omitUndefined } from '../../helpers/index.js';
|
|
3
2
|
import { HttpStatusCode, MimeTypes } from '../../http/index.js';
|
|
4
3
|
import { DATATYPE_METADATA } from '../constants.js';
|
|
5
4
|
import { FieldPathType, FilterType } from '../data-type/extended-types/index.js';
|
|
@@ -20,7 +19,7 @@ HttpOperation.Entity.Create = function (arg0, arg1) {
|
|
|
20
19
|
args = { ...arg1, type: arg0 };
|
|
21
20
|
/** Initialize the decorator and the chain */
|
|
22
21
|
const decoratorChain = [];
|
|
23
|
-
const decorator = HttpOperationDecoratorFactory(decoratorChain,
|
|
22
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
24
23
|
method: 'POST',
|
|
25
24
|
...args,
|
|
26
25
|
composition: 'Entity.Create',
|
|
@@ -29,7 +28,7 @@ HttpOperation.Entity.Create = function (arg0, arg1) {
|
|
|
29
28
|
...args.requestBody,
|
|
30
29
|
required: true,
|
|
31
30
|
},
|
|
32
|
-
})
|
|
31
|
+
});
|
|
33
32
|
decorator
|
|
34
33
|
.QueryParam('projection', {
|
|
35
34
|
description: 'Determines fields projection',
|
|
@@ -69,11 +68,11 @@ HttpOperation.Entity.Delete = function (arg0, arg1) {
|
|
|
69
68
|
args = { ...arg1, type: arg0 };
|
|
70
69
|
/** Initialize the decorator and the chain */
|
|
71
70
|
const decoratorChain = [];
|
|
72
|
-
const decorator = HttpOperationDecoratorFactory(decoratorChain,
|
|
71
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
73
72
|
method: 'DELETE',
|
|
74
73
|
...args,
|
|
75
74
|
composition: 'Entity.Delete',
|
|
76
|
-
})
|
|
75
|
+
});
|
|
77
76
|
decorator
|
|
78
77
|
.Response(HttpStatusCode.OK, {
|
|
79
78
|
description: 'Operation is successful. Returns OperationResult with "affected" field.',
|
|
@@ -129,11 +128,11 @@ HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
|
|
|
129
128
|
const filterRules = new FilterRules();
|
|
130
129
|
const filterType = new FilterType({ dataType: args.type });
|
|
131
130
|
filterType.rules = {};
|
|
132
|
-
const decorator = HttpOperationDecoratorFactory(decoratorChain,
|
|
131
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
133
132
|
method: 'DELETE',
|
|
134
133
|
...args,
|
|
135
134
|
composition: 'Entity.DeleteMany',
|
|
136
|
-
})
|
|
135
|
+
});
|
|
137
136
|
decorator
|
|
138
137
|
.Response(HttpStatusCode.OK, {
|
|
139
138
|
description: 'Operation is successful. Returns OperationResult with "affected" field.',
|
|
@@ -175,11 +174,11 @@ HttpOperation.Entity.FindMany = function (arg0, arg1) {
|
|
|
175
174
|
const filterRules = new FilterRules();
|
|
176
175
|
const filterType = new FilterType({ dataType: args.type });
|
|
177
176
|
filterType.rules = {};
|
|
178
|
-
const decorator = HttpOperationDecoratorFactory(decoratorChain,
|
|
177
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
179
178
|
method: 'GET',
|
|
180
179
|
...args,
|
|
181
180
|
composition: 'Entity.FindMany',
|
|
182
|
-
})
|
|
181
|
+
});
|
|
183
182
|
decorator
|
|
184
183
|
.Response(HttpStatusCode.OK, {
|
|
185
184
|
description: 'Operation is successful. Returns OperationResult with "payload" field that contains list of resources.',
|
|
@@ -271,11 +270,11 @@ HttpOperation.Entity.Get = function (arg0, arg1) {
|
|
|
271
270
|
args = { ...arg1, type: arg0 };
|
|
272
271
|
/** Initialize the decorator and the chain */
|
|
273
272
|
const decoratorChain = [];
|
|
274
|
-
const decorator = HttpOperationDecoratorFactory(decoratorChain,
|
|
273
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
275
274
|
method: 'GET',
|
|
276
275
|
...args,
|
|
277
276
|
composition: 'Entity.Get',
|
|
278
|
-
})
|
|
277
|
+
});
|
|
279
278
|
decorator
|
|
280
279
|
.QueryParam('projection', {
|
|
281
280
|
description: 'Determines fields projection',
|
|
@@ -345,7 +344,7 @@ HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
|
|
|
345
344
|
const filterType = new FilterType({ dataType: args.type });
|
|
346
345
|
filterType.rules = {};
|
|
347
346
|
const filterRules = new FilterRules();
|
|
348
|
-
const decorator = HttpOperationDecoratorFactory(decoratorChain,
|
|
347
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
349
348
|
method: 'PATCH',
|
|
350
349
|
...args,
|
|
351
350
|
composition: 'Entity.UpdateMany',
|
|
@@ -355,7 +354,7 @@ HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
|
|
|
355
354
|
...args.requestBody,
|
|
356
355
|
required: true,
|
|
357
356
|
},
|
|
358
|
-
})
|
|
357
|
+
});
|
|
359
358
|
decorator
|
|
360
359
|
.RequestContent(args.requestBody?.type || args.type)
|
|
361
360
|
.Response(HttpStatusCode.OK, {
|
|
@@ -398,7 +397,7 @@ HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
|
398
397
|
const filterRules = new FilterRules();
|
|
399
398
|
const filterType = new FilterType({ dataType: args.type });
|
|
400
399
|
filterType.rules = {};
|
|
401
|
-
const decorator = HttpOperationDecoratorFactory(decoratorChain,
|
|
400
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
402
401
|
method: 'PATCH',
|
|
403
402
|
...args,
|
|
404
403
|
composition: 'Entity.Update',
|
|
@@ -408,7 +407,7 @@ HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
|
408
407
|
...args.requestBody,
|
|
409
408
|
required: true,
|
|
410
409
|
},
|
|
411
|
-
})
|
|
410
|
+
});
|
|
412
411
|
decorator
|
|
413
412
|
.QueryParam('projection', {
|
|
414
413
|
description: 'Determines fields projection',
|
|
@@ -6,6 +6,7 @@ import { i18n } from '../i18n/index.js';
|
|
|
6
6
|
export class OpraException extends Error {
|
|
7
7
|
constructor(issue, cause) {
|
|
8
8
|
super('Unknown error');
|
|
9
|
+
this.severity = 'error';
|
|
9
10
|
cause = cause || (issue instanceof Error ? issue : undefined);
|
|
10
11
|
if (issue instanceof Error)
|
|
11
12
|
cause = issue;
|
|
@@ -4,10 +4,10 @@ import { DATATYPE_METADATA } from '../document/constants.js';
|
|
|
4
4
|
export function cloneObject(obj, jsonOnly) {
|
|
5
5
|
return merge({}, obj, {
|
|
6
6
|
deep: v => isPlainObject(v) && !v[DATATYPE_METADATA],
|
|
7
|
+
descriptor: true,
|
|
7
8
|
filter: (source, key) => {
|
|
8
9
|
const v = source[key];
|
|
9
|
-
return (
|
|
10
|
-
(typeof v !== 'function' && (typeof v !== 'object' || isPlainObject(v) || Array.isArray(v))));
|
|
10
|
+
return !jsonOnly || (typeof v !== 'function' && (typeof v !== 'object' || isPlainObject(v) || Array.isArray(v)));
|
|
11
11
|
},
|
|
12
12
|
});
|
|
13
13
|
}
|