@okf/ootils 1.21.3 → 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 CHANGED
@@ -763,6 +763,7 @@ declare class MongoConnector {
763
763
  static getEnv(): any;
764
764
  static getDbConfigs(): any;
765
765
  static getTenantToClusterMapping(): any;
766
+ static isClusterUnavailable(clusterName: any): any;
766
767
  constructor(options: any);
767
768
  clusterConnections: {};
768
769
  env: any;
@@ -775,6 +776,7 @@ declare class MongoConnector {
775
776
  */
776
777
  multiConnectToMongoDB(): {};
777
778
  multiConnectToMongoDBAsync(): Promise<{}>;
779
+ skippedClusters: Set<any> | undefined;
778
780
  initiateConnectionEventListeners: (CLUSTER_NAME: any) => void;
779
781
  /**
780
782
  * Helper function to close clusterConnections object
package/dist/node.d.ts CHANGED
@@ -763,6 +763,7 @@ declare class MongoConnector {
763
763
  static getEnv(): any;
764
764
  static getDbConfigs(): any;
765
765
  static getTenantToClusterMapping(): any;
766
+ static isClusterUnavailable(clusterName: any): any;
766
767
  constructor(options: any);
767
768
  clusterConnections: {};
768
769
  env: any;
@@ -775,6 +776,7 @@ declare class MongoConnector {
775
776
  */
776
777
  multiConnectToMongoDB(): {};
777
778
  multiConnectToMongoDBAsync(): Promise<{}>;
779
+ skippedClusters: Set<any> | undefined;
778
780
  initiateConnectionEventListeners: (CLUSTER_NAME: any) => void;
779
781
  /**
780
782
  * Helper function to close clusterConnections object
package/dist/node.js CHANGED
@@ -753,14 +753,20 @@ var require_MongoConnector = __commonJS({
753
753
  }
754
754
  async multiConnectToMongoDBAsync() {
755
755
  const allClusterConfigs = Object.values(this.dbConfigs);
756
+ this.skippedClusters = /* @__PURE__ */ new Set();
756
757
  await Promise.all(
757
758
  allClusterConfigs.map(async (clusterConf) => {
758
- const { CLUSTER_NAME, CLUSTER_URI } = clusterConf;
759
+ const { CLUSTER_NAME, CLUSTER_URI, skip } = clusterConf;
759
760
  if (!CLUSTER_NAME || !CLUSTER_URI) {
760
761
  throw new Error(
761
762
  `Missing CLUSTER_NAME or CLUSTER_URI in cluster conf: ${JSON.stringify(clusterConf)}`
762
763
  );
763
764
  }
765
+ if (skip) {
766
+ console.log(`\u23ED\uFE0F Skipping cluster ${CLUSTER_NAME} (skip: true)`);
767
+ this.skippedClusters.add(CLUSTER_NAME);
768
+ return;
769
+ }
764
770
  const connection = mongoose5.createConnection(CLUSTER_URI, this.mongoOptions);
765
771
  this.clusterConnections[CLUSTER_NAME] = connection;
766
772
  this.initiateConnectionEventListeners(CLUSTER_NAME);
@@ -773,9 +779,11 @@ var require_MongoConnector = __commonJS({
773
779
  });
774
780
  })
775
781
  );
776
- console.log(
777
- `\u{1F389} Connected to ${Object.keys(this.clusterConnections).length} MongoDB databases`
778
- );
782
+ const skippedCount = this.skippedClusters.size;
783
+ const connectedCount = Object.keys(this.clusterConnections).length;
784
+ let statusMsg = `\u{1F389} Connected to ${connectedCount} MongoDB databases`;
785
+ if (skippedCount > 0) statusMsg += ` (${skippedCount} skipped)`;
786
+ console.log(statusMsg);
779
787
  return this.clusterConnections;
780
788
  }
781
789
  // Static method to get the full instance
@@ -812,6 +820,12 @@ var require_MongoConnector = __commonJS({
812
820
  }
813
821
  return _MongoConnector.instance.tenantToClusterMapping;
814
822
  }
823
+ static isClusterUnavailable(clusterName) {
824
+ if (!_MongoConnector.instance) {
825
+ throw new Error("MongoConnector not initialized");
826
+ }
827
+ return _MongoConnector.instance.skippedClusters?.has(clusterName) || !_MongoConnector.instance.clusterConnections[clusterName];
828
+ }
815
829
  /**
816
830
  * Helper function to close clusterConnections object
817
831
  */
package/dist/node.mjs CHANGED
@@ -758,14 +758,20 @@ var require_MongoConnector = __commonJS({
758
758
  }
759
759
  async multiConnectToMongoDBAsync() {
760
760
  const allClusterConfigs = Object.values(this.dbConfigs);
761
+ this.skippedClusters = /* @__PURE__ */ new Set();
761
762
  await Promise.all(
762
763
  allClusterConfigs.map(async (clusterConf) => {
763
- const { CLUSTER_NAME, CLUSTER_URI } = clusterConf;
764
+ const { CLUSTER_NAME, CLUSTER_URI, skip } = clusterConf;
764
765
  if (!CLUSTER_NAME || !CLUSTER_URI) {
765
766
  throw new Error(
766
767
  `Missing CLUSTER_NAME or CLUSTER_URI in cluster conf: ${JSON.stringify(clusterConf)}`
767
768
  );
768
769
  }
770
+ if (skip) {
771
+ console.log(`\u23ED\uFE0F Skipping cluster ${CLUSTER_NAME} (skip: true)`);
772
+ this.skippedClusters.add(CLUSTER_NAME);
773
+ return;
774
+ }
769
775
  const connection = mongoose5.createConnection(CLUSTER_URI, this.mongoOptions);
770
776
  this.clusterConnections[CLUSTER_NAME] = connection;
771
777
  this.initiateConnectionEventListeners(CLUSTER_NAME);
@@ -778,9 +784,11 @@ var require_MongoConnector = __commonJS({
778
784
  });
779
785
  })
780
786
  );
781
- console.log(
782
- `\u{1F389} Connected to ${Object.keys(this.clusterConnections).length} MongoDB databases`
783
- );
787
+ const skippedCount = this.skippedClusters.size;
788
+ const connectedCount = Object.keys(this.clusterConnections).length;
789
+ let statusMsg = `\u{1F389} Connected to ${connectedCount} MongoDB databases`;
790
+ if (skippedCount > 0) statusMsg += ` (${skippedCount} skipped)`;
791
+ console.log(statusMsg);
784
792
  return this.clusterConnections;
785
793
  }
786
794
  // Static method to get the full instance
@@ -817,6 +825,12 @@ var require_MongoConnector = __commonJS({
817
825
  }
818
826
  return _MongoConnector.instance.tenantToClusterMapping;
819
827
  }
828
+ static isClusterUnavailable(clusterName) {
829
+ if (!_MongoConnector.instance) {
830
+ throw new Error("MongoConnector not initialized");
831
+ }
832
+ return _MongoConnector.instance.skippedClusters?.has(clusterName) || !_MongoConnector.instance.clusterConnections[clusterName];
833
+ }
820
834
  /**
821
835
  * Helper function to close clusterConnections object
822
836
  */
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.21.3",
6
+ "version": "1.21.5",
7
7
  "description": "Utility functions for both browser and Node.js",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.mjs",