@puca/puca-core 11.0.4 → 11.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@puca/puca-core",
3
- "version": "11.0.4",
3
+ "version": "11.1.0",
4
4
  "description": "",
5
5
  "author": "Raphael Aguiar",
6
6
  "license": "UNLICENSED",
@@ -25,6 +25,7 @@
25
25
  "@sentry/node": "^7.49.0",
26
26
  "@socket.io/redis-adapter": "^7.0.0",
27
27
  "@types/amqplib": "^0.10.5",
28
+ "@types/moment": "^2.13.0",
28
29
  "amqplib": "^0.10.4",
29
30
  "aws-sdk": "^2.991.0",
30
31
  "axios": "^0.22.0",
@@ -38,6 +39,7 @@
38
39
  "node-dir": "^0.1.17",
39
40
  "node-sql-parser": "4.18.0",
40
41
  "pg-escape": "0.2.0",
42
+ "queue": "^6.0.0",
41
43
  "redis": "^3.1.2",
42
44
  "reflect-metadata": "0.1.13",
43
45
  "rimraf": "3.0.0",
@@ -1,24 +0,0 @@
1
- import { FileSystemService } from '../../../../../plugins/file-system/file-system.service';
2
- import { UuidService } from '../../../../../plugins/uuid/uuid.service';
3
- import { ComunicationService } from '../../../comunication/comunication.service';
4
- import { StorageServiceManager } from '../../../storage/storage.service';
5
- import { ApplicationInterface, ApplicationServiceExec, Request as ParentRequest } from '../../application.interface';
6
- export interface Response<Req extends ParentRequest, Res> {
7
- messageFromParentId: string;
8
- type: "response";
9
- request: Req;
10
- response: Res;
11
- }
12
- export interface Request extends ParentRequest {
13
- }
14
- export declare class ApplicationService implements ApplicationInterface<Request> {
15
- private readonly javascriptV1Path;
16
- private readonly fileSystemService;
17
- private readonly comunicationService;
18
- private readonly uuidService;
19
- private readonly storageServiceManager;
20
- constructor(javascriptV1Path: string, fileSystemService: FileSystemService, comunicationService: ComunicationService, uuidService: UuidService, storageServiceManager: StorageServiceManager);
21
- getEngine(): string;
22
- getVersion(): string;
23
- exec<U>(args: ApplicationServiceExec<Request>): Promise<U>;
24
- }
@@ -1,142 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApplicationService = void 0;
4
- const _ = require("lodash");
5
- const child_process_1 = require("child_process");
6
- const logger_1 = require("../../../logger");
7
- class Application {
8
- constructor({ debugPort, cwd, javascriptV1Path }) {
9
- this.logger = new logger_1.Logger('Application');
10
- const execArgv = debugPort ? [`--inspect=localhost:${debugPort}`] : [];
11
- this.childProcess = child_process_1.fork(javascriptV1Path, {
12
- execArgv,
13
- cwd,
14
- env: {
15
- NODE_PATH: cwd
16
- },
17
- silent: true,
18
- });
19
- this.childProcess.stdout.on('data', (data) => {
20
- this.logger.log(data.toString());
21
- });
22
- const exit = (code) => {
23
- if (code === 12) {
24
- this.logger.error('Favor definir a porta de DEBUG em ENVS');
25
- }
26
- else if (code) {
27
- this.logger.error(`Child Closed (${code})`);
28
- }
29
- };
30
- this.childProcess.on('close', exit);
31
- this.childProcess.on('exit', exit);
32
- const error = (err) => {
33
- this.logger.error(err.toString());
34
- };
35
- this.childProcess.on('error', error);
36
- this.childProcess.stderr.on('data', (data) => {
37
- const str = data.toString();
38
- if (str.startsWith('Debugger')) {
39
- this.logger.log(str);
40
- }
41
- else {
42
- error(new Error(str));
43
- }
44
- });
45
- }
46
- onMessage(callback) {
47
- this.childProcess.on('message', callback);
48
- }
49
- onError(callback) {
50
- this.childProcess.on('error', callback);
51
- }
52
- send(message) {
53
- this.childProcess.send(message);
54
- }
55
- async close() {
56
- this.childProcess.removeAllListeners();
57
- this.childProcess.kill('SIGINT');
58
- setTimeout(() => {
59
- this.childProcess.kill('SIGKILL');
60
- }, 10000);
61
- }
62
- }
63
- class ApplicationService {
64
- constructor(javascriptV1Path, fileSystemService, comunicationService, uuidService, storageServiceManager) {
65
- this.javascriptV1Path = javascriptV1Path;
66
- this.fileSystemService = fileSystemService;
67
- this.comunicationService = comunicationService;
68
- this.uuidService = uuidService;
69
- this.storageServiceManager = storageServiceManager;
70
- }
71
- getEngine() {
72
- return 'javascript';
73
- }
74
- getVersion() {
75
- return 'v1';
76
- }
77
- async exec(args) {
78
- const storageService = await this.storageServiceManager.getInstance();
79
- const files = await storageService.readFolder({
80
- root: args.root + '/index.js'
81
- });
82
- if (_.isEmpty(files)) {
83
- throw new Error('Source not found (2)');
84
- }
85
- return await new Promise(async (resolve, reject) => {
86
- const baseFolder = `${process.cwd()}/sources/v1`;
87
- for (let i = 0; i < files.length; i++) {
88
- const file = files[i];
89
- const path = file.folder ? `${file.folder}/${file.name}` : file.name;
90
- await this.fileSystemService.writeBufferFile(`${baseFolder}/${path}`, Buffer.from(file.content));
91
- }
92
- const fileIndex = `${baseFolder}/${args.root}`;
93
- const application = new Application({
94
- cwd: baseFolder,
95
- javascriptV1Path: this.javascriptV1Path,
96
- });
97
- try {
98
- application.onMessage(async (message) => {
99
- switch (message.type) {
100
- case "response":
101
- args.request = message.request;
102
- resolve(message.response);
103
- application.close();
104
- break;
105
- case "responseError":
106
- args.request = message.request;
107
- reject(message.response);
108
- application.close();
109
- break;
110
- case "comunicationServiceCall":
111
- const response = await this.comunicationService.call({
112
- user: args.user,
113
- moduleName: message.moduleName,
114
- path: message.path,
115
- body: message.body,
116
- headers: message.headers,
117
- });
118
- application.send({
119
- messageFromChildId: message.id,
120
- type: "comunicationServiceCallResponse",
121
- data: response
122
- });
123
- break;
124
- }
125
- });
126
- application.send({
127
- type: "request",
128
- id: this.uuidService.v4(),
129
- request: args.request,
130
- user: args.user,
131
- path: fileIndex
132
- });
133
- }
134
- catch (e) {
135
- reject(e);
136
- application.close();
137
- }
138
- });
139
- }
140
- }
141
- exports.ApplicationService = ApplicationService;
142
- //# sourceMappingURL=application.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"application.service.js","sourceRoot":"","sources":["../../../../../../src/core/services/source/javascript/v1/application.service.ts"],"names":[],"mappings":";;;AAAA,4BAA2B;AAC3B,iDAAkD;AAMlD,4CAA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YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,CAAC,CAAC,CAAA;gBACT,WAAW,CAAC,KAAK,EAAE,CAAA;aACpB;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AA1FD,gDA0FC"}
@@ -1,83 +0,0 @@
1
- //depreciado
2
- const uuid = require('uuid')
3
- const EventEmmiter = require('events')
4
-
5
- const mensagens = new Map()
6
- const eventEmmiter = new EventEmmiter()
7
-
8
- process.on('uncaughtException', function (err) {
9
- eventEmmiter.removeAllListeners()
10
- })
11
-
12
- process.on('message', async (message) => {
13
- try {
14
- switch (message.type) {
15
- case "request":
16
- const f = require(message.path)
17
- mensagens.set(message.id, message)
18
- const response = await f({
19
- request: message.request,
20
- user: message.user,
21
- comunicationService: {
22
- call(args) {
23
- return new Promise((resolve, reject) => {
24
- try {
25
- const id = uuid.v4()
26
- eventEmmiter.on(id, (data) => {
27
- eventEmmiter.removeAllListeners(id)
28
- resolve(data)
29
- })
30
- process.send({
31
- ...args,
32
- id,
33
- type: "comunicationServiceCall",
34
- })
35
- } catch (e) {
36
- reject(e)
37
- }
38
- })
39
- }
40
- },
41
- // repository: (args) => new Promise((resolve, reject) => {
42
- // try {
43
- // const id = uuid.v4()
44
- // eventEmmiter.on(id, (data) => {
45
- // eventEmmiter.removeAllListeners(id)
46
- // resolve(data)
47
- // })
48
- // process.send({
49
- // ...args,
50
- // id,
51
- // type: "repositoryCall",
52
- // })
53
- // } catch (e) {
54
- // reject(e)
55
- // }
56
- // })
57
- })
58
-
59
- process.send({
60
- messageFromParentId: message.id,
61
- type: "response",
62
- request: message.request,
63
- response
64
- })
65
- mensagens.delete(message.id)
66
- break
67
- case "comunicationServiceCallResponse":
68
- eventEmmiter.send(message.messageFromChildId, message.data)
69
- break
70
- // case "repositoryCallResponse":
71
- // eventEmmiter.send(message.messageFromChildId, message.data)
72
- // break
73
- }
74
- } catch (e) {
75
- process.send({
76
- messageFromParentId: message.id,
77
- type: "responseError",
78
- request: message.request,
79
- response: e.message || e
80
- })
81
- mensagens.delete(message.id)
82
- }
83
- })