@anchan828/nest-cloud-run-queue-pubsub-publisher 3.1.7 → 3.1.9

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.
@@ -0,0 +1,3 @@
1
+ export declare const PUBSUB_PUBLISHER_MODULE_OPTIONS = "PUBSUB_PUBLISHER_MODULE_OPTIONS";
2
+ export declare const PUBSUB = "PUBSUB";
3
+ export declare const ERROR_TOPIC_NOT_FOUND = "Topic not found. Please set topic name.";
@@ -0,0 +1,3 @@
1
+ export const PUBSUB_PUBLISHER_MODULE_OPTIONS = "PUBSUB_PUBLISHER_MODULE_OPTIONS";
2
+ export const PUBSUB = "PUBSUB";
3
+ export const ERROR_TOPIC_NOT_FOUND = "Topic not found. Please set topic name.";
@@ -0,0 +1,4 @@
1
+ export { PUBSUB, PUBSUB_PUBLISHER_MODULE_OPTIONS } from "./constants";
2
+ export { PubSubPublisherModuleAsyncOptions, PubSubPublisherModuleOptions, PubSubPublisherModuleOptionsFactory, PublishData, } from "./interfaces";
3
+ export { PubSubPublisherModule } from "./publish.module";
4
+ export { PubSubPublisherService } from "./publish.service";
@@ -0,0 +1,3 @@
1
+ export { PUBSUB, PUBSUB_PUBLISHER_MODULE_OPTIONS } from "./constants";
2
+ export { PubSubPublisherModule } from "./publish.module";
3
+ export { PubSubPublisherService } from "./publish.service";
@@ -0,0 +1,15 @@
1
+ import { Message, ModuleAsyncOptions, ModuleOptions, ModuleOptionsFactory, PublishExtraConfig } from "@anchan828/nest-cloud-run-queue-common";
2
+ import { Attributes } from "@google-cloud/pubsub";
3
+ import { ClientConfig } from "@google-cloud/pubsub/build/src/pubsub";
4
+ import { PublishOptions } from "@google-cloud/pubsub/build/src/topic";
5
+ export interface PubSubPublisherModuleOptions extends ModuleOptions {
6
+ topic?: string;
7
+ clientConfig?: ClientConfig;
8
+ publishConfig?: PublishOptions;
9
+ extraConfig?: PublishExtraConfig<PublishData<any>>;
10
+ }
11
+ export type PubSubPublisherModuleAsyncOptions = ModuleAsyncOptions<PubSubPublisherModuleOptions>;
12
+ export type PubSubPublisherModuleOptionsFactory = ModuleOptionsFactory<PubSubPublisherModuleOptions>;
13
+ export interface PublishData<T> extends Message<T> {
14
+ attributes?: Attributes;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { PubSub } from "@google-cloud/pubsub";
2
+ import { PubSubPublisherModuleOptions } from "./interfaces";
3
+ export declare function createPubSub(options: PubSubPublisherModuleOptions): PubSub;
@@ -0,0 +1,4 @@
1
+ import { PubSub } from "@google-cloud/pubsub";
2
+ export function createPubSub(options) {
3
+ return new PubSub(options.clientConfig);
4
+ }
@@ -0,0 +1,6 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+ import { PubSubPublisherModuleAsyncOptions, PubSubPublisherModuleOptions } from "./interfaces";
3
+ export declare class PubSubPublisherModule {
4
+ static register(options?: PubSubPublisherModuleOptions): DynamicModule;
5
+ static registerAsync(options: PubSubPublisherModuleAsyncOptions): DynamicModule;
6
+ }
@@ -0,0 +1,50 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var PubSubPublisherModule_1;
8
+ import { createAsyncProviders, createOptionProvider } from "@anchan828/nest-cloud-run-queue-common";
9
+ import { Module } from "@nestjs/common";
10
+ import { PUBSUB, PUBSUB_PUBLISHER_MODULE_OPTIONS } from "./constants";
11
+ import { createPubSub } from "./providers";
12
+ import { PubSubPublisherService } from "./publish.service";
13
+ let PubSubPublisherModule = PubSubPublisherModule_1 = class PubSubPublisherModule {
14
+ static register(options = {}) {
15
+ const providers = [
16
+ createOptionProvider(PUBSUB_PUBLISHER_MODULE_OPTIONS, options),
17
+ PubSubPublisherService,
18
+ { provide: PUBSUB, useFactory: () => createPubSub(options) },
19
+ ];
20
+ return {
21
+ exports: providers,
22
+ global: true,
23
+ module: PubSubPublisherModule_1,
24
+ providers,
25
+ };
26
+ }
27
+ static registerAsync(options) {
28
+ const asyncProviders = [
29
+ ...createAsyncProviders(PUBSUB_PUBLISHER_MODULE_OPTIONS, options),
30
+ PubSubPublisherService,
31
+ {
32
+ inject: [PUBSUB_PUBLISHER_MODULE_OPTIONS],
33
+ provide: PUBSUB,
34
+ useFactory: (options) => createPubSub(options),
35
+ },
36
+ ];
37
+ const providers = [...asyncProviders];
38
+ return {
39
+ exports: providers,
40
+ global: true,
41
+ imports: [...(options.imports || [])],
42
+ module: PubSubPublisherModule_1,
43
+ providers,
44
+ };
45
+ }
46
+ };
47
+ PubSubPublisherModule = PubSubPublisherModule_1 = __decorate([
48
+ Module({})
49
+ ], PubSubPublisherModule);
50
+ export { PubSubPublisherModule };
@@ -0,0 +1,12 @@
1
+ import { PubSub } from "@google-cloud/pubsub";
2
+ import { PublishOptions } from "@google-cloud/pubsub/build/src/topic";
3
+ import { PubSubPublisherModuleOptions, PublishData } from "./interfaces";
4
+ export declare class PubSubPublisherService {
5
+ private readonly options;
6
+ private readonly pubsub;
7
+ constructor(options: PubSubPublisherModuleOptions, pubsub: PubSub);
8
+ publish<T>(message: PublishData<T>, options?: PublishOptions & {
9
+ topic?: string;
10
+ }): Promise<string>;
11
+ private getTopicName;
12
+ }
@@ -0,0 +1,50 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { PubSub } from "@google-cloud/pubsub";
14
+ import { Inject, Injectable } from "@nestjs/common";
15
+ import { ERROR_TOPIC_NOT_FOUND, PUBSUB, PUBSUB_PUBLISHER_MODULE_OPTIONS } from "./constants";
16
+ let PubSubPublisherService = class PubSubPublisherService {
17
+ constructor(options, pubsub) {
18
+ this.options = options;
19
+ this.pubsub = pubsub;
20
+ }
21
+ async publish(message, options) {
22
+ const topicName = this.getTopicName(options);
23
+ const topic = this.pubsub.topic(topicName, Object.assign({}, this.options.publishConfig, options));
24
+ const { attributes, ...data } = this.options.extraConfig?.prePublish
25
+ ? await this.options.extraConfig.prePublish(message)
26
+ : message;
27
+ const messageId = await topic.publishMessage({
28
+ attributes,
29
+ data: Buffer.from(JSON.stringify(data, this.options.extraConfig?.stringifyReplacer)),
30
+ });
31
+ if (this.options.extraConfig?.postPublish) {
32
+ await this.options.extraConfig?.postPublish(message, messageId);
33
+ }
34
+ return messageId;
35
+ }
36
+ getTopicName(options) {
37
+ const topic = this.options.topic || options?.topic;
38
+ if (!topic) {
39
+ throw new Error(ERROR_TOPIC_NOT_FOUND);
40
+ }
41
+ return topic;
42
+ }
43
+ };
44
+ PubSubPublisherService = __decorate([
45
+ Injectable(),
46
+ __param(0, Inject(PUBSUB_PUBLISHER_MODULE_OPTIONS)),
47
+ __param(1, Inject(PUBSUB)),
48
+ __metadata("design:paramtypes", [Object, PubSub])
49
+ ], PubSubPublisherService);
50
+ export { PubSubPublisherService };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anchan828/nest-cloud-run-queue-pubsub-publisher",
3
- "version": "3.1.7",
3
+ "version": "3.1.9",
4
4
  "description": "> TODO: description",
5
5
  "homepage": "https://github.com/anchan828/nest-cloud-run-queue/tree/master/packages/pubsub-publish#readme",
6
6
  "bugs": {
@@ -12,8 +12,8 @@
12
12
  },
13
13
  "license": "MIT",
14
14
  "author": "anchan828 <anchan828@gmail.com>",
15
- "main": "./dist/index.js",
16
- "types": "./dist/index.d.ts",
15
+ "main": "dist/cjs/index.js",
16
+ "types": "dist/cjs/index.d.ts",
17
17
  "directories": {
18
18
  "dist": "dist"
19
19
  },
@@ -21,7 +21,7 @@
21
21
  "dist"
22
22
  ],
