@anchan828/nest-cloud-run-queue-pubsub-publisher 3.1.6 → 3.1.8
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.
- package/dist/{publish.service.js → cjs/publish.service.js} +1 -1
- package/dist/esm/constants.d.ts +3 -0
- package/dist/esm/constants.js +3 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/interfaces.d.ts +15 -0
- package/dist/esm/interfaces.js +1 -0
- package/dist/esm/providers.d.ts +3 -0
- package/dist/esm/providers.js +4 -0
- package/dist/esm/publish.module.d.ts +6 -0
- package/dist/esm/publish.module.js +50 -0
- package/dist/esm/publish.service.d.ts +12 -0
- package/dist/esm/publish.service.js +50 -0
- package/package.json +21 -7
- /package/dist/{constants.d.ts → cjs/constants.d.ts} +0 -0
- /package/dist/{constants.js → cjs/constants.js} +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{interfaces.d.ts → cjs/interfaces.d.ts} +0 -0
- /package/dist/{interfaces.js → cjs/interfaces.js} +0 -0
- /package/dist/{providers.d.ts → cjs/providers.d.ts} +0 -0
- /package/dist/{providers.js → cjs/providers.js} +0 -0
- /package/dist/{publish.module.d.ts → cjs/publish.module.d.ts} +0 -0
- /package/dist/{publish.module.js → cjs/publish.module.js} +0 -0
- /package/dist/{publish.service.d.ts → cjs/publish.service.d.ts} +0 -0
|
@@ -25,7 +25,7 @@ let PubSubPublisherService = class PubSubPublisherService {
|
|
|
25
25
|
const topicName = this.getTopicName(options);
|
|
26
26
|
const topic = this.pubsub.topic(topicName, Object.assign({}, this.options.publishConfig, options));
|
|
27
27
|
const { attributes, ...data } = this.options.extraConfig?.prePublish
|
|
28
|
-
? await this.options.extraConfig
|
|
28
|
+
? await this.options.extraConfig.prePublish(message)
|
|
29
29
|
: message;
|
|
30
30
|
const messageId = await topic.publishMessage({
|
|
31
31
|
attributes,
|
|
@@ -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,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,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.
|
|
3
|
+
"version": "3.1.8",
|
|
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": "
|
|
16
|
-
"types": "
|
|
15
|
+
"main": "dist/cjs/index.js",
|
|
16
|
+
"types": "dist/cjs/index.d.ts",
|
|
17
17
|
"directories": {
|
|
18
18
|
"dist": "dist"
|
|
19
19
|
},
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
|
-
"build": "tsc -p tsconfig.
|
|
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
|
-
"lint": "TIMING=1 eslint
|
|
27
|
+
"lint": "TIMING=1 eslint '**/*.ts'",
|
|
28
28
|
"lint:fix": "npm run lint -- --fix",
|
|
29
29
|
"prepublishOnly": "rm -rf dist && npm run build && rm -f dist/*.tsbuildinfo && npm run copy:license",
|
|
30
30
|
"test": "jest --coverage --logHeapUsage --runInBand",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"watch": "tsc -w"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@anchan828/nest-cloud-run-queue-common": "^3.1.
|
|
36
|
+
"@anchan828/nest-cloud-run-queue-common": "^3.1.8",
|
|
37
37
|
"@google-cloud/pubsub": "^4.0.6"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
@@ -47,5 +47,19 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"packageManager": "npm@10.8.2",
|
|
50
|
-
"
|
|
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": "c6565dcca7c5ed619b5929f3342f55804b05519c"
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|