UNPKG

@nu-art/google-services

Version:
29 lines (28 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ModuleBE_GooglePubSub = void 0; const ts_common_1 = require("@nu-art/ts-common"); const pubsub_1 = require("@google-cloud/pubsub"); const ModuleBE_Auth_1 = require("./ModuleBE_Auth"); class ModuleBE_GooglePubSub_Class extends ts_common_1.Module { project(projectId, authKey = projectId) { const authObject = ModuleBE_Auth_1.ModuleBE_Auth.getAuth(authKey, []); const auth = authObject.auth; // @ts-ignore const pubSub = new pubsub_1.PubSub({ projectId, auth }); return { createTopic: async (topicName) => { const [topic] = await pubSub.createTopic(topicName); return topic; }, topic: (topicName, options) => { const topic = pubSub.topic(topicName, options); return { publishJson: async (json) => topic.publishJSON(json), publish: async (buffer) => topic.publish(buffer) }; } }; } } exports.ModuleBE_GooglePubSub = new ModuleBE_GooglePubSub_Class();