gcf-common-lib 0.26.60 → 0.27.60

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gcf-common-lib",
3
3
  "description": "",
4
- "version": "0.26.60",
4
+ "version": "0.27.60",
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.0.7",
27
+ "@google-cloud/pubsub": "^4.1.1",
28
28
  "@google-cloud/secret-manager": "^5.0.1",
29
- "@google-cloud/storage": "^7.6.0",
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.29.4",
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,7 +29,7 @@ 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
35
  const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
@@ -37,7 +37,8 @@ const mapValues_1 = __importDefault(require("lodash/mapValues"));
37
37
  const noop_1 = __importDefault(require("lodash/noop"));
38
38
  const rxjs_1 = require("rxjs");
39
39
  const utils_1 = require("./utils");
40
- // export * as Storage from '@google-cloud/storage';
40
+ const storage_1 = require("@google-cloud/storage");
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
- // export const storage = new Storage();
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,10 @@ class GcfCommon {
54
55
  * @param {!TEvent} event Event payload.
55
56
  * @param {!TContext} context Metadata for the event.
56
57
  * @param handler
57
- * @param timeout Seconds
58
+ * @param timeoutSec Seconds
58
59
  */
59
- static async process(event, context, handler = rxjs_1.identity, timeout = 535) {
60
- return Promise.race([(0, utils_1.timeoutAfter)(timeout), handler(event, context)])
60
+ static async process(event, context, handler = rxjs_1.identity, timeoutSec = 535) {
61
+ return Promise.race([(0, utils_1.timeoutAfter)(timeoutSec), handler(event, context)])
61
62
  .then(async (res) => {
62
63
  // console.log('res:', res);
63
64
  await this.publish(event, context, res);
@@ -68,6 +69,10 @@ class GcfCommon {
68
69
  throw error;
69
70
  });
70
71
  }
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
+ }
71
76
  static buildResponse(error) {
72
77
  return {
73
78
  error: {
package/src/index.ts CHANGED
@@ -4,12 +4,13 @@ import { Options } from 'amqplib';
4
4
  import isEmpty from 'lodash/isEmpty';
5
5
  import mapValues from 'lodash/mapValues';
6
6
  import noop from 'lodash/noop';
7
- import { identity } from 'rxjs';
7
+ import { defer, first, from, identity, timeout } from 'rxjs';
8
8
  import { TContext, TEvent, TGSEvent, TMetadataOrAttributes, TPSEvent, TResponse } from './types';
9
9
  import { ms, publishAmqp, timeoutAfter, withAmqpCh } from './utils';
10
10
  import Dict = NodeJS.Dict;
11
+ import { Storage } from '@google-cloud/storage';
11
12
 
12
- // export * as Storage from '@google-cloud/storage';
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
- // export const storage = new Storage();
22
+ export const storage = new Storage();
22
23
  export const secretClient = new SecretManagerServiceClient();
23
24
 
24
25
  export class GcfCommon {
@@ -40,15 +41,15 @@ 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 timeout Seconds
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
- timeout = 535,
50
+ timeoutSec = 535,
50
51
  ) {
51
- return Promise.race([timeoutAfter(timeout), handler(event, context)])
52
+ return Promise.race([timeoutAfter(timeoutSec), handler(event, context)])
52
53
  .then(async res => {
53
54
  // console.log('res:', res);
54
55
  await this.publish(event, context, res as T);
@@ -60,6 +61,16 @@ export class GcfCommon {
60
61
  });
61
62
  }
62
63
 
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
+
63
74
  static buildResponse(error: Error) {
64
75
  return {
65
76
  error: {
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