@travetto/model-memory 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 +28 -5
package/README.md
CHANGED
|
@@ -17,4 +17,4 @@ This module provides a memory-based implementation for the [Data Modeling Suppor
|
|
|
17
17
|
* [CRUD](https://github.com/travetto/travetto/tree/main/module/model/src/types/crud.ts#L11)
|
|
18
18
|
* [Expiry](https://github.com/travetto/travetto/tree/main/module/model/src/types/expiry.ts#L10)
|
|
19
19
|
* [Blob](https://github.com/travetto/travetto/tree/main/module/model/src/types/blob.ts#L8)
|
|
20
|
-
* [Indexed](https://github.com/travetto/travetto/tree/main/module/model-indexed/src/types/service.ts#
|
|
20
|
+
* [Indexed](https://github.com/travetto/travetto/tree/main/module/model-indexed/src/types/service.ts#L15)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-memory",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Memory backing for the travetto model module.",
|
|
6
6
|
"keywords": [
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@travetto/config": "^8.0.0-alpha.10",
|
|
30
30
|
"@travetto/di": "^8.0.0-alpha.10",
|
|
31
31
|
"@travetto/model": "^8.0.0-alpha.10",
|
|
32
|
-
"@travetto/model-indexed": "^8.0.0-alpha.
|
|
32
|
+
"@travetto/model-indexed": "^8.0.0-alpha.11",
|
|
33
33
|
"@travetto/schema": "^8.0.0-alpha.10"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
package/src/service.ts
CHANGED
|
@@ -150,10 +150,18 @@ export class MemoryModelService implements
|
|
|
150
150
|
const index = this.#indices[idx.type].get(indexName(cls, idx))?.get(computed.getKey());
|
|
151
151
|
let id: string | undefined;
|
|
152
152
|
if (index) {
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
if (computed.idPart) {
|
|
154
|
+
if (index.has(computed.idPart.value)) {
|
|
155
|
+
id = computed.idPart.value;
|
|
156
|
+
} else {
|
|
157
|
+
throw new NotFoundError(cls, computed.getKey({ sort: true }));
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
if (index instanceof Map) {
|
|
161
|
+
id = getFirstId(index, computed.getSort()); // Grab first id
|
|
162
|
+
} else if (index instanceof Set) {
|
|
163
|
+
id = getFirstId(index); // Grab first id
|
|
164
|
+
}
|
|
157
165
|
}
|
|
158
166
|
}
|
|
159
167
|
if (id) {
|
|
@@ -400,7 +408,7 @@ export class MemoryModelService implements
|
|
|
400
408
|
return this.update(cls, item);
|
|
401
409
|
}
|
|
402
410
|
|
|
403
|
-
async
|
|
411
|
+
async pageByIndex<
|
|
404
412
|
T extends ModelType,
|
|
405
413
|
K extends KeyedIndexSelection<T>,
|
|
406
414
|
S extends SortedIndexSelection<T>
|
|
@@ -420,4 +428,19 @@ export class MemoryModelService implements
|
|
|
420
428
|
}
|
|
421
429
|
return { items, nextOffset: items.length ? JSONUtil.toBase64(offset + items.length) : undefined };
|
|
422
430
|
}
|
|
431
|
+
|
|
432
|
+
async * listByIndex<
|
|
433
|
+
T extends ModelType,
|
|
434
|
+
K extends KeyedIndexSelection<T>,
|
|
435
|
+
S extends SortedIndexSelection<T>
|
|
436
|
+
>(
|
|
437
|
+
cls: Class<T>,
|
|
438
|
+
idx: SortedIndex<T, K, S>,
|
|
439
|
+
body: KeyedIndexBody<T, K>,
|
|
440
|
+
): AsyncIterable<T> {
|
|
441
|
+
const ids = this.#getIndexIds(cls, idx, body);
|
|
442
|
+
for (const id of ids) {
|
|
443
|
+
yield await this.get(cls, id);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
423
446
|
}
|