gcf-common-lib 0.27.60 → 0.28.61
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/package.json +1 -1
- package/src/index.js +5 -5
- package/src/index.ts +14 -12
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -32,12 +32,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
exports.GcfCommon = exports.secretClient = exports.storage = exports.pubSub = exports.MongoDb = exports.RxJs = exports.SecretManager = exports.PubSub = exports.Storage = void 0;
|
|
33
33
|
const pubsub_1 = require("@google-cloud/pubsub");
|
|
34
34
|
const secret_manager_1 = require("@google-cloud/secret-manager");
|
|
35
|
+
const storage_1 = require("@google-cloud/storage");
|
|
35
36
|
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
36
37
|
const mapValues_1 = __importDefault(require("lodash/mapValues"));
|
|
37
38
|
const noop_1 = __importDefault(require("lodash/noop"));
|
|
38
39
|
const rxjs_1 = require("rxjs");
|
|
39
40
|
const utils_1 = require("./utils");
|
|
40
|
-
const storage_1 = require("@google-cloud/storage");
|
|
41
41
|
exports.Storage = __importStar(require("@google-cloud/storage"));
|
|
42
42
|
exports.PubSub = __importStar(require("@google-cloud/pubsub"));
|
|
43
43
|
exports.SecretManager = __importStar(require("@google-cloud/secret-manager"));
|
|
@@ -58,6 +58,10 @@ class GcfCommon {
|
|
|
58
58
|
* @param timeoutSec Seconds
|
|
59
59
|
*/
|
|
60
60
|
static async process(event, context, handler = rxjs_1.identity, timeoutSec = 535) {
|
|
61
|
+
const asyncHandler = async (_event, _context) => await handler(_event, _context);
|
|
62
|
+
return (0, rxjs_1.firstValueFrom)((0, rxjs_1.defer)(() => (0, rxjs_1.from)(asyncHandler(event, context))).pipe((0, rxjs_1.first)(), (0, rxjs_1.timeout)({ first: (0, utils_1.ms)({ s: timeoutSec }) })));
|
|
63
|
+
}
|
|
64
|
+
static async processOLd(event, context, handler = rxjs_1.identity, timeoutSec = 535) {
|
|
61
65
|
return Promise.race([(0, utils_1.timeoutAfter)(timeoutSec), handler(event, context)])
|
|
62
66
|
.then(async (res) => {
|
|
63
67
|
// console.log('res:', res);
|
|
@@ -69,10 +73,6 @@ class GcfCommon {
|
|
|
69
73
|
throw error;
|
|
70
74
|
});
|
|
71
75
|
}
|
|
72
|
-
static async processRxjs(event, context, handler = rxjs_1.identity, timeoutSec = 535) {
|
|
73
|
-
const asyncHandler = async (_event, _context) => await handler(_event, _context);
|
|
74
|
-
return (0, rxjs_1.defer)(() => (0, rxjs_1.from)(asyncHandler(event, context))).pipe((0, rxjs_1.first)(), (0, rxjs_1.timeout)({ first: (0, utils_1.ms)({ s: timeoutSec }) }));
|
|
75
|
-
}
|
|
76
76
|
static buildResponse(error) {
|
|
77
77
|
return {
|
|
78
78
|
error: {
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { PubSub } from '@google-cloud/pubsub';
|
|
2
2
|
import { SecretManagerServiceClient } from '@google-cloud/secret-manager';
|
|
3
|
+
import { Storage } from '@google-cloud/storage';
|
|
3
4
|
import { Options } from 'amqplib';
|
|
4
5
|
import isEmpty from 'lodash/isEmpty';
|
|
5
6
|
import mapValues from 'lodash/mapValues';
|
|
6
7
|
import noop from 'lodash/noop';
|
|
7
|
-
import { defer, first, from, identity, timeout } from 'rxjs';
|
|
8
|
+
import { defer, first, firstValueFrom, from, identity, timeout } from 'rxjs';
|
|
8
9
|
import { TContext, TEvent, TGSEvent, TMetadataOrAttributes, TPSEvent, TResponse } from './types';
|
|
9
10
|
import { ms, publishAmqp, timeoutAfter, withAmqpCh } from './utils';
|
|
10
11
|
import Dict = NodeJS.Dict;
|
|
11
|
-
import { Storage } from '@google-cloud/storage';
|
|
12
12
|
|
|
13
13
|
export * as Storage from '@google-cloud/storage';
|
|
14
14
|
export * as PubSub from '@google-cloud/pubsub';
|
|
@@ -48,6 +48,18 @@ export class GcfCommon {
|
|
|
48
48
|
context: TContext,
|
|
49
49
|
handler: (event: E, context: TContext) => Promise<T | E> | T | E = identity,
|
|
50
50
|
timeoutSec = 535,
|
|
51
|
+
) {
|
|
52
|
+
const asyncHandler = async (_event: any, _context: any) => await handler(_event, _context);
|
|
53
|
+
return firstValueFrom(
|
|
54
|
+
defer(() => from(asyncHandler(event, context))).pipe(first(), timeout({ first: ms({ s: timeoutSec }) })),
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static async processOLd<T extends TResponse, E = TEvent>(
|
|
59
|
+
event: E,
|
|
60
|
+
context: TContext,
|
|
61
|
+
handler: (event: E, context: TContext) => Promise<T | E> | T | E = identity,
|
|
62
|
+
timeoutSec = 535,
|
|
51
63
|
) {
|
|
52
64
|
return Promise.race([timeoutAfter(timeoutSec), handler(event, context)])
|
|
53
65
|
.then(async res => {
|
|
@@ -61,16 +73,6 @@ export class GcfCommon {
|
|
|
61
73
|
});
|
|
62
74
|
}
|
|
63
75
|
|
|
64
|
-
static async processRxjs<T extends TResponse, E = TEvent>(
|
|
65
|
-
event: E,
|
|
66
|
-
context: TContext,
|
|
67
|
-
handler: (event: E, context: TContext) => Promise<T | E> | T | E = identity,
|
|
68
|
-
timeoutSec = 535,
|
|
69
|
-
) {
|
|
70
|
-
const asyncHandler = async (_event: any, _context: any) => await handler(_event, _context);
|
|
71
|
-
return defer(() => from(asyncHandler(event, context))).pipe(first(), timeout({ first: ms({ s: timeoutSec }) }));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
76
|
static buildResponse(error: Error) {
|
|
75
77
|
return {
|
|
76
78
|
error: {
|