@travetto/runtime 5.0.14 → 5.0.16

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
@@ -69,6 +69,9 @@ class $Runtime {
69
69
  }
70
70
  ```
71
71
 
72
+ ### Class and Function Metadata
73
+ For the framework to work properly, metadata needs to be collected about files, classes and functions to uniquely identify them, with support for detecting changes during live reloads. To achieve this, every `class` is decorated with metadata, including methods, line numbers, and ultimately a unique id stored at `Ⲑid`.
74
+
72
75
  ## Environment Support
73
76
  The functionality we support for testing and retrieving environment information for known environment variables. They can be accessed directly on the [Env](https://github.com/travetto/travetto/tree/main/module/runtime/src/env.ts#L111) object, and will return a scoped [EnvProp](https://github.com/travetto/travetto/tree/main/module/runtime/src/env.ts#L8), that is compatible with the property definition. E.g. only showing boolean related fields when the underlying flag supports `true` or `false`
74
77
 
@@ -213,20 +216,20 @@ export function work() {
213
216
  Object.defineProperty(exports, "__esModule", { value: true });
214
217
  exports.work = work;
215
218
  const tslib_1 = require("tslib");
216
- const Ⲑ_function_1 = tslib_1.__importStar(require("@travetto/runtime/src/function.js"));
217
- const ᚕ_c = tslib_1.__importStar(require("@travetto/runtime/src/console.js"));
218
- var ᚕm = ["@travetto/runtime", "doc/transpile.ts"];
219
+ const Δfunction = tslib_1.__importStar(require("@travetto/runtime/src/function.js"));
220
+ const Δconsole = tslib_1.__importStar(require("@travetto/runtime/src/console.js"));
221
+ var mod_1 = ["@travetto/runtime", "doc/transpile.ts"];
219
222
  function work() {
220
- ᚕ_c.log({ level: "debug", import: ᚕm, line: 2, scope: "work", args: ['Start Work'] });
223
+ Δconsole.log({ level: "debug", import: mod_1, line: 2, scope: "work", args: ['Start Work'] });
221
224
  try {
222
225
  1 / 0;
223
226
  }
224
227
  catch (err) {
225
- ᚕ_c.log({ level: "error", import: ᚕm, line: 7, scope: "work", args: ['Divide by zero', { error: err }] });
228
+ Δconsole.log({ level: "error", import: mod_1, line: 7, scope: "work", args: ['Divide by zero', { error: err }] });
226
229
  }
227
- ᚕ_c.log({ level: "debug", import: ᚕm, line: 9, scope: "work", args: ['End Work'] });
230
+ Δconsole.log({ level: "debug", import: mod_1, line: 9, scope: "work", args: ['End Work'] });
228
231
  }
229
- Ⲑ_function_1.registerFunction(work, ᚕm, { hash: 1030247697, lines: [1, 10, 2] });
232
+ Δfunction.registerFunction(work, mod_1, { hash: 1030247697, lines: [1, 10, 2] });
230
233
  ```
231
234
 
232
235
  #### Filtering Debug
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/runtime",
3
- "version": "5.0.14",
3
+ "version": "5.0.16",
4
4
  "description": "Runtime for travetto applications.",
5
5
  "keywords": [
6
6
  "console-manager",
@@ -21,16 +21,16 @@
21
21
  ],
22
22
  "main": "__index__.ts",
23
23
  "repository": {
24
- "url": "https://github.com/travetto/travetto.git",
24
+ "url": "git+https://github.com/travetto/travetto.git",
25
25
  "directory": "module/runtime"
26
26
  },
