gcf-common-lib 0.23.34 → 0.24.34

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.23.34",
4
+ "version": "0.24.34",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "branches": [
@@ -18,22 +18,22 @@
18
18
  "url": "https://github.com/TopTechnologies/gcf-common.git"
19
19
  },
20
20
  "dependencies": {
21
- "@google-cloud/pubsub": "^3.3.0",
22
- "@google-cloud/secret-manager": "^4.2.1",
23
- "@google-cloud/storage": "^6.9.4",
21
+ "@google-cloud/pubsub": "^4.0.0",
22
+ "@google-cloud/secret-manager": "^5.0.0",
23
+ "@google-cloud/storage": "^7.0.1",
24
24
  "amqplib": "^0.10.3",
25
25
  "bluebird": "^3.7.2",
26
26
  "lodash": "^4.17.21",
27
27
  "moment": "^2.29.4",
28
- "mongodb": "^4.14.0",
29
- "rxjs": "^7.8.0"
28
+ "mongodb": "^4.16.0",
29
+ "rxjs": "^7.8.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@tsconfig/node14": "^1.0.3",
32
+ "@tsconfig/node14": "^14.1.0",
33
33
  "@types/amqplib": "^0.10.1",
34
34
  "@types/bluebird": "^3.5.38",
35
- "@types/lodash": "^4.14.191",
36
- "@types/node": "^14.18.37"
35
+ "@types/lodash": "^4.14.197",
36
+ "@types/node": "^14.18.54"
37
37
  },
38
38
  "author": "alert83@gmail.com",
39
39
  "license": ""
