@apex-pub/convector-core-controller 1.4.1-2.0 → 1.4.1-4-alpha.6064f94c
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/dist/src/controller.decorator.js +8 -12
- package/dist/src/controller.decorator.js.map +1 -1
- package/dist/src/convector-controller.js +1 -5
- package/dist/src/convector-controller.js.map +1 -1
- package/dist/src/index.js +5 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/invokable.decorator.js +69 -71
- package/dist/src/invokable.decorator.js.map +1 -1
- package/dist/src/optional.decorator.js +7 -11
- package/dist/src/optional.decorator.js.map +1 -1
- package/dist/src/param.decorator.js +9 -13
- package/dist/src/param.decorator.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.controllerMetadataKey = g.ConvectorControllerMetadataKey || Symbol('controller');
|
|
8
|
-
g.ConvectorControllerMetadataKey = exports.controllerMetadataKey;
|
|
9
|
-
function Controller(namespace) {
|
|
1
|
+
import * as g from 'window-or-global';
|
|
2
|
+
import { ControllerInvalidError } from '@apex-pub/convector-core-errors';
|
|
3
|
+
import 'reflect-metadata';
|
|
4
|
+
export const controllerMetadataKey = g.ConvectorControllerMetadataKey || Symbol('controller');
|
|
5
|
+
g.ConvectorControllerMetadataKey = controllerMetadataKey;
|
|
6
|
+
export function Controller(namespace) {
|
|
10
7
|
return ctor => {
|
|
11
8
|
if (typeof ctor !== 'function') {
|
|
12
|
-
throw new
|
|
9
|
+
throw new ControllerInvalidError(namespace);
|
|
13
10
|
}
|
|
14
|
-
Reflect.defineMetadata(
|
|
11
|
+
Reflect.defineMetadata(controllerMetadataKey, namespace, ctor);
|
|
15
12
|
};
|
|
16
13
|
}
|
|
17
|
-
exports.Controller = Controller;
|
|
18
14
|
//# sourceMappingURL=controller.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.decorator.js","sourceRoot":"","sources":["../../src/controller.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"controller.decorator.js","sourceRoot":"","sources":["../../src/controller.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,kBAAkB,CAAC;AAG1B,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,8BAA8B,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC;AAC9F,CAAC,CAAC,8BAA8B,GAAG,qBAAqB,CAAC;AAWzD,MAAM,UAAU,UAAU,CAAC,SAAiB;IAC1C,OAAO,IAAI,CAAC,EAAE;QACZ,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;YAC9B,MAAM,IAAI,sBAAsB,CAAC,SAAS,CAAC,CAAC;SAC7C;QAED,OAAO,CAAC,cAAc,CAAC,qBAAqB,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACjE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConvectorController = void 0;
|
|
4
|
-
class ConvectorController {
|
|
1
|
+
export class ConvectorController {
|
|
5
2
|
}
|
|
6
|
-
exports.ConvectorController = ConvectorController;
|
|
7
3
|
//# sourceMappingURL=convector-controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convector-controller.js","sourceRoot":"","sources":["../../src/convector-controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"convector-controller.js","sourceRoot":"","sources":["../../src/convector-controller.ts"],"names":[],"mappings":"AAGA,MAAM,OAAgB,mBAAmB;CAYxC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
tslib_1.__exportStar(require("./optional.decorator"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./controller.decorator"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./convector-controller"), exports);
|
|
1
|
+
export * from './param.decorator';
|
|
2
|
+
export * from './invokable.decorator';
|
|
3
|
+
export * from './optional.decorator';
|
|
4
|
+
export * from './controller.decorator';
|
|
5
|
+
export * from './convector-controller';
|
|
9
6
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAQA,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC"}
|
|
@@ -1,108 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const controller_decorator_1 = require("./controller.decorator");
|
|
11
|
-
exports.invokableMetadataKey = g.ConvectorInvokableMetadataKey || Symbol('invokable');
|
|
12
|
-
g.ConvectorInvokableMetadataKey = exports.invokableMetadataKey;
|
|
13
|
-
function Invokable() {
|
|
1
|
+
import * as g from 'window-or-global';
|
|
2
|
+
import { ControllerNamespaceMissingError, ControllerInvokablesMissingError, ControllerInvalidInvokeError, ControllerInvalidArgumentError, ControllerArgumentParseError, ControllerInvalidFunctionError, ControllerUndefinedArgumentError } from '@apex-pub/convector-core-errors';
|
|
3
|
+
import 'reflect-metadata';
|
|
4
|
+
import { paramMetadataKey } from './param.decorator';
|
|
5
|
+
import { optionalMetadataKey } from './optional.decorator';
|
|
6
|
+
import { controllerMetadataKey } from './controller.decorator';
|
|
7
|
+
export const invokableMetadataKey = g.ConvectorInvokableMetadataKey || Symbol('invokable');
|
|
8
|
+
g.ConvectorInvokableMetadataKey = invokableMetadataKey;
|
|
9
|
+
export function Invokable() {
|
|
14
10
|
return (target, key, descriptor) => {
|
|
15
11
|
const fn = descriptor.value;
|
|
16
12
|
if (typeof fn !== 'function') {
|
|
17
|
-
throw new
|
|
13
|
+
throw new ControllerInvalidFunctionError();
|
|
18
14
|
}
|
|
19
|
-
const invokables = Reflect.getMetadata(
|
|
20
|
-
Reflect.defineMetadata(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
const invokables = Reflect.getMetadata(invokableMetadataKey, target.constructor) || {};
|
|
16
|
+
Reflect.defineMetadata(invokableMetadataKey, {
|
|
17
|
+
...invokables,
|
|
18
|
+
[key]: true
|
|
19
|
+
}, target.constructor);
|
|
20
|
+
descriptor.value = async function internalFn(_, args, extras, ...rest) {
|
|
21
|
+
let internalCall = false;
|
|
22
|
+
if ('_internal_invokable' in this) {
|
|
23
|
+
args = [_, args, extras, ...rest].filter(param => param !== undefined);
|
|
24
|
+
internalCall = true;
|
|
25
|
+
extras = {};
|
|
26
|
+
}
|
|
27
|
+
const schemas = Reflect.getOwnMetadata(paramMetadataKey, target, key);
|
|
28
|
+
if (schemas) {
|
|
29
|
+
const optionals = Reflect.getOwnMetadata(optionalMetadataKey, target, key) || [];
|
|
30
|
+
if (schemas.length - optionals.length > args.length) {
|
|
31
|
+
throw new ControllerInvalidInvokeError(key, args.length, schemas.length - optionals.length);
|
|
28
32
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
args = await schemas.reduce(async (result, [schema, opts, model], index) => {
|
|
34
|
+
let paramResult;
|
|
35
|
+
if (args[index] === undefined) {
|
|
36
|
+
if (optionals.indexOf(index) === -1) {
|
|
37
|
+
throw new ControllerUndefinedArgumentError(index);
|
|
38
|
+
}
|
|
39
|
+
return [...await result, undefined];
|
|
34
40
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return [...yield result, undefined];
|
|
41
|
+
try {
|
|
42
|
+
if (opts.update) {
|
|
43
|
+
paramResult = schema.cast(args[index], opts);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
paramResult = await schema.validate(args[index], opts);
|
|
42
47
|
}
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
throw new ControllerInvalidArgumentError(e, index, args[index]);
|
|
51
|
+
}
|
|
52
|
+
if (model) {
|
|
43
53
|
try {
|
|
44
|
-
|
|
45
|
-
paramResult = schema.cast(args[index], opts);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
paramResult = yield schema.validate(args[index], opts);
|
|
49
|
-
}
|
|
54
|
+
paramResult = new model(JSON.parse(args[index]));
|
|
50
55
|
}
|
|
51
56
|
catch (e) {
|
|
52
|
-
throw new
|
|
53
|
-
}
|
|
54
|
-
if (model) {
|
|
55
|
-
try {
|
|
56
|
-
paramResult = new model(JSON.parse(args[index]));
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
throw new convector_core_errors_1.ControllerArgumentParseError(e, index, args[index]);
|
|
60
|
-
}
|
|
57
|
+
throw new ControllerArgumentParseError(e, index, args[index]);
|
|
61
58
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
const error = new Error(e.message);
|
|
73
|
-
error.stack = e.stack;
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
59
|
+
}
|
|
60
|
+
return [...await result, paramResult];
|
|
61
|
+
}, Promise.resolve([]));
|
|
62
|
+
}
|
|
63
|
+
const namespace = Reflect.getMetadata(controllerMetadataKey, target.constructor);
|
|
64
|
+
const ctx = Object.create(internalCall ? this : this[namespace], {
|
|
65
|
+
...(extras || {}),
|
|
66
|
+
_internal_invokable: { value: true }
|
|
76
67
|
});
|
|
68
|
+
try {
|
|
69
|
+
const response = await fn.call(ctx, ...args);
|
|
70
|
+
return typeof response === 'object' ? JSON.parse(JSON.stringify(response)) : response;
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
const error = new Error(e.message);
|
|
74
|
+
error.stack = e.stack;
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
77
|
};
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
function getInvokables(controller) {
|
|
80
|
+
export function getInvokables(controller) {
|
|
82
81
|
let namespace;
|
|
83
82
|
let invokables;
|
|
84
83
|
try {
|
|
85
|
-
namespace = Reflect.getMetadata(
|
|
84
|
+
namespace = Reflect.getMetadata(controllerMetadataKey, controller);
|
|
86
85
|
if (!namespace) {
|
|
87
86
|
throw new TypeError();
|
|
88
87
|
}
|
|
89
88
|
}
|
|
90
89
|
catch (e) {
|
|
91
|
-
throw new
|
|
90
|
+
throw new ControllerNamespaceMissingError(e, controller.name);
|
|
92
91
|
}
|
|
93
92
|
try {
|
|
94
|
-
invokables = Reflect.getMetadata(
|
|
93
|
+
invokables = Reflect.getMetadata(invokableMetadataKey, controller);
|
|
95
94
|
if (!invokables) {
|
|
96
95
|
throw new TypeError();
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
catch (e) {
|
|
100
|
-
throw new
|
|
99
|
+
throw new ControllerInvokablesMissingError(e, namespace);
|
|
101
100
|
}
|
|
102
101
|
return {
|
|
103
102
|
invokables,
|
|
104
103
|
namespace
|
|
105
104
|
};
|
|
106
105
|
}
|
|
107
|
-
exports.getInvokables = getInvokables;
|
|
108
106
|
//# sourceMappingURL=invokable.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invokable.decorator.js","sourceRoot":"","sources":["../../src/invokable.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"invokable.decorator.js","sourceRoot":"","sources":["../../src/invokable.decorator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,EACL,+BAA+B,EAC/B,gCAAgC,EAChC,4BAA4B,EAC5B,8BAA8B,EAC9B,4BAA4B,EAC5B,8BAA8B,EAC9B,gCAAgC,EACjC,MAAM,iCAAiC,CAAC;AACzC,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAG/D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,6BAA6B,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC;AAC3F,CAAC,CAAC,6BAA6B,GAAG,oBAAoB,CAAC;AAavD,MAAM,UAAU,SAAS;IACvB,OAAO,CACL,MAAW,EACX,GAAW,EACX,UAAqE,EACrE,EAAE;QACF,MAAM,EAAE,GAAG,UAAU,CAAC,KAAM,CAAC;QAE7B,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE;YAC5B,MAAM,IAAI,8BAA8B,EAAE,CAAC;SAC5C;QAED,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,oBAAoB,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QACvF,OAAO,CAAC,cAAc,CAAC,oBAAoB,EAAE;YAC3C,GAAG,UAAU;YACb,CAAC,GAAG,CAAC,EAAE,IAAI;SACZ,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QAGvB,UAAU,CAAC,KAAK,GAAG,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ParamMetadataKey = exports.optionalMetadataKey;
|
|
8
|
-
function OptionalParam() {
|
|
1
|
+
import * as g from 'window-or-global';
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
export const optionalMetadataKey = g.ConvectorOptionalParamMetadataKey || Symbol('optional-param');
|
|
4
|
+
g.ConvectorOptionalParamMetadataKey = optionalMetadataKey;
|
|
5
|
+
export function OptionalParam() {
|
|
9
6
|
return (target, propertyKey, parameterIndex) => {
|
|
10
|
-
const optionals = Reflect.getOwnMetadata(
|
|
7
|
+
const optionals = Reflect.getOwnMetadata(optionalMetadataKey, target, propertyKey) || [];
|
|
11
8
|
optionals.push(parameterIndex);
|
|
12
|
-
Reflect.defineMetadata(
|
|
9
|
+
Reflect.defineMetadata(optionalMetadataKey, optionals, target, propertyKey);
|
|
13
10
|
};
|
|
14
11
|
}
|
|
15
|
-
exports.OptionalParam = OptionalParam;
|
|
16
12
|
//# sourceMappingURL=optional.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optional.decorator.js","sourceRoot":"","sources":["../../src/optional.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"optional.decorator.js","sourceRoot":"","sources":["../../src/optional.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,kBAAkB,CAAC;AAG1B,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,iCAAiC,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACnG,CAAC,CAAC,iCAAiC,GAAG,mBAAmB,CAAC;AAO1D,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,cAAsB,EAAE,EAAE;QAElE,MAAM,SAAS,GACb,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;QAEzE,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC/B,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAC9E,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const g = require("window-or-global");
|
|
5
|
-
const yup_1 = require("yup");
|
|
6
|
-
require("reflect-metadata");
|
|
1
|
+
import * as g from 'window-or-global';
|
|
2
|
+
import { object } from 'yup';
|
|
3
|
+
import 'reflect-metadata';
|
|
7
4
|
const isSchema = (schema) => 'validate' in schema;
|
|
8
|
-
|
|
9
|
-
g.ConvectorParamMetadataKey =
|
|
10
|
-
function Param(model, opts = { context: {} }) {
|
|
5
|
+
export const paramMetadataKey = g.ConvectorParamMetadataKey || Symbol('param');
|
|
6
|
+
g.ConvectorParamMetadataKey = paramMetadataKey;
|
|
7
|
+
export function Param(model, opts = { context: {} }) {
|
|
11
8
|
return (target, propertyKey, parameterIndex) => {
|
|
12
|
-
const schemas = Reflect.getOwnMetadata(
|
|
13
|
-
const schema = isSchema(model) ? model :
|
|
9
|
+
const schemas = Reflect.getOwnMetadata(paramMetadataKey, target, propertyKey) || [];
|
|
10
|
+
const schema = isSchema(model) ? model : object()
|
|
14
11
|
.transform(value => value instanceof model ? value : new model(value));
|
|
15
12
|
schemas[parameterIndex] = [schema, opts, !isSchema(model) && model];
|
|
16
|
-
Reflect.defineMetadata(
|
|
13
|
+
Reflect.defineMetadata(paramMetadataKey, schemas, target, propertyKey);
|
|
17
14
|
};
|
|
18
15
|
}
|
|
19
|
-
exports.Param = Param;
|
|
20
16
|
//# sourceMappingURL=param.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"param.decorator.js","sourceRoot":"","sources":["../../src/param.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"param.decorator.js","sourceRoot":"","sources":["../../src/param.decorator.ts"],"names":[],"mappings":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alpha.6064f94c",
|
|
4
4
|
"description": "Convector Controller base class",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"reflect-metadata": ">=0.1.12"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@apex-pub/convector-core-errors": "
|
|
54
|
-
"@apex-pub/convector-core-model": "
|
|
53
|
+
"@apex-pub/convector-core-errors": "1.4.1-4-alpha.6064f94c",
|
|
54
|
+
"@apex-pub/convector-core-model": "1.4.1-4-alpha.6064f94c",
|
|
55
55
|
"window-or-global": "^1.0.1",
|
|
56
56
|
"yup": "^0.26.10"
|
|
57
57
|
},
|