27
27
  "dependencies": {
28
- "@travetto/manifest": "^5.0.10",
28
+ "@travetto/manifest": "^5.0.12",
29
29
  "@types/debug": "^4.1.12",
30
30
  "debug": "^4.4.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/transformer": "^5.0.11"
33
+ "@travetto/transformer": "^5.0.13"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@travetto/transformer": {
package/src/binary.ts CHANGED
@@ -11,7 +11,7 @@ import { BinaryInput, BlobMeta } from './types';
11
11
  import { AppError } from './error';
12
12
  import { Util } from './util';
13
13
 
14
- const BlobMetaⲐ = Symbol.for('@travetto/runtime:blob-meta');
14
+ const BlobMetaSymbol = Symbol.for('@travetto/runtime:blob-meta');
15
15
 
16
16
  /**
17
17
  * Common functions for dealing with binary data/streams
@@ -86,7 +86,7 @@ export class BinaryUtil {
86
86
  arrayBuffer: { value: () => toBuffer(go()) },
87
87
  text: { value: () => toText(go()) },
88
88
  bytes: { value: () => toBuffer(go()).then(v => new Uint8Array(v)) },
89
- [BlobMetaⲐ]: { value: metadata }
89
+ [BlobMetaSymbol]: { value: metadata }
90
90
  });
91
91
  }
92
92
 
@@ -94,8 +94,8 @@ export class BinaryUtil {
94
94
  * Get blob metadata
95
95
  */
96
96
  static getBlobMeta(blob: Blob): BlobMeta | undefined {
97
- const withMeta: Blob & { [BlobMetaⲐ]?: BlobMeta } = blob;
98
- return withMeta[BlobMetaⲐ];
97
+ const withMeta: Blob & { [BlobMetaSymbol]?: BlobMeta } = blob;
98
+ return withMeta[BlobMetaSymbol];
99
99
  }
100
100
 
101
101
  /**
package/src/function.ts CHANGED
@@ -5,12 +5,11 @@ export type FunctionMetadata = FunctionMetadataTag & {
5
5
  module: string;
6
6
  modulePath: string;
7
7
  methods?: Record<string, FunctionMetadataTag>;
8
- synthetic?: boolean;
9
8
  class?: boolean;
10
9
  abstract?: boolean;
11
10
  };
12
11
 
13
- const METADATA = Symbol.for('@travetto/runtime:function-metadata');
12
+ const MetadataSymbol = Symbol.for('@travetto/runtime:function-metadata');
14
13
 
15
14
  const pending = new Set<Function>([]);
16
15
 
@@ -22,24 +21,23 @@ const pending = new Set<Function>([]);
22
21
  * @param `line` Line number in source
23
22
  * @param `methods` Methods and their hashes
24
23
  * @param `abstract` Is the class abstract
25
- * @param `synthetic` Is this code generated at build time
26
24
  * @private
27
25
  */
28
26
  export function registerFunction(
29
27
  fn: Function, [pkg, pth]: [string, string], tag: FunctionMetadataTag,
30
- methods?: Record<string, FunctionMetadataTag>, abstract?: boolean, synthetic?: boolean
28
+ methods?: Record<string, FunctionMetadataTag>, abstract?: boolean,
31
29
  ): void {
32
30
  const modulePath = pth.replace(/[.][cm]?[tj]sx?$/, '');
33
31
 
34
32
  const metadata: FunctionMetadata = {
35
- id: (fn.name ? `${pkg}:${modulePath}○${fn.name}` : `${pkg}:${modulePath}`),
33
+ id: (fn.name ? `${pkg}:${modulePath}#${fn.name}` : `${pkg}:${modulePath}`),
36
34
  import: `${pkg}/${pth}`,
37
35
  module: pkg,
38
36
  modulePath,
39
- ...tag, methods, abstract, synthetic, class: abstract !== undefined
37
+ ...tag, methods, abstract, class: abstract !== undefined
40
38
  };
41
39
  pending.add(fn);
42
- Object.defineProperties(fn, { Ⲑid: { value: metadata.id }, [METADATA]: { value: metadata } });
40
+ Object.defineProperties(fn, { Ⲑid: { value: metadata.id }, [MetadataSymbol]: { value: metadata } });
43
41
  }
44
42
 
45
43
  /**
@@ -56,6 +54,6 @@ export function flushPendingFunctions(): Function[] {
56
54
  */
57
55
  export function describeFunction(fn: Function): FunctionMetadata;
58
56
  export function describeFunction(fn?: Function): FunctionMetadata | undefined {
59
- const _fn: (Function & { [METADATA]?: FunctionMetadata }) | undefined = fn;
60
- return _fn?.[METADATA];
61
- }
57
+ const _fn: (Function & { [MetadataSymbol]?: FunctionMetadata }) | undefined = fn;
58
+ return _fn?.[MetadataSymbol];
59
+ }
package/src/global.d.ts CHANGED
@@ -6,7 +6,9 @@ declare global {
6
6
  interface WritableStreamDefaultWriter<W = any> {
7
7
  [write]?: (a: W) => void;
8
8
  }
9
+
9
10
  interface Function {
10
- Ⲑid: string;
11
+ /* Exposed for use within framework, only applies to framework managed classes */
12
+ readonly Ⲑid: string;
11
13
  }
12
14
  }
