@okf/ootils 1.4.2 → 1.4.4
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/dist/node.d.mts +1 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.js +32 -20
- package/dist/node.mjs +32 -20
- package/package.json +2 -1
package/dist/node.d.mts
CHANGED
|
@@ -173,6 +173,7 @@ declare class MongoConnector {
|
|
|
173
173
|
*/
|
|
174
174
|
multiConnectToMongoDB(): {};
|
|
175
175
|
multiConnectToMongoDBAsync(): Promise<{}>;
|
|
176
|
+
initiateConnectionEventListeners: (CLUSTER_NAME: any) => void;
|
|
176
177
|
/**
|
|
177
178
|
* Helper function to close clusterConnections object
|
|
178
179
|
*/
|
package/dist/node.d.ts
CHANGED
|
@@ -173,6 +173,7 @@ declare class MongoConnector {
|
|
|
173
173
|
*/
|
|
174
174
|
multiConnectToMongoDB(): {};
|
|
175
175
|
multiConnectToMongoDBAsync(): Promise<{}>;
|
|
176
|
+
initiateConnectionEventListeners: (CLUSTER_NAME: any) => void;
|
|
176
177
|
/**
|
|
177
178
|
* Helper function to close clusterConnections object
|
|
178
179
|
*/
|
package/dist/node.js
CHANGED
|
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
9
|
var __esm = (fn, res) => function __init() {
|
|
9
10
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
11
|
};
|
|
@@ -32,6 +33,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
33
|
mod
|
|
33
34
|
));
|
|
34
35
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
35
37
|
|
|
36
38
|
// src/models/Annotations.ts
|
|
37
39
|
var Annotations_exports = {};
|
|
@@ -339,19 +341,42 @@ var require_MongoConnector = __commonJS({
|
|
|
339
341
|
"src/db/MongoConnector.js"(exports2, module2) {
|
|
340
342
|
"use strict";
|
|
341
343
|
var mongoose5 = require("mongoose");
|
|
344
|
+
var { ServerApiVersion } = require("mongodb");
|
|
342
345
|
var AnnotationsSchema = (init_Annotations(), __toCommonJS(Annotations_exports));
|
|
343
346
|
var PlatformConfigsSchema2 = (init_PlatformConfigs(), __toCommonJS(PlatformConfigs_exports));
|
|
344
347
|
var TplSchema2 = (init_Tpl(), __toCommonJS(Tpl_exports));
|
|
345
348
|
var MongoConnector3 = class _MongoConnector {
|
|
346
349
|
constructor(options) {
|
|
350
|
+
__publicField(this, "initiateConnectionEventListeners", (CLUSTER_NAME) => {
|
|
351
|
+
this.clusterConnections[CLUSTER_NAME].on("open", () => {
|
|
352
|
+
console.log(`\u2705 Mongoose connection open to ${CLUSTER_NAME}`);
|
|
353
|
+
});
|
|
354
|
+
this.clusterConnections[CLUSTER_NAME].on("error", (err) => {
|
|
355
|
+
console.error(
|
|
356
|
+
`\u274C Mongoose connection error: ${err.message} with connection info ${CLUSTER_NAME}`
|
|
357
|
+
);
|
|
358
|
+
process.exit(1);
|
|
359
|
+
});
|
|
360
|
+
this.clusterConnections[CLUSTER_NAME].on("disconnected", () => {
|
|
361
|
+
console.log(`\u{1F50C} Mongoose disconnected from ${CLUSTER_NAME}`);
|
|
362
|
+
});
|
|
363
|
+
this.clusterConnections[CLUSTER_NAME].on("reconnected", () => {
|
|
364
|
+
console.log(`\u{1F504} Mongoose reconnected to ${CLUSTER_NAME}`);
|
|
365
|
+
});
|
|
366
|
+
});
|
|
347
367
|
this.clusterConnections = {};
|
|
348
368
|
this.env = options.env;
|
|
349
369
|
this.dbConfigs = options.dbConfigs;
|
|
350
370
|
this.mongoOptions = options.mongoOptions || {
|
|
351
|
-
maxPoolSize:
|
|
352
|
-
serverSelectionTimeoutMS:
|
|
353
|
-
socketTimeoutMS:
|
|
354
|
-
family: 4
|
|
371
|
+
// maxPoolSize: 40,
|
|
372
|
+
// serverSelectionTimeoutMS: 5000,
|
|
373
|
+
// socketTimeoutMS: 45000,
|
|
374
|
+
// family: 4,
|
|
375
|
+
serverApi: {
|
|
376
|
+
version: ServerApiVersion.v1
|
|
377
|
+
},
|
|
378
|
+
maxPoolSize: 40,
|
|
379
|
+
minPoolSize: 5
|
|
355
380
|
};
|
|
356
381
|
_MongoConnector.instance = this;
|
|
357
382
|
if (!this.env) {
|
|
@@ -383,21 +408,7 @@ var require_MongoConnector = __commonJS({
|
|
|
383
408
|
DB_URI,
|
|
384
409
|
this.mongoOptions
|
|
385
410
|
);
|
|
386
|
-
this.
|
|
387
|
-
console.log(`\u2705 Mongoose connection open to ${CLUSTER_NAME}`);
|
|
388
|
-
});
|
|
389
|
-
this.clusterConnections[CLUSTER_NAME].on("error", (err) => {
|
|
390
|
-
console.error(
|
|
391
|
-
`\u274C Mongoose connection error: ${err.message} with connection info ${CLUSTER_NAME}`
|
|
392
|
-
);
|
|
393
|
-
process.exit(1);
|
|
394
|
-
});
|
|
395
|
-
this.clusterConnections[CLUSTER_NAME].on("disconnected", () => {
|
|
396
|
-
console.log(`\u{1F50C} Mongoose disconnected from ${CLUSTER_NAME}`);
|
|
397
|
-
});
|
|
398
|
-
this.clusterConnections[CLUSTER_NAME].on("reconnected", () => {
|
|
399
|
-
console.log(`\u{1F504} Mongoose reconnected to ${CLUSTER_NAME}`);
|
|
400
|
-
});
|
|
411
|
+
this.initiateConnectionEventListeners(CLUSTER_NAME);
|
|
401
412
|
});
|
|
402
413
|
console.log(
|
|
403
414
|
`\u{1F389} Connected to ${Object.keys(this.clusterConnections).length} MongoDB databases`
|
|
@@ -422,8 +433,9 @@ var require_MongoConnector = __commonJS({
|
|
|
422
433
|
this.clusterConnections[CLUSTER_NAME] = await mongoose5.createConnection(
|
|
423
434
|
DB_URI,
|
|
424
435
|
this.mongoOptions
|
|
425
|
-
);
|
|
436
|
+
).asPromise();
|
|
426
437
|
console.log(`Connected to MongoDB: ${CLUSTER_NAME}`);
|
|
438
|
+
this.initiateConnectionEventListeners(CLUSTER_NAME);
|
|
427
439
|
})
|
|
428
440
|
);
|
|
429
441
|
return this.clusterConnections;
|
package/dist/node.mjs
CHANGED
|
@@ -4,6 +4,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
8
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
9
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
10
|
}) : x)(function(x) {
|
|
@@ -37,6 +38,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
37
38
|
mod
|
|
38
39
|
));
|
|
39
40
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
40
42
|
|
|
41
43
|
// src/models/Annotations.ts
|
|
42
44
|
var Annotations_exports = {};
|
|
@@ -344,19 +346,42 @@ var require_MongoConnector = __commonJS({
|
|
|
344
346
|
"src/db/MongoConnector.js"(exports, module) {
|
|
345
347
|
"use strict";
|
|
346
348
|
var mongoose5 = __require("mongoose");
|
|
349
|
+
var { ServerApiVersion } = __require("mongodb");
|
|
347
350
|
var AnnotationsSchema = (init_Annotations(), __toCommonJS(Annotations_exports));
|
|
348
351
|
var PlatformConfigsSchema2 = (init_PlatformConfigs(), __toCommonJS(PlatformConfigs_exports));
|
|
349
352
|
var TplSchema2 = (init_Tpl(), __toCommonJS(Tpl_exports));
|
|
350
353
|
var MongoConnector3 = class _MongoConnector {
|
|
351
354
|
constructor(options) {
|
|
355
|
+
__publicField(this, "initiateConnectionEventListeners", (CLUSTER_NAME) => {
|
|
356
|
+
this.clusterConnections[CLUSTER_NAME].on("open", () => {
|
|
357
|
+
console.log(`\u2705 Mongoose connection open to ${CLUSTER_NAME}`);
|
|
358
|
+
});
|
|
359
|
+
this.clusterConnections[CLUSTER_NAME].on("error", (err) => {
|
|
360
|
+
console.error(
|
|
361
|
+
`\u274C Mongoose connection error: ${err.message} with connection info ${CLUSTER_NAME}`
|
|
362
|
+
);
|
|
363
|
+
process.exit(1);
|
|
364
|
+
});
|
|
365
|
+
this.clusterConnections[CLUSTER_NAME].on("disconnected", () => {
|
|
366
|
+
console.log(`\u{1F50C} Mongoose disconnected from ${CLUSTER_NAME}`);
|
|
367
|
+
});
|
|
368
|
+
this.clusterConnections[CLUSTER_NAME].on("reconnected", () => {
|
|
369
|
+
console.log(`\u{1F504} Mongoose reconnected to ${CLUSTER_NAME}`);
|
|
370
|
+
});
|
|
371
|
+
});
|
|
352
372
|
this.clusterConnections = {};
|
|
353
373
|
this.env = options.env;
|
|
354
374
|
this.dbConfigs = options.dbConfigs;
|
|
355
375
|
this.mongoOptions = options.mongoOptions || {
|
|
356
|
-
maxPoolSize:
|
|
357
|
-
serverSelectionTimeoutMS:
|
|
358
|
-
socketTimeoutMS:
|
|
359
|
-
family: 4
|
|
376
|
+
// maxPoolSize: 40,
|
|
377
|
+
// serverSelectionTimeoutMS: 5000,
|
|
378
|
+
// socketTimeoutMS: 45000,
|
|
379
|
+
// family: 4,
|
|
380
|
+
serverApi: {
|
|
381
|
+
version: ServerApiVersion.v1
|
|
382
|
+
},
|
|
383
|
+
maxPoolSize: 40,
|
|
384
|
+
minPoolSize: 5
|
|
360
385
|
};
|
|
361
386
|
_MongoConnector.instance = this;
|
|
362
387
|
if (!this.env) {
|
|
@@ -388,21 +413,7 @@ var require_MongoConnector = __commonJS({
|
|
|
388
413
|
DB_URI,
|
|
389
414
|
this.mongoOptions
|
|
390
415
|
);
|
|
391
|
-
this.
|
|
392
|
-
console.log(`\u2705 Mongoose connection open to ${CLUSTER_NAME}`);
|
|
393
|
-
});
|
|
394
|
-
this.clusterConnections[CLUSTER_NAME].on("error", (err) => {
|
|
395
|
-
console.error(
|
|
396
|
-
`\u274C Mongoose connection error: ${err.message} with connection info ${CLUSTER_NAME}`
|
|
397
|
-
);
|
|
398
|
-
process.exit(1);
|
|
399
|
-
});
|
|
400
|
-
this.clusterConnections[CLUSTER_NAME].on("disconnected", () => {
|
|
401
|
-
console.log(`\u{1F50C} Mongoose disconnected from ${CLUSTER_NAME}`);
|
|
402
|
-
});
|
|
403
|
-
this.clusterConnections[CLUSTER_NAME].on("reconnected", () => {
|
|
404
|
-
console.log(`\u{1F504} Mongoose reconnected to ${CLUSTER_NAME}`);
|
|
405
|
-
});
|
|
416
|
+
this.initiateConnectionEventListeners(CLUSTER_NAME);
|
|
406
417
|
});
|
|
407
418
|
console.log(
|
|
408
419
|
`\u{1F389} Connected to ${Object.keys(this.clusterConnections).length} MongoDB databases`
|
|
@@ -427,8 +438,9 @@ var require_MongoConnector = __commonJS({
|
|
|
427
438
|
this.clusterConnections[CLUSTER_NAME] = await mongoose5.createConnection(
|
|
428
439
|
DB_URI,
|
|
429
440
|
this.mongoOptions
|
|
430
|
-
);
|
|
441
|
+
).asPromise();
|
|
431
442
|
console.log(`Connected to MongoDB: ${CLUSTER_NAME}`);
|
|
443
|
+
this.initiateConnectionEventListeners(CLUSTER_NAME);
|
|
432
444
|
})
|
|
433
445
|
);
|
|
434
446
|
return this.clusterConnections;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.4.
|
|
6
|
+
"version": "1.4.4",
|
|
7
7
|
"description": "Utility functions for both browser and Node.js",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"module": "dist/index.mjs",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"bullmq": "^5.58.2",
|
|
78
78
|
"ioredis": "^5.6.1",
|
|
79
|
+
"mongodb": "^6.13.0",
|
|
79
80
|
"mongoose": "^8.15.1"
|
|
80
81
|
}
|
|
81
82
|
}
|