@opra/mongodb 0.32.4 → 0.32.6
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/cjs/adapter-utils/prepare-patch.js +1 -1
- package/cjs/mongo-array-service.js +4 -4
- package/cjs/mongo-collection-service.js +10 -10
- package/cjs/mongo-service.js +1 -2
- package/esm/adapter-utils/prepare-patch.js +1 -1
- package/esm/mongo-array-service.js +4 -4
- package/esm/mongo-collection-service.js +10 -10
- package/esm/mongo-service.js +1 -2
- package/package.json +4 -4
|
@@ -21,7 +21,7 @@ function _preparePatch(src, trg = {}, path, options) {
|
|
|
21
21
|
trg.$unset[field] = '';
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
|
-
if (v && typeof v === 'object') {
|
|
24
|
+
if (v && typeof v === 'object' && !Array.isArray(v)) {
|
|
25
25
|
// If field name starts with "*", do "replace" operation except "merge"
|
|
26
26
|
if (!k.startsWith('*')) {
|
|
27
27
|
_preparePatch(v, trg, key);
|
|
@@ -64,7 +64,7 @@ class MongoArrayService extends mongo_service_js_1.MongoService {
|
|
|
64
64
|
options
|
|
65
65
|
}, this);
|
|
66
66
|
const encode = this.getEncoder('create');
|
|
67
|
-
const doc = encode(input);
|
|
67
|
+
const doc = encode(input, { coerce: true });
|
|
68
68
|
doc._id = doc._id || this._generateId();
|
|
69
69
|
const docFilter = mongo_adapter_js_1.MongoAdapter.prepareKeyValues(documentId, [this.collectionKey]);
|
|
70
70
|
const r = await this.__updateOne(docFilter, {
|
|
@@ -307,7 +307,7 @@ class MongoArrayService extends mongo_service_js_1.MongoService {
|
|
|
307
307
|
const projection = mongo_adapter_js_1.MongoAdapter.prepareProjection(dataType, options);
|
|
308
308
|
if (projection)
|
|
309
309
|
dataStages.push({ $project: projection });
|
|
310
|
-
const
|
|
310
|
+
const decode = this.getDecoder();
|
|
311
311
|
const cursor = await this.__aggregate(stages, {
|
|
312
312
|
...mongoOptions
|
|
313
313
|
});
|
|
@@ -315,7 +315,7 @@ class MongoArrayService extends mongo_service_js_1.MongoService {
|
|
|
315
315
|
if (options?.count) {
|
|
316
316
|
const facetResult = await cursor.toArray();
|
|
317
317
|
this.context.response.totalMatches = facetResult[0].count[0].totalMatches || 0;
|
|
318
|
-
return facetResult[0].data.map((r) =>
|
|
318
|
+
return facetResult[0].data.map((r) => decode(r, { coerce: true }));
|
|
319
319
|
}
|
|
320
320
|
else
|
|
321
321
|
return await cursor.toArray();
|
|
@@ -412,7 +412,7 @@ class MongoArrayService extends mongo_service_js_1.MongoService {
|
|
|
412
412
|
options
|
|
413
413
|
}, this);
|
|
414
414
|
const encode = this.getEncoder('update');
|
|
415
|
-
const doc = encode(input);
|
|
415
|
+
const doc = encode(input, { coerce: true });
|
|
416
416
|
if (!Object.keys(doc).length)
|
|
417
417
|
return 0;
|
|
418
418
|
const matchFilter = mongo_adapter_js_1.MongoAdapter.prepareFilter([
|
|
@@ -57,7 +57,7 @@ class MongoCollectionService extends mongo_service_js_1.MongoService {
|
|
|
57
57
|
options
|
|
58
58
|
}, this);
|
|
59
59
|
const encode = this.getEncoder('create');
|
|
60
|
-
const doc = encode(input);
|
|
60
|
+
const doc = encode(input, { coerce: true });
|
|
61
61
|
doc._id = doc._id || this._generateId();
|
|
62
62
|
const r = await this.__insertOne(doc, options);
|
|
63
63
|
if (r.insertedId) {
|
|
@@ -188,9 +188,9 @@ class MongoCollectionService extends mongo_service_js_1.MongoService {
|
|
|
188
188
|
projection: mongo_adapter_js_1.MongoAdapter.prepareProjection(this.getDataType(), options),
|
|
189
189
|
limit: undefined
|
|
190
190
|
};
|
|
191
|
-
const
|
|
191
|
+
const decode = this.getDecoder();
|
|
192
192
|
const out = await this.__findOne(filter, mongoOptions);
|
|
193
|
-
return out ?
|
|
193
|
+
return out ? decode(out, { coerce: true }) : undefined;
|
|
194
194
|
}
|
|
195
195
|
/**
|
|
196
196
|
* Finds multiple documents in the MongoDB collection.
|
|
@@ -246,7 +246,7 @@ class MongoCollectionService extends mongo_service_js_1.MongoService {
|
|
|
246
246
|
const projection = mongo_adapter_js_1.MongoAdapter.prepareProjection(dataType, options);
|
|
247
247
|
if (projection)
|
|
248
248
|
dataStages.push({ $project: projection });
|
|
249
|
-
const
|
|
249
|
+
const decode = this.getDecoder();
|
|
250
250
|
const cursor = await this.__aggregate(stages, {
|
|
251
251
|
...mongoOptions
|
|
252
252
|
});
|
|
@@ -254,7 +254,7 @@ class MongoCollectionService extends mongo_service_js_1.MongoService {
|
|
|
254
254
|
if (options?.count) {
|
|
255
255
|
const facetResult = await cursor.toArray();
|
|
256
256
|
this.context.response.totalMatches = facetResult[0].count[0].totalMatches || 0;
|
|
257
|
-
return facetResult[0].data.map((r) =>
|
|
257
|
+
return facetResult[0].data.map((r) => decode(r, { coerce: true }));
|
|
258
258
|
}
|
|
259
259
|
else
|
|
260
260
|
return await cursor.toArray();
|
|
@@ -298,7 +298,7 @@ class MongoCollectionService extends mongo_service_js_1.MongoService {
|
|
|
298
298
|
options,
|
|
299
299
|
}, this);
|
|
300
300
|
const encode = this.getEncoder('update');
|
|
301
|
-
const doc = encode(input);
|
|
301
|
+
const doc = encode(input, { coerce: true });
|
|
302
302
|
const patch = mongo_adapter_js_1.MongoAdapter.preparePatch(doc);
|
|
303
303
|
const mongoOptions = {
|
|
304
304
|
...options,
|
|
@@ -311,9 +311,9 @@ class MongoCollectionService extends mongo_service_js_1.MongoService {
|
|
|
311
311
|
options?.filter,
|
|
312
312
|
await this._getDocumentFilter()
|
|
313
313
|
]);
|
|
314
|
-
const
|
|
314
|
+
const decode = this.getDecoder();
|
|
315
315
|
const out = await this.__findOneAndUpdate(filter, patch, mongoOptions);
|
|
316
|
-
return out ?
|
|
316
|
+
return out ? decode(out, { coerce: true }) : undefined;
|
|
317
317
|
}
|
|
318
318
|
/**
|
|
319
319
|
* Updates a document in the collection with the specified ID.
|
|
@@ -338,7 +338,7 @@ class MongoCollectionService extends mongo_service_js_1.MongoService {
|
|
|
338
338
|
await this._getDocumentFilter()
|
|
339
339
|
]);
|
|
340
340
|
const encode = this.getEncoder('update');
|
|
341
|
-
const doc = encode(input);
|
|
341
|
+
const doc = encode(input, { coerce: true });
|
|
342
342
|
if (!Object.keys(doc).length)
|
|
343
343
|
return 0;
|
|
344
344
|
const patch = mongo_adapter_js_1.MongoAdapter.preparePatch(doc);
|
|
@@ -367,7 +367,7 @@ class MongoCollectionService extends mongo_service_js_1.MongoService {
|
|
|
367
367
|
options,
|
|
368
368
|
}, this);
|
|
369
369
|
const encode = this.getEncoder('update');
|
|
370
|
-
const doc = encode(input);
|
|
370
|
+
const doc = encode(input, { coerce: true });
|
|
371
371
|
if (!Object.keys(doc).length)
|
|
372
372
|
return 0;
|
|
373
373
|
const patch = mongo_adapter_js_1.MongoAdapter.preparePatch(doc);
|
package/cjs/mongo-service.js
CHANGED
|
@@ -430,8 +430,7 @@ class MongoService extends core_1.ApiService {
|
|
|
430
430
|
if (decoder)
|
|
431
431
|
return decoder;
|
|
432
432
|
const dataType = this.getDataType();
|
|
433
|
-
|
|
434
|
-
decoder = this._decoder = dataType.generateCodec('decode', options);
|
|
433
|
+
decoder = this._decoder = dataType.generateCodec('decode', { partial: true });
|
|
435
434
|
return decoder;
|
|
436
435
|
}
|
|
437
436
|
}
|
|
@@ -18,7 +18,7 @@ function _preparePatch(src, trg = {}, path, options) {
|
|
|
18
18
|
trg.$unset[field] = '';
|
|
19
19
|
continue;
|
|
20
20
|
}
|
|
21
|
-
if (v && typeof v === 'object') {
|
|
21
|
+
if (v && typeof v === 'object' && !Array.isArray(v)) {
|
|
22
22
|
// If field name starts with "*", do "replace" operation except "merge"
|
|
23
23
|
if (!k.startsWith('*')) {
|
|
24
24
|
_preparePatch(v, trg, key);
|
|
@@ -60,7 +60,7 @@ export class MongoArrayService extends MongoService {
|
|
|
60
60
|
options
|
|
61
61
|
}, this);
|
|
62
62
|
const encode = this.getEncoder('create');
|
|
63
|
-
const doc = encode(input);
|
|
63
|
+
const doc = encode(input, { coerce: true });
|
|
64
64
|
doc._id = doc._id || this._generateId();
|
|
65
65
|
const docFilter = MongoAdapter.prepareKeyValues(documentId, [this.collectionKey]);
|
|
66
66
|
const r = await this.__updateOne(docFilter, {
|
|
@@ -303,7 +303,7 @@ export class MongoArrayService extends MongoService {
|
|
|
303
303
|
const projection = MongoAdapter.prepareProjection(dataType, options);
|
|
304
304
|
if (projection)
|
|
305
305
|
dataStages.push({ $project: projection });
|
|
306
|
-
const
|
|
306
|
+
const decode = this.getDecoder();
|
|
307
307
|
const cursor = await this.__aggregate(stages, {
|
|
308
308
|
...mongoOptions
|
|
309
309
|
});
|
|
@@ -311,7 +311,7 @@ export class MongoArrayService extends MongoService {
|
|
|
311
311
|
if (options?.count) {
|
|
312
312
|
const facetResult = await cursor.toArray();
|
|
313
313
|
this.context.response.totalMatches = facetResult[0].count[0].totalMatches || 0;
|
|
314
|
-
return facetResult[0].data.map((r) =>
|
|
314
|
+
return facetResult[0].data.map((r) => decode(r, { coerce: true }));
|
|
315
315
|
}
|
|
316
316
|
else
|
|
317
317
|
return await cursor.toArray();
|
|
@@ -408,7 +408,7 @@ export class MongoArrayService extends MongoService {
|
|
|
408
408
|
options
|
|
409
409
|
}, this);
|
|
410
410
|
const encode = this.getEncoder('update');
|
|
411
|
-
const doc = encode(input);
|
|
411
|
+
const doc = encode(input, { coerce: true });
|
|
412
412
|
if (!Object.keys(doc).length)
|
|
413
413
|
return 0;
|
|
414
414
|
const matchFilter = MongoAdapter.prepareFilter([
|
|
@@ -53,7 +53,7 @@ export class MongoCollectionService extends MongoService {
|
|
|
53
53
|
options
|
|
54
54
|
}, this);
|
|
55
55
|
const encode = this.getEncoder('create');
|
|
56
|
-
const doc = encode(input);
|
|
56
|
+
const doc = encode(input, { coerce: true });
|
|
57
57
|
doc._id = doc._id || this._generateId();
|
|
58
58
|
const r = await this.__insertOne(doc, options);
|
|
59
59
|
if (r.insertedId) {
|
|
@@ -184,9 +184,9 @@ export class MongoCollectionService extends MongoService {
|
|
|
184
184
|
projection: MongoAdapter.prepareProjection(this.getDataType(), options),
|
|
185
185
|
limit: undefined
|
|
186
186
|
};
|
|
187
|
-
const
|
|
187
|
+
const decode = this.getDecoder();
|
|
188
188
|
const out = await this.__findOne(filter, mongoOptions);
|
|
189
|
-
return out ?
|
|
189
|
+
return out ? decode(out, { coerce: true }) : undefined;
|
|
190
190
|
}
|
|
191
191
|
/**
|
|
192
192
|
* Finds multiple documents in the MongoDB collection.
|
|
@@ -242,7 +242,7 @@ export class MongoCollectionService extends MongoService {
|
|
|
242
242
|
const projection = MongoAdapter.prepareProjection(dataType, options);
|
|
243
243
|
if (projection)
|
|
244
244
|
dataStages.push({ $project: projection });
|
|
245
|
-
const
|
|
245
|
+
const decode = this.getDecoder();
|
|
246
246
|
const cursor = await this.__aggregate(stages, {
|
|
247
247
|
...mongoOptions
|
|
248
248
|
});
|
|
@@ -250,7 +250,7 @@ export class MongoCollectionService extends MongoService {
|
|
|
250
250
|
if (options?.count) {
|
|
251
251
|
const facetResult = await cursor.toArray();
|
|
252
252
|
this.context.response.totalMatches = facetResult[0].count[0].totalMatches || 0;
|
|
253
|
-
return facetResult[0].data.map((r) =>
|
|
253
|
+
return facetResult[0].data.map((r) => decode(r, { coerce: true }));
|
|
254
254
|
}
|
|
255
255
|
else
|
|
256
256
|
return await cursor.toArray();
|
|
@@ -294,7 +294,7 @@ export class MongoCollectionService extends MongoService {
|
|
|
294
294
|
options,
|
|
295
295
|
}, this);
|
|
296
296
|
const encode = this.getEncoder('update');
|
|
297
|
-
const doc = encode(input);
|
|
297
|
+
const doc = encode(input, { coerce: true });
|
|
298
298
|
const patch = MongoAdapter.preparePatch(doc);
|
|
299
299
|
const mongoOptions = {
|
|
300
300
|
...options,
|
|
@@ -307,9 +307,9 @@ export class MongoCollectionService extends MongoService {
|
|
|
307
307
|
options?.filter,
|
|
308
308
|
await this._getDocumentFilter()
|
|
309
309
|
]);
|
|
310
|
-
const
|
|
310
|
+
const decode = this.getDecoder();
|
|
311
311
|
const out = await this.__findOneAndUpdate(filter, patch, mongoOptions);
|
|
312
|
-
return out ?
|
|
312
|
+
return out ? decode(out, { coerce: true }) : undefined;
|
|
313
313
|
}
|
|
314
314
|
/**
|
|
315
315
|
* Updates a document in the collection with the specified ID.
|
|
@@ -334,7 +334,7 @@ export class MongoCollectionService extends MongoService {
|
|
|
334
334
|
await this._getDocumentFilter()
|
|
335
335
|
]);
|
|
336
336
|
const encode = this.getEncoder('update');
|
|
337
|
-
const doc = encode(input);
|
|
337
|
+
const doc = encode(input, { coerce: true });
|
|
338
338
|
if (!Object.keys(doc).length)
|
|
339
339
|
return 0;
|
|
340
340
|
const patch = MongoAdapter.preparePatch(doc);
|
|
@@ -363,7 +363,7 @@ export class MongoCollectionService extends MongoService {
|
|
|
363
363
|
options,
|
|
364
364
|
}, this);
|
|
365
365
|
const encode = this.getEncoder('update');
|
|
366
|
-
const doc = encode(input);
|
|
366
|
+
const doc = encode(input, { coerce: true });
|
|
367
367
|
if (!Object.keys(doc).length)
|
|
368
368
|
return 0;
|
|
369
369
|
const patch = MongoAdapter.preparePatch(doc);
|
package/esm/mongo-service.js
CHANGED
|
@@ -427,8 +427,7 @@ export class MongoService extends ApiService {
|
|
|
427
427
|
if (decoder)
|
|
428
428
|
return decoder;
|
|
429
429
|
const dataType = this.getDataType();
|
|
430
|
-
|
|
431
|
-
decoder = this._decoder = dataType.generateCodec('decode', options);
|
|
430
|
+
decoder = this._decoder = dataType.generateCodec('decode', { partial: true });
|
|
432
431
|
return decoder;
|
|
433
432
|
}
|
|
434
433
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/mongodb",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.6",
|
|
4
4
|
"description": "Opra MongoDB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@faker-js/faker": "^8.3.1",
|
|
29
29
|
"mongodb": "^6.3.0",
|
|
30
|
-
"ts-gems": "^2.
|
|
30
|
+
"ts-gems": "^2.9.3"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@opra/common": "^0.32.
|
|
34
|
-
"@opra/core": "^0.32.
|
|
33
|
+
"@opra/common": "^0.32.6",
|
|
34
|
+
"@opra/core": "^0.32.6",
|
|
35
35
|
"mongodb": ">=6.x.x"
|
|
36
36
|
},
|
|
37
37
|
"type": "module",
|