@alphacharts/script 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +161 -2
- package/dist/builtins-BXxWK58s.js +812 -0
- package/dist/builtins-BXxWK58s.js.map +1 -0
- package/dist/editor.js +211 -0
- package/dist/editor.js.map +1 -0
- package/dist/index.js +342 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox-p2HPP8yl.js +2416 -0
- package/dist/sandbox-p2HPP8yl.js.map +1 -0
- package/dist/sandbox-worker.js +8 -0
- package/dist/sandbox-worker.js.map +1 -0
- package/dist/types/ast.d.ts +156 -0
- package/dist/types/builtins.d.ts +67 -0
- package/dist/types/check.d.ts +78 -0
- package/dist/types/codegen.d.ts +14 -0
- package/dist/types/compile.d.ts +52 -0
- package/dist/types/diag.d.ts +45 -0
- package/dist/types/editor/index.d.ts +23 -0
- package/dist/types/feeds.d.ts +33 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/lexer.d.ts +14 -0
- package/dist/types/limits.d.ts +25 -0
- package/dist/types/parser.d.ts +3 -0
- package/dist/types/run.d.ts +69 -0
- package/dist/types/runner.d.ts +54 -0
- package/dist/types/sandbox-worker.d.ts +1 -0
- package/dist/types/sandbox.d.ts +78 -0
- package/dist/types/ui-adapter.d.ts +21 -0
- package/package.json +75 -3
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type BarColumns, type BarInput, type FeedBar, type FeedData, type InputValue, type StudyDef } from "@alphacharts/indicators";
|
|
2
|
+
import { type Limits } from "./limits.js";
|
|
3
|
+
/** Host capabilities a script must not have: network, storage, other threads, message ports. */
|
|
4
|
+
export declare const BLOCKED_GLOBALS: readonly ["fetch", "XMLHttpRequest", "WebSocket", "WebTransport", "EventSource", "importScripts", "indexedDB", "caches", "BroadcastChannel", "SharedWorker", "Worker", "MessageChannel", "Request", "Response", "localStorage", "sessionStorage", "FileReader", "FileReaderSync", "Notification", "navigator", "location", "document", "window", "XMLHttpRequestUpload", "RTCPeerConnection"];
|
|
5
|
+
export interface LockdownReport {
|
|
6
|
+
blocked: string[];
|
|
7
|
+
missing: string[];
|
|
8
|
+
}
|
|
9
|
+
/** Shadow every blocked capability on `scope` with an undefined, non-configurable, read-only property. Idempotent. */
|
|
10
|
+
export declare function lockdown(scope?: object): LockdownReport;
|
|
11
|
+
export interface RunMsg {
|
|
12
|
+
type: "run";
|
|
13
|
+
id: number;
|
|
14
|
+
sid: number;
|
|
15
|
+
source: string;
|
|
16
|
+
params: Record<string, InputValue>;
|
|
17
|
+
bars: BarColumns;
|
|
18
|
+
feeds?: Record<string, FeedData>;
|
|
19
|
+
limits?: Partial<Limits>;
|
|
20
|
+
}
|
|
21
|
+
export interface BarMsg {
|
|
22
|
+
type: "bar";
|
|
23
|
+
sid: number;
|
|
24
|
+
index: number;
|
|
25
|
+
bar: BarInput;
|
|
26
|
+
}
|
|
27
|
+
/** A live bar of outside series `key` (the `bar` channel for another instrument or timeframe). */
|
|
28
|
+
export interface FeedBarMsg {
|
|
29
|
+
type: "feed-bar";
|
|
30
|
+
sid: number;
|
|
31
|
+
key: string;
|
|
32
|
+
bar: FeedBar;
|
|
33
|
+
}
|
|
34
|
+
export type ToWorker = RunMsg | BarMsg | FeedBarMsg | {
|
|
35
|
+
type: "cancel";
|
|
36
|
+
id: number;
|
|
37
|
+
} | {
|
|
38
|
+
type: "dispose";
|
|
39
|
+
sid: number;
|
|
40
|
+
};
|
|
41
|
+
export interface ErrorInfo {
|
|
42
|
+
message: string;
|
|
43
|
+
from?: number;
|
|
44
|
+
to?: number;
|
|
45
|
+
kind: "build" | "runtime" | "budget" | "compile";
|
|
46
|
+
}
|
|
47
|
+
export type FromWorker = {
|
|
48
|
+
type: "result";
|
|
49
|
+
id: number;
|
|
50
|
+
n: number;
|
|
51
|
+
buffers: Float64Array[];
|
|
52
|
+
} | {
|
|
53
|
+
type: "cancelled";
|
|
54
|
+
id: number;
|
|
55
|
+
} | {
|
|
56
|
+
type: "error";
|
|
57
|
+
id: number;
|
|
58
|
+
error: ErrorInfo;
|
|
59
|
+
} | {
|
|
60
|
+
type: "values";
|
|
61
|
+
sid: number;
|
|
62
|
+
index: number;
|
|
63
|
+
values: Float64Array;
|
|
64
|
+
}
|
|
65
|
+
/** A feed bar that changed nothing the chart's last bar sees: nothing was recomputed. */
|
|
66
|
+
| {
|
|
67
|
+
type: "idle";
|
|
68
|
+
sid: number;
|
|
69
|
+
} | {
|
|
70
|
+
type: "tick-error";
|
|
71
|
+
sid: number;
|
|
72
|
+
error: ErrorInfo;
|
|
73
|
+
};
|
|
74
|
+
export declare function errorInfo(e: unknown): ErrorInfo;
|
|
75
|
+
/** A script's definition with one trailing node (the bridge the main thread listens on). */
|
|
76
|
+
export declare function withBridge(def: StudyDef, body?: (i: number) => void, mirror?: boolean): StudyDef;
|
|
77
|
+
/** Worker-side handler. `post` sends to the main thread. */
|
|
78
|
+
export declare function serveScripts(post: (m: FromWorker, transfer?: Transferable[]) => void): (data: unknown) => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Chart, Series } from "@alphacharts/core";
|
|
2
|
+
import type { Diagnostic } from "./diag.js";
|
|
3
|
+
import { type RunScriptOptions } from "./run.js";
|
|
4
|
+
/** Structural copy of `@alphacharts/ui`'s `ScriptRunAdapter` (the definition); apps/playground/src/adapter-contract.ts fails to compile if they drift apart. */
|
|
5
|
+
export interface ScriptRunAdapter {
|
|
6
|
+
run(target: {
|
|
7
|
+
chart: Chart;
|
|
8
|
+
source: Series<"candles">;
|
|
9
|
+
volume: Series<"histogram"> | null;
|
|
10
|
+
}, code: string, onRuntimeError: (d: Diagnostic) => void): {
|
|
11
|
+
diagnostics: readonly Diagnostic[];
|
|
12
|
+
remove(): void;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Each run gets its own sandboxed worker (disposed with it), the script's
|
|
17
|
+
* default inputs, and the volume series when the chart has one.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createScriptRunAdapter(opts: Omit<RunScriptOptions, "volume" | "onError" | "runner" | "workerFactory"> & {
|
|
20
|
+
workerFactory: NonNullable<RunScriptOptions["workerFactory"]>;
|
|
21
|
+
}): ScriptRunAdapter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alphacharts/script",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A small Pine-like indicator language for alphacharts: compiler, sandboxed Web Worker runner and a CodeMirror 6 editor adapter.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"chart",
|
|
7
|
+
"indicators",
|
|
8
|
+
"pine",
|
|
9
|
+
"scripting",
|
|
10
|
+
"trading",
|
|
11
|
+
"codemirror"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Alphabench",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/alphabench/alphacharts.git",
|
|
18
|
+
"directory": "packages/script"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/alphabench/alphacharts#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/alphabench/alphacharts/issues"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": [
|
|
26
|
+
"./dist/sandbox-worker.js",
|
|
27
|
+
"./src/sandbox-worker.ts"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"module": "./dist/index.js",
|
|
34
|
+
"types": "./dist/types/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/types/index.d.ts",
|
|
38
|
+
"default": "./dist/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./editor": {
|
|
41
|
+
"types": "./dist/types/editor/index.d.ts",
|
|
42
|
+
"default": "./dist/editor.js"
|
|
43
|
+
},
|
|
44
|
+
"./worker": {
|
|
45
|
+
"types": "./dist/types/sandbox-worker.d.ts",
|
|
46
|
+
"default": "./dist/sandbox-worker.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist"
|
|
51
|
+
],
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@codemirror/autocomplete": "6.20.3",
|
|
54
|
+
"@codemirror/commands": "6.11.1",
|
|
55
|
+
"@codemirror/language": "6.12.4",
|
|
56
|
+
"@codemirror/lint": "6.9.7",
|
|
57
|
+
"@codemirror/state": "6.7.6",
|
|
58
|
+
"@codemirror/view": "6.43.13",
|
|
59
|
+
"@lezer/highlight": "1.2.5"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@alphacharts/core": "^0.1.1",
|
|
63
|
+
"@alphacharts/indicators": "^0.1.1"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"typescript": "5.9.3",
|
|
67
|
+
"vite": "8.3.1",
|
|
68
|
+
"vitest": "5.0.2",
|
|
69
|
+
"@alphacharts/indicators": "0.1.1",
|
|
70
|
+
"@alphacharts/core": "0.1.1"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
74
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
75
|
+
"typecheck:dist": "tsc -p tsconfig.dist.json",
|
|
76
|
+
"test": "vitest run"
|
|
77
|
+
}
|
|
6
78
|
}
|