gcf-common-lib 0.48.0 → 0.49.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/package.json +13 -15
- package/src/mongo-helper.js +9 -15
- package/src/mongo-helper.ts +9 -13
- package/src/utils.js +2 -3
- package/src/utils.ts +2 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-common-lib",
|
|
3
3
|
"description": "Common helpers for Google Cloud Functions: Pub/Sub publishing, Mongo helpers, and utilities for Node 20+ (TypeScript).",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.49.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"branches": [
|
|
@@ -21,30 +21,28 @@
|
|
|
21
21
|
"url": "git+https://github.com/TopTechnologies/gcf-common-lib.git"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@google-cloud/pubsub": "^5.2.
|
|
25
|
-
"@google-cloud/storage": "^7.
|
|
26
|
-
"@types/
|
|
27
|
-
"
|
|
28
|
-
"bluebird": "^3.7.2",
|
|
29
|
-
"lodash": "^4.17.21",
|
|
24
|
+
"@google-cloud/pubsub": "^5.2.2",
|
|
25
|
+
"@google-cloud/storage": "^7.19.0",
|
|
26
|
+
"@types/lodash": "^4.17.23",
|
|
27
|
+
"lodash": "^4.17.23",
|
|
30
28
|
"moment": "^2.30.1",
|
|
31
|
-
"mongodb": "^7.
|
|
29
|
+
"mongodb": "^7.1.0",
|
|
32
30
|
"rxjs": "^7.8.2"
|
|
33
31
|
},
|
|
34
32
|
"devDependencies": {
|
|
35
|
-
"@tsconfig/node20": "^20.1.
|
|
36
|
-
"@types/node": "^20.19.
|
|
33
|
+
"@tsconfig/node20": "^20.1.9",
|
|
34
|
+
"@types/node": "^20.19.33",
|
|
37
35
|
"@eslint/js": "^9.21.0",
|
|
36
|
+
"c8": "^9.1.0",
|
|
38
37
|
"eslint": "^9.21.0",
|
|
39
38
|
"eslint-plugin-lodash": "^8.0.0",
|
|
40
39
|
"eslint-plugin-promise": "^7.2.1",
|
|
41
|
-
"eslint-plugin-unicorn": "^
|
|
40
|
+
"eslint-plugin-unicorn": "^63.0.0",
|
|
42
41
|
"globals": "^15.15.0",
|
|
43
|
-
"prettier": "^3.
|
|
44
|
-
"typescript-eslint": "^8.25.0",
|
|
45
|
-
"typescript": "^5.8.3",
|
|
42
|
+
"prettier": "^3.8.1",
|
|
46
43
|
"tsx": "^4.16.2",
|
|
47
|
-
"
|
|
44
|
+
"typescript": "^5.8.3",
|
|
45
|
+
"typescript-eslint": "^8.25.0"
|
|
48
46
|
},
|
|
49
47
|
"author": "alert83@gmail.com",
|
|
50
48
|
"license": "MIT"
|
package/src/mongo-helper.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.MongoHelper = void 0;
|
|
7
4
|
const mongodb_1 = require("mongodb");
|
|
8
|
-
const bluebird_1 = __importDefault(require("bluebird"));
|
|
9
5
|
let mongoClient;
|
|
10
6
|
exports.MongoHelper = {
|
|
11
7
|
async collectionExists(client, name) {
|
|
@@ -27,17 +23,15 @@ exports.MongoHelper = {
|
|
|
27
23
|
return coll;
|
|
28
24
|
},
|
|
29
25
|
async withMongoClient(fn, url, mongoClientOptions) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
26
|
+
try {
|
|
27
|
+
if (!mongoClient) {
|
|
28
|
+
mongoClient = new mongodb_1.MongoClient(url, mongoClientOptions);
|
|
29
|
+
await mongoClient.connect();
|
|
30
|
+
}
|
|
31
|
+
return await fn(mongoClient);
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
// mongoClient.close();
|
|
40
35
|
}
|
|
41
|
-
return bluebird_1.default.using(withDisposer(), client => fn(client));
|
|
42
36
|
},
|
|
43
37
|
};
|
package/src/mongo-helper.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Collection, CreateCollectionOptions, MongoClient, MongoClientOptions } from 'mongodb';
|
|
2
2
|
import { Document } from 'bson';
|
|
3
|
-
import Bluebird from 'bluebird';
|
|
4
3
|
|
|
5
4
|
let mongoClient: MongoClient;
|
|
6
5
|
|
|
@@ -35,18 +34,15 @@ export const MongoHelper = {
|
|
|
35
34
|
url: string,
|
|
36
35
|
mongoClientOptions?: MongoClientOptions,
|
|
37
36
|
) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
return mongoClient;
|
|
45
|
-
})().disposer((client, promise) => {
|
|
46
|
-
// client.close();
|
|
47
|
-
});
|
|
48
|
-
}
|
|
37
|
+
try {
|
|
38
|
+
if (!mongoClient) {
|
|
39
|
+
mongoClient = new MongoClient(url, mongoClientOptions);
|
|
40
|
+
await mongoClient.connect();
|
|
41
|
+
}
|
|
49
42
|
|
|
50
|
-
|
|
43
|
+
return await fn(mongoClient);
|
|
44
|
+
} finally {
|
|
45
|
+
// mongoClient.close();
|
|
46
|
+
}
|
|
51
47
|
},
|
|
52
48
|
};
|
package/src/utils.js
CHANGED
|
@@ -29,8 +29,7 @@ function ms(o) {
|
|
|
29
29
|
return sec(o) * 1000;
|
|
30
30
|
}
|
|
31
31
|
function sec(o) {
|
|
32
|
-
const multiMap = {};
|
|
33
|
-
multiMap.s = 1;
|
|
32
|
+
const multiMap = { s: 1 };
|
|
34
33
|
multiMap.m = multiMap.s * 60;
|
|
35
34
|
multiMap.h = multiMap.m * 60;
|
|
36
35
|
multiMap.d = multiMap.h * 24;
|
|
@@ -66,7 +65,7 @@ function colNumToA1(columnNumber) {
|
|
|
66
65
|
}
|
|
67
66
|
// Reverse the string and print result
|
|
68
67
|
return charIdxArr
|
|
69
|
-
.
|
|
68
|
+
.toReversed()
|
|
70
69
|
.map(n => chars[n])
|
|
71
70
|
.join('');
|
|
72
71
|
}
|
package/src/utils.ts
CHANGED
|
@@ -20,8 +20,7 @@ export function ms(o: { w?: number; d?: number; h?: number; m?: number; s?: numb
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function sec(o: { w?: number; d?: number; h?: number; m?: number; s?: number }) {
|
|
23
|
-
const multiMap: any = {};
|
|
24
|
-
multiMap.s = 1;
|
|
23
|
+
const multiMap: any = { s: 1 };
|
|
25
24
|
multiMap.m = multiMap.s * 60;
|
|
26
25
|
multiMap.h = multiMap.m * 60;
|
|
27
26
|
multiMap.d = multiMap.h * 24;
|
|
@@ -64,7 +63,7 @@ export function colNumToA1(columnNumber: number) {
|
|
|
64
63
|
|
|
65
64
|
// Reverse the string and print result
|
|
66
65
|
return charIdxArr
|
|
67
|
-
.
|
|
66
|
+
.toReversed()
|
|
68
67
|
.map(n => chars[n])
|
|
69
68
|
.join('');
|
|
70
69
|
}
|