fix(all): Libraries update.
This commit is contained in:
		
							parent
							
								
									699ff27e14
								
							
						
					
					
						commit
						1173233971
					
				
					 3 changed files with 65 additions and 74 deletions
				
			
		| 
						 | 
					@ -5,7 +5,7 @@
 | 
				
			||||||
| ██   ██ █     █  ██ █ █     ██  ██ ██  ██ ██      ██  █ ██   ██  █      █   |
 | 
					| ██   ██ █     █  ██ █ █     ██  ██ ██  ██ ██      ██  █ ██   ██  █      █   |
 | 
				
			||||||
|  █████  █████ █   ███ █████ ██  ██ ██  ██ █████   ████   █████   █   ███    |
 | 
					|  █████  █████ █   ███ █████ ██  ██ ██  ██ █████   ████   █████   █   ███    |
 | 
				
			||||||
|                                                                             |
 | 
					|                                                                             |
 | 
				
			||||||
| General Bots Copyright (c) pragmatismo.cloud. All rights reserved.         |
 | 
					| General Bots Copyright (c) pragmatismo.cloud. All rights reserved.          |
 | 
				
			||||||
| Licensed under the AGPL-3.0.                                                |
 | 
					| Licensed under the AGPL-3.0.                                                |
 | 
				
			||||||
|                                                                             |
 | 
					|                                                                             |
 | 
				
			||||||
| According to our dual licensing model, this program can be used either      |
 | 
					| According to our dual licensing model, this program can be used either      |
 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,7 @@
 | 
				
			||||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                |
 | 
					| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                |
 | 
				
			||||||
| GNU Affero General Public License for more details.                         |
 | 
					| GNU Affero General Public License for more details.                         |
 | 
				
			||||||
|                                                                             |
 | 
					|                                                                             |
 | 
				
			||||||
| "General Bots" is a registered trademark of pragmatismo.cloud.             |
 | 
					| "General Bots" is a registered trademark of pragmatismo.cloud.              |
 | 
				
			||||||
| The licensing of the program under the AGPLv3 does not imply a              |
 | 
					| The licensing of the program under the AGPLv3 does not imply a              |
 | 
				
			||||||
| trademark license. Therefore any rights, title and interest in              |
 | 
					| trademark license. Therefore any rights, title and interest in              |
 | 
				
			||||||
| our trademarks remain entirely with us.                                     |
 | 
					| our trademarks remain entirely with us.                                     |
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										74
									
								
								src/app.ts
									
										
									
									
									
								
							
							
						
						
									
										74
									
								
								src/app.ts
									
										
									
									
									
								
							| 
						 | 
					@ -5,7 +5,7 @@
 | 
				
			||||||
| ██   ██ █     █  ██ █ █     ██  ██ ██  ██ ██      ██  █ ██   ██  █      █   |
 | 
					| ██   ██ █     █  ██ █ █     ██  ██ ██  ██ ██      ██  █ ██   ██  █      █   |
 | 
				
			||||||
|  █████  █████ █   ███ █████ ██  ██ ██  ██ █████   ████   █████   █   ███    |
 | 
					|  █████  █████ █   ███ █████ ██  ██ ██  ██ █████   ████   █████   █   ███    |
 | 
				
			||||||
|                                                                             |
 | 
					|                                                                             |
 | 
				
			||||||
| General Bots Copyright (c) pragmatismo.cloud. All rights reserved.         |
 | 
					| General Bots Copyright (c) pragmatismo.cloud. All rights reserved.          |
 | 
				
			||||||
| Licensed under the AGPL-3.0.                                                |
 | 
					| Licensed under the AGPL-3.0.                                                |
 | 
				
			||||||
|                                                                             |
 | 
					|                                                                             |
 | 
				
			||||||
| According to our dual licensing model, this program can be used either      |
 | 
					| According to our dual licensing model, this program can be used either      |
 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,7 @@
 | 
				
			||||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                |
 | 
					| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                |
 | 
				
			||||||
