Merge pull request #12386 from vvlladd28/improvement/js-executor/clear-dependencies
Clear JS executor dependencies and code
This commit is contained in:
		
						commit
						0c36ed1226
					
				@ -16,8 +16,6 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
export interface TbMessage {
 | 
			
		||||
    scriptIdMSB: string; // deprecated
 | 
			
		||||
    scriptIdLSB: string; // deprecated
 | 
			
		||||
    scriptHash: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -18,7 +18,7 @@ import config from 'config';
 | 
			
		||||
import { _logger } from '../config/logger';
 | 
			
		||||
import { JsExecutor, TbScript } from './jsExecutor';
 | 
			
		||||
import { performance } from 'perf_hooks';
 | 
			
		||||
import { isString, parseJsErrorDetails, toUUIDString, UUIDFromBuffer, UUIDToBits, isNotUUID } from './utils';
 | 
			
		||||
import { isString, parseJsErrorDetails, UUIDFromBuffer, UUIDToBits } from './utils';
 | 
			
		||||
import { IQueue } from '../queue/queue.models';
 | 
			
		||||
import {
 | 
			
		||||
    JsCompileRequest,
 | 
			
		||||
@ -306,26 +306,12 @@ export class JsInvokeMessageProcessor {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static createCompileResponse(scriptId: string, success: boolean, errorCode?: number, err?: any): JsCompileResponse {
 | 
			
		||||
        if (isNotUUID(scriptId)) {
 | 
			
		||||
            return {
 | 
			
		||||
                errorCode: errorCode,
 | 
			
		||||
                success: success,
 | 
			
		||||
                errorDetails: parseJsErrorDetails(err),
 | 
			
		||||
                scriptIdMSB: "0",
 | 
			
		||||
                scriptIdLSB: "0",
 | 
			
		||||
                scriptHash: scriptId
 | 
			
		||||
            };
 | 
			
		||||
        } else { // this is for backward compatibility (to be able to work with tb-node of previous version) - todo: remove in the next release
 | 
			
		||||
            let scriptIdBits = UUIDToBits(scriptId);
 | 
			
		||||
            return {
 | 
			
		||||
                errorCode: errorCode,
 | 
			
		||||
                success: success,
 | 
			
		||||
                errorDetails: parseJsErrorDetails(err),
 | 
			
		||||
                scriptIdMSB: scriptIdBits[0],
 | 
			
		||||
                scriptIdLSB: scriptIdBits[1],
 | 
			
		||||
                scriptHash: ""
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
        return {
 | 
			
		||||
            errorCode: errorCode,
 | 
			
		||||
            success: success,
 | 
			
		||||
            errorDetails: parseJsErrorDetails(err),
 | 
			
		||||
            scriptHash: scriptId
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static createInvokeResponse(result: string | undefined, success: boolean, errorCode?: number, err?: any): JsInvokeResponse {
 | 
			
		||||
@ -338,26 +324,14 @@ export class JsInvokeMessageProcessor {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static createReleaseResponse(scriptId: string, success: boolean): JsReleaseResponse {
 | 
			
		||||
        if (isNotUUID(scriptId)) {
 | 
			
		||||
            return {
 | 
			
		||||
                success: success,
 | 
			
		||||
                scriptIdMSB: "0",
 | 
			
		||||
                scriptIdLSB: "0",
 | 
			
		||||
                scriptHash: scriptId,
 | 
			
		||||
            };
 | 
			
		||||
        } else { // todo: remove in the next release
 | 
			
		||||
            let scriptIdBits = UUIDToBits(scriptId);
 | 
			
		||||
            return {
 | 
			
		||||
                success: success,
 | 
			
		||||
                scriptIdMSB: scriptIdBits[0],
 | 
			
		||||
                scriptIdLSB: scriptIdBits[1],
 | 
			
		||||
                scriptHash: ""
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return {
 | 
			
		||||
            success: success,
 | 
			
		||||
            scriptHash: scriptId,
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static getScriptId(request: TbMessage): string {
 | 
			
		||||
        return request.scriptHash ? request.scriptHash : toUUIDString(request.scriptIdMSB, request.scriptIdLSB);
 | 
			
		||||
        return request.scriptHash;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private incrementUseScriptId(scriptId: string) {
 | 
			
		||||
 | 
			
		||||
@ -17,13 +17,6 @@
 | 
			
		||||
import Long from 'long';
 | 
			
		||||
import uuidParse from 'uuid-parse';
 | 
			
		||||
 | 
			
		||||
export function toUUIDString(mostSigBits: string, leastSigBits: string): string {
 | 
			
		||||
    const msbBytes = Long.fromValue(mostSigBits, false).toBytes(false);
 | 
			
		||||
    const lsbBytes = Long.fromValue(leastSigBits, false).toBytes(false);
 | 
			
		||||
    const uuidBytes = msbBytes.concat(lsbBytes);
 | 
			
		||||
    return uuidParse.unparse(uuidBytes as any);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function UUIDFromBuffer(buf: Buffer): string {
 | 
			
		||||
    return uuidParse.unparse(buf);
 | 
			
		||||
}
 | 
			
		||||
@ -59,10 +52,6 @@ export function parseJsErrorDetails(err: any): string | undefined {
 | 
			
		||||
    return details;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function isNotUUID(candidate: string) {
 | 
			
		||||
    return candidate.length != 36 || !candidate.includes('-');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function isNotEmptyStr(value: any): boolean {
 | 
			
		||||
    return typeof value === 'string' && value.trim().length > 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -13,17 +13,12 @@
 | 
			
		||||
    "build": "tsc"
 | 
			
		||||
  },
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "@aws-sdk/client-sqs": "^3.682.0",
 | 
			
		||||
    "@azure/service-bus": "^7.9.5",
 | 
			
		||||
    "@google-cloud/pubsub": "^4.8.0",
 | 
			
		||||
    "amqplib": "^0.10.4",
 | 
			
		||||
    "config": "^3.3.12",
 | 
			
		||||
    "express": "^4.21.1",
 | 
			
		||||
    "js-yaml": "^4.1.0",
 | 
			
		||||
    "kafkajs": "^2.2.4",
 | 
			
		||||
    "long": "^5.2.3",
 | 
			
		||||
    "uuid-parse": "^1.1.0",
 | 
			
		||||
    "uuid-random": "^1.3.2",
 | 
			
		||||
    "winston": "^3.16.0",
 | 
			
		||||
    "winston-daily-rotate-file": "^5.0.0"
 | 
			
		||||
  },
 | 
			
		||||
@ -36,7 +31,6 @@
 | 
			
		||||
    ]
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "@types/amqplib": "^0.10.5",
 | 
			
		||||
    "@types/config": "^3.3.5",
 | 
			
		||||
    "@types/express": "~4.17.21",
 | 
			
		||||
    "@types/node": "~20.17.6",
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,6 @@ import { KeyObject } from 'tls';
 | 
			
		||||
 | 
			
		||||
import process, { exit, kill } from 'process';
 | 
			
		||||
 | 
			
		||||
// TODO: remove dependencies for other queue types
 | 
			
		||||
export class KafkaTemplate implements IQueue {
 | 
			
		||||
 | 
			
		||||
    private logger = _logger(`kafkaTemplate`);
 | 
			
		||||
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user