@travetto/registry 7.0.0-rc.0 → 7.0.0-rc.1

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
@@ -98,7 +98,7 @@ export class SampleRegistryIndex implements RegistryIndex {
98
98
  }
99
99
  ```
100
100
 
101
- The registry index is a [RegistryIndex](https://github.com/travetto/travetto/tree/main/module/registry/src/service/types.ts#L34) that similar to the [Schema](https://github.com/travetto/travetto/tree/main/module/schema#readme "Data type registry for runtime validation, reflection and binding.")'s Schema registry and [Dependency Injection](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support.")'s Dependency registry.
101
+ The registry index is a [RegistryIndex](https://github.com/travetto/travetto/tree/main/module/registry/src/service/types.ts#L36) that similar to the [Schema](https://github.com/travetto/travetto/tree/main/module/schema#readme "Data type registry for runtime validation, reflection and binding.")'s Schema registry and [Dependency Injection](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support.")'s Dependency registry.
102
102
 
103
103
  ### Live Flow
104
104
  At runtime, the registry is designed to listen for changes and to propagate the changes as necessary. In many cases the same file is handled by multiple registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/registry",
3
- "version": "7.0.0-rc.0",
3
+ "version": "7.0.0-rc.1",
4
4
  "description": "Patterns and utilities for handling registration of metadata and functionality for run-time use",
5
5
  "keywords": [
6
6
  "ast-transformations",
@@ -27,11 +27,11 @@
27
27
  "directory": "module/registry"
28
28
  },
29
29
  "dependencies": {
30
- "@travetto/runtime": "^7.0.0-rc.0"
30
+ "@travetto/runtime": "^7.0.0-rc.1"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/cli": "^7.0.0-rc.0",
34
- "@travetto/transformer": "^7.0.0-rc.0"
33
+ "@travetto/cli": "^7.0.0-rc.1",
34
+ "@travetto/transformer": "^7.0.0-rc.1"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@travetto/transformer": {
@@ -4,7 +4,7 @@ import { AppError, castTo, Class, Util } from '@travetto/runtime';
4
4
  import { ClassSource } from '../source/class-source';
5
5
  import { ChangeEvent } from '../types';
6
6
  import { MethodSource } from '../source/method-source';
7
- import { RegistryIndex, RegistryIndexClass } from './types';
7
+ import { RegistryIndex, RegistryIndexClass, EXPIRED_CLASS } from './types';
8
8
 
9
9
  class $Registry {
10
10
 
@@ -27,6 +27,8 @@ class $Registry {
27
27
  for (const idx of this.#indexOrder) {
28
28
  this.instance(idx).store.remove(cls);
29
29
  }
30
+ // Tag expired classes
31
+ Object.assign(cls, { [EXPIRED_CLASS]: true });
30
32
  }
31
33
  }
32
34
 
@@ -1,6 +1,22 @@
1
- import { AppError, castTo, Class, getParentClass } from '@travetto/runtime';
1
+ import { Any, AppError, castTo, Class, getParentClass, Runtime } from '@travetto/runtime';
2
2
 
3
- import { RegistrationMethods, RegistryAdapter } from './types';
3
+ import { EXPIRED_CLASS, RegistrationMethods, RegistryAdapter } from './types';
4
+
5
+ function ExchangeExpired<R = unknown>() {
6
+ return function (
7
+ target: Any,
8
+ propertyKey: string | symbol,
9
+ descriptor: TypedPropertyDescriptor<(this: RegistryIndexStore, cls: Class) => R>
10
+ ): void {
11
+ if (Runtime.dynamic) {
12
+ const original = descriptor.value!;
13
+ descriptor.value = function (this: RegistryIndexStore, cls: Class): R {
14
+ const resolved = EXPIRED_CLASS in cls ? this.getClassById(cls.Ⲑid) : cls;
15
+ return original.apply(this, [resolved]);
16
+ };
17
+ }
18
+ };
19
+ }
4
20
 
5
21
  /**
6
22
  * Base registry index implementation
@@ -15,16 +31,13 @@ export class RegistryIndexStore<A extends RegistryAdapter<{}> = RegistryAdapter<
15
31
 
16
32
  constructor(adapterCls: new (cls: Class) => A) {
17
33
  this.#adapterCls = adapterCls;
34
+ this.getClassById = this.getClassById.bind(this);
18
35
  }
19
36
 
20
37
  getClasses(): Class[] {
21
38
  return Array.from(this.#adapters.keys());
22
39
  }
23
40
 
24
- has(cls: Class): boolean {
25
- return this.#adapters.has(cls);
26
- }
27
-
28
41
  getClassById(id: string): Class {
29
42
  return this.#idToCls.get(id)!;
30
43
  }
@@ -38,6 +51,17 @@ export class RegistryIndexStore<A extends RegistryAdapter<{}> = RegistryAdapter<
38
51
  this.#finalized.set(cls, true);
39
52
  }
40
53
 
54
+ remove(cls: Class): void {
55
+ this.#adapters.delete(cls);
56
+ this.#finalized.delete(cls);
57
+ }
58
+
59
+ @ExchangeExpired()
60
+ has(cls: Class): boolean {
61
+ return this.#adapters.has(cls);
62
+ }
63
+
64
+ @ExchangeExpired()
41
65
  adapter(cls: Class): A {
42
66
  if (!this.#adapters.has(cls)!) {
43
67
  const adapter = new this.#adapterCls(cls);
@@ -48,11 +72,7 @@ export class RegistryIndexStore<A extends RegistryAdapter<{}> = RegistryAdapter<
48
72
  return castTo(this.#adapters.get(cls));
49
73
  }
50
74
 
51
- remove(cls: Class): void {
52
- this.#adapters.delete(cls);
53
- this.#finalized.delete(cls);
54
- }
55
-
75
+ @ExchangeExpired()
56
76
  getForRegister(cls: Class, allowFinalized = false): A {
57
77
  if (this.#finalized.get(cls) && !allowFinalized) {
58
78
  throw new AppError(`Class ${cls.Ⲑid} is already finalized`);
@@ -60,6 +80,7 @@ export class RegistryIndexStore<A extends RegistryAdapter<{}> = RegistryAdapter<
60
80
  return this.adapter(cls);
61
81
  }
62
82
 
83
+ @ExchangeExpired()
63
84
  get(cls: Class): Omit<A, RegistrationMethods> {
64
85
  if (!this.has(cls)) {
65
86
  throw new AppError(`Class ${cls.Ⲑid} is not registered for ${this.#adapterCls.Ⲑid}`);
@@ -67,6 +88,7 @@ export class RegistryIndexStore<A extends RegistryAdapter<{}> = RegistryAdapter<
67
88
  return this.adapter(cls);
68
89
  }
69
90
 
91
+ @ExchangeExpired()
70
92
  getOptional(cls: Class): Omit<A, RegistrationMethods> | undefined {
71
93
  if (!this.has(cls)) {
72
94
  return undefined;
@@ -74,6 +96,7 @@ export class RegistryIndexStore<A extends RegistryAdapter<{}> = RegistryAdapter<
74
96
  return this.adapter(cls);
75
97
  }
76
98
 
99
+ @ExchangeExpired()
77
100
  finalized(cls: Class): boolean {
78
101
  return this.#finalized.has(cls);
79
102
  }
@@ -3,6 +3,8 @@ import { ChangeEvent } from '../types';
3
3
 
4
4
  export type RegistrationMethods = `register${string}` | `finalize${string}`;
5
5
 
6
+ export const EXPIRED_CLASS = Symbol();
7
+
6
8
  /**
7
9
  * Interface for registry adapters to implement
8
10
  */