| GNU Affero General Public License for more details.                         |
 | 
					| GNU Affero General Public License for more details.                         |
 | 
				
			||||||
|                                                                             |
 | 
					|                                                                             |
 | 
				
			||||||
| "General Bots" is a registered trademark of pragmatismo.cloud.             |
 | 
					| "General Bots" is a registered trademark of pragmatismo.cloud.              |
 | 
				
			||||||
| The licensing of the program under the AGPLv3 does not imply a              |
 | 
					| The licensing of the program under the AGPLv3 does not imply a              |
 | 
				
			||||||
| trademark license. Therefore any rights, title and interest in              |
 | 
					| trademark license. Therefore any rights, title and interest in              |
 | 
				
			||||||
| our trademarks remain entirely with us.                                     |
 | 
					| our trademarks remain entirely with us.                                     |
 | 
				
			||||||
| 
						 | 
					@ -34,16 +34,19 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import express from 'express';
 | 
					import { Mutex } from 'async-mutex';
 | 
				
			||||||
 | 
					import auth from 'basic-auth';
 | 
				
			||||||
import bodyParser from 'body-parser';
 | 
					import bodyParser from 'body-parser';
 | 
				
			||||||
import https from 'https';
 | 
					import { GBLog, GBMinInstance, IGBCoreService, IGBInstance } from 'botlib';
 | 
				
			||||||
import http from 'http';
 | 
					import child_process from 'child_process';
 | 
				
			||||||
import mkdirp from 'mkdirp';
 | 
					import express from 'express';
 | 
				
			||||||
import Path from 'path';
 | 
					 | 
				
			||||||
import swaggerUI from 'swagger-ui-dist';
 | 
					 | 
				
			||||||
import path from 'path';
 | 
					 | 
				
			||||||
import fs from 'fs';
 | 
					import fs from 'fs';
 | 
				
			||||||
import { GBLog, GBMinInstance, IGBCoreService, IGBInstance, IGBPackage } from 'botlib';
 | 
					import http from 'http';
 | 
				
			||||||
 | 
					import httpProxy from 'http-proxy';
 | 
				
			||||||
 | 
					import https from 'https';
 | 
				
			||||||
 | 
					import mkdirp from 'mkdirp';
 | 
				
			||||||
 | 
					import { default as Path, default as path } from 'path';
 | 
				
			||||||
 | 
					import swaggerUI from 'swagger-ui-dist';
 | 
				
			||||||
import { GBAdminService } from '../packages/admin.gbapp/services/GBAdminService.js';
 | 
					import { GBAdminService } from '../packages/admin.gbapp/services/GBAdminService.js';
 | 
				
			||||||
import { AzureDeployerService } from '../packages/azuredeployer.gbapp/services/AzureDeployerService.js';
 | 
					import { AzureDeployerService } from '../packages/azuredeployer.gbapp/services/AzureDeployerService.js';
 | 
				
			||||||
import { GBConfigService } from '../packages/core.gbapp/services/GBConfigService.js';
 | 
					import { GBConfigService } from '../packages/core.gbapp/services/GBConfigService.js';
 | 
				
			||||||
| 
						 | 
					@ -51,14 +54,11 @@ import { GBConversationalService } from '../packages/core.gbapp/services/GBConve
 | 
				
			||||||
import { GBCoreService } from '../packages/core.gbapp/services/GBCoreService.js';
 | 
					import { GBCoreService } from '../packages/core.gbapp/services/GBCoreService.js';
 | 
				
			||||||
import { GBDeployer } from '../packages/core.gbapp/services/GBDeployer.js';
 | 
					import { GBDeployer } from '../packages/core.gbapp/services/GBDeployer.js';
 | 
				
			||||||
