UNPKG

@fairmint/canton-node-sdk

Version:
38 lines 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createWebSocketOperation = createWebSocketOperation; const zod_1 = require("zod"); const ws_1 = require("../ws"); const errors_1 = require("../errors"); function createWebSocketOperation(config) { return class WebSocketOperation { constructor(client) { this.client = client; } validateParams(params, schema) { try { return schema.parse(params); } catch (error) { if (error instanceof zod_1.z.ZodError) { throw new errors_1.ValidationError(`Parameter validation failed: ${error.issues.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}`); } throw error; } } async subscribe(params, handlers) { const validatedParams = this.validateParams(params, config.paramsSchema); const wsClient = new ws_1.WebSocketClient(this.client); const path = config.buildPath(validatedParams, this.client.getApiUrl(), this.client); const request = await config.buildRequestMessage(validatedParams, this.client); const wrappedHandlers = config.transformInbound ? { ...handlers, onMessage: (msg) => handlers.onMessage(config.transformInbound(msg)), } : handlers; return wsClient.connect(path, request, wrappedHandlers); } }; } //# sourceMappingURL=WebSocketOperationFactory.js.map