@travetto/model-memory 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.
Files changed (2) hide show
  1. package/package.json +7 -7
  2. package/src/service.ts +10 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-memory",
3
- "version": "6.0.1",
3
+ "version": "7.0.0-rc.0",
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.1",
29
- "@travetto/di": "^6.0.1",
30
- "@travetto/model": "^6.0.1",
31
- "@travetto/schema": "^6.0.1"
28
+ "@travetto/config": "^7.0.0-rc.0",
29
+ "@travetto/di": "^7.0.0-rc.0",
30
+ "@travetto/model": "^7.0.0-rc.0",
31
+ "@travetto/schema": "^7.0.0-rc.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "@travetto/cli": "^6.0.1",
35
- "@travetto/test": "^6.0.2"
34
+ "@travetto/cli": "^7.0.0-rc.0",
35
+ "@travetto/test": "^7.0.0-rc.0"
36
36
  },
37
37
  "peerDependenciesMeta": {
38
38
  "@travetto/cli": {
package/src/service.ts CHANGED
@@ -6,7 +6,7 @@ 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
+ ModelRegistryIndex, NotFoundError, ExistsError, OptionalId, ModelBlobSupport,
10
10
  ModelCrudUtil, ModelExpiryUtil, ModelIndexedUtil, ModelStorageUtil, ModelBlobUtil,
11
11
  } from '@travetto/model';
12
12
 
@@ -56,7 +56,7 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
56
56
  get client(): Map<string, StoreType> { return this.#store; }
57
57
 
58
58
  #getStore<T extends ModelType>(cls: Class<T> | string): StoreType {
59
- const key = typeof cls === 'string' ? cls : ModelRegistry.getStore(cls);
59
+ const key = typeof cls === 'string' ? cls : ModelRegistryIndex.getStoreName(cls);
60
60
  if (!this.#store.has(key)) {
61
61
  this.#store.set(key, new Map());
62
62
  }
@@ -76,7 +76,7 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
76
76
  async #removeIndices<T extends ModelType>(cls: Class<T>, id: string): Promise<void> {
77
77
  try {
78
78
  const item = await this.get(cls, id);
79
- for (const idx of ModelRegistry.getIndices(cls, ['sorted', 'unsorted'])) {
79
+ for (const idx of ModelRegistryIndex.getIndices(cls, ['sorted', 'unsorted'])) {
80
80
  const idxName = indexName(cls, idx);
81
81
  const { key } = ModelIndexedUtil.computeIndexKey(cls, idx, castTo(item));
82
82
  this.#indices[idx.type].get(idxName)?.get(key)?.delete(id);
@@ -89,7 +89,7 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
89
89
  }
90
90
 
91
91
  async #writeIndices<T extends ModelType>(cls: Class<T>, item: T): Promise<void> {
92
- for (const idx of ModelRegistry.getIndices(cls, ['sorted', 'unsorted'])) {
92
+ for (const idx of ModelRegistryIndex.getIndices(cls, ['sorted', 'unsorted'])) {
93
93
  const idxName = indexName(cls, idx);
94
94
  const { key, sort } = ModelIndexedUtil.computeIndexKey(cls, idx, castTo(item));
95
95
  let index = this.#indices[idx.type].get(idxName)?.get(key);
@@ -128,7 +128,7 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
128
128
  }
129
129
 
130
130
  async #getIdByIndex<T extends ModelType>(cls: Class<T>, idx: string, body: DeepPartial<T>): Promise<string> {
131
- const config = ModelRegistry.getIndex(cls, idx, ['sorted', 'unsorted']);
131
+ const config = ModelRegistryIndex.getIndex(cls, idx, ['sorted', 'unsorted']);
132
132
  const { key, sort } = ModelIndexedUtil.computeIndexKey(cls, config, body);
133
133
  const index = this.#indices[config.type].get(indexName(cls, idx))?.get(key);
134
134
  let id: string | undefined;
@@ -149,8 +149,8 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
149
149
  await ModelStorageUtil.registerModelChangeListener(this);
150
150
  ModelExpiryUtil.registerCull(this);
151
151
 
152
- for (const el of ModelRegistry.getClasses()) {
153
- for (const idx of ModelRegistry.get(el).indices ?? []) {
152
+ for (const el of ModelRegistryIndex.getClasses()) {
153
+ for (const idx of ModelRegistryIndex.getConfig(el).indices ?? []) {
154
154
  switch (idx.type) {
155
155
  case 'unique': {
156
156
  console.error('Unique indices are not supported for', { cls: el.Ⲑid, idx: idx.name });
@@ -167,7 +167,7 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
167
167
  if (store.has(id)) {
168
168
  const res = await ModelCrudUtil.load(cls, store.get(id)!);
169
169
  if (res) {
170
- if (ModelRegistry.get(cls).expiresAt) {
170
+ if (ModelRegistryIndex.getConfig(cls).expiresAt) {
171
171
  if (!ModelExpiryUtil.getExpiryState(cls, res).expired) {
172
172
  return res;
173
173
  }
@@ -302,7 +302,7 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
302
302
  }
303
303
 
304
304
  async createModel<T extends ModelType>(cls: Class<T>): Promise<void> {
305
- for (const idx of ModelRegistry.get(cls).indices ?? []) {
305
+ for (const idx of ModelRegistryIndex.getConfig(cls).indices ?? []) {
306
306
  if (idx.type === 'sorted' || idx.type === 'unsorted') {
307
307
  this.#indices[idx.type].set(indexName(cls, idx), new Map());
308
308
  }
@@ -332,7 +332,7 @@ export class MemoryModelService implements ModelCrudSupport, ModelBlobSupport, M
332
332
  }
333
333
 
334
334
  async * listByIndex<T extends ModelType>(cls: Class<T>, idx: string, body?: DeepPartial<T>): AsyncIterable<T> {
335
- const config = ModelRegistry.getIndex(cls, idx, ['sorted', 'unsorted']);
335
+ const config = ModelRegistryIndex.getIndex(cls, idx, ['sorted', 'unsorted']);
336
336
  const { key } = ModelIndexedUtil.computeIndexKey(cls, idx, body, { emptySortValue: null });
337
337
  const index = this.#indices[config.type].get(indexName(cls, idx))?.get(key);
338
338