import { GBImporter } from '../packages/core.gbapp/services/GBImporterService.js';
 | 
					import { GBImporter } from '../packages/core.gbapp/services/GBImporterService.js';
 | 
				
			||||||
import { GBMinService } from '../packages/core.gbapp/services/GBMinService.js';
 | 
					 | 
				
			||||||
import auth from 'basic-auth';
 | 
					 | 
				
			||||||
import child_process from 'child_process';
 | 
					 | 
				
			||||||
import { RootData } from './RootData.js';
 | 
					 | 
				
			||||||
import { GBSSR } from '../packages/core.gbapp/services/GBSSR.js';
 | 
					 | 
				
			||||||
import { Mutex } from 'async-mutex';
 | 
					 | 
				
			||||||
import httpProxy from 'http-proxy';
 | 
					 | 
				
			||||||
import { GBLogEx } from '../packages/core.gbapp/services/GBLogEx.js';
 | 
					import { GBLogEx } from '../packages/core.gbapp/services/GBLogEx.js';
 | 
				
			||||||
 | 
					import { GBMinService } from '../packages/core.gbapp/services/GBMinService.js';
 | 
				
			||||||
 | 
					import { GBSSR } from '../packages/core.gbapp/services/GBSSR.js';
 | 
				
			||||||
 | 
					import { RootData } from './RootData.js';
 | 
				
			||||||
 | 
					import { GBUtil } from './util.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * General Bots open-core entry point.
 | 
					 * General Bots open-core entry point.
 | 
				
			||||||
