@travetto/registry 5.0.0-rc.0 → 5.0.0-rc.2

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
@@ -27,7 +27,7 @@ This flow ensures all files are loaded and processed before application starts.
27
27
 
28
28
  **Code: Sample Registry**
29
29
  ```typescript
30
- import { Class } from '@travetto/base';
30
+ import { Class } from '@travetto/runtime';
31
31
  import { MetadataRegistry } from '@travetto/registry';
32
32
 
33
33
  interface Group {
@@ -112,9 +112,9 @@ As mentioned in [Manifest](https://github.com/travetto/travetto/tree/main/module
112
112
  changes += 1;
113
113
  this.emit({ type: 'added', curr: next.get(k)! });
114
114
  } else {
115
- const prevMeta = RuntimeIndex.getFunctionMetadataFromClass(prev.get(k));
116
- const nextMeta = RuntimeIndex.getFunctionMetadataFromClass(next.get(k));
117
- if (prevMeta?.hash !== nextMeta?.hash) {
115
+ const prevHash = describeFunction(prev.get(k)!)?.hash;
116
+ const nextHash = describeFunction(next.get(k)!)?.hash;
117
+ if (prevHash !== nextHash) {
118
118
  changes += 1;
119
119
  this.emit({ type: 'changed', curr: next.get(k)!, prev: prev.get(k) });
120
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/registry",
3
- "version": "5.0.0-rc.0",
3
+ "version": "5.0.0-rc.2",
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/base": "^5.0.0-rc.0"
30
+ "@travetto/runtime": "^5.0.0-rc.2"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/cli": "^5.0.0-rc.0",
34
- "@travetto/transformer": "^5.0.0-rc.0"
33
+ "@travetto/cli": "^5.0.0-rc.2",
34
+ "@travetto/transformer": "^5.0.0-rc.2"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@travetto/transformer": {
package/src/decorator.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { Class } from '@travetto/base';
2
- import { RuntimeIndex } from '@travetto/manifest';
1
+ import { Class, Runtime } from '@travetto/runtime';
3
2
 
4
3
  /**
5
4
  * Register a class as pending
@@ -12,7 +11,7 @@ class $PendingRegister {
12
11
  * Register class as pending
13
12
  */
14
13
  add(cls: Class): void {
15
- const src = RuntimeIndex.getFunctionMetadata(cls)!.source;
14
+ const src = Runtime.getSource(cls);
16
15
  if (!this.map.has(src)) {
17
16
  const sub: Class[] = [];
18
17
  this.map.set(src, sub);
@@ -1,7 +1,7 @@
1
1
  import { Module } from 'node:module';
2
2
 
3
- import { path, RuntimeIndex } from '@travetto/manifest';
4
- import { Env } from '@travetto/base';
3
+ import { path } from '@travetto/manifest';
4
+ import { Runtime, RuntimeIndex } from '@travetto/runtime';
5
5
 
6
6
  import { RetargettingProxy } from '../proxy';
7
7
 
@@ -32,7 +32,7 @@ export class DynamicCommonjsLoader {
32
32
  mod = moduleLoad.apply(null, [request, parent]);
33
33
  } catch (err: unknown) {
34
34
  const name = Module._resolveFilename!(request, parent);
35
- if (err instanceof Error && Env.dynamic && !name.startsWith('test/')) {
35
+ if (err instanceof Error && Runtime.dynamic && !name.startsWith('test/')) {
36
36
  const errMsg = err.message;
37
37
  console.debug(`Unable to load ${name}: stubbing out with error proxy.`, errMsg);
38
38
  const e = (): never => { throw new Error(errMsg); };
@@ -1,5 +1,5 @@
1
- import { ManifestModuleUtil, RuntimeIndex, RuntimeContext } from '@travetto/manifest';
2
- import { watchCompiler, FullWatchEvent, WatchEvent } from '@travetto/base';
1
+ import { ManifestModuleUtil } from '@travetto/manifest';
2
+ import { watchCompiler, WatchEvent, Runtime, RuntimeIndex } from '@travetto/runtime';
3
3
 
4
4
  interface ModuleLoader {
5
5
  init?(): Promise<void>;
@@ -19,12 +19,12 @@ class $DynamicFileLoader {
19
19
  #loader: ModuleLoader;
20
20
  #initialized = false;
21
21
 
22
- async dispatch(ev: FullWatchEvent): Promise<void> {
22
+ async dispatch(ev: WatchEvent): Promise<void> {
23
23
  if (ev.action === 'update' || ev.action === 'delete') {
24
24
  await this.#loader.unload(ev.output);
25
25
  }
26
26
  if (ev.action === 'create' || ev.action === 'delete') {
27
- RuntimeIndex.reinitForModule(RuntimeContext.main.name);
27
+ RuntimeIndex.reinitForModule(Runtime.main.name);
28
28
  }
29
29
  if (ev.action === 'create' || ev.action === 'update') {
30
30
  await this.#loader.load(ev.output);
@@ -66,7 +66,7 @@ class $DynamicFileLoader {
66
66
 
67
67
  // Fire off, and let it run in the bg. Restart on exit
68
68
  (async (): Promise<void> => {
69
- for await (const ev of watchCompiler<FullWatchEvent>({ restartOnExit: true })) {
69
+ for await (const ev of watchCompiler({ restartOnExit: true })) {
70
70
  if (ev.file && RuntimeIndex.hasModule(ev.module) && VALID_FILE_TYPES.has(ManifestModuleUtil.getFileType(ev.file))) {
71
71
  await this.dispatch(ev);
72
72
  }
package/src/proxy.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
2
  type ConcreteClass<T = any> = new (...args: any[]) => T;
3
- const ProxyTargetⲐ = Symbol.for('@travetto/base:proxy-target');
3
+ const ProxyTargetⲐ = Symbol.for('@travetto/runtime:proxy-target');
4
4
 
5
5
  const AsyncGeneratorFunction = Object.getPrototypeOf(async function* () { });
6
6
  const GeneratorFunction = Object.getPrototypeOf(function* () { });
package/src/registry.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'node:events';
2
- import { Class, Env } from '@travetto/base';
2
+ import { Class, Env } from '@travetto/runtime';
3
3
  import { ChangeSource, ChangeEvent, ChangeHandler } from './types';
4
4
 
5
5
  /**
@@ -1,4 +1,4 @@
1
- import { Class } from '@travetto/base';
1
+ import { Class } from '@travetto/runtime';
2
2
 
3
3
  import { Registry } from '../registry';
4
4
  import { ChangeEvent } from '../types';
@@ -1,4 +1,4 @@
1
- import { Class } from '@travetto/base';
1
+ import { Class } from '@travetto/runtime';
2
2
 
3
3
  import { Registry } from '../registry';
4
4
  import { ClassSource } from '../source/class-source';
@@ -1,7 +1,7 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
 
3
- import { FindConfig, RuntimeIndex } from '@travetto/manifest';
4
- import { Class, Env } from '@travetto/base';
3
+ import { type FindConfig } from '@travetto/manifest';
4
+ import { Class, Env, Runtime, RuntimeIndex, describeFunction } from '@travetto/runtime';
5
5
 
6
6
  import { DynamicFileLoader } from '../internal/file-loader';
7
7
  import { ChangeSource, ChangeEvent, ChangeHandler } from '../types';
@@ -11,7 +11,7 @@ const moduleFindConfig: FindConfig = {
11
11
  module: (m) => {
12
12
  const role = Env.TRV_ROLE.val;
13
13
  return m.roles.includes('std') && (
14
- !Env.production || m.prod ||
14
+ !Runtime.production || m.prod ||
15
15
  ((role === 'doc' || role === 'test') && m.roles.includes(role))
16
16
  );
17
17
  },
@@ -43,7 +43,7 @@ export class ClassSource implements ChangeSource<Class> {
43
43
  }
44
44
  this.#classes.set(file, new Map());
45
45
  for (const cls of classes) {
46
- const src = RuntimeIndex.getFunctionMetadata(cls)!.source;
46
+ const src = Runtime.getSource(cls);
47
47
  this.#classes.get(src)!.set(cls.Ⲑid, cls);
48
48
  this.emit({ type: 'added', curr: cls });
49
49
  }
@@ -83,9 +83,9 @@ export class ClassSource implements ChangeSource<Class> {
83
83
  changes += 1;
84
84
  this.emit({ type: 'added', curr: next.get(k)! });
85
85
  } else {
86
- const prevMeta = RuntimeIndex.getFunctionMetadataFromClass(prev.get(k));
87
- const nextMeta = RuntimeIndex.getFunctionMetadataFromClass(next.get(k));
88
- if (prevMeta?.hash !== nextMeta?.hash) {
86
+ const prevHash = describeFunction(prev.get(k)!)?.hash;
87
+ const nextHash = describeFunction(next.get(k)!)?.hash;
88
+ if (prevHash !== nextHash) {
89
89
  changes += 1;
90
90
  this.emit({ type: 'changed', curr: next.get(k)!, prev: prev.get(k) });
91
91
  }
@@ -111,7 +111,7 @@ export class ClassSource implements ChangeSource<Class> {
111
111
  * Initialize
112
112
  */
113
113
  async init(): Promise<void> {
114
- if (Env.dynamic) {
114
+ if (Runtime.dynamic) {
115
115
  DynamicFileLoader.onLoadEvent(ev => {
116
116
  for (const [file, classes] of PendingRegister.flush(true)) {
117
117
  this.#handleFileChanges(file, classes);
@@ -1,7 +1,6 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
 
3
- import { Class } from '@travetto/base';
4
- import { RuntimeIndex } from '@travetto/manifest';
3
+ import { Class, describeFunction } from '@travetto/runtime';
5
4
 
6
5
  import { ChangeSource, ChangeEvent, ChangeHandler } from '../types';
7
6
 
@@ -30,8 +29,8 @@ export class MethodSource implements ChangeSource<[Class, Function]> {
30
29
  * On a class being emitted, check methods
31
30
  */
32
31
  onClassEvent(e: ChangeEvent<Class>): void {
33
- const next = RuntimeIndex.getFunctionMetadataFromClass(e.curr!)?.methods ?? {};
34
- const prev = RuntimeIndex.getFunctionMetadataFromClass(e.prev!)?.methods ?? {};
32
+ const next = describeFunction(e.curr!)?.methods ?? {};
33
+ const prev = describeFunction(e.prev!)?.methods ?? {};
35
34
 
36
35
  /**
37
36
  * Go through each method, comparing hashes. To see added/removed and changed
@@ -3,7 +3,8 @@ import ts from 'typescript';
3
3
  import { TransformerState, AfterClass, DecoratorUtil } from '@travetto/transformer';
4
4
 
5
5
  const REGISTER_MOD = '@travetto/registry/src/decorator';
6
- const SKIP_SRC = /^@travetto\/(base|manifest)\/(src|support)/;
6
+ const SKIP_SRC = /^@travetto\/(runtime|manifest)\/(src|support)/;
7
+ const SKIP_FUNCTION = /^@travetto\/registry\/src\/function/;
7
8
 
8
9
  /**
9
10
  * Registration of all classes to support the registry
@@ -17,7 +18,8 @@ export class RegisterTransformer {
17
18
  static registerClass(state: TransformerState, node: ts.ClassDeclaration): ts.ClassDeclaration {
18
19
  if (
19
20
  state.importName === REGISTER_MOD ||
20
- SKIP_SRC.test(state.importName)
21
+ SKIP_SRC.test(state.importName) ||
22
+ SKIP_FUNCTION.test(state.importName)
21
23
  ) { // Cannot process self
22
24
  return node;
23
25
  }