@atscript/mongo 0.0.18 → 0.0.20

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/index.cjs CHANGED
@@ -1087,13 +1087,20 @@ var AsMongo = class {
1087
1087
  return list.has(name);
1088
1088
  }
1089
1089
  getCollection(type, logger) {
1090
- return new AsCollection(this, type, logger || this.logger);
1090
+ let collection = this._collections.get(type);
1091
+ if (!collection) {
1092
+ collection = new AsCollection(this, type, logger || this.logger);
1093
+ this._collections.set(type, collection);
1094
+ }
1095
+ return collection;
1091
1096
  }
1092
1097
  constructor(client, logger = NoopLogger) {
1093
1098
  _define_property(this, "logger", void 0);
1094
1099
  _define_property(this, "client", void 0);
1095
1100
  _define_property(this, "collectionsList", void 0);
1101
+ _define_property(this, "_collections", void 0);
1096
1102
  this.logger = logger;
1103
+ this._collections = new WeakMap();
1097
1104
  if (typeof client === "string") this.client = new mongodb.MongoClient(client);
1098
1105
  else this.client = client;
1099
1106
  }
package/dist/index.d.ts CHANGED
@@ -22,6 +22,7 @@ declare class AsMongo {
22
22
  protected getCollectionsList(): Promise<Set<string>>;
23
23
  collectionExists(name: string): Promise<boolean>;
24
24
  getCollection<T extends TAtscriptAnnotatedTypeConstructor>(type: T, logger?: TGenericLogger): AsCollection<T>;
25
+ private _collections;
25
26
  }
26
27
 
27
28
  type TPlainIndex = {
package/dist/index.mjs CHANGED
@@ -1063,13 +1063,20 @@ var AsMongo = class {
1063
1063
  return list.has(name);
1064
1064
  }
1065
1065
  getCollection(type, logger) {
1066
- return new AsCollection(this, type, logger || this.logger);
1066
+ let collection = this._collections.get(type);
1067
+ if (!collection) {
1068
+ collection = new AsCollection(this, type, logger || this.logger);
1069
+ this._collections.set(type, collection);
1070
+ }
1071
+ return collection;
1067
1072
  }
1068
1073
  constructor(client, logger = NoopLogger) {
1069
1074
  _define_property(this, "logger", void 0);
1070
1075
  _define_property(this, "client", void 0);
1071
1076
  _define_property(this, "collectionsList", void 0);
1077
+ _define_property(this, "_collections", void 0);
1072
1078
  this.logger = logger;
1079
+ this._collections = new WeakMap();
1073
1080
  if (typeof client === "string") this.client = new MongoClient(client);
1074
1081
  else this.client = client;
1075
1082
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/mongo",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "Mongodb plugin for atscript.",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -34,8 +34,8 @@
34
34
  "license": "ISC",
35
35
  "peerDependencies": {
36
36
  "mongodb": "^6.17.0",
37
- "@atscript/core": "^0.0.18",
38
- "@atscript/typescript": "^0.0.18"
37
+ "@atscript/core": "^0.0.20",
38
+ "@atscript/typescript": "^0.0.20"
39
39
  },
40
40
  "devDependencies": {
41
41
  "vitest": "3.2.4"