UNPKG

@gravityai-dev/gravity-server

Version:

Integration SDK for the Gravity AI orchestration platform - Connect any AI platform in minutes

70 lines 2.25 kB
"use strict"; /** * Publisher for Gravity AI * * Handles publishing messages to Redis channels. * This is the client-facing publisher that external services use. * * Key features: * - Simple API for publishing to channels * - Automatic connection management * - Support for Redis credentials-based initialization * * Usage: * ```typescript * const publisher = Publisher.fromRedisCredentials({ * host: 'localhost', * port: 6379, * password: 'your-password' * }, 'my-service'); * await publisher.publishEvent('channel', { data: 'hello' }); * ``` */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Publisher = void 0; const RedisManager_1 = require("../RedisManager"); const types_1 = require("../types"); class Publisher { constructor(options, providerId) { // Use connection pooling from RedisManager this.redis = (0, RedisManager_1.getStandardConnection)(options); this.providerId = providerId; } static fromRedisCredentials(redisOptions, providerId) { return new Publisher(redisOptions, providerId); } static fromConfig(host, port, password, providerId, username, db, token, tls) { const redisOptions = (0, RedisManager_1.getOptionsFromConfig)(host, port, username, password, token); if (tls !== undefined) { redisOptions.tls = tls; } return new Publisher(redisOptions, providerId); } getProviderId() { return this.providerId; } getRedisConnection() { return this.redis; } /** * Publish system-level events * Used by EventBus and system services */ async publishSystem(message) { await this.redis.publish(types_1.SYSTEM_CHANNEL, JSON.stringify(message)); } /** * Publish to arbitrary event channels * Used by EventBus, n8n resolver, and health monitor */ async publishEvent(eventType, payload) { await this.redis.publish(eventType, JSON.stringify(payload)); } async disconnect() { // Don't close shared connections - they're managed by RedisManager // Just clear our reference this.redis = null; } } exports.Publisher = Publisher; //# sourceMappingURL=Publisher.js.map