@travetto/model-redis 6.0.0 → 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 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#L7) is defined by:
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": "6.0.0",
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
- "@travetto/cli": "^6.0.0",
29
- "@travetto/config": "^6.0.0",
30
- "@travetto/model": "^6.0.0",
31
- "redis": "^4.7.0"
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
@@ -1,8 +1,8 @@
1
- import { createClient } from 'redis';
1
+ import { createClient } from '@redis/client';
2
2
 
3
3
  import { ShutdownManager, type Class, type DeepPartial } from '@travetto/runtime';
4
4
  import {
5
- ModelCrudSupport, ModelExpirySupport, ModelRegistry, ModelType, ModelStorageSupport,
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 : ModelRegistry.getStore(cls);
30
+ let key = typeof cls === 'string' ? cls : ModelRegistryIndex.getStoreName(cls);
31
31
  if (id) {
32
32
  key = `${key}:${id}`;
33
33
  }
@@ -41,7 +41,7 @@ export class RedisModelService implements ModelCrudSupport, ModelExpirySupport,
41
41
  }
42
42
 
43
43
  async * #streamValues(op: 'scan' | 'sScan' | 'zScan', search: RedisScan, count = 100): AsyncIterable<string[]> {
44
- let prevCursor = 0;
44
+ let prevCursor = '0';
45
45
  let done = false;
46
46
 
47
47
  const flags = { COUNT: count, ...('match' in search ? { MATCH: search.match } : {}) };
@@ -60,7 +60,7 @@ export class RedisModelService implements ModelCrudSupport, ModelExpirySupport,
60
60
 
61
61
  yield results;
62
62
 
63
- if (cursor === 0) {
63
+ if (cursor === '0') {
64
64
  done = true;
65
65
  }
66
66
  }
@@ -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 ModelRegistry.getIndices(cls, ['sorted', 'unsorted'])) {
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 ModelRegistry.getIndices(cls, ['sorted', 'unsorted'])) {
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 = ModelRegistry.get(cls);
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 = ModelRegistry.getIndex(cls, idx, ['sorted', 'unsorted']);
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;
@@ -171,9 +171,9 @@ export class RedisModelService implements ModelCrudSupport, ModelExpirySupport,
171
171
  this.client = createClient(this.config.client);
172
172
  await this.client.connect();
173
173
  await ModelStorageUtil.registerModelChangeListener(this);
174
- ShutdownManager.onGracefulShutdown(() => this.client.disconnect(), this);
175
- for (const el of ModelRegistry.getClasses()) {
176
- for (const idx of ModelRegistry.get(el).indices ?? []) {
174
+ ShutdownManager.onGracefulShutdown(() => this.client.destroy());
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 = ModelRegistry.getIndex(cls, idx, ['sorted', 'unsorted']);
312
+ const idxCfg = ModelRegistryIndex.getIndex(cls, idx, ['sorted', 'unsorted']);
313
313
 
314
314
  let stream: AsyncIterable<string[]>;
315
315
 
@@ -1,6 +1,6 @@
1
1
  import type { ServiceDescriptor } from '@travetto/cli';
2
2
 
3
- const version = process.env.REDIS_VERSION || '7.4';
3
+ const version = process.env.REDIS_VERSION || '8.4';
4
4
 
5
5
  export const service: ServiceDescriptor = {
6
6
  name: 'redis',