@anchan828/nest-cloud-run-queue-worker 1.0.12 → 1.0.13
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/interfaces.d.ts +2 -3
- package/dist/util.d.ts +9 -0
- package/dist/util.js +27 -1
- package/dist/worker.service.js +10 -3
- package/package.json +3 -4
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { QueueWorkerName, ModuleAsyncOptions, ModuleOptions, ModuleOptionsFactory, Message } from "@anchan828/nest-cloud-run-queue-common";
|
|
3
2
|
import { RequestMappingMetadata } from "@nestjs/common";
|
|
4
3
|
import { Injectable } from "@nestjs/common/interfaces";
|
|
@@ -72,8 +71,8 @@ export interface QueueWorkerProcessDecoratorArgs {
|
|
|
72
71
|
*/
|
|
73
72
|
priority: number;
|
|
74
73
|
}
|
|
75
|
-
export declare type QueueWorkerRawMessage = {
|
|
76
|
-
readonly data?: string |
|
|
74
|
+
export declare type QueueWorkerRawMessage<T = any> = {
|
|
75
|
+
readonly data?: string | null | Message<T>;
|
|
77
76
|
readonly headers?: Record<string, string>;
|
|
78
77
|
} & Record<string, any>;
|
|
79
78
|
export declare type QueueWorkerDecodedMessage<T = any> = {
|
package/dist/util.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Message } from "@anchan828/nest-cloud-run-queue-common";
|
|
1
2
|
/**
|
|
2
3
|
* parse json string to javascript object.
|
|
3
4
|
* JSON.parse has receiver for Date.parse.
|
|
@@ -15,3 +16,11 @@ export declare const parseJSON: <T>(json: string) => T;
|
|
|
15
16
|
export declare function sortByPriority<T extends {
|
|
16
17
|
priority: number;
|
|
17
18
|
}>(items: T[]): T[];
|
|
19
|
+
/**
|
|
20
|
+
* Check if a string is base64 encoded.
|
|
21
|
+
*
|
|
22
|
+
* @export
|
|
23
|
+
* @param {string} value
|
|
24
|
+
* @return {*} {boolean}
|
|
25
|
+
*/
|
|
26
|
+
export declare function isBase64(value?: string | null | Message): value is string;
|
package/dist/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sortByPriority = exports.parseJSON = void 0;
|
|
3
|
+
exports.isBase64 = exports.sortByPriority = exports.parseJSON = void 0;
|
|
4
4
|
const dateRegExp = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
5
5
|
/**
|
|
6
6
|
* parse json string to javascript object.
|
|
@@ -31,3 +31,29 @@ function sortByPriority(items) {
|
|
|
31
31
|
return items.sort((x, y) => x.priority - y.priority);
|
|
32
32
|
}
|
|
33
33
|
exports.sortByPriority = sortByPriority;
|
|
34
|
+
const customBase64Strs = ["e30"];
|
|
35
|
+
/**
|
|
36
|
+
* Check if a string is base64 encoded.
|
|
37
|
+
*
|
|
38
|
+
* @export
|
|
39
|
+
* @param {string} value
|
|
40
|
+
* @return {*} {boolean}
|
|
41
|
+
*/
|
|
42
|
+
function isBase64(value) {
|
|
43
|
+
if (!value) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (typeof value !== "string") {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const len = value.length;
|
|
50
|
+
if (len <= 4 && customBase64Strs.some((base64Str) => value.startsWith(base64Str))) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
if ((len === 4 && ![2, 3].every((n) => value[n] === "=")) || !len || len % 4 !== 0 || /[^A-Z0-9+\/=]/i.test(value)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const firstPaddingChar = value.indexOf("=");
|
|
57
|
+
return (firstPaddingChar === -1 || firstPaddingChar === len - 1 || (firstPaddingChar === len - 2 && value[len - 1] === "="));
|
|
58
|
+
}
|
|
59
|
+
exports.isBase64 = isBase64;
|
package/dist/worker.service.js
CHANGED
|
@@ -35,7 +35,6 @@ var _QueueWorkerService_instances, _QueueWorkerService__allWorkers, _QueueWorker
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.QueueWorkerService = void 0;
|
|
37
37
|
const common_1 = require("@nestjs/common");
|
|
38
|
-
const class_validator_1 = require("class-validator");
|
|
39
38
|
const constants_1 = require("./constants");
|
|
40
39
|
const explorer_service_1 = require("./explorer.service");
|
|
41
40
|
const interfaces_1 = require("./interfaces");
|
|
@@ -55,7 +54,15 @@ let QueueWorkerService = class QueueWorkerService {
|
|
|
55
54
|
});
|
|
56
55
|
}
|
|
57
56
|
decodeMessage(message) {
|
|
58
|
-
|
|
57
|
+
let data;
|
|
58
|
+
if ((0, util_1.isBase64)(message.data)) {
|
|
59
|
+
// pubsub
|
|
60
|
+
data = this.decodeData(message.data);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// tasks / http
|
|
64
|
+
data = message;
|
|
65
|
+
}
|
|
59
66
|
if (!data.name) {
|
|
60
67
|
throw new common_1.BadRequestException(constants_1.ERROR_QUEUE_WORKER_NAME_NOT_FOUND);
|
|
61
68
|
}
|
|
@@ -105,7 +112,7 @@ let QueueWorkerService = class QueueWorkerService {
|
|
|
105
112
|
if (data instanceof Uint8Array) {
|
|
106
113
|
data = new TextDecoder("utf8").decode(data);
|
|
107
114
|
}
|
|
108
|
-
if ((0,
|
|
115
|
+
if ((0, util_1.isBase64)(data)) {
|
|
109
116
|
data = Buffer.from(data, "base64").toString();
|
|
110
117
|
}
|
|
111
118
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anchan828/nest-cloud-run-queue-worker",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"homepage": "https://github.com/anchan828/nest-cloud-run-queue/tree/master/packages/worker#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -33,8 +33,7 @@
|
|
|
33
33
|
"watch": "tsc -w"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@anchan828/nest-cloud-run-queue-common": "^1.0.
|
|
37
|
-
"class-validator": "0.13.2"
|
|
36
|
+
"@anchan828/nest-cloud-run-queue-common": "^1.0.13"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
39
|
"@nestjs/common": "8.4.5",
|
|
@@ -46,5 +45,5 @@
|
|
|
46
45
|
"publishConfig": {
|
|
47
46
|
"access": "public"
|
|
48
47
|
},
|
|
49
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "54936c9f95780c7c389cbacb4d824f4dedcb6678"
|
|
50
49
|
}
|