23
23
  "scripts": {
24
- "build": "tsc -p tsconfig.build.json",
24
+ "build": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json",
25
25
  "build:watch": "tsc --watch",
26
26
  "copy:license": "cp ../../LICENSE ./",
27
27
  "lint": "TIMING=1 eslint '**/*.ts'",
@@ -33,11 +33,11 @@
33
33
  "watch": "tsc -w"
34
34
  },
35
35
  "dependencies": {
36
- "@anchan828/nest-cloud-run-queue-common": "^3.1.7",
36
+ "@anchan828/nest-cloud-run-queue-common": "^3.1.9",
37
37
  "@google-cloud/pubsub": "^4.0.6"
38
38
  },
39
39
  "devDependencies": {
40
- "@nestjs/common": "10.3.10",
40
+ "@nestjs/common": "10.4.1",
41
41
  "rxjs": "7.8.1"
42
42
  },
43
43
  "peerDependencies": {
@@ -47,5 +47,19 @@
47
47
  "access": "public"
48
48
  },
49
49
  "packageManager": "npm@10.8.2",
50
- "gitHead": "d63c1143192396b815ac6b72d54925971d00497a"
50
+ "exports": {
51
+ ".": {
52
+ "import": {
53
+ "types": "./dist/esm/index.d.ts",
54
+ "default": "./dist/esm/index.js"
55
+ },
56
+ "require": {
57
+ "types": "./dist/cjs/index.d.ts",
58
+ "default": "./dist/cjs/index.js"
59
+ },
60
+ "types": "./dist/cjs/index.d.ts",
61
+ "default": "./dist/cjs/index.js"
62
+ }
63
+ },
64
+ "gitHead": "9a7d8adc63d5610993cebdfcd230595ab549a914"
51
65
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes