UNPKG

@villedemontreal/workit

Version:

Worker for Node.js system with pluggable clients that works with both AWS Step function and Camunda platform powered by TypeScript

60 lines 2.37 kB
"use strict"; /* * Copyright (c) 2025 Ville de Montreal. All rights reserved. * Licensed under the MIT license. * See LICENSE file in the project root for full license information. */ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Client = void 0; const inversify_1 = require("inversify"); require("reflect-metadata"); const identifiers_1 = require("../config/constants/identifiers"); let Client = class Client { constructor(client) { this._client = client; } async subscribe(handler) { if (handler != null) { this._onMessageReceived = handler; await this._startSubscriber(); } } async unsubscribe() { await this._execute((x) => x.unsubscribe()); } async _execute(action, onException) { try { return await action(this._client); } catch (ex) { if (!onException) { return Promise.resolve(); } return onException(this._client); } } async _startSubscriber() { if (this._client != null) { await this._execute((x) => x.subscribe(this._onMessageReceived)); } } }; Client = __decorate([ (0, inversify_1.injectable)(), __param(0, (0, inversify_1.inject)(identifiers_1.SERVICE_IDENTIFIER.camunda_client)), __metadata("design:paramtypes", [Object]) ], Client); exports.Client = Client; //# sourceMappingURL=client.js.map