@opra/common 1.0.0-alpha.1 → 1.0.0-alpha.2
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/package.json +1 -1
- package/cjs/document/data-type/decorators/api-field-decorator.js +0 -26
- package/cjs/document/data-type/decorators/complex-type.decorator.js +0 -33
- package/cjs/document/data-type/decorators/simple-type.decorator.js +0 -67
- package/cjs/document/http/decorators/http-controller.decorator.js +0 -117
- package/cjs/document/http/decorators/http-operation-entity.decorator.js +0 -461
- package/cjs/document/http/decorators/http-operation.decorator.js +0 -183
- package/cjs/helpers/is-url-string.js +0 -12
- package/cjs/http/opra-url-path.js +0 -266
- package/cjs/http/opra-url.js +0 -253
- package/esm/document/data-type/decorators/api-field-decorator.js +0 -22
- package/esm/document/data-type/decorators/complex-type.decorator.js +0 -28
- package/esm/document/data-type/decorators/simple-type.decorator.js +0 -61
- package/esm/document/http/decorators/http-controller.decorator.js +0 -112
- package/esm/document/http/decorators/http-operation-entity.decorator.js +0 -459
- package/esm/document/http/decorators/http-operation.decorator.js +0 -178
- package/esm/helpers/is-url-string.js +0 -7
- package/esm/http/opra-url-path.js +0 -260
- package/esm/http/opra-url.js +0 -249
- package/types/document/data-type/decorators/api-field-decorator.d.ts +0 -5
- package/types/document/data-type/decorators/complex-type.decorator.d.ts +0 -2
- package/types/document/data-type/decorators/simple-type.decorator.d.ts +0 -20
- package/types/document/http/decorators/http-controller.decorator.d.ts +0 -14
- package/types/document/http/decorators/http-operation-entity.decorator.d.ts +0 -100
- package/types/document/http/decorators/http-operation.decorator.d.ts +0 -30
- package/types/helpers/is-url-string.d.ts +0 -2
- package/types/http/opra-url-path.d.ts +0 -55
- package/types/http/opra-url.d.ts +0 -66
package/package.json
CHANGED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiFieldDecorator = void 0;
|
|
4
|
-
const index_js_1 = require("../../../helpers/index.js");
|
|
5
|
-
const index_js_2 = require("../../../schema/index.js");
|
|
6
|
-
const constants_js_1 = require("../../constants.js");
|
|
7
|
-
function ApiFieldDecorator(options) {
|
|
8
|
-
return function (target, propertyKey) {
|
|
9
|
-
if (typeof propertyKey !== 'string')
|
|
10
|
-
throw new TypeError(`Symbol properties can't be used as a field`);
|
|
11
|
-
const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) || {};
|
|
12
|
-
metadata.kind = index_js_2.OpraSchema.ComplexType.Kind;
|
|
13
|
-
metadata.fields = metadata.fields || {};
|
|
14
|
-
const designType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
15
|
-
const elemMeta = (metadata.fields[propertyKey] = {
|
|
16
|
-
...options,
|
|
17
|
-
});
|
|
18
|
-
if (designType === Array) {
|
|
19
|
-
elemMeta.isArray = true;
|
|
20
|
-
}
|
|
21
|
-
else
|
|
22
|
-
elemMeta.type = elemMeta.type || designType;
|
|
23
|
-
Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, (0, index_js_1.omitUndefined)(metadata), target.constructor);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
exports.ApiFieldDecorator = ApiFieldDecorator;
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
let name;
|
|
11
|
-
if (!options?.embedded) {
|
|
12
|
-
if (options?.name) {
|
|
13
|
-
if (!constants_js_1.CLASS_NAME_PATTERN.test(options.name))
|
|
14
|
-
throw new TypeError(`"${options.name}" is not a valid type name`);
|
|
15
|
-
name = options.name;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
name = target.name.match(constants_js_1.EXTRACT_TYPENAME_PATTERN)?.[1] || target.name;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
let metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target);
|
|
22
|
-
if (!metadata) {
|
|
23
|
-
metadata = {};
|
|
24
|
-
Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, metadata, target);
|
|
25
|
-
}
|
|
26
|
-
metadata.kind = index_js_1.OpraSchema.ComplexType.Kind;
|
|
27
|
-
metadata.name = name;
|
|
28
|
-
// Merge options
|
|
29
|
-
if (options)
|
|
30
|
-
Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name', 'base', 'fields']));
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
exports.ComplexTypeDecorator = ComplexTypeDecorator;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AttributeDecoratorFactory = exports.SimpleTypeDecoratorFactory = 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 SimpleTypeDecoratorFactory(options) {
|
|
9
|
-
const decoratorChain = [];
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
const decorator = function (target) {
|
|
14
|
-
let name;
|
|
15
|
-
if (!options?.embedded) {
|
|
16
|
-
if (options?.name) {
|
|
17
|
-
if (!constants_js_1.CLASS_NAME_PATTERN.test(options.name))
|
|
18
|
-
throw new TypeError(`"${options.name}" is not a valid type name`);
|
|
19
|
-
name = options.name;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
name = target.name.match(constants_js_1.EXTRACT_TYPENAME_PATTERN)?.[1] || target.name;
|
|
23
|
-
name = name.toLowerCase();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target) || {};
|
|
27
|
-
metadata.kind = index_js_1.OpraSchema.SimpleType.Kind;
|
|
28
|
-
metadata.name = name;
|
|
29
|
-
if (options)
|
|
30
|
-
Object.assign(metadata, (0, lodash_omit_1.default)(options, ['kind', 'name']));
|
|
31
|
-
Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, metadata, target);
|
|
32
|
-
};
|
|
33
|
-
decorator.Example = (value, description) => {
|
|
34
|
-
decoratorChain.push((meta) => {
|
|
35
|
-
meta.examples = meta.examples || [];
|
|
36
|
-
meta.examples.push({
|
|
37
|
-
description,
|
|
38
|
-
value,
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
return decorator;
|
|
42
|
-
};
|
|
43
|
-
return decorator;
|
|
44
|
-
}
|
|
45
|
-
exports.SimpleTypeDecoratorFactory = SimpleTypeDecoratorFactory;
|
|
46
|
-
function AttributeDecoratorFactory(options) {
|
|
47
|
-
return (target, propertyKey) => {
|
|
48
|
-
if (typeof propertyKey !== 'string')
|
|
49
|
-
throw new TypeError(`Symbol properties can't be decorated with Attribute`);
|
|
50
|
-
const metadata = Reflect.getOwnMetadata(constants_js_1.DATATYPE_METADATA, target.constructor) || {};
|
|
51
|
-
const designType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
52
|
-
let format = 'string';
|
|
53
|
-
if (designType === Boolean)
|
|
54
|
-
format = 'boolean';
|
|
55
|
-
else if (designType === Number)
|
|
56
|
-
format = 'number';
|
|
57
|
-
metadata.kind = index_js_1.OpraSchema.SimpleType.Kind;
|
|
58
|
-
metadata.attributes = metadata.attributes || {};
|
|
59
|
-
metadata.attributes[propertyKey] = {
|
|
60
|
-
format: options?.format || format,
|
|
61
|
-
description: options?.description,
|
|
62
|
-
deprecated: options?.deprecated,
|
|
63
|
-
};
|
|
64
|
-
Reflect.defineMetadata(constants_js_1.DATATYPE_METADATA, metadata, target.constructor);
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
exports.AttributeDecoratorFactory = AttributeDecoratorFactory;
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpControllerDecoratorFactory = 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 index_js_1 = require("../../../schema/index.js");
|
|
8
|
-
const constants_js_1 = require("../../constants.js");
|
|
9
|
-
const CLASS_NAME_PATTERN = /^(.*)(Collection|Singleton|Resource|Controller)$/;
|
|
10
|
-
function HttpControllerDecoratorFactory(options) {
|
|
11
|
-
const decoratorChain = [];
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
const decorator = function (target) {
|
|
16
|
-
let name = options?.name;
|
|
17
|
-
if (!name)
|
|
18
|
-
name = CLASS_NAME_PATTERN.exec(target.name)?.[1] || target.name;
|
|
19
|
-
const metadata = {};
|
|
20
|
-
const baseMetadata = Reflect.getOwnMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, Object.getPrototypeOf(target));
|
|
21
|
-
if (baseMetadata)
|
|
22
|
-
(0, putil_merge_1.default)(metadata, baseMetadata, { deep: true });
|
|
23
|
-
const oldMetadata = Reflect.getOwnMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, target);
|
|
24
|
-
if (oldMetadata)
|
|
25
|
-
(0, putil_merge_1.default)(metadata, oldMetadata, { deep: true });
|
|
26
|
-
(0, putil_merge_1.default)(metadata, {
|
|
27
|
-
kind: index_js_1.OpraSchema.HttpController.Kind,
|
|
28
|
-
name,
|
|
29
|
-
path: name,
|
|
30
|
-
...(0, lodash_omit_1.default)(options, ['kind', 'name', 'instance', 'endpoints', 'key']),
|
|
31
|
-
}, { deep: true });
|
|
32
|
-
Reflect.defineMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, metadata, target);
|
|
33
|
-
for (const fn of decoratorChain)
|
|
34
|
-
fn(metadata);
|
|
35
|
-
Reflect.defineMetadata(constants_js_1.HTTP_CONTROLLER_METADATA, metadata, target);
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
*
|
|
39
|
-
*/
|
|
40
|
-
decorator.Cookie = (name, arg1) => {
|
|
41
|
-
decoratorChain.push((meta) => {
|
|
42
|
-
const paramMeta = typeof arg1 === 'string' || typeof arg1 === 'function'
|
|
43
|
-
? {
|
|
44
|
-
name,
|
|
45
|
-
location: 'cookie',
|
|
46
|
-
type: arg1,
|
|
47
|
-
}
|
|
48
|
-
: { ...arg1, name, location: 'cookie' };
|
|
49
|
-
meta.parameters = meta.parameters || [];
|
|
50
|
-
meta.parameters.push(paramMeta);
|
|
51
|
-
});
|
|
52
|
-
return decorator;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
decorator.Header = (name, arg1) => {
|
|
58
|
-
decoratorChain.push((meta) => {
|
|
59
|
-
const paramMeta = typeof arg1 === 'string' || typeof arg1 === 'function'
|
|
60
|
-
? {
|
|
61
|
-
name,
|
|
62
|
-
location: 'header',
|
|
63
|
-
type: arg1,
|
|
64
|
-
}
|
|
65
|
-
: { ...arg1, name, location: 'header' };
|
|
66
|
-
meta.parameters = meta.parameters || [];
|
|
67
|
-
meta.parameters.push(paramMeta);
|
|
68
|
-
});
|
|
69
|
-
return decorator;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
*
|
|
73
|
-
*/
|
|
74
|
-
decorator.QueryParam = (name, arg1) => {
|
|
75
|
-
decoratorChain.push((meta) => {
|
|
76
|
-
const paramMeta = typeof arg1 === 'string' || typeof arg1 === 'function'
|
|
77
|
-
? {
|
|
78
|
-
name,
|
|
79
|
-
location: 'query',
|
|
80
|
-
type: arg1,
|
|
81
|
-
}
|
|
82
|
-
: { ...arg1, name, location: 'query' };
|
|
83
|
-
meta.parameters = meta.parameters || [];
|
|
84
|
-
meta.parameters.push(paramMeta);
|
|
85
|
-
});
|
|
86
|
-
return decorator;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
*
|
|
90
|
-
*/
|
|
91
|
-
decorator.PathParam = (name, arg1) => {
|
|
92
|
-
decoratorChain.push((meta) => {
|
|
93
|
-
const paramMeta = typeof arg1 === 'string' || typeof arg1 === 'function'
|
|
94
|
-
? {
|
|
95
|
-
name,
|
|
96
|
-
location: 'path',
|
|
97
|
-
type: arg1,
|
|
98
|
-
}
|
|
99
|
-
: { ...arg1, name, location: 'path' };
|
|
100
|
-
meta.parameters = meta.parameters || [];
|
|
101
|
-
meta.parameters.push(paramMeta);
|
|
102
|
-
});
|
|
103
|
-
return decorator;
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
*
|
|
107
|
-
*/
|
|
108
|
-
decorator.UseType = (...type) => {
|
|
109
|
-
decoratorChain.push((meta) => {
|
|
110
|
-
meta.types = meta.types || [];
|
|
111
|
-
meta.types.push(...type);
|
|
112
|
-
});
|
|
113
|
-
return decorator;
|
|
114
|
-
};
|
|
115
|
-
return decorator;
|
|
116
|
-
}
|
|
117
|
-
exports.HttpControllerDecoratorFactory = HttpControllerDecoratorFactory;
|