@transai/connector-runner-dummy-node 0.17.0 → 0.18.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/CHANGELOG.md +6 -0
- package/index.cjs +1 -1
- package/index.cjs.map +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var l=Object.create;var i=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var y=(t,r)=>{for(var e in r)i(t,e,{get:r[e],enumerable:!0})},m=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of g(r))!b.call(t,o)&&o!==e&&i(t,o,{get:()=>r[o],enumerable:!(n=d(r,o))||n.enumerable});return t};var P=(t,r,e)=>(e=t!=null?l(I(t)):{},m(r||!t||!t.__esModule?i(e,"default",{value:t,enumerable:!0}):e,t)),x=t=>m(i({},"__esModule",{value:!0}),t);var C={};y(C,{ConnectorRunnerDummyNode:()=>
|
|
1
|
+
"use strict";var l=Object.create;var i=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var y=(t,r)=>{for(var e in r)i(t,e,{get:r[e],enumerable:!0})},m=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of g(r))!b.call(t,o)&&o!==e&&i(t,o,{get:()=>r[o],enumerable:!(n=d(r,o))||n.enumerable});return t};var P=(t,r,e)=>(e=t!=null?l(I(t)):{},m(r||!t||!t.__esModule?i(e,"default",{value:t,enumerable:!0}):e,t)),x=t=>m(i({},"__esModule",{value:!0}),t);var C={};y(C,{ConnectorRunnerDummyNode:()=>c});module.exports=x(C);var a=P(require("node:process")),s=class{#r="connector-runtime";#e;constructor(r,e){this.#e=e,a.default.on?a.default.on("message",n=>{n.cmd===this.#r&&e.logger.verbose(`${a.default.pid} Received message from parent process:`,n)}):e.logger.warn("IPC channel is not available. process.on is undefined."),a.default.send||e.logger.warn("IPC channel is not available. process.send is undefined."),r.actions?.forEach(n=>{if(n.config.templates===void 0)return;let o={};Object.entries(n.config.templates).forEach(([p,f])=>{try{o[p]=e.templating.compile(f)}catch(u){e.logger.error(`Error compiling template ${p} for action ${n.identifier}`,u)}}),n.config.parsedTemplates=o})}init=()=>Promise.resolve();start=()=>Promise.resolve();stop=()=>Promise.resolve();set callbackFunction(r){this.connectorSDK.receiver.registerCallback(this.#t(r))}get connectorSDK(){return this.#e}#t(r){return async e=>{let n=await this.#e.receiver.getActionConfig(e);return n?r(e,n):this.#e.receiver.responses.badRequest("Action not found")(e)}}};var c=class extends s{CONNECTOR_INSTANCE="XOD_CONNECTOR_DUMMY_NODE_CONFIG";init=async()=>{let{config:r}=this.connectorSDK,e=r.failProbability||0;e>0&&this.connectorSDK.logger.debug("Fail probability set to",e);let n=()=>Math.random()<e;this.callbackFunction=async o=>(this.connectorSDK.logger.info("Received message: ",o.testRun?"(test run)":"",o.eventId,o.payload),n()?(this.connectorSDK.logger.error("Dummy process failed"),this.connectorSDK.receiver.responses.internalServerError("Dummy process failed")(o)):this.connectorSDK.receiver.responses.ok()(o))}};0&&(module.exports={ConnectorRunnerDummyNode});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../libs/connector-runner-dummy-node/src/index.ts", "../../../libs/connector-runtime-sdk/src/lib/connector-runtime.ts", "../../../libs/connector-runner-dummy-node/src/lib/connector-runner-dummy-node.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './lib/connector-runner-dummy-node';\n", "import process from 'node:process';\n\nimport { ConnectorRuntimeInterface } from './connector-runtime.interface';\nimport { CompileDelegate, ConnectorSDKInterface } from './sdk';\nimport {\n ActionInterface,\n BaseConnectorConfig,\n ConnectorInterface,\n KafkaCallbackResponse,\n XodJobType,\n} from './types';\n\nexport interface IpcMessage {\n cmd: string;\n message: string;\n}\n\nexport abstract class ConnectorRuntimeSDK<\n T extends BaseConnectorConfig = BaseConnectorConfig,\n> implements ConnectorRuntimeInterface {\n readonly #IPC_CHANNEL = 'connector-runtime';\n\n readonly #connectorSDK: ConnectorSDKInterface<T>;\n\n constructor(\n connector: ConnectorInterface,\n connectorSDK: ConnectorSDKInterface,\n ) {\n this.#connectorSDK = connectorSDK as ConnectorSDKInterface<T>;\n\n if (process.on) {\n process.on('message', (message: IpcMessage) => {\n if (message.cmd === this.#IPC_CHANNEL) {\n connectorSDK.logger.verbose(\n `${process.pid} Received message from parent process:`,\n message,\n );\n }\n });\n } else {\n connectorSDK.logger.warn(\n 'IPC channel is not available. process.on is undefined.',\n );\n }\n\n if (!process.send) {\n // Check if process.send is available\n connectorSDK.logger.warn(\n 'IPC channel is not available. process.send is undefined.',\n );\n }\n\n // eslint-disable-next-line no-restricted-syntax\n connector.actions?.forEach((action: ActionInterface) => {\n if (action.config['templates'] === undefined) {\n return;\n }\n\n const containers: {\n [key: string]: CompileDelegate;\n } = {};\n\n Object.entries(action.config['templates']).forEach(([key, value]) => {\n try {\n // eslint-disable-next-line security/detect-object-injection\n containers[key] = connectorSDK.templating.compile(value);\n } catch (error: unknown) {\n connectorSDK.logger.error(\n `Error compiling template ${key} for action ${action.identifier}`,\n error,\n );\n }\n });\n\n // eslint-disable-next-line no-param-reassign\n action.config['parsedTemplates'] = containers;\n });\n }\n\n public init: () => Promise<void> = () => Promise.resolve();\n\n public start: () => Promise<void> = () => Promise.resolve();\n\n public stop: () => Promise<void> = () => Promise.resolve();\n\n set callbackFunction(\n callback: (\n message: XodJobType,\n action: ActionInterface,\n ) => Promise<KafkaCallbackResponse>,\n ) {\n this.connectorSDK.receiver.registerCallback(\n this.#enrichWithActionConfig(callback),\n );\n }\n\n protected get connectorSDK(): ConnectorSDKInterface<T> {\n return this.#connectorSDK;\n }\n\n #enrichWithActionConfig(\n callbackFunction: (\n message: XodJobType,\n action: ActionInterface,\n ) => Promise<KafkaCallbackResponse>,\n ): (message: XodJobType) => Promise<KafkaCallbackResponse> {\n return async (message: XodJobType) => {\n const action = await this.#connectorSDK.receiver.getActionConfig(message);\n if (!action) {\n return this.#connectorSDK.receiver.responses.badRequest(\n 'Action not found',\n )(message);\n }\n return callbackFunction(message, action);\n };\n }\n}\n", "import {\n
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAoB,2BAiBEC,EAAf,KAEgC,CAC5BC,GAAe,oBAEfC,GAET,YACEC,EACAC,EACA,CACA,KAAKF,GAAgBE,EAEjB,EAAAC,QAAQ,GACV,EAAAA,QAAQ,GAAG,UAAYC,GAAwB,CACzCA,EAAQ,MAAQ,KAAKL,IACvBG,EAAa,OAAO,QAClB,GAAG,EAAAC,QAAQ,GAAG,yCACdC,CACF,CAEJ,CAAC,EAEDF,EAAa,OAAO,KAClB,wDACF,EAGG,EAAAC,QAAQ,MAEXD,EAAa,OAAO,KAClB,0DACF,EAIFD,EAAU,SAAS,QAASI,GAA4B,CACtD,GAAIA,EAAO,OAAO,YAAiB,OACjC,OAGF,IAAMC,EAEF,CAAC,EAEL,OAAO,QAAQD,EAAO,OAAO,SAAY,EAAE,QAAQ,CAAC,CAACE,EAAKC,CAAK,IAAM,CACnE,GAAI,CAEFF,EAAWC,CAAG,EAAIL,EAAa,WAAW,QAAQM,CAAK,CACzD,OAASC,EAAgB,CACvBP,EAAa,OAAO,MAClB,4BAA4BK,CAAG,eAAeF,EAAO,UAAU,GAC/DI,CACF,CACF,CACF,CAAC,EAGDJ,EAAO,OAAO,gBAAqBC,CACrC,CAAC,CACH,CAEO,KAA4B,IAAM,QAAQ,QAAQ,EAElD,MAA6B,IAAM,QAAQ,QAAQ,EAEnD,KAA4B,IAAM,QAAQ,QAAQ,EAEzD,IAAI,iBACFI,EAIA,CACA,KAAK,aAAa,SAAS,iBACzB,KAAKC,GAAwBD,CAAQ,CACvC,CACF,CAEA,IAAc,cAAyC,CACrD,OAAO,KAAKV,EACd,CAEAW,GACEC,EAIyD,CACzD,MAAO,OAAOR,GAAwB,CACpC,IAAMC,EAAS,MAAM,KAAKL,GAAc,SAAS,gBAAgBI,CAAO,EACxE,OAAKC,EAKEO,EAAiBR,EAASC,CAAM,EAJ9B,KAAKL,GAAc,SAAS,UAAU,WAC3C,kBACF,EAAEI,CAAO,CAGb,CACF,CACF,
|
|
6
|
-
"names": ["index_exports", "__export", "ConnectorRunnerDummyNode", "__toCommonJS", "import_node_process", "ConnectorRuntimeSDK", "#IPC_CHANNEL", "#connectorSDK", "connector", "connectorSDK", "process", "message", "action", "containers", "key", "value", "error", "callback", "#enrichWithActionConfig", "callbackFunction", "ConnectorRunnerDummyNode", "ConnectorRuntimeSDK", "config", "failProbability", "dummyProcessFailed", "message"
|
|
4
|
+
"sourcesContent": ["export * from './lib/connector-runner-dummy-node';\n", "import process from 'node:process';\n\nimport { ConnectorRuntimeInterface } from './connector-runtime.interface';\nimport { CompileDelegate, ConnectorSDKInterface } from './sdk';\nimport {\n ActionInterface,\n BaseConnectorConfig,\n ConnectorInterface,\n KafkaCallbackResponse,\n XodJobType,\n} from './types';\n\nexport interface IpcMessage {\n cmd: string;\n message: string;\n}\n\nexport abstract class ConnectorRuntimeSDK<\n T extends BaseConnectorConfig = BaseConnectorConfig,\n> implements ConnectorRuntimeInterface {\n readonly #IPC_CHANNEL = 'connector-runtime';\n\n readonly #connectorSDK: ConnectorSDKInterface<T>;\n\n constructor(\n connector: ConnectorInterface,\n connectorSDK: ConnectorSDKInterface,\n ) {\n this.#connectorSDK = connectorSDK as ConnectorSDKInterface<T>;\n\n if (process.on) {\n process.on('message', (message: IpcMessage) => {\n if (message.cmd === this.#IPC_CHANNEL) {\n connectorSDK.logger.verbose(\n `${process.pid} Received message from parent process:`,\n message,\n );\n }\n });\n } else {\n connectorSDK.logger.warn(\n 'IPC channel is not available. process.on is undefined.',\n );\n }\n\n if (!process.send) {\n // Check if process.send is available\n connectorSDK.logger.warn(\n 'IPC channel is not available. process.send is undefined.',\n );\n }\n\n // eslint-disable-next-line no-restricted-syntax\n connector.actions?.forEach((action: ActionInterface) => {\n if (action.config['templates'] === undefined) {\n return;\n }\n\n const containers: {\n [key: string]: CompileDelegate;\n } = {};\n\n Object.entries(action.config['templates']).forEach(([key, value]) => {\n try {\n // eslint-disable-next-line security/detect-object-injection\n containers[key] = connectorSDK.templating.compile(value);\n } catch (error: unknown) {\n connectorSDK.logger.error(\n `Error compiling template ${key} for action ${action.identifier}`,\n error,\n );\n }\n });\n\n // eslint-disable-next-line no-param-reassign\n action.config['parsedTemplates'] = containers;\n });\n }\n\n public init: () => Promise<void> = () => Promise.resolve();\n\n public start: () => Promise<void> = () => Promise.resolve();\n\n public stop: () => Promise<void> = () => Promise.resolve();\n\n set callbackFunction(\n callback: (\n message: XodJobType,\n action: ActionInterface,\n ) => Promise<KafkaCallbackResponse>,\n ) {\n this.connectorSDK.receiver.registerCallback(\n this.#enrichWithActionConfig(callback),\n );\n }\n\n protected get connectorSDK(): ConnectorSDKInterface<T> {\n return this.#connectorSDK;\n }\n\n #enrichWithActionConfig(\n callbackFunction: (\n message: XodJobType,\n action: ActionInterface,\n ) => Promise<KafkaCallbackResponse>,\n ): (message: XodJobType) => Promise<KafkaCallbackResponse> {\n return async (message: XodJobType) => {\n const action = await this.#connectorSDK.receiver.getActionConfig(message);\n if (!action) {\n return this.#connectorSDK.receiver.responses.badRequest(\n 'Action not found',\n )(message);\n }\n return callbackFunction(message, action);\n };\n }\n}\n", "import {\n BaseConnectorConfig,\n ConnectorRuntimeSDK,\n KafkaCallbackResponse,\n XodJobType,\n} from '@transai/connector-runtime-sdk';\n\nexport class ConnectorRunnerDummyNode extends ConnectorRuntimeSDK<\n {\n failProbability?: number;\n } & BaseConnectorConfig\n> {\n readonly CONNECTOR_INSTANCE: string = 'XOD_CONNECTOR_DUMMY_NODE_CONFIG';\n\n override init = async (): Promise<void> => {\n const { config } = this.connectorSDK;\n\n const failProbability = config.failProbability || 0.0;\n if (failProbability > 0) {\n this.connectorSDK.logger.debug(\n 'Fail probability set to',\n failProbability,\n );\n }\n\n const dummyProcessFailed = (): boolean => {\n return Math.random() < failProbability;\n };\n\n this.callbackFunction = async (\n message: XodJobType,\n ): Promise<KafkaCallbackResponse> => {\n this.connectorSDK.logger.info(\n 'Received message: ',\n message.testRun ? '(test run)' : '',\n message.eventId,\n message.payload,\n );\n\n if (dummyProcessFailed()) {\n this.connectorSDK.logger.error('Dummy process failed');\n return this.connectorSDK.receiver.responses.internalServerError(\n 'Dummy process failed',\n )(message);\n }\n\n return this.connectorSDK.receiver.responses.ok()(message);\n };\n };\n}\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAoB,2BAiBEC,EAAf,KAEgC,CAC5BC,GAAe,oBAEfC,GAET,YACEC,EACAC,EACA,CACA,KAAKF,GAAgBE,EAEjB,EAAAC,QAAQ,GACV,EAAAA,QAAQ,GAAG,UAAYC,GAAwB,CACzCA,EAAQ,MAAQ,KAAKL,IACvBG,EAAa,OAAO,QAClB,GAAG,EAAAC,QAAQ,GAAG,yCACdC,CACF,CAEJ,CAAC,EAEDF,EAAa,OAAO,KAClB,wDACF,EAGG,EAAAC,QAAQ,MAEXD,EAAa,OAAO,KAClB,0DACF,EAIFD,EAAU,SAAS,QAASI,GAA4B,CACtD,GAAIA,EAAO,OAAO,YAAiB,OACjC,OAGF,IAAMC,EAEF,CAAC,EAEL,OAAO,QAAQD,EAAO,OAAO,SAAY,EAAE,QAAQ,CAAC,CAACE,EAAKC,CAAK,IAAM,CACnE,GAAI,CAEFF,EAAWC,CAAG,EAAIL,EAAa,WAAW,QAA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ConnectorRuntimeSDK", "#IPC_CHANNEL", "#connectorSDK", "connector", "connectorSDK", "process", "message", "action", "containers", "key", "value", "error", "callback", "#enrichWithActionConfig", "callbackFunction", "ConnectorRunnerDummyNode", "ConnectorRuntimeSDK", "config", "failProbability", "dummyProcessFailed", "message"]
|
|
7
7
|
}
|