@travetto/runtime 5.0.13 → 5.0.15
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 +10 -7
- package/package.json +4 -8
- package/src/binary.ts +4 -4
- package/src/function.ts +8 -10
- package/src/global.d.ts +3 -1
- package/src/shutdown.ts +2 -2
- package/src/time.ts +1 -1
- package/src/types.ts +1 -3
- package/src/util.ts +1 -1
- package/support/transformer.console-log.ts +2 -5
- package/support/transformer.debug-method.ts +5 -5
- package/support/transformer.function-metadata.ts +6 -6
- package/LICENSE +0 -21
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
|
|
217
|
-
const
|
|
218
|
-
var
|
|
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
|
-
|
|
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
|
-
|
|
228
|
+
Δconsole.log({ level: "error", import: mod_1, line: 7, scope: "work", args: ['Divide by zero', { error: err }] });
|
|
226
229
|
}
|
|
227
|
-
|
|
230
|
+
Δconsole.log({ level: "debug", import: mod_1, line: 9, scope: "work", args: ['End Work'] });
|
|
228
231
|
}
|
|
229
|
-
|
|
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.
|
|
3
|
+
"version": "5.0.15",
|
|
4
4
|
"description": "Runtime for travetto applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"console-manager",
|
|
@@ -24,17 +24,13 @@
|
|
|
24
24
|
"url": "https://github.com/travetto/travetto.git",
|
|
25
25
|
"directory": "module/runtime"
|
|
26
26
|
},
|
|
27
|
-
"engines": {
|
|
28
|
-
"node": ">=22.0.0"
|
|
29
|
-
},
|
|
30
27
|
"dependencies": {
|
|
31
|
-
"@travetto/manifest": "^5.0.
|
|
28
|
+
"@travetto/manifest": "^5.0.11",
|
|
32
29
|
"@types/debug": "^4.1.12",
|
|
33
|
-
"
|
|
34
|
-
"debug": "^4.3.7"
|
|
30
|
+
"debug": "^4.4.0"
|
|
35
31
|
},
|
|
36
32
|
"peerDependencies": {
|
|
37
|
-
"@travetto/transformer": "^5.0.
|
|
33
|
+
"@travetto/transformer": "^5.0.12"
|
|
38
34
|
},
|
|
39
35
|
"peerDependenciesMeta": {
|
|
40
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
|
|
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
|
-
[
|
|
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 & { [
|
|
98
|
-
return withMeta[
|
|
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
|
|
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,
|
|
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}
|
|
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,
|
|
37
|
+
...tag, methods, abstract, class: abstract !== undefined
|
|
40
38
|
};
|
|
41
39
|
pending.add(fn);
|
|
42
|
-
Object.defineProperties(fn, { Ⲑid: { value: metadata.id }, [
|
|
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 & { [
|
|
60
|
-
return _fn?.[
|
|
61
|
-
}
|
|
57
|
+
const _fn: (Function & { [MetadataSymbol]?: FunctionMetadata }) | undefined = fn;
|
|
58
|
+
return _fn?.[MetadataSymbol];
|
|
59
|
+
}
|
package/src/global.d.ts
CHANGED
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:
|
|
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
|
|
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/time.ts
CHANGED
|
@@ -69,7 +69,7 @@ export class TimeUtil {
|
|
|
69
69
|
if (value === undefined) {
|
|
70
70
|
return value;
|
|
71
71
|
}
|
|
72
|
-
const val = (typeof value === 'string' && /\d
|
|
72
|
+
const val = (typeof value === 'string' && /\d{1,30}[a-z]$/i.test(value)) ?
|
|
73
73
|
(this.isTimeSpan(value) ? this.asMillis(value) : undefined) :
|
|
74
74
|
(typeof value === 'string' ? parseInt(value, 10) :
|
|
75
75
|
(value instanceof Date ? value.getTime() : value));
|
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
|
|
package/src/util.ts
CHANGED
|
@@ -117,7 +117,7 @@ export class Util {
|
|
|
117
117
|
cacheKey?: (...keyInput: K) => string
|
|
118
118
|
): (...input: K) => boolean {
|
|
119
119
|
|
|
120
|
-
const rawRules = (Array.isArray(rules) ? rules : rules.split(
|
|
120
|
+
const rawRules = (Array.isArray(rules) ? rules : rules.split(/,/g).map(x => x.trim()));
|
|
121
121
|
const convertedRules = rawRules.map(rule => this.#allowDenyRuleInput(rule, convert));
|
|
122
122
|
const unmatchedValue = !convertedRules.some(r => r.positive);
|
|
123
123
|
|
|
@@ -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
|
|
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
|
|
5
|
+
const DebugSymbol = Symbol.for('@travetto/runtime:debug');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Debug transformation state
|
|
9
9
|
*/
|
|
10
10
|
interface DebugState {
|
|
11
|
-
[
|
|
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[
|
|
21
|
+
if (!state[DebugSymbol]) {
|
|
22
22
|
const imp = state.importFile('@travetto/runtime/src/debug').ident;
|
|
23
|
-
state[
|
|
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[
|
|
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.
|
|
108
|
+
state.factory.createClassStaticBlockDeclaration(
|
|
109
|
+
state.factory.createBlock([
|
|
110
|
+
state.factory.createExpressionStatement(meta)
|
|
111
|
+
])
|
|
112
|
+
),
|
|
113
113
|
...node.members
|
|
114
114
|
]
|
|
115
115
|
);
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 ArcSine Technologies
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|