@travetto/model-memory 6.0.0-rc.0 → 6.0.0-rc.2
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 +4 -4
- package/__index__.ts +1 -1
- package/package.json +7 -7
- package/src/service.ts +11 -15
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ yarn add @travetto/model-memory
|
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
This module provides a memory-based implementation for the [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations."). Supported features:
|
|
17
|
-
* [CRUD](https://github.com/travetto/travetto/tree/main/module/model/src/
|
|
18
|
-
* [Expiry](https://github.com/travetto/travetto/tree/main/module/model/src/
|
|
19
|
-
* [Indexed](https://github.com/travetto/travetto/tree/main/module/model/src/
|
|
20
|
-
* [Blob](https://github.com/travetto/travetto/tree/main/module/model/src/
|
|
17
|
+
* [CRUD](https://github.com/travetto/travetto/tree/main/module/model/src/types/crud.ts#L11)
|
|
18
|
+
* [Expiry](https://github.com/travetto/travetto/tree/main/module/model/src/types/expiry.ts#L10)
|
|
19
|
+
* [Indexed](https://github.com/travetto/travetto/tree/main/module/model/src/types/indexed.ts#L11)
|
|
20
|
+
* [Blob](https://github.com/travetto/travetto/tree/main/module/model/src/types/blob.ts#L8)
|
package/__index__.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './src/service';
|
|
1
|
+
export * from './src/service.ts';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-memory",
|
|
3
|
-
"version": "6.0.0-rc.
|
|
3
|
+
"version": "6.0.0-rc.2",
|
|
4
4
|
"description": "Memory backing for the travetto model module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datastore",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"directory": "module/model-memory"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@travetto/config": "^6.0.0-rc.
|
|
29
|
-
"@travetto/di": "^6.0.0-rc.
|
|
30
|
-
"@travetto/model": "^6.0.0-rc.
|
|
31
|
-
"@travetto/schema": "^6.0.0-rc.
|
|
28
|
+
"@travetto/config": "^6.0.0-rc.2",
|
|
29
|
+
"@travetto/di": "^6.0.0-rc.2",
|
|
30
|
+
"@travetto/model": "^6.0.0-rc.2",
|
|
31
|
+
"@travetto/schema": "^6.0.0-rc.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@travetto/cli": "^6.0.0-rc.
|
|
35
|
-
"@travetto/test": "^6.0.0-rc.
|
|
34
|
+
"@travetto/cli": "^6.0.0-rc.2",
|
|
35
|
+
"@travetto/test": "^6.0.0-rc.2"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"@travetto/cli": {
|
package/src/service.ts
CHANGED
|
@@ -6,15 +6,11 @@ import { Injectable } from '@travetto/di';
|
|
|
6
6
|
import { Config } from '@travetto/config';
|
|
7
7
|
import {
|
|
8
8
|
ModelType, IndexConfig, ModelCrudSupport, ModelExpirySupport, ModelStorageSupport, ModelIndexedSupport,
|
|
9
|
-
ModelRegistry, NotFoundError, ExistsError, OptionalId, ModelBlobSupport
|
|
9
|
+
ModelRegistry, NotFoundError, ExistsError, OptionalId, ModelBlobSupport,
|
|
10
|
+
ModelCrudUtil, ModelExpiryUtil, ModelIndexedUtil, ModelStorageUtil, ModelBlobUtil,
|
|
10
11
|
} from '@travetto/model';
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
import { ModelExpiryUtil } from '@travetto/model/src/internal/service/expiry';
|
|
14
|
-
import { ModelIndexedUtil } from '@travetto/model/src/internal/service/indexed';
|
|
15
|
-
import { ModelStorageUtil } from '@travetto/model/src/internal/service/storage';
|
|
16
|
-
import { MODEL_BLOB, ModelBlobNamespace, ModelBlobUtil } from '@travetto/model/src/internal/service/blob';
|
|
17
|
-
|
|
13
|
+
const ModelBlobNamespace = '__blobs';
|
|
18
14
|
const ModelBlobMetaNamespace = `${ModelBlobNamespace}_meta`;
|
|
19
15
|
|
|
20
16
|
type StoreType = Map<string, Buffer>;
|
|
@@ -35,7 +31,7 @@ function getFirstId(data: Map<string, unknown> | Set<string>, value?: string | n
|
|
|
35
31
|
if (data instanceof Set) {
|
|
36
32
|
id = data.values().next().value;
|
|
37
33
|
} else {
|
|
38
|
-
id = [...data.entries()].find(([
|
|
34
|
+
id = [...data.entries()].find(([, v]) => value === undefined || v === value)?.[0];
|
|
39
35
|
}
|
|
40
36
|
return id;
|
|
41
37
|
}
|
|
@@ -314,12 +310,12 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
|
|
|
314
310
|
}
|
|
315
311
|
|
|
316
312
|
async truncateModel<T extends ModelType>(cls: Class<T>): Promise<void> {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
313
|
+
this.#getStore(cls).clear();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
async truncateBlob(): Promise<void> {
|
|
317
|
+
this.#getStore(ModelBlobNamespace).clear();
|
|
318
|
+
this.#getStore(ModelBlobMetaNamespace).clear();
|
|
323
319
|
}
|
|
324
320
|
|
|
325
321
|
// Indexed
|
|
@@ -346,7 +342,7 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
|
|
|
346
342
|
yield this.get(cls, id);
|
|
347
343
|
}
|
|
348
344
|
} else {
|
|
349
|
-
for (const id of [...index.entries()].
|
|
345
|
+
for (const id of [...index.entries()].toSorted((a, b) => +a[1] - +b[1]).map(([a,]) => a)) {
|
|
350
346
|
yield this.get(cls, id);
|
|
351
347
|
}
|
|
352
348
|
}
|