@invinite-org/chartlang-core 1.1.1 → 1.3.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/CHANGELOG.md +282 -0
- package/README.md +2 -1
- package/dist/draw/buckets.d.ts.map +1 -1
- package/dist/draw/buckets.js +1 -0
- package/dist/draw/buckets.js.map +1 -1
- package/dist/draw/draw.d.ts +8 -1
- package/dist/draw/draw.d.ts.map +1 -1
- package/dist/draw/draw.js.map +1 -1
- package/dist/draw/drawingKind.d.ts +8 -8
- package/dist/draw/drawingKind.d.ts.map +1 -1
- package/dist/draw/drawingKind.js +5 -3
- package/dist/draw/drawingKind.js.map +1 -1
- package/dist/draw/drawingState.d.ts +27 -3
- package/dist/draw/drawingState.d.ts.map +1 -1
- package/dist/draw/drawingState.js.map +1 -1
- package/dist/draw/drawingStyle.d.ts +52 -9
- package/dist/draw/drawingStyle.d.ts.map +1 -1
- package/dist/draw/drawingStyle.js.map +1 -1
- package/dist/draw/index.d.ts +2 -2
- package/dist/draw/index.d.ts.map +1 -1
- package/dist/draw/index.js.map +1 -1
- package/dist/index.d.ts +11 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/input/index.d.ts +1 -1
- package/dist/input/index.d.ts.map +1 -1
- package/dist/input/index.js.map +1 -1
- package/dist/input/input.d.ts +15 -1
- package/dist/input/input.d.ts.map +1 -1
- package/dist/input/input.js +14 -0
- package/dist/input/input.js.map +1 -1
- package/dist/input/inputDescriptor.d.ts +15 -2
- package/dist/input/inputDescriptor.d.ts.map +1 -1
- package/dist/input/inputDescriptor.js.map +1 -1
- package/dist/plot/plot.d.ts +75 -0
- package/dist/plot/plot.d.ts.map +1 -1
- package/dist/plot/plot.js +34 -0
- package/dist/plot/plot.js.map +1 -1
- package/dist/request/feedKey.d.ts +20 -0
- package/dist/request/feedKey.d.ts.map +1 -0
- package/dist/request/feedKey.js +29 -0
- package/dist/request/feedKey.js.map +1 -0
- package/dist/request/index.d.ts +3 -1
- package/dist/request/index.d.ts.map +1 -1
- package/dist/request/index.js +1 -0
- package/dist/request/index.js.map +1 -1
- package/dist/request/request.d.ts +107 -20
- package/dist/request/request.d.ts.map +1 -1
- package/dist/request/request.js +27 -26
- package/dist/request/request.js.map +1 -1
- package/dist/state/arraySlot.d.ts +38 -0
- package/dist/state/arraySlot.d.ts.map +1 -0
- package/dist/state/arraySlot.js +4 -0
- package/dist/state/arraySlot.js.map +1 -0
- package/dist/state/index.d.ts +1 -0
- package/dist/state/index.d.ts.map +1 -1
- package/dist/state/index.js.map +1 -1
- package/dist/state/state.d.ts +36 -0
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.js +38 -0
- package/dist/state/state.js.map +1 -1
- package/dist/statefulPrimitives.d.ts +9 -5
- package/dist/statefulPrimitives.d.ts.map +1 -1
- package/dist/statefulPrimitives.js +37 -5
- package/dist/statefulPrimitives.js.map +1 -1
- package/dist/ta/ta.d.ts +39 -8
- package/dist/ta/ta.d.ts.map +1 -1
- package/dist/ta/ta.js +6 -0
- package/dist/ta/ta.js.map +1 -1
- package/dist/time-accessors/index.d.ts +5 -0
- package/dist/time-accessors/index.d.ts.map +1 -0
- package/dist/time-accessors/index.js +5 -0
- package/dist/time-accessors/index.js.map +1 -0
- package/dist/time-accessors/sessionAccessors.d.ts +43 -0
- package/dist/time-accessors/sessionAccessors.d.ts.map +1 -0
- package/dist/time-accessors/sessionAccessors.js +38 -0
- package/dist/time-accessors/sessionAccessors.js.map +1 -0
- package/dist/time-accessors/timeAccessors.d.ts +132 -0
- package/dist/time-accessors/timeAccessors.d.ts.map +1 -0
- package/dist/time-accessors/timeAccessors.js +143 -0
- package/dist/time-accessors/timeAccessors.js.map +1 -0
- package/dist/types.d.ts +219 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAmsB/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAClC,CAA8C,EACrB,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type { DependencyDeclaration, OutputDeclaration } from \"./define/dependency.js\";\nimport type { ScaleAxis, ValueFormat } from \"./define/overrides.js\";\nimport type { DrawNamespace } from \"./draw/draw.js\";\nimport type { InputDescriptor } from \"./input/inputDescriptor.js\";\nimport type { PlotKind } from \"./plot/plot.js\";\nimport type { RequestNamespace } from \"./request/index.js\";\nimport type { RuntimeNamespace } from \"./runtime/index.js\";\nimport type { StateNamespace } from \"./state/state.js\";\nimport type { TaNamespace } from \"./ta/ta.js\";\nimport type { BarStateView, SymInfoView, TimeframeView } from \"./views/index.js\";\n\n/**\n * UTC milliseconds since epoch — the only time representation the runtime\n * speaks. Display-side timezones are the adapter's responsibility.\n *\n * @since 0.1\n * @example\n * const t: Time = 1_700_000_000_000;\n */\nexport type Time = number;\n\n/**\n * A price quote in the symbol's quote currency, finite or NaN. NaN marks an\n * unwarmed series slot.\n *\n * @since 0.1\n * @example\n * const last: Price = 42.31;\n */\nexport type Price = number;\n\n/**\n * Traded volume for the bar, in the symbol's native unit (shares, contracts,\n * coins, …).\n *\n * @since 0.1\n * @example\n * const v: Volume = 1_250_000;\n */\nexport type Volume = number;\n\n/**\n * Visible chart range in UTC milliseconds. Phase 5's OSS runtime\n * supplies a fallback range spanning the latest 100 bars ending at the\n * current head; adapters with a real viewport can replace this view in\n * later phases.\n *\n * @since 0.5\n * @stable\n * @example\n * const viewport: BarViewport = {\n * fromTime: 1_700_000_000_000,\n * toTime: 1_700_006_000_000,\n * };\n */\nexport type BarViewport = Readonly<{\n readonly fromTime: Time;\n readonly toTime: Time;\n}>;\n\n/**\n * The OHLCV record the runtime hands to `compute` for the current bar. Every\n * field is `readonly`; scripts must not mutate it.\n *\n * Phase 2 surfaces the four pre-computed derived sources (`hl2` / `hlc3` /\n * `ohlc4` / `hlcc4`) the runtime's `BarView`\n * (`packages/runtime/src/streamState.ts`) already populates on every close.\n * Script authors can write `ta.cci(bar.hlc3, 20)` directly — matching Pine's\n * canonical `bar.hlc3` / `bar.ohlc4` access pattern — without re-computing\n * the derived source per lookup.\n *\n * @since 0.1\n * @example\n * function tick(bar: Bar): void {\n * console.log(bar.close, bar.symbol, bar.interval);\n * // Phase 2 — Pine-style derived sources:\n * console.log(bar.hl2, bar.hlc3, bar.ohlc4, bar.hlcc4);\n * // Phase 5 — visible-range fallback:\n * console.log(bar.viewport.fromTime, bar.viewport.toTime);\n * }\n */\nexport type Bar = {\n readonly time: Time;\n readonly open: Price;\n readonly high: Price;\n readonly low: Price;\n readonly close: Price;\n readonly volume: Volume;\n readonly symbol: string;\n readonly interval: string;\n /** `(high + low) / 2`. @since 0.2 */\n readonly hl2: Price;\n /** `(high + low + close) / 3`. @since 0.2 */\n readonly hlc3: Price;\n /** `(open + high + low + close) / 4`. @since 0.2 */\n readonly ohlc4: Price;\n /** `(high + low + close + close) / 4` (Pine's `hlcc4`). @since 0.2 */\n readonly hlcc4: Price;\n /** Visible-range fallback used by viewport-aware primitives. @since 0.5 */\n readonly viewport?: BarViewport;\n};\n\n/**\n * Read-only view over a ring-buffered history of values. `current` is bar 0,\n * numeric indices look back N bars. The runtime owns the storage; scripts see\n * only this shape.\n *\n * @since 0.1\n * @example\n * function delta(close: Series<number>): number {\n * return close.current - close[1];\n * }\n */\nexport type Series<T> = {\n readonly current: T;\n readonly [n: number]: T;\n readonly length: number;\n};\n\n/**\n * CSS color string — `\"#rrggbb\"`, `\"rgb(...)\"`, `\"hsl(...)\"`, etc. Adapters\n * round-trip the string verbatim.\n *\n * @since 0.1\n * @example\n * const blue: Color = \"#3b82f6\";\n */\nexport type Color = string;\n\n/**\n * Stroke style for `plot` and `hline` lines. Adapters that cannot render a\n * style fall back to `\"solid\"` and emit `\"line-style-unsupported\"`.\n *\n * @since 0.1\n * @example\n * const ls: LineStyle = \"dashed\";\n */\nexport type LineStyle = \"solid\" | \"dashed\" | \"dotted\";\n\n/**\n * The rendered shape an adapter requests for a `plot` emission. Maps to\n * `Capabilities.plotKinds`.\n *\n * @since 0.1\n * @example\n * const k: PlotLineStyle = \"step\";\n */\nexport type PlotLineStyle = \"line\" | \"step\" | \"dashed\" | \"circles\" | \"cross\";\n\n/**\n * Alert severity used by `alert(...)` and downstream alert channels. Defaults\n * to `\"info\"` when callers omit `opts.severity`.\n *\n * @since 0.1\n * @example\n * const sev: AlertSeverity = \"warning\";\n */\nexport type AlertSeverity = \"info\" | \"warning\" | \"critical\";\n\n/**\n * Adapter-declared timeframe entry surfaced in the script-settings UI. The\n * optional `intervalSeconds` override lets exotic intervals declare their\n * effective duration without extending the standard parser grammar.\n *\n * @since 0.1\n * @example\n * const d: IntervalDescriptor = {\n * value: \"1D\",\n * label: \"1 day\",\n * group: \"Days\",\n * };\n */\nexport type IntervalDescriptor = {\n readonly value: string;\n readonly label: string;\n readonly group: string;\n /**\n * Optional positive finite second-count override used by interval\n * ordering helpers before parsing `value`.\n *\n * @since 0.6\n * @stable\n */\n readonly intervalSeconds?: number;\n};\n\n/**\n * Script-author-declared input schema attached to `defineIndicator` /\n * `defineAlert` / `defineDrawing`. Each key carries an `InputDescriptor<T>`\n * returned by an `input.*` builder. The compiler serialises this schema into\n * `manifest.inputs`; the runtime resolves user overrides against defaults.\n *\n * @since 0.1 — widened in 0.4 from opaque `Readonly<Record<string, unknown>>`\n * to the typed `InputDescriptor<unknown>` shape returned by `input.*`\n * builders. Existing scripts stay source-compatible because the previous\n * opaque record subsumes the new typed shape.\n * @example\n * import { input } from \"@invinite-org/chartlang-core\";\n * const inputs: InputSchema = { length: input.int(20) };\n * void inputs;\n */\nexport type InputSchema = Readonly<Record<string, InputDescriptor<unknown>>>;\n\n/**\n * Discriminator for the Phase-1 adapter capability subset the script-side\n * surface references. The full `Capabilities` type lives in\n * `@invinite-org/chartlang-adapter-kit` (Task 4); only the id strings appear\n * here.\n *\n * @since 0.1\n * @example\n * const caps: ReadonlyArray<CapabilityId> = [\"indicators\", \"alerts\"];\n */\nexport type CapabilityId = \"indicators\" | \"drawings\" | \"alerts\" | \"alertConditions\";\n\n/**\n * Per-script drawing-emission budget. Excess `draw.*` calls drop with\n * `drawing-budget-exceeded` once a bucket is full. Mirrors Pine's\n * `max_*_count` family. The runtime enforces\n * `min(scriptManifest.maxDrawings, adapter.capabilities.maxDrawingsPerScript)`\n * per bucket.\n *\n * Canonical declaration lives here in core so both\n * `ScriptManifest.maxDrawings?` and the adapter-kit re-export pin the\n * same shape — preserving the adapter-kit → core dependency direction.\n *\n * @since 0.3\n * @stable\n * @example\n * const c: DrawingCounts = {\n * lines: 50, labels: 50, boxes: 50, polylines: 50, other: 50,\n * };\n * void c;\n */\nexport type DrawingCounts = {\n readonly lines: number;\n readonly labels: number;\n readonly boxes: number;\n readonly polylines: number;\n readonly other: number;\n};\n\n/**\n * One plotted-slot descriptor in `ScriptManifest.plots`. The compiler\n * emits one entry per `plot()` / `plot.*()` / `hline()` callsite so an\n * embedder can build a style/visibility UI keyed by the stable `slotId`\n * before the first emission. `title` is present only when the call's\n * opts carries a string-literal `title`.\n *\n * @since 0.8\n * @stable\n * @example\n * const slot: PlotSlotDescriptor = {\n * slotId: \"ema.ts:12:5#0\",\n * kind: \"line\",\n * title: \"EMA\",\n * };\n * void slot;\n */\nexport type PlotSlotDescriptor = {\n readonly slotId: string;\n readonly kind: PlotKind;\n readonly title?: string;\n};\n\n/**\n * Host-supplied presentation override for a single plot slot, keyed by\n * `PlotEmission.slotId`. Applied by the runtime at emit time; never\n * affects `compute`. `lineWidth` / `lineStyle` apply only to the\n * line-family plot kinds (`line`, `step-line`, `horizontal-line`,\n * `area`); ignored as a silent no-op on other kinds.\n *\n * @since 0.8\n * @stable\n * @example\n * const override: PlotOverride = {\n * visible: false,\n * color: \"#ff0000\",\n * lineWidth: 2,\n * lineStyle: \"dashed\",\n * };\n * void override;\n */\nexport type PlotOverride = {\n readonly visible?: boolean;\n readonly color?: string;\n readonly lineWidth?: number;\n readonly lineStyle?: LineStyle;\n};\n\n/**\n * The metadata sidecar the compiler emits next to a compiled script. The\n * runtime reads this to size ring buffers, gate against adapter capabilities,\n * and pick secondary candle streams.\n *\n * @since 0.1\n * @example\n * const m: ScriptManifest = {\n * apiVersion: 1,\n * kind: \"indicator\",\n * name: \"demo\",\n * inputs: {},\n * capabilities: [\"indicators\"],\n * requestedIntervals: [],\n * userPickableInterval: false,\n * seriesCapacities: {},\n * maxLookback: 0,\n * shortName: \"demo\",\n * format: \"compact\",\n * };\n */\nexport type ScriptManifest = {\n readonly apiVersion: 1;\n readonly kind: \"indicator\" | \"drawing\" | \"alert\" | \"alertCondition\";\n readonly name: string;\n readonly inputs: InputSchema;\n readonly capabilities: ReadonlyArray<CapabilityId>;\n readonly requestedIntervals: ReadonlyArray<string>;\n readonly userPickableInterval: boolean;\n readonly seriesCapacities: Readonly<Record<string, number>>;\n readonly maxLookback: number;\n /**\n * `overlay: false` on `defineIndicator(...)` is persisted here as the\n * script-level default pane signal. Absent / `true` means the script\n * defaults to the price overlay pane; `false` means the runtime\n * routes every `plot()` / `hline()` call without an explicit `pane`\n * opt into a per-script subpane key.\n *\n * @since 0.2\n * @stable\n * @example\n * const m: Pick<ScriptManifest, \"overlay\"> = { overlay: false };\n * void m;\n */\n readonly overlay?: boolean;\n /**\n * Per-bucket cap on `draw.*` emissions the script intends to\n * produce per bar. The runtime enforces\n * `min(this, adapter.capabilities.maxDrawingsPerScript)` per\n * bucket. Omit to default to the adapter's cap.\n *\n * @since 0.3\n */\n readonly maxDrawings?: DrawingCounts;\n /**\n * Max bars of historical lookback the script declares it needs.\n *\n * @since 0.4\n * @example\n * const v: ScriptManifest[\"maxBarsBack\"] = 100;\n * void v;\n */\n readonly maxBarsBack?: number;\n /**\n * Value-formatting hint for axis labels + cursor read-out.\n *\n * @since 0.4\n * @example\n * const v: ScriptManifest[\"format\"] = \"price\";\n * void v;\n */\n readonly format?: ValueFormat;\n /**\n * Decimal precision the adapter renders the script at.\n *\n * @since 0.4\n * @example\n * const v: ScriptManifest[\"precision\"] = 2;\n * void v;\n */\n readonly precision?: number;\n /**\n * Scale-axis binding requested by the script.\n *\n * @since 0.4\n * @example\n * const v: ScriptManifest[\"scale\"] = \"right\";\n * void v;\n */\n readonly scale?: ScaleAxis;\n /**\n * Compact display label for legend chips.\n *\n * @since 0.4\n * @example\n * const v: ScriptManifest[\"shortName\"] = \"EMA\";\n * void v;\n */\n readonly shortName?: string;\n /**\n * Static set of intervals the script requires the target adapter to ship\n * in `Capabilities.intervals`. The compiler unions this with the static\n * set extracted from `request.security` calls in Task 8. `input.interval`\n * is user-pickable and does not contribute to this author-declared hard\n * requirement set.\n *\n * @since 0.4\n * @example\n * const v: ScriptManifest[\"requiresIntervals\"] = [\"1D\"];\n * void v;\n */\n readonly requiresIntervals?: ReadonlyArray<string>;\n /**\n * Static list of user-wireable alert conditions declared by\n * `defineAlertCondition({ conditions })`.\n *\n * @since 0.5\n * @stable\n * @example\n * const defs: ScriptManifest[\"alertConditions\"] = [\n * { id: \"up\", title: \"Up\", description: \"Close > EMA\", defaultMessage: \"{{ticker}} up\" },\n * ];\n * void defs;\n */\n readonly alertConditions?: ReadonlyArray<AlertConditionDefinition>;\n /**\n * Statically-resolved dependency graph nodes consumed by this\n * script. Empty / omitted for scripts with no\n * `<binding>.output(...)` calls. Each entry is one consumer-side\n * `const` binding pointing at another `defineIndicator(...)`\n * result.\n *\n * @since 0.7\n * @stable\n * @example\n * const v: ScriptManifest[\"dependencies\"] = [];\n * void v;\n */\n readonly dependencies?: ReadonlyArray<DependencyDeclaration>;\n /**\n * Titled outputs this script exposes for consumption by other\n * indicators. Derived from `plot(value, { title })` calls in\n * this script's compute body. Empty / omitted when the script\n * has no titled plots.\n *\n * @since 0.7\n * @stable\n * @example\n * const v: ScriptManifest[\"outputs\"] = [\n * { title: \"line\", kind: \"series-number\" },\n * ];\n * void v;\n */\n readonly outputs?: ReadonlyArray<OutputDeclaration>;\n /**\n * Static plot-slot descriptors — one per `plot()` / `hline()` callsite,\n * in callsite order. Lets an embedder enumerate plottable slots (and\n * key per-slot style/visibility overrides) without waiting for the\n * first emission. Absent on scripts that issue no plot/hline calls.\n *\n * @since 0.8\n * @stable\n * @example\n * const v: ScriptManifest[\"plots\"] = [\n * { slotId: \"ema.ts:12:5#0\", kind: \"line\", title: \"EMA\" },\n * ];\n * void v;\n */\n readonly plots?: ReadonlyArray<PlotSlotDescriptor>;\n /**\n * The ES-module binding name this manifest was reached through.\n * `\"default\"` for `export default defineIndicator(...)`; the\n * named-binding identifier otherwise. Always present when the\n * source file has more than one drawn indicator; omitted on\n * single-script files for back-compat.\n *\n * @since 0.7\n * @stable\n * @example\n * const v: ScriptManifest[\"exportName\"] = \"default\";\n * void v;\n */\n readonly exportName?: string;\n /**\n * Other drawn manifests in the same compiled file. Present\n * only when this manifest is the file's default export and the\n * file has additional named-exported drawn indicators. Omitted\n * for single-script files and for non-default-export entries\n * in the array-form manifest sidecar.\n *\n * @since 0.7\n * @stable\n * @example\n * const v: ScriptManifest[\"siblings\"] = [];\n * void v;\n */\n readonly siblings?: ReadonlyArray<ScriptManifest>;\n /**\n * `true` when this manifest belongs to a drawn (exported)\n * indicator — the host should mount it. `false` when this\n * manifest belongs to a private dep — emissions are dropped.\n * Defaults to `true` for back-compat.\n *\n * @since 0.7\n * @stable\n * @example\n * const v: ScriptManifest[\"isDrawn\"] = true;\n * void v;\n */\n readonly isDrawn?: boolean;\n};\n\n/**\n * Per-condition descriptor authored under\n * `DefineAlertConditionOpts.conditions`.\n *\n * @since 0.5\n * @stable\n * @example\n * const d: AlertConditionDescriptor = {\n * title: \"Up\",\n * description: \"Close crossed up\",\n * defaultMessage: \"{{ticker}} crossed up\",\n * };\n * void d;\n */\nexport type AlertConditionDescriptor = Readonly<{\n title: string;\n description: string;\n defaultMessage: string;\n}>;\n\n/**\n * Manifest-ready alert-condition descriptor with the author map key\n * normalised into `id`.\n *\n * @since 0.5\n * @stable\n * @example\n * const d: AlertConditionDefinition = {\n * id: \"up\",\n * title: \"Up\",\n * description: \"Close crossed up\",\n * defaultMessage: \"{{ticker}} crossed up\",\n * };\n * void d;\n */\nexport type AlertConditionDefinition = AlertConditionDescriptor &\n Readonly<{\n id: string;\n }>;\n\n/**\n * The argument the runtime hands a script's `compute` function each bar. The\n * `ta` / `plot` / `hline` / `alert` slots are the runtime's implementations,\n * not the compile-time callable holes from `@invinite-org/chartlang-core`.\n *\n * @since 0.1\n * @example\n * const fn: ComputeFn = ({ bar, plot }) => { plot(bar.close); };\n */\nexport type ComputeContext = {\n readonly bar: Bar;\n readonly inputs: Readonly<Record<string, unknown>>;\n readonly ta: TaNamespace;\n readonly plot: typeof import(\"./plot/plot.js\").plot;\n readonly hline: typeof import(\"./plot/plot.js\").hline;\n readonly alert: typeof import(\"./alert/alert.js\").alert;\n /** Pine `var` / `varip` state slots. @since 0.4 */\n readonly state: StateNamespace;\n /** Bar-state view derived for the active step. @since 0.4 */\n readonly barstate: BarStateView;\n /** Symbol metadata view for the active script mount. @since 0.4 */\n readonly syminfo: SymInfoView;\n /** Timeframe helper view derived for the active step. @since 0.4 */\n readonly timeframe: TimeframeView;\n /** Secondary timeframe request namespace. @since 0.4 */\n readonly request: RequestNamespace;\n /** Runtime logging and fatal halt namespace. @since 0.5 */\n readonly runtime: RuntimeNamespace;\n /**\n * Signal a named condition declared by `defineAlertCondition`. Present\n * only for scripts whose manifest kind is `\"alertCondition\"`.\n *\n * @since 0.5\n * @stable\n * @example\n * const fn: NonNullable<ComputeContext[\"signal\"]> = (id, fired) => {\n * void id;\n * void fired;\n * };\n * void fn;\n */\n readonly signal?: (conditionId: string, fired: boolean) => void;\n /**\n * Imperative drawing namespace. Each method returns a\n * {@link DrawingHandle} the script can `update(...)` or\n * `remove()` within the same `compute` run, and across bars.\n * The Phase-3 runtime impl lives in\n * `@invinite-org/chartlang-runtime/emit/draw`. @since 0.3\n */\n readonly draw: DrawNamespace;\n};\n\n/**\n * The per-bar compute function a script exports via `defineIndicator` /\n * `defineAlert`. Pure with respect to its arguments — no `this`, no closures\n * over host state.\n *\n * @since 0.1\n * @example\n * const fn: ComputeFn = (ctx) => { ctx.plot(ctx.bar.close); };\n */\nexport type ComputeFn = (ctx: ComputeContext) => void;\n\n/**\n * The frozen object the `defineIndicator` / `defineAlert` constructors return.\n * The compiler rewrites `manifest` fields at build time; the runtime invokes\n * `compute` per bar.\n *\n * The `output` / `withInputs` accessors (Phase 7) are compiler-rewritten\n * sentinels — the indicator-composition compiler pass statically replaces\n * every consumer-side call site before bundling, so the runtime never\n * executes the throwing bodies. Direct invocation from an un-compiled\n * script (e.g. a unit test that imports the module directly) hits the\n * sentinel and throws, which is the desired failure.\n *\n * @since 0.1\n * @example\n * const cs: CompiledScriptObject = defineIndicator({\n * name: \"demo\",\n * apiVersion: 1,\n * compute: () => {},\n * });\n */\nexport type CompiledScriptObject = {\n readonly manifest: ScriptManifest;\n readonly compute: ComputeFn;\n /**\n * Read the named output of this indicator inside another\n * indicator's compute body. Output names come from the\n * producer's `plot(value, { title })` calls. The compiler\n * rewrites every consumer-side call site before bundling;\n * direct invocation throws the dep-accessor sentinel.\n *\n * @since 0.7\n * @stable\n * @example\n * declare const baseTrend: CompiledScriptObject;\n * const line: Series<number> = baseTrend.output(\"line\");\n * void line;\n */\n readonly output: (name: string) => Series<number>;\n /**\n * Return a new `CompiledScriptObject` whose dependency-binding\n * effective inputs are the merge of the producer's defaults with\n * the supplied overrides. Static — the compiler folds the\n * override into the inlined dep manifest at bundle time.\n *\n * @since 0.7\n * @stable\n * @example\n * declare const baseTrend: CompiledScriptObject;\n * const trend = baseTrend.withInputs({ length: 50 });\n * void trend;\n */\n readonly withInputs: (overrides: Readonly<Record<string, unknown>>) => CompiledScriptObject;\n};\n\n/**\n * The compiled artefact for a `.chart.ts` file when it contains\n * multiple drawn indicators or any dependency graph. The Phase-7\n * runtime accepts either this shape or the legacy\n * `CompiledScriptObject` (single-script files).\n *\n * `primary` is the default-exported drawn script. `siblings` are\n * every other drawn export (named consts). `dependencies` is every\n * private-dep compiled object — keyed by `localId` so the runtime\n * can look them up by the `DependencyDeclaration.localId` it sees\n * on each consumer's manifest.\n *\n * @since 0.7\n * @stable\n * @example\n * declare const primary: CompiledScriptObject;\n * const bundle: CompiledScriptBundle = {\n * primary,\n * siblings: [],\n * dependencies: [],\n * };\n * void bundle;\n */\nexport type CompiledScriptBundle = Readonly<{\n readonly primary: CompiledScriptObject;\n readonly siblings: ReadonlyArray<{\n readonly exportName: string;\n readonly compiled: CompiledScriptObject;\n }>;\n readonly dependencies: ReadonlyArray<{\n readonly localId: string;\n readonly compiled: CompiledScriptObject;\n /**\n * Merged `.withInputs({...})` overrides the consumer applied\n * to its alias binding. Forwarded into the `DepRunner` as the\n * dep's input overrides so the producer's `compute` reads the\n * consumer-supplied values instead of the producer's manifest\n * defaults. Omitted for direct private deps that don't apply\n * overrides.\n *\n * @since 0.7\n */\n readonly inputOverrides?: Readonly<Record<string, unknown>>;\n }>;\n}>;\n\n/**\n * Narrowing helper that distinguishes the new\n * {@link CompiledScriptBundle} envelope from the legacy single-script\n * {@link CompiledScriptObject}. The runner uses it to pick the\n * multi-script execution path without re-parsing manifests.\n *\n * @since 0.7\n * @stable\n * @example\n * declare const v: CompiledScriptObject | CompiledScriptBundle;\n * if (isCompiledScriptBundle(v)) {\n * void v.primary;\n * } else {\n * void v.manifest;\n * }\n */\nexport const isCompiledScriptBundle = (\n v: CompiledScriptObject | CompiledScriptBundle,\n): v is CompiledScriptBundle => Object.prototype.hasOwnProperty.call(v, \"primary\");\n\n/**\n * JSON-compatible payload type for `alert(...).meta` and other places the\n * runtime serialises script-supplied data across worker / host boundaries.\n *\n * @since 0.1\n * @example\n * const meta: JsonValue = { reason: \"crossover\", strength: 0.42 };\n */\nexport type JsonValue =\n | null\n | boolean\n | number\n | string\n | ReadonlyArray<JsonValue>\n | { readonly [k: string]: JsonValue };\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAs6B/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAClC,CAA8C,EACrB,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC","sourcesContent":["// Copyright (c) 2026 Invinite. Licensed under the MIT License.\n// See the LICENSE file in the repo root for full license text.\n\nimport type { DependencyDeclaration, OutputDeclaration } from \"./define/dependency.js\";\nimport type { ScaleAxis, ValueFormat } from \"./define/overrides.js\";\nimport type { DrawNamespace } from \"./draw/draw.js\";\nimport type { WorldPoint } from \"./draw/worldPoint.js\";\nimport type { InputDescriptor } from \"./input/inputDescriptor.js\";\nimport type { PlotKind } from \"./plot/plot.js\";\nimport type { RequestNamespace } from \"./request/index.js\";\nimport type { RuntimeNamespace } from \"./runtime/index.js\";\nimport type { MutableSlot } from \"./state/mutableSlot.js\";\nimport type { StateNamespace } from \"./state/state.js\";\nimport type { TaNamespace } from \"./ta/ta.js\";\nimport type { SessionNamespace, TimeNamespace } from \"./time-accessors/index.js\";\nimport type { BarStateView, SymInfoView, TimeframeView } from \"./views/index.js\";\n\n/**\n * UTC milliseconds since epoch — the only time representation the runtime\n * speaks. Display-side timezones are the adapter's responsibility.\n *\n * @since 0.1\n * @example\n * const t: Time = 1_700_000_000_000;\n */\nexport type Time = number;\n\n/**\n * A price quote in the symbol's quote currency, finite or NaN. NaN marks an\n * unwarmed series slot.\n *\n * @since 0.1\n * @example\n * const last: Price = 42.31;\n */\nexport type Price = number;\n\n/**\n * Traded volume for the bar, in the symbol's native unit (shares, contracts,\n * coins, …).\n *\n * @since 0.1\n * @example\n * const v: Volume = 1_250_000;\n */\nexport type Volume = number;\n\n/**\n * Visible chart range in UTC milliseconds. Phase 5's OSS runtime\n * supplies a fallback range spanning the latest 100 bars ending at the\n * current head; adapters with a real viewport can replace this view in\n * later phases.\n *\n * @since 0.5\n * @stable\n * @example\n * const viewport: BarViewport = {\n * fromTime: 1_700_000_000_000,\n * toTime: 1_700_006_000_000,\n * };\n */\nexport type BarViewport = Readonly<{\n readonly fromTime: Time;\n readonly toTime: Time;\n}>;\n\n/**\n * The OHLCV record the runtime hands to `compute` for the current bar. Every\n * field is `readonly`; scripts must not mutate it.\n *\n * Phase 2 surfaces the four pre-computed derived sources (`hl2` / `hlc3` /\n * `ohlc4` / `hlcc4`) the runtime's `BarView`\n * (`packages/runtime/src/streamState.ts`) already populates on every close.\n * Script authors can write `ta.cci(bar.hlc3, 20)` directly — matching Pine's\n * canonical `bar.hlc3` / `bar.ohlc4` access pattern — without re-computing\n * the derived source per lookup.\n *\n * @since 0.1\n * @example\n * function tick(bar: Bar): void {\n * console.log(bar.close, bar.symbol, bar.interval);\n * // Phase 2 — Pine-style derived sources:\n * console.log(bar.hl2, bar.hlc3, bar.ohlc4, bar.hlcc4);\n * // Phase 5 — visible-range fallback:\n * console.log(bar.viewport.fromTime, bar.viewport.toTime);\n * }\n */\nexport type Bar = {\n readonly time: Time;\n readonly open: Price;\n readonly high: Price;\n readonly low: Price;\n readonly close: Price;\n readonly volume: Volume;\n readonly symbol: string;\n readonly interval: string;\n /** `(high + low) / 2`. @since 0.2 */\n readonly hl2: Price;\n /** `(high + low + close) / 3`. @since 0.2 */\n readonly hlc3: Price;\n /** `(open + high + low + close) / 4`. @since 0.2 */\n readonly ohlc4: Price;\n /** `(high + low + close + close) / 4` (Pine's `hlcc4`). @since 0.2 */\n readonly hlcc4: Price;\n /** Visible-range fallback used by viewport-aware primitives. @since 0.5 */\n readonly viewport?: BarViewport;\n /**\n * Anchor a {@link WorldPoint} by integer bar `offset` instead of an\n * absolute timestamp. The returned `{ time, price }` is the only frame\n * drawings persist (see {@link WorldPoint}), so it composes directly\n * with every `draw.*` anchor argument — `bar.point` is authoring sugar\n * that resolves the offset to a real / extrapolated time at compute\n * time; it introduces no new anchor shape.\n *\n * Offset semantics (relative to the current bar):\n * - `offset === 0` → the current bar: `{ time: bar.time, price }`.\n * - `offset < 0` → `|offset|` bars back; the time is the real\n * historical timestamp from the runtime's time ring buffer. When the\n * offset reaches past retained history the time is `NaN` (graceful\n * degradation, matching how a `Series` lookback past history reads\n * `NaN`) — it never throws.\n * - `offset > 0` → a future bar that does not exist yet; the time is\n * extrapolated as `lastTime + offset * spacing`, where `spacing` is\n * the median delta of the most recent retained bar times, falling\n * back to the parsed bar interval when fewer than two bars are\n * retained.\n *\n * `price` passes through unchanged (it may be `NaN`).\n *\n * @since 0.9\n * @stable\n * @formula time = offset === 0 ? bar.time\n * : offset < 0 ? history.time.at(-offset)\n * : lastTime + offset * spacing\n * @anchors offset (bar index), price, and the runtime time history\n * @example\n * function tick(bar: Bar): WorldPoint {\n * // Tracking line from 10 bars ago to the current close.\n * const from = bar.point(-10, bar.close);\n * const to = bar.point(0, bar.close);\n * void from;\n * return to;\n * }\n */\n point(offset: number, price: Price): WorldPoint;\n};\n\n/**\n * Read-only view over a ring-buffered history of values. `current` is bar 0,\n * numeric indices look back N bars. The runtime owns the storage; scripts see\n * only this shape.\n *\n * @since 0.1\n * @example\n * function delta(close: Series<number>): number {\n * return close.current - close[1];\n * }\n */\nexport type Series<T> = {\n readonly current: T;\n readonly [n: number]: T;\n readonly length: number;\n};\n\n/**\n * A bar price field that is **both** a scalar `Price` (so `bar.close * 2`,\n * comparisons, `Math.*`, `plot(bar.close)`, and `ta.*` source arguments all\n * work) **and** an indexable `Series<Price>` (so `bar.close[1]` reads the\n * close one bar ago, `bar.close.current` reads the current close, and\n * `bar.close.length` reads the filled depth). The runtime backs it with a\n * number-coercible ring-buffer view: arithmetic reads `bar.close[0]` (the\n * current value) while a literal index reads that many bars back.\n *\n * Because the value is an object, raw-number reflection differs from a plain\n * `number`: `Number.isFinite(bar.close)` is always `false` (it does not\n * coerce) and `bar.close === 42` is `false` (object vs number). Use\n * `bar.close.current` or `+bar.close` for those contexts.\n *\n * @since 1.3\n * @example\n * function delta(close: PriceSeries): number {\n * // current close minus the close one bar ago\n * return close - close[1];\n * }\n */\nexport type PriceSeries = Price & Series<Price>;\n\n/**\n * Volume counterpart of {@link PriceSeries}: a bar `volume` field usable both\n * as a scalar `Volume` and as an indexable `Series<Volume>` (`bar.volume[1]`).\n *\n * @since 1.3\n * @example\n * function avgVol(v: VolumeSeries): number {\n * return (v[0] + v[1] + v[2]) / 3;\n * }\n */\nexport type VolumeSeries = Volume & Series<Volume>;\n\n/**\n * A user-allocated, writable, indexable number series — the value half of\n * {@link state}'s `series` slot. It is **both** a writable scalar slot\n * (`s.value = x`, like `state.float`) **and** an indexable\n * `Series<number>` (`s[1]`, `s.current`, `+s`, like `bar.close`). Assign\n * the current bar's value with `s.value = …` each step; read history with\n * `s[n]` (n bars ago, `NaN` until filled). The runtime backs it with a\n * number-coercible ring-buffer view sized to the script's max lookback.\n *\n * `Number.isFinite(s)` / `s === x` see the **object**, not the number —\n * use `s.current` / `+s` / `s.value` for raw-number contexts.\n *\n * @since 1.3\n * @stable\n * @example\n * function lag(s: NumberSeriesSlot): number {\n * s.value = 42;\n * return s.current - s[1]; // current minus one bar ago\n * }\n */\nexport type NumberSeriesSlot = MutableSlot<number> & Series<number>;\n\n/**\n * The current bar as `compute` sees it. Identical to {@link Bar} except the\n * OHLCV + derived price/volume fields are {@link PriceSeries} /\n * {@link VolumeSeries} — both a scalar (`bar.close * 2`, `plot(bar.close)`,\n * `ta.ema(bar.close, 20)`) and an indexable series (`bar.close[1]` reads the\n * close one bar ago). `time` stays a scalar `Time`.\n *\n * This is distinct from {@link Bar} on purpose: {@link Bar} is the\n * adapter-supplied / `request.lowerTf` candle (scalar OHLCV, no per-field\n * history), while `BarSeries` is the streaming bar inside `compute` where the\n * runtime retains a ring buffer per field. `request.security`'s higher-\n * timeframe bar is the separate {@link SecurityBar}.\n *\n * @since 1.3\n * @example\n * function delta(bar: BarSeries): number {\n * return bar.close - bar.close[1];\n * }\n */\nexport type BarSeries = Omit<\n Bar,\n \"open\" | \"high\" | \"low\" | \"close\" | \"volume\" | \"hl2\" | \"hlc3\" | \"ohlc4\" | \"hlcc4\"\n> & {\n readonly open: PriceSeries;\n readonly high: PriceSeries;\n readonly low: PriceSeries;\n readonly close: PriceSeries;\n readonly volume: VolumeSeries;\n readonly hl2: PriceSeries;\n readonly hlc3: PriceSeries;\n readonly ohlc4: PriceSeries;\n readonly hlcc4: PriceSeries;\n};\n\n/**\n * CSS color string — `\"#rrggbb\"`, `\"rgb(...)\"`, `\"hsl(...)\"`, etc. Adapters\n * round-trip the string verbatim.\n *\n * @since 0.1\n * @example\n * const blue: Color = \"#3b82f6\";\n */\nexport type Color = string;\n\n/**\n * Stroke style for `plot` and `hline` lines. Adapters that cannot render a\n * style fall back to `\"solid\"` and emit `\"line-style-unsupported\"`.\n *\n * @since 0.1\n * @example\n * const ls: LineStyle = \"dashed\";\n */\nexport type LineStyle = \"solid\" | \"dashed\" | \"dotted\";\n\n/**\n * The rendered shape an adapter requests for a `plot` emission. Maps to\n * `Capabilities.plotKinds`.\n *\n * @since 0.1\n * @example\n * const k: PlotLineStyle = \"step\";\n */\nexport type PlotLineStyle = \"line\" | \"step\" | \"dashed\" | \"circles\" | \"cross\";\n\n/**\n * Alert severity used by `alert(...)` and downstream alert channels. Defaults\n * to `\"info\"` when callers omit `opts.severity`.\n *\n * @since 0.1\n * @example\n * const sev: AlertSeverity = \"warning\";\n */\nexport type AlertSeverity = \"info\" | \"warning\" | \"critical\";\n\n/**\n * Adapter-declared timeframe entry surfaced in the script-settings UI. The\n * optional `intervalSeconds` override lets exotic intervals declare their\n * effective duration without extending the standard parser grammar.\n *\n * @since 0.1\n * @example\n * const d: IntervalDescriptor = {\n * value: \"1D\",\n * label: \"1 day\",\n * group: \"Days\",\n * };\n */\nexport type IntervalDescriptor = {\n readonly value: string;\n readonly label: string;\n readonly group: string;\n /**\n * Optional positive finite second-count override used by interval\n * ordering helpers before parsing `value`.\n *\n * @since 0.6\n * @stable\n */\n readonly intervalSeconds?: number;\n};\n\n/**\n * Script-author-declared input schema attached to `defineIndicator` /\n * `defineAlert` / `defineDrawing`. Each key carries an `InputDescriptor<T>`\n * returned by an `input.*` builder. The compiler serialises this schema into\n * `manifest.inputs`; the runtime resolves user overrides against defaults.\n *\n * @since 0.1 — widened in 0.4 from opaque `Readonly<Record<string, unknown>>`\n * to the typed `InputDescriptor<unknown>` shape returned by `input.*`\n * builders. Existing scripts stay source-compatible because the previous\n * opaque record subsumes the new typed shape.\n * @example\n * import { input } from \"@invinite-org/chartlang-core\";\n * const inputs: InputSchema = { length: input.int(20) };\n * void inputs;\n */\nexport type InputSchema = Readonly<Record<string, InputDescriptor<unknown>>>;\n\n/**\n * Discriminator for the Phase-1 adapter capability subset the script-side\n * surface references. The full `Capabilities` type lives in\n * `@invinite-org/chartlang-adapter-kit` (Task 4); only the id strings appear\n * here.\n *\n * @since 0.1\n * @example\n * const caps: ReadonlyArray<CapabilityId> = [\"indicators\", \"alerts\"];\n */\nexport type CapabilityId = \"indicators\" | \"drawings\" | \"alerts\" | \"alertConditions\";\n\n/**\n * Per-script drawing-emission budget. Excess `draw.*` calls drop with\n * `drawing-budget-exceeded` once a bucket is full. Mirrors Pine's\n * `max_*_count` family. The runtime enforces\n * `min(scriptManifest.maxDrawings, adapter.capabilities.maxDrawingsPerScript)`\n * per bucket.\n *\n * Canonical declaration lives here in core so both\n * `ScriptManifest.maxDrawings?` and the adapter-kit re-export pin the\n * same shape — preserving the adapter-kit → core dependency direction.\n *\n * @since 0.3\n * @stable\n * @example\n * const c: DrawingCounts = {\n * lines: 50, labels: 50, boxes: 50, polylines: 50, other: 50,\n * };\n * void c;\n */\nexport type DrawingCounts = {\n readonly lines: number;\n readonly labels: number;\n readonly boxes: number;\n readonly polylines: number;\n readonly other: number;\n};\n\n/**\n * One plotted-slot descriptor in `ScriptManifest.plots`. The compiler\n * emits one entry per `plot()` / `plot.*()` / `hline()` callsite so an\n * embedder can build a style/visibility UI keyed by the stable `slotId`\n * before the first emission. `title` is present only when the call's\n * opts carries a string-literal `title`.\n *\n * @since 0.8\n * @stable\n * @example\n * const slot: PlotSlotDescriptor = {\n * slotId: \"ema.ts:12:5#0\",\n * kind: \"line\",\n * title: \"EMA\",\n * };\n * void slot;\n */\nexport type PlotSlotDescriptor = {\n readonly slotId: string;\n readonly kind: PlotKind;\n readonly title?: string;\n};\n\n/**\n * One higher-timeframe expression unit in `ScriptManifest.securityExpressions`.\n * The compiler emits one entry per `request.security({ interval }, (bar) => …)`\n * callsite so the runtime knows which `slotId` is an HTF expression, on which\n * `interval` to clock it, and the callback's single parameter name. The\n * callback body stays inline in the compiled module — this descriptor is only\n * the registry pointing at it.\n *\n * @since 0.7\n * @stable\n * @example\n * // symbol omitted ⇒ the chart's own symbol (the HTF-only back-compat case)\n * const unit: SecurityExpressionDescriptor = {\n * slotId: \"trend.ts:8:21#0\",\n * interval: \"1W\",\n * paramName: \"bar\",\n * };\n * void unit;\n */\nexport type SecurityExpressionDescriptor = {\n readonly slotId: string;\n /**\n * Requested symbol; omitted ⇒ the chart's own symbol.\n *\n * @since 1.3\n */\n readonly symbol?: string;\n readonly interval: string;\n readonly paramName: string;\n};\n\n/**\n * One requested secondary feed — a `(symbol, interval)` pair the script's\n * `request.security` calls ask for. `symbol` omitted ⇒ the chart's own\n * symbol (the higher-timeframe-only case). The compiler emits one entry per\n * **distinct** feed; the runtime creates one secondary `StreamState` per\n * entry, keyed by the shared `feedKey(symbol, interval)` composite.\n *\n * @since 1.3\n * @stable\n * @example\n * const f: RequestedFeed = { symbol: \"AMEX:SPY\", interval: \"1D\" };\n * void f;\n */\nexport type RequestedFeed = {\n readonly symbol?: string;\n readonly interval: string;\n};\n\n/**\n * Host-supplied presentation override for a single plot slot, keyed by\n * `PlotEmission.slotId`. Applied by the runtime at emit time; never\n * affects `compute`. `lineWidth` / `lineStyle` apply only to the\n * line-family plot kinds (`line`, `step-line`, `horizontal-line`,\n * `area`); ignored as a silent no-op on other kinds.\n *\n * @since 0.8\n * @stable\n * @example\n * const override: PlotOverride = {\n * visible: false,\n * color: \"#ff0000\",\n * lineWidth: 2,\n * lineStyle: \"dashed\",\n * };\n * void override;\n */\nexport type PlotOverride = {\n readonly visible?: boolean;\n readonly color?: string;\n readonly lineWidth?: number;\n readonly lineStyle?: LineStyle;\n};\n\n/**\n * The metadata sidecar the compiler emits next to a compiled script. The\n * runtime reads this to size ring buffers, gate against adapter capabilities,\n * and pick secondary candle streams.\n *\n * @since 0.1\n * @example\n * const m: ScriptManifest = {\n * apiVersion: 1,\n * kind: \"indicator\",\n * name: \"demo\",\n * inputs: {},\n * capabilities: [\"indicators\"],\n * requestedIntervals: [],\n * userPickableInterval: false,\n * seriesCapacities: {},\n * maxLookback: 0,\n * shortName: \"demo\",\n * format: \"compact\",\n * };\n */\nexport type ScriptManifest = {\n readonly apiVersion: 1;\n readonly kind: \"indicator\" | \"drawing\" | \"alert\" | \"alertCondition\";\n readonly name: string;\n readonly inputs: InputSchema;\n readonly capabilities: ReadonlyArray<CapabilityId>;\n readonly requestedIntervals: ReadonlyArray<string>;\n readonly userPickableInterval: boolean;\n readonly seriesCapacities: Readonly<Record<string, number>>;\n readonly maxLookback: number;\n /**\n * `overlay: false` on `defineIndicator(...)` is persisted here as the\n * script-level default pane signal. Absent / `true` means the script\n * defaults to the price overlay pane; `false` means the runtime\n * routes every `plot()` / `hline()` call without an explicit `pane`\n * opt into a per-script subpane key.\n *\n * @since 0.2\n * @stable\n * @example\n * const m: Pick<ScriptManifest, \"overlay\"> = { overlay: false };\n * void m;\n */\n readonly overlay?: boolean;\n /**\n * Per-bucket cap on `draw.*` emissions the script intends to\n * produce per bar. The runtime enforces\n * `min(this, adapter.capabilities.maxDrawingsPerScript)` per\n * bucket. Omit to default to the adapter's cap.\n *\n * @since 0.3\n */\n readonly maxDrawings?: DrawingCounts;\n /**\n * Max bars of historical lookback the script declares it needs.\n *\n * @since 0.4\n * @example\n * const v: ScriptManifest[\"maxBarsBack\"] = 100;\n * void v;\n */\n readonly maxBarsBack?: number;\n /**\n * Value-formatting hint for axis labels + cursor read-out.\n *\n * @since 0.4\n * @example\n * const v: ScriptManifest[\"format\"] = \"price\";\n * void v;\n */\n readonly format?: ValueFormat;\n /**\n * Decimal precision the adapter renders the script at.\n *\n * @since 0.4\n * @example\n * const v: ScriptManifest[\"precision\"] = 2;\n * void v;\n */\n readonly precision?: number;\n /**\n * Scale-axis binding requested by the script.\n *\n * @since 0.4\n * @example\n * const v: ScriptManifest[\"scale\"] = \"right\";\n * void v;\n */\n readonly scale?: ScaleAxis;\n /**\n * Compact display label for legend chips.\n *\n * @since 0.4\n * @example\n * const v: ScriptManifest[\"shortName\"] = \"EMA\";\n * void v;\n */\n readonly shortName?: string;\n /**\n * Static set of intervals the script requires the target adapter to ship\n * in `Capabilities.intervals`. The compiler unions this with the static\n * set extracted from `request.security` calls in Task 8. `input.interval`\n * is user-pickable and does not contribute to this author-declared hard\n * requirement set.\n *\n * @since 0.4\n * @example\n * const v: ScriptManifest[\"requiresIntervals\"] = [\"1D\"];\n * void v;\n */\n readonly requiresIntervals?: ReadonlyArray<string>;\n /**\n * Static list of user-wireable alert conditions declared by\n * `defineAlertCondition({ conditions })`.\n *\n * @since 0.5\n * @stable\n * @example\n * const defs: ScriptManifest[\"alertConditions\"] = [\n * { id: \"up\", title: \"Up\", description: \"Close > EMA\", defaultMessage: \"{{ticker}} up\" },\n * ];\n * void defs;\n */\n readonly alertConditions?: ReadonlyArray<AlertConditionDefinition>;\n /**\n * Statically-resolved dependency graph nodes consumed by this\n * script. Empty / omitted for scripts with no\n * `<binding>.output(...)` calls. Each entry is one consumer-side\n * `const` binding pointing at another `defineIndicator(...)`\n * result.\n *\n * @since 0.7\n * @stable\n * @example\n * const v: ScriptManifest[\"dependencies\"] = [];\n * void v;\n */\n readonly dependencies?: ReadonlyArray<DependencyDeclaration>;\n /**\n * Titled outputs this script exposes for consumption by other\n * indicators. Derived from `plot(value, { title })` calls in\n * this script's compute body. Empty / omitted when the script\n * has no titled plots.\n *\n * @since 0.7\n * @stable\n * @example\n * const v: ScriptManifest[\"outputs\"] = [\n * { title: \"line\", kind: \"series-number\" },\n * ];\n * void v;\n */\n readonly outputs?: ReadonlyArray<OutputDeclaration>;\n /**\n * Static plot-slot descriptors — one per `plot()` / `hline()` callsite,\n * in callsite order. Lets an embedder enumerate plottable slots (and\n * key per-slot style/visibility overrides) without waiting for the\n * first emission. Absent on scripts that issue no plot/hline calls.\n *\n * @since 0.8\n * @stable\n * @example\n * const v: ScriptManifest[\"plots\"] = [\n * { slotId: \"ema.ts:12:5#0\", kind: \"line\", title: \"EMA\" },\n * ];\n * void v;\n */\n readonly plots?: ReadonlyArray<PlotSlotDescriptor>;\n /**\n * Higher-timeframe expression units — one per\n * `request.security({ interval }, (bar) => …)` callsite, sorted by\n * `slotId`. Tells the runtime which slot ids run on an HTF clock and on\n * which interval. Absent on scripts that use only the data form (or no\n * `request.security` at all) so existing manifest snapshots stay\n * byte-identical.\n *\n * @since 0.7\n * @stable\n * @example\n * const v: ScriptManifest[\"securityExpressions\"] = [\n * { slotId: \"trend.ts:8:21#0\", interval: \"1W\", paramName: \"bar\" },\n * { slotId: \"aapl.ts:9:21#0\", symbol: \"NASDAQ:AAPL\", interval: \"1W\", paramName: \"bar\" },\n * ];\n * void v;\n */\n readonly securityExpressions?: ReadonlyArray<SecurityExpressionDescriptor>;\n /**\n * Every distinct secondary feed the script's `request.security` calls\n * request, as `(symbol?, interval)` pairs. Superset of\n * {@link ScriptManifest.requestedIntervals}, which stays the\n * **main-symbol** HTF projection (symbol-omitted feeds) for back-compat —\n * adding this field is additive within `apiVersion: 1`, whereas reshaping\n * `requestedIntervals` would not be. Absent on scripts with no\n * `request.security` so existing manifest snapshots stay byte-identical.\n *\n * @since 1.3\n * @stable\n * @example\n * const v: ScriptManifest[\"requestedFeeds\"] = [\n * { interval: \"1W\" },\n * { symbol: \"AMEX:SPY\", interval: \"1D\" },\n * ];\n * void v;\n */\n readonly requestedFeeds?: ReadonlyArray<RequestedFeed>;\n /**\n * The ES-module binding name this manifest was reached through.\n * `\"default\"` for `export default defineIndicator(...)`; the\n * named-binding identifier otherwise. Always present when the\n * source file has more than one drawn indicator; omitted on\n * single-script files for back-compat.\n *\n * @since 0.7\n * @stable\n * @example\n * const v: ScriptManifest[\"exportName\"] = \"default\";\n * void v;\n */\n readonly exportName?: string;\n /**\n * Other drawn manifests in the same compiled file. Present\n * only when this manifest is the file's default export and the\n * file has additional named-exported drawn indicators. Omitted\n * for single-script files and for non-default-export entries\n * in the array-form manifest sidecar.\n *\n * @since 0.7\n * @stable\n * @example\n * const v: ScriptManifest[\"siblings\"] = [];\n * void v;\n */\n readonly siblings?: ReadonlyArray<ScriptManifest>;\n /**\n * `true` when this manifest belongs to a drawn (exported)\n * indicator — the host should mount it. `false` when this\n * manifest belongs to a private dep — emissions are dropped.\n * Defaults to `true` for back-compat.\n *\n * @since 0.7\n * @stable\n * @example\n * const v: ScriptManifest[\"isDrawn\"] = true;\n * void v;\n */\n readonly isDrawn?: boolean;\n};\n\n/**\n * Per-condition descriptor authored under\n * `DefineAlertConditionOpts.conditions`.\n *\n * @since 0.5\n * @stable\n * @example\n * const d: AlertConditionDescriptor = {\n * title: \"Up\",\n * description: \"Close crossed up\",\n * defaultMessage: \"{{ticker}} crossed up\",\n * };\n * void d;\n */\nexport type AlertConditionDescriptor = Readonly<{\n title: string;\n description: string;\n defaultMessage: string;\n}>;\n\n/**\n * Manifest-ready alert-condition descriptor with the author map key\n * normalised into `id`.\n *\n * @since 0.5\n * @stable\n * @example\n * const d: AlertConditionDefinition = {\n * id: \"up\",\n * title: \"Up\",\n * description: \"Close crossed up\",\n * defaultMessage: \"{{ticker}} crossed up\",\n * };\n * void d;\n */\nexport type AlertConditionDefinition = AlertConditionDescriptor &\n Readonly<{\n id: string;\n }>;\n\n/**\n * The argument the runtime hands a script's `compute` function each bar. The\n * `ta` / `plot` / `hline` / `alert` slots are the runtime's implementations,\n * not the compile-time callable holes from `@invinite-org/chartlang-core`.\n *\n * @since 0.1\n * @example\n * const fn: ComputeFn = ({ bar, plot }) => { plot(bar.close); };\n */\nexport type ComputeContext = {\n readonly bar: BarSeries;\n readonly inputs: Readonly<Record<string, unknown>>;\n readonly ta: TaNamespace;\n readonly plot: typeof import(\"./plot/plot.js\").plot;\n readonly hline: typeof import(\"./plot/plot.js\").hline;\n /** Pane-background band alias (`bg-color` plot style). @since 1.4 */\n readonly bgcolor: typeof import(\"./plot/plot.js\").bgcolor;\n /** Candle/bar tint alias (`bar-color` plot style). @since 1.4 */\n readonly barcolor: typeof import(\"./plot/plot.js\").barcolor;\n readonly alert: typeof import(\"./alert/alert.js\").alert;\n /** Pine `var` / `varip` state slots. @since 0.4 */\n readonly state: StateNamespace;\n /** Bar-state view derived for the active step. @since 0.4 */\n readonly barstate: BarStateView;\n /** Symbol metadata view for the active script mount. @since 0.4 */\n readonly syminfo: SymInfoView;\n /** Timeframe helper view derived for the active step. @since 0.4 */\n readonly timeframe: TimeframeView;\n /** Calendar accessors over a `Time` epoch (UTC-first). @since 1.5 */\n readonly time: TimeNamespace;\n /** Session-window membership helpers. @since 1.5 */\n readonly session: SessionNamespace;\n /** Secondary timeframe request namespace. @since 0.4 */\n readonly request: RequestNamespace;\n /** Runtime logging and fatal halt namespace. @since 0.5 */\n readonly runtime: RuntimeNamespace;\n /**\n * Signal a named condition declared by `defineAlertCondition`. Present\n * only for scripts whose manifest kind is `\"alertCondition\"`.\n *\n * @since 0.5\n * @stable\n * @example\n * const fn: NonNullable<ComputeContext[\"signal\"]> = (id, fired) => {\n * void id;\n * void fired;\n * };\n * void fn;\n */\n readonly signal?: (conditionId: string, fired: boolean) => void;\n /**\n * Imperative drawing namespace. Each method returns a\n * {@link DrawingHandle} the script can `update(...)` or\n * `remove()` within the same `compute` run, and across bars.\n * The Phase-3 runtime impl lives in\n * `@invinite-org/chartlang-runtime/emit/draw`. @since 0.3\n */\n readonly draw: DrawNamespace;\n};\n\n/**\n * The per-bar compute function a script exports via `defineIndicator` /\n * `defineAlert`. Pure with respect to its arguments — no `this`, no closures\n * over host state.\n *\n * @since 0.1\n * @example\n * const fn: ComputeFn = (ctx) => { ctx.plot(ctx.bar.close); };\n */\nexport type ComputeFn = (ctx: ComputeContext) => void;\n\n/**\n * The frozen object the `defineIndicator` / `defineAlert` constructors return.\n * The compiler rewrites `manifest` fields at build time; the runtime invokes\n * `compute` per bar.\n *\n * The `output` / `withInputs` accessors (Phase 7) are compiler-rewritten\n * sentinels — the indicator-composition compiler pass statically replaces\n * every consumer-side call site before bundling, so the runtime never\n * executes the throwing bodies. Direct invocation from an un-compiled\n * script (e.g. a unit test that imports the module directly) hits the\n * sentinel and throws, which is the desired failure.\n *\n * @since 0.1\n * @example\n * const cs: CompiledScriptObject = defineIndicator({\n * name: \"demo\",\n * apiVersion: 1,\n * compute: () => {},\n * });\n */\nexport type CompiledScriptObject = {\n readonly manifest: ScriptManifest;\n readonly compute: ComputeFn;\n /**\n * Read the named output of this indicator inside another\n * indicator's compute body. Output names come from the\n * producer's `plot(value, { title })` calls. The compiler\n * rewrites every consumer-side call site before bundling;\n * direct invocation throws the dep-accessor sentinel.\n *\n * @since 0.7\n * @stable\n * @example\n * declare const baseTrend: CompiledScriptObject;\n * const line: Series<number> = baseTrend.output(\"line\");\n * void line;\n */\n readonly output: (name: string) => Series<number>;\n /**\n * Return a new `CompiledScriptObject` whose dependency-binding\n * effective inputs are the merge of the producer's defaults with\n * the supplied overrides. Static — the compiler folds the\n * override into the inlined dep manifest at bundle time.\n *\n * @since 0.7\n * @stable\n * @example\n * declare const baseTrend: CompiledScriptObject;\n * const trend = baseTrend.withInputs({ length: 50 });\n * void trend;\n */\n readonly withInputs: (overrides: Readonly<Record<string, unknown>>) => CompiledScriptObject;\n};\n\n/**\n * The compiled artefact for a `.chart.ts` file when it contains\n * multiple drawn indicators or any dependency graph. The Phase-7\n * runtime accepts either this shape or the legacy\n * `CompiledScriptObject` (single-script files).\n *\n * `primary` is the default-exported drawn script. `siblings` are\n * every other drawn export (named consts). `dependencies` is every\n * private-dep compiled object — keyed by `localId` so the runtime\n * can look them up by the `DependencyDeclaration.localId` it sees\n * on each consumer's manifest.\n *\n * @since 0.7\n * @stable\n * @example\n * declare const primary: CompiledScriptObject;\n * const bundle: CompiledScriptBundle = {\n * primary,\n * siblings: [],\n * dependencies: [],\n * };\n * void bundle;\n */\nexport type CompiledScriptBundle = Readonly<{\n readonly primary: CompiledScriptObject;\n readonly siblings: ReadonlyArray<{\n readonly exportName: string;\n readonly compiled: CompiledScriptObject;\n }>;\n readonly dependencies: ReadonlyArray<{\n readonly localId: string;\n readonly compiled: CompiledScriptObject;\n /**\n * Merged `.withInputs({...})` overrides the consumer applied\n * to its alias binding. Forwarded into the `DepRunner` as the\n * dep's input overrides so the producer's `compute` reads the\n * consumer-supplied values instead of the producer's manifest\n * defaults. Omitted for direct private deps that don't apply\n * overrides.\n *\n * @since 0.7\n */\n readonly inputOverrides?: Readonly<Record<string, unknown>>;\n }>;\n}>;\n\n/**\n * Narrowing helper that distinguishes the new\n * {@link CompiledScriptBundle} envelope from the legacy single-script\n * {@link CompiledScriptObject}. The runner uses it to pick the\n * multi-script execution path without re-parsing manifests.\n *\n * @since 0.7\n * @stable\n * @example\n * declare const v: CompiledScriptObject | CompiledScriptBundle;\n * if (isCompiledScriptBundle(v)) {\n * void v.primary;\n * } else {\n * void v.manifest;\n * }\n */\nexport const isCompiledScriptBundle = (\n v: CompiledScriptObject | CompiledScriptBundle,\n): v is CompiledScriptBundle => Object.prototype.hasOwnProperty.call(v, \"primary\");\n\n/**\n * JSON-compatible payload type for `alert(...).meta` and other places the\n * runtime serialises script-supplied data across worker / host boundaries.\n *\n * @since 0.1\n * @example\n * const meta: JsonValue = { reason: \"crossover\", strength: 0.42 };\n */\nexport type JsonValue =\n | null\n | boolean\n | number\n | string\n | ReadonlyArray<JsonValue>\n | { readonly [k: string]: JsonValue };\n"]}
|