@travetto/model-mongo 8.0.0-alpha.10 → 8.0.0-alpha.11
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/README.md +1 -1
- package/package.json +2 -2
- package/src/service.ts +30 -3
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Supported features:
|
|
|
20
20
|
* [Expiry](https://github.com/travetto/travetto/tree/main/module/model/src/types/expiry.ts#L10)
|
|
21
21
|
* [Bulk](https://github.com/travetto/travetto/tree/main/module/model/src/types/bulk.ts#L64)
|
|
22
22
|
* [Blob](https://github.com/travetto/travetto/tree/main/module/model/src/types/blob.ts#L8)
|
|
23
|
-
* [Indexed](https://github.com/travetto/travetto/tree/main/module/model-indexed/src/types/service.ts#
|
|
23
|
+
* [Indexed](https://github.com/travetto/travetto/tree/main/module/model-indexed/src/types/service.ts#L15)
|
|
24
24
|
* [Query Crud](https://github.com/travetto/travetto/tree/main/module/model-query/src/types/crud.ts#L11)
|
|
25
25
|
* [Facet](https://github.com/travetto/travetto/tree/main/module/model-query/src/types/facet.ts#L14)
|
|
26
26
|
* [Query](https://github.com/travetto/travetto/tree/main/module/model-query/src/types/query.ts#L10)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-mongo",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Mongo backing for the travetto model module.",
|
|
6
6
|
"keywords": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@travetto/config": "^8.0.0-alpha.10",
|
|
30
30
|
"@travetto/model": "^8.0.0-alpha.10",
|
|
31
|
-
"@travetto/model-indexed": "^8.0.0-alpha.
|
|
31
|
+
"@travetto/model-indexed": "^8.0.0-alpha.11",
|
|
32
32
|
"@travetto/model-query": "^8.0.0-alpha.10",
|
|
33
33
|
"mongodb": "^7.1.1"
|
|
34
34
|
},
|
package/src/service.ts
CHANGED
|
@@ -446,7 +446,7 @@ export class MongoModelService implements
|
|
|
446
446
|
const computed = ModelIndexedComputedIndex.get(idx, body).validate({ sort: true });
|
|
447
447
|
|
|
448
448
|
const result = await store.findOne(
|
|
449
|
-
this.getWhereFilter(cls, castTo(computed.project({ sort: true })))
|
|
449
|
+
this.getWhereFilter(cls, castTo(computed.project({ sort: true, includeId: true })))
|
|
450
450
|
);
|
|
451
451
|
if (!result) {
|
|
452
452
|
throw new NotFoundError(`${cls.name}: ${idx}`, computed.getKey({ sort: true }));
|
|
@@ -464,7 +464,7 @@ export class MongoModelService implements
|
|
|
464
464
|
const computed = ModelIndexedComputedIndex.get(idx, body).validate({ sort: true });
|
|
465
465
|
|
|
466
466
|
const result = await store.deleteOne(
|
|
467
|
-
this.getWhereFilter(cls, castTo(computed.project({ sort: true })))
|
|
467
|
+
this.getWhereFilter(cls, castTo(computed.project({ sort: true, includeId: true })))
|
|
468
468
|
);
|
|
469
469
|
if (!result.deletedCount) {
|
|
470
470
|
throw new NotFoundError(`${cls.name}: ${idx}`, computed.getKey({ sort: true }));
|
|
@@ -496,7 +496,7 @@ export class MongoModelService implements
|
|
|
496
496
|
return this.update(cls, item);
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
-
async
|
|
499
|
+
async pageByIndex<
|
|
500
500
|
T extends ModelType,
|
|
501
501
|
K extends KeyedIndexSelection<T>,
|
|
502
502
|
S extends SortedIndexSelection<T>
|
|
@@ -522,6 +522,33 @@ export class MongoModelService implements
|
|
|
522
522
|
}
|
|
523
523
|
}
|
|
524
524
|
|
|
525
|
+
async * listByIndex<
|
|
526
|
+
T extends ModelType,
|
|
527
|
+
K extends KeyedIndexSelection<T>,
|
|
528
|
+
S extends SortedIndexSelection<T>
|
|
529
|
+
>(
|
|
530
|
+
cls: Class<T>,
|
|
531
|
+
idx: SortedIndex<T, K, S>,
|
|
532
|
+
body: KeyedIndexBody<T, K>,
|
|
533
|
+
): AsyncIterable<T> {
|
|
534
|
+
let offset = 0;
|
|
535
|
+
while (offset >= 0) {
|
|
536
|
+
const cursor = (await this.#buildIndexQuery(cls, idx, body))
|
|
537
|
+
.limit(100)
|
|
538
|
+
.skip(offset);
|
|
539
|
+
|
|
540
|
+
const items = await cursor.toArray();
|
|
541
|
+
if (items.length === 0) {
|
|
542
|
+
offset = -1;
|
|
543
|
+
} else {
|
|
544
|
+
offset += items.length;
|
|
545
|
+
for (const item of items) {
|
|
546
|
+
yield await this.postLoad(cls, item);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
525
552
|
// Query
|
|
526
553
|
async query<T extends ModelType>(cls: Class<T>, query: PageableModelQuery<T>): Promise<T[]> {
|
|
527
554
|
await QueryVerifier.verify(cls, query);
|