| 
						 | 
					@ -105,9 +105,8 @@ export class GBServer {
 | 
				
			||||||
    server.use(bodyParser.json());
 | 
					    server.use(bodyParser.json());
 | 
				
			||||||
    server.use(bodyParser.json({ limit: '1mb' }));
 | 
					    server.use(bodyParser.json({ limit: '1mb' }));
 | 
				
			||||||
    server.use(bodyParser.urlencoded({ limit: '1mb', extended: true }));
 | 
					    server.use(bodyParser.urlencoded({ limit: '1mb', extended: true }));
 | 
				
			||||||
    server.use(function(req, res, next) {
 | 
					    server.use(function (req, res, next) {
 | 
				
			||||||
      for (const key in req.query)
 | 
					      for (const key in req.query) {
 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        req.query[key.toLowerCase()] = req.query[key];
 | 
					        req.query[key.toLowerCase()] = req.query[key];
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      next();
 | 
					      next();
 | 
				
			||||||
| 
						 | 
					@ -118,13 +117,14 @@ export class GBServer {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    process.on('uncaughtException', (err, p) => {
 | 
					    process.on('uncaughtException', (err, p) => {
 | 
				
			||||||
        GBLog.error(`UNCAUGHT_EXCEPTION: ${JSON.stringify(err, Object.getOwnPropertyNames(err))}`);
 | 
					      GBLogEx.error(0, `GBEXCEPTION: ${GBUtil.toYAML(JSON.stringify(err, Object.getOwnPropertyNames(err)))}`);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    process.on('unhandledRejection', (err, p) => {
 | 
					    process.on('unhandledRejection', (err, p) => {
 | 
				
			||||||
      GBLog.error(`UNHANDLED_REJECTION: ${JSON.stringify(err, Object.getOwnPropertyNames(err))}`);
 | 
					      GBLogEx.error(0,`GBREJECTION: ${GBUtil.toYAML(JSON.stringify(err, Object.getOwnPropertyNames(err)))}`);
 | 
				
			||||||
  });
 | 
					    });
 | 
				
			||||||
  // Creates working directory.
 | 
					
 | 
				
			||||||
 | 
					    // Creates working directory.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    process.env.PWD = process.cwd();
 | 
					    process.env.PWD = process.cwd();
 | 
				
			||||||
    const workDir = Path.join(process.env.PWD, 'work');
 | 
					    const workDir = Path.join(process.env.PWD, 'work');
 | 
				
			||||||
| 
						 | 
					@ -134,7 +134,6 @@ export class GBServer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const mainCallback = () => {
 | 
					    const mainCallback = () => {
 | 
				
			||||||
      (async () => {
 | 
					      (async () => {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
          GBLogEx.info(0, `Now accepting connections on ${port}...`);
 | 
					          GBLogEx.info(0, `Now accepting connections on ${port}...`);
 | 
				
			||||||
          process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
 | 
					          process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
 | 
				
			||||||
| 
						 | 
					@ -163,7 +162,6 @@ export class GBServer {
 | 
				
			||||||
            GBServer.globals.publicAddress = serverAddress;
 | 
					            GBServer.globals.publicAddress = serverAddress;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
          // Creates a boot instance or load it from storage.
 | 
					          // Creates a boot instance or load it from storage.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          let runOnce = false;
 | 
					          let runOnce = false;
 | 
				
			||||||
| 
						 | 
					@ -237,13 +235,11 @@ export class GBServer {
 | 
				
			||||||
          GBServer.globals.minService = minService;
 | 
					          GBServer.globals.minService = minService;
 | 
				
			||||||
          await minService.buildMin(instances);
 | 
					          await minService.buildMin(instances);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
          server.all('*', async (req, res, next) => {
 | 
					          server.all('*', async (req, res, next) => {
 | 
				
			||||||
 | 
					 | 
				
			||||||
            const host = req.headers.host;
 | 
					            const host = req.headers.host;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (req.originalUrl.startsWith('/logs')) {
 | 
					            if (req.originalUrl.startsWith('/logs')) {
 | 
				
			||||||
              if (process.env.ENABLE_WEBLOG === "true") {
 | 
					              if (process.env.ENABLE_WEBLOG === 'true') {
 | 
				
			||||||
                const admins = {
 | 
					                const admins = {
 | 
				
			||||||
                  admin: { password: process.env.ADMIN_PASS }
 | 
					                  admin: { password: process.env.ADMIN_PASS }
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
| 
						 | 
					@ -258,7 +254,6 @@ export class GBServer {
 | 
				
			||||||
                await GBSSR.ssrFilter(req, res, next);
 | 
					                await GBSSR.ssrFilter(req, res, next);
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
 | 
					 | 
				
			||||||
              // Setups unsecure http redirect.
 | 
					              // Setups unsecure http redirect.
 | 
				
			||||||
              const proxy = httpProxy.createProxyServer({});
 | 
					              const proxy = httpProxy.createProxyServer({});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -285,24 +280,22 @@ export class GBServer {
 | 
				
			||||||
      })();
 | 
					      })();
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (process.env.CERTIFICATE_PFX) {
 | 
					    if (process.env.CERTIFICATE_PFX) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
      const server1 = http.createServer((req, res) => {
 | 
					      const server1 = http.createServer((req, res) => {
 | 
				
			||||||
        const host = req.headers.host.startsWith('www.') ?
 | 
					        const host = req.headers.host.startsWith('www.') ? req.headers.host.substring(4) : req.headers.host;
 | 
				
			||||||
          req.headers.host.substring(4) : req.headers.host;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        res.writeHead(301, {
 | 
					        res
 | 
				
			||||||
          Location: "https://" + host + req.url
 | 
					          .writeHead(301, {
 | 
				
			||||||
 | 
					            Location: 'https://' + host + req.url
 | 
				
			||||||
        }).end();
 | 
					          })
 | 
				
			||||||
 | 
					          .end();
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      server1.listen(80);
 | 
					      server1.listen(80);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const options1 = {
 | 
					      const options1 = {
 | 
				
			||||||
        passphrase: process.env.CERTIFICATE_PASSPHRASE,
 | 
					        passphrase: process.env.CERTIFICATE_PASSPHRASE,
 | 
				
			||||||
        pfx: fs.readFileSync(process.env.CERTIFICATE_PFX),
 | 
					        pfx: fs.readFileSync(process.env.CERTIFICATE_PFX),
 | 
				
			||||||
        ca: fs.existsSync(process.env.CERTIFICATE_CA)? fs.readFileSync(process.env.CERTIFICATE_CA):null
 | 
					        ca: fs.existsSync(process.env.CERTIFICATE_CA) ? fs.readFileSync(process.env.CERTIFICATE_CA) : null
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
 | 
					      const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
 | 
				
			||||||
| 
						 | 
					@ -323,8 +316,7 @@ export class GBServer {
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    } else {
 | 
				
			||||||
    else {
 | 
					 | 
				
			||||||
      server.listen(port, mainCallback);
 | 
					      server.listen(port, mainCallback);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										61
									
								
								src/util.ts
									
										
									
									
									
								
							
							
						
						
									
										61
									
								
								src/util.ts
									
										
									
									
									
								
							| 
						 | 
					@ -5,7 +5,7 @@
 | 
				
			||||||
| ██   ██ █     █  ██ █ █     ██  ██ ██  ██ ██      ██  █ ██   ██  █      █   |
 | 
					| ██   ██ █     █  ██ █ █     ██  ██ ██  ██ ██      ██  █ ██   ██  █      █   |
 | 
				
			||||||
|  █████  █████ █   ███ █████ ██  ██ ██  ██ █████   ████   █████   █   ███    |
 | 
					|  █████  █████ █   ███ █████ ██  ██ ██  ██ █████   ████   █████   █   ███    |
 | 
				
			||||||
|                                                                             |
 | 
					|                                                                             |
 | 
				
			||||||
| General Bots Copyright (c) pragmatismo.cloud. All rights reserved.         |
 | 
					| General Bots Copyright (c) pragmatismo.cloud. All rights reserved.          |
 | 
				
			||||||
| Licensed under the AGPL-3.0.                                                |
 | 
					| Licensed under the AGPL-3.0.                                                |
 | 
				
			||||||
|                                                                             |
 | 
					|                                                                             |
 | 
				
			||||||
| According to our dual licensing model, this program can be used either      |
 | 
					| According to our dual licensing model, this program can be used either      |
 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,7 @@
 | 
				
			||||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                |
 | 
					| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                |
 | 
				
			||||||
| GNU Affero General Public License for more details.                         |
 | 
					| GNU Affero General Public License for more details.                         |
 | 
				
			||||||
|                                                                             |
 | 
					|                                                                             |
 | 
				
			||||||
| "General Bots" is a registered trademark of pragmatismo.cloud.             |
 | 
					| "General Bots" is a registered trademark of pragmatismo.cloud.              |
 | 
				
			||||||
| The licensing of the program under the AGPLv3 does not imply a              |
 | 
					| The licensing of the program under the AGPLv3 does not imply a              |
 | 
				
			||||||
| trademark license. Therefore any rights, title and interest in              |
 | 
					| trademark license. Therefore any rights, title and interest in              |
 | 
				
			||||||
| our trademarks remain entirely with us.                                     |
 | 
					| our trademarks remain entirely with us.                                     |
 | 
				
			||||||
| 
						 | 
					@ -33,66 +33,65 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
 | 
					import * as YAML from 'yaml';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class GBUtil {
 | 
					export class GBUtil {
 | 
				
			||||||
 | 
					  public static repeat(chr, count) {
 | 
				
			||||||
  public static repeat (chr, count) {
 | 
					    let str = '';
 | 
				
			||||||
    let str = "";
 | 
					    for (let x = 0; x < count; x++) {
 | 
				
			||||||
    for (let x = 0; x < count; x++) { str += chr };
 | 
					      str += chr;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    return str;
 | 
					    return str;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public static padL  (value, width, pad) {
 | 
					  public static padL(value, width, pad) {
 | 
				
			||||||
    if (!width || width < 1)
 | 
					    if (!width || width < 1) return value;
 | 
				
			||||||
      return value;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!pad) pad = " ";
 | 
					    if (!pad) pad = ' ';
 | 
				
			||||||
    const length = width - value.length
 | 
					    const length = width - value.length;
 | 
				
			||||||
    if (length < 1) return value.substr(0, width);
 | 
					    if (length < 1) return value.substr(0, width);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (GBUtil.repeat(pad, length) + value).substr(0, width);
 | 
					    return (GBUtil.repeat(pad, length) + value).substr(0, width);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  public static padR  (value, width, pad) {
 | 
					  
 | 
				
			||||||
    if (!width || width < 1)
 | 
					  public static padR(value, width, pad) {
 | 
				
			||||||
      return value;
 | 
					    if (!width || width < 1) return value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!pad) pad = " ";
 | 
					    if (!pad) pad = ' ';
 | 
				
			||||||
    const length = width - value.length
 | 
					    const length = width - value.length;
 | 
				
			||||||
    if (length < 1) value.substr(0, width);
 | 
					    if (length < 1) value.substr(0, width);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (value + GBUtil.repeat(pad, length)).substr(0, width);
 | 
					    return (value + GBUtil.repeat(pad, length)).substr(0, width);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public static toYAML(json) {
 | 
				
			||||||
 | 
					    const doc = new YAML.Document();
 | 
				
			||||||
 | 
					    doc.contents = json;
 | 
				
			||||||
 | 
					    return doc.toString();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public static sleep(ms) {
 | 
					  public static sleep(ms) {
 | 
				
			||||||
    return new Promise(resolve => {
 | 
					    return new Promise(resolve => {
 | 
				
			||||||
      setTimeout(resolve, ms);
 | 
					      setTimeout(resolve, ms);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  };
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public static caseInsensitive(listOrRow) {
 | 
					  public static caseInsensitive(listOrRow) {
 | 
				
			||||||
 | 
					    if (!listOrRow || typeof listOrRow !== 'object') {
 | 
				
			||||||
    if (!listOrRow) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      return listOrRow;
 | 
					      return listOrRow;
 | 
				
			||||||
    };
 | 
					    }
 | 
				
			||||||
 | 
					    const lowercase = oldKey => (typeof oldKey === 'string' ? oldKey.toLowerCase() : oldKey);
 | 
				
			||||||
    const lowercase = (oldKey) => typeof oldKey === 'string' ? oldKey.toLowerCase() : oldKey;
 | 
					    const createCaseInsensitiveProxy = obj => {
 | 
				
			||||||
 | 
					 | 
				
			||||||
    const createCaseInsensitiveProxy = (obj) => {
 | 
					 | 
				
			||||||
      const propertiesMap = new Map(Object.keys(obj).map(propKey => [lowercase(propKey), obj[propKey]]));
 | 
					      const propertiesMap = new Map(Object.keys(obj).map(propKey => [lowercase(propKey), obj[propKey]]));
 | 
				
			||||||
      const caseInsensitiveGetHandler = {
 | 
					      const caseInsensitiveGetHandler = {
 | 
				
			||||||
        get: (target, property) => propertiesMap.get(lowercase(property))
 | 
					        get: (target, property) => propertiesMap.get(lowercase(property))
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
      return new Proxy(obj, caseInsensitiveGetHandler);
 | 
					      return new Proxy(obj, caseInsensitiveGetHandler);
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					    if (Array.isArray(listOrRow)) {
 | 
				
			||||||
    if (listOrRow.length) {
 | 
					 | 
				
			||||||
      return listOrRow.map(row => createCaseInsensitiveProxy(row));
 | 
					      return listOrRow.map(row => createCaseInsensitiveProxy(row));
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      return createCaseInsensitiveProxy(listOrRow);
 | 
					      return createCaseInsensitiveProxy(listOrRow);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  };
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue