@opra/common 0.24.2 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser.js +368 -314
- package/cjs/document/data-type/complex-type-class.js +151 -0
- package/cjs/document/data-type/complex-type.js +13 -168
- package/cjs/document/data-type/data-type.js +4 -0
- package/cjs/document/data-type/enum-type-class.js +32 -0
- package/cjs/document/data-type/enum-type.js +24 -49
- package/cjs/document/data-type/field-class.js +34 -0
- package/cjs/document/data-type/field-decorator.js +45 -0
- package/cjs/document/data-type/field.js +25 -0
- package/cjs/document/data-type/mapped-type-class.js +48 -0
- package/cjs/document/data-type/mapped-type.js +18 -58
- package/cjs/document/data-type/simple-type-class.js +29 -0
- package/cjs/document/data-type/simple-type.js +12 -43
- package/cjs/document/data-type/union-type-class.js +36 -0
- package/cjs/document/data-type/union-type.js +3 -31
- package/cjs/document/{resource → decorators}/collection-decorator.js +2 -24
- package/cjs/document/decorators/complex-type.decorator.js +23 -0
- package/cjs/document/decorators/resource.decorator.js +38 -0
- package/cjs/document/decorators/simple-type.decorator.js +20 -0
- package/cjs/document/{resource/singleton-decorator.js → decorators/singleton.decorator.js} +2 -19
- package/cjs/document/{resource/storage-decorator.js → decorators/storage.decorator.js} +2 -18
- package/cjs/document/index.js +1 -1
- package/cjs/document/resource/collection.js +4 -3
- package/cjs/document/resource/endpoint.js +44 -0
- package/cjs/document/resource/resource.js +9 -10
- package/cjs/document/resource/singleton.js +5 -1
- package/cjs/document/resource/storage.js +5 -1
- package/cjs/schema/opra-schema.ns.js +1 -0
- package/cjs/schema/resource/endpoint.interface.js +2 -0
- package/esm/document/data-type/complex-type-class.js +147 -0
- package/esm/document/data-type/complex-type.js +13 -168
- package/esm/document/data-type/data-type.js +4 -0
- package/esm/document/data-type/enum-type-class.js +27 -0
- package/esm/document/data-type/enum-type.js +22 -47
- package/esm/document/data-type/field-class.js +30 -0
- package/esm/document/data-type/field-decorator.js +41 -0
- package/esm/document/data-type/field.js +21 -0
- package/esm/document/data-type/mapped-type-class.js +43 -0
- package/esm/document/data-type/mapped-type.js +13 -53
- package/esm/document/data-type/simple-type-class.js +24 -0
- package/esm/document/data-type/simple-type.js +12 -43
- package/esm/document/data-type/union-type-class.js +32 -0
- package/esm/document/data-type/union-type.js +2 -30
- package/esm/document/{resource → decorators}/collection-decorator.js +2 -23
- package/esm/document/decorators/complex-type.decorator.js +18 -0
- package/esm/document/decorators/resource.decorator.js +33 -0
- package/esm/document/decorators/simple-type.decorator.js +15 -0
- package/esm/document/{resource/singleton-decorator.js → decorators/singleton.decorator.js} +2 -18
- package/esm/document/{resource/storage-decorator.js → decorators/storage.decorator.js} +2 -17
- package/esm/document/index.js +1 -1
- package/esm/document/resource/collection.js +4 -3
- package/esm/document/resource/endpoint.js +40 -0
- package/esm/document/resource/resource.js +9 -10
- package/esm/document/resource/singleton.js +5 -1
- package/esm/document/resource/storage.js +5 -1
- package/esm/schema/opra-schema.ns.js +1 -0
- package/esm/schema/resource/endpoint.interface.js +1 -0
- package/package.json +3 -11
- package/types/document/data-type/complex-type-class.d.ts +33 -0
- package/types/document/data-type/complex-type.d.ts +18 -43
- package/types/document/data-type/data-type.d.ts +17 -13
- package/types/document/data-type/enum-type-class.d.ts +17 -0
- package/types/document/data-type/enum-type.d.ts +11 -24
- package/types/document/data-type/field-class.d.ts +20 -0
- package/types/document/data-type/field-decorator.d.ts +5 -0
- package/types/document/data-type/{api-field.d.ts → field.d.ts} +20 -20
- package/types/document/data-type/mapped-type-class.d.ts +21 -0
- package/types/document/data-type/mapped-type.d.ts +24 -39
- package/types/document/data-type/simple-type-class.d.ts +17 -0
- package/types/document/data-type/simple-type.d.ts +21 -31
- package/types/document/data-type/union-type-class.d.ts +18 -0
- package/types/document/data-type/union-type.d.ts +15 -27
- package/types/document/{resource → decorators}/collection-decorator.d.ts +14 -14
- package/types/document/decorators/complex-type.decorator.d.ts +2 -0
- package/types/document/decorators/resource.decorator.d.ts +9 -0
- package/types/document/decorators/simple-type.decorator.d.ts +2 -0
- package/types/document/{resource/singleton-decorator.d.ts → decorators/singleton.decorator.d.ts} +11 -11
- package/types/document/{resource/storage-decorator.d.ts → decorators/storage.decorator.d.ts} +10 -10
- package/types/document/factory/import-type-class.d.ts +1 -1
- package/types/document/index.d.ts +1 -1
- package/types/document/resource/collection.d.ts +16 -12
- package/types/document/resource/endpoint.d.ts +29 -0
- package/types/document/resource/resource.d.ts +15 -14
- package/types/document/resource/singleton.d.ts +15 -8
- package/types/document/resource/storage-class.d.ts +0 -2
- package/types/document/resource/storage.d.ts +12 -8
- package/types/filter/ast/terms/qualified-identifier.d.ts +1 -1
- package/types/schema/opra-schema.ns.d.ts +1 -0
- package/types/schema/resource/collection.interface.d.ts +2 -1
- package/types/schema/resource/endpoint.interface.d.ts +12 -0
- package/types/schema/resource/resource.interface.d.ts +3 -15
- package/types/schema/resource/storage.interface.d.ts +2 -1
- package/cjs/document/data-type/api-field.js +0 -83
- package/cjs/document/resource/action.js +0 -12
- package/cjs/document/resource/resource-decorator.js +0 -16
- package/esm/document/data-type/api-field.js +0 -80
- package/esm/document/resource/action.js +0 -8
- package/esm/document/resource/resource-decorator.js +0 -13
- package/types/document/resource/action.d.ts +0 -11
- package/types/document/resource/resource-decorator.d.ts +0 -5
|
@@ -1,42 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MappedType = exports.OmitType = exports.PickType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
require("reflect-metadata");
|
|
6
6
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
7
7
|
const index_js_1 = require("../../helpers/index.js");
|
|
8
8
|
const index_js_2 = require("../../schema/index.js");
|
|
9
9
|
const constants_js_1 = require("../constants.js");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
own.pick = init.pick;
|
|
17
|
-
own.omit = init.omit;
|
|
18
|
-
this.kind = index_js_2.OpraSchema.MappedType.Kind;
|
|
19
|
-
this.type = init.type;
|
|
20
|
-
this.pick = own.pick;
|
|
21
|
-
this.omit = own.omit;
|
|
22
|
-
this.fields = new index_js_1.ResponsiveMap();
|
|
23
|
-
this.additionalFields = this.type.additionalFields;
|
|
24
|
-
const isInheritedPredicate = getIsInheritedPredicateFn(init.pick, init.omit);
|
|
25
|
-
for (const [elemName, elem] of this.type.fields.entries()) {
|
|
26
|
-
if (isInheritedPredicate(elemName))
|
|
27
|
-
this.fields.set(elemName, elem);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exportSchema() {
|
|
31
|
-
const out = data_type_js_1.DataType.prototype.exportSchema.call(this);
|
|
32
|
-
Object.assign(out, (0, index_js_1.omitUndefined)({
|
|
33
|
-
type: this.type.name ? this.type.name : this.type.exportSchema(),
|
|
34
|
-
pick: this.own.pick,
|
|
35
|
-
omit: this.own.omit,
|
|
36
|
-
}));
|
|
37
|
-
return out;
|
|
38
|
-
}
|
|
10
|
+
const mapped_type_class_js_1 = require("./mapped-type-class.js");
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
function PickType(classRef, keys) {
|
|
15
|
+
return (0, exports.MappedType)(classRef, { pick: keys });
|
|
39
16
|
}
|
|
17
|
+
exports.PickType = PickType;
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
function OmitType(classRef, keys) {
|
|
22
|
+
return (0, exports.MappedType)(classRef, { omit: keys });
|
|
23
|
+
}
|
|
24
|
+
exports.OmitType = OmitType;
|
|
40
25
|
/**
|
|
41
26
|
* @class MappedType
|
|
42
27
|
*/
|
|
@@ -44,12 +29,12 @@ exports.MappedType = function (...args) {
|
|
|
44
29
|
// Constructor
|
|
45
30
|
if (this) {
|
|
46
31
|
const [document, init] = args;
|
|
47
|
-
(0, putil_merge_1.default)(this, new MappedTypeClass(document, init), { descriptor: true });
|
|
32
|
+
(0, putil_merge_1.default)(this, new mapped_type_class_js_1.MappedTypeClass(document, init), { descriptor: true });
|
|
48
33
|
return;
|
|
49
34
|
}
|
|
50
35
|
// MappedType helper
|
|
51
36
|
const [mappedSource, options] = args;
|
|
52
|
-
const isInheritedPredicate = getIsInheritedPredicateFn(options.pick, options.omit);
|
|
37
|
+
const isInheritedPredicate = (0, mapped_type_class_js_1.getIsInheritedPredicateFn)(options.pick, options.omit);
|
|
53
38
|
class MappedClass {
|
|
54
39
|
constructor() {
|
|
55
40
|
(0, index_js_1.inheritPropertyInitializers)(this, mappedSource, isInheritedPredicate);
|
|
@@ -77,30 +62,5 @@ exports.MappedType = function (...args) {
|
|
|
77
62
|
});
|
|
78
63
|
return MappedClass;
|
|
79
64
|
};
|
|
80
|
-
exports.MappedType.prototype = MappedTypeClass.prototype;
|
|
65
|
+
exports.MappedType.prototype = mapped_type_class_js_1.MappedTypeClass.prototype;
|
|
81
66
|
exports.MappedType._applyMixin = () => void 0;
|
|
82
|
-
function getIsInheritedPredicateFn(pick, omit) {
|
|
83
|
-
const pickKeys = pick?.map(x => String(x).toLowerCase());
|
|
84
|
-
const omitKeys = omit?.map(x => String(x).toLowerCase());
|
|
85
|
-
return (propertyName) => {
|
|
86
|
-
if (omitKeys && omitKeys.includes(propertyName.toLowerCase()))
|
|
87
|
-
return false;
|
|
88
|
-
if (pickKeys)
|
|
89
|
-
return pickKeys.includes(propertyName.toLowerCase());
|
|
90
|
-
return true;
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
*/
|
|
96
|
-
function PickType(classRef, keys) {
|
|
97
|
-
return (0, exports.MappedType)(classRef, { pick: keys });
|
|
98
|
-
}
|
|
99
|
-
exports.PickType = PickType;
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
*/
|
|
103
|
-
function OmitType(classRef, keys) {
|
|
104
|
-
return (0, exports.MappedType)(classRef, { omit: keys });
|
|
105
|
-
}
|
|
106
|
-
exports.OmitType = OmitType;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleTypeClass = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const vg = tslib_1.__importStar(require("valgen"));
|
|
6
|
+
const index_js_1 = require("../../schema/index.js");
|
|
7
|
+
const data_type_js_1 = require("./data-type.js");
|
|
8
|
+
/**
|
|
9
|
+
* @class SimpleType
|
|
10
|
+
*/
|
|
11
|
+
class SimpleTypeClass extends data_type_js_1.DataType {
|
|
12
|
+
constructor(document, init) {
|
|
13
|
+
super(document, init);
|
|
14
|
+
this.kind = index_js_1.OpraSchema.SimpleType.Kind;
|
|
15
|
+
this.base = init.base;
|
|
16
|
+
this.decode = init.decoder || init.base?.decode || vg.isAny();
|
|
17
|
+
this.encode = init.encoder || init.base?.encode || vg.isAny();
|
|
18
|
+
}
|
|
19
|
+
exportSchema() {
|
|
20
|
+
// noinspection UnnecessaryLocalVariableJS
|
|
21
|
+
const out = super.exportSchema();
|
|
22
|
+
// Object.assign(out, omitUndefined({
|
|
23
|
+
// base: this.base ?
|
|
24
|
+
// (this.base.name ? this.base.name : this.base.exportSchema()) : undefined,
|
|
25
|
+
// }));
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.SimpleTypeClass = SimpleTypeClass;
|
|
@@ -3,54 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SimpleType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
require("reflect-metadata");
|
|
6
|
-
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
7
6
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
8
|
-
const vg = tslib_1.__importStar(require("valgen"));
|
|
9
|
-
const index_js_1 = require("../../schema/index.js");
|
|
10
7
|
const constants_js_1 = require("../constants.js");
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
* @class SimpleType
|
|
14
|
-
*/
|
|
15
|
-
class SimpleTypeClass extends data_type_js_1.DataType {
|
|
16
|
-
constructor(document, init) {
|
|
17
|
-
super(document, init);
|
|
18
|
-
this.kind = index_js_1.OpraSchema.SimpleType.Kind;
|
|
19
|
-
this.base = init.base;
|
|
20
|
-
this.decode = init.decoder || init.base?.decode || vg.isAny();
|
|
21
|
-
this.encode = init.encoder || init.base?.encode || vg.isAny();
|
|
22
|
-
}
|
|
23
|
-
exportSchema() {
|
|
24
|
-
// noinspection UnnecessaryLocalVariableJS
|
|
25
|
-
const out = super.exportSchema();
|
|
26
|
-
// Object.assign(out, omitUndefined({
|
|
27
|
-
// base: this.base ?
|
|
28
|
-
// (this.base.name ? this.base.name : this.base.exportSchema()) : undefined,
|
|
29
|
-
// }));
|
|
30
|
-
return out;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
8
|
+
const simple_type_decorator_js_1 = require("../decorators/simple-type.decorator.js");
|
|
9
|
+
const simple_type_class_js_1 = require("./simple-type-class.js");
|
|
33
10
|
/**
|
|
34
11
|
* @class SimpleType
|
|
35
12
|
*/
|
|
36
13
|
exports.SimpleType = function (...args) {
|
|
37
|
-
//
|
|
38
|
-
if (this) {
|
|
39
|
-
const [
|
|
40
|
-
|
|
41
|
-
return;
|
|
14
|
+
// Decorator
|
|
15
|
+
if (!this) {
|
|
16
|
+
const [options] = args;
|
|
17
|
+
return exports.SimpleType[constants_js_1.DECORATOR](options);
|
|
42
18
|
}
|
|
43
|
-
//
|
|
44
|
-
const [
|
|
45
|
-
|
|
46
|
-
let name = options?.name || target.name.match(constants_js_1.TYPENAME_PATTERN)?.[1] || target.name;
|
|
47
|
-
name = name.charAt(0).toLowerCase() + name.substring(1);
|
|
48
|
-
const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target) || {};
|
|
49
|
-
metadata.kind = index_js_1.OpraSchema.SimpleType.Kind;
|
|
50
|
-
metadata.name = name;
|
|
51
|
-
if (options)
|
|
52
|
-
Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name']));
|
|
53
|
-
Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, metadata, target);
|
|
54
|
-
};
|
|
19
|
+
// Constructor
|
|
20
|
+
const [document, init] = args;
|
|
21
|
+
(0, putil_merge_1.default)(this, new simple_type_class_js_1.SimpleTypeClass(document, init), { descriptor: true });
|
|
55
22
|
};
|
|
56
|
-
exports.SimpleType.prototype = SimpleTypeClass.prototype;
|
|
23
|
+
exports.SimpleType.prototype = simple_type_class_js_1.SimpleTypeClass.prototype;
|
|
24
|
+
Object.assign(exports.SimpleType, simple_type_decorator_js_1.SimpleTypeDecorator);
|
|
25
|
+
exports.SimpleType[constants_js_1.DECORATOR] = simple_type_decorator_js_1.SimpleTypeDecorator;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnionTypeClass = void 0;
|
|
4
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
5
|
+
const index_js_2 = require("../../schema/index.js");
|
|
6
|
+
const complex_type_js_1 = require("./complex-type.js");
|
|
7
|
+
const data_type_js_1 = require("./data-type.js");
|
|
8
|
+
const mapped_type_js_1 = require("./mapped-type.js");
|
|
9
|
+
class UnionTypeClass extends data_type_js_1.DataType {
|
|
10
|
+
constructor(document, init) {
|
|
11
|
+
super(document, init);
|
|
12
|
+
this.kind = index_js_2.OpraSchema.UnionType.Kind;
|
|
13
|
+
this.fields = new index_js_1.ResponsiveMap();
|
|
14
|
+
const own = this.own;
|
|
15
|
+
own.types = [];
|
|
16
|
+
const UnionType = Object.getPrototypeOf(this).constructor;
|
|
17
|
+
for (const base of init.types) {
|
|
18
|
+
if (!(base instanceof complex_type_js_1.ComplexType || base instanceof UnionType || base instanceof mapped_type_js_1.MappedType))
|
|
19
|
+
throw new TypeError(`${index_js_2.OpraSchema.UnionType.Kind} shall contain ${index_js_2.OpraSchema.ComplexType.Kind}, ` +
|
|
20
|
+
`${index_js_2.OpraSchema.UnionType.Kind} of ${index_js_2.OpraSchema.MappedType.Kind} types.`);
|
|
21
|
+
own.types.push(base);
|
|
22
|
+
if (base.additionalFields)
|
|
23
|
+
this.additionalFields = base.additionalFields;
|
|
24
|
+
this.fields.setAll(base.fields);
|
|
25
|
+
}
|
|
26
|
+
this.types = [...own.types];
|
|
27
|
+
}
|
|
28
|
+
exportSchema() {
|
|
29
|
+
const out = super.exportSchema();
|
|
30
|
+
Object.assign(out, (0, index_js_1.omitUndefined)({
|
|
31
|
+
types: this.own.types.map(t => t.name ? t.name : t.exportSchema())
|
|
32
|
+
}));
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.UnionTypeClass = UnionTypeClass;
|
|
@@ -7,35 +7,7 @@ const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
|
7
7
|
const index_js_1 = require("../../helpers/index.js");
|
|
8
8
|
const index_js_2 = require("../../schema/index.js");
|
|
9
9
|
const constants_js_1 = require("../constants.js");
|
|
10
|
-
const
|
|
11
|
-
const data_type_js_1 = require("./data-type.js");
|
|
12
|
-
const mapped_type_js_1 = require("./mapped-type.js");
|
|
13
|
-
class UnionTypeClass extends data_type_js_1.DataType {
|
|
14
|
-
constructor(document, init) {
|
|
15
|
-
super(document, init);
|
|
16
|
-
this.kind = index_js_2.OpraSchema.UnionType.Kind;
|
|
17
|
-
this.fields = new index_js_1.ResponsiveMap();
|
|
18
|
-
const own = this.own;
|
|
19
|
-
own.types = [];
|
|
20
|
-
for (const base of init.types) {
|
|
21
|
-
if (!(base instanceof complex_type_js_1.ComplexType || base instanceof exports.UnionType || base instanceof mapped_type_js_1.MappedType))
|
|
22
|
-
throw new TypeError(`${index_js_2.OpraSchema.UnionType.Kind} shall contain ${index_js_2.OpraSchema.ComplexType.Kind}, ` +
|
|
23
|
-
`${index_js_2.OpraSchema.UnionType.Kind} of ${index_js_2.OpraSchema.MappedType.Kind} types.`);
|
|
24
|
-
own.types.push(base);
|
|
25
|
-
if (base.additionalFields)
|
|
26
|
-
this.additionalFields = base.additionalFields;
|
|
27
|
-
this.fields.setAll(base.fields);
|
|
28
|
-
}
|
|
29
|
-
this.types = [...own.types];
|
|
30
|
-
}
|
|
31
|
-
exportSchema() {
|
|
32
|
-
const out = super.exportSchema();
|
|
33
|
-
Object.assign(out, (0, index_js_1.omitUndefined)({
|
|
34
|
-
types: this.own.types.map(t => t.name ? t.name : t.exportSchema())
|
|
35
|
-
}));
|
|
36
|
-
return out;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
10
|
+
const union_type_class_js_1 = require("./union-type-class.js");
|
|
39
11
|
/**
|
|
40
12
|
* @class UnionType
|
|
41
13
|
*/
|
|
@@ -43,7 +15,7 @@ exports.UnionType = function (...args) {
|
|
|
43
15
|
// Constructor
|
|
44
16
|
if (this) {
|
|
45
17
|
const [document, init] = args;
|
|
46
|
-
(0, putil_merge_1.default)(this, new UnionTypeClass(document, init), { descriptor: true });
|
|
18
|
+
(0, putil_merge_1.default)(this, new union_type_class_js_1.UnionTypeClass(document, init), { descriptor: true });
|
|
47
19
|
return;
|
|
48
20
|
}
|
|
49
21
|
// UnionType helper
|
|
@@ -75,5 +47,5 @@ exports.UnionType = function (...args) {
|
|
|
75
47
|
exports.UnionType._applyMixin(UnionClass, ...clasRefs);
|
|
76
48
|
return UnionClass;
|
|
77
49
|
};
|
|
78
|
-
exports.UnionType.prototype = UnionTypeClass.prototype;
|
|
50
|
+
exports.UnionType.prototype = union_type_class_js_1.UnionTypeClass.prototype;
|
|
79
51
|
exports.UnionType._applyMixin = () => void 0;
|
|
@@ -1,34 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CollectionDecorator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
|
-
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
7
4
|
const index_js_1 = require("../../schema/index.js");
|
|
8
5
|
const constants_js_1 = require("../constants.js");
|
|
9
|
-
const resource_decorator_js_1 = require("./resource
|
|
10
|
-
const NAME_PATTERN = /^(.*)(Resource|Collection|Controller)$/;
|
|
6
|
+
const resource_decorator_js_1 = require("./resource.decorator.js");
|
|
11
7
|
const operationProperties = ['create', 'delete', 'deleteMany', 'get', 'findMany', 'update', 'updateMany'];
|
|
12
8
|
function CollectionDecorator(type, options) {
|
|
13
|
-
return
|
|
14
|
-
const name = options?.name || target.name.match(NAME_PATTERN)?.[1] || target.name;
|
|
15
|
-
const metadata = Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target) || {};
|
|
16
|
-
const baseMetadata = Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, Object.getPrototypeOf(target));
|
|
17
|
-
if (baseMetadata) {
|
|
18
|
-
(0, putil_merge_1.default)(metadata, baseMetadata, { deep: true });
|
|
19
|
-
}
|
|
20
|
-
metadata.kind = index_js_1.OpraSchema.Collection.Kind;
|
|
21
|
-
metadata.name = name;
|
|
22
|
-
metadata.type = type;
|
|
23
|
-
// Merge with previous metadata object
|
|
24
|
-
const m = Reflect.getMetadata(constants_js_1.RESOURCE_METADATA, target);
|
|
25
|
-
if (m && metadata !== m)
|
|
26
|
-
Object.assign(metadata, (0, lodash_omit_1.default)(m), Object.keys(metadata));
|
|
27
|
-
// Merge options
|
|
28
|
-
if (options)
|
|
29
|
-
Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name', 'type', 'controller']));
|
|
30
|
-
Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, metadata, target);
|
|
31
|
-
};
|
|
9
|
+
return (0, resource_decorator_js_1.ResourceDecorator)(index_js_1.OpraSchema.Collection.Kind, { ...options, type });
|
|
32
10
|
}
|
|
33
11
|
exports.CollectionDecorator = CollectionDecorator;
|
|
34
12
|
Object.assign(CollectionDecorator, resource_decorator_js_1.ResourceDecorator);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComplexTypeDecorator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
|
+
const index_js_1 = require("../../schema/index.js");
|
|
7
|
+
const constants_js_1 = require("../constants.js");
|
|
8
|
+
function ComplexTypeDecorator(options) {
|
|
9
|
+
return function (target) {
|
|
10
|
+
const name = options?.name || target.name.match(constants_js_1.TYPENAME_PATTERN)?.[1] || target.name;
|
|
11
|
+
let metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target);
|
|
12
|
+
if (!metadata) {
|
|
13
|
+
metadata = {};
|
|
14
|
+
Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, metadata, target);
|
|
15
|
+
}
|
|
16
|
+
metadata.kind = index_js_1.OpraSchema.ComplexType.Kind;
|
|
17
|
+
metadata.name = name;
|
|
18
|
+
// Merge options
|
|
19
|
+
if (options)
|
|
20
|
+
Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name', 'base', 'fields']));
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.ComplexTypeDecorator = ComplexTypeDecorator;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourceDecorator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
|
+
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
7
|
+
const constants_js_1 = require("../constants.js");
|
|
8
|
+
function ResourceDecorator(kind, options) {
|
|
9
|
+
const namePattern = new RegExp(`^(.*)(${kind}|Resource|Controller)$`);
|
|
10
|
+
return function (target) {
|
|
11
|
+
const name = options?.name || namePattern.exec(target.name)?.[1] || target.name;
|
|
12
|
+
const metadata = { kind, name };
|
|
13
|
+
const baseMetadata = Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, Object.getPrototypeOf(target));
|
|
14
|
+
if (baseMetadata)
|
|
15
|
+
(0, putil_merge_1.default)(metadata, baseMetadata, { deep: true });
|
|
16
|
+
const oldMetadata = Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target);
|
|
17
|
+
if (oldMetadata)
|
|
18
|
+
(0, putil_merge_1.default)(metadata, oldMetadata, { deep: true });
|
|
19
|
+
(0, putil_merge_1.default)(metadata, {
|
|
20
|
+
kind,
|
|
21
|
+
name,
|
|
22
|
+
...(0, lodash_omit_1.default)(options, ['kind', 'name', 'controller'])
|
|
23
|
+
}, { deep: true });
|
|
24
|
+
Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, metadata, target);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.ResourceDecorator = ResourceDecorator;
|
|
28
|
+
ResourceDecorator.Action = function (options) {
|
|
29
|
+
return (target, propertyKey) => {
|
|
30
|
+
if (typeof propertyKey !== 'string')
|
|
31
|
+
throw new TypeError(`This decorator can't be used for Symbol keys'`);
|
|
32
|
+
const actionMeta = { ...options };
|
|
33
|
+
const resourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target.constructor) || {});
|
|
34
|
+
resourceMetadata.actions = resourceMetadata.actions || {};
|
|
35
|
+
resourceMetadata.actions[propertyKey] = actionMeta;
|
|
36
|
+
Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, resourceMetadata, target.constructor);
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleTypeDecorator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
|
+
const index_js_1 = require("../../schema/index.js");
|
|
7
|
+
const constants_js_1 = require("../constants.js");
|
|
8
|
+
function SimpleTypeDecorator(options) {
|
|
9
|
+
return function (target) {
|
|
10
|
+
let name = options?.name || target.name.match(constants_js_1.TYPENAME_PATTERN)?.[1] || target.name;
|
|
11
|
+
name = name.charAt(0).toLowerCase() + name.substring(1);
|
|
12
|
+
const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target) || {};
|
|
13
|
+
metadata.kind = index_js_1.OpraSchema.SimpleType.Kind;
|
|
14
|
+
metadata.name = name;
|
|
15
|
+
if (options)
|
|
16
|
+
Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name']));
|
|
17
|
+
Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, metadata, target);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.SimpleTypeDecorator = SimpleTypeDecorator;
|
|
@@ -1,29 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SingletonDecorator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
4
|
const index_js_1 = require("../../schema/index.js");
|
|
7
5
|
const constants_js_1 = require("../constants.js");
|
|
8
|
-
const resource_decorator_js_1 = require("./resource
|
|
9
|
-
const NAME_PATTERN = /^(.*)(Resource|Singleton|Controller)$/;
|
|
6
|
+
const resource_decorator_js_1 = require("./resource.decorator.js");
|
|
10
7
|
const operationProperties = ['create', 'delete', 'get', 'update'];
|
|
11
8
|
function SingletonDecorator(type, options) {
|
|
12
|
-
return
|
|
13
|
-
const name = options?.name || target.name.match(NAME_PATTERN)?.[1] || target.name;
|
|
14
|
-
const metadata = Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target) || {};
|
|
15
|
-
metadata.kind = index_js_1.OpraSchema.Singleton.Kind;
|
|
16
|
-
metadata.name = name;
|
|
17
|
-
metadata.type = type;
|
|
18
|
-
// Merge with previous metadata object
|
|
19
|
-
const m = Reflect.getMetadata(constants_js_1.RESOURCE_METADATA, target);
|
|
20
|
-
if (m && metadata !== m)
|
|
21
|
-
Object.assign(metadata, (0, lodash_omit_1.default)(m), Object.keys(metadata));
|
|
22
|
-
// Merge options
|
|
23
|
-
if (options)
|
|
24
|
-
Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name', 'type', 'controller']));
|
|
25
|
-
Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, metadata, target);
|
|
26
|
-
};
|
|
9
|
+
return (0, resource_decorator_js_1.ResourceDecorator)(index_js_1.OpraSchema.Singleton.Kind, { ...options, type });
|
|
27
10
|
}
|
|
28
11
|
exports.SingletonDecorator = SingletonDecorator;
|
|
29
12
|
Object.assign(SingletonDecorator, resource_decorator_js_1.ResourceDecorator);
|
|
@@ -1,28 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StorageDecorator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
4
|
const index_js_1 = require("../../schema/index.js");
|
|
7
5
|
const constants_js_1 = require("../constants.js");
|
|
8
|
-
const resource_decorator_js_1 = require("./resource
|
|
9
|
-
const NAME_PATTERN = /^(.*)(Resource|Storage|Controller)$/;
|
|
6
|
+
const resource_decorator_js_1 = require("./resource.decorator.js");
|
|
10
7
|
const operationProperties = ['delete', 'get', 'post'];
|
|
11
8
|
function StorageDecorator(options) {
|
|
12
|
-
return
|
|
13
|
-
const name = options?.name || target.name.match(NAME_PATTERN)?.[1] || target.name;
|
|
14
|
-
const metadata = Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target) || {};
|
|
15
|
-
metadata.kind = index_js_1.OpraSchema.Storage.Kind;
|
|
16
|
-
metadata.name = name;
|
|
17
|
-
// Merge with previous metadata object
|
|
18
|
-
const m = Reflect.getMetadata(constants_js_1.RESOURCE_METADATA, target);
|
|
19
|
-
if (m && metadata !== m)
|
|
20
|
-
Object.assign(metadata, (0, lodash_omit_1.default)(m), Object.keys(metadata));
|
|
21
|
-
// Merge options
|
|
22
|
-
if (options)
|
|
23
|
-
Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name', 'type', 'controller']));
|
|
24
|
-
Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, metadata, target);
|
|
25
|
-
};
|
|
9
|
+
return (0, resource_decorator_js_1.ResourceDecorator)(index_js_1.OpraSchema.Storage.Kind, options);
|
|
26
10
|
}
|
|
27
11
|
exports.StorageDecorator = StorageDecorator;
|
|
28
12
|
Object.assign(StorageDecorator, resource_decorator_js_1.ResourceDecorator);
|
package/cjs/document/index.js
CHANGED
|
@@ -7,7 +7,7 @@ tslib_1.__exportStar(require("./api-document.js"), exports);
|
|
|
7
7
|
tslib_1.__exportStar(require("./factory/index.js"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./data-type/data-type.js"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./data-type/complex-type.js"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./data-type/
|
|
10
|
+
tslib_1.__exportStar(require("./data-type/field.js"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./data-type/enum-type.js"), exports);
|
|
12
12
|
tslib_1.__exportStar(require("./data-type/mapped-type.js"), exports);
|
|
13
13
|
tslib_1.__exportStar(require("./data-type/simple-type.js"), exports);
|
|
@@ -4,13 +4,14 @@ exports.Collection = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
6
6
|
const constants_js_1 = require("../constants.js");
|
|
7
|
+
const collection_decorator_js_1 = require("../decorators/collection-decorator.js");
|
|
7
8
|
const collection_class_js_1 = require("./collection-class.js");
|
|
8
|
-
const collection_decorator_js_1 = require("./collection-decorator.js");
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* @class Collection
|
|
11
|
+
* @decorator Collection
|
|
11
12
|
*/
|
|
12
13
|
exports.Collection = function (...args) {
|
|
13
|
-
//
|
|
14
|
+
// Decorator
|
|
14
15
|
if (!this) {
|
|
15
16
|
const [type, options] = args;
|
|
16
17
|
return exports.Collection[constants_js_1.DECORATOR].call(undefined, type, options);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Endpoint = void 0;
|
|
4
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
5
|
+
class Endpoint {
|
|
6
|
+
constructor(init) {
|
|
7
|
+
this.parameters = new index_js_1.ResponsiveMap();
|
|
8
|
+
this.name = init.name;
|
|
9
|
+
this.description = init.description;
|
|
10
|
+
if (init.parameters) {
|
|
11
|
+
for (const [n, p] of Object.entries(init.parameters)) {
|
|
12
|
+
this.parameters.set(n, new Endpoint.Parameter(p));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exportSchema() {
|
|
17
|
+
const schema = (0, index_js_1.omitUndefined)({
|
|
18
|
+
description: this.description
|
|
19
|
+
});
|
|
20
|
+
if (this.parameters.size) {
|
|
21
|
+
schema.parameters = {};
|
|
22
|
+
for (const [name, param] of this.parameters.entries()) {
|
|
23
|
+
schema.parameters[name] = param.exportSchema();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return schema;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.Endpoint = Endpoint;
|
|
30
|
+
(function (Endpoint) {
|
|
31
|
+
class Parameter {
|
|
32
|
+
constructor(init) {
|
|
33
|
+
Object.assign(this, init);
|
|
34
|
+
}
|
|
35
|
+
exportSchema() {
|
|
36
|
+
return (0, index_js_1.omitUndefined)({
|
|
37
|
+
type: typeof this.type === 'string' ? this.type : this.type.exportSchema(),
|
|
38
|
+
description: this.description,
|
|
39
|
+
isArray: this.isArray
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
Endpoint.Parameter = Parameter;
|
|
44
|
+
})(Endpoint || (exports.Endpoint = Endpoint = {}));
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Resource = void 0;
|
|
4
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
4
5
|
const object_utils_js_1 = require("../../helpers/object-utils.js");
|
|
5
6
|
const inspect_util_js_1 = require("../utils/inspect.util.js");
|
|
6
|
-
const
|
|
7
|
+
const endpoint_js_1 = require("./endpoint.js");
|
|
7
8
|
class Resource {
|
|
8
9
|
constructor(document, init) {
|
|
9
|
-
this.actions =
|
|
10
|
+
this.actions = new index_js_1.ResponsiveMap();
|
|
10
11
|
this.document = document;
|
|
11
12
|
this.name = init.name;
|
|
12
13
|
this.description = init.description;
|
|
13
14
|
this.controller = init.controller;
|
|
14
15
|
if (init.actions) {
|
|
15
16
|
for (const [name, meta] of Object.entries(init.actions)) {
|
|
16
|
-
this.actions
|
|
17
|
+
this.actions.set(name, new endpoint_js_1.Endpoint({ ...meta, name }));
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -22,14 +23,12 @@ class Resource {
|
|
|
22
23
|
kind: this.kind,
|
|
23
24
|
description: this.description,
|
|
24
25
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
if (this.actions.size) {
|
|
27
|
+
schema.actions = {};
|
|
28
|
+
for (const action of this.actions.values()) {
|
|
29
|
+
schema.actions[action.name] = action.exportSchema();
|
|
30
|
+
}
|
|
30
31
|
}
|
|
31
|
-
if (i)
|
|
32
|
-
schema.actions = actions;
|
|
33
32
|
return schema;
|
|
34
33
|
}
|
|
35
34
|
toString() {
|
|
@@ -4,8 +4,12 @@ exports.Singleton = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
6
6
|
const constants_js_1 = require("../constants.js");
|
|
7
|
+
const singleton_decorator_js_1 = require("../decorators/singleton.decorator.js");
|
|
7
8
|
const singleton_class_js_1 = require("./singleton-class.js");
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @class Singleton
|
|
11
|
+
* @decorator Singleton
|
|
12
|
+
*/
|
|
9
13
|
exports.Singleton = function (...args) {
|
|
10
14
|
// ClassDecorator
|
|
11
15
|
if (!this) {
|
|
@@ -4,8 +4,12 @@ exports.Storage = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
6
6
|
const constants_js_1 = require("../constants.js");
|
|
7
|
+
const storage_decorator_js_1 = require("../decorators/storage.decorator.js");
|
|
7
8
|
const storage_class_js_1 = require("./storage-class.js");
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @class Storage
|
|
11
|
+
* @decorator Storage
|
|
12
|
+
*/
|
|
9
13
|
exports.Storage = function (...args) {
|
|
10
14
|
// ClassDecorator
|
|
11
15
|
if (!this) {
|
|
@@ -8,6 +8,7 @@ tslib_1.__exportStar(require("./data-type/field.interface.js"), exports);
|
|
|
8
8
|
tslib_1.__exportStar(require("./data-type/simple-type.interface.js"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./data-type/mapped-type.interface.js"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./data-type/union-type.interface.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./resource/endpoint.interface.js"), exports);
|
|
11
12
|
tslib_1.__exportStar(require("./resource/collection.interface.js"), exports);
|
|
12
13
|
tslib_1.__exportStar(require("./resource/container.interface.js"), exports);
|
|
13
14
|
tslib_1.__exportStar(require("./resource/resource.interface.js"), exports);
|