package/src/shutdown.ts CHANGED
@@ -15,13 +15,13 @@ export class ShutdownManager {
15
15
  * @param name name to log for
16
16
  * @param handler synchronous or asynchronous handler
17
17
  */
18
- static onGracefulShutdown(handler: () => Promise<void>, name?: string | { constructor: { Ⲑid: string } }): () => void {
18
+ static onGracefulShutdown(handler: () => Promise<void>, name?: string | { constructor: Function }): () => void {
19
19
  if (!this.#registered) {
20
20
  this.#registered = true;
21
21
  const done = (): void => { this.gracefulShutdown(0); };
22
22
  process.on('SIGUSR2', done).on('SIGTERM', done).on('SIGINT', done);
23
23
  }
24
- this.#handlers.push({ handler, name: typeof name === 'string' ? name : name?.constructor.Ⲑid });
24
+ this.#handlers.push({ handler, name: typeof name === 'string' ? name : name?.constructor?.Ⲑid });
25
25
  return () => {
26
26
  const idx = this.#handlers.findIndex(x => x.handler === handler);
27
27
  if (idx >= 0) {
package/src/types.ts CHANGED
@@ -6,9 +6,7 @@ export type Any = any;
6
6
 
7
7
  export type AnyMap = { [key: string]: Any };
8
8
  export type Class<T = Any> = abstract new (...args: Any[]) => T;
9
- export type ClassInstance<T = Any> = T & {
10
- constructor: Class<T> & { Ⲑid: string };
11
- };
9
+ export type ClassInstance<T = Any> = T & { constructor: Class<T> };
12
10
 
13
11
  export type BinaryInput = Blob | Buffer | Readable | ReadableStream;
14
12
 
@@ -1,9 +1,6 @@
1
1
  import ts from 'typescript';
2
2
 
3
- import {
4
- TransformerState, OnCall, LiteralUtil,
5
- OnClass, AfterClass, OnMethod, AfterMethod, AfterFunction, OnFunction
6
- } from '@travetto/transformer';
3
+ import { TransformerState, OnCall, LiteralUtil, OnClass, AfterClass, OnMethod, AfterMethod, AfterFunction, OnFunction } from '@travetto/transformer';
7
4
 
8
5
  const CONSOLE_IMPORT = '@travetto/runtime/src/console';
9
6
 
@@ -89,7 +86,7 @@ export class ConsoleLogTransformer {
89
86
  const level = name.escapedText!;
90
87
 
91
88
  if (VALID_LEVELS[level]) {
92
- const ident = state.imported ??= state.importFile(CONSOLE_IMPORT, 'ᚕ_c').ident;
89
+ const ident = state.imported ??= state.importFile(CONSOLE_IMPORT).ident;
93
90
  return state.factory.updateCallExpression(
94
91
  node,
95
92
  state.createAccess(ident, 'log'),
@@ -2,13 +2,13 @@ import ts from 'typescript';
2
2
 
3
3
  import { TransformerState, OnMethod, CoreUtil } from '@travetto/transformer';
4
4
 
5
- const DebugⲐ = Symbol.for('@travetto/runtime:debug');
5
+ const DebugSymbol = Symbol.for('@travetto/runtime:debug');
6
6
 
7
7
  /**
8
8
  * Debug transformation state
9
9
  */
10
10
  interface DebugState {
11
- [DebugⲐ]?: ts.Expression;
11
+ [DebugSymbol]?: ts.Expression;
12
12
  }
13
13
 
14
14
  /**
@@ -18,9 +18,9 @@ export class DebugEntryTransformer {
18
18
 
19
19
  @OnMethod('DebugBreak')
20
20
  static debugOnEntry(state: TransformerState & DebugState, node: ts.MethodDeclaration): ts.MethodDeclaration {
21
- if (!state[DebugⲐ]) {
21
+ if (!state[DebugSymbol]) {
22
22
  const imp = state.importFile('@travetto/runtime/src/debug').ident;
23
- state[DebugⲐ] = CoreUtil.createAccess(state.factory, imp, 'tryDebugger');
23
+ state[DebugSymbol] = CoreUtil.createAccess(state.factory, imp, 'tryDebugger');
24
24
  }
25
25
 
26
26
  return state.factory.updateMethodDeclaration(node,
@@ -32,7 +32,7 @@ export class DebugEntryTransformer {
32
32
  node.parameters,
33
33
  node.type,
34
34
  node.body ? state.factory.updateBlock(node.body, [
35
- state.factory.createIfStatement(state[DebugⲐ]!,
35
+ state.factory.createIfStatement(state[DebugSymbol]!,
36
36
  state.factory.createExpressionStatement(state.factory.createIdentifier('debugger'))),
37
37
  ...node.body.statements
38
38
  ]) : node.body
@@ -1,9 +1,6 @@
1
1
  import ts from 'typescript';
2
2
 
3
- import {
4
- TransformerState, OnMethod, OnClass, AfterClass,
5
- CoreUtil, SystemUtil, Import, OnFunction
6
- } from '@travetto/transformer';
3
+ import { TransformerState, OnMethod, OnClass, AfterClass, CoreUtil, SystemUtil, Import, OnFunction } from '@travetto/transformer';
7
4
 
8
5
  import type { FunctionMetadataTag } from '../src/function';
9
6
 
@@ -95,7 +92,6 @@ export class RegisterTransformer {
95
92
  state.fromLiteral(state[cls]),
96
93
  state.extendObjectLiteral(state[methods] || {}),
97
94
  state.fromLiteral(CoreUtil.isAbstract(node)),
98
- state.fromLiteral(name.endsWith(TransformerState.SYNTHETIC_EXT))
99
95
  ]
100
96
  );
101
97
 
@@ -109,7 +105,11 @@ export class RegisterTransformer {
109
105
  node.typeParameters,
110
106
  node.heritageClauses,
111
107
  [
112
- state.createStaticField('Ⲑinit', meta),
108
+ state.factory.createClassStaticBlockDeclaration(
109
+ state.factory.createBlock([
110
+ state.factory.createExpressionStatement(meta)
111
+ ])
112
+ ),
113
113
  ...node.members
114
114
  ]
115
115
  );