@invinite-org/chartlang-runtime 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 +307 -0
- package/dist/barPoint.d.ts +20 -0
- package/dist/barPoint.d.ts.map +1 -0
- package/dist/barPoint.js +72 -0
- package/dist/barPoint.js.map +1 -0
- package/dist/bufferSnapshot.d.ts +102 -0
- package/dist/bufferSnapshot.d.ts.map +1 -0
- package/dist/bufferSnapshot.js +119 -0
- package/dist/bufferSnapshot.js.map +1 -0
- package/dist/buildComputeContext.d.ts.map +1 -1
- package/dist/buildComputeContext.js +6 -1
- package/dist/buildComputeContext.js.map +1 -1
- package/dist/createScriptRunner.d.ts +6 -3
- package/dist/createScriptRunner.d.ts.map +1 -1
- package/dist/createScriptRunner.js +65 -11
- package/dist/createScriptRunner.js.map +1 -1
- package/dist/dep/DepRunner.d.ts +7 -0
- package/dist/dep/DepRunner.d.ts.map +1 -1
- package/dist/dep/DepRunner.js +4 -0
- package/dist/dep/DepRunner.js.map +1 -1
- package/dist/emit/barcolor.d.ts +44 -0
- package/dist/emit/barcolor.d.ts.map +1 -0
- package/dist/emit/barcolor.js +40 -0
- package/dist/emit/barcolor.js.map +1 -0
- package/dist/emit/bgcolor.d.ts +44 -0
- package/dist/emit/bgcolor.d.ts.map +1 -0
- package/dist/emit/bgcolor.js +45 -0
- package/dist/emit/bgcolor.js.map +1 -0
- package/dist/emit/draw/boxes/fillBetween.d.ts +45 -0
- package/dist/emit/draw/boxes/fillBetween.d.ts.map +1 -0
- package/dist/emit/draw/boxes/fillBetween.js +36 -0
- package/dist/emit/draw/boxes/fillBetween.js.map +1 -0
- package/dist/emit/draw/handle.d.ts +9 -0
- package/dist/emit/draw/handle.d.ts.map +1 -1
- package/dist/emit/draw/handle.js +65 -10
- package/dist/emit/draw/handle.js.map +1 -1
- package/dist/emit/draw/namespace.d.ts +4 -3
- package/dist/emit/draw/namespace.d.ts.map +1 -1
- package/dist/emit/draw/namespace.js +6 -3
- package/dist/emit/draw/namespace.js.map +1 -1
- package/dist/emit/index.d.ts +2 -0
- package/dist/emit/index.d.ts.map +1 -1
- package/dist/emit/index.js +2 -0
- package/dist/emit/index.js.map +1 -1
- package/dist/emit/plot.d.ts +30 -1
- package/dist/emit/plot.d.ts.map +1 -1
- package/dist/emit/plot.js +45 -1
- package/dist/emit/plot.js.map +1 -1
- package/dist/execution/dispose.d.ts.map +1 -1
- package/dist/execution/dispose.js +18 -0
- package/dist/execution/dispose.js.map +1 -1
- package/dist/execution/runComputeStep.d.ts.map +1 -1
- package/dist/execution/runComputeStep.js +12 -1
- package/dist/execution/runComputeStep.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/inputs/resolveInputs.js +1 -0
- package/dist/inputs/resolveInputs.js.map +1 -1
- package/dist/persistentStateStore.runtime.d.ts.map +1 -1
- package/dist/persistentStateStore.runtime.js +26 -7
- package/dist/persistentStateStore.runtime.js.map +1 -1
- package/dist/primitives.d.ts +1 -1
- package/dist/primitives.d.ts.map +1 -1
- package/dist/primitives.js +7 -1
- package/dist/primitives.js.map +1 -1
- package/dist/request/index.d.ts +2 -1
- package/dist/request/index.d.ts.map +1 -1
- package/dist/request/index.js +2 -1
- package/dist/request/index.js.map +1 -1
- package/dist/request/lowerTf.d.ts.map +1 -1
- package/dist/request/lowerTf.js +6 -0
- package/dist/request/lowerTf.js.map +1 -1
- package/dist/request/requestNamespace.d.ts.map +1 -1
- package/dist/request/requestNamespace.js +30 -3
- package/dist/request/requestNamespace.js.map +1 -1
- package/dist/request/security.d.ts +40 -4
- package/dist/request/security.d.ts.map +1 -1
- package/dist/request/security.js +114 -40
- package/dist/request/security.js.map +1 -1
- package/dist/request/securityExprRunner.d.ts +137 -0
- package/dist/request/securityExprRunner.d.ts.map +1 -0
- package/dist/request/securityExprRunner.js +253 -0
- package/dist/request/securityExprRunner.js.map +1 -0
- package/dist/request/streamBars.d.ts +14 -1
- package/dist/request/streamBars.d.ts.map +1 -1
- package/dist/request/streamBars.js +39 -1
- package/dist/request/streamBars.js.map +1 -1
- package/dist/ringBuffer.d.ts +19 -0
- package/dist/ringBuffer.d.ts.map +1 -1
- package/dist/ringBuffer.js +23 -0
- package/dist/ringBuffer.js.map +1 -1
- package/dist/runtimeContext.d.ts +90 -5
- package/dist/runtimeContext.d.ts.map +1 -1
- package/dist/runtimeContext.js.map +1 -1
- package/dist/seriesView.d.ts +42 -17
- package/dist/seriesView.d.ts.map +1 -1
- package/dist/seriesView.js +65 -42
- package/dist/seriesView.js.map +1 -1
- package/dist/state/arrayPersistence.d.ts +48 -0
- package/dist/state/arrayPersistence.d.ts.map +1 -0
- package/dist/state/arrayPersistence.js +88 -0
- package/dist/state/arrayPersistence.js.map +1 -0
- package/dist/state/arrayStateSlot.d.ts +78 -0
- package/dist/state/arrayStateSlot.d.ts.map +1 -0
- package/dist/state/arrayStateSlot.js +116 -0
- package/dist/state/arrayStateSlot.js.map +1 -0
- package/dist/state/index.d.ts +4 -1
- package/dist/state/index.d.ts.map +1 -1
- package/dist/state/index.js +4 -1
- package/dist/state/index.js.map +1 -1
- package/dist/state/lifecycle.d.ts +68 -0
- package/dist/state/lifecycle.d.ts.map +1 -1
- package/dist/state/lifecycle.js +89 -0
- package/dist/state/lifecycle.js.map +1 -1
- package/dist/state/seriesPersistence.d.ts +48 -0
- package/dist/state/seriesPersistence.d.ts.map +1 -0
- package/dist/state/seriesPersistence.js +87 -0
- package/dist/state/seriesPersistence.js.map +1 -0
- package/dist/state/seriesSlot.d.ts +105 -0
- package/dist/state/seriesSlot.d.ts.map +1 -0
- package/dist/state/seriesSlot.js +123 -0
- package/dist/state/seriesSlot.js.map +1 -0
- package/dist/state/stateNamespace.d.ts.map +1 -1
- package/dist/state/stateNamespace.js +55 -0
- package/dist/state/stateNamespace.js.map +1 -1
- package/dist/streamState.d.ts +25 -19
- package/dist/streamState.d.ts.map +1 -1
- package/dist/streamState.js +40 -66
- package/dist/streamState.js.map +1 -1
- package/dist/ta/adx.d.ts +3 -2
- package/dist/ta/adx.d.ts.map +1 -1
- package/dist/ta/adx.js +3 -2
- package/dist/ta/adx.js.map +1 -1
- package/dist/ta/alma.d.ts +6 -4
- package/dist/ta/alma.d.ts.map +1 -1
- package/dist/ta/alma.js +19 -6
- package/dist/ta/alma.js.map +1 -1
- package/dist/ta/atr.d.ts +3 -2
- package/dist/ta/atr.d.ts.map +1 -1
- package/dist/ta/atr.js +3 -2
- package/dist/ta/atr.js.map +1 -1
- package/dist/ta/bb.d.ts +3 -2
- package/dist/ta/bb.d.ts.map +1 -1
- package/dist/ta/bb.js +3 -2
- package/dist/ta/bb.js.map +1 -1
- package/dist/ta/chaikinOsc.d.ts +3 -2
- package/dist/ta/chaikinOsc.d.ts.map +1 -1
- package/dist/ta/chaikinOsc.js +3 -2
- package/dist/ta/chaikinOsc.js.map +1 -1
- package/dist/ta/crossover.d.ts +3 -2
- package/dist/ta/crossover.d.ts.map +1 -1
- package/dist/ta/crossover.js +3 -2
- package/dist/ta/crossover.js.map +1 -1
- package/dist/ta/crossunder.d.ts +3 -2
- package/dist/ta/crossunder.d.ts.map +1 -1
- package/dist/ta/crossunder.js +3 -2
- package/dist/ta/crossunder.js.map +1 -1
- package/dist/ta/dmi.d.ts +4 -3
- package/dist/ta/dmi.d.ts.map +1 -1
- package/dist/ta/dmi.js +4 -3
- package/dist/ta/dmi.js.map +1 -1
- package/dist/ta/ema.d.ts +3 -2
- package/dist/ta/ema.d.ts.map +1 -1
- package/dist/ta/ema.js +3 -2
- package/dist/ta/ema.js.map +1 -1
- package/dist/ta/eom.d.ts +3 -1
- package/dist/ta/eom.d.ts.map +1 -1
- package/dist/ta/eom.js +3 -1
- package/dist/ta/eom.js.map +1 -1
- package/dist/ta/highestbars.d.ts +25 -0
- package/dist/ta/highestbars.d.ts.map +1 -0
- package/dist/ta/highestbars.js +106 -0
- package/dist/ta/highestbars.js.map +1 -0
- package/dist/ta/historicalVolatility.d.ts +3 -2
- package/dist/ta/historicalVolatility.d.ts.map +1 -1
- package/dist/ta/historicalVolatility.js +3 -2
- package/dist/ta/historicalVolatility.js.map +1 -1
- package/dist/ta/ichimoku.d.ts +3 -1
- package/dist/ta/ichimoku.d.ts.map +1 -1
- package/dist/ta/ichimoku.js +3 -1
- package/dist/ta/ichimoku.js.map +1 -1
- package/dist/ta/lowestbars.d.ts +25 -0
- package/dist/ta/lowestbars.d.ts.map +1 -0
- package/dist/ta/lowestbars.js +102 -0
- package/dist/ta/lowestbars.js.map +1 -0
- package/dist/ta/macd.d.ts +3 -2
- package/dist/ta/macd.d.ts.map +1 -1
- package/dist/ta/macd.js +3 -2
- package/dist/ta/macd.js.map +1 -1
- package/dist/ta/massIndex.d.ts +3 -2
- package/dist/ta/massIndex.d.ts.map +1 -1
- package/dist/ta/massIndex.js +3 -2
- package/dist/ta/massIndex.js.map +1 -1
- package/dist/ta/mfi.d.ts +3 -1
- package/dist/ta/mfi.d.ts.map +1 -1
- package/dist/ta/mfi.js +3 -1
- package/dist/ta/mfi.js.map +1 -1
- package/dist/ta/netVolume.d.ts +3 -1
- package/dist/ta/netVolume.d.ts.map +1 -1
- package/dist/ta/netVolume.js +3 -1
- package/dist/ta/netVolume.js.map +1 -1
- package/dist/ta/nvi.d.ts +3 -1
- package/dist/ta/nvi.d.ts.map +1 -1
- package/dist/ta/nvi.js +3 -1
- package/dist/ta/nvi.js.map +1 -1
- package/dist/ta/persistence.d.ts.map +1 -1
- package/dist/ta/persistence.js +1 -40
- package/dist/ta/persistence.js.map +1 -1
- package/dist/ta/ppo.d.ts +3 -2
- package/dist/ta/ppo.d.ts.map +1 -1
- package/dist/ta/ppo.js +3 -2
- package/dist/ta/ppo.js.map +1 -1
- package/dist/ta/pvi.d.ts +3 -1
- package/dist/ta/pvi.d.ts.map +1 -1
- package/dist/ta/pvi.js +3 -1
- package/dist/ta/pvi.js.map +1 -1
- package/dist/ta/pvo.d.ts +3 -1
- package/dist/ta/pvo.d.ts.map +1 -1
- package/dist/ta/pvo.js +3 -1
- package/dist/ta/pvo.js.map +1 -1
- package/dist/ta/pvt.d.ts +3 -1
- package/dist/ta/pvt.d.ts.map +1 -1
- package/dist/ta/pvt.js +3 -1
- package/dist/ta/pvt.js.map +1 -1
- package/dist/ta/registry.d.ts +7 -1
- package/dist/ta/registry.d.ts.map +1 -1
- package/dist/ta/registry.js +4 -0
- package/dist/ta/registry.js.map +1 -1
- package/dist/ta/rsi.d.ts +3 -2
- package/dist/ta/rsi.d.ts.map +1 -1
- package/dist/ta/rsi.js +3 -2
- package/dist/ta/rsi.js.map +1 -1
- package/dist/ta/rvi.d.ts +3 -2
- package/dist/ta/rvi.d.ts.map +1 -1
- package/dist/ta/rvi.js +3 -2
- package/dist/ta/rvi.js.map +1 -1
- package/dist/ta/sessionVolumeProfile.d.ts.map +1 -1
- package/dist/ta/sessionVolumeProfile.js +1 -17
- package/dist/ta/sessionVolumeProfile.js.map +1 -1
- package/dist/ta/sma.d.ts +6 -3
- package/dist/ta/sma.d.ts.map +1 -1
- package/dist/ta/sma.js +6 -3
- package/dist/ta/sma.js.map +1 -1
- package/dist/ta/stdev.d.ts +3 -2
- package/dist/ta/stdev.d.ts.map +1 -1
- package/dist/ta/stdev.js +3 -2
- package/dist/ta/stdev.js.map +1 -1
- package/dist/ta/trendStrengthIndex.d.ts +3 -2
- package/dist/ta/trendStrengthIndex.d.ts.map +1 -1
- package/dist/ta/trendStrengthIndex.js +3 -2
- package/dist/ta/trendStrengthIndex.js.map +1 -1
- package/dist/ta/trix.d.ts +4 -3
- package/dist/ta/trix.d.ts.map +1 -1
- package/dist/ta/trix.js +4 -3
- package/dist/ta/trix.js.map +1 -1
- package/dist/ta/vortex.d.ts +3 -2
- package/dist/ta/vortex.d.ts.map +1 -1
- package/dist/ta/vortex.js +3 -2
- package/dist/ta/vortex.js.map +1 -1
- package/dist/time-accessors/civil.d.ts +73 -0
- package/dist/time-accessors/civil.d.ts.map +1 -0
- package/dist/time-accessors/civil.js +105 -0
- package/dist/time-accessors/civil.js.map +1 -0
- package/dist/time-accessors/index.d.ts +8 -0
- package/dist/time-accessors/index.d.ts.map +1 -0
- package/dist/time-accessors/index.js +9 -0
- package/dist/time-accessors/index.js.map +1 -0
- package/dist/time-accessors/sessionAccessors.d.ts +50 -0
- package/dist/time-accessors/sessionAccessors.d.ts.map +1 -0
- package/dist/time-accessors/sessionAccessors.js +79 -0
- package/dist/time-accessors/sessionAccessors.js.map +1 -0
- package/dist/time-accessors/sessionWindow.d.ts +17 -0
- package/dist/time-accessors/sessionWindow.d.ts.map +1 -0
- package/dist/time-accessors/sessionWindow.js +41 -0
- package/dist/time-accessors/sessionWindow.js.map +1 -0
- package/dist/time-accessors/timeAccessors.d.ts +54 -0
- package/dist/time-accessors/timeAccessors.d.ts.map +1 -0
- package/dist/time-accessors/timeAccessors.js +132 -0
- package/dist/time-accessors/timeAccessors.js.map +1 -0
- package/dist/time-accessors/tzDiagnostic.d.ts +17 -0
- package/dist/time-accessors/tzDiagnostic.d.ts.map +1 -0
- package/dist/time-accessors/tzDiagnostic.js +34 -0
- package/dist/time-accessors/tzDiagnostic.js.map +1 -0
- package/dist/time-accessors/tzOffset.d.ts +31 -0
- package/dist/time-accessors/tzOffset.d.ts.map +1 -0
- package/dist/time-accessors/tzOffset.js +67 -0
- package/dist/time-accessors/tzOffset.js.map +1 -0
- package/package.json +3 -3
- package/dist/ta/lib/applyOffset.d.ts +0 -19
- package/dist/ta/lib/applyOffset.d.ts.map +0 -1
- package/dist/ta/lib/applyOffset.js +0 -38
- package/dist/ta/lib/applyOffset.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildComputeContext.d.ts","sourceRoot":"","sources":["../src/buildComputeContext.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"buildComputeContext.d.ts","sourceRoot":"","sources":["../src/buildComputeContext.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAQ3D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,cAAc,CA0BtE"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Copyright (c) 2026 Invinite. Licensed under the MIT License.
|
|
2
2
|
// See the LICENSE file in the repo root for full license text.
|
|
3
|
-
import { alert, draw, hline, plot, ta } from "./primitives.js";
|
|
3
|
+
import { alert, barcolor, bgcolor, draw, hline, plot, ta } from "./primitives.js";
|
|
4
4
|
import { emitAlertCondition } from "./emit/alertConditionEmission.js";
|
|
5
5
|
import { buildRuntimeNamespace } from "./emit/logEmission.js";
|
|
6
6
|
import { buildRequestNamespace } from "./request/index.js";
|
|
7
7
|
import { buildStateNamespace } from "./state/index.js";
|
|
8
|
+
import { buildSessionNamespace, buildTimeNamespace } from "./time-accessors/index.js";
|
|
8
9
|
/**
|
|
9
10
|
* Build the `ComputeContext` the runner hands the compiled script on
|
|
10
11
|
* every step. Phase 1 returns the runtime's stable `BarView` (identity
|
|
@@ -29,12 +30,16 @@ export function buildComputeContext(state) {
|
|
|
29
30
|
ta,
|
|
30
31
|
plot,
|
|
31
32
|
hline,
|
|
33
|
+
bgcolor,
|
|
34
|
+
barcolor,
|
|
32
35
|
alert,
|
|
33
36
|
draw,
|
|
34
37
|
state: buildStateNamespace(),
|
|
35
38
|
barstate: state.runtimeContext.views.barstate,
|
|
36
39
|
syminfo: state.runtimeContext.views.syminfo,
|
|
37
40
|
timeframe: state.runtimeContext.views.timeframe,
|
|
41
|
+
time: buildTimeNamespace(state.runtimeContext),
|
|
42
|
+
session: buildSessionNamespace(state.runtimeContext),
|
|
38
43
|
request: buildRequestNamespace(),
|
|
39
44
|
runtime: buildRuntimeNamespace(state.runtimeContext),
|
|
40
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildComputeContext.js","sourceRoot":"","sources":["../src/buildComputeContext.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAK/D,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"buildComputeContext.js","sourceRoot":"","sources":["../src/buildComputeContext.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAK/D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEtF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAkB;IAClD,MAAM,IAAI,GAAG;QACT,GAAG,EAAE,KAAK,CAAC,UAAU,CAAC,GAAG;QACzB,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,cAAc;QAC3C,EAAE;QACF,IAAI;QACJ,KAAK;QACL,OAAO;QACP,QAAQ;QACR,KAAK;QACL,IAAI;QACJ,KAAK,EAAE,mBAAmB,EAAE;QAC5B,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,QAAQ;QAC7C,OAAO,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO;QAC3C,SAAS,EAAE,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,SAAS;QAC/C,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC,cAAc,CAAC;QAC9C,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,cAAc,CAAC;QACpD,OAAO,EAAE,qBAAqB,EAAE;QAChC,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,cAAc,CAAC;KACvD,CAAC;IACF,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,IAAI,CAAC;IAC1D,OAAO;QACH,GAAG,IAAI;QACP,MAAM,EAAE,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE,CAC3B,kBAAkB,CAAC,KAAK,CAAC,cAAc,EAAE,WAAW,EAAE,KAAK,CAAC;KACnE,CAAC;AACN,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 { ComputeContext } from \"@invinite-org/chartlang-core\";\n\nimport type { RunnerState } from \"./createScriptRunner.js\";\nimport { alert, barcolor, bgcolor, draw, hline, plot, ta } from \"./primitives.js\";\nimport { emitAlertCondition } from \"./emit/alertConditionEmission.js\";\nimport { buildRuntimeNamespace } from \"./emit/logEmission.js\";\nimport { buildRequestNamespace } from \"./request/index.js\";\nimport { buildStateNamespace } from \"./state/index.js\";\nimport { buildSessionNamespace, buildTimeNamespace } from \"./time-accessors/index.js\";\n\n/**\n * Build the `ComputeContext` the runner hands the compiled script on\n * every step. Phase 1 returns the runtime's stable `BarView` (identity\n * preserved across bars per PLAN §6.7), the mount-resolved frozen\n * `inputs` record, and the runtime primitive implementations.\n *\n * The `bar` field is the mutable `BarView` typed-narrowed to the\n * readonly `Bar` surface the script sees. Identity is stable, so a\n * `const { bar } = ctx` at the top of `compute` keeps seeing the live\n * scalars without re-binding per bar.\n *\n * @since 0.1\n * @example\n * // import { buildComputeContext } from \"@invinite-org/chartlang-runtime\";\n * // const ctx = buildComputeContext(state);\n * // void ctx.bar.close;\n */\nexport function buildComputeContext(state: RunnerState): ComputeContext {\n const base = {\n bar: state.mainStream.bar,\n inputs: state.runtimeContext.resolvedInputs,\n ta,\n plot,\n hline,\n bgcolor,\n barcolor,\n alert,\n draw,\n state: buildStateNamespace(),\n barstate: state.runtimeContext.views.barstate,\n syminfo: state.runtimeContext.views.syminfo,\n timeframe: state.runtimeContext.views.timeframe,\n time: buildTimeNamespace(state.runtimeContext),\n session: buildSessionNamespace(state.runtimeContext),\n request: buildRequestNamespace(),\n runtime: buildRuntimeNamespace(state.runtimeContext),\n };\n if (state.manifest.kind !== \"alertCondition\") return base;\n return {\n ...base,\n signal: (conditionId, fired) =>\n emitAlertCondition(state.runtimeContext, conditionId, fired),\n };\n}\n"]}
|
|
@@ -145,10 +145,13 @@ export type CreateScriptRunnerArgs = {
|
|
|
145
145
|
* `ACTIVE_RUNTIME_CONTEXT`. Phase 1 ships a single-stream model; the
|
|
146
146
|
* `requestedIntervals` field on the manifest is always empty.
|
|
147
147
|
*
|
|
148
|
-
* Capacity sizing follows PLAN §6.6:
|
|
148
|
+
* Capacity sizing follows PLAN §6.6: take the max of
|
|
149
149
|
* `manifest.seriesCapacities.ohlcv` (compiler-emitted per-series
|
|
150
|
-
* lookback)
|
|
151
|
-
*
|
|
150
|
+
* lookback) or the `manifest.maxLookback + 1` floor, and
|
|
151
|
+
* `manifest.seriesCapacities.dynamicFallback` (the 5000-slot safety net the
|
|
152
|
+
* compiler emits when a series is read at a non-literal index it cannot size
|
|
153
|
+
* statically), clamped to a minimum of 1 so an empty-history script still has
|
|
154
|
+
* a valid head slot.
|
|
152
155
|
*
|
|
153
156
|
* @since 0.1 — widened to accept `CompiledScriptBundle` in 0.7.
|
|
154
157
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createScriptRunner.d.ts","sourceRoot":"","sources":["../src/createScriptRunner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,eAAe,EAClB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EACR,GAAG,EACH,oBAAoB,EACpB,oBAAoB,EACpB,SAAS,
|
|
1
|
+
{"version":3,"file":"createScriptRunner.d.ts","sourceRoot":"","sources":["../src/createScriptRunner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,eAAe,EAClB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EACR,GAAG,EACH,oBAAoB,EACpB,oBAAoB,EACpB,SAAS,EAET,cAAc,EACjB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACH,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,aAAa,EAKrB,MAAM,gBAAgB,CAAC;AAexB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAYtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,KAAK,UAAU,EAAsB,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,KAAK,WAAW,EAAqB,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,KAAK,cAAc,EAAuC,MAAM,kBAAkB,CAAC;AAE5F;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GAAG;IACtB,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAC;IAC3B,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B,GAAG,oBAAoB,CAAC;IAC/D,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IACjC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IACrD,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IACxC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjF,QAAQ,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5D,QAAQ,CAAC,oBAAoB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAC7F,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;CACnE,CAAC;AAmRF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,YAAY,CA6E7E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) 2026 Invinite. Licensed under the MIT License.
|
|
2
2
|
// See the LICENSE file in the repo root for full license text.
|
|
3
|
-
import { isCompiledScriptBundle } from "@invinite-org/chartlang-core";
|
|
3
|
+
import { feedKey, isCompiledScriptBundle } from "@invinite-org/chartlang-core";
|
|
4
4
|
import { createDepOutputStore, createDepRunner, createSiblingRunner, installDepOutputGlobal, } from "./dep/index.js";
|
|
5
5
|
import { pushDiagnostic, resolveDefaultPane, resolveScriptPane } from "./emit/index.js";
|
|
6
6
|
import { dispose as disposeImpl, drain as drainImpl, onBarClose as onBarCloseImpl, onBarTick as onBarTickImpl, onHistory as onHistoryImpl, } from "./execution/index.js";
|
|
@@ -8,20 +8,46 @@ import { appendSecondaryBar, appendSecondaryHistory, replaceSecondaryHead, } fro
|
|
|
8
8
|
import { resolveInputs } from "./inputs/index.js";
|
|
9
9
|
import { PERSISTENCE_INTERVAL_MS, maybeSaveStateSnapshot, restoreStateSnapshot, saveStateSnapshot, } from "./persistentStateStore.runtime.js";
|
|
10
10
|
import { validateSnapshot } from "./persistentStateStore.validate.js";
|
|
11
|
+
import { buildSecurityExprRunners, driveSecurityExpressions, } from "./request/securityExprRunner.js";
|
|
11
12
|
import { inMemoryStateStore } from "./stateStore.js";
|
|
12
13
|
import { createStreamState } from "./streamState.js";
|
|
13
14
|
import { createRuntimeViews, makeSymInfoView } from "./views/index.js";
|
|
14
15
|
function resolveCapacity(manifest) {
|
|
15
|
-
const
|
|
16
|
+
const { ohlcv, dynamicFallback } = manifest.seriesCapacities;
|
|
16
17
|
const fallback = manifest.maxLookback + 1;
|
|
17
|
-
|
|
18
|
+
// `dynamicFallback` is the compiler's §6.6 safety net: a non-literal
|
|
19
|
+
// series index (e.g. `trend[LOOKBACK]` with `const LOOKBACK = 20`)
|
|
20
|
+
// cannot be sized statically, so `extractMaxLookback` emits a 5000-slot
|
|
21
|
+
// request instead of bumping `maxLookback`. Honour it here — otherwise
|
|
22
|
+
// the buffer collapses to `maxLookback + 1` and every dynamic-index read
|
|
23
|
+
// past slot 0 returns NaN (the "forecast line never drawn" bug).
|
|
24
|
+
return Math.max(1, ohlcv ?? fallback, dynamicFallback ?? 0);
|
|
18
25
|
}
|
|
19
|
-
|
|
26
|
+
// A manifest produced BEFORE the multi-symbol feature has no `requestedFeeds`
|
|
27
|
+
// field but may carry `requestedIntervals`; projecting the interval list to
|
|
28
|
+
// symbol-omitted feeds keeps such a manifest mounting its main-symbol HTF
|
|
29
|
+
// streams. This `requestedFeeds ?? …` fallback is the apiVersion-1
|
|
30
|
+
// forward-compat seam; because `feedKey(undefined, iv) === iv`, the resulting
|
|
31
|
+
// keys equal today's interval keys exactly.
|
|
32
|
+
function legacyFeedsFromIntervals(manifest) {
|
|
33
|
+
return manifest.requestedIntervals.map((interval) => ({ interval }));
|
|
34
|
+
}
|
|
35
|
+
function createSecondaryStreams(manifest, capacity, chartSymbol) {
|
|
20
36
|
const streams = new Map();
|
|
21
|
-
|
|
22
|
-
|
|
37
|
+
const feeds = manifest.requestedFeeds ?? legacyFeedsFromIntervals(manifest);
|
|
38
|
+
for (const feed of feeds) {
|
|
39
|
+
// Collapse a feed whose symbol IS the chart symbol (omitted, or the
|
|
40
|
+
// author passed the chart's own ticker explicitly) to `undefined`
|
|
41
|
+
// BEFORE keying, mirroring `requestNamespace`'s resolution: `feedKey`
|
|
42
|
+
// then yields the bare interval, so both spellings hit one stream and
|
|
43
|
+
// the chart-symbol path stays byte-identical to the baseline. A
|
|
44
|
+
// genuinely different symbol survives as `"<symbol>@<interval>"`.
|
|
45
|
+
const resolved = feed.symbol === undefined || feed.symbol === chartSymbol ? undefined : feed.symbol;
|
|
46
|
+
const key = feedKey(resolved, feed.interval);
|
|
47
|
+
if (streams.has(key))
|
|
23
48
|
continue;
|
|
24
|
-
|
|
49
|
+
const symbol = feed.symbol ?? chartSymbol;
|
|
50
|
+
streams.set(key, createStreamState({ interval: feed.interval, capacity, symbol }));
|
|
25
51
|
}
|
|
26
52
|
return streams;
|
|
27
53
|
}
|
|
@@ -55,15 +81,24 @@ function pushSecondaryEvent(state, streamKey, event) {
|
|
|
55
81
|
pushUnknownSecondaryDiagnostic(state, streamKey);
|
|
56
82
|
return;
|
|
57
83
|
}
|
|
84
|
+
const ctx = state.runtimeContext;
|
|
58
85
|
switch (event.kind) {
|
|
59
86
|
case "history":
|
|
87
|
+
// History bars are finalised HTF closes: fill the buffer, then
|
|
88
|
+
// drive every registered runner once per bar in source order (a
|
|
89
|
+
// no-op until the main compute captures the callback).
|
|
60
90
|
appendSecondaryHistory(stream, event.bars);
|
|
91
|
+
for (const bar of event.bars) {
|
|
92
|
+
driveSecurityExpressions(ctx, streamKey, "close", bar);
|
|
93
|
+
}
|
|
61
94
|
return;
|
|
62
95
|
case "close":
|
|
63
96
|
appendSecondaryBar(stream, event.bar);
|
|
97
|
+
driveSecurityExpressions(ctx, streamKey, "close", event.bar);
|
|
64
98
|
return;
|
|
65
99
|
case "tick":
|
|
66
100
|
replaceSecondaryHead(stream, event.bar);
|
|
101
|
+
driveSecurityExpressions(ctx, streamKey, "tick", event.bar);
|
|
67
102
|
return;
|
|
68
103
|
}
|
|
69
104
|
}
|
|
@@ -72,8 +107,13 @@ function primaryOf(compiled) {
|
|
|
72
107
|
}
|
|
73
108
|
function buildPrimaryState(args, primary) {
|
|
74
109
|
const capacity = resolveCapacity(primary.manifest);
|
|
110
|
+
// The chart symbol is the adapter's `syminfo.ticker` when supplied — the
|
|
111
|
+
// single existing mount-time source (the main stream's `symbol` is `""`
|
|
112
|
+
// until bars flow). A symbol-omitted / explicit-chart-symbol request
|
|
113
|
+
// collapses against this value to the bare-interval feed key.
|
|
114
|
+
const chartSymbol = args.symInfo?.ticker ?? "";
|
|
75
115
|
const mainStream = createStreamState({ interval: "", capacity, symbol: "" });
|
|
76
|
-
const secondaryStreams = createSecondaryStreams(primary.manifest, capacity);
|
|
116
|
+
const secondaryStreams = createSecondaryStreams(primary.manifest, capacity, chartSymbol);
|
|
77
117
|
const stateStore = args.stateStore ?? inMemoryStateStore();
|
|
78
118
|
const now = args.now ?? Date.now;
|
|
79
119
|
const views = createRuntimeViews({
|
|
@@ -120,12 +160,16 @@ function buildPrimaryState(args, primary) {
|
|
|
120
160
|
},
|
|
121
161
|
scriptMaxDrawings: primary.manifest.maxDrawings ?? null,
|
|
122
162
|
stateSlots: new Map(),
|
|
163
|
+
seriesSlots: new Map(),
|
|
164
|
+
arraySlots: new Map(),
|
|
165
|
+
chartSymbol,
|
|
123
166
|
secondaryStreams,
|
|
124
167
|
requestSecurityBars: new Map(),
|
|
125
168
|
requestSecurityAlignments: new Map(),
|
|
126
169
|
requestSecurityAscendingBars: new Map(),
|
|
127
170
|
requestLowerTfViews: new Map(),
|
|
128
171
|
diagnosedRequestKeys: new Set(),
|
|
172
|
+
diagnosedTzKeys: new Set(),
|
|
129
173
|
alertConditions,
|
|
130
174
|
diagnosedAlertConditionKeys: new Set(),
|
|
131
175
|
logBudget: 0,
|
|
@@ -150,6 +194,10 @@ function buildPrimaryState(args, primary) {
|
|
|
150
194
|
args.plotOverrides ??
|
|
151
195
|
args.resolvePlotOverrides?.(primary.manifest.name) ??
|
|
152
196
|
Object.freeze({});
|
|
197
|
+
const exprRunners = buildSecurityExprRunners(primary.manifest, state.runtimeContext, capacity);
|
|
198
|
+
state.runtimeContext.securityExprRunners = exprRunners.bySlot;
|
|
199
|
+
state.runtimeContext.securityExprRunnersByFeed = exprRunners.byFeed;
|
|
200
|
+
state.runtimeContext.requestSecurityExprSeries = new Map();
|
|
153
201
|
return state;
|
|
154
202
|
}
|
|
155
203
|
function attachBundle(primary, bundle, capabilities, now) {
|
|
@@ -170,10 +218,12 @@ function attachBundle(primary, bundle, capabilities, now) {
|
|
|
170
218
|
})),
|
|
171
219
|
];
|
|
172
220
|
const store = createDepOutputStore({ producers, capacity: storeCapacity });
|
|
221
|
+
const { chartSymbol } = primary.runtimeContext;
|
|
173
222
|
const depRunners = bundle.dependencies.map((entry) => createDepRunner({
|
|
174
223
|
compiled: entry.compiled,
|
|
175
224
|
localId: entry.localId,
|
|
176
225
|
parentCapabilities: capabilities,
|
|
226
|
+
chartSymbol,
|
|
177
227
|
mainStream: primary.mainStream,
|
|
178
228
|
secondaryStreams: primary.runtimeContext.secondaryStreams,
|
|
179
229
|
depOutputStore: store,
|
|
@@ -184,6 +234,7 @@ function attachBundle(primary, bundle, capabilities, now) {
|
|
|
184
234
|
compiled: entry.compiled,
|
|
185
235
|
exportName: entry.exportName,
|
|
186
236
|
parentCapabilities: capabilities,
|
|
237
|
+
chartSymbol,
|
|
187
238
|
mainStream: primary.mainStream,
|
|
188
239
|
secondaryStreams: primary.runtimeContext.secondaryStreams,
|
|
189
240
|
depOutputStore: store,
|
|
@@ -205,10 +256,13 @@ function attachBundle(primary, bundle, capabilities, now) {
|
|
|
205
256
|
* `ACTIVE_RUNTIME_CONTEXT`. Phase 1 ships a single-stream model; the
|
|
206
257
|
* `requestedIntervals` field on the manifest is always empty.
|
|
207
258
|
*
|
|
208
|
-
* Capacity sizing follows PLAN §6.6:
|
|
259
|
+
* Capacity sizing follows PLAN §6.6: take the max of
|
|
209
260
|
* `manifest.seriesCapacities.ohlcv` (compiler-emitted per-series
|
|
210
|
-
* lookback)
|
|
211
|
-
*
|
|
261
|
+
* lookback) or the `manifest.maxLookback + 1` floor, and
|
|
262
|
+
* `manifest.seriesCapacities.dynamicFallback` (the 5000-slot safety net the
|
|
263
|
+
* compiler emits when a series is read at a non-literal index it cannot size
|
|
264
|
+
* statically), clamped to a minimum of 1 so an empty-history script still has
|
|
265
|
+
* a valid head slot.
|
|
212
266
|
*
|
|
213
267
|
* @since 0.1 — widened to accept `CompiledScriptBundle` in 0.7.
|
|
214
268
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createScriptRunner.js","sourceRoot":"","sources":["../src/createScriptRunner.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAe/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,OAAO,EAIH,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,sBAAsB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACxF,OAAO,EACH,OAAO,IAAI,WAAW,EACtB,KAAK,IAAI,SAAS,EAClB,UAAU,IAAI,cAAc,EAC5B,SAAS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C,CAAC;AACP,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 {\n CandleEvent,\n Capabilities,\n PlotOverride,\n RunnerEmissions,\n} from \"@invinite-org/chartlang-adapter-kit\";\nimport type {\n Bar,\n CompiledScriptBundle,\n CompiledScriptObject,\n ComputeFn,\n ScriptManifest,\n} from \"@invinite-org/chartlang-core\";\nimport { isCompiledScriptBundle } from \"@invinite-org/chartlang-core\";\n\nimport {\n type DepOutputStore,\n type DepRunner,\n type SiblingRunner,\n createDepOutputStore,\n createDepRunner,\n createSiblingRunner,\n installDepOutputGlobal,\n} from \"./dep/index.js\";\nimport { pushDiagnostic, resolveDefaultPane, resolveScriptPane } from \"./emit/index.js\";\nimport {\n dispose as disposeImpl,\n drain as drainImpl,\n onBarClose as onBarCloseImpl,\n onBarTick as onBarTickImpl,\n onHistory as onHistoryImpl,\n} from \"./execution/index.js\";\nimport {\n appendSecondaryBar,\n appendSecondaryHistory,\n replaceSecondaryHead,\n} from \"./execution/secondaryStream.js\";\nimport { resolveInputs } from \"./inputs/index.js\";\nimport type { PersistentStateStore } from \"./persistentStateStore.js\";\nimport {\n PERSISTENCE_INTERVAL_MS,\n maybeSaveStateSnapshot,\n restoreStateSnapshot,\n saveStateSnapshot,\n} from \"./persistentStateStore.runtime.js\";\nimport { validateSnapshot } from \"./persistentStateStore.validate.js\";\nimport type { MutableRunnerEmissions, RuntimeContext } from \"./runtimeContext.js\";\nimport { type StateStore, inMemoryStateStore } from \"./stateStore.js\";\nimport { type StreamState, createStreamState } from \"./streamState.js\";\nimport { type AdapterSymInfo, createRuntimeViews, makeSymInfoView } from \"./views/index.js\";\n\n/**\n * Internal handle the execution functions read and mutate per step. Lives\n * inside `createScriptRunner`'s closure; never exposed on the public\n * barrel. `barIndex` is the only mutable field — `onBarClose` increments\n * it; `onBarTick` does not.\n *\n * @since 0.1\n * @example\n * // RunnerState is internal — execution functions accept it as\n * // their first argument:\n * // await onBarClose(state, rawBar);\n */\nexport type RunnerState = {\n readonly manifest: ScriptManifest;\n readonly compute: ComputeFn;\n readonly capabilities: Capabilities;\n readonly stateStore: StateStore;\n readonly persistenceIntervalMs: number;\n readonly now: () => number;\n readonly mainStream: StreamState;\n readonly runtimeContext: RuntimeContext;\n readonly emissions: MutableRunnerEmissions;\n /**\n * Sub-runners for every private dep entry of a\n * `CompiledScriptBundle`. Empty array for single-script callers.\n * Walked in declaration order before the primary's compute each\n * bar. @since 0.7\n */\n readonly depRunners: ReadonlyArray<DepRunner>;\n /**\n * Sub-runners for every drawn named-export entry of a\n * `CompiledScriptBundle`. Empty for single-script callers.\n * Walked in declaration order after deps, before the primary's\n * compute. @since 0.7\n */\n readonly siblingRunners: ReadonlyArray<SiblingRunner>;\n /**\n * Shared titled-output buffer for the bundle. `null` for\n * single-script callers (no deps to read from). @since 0.7\n */\n readonly depOutputStore: DepOutputStore | null;\n /**\n * Per-bar flag set by `runDepStep` when any dep halts. Read by\n * `onBarClose` / `onBarTick` after the primary's compute returns,\n * clearing the primary's plot/drawing/alert queues. Reset at the\n * top of every bar. @since 0.7\n */\n depErroredThisBar: boolean;\n barIndex: number;\n};\n\n/**\n * The user-facing handle `createScriptRunner` returns. Hosts (Worker,\n * QuickJS, conformance harness) drive a `ScriptRunner` through the\n * standard lifecycle: `load → onHistory → onBarClose × N → onBarTick × M\n * → drain → dispose`. PLAN §6.1 fixes this shape; consumer-repo hosts\n * pin against it.\n *\n * `onHistory` / `onBarClose` / `onBarTick` return `Promise<void>` — the\n * runtime allows compute bodies to `await` (Phase 1 doesn't, but the\n * surface is forward-compatible with Phase-5 `request.security` warmup).\n *\n * @since 0.1\n * @example\n * // import { createScriptRunner }\n * // from \"@invinite-org/chartlang-runtime\";\n * // const runner = createScriptRunner({ compiled, capabilities });\n * // await runner.onHistory(historicalBars);\n * // const emissions = runner.drain();\n * // runner.dispose();\n */\nexport type ScriptRunner = {\n onHistory(bars: ReadonlyArray<Bar>): Promise<void>;\n onBarClose(bar: Bar): Promise<void>;\n onBarTick(bar: Bar): Promise<void>;\n push(event: CandleEvent): Promise<void>;\n warmStart(currentMainBarTime: number): Promise<void>;\n drain(): RunnerEmissions;\n /**\n * Replace the per-slot presentation override map live. Cheap and\n * recompute-free — the swap takes effect on the NEXT push's\n * `compute`; the just-pushed bar's drain returns the pre-swap\n * emissions (already baked during that bar's `compute`). Entries\n * are frozen on assignment; overrides are presentation-only and\n * never feed `compute`.\n *\n * @since 0.8\n * @stable\n * @example\n * // runner.setPlotOverrides({ \"ema.chart.ts:12:5#0\": { visible: false } });\n */\n setPlotOverrides(next: Readonly<Record<string, PlotOverride>>): void;\n dispose(): Promise<void>;\n};\n\n/**\n * Constructor arguments for {@link createScriptRunner}. `stateStore`\n * defaults to {@link inMemoryStateStore} so callers without persistence\n * needs can omit it. `symInfo` defaults to empty sentinels and is gated\n * by `capabilities.symInfoFields` at mount. `resolveInputs` is called\n * once at mount with `manifest.name`; worker-backed callers can pass an\n * already structured-cloned `inputOverrides` record instead.\n * `persistentStateStore` is the PLAN §6.9 cross-mount snapshot store;\n * `persistenceIntervalMs` defaults to 60 seconds.\n *\n * @since 0.1\n * @example\n * // const args: CreateScriptRunnerArgs = {\n * // compiled,\n * // capabilities,\n * // stateStore: inMemoryStateStore(),\n * // };\n */\nexport type CreateScriptRunnerArgs = {\n /**\n * Either a single `CompiledScriptObject` (Phase-1 contract — preserved\n * byte-identically) or a `CompiledScriptBundle` whose primary script\n * is mounted alongside one `DepRunner` per private dep entry and one\n * `SiblingRunner` per drawn named export.\n *\n * @since 0.1 — widened to bundle in 0.7\n */\n readonly compiled: CompiledScriptObject | CompiledScriptBundle;\n readonly capabilities: Capabilities;\n readonly stateStore?: StateStore;\n readonly persistentStateStore?: PersistentStateStore;\n readonly persistenceIntervalMs?: number;\n readonly now?: () => number;\n readonly symInfo?: AdapterSymInfo;\n readonly resolveInputs?: (scriptId: string) => Readonly<Record<string, unknown>>;\n readonly inputOverrides?: Readonly<Record<string, unknown>>;\n readonly resolvePlotOverrides?: (scriptId: string) => Readonly<Record<string, PlotOverride>>;\n readonly plotOverrides?: Readonly<Record<string, PlotOverride>>;\n};\n\nfunction resolveCapacity(manifest: ScriptManifest): number {\n const requested = manifest.seriesCapacities.ohlcv;\n const fallback = manifest.maxLookback + 1;\n return Math.max(1, requested ?? fallback);\n}\n\nfunction createSecondaryStreams(\n manifest: ScriptManifest,\n capacity: number,\n): Map<string, StreamState> {\n const streams = new Map<string, StreamState>();\n for (const interval of manifest.requestedIntervals) {\n if (streams.has(interval)) continue;\n streams.set(interval, createStreamState({ interval, capacity, symbol: \"\" }));\n }\n return streams;\n}\n\nasync function pushMainEvent(state: RunnerState, event: CandleEvent): Promise<void> {\n switch (event.kind) {\n case \"history\":\n await onHistoryImpl(state, event.bars);\n return;\n case \"close\":\n await onBarCloseImpl(state, event.bar);\n await maybeSaveStateSnapshot(state, state.now(), state.persistenceIntervalMs);\n return;\n case \"tick\":\n await onBarTickImpl(state, event.bar);\n return;\n }\n}\n\nfunction pushUnknownSecondaryDiagnostic(state: RunnerState, streamKey: string): void {\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"warning\",\n code: \"unknown-secondary-stream\",\n message: `Secondary stream \"${streamKey}\" was not registered by the script manifest`,\n slotId: null,\n bar: state.barIndex,\n });\n}\n\nfunction pushSecondaryEvent(state: RunnerState, streamKey: string, event: CandleEvent): void {\n const stream = state.runtimeContext.secondaryStreams.get(streamKey);\n if (stream === undefined) {\n pushUnknownSecondaryDiagnostic(state, streamKey);\n return;\n }\n switch (event.kind) {\n case \"history\":\n appendSecondaryHistory(stream, event.bars);\n return;\n case \"close\":\n appendSecondaryBar(stream, event.bar);\n return;\n case \"tick\":\n replaceSecondaryHead(stream, event.bar);\n return;\n }\n}\n\nfunction primaryOf(compiled: CompiledScriptObject | CompiledScriptBundle): CompiledScriptObject {\n return isCompiledScriptBundle(compiled) ? compiled.primary : compiled;\n}\n\nfunction buildPrimaryState(\n args: CreateScriptRunnerArgs,\n primary: CompiledScriptObject,\n): RunnerState {\n const capacity = resolveCapacity(primary.manifest);\n const mainStream = createStreamState({ interval: \"\", capacity, symbol: \"\" });\n const secondaryStreams = createSecondaryStreams(primary.manifest, capacity);\n const stateStore = args.stateStore ?? inMemoryStateStore();\n const now = args.now ?? Date.now;\n const views = createRuntimeViews({\n syminfo: makeSymInfoView(args.symInfo ?? {}, args.capabilities.symInfoFields),\n });\n const emissions: MutableRunnerEmissions = {\n plots: [],\n drawings: [],\n alerts: [],\n alertConditions: [],\n logs: [],\n diagnostics: [],\n fromBar: 0,\n toBar: 0,\n };\n const alertConditions = new Map(\n (primary.manifest.alertConditions ?? []).map((condition) => [condition.id, condition]),\n );\n\n const state: RunnerState = {\n manifest: primary.manifest,\n compute: primary.compute,\n capabilities: args.capabilities,\n stateStore,\n persistenceIntervalMs: args.persistenceIntervalMs ?? PERSISTENCE_INTERVAL_MS,\n now,\n mainStream,\n runtimeContext: {\n stream: mainStream,\n stateStore,\n ...(args.persistentStateStore === undefined\n ? {}\n : { persistentStateStore: args.persistentStateStore }),\n lastPersistTime: 0,\n capabilities: args.capabilities,\n emissions,\n barIndex: () => state.barIndex,\n isTick: false,\n drawingSlots: new Map(),\n drawingSubIdCounters: new Map(),\n drawingBucketCounters: {\n lines: 0,\n labels: 0,\n boxes: 0,\n polylines: 0,\n other: 0,\n },\n scriptMaxDrawings: primary.manifest.maxDrawings ?? null,\n stateSlots: new Map(),\n secondaryStreams,\n requestSecurityBars: new Map(),\n requestSecurityAlignments: new Map(),\n requestSecurityAscendingBars: new Map(),\n requestLowerTfViews: new Map(),\n diagnosedRequestKeys: new Set(),\n alertConditions,\n diagnosedAlertConditionKeys: new Set(),\n logBudget: 0,\n logBudgetExceededDiagnosed: false,\n resolvedInputs: Object.freeze({}),\n defaultPane: resolveDefaultPane(primary.manifest),\n scriptPane: resolveScriptPane(primary.manifest),\n plotOverrides: Object.freeze({}),\n diagnosedInputKeys: new Set(),\n views,\n },\n emissions,\n depRunners: [],\n siblingRunners: [],\n depOutputStore: null,\n depErroredThisBar: false,\n barIndex: 0,\n };\n const overrides =\n args.inputOverrides ?? args.resolveInputs?.(primary.manifest.name) ?? Object.freeze({});\n state.runtimeContext.resolvedInputs = resolveInputs(\n primary.manifest,\n overrides,\n state.runtimeContext,\n );\n state.runtimeContext.plotOverrides =\n args.plotOverrides ??\n args.resolvePlotOverrides?.(primary.manifest.name) ??\n Object.freeze({});\n return state;\n}\n\nfunction attachBundle(\n primary: RunnerState,\n bundle: CompiledScriptBundle,\n capabilities: Capabilities,\n now: () => number,\n): void {\n const consumerLookback = Math.max(\n primary.manifest.maxLookback,\n ...bundle.siblings.map((s) => s.compiled.manifest.maxLookback),\n );\n const storeCapacity = Math.max(1, consumerLookback + 1);\n const producers = [\n ...bundle.dependencies.map((d) => ({\n producerId: d.localId,\n outputs: (d.compiled.manifest.outputs ?? []).map((o) => ({\n title: o.title,\n })),\n })),\n ...bundle.siblings.map((s) => ({\n producerId: s.exportName,\n outputs: (s.compiled.manifest.outputs ?? []).map((o) => ({\n title: o.title,\n })),\n })),\n ];\n const store = createDepOutputStore({ producers, capacity: storeCapacity });\n const depRunners: DepRunner[] = bundle.dependencies.map((entry) =>\n createDepRunner({\n compiled: entry.compiled,\n localId: entry.localId,\n parentCapabilities: capabilities,\n mainStream: primary.mainStream,\n secondaryStreams: primary.runtimeContext.secondaryStreams,\n depOutputStore: store,\n inputOverrides: entry.inputOverrides ?? Object.freeze({}),\n now,\n }),\n );\n const siblingRunners: SiblingRunner[] = bundle.siblings.map((entry) =>\n createSiblingRunner({\n compiled: entry.compiled,\n exportName: entry.exportName,\n parentCapabilities: capabilities,\n mainStream: primary.mainStream,\n secondaryStreams: primary.runtimeContext.secondaryStreams,\n depOutputStore: store,\n inputOverrides: Object.freeze({}),\n now,\n }),\n );\n Object.assign(primary, {\n depRunners,\n siblingRunners,\n depOutputStore: store,\n });\n primary.runtimeContext.depOutputStore = store;\n installDepOutputGlobal();\n}\n\n/**\n * Build a `ScriptRunner` for a compiled chartlang script. The runner\n * owns one `StreamState`, one `MutableRunnerEmissions` queue set, and\n * the `RuntimeContext` Task 7-8 primitives read through\n * `ACTIVE_RUNTIME_CONTEXT`. Phase 1 ships a single-stream model; the\n * `requestedIntervals` field on the manifest is always empty.\n *\n * Capacity sizing follows PLAN §6.6: prefer\n * `manifest.seriesCapacities.ohlcv` (compiler-emitted per-series\n * lookback) and fall back to `manifest.maxLookback + 1`, clamped to a\n * minimum of 1 so an empty-history script still has a valid head slot.\n *\n * @since 0.1 — widened to accept `CompiledScriptBundle` in 0.7.\n * @example\n * // import { createScriptRunner } from \"@invinite-org/chartlang-runtime\";\n * // const runner = createScriptRunner({ compiled, capabilities });\n * // await runner.onHistory([]);\n * // runner.drain();\n * // runner.dispose();\n */\nexport function createScriptRunner(args: CreateScriptRunnerArgs): ScriptRunner {\n const primary = primaryOf(args.compiled);\n const state = buildPrimaryState(args, primary);\n if (isCompiledScriptBundle(args.compiled)) {\n attachBundle(state, args.compiled, args.capabilities, state.now);\n }\n\n return Object.freeze({\n async onHistory(bars) {\n await onHistoryImpl(state, bars);\n },\n async onBarClose(bar) {\n await onBarCloseImpl(state, bar);\n await maybeSaveStateSnapshot(state, state.now(), state.persistenceIntervalMs);\n },\n async onBarTick(bar) {\n await onBarTickImpl(state, bar);\n },\n async push(event) {\n if (event.streamKey === undefined) {\n await pushMainEvent(state, event);\n return;\n }\n pushSecondaryEvent(state, event.streamKey, event);\n },\n async warmStart(currentMainBarTime) {\n const store = state.runtimeContext.persistentStateStore;\n if (store === undefined) return;\n const snap = await store.load();\n if (snap === null) return;\n if (!validateSnapshot(snap)) return;\n if (snap.lastBarTime >= currentMainBarTime) {\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"warning\",\n code: \"state-snapshot-future-dated\",\n message: \"persistent state snapshot is ahead of the current bar cursor\",\n slotId: null,\n bar: state.barIndex,\n });\n try {\n await store.clear();\n } catch (err) {\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"warning\",\n code: \"state-snapshot-save-failed\",\n message: err instanceof Error ? err.message : String(err),\n slotId: null,\n bar: state.barIndex,\n });\n }\n return;\n }\n restoreStateSnapshot(state, snap);\n state.runtimeContext.lastPersistTime = snap.savedAt;\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"info\",\n code: \"state-snapshot-restored\",\n message: `persistent state snapshot restored through bar ${snap.lastBarTime}`,\n slotId: null,\n bar: state.barIndex,\n });\n },\n drain() {\n return drainImpl(state);\n },\n setPlotOverrides(next) {\n state.runtimeContext.plotOverrides = Object.freeze({ ...next });\n },\n async dispose() {\n const finalSave = saveStateSnapshot(state, state.now());\n disposeImpl(state);\n await finalSave;\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"createScriptRunner.js","sourceRoot":"","sources":["../src/createScriptRunner.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAgB/D,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAE/E,OAAO,EAIH,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,sBAAsB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACxF,OAAO,EACH,OAAO,IAAI,WAAW,EACtB,KAAK,IAAI,SAAS,EAClB,UAAU,IAAI,cAAc,EAC5B,SAAS,IAAI,aAAa,EAC1B,SAAS,IAAI,aAAa,GAC7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EACH,uBAAuB,EACvB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,GACpB,MAAM,mC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C,WAAW,EAAE;gBAC7E,MAAM,EAAE,IAAI;gBACZ,GAAG,EAAE,KAAK,CAAC,QAAQ;aACtB,CAAC,CAAC;QACP,CAAC;QACD,KAAK;YACD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;QACD,gBAAgB,CAAC,IAAI;YACjB,KAAK,CAAC,cAAc,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,KAAK,CAAC,OAAO;YACT,MAAM,SAAS,GAAG,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;YACxD,WAAW,CAAC,KAAK,CAAC,CAAC;YACnB,MAAM,SAAS,CAAC;QACpB,CAAC;KACJ,CAAC,CAAC;AACP,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 {\n CandleEvent,\n Capabilities,\n PlotOverride,\n RunnerEmissions,\n} from \"@invinite-org/chartlang-adapter-kit\";\nimport type {\n Bar,\n CompiledScriptBundle,\n CompiledScriptObject,\n ComputeFn,\n RequestedFeed,\n ScriptManifest,\n} from \"@invinite-org/chartlang-core\";\nimport { feedKey, isCompiledScriptBundle } from \"@invinite-org/chartlang-core\";\n\nimport {\n type DepOutputStore,\n type DepRunner,\n type SiblingRunner,\n createDepOutputStore,\n createDepRunner,\n createSiblingRunner,\n installDepOutputGlobal,\n} from \"./dep/index.js\";\nimport { pushDiagnostic, resolveDefaultPane, resolveScriptPane } from \"./emit/index.js\";\nimport {\n dispose as disposeImpl,\n drain as drainImpl,\n onBarClose as onBarCloseImpl,\n onBarTick as onBarTickImpl,\n onHistory as onHistoryImpl,\n} from \"./execution/index.js\";\nimport {\n appendSecondaryBar,\n appendSecondaryHistory,\n replaceSecondaryHead,\n} from \"./execution/secondaryStream.js\";\nimport { resolveInputs } from \"./inputs/index.js\";\nimport type { PersistentStateStore } from \"./persistentStateStore.js\";\nimport {\n PERSISTENCE_INTERVAL_MS,\n maybeSaveStateSnapshot,\n restoreStateSnapshot,\n saveStateSnapshot,\n} from \"./persistentStateStore.runtime.js\";\nimport { validateSnapshot } from \"./persistentStateStore.validate.js\";\nimport {\n buildSecurityExprRunners,\n driveSecurityExpressions,\n} from \"./request/securityExprRunner.js\";\nimport type { MutableRunnerEmissions, RuntimeContext } from \"./runtimeContext.js\";\nimport { type StateStore, inMemoryStateStore } from \"./stateStore.js\";\nimport { type StreamState, createStreamState } from \"./streamState.js\";\nimport { type AdapterSymInfo, createRuntimeViews, makeSymInfoView } from \"./views/index.js\";\n\n/**\n * Internal handle the execution functions read and mutate per step. Lives\n * inside `createScriptRunner`'s closure; never exposed on the public\n * barrel. `barIndex` is the only mutable field — `onBarClose` increments\n * it; `onBarTick` does not.\n *\n * @since 0.1\n * @example\n * // RunnerState is internal — execution functions accept it as\n * // their first argument:\n * // await onBarClose(state, rawBar);\n */\nexport type RunnerState = {\n readonly manifest: ScriptManifest;\n readonly compute: ComputeFn;\n readonly capabilities: Capabilities;\n readonly stateStore: StateStore;\n readonly persistenceIntervalMs: number;\n readonly now: () => number;\n readonly mainStream: StreamState;\n readonly runtimeContext: RuntimeContext;\n readonly emissions: MutableRunnerEmissions;\n /**\n * Sub-runners for every private dep entry of a\n * `CompiledScriptBundle`. Empty array for single-script callers.\n * Walked in declaration order before the primary's compute each\n * bar. @since 0.7\n */\n readonly depRunners: ReadonlyArray<DepRunner>;\n /**\n * Sub-runners for every drawn named-export entry of a\n * `CompiledScriptBundle`. Empty for single-script callers.\n * Walked in declaration order after deps, before the primary's\n * compute. @since 0.7\n */\n readonly siblingRunners: ReadonlyArray<SiblingRunner>;\n /**\n * Shared titled-output buffer for the bundle. `null` for\n * single-script callers (no deps to read from). @since 0.7\n */\n readonly depOutputStore: DepOutputStore | null;\n /**\n * Per-bar flag set by `runDepStep` when any dep halts. Read by\n * `onBarClose` / `onBarTick` after the primary's compute returns,\n * clearing the primary's plot/drawing/alert queues. Reset at the\n * top of every bar. @since 0.7\n */\n depErroredThisBar: boolean;\n barIndex: number;\n};\n\n/**\n * The user-facing handle `createScriptRunner` returns. Hosts (Worker,\n * QuickJS, conformance harness) drive a `ScriptRunner` through the\n * standard lifecycle: `load → onHistory → onBarClose × N → onBarTick × M\n * → drain → dispose`. PLAN §6.1 fixes this shape; consumer-repo hosts\n * pin against it.\n *\n * `onHistory` / `onBarClose` / `onBarTick` return `Promise<void>` — the\n * runtime allows compute bodies to `await` (Phase 1 doesn't, but the\n * surface is forward-compatible with Phase-5 `request.security` warmup).\n *\n * @since 0.1\n * @example\n * // import { createScriptRunner }\n * // from \"@invinite-org/chartlang-runtime\";\n * // const runner = createScriptRunner({ compiled, capabilities });\n * // await runner.onHistory(historicalBars);\n * // const emissions = runner.drain();\n * // runner.dispose();\n */\nexport type ScriptRunner = {\n onHistory(bars: ReadonlyArray<Bar>): Promise<void>;\n onBarClose(bar: Bar): Promise<void>;\n onBarTick(bar: Bar): Promise<void>;\n push(event: CandleEvent): Promise<void>;\n warmStart(currentMainBarTime: number): Promise<void>;\n drain(): RunnerEmissions;\n /**\n * Replace the per-slot presentation override map live. Cheap and\n * recompute-free — the swap takes effect on the NEXT push's\n * `compute`; the just-pushed bar's drain returns the pre-swap\n * emissions (already baked during that bar's `compute`). Entries\n * are frozen on assignment; overrides are presentation-only and\n * never feed `compute`.\n *\n * @since 0.8\n * @stable\n * @example\n * // runner.setPlotOverrides({ \"ema.chart.ts:12:5#0\": { visible: false } });\n */\n setPlotOverrides(next: Readonly<Record<string, PlotOverride>>): void;\n dispose(): Promise<void>;\n};\n\n/**\n * Constructor arguments for {@link createScriptRunner}. `stateStore`\n * defaults to {@link inMemoryStateStore} so callers without persistence\n * needs can omit it. `symInfo` defaults to empty sentinels and is gated\n * by `capabilities.symInfoFields` at mount. `resolveInputs` is called\n * once at mount with `manifest.name`; worker-backed callers can pass an\n * already structured-cloned `inputOverrides` record instead.\n * `persistentStateStore` is the PLAN §6.9 cross-mount snapshot store;\n * `persistenceIntervalMs` defaults to 60 seconds.\n *\n * @since 0.1\n * @example\n * // const args: CreateScriptRunnerArgs = {\n * // compiled,\n * // capabilities,\n * // stateStore: inMemoryStateStore(),\n * // };\n */\nexport type CreateScriptRunnerArgs = {\n /**\n * Either a single `CompiledScriptObject` (Phase-1 contract — preserved\n * byte-identically) or a `CompiledScriptBundle` whose primary script\n * is mounted alongside one `DepRunner` per private dep entry and one\n * `SiblingRunner` per drawn named export.\n *\n * @since 0.1 — widened to bundle in 0.7\n */\n readonly compiled: CompiledScriptObject | CompiledScriptBundle;\n readonly capabilities: Capabilities;\n readonly stateStore?: StateStore;\n readonly persistentStateStore?: PersistentStateStore;\n readonly persistenceIntervalMs?: number;\n readonly now?: () => number;\n readonly symInfo?: AdapterSymInfo;\n readonly resolveInputs?: (scriptId: string) => Readonly<Record<string, unknown>>;\n readonly inputOverrides?: Readonly<Record<string, unknown>>;\n readonly resolvePlotOverrides?: (scriptId: string) => Readonly<Record<string, PlotOverride>>;\n readonly plotOverrides?: Readonly<Record<string, PlotOverride>>;\n};\n\nfunction resolveCapacity(manifest: ScriptManifest): number {\n const { ohlcv, dynamicFallback } = manifest.seriesCapacities;\n const fallback = manifest.maxLookback + 1;\n // `dynamicFallback` is the compiler's §6.6 safety net: a non-literal\n // series index (e.g. `trend[LOOKBACK]` with `const LOOKBACK = 20`)\n // cannot be sized statically, so `extractMaxLookback` emits a 5000-slot\n // request instead of bumping `maxLookback`. Honour it here — otherwise\n // the buffer collapses to `maxLookback + 1` and every dynamic-index read\n // past slot 0 returns NaN (the \"forecast line never drawn\" bug).\n return Math.max(1, ohlcv ?? fallback, dynamicFallback ?? 0);\n}\n\n// A manifest produced BEFORE the multi-symbol feature has no `requestedFeeds`\n// field but may carry `requestedIntervals`; projecting the interval list to\n// symbol-omitted feeds keeps such a manifest mounting its main-symbol HTF\n// streams. This `requestedFeeds ?? …` fallback is the apiVersion-1\n// forward-compat seam; because `feedKey(undefined, iv) === iv`, the resulting\n// keys equal today's interval keys exactly.\nfunction legacyFeedsFromIntervals(manifest: ScriptManifest): RequestedFeed[] {\n return manifest.requestedIntervals.map((interval) => ({ interval }));\n}\n\nfunction createSecondaryStreams(\n manifest: ScriptManifest,\n capacity: number,\n chartSymbol: string,\n): Map<string, StreamState> {\n const streams = new Map<string, StreamState>();\n const feeds = manifest.requestedFeeds ?? legacyFeedsFromIntervals(manifest);\n for (const feed of feeds) {\n // Collapse a feed whose symbol IS the chart symbol (omitted, or the\n // author passed the chart's own ticker explicitly) to `undefined`\n // BEFORE keying, mirroring `requestNamespace`'s resolution: `feedKey`\n // then yields the bare interval, so both spellings hit one stream and\n // the chart-symbol path stays byte-identical to the baseline. A\n // genuinely different symbol survives as `\"<symbol>@<interval>\"`.\n const resolved =\n feed.symbol === undefined || feed.symbol === chartSymbol ? undefined : feed.symbol;\n const key = feedKey(resolved, feed.interval);\n if (streams.has(key)) continue;\n const symbol = feed.symbol ?? chartSymbol;\n streams.set(key, createStreamState({ interval: feed.interval, capacity, symbol }));\n }\n return streams;\n}\n\nasync function pushMainEvent(state: RunnerState, event: CandleEvent): Promise<void> {\n switch (event.kind) {\n case \"history\":\n await onHistoryImpl(state, event.bars);\n return;\n case \"close\":\n await onBarCloseImpl(state, event.bar);\n await maybeSaveStateSnapshot(state, state.now(), state.persistenceIntervalMs);\n return;\n case \"tick\":\n await onBarTickImpl(state, event.bar);\n return;\n }\n}\n\nfunction pushUnknownSecondaryDiagnostic(state: RunnerState, streamKey: string): void {\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"warning\",\n code: \"unknown-secondary-stream\",\n message: `Secondary stream \"${streamKey}\" was not registered by the script manifest`,\n slotId: null,\n bar: state.barIndex,\n });\n}\n\nfunction pushSecondaryEvent(state: RunnerState, streamKey: string, event: CandleEvent): void {\n const stream = state.runtimeContext.secondaryStreams.get(streamKey);\n if (stream === undefined) {\n pushUnknownSecondaryDiagnostic(state, streamKey);\n return;\n }\n const ctx = state.runtimeContext;\n switch (event.kind) {\n case \"history\":\n // History bars are finalised HTF closes: fill the buffer, then\n // drive every registered runner once per bar in source order (a\n // no-op until the main compute captures the callback).\n appendSecondaryHistory(stream, event.bars);\n for (const bar of event.bars) {\n driveSecurityExpressions(ctx, streamKey, \"close\", bar);\n }\n return;\n case \"close\":\n appendSecondaryBar(stream, event.bar);\n driveSecurityExpressions(ctx, streamKey, \"close\", event.bar);\n return;\n case \"tick\":\n replaceSecondaryHead(stream, event.bar);\n driveSecurityExpressions(ctx, streamKey, \"tick\", event.bar);\n return;\n }\n}\n\nfunction primaryOf(compiled: CompiledScriptObject | CompiledScriptBundle): CompiledScriptObject {\n return isCompiledScriptBundle(compiled) ? compiled.primary : compiled;\n}\n\nfunction buildPrimaryState(\n args: CreateScriptRunnerArgs,\n primary: CompiledScriptObject,\n): RunnerState {\n const capacity = resolveCapacity(primary.manifest);\n // The chart symbol is the adapter's `syminfo.ticker` when supplied — the\n // single existing mount-time source (the main stream's `symbol` is `\"\"`\n // until bars flow). A symbol-omitted / explicit-chart-symbol request\n // collapses against this value to the bare-interval feed key.\n const chartSymbol = args.symInfo?.ticker ?? \"\";\n const mainStream = createStreamState({ interval: \"\", capacity, symbol: \"\" });\n const secondaryStreams = createSecondaryStreams(primary.manifest, capacity, chartSymbol);\n const stateStore = args.stateStore ?? inMemoryStateStore();\n const now = args.now ?? Date.now;\n const views = createRuntimeViews({\n syminfo: makeSymInfoView(args.symInfo ?? {}, args.capabilities.symInfoFields),\n });\n const emissions: MutableRunnerEmissions = {\n plots: [],\n drawings: [],\n alerts: [],\n alertConditions: [],\n logs: [],\n diagnostics: [],\n fromBar: 0,\n toBar: 0,\n };\n const alertConditions = new Map(\n (primary.manifest.alertConditions ?? []).map((condition) => [condition.id, condition]),\n );\n\n const state: RunnerState = {\n manifest: primary.manifest,\n compute: primary.compute,\n capabilities: args.capabilities,\n stateStore,\n persistenceIntervalMs: args.persistenceIntervalMs ?? PERSISTENCE_INTERVAL_MS,\n now,\n mainStream,\n runtimeContext: {\n stream: mainStream,\n stateStore,\n ...(args.persistentStateStore === undefined\n ? {}\n : { persistentStateStore: args.persistentStateStore }),\n lastPersistTime: 0,\n capabilities: args.capabilities,\n emissions,\n barIndex: () => state.barIndex,\n isTick: false,\n drawingSlots: new Map(),\n drawingSubIdCounters: new Map(),\n drawingBucketCounters: {\n lines: 0,\n labels: 0,\n boxes: 0,\n polylines: 0,\n other: 0,\n },\n scriptMaxDrawings: primary.manifest.maxDrawings ?? null,\n stateSlots: new Map(),\n seriesSlots: new Map(),\n arraySlots: new Map(),\n chartSymbol,\n secondaryStreams,\n requestSecurityBars: new Map(),\n requestSecurityAlignments: new Map(),\n requestSecurityAscendingBars: new Map(),\n requestLowerTfViews: new Map(),\n diagnosedRequestKeys: new Set(),\n diagnosedTzKeys: new Set(),\n alertConditions,\n diagnosedAlertConditionKeys: new Set(),\n logBudget: 0,\n logBudgetExceededDiagnosed: false,\n resolvedInputs: Object.freeze({}),\n defaultPane: resolveDefaultPane(primary.manifest),\n scriptPane: resolveScriptPane(primary.manifest),\n plotOverrides: Object.freeze({}),\n diagnosedInputKeys: new Set(),\n views,\n },\n emissions,\n depRunners: [],\n siblingRunners: [],\n depOutputStore: null,\n depErroredThisBar: false,\n barIndex: 0,\n };\n const overrides =\n args.inputOverrides ?? args.resolveInputs?.(primary.manifest.name) ?? Object.freeze({});\n state.runtimeContext.resolvedInputs = resolveInputs(\n primary.manifest,\n overrides,\n state.runtimeContext,\n );\n state.runtimeContext.plotOverrides =\n args.plotOverrides ??\n args.resolvePlotOverrides?.(primary.manifest.name) ??\n Object.freeze({});\n const exprRunners = buildSecurityExprRunners(primary.manifest, state.runtimeContext, capacity);\n state.runtimeContext.securityExprRunners = exprRunners.bySlot;\n state.runtimeContext.securityExprRunnersByFeed = exprRunners.byFeed;\n state.runtimeContext.requestSecurityExprSeries = new Map();\n return state;\n}\n\nfunction attachBundle(\n primary: RunnerState,\n bundle: CompiledScriptBundle,\n capabilities: Capabilities,\n now: () => number,\n): void {\n const consumerLookback = Math.max(\n primary.manifest.maxLookback,\n ...bundle.siblings.map((s) => s.compiled.manifest.maxLookback),\n );\n const storeCapacity = Math.max(1, consumerLookback + 1);\n const producers = [\n ...bundle.dependencies.map((d) => ({\n producerId: d.localId,\n outputs: (d.compiled.manifest.outputs ?? []).map((o) => ({\n title: o.title,\n })),\n })),\n ...bundle.siblings.map((s) => ({\n producerId: s.exportName,\n outputs: (s.compiled.manifest.outputs ?? []).map((o) => ({\n title: o.title,\n })),\n })),\n ];\n const store = createDepOutputStore({ producers, capacity: storeCapacity });\n const { chartSymbol } = primary.runtimeContext;\n const depRunners: DepRunner[] = bundle.dependencies.map((entry) =>\n createDepRunner({\n compiled: entry.compiled,\n localId: entry.localId,\n parentCapabilities: capabilities,\n chartSymbol,\n mainStream: primary.mainStream,\n secondaryStreams: primary.runtimeContext.secondaryStreams,\n depOutputStore: store,\n inputOverrides: entry.inputOverrides ?? Object.freeze({}),\n now,\n }),\n );\n const siblingRunners: SiblingRunner[] = bundle.siblings.map((entry) =>\n createSiblingRunner({\n compiled: entry.compiled,\n exportName: entry.exportName,\n parentCapabilities: capabilities,\n chartSymbol,\n mainStream: primary.mainStream,\n secondaryStreams: primary.runtimeContext.secondaryStreams,\n depOutputStore: store,\n inputOverrides: Object.freeze({}),\n now,\n }),\n );\n Object.assign(primary, {\n depRunners,\n siblingRunners,\n depOutputStore: store,\n });\n primary.runtimeContext.depOutputStore = store;\n installDepOutputGlobal();\n}\n\n/**\n * Build a `ScriptRunner` for a compiled chartlang script. The runner\n * owns one `StreamState`, one `MutableRunnerEmissions` queue set, and\n * the `RuntimeContext` Task 7-8 primitives read through\n * `ACTIVE_RUNTIME_CONTEXT`. Phase 1 ships a single-stream model; the\n * `requestedIntervals` field on the manifest is always empty.\n *\n * Capacity sizing follows PLAN §6.6: take the max of\n * `manifest.seriesCapacities.ohlcv` (compiler-emitted per-series\n * lookback) or the `manifest.maxLookback + 1` floor, and\n * `manifest.seriesCapacities.dynamicFallback` (the 5000-slot safety net the\n * compiler emits when a series is read at a non-literal index it cannot size\n * statically), clamped to a minimum of 1 so an empty-history script still has\n * a valid head slot.\n *\n * @since 0.1 — widened to accept `CompiledScriptBundle` in 0.7.\n * @example\n * // import { createScriptRunner } from \"@invinite-org/chartlang-runtime\";\n * // const runner = createScriptRunner({ compiled, capabilities });\n * // await runner.onHistory([]);\n * // runner.drain();\n * // runner.dispose();\n */\nexport function createScriptRunner(args: CreateScriptRunnerArgs): ScriptRunner {\n const primary = primaryOf(args.compiled);\n const state = buildPrimaryState(args, primary);\n if (isCompiledScriptBundle(args.compiled)) {\n attachBundle(state, args.compiled, args.capabilities, state.now);\n }\n\n return Object.freeze({\n async onHistory(bars) {\n await onHistoryImpl(state, bars);\n },\n async onBarClose(bar) {\n await onBarCloseImpl(state, bar);\n await maybeSaveStateSnapshot(state, state.now(), state.persistenceIntervalMs);\n },\n async onBarTick(bar) {\n await onBarTickImpl(state, bar);\n },\n async push(event) {\n if (event.streamKey === undefined) {\n await pushMainEvent(state, event);\n return;\n }\n pushSecondaryEvent(state, event.streamKey, event);\n },\n async warmStart(currentMainBarTime) {\n const store = state.runtimeContext.persistentStateStore;\n if (store === undefined) return;\n const snap = await store.load();\n if (snap === null) return;\n if (!validateSnapshot(snap)) return;\n if (snap.lastBarTime >= currentMainBarTime) {\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"warning\",\n code: \"state-snapshot-future-dated\",\n message: \"persistent state snapshot is ahead of the current bar cursor\",\n slotId: null,\n bar: state.barIndex,\n });\n try {\n await store.clear();\n } catch (err) {\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"warning\",\n code: \"state-snapshot-save-failed\",\n message: err instanceof Error ? err.message : String(err),\n slotId: null,\n bar: state.barIndex,\n });\n }\n return;\n }\n restoreStateSnapshot(state, snap);\n state.runtimeContext.lastPersistTime = snap.savedAt;\n pushDiagnostic(state.emissions, {\n kind: \"diagnostic\",\n severity: \"info\",\n code: \"state-snapshot-restored\",\n message: `persistent state snapshot restored through bar ${snap.lastBarTime}`,\n slotId: null,\n bar: state.barIndex,\n });\n },\n drain() {\n return drainImpl(state);\n },\n setPlotOverrides(next) {\n state.runtimeContext.plotOverrides = Object.freeze({ ...next });\n },\n async dispose() {\n const finalSave = saveStateSnapshot(state, state.now());\n disposeImpl(state);\n await finalSave;\n },\n });\n}\n"]}
|
package/dist/dep/DepRunner.d.ts
CHANGED
|
@@ -72,6 +72,13 @@ export type SiblingRunner = Readonly<{
|
|
|
72
72
|
export type CreateDepRunnerArgs = Readonly<{
|
|
73
73
|
readonly compiled: CompiledScriptObject;
|
|
74
74
|
readonly parentCapabilities: Capabilities;
|
|
75
|
+
/**
|
|
76
|
+
* The bundle's chart symbol (the parent runner's resolved
|
|
77
|
+
* `syminfo.ticker`). A `request.security` inside a dep / sibling resolves a
|
|
78
|
+
* symbol-omitted / explicit-chart-symbol request against it, exactly like
|
|
79
|
+
* the primary runner. @since 1.4
|
|
80
|
+
*/
|
|
81
|
+
readonly chartSymbol: string;
|
|
75
82
|
readonly mainStream: StreamState;
|
|
76
83
|
readonly secondaryStreams: Map<string, StreamState>;
|
|
77
84
|
readonly depOutputStore: DepOutputStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DepRunner.d.ts","sourceRoot":"","sources":["../../src/dep/DepRunner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,KAAK,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAE9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAO5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAA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null,
|
|
52
52
|
stateSlots: new Map(),
|
|
53
|
+
seriesSlots: new Map(),
|
|
54
|
+
arraySlots: new Map(),
|
|
55
|
+
chartSymbol: args.chartSymbol,
|
|
53
56
|
secondaryStreams: args.secondaryStreams,
|
|
54
57
|
requestSecurityBars: new Map(),
|
|
55
58
|
requestSecurityAlignments: new Map(),
|
|
56
59
|
requestSecurityAscendingBars: new Map(),
|
|
57
60
|
requestLowerTfViews: new Map(),
|
|
58
61
|
diagnosedRequestKeys: new Set(),
|
|
62
|
+
diagnosedTzKeys: new Set(),
|
|
59
63
|
alertConditions,
|
|
60
64
|
diagnosedAlertConditionKeys: new Set(),
|
|
61
65
|
logBudget: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DepRunner.js","sourceRoot":"","sources":["../../src/dep/DepRunner.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAM/D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,EAGH,sBAAsB,GACzB,MAAM,qBAAqB,CAAC;AA+E7B,SAAS,cAAc,CAAC,QAAgB;IACpC,OAAO;QACH,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,eAAe,EAAE,EAAE;QACnB,IAAI,EAAE,EAAE;QACR,WAAW,EAAE,EAAE;QACf,OAAO,EAAE,QAAQ;QACjB,KAAK,EAAE,QAAQ;KAClB,CAAC;AACN,CAAC;AAED,SAAS,mB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,IAAI,CAAC,CAAC;IAChC,CAAC;IACD,sBAAsB,CAClB,iBAAiB,CAAC,OAAO,CAAC,EAC1B,WAAW,CAAC,SAAS,EACrB,WAAW,CAAC,cAAc,CAC7B,CAAC;AACN,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 { Capabilities } from \"@invinite-org/chartlang-adapter-kit\";\nimport type { Bar, CompiledScriptObject } from \"@invinite-org/chartlang-core\";\n\nimport type { RunnerState } from \"../createScriptRunner.js\";\nimport { pushDiagnostic } from \"../emit/emissionsQueue.js\";\nimport { resolveDefaultPane, resolveScriptPane } from \"../emit/paneResolver.js\";\nimport { resetBarEmissions, runComputeBody } from \"../execution/runComputeStep.js\";\nimport { resolveInputs } from \"../inputs/resolveInputs.js\";\nimport type { MutableRunnerEmissions } from \"../runtimeContext.js\";\nimport { inMemoryStateStore } from \"../stateStore.js\";\nimport type { StreamState } from \"../streamState.js\";\nimport { createRuntimeViews } from \"../views/index.js\";\nimport type { EventKind } from \"../views/index.js\";\nimport type { DepOutputStore } from \"./DepOutputStore.js\";\nimport {\n type DepRunnerLike,\n type SiblingRunnerLike,\n applyDepEmissionPolicy,\n} from \"./emissionFilter.js\";\n\n/**\n * One mounted private dep — a `const X = defineIndicator(...)` binding\n * that another script in the same compiled bundle references via\n * `X.output(\"title\")`. Owns its own `RunnerState`; shares the parent's\n * `mainStream` + `secondaryStreams`. Plot emissions are dropped from\n * the parent's queue and captured into the shared\n * {@link DepOutputStore}.\n *\n * @since 0.7\n * @stable\n * @example\n * // const dep = createDepRunner({ compiled, localId: \"fast\", ... });\n * // await runDepStep(dep, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport type DepRunner = Readonly<{\n readonly kind: \"dep\";\n readonly localId: string;\n readonly slotIdPrefix: string;\n readonly declaredOutputs: ReadonlyArray<string>;\n readonly state: RunnerState;\n}>;\n\n/**\n * One mounted drawn sibling — a `export const X = defineIndicator(...)`\n * binding whose emissions ARE forwarded to the parent's queue, with\n * slot ids prefixed by `export:<exportName>/`. Siblings can also expose\n * outputs consumed by the primary or by other siblings.\n *\n * @since 0.7\n * @stable\n * @example\n * // const sib = createSiblingRunner({ compiled, exportName: \"slow\", ... });\n * // await runSiblingStep(sib, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport type SiblingRunner = Readonly<{\n readonly kind: \"sibling\";\n readonly exportName: string;\n readonly slotIdPrefix: string;\n readonly declaredOutputs: ReadonlyArray<string>;\n readonly state: RunnerState;\n}>;\n\n/**\n * Constructor arguments for {@link createDepRunner} /\n * {@link createSiblingRunner}.\n *\n * `mainStream` + `secondaryStreams` are SHARED with the parent runner\n * (same OHLCV history); `depOutputStore` is also shared so every\n * sibling + dep + primary read from the same store. `inputOverrides`\n * is the merged effective-inputs record the compiler attached to the\n * dep's `DependencyDeclaration`.\n *\n * @since 0.7\n * @stable\n * @example\n * // const args: CreateDepRunnerArgs = {\n * // compiled, localId: \"x\",\n * // parentCapabilities, mainStream, secondaryStreams,\n * // depOutputStore, inputOverrides: {}, now: Date.now,\n * // };\n * const x: number = 1;\n * void x;\n */\nexport type CreateDepRunnerArgs = Readonly<{\n readonly compiled: CompiledScriptObject;\n readonly parentCapabilities: Capabilities;\n readonly mainStream: StreamState;\n readonly secondaryStreams: Map<string, StreamState>;\n readonly depOutputStore: DepOutputStore;\n readonly inputOverrides: Readonly<Record<string, unknown>>;\n readonly now: () => number;\n}>;\n\nfunction freshEmissions(barIndex: number): MutableRunnerEmissions {\n return {\n plots: [],\n drawings: [],\n alerts: [],\n alertConditions: [],\n logs: [],\n diagnostics: [],\n fromBar: barIndex,\n toBar: barIndex,\n };\n}\n\nfunction buildSubRunnerState(\n args: CreateDepRunnerArgs,\n slotIdPrefix: string,\n isDep: boolean,\n): RunnerState {\n const stateStore = inMemoryStateStore();\n const emissions = freshEmissions(0);\n const alertConditions = new Map(\n (args.compiled.manifest.alertConditions ?? []).map((c) => [c.id, c]),\n );\n const state: RunnerState = {\n manifest: args.compiled.manifest,\n compute: args.compiled.compute,\n capabilities: args.parentCapabilities,\n stateStore,\n persistenceIntervalMs: Number.POSITIVE_INFINITY,\n now: args.now,\n mainStream: args.mainStream,\n runtimeContext: {\n stream: args.mainStream,\n stateStore,\n lastPersistTime: 0,\n capabilities: args.parentCapabilities,\n emissions,\n barIndex: () => state.barIndex,\n isTick: false,\n drawingSlots: new Map(),\n drawingSubIdCounters: new Map(),\n drawingBucketCounters: {\n lines: 0,\n labels: 0,\n boxes: 0,\n polylines: 0,\n other: 0,\n },\n scriptMaxDrawings: args.compiled.manifest.maxDrawings ?? null,\n stateSlots: new Map(),\n secondaryStreams: args.secondaryStreams,\n requestSecurityBars: new Map(),\n requestSecurityAlignments: new Map(),\n requestSecurityAscendingBars: new Map(),\n requestLowerTfViews: new Map(),\n diagnosedRequestKeys: new Set(),\n alertConditions,\n diagnosedAlertConditionKeys: new Set(),\n logBudget: 0,\n logBudgetExceededDiagnosed: false,\n resolvedInputs: Object.freeze({}),\n defaultPane: resolveDefaultPane(args.compiled.manifest),\n scriptPane: resolveScriptPane(args.compiled.manifest),\n // Overrides target the primary script's slots only in v1;\n // dep-output plots are not host-overridable.\n plotOverrides: Object.freeze({}),\n diagnosedInputKeys: new Set(),\n views: createRuntimeViews(),\n slotIdPrefix,\n isDep,\n depOutputStore: args.depOutputStore,\n },\n emissions,\n depRunners: [],\n siblingRunners: [],\n depOutputStore: args.depOutputStore,\n depErroredThisBar: false,\n barIndex: 0,\n };\n state.runtimeContext.resolvedInputs = resolveInputs(\n args.compiled.manifest,\n args.inputOverrides,\n state.runtimeContext,\n );\n return state;\n}\n\nfunction declaredOutputTitles(compiled: CompiledScriptObject): ReadonlyArray<string> {\n return (compiled.manifest.outputs ?? []).map((o) => o.title);\n}\n\n/**\n * Construct a {@link DepRunner} for one private dep entry of a\n * `CompiledScriptBundle`. The runner shares the parent's `mainStream`\n * + `secondaryStreams`, owns a fresh `inMemoryStateStore`, and feeds\n * its plot emissions into the shared `DepOutputStore`.\n *\n * @since 0.7\n * @stable\n * @example\n * // const dep = createDepRunner({ compiled, localId: \"fast\",\n * // parentCapabilities, mainStream, secondaryStreams,\n * // depOutputStore, inputOverrides: { length: 20 }, now: Date.now });\n * const x: number = 1;\n * void x;\n */\nexport function createDepRunner(\n args: CreateDepRunnerArgs & { readonly localId: string },\n): DepRunner {\n const slotIdPrefix = `dep:${args.localId}/`;\n return Object.freeze({\n kind: \"dep\" as const,\n localId: args.localId,\n slotIdPrefix,\n declaredOutputs: declaredOutputTitles(args.compiled),\n state: buildSubRunnerState(args, slotIdPrefix, true),\n });\n}\n\n/**\n * Construct a {@link SiblingRunner} for one drawn named-export entry of\n * a `CompiledScriptBundle`. Shares streams + store with the parent;\n * emissions forward to the parent with `export:<exportName>/` slot-id\n * prefixes.\n *\n * @since 0.7\n * @stable\n * @example\n * // const sib = createSiblingRunner({ compiled, exportName: \"slow\", ... });\n * const x: number = 1;\n * void x;\n */\nexport function createSiblingRunner(\n args: CreateDepRunnerArgs & { readonly exportName: string },\n): SiblingRunner {\n const slotIdPrefix = `export:${args.exportName}/`;\n return Object.freeze({\n kind: \"sibling\" as const,\n exportName: args.exportName,\n slotIdPrefix,\n declaredOutputs: declaredOutputTitles(args.compiled),\n state: buildSubRunnerState(args, slotIdPrefix, false),\n });\n}\n\nfunction depRunnerLike(dep: DepRunner): DepRunnerLike {\n return {\n kind: \"dep\",\n localId: dep.localId,\n slotIdPrefix: dep.slotIdPrefix,\n declaredOutputs: dep.declaredOutputs,\n emissions: dep.state.emissions,\n };\n}\n\nfunction siblingRunnerLike(sib: SiblingRunner): SiblingRunnerLike {\n return {\n kind: \"sibling\",\n exportName: sib.exportName,\n slotIdPrefix: sib.slotIdPrefix,\n declaredOutputs: sib.declaredOutputs,\n emissions: sib.state.emissions,\n };\n}\n\nasync function executeSubStep(\n state: RunnerState,\n eventKind: EventKind,\n isTick: boolean,\n): Promise<{ readonly halted: boolean; readonly message: string }> {\n resetBarEmissions(state);\n try {\n const outcome = await runComputeBody({ state, eventKind, isTick });\n return outcome.kind === \"halt\"\n ? { halted: true, message: outcome.message }\n : { halted: false, message: \"\" };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { halted: true, message };\n }\n}\n\n/**\n * Drive one bar of execution for a {@link DepRunner}. Runs the dep's\n * `compute`, captures its titled-plot output into the shared\n * `DepOutputStore` via {@link applyDepEmissionPolicy}, namespaces\n * diagnostics with `dep:<localId>/`, and on halt sets\n * `parentState.depErroredThisBar = true` so the parent's primary\n * step drops its emissions for the bar (per task spec §6).\n *\n * @since 0.7\n * @stable\n * @example\n * // await runDepStep(dep, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport async function runDepStep(\n dep: DepRunner,\n parentState: RunnerState,\n rawBar: Bar,\n eventKind: EventKind,\n isTick: boolean,\n): Promise<void> {\n if (parentState.depOutputStore === null) {\n throw new Error(\"runDepStep called on a runner with no dep output store\");\n }\n void rawBar;\n const result = await executeSubStep(dep.state, eventKind, isTick);\n if (result.halted) {\n // Use an empty slot id so the filter's prefix call produces the\n // runner's slotIdPrefix (`dep:<localId>/`) — preserves the\n // distinguished slotId in the parent's diagnostic queue.\n pushDiagnostic(dep.state.emissions, {\n kind: \"diagnostic\",\n severity: \"error\",\n code: \"dep-error\",\n message: result.message,\n slotId: \"\",\n bar: dep.state.barIndex,\n });\n parentState.depErroredThisBar = true;\n }\n if (!isTick) {\n dep.state.barIndex += 1;\n }\n applyDepEmissionPolicy(depRunnerLike(dep), parentState.emissions, parentState.depOutputStore);\n}\n\n/**\n * Drive one bar of execution for a {@link SiblingRunner}. Same shape\n * as {@link runDepStep} but the sibling's emissions are forwarded to\n * the parent with `export:<exportName>/` slot-id prefixes, and a\n * sibling halt does NOT clear the primary's emissions — only the\n * sibling's own bar emissions are lost.\n *\n * @since 0.7\n * @stable\n * @example\n * // await runSiblingStep(sibling, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport async function runSiblingStep(\n sibling: SiblingRunner,\n parentState: RunnerState,\n rawBar: Bar,\n eventKind: EventKind,\n isTick: boolean,\n): Promise<void> {\n if (parentState.depOutputStore === null) {\n throw new Error(\"runSiblingStep called on a runner with no dep output store\");\n }\n void rawBar;\n const result = await executeSubStep(sibling.state, eventKind, isTick);\n if (result.halted) {\n pushDiagnostic(sibling.state.emissions, {\n kind: \"diagnostic\",\n severity: \"error\",\n code: \"dep-error\",\n message: result.message,\n slotId: \"\",\n bar: sibling.state.barIndex,\n });\n // sibling halt does NOT set parentState.depErroredThisBar.\n }\n if (!isTick) {\n sibling.state.barIndex += 1;\n }\n applyDepEmissionPolicy(\n siblingRunnerLike(sibling),\n parentState.emissions,\n parentState.depOutputStore,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DepRunner.js","sourceRoot":"","sources":["../../src/dep/DepRunner.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAM/D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,EAGH,sBAAsB,GACzB,MAAM,qBAAqB,CAAC;AAsF7B,SAAS,cAAc,CAAC,QAAgB;IACpC,OAAO;QACH,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,eAAe,EAAE,EAAE;QACnB,IAAI,EAAE,EAAE;QACR,WAAW,EAAE,EAAE;QACf,OAAO,EAAE,QAAQ;QACjB,KAAK,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AC,OAAO;YACvB,MAAM,EAAE,EAAE;YACV,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ;SAC9B,CAAC,CAAC;QACH,2DAA2D;IAC/D,CAAC;IACD,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,CAAC;IAChC,CAAC;IACD,sBAAsB,CAClB,iBAAiB,CAAC,OAAO,CAAC,EAC1B,WAAW,CAAC,SAAS,EACrB,WAAW,CAAC,cAAc,CAC7B,CAAC;AACN,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 { Capabilities } from \"@invinite-org/chartlang-adapter-kit\";\nimport type { Bar, CompiledScriptObject } from \"@invinite-org/chartlang-core\";\n\nimport type { RunnerState } from \"../createScriptRunner.js\";\nimport { pushDiagnostic } from \"../emit/emissionsQueue.js\";\nimport { resolveDefaultPane, resolveScriptPane } from \"../emit/paneResolver.js\";\nimport { resetBarEmissions, runComputeBody } from \"../execution/runComputeStep.js\";\nimport { resolveInputs } from \"../inputs/resolveInputs.js\";\nimport type { MutableRunnerEmissions } from \"../runtimeContext.js\";\nimport { inMemoryStateStore } from \"../stateStore.js\";\nimport type { StreamState } from \"../streamState.js\";\nimport { createRuntimeViews } from \"../views/index.js\";\nimport type { EventKind } from \"../views/index.js\";\nimport type { DepOutputStore } from \"./DepOutputStore.js\";\nimport {\n type DepRunnerLike,\n type SiblingRunnerLike,\n applyDepEmissionPolicy,\n} from \"./emissionFilter.js\";\n\n/**\n * One mounted private dep — a `const X = defineIndicator(...)` binding\n * that another script in the same compiled bundle references via\n * `X.output(\"title\")`. Owns its own `RunnerState`; shares the parent's\n * `mainStream` + `secondaryStreams`. Plot emissions are dropped from\n * the parent's queue and captured into the shared\n * {@link DepOutputStore}.\n *\n * @since 0.7\n * @stable\n * @example\n * // const dep = createDepRunner({ compiled, localId: \"fast\", ... });\n * // await runDepStep(dep, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport type DepRunner = Readonly<{\n readonly kind: \"dep\";\n readonly localId: string;\n readonly slotIdPrefix: string;\n readonly declaredOutputs: ReadonlyArray<string>;\n readonly state: RunnerState;\n}>;\n\n/**\n * One mounted drawn sibling — a `export const X = defineIndicator(...)`\n * binding whose emissions ARE forwarded to the parent's queue, with\n * slot ids prefixed by `export:<exportName>/`. Siblings can also expose\n * outputs consumed by the primary or by other siblings.\n *\n * @since 0.7\n * @stable\n * @example\n * // const sib = createSiblingRunner({ compiled, exportName: \"slow\", ... });\n * // await runSiblingStep(sib, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport type SiblingRunner = Readonly<{\n readonly kind: \"sibling\";\n readonly exportName: string;\n readonly slotIdPrefix: string;\n readonly declaredOutputs: ReadonlyArray<string>;\n readonly state: RunnerState;\n}>;\n\n/**\n * Constructor arguments for {@link createDepRunner} /\n * {@link createSiblingRunner}.\n *\n * `mainStream` + `secondaryStreams` are SHARED with the parent runner\n * (same OHLCV history); `depOutputStore` is also shared so every\n * sibling + dep + primary read from the same store. `inputOverrides`\n * is the merged effective-inputs record the compiler attached to the\n * dep's `DependencyDeclaration`.\n *\n * @since 0.7\n * @stable\n * @example\n * // const args: CreateDepRunnerArgs = {\n * // compiled, localId: \"x\",\n * // parentCapabilities, mainStream, secondaryStreams,\n * // depOutputStore, inputOverrides: {}, now: Date.now,\n * // };\n * const x: number = 1;\n * void x;\n */\nexport type CreateDepRunnerArgs = Readonly<{\n readonly compiled: CompiledScriptObject;\n readonly parentCapabilities: Capabilities;\n /**\n * The bundle's chart symbol (the parent runner's resolved\n * `syminfo.ticker`). A `request.security` inside a dep / sibling resolves a\n * symbol-omitted / explicit-chart-symbol request against it, exactly like\n * the primary runner. @since 1.4\n */\n readonly chartSymbol: string;\n readonly mainStream: StreamState;\n readonly secondaryStreams: Map<string, StreamState>;\n readonly depOutputStore: DepOutputStore;\n readonly inputOverrides: Readonly<Record<string, unknown>>;\n readonly now: () => number;\n}>;\n\nfunction freshEmissions(barIndex: number): MutableRunnerEmissions {\n return {\n plots: [],\n drawings: [],\n alerts: [],\n alertConditions: [],\n logs: [],\n diagnostics: [],\n fromBar: barIndex,\n toBar: barIndex,\n };\n}\n\nfunction buildSubRunnerState(\n args: CreateDepRunnerArgs,\n slotIdPrefix: string,\n isDep: boolean,\n): RunnerState {\n const stateStore = inMemoryStateStore();\n const emissions = freshEmissions(0);\n const alertConditions = new Map(\n (args.compiled.manifest.alertConditions ?? []).map((c) => [c.id, c]),\n );\n const state: RunnerState = {\n manifest: args.compiled.manifest,\n compute: args.compiled.compute,\n capabilities: args.parentCapabilities,\n stateStore,\n persistenceIntervalMs: Number.POSITIVE_INFINITY,\n now: args.now,\n mainStream: args.mainStream,\n runtimeContext: {\n stream: args.mainStream,\n stateStore,\n lastPersistTime: 0,\n capabilities: args.parentCapabilities,\n emissions,\n barIndex: () => state.barIndex,\n isTick: false,\n drawingSlots: new Map(),\n drawingSubIdCounters: new Map(),\n drawingBucketCounters: {\n lines: 0,\n labels: 0,\n boxes: 0,\n polylines: 0,\n other: 0,\n },\n scriptMaxDrawings: args.compiled.manifest.maxDrawings ?? null,\n stateSlots: new Map(),\n seriesSlots: new Map(),\n arraySlots: new Map(),\n chartSymbol: args.chartSymbol,\n secondaryStreams: args.secondaryStreams,\n requestSecurityBars: new Map(),\n requestSecurityAlignments: new Map(),\n requestSecurityAscendingBars: new Map(),\n requestLowerTfViews: new Map(),\n diagnosedRequestKeys: new Set(),\n diagnosedTzKeys: new Set(),\n alertConditions,\n diagnosedAlertConditionKeys: new Set(),\n logBudget: 0,\n logBudgetExceededDiagnosed: false,\n resolvedInputs: Object.freeze({}),\n defaultPane: resolveDefaultPane(args.compiled.manifest),\n scriptPane: resolveScriptPane(args.compiled.manifest),\n // Overrides target the primary script's slots only in v1;\n // dep-output plots are not host-overridable.\n plotOverrides: Object.freeze({}),\n diagnosedInputKeys: new Set(),\n views: createRuntimeViews(),\n slotIdPrefix,\n isDep,\n depOutputStore: args.depOutputStore,\n },\n emissions,\n depRunners: [],\n siblingRunners: [],\n depOutputStore: args.depOutputStore,\n depErroredThisBar: false,\n barIndex: 0,\n };\n state.runtimeContext.resolvedInputs = resolveInputs(\n args.compiled.manifest,\n args.inputOverrides,\n state.runtimeContext,\n );\n return state;\n}\n\nfunction declaredOutputTitles(compiled: CompiledScriptObject): ReadonlyArray<string> {\n return (compiled.manifest.outputs ?? []).map((o) => o.title);\n}\n\n/**\n * Construct a {@link DepRunner} for one private dep entry of a\n * `CompiledScriptBundle`. The runner shares the parent's `mainStream`\n * + `secondaryStreams`, owns a fresh `inMemoryStateStore`, and feeds\n * its plot emissions into the shared `DepOutputStore`.\n *\n * @since 0.7\n * @stable\n * @example\n * // const dep = createDepRunner({ compiled, localId: \"fast\",\n * // parentCapabilities, mainStream, secondaryStreams,\n * // depOutputStore, inputOverrides: { length: 20 }, now: Date.now });\n * const x: number = 1;\n * void x;\n */\nexport function createDepRunner(\n args: CreateDepRunnerArgs & { readonly localId: string },\n): DepRunner {\n const slotIdPrefix = `dep:${args.localId}/`;\n return Object.freeze({\n kind: \"dep\" as const,\n localId: args.localId,\n slotIdPrefix,\n declaredOutputs: declaredOutputTitles(args.compiled),\n state: buildSubRunnerState(args, slotIdPrefix, true),\n });\n}\n\n/**\n * Construct a {@link SiblingRunner} for one drawn named-export entry of\n * a `CompiledScriptBundle`. Shares streams + store with the parent;\n * emissions forward to the parent with `export:<exportName>/` slot-id\n * prefixes.\n *\n * @since 0.7\n * @stable\n * @example\n * // const sib = createSiblingRunner({ compiled, exportName: \"slow\", ... });\n * const x: number = 1;\n * void x;\n */\nexport function createSiblingRunner(\n args: CreateDepRunnerArgs & { readonly exportName: string },\n): SiblingRunner {\n const slotIdPrefix = `export:${args.exportName}/`;\n return Object.freeze({\n kind: \"sibling\" as const,\n exportName: args.exportName,\n slotIdPrefix,\n declaredOutputs: declaredOutputTitles(args.compiled),\n state: buildSubRunnerState(args, slotIdPrefix, false),\n });\n}\n\nfunction depRunnerLike(dep: DepRunner): DepRunnerLike {\n return {\n kind: \"dep\",\n localId: dep.localId,\n slotIdPrefix: dep.slotIdPrefix,\n declaredOutputs: dep.declaredOutputs,\n emissions: dep.state.emissions,\n };\n}\n\nfunction siblingRunnerLike(sib: SiblingRunner): SiblingRunnerLike {\n return {\n kind: \"sibling\",\n exportName: sib.exportName,\n slotIdPrefix: sib.slotIdPrefix,\n declaredOutputs: sib.declaredOutputs,\n emissions: sib.state.emissions,\n };\n}\n\nasync function executeSubStep(\n state: RunnerState,\n eventKind: EventKind,\n isTick: boolean,\n): Promise<{ readonly halted: boolean; readonly message: string }> {\n resetBarEmissions(state);\n try {\n const outcome = await runComputeBody({ state, eventKind, isTick });\n return outcome.kind === \"halt\"\n ? { halted: true, message: outcome.message }\n : { halted: false, message: \"\" };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return { halted: true, message };\n }\n}\n\n/**\n * Drive one bar of execution for a {@link DepRunner}. Runs the dep's\n * `compute`, captures its titled-plot output into the shared\n * `DepOutputStore` via {@link applyDepEmissionPolicy}, namespaces\n * diagnostics with `dep:<localId>/`, and on halt sets\n * `parentState.depErroredThisBar = true` so the parent's primary\n * step drops its emissions for the bar (per task spec §6).\n *\n * @since 0.7\n * @stable\n * @example\n * // await runDepStep(dep, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport async function runDepStep(\n dep: DepRunner,\n parentState: RunnerState,\n rawBar: Bar,\n eventKind: EventKind,\n isTick: boolean,\n): Promise<void> {\n if (parentState.depOutputStore === null) {\n throw new Error(\"runDepStep called on a runner with no dep output store\");\n }\n void rawBar;\n const result = await executeSubStep(dep.state, eventKind, isTick);\n if (result.halted) {\n // Use an empty slot id so the filter's prefix call produces the\n // runner's slotIdPrefix (`dep:<localId>/`) — preserves the\n // distinguished slotId in the parent's diagnostic queue.\n pushDiagnostic(dep.state.emissions, {\n kind: \"diagnostic\",\n severity: \"error\",\n code: \"dep-error\",\n message: result.message,\n slotId: \"\",\n bar: dep.state.barIndex,\n });\n parentState.depErroredThisBar = true;\n }\n if (!isTick) {\n dep.state.barIndex += 1;\n }\n applyDepEmissionPolicy(depRunnerLike(dep), parentState.emissions, parentState.depOutputStore);\n}\n\n/**\n * Drive one bar of execution for a {@link SiblingRunner}. Same shape\n * as {@link runDepStep} but the sibling's emissions are forwarded to\n * the parent with `export:<exportName>/` slot-id prefixes, and a\n * sibling halt does NOT clear the primary's emissions — only the\n * sibling's own bar emissions are lost.\n *\n * @since 0.7\n * @stable\n * @example\n * // await runSiblingStep(sibling, parent, rawBar, \"close\", false);\n * const x: number = 1;\n * void x;\n */\nexport async function runSiblingStep(\n sibling: SiblingRunner,\n parentState: RunnerState,\n rawBar: Bar,\n eventKind: EventKind,\n isTick: boolean,\n): Promise<void> {\n if (parentState.depOutputStore === null) {\n throw new Error(\"runSiblingStep called on a runner with no dep output store\");\n }\n void rawBar;\n const result = await executeSubStep(sibling.state, eventKind, isTick);\n if (result.halted) {\n pushDiagnostic(sibling.state.emissions, {\n kind: \"diagnostic\",\n severity: \"error\",\n code: \"dep-error\",\n message: result.message,\n slotId: \"\",\n bar: sibling.state.barIndex,\n });\n // sibling halt does NOT set parentState.depErroredThisBar.\n }\n if (!isTick) {\n sibling.state.barIndex += 1;\n }\n applyDepEmissionPolicy(\n siblingRunnerLike(sibling),\n parentState.emissions,\n parentState.depOutputStore,\n );\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { BarColorOpts, Color } from "@invinite-org/chartlang-core";
|
|
2
|
+
/**
|
|
3
|
+
* Tint the candle / bar for the current bar — the runtime impl of the
|
|
4
|
+
* Pine-ergonomic `barcolor` alias (script-facing overload).
|
|
5
|
+
*
|
|
6
|
+
* Same dual-signature contract as {@link plot}: scripts call
|
|
7
|
+
* `barcolor(color, opts?)`; the compiler's callsite-id transformer rewrites
|
|
8
|
+
* every call to `barcolor(slotId, color, opts?)` (the sibling overload).
|
|
9
|
+
* Direct invocation without a slot id throws the sentinel error.
|
|
10
|
+
*
|
|
11
|
+
* `barcolor` is Pine-ergonomic sugar — it builds the `bar-color` `PlotStyle`
|
|
12
|
+
* and dispatches to the shared {@link plotImpl} with `value = NaN` (→ wire
|
|
13
|
+
* `value: null`). The per-bar color rides the wire as
|
|
14
|
+
* `PlotEmission.colorValue` (the dynamic-color channel), so a single call
|
|
15
|
+
* recolors every bar by that bar's evaluated color; the static `style.color`
|
|
16
|
+
* remains the fallback. Adapters that do not declare the `bar-color`
|
|
17
|
+
* capability drop it with `unsupported-plot-kind`.
|
|
18
|
+
*
|
|
19
|
+
* @since 1.4
|
|
20
|
+
* @example
|
|
21
|
+
* import { defineIndicator, barcolor } from "@invinite-org/chartlang-core";
|
|
22
|
+
* export default defineIndicator({
|
|
23
|
+
* name: "Tint",
|
|
24
|
+
* apiVersion: 1,
|
|
25
|
+
* compute({ bar }) {
|
|
26
|
+
* barcolor(bar.close > bar.open ? "#16a34a" : "#dc2626");
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
export declare function barcolor(color: Color, opts?: BarColorOpts): void;
|
|
31
|
+
/**
|
|
32
|
+
* Tint the candle / bar for the current bar (compiler-injected overload).
|
|
33
|
+
* The callsite-id transformer rewrites script-side `barcolor(color, opts?)`
|
|
34
|
+
* into `barcolor(slotId, color, opts?)`.
|
|
35
|
+
*
|
|
36
|
+
* @since 1.4
|
|
37
|
+
* @example
|
|
38
|
+
* // Internal — the compiler rewrites every script callsite, e.g.
|
|
39
|
+
* // `barcolor("#000")` becomes `barcolor("demo.chart.ts:5:9#0", "#000")`.
|
|
40
|
+
* // const fn: typeof barcolor = barcolor;
|
|
41
|
+
* // void fn;
|
|
42
|
+
*/
|
|
43
|
+
export declare function barcolor(slotId: string, color: Color, opts?: BarColorOpts): void;
|
|
44
|
+
//# sourceMappingURL=barcolor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barcolor.d.ts","sourceRoot":"","sources":["../../src/emit/barcolor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAY,MAAM,8BAA8B,CAAC;AAuBlF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;AAClE;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC"}
|