gcf-common-lib 0.26.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 +4 -4
- package/src/index.js +11 -6
- package/src/index.ts +19 -6
- package/src/mongo-lock.js +4 -1
- package/src/mongo-lock.ts +4 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-common-lib",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.28.61",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"branches": [
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"@types/bluebird": "^3.5.42",
|
|
25
25
|
"@types/lodash": "^4.14.201",
|
|
26
26
|
"@types/node": "^16.18.61",
|
|
27
|
-
"@google-cloud/pubsub": "^4.
|
|
27
|
+
"@google-cloud/pubsub": "^4.1.1",
|
|
28
28
|
"@google-cloud/secret-manager": "^5.0.1",
|
|
29
|
-
"@google-cloud/storage": "^7.
|
|
29
|
+
"@google-cloud/storage": "^7.7.0",
|
|
30
30
|
"amqplib": "^0.10.3",
|
|
31
31
|
"bluebird": "^3.7.2",
|
|
32
32
|
"lodash": "^4.17.21",
|
|
33
|
-
"moment": "^2.
|
|
33
|
+
"moment": "^2.30.1",
|
|
34
34
|
"mongodb": "^4.17.1",
|
|
35
35
|
"rxjs": "^7.8.1"
|
|
36
36
|
},
|
package/src/index.js
CHANGED
|
@@ -29,15 +29,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
29
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.GcfCommon = exports.secretClient = exports.pubSub = exports.MongoDb = exports.RxJs = exports.SecretManager = exports.PubSub = void 0;
|
|
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
|
-
|
|
41
|
+
exports.Storage = __importStar(require("@google-cloud/storage"));
|
|
41
42
|
exports.PubSub = __importStar(require("@google-cloud/pubsub"));
|
|
42
43
|
exports.SecretManager = __importStar(require("@google-cloud/secret-manager"));
|
|
43
44
|
exports.RxJs = __importStar(require("rxjs"));
|
|
@@ -45,7 +46,7 @@ exports.MongoDb = __importStar(require("mongodb"));
|
|
|
45
46
|
__exportStar(require("./types"), exports);
|
|
46
47
|
__exportStar(require("./utils"), exports);
|
|
47
48
|
exports.pubSub = new pubsub_1.PubSub();
|
|
48
|
-
|
|
49
|
+
exports.storage = new storage_1.Storage();
|
|
49
50
|
exports.secretClient = new secret_manager_1.SecretManagerServiceClient();
|
|
50
51
|
class GcfCommon {
|
|
51
52
|
constructor() { }
|
|
@@ -54,10 +55,14 @@ class GcfCommon {
|
|
|
54
55
|
* @param {!TEvent} event Event payload.
|
|
55
56
|
* @param {!TContext} context Metadata for the event.
|
|
56
57
|
* @param handler
|
|
57
|
-
* @param
|
|
58
|
+
* @param timeoutSec Seconds
|
|
58
59
|
*/
|
|
59
|
-
static async process(event, context, handler = rxjs_1.identity,
|
|
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) {
|
|
65
|
+
return Promise.race([(0, utils_1.timeoutAfter)(timeoutSec), handler(event, context)])
|
|
61
66
|
.then(async (res) => {
|
|
62
67
|
// console.log('res:', res);
|
|
63
68
|
await this.publish(event, context, res);
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
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 { identity } 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
12
|
|
|
12
|
-
|
|
13
|
+
export * as Storage from '@google-cloud/storage';
|
|
13
14
|
export * as PubSub from '@google-cloud/pubsub';
|
|
14
15
|
export * as SecretManager from '@google-cloud/secret-manager';
|
|
15
16
|
export * as RxJs from 'rxjs';
|
|
@@ -18,7 +19,7 @@ export * from './types';
|
|
|
18
19
|
export * from './utils';
|
|
19
20
|
|
|
20
21
|
export const pubSub = new PubSub();
|
|
21
|
-
|
|
22
|
+
export const storage = new Storage();
|
|
22
23
|
export const secretClient = new SecretManagerServiceClient();
|
|
23
24
|
|
|
24
25
|
export class GcfCommon {
|
|
@@ -40,15 +41,27 @@ export class GcfCommon {
|
|
|
40
41
|
* @param {!TEvent} event Event payload.
|
|
41
42
|
* @param {!TContext} context Metadata for the event.
|
|
42
43
|
* @param handler
|
|
43
|
-
* @param
|
|
44
|
+
* @param timeoutSec Seconds
|
|
44
45
|
*/
|
|
45
46
|
static async process<T extends TResponse, E = TEvent>(
|
|
46
47
|
event: E,
|
|
47
48
|
context: TContext,
|
|
48
49
|
handler: (event: E, context: TContext) => Promise<T | E> | T | E = identity,
|
|
49
|
-
|
|
50
|
+
timeoutSec = 535,
|
|
50
51
|
) {
|
|
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,
|
|
63
|
+
) {
|
|
64
|
+
return Promise.race([timeoutAfter(timeoutSec), handler(event, context)])
|
|
52
65
|
.then(async res => {
|
|
53
66
|
// console.log('res:', res);
|
|
54
67
|
await this.publish(event, context, res as T);
|
package/src/mongo-lock.js
CHANGED
|
@@ -4,11 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.MongoLock = void 0;
|
|
7
|
-
const moment_1 = __importDefault(require("moment"));
|
|
7
|
+
const moment_1 = __importDefault(require("moment/moment"));
|
|
8
8
|
const noop_1 = __importDefault(require("lodash/noop"));
|
|
9
9
|
const rxjs_1 = require("rxjs");
|
|
10
10
|
const mongo_helper_1 = require("./mongo-helper");
|
|
11
11
|
const bluebird_1 = __importDefault(require("bluebird"));
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated
|
|
14
|
+
*/
|
|
12
15
|
class MongoLock {
|
|
13
16
|
constructor(client) {
|
|
14
17
|
this.client = client;
|
package/src/mongo-lock.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import moment from 'moment/moment';
|
|
1
2
|
import { MongoClient, MongoError } from 'mongodb';
|
|
2
|
-
import moment from 'moment';
|
|
3
3
|
import noop from 'lodash/noop';
|
|
4
4
|
import { defer, from, identity, lastValueFrom, map, retry, switchMap, tap } from 'rxjs';
|
|
5
5
|
import { MongoHelper } from './mongo-helper';
|
|
6
6
|
import Bluebird from 'bluebird';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated
|
|
10
|
+
*/
|
|
8
11
|
export class MongoLock {
|
|
9
12
|
constructor(private client: MongoClient) {}
|
|
10
13
|
|