@luxalgo/vela-pinets 0.2.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/LICENSE +661 -0
- package/README.md +44 -0
- package/dist/index.cjs +1545 -0
- package/dist/index.d.cts +93 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +1542 -0
- package/dist/vela-pinets.global.js +16622 -0
- package/dist/vela-pinets.global.min.js +125 -0
- package/package.json +50 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ScriptingEngine, EngineCapabilities, PreparedScript, ExecutionRequest, ExecutionHandlers, ExecutionSession } from '@luxalgo/vela/plugin';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The in-process PineTS implementation of `ScriptingEngine`. Both the static run
|
|
5
|
+
* and the live stream go through the shared `runtime` — the same code the
|
|
6
|
+
* worker-backed `PineWorkerEngine` runs — so this class is just the in-process
|
|
7
|
+
* wiring to the port. Vela owns market data and passes bars into `execute`;
|
|
8
|
+
* this engine never fetches.
|
|
9
|
+
*/
|
|
10
|
+
declare class PineEngine implements ScriptingEngine {
|
|
11
|
+
readonly language = "pine";
|
|
12
|
+
readonly capabilities: EngineCapabilities;
|
|
13
|
+
prepare(source: string, instanceId: string): Promise<PreparedScript>;
|
|
14
|
+
execute(req: ExecutionRequest, handlers: ExecutionHandlers): ExecutionSession;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Minimal Worker surface the proxy needs — the real `Worker` satisfies it; tests inject a fake. */
|
|
18
|
+
interface WorkerLike {
|
|
19
|
+
postMessage(message: unknown): void;
|
|
20
|
+
addEventListener(type: 'message', listener: (event: {
|
|
21
|
+
data: unknown;
|
|
22
|
+
}) => void): void;
|
|
23
|
+
terminate(): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface PineWorkerOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Override the worker source. By default the worker is inlined into the bundle
|
|
29
|
+
* and spawned from a Blob URL (no separate file, no URL to configure); set this
|
|
30
|
+
* to load a hosted worker file instead — e.g. under a CSP that blocks `blob:`.
|
|
31
|
+
*/
|
|
32
|
+
workerUrl?: string;
|
|
33
|
+
/** Worker factory — tests inject a fake; defaults to the inlined Blob worker. */
|
|
34
|
+
createWorker?: () => WorkerLike;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A worker-backed PineTS engine: identical Pine semantics to `PineEngine`, but the
|
|
38
|
+
* transpile + execution run on a Web Worker, keeping the main thread responsive.
|
|
39
|
+
* Implements the same `ScriptingEngine` port, so the orchestrator never learns a
|
|
40
|
+
* worker exists. Secondary fetches (request.security) round-trip back to the main
|
|
41
|
+
* thread, where the cache + network live.
|
|
42
|
+
*
|
|
43
|
+
* Live charts stream: the worker holds ONE persistent PineTS streaming context per
|
|
44
|
+
* live session, so a tick ships only the forming bar (a tiny `bars` delta) and the
|
|
45
|
+
* script re-executes incrementally — never a full snapshot + full re-run per tick.
|
|
46
|
+
* Static sessions (non-live charts, viewport-dependent scripts) run per poke with
|
|
47
|
+
* the pending-run coalescing below; live messages NEVER enter that bookkeeping —
|
|
48
|
+
* a live session acks nothing, so counting it would jam the coalescing forever.
|
|
49
|
+
*/
|
|
50
|
+
declare class PineWorkerEngine implements ScriptingEngine {
|
|
51
|
+
readonly language = "pine";
|
|
52
|
+
readonly capabilities: EngineCapabilities;
|
|
53
|
+
private worker;
|
|
54
|
+
private readonly spawn;
|
|
55
|
+
private readonly prepares;
|
|
56
|
+
private readonly sessions;
|
|
57
|
+
private reqId;
|
|
58
|
+
private readonly contextWaits;
|
|
59
|
+
private sessionId;
|
|
60
|
+
constructor(opts?: PineWorkerOptions);
|
|
61
|
+
prepare(source: string, instanceId: string): Promise<PreparedScript>;
|
|
62
|
+
execute(req: ExecutionRequest, handlers: ExecutionHandlers): ExecutionSession;
|
|
63
|
+
/**
|
|
64
|
+
* Coalesced bar-change notification: shipping a full bars snapshot + a complete re-run per
|
|
65
|
+
* tick is wasteful when ticks burst (a gap heal, a fast market) — while ANY run is in flight
|
|
66
|
+
* for the session, just mark it dirty and re-run ONCE (with a fresh snapshot) when the run
|
|
67
|
+
* lands. The worker can't read the live bars array, hence the snapshot per posted run.
|
|
68
|
+
*
|
|
69
|
+
* `'backfill'` notifications never cross to the worker at all: every posted run ships a
|
|
70
|
+
* FRESH full snapshot anyway, so intermediate partial-history snapshots buy nothing — the
|
|
71
|
+
* worker sees the deepened history on the `'complete'` (or next tick) run. This also keeps
|
|
72
|
+
* the pending-run bookkeeping honest (a posted-but-skipped run would jam the coalescing).
|
|
73
|
+
*/
|
|
74
|
+
private notifyBars;
|
|
75
|
+
/** Post a message that triggers exactly one worker run (acked by one `done`/`error`). */
|
|
76
|
+
private postRun;
|
|
77
|
+
/** A worker run finished (`done` or `error`): flush a coalesced bar notification, if any. */
|
|
78
|
+
private runFinished;
|
|
79
|
+
/** Terminate the worker (no port hook calls this yet; exposed for host cleanup). */
|
|
80
|
+
terminate(): void;
|
|
81
|
+
private barsOf;
|
|
82
|
+
private workerInstance;
|
|
83
|
+
private post;
|
|
84
|
+
private onMessage;
|
|
85
|
+
/**
|
|
86
|
+
* Answer a worker's secondary-fetch request via the orchestrator's gateway. Any
|
|
87
|
+
* live session's `fetchSeries` works — they all route to the same chart-level
|
|
88
|
+
* cache-backed gateway (same provider, neutral by (symbol, timeframe)).
|
|
89
|
+
*/
|
|
90
|
+
private serveFetch;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { PineEngine, PineWorkerEngine, type PineWorkerOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ScriptingEngine, EngineCapabilities, PreparedScript, ExecutionRequest, ExecutionHandlers, ExecutionSession } from '@luxalgo/vela/plugin';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The in-process PineTS implementation of `ScriptingEngine`. Both the static run
|
|
5
|
+
* and the live stream go through the shared `runtime` — the same code the
|
|
6
|
+
* worker-backed `PineWorkerEngine` runs — so this class is just the in-process
|
|
7
|
+
* wiring to the port. Vela owns market data and passes bars into `execute`;
|
|
8
|
+
* this engine never fetches.
|
|
9
|
+
*/
|
|
10
|
+
declare class PineEngine implements ScriptingEngine {
|
|
11
|
+
readonly language = "pine";
|
|
12
|
+
readonly capabilities: EngineCapabilities;
|
|
13
|
+
prepare(source: string, instanceId: string): Promise<PreparedScript>;
|
|
14
|
+
execute(req: ExecutionRequest, handlers: ExecutionHandlers): ExecutionSession;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Minimal Worker surface the proxy needs — the real `Worker` satisfies it; tests inject a fake. */
|
|
18
|
+
interface WorkerLike {
|
|
19
|
+
postMessage(message: unknown): void;
|
|
20
|
+
addEventListener(type: 'message', listener: (event: {
|
|
21
|
+
data: unknown;
|
|
22
|
+
}) => void): void;
|
|
23
|
+
terminate(): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface PineWorkerOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Override the worker source. By default the worker is inlined into the bundle
|
|
29
|
+
* and spawned from a Blob URL (no separate file, no URL to configure); set this
|
|
30
|
+
* to load a hosted worker file instead — e.g. under a CSP that blocks `blob:`.
|
|
31
|
+
*/
|
|
32
|
+
workerUrl?: string;
|
|
33
|
+
/** Worker factory — tests inject a fake; defaults to the inlined Blob worker. */
|
|
34
|
+
createWorker?: () => WorkerLike;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A worker-backed PineTS engine: identical Pine semantics to `PineEngine`, but the
|
|
38
|
+
* transpile + execution run on a Web Worker, keeping the main thread responsive.
|
|
39
|
+
* Implements the same `ScriptingEngine` port, so the orchestrator never learns a
|
|
40
|
+
* worker exists. Secondary fetches (request.security) round-trip back to the main
|
|
41
|
+
* thread, where the cache + network live.
|
|
42
|
+
*
|
|
43
|
+
* Live charts stream: the worker holds ONE persistent PineTS streaming context per
|
|
44
|
+
* live session, so a tick ships only the forming bar (a tiny `bars` delta) and the
|
|
45
|
+
* script re-executes incrementally — never a full snapshot + full re-run per tick.
|
|
46
|
+
* Static sessions (non-live charts, viewport-dependent scripts) run per poke with
|
|
47
|
+
* the pending-run coalescing below; live messages NEVER enter that bookkeeping —
|
|
48
|
+
* a live session acks nothing, so counting it would jam the coalescing forever.
|
|
49
|
+
*/
|
|
50
|
+
declare class PineWorkerEngine implements ScriptingEngine {
|
|
51
|
+
readonly language = "pine";
|
|
52
|
+
readonly capabilities: EngineCapabilities;
|
|
53
|
+
private worker;
|
|
54
|
+
private readonly spawn;
|
|
55
|
+
private readonly prepares;
|
|
56
|
+
private readonly sessions;
|
|
57
|
+
private reqId;
|
|
58
|
+
private readonly contextWaits;
|
|
59
|
+
private sessionId;
|
|
60
|
+
constructor(opts?: PineWorkerOptions);
|
|
61
|
+
prepare(source: string, instanceId: string): Promise<PreparedScript>;
|
|
62
|
+
execute(req: ExecutionRequest, handlers: ExecutionHandlers): ExecutionSession;
|
|
63
|
+
/**
|
|
64
|
+
* Coalesced bar-change notification: shipping a full bars snapshot + a complete re-run per
|
|
65
|
+
* tick is wasteful when ticks burst (a gap heal, a fast market) — while ANY run is in flight
|
|
66
|
+
* for the session, just mark it dirty and re-run ONCE (with a fresh snapshot) when the run
|
|
67
|
+
* lands. The worker can't read the live bars array, hence the snapshot per posted run.
|
|
68
|
+
*
|
|
69
|
+
* `'backfill'` notifications never cross to the worker at all: every posted run ships a
|
|
70
|
+
* FRESH full snapshot anyway, so intermediate partial-history snapshots buy nothing — the
|
|
71
|
+
* worker sees the deepened history on the `'complete'` (or next tick) run. This also keeps
|
|
72
|
+
* the pending-run bookkeeping honest (a posted-but-skipped run would jam the coalescing).
|
|
73
|
+
*/
|
|
74
|
+
private notifyBars;
|
|
75
|
+
/** Post a message that triggers exactly one worker run (acked by one `done`/`error`). */
|
|
76
|
+
private postRun;
|
|
77
|
+
/** A worker run finished (`done` or `error`): flush a coalesced bar notification, if any. */
|
|
78
|
+
private runFinished;
|
|
79
|
+
/** Terminate the worker (no port hook calls this yet; exposed for host cleanup). */
|
|
80
|
+
terminate(): void;
|
|
81
|
+
private barsOf;
|
|
82
|
+
private workerInstance;
|
|
83
|
+
private post;
|
|
84
|
+
private onMessage;
|
|
85
|
+
/**
|
|
86
|
+
* Answer a worker's secondary-fetch request via the orchestrator's gateway. Any
|
|
87
|
+
* live session's `fetchSeries` works — they all route to the same chart-level
|
|
88
|
+
* cache-backed gateway (same provider, neutral by (symbol, timeframe)).
|
|
89
|
+
*/
|
|
90
|
+
private serveFetch;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { PineEngine, PineWorkerEngine, type PineWorkerOptions };
|