gcf-common-lib 0.32.67 → 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.
- package/.github/workflows/npm-publish.yml +4 -2
- package/package.json +11 -11
- package/src/amqp-helper.js +4 -4
- package/src/amqp-helper.ts +6 -6
- package/src/index.js +19 -7
- package/src/index.ts +2 -0
- package/src/mongo-lock.js +1 -1
- package/src/utils.js +9 -10
- package/.eslintrc.json +0 -49
|
@@ -15,8 +15,9 @@ jobs:
|
|
|
15
15
|
- uses: actions/checkout@v4
|
|
16
16
|
- uses: actions/setup-node@v4
|
|
17
17
|
with:
|
|
18
|
-
node-version:
|
|
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:
|
|
@@ -26,9 +27,10 @@ jobs:
|
|
|
26
27
|
- uses: actions/checkout@v4
|
|
27
28
|
- uses: actions/setup-node@v4
|
|
28
29
|
with:
|
|
29
|
-
node-version:
|
|
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.
|
|
4
|
+
"version": "0.34.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"branches": [
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
},
|
|
14
14
|
"main": "src/index",
|
|
15
15
|
"scripts": {
|
|
16
|
-
"postinstall": "npm run build && npm run test",
|
|
17
16
|
"build": "tsc",
|
|
18
17
|
"test": "node --test ./test/"
|
|
19
18
|
},
|
|
@@ -22,20 +21,20 @@
|
|
|
22
21
|
"url": "https://github.com/TopTechnologies/gcf-common.git"
|
|
23
22
|
},
|
|
24
23
|
"dependencies": {
|
|
25
|
-
"@google-cloud/pubsub": "^4.
|
|
26
|
-
"@google-cloud/storage": "^7.
|
|
24
|
+
"@google-cloud/pubsub": "^4.10.0",
|
|
25
|
+
"@google-cloud/storage": "^7.15.2",
|
|
27
26
|
"@tsconfig/node20": "^20.1.4",
|
|
28
|
-
"@types/amqplib": "^0.10.
|
|
27
|
+
"@types/amqplib": "^0.10.7",
|
|
29
28
|
"@types/bluebird": "^3.5.42",
|
|
30
29
|
"@types/express": "^4.17.21",
|
|
31
|
-
"@types/lodash": "^4.17.
|
|
32
|
-
"@types/node": "^20.17.
|
|
33
|
-
"amqplib": "^0.10.
|
|
30
|
+
"@types/lodash": "^4.17.16",
|
|
31
|
+
"@types/node": "^20.17.23",
|
|
32
|
+
"amqplib": "^0.10.5",
|
|
34
33
|
"bluebird": "^3.7.2",
|
|
35
34
|
"lodash": "^4.17.21",
|
|
36
35
|
"moment": "^2.30.1",
|
|
37
|
-
"mongodb": "^6.
|
|
38
|
-
"rxjs": "^7.8.
|
|
36
|
+
"mongodb": "^6.14.1",
|
|
37
|
+
"rxjs": "^7.8.2"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
40
|
"@eslint/js": "^9.21.0",
|
|
@@ -45,7 +44,8 @@
|
|
|
45
44
|
"eslint-plugin-unicorn": "^57.0.0",
|
|
46
45
|
"globals": "^15.15.0",
|
|
47
46
|
"prettier": "^3.5.2",
|
|
48
|
-
"typescript-eslint": "^8.25.0"
|
|
47
|
+
"typescript-eslint": "^8.25.0",
|
|
48
|
+
"typescript": "^5.3.3"
|
|
49
49
|
},
|
|
50
50
|
"author": "alert83@gmail.com",
|
|
51
51
|
"license": ""
|
package/src/amqp-helper.js
CHANGED
|
@@ -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((
|
|
16
|
+
})().disposer((channelModel, promise) => channelModel.close());
|
|
17
17
|
}
|
|
18
|
-
return bluebird_1.default.using(withDisposer(),
|
|
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 (
|
|
21
|
+
return exports.AmqpHelper.withAmqpConn(async (channelModel) => {
|
|
22
22
|
function withDisposer() {
|
|
23
23
|
return bluebird_1.default.method(async () => {
|
|
24
|
-
const ch = useConfirmChannel ? await
|
|
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());
|
package/src/amqp-helper.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { Channel, ConfirmChannel, connect,
|
|
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: (
|
|
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((
|
|
12
|
+
})().disposer((channelModel, promise) => channelModel.close());
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
return Bluebird.using(withDisposer(),
|
|
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
|
|
19
|
+
return AmqpHelper.withAmqpConn(async channelModel => {
|
|
20
20
|
function withDisposer() {
|
|
21
21
|
return Bluebird.method(async () => {
|
|
22
|
-
const ch = useConfirmChannel ? await
|
|
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 (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
package/src/utils.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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;
|
package/.eslintrc.json
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"env": {
|
|
4
|
-
"es2021": true,
|
|
5
|
-
"commonjs": true
|
|
6
|
-
},
|
|
7
|
-
"parser": "@typescript-eslint/parser",
|
|
8
|
-
"parserOptions": {
|
|
9
|
-
"ecmaVersion": "latest",
|
|
10
|
-
"sourceType": "module",
|
|
11
|
-
"tsconfigRootDir": ".",
|
|
12
|
-
"project": [
|
|
13
|
-
"./tsconfig.json"
|
|
14
|
-
]
|
|
15
|
-
},
|
|
16
|
-
"plugins": [
|
|
17
|
-
"@typescript-eslint",
|
|
18
|
-
"import",
|
|
19
|
-
"promise",
|
|
20
|
-
"rxjs",
|
|
21
|
-
"lodash",
|
|
22
|
-
"unicorn"
|
|
23
|
-
],
|
|
24
|
-
"extends": [
|
|
25
|
-
"eslint:recommended",
|
|
26
|
-
"plugin:@typescript-eslint/recommended",
|
|
27
|
-
"plugin:import/recommended",
|
|
28
|
-
"plugin:import/typescript",
|
|
29
|
-
"plugin:promise/recommended",
|
|
30
|
-
"plugin:rxjs/recommended",
|
|
31
|
-
"plugin:lodash/recommended",
|
|
32
|
-
"plugin:unicorn/recommended"
|
|
33
|
-
],
|
|
34
|
-
"settings": {
|
|
35
|
-
"import/resolver": {
|
|
36
|
-
"typescript": true,
|
|
37
|
-
"node": true
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
"rules": {
|
|
41
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
42
|
-
"@typescript-eslint/no-unused-vars": "off",
|
|
43
|
-
"@typescript-eslint/no-empty-function": "off",
|
|
44
|
-
"@typescript-eslint/no-empty-interface": "off",
|
|
45
|
-
"lodash/prefer-lodash-method": "off",
|
|
46
|
-
"rxjs/no-implicit-any-catch": "off",
|
|
47
|
-
"unicorn/prevent-abbreviations": "off"
|
|
48
|
-
}
|
|
49
|
-
}
|