@wabot-dev/framework 0.2.0 → 0.2.1-beta.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/dist/src/addon/auth/api-key/@apiKeyGuard.js +1 -0
- package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +1 -1
- package/dist/src/addon/auth/jwt/@jwtGuard.js +1 -0
- package/dist/src/addon/chat-controller/cmd/@cmd.js +0 -1
- package/dist/src/addon/chat-controller/socket/@socket.js +0 -1
- package/dist/src/addon/chat-controller/telegram/@telegram.js +0 -1
- package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +0 -1
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppSenderByCloudApi.js +0 -1
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +0 -1
- package/dist/src/addon/mindset/html/HtmlModule.js +5 -12
- package/dist/src/core/description/metadata/@description.js +21 -0
- package/dist/src/core/description/metadata/DescriptionMetadataStore.js +21 -0
- package/dist/src/core/validation/metadata/@isArray.js +1 -0
- package/dist/src/core/validation/metadata/@isModel.js +1 -0
- package/dist/src/core/validation/metadata/ValidationMetadataStore.js +1 -0
- package/dist/src/core/validation/validators/is-boolean/@isBoolean.js +1 -0
- package/dist/src/core/validation/validators/is-date/@isDate.js +1 -0
- package/dist/src/core/validation/validators/is-number/@isNumber.js +1 -0
- package/dist/src/core/validation/validators/is-record/@isRecord.js +18 -0
- package/dist/src/core/validation/validators/is-record/validateIsRecord.js +35 -0
- package/dist/src/core/validation/validators/is-string/@isString.js +1 -0
- package/dist/src/feature/chat-bot/ChatBot.js +0 -1
- package/dist/src/feature/chat-controller/runChatControllers.js +0 -1
- package/dist/src/feature/mindset/MindsetOperator.js +39 -33
- package/dist/src/feature/mindset/metadata/MindsetMetadataStore.js +62 -115
- package/dist/src/feature/mindset/metadata/mindsets/@mindset.js +2 -5
- package/dist/src/feature/mindset/metadata/modules/@mindsetModule.js +2 -4
- package/dist/src/feature/rest-controller/RestRequest.js +14 -0
- package/dist/src/feature/rest-controller/runRestControllers.js +19 -14
- package/dist/src/index.d.ts +83 -81
- package/dist/src/index.js +3 -6
- package/package.json +1 -2
- package/dist/src/feature/mindset/metadata/functions/@mindsetFunction.js +0 -21
- package/dist/src/feature/mindset/metadata/functions/decoratorNames.js +0 -3
- package/dist/src/feature/mindset/metadata/mindsets/decoratorNames.js +0 -3
- package/dist/src/feature/mindset/metadata/modules/decoratorNames.js +0 -3
- package/dist/src/feature/mindset/metadata/params/@param.js +0 -21
- package/dist/src/feature/mindset/metadata/params/decoratorNames.js +0 -4
|
@@ -6,6 +6,7 @@ import '../../../core/validation/metadata/ValidationMetadataStore.js';
|
|
|
6
6
|
import '../../../feature/express/ExpressProvider.js';
|
|
7
7
|
import 'express';
|
|
8
8
|
import 'path';
|
|
9
|
+
import '../../../feature/rest-controller/RestRequest.js';
|
|
9
10
|
import { ApiKeyGuardMiddleware } from './ApiKeyGuardMiddleware.js';
|
|
10
11
|
|
|
11
12
|
function apiKeyGuard() {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { PgCrudRepository } from '../../../feature/pg/PgCrudRepository.js';
|
|
3
3
|
import { Pool } from 'pg';
|
|
4
|
-
import { singleton } from 'tsyringe';
|
|
5
4
|
import { ApiKey } from './ApiKey.js';
|
|
6
5
|
import { CustomError } from '../../../core/error/CustomError.js';
|
|
6
|
+
import { singleton } from '../../../core/injection/index.js';
|
|
7
7
|
|
|
8
8
|
let PgApiKeyRepository = class PgApiKeyRepository extends PgCrudRepository {
|
|
9
9
|
constructor(pool) {
|
|
@@ -6,6 +6,7 @@ import '../../../core/validation/metadata/ValidationMetadataStore.js';
|
|
|
6
6
|
import '../../../feature/express/ExpressProvider.js';
|
|
7
7
|
import 'express';
|
|
8
8
|
import 'path';
|
|
9
|
+
import '../../../feature/rest-controller/RestRequest.js';
|
|
9
10
|
import { JwtGuardMiddleware } from './JwtGuardMiddleware.js';
|
|
10
11
|
|
|
11
12
|
function jwtGuard() {
|
|
@@ -5,7 +5,6 @@ import '../../../core/auth/Auth.js';
|
|
|
5
5
|
import '../../../feature/chat-bot/ChatBot.js';
|
|
6
6
|
import 'uuid';
|
|
7
7
|
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
8
|
-
import 'reflect-metadata';
|
|
9
8
|
import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
10
9
|
import '../../../feature/mindset/MindsetOperator.js';
|
|
11
10
|
import { CmdChannel } from './CmdChannel.js';
|
|
@@ -5,7 +5,6 @@ import '../../../core/auth/Auth.js';
|
|
|
5
5
|
import '../../../feature/chat-bot/ChatBot.js';
|
|
6
6
|
import 'uuid';
|
|
7
7
|
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
8
|
-
import 'reflect-metadata';
|
|
9
8
|
import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
10
9
|
import '../../../feature/mindset/MindsetOperator.js';
|
|
11
10
|
import { SocketChannel } from './SocketChannel.js';
|
|
@@ -5,7 +5,6 @@ import '../../../core/auth/Auth.js';
|
|
|
5
5
|
import '../../../feature/chat-bot/ChatBot.js';
|
|
6
6
|
import 'uuid';
|
|
7
7
|
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
8
|
-
import 'reflect-metadata';
|
|
9
8
|
import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
10
9
|
import '../../../feature/mindset/MindsetOperator.js';
|
|
11
10
|
import { TelegramChannel } from './TelegramChannel.js';
|
|
@@ -6,7 +6,6 @@ import '../../../core/auth/Auth.js';
|
|
|
6
6
|
import '../../../feature/chat-bot/ChatBot.js';
|
|
7
7
|
import 'uuid';
|
|
8
8
|
import '../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
9
|
-
import 'reflect-metadata';
|
|
10
9
|
import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
11
10
|
import '../../../feature/mindset/MindsetOperator.js';
|
|
12
11
|
import { WhatsAppChannel } from './WhatsAppChannel.js';
|
|
@@ -9,7 +9,6 @@ import '../../../../feature/chat-bot/ChatBot.js';
|
|
|
9
9
|
import { ChatRepository } from '../../../../feature/chat-bot/ChatRepository.js';
|
|
10
10
|
import 'uuid';
|
|
11
11
|
import '../../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
12
|
-
import 'reflect-metadata';
|
|
13
12
|
import '../../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
14
13
|
import '../../../../feature/mindset/MindsetOperator.js';
|
|
15
14
|
import { WhatsAppRepository } from '../WhatsAppRepository.js';
|
|
@@ -9,7 +9,6 @@ import '../../../../feature/chat-bot/metadata/ChatBotMetadataStore.js';
|
|
|
9
9
|
import '../../../../feature/chat-controller/metadata/ControllerMetadataStore.js';
|
|
10
10
|
import { ChatResolver } from '../../../../feature/chat-controller/ChatResolver.js';
|
|
11
11
|
import '../../../../core/auth/Auth.js';
|
|
12
|
-
import 'reflect-metadata';
|
|
13
12
|
import '../../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
14
13
|
import '../../../../feature/mindset/MindsetOperator.js';
|
|
15
14
|
import { WhatsAppRepository } from '../WhatsAppRepository.js';
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { __decorate, __metadata } from 'tslib';
|
|
2
|
-
import {
|
|
3
|
-
import '
|
|
2
|
+
import { description } from '../../../core/description/metadata/@description.js';
|
|
3
|
+
import '../../../core/description/metadata/DescriptionMetadataStore.js';
|
|
4
4
|
import '../../../core/injection/index.js';
|
|
5
5
|
import '../../../feature/mindset/metadata/MindsetMetadataStore.js';
|
|
6
6
|
import { mindsetModule } from '../../../feature/mindset/metadata/modules/@mindsetModule.js';
|
|
7
|
-
import { param } from '../../../feature/mindset/metadata/params/@param.js';
|
|
8
7
|
import '../../../feature/mindset/MindsetOperator.js';
|
|
9
8
|
import { convert } from 'html-to-text';
|
|
10
9
|
|
|
@@ -33,9 +32,7 @@ class KeywordsReq {
|
|
|
33
32
|
keywords = '';
|
|
34
33
|
}
|
|
35
34
|
__decorate([
|
|
36
|
-
|
|
37
|
-
description: 'Keywords separated by space',
|
|
38
|
-
}),
|
|
35
|
+
description('Keywords separated by space'),
|
|
39
36
|
__metadata("design:type", String)
|
|
40
37
|
], KeywordsReq.prototype, "keywords", void 0);
|
|
41
38
|
function HtmlModule(options) {
|
|
@@ -52,17 +49,13 @@ function HtmlModule(options) {
|
|
|
52
49
|
}
|
|
53
50
|
};
|
|
54
51
|
__decorate([
|
|
55
|
-
|
|
56
|
-
description: `Search information using keywords in the document "${options.title}". Priorize this info.`,
|
|
57
|
-
}),
|
|
52
|
+
description(`Search information using keywords in the document "${options.title}". Priorize this info.`),
|
|
58
53
|
__metadata("design:type", Function),
|
|
59
54
|
__metadata("design:paramtypes", [KeywordsReq]),
|
|
60
55
|
__metadata("design:returntype", Promise)
|
|
61
56
|
], HtmlModuleIntern.prototype, _a, null);
|
|
62
57
|
HtmlModuleIntern = __decorate([
|
|
63
|
-
mindsetModule(
|
|
64
|
-
description: `Search information using keywords in the document ${options.title}`,
|
|
65
|
-
})
|
|
58
|
+
mindsetModule()
|
|
66
59
|
], HtmlModuleIntern);
|
|
67
60
|
return HtmlModuleIntern;
|
|
68
61
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { container } from '../../injection/index.js';
|
|
2
|
+
import { DescriptionMetadataStore } from './DescriptionMetadataStore.js';
|
|
3
|
+
|
|
4
|
+
function description(description) {
|
|
5
|
+
return (target, propertyKey) => {
|
|
6
|
+
const propertyName = propertyKey.toString();
|
|
7
|
+
const propertyType = Reflect.getMetadata('design:type', target, propertyName);
|
|
8
|
+
const functionArgsTypes = Reflect.getMetadata('design:paramtypes', target, propertyName);
|
|
9
|
+
const store = container.resolve(DescriptionMetadataStore);
|
|
10
|
+
store.saveDescriptionMetadata({
|
|
11
|
+
constructor: target.constructor,
|
|
12
|
+
propertyName,
|
|
13
|
+
propertyType,
|
|
14
|
+
functionArgsTypes,
|
|
15
|
+
functionReturnType: undefined,
|
|
16
|
+
description
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { description };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { __decorate } from 'tslib';
|
|
2
|
+
import { singleton } from '../../injection/index.js';
|
|
3
|
+
|
|
4
|
+
let DescriptionMetadataStore = class DescriptionMetadataStore {
|
|
5
|
+
descriptions = new Map();
|
|
6
|
+
saveDescriptionMetadata(metadata) {
|
|
7
|
+
let ctorDescriptions = this.descriptions.get(metadata.constructor);
|
|
8
|
+
if (!ctorDescriptions) {
|
|
9
|
+
this.descriptions.set(metadata.constructor, (ctorDescriptions = []));
|
|
10
|
+
}
|
|
11
|
+
ctorDescriptions.unshift(metadata);
|
|
12
|
+
}
|
|
13
|
+
getModelDescriptions(model) {
|
|
14
|
+
return this.descriptions.get(model) ?? [];
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
DescriptionMetadataStore = __decorate([
|
|
18
|
+
singleton()
|
|
19
|
+
], DescriptionMetadataStore);
|
|
20
|
+
|
|
21
|
+
export { DescriptionMetadataStore };
|
|
@@ -58,6 +58,7 @@ let ValidationMetadataStore = class ValidationMetadataStore {
|
|
|
58
58
|
constructors.unshift(modelConstructor);
|
|
59
59
|
const modelValidators = {
|
|
60
60
|
modelConstructor: modelConstructor,
|
|
61
|
+
modelHierarchy: constructors,
|
|
61
62
|
properties: Object.assign({}, ...constructors.map((x) => this.getConstructorPropertiesValidatorsInfo(x))),
|
|
62
63
|
};
|
|
63
64
|
return modelValidators;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { container } from '../../../injection/index.js';
|
|
2
|
+
import { ValidationMetadataStore } from '../../metadata/ValidationMetadataStore.js';
|
|
3
|
+
import { validateIsRecord } from './validateIsRecord.js';
|
|
4
|
+
|
|
5
|
+
function isRecord(keyType, valueType) {
|
|
6
|
+
return function (target, propertyKey) {
|
|
7
|
+
const propertyName = propertyKey.toString();
|
|
8
|
+
const store = container.resolve(ValidationMetadataStore);
|
|
9
|
+
store.saveValidatorMetadata({
|
|
10
|
+
modelConstructor: target.constructor,
|
|
11
|
+
propertyName,
|
|
12
|
+
validator: validateIsRecord,
|
|
13
|
+
validatorOptions: { keyType, valueType },
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { isRecord };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function validateIsRecord(value, options) {
|
|
2
|
+
if (value == null) {
|
|
3
|
+
return {
|
|
4
|
+
error: { description: `null is not allowed` },
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
if (typeof value !== 'object') {
|
|
8
|
+
return {
|
|
9
|
+
error: { description: `value should be an object` },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
return {
|
|
14
|
+
error: { description: `array is not allowed` },
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
for (const key in value) {
|
|
18
|
+
if (typeof key !== options.keyType) {
|
|
19
|
+
return {
|
|
20
|
+
error: { description: `record keys should be ${options.keyType}` },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const keyValue = value[key];
|
|
24
|
+
if (typeof keyValue !== options.valueType) {
|
|
25
|
+
return {
|
|
26
|
+
error: { description: `record values should be ${options.valueType}` },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
value,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { validateIsRecord };
|
|
@@ -6,7 +6,6 @@ import { ChatMemory } from '../chat-bot/ChatMemory.js';
|
|
|
6
6
|
import { ChatRepository } from '../chat-bot/ChatRepository.js';
|
|
7
7
|
import 'uuid';
|
|
8
8
|
import { ChatBotMetadataStore } from '../chat-bot/metadata/ChatBotMetadataStore.js';
|
|
9
|
-
import 'reflect-metadata';
|
|
10
9
|
import '../mindset/metadata/MindsetMetadataStore.js';
|
|
11
10
|
import { Mindset } from '../mindset/IMindset.js';
|
|
12
11
|
import '../mindset/MindsetOperator.js';
|
|
@@ -2,6 +2,9 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import { injectable } from '../../core/injection/index.js';
|
|
3
3
|
import { Mindset } from './IMindset.js';
|
|
4
4
|
import { MindsetMetadataStore } from './metadata/MindsetMetadataStore.js';
|
|
5
|
+
import { validateModel } from '../../core/validation/core/validateModel.js';
|
|
6
|
+
import '../../core/validation/metadata/ValidationMetadataStore.js';
|
|
7
|
+
import { CustomError } from '../../core/error/CustomError.js';
|
|
5
8
|
import { Container } from '../../core/injection/Container.js';
|
|
6
9
|
|
|
7
10
|
let MindsetOperator = class MindsetOperator {
|
|
@@ -11,7 +14,7 @@ let MindsetOperator = class MindsetOperator {
|
|
|
11
14
|
constructor(mindset, container, metadataStore) {
|
|
12
15
|
this.mindset = mindset;
|
|
13
16
|
this.container = container;
|
|
14
|
-
this.metadata = metadataStore.
|
|
17
|
+
this.metadata = metadataStore.getMindsetInfo(this.mindset.constructor);
|
|
15
18
|
}
|
|
16
19
|
identity() {
|
|
17
20
|
return this.mindset.identity();
|
|
@@ -68,41 +71,36 @@ let MindsetOperator = class MindsetOperator {
|
|
|
68
71
|
}
|
|
69
72
|
tools() {
|
|
70
73
|
return this.metadata.modules
|
|
71
|
-
.map((module) => module.functions.map((fn) =>
|
|
74
|
+
.map((module) => module.functions.map((fn) => {
|
|
75
|
+
return {
|
|
76
|
+
language: module.config?.language ?? 'english',
|
|
77
|
+
name: fn.name,
|
|
78
|
+
description: fn.description,
|
|
79
|
+
parameters: fn.argsDescriptions.map((x) => ({
|
|
80
|
+
type: this.paramType(x.typeDescriptor),
|
|
81
|
+
name: x.propertyName,
|
|
82
|
+
description: this.paramDescription(x.description, x.typeDescriptor),
|
|
83
|
+
})),
|
|
84
|
+
};
|
|
85
|
+
}))
|
|
72
86
|
.flat();
|
|
73
87
|
}
|
|
74
|
-
|
|
75
|
-
const description = fn.config.description.replaceAll('#', ' ');
|
|
76
|
-
return {
|
|
77
|
-
language: module.config.language ?? 'english',
|
|
78
|
-
name: fn.name,
|
|
79
|
-
description,
|
|
80
|
-
parameters: fn.params.map((param) => this.toolParameter(param)),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
toolParameter(param) {
|
|
88
|
+
paramDescription(rawDescription, rawType) {
|
|
84
89
|
let description = `
|
|
85
90
|
### description (in your main language)
|
|
86
|
-
${
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return 'number';
|
|
91
|
-
if (param.type === String)
|
|
92
|
-
return 'string';
|
|
93
|
-
if (param.type === Date) {
|
|
94
|
-
description = `${description}
|
|
91
|
+
${rawDescription.replaceAll('#', ' ')}
|
|
92
|
+
`;
|
|
93
|
+
if (rawType === 'date') {
|
|
94
|
+
description = `${description}
|
|
95
95
|
### format: ISO 8681 - YYYY-MM-DDTHH:mm:ssZ
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
description,
|
|
105
|
-
};
|
|
96
|
+
`;
|
|
97
|
+
}
|
|
98
|
+
return description;
|
|
99
|
+
}
|
|
100
|
+
paramType(rawType) {
|
|
101
|
+
if (rawType === 'date')
|
|
102
|
+
return 'string';
|
|
103
|
+
return rawType;
|
|
106
104
|
}
|
|
107
105
|
async callFunction(name, params) {
|
|
108
106
|
const fnMetadata = this.metadata.modules
|
|
@@ -112,9 +110,17 @@ let MindsetOperator = class MindsetOperator {
|
|
|
112
110
|
if (!fnMetadata) {
|
|
113
111
|
throw new Error(`Function ${name} not found`);
|
|
114
112
|
}
|
|
115
|
-
const paramsObj = JSON.parse(params);
|
|
116
|
-
const module = this.container.resolve(fnMetadata.moduleConstructor);
|
|
117
113
|
try {
|
|
114
|
+
let paramsObj = JSON.parse(params);
|
|
115
|
+
const modelValidationInfo = fnMetadata.argsValidatorsInfo;
|
|
116
|
+
if (modelValidationInfo) {
|
|
117
|
+
const validation = validateModel(paramsObj, modelValidationInfo);
|
|
118
|
+
if (validation.error) {
|
|
119
|
+
throw new CustomError({ message: 'IA Params Are invalid', info: validation.error });
|
|
120
|
+
}
|
|
121
|
+
paramsObj = validation.value;
|
|
122
|
+
}
|
|
123
|
+
const module = this.container.resolve(fnMetadata.moduleConstructor);
|
|
118
124
|
const response = await module[name](paramsObj);
|
|
119
125
|
if (!response) {
|
|
120
126
|
return 'success';
|
|
@@ -1,134 +1,81 @@
|
|
|
1
|
-
import { __decorate } from 'tslib';
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { singleton } from '../../../core/injection/index.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { MINDSET_MODULE_DECORATION_MODULE } from './modules/decoratorNames.js';
|
|
3
|
+
import { DescriptionMetadataStore } from '../../../core/description/metadata/DescriptionMetadataStore.js';
|
|
4
|
+
import { ValidationMetadataStore } from '../../../core/validation/metadata/ValidationMetadataStore.js';
|
|
6
5
|
|
|
7
6
|
let MindsetMetadataStore = class MindsetMetadataStore {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
paramsMap = new Map();
|
|
16
|
-
this.paramsDecorations.set(paramDecoration.constructor, paramsMap);
|
|
17
|
-
}
|
|
18
|
-
let decorations = paramsMap.get(paramDecoration.paramName);
|
|
19
|
-
if (!decorations) {
|
|
20
|
-
decorations = [];
|
|
21
|
-
paramsMap.set(paramDecoration.paramName, decorations);
|
|
22
|
-
}
|
|
23
|
-
decorations.push(paramDecoration);
|
|
7
|
+
descriptionMetadataStore;
|
|
8
|
+
validationMetadataStore;
|
|
9
|
+
modules = new Map();
|
|
10
|
+
mindsets = new Map();
|
|
11
|
+
constructor(descriptionMetadataStore, validationMetadataStore) {
|
|
12
|
+
this.descriptionMetadataStore = descriptionMetadataStore;
|
|
13
|
+
this.validationMetadataStore = validationMetadataStore;
|
|
24
14
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (!functionsMap) {
|
|
28
|
-
functionsMap = new Map();
|
|
29
|
-
this.functionsDecorations.set(functionDecoration.constructor, functionsMap);
|
|
30
|
-
}
|
|
31
|
-
let decorations = functionsMap.get(functionDecoration.functionName);
|
|
32
|
-
if (!decorations) {
|
|
33
|
-
decorations = [];
|
|
34
|
-
functionsMap.set(functionDecoration.functionName, decorations);
|
|
35
|
-
}
|
|
36
|
-
decorations.push(functionDecoration);
|
|
15
|
+
saveModuleMetadata(metadata) {
|
|
16
|
+
this.modules.set(metadata.constructor, metadata);
|
|
37
17
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (!modulesDecorations) {
|
|
41
|
-
modulesDecorations = [];
|
|
42
|
-
this.modulesDecorations.set(moduleDecoration.constructor, modulesDecorations);
|
|
43
|
-
}
|
|
44
|
-
modulesDecorations.push(moduleDecoration);
|
|
45
|
-
}
|
|
46
|
-
saveMindsetDecoration(mindsetDecoration) {
|
|
47
|
-
let mindsetsDecorations = this.mindsetsDecorations.get(mindsetDecoration.constructor);
|
|
48
|
-
if (!mindsetsDecorations) {
|
|
49
|
-
mindsetsDecorations = [];
|
|
50
|
-
this.mindsetsDecorations.set(mindsetDecoration.constructor, mindsetsDecorations);
|
|
51
|
-
}
|
|
52
|
-
mindsetsDecorations.push(mindsetDecoration);
|
|
18
|
+
saveMindsetMetadata(metadata) {
|
|
19
|
+
this.mindsets.set(metadata.constructor, metadata);
|
|
53
20
|
}
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
if (!
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
const paramsMetadata = [];
|
|
60
|
-
paramsMap.forEach((decorations, paramName) => {
|
|
61
|
-
const paramMainDecoration = decorations.find((decoration) => decoration.decorationConfig);
|
|
62
|
-
if (!paramMainDecoration) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
paramsMetadata.push({
|
|
66
|
-
config: paramMainDecoration.decorationConfig,
|
|
67
|
-
name: paramName,
|
|
68
|
-
type: paramMainDecoration.paramType,
|
|
69
|
-
});
|
|
70
|
-
// TODO: add support for validation decorators
|
|
71
|
-
});
|
|
72
|
-
return paramsMetadata;
|
|
73
|
-
}
|
|
74
|
-
getFunctionsMetadata(moduleConstructor) {
|
|
75
|
-
const functionsMap = this.functionsDecorations.get(moduleConstructor);
|
|
76
|
-
if (!functionsMap) {
|
|
77
|
-
return [];
|
|
78
|
-
}
|
|
79
|
-
const functionsMetadata = [];
|
|
80
|
-
functionsMap.forEach((decorations) => {
|
|
81
|
-
const mainDecoration = decorations.find((decoration) => decoration.decorationName === MINDSET_FUNCTION_DECORATION_FUNCTION);
|
|
82
|
-
if (!mainDecoration) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
functionsMetadata.push({
|
|
86
|
-
moduleConstructor: mainDecoration.constructor,
|
|
87
|
-
config: mainDecoration.decorationConfig,
|
|
88
|
-
name: mainDecoration.functionName,
|
|
89
|
-
requestConstructor: mainDecoration.paramsTypes[0],
|
|
90
|
-
params: mainDecoration.paramsTypes[0]
|
|
91
|
-
? this.getRequestParamsMetadata(mainDecoration.paramsTypes[0])
|
|
92
|
-
: [],
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
return functionsMetadata;
|
|
96
|
-
}
|
|
97
|
-
getModuleMetadata(moduleConstructor) {
|
|
98
|
-
const decorations = this.modulesDecorations.get(moduleConstructor);
|
|
99
|
-
if (!decorations) {
|
|
100
|
-
throw new Error(`Module ${moduleConstructor.name} not found`);
|
|
101
|
-
}
|
|
102
|
-
const mainDecoration = decorations.find((decoration) => decoration.decorationName === MINDSET_MODULE_DECORATION_MODULE);
|
|
103
|
-
if (!mainDecoration) {
|
|
104
|
-
throw new Error(`Module ${moduleConstructor.name} not found`);
|
|
21
|
+
getModuleInfo(moduleCtor) {
|
|
22
|
+
const module = this.modules.get(moduleCtor);
|
|
23
|
+
if (!module) {
|
|
24
|
+
throw new Error(`not found mindsetModule info for ${moduleCtor.name}`);
|
|
105
25
|
}
|
|
26
|
+
const descriptions = this.descriptionMetadataStore.getModelDescriptions(moduleCtor);
|
|
27
|
+
const functions = descriptions.filter((x) => x.propertyType === Function);
|
|
106
28
|
return {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
29
|
+
config: module.config,
|
|
30
|
+
functions: functions.map((x) => {
|
|
31
|
+
if (x.functionArgsTypes && x.functionArgsTypes.length > 1) {
|
|
32
|
+
throw new Error(`invalid mindset function ${x.propertyName}, should have none or one object parámeter`);
|
|
33
|
+
}
|
|
34
|
+
const functionArgsModel = x.functionArgsTypes && x.functionArgsTypes.length === 1 ? x.functionArgsTypes[0] : null;
|
|
35
|
+
const argsDescriptions = (functionArgsModel &&
|
|
36
|
+
this.descriptionMetadataStore.getModelDescriptions(functionArgsModel)) ??
|
|
37
|
+
[];
|
|
38
|
+
const functionArgsModelValidatorsInfo = functionArgsModel &&
|
|
39
|
+
this.validationMetadataStore.getModelValidatorsInfo(functionArgsModel);
|
|
40
|
+
const argsValidators = functionArgsModelValidatorsInfo?.properties ?? {};
|
|
41
|
+
const argsDescriptionsWithTypes = argsDescriptions.map((argDescription) => {
|
|
42
|
+
const argValidator = argsValidators[argDescription.propertyName];
|
|
43
|
+
const typeValidator = argValidator?.validators?.find((x) => x.typeDescriptor);
|
|
44
|
+
const typeDescriptor = typeValidator?.typeDescriptor;
|
|
45
|
+
if (!typeDescriptor) {
|
|
46
|
+
throw new Error(`the property '${argDescription.constructor.name}.${argDescription.propertyName}' should have a type validator`);
|
|
47
|
+
}
|
|
48
|
+
return { ...argDescription, typeDescriptor };
|
|
49
|
+
});
|
|
50
|
+
if (argsDescriptions.length !== Object.keys(argsValidators).length) {
|
|
51
|
+
throw new Error(`the model '${moduleCtor.name}' have properties without descriptions`);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
moduleConstructor: moduleCtor,
|
|
55
|
+
function: x,
|
|
56
|
+
name: x.propertyName,
|
|
57
|
+
description: x.description,
|
|
58
|
+
argsDescriptions: argsDescriptionsWithTypes,
|
|
59
|
+
argsValidatorsInfo: functionArgsModelValidatorsInfo,
|
|
60
|
+
};
|
|
61
|
+
}),
|
|
110
62
|
};
|
|
111
63
|
}
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
if (!
|
|
115
|
-
throw new Error(`
|
|
116
|
-
}
|
|
117
|
-
const mainDecoration = decorations.find((decoration) => decoration.decorationName === MINDSET_DECORATION_MINDSET);
|
|
118
|
-
if (!mainDecoration) {
|
|
119
|
-
throw new Error(`Mindset ${ctor.name} not found`);
|
|
64
|
+
getMindsetInfo(mindsetCtor) {
|
|
65
|
+
const mindset = this.mindsets.get(mindsetCtor);
|
|
66
|
+
if (!mindset) {
|
|
67
|
+
throw new Error(`not found mindset info for ${mindsetCtor.name}`);
|
|
120
68
|
}
|
|
121
69
|
return {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
modules: mainDecoration.decorationConfig.modules
|
|
125
|
-
? mainDecoration.decorationConfig.modules.map((module) => this.getModuleMetadata(module))
|
|
126
|
-
: [],
|
|
70
|
+
config: mindset.config,
|
|
71
|
+
modules: mindset.config?.modules?.map((x) => this.getModuleInfo(x)) ?? [],
|
|
127
72
|
};
|
|
128
73
|
}
|
|
129
74
|
};
|
|
130
75
|
MindsetMetadataStore = __decorate([
|
|
131
|
-
singleton()
|
|
76
|
+
singleton(),
|
|
77
|
+
__metadata("design:paramtypes", [DescriptionMetadataStore,
|
|
78
|
+
ValidationMetadataStore])
|
|
132
79
|
], MindsetMetadataStore);
|
|
133
80
|
|
|
134
81
|
export { MindsetMetadataStore };
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
1
|
import { container, injectable } from '../../../../core/injection/index.js';
|
|
3
2
|
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
4
|
-
import { MINDSET_DECORATION_MINDSET } from './decoratorNames.js';
|
|
5
3
|
|
|
6
4
|
function mindset(config) {
|
|
7
5
|
return function (target) {
|
|
8
6
|
const store = container.resolve(MindsetMetadataStore);
|
|
9
|
-
store.
|
|
10
|
-
decorationName: MINDSET_DECORATION_MINDSET,
|
|
7
|
+
store.saveMindsetMetadata({
|
|
11
8
|
constructor: target,
|
|
12
|
-
|
|
9
|
+
config,
|
|
13
10
|
});
|
|
14
11
|
injectable()(target);
|
|
15
12
|
};
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { container, injectable } from '../../../../core/injection/index.js';
|
|
2
2
|
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
3
|
-
import { MINDSET_MODULE_DECORATION_MODULE } from './decoratorNames.js';
|
|
4
3
|
|
|
5
4
|
function mindsetModule(config) {
|
|
6
5
|
return function (target) {
|
|
7
6
|
const store = container.resolve(MindsetMetadataStore);
|
|
8
|
-
store.
|
|
9
|
-
decorationName: MINDSET_MODULE_DECORATION_MODULE,
|
|
7
|
+
store.saveModuleMetadata({
|
|
10
8
|
constructor: target,
|
|
11
|
-
|
|
9
|
+
config: config,
|
|
12
10
|
});
|
|
13
11
|
injectable()(target);
|
|
14
12
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import '../../core/injection/index.js';
|
|
3
|
+
import '../../core/validation/metadata/ValidationMetadataStore.js';
|
|
4
|
+
import { isRecord } from '../../core/validation/validators/is-record/@isRecord.js';
|
|
5
|
+
|
|
6
|
+
class RestRequest {
|
|
7
|
+
headers;
|
|
8
|
+
}
|
|
9
|
+
__decorate([
|
|
10
|
+
isRecord('string', 'string'),
|
|
11
|
+
__metadata("design:type", Object)
|
|
12
|
+
], RestRequest.prototype, "headers", void 0);
|
|
13
|
+
|
|
14
|
+
export { RestRequest };
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { CustomError } from '../../core/error/CustomError.js';
|
|
2
2
|
import { container } from '../../core/injection/index.js';
|
|
3
3
|
import { Logger } from '../../core/logger/Logger.js';
|
|
4
|
-
import '../../core/validation/
|
|
5
|
-
import {
|
|
4
|
+
import { validateModel } from '../../core/validation/core/validateModel.js';
|
|
5
|
+
import { ValidationMetadataStore } from '../../core/validation/metadata/ValidationMetadataStore.js';
|
|
6
6
|
import { ExpressProvider } from '../express/ExpressProvider.js';
|
|
7
7
|
import { json, urlencoded } from 'express';
|
|
8
8
|
import path__default from 'path';
|
|
9
9
|
import { EXPRESS_REQ, EXPRESS_RES } from './injection-tokens.js';
|
|
10
10
|
import { RestControllerMetadataStore } from './metadata/RestControllerMetadataStore.js';
|
|
11
|
+
import { RestRequest } from './RestRequest.js';
|
|
11
12
|
|
|
12
13
|
function buildRequest(req) {
|
|
13
14
|
return Object.assign({}, req.body, req.query, req.params);
|
|
@@ -16,6 +17,7 @@ function runRestControllers(controllers) {
|
|
|
16
17
|
const logger = new Logger('wabot:rest');
|
|
17
18
|
const metadataStore = container.resolve(RestControllerMetadataStore);
|
|
18
19
|
const expressProvider = container.resolve(ExpressProvider);
|
|
20
|
+
const validationMetadataStore = container.resolve(ValidationMetadataStore);
|
|
19
21
|
const expressApp = expressProvider.getExpress();
|
|
20
22
|
controllers.forEach((controller) => {
|
|
21
23
|
const endPoints = metadataStore.getControllerEndPointsInfo(controller);
|
|
@@ -43,20 +45,23 @@ function runRestControllers(controllers) {
|
|
|
43
45
|
}
|
|
44
46
|
const controllerInstance = requestContainer.resolve(endPoint.controllerConstructor);
|
|
45
47
|
const endPointArgs = [];
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
if (endPoint.paramsTypes.length > 1) {
|
|
49
|
+
throw new Error(`rest controller endpoints should have zero or one parameter only`);
|
|
50
|
+
}
|
|
51
|
+
if (endPoint.paramsTypes.length === 1) {
|
|
52
|
+
const paramType = endPoint.paramsTypes[0];
|
|
53
|
+
if (typeof paramType !== 'function') {
|
|
54
|
+
throw new Error(`invalid rest controller endpoint parameter type`);
|
|
51
55
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
const paramInfo = validationMetadataStore.getModelValidatorsInfo(paramType);
|
|
57
|
+
const validableReq = paramInfo.modelHierarchy.includes(RestRequest)
|
|
58
|
+
? req
|
|
59
|
+
: buildRequest(req);
|
|
60
|
+
const { value, error } = validateModel(validableReq, paramInfo);
|
|
61
|
+
if (error) {
|
|
62
|
+
throw new CustomError({ httpCode: 400, message: error.description, info: error });
|
|
59
63
|
}
|
|
64
|
+
endPointArgs.push(value);
|
|
60
65
|
}
|
|
61
66
|
const response = await controllerInstance[endPoint.functionName].apply(controllerInstance, endPointArgs);
|
|
62
67
|
res.status(200).json(response ?? null);
|
package/dist/src/index.d.ts
CHANGED
|
@@ -172,9 +172,11 @@ interface IPropertyValidatorInfo {
|
|
|
172
172
|
propertyName: string;
|
|
173
173
|
validator: IValidator;
|
|
174
174
|
validatorOptions?: any;
|
|
175
|
+
typeDescriptor?: string;
|
|
175
176
|
}
|
|
176
177
|
type IModelValidatorsInfo<V> = {
|
|
177
178
|
modelConstructor: IConstructor<V>;
|
|
179
|
+
modelHierarchy: IConstructor<any>[];
|
|
178
180
|
properties: {
|
|
179
181
|
[prop: string]: {
|
|
180
182
|
isOptional?: boolean;
|
|
@@ -202,6 +204,7 @@ interface IValidatorMetadata {
|
|
|
202
204
|
propertyName: string;
|
|
203
205
|
validator: IValidator;
|
|
204
206
|
validatorOptions?: any;
|
|
207
|
+
typeDescriptor?: string;
|
|
205
208
|
}
|
|
206
209
|
|
|
207
210
|
declare class ValidationMetadataStore {
|
|
@@ -265,6 +268,14 @@ interface IValidateMinOptions {
|
|
|
265
268
|
}
|
|
266
269
|
declare function validateMin(value: any, options: IValidateMinOptions): IValidationResult<any>;
|
|
267
270
|
|
|
271
|
+
declare function isRecord(keyType: 'number' | 'string', valueType: 'number' | 'string' | 'boolean'): (target: object, propertyKey: string | symbol) => void;
|
|
272
|
+
|
|
273
|
+
interface IValidateIsRecordOptions {
|
|
274
|
+
keyType: 'string' | 'number';
|
|
275
|
+
valueType: 'string' | 'number' | 'boolean';
|
|
276
|
+
}
|
|
277
|
+
declare function validateIsRecord(value: any, options: IValidateIsRecordOptions): IValidationResult<any>;
|
|
278
|
+
|
|
268
279
|
declare class Mapper {
|
|
269
280
|
map<T>(data: IValidateInputShape<T>, ctor: IConstructor<T>): T;
|
|
270
281
|
}
|
|
@@ -422,22 +433,6 @@ declare class Chat extends Entity<IChatData> {
|
|
|
422
433
|
validate(): void;
|
|
423
434
|
}
|
|
424
435
|
|
|
425
|
-
interface IMindsetFunctionConfig {
|
|
426
|
-
description: string;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
declare function mindsetFunction(config: IMindsetFunctionConfig): (target: object, propertyKey: string | symbol) => void;
|
|
430
|
-
|
|
431
|
-
declare const MINDSET_FUNCTION_DECORATION_FUNCTION = "mindsetFunction";
|
|
432
|
-
|
|
433
|
-
interface IMindsetFunctionDecoration {
|
|
434
|
-
decorationName: string;
|
|
435
|
-
functionName: string;
|
|
436
|
-
constructor: Function;
|
|
437
|
-
paramsTypes: Function[];
|
|
438
|
-
decorationConfig: any;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
436
|
interface IMindsetIdentity {
|
|
442
437
|
name: string;
|
|
443
438
|
language: string;
|
|
@@ -470,84 +465,86 @@ interface IMindsetConfig {
|
|
|
470
465
|
|
|
471
466
|
declare function mindset(config?: IMindsetConfig): (target: IConstructor<IMindset>) => void;
|
|
472
467
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
decorationName: string;
|
|
477
|
-
constructor: Function;
|
|
478
|
-
decorationConfig: IMindsetConfig;
|
|
468
|
+
interface IMindsetMetadata {
|
|
469
|
+
constructor: IConstructor<IMindset>;
|
|
470
|
+
config?: IMindsetConfig;
|
|
479
471
|
}
|
|
480
472
|
|
|
481
473
|
interface IMindsetModuleConfig {
|
|
482
|
-
description: string;
|
|
483
474
|
language?: string;
|
|
484
475
|
}
|
|
485
476
|
|
|
486
|
-
declare function mindsetModule<A>(config
|
|
487
|
-
|
|
488
|
-
declare const MINDSET_MODULE_DECORATION_MODULE = "mindsetModule";
|
|
477
|
+
declare function mindsetModule<A>(config?: IMindsetModuleConfig): (target: IConstructor<A>) => void;
|
|
489
478
|
|
|
490
|
-
interface
|
|
491
|
-
decorationName: string;
|
|
479
|
+
interface IMindsetModuleMetadata {
|
|
492
480
|
constructor: Function;
|
|
493
|
-
|
|
481
|
+
config?: IMindsetModuleConfig;
|
|
494
482
|
}
|
|
495
483
|
|
|
496
|
-
interface
|
|
497
|
-
|
|
498
|
-
|
|
484
|
+
interface IDescriptionMetadata {
|
|
485
|
+
constructor: IConstructor<any>;
|
|
486
|
+
propertyName: string;
|
|
487
|
+
propertyType?: Function;
|
|
488
|
+
functionArgsTypes?: Function[];
|
|
489
|
+
functionReturnType?: Function;
|
|
499
490
|
description: string;
|
|
500
491
|
}
|
|
501
492
|
|
|
502
|
-
declare
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
paramType: any;
|
|
507
|
-
paramName: string;
|
|
508
|
-
constructor: Function;
|
|
509
|
-
decorationConfig: any;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
declare const PARAM_DECORATION_IS_OPTIONAL = "isOptional";
|
|
513
|
-
declare const PARAM_DECORATION_PARAM = "param";
|
|
514
|
-
|
|
515
|
-
interface IMindsetFunctionParamMetadata {
|
|
516
|
-
config: IParamConfig;
|
|
517
|
-
name: string;
|
|
518
|
-
type: Function;
|
|
519
|
-
}
|
|
520
|
-
interface IMindsetFunctionMetadata {
|
|
521
|
-
moduleConstructor: Function;
|
|
522
|
-
requestConstructor?: Function;
|
|
523
|
-
name: string;
|
|
524
|
-
config: IMindsetFunctionConfig;
|
|
525
|
-
params: IMindsetFunctionParamMetadata[];
|
|
526
|
-
}
|
|
527
|
-
interface IMindsetModuleMetadata {
|
|
528
|
-
constructor: Function;
|
|
529
|
-
config: IMindsetModuleConfig;
|
|
530
|
-
functions: IMindsetFunctionMetadata[];
|
|
531
|
-
}
|
|
532
|
-
interface IMindsetMetadata {
|
|
533
|
-
constructor: IConstructor<IMindset>;
|
|
534
|
-
config: IMindsetConfig;
|
|
535
|
-
modules: IMindsetModuleMetadata[];
|
|
493
|
+
declare class DescriptionMetadataStore {
|
|
494
|
+
private descriptions;
|
|
495
|
+
saveDescriptionMetadata(metadata: IDescriptionMetadata): void;
|
|
496
|
+
getModelDescriptions(model: IConstructor<any>): IDescriptionMetadata[];
|
|
536
497
|
}
|
|
537
498
|
|
|
538
499
|
declare class MindsetMetadataStore {
|
|
539
|
-
private
|
|
540
|
-
private
|
|
541
|
-
private readonly
|
|
542
|
-
private readonly
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
500
|
+
private descriptionMetadataStore;
|
|
501
|
+
private validationMetadataStore;
|
|
502
|
+
private readonly modules;
|
|
503
|
+
private readonly mindsets;
|
|
504
|
+
constructor(descriptionMetadataStore: DescriptionMetadataStore, validationMetadataStore: ValidationMetadataStore);
|
|
505
|
+
saveModuleMetadata(metadata: IMindsetModuleMetadata): void;
|
|
506
|
+
saveMindsetMetadata(metadata: IMindsetMetadata): void;
|
|
507
|
+
getModuleInfo(moduleCtor: IConstructor<any>): {
|
|
508
|
+
config: IMindsetModuleConfig | undefined;
|
|
509
|
+
functions: {
|
|
510
|
+
moduleConstructor: IConstructor<any>;
|
|
511
|
+
function: IDescriptionMetadata;
|
|
512
|
+
name: string;
|
|
513
|
+
description: string;
|
|
514
|
+
argsDescriptions: {
|
|
515
|
+
typeDescriptor: string;
|
|
516
|
+
constructor: IConstructor<any>;
|
|
517
|
+
propertyName: string;
|
|
518
|
+
propertyType?: Function;
|
|
519
|
+
functionArgsTypes?: Function[];
|
|
520
|
+
functionReturnType?: Function;
|
|
521
|
+
description: string;
|
|
522
|
+
}[];
|
|
523
|
+
argsValidatorsInfo: IModelValidatorsInfo<unknown> | null;
|
|
524
|
+
}[];
|
|
525
|
+
};
|
|
526
|
+
getMindsetInfo(mindsetCtor: IConstructor<IMindset>): {
|
|
527
|
+
config: IMindsetConfig | undefined;
|
|
528
|
+
modules: {
|
|
529
|
+
config: IMindsetModuleConfig | undefined;
|
|
530
|
+
functions: {
|
|
531
|
+
moduleConstructor: IConstructor<any>;
|
|
532
|
+
function: IDescriptionMetadata;
|
|
533
|
+
name: string;
|
|
534
|
+
description: string;
|
|
535
|
+
argsDescriptions: {
|
|
536
|
+
typeDescriptor: string;
|
|
537
|
+
constructor: IConstructor<any>;
|
|
538
|
+
propertyName: string;
|
|
539
|
+
propertyType?: Function;
|
|
540
|
+
functionArgsTypes?: Function[];
|
|
541
|
+
functionReturnType?: Function;
|
|
542
|
+
description: string;
|
|
543
|
+
}[];
|
|
544
|
+
argsValidatorsInfo: IModelValidatorsInfo<unknown> | null;
|
|
545
|
+
}[];
|
|
546
|
+
}[];
|
|
547
|
+
};
|
|
551
548
|
}
|
|
552
549
|
|
|
553
550
|
interface IMindsetToolParameter {
|
|
@@ -555,6 +552,7 @@ interface IMindsetToolParameter {
|
|
|
555
552
|
name: string;
|
|
556
553
|
description: string;
|
|
557
554
|
}
|
|
555
|
+
|
|
558
556
|
interface IMindsetTool {
|
|
559
557
|
language: string;
|
|
560
558
|
name: string;
|
|
@@ -574,8 +572,8 @@ declare class MindsetOperator implements IMindset {
|
|
|
574
572
|
llms(): Promise<IMindsetLlm[]>;
|
|
575
573
|
systemPrompt(): Promise<string>;
|
|
576
574
|
tools(): IMindsetTool[];
|
|
577
|
-
protected
|
|
578
|
-
protected
|
|
575
|
+
protected paramDescription(rawDescription: string, rawType: string): string;
|
|
576
|
+
protected paramType(rawType: string): string;
|
|
579
577
|
callFunction(name: string, params: string): Promise<string>;
|
|
580
578
|
functionResponseToString(response: any): Promise<string>;
|
|
581
579
|
functionErrorToString(error: any): Promise<string>;
|
|
@@ -915,6 +913,10 @@ declare function runRestControllers(controllers: IConstructor<any>[]): void;
|
|
|
915
913
|
declare const EXPRESS_REQ = "EXPRESS_REQ";
|
|
916
914
|
declare const EXPRESS_RES = "EXPRESS_RES";
|
|
917
915
|
|
|
916
|
+
declare class RestRequest {
|
|
917
|
+
headers?: Record<string, string>;
|
|
918
|
+
}
|
|
919
|
+
|
|
918
920
|
declare class SocketServerProvider {
|
|
919
921
|
private httpServerProvider;
|
|
920
922
|
private socketServer;
|
|
@@ -1625,4 +1627,4 @@ declare function HtmlModule(options: IHtmlModuleOptions): {
|
|
|
1625
1627
|
new (): {};
|
|
1626
1628
|
};
|
|
1627
1629
|
|
|
1628
|
-
export { AnthropicChatAdapter, ApiKey, ApiKeyGuardMiddleware, ApiKeyHandshakeGuardMiddleware, ApiKeyRepository, Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GoogleChatAdapter, type GoogleChatAdapterV2Options, HtmlModule, HttpServerProvider, type IApiKeyData, type IApiKeyRepository, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemsReq, type IChatAdapterNextItemsRes, type IChatBot, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatItem, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEndPointConfig, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type IGenerateApiKeyReq, type IGenerateApiKeyRes, type IGetWhatsAppTemplateRequest, type IHandshakeMiddleware, type IHandshakeMiddlewareMetadata, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobEvent, type IJobEventListener, type IJobRepository, type IJwtRefreshTokenData, type IJwtRefreshTokenRepository, type ILanguageModelUsage, type IListenWhatsAppMessageRequest, type IMessageContext, type IMiddleware, type IMiddlewareMetadata, type IMindset, type
|
|
1630
|
+
export { AnthropicChatAdapter, ApiKey, ApiKeyGuardMiddleware, ApiKeyHandshakeGuardMiddleware, ApiKeyRepository, Async, Auth, Chat, ChatAdapter, ChatBot, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Command, CommandMetadataStore, Container, ControllerMetadataStore, CustomError, DeepSeekChatAdapter, EXPRESS_REQ, EXPRESS_RES, Entity, Env, EnvWhatsAppRepository, ExpressProvider, GoogleChatAdapter, type GoogleChatAdapterV2Options, HtmlModule, HttpServerProvider, type IApiKeyData, type IApiKeyRepository, type IArrayValidationError, type IArrayValidationResult, type IBotMessageItem, type IChannelMessage, type IChannelMetadata, type IChatAdapter, type IChatAdapterNextItemsReq, type IChatAdapterNextItemsRes, type IChatBot, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatItem, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type ICommandConfig, type ICommandHandler, type ICommandHandlerConfig, type IConstructor, type ICrudRepository, type ICustomErrorData, type IEndPointConfig, type IEndPointMetadata, type IEntityData, type IEnvType, type IFunctionCall, type IFunctionCallItem, type IGenerateApiKeyReq, type IGenerateApiKeyRes, type IGetWhatsAppTemplateRequest, type IHandshakeMiddleware, type IHandshakeMiddlewareMetadata, type IHtmlModuleOptions, type IHumanMessageItem, type IJobData, type IJobEvent, type IJobEventListener, type IJobRepository, type IJwtRefreshTokenData, type IJwtRefreshTokenRepository, type ILanguageModelUsage, type IListenWhatsAppMessageRequest, type IMessageContext, type IMiddleware, type IMiddlewareMetadata, type IMindset, type IMindsetConfig, type IMindsetIdentity, type IMindsetLlm, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleMetadata, type IMindsetTool, type IMindsetToolParameter, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IMoneyData, type IPersistentData, type IPgRepositoryConfig, type IPrimitive, type IPropertyValidatorInfo, type IReceivedMessage, type IRemoteApiKeyFetcher, type IRestControllerConfig, type IRestControllerMetadata, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type ISocketControllerConfig, type ISocketControllerMetadata, type ISocketEventConfig, type ISocketEventMetadata, type IStorableData, type ITelegramChannelConfig, type IValidateArrayOptions, type IValidateArrayOptionsWithItemsValidators, type IValidateInputShape, type IValidateIsInOptions, type IValidateIsRecordOptions, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppCloudContact, type IWhatsAppCloudMessage, type IWhatsAppCloudMessageMetadata, type IWhatsAppCloudTemplate, type IWhatsAppCloudTemplateComponent, type IWhatsAppCloudTemplateMessage, type IWhatsAppCloudTemplateParameter, type IWhatsAppCloudTemplateResponse, type IWhatsAppCloudWebhookPayload, type IWhatsAppData, type IWhatsAppMessageListener, type IWhatsAppProxyListenMessageEventData, type IWhatsAppProxyListenMessageEventReq, type IWhatsAppProxyMessage, type IWhatsAppProxyMessageContent, type IWhatsAppProxyMessageEventReq, type IWhatsAppProxySendMessageEventReq, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsappChannelConfig, type IchatControllerConfig, Job, JobRepository, JobRunner, JobsEventsHub, Jwt, JwtAccessAndRefreshTokenDto, JwtConfig, JwtGuardMiddleware, JwtHandshakeGuardMiddleware, JwtRefreshToken, JwtRefreshTokenRepository, JwtSigner, JwtTokenDto, Lifecycle, Logger, Mapper, Mindset, MindsetMetadataStore, MindsetOperator, Money, MoneyDto, OpenaiChatAdapter, Password, type PasswordHashOptions, Persistent, PgApiKeyRepository, PgChatMemory, PgChatRepository, PgCrudRepository, PgJobRepository, PgJwtRefreshTokenRepository, PgRepositoryBase, PgWhatsAppRepository, RamChatMemory, RamChatRepository, Random, RemoteApiKeyRepository, RestControllerMetadataStore, RestRequest, SocketChannel, SocketChannelConfig, SocketChannelReceivedMessage, SocketControllerMetadataStore, SocketServerProvider, Storable, TelegramChannel, TelegramChannelConfig, ValidationMetadataStore, WHATSAPP_MESSAGE_EVENT, WHATSAPP_PROXY_LISTEN_MESSAGE_EVENT, WHATSAPP_PROXY_SEND_MESSAGE_EVENT, WabotChatAdapter, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByCloudApi, WhatsAppReceiverByWabotProxy, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByWabotProxy, WhatsAppWabotProxyConnection, WhatsappChannelConfig, apiKeyGuard, apiKeyHandshakeGuard, chatBot, chatController, chatItemTypeOptions, cmd, command, commandHandler, container, handshakeMiddlewares, inject, injectable, isArray, isBoolean, isDate, isIn, isModel, isNotEmpty, isNumber, isOptional, isPresent, isRecord, isString, jwtGuard, jwtHandshakeGuard, max, middleware, min, mindset, mindsetModule, modelInfo, onDelete, onGet, onPost, onPut, onSocketEvent, readJsonFromFile, restController, runAsyncCommandHandlers, runChatControllers, runRestControllers, runSocketControllers, scoped, singleton, socket, socketController, telegram, validateAndTransform, validateArray, validateIsBoolean, validateIsDate, validateIsIn, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsRecord, validateIsString, validateMax, validateMin, validateModel, whatsApp, writeJsonToFile };
|
package/dist/src/index.js
CHANGED
|
@@ -34,6 +34,8 @@ export { max } from './core/validation/validators/max/@max.js';
|
|
|
34
34
|
export { validateMax } from './core/validation/validators/max/validateMax.js';
|
|
35
35
|
export { min } from './core/validation/validators/min/@min.js';
|
|
36
36
|
export { validateMin } from './core/validation/validators/min/validateMin.js';
|
|
37
|
+
export { isRecord } from './core/validation/validators/is-record/@isRecord.js';
|
|
38
|
+
export { validateIsRecord } from './core/validation/validators/is-record/validateIsRecord.js';
|
|
37
39
|
export { command } from './feature/async/@command.js';
|
|
38
40
|
export { commandHandler } from './feature/async/@commandHandler.js';
|
|
39
41
|
export { Async } from './feature/async/Async.js';
|
|
@@ -59,14 +61,8 @@ export { ChatResolver } from './feature/chat-controller/ChatResolver.js';
|
|
|
59
61
|
export { runChatControllers } from './feature/chat-controller/runChatControllers.js';
|
|
60
62
|
export { ExpressProvider } from './feature/express/ExpressProvider.js';
|
|
61
63
|
export { HttpServerProvider } from './feature/http/HttpServerProvider.js';
|
|
62
|
-
export { mindsetFunction } from './feature/mindset/metadata/functions/@mindsetFunction.js';
|
|
63
|
-
export { MINDSET_FUNCTION_DECORATION_FUNCTION } from './feature/mindset/metadata/functions/decoratorNames.js';
|
|
64
64
|
export { mindset } from './feature/mindset/metadata/mindsets/@mindset.js';
|
|
65
|
-
export { MINDSET_DECORATION_MINDSET } from './feature/mindset/metadata/mindsets/decoratorNames.js';
|
|
66
65
|
export { mindsetModule } from './feature/mindset/metadata/modules/@mindsetModule.js';
|
|
67
|
-
export { MINDSET_MODULE_DECORATION_MODULE } from './feature/mindset/metadata/modules/decoratorNames.js';
|
|
68
|
-
export { param } from './feature/mindset/metadata/params/@param.js';
|
|
69
|
-
export { PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM } from './feature/mindset/metadata/params/decoratorNames.js';
|
|
70
66
|
export { MindsetMetadataStore } from './feature/mindset/metadata/MindsetMetadataStore.js';
|
|
71
67
|
export { Mindset } from './feature/mindset/IMindset.js';
|
|
72
68
|
export { MindsetOperator } from './feature/mindset/MindsetOperator.js';
|
|
@@ -83,6 +79,7 @@ export { restController } from './feature/rest-controller/metadata/@restControll
|
|
|
83
79
|
export { RestControllerMetadataStore } from './feature/rest-controller/metadata/RestControllerMetadataStore.js';
|
|
84
80
|
export { runRestControllers } from './feature/rest-controller/runRestControllers.js';
|
|
85
81
|
export { EXPRESS_REQ, EXPRESS_RES } from './feature/rest-controller/injection-tokens.js';
|
|
82
|
+
export { RestRequest } from './feature/rest-controller/RestRequest.js';
|
|
86
83
|
export { SocketServerProvider } from './feature/socket/SocketServerProvider.js';
|
|
87
84
|
export { handshakeMiddlewares } from './feature/socket-controller/metadata/@handshakeMiddlewares.js';
|
|
88
85
|
export { socketController } from './feature/socket-controller/metadata/@socketController.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wabot-dev/framework",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1-beta.2",
|
|
4
4
|
"description": "Framework for IA Chat Bots",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"@rollup/plugin-typescript": "12.1.2",
|
|
27
27
|
"@yucacodes/ts": "^0.0.4",
|
|
28
28
|
"prettier": "^3.5.3",
|
|
29
|
-
"resend": "^4.4.1",
|
|
30
29
|
"rollup": "4.39.0",
|
|
31
30
|
"tsup": "^8.4.0",
|
|
32
31
|
"typescript": "5.8.3"
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { container } from '../../../../core/injection/index.js';
|
|
3
|
-
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
4
|
-
import { MINDSET_FUNCTION_DECORATION_FUNCTION } from './decoratorNames.js';
|
|
5
|
-
|
|
6
|
-
function mindsetFunction(config) {
|
|
7
|
-
return function (target, propertyKey) {
|
|
8
|
-
const functionName = propertyKey.toString();
|
|
9
|
-
const paramsTypes = Reflect.getMetadata('design:paramtypes', target, functionName);
|
|
10
|
-
const store = container.resolve(MindsetMetadataStore);
|
|
11
|
-
store.saveFunctionDecoration({
|
|
12
|
-
decorationName: MINDSET_FUNCTION_DECORATION_FUNCTION,
|
|
13
|
-
paramsTypes: paramsTypes,
|
|
14
|
-
functionName,
|
|
15
|
-
constructor: target.constructor,
|
|
16
|
-
decorationConfig: config,
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { mindsetFunction };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { MindsetMetadataStore } from '../MindsetMetadataStore.js';
|
|
3
|
-
import { container } from '../../../../core/injection/index.js';
|
|
4
|
-
import { PARAM_DECORATION_PARAM } from './decoratorNames.js';
|
|
5
|
-
|
|
6
|
-
function param(config) {
|
|
7
|
-
return (target, propertyKey) => {
|
|
8
|
-
const paramName = propertyKey.toString();
|
|
9
|
-
const paramType = Reflect.getMetadata('design:type', target, paramName);
|
|
10
|
-
const store = container.resolve(MindsetMetadataStore);
|
|
11
|
-
store.saveParamDecoration({
|
|
12
|
-
decorationName: PARAM_DECORATION_PARAM,
|
|
13
|
-
paramType: paramType,
|
|
14
|
-
paramName: paramName,
|
|
15
|
-
constructor: target.constructor,
|
|
16
|
-
decorationConfig: config,
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { param };
|