@okf/ootils 1.21.4 → 1.21.5
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 -2
- package/dist/node.d.ts +1 -2
- package/dist/node.js +21 -66
- package/dist/node.mjs +21 -66
- package/package.json +1 -1
package/dist/node.d.mts
CHANGED
|
@@ -776,9 +776,8 @@ declare class MongoConnector {
|
|
|
776
776
|
*/
|
|
777
777
|
multiConnectToMongoDB(): {};
|
|
778
778
|
multiConnectToMongoDBAsync(): Promise<{}>;
|
|
779
|
-
|
|
779
|
+
skippedClusters: Set<any> | undefined;
|
|
780
780
|
initiateConnectionEventListeners: (CLUSTER_NAME: any) => void;
|
|
781
|
-
initiateOptionalConnectionEventListeners: (CLUSTER_NAME: any) => void;
|
|
782
781
|
/**
|
|
783
782
|
* Helper function to close clusterConnections object
|
|
784
783
|
*/
|
package/dist/node.d.ts
CHANGED
|
@@ -776,9 +776,8 @@ declare class MongoConnector {
|
|
|
776
776
|
*/
|
|
777
777
|
multiConnectToMongoDB(): {};
|
|
778
778
|
multiConnectToMongoDBAsync(): Promise<{}>;
|
|
779
|
-
|
|
779
|
+
skippedClusters: Set<any> | undefined;
|
|
780
780
|
initiateConnectionEventListeners: (CLUSTER_NAME: any) => void;
|
|
781
|
-
initiateOptionalConnectionEventListeners: (CLUSTER_NAME: any) => void;
|
|
782
781
|
/**
|
|
783
782
|
* Helper function to close clusterConnections object
|
|
784
783
|
*/
|
package/dist/node.js
CHANGED
|
@@ -700,26 +700,6 @@ var require_MongoConnector = __commonJS({
|
|
|
700
700
|
console.log(`\u{1F504} Mongoose reconnected to ${CLUSTER_NAME}`);
|
|
701
701
|
});
|
|
702
702
|
});
|
|
703
|
-
__publicField(this, "initiateOptionalConnectionEventListeners", (CLUSTER_NAME) => {
|
|
704
|
-
this.clusterConnections[CLUSTER_NAME].on("open", () => {
|
|
705
|
-
console.log(`\u2705 Mongoose connection open to optional cluster ${CLUSTER_NAME}`);
|
|
706
|
-
this.failedOptionalClusters?.delete(CLUSTER_NAME);
|
|
707
|
-
});
|
|
708
|
-
this.clusterConnections[CLUSTER_NAME].on("error", (err) => {
|
|
709
|
-
console.warn(
|
|
710
|
-
`\u26A0\uFE0F Mongoose connection error on optional cluster ${CLUSTER_NAME}: ${err.message}`
|
|
711
|
-
);
|
|
712
|
-
this.failedOptionalClusters?.add(CLUSTER_NAME);
|
|
713
|
-
});
|
|
714
|
-
this.clusterConnections[CLUSTER_NAME].on("disconnected", () => {
|
|
715
|
-
console.log(`\u{1F50C} Mongoose disconnected from optional cluster ${CLUSTER_NAME}`);
|
|
716
|
-
this.failedOptionalClusters?.add(CLUSTER_NAME);
|
|
717
|
-
});
|
|
718
|
-
this.clusterConnections[CLUSTER_NAME].on("reconnected", () => {
|
|
719
|
-
console.log(`\u{1F504} Mongoose reconnected to optional cluster ${CLUSTER_NAME}`);
|
|
720
|
-
this.failedOptionalClusters?.delete(CLUSTER_NAME);
|
|
721
|
-
});
|
|
722
|
-
});
|
|
723
703
|
this.clusterConnections = {};
|
|
724
704
|
this.env = options.env;
|
|
725
705
|
this.dbConfigs = options.dbConfigs;
|
|
@@ -773,62 +753,37 @@ var require_MongoConnector = __commonJS({
|
|
|
773
753
|
}
|
|
774
754
|
async multiConnectToMongoDBAsync() {
|
|
775
755
|
const allClusterConfigs = Object.values(this.dbConfigs);
|
|
776
|
-
this.
|
|
756
|
+
this.skippedClusters = /* @__PURE__ */ new Set();
|
|
777
757
|
await Promise.all(
|
|
778
758
|
allClusterConfigs.map(async (clusterConf) => {
|
|
779
|
-
const { CLUSTER_NAME, CLUSTER_URI,
|
|
759
|
+
const { CLUSTER_NAME, CLUSTER_URI, skip } = clusterConf;
|
|
780
760
|
if (!CLUSTER_NAME || !CLUSTER_URI) {
|
|
781
761
|
throw new Error(
|
|
782
762
|
`Missing CLUSTER_NAME or CLUSTER_URI in cluster conf: ${JSON.stringify(clusterConf)}`
|
|
783
763
|
);
|
|
784
764
|
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
this.
|
|
788
|
-
|
|
789
|
-
this.initiateConnectionEventListeners(CLUSTER_NAME);
|
|
790
|
-
} else {
|
|
791
|
-
this.initiateOptionalConnectionEventListeners(CLUSTER_NAME);
|
|
792
|
-
}
|
|
793
|
-
await new Promise((resolve, reject) => {
|
|
794
|
-
connection.once("open", () => {
|
|
795
|
-
console.log(`Connected to MongoDB: ${CLUSTER_NAME}`);
|
|
796
|
-
resolve();
|
|
797
|
-
});
|
|
798
|
-
connection.once("error", (err) => {
|
|
799
|
-
if (optional) {
|
|
800
|
-
console.warn(`\u26A0\uFE0F Optional cluster ${CLUSTER_NAME} failed to connect: ${err.message}`);
|
|
801
|
-
resolve();
|
|
802
|
-
} else {
|
|
803
|
-
reject(err);
|
|
804
|
-
}
|
|
805
|
-
});
|
|
806
|
-
});
|
|
807
|
-
} catch (err) {
|
|
808
|
-
if (optional) {
|
|
809
|
-
console.warn(`\u26A0\uFE0F Optional cluster ${CLUSTER_NAME} failed to connect: ${err.message}`);
|
|
810
|
-
this.failedOptionalClusters.add(CLUSTER_NAME);
|
|
811
|
-
delete this.clusterConnections[CLUSTER_NAME];
|
|
812
|
-
} else {
|
|
813
|
-
throw err;
|
|
814
|
-
}
|
|
765
|
+
if (skip) {
|
|
766
|
+
console.log(`\u23ED\uFE0F Skipping cluster ${CLUSTER_NAME} (skip: true)`);
|
|
767
|
+
this.skippedClusters.add(CLUSTER_NAME);
|
|
768
|
+
return;
|
|
815
769
|
}
|
|
770
|
+
const connection = mongoose5.createConnection(CLUSTER_URI, this.mongoOptions);
|
|
771
|
+
this.clusterConnections[CLUSTER_NAME] = connection;
|
|
772
|
+
this.initiateConnectionEventListeners(CLUSTER_NAME);
|
|
773
|
+
await new Promise((resolve, reject) => {
|
|
774
|
+
connection.once("open", () => {
|
|
775
|
+
console.log(`Connected to MongoDB: ${CLUSTER_NAME}`);
|
|
776
|
+
resolve();
|
|
777
|
+
});
|
|
778
|
+
connection.once("error", reject);
|
|
779
|
+
});
|
|
816
780
|
})
|
|
817
781
|
);
|
|
818
|
-
|
|
819
|
-
delete this.clusterConnections[clusterName];
|
|
820
|
-
}
|
|
821
|
-
const optionalFailedCount = this.failedOptionalClusters.size;
|
|
782
|
+
const skippedCount = this.skippedClusters.size;
|
|
822
783
|
const connectedCount = Object.keys(this.clusterConnections).length;
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
);
|
|
827
|
-
} else {
|
|
828
|
-
console.log(
|
|
829
|
-
`\u{1F389} Connected to ${connectedCount} MongoDB databases`
|
|
830
|
-
);
|
|
831
|
-
}
|
|
784
|
+
let statusMsg = `\u{1F389} Connected to ${connectedCount} MongoDB databases`;
|
|
785
|
+
if (skippedCount > 0) statusMsg += ` (${skippedCount} skipped)`;
|
|
786
|
+
console.log(statusMsg);
|
|
832
787
|
return this.clusterConnections;
|
|
833
788
|
}
|
|
834
789
|
// Static method to get the full instance
|
|
@@ -869,7 +824,7 @@ var require_MongoConnector = __commonJS({
|
|
|
869
824
|
if (!_MongoConnector.instance) {
|
|
870
825
|
throw new Error("MongoConnector not initialized");
|
|
871
826
|
}
|
|
872
|
-
return _MongoConnector.instance.
|
|
827
|
+
return _MongoConnector.instance.skippedClusters?.has(clusterName) || !_MongoConnector.instance.clusterConnections[clusterName];
|
|
873
828
|
}
|
|
874
829
|
/**
|
|
875
830
|
* Helper function to close clusterConnections object
|
package/dist/node.mjs
CHANGED
|
@@ -705,26 +705,6 @@ var require_MongoConnector = __commonJS({
|
|
|
705
705
|
console.log(`\u{1F504} Mongoose reconnected to ${CLUSTER_NAME}`);
|
|
706
706
|
});
|
|
707
707
|
});
|
|
708
|
-
__publicField(this, "initiateOptionalConnectionEventListeners", (CLUSTER_NAME) => {
|
|
709
|
-
this.clusterConnections[CLUSTER_NAME].on("open", () => {
|
|
710
|
-
console.log(`\u2705 Mongoose connection open to optional cluster ${CLUSTER_NAME}`);
|
|
711
|
-
this.failedOptionalClusters?.delete(CLUSTER_NAME);
|
|
712
|
-
});
|
|
713
|
-
this.clusterConnections[CLUSTER_NAME].on("error", (err) => {
|
|
714
|
-
console.warn(
|
|
715
|
-
`\u26A0\uFE0F Mongoose connection error on optional cluster ${CLUSTER_NAME}: ${err.message}`
|
|
716
|
-
);
|
|
717
|
-
this.failedOptionalClusters?.add(CLUSTER_NAME);
|
|
718
|
-
});
|
|
719
|
-
this.clusterConnections[CLUSTER_NAME].on("disconnected", () => {
|
|
720
|
-
console.log(`\u{1F50C} Mongoose disconnected from optional cluster ${CLUSTER_NAME}`);
|
|
721
|
-
this.failedOptionalClusters?.add(CLUSTER_NAME);
|
|
722
|
-
});
|
|
723
|
-
this.clusterConnections[CLUSTER_NAME].on("reconnected", () => {
|
|
724
|
-
console.log(`\u{1F504} Mongoose reconnected to optional cluster ${CLUSTER_NAME}`);
|
|
725
|
-
this.failedOptionalClusters?.delete(CLUSTER_NAME);
|
|
726
|
-
});
|
|
727
|
-
});
|
|
728
708
|
this.clusterConnections = {};
|
|
729
709
|
this.env = options.env;
|
|
730
710
|
this.dbConfigs = options.dbConfigs;
|
|
@@ -778,62 +758,37 @@ var require_MongoConnector = __commonJS({
|
|
|
778
758
|
}
|
|
779
759
|
async multiConnectToMongoDBAsync() {
|
|
780
760
|
const allClusterConfigs = Object.values(this.dbConfigs);
|
|
781
|
-
this.
|
|
761
|
+
this.skippedClusters = /* @__PURE__ */ new Set();
|
|
782
762
|
await Promise.all(
|
|
783
763
|
allClusterConfigs.map(async (clusterConf) => {
|
|
784
|
-
const { CLUSTER_NAME, CLUSTER_URI,
|
|
764
|
+
const { CLUSTER_NAME, CLUSTER_URI, skip } = clusterConf;
|
|
785
765
|
if (!CLUSTER_NAME || !CLUSTER_URI) {
|
|
786
766
|
throw new Error(
|
|
787
767
|
`Missing CLUSTER_NAME or CLUSTER_URI in cluster conf: ${JSON.stringify(clusterConf)}`
|
|
788
768
|
);
|
|
789
769
|
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
this.
|
|
793
|
-
|
|
794
|
-
this.initiateConnectionEventListeners(CLUSTER_NAME);
|
|
795
|
-
} else {
|
|
796
|
-
this.initiateOptionalConnectionEventListeners(CLUSTER_NAME);
|
|
797
|
-
}
|
|
798
|
-
await new Promise((resolve, reject) => {
|
|
799
|
-
connection.once("open", () => {
|
|
800
|
-
console.log(`Connected to MongoDB: ${CLUSTER_NAME}`);
|
|
801
|
-
resolve();
|
|
802
|
-
});
|
|
803
|
-
connection.once("error", (err) => {
|
|
804
|
-
if (optional) {
|
|
805
|
-
console.warn(`\u26A0\uFE0F Optional cluster ${CLUSTER_NAME} failed to connect: ${err.message}`);
|
|
806
|
-
resolve();
|
|
807
|
-
} else {
|
|
808
|
-
reject(err);
|
|
809
|
-
}
|
|
810
|
-
});
|
|
811
|
-
});
|
|
812
|
-
} catch (err) {
|
|
813
|
-
if (optional) {
|
|
814
|
-
console.warn(`\u26A0\uFE0F Optional cluster ${CLUSTER_NAME} failed to connect: ${err.message}`);
|
|
815
|
-
this.failedOptionalClusters.add(CLUSTER_NAME);
|
|
816
|
-
delete this.clusterConnections[CLUSTER_NAME];
|
|
817
|
-
} else {
|
|
818
|
-
throw err;
|
|
819
|
-
}
|
|
770
|
+
if (skip) {
|
|
771
|
+
console.log(`\u23ED\uFE0F Skipping cluster ${CLUSTER_NAME} (skip: true)`);
|
|
772
|
+
this.skippedClusters.add(CLUSTER_NAME);
|
|
773
|
+
return;
|
|
820
774
|
}
|
|
775
|
+
const connection = mongoose5.createConnection(CLUSTER_URI, this.mongoOptions);
|
|
776
|
+
this.clusterConnections[CLUSTER_NAME] = connection;
|
|
777
|
+
this.initiateConnectionEventListeners(CLUSTER_NAME);
|
|
778
|
+
await new Promise((resolve, reject) => {
|
|
779
|
+
connection.once("open", () => {
|
|
780
|
+
console.log(`Connected to MongoDB: ${CLUSTER_NAME}`);
|
|
781
|
+
resolve();
|
|
782
|
+
});
|
|
783
|
+
connection.once("error", reject);
|
|
784
|
+
});
|
|
821
785
|
})
|
|
822
786
|
);
|
|
823
|
-
|
|
824
|
-
delete this.clusterConnections[clusterName];
|
|
825
|
-
}
|
|
826
|
-
const optionalFailedCount = this.failedOptionalClusters.size;
|
|
787
|
+
const skippedCount = this.skippedClusters.size;
|
|
827
788
|
const connectedCount = Object.keys(this.clusterConnections).length;
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
);
|
|
832
|
-
} else {
|
|
833
|
-
console.log(
|
|
834
|
-
`\u{1F389} Connected to ${connectedCount} MongoDB databases`
|
|
835
|
-
);
|
|
836
|
-
}
|
|
789
|
+
let statusMsg = `\u{1F389} Connected to ${connectedCount} MongoDB databases`;
|
|
790
|
+
if (skippedCount > 0) statusMsg += ` (${skippedCount} skipped)`;
|
|
791
|
+
console.log(statusMsg);
|
|
837
792
|
return this.clusterConnections;
|
|
838
793
|
}
|
|
839
794
|
// Static method to get the full instance
|
|
@@ -874,7 +829,7 @@ var require_MongoConnector = __commonJS({
|
|
|
874
829
|
if (!_MongoConnector.instance) {
|
|
875
830
|
throw new Error("MongoConnector not initialized");
|
|
876
831
|
}
|
|
877
|
-
return _MongoConnector.instance.
|
|
832
|
+
return _MongoConnector.instance.skippedClusters?.has(clusterName) || !_MongoConnector.instance.clusterConnections[clusterName];
|
|
878
833
|
}
|
|
879
834
|
/**
|
|
880
835
|
* Helper function to close clusterConnections object
|