@anchan828/nest-cloud-run-queue-tasks-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/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 +16 -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 +8 -0
- package/dist/esm/publish.service.js +57 -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
- /package/dist/{publish.service.js → cjs/publish.service.js} +0 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { TasksPublisherModuleAsyncOptions, TasksPublisherModuleOptions, TasksPublisherModuleOptionsFactory, PublishConfig, PublishData, PublishOptions, } from "./interfaces";
|
|
2
|
+
export { TASKS_CLIENT } from "./constants";
|
|
3
|
+
export { TasksPublisherModule } from "./publish.module";
|
|
4
|
+
export { TasksPublisherService } from "./publish.service";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Message, ModuleAsyncOptions, ModuleOptions, ModuleOptionsFactory, PublishExtraConfig } from "@anchan828/nest-cloud-run-queue-common";
|
|
2
|
+
import type { CloudTasksClient } from "@google-cloud/tasks";
|
|
3
|
+
import type { google } from "@google-cloud/tasks/build/protos/protos";
|
|
4
|
+
export interface TasksPublisherModuleOptions extends ModuleOptions {
|
|
5
|
+
queue?: string;
|
|
6
|
+
clientConfig?: ConstructorParameters<typeof CloudTasksClient>[0];
|
|
7
|
+
publishConfig?: PublishConfig;
|
|
8
|
+
extraConfig?: PublishExtraConfig;
|
|
9
|
+
}
|
|
10
|
+
export type TasksPublisherModuleAsyncOptions = ModuleAsyncOptions<TasksPublisherModuleOptions>;
|
|
11
|
+
export type TasksPublisherModuleOptionsFactory = ModuleOptionsFactory<TasksPublisherModuleOptions>;
|
|
12
|
+
export type PublishConfig = Omit<google.cloud.tasks.v2.ITask, "name">;
|
|
13
|
+
export type PublishOptions = {
|
|
14
|
+
queue?: string;
|
|
15
|
+
} & PublishConfig;
|
|
16
|
+
export type PublishData<T> = Message<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { TasksPublisherModuleAsyncOptions, TasksPublisherModuleOptions } from "./interfaces";
|
|
3
|
+
export declare class TasksPublisherModule {
|
|
4
|
+
static register(options?: TasksPublisherModuleOptions): DynamicModule;
|
|
5
|
+
static registerAsync(options: TasksPublisherModuleAsyncOptions): 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 TasksPublisherModule_1;
|
|
8
|
+
import { createAsyncProviders, createOptionProvider } from "@anchan828/nest-cloud-run-queue-common";
|
|
9
|
+
import { Module } from "@nestjs/common";
|
|
10
|
+
import { TASKS_CLIENT, TASKS_PUBLISHER_MODULE_OPTIONS } from "./constants";
|
|
11
|
+
import { createClient } from "./providers";
|
|
12
|
+
import { TasksPublisherService } from "./publish.service";
|
|
13
|
+
let TasksPublisherModule = TasksPublisherModule_1 = class TasksPublisherModule {
|
|
14
|
+
static register(options = {}) {
|
|
15
|
+
const providers = [
|
|
16
|
+
createOptionProvider(TASKS_PUBLISHER_MODULE_OPTIONS, options),
|
|
17
|
+
TasksPublisherService,
|
|
18
|
+
{ provide: TASKS_CLIENT, useFactory: () => createClient(options) },
|
|
19
|
+
];
|
|
20
|
+
return {
|
|
21
|
+
exports: providers,
|
|
22
|
+
global: true,
|
|
23
|
+
module: TasksPublisherModule_1,
|
|
24
|
+
providers,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
static registerAsync(options) {
|
|
28
|
+
const asyncProviders = [
|
|
29
|
+
...createAsyncProviders(TASKS_PUBLISHER_MODULE_OPTIONS, options),
|
|
30
|
+
TasksPublisherService,
|
|
31
|
+
{
|
|
32
|
+
inject: [TASKS_PUBLISHER_MODULE_OPTIONS],
|
|
33
|
+
provide: TASKS_CLIENT,
|
|
34
|
+
useFactory: (options) => createClient(options),
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
const providers = [...asyncProviders];
|
|
38
|
+
return {
|
|
39
|
+
exports: providers,
|
|
40
|
+
global: true,
|
|
41
|
+
imports: [...(options.imports || [])],
|
|
42
|
+
module: TasksPublisherModule_1,
|
|
43
|
+
providers,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
TasksPublisherModule = TasksPublisherModule_1 = __decorate([
|
|
48
|
+
Module({})
|
|
49
|
+
], TasksPublisherModule);
|
|
50
|
+
export { TasksPublisherModule };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CloudTasksClient } from "@google-cloud/tasks";
|
|
2
|
+
import { PublishData, PublishOptions, TasksPublisherModuleOptions } from "./interfaces";
|
|
3
|
+
export declare class TasksPublisherService {
|
|
4
|
+
private readonly options;
|
|
5
|
+
private readonly client;
|
|
6
|
+
constructor(options: TasksPublisherModuleOptions, client: CloudTasksClient);
|
|
7
|
+
publish<T>(message: PublishData<T>, options?: PublishOptions): Promise<string>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 { CloudTasksClient } from "@google-cloud/tasks";
|
|
14
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
15
|
+
import { TASKS_CLIENT, TASKS_PUBLISHER_MODULE_OPTIONS } from "./constants";
|
|
16
|
+
let TasksPublisherService = class TasksPublisherService {
|
|
17
|
+
constructor(options, client) {
|
|
18
|
+
this.options = options;
|
|
19
|
+
this.client = client;
|
|
20
|
+
}
|
|
21
|
+
async publish(message, options) {
|
|
22
|
+
const taskMessage = this.options.extraConfig?.prePublish
|
|
23
|
+
? await this.options.extraConfig?.prePublish(message)
|
|
24
|
+
: message;
|
|
25
|
+
const [task] = await this.client.createTask({
|
|
26
|
+
parent: options?.queue || this.options.queue,
|
|
27
|
+
task: {
|
|
28
|
+
...this.options.publishConfig,
|
|
29
|
+
...options,
|
|
30
|
+
httpRequest: {
|
|
31
|
+
body: Buffer.from(JSON.stringify({ message: taskMessage || {} }, this.options.extraConfig?.stringifyReplacer)).toString("base64"),
|
|
32
|
+
headers: {
|
|
33
|
+
"content-type": "application/json",
|
|
34
|
+
...options?.httpRequest?.headers,
|
|
35
|
+
...this.options.publishConfig?.httpRequest?.headers,
|
|
36
|
+
},
|
|
37
|
+
httpMethod: options?.httpRequest?.httpMethod || this.options.publishConfig?.httpRequest?.httpMethod || "POST",
|
|
38
|
+
oauthToken: options?.httpRequest?.oauthToken || this.options.publishConfig?.httpRequest?.oauthToken,
|
|
39
|
+
oidcToken: options?.httpRequest?.oidcToken || this.options.publishConfig?.httpRequest?.oidcToken,
|
|
40
|
+
url: options?.httpRequest?.url || this.options.publishConfig?.httpRequest?.url,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const taskName = task?.name || "";
|
|
45
|
+
if (this.options.extraConfig?.postPublish) {
|
|
46
|
+
await this.options.extraConfig?.postPublish(taskMessage, taskName);
|
|
47
|
+
}
|
|
48
|
+
return taskName;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
TasksPublisherService = __decorate([
|
|
52
|
+
Injectable(),
|
|
53
|
+
__param(0, Inject(TASKS_PUBLISHER_MODULE_OPTIONS)),
|
|
54
|
+
__param(1, Inject(TASKS_CLIENT)),
|
|
55
|
+
__metadata("design:paramtypes", [Object, CloudTasksClient])
|
|
56
|
+
], TasksPublisherService);
|
|
57
|
+
export { TasksPublisherService };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anchan828/nest-cloud-run-queue-tasks-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/tasks": "^5.0.0"
|
|
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
|
|
File without changes
|