@invinite-org/chartlang-adapter-kit 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +1380 -0
  2. package/LICENSE +21 -0
  3. package/README.md +69 -0
  4. package/dist/base/bufferingAdapter.d.ts +52 -0
  5. package/dist/base/bufferingAdapter.d.ts.map +1 -0
  6. package/dist/base/bufferingAdapter.js +68 -0
  7. package/dist/base/bufferingAdapter.js.map +1 -0
  8. package/dist/base/index.d.ts +3 -0
  9. package/dist/base/index.d.ts.map +1 -0
  10. package/dist/base/index.js +5 -0
  11. package/dist/base/index.js.map +1 -0
  12. package/dist/base/passThroughAdapter.d.ts +49 -0
  13. package/dist/base/passThroughAdapter.d.ts.map +1 -0
  14. package/dist/base/passThroughAdapter.js +61 -0
  15. package/dist/base/passThroughAdapter.js.map +1 -0
  16. package/dist/capabilities/capabilities.d.ts +336 -0
  17. package/dist/capabilities/capabilities.d.ts.map +1 -0
  18. package/dist/capabilities/capabilities.js +616 -0
  19. package/dist/capabilities/capabilities.js.map +1 -0
  20. package/dist/capabilities/index.d.ts +2 -0
  21. package/dist/capabilities/index.d.ts.map +1 -0
  22. package/dist/capabilities/index.js +4 -0
  23. package/dist/capabilities/index.js.map +1 -0
  24. package/dist/defineAdapter.d.ts +74 -0
  25. package/dist/defineAdapter.d.ts.map +1 -0
  26. package/dist/defineAdapter.js +55 -0
  27. package/dist/defineAdapter.js.map +1 -0
  28. package/dist/index.d.ts +12 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +9 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/mocks/index.d.ts +3 -0
  33. package/dist/mocks/index.d.ts.map +1 -0
  34. package/dist/mocks/index.js +4 -0
  35. package/dist/mocks/index.js.map +1 -0
  36. package/dist/mocks/mockCandleSource.d.ts +68 -0
  37. package/dist/mocks/mockCandleSource.d.ts.map +1 -0
  38. package/dist/mocks/mockCandleSource.js +61 -0
  39. package/dist/mocks/mockCandleSource.js.map +1 -0
  40. package/dist/types.d.ts +655 -0
  41. package/dist/types.d.ts.map +1 -0
  42. package/dist/types.js +4 -0
  43. package/dist/types.js.map +1 -0
  44. package/dist/validation/decodeDrawing.d.ts +29 -0
  45. package/dist/validation/decodeDrawing.d.ts.map +1 -0
  46. package/dist/validation/decodeDrawing.js +35 -0
  47. package/dist/validation/decodeDrawing.js.map +1 -0
  48. package/dist/validation/index.d.ts +4 -0
  49. package/dist/validation/index.d.ts.map +1 -0
  50. package/dist/validation/index.js +5 -0
  51. package/dist/validation/index.js.map +1 -0
  52. package/dist/validation/validateEmission.d.ts +70 -0
  53. package/dist/validation/validateEmission.d.ts.map +1 -0
  54. package/dist/validation/validateEmission.js +1481 -0
  55. package/dist/validation/validateEmission.js.map +1 -0
  56. package/package.json +41 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Invinite
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # @invinite-org/chartlang-adapter-kit
2
+
3
+ `experimental`
4
+
5
+ SDK for writing chartlang adapters in consumer repos. It ships the adapter
6
+ contract, capabilities model, emission validators, mock candles, and test base
7
+ classes.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @invinite-org/chartlang-adapter-kit
13
+ ```
14
+
15
+ ## Public surface
16
+
17
+ - `defineAdapter(opts) -> Adapter` — factory preserving optional hooks such as
18
+ `symInfo` and `resolveInputs`.
19
+ - `capabilities` — builders for plots, alerts, 61 drawing kinds, drawing
20
+ groups, and Phase 4 capability fields: `intervals(...)`,
21
+ `multiTimeframe(...)`, `subPanes(...)`, `symInfoFields(...)`,
22
+ `maxDrawingsPerScript(...)`, `alertConditions(...)`, and `logs(...)`.
23
+ - `validateEmission(e) -> ValidationResult` — validates plot, alert, drawing,
24
+ diagnostic, log, and alert-condition payloads.
25
+ - `decodeDrawing(e) -> DrawingState | null`.
26
+ - `bucketFor(kind)`, `KIND_BUCKET`, and drawing kind maps from core.
27
+ - `mockCandleSource(bars, opts)` for tests, conformance scenarios,
28
+ and demos. `opts.mode` selects `"history"` (default), `"stream"`,
29
+ or `"history-then-stream"` (one history batch followed by per-bar
30
+ `close` events for the trailing `streamTail` bars).
31
+ - `PassThroughAdapter`, `BufferingAdapter`.
32
+ - Types: `Adapter`, `Capabilities`, `CandleEvent`, emissions, diagnostics,
33
+ input kinds, `SymInfoField`, `RunnerEmissions`, and `DefineAdapterOpts`.
34
+
35
+ ## Minimum-viable API call
36
+
37
+ ```ts
38
+ import { capabilities, defineAdapter, mockCandleSource } from "@invinite-org/chartlang-adapter-kit";
39
+
40
+ export default defineAdapter({
41
+ id: "demo",
42
+ name: "Demo",
43
+ capabilities: {
44
+ plots: capabilities.allLines(),
45
+ drawings: new Set(),
46
+ alerts: capabilities.alerts("toast"),
47
+ alertConditions: false,
48
+ logs: false,
49
+ inputs: new Set(),
50
+ intervals: capabilities.intervals([{ value: "1D", label: "1 day", group: "daily" }]).intervals,
51
+ multiTimeframe: false,
52
+ subPanes: 0,
53
+ symInfoFields: new Set(),
54
+ maxDrawingsPerScript: { lines: 0, labels: 0, boxes: 0, polylines: 0, other: 0 },
55
+ maxLookback: 5000,
56
+ maxTickHz: 10,
57
+ },
58
+ candles: () => mockCandleSource([], { interval: "1D" }),
59
+ onEmissions: () => {},
60
+ });
61
+ ```
62
+
63
+ ## Docs
64
+
65
+ See [`docs/adapters/contract.md`](../../docs/adapters/contract.md).
66
+
67
+ ## License
68
+
69
+ MIT
@@ -0,0 +1,52 @@
1
+ import type { Adapter, CandleEvent, Capabilities, RunnerEmissions } from "../types.js";
2
+ /**
3
+ * `Adapter` that records every `onEmissions` batch and exposes a
4
+ * `drain()` method to retrieve them all at once. Used by the
5
+ * conformance suite (Task 11) to collect emissions across a full
6
+ * fixture playback before asserting against golden bars.
7
+ *
8
+ * @since 0.1
9
+ * @stable
10
+ * @example
11
+ * import {
12
+ * BufferingAdapter,
13
+ * capabilities,
14
+ * mockCandleSource,
15
+ * } from "@invinite-org/chartlang-adapter-kit";
16
+ *
17
+ * const a = new BufferingAdapter(
18
+ * "b", "Buffering",
19
+ * {
20
+ * plots: capabilities.allLines(),
21
+ * drawings: new Set(),
22
+ * alerts: new Set(),
23
+ * alertConditions: false,
24
+ * logs: false,
25
+ * inputs: new Set(),
26
+ * intervals: [],
27
+ * multiTimeframe: false,
28
+ * subPanes: 0,
29
+ * symInfoFields: new Set(),
30
+ * maxDrawingsPerScript: {
31
+ * lines: 0, labels: 0, boxes: 0, polylines: 0, other: 0,
32
+ * },
33
+ * maxLookback: 5000,
34
+ * maxTickHz: 10,
35
+ * },
36
+ * mockCandleSource([]),
37
+ * );
38
+ * a.drain();
39
+ */
40
+ export declare class BufferingAdapter implements Adapter {
41
+ readonly id: string;
42
+ readonly name: string;
43
+ readonly capabilities: Capabilities;
44
+ private readonly source;
45
+ private buffered;
46
+ constructor(id: string, name: string, capabilities: Capabilities, source: AsyncIterable<CandleEvent>);
47
+ candles(): AsyncIterable<CandleEvent>;
48
+ onEmissions(emissions: RunnerEmissions): void;
49
+ drain(): ReadonlyArray<RunnerEmissions>;
50
+ dispose(): void;
51
+ }
52
+ //# sourceMappingURL=bufferingAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferingAdapter.d.ts","sourceRoot":"","sources":["../../src/base/bufferingAdapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,qBAAa,gBAAiB,YAAW,OAAO;aAIxB,EAAE,EAAE,MAAM;aACV,IAAI,EAAE,MAAM;aACZ,YAAY,EAAE,YAAY;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM;IAN3B,OAAO,CAAC,QAAQ,CAAyB;gBAGrB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,YAAY,EACzB,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC;IAGvD,OAAO,IAAI,aAAa,CAAC,WAAW,CAAC;IAIrC,WAAW,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI;IAI7C,KAAK,IAAI,aAAa,CAAC,eAAe,CAAC;IAMvC,OAAO,IAAI,IAAI;CAGlB"}
@@ -0,0 +1,68 @@
1
+ // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
+ // See the LICENSE file in the repo root for full license text.
3
+ /**
4
+ * `Adapter` that records every `onEmissions` batch and exposes a
5
+ * `drain()` method to retrieve them all at once. Used by the
6
+ * conformance suite (Task 11) to collect emissions across a full
7
+ * fixture playback before asserting against golden bars.
8
+ *
9
+ * @since 0.1
10
+ * @stable
11
+ * @example
12
+ * import {
13
+ * BufferingAdapter,
14
+ * capabilities,
15
+ * mockCandleSource,
16
+ * } from "@invinite-org/chartlang-adapter-kit";
17
+ *
18
+ * const a = new BufferingAdapter(
19
+ * "b", "Buffering",
20
+ * {
21
+ * plots: capabilities.allLines(),
22
+ * drawings: new Set(),
23
+ * alerts: new Set(),
24
+ * alertConditions: false,
25
+ * logs: false,
26
+ * inputs: new Set(),
27
+ * intervals: [],
28
+ * multiTimeframe: false,
29
+ * subPanes: 0,
30
+ * symInfoFields: new Set(),
31
+ * maxDrawingsPerScript: {
32
+ * lines: 0, labels: 0, boxes: 0, polylines: 0, other: 0,
33
+ * },
34
+ * maxLookback: 5000,
35
+ * maxTickHz: 10,
36
+ * },
37
+ * mockCandleSource([]),
38
+ * );
39
+ * a.drain();
40
+ */
41
+ export class BufferingAdapter {
42
+ id;
43
+ name;
44
+ capabilities;
45
+ source;
46
+ buffered = [];
47
+ constructor(id, name, capabilities, source) {
48
+ this.id = id;
49
+ this.name = name;
50
+ this.capabilities = capabilities;
51
+ this.source = source;
52
+ }
53
+ candles() {
54
+ return this.source;
55
+ }
56
+ onEmissions(emissions) {
57
+ this.buffered.push(emissions);
58
+ }
59
+ drain() {
60
+ const out = this.buffered.slice();
61
+ this.buffered = [];
62
+ return out;
63
+ }
64
+ dispose() {
65
+ this.buffered = [];
66
+ }
67
+ }
68
+ //# sourceMappingURL=bufferingAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferingAdapter.js","sourceRoot":"","sources":["../../src/base/bufferingAdapter.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAI/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,OAAO,gBAAgB;IAIL;IACA;IACA;IACC;IANb,QAAQ,GAAsB,EAAE,CAAC;IAEzC,YACoB,EAAU,EACV,IAAY,EACZ,YAA0B,EACzB,MAAkC;QAHnC,OAAE,GAAF,EAAE,CAAQ;QACV,SAAI,GAAJ,IAAI,CAAQ;QACZ,iBAAY,GAAZ,YAAY,CAAc;QACzB,WAAM,GAAN,MAAM,CAA4B;IACpD,CAAC;IAEJ,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,WAAW,CAAC,SAA0B;QAClC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED,KAAK;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,OAAO,GAAG,CAAC;IACf,CAAC;IAED,OAAO;QACH,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACvB,CAAC;CACJ"}
@@ -0,0 +1,3 @@
1
+ export { BufferingAdapter } from "./bufferingAdapter.js";
2
+ export { PassThroughAdapter } from "./passThroughAdapter.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,5 @@
1
+ // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
+ // See the LICENSE file in the repo root for full license text.
3
+ export { BufferingAdapter } from "./bufferingAdapter.js";
4
+ export { PassThroughAdapter } from "./passThroughAdapter.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/base/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,49 @@
1
+ import type { Adapter, CandleEvent, Capabilities, RunnerEmissions } from "../types.js";
2
+ /**
3
+ * Minimal `Adapter` that forwards a supplied `AsyncIterable<CandleEvent>`
4
+ * and drops every emission. Useful as a runtime test fixture when the
5
+ * caller doesn't need to observe outputs.
6
+ *
7
+ * @since 0.1
8
+ * @stable
9
+ * @example
10
+ * import {
11
+ * PassThroughAdapter,
12
+ * capabilities,
13
+ * mockCandleSource,
14
+ * } from "@invinite-org/chartlang-adapter-kit";
15
+ *
16
+ * const a = new PassThroughAdapter(
17
+ * "p", "Passthrough",
18
+ * {
19
+ * plots: capabilities.allLines(),
20
+ * drawings: new Set(),
21
+ * alerts: new Set(),
22
+ * alertConditions: false,
23
+ * logs: false,
24
+ * inputs: new Set(),
25
+ * intervals: [],
26
+ * multiTimeframe: false,
27
+ * subPanes: 0,
28
+ * symInfoFields: new Set(),
29
+ * maxDrawingsPerScript: {
30
+ * lines: 0, labels: 0, boxes: 0, polylines: 0, other: 0,
31
+ * },
32
+ * maxLookback: 5000,
33
+ * maxTickHz: 10,
34
+ * },
35
+ * mockCandleSource([]),
36
+ * );
37
+ * void a;
38
+ */
39
+ export declare class PassThroughAdapter implements Adapter {
40
+ readonly id: string;
41
+ readonly name: string;
42
+ readonly capabilities: Capabilities;
43
+ private readonly source;
44
+ constructor(id: string, name: string, capabilities: Capabilities, source: AsyncIterable<CandleEvent>);
45
+ candles(): AsyncIterable<CandleEvent>;
46
+ onEmissions(_emissions: RunnerEmissions): void;
47
+ dispose(): void;
48
+ }
49
+ //# sourceMappingURL=passThroughAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passThroughAdapter.d.ts","sourceRoot":"","sources":["../../src/base/passThroughAdapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qBAAa,kBAAmB,YAAW,OAAO;aAE1B,EAAE,EAAE,MAAM;aACV,IAAI,EAAE,MAAM;aACZ,YAAY,EAAE,YAAY;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAHP,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,YAAY,EACzB,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC;IAGvD,OAAO,IAAI,aAAa,CAAC,WAAW,CAAC;IAIrC,WAAW,CAAC,UAAU,EAAE,eAAe,GAAG,IAAI;IAI9C,OAAO,IAAI,IAAI;CAGlB"}
@@ -0,0 +1,61 @@
1
+ // Copyright (c) 2026 Invinite. Licensed under the MIT License.
2
+ // See the LICENSE file in the repo root for full license text.
3
+ /**
4
+ * Minimal `Adapter` that forwards a supplied `AsyncIterable<CandleEvent>`
5
+ * and drops every emission. Useful as a runtime test fixture when the
6
+ * caller doesn't need to observe outputs.
7
+ *
8
+ * @since 0.1
9
+ * @stable
10
+ * @example
11
+ * import {
12
+ * PassThroughAdapter,
13
+ * capabilities,
14
+ * mockCandleSource,
15
+ * } from "@invinite-org/chartlang-adapter-kit";
16
+ *
17
+ * const a = new PassThroughAdapter(
18
+ * "p", "Passthrough",
19
+ * {
20
+ * plots: capabilities.allLines(),
21
+ * drawings: new Set(),
22
+ * alerts: new Set(),
23
+ * alertConditions: false,
24
+ * logs: false,
25
+ * inputs: new Set(),
26
+ * intervals: [],
27
+ * multiTimeframe: false,
28
+ * subPanes: 0,
29
+ * symInfoFields: new Set(),
30
+ * maxDrawingsPerScript: {
31
+ * lines: 0, labels: 0, boxes: 0, polylines: 0, other: 0,
32
+ * },
33
+ * maxLookback: 5000,
34
+ * maxTickHz: 10,
35
+ * },
36
+ * mockCandleSource([]),
37
+ * );
38
+ * void a;
39
+ */
40
+ export class PassThroughAdapter {
41
+ id;
42
+ name;
43
+ capabilities;
44
+ source;
45
+ constructor(id, name, capabilities, source) {
46
+ this.id = id;
47
+ this.name = name;
48
+ this.capabilities = capabilities;
49
+ this.source = source;
50
+ }
51
+ candles() {
52
+ return this.source;
53
+ }
54
+ onEmissions(_emissions) {
55
+ // intentional no-op
56
+ }
57
+ dispose() {
58
+ // intentional no-op
59
+ }
60
+ }
61
+ //# sourceMappingURL=passThroughAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passThroughAdapter.js","sourceRoot":"","sources":["../../src/base/passThroughAdapter.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+DAA+D;AAI/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,OAAO,kBAAkB;IAEP;IACA;IACA;IACC;IAJrB,YACoB,EAAU,EACV,IAAY,EACZ,YAA0B,EACzB,MAAkC;QAHnC,OAAE,GAAF,EAAE,CAAQ;QACV,SAAI,GAAJ,IAAI,CAAQ;QACZ,iBAAY,GAAZ,YAAY,CAAc;QACzB,WAAM,GAAN,MAAM,CAA4B;IACpD,CAAC;IAEJ,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,WAAW,CAAC,UAA2B;QACnC,oBAAoB;IACxB,CAAC;IAED,OAAO;QACH,oBAAoB;IACxB,CAAC;CACJ"}