@travetto/model-memory 7.0.0-rc.1 → 7.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/package.json +7 -7
- package/src/service.ts +18 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-memory",
|
|
3
|
-
"version": "7.0.0-rc.
|
|
3
|
+
"version": "7.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": "^7.0.0-rc.
|
|
29
|
-
"@travetto/di": "^7.0.0-rc.
|
|
30
|
-
"@travetto/model": "^7.0.0-rc.
|
|
31
|
-
"@travetto/schema": "^7.0.0-rc.
|
|
28
|
+
"@travetto/config": "^7.0.0-rc.2",
|
|
29
|
+
"@travetto/di": "^7.0.0-rc.2",
|
|
30
|
+
"@travetto/model": "^7.0.0-rc.2",
|
|
31
|
+
"@travetto/schema": "^7.0.0-rc.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@travetto/cli": "^7.0.0-rc.
|
|
35
|
-
"@travetto/test": "^7.0.0-rc.
|
|
34
|
+
"@travetto/cli": "^7.0.0-rc.2",
|
|
35
|
+
"@travetto/test": "^7.0.0-rc.2"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"@travetto/cli": {
|
package/src/service.ts
CHANGED
|
@@ -23,7 +23,7 @@ export class MemoryModelConfig {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
function indexName<T extends ModelType>(cls: Class<T>, idx: IndexConfig<T> | string, suffix?: string): string {
|
|
26
|
-
return [cls.Ⲑid, typeof idx === 'string' ? idx : idx.name, suffix].filter(
|
|
26
|
+
return [cls.Ⲑid, typeof idx === 'string' ? idx : idx.name, suffix].filter(part => !!part).join(':');
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function getFirstId(data: Map<string, unknown> | Set<string>, value?: string | number): string | undefined {
|
|
@@ -31,7 +31,7 @@ function getFirstId(data: Map<string, unknown> | Set<string>, value?: string | n
|
|
|
31
31
|
if (data instanceof Set) {
|
|
32
32
|
id = data.values().next().value;
|
|
33
33
|
} else {
|
|
34
|
-
id = [...data.entries()].find(([,
|
|
34
|
+
id = [...data.entries()].find(([, item]) => value === undefined || item === value)?.[0];
|
|
35
35
|
}
|
|
36
36
|
return id;
|
|
37
37
|
}
|
|
@@ -81,9 +81,9 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
|
|
|
81
81
|
const { key } = ModelIndexedUtil.computeIndexKey(cls, idx, castTo(item));
|
|
82
82
|
this.#indices[idx.type].get(idxName)?.get(key)?.delete(id);
|
|
83
83
|
}
|
|
84
|
-
} catch (
|
|
85
|
-
if (!(
|
|
86
|
-
throw
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (!(error instanceof NotFoundError)) {
|
|
86
|
+
throw error;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -149,11 +149,11 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
|
|
|
149
149
|
await ModelStorageUtil.registerModelChangeListener(this);
|
|
150
150
|
ModelExpiryUtil.registerCull(this);
|
|
151
151
|
|
|
152
|
-
for (const
|
|
153
|
-
for (const idx of ModelRegistryIndex.getConfig(
|
|
152
|
+
for (const cls of ModelRegistryIndex.getClasses()) {
|
|
153
|
+
for (const idx of ModelRegistryIndex.getConfig(cls).indices ?? []) {
|
|
154
154
|
switch (idx.type) {
|
|
155
155
|
case 'unique': {
|
|
156
|
-
console.error('Unique indices are not supported for', { cls:
|
|
156
|
+
console.error('Unique indices are not supported for', { cls: cls.Ⲑid, idx: idx.name });
|
|
157
157
|
break;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
@@ -165,14 +165,14 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
|
|
|
165
165
|
async get<T extends ModelType>(cls: Class<T>, id: string): Promise<T> {
|
|
166
166
|
const store = this.#getStore(cls);
|
|
167
167
|
if (store.has(id)) {
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
168
|
+
const result = await ModelCrudUtil.load(cls, store.get(id)!);
|
|
169
|
+
if (result) {
|
|
170
170
|
if (ModelRegistryIndex.getConfig(cls).expiresAt) {
|
|
171
|
-
if (!ModelExpiryUtil.getExpiryState(cls,
|
|
172
|
-
return
|
|
171
|
+
if (!ModelExpiryUtil.getExpiryState(cls, result).expired) {
|
|
172
|
+
return result;
|
|
173
173
|
}
|
|
174
174
|
} else {
|
|
175
|
-
return
|
|
175
|
+
return result;
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
}
|
|
@@ -221,9 +221,9 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
|
|
|
221
221
|
for (const id of this.#getStore(cls).keys()) {
|
|
222
222
|
try {
|
|
223
223
|
yield await this.get(cls, id);
|
|
224
|
-
} catch (
|
|
225
|
-
if (!(
|
|
226
|
-
throw
|
|
224
|
+
} catch (error) {
|
|
225
|
+
if (!(error instanceof NotFoundError)) {
|
|
226
|
+
throw error;
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
}
|
|
@@ -281,8 +281,8 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
|
|
|
281
281
|
let deleted = 0;
|
|
282
282
|
for (const key of [...store.keys()]) {
|
|
283
283
|
try {
|
|
284
|
-
const
|
|
285
|
-
if (ModelExpiryUtil.getExpiryState(cls,
|
|
284
|
+
const result = await ModelCrudUtil.load(cls, store.get(key)!);
|
|
285
|
+
if (ModelExpiryUtil.getExpiryState(cls, result).expired) {
|
|
286
286
|
store.delete(key);
|
|
287
287
|
deleted += 1;
|
|
288
288
|
}
|