@travetto/model-redis 6.0.1 → 7.0.0-rc.0
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 -3
- package/package.json +5 -5
- package/src/config.ts +0 -3
- package/src/service.ts +9 -9
- package/support/service.redis.ts +1 -1
package/README.md
CHANGED
|
@@ -37,14 +37,12 @@ export class Init {
|
|
|
37
37
|
}
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
where the [RedisModelConfig](https://github.com/travetto/travetto/tree/main/module/model-redis/src/config.ts#
|
|
40
|
+
where the [RedisModelConfig](https://github.com/travetto/travetto/tree/main/module/model-redis/src/config.ts#L6) is defined by:
|
|
41
41
|
|
|
42
42
|
**Code: Structure of RedisModelConfig**
|
|
43
43
|
```typescript
|
|
44
44
|
@Config('model.redis')
|
|
45
45
|
export class RedisModelConfig {
|
|
46
|
-
|
|
47
|
-
@Field(Object)
|
|
48
46
|
client: redis.RedisClientOptions = {};
|
|
49
47
|
namespace?: string;
|
|
50
48
|
autoCreate?: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-redis",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-rc.0",
|
|
4
4
|
"description": "Redis backing for the travetto model module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"directory": "module/model-redis"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@redis/client": "^5.
|
|
29
|
-
"@travetto/cli": "^
|
|
30
|
-
"@travetto/config": "^
|
|
31
|
-
"@travetto/model": "^
|
|
28
|
+
"@redis/client": "^5.10.0",
|
|
29
|
+
"@travetto/cli": "^7.0.0-rc.0",
|
|
30
|
+
"@travetto/config": "^7.0.0-rc.0",
|
|
31
|
+
"@travetto/model": "^7.0.0-rc.0"
|
|
32
32
|
},
|
|
33
33
|
"travetto": {
|
|
34
34
|
"displayName": "Redis Model Support"
|
package/src/config.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type redis from 'redis';
|
|
2
2
|
|
|
3
3
|
import { Config } from '@travetto/config';
|
|
4
|
-
import { Field } from '@travetto/schema';
|
|
5
4
|
|
|
6
5
|
@Config('model.redis')
|
|
7
6
|
export class RedisModelConfig {
|
|
8
|
-
|
|
9
|
-
@Field(Object)
|
|
10
7
|
client: redis.RedisClientOptions = {};
|
|
11
8
|
namespace?: string;
|
|
12
9
|
autoCreate?: boolean;
|
package/src/service.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { createClient } from '@redis/client';
|
|
|
2
2
|
|
|
3
3
|
import { ShutdownManager, type Class, type DeepPartial } from '@travetto/runtime';
|
|
4
4
|
import {
|
|
5
|
-
ModelCrudSupport, ModelExpirySupport,
|
|
5
|
+
ModelCrudSupport, ModelExpirySupport, ModelRegistryIndex, ModelType, ModelStorageSupport,
|
|
6
6
|
NotFoundError, ExistsError, ModelIndexedSupport, OptionalId,
|
|
7
7
|
ModelCrudUtil, ModelExpiryUtil, ModelIndexedUtil, ModelStorageUtil,
|
|
8
8
|
} from '@travetto/model';
|
|
@@ -27,7 +27,7 @@ export class RedisModelService implements ModelCrudSupport, ModelExpirySupport,
|
|
|
27
27
|
constructor(config: RedisModelConfig) { this.config = config; }
|
|
28
28
|
|
|
29
29
|
#resolveKey(cls: Class | string, id?: string, extra?: string): string {
|
|
30
|
-
let key = typeof cls === 'string' ? cls :
|
|
30
|
+
let key = typeof cls === 'string' ? cls : ModelRegistryIndex.getStoreName(cls);
|
|
31
31
|
if (id) {
|
|
32
32
|
key = `${key}:${id}`;
|
|
33
33
|
}
|
|
@@ -71,7 +71,7 @@ export class RedisModelService implements ModelCrudSupport, ModelExpirySupport,
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
#removeIndices<T extends ModelType>(cls: Class, item: T, multi: RedisMulti): void {
|
|
74
|
-
for (const idx of
|
|
74
|
+
for (const idx of ModelRegistryIndex.getIndices(cls, ['sorted', 'unsorted'])) {
|
|
75
75
|
const { key } = ModelIndexedUtil.computeIndexKey(cls, idx, item);
|
|
76
76
|
const fullKey = this.#resolveKey(cls, idx.name, key);
|
|
77
77
|
switch (idx.type) {
|
|
@@ -82,7 +82,7 @@ export class RedisModelService implements ModelCrudSupport, ModelExpirySupport,
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
#addIndices<T extends ModelType>(cls: Class, item: T, multi: RedisMulti): void {
|
|
85
|
-
for (const idx of
|
|
85
|
+
for (const idx of ModelRegistryIndex.getIndices(cls, ['sorted', 'unsorted'])) {
|
|
86
86
|
const { key, sort } = ModelIndexedUtil.computeIndexKey(cls, idx, item);
|
|
87
87
|
const fullKey = this.#resolveKey(cls, idx.name, key);
|
|
88
88
|
|
|
@@ -95,7 +95,7 @@ export class RedisModelService implements ModelCrudSupport, ModelExpirySupport,
|
|
|
95
95
|
|
|
96
96
|
async #store<T extends ModelType>(cls: Class<T>, item: T, action: 'write' | 'delete'): Promise<void> {
|
|
97
97
|
const key = this.#resolveKey(cls, item.id);
|
|
98
|
-
const config =
|
|
98
|
+
const config = ModelRegistryIndex.getConfig(cls);
|
|
99
99
|
const existing = await this.get(cls, item.id).catch(() => undefined);
|
|
100
100
|
|
|
101
101
|
// Store with indices
|
|
@@ -149,7 +149,7 @@ export class RedisModelService implements ModelCrudSupport, ModelExpirySupport,
|
|
|
149
149
|
async #getIdByIndex<T extends ModelType>(cls: Class<T>, idx: string, body: DeepPartial<T>): Promise<string> {
|
|
150
150
|
ModelCrudUtil.ensureNotSubType(cls);
|
|
151
151
|
|
|
152
|
-
const idxCfg =
|
|
152
|
+
const idxCfg = ModelRegistryIndex.getIndex(cls, idx, ['sorted', 'unsorted']);
|
|
153
153
|
const { key, sort } = ModelIndexedUtil.computeIndexKey(cls, idxCfg, body);
|
|
154
154
|
const fullKey = this.#resolveKey(cls, idxCfg.name, key);
|
|
155
155
|
let id: string | undefined;
|
|
@@ -172,8 +172,8 @@ export class RedisModelService implements ModelCrudSupport, ModelExpirySupport,
|
|
|
172
172
|
await this.client.connect();
|
|
173
173
|
await ModelStorageUtil.registerModelChangeListener(this);
|
|
174
174
|
ShutdownManager.onGracefulShutdown(() => this.client.destroy());
|
|
175
|
-
for (const el of
|
|
176
|
-
for (const idx of
|
|
175
|
+
for (const el of ModelRegistryIndex.getClasses()) {
|
|
176
|
+
for (const idx of ModelRegistryIndex.getConfig(el).indices ?? []) {
|
|
177
177
|
switch (idx.type) {
|
|
178
178
|
case 'unique': {
|
|
179
179
|
console.error('Unique indices are not supported in redis for', { cls: el.Ⲑid, idx: idx.name });
|
|
@@ -309,7 +309,7 @@ export class RedisModelService implements ModelCrudSupport, ModelExpirySupport,
|
|
|
309
309
|
async * listByIndex<T extends ModelType>(cls: Class<T>, idx: string, body?: DeepPartial<T>): AsyncIterable<T> {
|
|
310
310
|
ModelCrudUtil.ensureNotSubType(cls);
|
|
311
311
|
|
|
312
|
-
const idxCfg =
|
|
312
|
+
const idxCfg = ModelRegistryIndex.getIndex(cls, idx, ['sorted', 'unsorted']);
|
|
313
313
|
|
|
314
314
|
let stream: AsyncIterable<string[]>;
|
|
315
315
|
|
package/support/service.redis.ts
CHANGED