package/src/index.js CHANGED
@@ -93,7 +93,7 @@ class GcfCommon {
93
93
  console.log('publish:', topic, appId, env, json, attributes);
94
94
  return exports.pubSub.topic(topic).publishMessage({
95
95
  json: json !== null && json !== void 0 ? json : {},
96
- attributes: Object.assign(Object.assign({}, (0, lodash_1.mapValues)(attributes !== null && attributes !== void 0 ? attributes : {}, (v) => '' + v)), { appId: appId !== null && appId !== void 0 ? appId : '', requestId: requestId !== null && requestId !== void 0 ? requestId : '', env: env !== null && env !== void 0 ? env : '',
96
+ attributes: Object.assign(Object.assign({}, (0, lodash_1.mapValues)(attributes !== null && attributes !== void 0 ? attributes : {}, (v) => '' + v)), { appId: appId !== null && appId !== void 0 ? appId : '', env: env !== null && env !== void 0 ? env : '', requestId: requestId !== null && requestId !== void 0 ? requestId : '',
97
97
  //
98
98
  type: 'response', response: '1' }),
99
99
  });
@@ -215,6 +215,6 @@ class GcfCommon {
215
215
  }
216
216
  exports.GcfCommon = GcfCommon;
217
217
  GcfCommon.amqpOptions = {
218
- assertOptions: { durable: true },
218
+ assertOptions: { durable: true, autoDelete: true, expires: (0, utils_1.ms)({ d: 1 }) },
219
219
  publishOptions: { persistent: true },
220
220
  };
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PubSub } from '@google-cloud/pubsub';
2
2
  import isEmpty from 'lodash/isEmpty';
3
3
  import noop from 'lodash/noop';
4
- import { sendToQueueAsync, timeoutAfter, withAmqpCh } from './utils';
4
+ import { ms, sendToQueueAsync, timeoutAfter, withAmqpCh } from './utils';
5
5
  import { Storage } from '@google-cloud/storage';
6
6
  import { SecretManagerServiceClient } from '@google-cloud/secret-manager';
7
7
  import { TContext, TEvent, TGSEvent, TMetadata, TPSEvent, TResponse } from './types';
@@ -27,7 +27,7 @@ export class GcfCommon {
27
27
  assertOptions?: Options.AssertQueue;
28
28
  publishOptions?: Options.Publish;
29
29
  } = {
30
- assertOptions: { durable: true },
30
+ assertOptions: { durable: true, autoDelete: true, expires: ms({ d: 1 }) },
31
31
  publishOptions: { persistent: true },
32
32
  };
33
33
 
@@ -73,8 +73,8 @@ export class GcfCommon {
73
73
  attributes: {
74
74
  ...mapValues(attributes ?? {}, (v) => '' + v),
75
75
  appId: appId ?? '',
76
- requestId: requestId ?? '',
77
76
  env: env ?? '',
77
+ requestId: requestId ?? '',
78
78
  //
79
79
  type: 'response',
80
80
  response: '1',
package/src/utils.js CHANGED
@@ -12,9 +12,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.sendToQueueConfAsync = exports.sendToQueueAsync = exports.withAmqpConfCh = exports.withAmqpCh = exports.withAmqpConn = exports.A1ToColNum = exports.colNumToA1 = exports.A1ToIndex = exports.indexToA1 = exports.delay = exports.timeoutAfter = void 0;
15
+ exports.sendToQueueConfAsync = exports.sendToQueueAsync = exports.withAmqpConfCh = exports.withAmqpCh = exports.withAmqpConn = exports.A1ToColNum = exports.colNumToA1 = exports.A1ToIndex = exports.indexToA1 = exports.sec = exports.ms = exports.delay = exports.timeoutAfter = void 0;
16
16
  const amqplib_1 = require("amqplib");
17
17
  const bluebird_1 = __importDefault(require("bluebird"));
18
+ const lodash_1 = require("lodash");
18
19
  /**
19
20
  *
20
21
  * @param seconds Google function v1 timeout limit (max: 9 min)
@@ -32,6 +33,23 @@ function delay(seconds) {
32
33
  }
33
34
  exports.delay = delay;
34
35
  //
36
+ function ms(o) {
37
+ return sec(o) * 1000;
38
+ }
39
+ exports.ms = ms;
40
+ function sec(o) {
41
+ const multiMap = {};
42
+ multiMap.s = 1;
43
+ multiMap.m = multiMap.s * 60;
44
+ multiMap.h = multiMap.m * 60;
45
+ multiMap.d = multiMap.h * 24;
46
+ multiMap.w = multiMap.d * 7;
47
+ return (0, lodash_1.chain)(Object.entries(o))
48
+ .map(([k, v]) => { var _a; return ((_a = multiMap[k]) !== null && _a !== void 0 ? _a : 0) * (v !== null && v !== void 0 ? v : 0); })
49
+ .reduce((sum, v) => sum + v)
50
+ .value();
51
+ }
52
+ exports.sec = sec;
35
53
  function indexToA1(idx) {
36
54
  return colNumToA1(idx + 1);
37
55
  }
package/src/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Channel, ConfirmChannel, connect, Connection, Options } from 'amqplib';
2
2
  import Bluebird from 'bluebird';
3
- import { Dictionary } from 'lodash';
3
+ import { chain, Dictionary } from 'lodash';
4
4
 
5
5
  /**
6
6
  *
@@ -17,6 +17,24 @@ export async function delay(seconds: number) {
17
17
 
18
18
  //
19
19
 
20
+ export function ms(o: { w?: number; d?: number; h?: number; m?: number; s?: number }) {
21
+ return sec(o) * 1000;
22
+ }
23
+
24
+ export function sec(o: { w?: number; d?: number; h?: number; m?: number; s?: number }) {
25
+ const multiMap: any = {};
26
+ multiMap.s = 1;
27
+ multiMap.m = multiMap.s * 60;
28
+ multiMap.h = multiMap.m * 60;
29
+ multiMap.d = multiMap.h * 24;
30
+ multiMap.w = multiMap.d * 7;
31
+
32
+ return chain(Object.entries(o))
33
+ .map(([k, v]) => (multiMap[k] ?? 0) * (v ?? 0))
34
+ .reduce((sum, v) => sum + v)
35
+ .value();
36
+ }
37
+
20
38
  export function indexToA1(idx: number) {
21
39
  return colNumToA1(idx + 1);
22
40
  }
package/tsconfig.json CHANGED
@@ -8,6 +8,7 @@
8
8
  "ES2019",
9
9
  "ES2020",
10
10
  "ES2021",
11
+ "ES2022",
11
12
  "ESNext"
12
13
  ]
13
14
  }