@orion-js/mongodb 4.2.7 → 4.2.9
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 +40 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +43 -37
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -45,7 +45,7 @@ declare class OrionMongoDatabaseWrapper implements OrionMongoClient {
|
|
|
45
45
|
constructor(connectionName: string);
|
|
46
46
|
config(mongoURL: string, mongoOptions: MongoClientOptions): void;
|
|
47
47
|
awaitConnection(): Promise<this>;
|
|
48
|
-
connectWithRetry(client: MongoClient):
|
|
48
|
+
connectWithRetry(client: MongoClient): Promise<MongoClient>;
|
|
49
49
|
startConnection(): Promise<MongoClient>;
|
|
50
50
|
closeConnection(): Promise<void>;
|
|
51
51
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ declare class OrionMongoDatabaseWrapper implements OrionMongoClient {
|
|
|
45
45
|
constructor(connectionName: string);
|
|
46
46
|
config(mongoURL: string, mongoOptions: MongoClientOptions): void;
|
|
47
47
|
awaitConnection(): Promise<this>;
|
|
48
|
-
connectWithRetry(client: MongoClient):
|
|
48
|
+
connectWithRetry(client: MongoClient): Promise<MongoClient>;
|
|
49
49
|
startConnection(): Promise<MongoClient>;
|
|
50
50
|
closeConnection(): Promise<void>;
|
|
51
51
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// src/connect/connections.ts
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
|
+
import { sleep } from "@orion-js/helpers";
|
|
4
|
+
import { logger } from "@orion-js/logger";
|
|
3
5
|
import { MongoClient } from "mongodb";
|
|
4
6
|
|
|
5
7
|
// src/connect/getDBName.ts
|
|
@@ -22,11 +24,6 @@ function getDBName(url) {
|
|
|
22
24
|
return dbName;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
// src/connect/connections.ts
|
|
26
|
-
import { nextTick } from "process";
|
|
27
|
-
import { logger } from "@orion-js/logger";
|
|
28
|
-
import { sleep } from "@orion-js/helpers";
|
|
29
|
-
|
|
30
27
|
// src/connect/getMongoURLFromEnv.ts
|
|
31
28
|
import { internalGetEnv } from "@orion-js/env";
|
|
32
29
|
var getMongoURLFromEnv = (connectionName) => {
|
|
@@ -131,22 +128,20 @@ var OrionMongoDatabaseWrapper = class {
|
|
|
131
128
|
await this.connectWithRetry(this.client);
|
|
132
129
|
this.state = "connected";
|
|
133
130
|
this.connectionEvent.emit("connected", this.client);
|
|
134
|
-
|
|
135
|
-
this.connectionEvent.removeAllListeners();
|
|
136
|
-
this.connectionEvent = null;
|
|
137
|
-
});
|
|
131
|
+
this.connectionEvent.removeAllListeners();
|
|
138
132
|
return this;
|
|
139
133
|
}
|
|
140
134
|
async connectWithRetry(client) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
error,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
135
|
+
while (true) {
|
|
136
|
+
try {
|
|
137
|
+
return await client.connect();
|
|
138
|
+
} catch (error) {
|
|
139
|
+
logger.error("Error connecting to mongo. Will retry in 5s", {
|
|
140
|
+
error,
|
|
141
|
+
connectionName: this.connectionName
|
|
142
|
+
});
|
|
143
|
+
await sleep(5e3);
|
|
144
|
+
}
|
|
150
145
|
}
|
|
151
146
|
}
|
|
152
147
|
async startConnection() {
|
|
@@ -436,19 +431,6 @@ function omit(propsToOmit, obj) {
|
|
|
436
431
|
return willReturn;
|
|
437
432
|
}
|
|
438
433
|
|
|
439
|
-
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/flatten.js
|
|
440
|
-
function flatten(list, input) {
|
|
441
|
-
const willReturn = input === void 0 ? [] : input;
|
|
442
|
-
for (let i = 0; i < list.length; i++) {
|
|
443
|
-
if (isArray(list[i])) {
|
|
444
|
-
flatten(list[i], willReturn);
|
|
445
|
-
} else {
|
|
446
|
-
willReturn.push(list[i]);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
return willReturn;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
434
|
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isEmpty.js
|
|
453
435
|
function isEmpty(input) {
|
|
454
436
|
const inputType = type(input);
|
|
@@ -1021,16 +1003,26 @@ function loadOne_default(collection) {
|
|
|
1021
1003
|
}
|
|
1022
1004
|
|
|
1023
1005
|
// src/createCollection/getMethods/dataLoader/loadData.ts
|
|
1024
|
-
import { createMapArray
|
|
1006
|
+
import { createMapArray } from "@orion-js/helpers";
|
|
1007
|
+
|
|
1008
|
+
// src/createCollection/getMethods/dataLoader/dataLoad/index.ts
|
|
1009
|
+
import { hashObject } from "@orion-js/helpers";
|
|
1025
1010
|
|
|
1026
1011
|
// src/createCollection/getMethods/dataLoader/dataLoad/getDataLoader.ts
|
|
1027
1012
|
import DataLoader from "dataloader";
|
|
1028
1013
|
var cache = /* @__PURE__ */ new Map();
|
|
1014
|
+
var staleTimers = /* @__PURE__ */ new Map();
|
|
1029
1015
|
var getDataLoader = (params) => {
|
|
1016
|
+
var _a;
|
|
1030
1017
|
const { key, func, timeout } = params;
|
|
1031
1018
|
const existing = cache.get(key);
|
|
1032
1019
|
if (existing) return existing;
|
|
1033
1020
|
const load = async (ids) => {
|
|
1021
|
+
const staleTimer2 = staleTimers.get(key);
|
|
1022
|
+
if (staleTimer2) {
|
|
1023
|
+
clearTimeout(staleTimer2);
|
|
1024
|
+
staleTimers.delete(key);
|
|
1025
|
+
}
|
|
1034
1026
|
cache.delete(key);
|
|
1035
1027
|
return await func(ids);
|
|
1036
1028
|
};
|
|
@@ -1038,13 +1030,27 @@ var getDataLoader = (params) => {
|
|
|
1038
1030
|
batchScheduleFn: (callback) => setTimeout(callback, timeout)
|
|
1039
1031
|
};
|
|
1040
1032
|
const dataLoader = new DataLoader(load, options);
|
|
1033
|
+
const staleTimer = setTimeout(
|
|
1034
|
+
() => {
|
|
1035
|
+
cache.delete(key);
|
|
1036
|
+
staleTimers.delete(key);
|
|
1037
|
+
},
|
|
1038
|
+
Math.max(100, timeout * 20)
|
|
1039
|
+
);
|
|
1040
|
+
(_a = staleTimer.unref) == null ? void 0 : _a.call(staleTimer);
|
|
1041
|
+
staleTimers.set(key, staleTimer);
|
|
1041
1042
|
cache.set(key, dataLoader);
|
|
1042
1043
|
return dataLoader;
|
|
1043
1044
|
};
|
|
1044
1045
|
|
|
1045
1046
|
// src/createCollection/getMethods/dataLoader/dataLoad/index.ts
|
|
1046
|
-
import { hashObject } from "@orion-js/helpers";
|
|
1047
1047
|
var dataLoad = async (options) => {
|
|
1048
|
+
if (options.ids && options.ids.length === 0) {
|
|
1049
|
+
return [];
|
|
1050
|
+
}
|
|
1051
|
+
if (!options.ids && typeof options.id === "undefined") {
|
|
1052
|
+
return [];
|
|
1053
|
+
}
|
|
1048
1054
|
const dataLoader = getDataLoader({
|
|
1049
1055
|
key: hashObject(options.loaderKey),
|
|
1050
1056
|
func: options.load,
|
|
@@ -1052,7 +1058,7 @@ var dataLoad = async (options) => {
|
|
|
1052
1058
|
});
|
|
1053
1059
|
if (options.ids) {
|
|
1054
1060
|
const resultArray = await dataLoader.loadMany(options.ids);
|
|
1055
|
-
return
|
|
1061
|
+
return resultArray.flat();
|
|
1056
1062
|
}
|
|
1057
1063
|
return await dataLoader.load(options.id);
|
|
1058
1064
|
};
|
|
@@ -1075,7 +1081,7 @@ function loadData_default(collection) {
|
|
|
1075
1081
|
timeout: options.timeout,
|
|
1076
1082
|
load: async (values) => {
|
|
1077
1083
|
const query = {
|
|
1078
|
-
...
|
|
1084
|
+
...options.match || {},
|
|
1079
1085
|
[options.key]: { $in: values }
|
|
1080
1086
|
};
|
|
1081
1087
|
const cursor = collection.find(query, { readPreference: "secondaryPreferred" });
|
|
@@ -1365,7 +1371,7 @@ async function loadIndexes(collection) {
|
|
|
1365
1371
|
}
|
|
1366
1372
|
|
|
1367
1373
|
// src/createCollection/getSchemaAndModel.ts
|
|
1368
|
-
import { clone as
|
|
1374
|
+
import { clone as clone2 } from "@orion-js/helpers";
|
|
1369
1375
|
Symbol.metadata ?? (Symbol.metadata = Symbol("Symbol.metadata"));
|
|
1370
1376
|
function prepareShema(schema) {
|
|
1371
1377
|
if (!schema._id) {
|
|
@@ -1387,7 +1393,7 @@ function getSchema(options) {
|
|
|
1387
1393
|
}
|
|
1388
1394
|
if (options.schema.getModel) {
|
|
1389
1395
|
const model = options.schema.getModel();
|
|
1390
|
-
const schema = model ?
|
|
1396
|
+
const schema = model ? clone2(model.getSchema()) : {};
|
|
1391
1397
|
return prepareShema(schema);
|
|
1392
1398
|
}
|
|
1393
1399
|
if (type(options.schema) === "Object") {
|