@travetto/registry 5.0.0-rc.8 → 5.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/registry",
3
- "version": "5.0.0-rc.8",
3
+ "version": "5.0.0",
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": "^5.0.0-rc.8"
30
+ "@travetto/runtime": "^5.0.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/cli": "^5.0.0-rc.8",
34
- "@travetto/transformer": "^5.0.0-rc.5"
33
+ "@travetto/cli": "^5.0.0",
34
+ "@travetto/transformer": "^5.0.0"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@travetto/transformer": {
@@ -62,8 +62,7 @@ export class DynamicCommonjsLoader {
62
62
  } else {
63
63
  this.#modules.get(file)!.setTarget(mod);
64
64
  }
65
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
66
- return this.#modules.get(file)!.get() as T;
65
+ return this.#modules.get(file)!.get<T>();
67
66
  }
68
67
 
69
68
  async init(): Promise<void> {
package/src/proxy.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ConcreteClass } from '@travetto/runtime';
1
+ import { Any, castKey, castTo, classConstruct } from '@travetto/runtime';
2
2
 
3
3
  const ProxyTargetⲐ = Symbol.for('@travetto/runtime:proxy-target');
4
4
 
@@ -14,8 +14,7 @@ function isFunction(o: unknown): o is Function {
14
14
  /**
15
15
  * Handler for for proxying modules while watching
16
16
  */
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- export class RetargettingHandler<T> implements ProxyHandler<any> {
17
+ export class RetargettingHandler<T> implements ProxyHandler<Any> {
19
18
  constructor(public target: T) { }
20
19
 
21
20
  isExtensible(target: T): boolean {
@@ -35,31 +34,26 @@ export class RetargettingHandler<T> implements ProxyHandler<any> {
35
34
  }
36
35
 
37
36
  apply(target: T, thisArg: T, argArray?: unknown[]): unknown {
38
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
39
- return (this.target as unknown as Function).apply(this.target, argArray);
37
+ return castTo<Function>(this.target).apply(this.target, argArray);
40
38
  }
41
39
 
42
40
  construct(target: T, argArray: unknown[], newTarget?: unknown): object {
43
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
44
- return new (this.target as unknown as ConcreteClass)(...argArray);
41
+ return classConstruct(castTo(this.target), argArray);
45
42
  }
46
43
 
47
44
  setPrototypeOf(target: T, v: unknown): boolean {
48
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
49
- return Object.setPrototypeOf(this.target, v as Record<string, unknown>);
45
+ return Object.setPrototypeOf(this.target, castTo(v));
50
46
  }
51
47
 
52
48
  getPrototypeOf(target: T): object | null {
53
49
  return Object.getPrototypeOf(this.target);
54
50
  }
55
51
 
56
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
- get(target: T, prop: PropertyKey, receiver: unknown): any {
52
+ get(target: T, prop: PropertyKey, receiver: unknown): Any {
58
53
  if (prop === ProxyTargetⲐ) {
59
54
  return this.target;
60
55
  }
61
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
62
- let ret = this.target[prop as keyof T];
56
+ let ret = this.target[castKey<T>(prop)];
63
57
  if (isFunction(ret) && !/^class\s/.test(Function.prototype.toString.call(ret))) {
64
58
  // Bind class members to class instance instead of proxy propagating
65
59
  ret = ret.bind(this.target);
@@ -68,13 +62,11 @@ export class RetargettingHandler<T> implements ProxyHandler<any> {
68
62
  }
69
63
 
70
64
  has(target: T, prop: PropertyKey): boolean {
71
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
72
- return (this.target as Object).hasOwnProperty(prop);
65
+ return castTo<object>(this.target).hasOwnProperty(prop);
73
66
  }
74
67
 
75
68
  set(target: T, prop: PropertyKey, value: unknown): boolean {
76
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
77
- this.target[prop as keyof T] = value as any;
69
+ this.target[castKey<T>(prop)] = castTo(value);
78
70
  return true;
79
71
  }
80
72
 
@@ -86,8 +78,7 @@ export class RetargettingHandler<T> implements ProxyHandler<any> {
86
78
  }
87
79
 
88
80
  deleteProperty(target: T, p: PropertyKey): boolean {
89
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
90
- return delete this.target[p as keyof T];
81
+ return delete this.target[castKey<T>(p)];
91
82
  }
92
83
 
93
84
  defineProperty(target: T, p: PropertyKey, attributes: PropertyDescriptor): boolean {
@@ -107,8 +98,7 @@ export class RetargettingProxy<T> {
107
98
  * Unwrap proxy
108
99
  */
109
100
  static unwrap<U>(el: U): U {
110
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
111
- return (el ? ((el as any)[ProxyTargetⲐ] ?? el) : el) as U;
101
+ return castTo<{ [ProxyTargetⲐ]: U }>(el)?.[ProxyTargetⲐ] ?? el;
112
102
  }
113
103
 
114
104
  #handler: RetargettingHandler<T>;
@@ -116,8 +106,7 @@ export class RetargettingProxy<T> {
116
106
 
117
107
  constructor(initial: T) {
118
108
  this.#handler = new RetargettingHandler(initial);
119
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
120
- this.#instance = new Proxy({}, this.#handler as ProxyHandler<object>);
109
+ this.#instance = new Proxy({}, castTo(this.#handler));
121
110
  }
122
111
 
123
112
  setTarget(next: T): void {
@@ -130,8 +119,7 @@ export class RetargettingProxy<T> {
130
119
  return this.#handler.target;
131
120
  }
132
121
 
133
- get(): T {
134
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
135
- return this.#instance as T;
122
+ get<V extends T>(): V {
123
+ return castTo(this.#instance);
136
124
  }
137
125
  }
@@ -107,8 +107,7 @@ export abstract class MetadataRegistry<C extends { class: Class }, M = unknown,
107
107
  * Find parent class for a given class object
108
108
  */
109
109
  getParentClass(cls: Class): Class | null {
110
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
111
- const parent = Object.getPrototypeOf(cls) as Class;
110
+ const parent: Class = Object.getPrototypeOf(cls);
112
111
  return parent.name && parent !== Object ? parent : null;
113
112
  }
114
113