fix(basic.gblib): Databases. #392 @othonlima.
This commit is contained in:
parent
77a3a9a7a6
commit
165619960d
7 changed files with 34 additions and 63 deletions
|
@ -37,6 +37,7 @@
|
||||||
"build-docs": "typedoc --options typedoc.json src/",
|
"build-docs": "typedoc --options typedoc.json src/",
|
||||||
"test": "node test.js",
|
"test": "node test.js",
|
||||||
"start": "NODE_NO_WARNINGS=1 node ./boot.mjs --loader ts-node/esm --require ./suppress-node-warnings.cjs",
|
"start": "NODE_NO_WARNINGS=1 node ./boot.mjs --loader ts-node/esm --require ./suppress-node-warnings.cjs",
|
||||||
|
"debug": "NODE_NO_WARNINGS=1 node ./boot.mjs --loader ts-node/esm --require ./suppress-node-warnings.cjs --inspect",
|
||||||
"reverse-proxy": "node_modules/.bin/ngrok http 4242",
|
"reverse-proxy": "node_modules/.bin/ngrok http 4242",
|
||||||
"watch:build": "tsc --watch",
|
"watch:build": "tsc --watch",
|
||||||
"posttypedoc": "shx cp .nojekyll docs/reference/.nojekyll",
|
"posttypedoc": "shx cp .nojekyll docs/reference/.nojekyll",
|
||||||
|
@ -70,9 +71,9 @@
|
||||||
"@microsoft/microsoft-graph-client": "3.0.4",
|
"@microsoft/microsoft-graph-client": "3.0.4",
|
||||||
"@nlpjs/basic": "4.26.1",
|
"@nlpjs/basic": "4.26.1",
|
||||||
"@nosferatu500/textract": "3.1.2",
|
"@nosferatu500/textract": "3.1.2",
|
||||||
"@push-rpc/core": "1.1.5",
|
"@push-rpc/core": "1.8.2",
|
||||||
"@push-rpc/http": "1.1.5",
|
"@push-rpc/http": "1.8.2",
|
||||||
"@push-rpc/websocket": "1.1.5",
|
"@push-rpc/websocket": "1.8.2",
|
||||||
"@semantic-release/changelog": "5.0.1",
|
"@semantic-release/changelog": "5.0.1",
|
||||||
"@semantic-release/exec": "5.0.0",
|
"@semantic-release/exec": "5.0.0",
|
||||||
"@semantic-release/git": "9.0.0",
|
"@semantic-release/git": "9.0.0",
|
||||||
|
|
|
@ -41,8 +41,7 @@ import { GuaribasSchedule } from '../core.gbapp/models/GBModel.js';
|
||||||
import { Sequelize } from 'sequelize-typescript';
|
import { Sequelize } from 'sequelize-typescript';
|
||||||
import Koa from 'koa';
|
import Koa from 'koa';
|
||||||
import cors from '@koa/cors';
|
import cors from '@koa/cors';
|
||||||
import { createHttpKoaMiddleware } from '@push-rpc/http';
|
import { createKoaHttpMiddleware } from '@push-rpc/http';
|
||||||
import { HttpServerOptions } from '@push-rpc/http/dist/server.js';
|
|
||||||
import { GBServer } from '../../src/app.js';
|
import { GBServer } from '../../src/app.js';
|
||||||
import { SocketServer } from '@push-rpc/core';
|
import { SocketServer } from '@push-rpc/core';
|
||||||
import * as koaBody from 'koa-body';
|
import * as koaBody from 'koa-body';
|
||||||
|
@ -50,10 +49,10 @@ import * as koaBody from 'koa-body';
|
||||||
export function createKoaHttpServer(
|
export function createKoaHttpServer(
|
||||||
port: number,
|
port: number,
|
||||||
getRemoteId: (ctx: Koa.Context) => string,
|
getRemoteId: (ctx: Koa.Context) => string,
|
||||||
opts: Partial<HttpServerOptions> = {}
|
opts:{}
|
||||||
): SocketServer {
|
): SocketServer {
|
||||||
const { onError, onConnection, middleware } =
|
const { onError, onConnection, middleware } =
|
||||||
createHttpKoaMiddleware(getRemoteId, opts);
|
createKoaHttpMiddleware(getRemoteId);
|
||||||
|
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
app.use(cors({ origin: '*' }));
|
app.use(cors({ origin: '*' }));
|
||||||
|
|
|
@ -159,8 +159,8 @@ export class GBVMService extends GBService {
|
||||||
"encoding": "0.1.13",
|
"encoding": "0.1.13",
|
||||||
"isomorphic-fetch": "3.0.0",
|
"isomorphic-fetch": "3.0.0",
|
||||||
"punycode": "2.1.1",
|
"punycode": "2.1.1",
|
||||||
"@push-rpc/core": "1.1.5",
|
"@push-rpc/core": "1.8.2",
|
||||||
"@push-rpc/http": "1.1.5",
|
"@push-rpc/http": "1.8.2",
|
||||||
"vm2": "3.9.11"
|
"vm2": "3.9.11"
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
@ -572,14 +572,14 @@ export class GBVMService extends GBService {
|
||||||
let url;
|
let url;
|
||||||
const agent = http.Agent({ keepAlive: true });
|
const agent = http.Agent({ keepAlive: true });
|
||||||
|
|
||||||
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/dk';
|
url = 'http://localhost:${GBVMService.API_PORT}/${min.botId}/dk';
|
||||||
const dk = (await createRpcClient(0, () => createHttpClient(url, {agent: agent}), optsRPC)).remote;
|
const dk = (await createRpcClient(() => createHttpClient(url, {agent: agent}), optsRPC)).remote;
|
||||||
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/sys';
|
url = 'http://localhost:${GBVMService.API_PORT}/${min.botId}/sys';
|
||||||
const sys = (await createRpcClient(0, () => createHttpClient(url, {agent: agent}), optsRPC)).remote;
|
const sys = (await createRpcClient(() => createHttpClient(url, {agent: agent}), optsRPC)).remote;
|
||||||
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/wa';
|
url = 'http://localhost:${GBVMService.API_PORT}/${min.botId}/wa';
|
||||||
const wa = (await createRpcClient(0, () => createHttpClient(url, {agent: agent}), optsRPC)).remote;
|
const wa = (await createRpcClient(() => createHttpClient(url, {agent: agent}), optsRPC)).remote;
|
||||||
url = 'http://localhost:${GBVMService.API_PORT}/api/v3/${min.botId}/img';
|
url = 'http://localhost:${GBVMService.API_PORT}/${min.botId}/img';
|
||||||
const img = (await createRpcClient(0, () => createHttpClient(url, {agent: agent}), optsRPC)).remote;
|
const img = (await createRpcClient(() => createHttpClient(url, {agent: agent}), optsRPC)).remote;
|
||||||
|
|
||||||
${code}
|
${code}
|
||||||
|
|
||||||
|
|
|
@ -379,7 +379,7 @@ export class KeywordsExpressions {
|
||||||
|
|
||||||
// Performs GET request using the constructed URL
|
// Performs GET request using the constructed URL
|
||||||
|
|
||||||
__data = await sys.get ({pid: pid, file: __url, addressOrHeaders: headers, httpUsername, httpPs});
|
__data = await sys.getHttp ({pid: pid, file: __url, addressOrHeaders: headers, httpUsername, httpPs});
|
||||||
|
|
||||||
// Updates current variable handlers.
|
// Updates current variable handlers.
|
||||||
|
|
||||||
|
@ -649,7 +649,7 @@ export class KeywordsExpressions {
|
||||||
|
|
||||||
// Handles the GET http version.
|
// Handles the GET http version.
|
||||||
else {
|
else {
|
||||||
return `${$1} = await sys.get ({pid: pid, file: ${$2}, addressOrHeaders: headers, httpUsername, httpPs})`;
|
return `${$1} = await sys.getHttp ({pid: pid, file: ${$2}, addressOrHeaders: headers, httpUsername, httpPs})`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -666,16 +666,16 @@ export class SystemKeywords {
|
||||||
const definition = this.getTableFromName(table, min);
|
const definition = this.getTableFromName(table, min);
|
||||||
|
|
||||||
let dst = {};
|
let dst = {};
|
||||||
// Uppercases fields.
|
// Uppercases fields.
|
||||||
let i = 0;
|
let i = 0;
|
||||||
Object.keys(fieldsValues).forEach(fieldSrc => {
|
Object.keys(fieldsValues).forEach(fieldSrc => {
|
||||||
const field = fieldsNames[i].charAt(0).toUpperCase() + fieldsNames[i].slice(1);
|
const field = fieldsNames[i].charAt(0).toUpperCase() + fieldsNames[i].slice(1);
|
||||||
|
|
||||||
dst[field] = fieldsValues[fieldSrc];
|
dst[field] = fieldsValues[fieldSrc];
|
||||||
|
|
||||||
|
i++;
|
||||||
|
});
|
||||||
|
|
||||||
i++;
|
|
||||||
});
|
|
||||||
|
|
||||||
let item;
|
let item;
|
||||||
await retry(
|
await retry(
|
||||||
async (bail) => {
|
async (bail) => {
|
||||||
|
@ -683,7 +683,7 @@ export class SystemKeywords {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
retries: 5,
|
retries: 5,
|
||||||
onRetry: (err)=>{GBLog.error(`Retrying due to: ${err.message}.`);}
|
onRetry: (err) => { GBLog.error(`Retrying due to: ${err.message}.`); }
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
|
@ -811,7 +811,7 @@ export class SystemKeywords {
|
||||||
* @example value = GET "file.xlsx", "A2"
|
* @example value = GET "file.xlsx", "A2"
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public async get({ pid, file, addressOrHeaders, httpUsername, httpPs, qs, streaming }): Promise<any> {
|
public async getHttp({ pid, file, addressOrHeaders, httpUsername, httpPs, qs, streaming }): Promise<any> {
|
||||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||||
if (file.startsWith('http')) {
|
if (file.startsWith('http')) {
|
||||||
return await this.getByHttp({
|
return await this.getByHttp({
|
||||||
|
@ -1682,7 +1682,7 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res) { res['pageMode'] = pageMode; }
|
if (res) { res['pageMode'] = pageMode; }
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2102,8 +2102,7 @@ export class SystemKeywords {
|
||||||
else {
|
else {
|
||||||
table = this.cachedMerge[pid][file];
|
table = this.cachedMerge[pid][file];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let key1Index, key2Index;
|
let key1Index, key2Index;
|
||||||
|
|
||||||
if (key1) {
|
if (key1) {
|
||||||
|
@ -2230,8 +2229,9 @@ export class SystemKeywords {
|
||||||
|
|
||||||
if (storage) {
|
if (storage) {
|
||||||
|
|
||||||
let dst={};
|
let dst = {};
|
||||||
// Uppercases fields.
|
|
||||||
|
// Uppercases fields.
|
||||||
let i = 0;
|
let i = 0;
|
||||||
Object.keys(fieldsValues).forEach(fieldSrc => {
|
Object.keys(fieldsValues).forEach(fieldSrc => {
|
||||||
const field = fieldsNames[i].charAt(0).toUpperCase() + fieldsNames[i].slice(1);
|
const field = fieldsNames[i].charAt(0).toUpperCase() + fieldsNames[i].slice(1);
|
||||||
|
|
|
@ -37,22 +37,16 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
import cliProgress from 'cli-progress';
|
import cliProgress from 'cli-progress';
|
||||||
import { DialogSet, TextPrompt } from 'botbuilder-dialogs';
|
import { DialogSet, TextPrompt } from 'botbuilder-dialogs';
|
||||||
import express from 'express';
|
|
||||||
import SwaggerClient from 'swagger-client';
|
import SwaggerClient from 'swagger-client';
|
||||||
import removeRoute from 'express-remove-route';
|
import removeRoute from 'express-remove-route';
|
||||||
import AuthenticationContext from 'adal-node';
|
import AuthenticationContext from 'adal-node';
|
||||||
import { FacebookAdapter } from 'botbuilder-adapter-facebook';
|
import { FacebookAdapter } from 'botbuilder-adapter-facebook';
|
||||||
import path from 'path';
|
|
||||||
import mkdirp from 'mkdirp';
|
import mkdirp from 'mkdirp';
|
||||||
import Fs from 'fs';
|
import Fs from 'fs';
|
||||||
import arrayBufferToBuffer from 'arraybuffer-to-buffer';
|
import arrayBufferToBuffer from 'arraybuffer-to-buffer';
|
||||||
import { NlpManager } from 'node-nlp';
|
import { NlpManager } from 'node-nlp';
|
||||||
import Koa from 'koa';
|
import Koa from 'koa';
|
||||||
import cors from '@koa/cors';
|
|
||||||
import { createRpcServer } from '@push-rpc/core';
|
import { createRpcServer } from '@push-rpc/core';
|
||||||
import { createHttpKoaMiddleware } from '@push-rpc/http';
|
|
||||||
import { HttpServerOptions } from '@push-rpc/http/dist/server.js';
|
|
||||||
import { List } from 'whatsapp-web.js';
|
|
||||||
import wash from 'washyourmouthoutwithsoap';
|
import wash from 'washyourmouthoutwithsoap';
|
||||||
import {
|
import {
|
||||||
AutoSaveStateMiddleware,
|
AutoSaveStateMiddleware,
|
||||||
|
@ -100,7 +94,6 @@ import { createKoaHttpServer } from '../../basic.gblib/index.js';
|
||||||
import { DebuggerService } from '../../basic.gblib/services/DebuggerService.js';
|
import { DebuggerService } from '../../basic.gblib/services/DebuggerService.js';
|
||||||
import { ImageProcessingServices } from '../../basic.gblib/services/ImageProcessingServices.js';
|
import { ImageProcessingServices } from '../../basic.gblib/services/ImageProcessingServices.js';
|
||||||
import { ScheduleServices } from '../../basic.gblib/services/ScheduleServices.js';
|
import { ScheduleServices } from '../../basic.gblib/services/ScheduleServices.js';
|
||||||
import mime from 'mime-types';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minimal service layer for a bot and encapsulation of BOT Framework calls.
|
* Minimal service layer for a bot and encapsulation of BOT Framework calls.
|
||||||
|
@ -1613,11 +1606,9 @@ export class GBMinService {
|
||||||
connected(remoteId: string, connections: number): void { },
|
connected(remoteId: string, connections: number): void { },
|
||||||
messageIn(...params): void {
|
messageIn(...params): void {
|
||||||
params.shift();
|
params.shift();
|
||||||
GBLogEx.verbose(0, '[IN] ' + params);
|
|
||||||
},
|
},
|
||||||
messageOut(...params): void {
|
messageOut(...params): void {
|
||||||
params.shift();
|
params.shift();
|
||||||
GBLogEx.verbose(0, '[OUT] ' + params);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
20
src/app.ts
20
src/app.ts
|
@ -59,9 +59,6 @@ import * as winston from 'winston-logs-display';
|
||||||
import { RootData } from './RootData.js';
|
import { RootData } from './RootData.js';
|
||||||
import { GBSSR } from '../packages/core.gbapp/services/GBSSR.js';
|
import { GBSSR } from '../packages/core.gbapp/services/GBSSR.js';
|
||||||
import { Mutex } from 'async-mutex';
|
import { Mutex } from 'async-mutex';
|
||||||
import { setFlagsFromString } from 'v8';
|
|
||||||
import { runInNewContext } from 'vm';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General Bots open-core entry point.
|
* General Bots open-core entry point.
|
||||||
|
@ -79,23 +76,6 @@ export class GBServer {
|
||||||
GBConfigService.init();
|
GBConfigService.init();
|
||||||
const port = GBConfigService.getServerPort();
|
const port = GBConfigService.getServerPort();
|
||||||
|
|
||||||
setFlagsFromString('--expose_gc');
|
|
||||||
|
|
||||||
const runGC = () => {
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
|
|
||||||
// Do something here
|
|
||||||
GBLog.info('Running GC...');
|
|
||||||
|
|
||||||
const gc = runInNewContext('gc'); // nocommit
|
|
||||||
gc();
|
|
||||||
runGC();
|
|
||||||
}, 5 * 60 * 1000);
|
|
||||||
}
|
|
||||||
runGC();
|
|
||||||
|
|
||||||
|
|
||||||
if (process.env.TEST_SHELL) {
|
if (process.env.TEST_SHELL) {
|
||||||
GBLog.info(`Running TEST_SHELL: ${process.env.TEST_SHELL}...`);
|
GBLog.info(`Running TEST_SHELL: ${process.env.TEST_SHELL}...`);
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Reference in a new issue