gcf-common-lib 0.33.0 → 0.34.0

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.
@@ -17,6 +17,7 @@ jobs:
17
17
  with:
18
18
  node-version: 20
19
19
  - run: npm ci
20
+ # - run: npm run build
20
21
  - run: npm test
21
22
 
22
23
  publish-npm:
@@ -29,6 +30,7 @@ jobs:
29
30
  node-version: 20
30
31
  registry-url: https://registry.npmjs.org/
31
32
  - run: npm ci
33
+ # - run: npm run build
32
34
  - run: npm publish
33
35
  env:
34
36
  NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gcf-common-lib",
3
3
  "description": "",
4
- "version": "0.33.0",
4
+ "version": "0.34.0",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "branches": [
@@ -13,15 +13,15 @@ exports.AmqpHelper = {
13
13
  const amqpConn = await (0, amqplib_1.connect)(url);
14
14
  amqpConn.on('close', () => console.info('Amqp connection closed!'));
15
15
  return amqpConn;
16
- })().disposer((conn, promise) => conn.close());
16
+ })().disposer((channelModel, promise) => channelModel.close());
17
17
  }
18
- return bluebird_1.default.using(withDisposer(), conn => fn(conn));
18
+ return bluebird_1.default.using(withDisposer(), channelModel => fn(channelModel));
19
19
  },
