@opra/common 1.0.0-alpha.3 → 1.0.0-alpha.5
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 +253 -78
- package/cjs/document/data-type/api-field.js +4 -0
- package/cjs/document/data-type/complex-type-base.js +4 -0
- package/cjs/document/data-type/complex-type.js +2 -0
- package/cjs/document/data-type/enum-type.js +2 -0
- package/cjs/document/data-type/extended-types/base64.type.js +4 -0
- package/cjs/document/data-type/extended-types/date-string.type.js +4 -0
- package/cjs/document/data-type/extended-types/date-time-string.type.js +4 -0
- package/cjs/document/data-type/extended-types/date-time.type.js +4 -0
- package/cjs/document/data-type/extended-types/date.type.js +4 -0
- package/cjs/document/data-type/extended-types/email.type.js +4 -0
- package/cjs/document/data-type/extended-types/field-path.type.js +4 -0
- package/cjs/document/data-type/extended-types/filter.type.js +4 -0
- package/cjs/document/data-type/extended-types/object-id.type.js +4 -0
- package/cjs/document/data-type/extended-types/time.type.js +4 -0
- package/cjs/document/data-type/extended-types/url.type.js +4 -0
- package/cjs/document/data-type/extended-types/uuid.type.js +4 -0
- package/cjs/document/data-type/mapped-type.js +3 -0
- package/cjs/document/data-type/mixin-type.js +3 -0
- package/cjs/document/data-type/primitive-types/bigint.type.js +4 -0
- package/cjs/document/data-type/primitive-types/boolean.type.js +4 -0
- package/cjs/document/data-type/primitive-types/integer.type.js +4 -0
- package/cjs/document/data-type/primitive-types/null.type.js +4 -0
- package/cjs/document/data-type/primitive-types/number.type.js +4 -0
- package/cjs/document/data-type/primitive-types/string.type.js +4 -0
- package/cjs/document/data-type/simple-type.js +8 -1
- package/cjs/document/decorators/http-controller.decorator.js +25 -0
- package/cjs/document/decorators/http-operation-entity.decorator.js +55 -19
- package/cjs/document/factory/data-type.factory.js +61 -38
- package/cjs/document/http/http-api.js +2 -2
- package/cjs/document/http/http-controller.js +6 -6
- package/cjs/document/http/http-parameter.js +2 -0
- package/esm/document/data-type/api-field.js +4 -0
- package/esm/document/data-type/complex-type-base.js +4 -0
- package/esm/document/data-type/complex-type.js +2 -0
- package/esm/document/data-type/enum-type.js +2 -0
- package/esm/document/data-type/extended-types/base64.type.js +4 -0
- package/esm/document/data-type/extended-types/date-string.type.js +4 -0
- package/esm/document/data-type/extended-types/date-time-string.type.js +4 -0
- package/esm/document/data-type/extended-types/date-time.type.js +4 -0
- package/esm/document/data-type/extended-types/date.type.js +4 -0
- package/esm/document/data-type/extended-types/email.type.js +4 -0
- package/esm/document/data-type/extended-types/field-path.type.js +4 -0
- package/esm/document/data-type/extended-types/filter.type.js +4 -0
- package/esm/document/data-type/extended-types/object-id.type.js +4 -0
- package/esm/document/data-type/extended-types/time.type.js +4 -0
- package/esm/document/data-type/extended-types/url.type.js +4 -0
- package/esm/document/data-type/extended-types/uuid.type.js +4 -0
- package/esm/document/data-type/mapped-type.js +3 -0
- package/esm/document/data-type/mixin-type.js +3 -0
- package/esm/document/data-type/primitive-types/bigint.type.js +4 -0
- package/esm/document/data-type/primitive-types/boolean.type.js +4 -0
- package/esm/document/data-type/primitive-types/integer.type.js +4 -0
- package/esm/document/data-type/primitive-types/null.type.js +4 -0
- package/esm/document/data-type/primitive-types/number.type.js +4 -0
- package/esm/document/data-type/primitive-types/string.type.js +4 -0
- package/esm/document/data-type/simple-type.js +8 -1
- package/esm/document/decorators/http-controller.decorator.js +25 -0
- package/esm/document/decorators/http-operation-entity.decorator.js +55 -19
- package/esm/document/factory/data-type.factory.js +61 -38
- package/esm/document/http/http-api.js +2 -2
- package/esm/document/http/http-controller.js +6 -6
- package/esm/document/http/http-parameter.js +2 -0
- package/package.json +3 -3
- package/types/document/data-type/api-field.d.ts +2 -0
- package/types/document/data-type/complex-type.d.ts +1 -1
- package/types/document/data-type/data-type.d.ts +4 -2
- package/types/document/data-type/enum-type.d.ts +2 -2
- package/types/document/data-type/mapped-type.d.ts +2 -2
- package/types/document/data-type/mixin-type.d.ts +2 -2
- package/types/document/data-type/simple-type.d.ts +4 -2
- package/types/document/decorators/http-controller.decorator.d.ts +1 -0
- package/types/document/factory/data-type.factory.d.ts +5 -0
- package/types/document/http/http-parameter.d.ts +2 -0
- package/types/schema/data-type/simple-type.interface.d.ts +4 -0
- package/types/schema/http/http-parameter.interface.d.ts +4 -0
|
@@ -7,6 +7,7 @@ const document_init_context_js_1 = require("../common/document-init-context.js")
|
|
|
7
7
|
const constants_js_1 = require("../constants.js");
|
|
8
8
|
const complex_type_js_1 = require("../data-type/complex-type.js");
|
|
9
9
|
const complex_type_base_js_1 = require("../data-type/complex-type-base.js");
|
|
10
|
+
const data_type_js_1 = require("../data-type/data-type.js");
|
|
10
11
|
const enum_type_js_1 = require("../data-type/enum-type.js");
|
|
11
12
|
const mapped_type_js_1 = require("../data-type/mapped-type.js");
|
|
12
13
|
const mixin_type_js_1 = require("../data-type/mixin-type.js");
|
|
@@ -133,7 +134,7 @@ class DataTypeFactory {
|
|
|
133
134
|
const { importQueue, initArgsMap } = context;
|
|
134
135
|
// Check if data type already exist (maybe a builtin type or already imported)
|
|
135
136
|
const dataType = owner.node.findDataType(thunk);
|
|
136
|
-
if (dataType)
|
|
137
|
+
if (dataType instanceof data_type_js_1.DataType)
|
|
137
138
|
return dataType.name;
|
|
138
139
|
let metadata;
|
|
139
140
|
let ctor;
|
|
@@ -212,11 +213,15 @@ class DataTypeFactory {
|
|
|
212
213
|
/** Mark "out" object as initializing. This will help us to detect circular dependencies */
|
|
213
214
|
out[initializingSymbol] = true;
|
|
214
215
|
try {
|
|
215
|
-
if (out.name
|
|
216
|
-
|
|
216
|
+
if (out.name) {
|
|
217
|
+
if (importQueue?.has(out.name)) {
|
|
218
|
+
initArgsMap?.set(metadata.name, out);
|
|
219
|
+
out._instance = { name: metadata.name };
|
|
220
|
+
out[constants_js_1.kDataTypeMap] = owner.node[constants_js_1.kDataTypeMap];
|
|
221
|
+
}
|
|
222
|
+
else
|
|
223
|
+
return context.addError(`Data Type (${out.name}) must be explicitly added to type list in the document scope`);
|
|
217
224
|
}
|
|
218
|
-
else if (out.name)
|
|
219
|
-
return context.addError(`Data Type (${out.name}) must be explicitly added to type list in the document scope`);
|
|
220
225
|
switch (out.kind) {
|
|
221
226
|
case index_js_2.OpraSchema.ComplexType.Kind:
|
|
222
227
|
out.ctor = ctor;
|
|
@@ -332,6 +337,7 @@ class DataTypeFactory {
|
|
|
332
337
|
initArgs.ctor = initArgs.ctor || baseArgs.ctor;
|
|
333
338
|
});
|
|
334
339
|
initArgs.properties = metadata.properties;
|
|
340
|
+
initArgs.nameMappings = metadata.nameMappings;
|
|
335
341
|
if (!initArgs.properties && initArgs.ctor)
|
|
336
342
|
initArgs.properties = new initArgs.ctor();
|
|
337
343
|
if (metadata.attributes)
|
|
@@ -384,27 +390,40 @@ class DataTypeFactory {
|
|
|
384
390
|
});
|
|
385
391
|
}
|
|
386
392
|
static _createDataType(context, owner, args) {
|
|
393
|
+
let dataType = owner.node.findDataType(typeof args === 'string' ? args : args.name || '');
|
|
394
|
+
if (dataType instanceof data_type_js_1.DataType)
|
|
395
|
+
return dataType;
|
|
387
396
|
const initArgs = typeof args === 'string' ? context.initArgsMap?.get(args) : args;
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
397
|
+
if (initArgs) {
|
|
398
|
+
const dataTypeMap = initArgs[constants_js_1.kDataTypeMap];
|
|
399
|
+
if (!dataTypeMap)
|
|
400
|
+
delete initArgs._instance;
|
|
401
|
+
dataType = initArgs._instance;
|
|
402
|
+
if (dataType?.name && dataTypeMap) {
|
|
403
|
+
dataTypeMap.set(dataType.name, dataType);
|
|
404
|
+
}
|
|
405
|
+
switch (initArgs?.kind) {
|
|
406
|
+
case index_js_2.OpraSchema.ComplexType.Kind:
|
|
407
|
+
return this._createComplexType(context, owner, initArgs);
|
|
408
|
+
case index_js_2.OpraSchema.EnumType.Kind:
|
|
409
|
+
return this._createEnumType(context, owner, initArgs);
|
|
410
|
+
case index_js_2.OpraSchema.MappedType.Kind:
|
|
411
|
+
return this._createMappedType(context, owner, initArgs);
|
|
412
|
+
case index_js_2.OpraSchema.MixinType.Kind:
|
|
413
|
+
return this._createMixinType(context, owner, initArgs);
|
|
414
|
+
case index_js_2.OpraSchema.SimpleType.Kind:
|
|
415
|
+
return this._createSimpleType(context, owner, initArgs);
|
|
416
|
+
}
|
|
399
417
|
}
|
|
400
418
|
context.addError(`Unknown data type (${String(args)})`);
|
|
401
419
|
}
|
|
402
420
|
static _createComplexType(context, owner, args) {
|
|
421
|
+
const dataType = args._instance || {};
|
|
422
|
+
Object.setPrototypeOf(dataType, complex_type_js_1.ComplexType.prototype);
|
|
403
423
|
const initArgs = (0, index_js_1.cloneObject)(args);
|
|
404
424
|
if (args.base) {
|
|
405
425
|
context.enter('.base', () => {
|
|
406
|
-
initArgs.base = (owner
|
|
407
|
-
this._createDataType(context, owner, args.base));
|
|
426
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
408
427
|
});
|
|
409
428
|
}
|
|
410
429
|
/** Set additionalFields */
|
|
@@ -413,14 +432,7 @@ class DataTypeFactory {
|
|
|
413
432
|
if (typeof args.additionalFields === 'boolean' || Array.isArray(args.additionalFields))
|
|
414
433
|
initArgs.additionalFields = args.additionalFields;
|
|
415
434
|
else {
|
|
416
|
-
|
|
417
|
-
initArgs.additionalFields =
|
|
418
|
-
owner.node.findDataType(args.additionalFields) ||
|
|
419
|
-
this._createDataType(context, owner, args.additionalFields);
|
|
420
|
-
}
|
|
421
|
-
else {
|
|
422
|
-
initArgs.additionalFields = this._createDataType(context, owner, args.additionalFields);
|
|
423
|
-
}
|
|
435
|
+
initArgs.additionalFields = this._createDataType(context, owner, args.additionalFields);
|
|
424
436
|
}
|
|
425
437
|
});
|
|
426
438
|
}
|
|
@@ -430,7 +442,7 @@ class DataTypeFactory {
|
|
|
430
442
|
context.enter('.fields', () => {
|
|
431
443
|
for (const [k, v] of Object.entries(args.fields)) {
|
|
432
444
|
context.enter(`[${k}]`, () => {
|
|
433
|
-
const type =
|
|
445
|
+
const type = this._createDataType(context, owner, v.type);
|
|
434
446
|
if (type)
|
|
435
447
|
initArgs.fields[k] = {
|
|
436
448
|
...v,
|
|
@@ -441,29 +453,37 @@ class DataTypeFactory {
|
|
|
441
453
|
}
|
|
442
454
|
});
|
|
443
455
|
}
|
|
444
|
-
|
|
456
|
+
complex_type_js_1.ComplexType.apply(dataType, [owner, initArgs]);
|
|
457
|
+
return dataType;
|
|
445
458
|
}
|
|
446
459
|
static _createEnumType(context, owner, args) {
|
|
460
|
+
const dataType = args._instance || {};
|
|
461
|
+
Object.setPrototypeOf(dataType, enum_type_js_1.EnumType.prototype);
|
|
447
462
|
const initArgs = (0, index_js_1.cloneObject)(args);
|
|
448
463
|
if (args.base) {
|
|
449
464
|
context.enter('.base', () => {
|
|
450
|
-
initArgs.base = (owner
|
|
451
|
-
this._createDataType(context, owner, args.base));
|
|
465
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
452
466
|
});
|
|
453
467
|
}
|
|
454
468
|
initArgs.attributes = args.attributes;
|
|
455
|
-
|
|
469
|
+
enum_type_js_1.EnumType.apply(dataType, [owner, initArgs]);
|
|
470
|
+
return dataType;
|
|
456
471
|
}
|
|
457
472
|
static _createMappedType(context, owner, args) {
|
|
473
|
+
const dataType = args._instance || {};
|
|
474
|
+
Object.setPrototypeOf(dataType, mapped_type_js_1.MappedType.prototype);
|
|
458
475
|
const initArgs = (0, index_js_1.cloneObject)(args);
|
|
459
476
|
if (args.base) {
|
|
460
477
|
context.enter('.base', () => {
|
|
461
|
-
initArgs.base =
|
|
478
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
462
479
|
});
|
|
463
480
|
}
|
|
464
|
-
|
|
481
|
+
mapped_type_js_1.MappedType.apply(dataType, [owner, initArgs]);
|
|
482
|
+
return dataType;
|
|
465
483
|
}
|
|
466
484
|
static _createMixinType(context, owner, args) {
|
|
485
|
+
const dataType = args._instance || {};
|
|
486
|
+
Object.setPrototypeOf(dataType, mixin_type_js_1.MixinType.prototype);
|
|
467
487
|
const initArgs = (0, index_js_1.cloneObject)(args);
|
|
468
488
|
if (args.types) {
|
|
469
489
|
context.enter('.types', () => {
|
|
@@ -471,7 +491,7 @@ class DataTypeFactory {
|
|
|
471
491
|
let i = 0;
|
|
472
492
|
for (const t of args.types) {
|
|
473
493
|
context.enter(`[${i++}]`, () => {
|
|
474
|
-
const base =
|
|
494
|
+
const base = this._createDataType(context, owner, t);
|
|
475
495
|
if (!(base instanceof complex_type_base_js_1.ComplexTypeBase))
|
|
476
496
|
throw new TypeError(`"${base?.kind}" can't be set as base for a "${initArgs.kind}"`);
|
|
477
497
|
initArgs.types.push(base);
|
|
@@ -479,17 +499,20 @@ class DataTypeFactory {
|
|
|
479
499
|
}
|
|
480
500
|
});
|
|
481
501
|
}
|
|
482
|
-
|
|
502
|
+
mixin_type_js_1.MixinType.apply(dataType, [owner, initArgs]);
|
|
503
|
+
return dataType;
|
|
483
504
|
}
|
|
484
505
|
static _createSimpleType(context, owner, args) {
|
|
506
|
+
const dataType = args._instance || {};
|
|
507
|
+
Object.setPrototypeOf(dataType, simple_type_js_1.SimpleType.prototype);
|
|
485
508
|
const initArgs = (0, index_js_1.cloneObject)(args);
|
|
486
509
|
if (args.base) {
|
|
487
510
|
context.enter('.base', () => {
|
|
488
|
-
initArgs.base = (owner
|
|
489
|
-
this._createDataType(context, owner, args.base));
|
|
511
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
490
512
|
});
|
|
491
513
|
}
|
|
492
|
-
|
|
514
|
+
simple_type_js_1.SimpleType.apply(dataType, [owner, initArgs]);
|
|
515
|
+
return dataType;
|
|
493
516
|
}
|
|
494
517
|
}
|
|
495
518
|
exports.DataTypeFactory = DataTypeFactory;
|
|
@@ -31,8 +31,8 @@ class HttpApi extends api_base_js_1.ApiBase {
|
|
|
31
31
|
url: this.url,
|
|
32
32
|
controllers: {},
|
|
33
33
|
};
|
|
34
|
-
for (const
|
|
35
|
-
out.controllers[name] = v.toJSON();
|
|
34
|
+
for (const v of this.controllers.values()) {
|
|
35
|
+
out.controllers[v.name] = v.toJSON();
|
|
36
36
|
}
|
|
37
37
|
return out;
|
|
38
38
|
}
|
|
@@ -109,20 +109,20 @@ class HttpControllerClass extends document_element_js_1.DocumentElement {
|
|
|
109
109
|
});
|
|
110
110
|
if (this.operations.size) {
|
|
111
111
|
out.operations = {};
|
|
112
|
-
for (const
|
|
113
|
-
out.operations[name] = v.toJSON();
|
|
112
|
+
for (const v of this.operations.values()) {
|
|
113
|
+
out.operations[v.name] = v.toJSON();
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
if (this.controllers.size) {
|
|
117
117
|
out.controllers = {};
|
|
118
|
-
for (const
|
|
119
|
-
out.controllers[name] = v.toJSON();
|
|
118
|
+
for (const v of this.controllers.values()) {
|
|
119
|
+
out.controllers[v.name] = v.toJSON();
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
if (this.types.size) {
|
|
123
123
|
out.types = {};
|
|
124
|
-
for (const
|
|
125
|
-
out.types[name] = v.toJSON();
|
|
124
|
+
for (const v of this.types.values()) {
|
|
125
|
+
out.types[v.name] = v.toJSON();
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
if (this.parameters.length) {
|
|
@@ -25,6 +25,7 @@ exports.HttpParameter = function (owner, initArgs) {
|
|
|
25
25
|
_this.deprecated = initArgs.deprecated;
|
|
26
26
|
_this.required = initArgs.required;
|
|
27
27
|
_this.arraySeparator = initArgs.arraySeparator;
|
|
28
|
+
_this.keyParam = initArgs.keyParam;
|
|
28
29
|
};
|
|
29
30
|
/**
|
|
30
31
|
* @class HttpParameter
|
|
@@ -36,6 +37,7 @@ class HttpParameterClass extends value_js_1.Value {
|
|
|
36
37
|
name: this.name,
|
|
37
38
|
location: this.location,
|
|
38
39
|
arraySeparator: this.arraySeparator,
|
|
40
|
+
keyParam: this.keyParam,
|
|
39
41
|
required: this.required,
|
|
40
42
|
deprecated: this.deprecated,
|
|
41
43
|
});
|
|
@@ -33,6 +33,8 @@ export const ApiField = function (...args) {
|
|
|
33
33
|
_this.exclusive = initArgs.exclusive;
|
|
34
34
|
_this.translatable = initArgs.translatable;
|
|
35
35
|
_this.deprecated = initArgs.deprecated;
|
|
36
|
+
_this.readonly = initArgs.readonly;
|
|
37
|
+
_this.writeonly = initArgs.writeonly;
|
|
36
38
|
_this.examples = initArgs.examples;
|
|
37
39
|
};
|
|
38
40
|
/**
|
|
@@ -52,6 +54,8 @@ class ApiFieldClass extends DocumentElement {
|
|
|
52
54
|
exclusive: this.exclusive,
|
|
53
55
|
translatable: this.translatable,
|
|
54
56
|
deprecated: this.deprecated,
|
|
57
|
+
readonly: this.readonly,
|
|
58
|
+
writeonly: this.writeonly,
|
|
55
59
|
examples: this.examples,
|
|
56
60
|
});
|
|
57
61
|
}
|
|
@@ -143,6 +143,10 @@ class ComplexTypeBaseClass extends DataType {
|
|
|
143
143
|
// Process fields
|
|
144
144
|
let fieldName;
|
|
145
145
|
for (const field of this.fields.values()) {
|
|
146
|
+
if ((context.ignoreReadonlyFields && field.readonly) || (context.ignoreWriteonlyFields && field.writeonly)) {
|
|
147
|
+
schema[field.name] = vg.isUndefined({ coerce: true });
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
146
150
|
fieldName = field.name;
|
|
147
151
|
let p;
|
|
148
152
|
if (projection !== '*') {
|
|
@@ -57,6 +57,8 @@ export const ComplexType = function (...args) {
|
|
|
57
57
|
*/
|
|
58
58
|
class ComplexTypeClass extends ComplexTypeBase {
|
|
59
59
|
extendsFrom(baseType) {
|
|
60
|
+
if (!(baseType instanceof DataType))
|
|
61
|
+
baseType = this.node.getDataType(baseType);
|
|
60
62
|
if (!(baseType instanceof ComplexTypeBase))
|
|
61
63
|
return false;
|
|
62
64
|
if (baseType === this)
|
|
@@ -35,6 +35,8 @@ export const EnumType = function (...args) {
|
|
|
35
35
|
*/
|
|
36
36
|
class EnumTypeClass extends DataType {
|
|
37
37
|
extendsFrom(baseType) {
|
|
38
|
+
if (!(baseType instanceof DataType))
|
|
39
|
+
baseType = this.node.getDataType(baseType);
|
|
38
40
|
if (!(baseType instanceof EnumType))
|
|
39
41
|
return false;
|
|
40
42
|
if (baseType === this)
|
|
@@ -17,6 +17,10 @@ let Base64Type = class Base64Type {
|
|
|
17
17
|
Base64Type = __decorate([
|
|
18
18
|
SimpleType({
|
|
19
19
|
description: 'A stream of bytes, base64 encoded',
|
|
20
|
+
nameMappings: {
|
|
21
|
+
js: 'string',
|
|
22
|
+
json: 'string',
|
|
23
|
+
},
|
|
20
24
|
}),
|
|
21
25
|
__metadata("design:paramtypes", [Object])
|
|
22
26
|
], Base64Type);
|
|
@@ -35,6 +35,10 @@ __decorate([
|
|
|
35
35
|
DateStringType = __decorate([
|
|
36
36
|
SimpleType({
|
|
37
37
|
description: 'Date string value',
|
|
38
|
+
nameMappings: {
|
|
39
|
+
js: 'string',
|
|
40
|
+
json: 'string',
|
|
41
|
+
},
|
|
38
42
|
})
|
|
39
43
|
.Example('2021-04-18', 'Full date value')
|
|
40
44
|
.Example('2021-04', 'Date value without day')
|
|
@@ -35,6 +35,10 @@ __decorate([
|
|
|
35
35
|
DateTimeStringType = __decorate([
|
|
36
36
|
SimpleType({
|
|
37
37
|
description: 'DateTime string value',
|
|
38
|
+
nameMappings: {
|
|
39
|
+
js: 'string',
|
|
40
|
+
json: 'string',
|
|
41
|
+
},
|
|
38
42
|
})
|
|
39
43
|
.Example('2021-04-18T22:30:15+01:00', 'Full date-time value with timezone')
|
|
40
44
|
.Example('2021-04-18T22:30:15', 'Full date-time value without timezone')
|
|
@@ -49,6 +49,10 @@ __decorate([
|
|
|
49
49
|
DateType = __decorate([
|
|
50
50
|
SimpleType({
|
|
51
51
|
description: 'A date without time',
|
|
52
|
+
nameMappings: {
|
|
53
|
+
js: 'Date',
|
|
54
|
+
json: 'string',
|
|
55
|
+
},
|
|
52
56
|
}).Example('2021-04-18', 'Full date value'),
|
|
53
57
|
__metadata("design:paramtypes", [Object])
|
|
54
58
|
], DateType);
|
|
@@ -17,6 +17,10 @@ let ObjectIdType = class ObjectIdType {
|
|
|
17
17
|
ObjectIdType = __decorate([
|
|
18
18
|
SimpleType({
|
|
19
19
|
description: 'A MongoDB ObjectID value',
|
|
20
|
+
nameMappings: {
|
|
21
|
+
js: 'object',
|
|
22
|
+
json: 'string',
|
|
23
|
+
},
|
|
20
24
|
}),
|
|
21
25
|
__metadata("design:paramtypes", [Object])
|
|
22
26
|
], ObjectIdType);
|
|
@@ -39,6 +39,10 @@ __decorate([
|
|
|
39
39
|
TimeType = __decorate([
|
|
40
40
|
SimpleType({
|
|
41
41
|
description: 'Time string in 24h format',
|
|
42
|
+
nameMappings: {
|
|
43
|
+
js: 'string',
|
|
44
|
+
json: 'string',
|
|
45
|
+
},
|
|
42
46
|
})
|
|
43
47
|
.Example('18:23:00', 'Full time value')
|
|
44
48
|
.Example('18:23:00', 'Time value without seconds'),
|
|
@@ -17,6 +17,10 @@ let UrlType = class UrlType {
|
|
|
17
17
|
UrlType = __decorate([
|
|
18
18
|
SimpleType({
|
|
19
19
|
description: 'A Uniform Resource Identifier Reference (RFC 3986 icon) value',
|
|
20
|
+
nameMappings: {
|
|
21
|
+
js: 'string',
|
|
22
|
+
json: 'string',
|
|
23
|
+
},
|
|
20
24
|
}).Example('http://tempuri.org'),
|
|
21
25
|
__metadata("design:paramtypes", [Object])
|
|
22
26
|
], UrlType);
|
|
@@ -4,6 +4,7 @@ import { omitUndefined } from '../../helpers/index.js';
|
|
|
4
4
|
import { OpraSchema } from '../../schema/index.js';
|
|
5
5
|
import { ApiField } from './api-field.js';
|
|
6
6
|
import { ComplexTypeBase } from './complex-type-base.js';
|
|
7
|
+
import { DataType } from './data-type.js';
|
|
7
8
|
import { getIsInheritedPredicateFn } from './utils/get-is-inherited-predicate-fn.js';
|
|
8
9
|
/**
|
|
9
10
|
* MappedType constructor
|
|
@@ -65,6 +66,8 @@ export const MappedType = function (...args) {
|
|
|
65
66
|
*/
|
|
66
67
|
class MappedTypeClass extends ComplexTypeBase {
|
|
67
68
|
extendsFrom(baseType) {
|
|
69
|
+
if (!(baseType instanceof DataType))
|
|
70
|
+
baseType = this.node.getDataType(baseType);
|
|
68
71
|
if (!(baseType instanceof ComplexTypeBase))
|
|
69
72
|
return false;
|
|
70
73
|
if (baseType === this)
|
|
@@ -5,6 +5,7 @@ import { OpraSchema } from '../../schema/index.js';
|
|
|
5
5
|
import { DATATYPE_METADATA, DECORATOR } from '../constants.js';
|
|
6
6
|
import { ApiField } from './api-field.js';
|
|
7
7
|
import { ComplexTypeBase } from './complex-type-base.js';
|
|
8
|
+
import { DataType } from './data-type.js';
|
|
8
9
|
/**
|
|
9
10
|
* @class MixinType
|
|
10
11
|
*/
|
|
@@ -40,6 +41,8 @@ export const MixinType = function (...args) {
|
|
|
40
41
|
*/
|
|
41
42
|
class MixinTypeClass extends ComplexTypeBase {
|
|
42
43
|
extendsFrom(baseType) {
|
|
44
|
+
if (!(baseType instanceof DataType))
|
|
45
|
+
baseType = this.node.getDataType(baseType);
|
|
43
46
|
if (!(baseType instanceof ComplexTypeBase))
|
|
44
47
|
return false;
|
|
45
48
|
if (baseType === this)
|
|
@@ -22,6 +22,10 @@ let BigintType = class BigintType extends NumberType {
|
|
|
22
22
|
BigintType = __decorate([
|
|
23
23
|
SimpleType({
|
|
24
24
|
description: 'BigInt number',
|
|
25
|
+
nameMappings: {
|
|
26
|
+
js: 'bigint',
|
|
27
|
+
json: 'string',
|
|
28
|
+
},
|
|
25
29
|
}),
|
|
26
30
|
__metadata("design:paramtypes", [Object])
|
|
27
31
|
], BigintType);
|
|
@@ -17,6 +17,10 @@ let BooleanType = class BooleanType {
|
|
|
17
17
|
BooleanType = __decorate([
|
|
18
18
|
SimpleType({
|
|
19
19
|
description: 'Simple true/false value',
|
|
20
|
+
nameMappings: {
|
|
21
|
+
js: 'boolean',
|
|
22
|
+
json: 'boolean',
|
|
23
|
+
},
|
|
20
24
|
}),
|
|
21
25
|
__metadata("design:paramtypes", [Object])
|
|
22
26
|
], BooleanType);
|
|
@@ -22,6 +22,10 @@ let IntegerType = class IntegerType extends NumberType {
|
|
|
22
22
|
IntegerType = __decorate([
|
|
23
23
|
SimpleType({
|
|
24
24
|
description: 'An integer number',
|
|
25
|
+
nameMappings: {
|
|
26
|
+
js: 'number',
|
|
27
|
+
json: 'number',
|
|
28
|
+
},
|
|
25
29
|
}),
|
|
26
30
|
__metadata("design:paramtypes", [Object])
|
|
27
31
|
], IntegerType);
|
|
@@ -34,6 +34,10 @@ __decorate([
|
|
|
34
34
|
NumberType = __decorate([
|
|
35
35
|
SimpleType({
|
|
36
36
|
description: 'Both Integer as well as Floating-Point numbers',
|
|
37
|
+
nameMappings: {
|
|
38
|
+
js: 'number',
|
|
39
|
+
json: 'number',
|
|
40
|
+
},
|
|
37
41
|
}),
|
|
38
42
|
__metadata("design:paramtypes", [Object])
|
|
39
43
|
], NumberType);
|
|
@@ -25,6 +25,8 @@ export const SimpleType = function (...args) {
|
|
|
25
25
|
_this.base = initArgs.base;
|
|
26
26
|
}
|
|
27
27
|
_this.properties = initArgs.properties;
|
|
28
|
+
_this.ownNameMappings = { ...initArgs.nameMappings };
|
|
29
|
+
_this.nameMappings = { ..._this.base?.nameMappings, ...initArgs.nameMappings };
|
|
28
30
|
_this.ownAttributes = cloneObject(initArgs.attributes || {});
|
|
29
31
|
_this.attributes = _this.base ? cloneObject(_this.base.attributes) : {};
|
|
30
32
|
if (_this.ownAttributes) {
|
|
@@ -43,6 +45,8 @@ export const SimpleType = function (...args) {
|
|
|
43
45
|
*/
|
|
44
46
|
class SimpleTypeClass extends DataType {
|
|
45
47
|
extendsFrom(baseType) {
|
|
48
|
+
if (!(baseType instanceof DataType))
|
|
49
|
+
baseType = this.node.getDataType(baseType);
|
|
46
50
|
if (!(baseType instanceof SimpleType))
|
|
47
51
|
return false;
|
|
48
52
|
if (baseType === this)
|
|
@@ -87,12 +91,15 @@ class SimpleTypeClass extends DataType {
|
|
|
87
91
|
return o;
|
|
88
92
|
}, {});
|
|
89
93
|
const baseName = this.base ? this.node.getDataTypeNameWithNs(this.base) : undefined;
|
|
90
|
-
|
|
94
|
+
const out = omitUndefined({
|
|
91
95
|
...DataType.prototype.toJSON.apply(this),
|
|
92
96
|
base: this.base ? (baseName ? baseName : this.base.toJSON()) : undefined,
|
|
93
97
|
attributes: attributes && Object.keys(attributes).length ? attributes : undefined,
|
|
94
98
|
properties: Object.keys(properties).length ? properties : undefined,
|
|
95
99
|
});
|
|
100
|
+
if (Object.keys(this.ownNameMappings).length)
|
|
101
|
+
out.nameMappings = { ...this.ownNameMappings };
|
|
102
|
+
return out;
|
|
96
103
|
}
|
|
97
104
|
}
|
|
98
105
|
SimpleType.prototype = SimpleTypeClass.prototype;
|
|
@@ -98,6 +98,31 @@ export function HttpControllerDecoratorFactory(options) {
|
|
|
98
98
|
});
|
|
99
99
|
return decorator;
|
|
100
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
*/
|
|
104
|
+
decorator.KeyParam = (name, arg1) => {
|
|
105
|
+
decoratorChain.push((meta) => {
|
|
106
|
+
if (!meta.path?.includes(':' + name))
|
|
107
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
108
|
+
const paramMeta = typeof arg1 === 'string' || typeof arg1 === 'function'
|
|
109
|
+
? {
|
|
110
|
+
name,
|
|
111
|
+
location: 'path',
|
|
112
|
+
type: arg1,
|
|
113
|
+
keyParam: true,
|
|
114
|
+
}
|
|
115
|
+
: {
|
|
116
|
+
...arg1,
|
|
117
|
+
name,
|
|
118
|
+
location: 'path',
|
|
119
|
+
keyParam: true,
|
|
120
|
+
};
|
|
121
|
+
meta.parameters = meta.parameters || [];
|
|
122
|
+
meta.parameters.push(paramMeta);
|
|
123
|
+
});
|
|
124
|
+
return decorator;
|
|
125
|
+
};
|
|
101
126
|
/**
|
|
102
127
|
*
|
|
103
128
|
*/
|