@opra/common 1.0.0-alpha.6 → 1.0.0-alpha.8
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 +5454 -5437
- package/cjs/document/common/document-element.js +2 -1
- package/cjs/document/data-type/api-field.js +2 -1
- package/cjs/document/data-type/complex-type-base.js +2 -1
- package/cjs/document/data-type/complex-type.js +4 -2
- package/cjs/document/data-type/data-type.js +2 -1
- package/cjs/document/data-type/enum-type.js +3 -2
- package/cjs/document/data-type/extended-types/field-path.type.js +1 -3
- package/cjs/document/data-type/extended-types/filter.type.js +15 -17
- package/cjs/document/data-type/mapped-type.js +9 -5
- package/cjs/document/data-type/mixin-type.js +2 -1
- package/cjs/document/data-type/simple-type.js +8 -9
- package/cjs/document/data-type/utils/create-mapped-class.js +2 -1
- package/cjs/document/decorators/http-operation.decorator.js +8 -4
- package/cjs/document/factory/api-document.factory.js +1 -3
- package/cjs/document/factory/data-type.factory.js +37 -19
- package/cjs/document/factory/http-api.factory.js +3 -1
- package/cjs/document/http/http-controller.js +6 -2
- package/cjs/document/http/http-media-type.js +4 -2
- package/cjs/document/http/http-operation-response.js +2 -1
- package/cjs/document/http/http-operation.js +6 -0
- package/cjs/document/http/http-status-range.js +1 -2
- package/cjs/document/index.js +5 -5
- package/cjs/exception/index.js +5 -5
- package/cjs/filter/antlr/OpraFilterParser.js +28 -82
- package/cjs/filter/ast/index.js +1 -1
- package/cjs/filter/build.js +1 -3
- package/cjs/filter/filter-rules.js +4 -2
- package/cjs/filter/opra-filter.ns.js +2 -2
- package/cjs/filter/parse.js +1 -3
- package/cjs/helpers/mixin-utils.js +2 -1
- package/cjs/helpers/monkey-patches.js +4 -2
- package/cjs/helpers/parse-fields-projection.js +1 -3
- package/cjs/helpers/responsive-map.js +5 -4
- package/cjs/i18n/i18n.js +4 -3
- package/cjs/i18n/index.js +1 -1
- package/cjs/index.js +1 -1
- package/esm/document/common/document-element.js +2 -1
- package/esm/document/data-type/api-field.js +2 -1
- package/esm/document/data-type/complex-type-base.js +2 -1
- package/esm/document/data-type/complex-type.js +4 -2
- package/esm/document/data-type/data-type.js +2 -1
- package/esm/document/data-type/enum-type.js +3 -2
- package/esm/document/data-type/extended-types/field-path.type.js +1 -3
- package/esm/document/data-type/extended-types/filter.type.js +15 -17
- package/esm/document/data-type/mapped-type.js +9 -5
- package/esm/document/data-type/mixin-type.js +2 -1
- package/esm/document/data-type/simple-type.js +8 -9
- package/esm/document/data-type/utils/create-mapped-class.js +2 -1
- package/esm/document/decorators/http-operation.decorator.js +8 -4
- package/esm/document/factory/api-document.factory.js +1 -3
- package/esm/document/factory/data-type.factory.js +37 -19
- package/esm/document/factory/http-api.factory.js +3 -1
- package/esm/document/http/http-controller.js +6 -2
- package/esm/document/http/http-media-type.js +4 -2
- package/esm/document/http/http-operation-response.js +2 -1
- package/esm/document/http/http-operation.js +5 -0
- package/esm/document/http/http-status-range.js +1 -2
- package/esm/document/index.js +5 -5
- package/esm/exception/index.js +5 -5
- package/esm/filter/antlr/OpraFilterParser.js +28 -82
- package/esm/filter/ast/index.js +1 -1
- package/esm/filter/build.js +1 -3
- package/esm/filter/filter-rules.js +4 -2
- package/esm/filter/opra-filter.ns.js +2 -2
- package/esm/filter/parse.js +1 -3
- package/esm/helpers/mixin-utils.js +2 -1
- package/esm/helpers/monkey-patches.js +4 -2
- package/esm/helpers/parse-fields-projection.js +1 -3
- package/esm/helpers/responsive-map.js +5 -4
- package/esm/i18n/i18n.js +4 -3
- package/esm/i18n/index.js +1 -1
- package/esm/index.js +1 -1
- package/package.json +5 -4
- package/types/document/http/http-controller.d.ts +1 -0
- package/types/document/http/http-operation.d.ts +1 -0
- package/types/document/index.d.ts +5 -5
- package/types/exception/index.d.ts +5 -5
- package/types/filter/ast/index.d.ts +1 -1
- package/types/filter/opra-filter.ns.d.ts +2 -2
- package/types/i18n/i18n.d.ts +21 -19
- package/types/index.d.ts +1 -1
|
@@ -53,24 +53,22 @@ FilterType = __decorate([
|
|
|
53
53
|
__metadata("design:paramtypes", [Object])
|
|
54
54
|
], FilterType);
|
|
55
55
|
export { FilterType };
|
|
56
|
-
const decodeFilter = (dataType, rules) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return filter;
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
context.fail(_this, `Not a valid filter expression. ${e.message}`, input, e.errors);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
56
|
+
const decodeFilter = (dataType, rules) => validator('decodeFilter', (input, context, _this) => {
|
|
57
|
+
if (typeof input === 'string') {
|
|
58
|
+
try {
|
|
59
|
+
const filter = OpraFilter.parse(input);
|
|
60
|
+
if (rules)
|
|
61
|
+
return rules.normalizeFilter(filter, dataType);
|
|
62
|
+
return filter;
|
|
69
63
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
catch (e) {
|
|
65
|
+
context.fail(_this, `Not a valid filter expression. ${e.message}`, input, e.errors);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
context.fail(_this, `Nt a valid filter expression string`, input);
|
|
70
|
+
});
|
|
71
|
+
const encodeFilter = validator('encodeFilter', (input, context, _this) => {
|
|
74
72
|
if (input instanceof OpraFilter.Ast) {
|
|
75
73
|
return input.toString();
|
|
76
74
|
}
|
|
@@ -19,22 +19,25 @@ export const MappedType = function (...args) {
|
|
|
19
19
|
_this.kind = OpraSchema.MappedType.Kind;
|
|
20
20
|
if (initArgs.base) {
|
|
21
21
|
// noinspection SuspiciousTypeOfGuard
|
|
22
|
-
if (!(initArgs.base instanceof ComplexTypeBase))
|
|
22
|
+
if (!(initArgs.base instanceof ComplexTypeBase)) {
|
|
23
23
|
throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
|
|
24
|
+
}
|
|
24
25
|
_this.base = initArgs.base;
|
|
25
26
|
_this.ctor = initArgs.ctor || _this.base.ctor;
|
|
26
27
|
if (initArgs.pick)
|
|
27
28
|
_this.pick = initArgs.pick.map(f => _this.base.normalizeFieldPath(f));
|
|
28
29
|
else if (initArgs.omit)
|
|
29
30
|
_this.omit = initArgs.omit.map(f => _this.base.normalizeFieldPath(f));
|
|
30
|
-
else if (initArgs.partial)
|
|
31
|
+
else if (initArgs.partial) {
|
|
31
32
|
_this.partial = Array.isArray(initArgs.partial)
|
|
32
33
|
? initArgs.partial.map(f => _this.base.normalizeFieldPath(f))
|
|
33
34
|
: initArgs.partial;
|
|
34
|
-
|
|
35
|
+
}
|
|
36
|
+
else if (initArgs.required) {
|
|
35
37
|
_this.required = Array.isArray(initArgs.required)
|
|
36
38
|
? initArgs.required.map(f => _this.base.normalizeFieldPath(f))
|
|
37
39
|
: initArgs.required;
|
|
40
|
+
}
|
|
38
41
|
/** Copy fields from base */
|
|
39
42
|
const isInheritedPredicate = getIsInheritedPredicateFn(_this.pick, _this.omit);
|
|
40
43
|
const partial = Array.isArray(_this.partial) ? _this.partial.map(x => x.toLowerCase()) : _this.partial;
|
|
@@ -54,8 +57,9 @@ export const MappedType = function (...args) {
|
|
|
54
57
|
}
|
|
55
58
|
if (!_this.pick ||
|
|
56
59
|
_this.base.additionalFields === false ||
|
|
57
|
-
(Array.isArray(_this.base.additionalFields) && _this.base.additionalFields?.[0] === 'error'))
|
|
60
|
+
(Array.isArray(_this.base.additionalFields) && _this.base.additionalFields?.[0] === 'error')) {
|
|
58
61
|
_this.additionalFields = _this.base.additionalFields;
|
|
62
|
+
}
|
|
59
63
|
if (initArgs.base.keyField && isInheritedPredicate(initArgs.base.keyField))
|
|
60
64
|
_this.keyField = initArgs.base.keyField;
|
|
61
65
|
}
|
|
@@ -88,4 +92,4 @@ class MappedTypeClass extends ComplexTypeBase {
|
|
|
88
92
|
}
|
|
89
93
|
}
|
|
90
94
|
MappedType.prototype = MappedTypeClass.prototype;
|
|
91
|
-
MappedType._applyMixin = () =>
|
|
95
|
+
MappedType._applyMixin = () => undefined;
|
|
@@ -97,8 +97,9 @@ function MixinTypeFactory(...args) {
|
|
|
97
97
|
if (!(itemMeta &&
|
|
98
98
|
(itemMeta.kind === OpraSchema.ComplexType.Kind ||
|
|
99
99
|
itemMeta.kind === OpraSchema.MixinType.Kind ||
|
|
100
|
-
itemMeta.kind === OpraSchema.MappedType.Kind)))
|
|
100
|
+
itemMeta.kind === OpraSchema.MappedType.Kind))) {
|
|
101
101
|
throw new TypeError(`Class "${c.name}" is not a ${OpraSchema.ComplexType.Kind}, ${OpraSchema.MixinType.Kind} or ${OpraSchema.MappedType.Kind}`);
|
|
102
|
+
}
|
|
102
103
|
metadata.types.push(c);
|
|
103
104
|
mergePrototype(MixinClass.prototype, c.prototype);
|
|
104
105
|
}
|
|
@@ -20,8 +20,9 @@ export const SimpleType = function (...args) {
|
|
|
20
20
|
_this.kind = OpraSchema.SimpleType.Kind;
|
|
21
21
|
if (initArgs.base) {
|
|
22
22
|
// noinspection SuspiciousTypeOfGuard
|
|
23
|
-
if (!(initArgs.base instanceof SimpleType))
|
|
23
|
+
if (!(initArgs.base instanceof SimpleType)) {
|
|
24
24
|
throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
|
|
25
|
+
}
|
|
25
26
|
_this.base = initArgs.base;
|
|
26
27
|
}
|
|
27
28
|
_this.properties = initArgs.properties;
|
|
@@ -67,15 +68,13 @@ class SimpleTypeClass extends DataType {
|
|
|
67
68
|
}
|
|
68
69
|
return isAny;
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
t = this.base;
|
|
76
|
-
}
|
|
77
|
-
return isAny;
|
|
71
|
+
let t = this;
|
|
72
|
+
while (t) {
|
|
73
|
+
if (t._generateEncoder)
|
|
74
|
+
return t._generateEncoder(prop, options?.documentElement || this.owner);
|
|
75
|
+
t = this.base;
|
|
78
76
|
}
|
|
77
|
+
return isAny;
|
|
79
78
|
}
|
|
80
79
|
toJSON() {
|
|
81
80
|
const attributes = omitUndefined(this.ownAttributes);
|
|
@@ -23,8 +23,9 @@ export function createMappedClass(source, config, options) {
|
|
|
23
23
|
throw new TypeError(`Class "${source}" doesn't have datatype metadata information`);
|
|
24
24
|
if (!(m.kind === OpraSchema.ComplexType.Kind ||
|
|
25
25
|
m.kind === OpraSchema.MappedType.Kind ||
|
|
26
|
-
m.kind === OpraSchema.MixinType.Kind))
|
|
26
|
+
m.kind === OpraSchema.MixinType.Kind)) {
|
|
27
27
|
throw new TypeError(`Class "${source}" is not a ${OpraSchema.ComplexType.Kind}`);
|
|
28
|
+
}
|
|
28
29
|
}
|
|
29
30
|
const metadata = {
|
|
30
31
|
...options,
|
|
@@ -33,8 +33,9 @@ export function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
33
33
|
type: arg1,
|
|
34
34
|
}
|
|
35
35
|
: { ...arg1, name, location: 'cookie' };
|
|
36
|
-
if (meta.parameters)
|
|
36
|
+
if (meta.parameters) {
|
|
37
37
|
meta.parameters = meta.parameters.filter(p => !(p.location === 'cookie' && String(p.name) === String(name)));
|
|
38
|
+
}
|
|
38
39
|
else
|
|
39
40
|
meta.parameters = [];
|
|
40
41
|
meta.parameters.push(paramMeta);
|
|
@@ -53,8 +54,9 @@ export function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
53
54
|
type: arg1,
|
|
54
55
|
}
|
|
55
56
|
: { ...arg1, name, location: 'header' };
|
|
56
|
-
if (meta.parameters)
|
|
57
|
+
if (meta.parameters) {
|
|
57
58
|
meta.parameters = meta.parameters.filter(p => !(p.location === 'header' && String(p.name) === String(name)));
|
|
59
|
+
}
|
|
58
60
|
else
|
|
59
61
|
meta.parameters = [];
|
|
60
62
|
meta.parameters.push(paramMeta);
|
|
@@ -73,8 +75,9 @@ export function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
73
75
|
type: arg1,
|
|
74
76
|
}
|
|
75
77
|
: { ...arg1, name, location: 'query' };
|
|
76
|
-
if (meta.parameters)
|
|
78
|
+
if (meta.parameters) {
|
|
77
79
|
meta.parameters = meta.parameters.filter(p => !(p.location === 'query' && String(p.name) === String(name)));
|
|
80
|
+
}
|
|
78
81
|
else
|
|
79
82
|
meta.parameters = [];
|
|
80
83
|
meta.parameters.push(paramMeta);
|
|
@@ -93,8 +96,9 @@ export function HttpOperationDecoratorFactory(decoratorChain, options) {
|
|
|
93
96
|
type: arg1,
|
|
94
97
|
}
|
|
95
98
|
: { ...arg1, name, location: 'path' };
|
|
96
|
-
if (meta.parameters)
|
|
99
|
+
if (meta.parameters) {
|
|
97
100
|
meta.parameters = meta.parameters.filter(p => !(p.location === 'path' && String(p.name) === String(name)));
|
|
101
|
+
}
|
|
98
102
|
else
|
|
99
103
|
meta.parameters = [];
|
|
100
104
|
meta.parameters.push(paramMeta);
|
|
@@ -42,9 +42,7 @@ export class ApiDocumentFactory {
|
|
|
42
42
|
context.error.message = `(${l}) error${l > 1 ? 's' : ''} found in document schema.`;
|
|
43
43
|
if (context.showErrorDetails) {
|
|
44
44
|
context.error.message += context.error.details
|
|
45
|
-
.map(d => {
|
|
46
|
-
return `\n\n - ${d.message}` + (d.path ? `\n @${d.path}` : '');
|
|
47
|
-
})
|
|
45
|
+
.map(d => `\n\n - ${d.message}` + (d.path ? `\n @${d.path}` : ''))
|
|
48
46
|
.join('');
|
|
49
47
|
}
|
|
50
48
|
}
|
|
@@ -92,10 +92,10 @@ export class DataTypeFactory {
|
|
|
92
92
|
thunk = await resolveThunk(thunk);
|
|
93
93
|
const metadata = Reflect.getMetadata(DATATYPE_METADATA, thunk) || thunk[DATATYPE_METADATA];
|
|
94
94
|
if (!(metadata && metadata.name)) {
|
|
95
|
-
if (typeof thunk === 'function')
|
|
95
|
+
if (typeof thunk === 'function') {
|
|
96
96
|
return context.addError(`Class "${thunk.name}" doesn't have a valid data type metadata`);
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
}
|
|
98
|
+
return context.addError(`Object doesn't have a valid data type metadata`);
|
|
99
99
|
}
|
|
100
100
|
importQueue.set(metadata.name, thunk);
|
|
101
101
|
});
|
|
@@ -114,8 +114,9 @@ export class DataTypeFactory {
|
|
|
114
114
|
continue;
|
|
115
115
|
const dt = await this._importDataTypeArgs(context, owner, name);
|
|
116
116
|
// istanbul ignore next
|
|
117
|
-
if (dt && typeof dt !== 'string')
|
|
117
|
+
if (dt && typeof dt !== 'string') {
|
|
118
118
|
context.addError(`Embedded data type can't be loaded into document node directly`);
|
|
119
|
+
}
|
|
119
120
|
}
|
|
120
121
|
return Array.from(initArgsMap.values());
|
|
121
122
|
}
|
|
@@ -179,8 +180,9 @@ export class DataTypeFactory {
|
|
|
179
180
|
const baseArgs = await this._importDataTypeArgs(context, owner, metadata.name);
|
|
180
181
|
if (!baseArgs)
|
|
181
182
|
return;
|
|
182
|
-
if (typeof baseArgs === 'object' && baseArgs.kind !== OpraSchema.SimpleType.Kind)
|
|
183
|
+
if (typeof baseArgs === 'object' && baseArgs.kind !== OpraSchema.SimpleType.Kind) {
|
|
183
184
|
return context.addError('Kind of base data type is not same');
|
|
185
|
+
}
|
|
184
186
|
return {
|
|
185
187
|
kind: OpraSchema.SimpleType.Kind,
|
|
186
188
|
name: undefined,
|
|
@@ -216,8 +218,9 @@ export class DataTypeFactory {
|
|
|
216
218
|
out._instance = { name: metadata.name };
|
|
217
219
|
out[kDataTypeMap] = owner.node[kDataTypeMap];
|
|
218
220
|
}
|
|
219
|
-
else
|
|
221
|
+
else {
|
|
220
222
|
return context.addError(`Data Type (${out.name}) must be explicitly added to type list in the document scope`);
|
|
223
|
+
}
|
|
221
224
|
}
|
|
222
225
|
switch (out.kind) {
|
|
223
226
|
case OpraSchema.ComplexType.Kind:
|
|
@@ -265,8 +268,9 @@ export class DataTypeFactory {
|
|
|
265
268
|
}
|
|
266
269
|
else if (initArgs.ctor) {
|
|
267
270
|
const baseClass = Object.getPrototypeOf(initArgs.ctor.prototype).constructor;
|
|
268
|
-
if (Reflect.hasMetadata(DATATYPE_METADATA, baseClass))
|
|
271
|
+
if (Reflect.hasMetadata(DATATYPE_METADATA, baseClass)) {
|
|
269
272
|
baseArgs = await this._importDataTypeArgs(context, owner, baseClass);
|
|
273
|
+
}
|
|
270
274
|
}
|
|
271
275
|
if (!baseArgs)
|
|
272
276
|
return;
|
|
@@ -275,14 +279,16 @@ export class DataTypeFactory {
|
|
|
275
279
|
});
|
|
276
280
|
// Initialize additionalFields
|
|
277
281
|
if (metadata.additionalFields != null) {
|
|
278
|
-
if (typeof metadata.additionalFields === 'boolean' || Array.isArray(metadata.additionalFields))
|
|
282
|
+
if (typeof metadata.additionalFields === 'boolean' || Array.isArray(metadata.additionalFields)) {
|
|
279
283
|
initArgs.additionalFields = metadata.additionalFields;
|
|
280
|
-
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
281
286
|
await context.enterAsync('.additionalFields', async () => {
|
|
282
287
|
const t = await this._importDataTypeArgs(context, owner, metadata.additionalFields);
|
|
283
288
|
if (t)
|
|
284
289
|
initArgs.additionalFields = preferName(t);
|
|
285
290
|
});
|
|
291
|
+
}
|
|
286
292
|
}
|
|
287
293
|
if (metadata.fields) {
|
|
288
294
|
initArgs.fields = {};
|
|
@@ -290,8 +296,9 @@ export class DataTypeFactory {
|
|
|
290
296
|
for (const [k, v] of Object.entries(metadata.fields)) {
|
|
291
297
|
await context.enterAsync(`[${k}]`, async () => {
|
|
292
298
|
const fieldMeta = typeof v === 'string' ? { type: v } : v;
|
|
293
|
-
if (fieldMeta.isArray && !fieldMeta.type)
|
|
299
|
+
if (fieldMeta.isArray && !fieldMeta.type) {
|
|
294
300
|
return context.addError(`"type" must be defined explicitly for array fields`);
|
|
301
|
+
}
|
|
295
302
|
const t = await this._importDataTypeArgs(context, owner, fieldMeta.type || 'any');
|
|
296
303
|
if (!t)
|
|
297
304
|
return;
|
|
@@ -325,8 +332,9 @@ export class DataTypeFactory {
|
|
|
325
332
|
}
|
|
326
333
|
else if (initArgs.ctor) {
|
|
327
334
|
const baseClass = Object.getPrototypeOf(initArgs.ctor.prototype).constructor;
|
|
328
|
-
if (Reflect.hasMetadata(DATATYPE_METADATA, baseClass))
|
|
335
|
+
if (Reflect.hasMetadata(DATATYPE_METADATA, baseClass)) {
|
|
329
336
|
baseArgs = await this._importDataTypeArgs(context, owner, baseClass);
|
|
337
|
+
}
|
|
330
338
|
}
|
|
331
339
|
if (!baseArgs)
|
|
332
340
|
return;
|
|
@@ -339,10 +347,12 @@ export class DataTypeFactory {
|
|
|
339
347
|
initArgs.properties = new initArgs.ctor();
|
|
340
348
|
if (metadata.attributes)
|
|
341
349
|
initArgs.attributes = cloneObject(metadata.attributes);
|
|
342
|
-
if (typeof initArgs.properties?.[DECODER] === 'function')
|
|
350
|
+
if (typeof initArgs.properties?.[DECODER] === 'function') {
|
|
343
351
|
initArgs.generateDecoder = initArgs.properties?.[DECODER].bind(initArgs.properties);
|
|
344
|
-
|
|
352
|
+
}
|
|
353
|
+
if (typeof initArgs.properties?.[ENCODER] === 'function') {
|
|
345
354
|
initArgs.generateEncoder = initArgs.properties?.[ENCODER].bind(initArgs.properties);
|
|
355
|
+
}
|
|
346
356
|
}
|
|
347
357
|
static async _prepareMappedTypeArgs(context, owner, initArgs, metadata) {
|
|
348
358
|
await this._prepareDataTypeArgs(context, initArgs, metadata);
|
|
@@ -353,8 +363,9 @@ export class DataTypeFactory {
|
|
|
353
363
|
}
|
|
354
364
|
else if (initArgs.ctor) {
|
|
355
365
|
const baseClass = Object.getPrototypeOf(initArgs.ctor.prototype).constructor;
|
|
356
|
-
if (Reflect.hasMetadata(DATATYPE_METADATA, baseClass))
|
|
366
|
+
if (Reflect.hasMetadata(DATATYPE_METADATA, baseClass)) {
|
|
357
367
|
baseArgs = await this._importDataTypeArgs(context, owner, baseClass);
|
|
368
|
+
}
|
|
358
369
|
}
|
|
359
370
|
if (!baseArgs)
|
|
360
371
|
return;
|
|
@@ -365,10 +376,12 @@ export class DataTypeFactory {
|
|
|
365
376
|
initArgs.pick = [...metadata.pick];
|
|
366
377
|
else if (metadata.omit)
|
|
367
378
|
initArgs.omit = [...metadata.omit];
|
|
368
|
-
else if (metadata.partial)
|
|
379
|
+
else if (metadata.partial) {
|
|
369
380
|
initArgs.partial = Array.isArray(metadata.partial) ? [...metadata.partial] : metadata.partial;
|
|
370
|
-
|
|
381
|
+
}
|
|
382
|
+
else if (metadata.required) {
|
|
371
383
|
initArgs.required = Array.isArray(metadata.required) ? [...metadata.required] : metadata.required;
|
|
384
|
+
}
|
|
372
385
|
}
|
|
373
386
|
static async _prepareMixinTypeArgs(context, owner, initArgs, metadata) {
|
|
374
387
|
await this._prepareDataTypeArgs(context, initArgs, metadata);
|
|
@@ -410,6 +423,8 @@ export class DataTypeFactory {
|
|
|
410
423
|
return this._createMixinType(context, owner, initArgs);
|
|
411
424
|
case OpraSchema.SimpleType.Kind:
|
|
412
425
|
return this._createSimpleType(context, owner, initArgs);
|
|
426
|
+
default:
|
|
427
|
+
break;
|
|
413
428
|
}
|
|
414
429
|
}
|
|
415
430
|
context.addError(`Unknown data type (${String(args)})`);
|
|
@@ -426,8 +441,9 @@ export class DataTypeFactory {
|
|
|
426
441
|
/** Set additionalFields */
|
|
427
442
|
if (args.additionalFields) {
|
|
428
443
|
context.enter('.additionalFields', () => {
|
|
429
|
-
if (typeof args.additionalFields === 'boolean' || Array.isArray(args.additionalFields))
|
|
444
|
+
if (typeof args.additionalFields === 'boolean' || Array.isArray(args.additionalFields)) {
|
|
430
445
|
initArgs.additionalFields = args.additionalFields;
|
|
446
|
+
}
|
|
431
447
|
else {
|
|
432
448
|
initArgs.additionalFields = this._createDataType(context, owner, args.additionalFields);
|
|
433
449
|
}
|
|
@@ -440,12 +456,13 @@ export class DataTypeFactory {
|
|
|
440
456
|
for (const [k, v] of Object.entries(args.fields)) {
|
|
441
457
|
context.enter(`[${k}]`, () => {
|
|
442
458
|
const type = this._createDataType(context, owner, v.type);
|
|
443
|
-
if (type)
|
|
459
|
+
if (type) {
|
|
444
460
|
initArgs.fields[k] = {
|
|
445
461
|
...v,
|
|
446
462
|
name: k,
|
|
447
463
|
type,
|
|
448
464
|
};
|
|
465
|
+
}
|
|
449
466
|
});
|
|
450
467
|
}
|
|
451
468
|
});
|
|
@@ -489,8 +506,9 @@ export class DataTypeFactory {
|
|
|
489
506
|
for (const t of args.types) {
|
|
490
507
|
context.enter(`[${i++}]`, () => {
|
|
491
508
|
const base = this._createDataType(context, owner, t);
|
|
492
|
-
if (!(base instanceof ComplexTypeBase))
|
|
509
|
+
if (!(base instanceof ComplexTypeBase)) {
|
|
493
510
|
throw new TypeError(`"${base?.kind}" can't be set as base for a "${initArgs.kind}"`);
|
|
511
|
+
}
|
|
494
512
|
initArgs.types.push(base);
|
|
495
513
|
});
|
|
496
514
|
}
|
|
@@ -21,6 +21,7 @@ export class HttpApiFactory {
|
|
|
21
21
|
*/
|
|
22
22
|
static async createApi(context, document, init) {
|
|
23
23
|
const api = new HttpApi(document);
|
|
24
|
+
api.name = init.name;
|
|
24
25
|
api.description = init.description;
|
|
25
26
|
api.url = init.url;
|
|
26
27
|
if (init.controllers) {
|
|
@@ -44,8 +45,9 @@ export class HttpApiFactory {
|
|
|
44
45
|
return api;
|
|
45
46
|
}
|
|
46
47
|
static async _createController(context, parent, thunk, name) {
|
|
47
|
-
if (typeof thunk === 'function' && !isConstructor(thunk))
|
|
48
|
+
if (typeof thunk === 'function' && !isConstructor(thunk)) {
|
|
48
49
|
thunk = parent instanceof HttpController ? thunk(parent.instance) : thunk();
|
|
50
|
+
}
|
|
49
51
|
thunk = await resolveThunk(thunk);
|
|
50
52
|
let ctor;
|
|
51
53
|
let metadata;
|
|
@@ -58,7 +58,7 @@ class HttpControllerClass extends DocumentElement {
|
|
|
58
58
|
if (c.controllers.size) {
|
|
59
59
|
controller = c.findController(arg0);
|
|
60
60
|
if (controller) {
|
|
61
|
-
this._controllerReverseMap.set(arg0,
|
|
61
|
+
this._controllerReverseMap.set(arg0, controller);
|
|
62
62
|
return controller;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -92,8 +92,12 @@ class HttpControllerClass extends DocumentElement {
|
|
|
92
92
|
if (prm.name instanceof RegExp && prm.name.test(paramName))
|
|
93
93
|
return prm;
|
|
94
94
|
}
|
|
95
|
-
if (this.node.parent && this.node.parent.element instanceof HttpController)
|
|
95
|
+
if (this.node.parent && this.node.parent.element instanceof HttpController) {
|
|
96
96
|
return this.node.parent.element.findParameter(paramName, location);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
getFullUrl() {
|
|
100
|
+
return (this.owner instanceof HttpController ? this.owner.getFullUrl() : '/') + this.path;
|
|
97
101
|
}
|
|
98
102
|
/**
|
|
99
103
|
*
|
|
@@ -22,8 +22,9 @@ export const HttpMediaType = function (owner, initArgs) {
|
|
|
22
22
|
_this.maxFileSize = initArgs.maxFileSize;
|
|
23
23
|
_this.maxTotalFileSize = initArgs.maxTotalFileSize;
|
|
24
24
|
_this.minFileSize = initArgs.minFileSize;
|
|
25
|
-
if (initArgs?.type)
|
|
25
|
+
if (initArgs?.type) {
|
|
26
26
|
_this.type = initArgs?.type instanceof DataType ? initArgs.type : _this.owner.node.getDataType(initArgs.type);
|
|
27
|
+
}
|
|
27
28
|
_this.isArray = initArgs.isArray;
|
|
28
29
|
};
|
|
29
30
|
/**
|
|
@@ -35,8 +36,9 @@ class HttpMediaTypeClass extends DocumentElement {
|
|
|
35
36
|
return;
|
|
36
37
|
for (const f of this.multipartFields) {
|
|
37
38
|
if ((!fieldType || fieldType === f.fieldType) &&
|
|
38
|
-
((f.fieldName instanceof RegExp && f.fieldName.test(fieldName)) || f.fieldName === fieldName))
|
|
39
|
+
((f.fieldName instanceof RegExp && f.fieldName.test(fieldName)) || f.fieldName === fieldName)) {
|
|
39
40
|
return f;
|
|
41
|
+
}
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
toJSON() {
|
|
@@ -16,8 +16,9 @@ export class HttpOperationResponse extends HttpMediaType {
|
|
|
16
16
|
paramName = paramName.toLowerCase();
|
|
17
17
|
for (const prm of this.parameters) {
|
|
18
18
|
if ((!location || location === prm.location) &&
|
|
19
|
-
((prm.name instanceof RegExp && prm.name.test(paramName)) || prm.name === paramName))
|
|
19
|
+
((prm.name instanceof RegExp && prm.name.test(paramName)) || prm.name === paramName)) {
|
|
20
20
|
return prm;
|
|
21
|
+
}
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
toJSON() {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import nodePath from 'node:path';
|
|
1
2
|
import { asMutable } from 'ts-gems';
|
|
2
3
|
import { cloneObject, omitUndefined } from '../../helpers/index.js';
|
|
3
4
|
import { OpraSchema } from '../../schema/index.js';
|
|
@@ -50,6 +51,10 @@ class HttpOperationClass extends DocumentElement {
|
|
|
50
51
|
return prm;
|
|
51
52
|
}
|
|
52
53
|
}
|
|
54
|
+
getFullUrl() {
|
|
55
|
+
const out = this.owner.getFullUrl();
|
|
56
|
+
return out ? (this.path ? nodePath.posix.join(out, this.path) : out) : this.path || '/';
|
|
57
|
+
}
|
|
53
58
|
toJSON() {
|
|
54
59
|
const out = omitUndefined({
|
|
55
60
|
kind: OpraSchema.HttpOperation.Kind,
|
|
@@ -28,8 +28,7 @@ export class HttpStatusRange {
|
|
|
28
28
|
toString() {
|
|
29
29
|
if (this.start === this.end)
|
|
30
30
|
return String(this.start);
|
|
31
|
-
|
|
32
|
-
return String(this.start) + '-' + String(this.end);
|
|
31
|
+
return String(this.start) + '-' + String(this.end);
|
|
33
32
|
}
|
|
34
33
|
toJSON() {
|
|
35
34
|
return !this.end || this.start === this.end ? this.start : { start: this.start, end: this.end };
|
package/esm/document/index.js
CHANGED
|
@@ -2,36 +2,36 @@ import 'reflect-metadata';
|
|
|
2
2
|
import * as DataTypeFactory_ from './factory/data-type.factory.js';
|
|
3
3
|
import * as HttpApiFactory_ from './factory/http-api.factory.js';
|
|
4
4
|
export * from './api-document.js';
|
|
5
|
-
export * from './constants.js';
|
|
6
5
|
export * from './common/api-base.js';
|
|
7
6
|
export * from './common/data-type-map.js';
|
|
8
7
|
export * from './common/document-element.js';
|
|
9
8
|
export * from './common/document-init-context.js';
|
|
10
9
|
export * from './common/document-node.js';
|
|
11
10
|
export * from './common/opra-document-error.js';
|
|
11
|
+
export * from './constants.js';
|
|
12
|
+
export * from './data-type/api-field.js';
|
|
12
13
|
export * from './data-type/complex-type.js';
|
|
13
14
|
export * from './data-type/data-type.js';
|
|
14
15
|
export * from './data-type/enum-type.js';
|
|
15
|
-
export * from './data-type/
|
|
16
|
+
export * from './data-type/extended-types/index.js';
|
|
16
17
|
export * from './data-type/mapped-type.js';
|
|
17
18
|
export * from './data-type/mixin-type.js';
|
|
18
19
|
export * from './data-type/omit-type.js';
|
|
19
20
|
export * from './data-type/partial-type.js';
|
|
20
21
|
export * from './data-type/pick-type.js';
|
|
22
|
+
export * from './data-type/primitive-types/index.js';
|
|
21
23
|
export * from './data-type/required-type.js';
|
|
22
24
|
export * from './data-type/simple-type.js';
|
|
23
|
-
export * from './data-type/primitive-types/index.js';
|
|
24
|
-
export * from './data-type/extended-types/index.js';
|
|
25
25
|
export * from './decorators/http-operation-entity.decorator.js';
|
|
26
26
|
export * from './factory/api-document.factory.js';
|
|
27
27
|
export * from './http/http-api.js';
|
|
28
|
+
export * from './http/http-controller.js';
|
|
28
29
|
export * from './http/http-media-type.js';
|
|
29
30
|
export * from './http/http-multipart-field.js';
|
|
30
31
|
export * from './http/http-operation.js';
|
|
31
32
|
export * from './http/http-operation-response.js';
|
|
32
33
|
export * from './http/http-parameter.js';
|
|
33
34
|
export * from './http/http-request-body.js';
|
|
34
|
-
export * from './http/http-controller.js';
|
|
35
35
|
export * from './http/http-status-range.js';
|
|
36
36
|
export var classes;
|
|
37
37
|
(function (classes) {
|
package/esm/exception/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export * from './opra-exception.js';
|
|
2
|
-
export * from './opra-http-error.js';
|
|
3
1
|
export * from './error-issue.js';
|
|
4
|
-
export * from './issue-severity.enum.js';
|
|
5
2
|
export * from './http-errors/bad-request.error.js';
|
|
6
3
|
export * from './http-errors/conflict.error.js';
|
|
7
4
|
export * from './http-errors/failed-dependency.error.js';
|
|
@@ -10,8 +7,11 @@ export * from './http-errors/internal-server.error.js';
|
|
|
10
7
|
export * from './http-errors/method-not-allowed.error.js';
|
|
11
8
|
export * from './http-errors/not-acceptable.error.js';
|
|
12
9
|
export * from './http-errors/not-found.error.js';
|
|
13
|
-
export * from './http-errors/unauthorized.error.js';
|
|
14
|
-
export * from './http-errors/unprocessable-entity.error.js';
|
|
15
10
|
export * from './http-errors/permission.error.js';
|
|
16
11
|
export * from './http-errors/resource-conflict.error.js';
|
|
17
12
|
export * from './http-errors/resource-not.available.error.js';
|
|
13
|
+
export * from './http-errors/unauthorized.error.js';
|
|
14
|
+
export * from './http-errors/unprocessable-entity.error.js';
|
|
15
|
+
export * from './issue-severity.enum.js';
|
|
16
|
+
export * from './opra-exception.js';
|
|
17
|
+
export * from './opra-http-error.js';
|