20
20
  async withAmqpCh(fn, url, useConfirmChannel = false, prefetch = 1) {
21
- return exports.AmqpHelper.withAmqpConn(async (conn) => {
21
+ return exports.AmqpHelper.withAmqpConn(async (channelModel) => {
22
22
  function withDisposer() {
23
23
  return bluebird_1.default.method(async () => {
24
- const ch = useConfirmChannel ? await conn.createConfirmChannel() : await conn.createChannel();
24
+ const ch = useConfirmChannel ? await channelModel.createConfirmChannel() : await channelModel.createChannel();
25
25
  await ch.prefetch(prefetch);
26
26
  return ch;
27
27
  })().disposer((ch, promise) => ch.close());
@@ -1,25 +1,25 @@
1
- import { Channel, ConfirmChannel, connect, Connection, Options } from 'amqplib';
1
+ import { Channel, ChannelModel, ConfirmChannel, connect, Options } from 'amqplib';
2
2
  import Bluebird from 'bluebird';
3
3
  import Dict = NodeJS.Dict;
4
4
 
5
5
  export const AmqpHelper = {
6
- async withAmqpConn(fn: (conn: Connection) => Promise<any>, url: string) {
6
+ async withAmqpConn(fn: (channelModel: ChannelModel) => Promise<any>, url: string) {
7
7
  function withDisposer() {
8
8
  return Bluebird.method(async () => {
9
9
  const amqpConn = await connect(url);
10
10
  amqpConn.on('close', () => console.info('Amqp connection closed!'));
11
11
  return amqpConn;
12
- })().disposer((conn, promise) => conn.close());
12
+ })().disposer((channelModel, promise) => channelModel.close());
13
13
  }
14
14
 
15
- return Bluebird.using(withDisposer(), conn => fn(conn));
15
+ return Bluebird.using(withDisposer(), channelModel => fn(channelModel));
16
16
  },
17
17
 
18
18
  async withAmqpCh(fn: (ch: Channel) => Promise<any>, url: string, useConfirmChannel = false, prefetch = 1) {
19
- return AmqpHelper.withAmqpConn(async conn => {
19
+ return AmqpHelper.withAmqpConn(async channelModel => {
20
20
  function withDisposer() {
21
21
  return Bluebird.method(async () => {
22
- const ch = useConfirmChannel ? await conn.createConfirmChannel() : await conn.createChannel();
22
+ const ch = useConfirmChannel ? await channelModel.createConfirmChannel() : await channelModel.createChannel();
23
23
  await ch.prefetch(prefetch);
24
24
  return ch;
25
25
  })().disposer((ch, promise) => ch.close());
package/src/index.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
36
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
37
  };
@@ -44,6 +54,8 @@ exports.RxJs = __importStar(require("rxjs"));
44
54
  exports.MongoDb = __importStar(require("mongodb"));
45
55
  __exportStar(require("./types"), exports);
46
56
  __exportStar(require("./utils"), exports);
57
+ __exportStar(require("./mongo-helper"), exports);
58
+ __exportStar(require("./amqp-helper"), exports);
47
59
  exports.pubSub = new pubsub_1.PubSub();
48
60
  exports.storage = new storage_1.Storage();
49
61
  // export const secretClient = new SecretManagerServiceClient();
package/src/index.ts CHANGED
@@ -17,6 +17,8 @@ export * as RxJs from 'rxjs';
17
17
  export * as MongoDb from 'mongodb';
18
18
  export * from './types';
19
19
  export * from './utils';
20
+ export * from './mongo-helper';
21
+ export * from './amqp-helper';
20
22
 
21
23
  export const pubSub = new PubSub();
22
24
  export const storage = new Storage();
package/src/mongo-lock.js CHANGED
@@ -45,7 +45,7 @@ class MongoLock {
45
45
  }
46
46
  catch (error) {
47
47
  // 11000 means duplicate key error, which is expected on an active lock
48
- if (error?.code !== 11000) {
48
+ if (error?.code !== 11_000) {
49
49
  // Unexpected error, what happened here :o
50
50
  throw error;
51
51
  }
package/src/utils.js CHANGED
@@ -1,6 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.safeJsonParse = exports.A1ToColNum = exports.colNumToA1 = exports.A1ToIndex = exports.indexToA1 = exports.sec = exports.ms = exports.delay = exports.timeoutAfter = void 0;
3
+ exports.timeoutAfter = timeoutAfter;
4
+ exports.delay = delay;
5
+ exports.ms = ms;
6
+ exports.sec = sec;
7
+ exports.indexToA1 = indexToA1;
8
+ exports.A1ToIndex = A1ToIndex;
9
+ exports.colNumToA1 = colNumToA1;
10
+ exports.A1ToColNum = A1ToColNum;
11
+ exports.safeJsonParse = safeJsonParse;
4
12
  /**
5
13
  *
6
14
  * @param seconds Google function v1 timeout limit (max: 9 min)
@@ -8,15 +16,12 @@ exports.safeJsonParse = exports.A1ToColNum = exports.colNumToA1 = exports.A1ToIn
8
16
  async function timeoutAfter(seconds = 540) {
9
17
  return new Promise((resolve, reject) => setTimeout(() => reject(new Error(`${seconds} seconds timeout exceeded`)), seconds * 1000));
10
18
  }
11
- exports.timeoutAfter = timeoutAfter;
12
19
  async function delay(seconds) {
13
20
  return new Promise(resolve => setTimeout(() => resolve(), seconds * 1000));
14
21
  }
15
- exports.delay = delay;
16
22
  function ms(o) {
17
23
  return sec(o) * 1000;
18
24
  }
19
- exports.ms = ms;
20
25
  function sec(o) {
21
26
  const multiMap = {};
22
27
  multiMap.s = 1;
@@ -28,15 +33,12 @@ function sec(o) {
28
33
  .map(([k, v]) => (multiMap[k] ?? 0) * (v ?? 0))
29
34
  .reduce((sum, v) => sum + v, 0);
30
35
  }
31
- exports.sec = sec;
32
36
  function indexToA1(idx) {
33
37
  return colNumToA1(idx + 1);
34
38
  }
35
- exports.indexToA1 = indexToA1;
36
39
  function A1ToIndex(value) {
37
40
  return A1ToColNum(value) - 1;
38
41
  }
39
- exports.A1ToIndex = A1ToIndex;
40
42
  function colNumToA1(columnNumber) {
41
43
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
42
44
  // To store result (Excel column name)
@@ -62,7 +64,6 @@ function colNumToA1(columnNumber) {
62
64
  .map(n => chars[n])
63
65
  .join('');
64
66
  }
65
- exports.colNumToA1 = colNumToA1;
66
67
  function A1ToColNum(value) {
67
68
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
68
69
  let result = 0;
@@ -73,7 +74,6 @@ function A1ToColNum(value) {
73
74
  }
74
75
  return result;
75
76
  }
76
- exports.A1ToColNum = A1ToColNum;
77
77
  function safeJsonParse(value, fallbackValue) {
78
78
  try {
79
79
  return JSON.parse(value);
@@ -82,4 +82,3 @@ function safeJsonParse(value, fallbackValue) {
82
82
  return fallbackValue;
83
83
  }
84
84
  }
85
- exports.safeJsonParse = safeJsonParse;