@smartsoft001/mongo 2.126.0 → 2.128.0
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/index.cjs +23 -31
- package/package.json +5 -5
package/index.cjs
CHANGED
|
@@ -30,23 +30,21 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
30
30
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
31
31
|
if (decorator = decorators[i])
|
|
32
32
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
33
|
-
if (kind && result)
|
|
34
|
-
__defProp(target, key, result);
|
|
33
|
+
if (kind && result) __defProp(target, key, result);
|
|
35
34
|
return result;
|
|
36
35
|
};
|
|
37
36
|
|
|
38
37
|
// packages/shared/mongo/src/index.ts
|
|
39
|
-
var
|
|
40
|
-
__export(
|
|
38
|
+
var index_exports = {};
|
|
39
|
+
__export(index_exports, {
|
|
41
40
|
MongoConfig: () => MongoConfig,
|
|
42
41
|
MongoItemRepository: () => MongoItemRepository,
|
|
43
42
|
MongoModule: () => MongoModule
|
|
44
43
|
});
|
|
45
|
-
module.exports = __toCommonJS(
|
|
44
|
+
module.exports = __toCommonJS(index_exports);
|
|
46
45
|
|
|
47
46
|
// packages/shared/models/src/lib/symbols.ts
|
|
48
|
-
var
|
|
49
|
-
var SYMBOL_FIELD = Symbol.for("smartsoft:field");
|
|
47
|
+
var SYMBOL_FIELD = /* @__PURE__ */ Symbol.for("smartsoft:field");
|
|
50
48
|
|
|
51
49
|
// packages/shared/models/src/lib/decorators/model/model.decorator.ts
|
|
52
50
|
var import_reflect_metadata = require("reflect-metadata");
|
|
@@ -70,11 +68,9 @@ var ObjectService = class {
|
|
|
70
68
|
* @return - new type object
|
|
71
69
|
*/
|
|
72
70
|
static createByType(data, type) {
|
|
73
|
-
if (!data)
|
|
74
|
-
return data;
|
|
71
|
+
if (!data) return data;
|
|
75
72
|
try {
|
|
76
|
-
if (data instanceof type)
|
|
77
|
-
return data;
|
|
73
|
+
if (data instanceof type) return data;
|
|
78
74
|
} catch (e) {
|
|
79
75
|
console.warn(e);
|
|
80
76
|
}
|
|
@@ -90,8 +86,7 @@ var ObjectService = class {
|
|
|
90
86
|
* @return - object without type
|
|
91
87
|
*/
|
|
92
88
|
static removeTypes(obj) {
|
|
93
|
-
if (!obj)
|
|
94
|
-
return obj;
|
|
89
|
+
if (!obj) return obj;
|
|
95
90
|
const result = {};
|
|
96
91
|
Object.keys(obj).forEach((key) => {
|
|
97
92
|
if (obj[key] && obj[key].constructor && !(obj[key] instanceof Date)) {
|
|
@@ -116,8 +111,7 @@ var import_md5 = __toESM(require("md5"));
|
|
|
116
111
|
|
|
117
112
|
// packages/shared/models/src/lib/utils.ts
|
|
118
113
|
function getModelFieldKeys(type) {
|
|
119
|
-
if (!type["__fields"])
|
|
120
|
-
return [];
|
|
114
|
+
if (!type["__fields"]) return [];
|
|
121
115
|
return Object.keys(type["__fields"]);
|
|
122
116
|
}
|
|
123
117
|
function getModelFieldOptions(instance, fieldKey) {
|
|
@@ -162,8 +156,7 @@ function getMongoUrl(config) {
|
|
|
162
156
|
let url;
|
|
163
157
|
if (config.username && config.password)
|
|
164
158
|
url = `mongodb://${config.username}:${config.password}@${config.host}:${config.port}`;
|
|
165
|
-
else
|
|
166
|
-
url = `mongodb://${config.host}:${config.port}`;
|
|
159
|
+
else url = `mongodb://${config.host}:${config.port}`;
|
|
167
160
|
url = url + "?authSource=" + config.database;
|
|
168
161
|
if (config.host.indexOf("ondigitalocean.com") > -1) {
|
|
169
162
|
url = url.replace("mongodb://", "mongodb+srv://");
|
|
@@ -178,6 +171,7 @@ var MongoUnitOfWork = class extends IUnitOfWork {
|
|
|
178
171
|
super();
|
|
179
172
|
this.config = config;
|
|
180
173
|
}
|
|
174
|
+
config;
|
|
181
175
|
async scope(definition) {
|
|
182
176
|
const client = await import_mongodb.MongoClient.connect(this.getUrl());
|
|
183
177
|
const session = client.startSession();
|
|
@@ -200,8 +194,7 @@ var MongoUnitOfWork = class extends IUnitOfWork {
|
|
|
200
194
|
await session.endSession();
|
|
201
195
|
await client.close();
|
|
202
196
|
}
|
|
203
|
-
if (error)
|
|
204
|
-
throw error;
|
|
197
|
+
if (error) throw error;
|
|
205
198
|
}
|
|
206
199
|
getUrl() {
|
|
207
200
|
return getMongoUrl(this.config);
|
|
@@ -220,6 +213,7 @@ var MongoAttachmentRepository = class extends IAttachmentRepository {
|
|
|
220
213
|
super();
|
|
221
214
|
this.config = config;
|
|
222
215
|
}
|
|
216
|
+
config;
|
|
223
217
|
async upload(data, options) {
|
|
224
218
|
const client = await import_mongodb2.MongoClient.connect(this.getUrl());
|
|
225
219
|
return await new Promise((res, rej) => {
|
|
@@ -231,11 +225,10 @@ var MongoAttachmentRepository = class extends IAttachmentRepository {
|
|
|
231
225
|
data.id,
|
|
232
226
|
data.fileName,
|
|
233
227
|
{
|
|
234
|
-
contentType: data.mimeType
|
|
228
|
+
metadata: { contentType: data.mimeType }
|
|
235
229
|
}
|
|
236
230
|
);
|
|
237
|
-
if (options?.streamCallback)
|
|
238
|
-
options.streamCallback(writeStream);
|
|
231
|
+
if (options?.streamCallback) options.streamCallback(writeStream);
|
|
239
232
|
data.stream.pipe(writeStream);
|
|
240
233
|
writeStream.on("error", (error) => {
|
|
241
234
|
rej(error);
|
|
@@ -254,11 +247,12 @@ var MongoAttachmentRepository = class extends IAttachmentRepository {
|
|
|
254
247
|
const items = await bucket.find({
|
|
255
248
|
_id: id
|
|
256
249
|
}).toArray();
|
|
257
|
-
if (!items || items.length === 0)
|
|
258
|
-
return null;
|
|
250
|
+
if (!items || items.length === 0) return null;
|
|
259
251
|
return {
|
|
260
252
|
fileName: items[0].filename,
|
|
261
|
-
contentType
|
|
253
|
+
// mongodb 7 removed the deprecated top-level contentType - files written
|
|
254
|
+
// by older driver versions still carry it, so fall back to it
|
|
255
|
+
contentType: items[0].metadata?.["contentType"] ?? items[0].contentType,
|
|
262
256
|
length: items[0].length
|
|
263
257
|
};
|
|
264
258
|
}
|
|
@@ -297,6 +291,7 @@ var MongoItemRepository = class extends IItemRepository {
|
|
|
297
291
|
super();
|
|
298
292
|
this.config = config;
|
|
299
293
|
}
|
|
294
|
+
config;
|
|
300
295
|
async create(item, user, repoOptions) {
|
|
301
296
|
await this.collectionContext(async (collection) => {
|
|
302
297
|
try {
|
|
@@ -612,8 +607,7 @@ var MongoItemRepository = class extends IItemRepository {
|
|
|
612
607
|
return result;
|
|
613
608
|
}
|
|
614
609
|
getModelToResult(item) {
|
|
615
|
-
if (!item)
|
|
616
|
-
return null;
|
|
610
|
+
if (!item) return null;
|
|
617
611
|
const result = ObjectService.removeTypes(item);
|
|
618
612
|
result["id"] = result._id;
|
|
619
613
|
delete result._id;
|
|
@@ -643,8 +637,7 @@ var MongoItemRepository = class extends IItemRepository {
|
|
|
643
637
|
}
|
|
644
638
|
}
|
|
645
639
|
generateSearch(criteria) {
|
|
646
|
-
if (!criteria["$search"])
|
|
647
|
-
return;
|
|
640
|
+
if (!criteria["$search"]) return;
|
|
648
641
|
if (this.config.type) {
|
|
649
642
|
const modelFields = getModelFieldsWithOptions(
|
|
650
643
|
new this.config.type()
|
|
@@ -659,8 +652,7 @@ var MongoItemRepository = class extends IItemRepository {
|
|
|
659
652
|
};
|
|
660
653
|
searchArray.push(res);
|
|
661
654
|
});
|
|
662
|
-
if (!criteria["$or"])
|
|
663
|
-
criteria["$or"] = searchArray;
|
|
655
|
+
if (!criteria["$or"]) criteria["$or"] = searchArray;
|
|
664
656
|
else if (criteria["$or"] && !criteria["$and"]) {
|
|
665
657
|
criteria["$and"] = [{ $or: criteria["$or"] }, { $or: searchArray }];
|
|
666
658
|
delete criteria["$or"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartsoft001/mongo",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.128.0",
|
|
4
4
|
"description": "Utils to mongo",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/emiljuchnikowski/smartsoft#readme",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@angular/core": "
|
|
22
|
-
"@jest/globals": "30.
|
|
21
|
+
"@angular/core": "22.1.3",
|
|
22
|
+
"@jest/globals": "30.4.1",
|
|
23
23
|
"@nestjs/common": "^11.1.5",
|
|
24
|
-
"flatted": "3.4.
|
|
24
|
+
"flatted": "3.4.4",
|
|
25
25
|
"guid-typescript": "^1.0.9",
|
|
26
26
|
"lodash": "4.18.1",
|
|
27
27
|
"md5": "^2.3.0",
|
|
28
|
-
"mongodb": "^5.
|
|
28
|
+
"mongodb": "^7.5.0",
|
|
29
29
|
"reflect-metadata": "^0.2.1",
|
|
30
30
|
"rxjs": "^7.8.1",
|
|
31
31
|
"tslib": "^2.3.0"
|