@opra/common 1.0.0-alpha.3 → 1.0.0-alpha.4
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 +181 -58
- 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-operation-entity.decorator.js +7 -7
- package/cjs/document/factory/data-type.factory.js +61 -38
- 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-operation-entity.decorator.js +7 -7
- package/esm/document/factory/data-type.factory.js +61 -38
- 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/factory/data-type.factory.d.ts +5 -0
- package/types/schema/data-type/simple-type.interface.d.ts +4 -0
|
@@ -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;
|
|
@@ -21,8 +21,8 @@ HttpOperation.Entity.Create = function (arg0, arg1) {
|
|
|
21
21
|
/** Initialize the decorator and the chain */
|
|
22
22
|
const decoratorChain = [];
|
|
23
23
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
24
|
-
description: args.description,
|
|
25
24
|
method: 'POST',
|
|
25
|
+
...args,
|
|
26
26
|
composition: 'Entity.Create',
|
|
27
27
|
requestBody: {
|
|
28
28
|
immediateFetch: true,
|
|
@@ -72,8 +72,8 @@ HttpOperation.Entity.Delete = function (arg0, arg1) {
|
|
|
72
72
|
/** Initialize the decorator and the chain */
|
|
73
73
|
const decoratorChain = [];
|
|
74
74
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
75
|
-
description: args.description,
|
|
76
75
|
method: 'DELETE',
|
|
76
|
+
...args,
|
|
77
77
|
composition: 'Entity.Delete',
|
|
78
78
|
}));
|
|
79
79
|
decorator
|
|
@@ -121,8 +121,8 @@ HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
|
|
|
121
121
|
const filterType = new FilterType({ dataType: args.type });
|
|
122
122
|
filterType.rules = {};
|
|
123
123
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
124
|
-
description: args.description,
|
|
125
124
|
method: 'DELETE',
|
|
125
|
+
...args,
|
|
126
126
|
composition: 'Entity.DeleteMany',
|
|
127
127
|
}));
|
|
128
128
|
decorator
|
|
@@ -169,8 +169,8 @@ HttpOperation.Entity.FindMany = function (arg0, arg1) {
|
|
|
169
169
|
const filterType = new FilterType({ dataType: args.type });
|
|
170
170
|
filterType.rules = {};
|
|
171
171
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
172
|
-
description: args.description,
|
|
173
172
|
method: 'GET',
|
|
173
|
+
...args,
|
|
174
174
|
composition: 'Entity.FindMany',
|
|
175
175
|
}));
|
|
176
176
|
decorator
|
|
@@ -261,8 +261,8 @@ HttpOperation.Entity.Get = function (arg0, arg1) {
|
|
|
261
261
|
/** Initialize the decorator and the chain */
|
|
262
262
|
const decoratorChain = [];
|
|
263
263
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
264
|
-
description: args.description,
|
|
265
264
|
method: 'GET',
|
|
265
|
+
...args,
|
|
266
266
|
composition: 'Entity.Get',
|
|
267
267
|
}));
|
|
268
268
|
decorator
|
|
@@ -324,8 +324,8 @@ HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
|
|
|
324
324
|
filterType.rules = {};
|
|
325
325
|
const filterRules = new FilterRules();
|
|
326
326
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
327
|
-
description: args.description,
|
|
328
327
|
method: 'PATCH',
|
|
328
|
+
...args,
|
|
329
329
|
composition: 'Entity.UpdateMany',
|
|
330
330
|
requestBody: {
|
|
331
331
|
immediateFetch: true,
|
|
@@ -379,8 +379,8 @@ HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
|
379
379
|
const filterType = new FilterType({ dataType: args.type });
|
|
380
380
|
filterType.rules = {};
|
|
381
381
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
382
|
-
description: args.description,
|
|
383
382
|
method: 'PATCH',
|
|
383
|
+
...args,
|
|
384
384
|
composition: 'Entity.Update',
|
|
385
385
|
requestBody: {
|
|
386
386
|
partial: 'deep',
|
|
@@ -4,6 +4,7 @@ import { DocumentInitContext } from '../common/document-init-context.js';
|
|
|
4
4
|
import { DATATYPE_METADATA, DECODER, ENCODER, kCtorMap, kDataTypeMap } from '../constants.js';
|
|
5
5
|
import { ComplexType } from '../data-type/complex-type.js';
|
|
6
6
|
import { ComplexTypeBase } from '../data-type/complex-type-base.js';
|
|
7
|
+
import { DataType } from '../data-type/data-type.js';
|
|
7
8
|
import { EnumType } from '../data-type/enum-type.js';
|
|
8
9
|
import { MappedType } from '../data-type/mapped-type.js';
|
|
9
10
|
import { MixinType } from '../data-type/mixin-type.js';
|
|
@@ -130,7 +131,7 @@ export class DataTypeFactory {
|
|
|
130
131
|
const { importQueue, initArgsMap } = context;
|
|
131
132
|
// Check if data type already exist (maybe a builtin type or already imported)
|
|
132
133
|
const dataType = owner.node.findDataType(thunk);
|
|
133
|
-
if (dataType)
|
|
134
|
+
if (dataType instanceof DataType)
|
|
134
135
|
return dataType.name;
|
|
135
136
|
let metadata;
|
|
136
137
|
let ctor;
|
|
@@ -209,11 +210,15 @@ export class DataTypeFactory {
|
|
|
209
210
|
/** Mark "out" object as initializing. This will help us to detect circular dependencies */
|
|
210
211
|
out[initializingSymbol] = true;
|
|
211
212
|
try {
|
|
212
|
-
if (out.name
|
|
213
|
-
|
|
213
|
+
if (out.name) {
|
|
214
|
+
if (importQueue?.has(out.name)) {
|
|
215
|
+
initArgsMap?.set(metadata.name, out);
|
|
216
|
+
out._instance = { name: metadata.name };
|
|
217
|
+
out[kDataTypeMap] = owner.node[kDataTypeMap];
|
|
218
|
+
}
|
|
219
|
+
else
|
|
220
|
+
return context.addError(`Data Type (${out.name}) must be explicitly added to type list in the document scope`);
|
|
214
221
|
}
|
|
215
|
-
else if (out.name)
|
|
216
|
-
return context.addError(`Data Type (${out.name}) must be explicitly added to type list in the document scope`);
|
|
217
222
|
switch (out.kind) {
|
|
218
223
|
case OpraSchema.ComplexType.Kind:
|
|
219
224
|
out.ctor = ctor;
|
|
@@ -329,6 +334,7 @@ export class DataTypeFactory {
|
|
|
329
334
|
initArgs.ctor = initArgs.ctor || baseArgs.ctor;
|
|
330
335
|
});
|
|
331
336
|
initArgs.properties = metadata.properties;
|
|
337
|
+
initArgs.nameMappings = metadata.nameMappings;
|
|
332
338
|
if (!initArgs.properties && initArgs.ctor)
|
|
333
339
|
initArgs.properties = new initArgs.ctor();
|
|
334
340
|
if (metadata.attributes)
|
|
@@ -381,27 +387,40 @@ export class DataTypeFactory {
|
|
|
381
387
|
});
|
|
382
388
|
}
|
|
383
389
|
static _createDataType(context, owner, args) {
|
|
390
|
+
let dataType = owner.node.findDataType(typeof args === 'string' ? args : args.name || '');
|
|
391
|
+
if (dataType instanceof DataType)
|
|
392
|
+
return dataType;
|
|
384
393
|
const initArgs = typeof args === 'string' ? context.initArgsMap?.get(args) : args;
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
394
|
+
if (initArgs) {
|
|
395
|
+
const dataTypeMap = initArgs[kDataTypeMap];
|
|
396
|
+
if (!dataTypeMap)
|
|
397
|
+
delete initArgs._instance;
|
|
398
|
+
dataType = initArgs._instance;
|
|
399
|
+
if (dataType?.name && dataTypeMap) {
|
|
400
|
+
dataTypeMap.set(dataType.name, dataType);
|
|
401
|
+
}
|
|
402
|
+
switch (initArgs?.kind) {
|
|
403
|
+
case OpraSchema.ComplexType.Kind:
|
|
404
|
+
return this._createComplexType(context, owner, initArgs);
|
|
405
|
+
case OpraSchema.EnumType.Kind:
|
|
406
|
+
return this._createEnumType(context, owner, initArgs);
|
|
407
|
+
case OpraSchema.MappedType.Kind:
|
|
408
|
+
return this._createMappedType(context, owner, initArgs);
|
|
409
|
+
case OpraSchema.MixinType.Kind:
|
|
410
|
+
return this._createMixinType(context, owner, initArgs);
|
|
411
|
+
case OpraSchema.SimpleType.Kind:
|
|
412
|
+
return this._createSimpleType(context, owner, initArgs);
|
|
413
|
+
}
|
|
396
414
|
}
|
|
397
415
|
context.addError(`Unknown data type (${String(args)})`);
|
|
398
416
|
}
|
|
399
417
|
static _createComplexType(context, owner, args) {
|
|
418
|
+
const dataType = args._instance || {};
|
|
419
|
+
Object.setPrototypeOf(dataType, ComplexType.prototype);
|
|
400
420
|
const initArgs = cloneObject(args);
|
|
401
421
|
if (args.base) {
|
|
402
422
|
context.enter('.base', () => {
|
|
403
|
-
initArgs.base = (owner
|
|
404
|
-
this._createDataType(context, owner, args.base));
|
|
423
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
405
424
|
});
|
|
406
425
|
}
|
|
407
426
|
/** Set additionalFields */
|
|
@@ -410,14 +429,7 @@ export class DataTypeFactory {
|
|
|
410
429
|
if (typeof args.additionalFields === 'boolean' || Array.isArray(args.additionalFields))
|
|
411
430
|
initArgs.additionalFields = args.additionalFields;
|
|
412
431
|
else {
|
|
413
|
-
|
|
414
|
-
initArgs.additionalFields =
|
|
415
|
-
owner.node.findDataType(args.additionalFields) ||
|
|
416
|
-
this._createDataType(context, owner, args.additionalFields);
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
initArgs.additionalFields = this._createDataType(context, owner, args.additionalFields);
|
|
420
|
-
}
|
|
432
|
+
initArgs.additionalFields = this._createDataType(context, owner, args.additionalFields);
|
|
421
433
|
}
|
|
422
434
|
});
|
|
423
435
|
}
|
|
@@ -427,7 +439,7 @@ export class DataTypeFactory {
|
|
|
427
439
|
context.enter('.fields', () => {
|
|
428
440
|
for (const [k, v] of Object.entries(args.fields)) {
|
|
429
441
|
context.enter(`[${k}]`, () => {
|
|
430
|
-
const type =
|
|
442
|
+
const type = this._createDataType(context, owner, v.type);
|
|
431
443
|
if (type)
|
|
432
444
|
initArgs.fields[k] = {
|
|
433
445
|
...v,
|
|
@@ -438,29 +450,37 @@ export class DataTypeFactory {
|
|
|
438
450
|
}
|
|
439
451
|
});
|
|
440
452
|
}
|
|
441
|
-
|
|
453
|
+
ComplexType.apply(dataType, [owner, initArgs]);
|
|
454
|
+
return dataType;
|
|
442
455
|
}
|
|
443
456
|
static _createEnumType(context, owner, args) {
|
|
457
|
+
const dataType = args._instance || {};
|
|
458
|
+
Object.setPrototypeOf(dataType, EnumType.prototype);
|
|
444
459
|
const initArgs = cloneObject(args);
|
|
445
460
|
if (args.base) {
|
|
446
461
|
context.enter('.base', () => {
|
|
447
|
-
initArgs.base = (owner
|
|
448
|
-
this._createDataType(context, owner, args.base));
|
|
462
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
449
463
|
});
|
|
450
464
|
}
|
|
451
465
|
initArgs.attributes = args.attributes;
|
|
452
|
-
|
|
466
|
+
EnumType.apply(dataType, [owner, initArgs]);
|
|
467
|
+
return dataType;
|
|
453
468
|
}
|
|
454
469
|
static _createMappedType(context, owner, args) {
|
|
470
|
+
const dataType = args._instance || {};
|
|
471
|
+
Object.setPrototypeOf(dataType, MappedType.prototype);
|
|
455
472
|
const initArgs = cloneObject(args);
|
|
456
473
|
if (args.base) {
|
|
457
474
|
context.enter('.base', () => {
|
|
458
|
-
initArgs.base =
|
|
475
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
459
476
|
});
|
|
460
477
|
}
|
|
461
|
-
|
|
478
|
+
MappedType.apply(dataType, [owner, initArgs]);
|
|
479
|
+
return dataType;
|
|
462
480
|
}
|
|
463
481
|
static _createMixinType(context, owner, args) {
|
|
482
|
+
const dataType = args._instance || {};
|
|
483
|
+
Object.setPrototypeOf(dataType, MixinType.prototype);
|
|
464
484
|
const initArgs = cloneObject(args);
|
|
465
485
|
if (args.types) {
|
|
466
486
|
context.enter('.types', () => {
|
|
@@ -468,7 +488,7 @@ export class DataTypeFactory {
|
|
|
468
488
|
let i = 0;
|
|
469
489
|
for (const t of args.types) {
|
|
470
490
|
context.enter(`[${i++}]`, () => {
|
|
471
|
-
const base =
|
|
491
|
+
const base = this._createDataType(context, owner, t);
|
|
472
492
|
if (!(base instanceof ComplexTypeBase))
|
|
473
493
|
throw new TypeError(`"${base?.kind}" can't be set as base for a "${initArgs.kind}"`);
|
|
474
494
|
initArgs.types.push(base);
|
|
@@ -476,17 +496,20 @@ export class DataTypeFactory {
|
|
|
476
496
|
}
|
|
477
497
|
});
|
|
478
498
|
}
|
|
479
|
-
|
|
499
|
+
MixinType.apply(dataType, [owner, initArgs]);
|
|
500
|
+
return dataType;
|
|
480
501
|
}
|
|
481
502
|
static _createSimpleType(context, owner, args) {
|
|
503
|
+
const dataType = args._instance || {};
|
|
504
|
+
Object.setPrototypeOf(dataType, SimpleType.prototype);
|
|
482
505
|
const initArgs = cloneObject(args);
|
|
483
506
|
if (args.base) {
|
|
484
507
|
context.enter('.base', () => {
|
|
485
|
-
initArgs.base = (owner
|
|
486
|
-
this._createDataType(context, owner, args.base));
|
|
508
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
487
509
|
});
|
|
488
510
|
}
|
|
489
|
-
|
|
511
|
+
SimpleType.apply(dataType, [owner, initArgs]);
|
|
512
|
+
return dataType;
|
|
490
513
|
}
|
|
491
514
|
}
|
|
492
515
|
function preferName(initArgs) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/common",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.4",
|
|
4
4
|
"description": "Opra common package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"lint": "eslint . --max-warnings=0",
|
|
26
26
|
"check": "madge --circular src/**",
|
|
27
27
|
"format": "prettier . --write --log-level=warn",
|
|
28
|
-
"test": "jest",
|
|
29
|
-
"cover": "jest --collect-coverage",
|
|
28
|
+
"test": "jest --passWithNoTests",
|
|
29
|
+
"cover": "jest --passWithNoTests --collect-coverage",
|
|
30
30
|
"clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
|
|
31
31
|
"clean:src": "ts-cleanup -s src --all",
|
|
32
32
|
"clean:test": "ts-cleanup -s test --all",
|
|
@@ -59,6 +59,8 @@ declare class ApiFieldClass extends DocumentElement {
|
|
|
59
59
|
readonly exclusive?: boolean;
|
|
60
60
|
readonly translatable?: boolean;
|
|
61
61
|
readonly deprecated?: boolean | string;
|
|
62
|
+
readonly readonly?: boolean;
|
|
63
|
+
readonly writeonly?: boolean;
|
|
62
64
|
readonly examples?: any[] | Record<string, any>;
|
|
63
65
|
toJSON(): OpraSchema.Field;
|
|
64
66
|
}
|
|
@@ -71,7 +71,7 @@ declare abstract class ComplexTypeClass extends ComplexTypeBase {
|
|
|
71
71
|
readonly kind: OpraSchema.ComplexType.Kind;
|
|
72
72
|
readonly base?: ComplexType | MappedType | MixinType;
|
|
73
73
|
readonly ctor?: Type;
|
|
74
|
-
extendsFrom(baseType: DataType): boolean;
|
|
74
|
+
extendsFrom(baseType: DataType | string | Type | object): boolean;
|
|
75
75
|
toJSON(): OpraSchema.ComplexType;
|
|
76
76
|
}
|
|
77
77
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
1
|
+
import { StrictOmit, Type } from 'ts-gems';
|
|
2
2
|
import { ValidationOptions, Validator } from 'valgen';
|
|
3
3
|
import { FieldsProjection } from '../../helpers/index.js';
|
|
4
4
|
import type { DataTypeBase } from '../../schema/data-type/data-type.interface.js';
|
|
@@ -23,6 +23,8 @@ export declare namespace DataType {
|
|
|
23
23
|
caseInSensitive?: boolean;
|
|
24
24
|
partial?: boolean | 'deep';
|
|
25
25
|
projection?: string[] | FieldsProjection | '*';
|
|
26
|
+
ignoreReadonlyFields?: boolean;
|
|
27
|
+
ignoreWriteonlyFields?: boolean;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
interface DataTypeStatic {
|
|
@@ -52,7 +54,7 @@ declare abstract class DataTypeClass extends DocumentElement {
|
|
|
52
54
|
readonly examples?: OpraSchema.DataTypeExample[];
|
|
53
55
|
abstract generateCodec(codec: 'encode' | 'decode', options?: DataType.GenerateCodecOptions): Validator;
|
|
54
56
|
get embedded(): any;
|
|
55
|
-
abstract extendsFrom(baseType: DataType): boolean;
|
|
57
|
+
abstract extendsFrom(baseType: DataType | string | Type | object): boolean;
|
|
56
58
|
toJSON(): OpraSchema.DataType;
|
|
57
59
|
toString(): string;
|
|
58
60
|
[nodeInspectCustom](): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { Combine } from 'ts-gems';
|
|
2
|
+
import { Combine, Type } from 'ts-gems';
|
|
3
3
|
import { Validator } from 'valgen';
|
|
4
4
|
import { OpraSchema } from '../../schema/index.js';
|
|
5
5
|
import type { DocumentElement } from '../common/document-element.js';
|
|
@@ -63,7 +63,7 @@ declare class EnumTypeClass extends DataType {
|
|
|
63
63
|
readonly instance?: object;
|
|
64
64
|
readonly attributes: Record<string | number, OpraSchema.EnumType.ValueInfo>;
|
|
65
65
|
readonly ownAttributes: Record<string | number, OpraSchema.EnumType.ValueInfo>;
|
|
66
|
-
extendsFrom(baseType: DataType): boolean;
|
|
66
|
+
extendsFrom(baseType: DataType | string | Type | object): boolean;
|
|
67
67
|
generateCodec(): Validator;
|
|
68
68
|
toJSON(): OpraSchema.EnumType;
|
|
69
69
|
}
|
|
@@ -5,7 +5,7 @@ import { OpraSchema } from '../../schema/index.js';
|
|
|
5
5
|
import { DocumentElement } from '../common/document-element.js';
|
|
6
6
|
import type { ComplexType } from './complex-type.js';
|
|
7
7
|
import { ComplexTypeBase } from './complex-type-base.js';
|
|
8
|
-
import
|
|
8
|
+
import { DataType } from './data-type.js';
|
|
9
9
|
import type { MixinType } from './mixin-type';
|
|
10
10
|
/**
|
|
11
11
|
* @namespace MappedType
|
|
@@ -67,7 +67,7 @@ declare class MappedTypeClass extends ComplexTypeBase {
|
|
|
67
67
|
readonly pick?: Field.Name[];
|
|
68
68
|
readonly partial?: Field.Name[] | boolean;
|
|
69
69
|
readonly required?: Field.Name[] | boolean;
|
|
70
|
-
extendsFrom(baseType: DataType): boolean;
|
|
70
|
+
extendsFrom(baseType: DataType | string | Type | object): boolean;
|
|
71
71
|
toJSON(): OpraSchema.MappedType;
|
|
72
72
|
}
|
|
73
73
|
export {};
|
|
@@ -4,7 +4,7 @@ import { OpraSchema } from '../../schema/index.js';
|
|
|
4
4
|
import type { DocumentElement } from '../common/document-element.js';
|
|
5
5
|
import type { ComplexType } from './complex-type.js';
|
|
6
6
|
import { ComplexTypeBase } from './complex-type-base.js';
|
|
7
|
-
import
|
|
7
|
+
import { DataType } from './data-type.js';
|
|
8
8
|
import type { MappedType } from './mapped-type.js';
|
|
9
9
|
/**
|
|
10
10
|
* @namespace MixinType
|
|
@@ -76,7 +76,7 @@ export declare const MixinType: MixinTypeStatic;
|
|
|
76
76
|
declare class MixinTypeClass extends ComplexTypeBase {
|
|
77
77
|
readonly kind: OpraSchema.MixinType.Kind;
|
|
78
78
|
readonly types: (ComplexType | MixinType | MappedType)[];
|
|
79
|
-
extendsFrom(baseType: DataType): boolean;
|
|
79
|
+
extendsFrom(baseType: DataType | string | Type | object): boolean;
|
|
80
80
|
toJSON(): OpraSchema.MixinType;
|
|
81
81
|
}
|
|
82
82
|
export {};
|
|
@@ -14,7 +14,7 @@ export declare namespace SimpleType {
|
|
|
14
14
|
kind: OpraSchema.SimpleType.Kind;
|
|
15
15
|
}, DataType.Metadata, OpraSchema.SimpleType> {
|
|
16
16
|
}
|
|
17
|
-
interface Options extends DataType.Options {
|
|
17
|
+
interface Options extends Combine<Pick<OpraSchema.SimpleType, 'nameMappings'>, DataType.Options> {
|
|
18
18
|
}
|
|
19
19
|
interface InitArguments extends Combine<{
|
|
20
20
|
kind: OpraSchema.SimpleType.Kind;
|
|
@@ -64,11 +64,13 @@ declare abstract class SimpleTypeClass extends DataType {
|
|
|
64
64
|
readonly kind: OpraSchema.SimpleType.Kind;
|
|
65
65
|
readonly base?: SimpleType;
|
|
66
66
|
readonly attributes: Record<string, SimpleType.Attribute>;
|
|
67
|
+
readonly nameMappings: Record<string, string>;
|
|
67
68
|
readonly ownAttributes: Record<string, SimpleType.Attribute>;
|
|
69
|
+
readonly ownNameMappings: Record<string, string>;
|
|
68
70
|
protected _generateDecoder?: SimpleType.ValidatorGenerator;
|
|
69
71
|
protected _generateEncoder?: SimpleType.ValidatorGenerator;
|
|
70
72
|
properties?: any;
|
|
71
|
-
extendsFrom(baseType: DataType): boolean;
|
|
73
|
+
extendsFrom(baseType: DataType | string | Type | object): boolean;
|
|
72
74
|
generateCodec<T extends Record<string, any> | object = object>(codec: 'encode' | 'decode', options?: DataType.GenerateCodecOptions | null, properties?: Partial<T>): Validator;
|
|
73
75
|
toJSON(): OpraSchema.SimpleType;
|
|
74
76
|
}
|
|
@@ -18,24 +18,29 @@ export declare namespace DataTypeFactory {
|
|
|
18
18
|
type DataTypeSources = ThunkAsync<Type | EnumType.EnumObject | EnumType.EnumArray | object>[] | Record<string, OpraSchema.DataType>;
|
|
19
19
|
type DataTypeThunk = Type | EnumType.EnumObject | EnumType.EnumArray | object;
|
|
20
20
|
interface ComplexTypeInit extends Combine<{
|
|
21
|
+
_instance?: ComplexType;
|
|
21
22
|
base?: string | ComplexTypeInit | MappedTypeInit | MixinTypeInit;
|
|
22
23
|
fields?: Record<string, ApiFieldInit>;
|
|
23
24
|
additionalFields?: boolean | string | DataTypeFactory.DataTypeInitArguments | ['error'] | ['error', string];
|
|
24
25
|
}, ComplexType.InitArguments> {
|
|
25
26
|
}
|
|
26
27
|
interface EnumTypeInit extends Combine<{
|
|
28
|
+
_instance?: MappedType;
|
|
27
29
|
base?: string | EnumTypeInit;
|
|
28
30
|
}, EnumType.InitArguments> {
|
|
29
31
|
}
|
|
30
32
|
interface MappedTypeInit extends Combine<{
|
|
33
|
+
_instance?: MappedType;
|
|
31
34
|
base: string | ComplexTypeInit | MappedTypeInit | MixinTypeInit;
|
|
32
35
|
}, MappedType.InitArguments> {
|
|
33
36
|
}
|
|
34
37
|
interface MixinTypeInit extends Combine<{
|
|
38
|
+
_instance?: MixinType;
|
|
35
39
|
types: (string | ComplexTypeInit | MappedTypeInit | MixinTypeInit)[];
|
|
36
40
|
}, MixinType.InitArguments> {
|
|
37
41
|
}
|
|
38
42
|
interface SimpleTypeInit extends Combine<{
|
|
43
|
+
_instance?: SimpleType;
|
|
39
44
|
base?: string | SimpleTypeInit;
|
|
40
45
|
}, SimpleType.InitArguments> {
|
|
41
46
|
}
|
|
@@ -9,6 +9,10 @@ export interface SimpleType extends StrictOmit<DataTypeBase, 'kind'> {
|
|
|
9
9
|
base?: DataType.Name;
|
|
10
10
|
attributes?: Record<string, Attribute>;
|
|
11
11
|
properties?: Record<string, any>;
|
|
12
|
+
/**
|
|
13
|
+
* Naming alternatives across software languages
|
|
14
|
+
*/
|
|
15
|
+
nameMappings?: Record<string, string>;
|
|
12
16
|
}
|
|
13
17
|
export declare namespace SimpleType {
|
|
14
18
|
const Kind = "SimpleType";
|