pinets 0.9.9 → 0.9.11

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.
@@ -148,6 +148,34 @@ export declare class PineTS {
148
148
  * @private
149
149
  */
150
150
  private _removeLastResult;
151
+ /**
152
+ * Snapshot the var/let/const/params Series state for streaming rollback.
153
+ * Captures the data array length and last value for each variable so we can
154
+ * restore to this exact state before re-executing the last bar.
155
+ *
156
+ * PERF NOTE: This currently snapshots ALL scopes (const, var, let, params).
157
+ * In practice, only `var` variables need snapshot/restore because:
158
+ * - `let` variables are re-initialized every bar via $.init() — they reset naturally
159
+ * - `const` variables are set once and never modified
160
+ * - `params` are function parameters, not modified across bars
161
+ * Only `var` variables persist and get modified in-place by $.set() (e.g. n += 1),
162
+ * which causes drift on streaming re-execution.
163
+ * If this becomes a bottleneck, narrow to `['var']` only.
164
+ *
165
+ * An even lighter alternative: make $.set() on var Series append-only (push
166
+ * instead of in-place modify). Then the existing pop-based _removeLastResult
167
+ * would correctly revert var state without any snapshot. This would require
168
+ * changes to the core Series/set mechanics.
169
+ *
170
+ * @private
171
+ */
172
+ private _snapshotVarState;
173
+ /**
174
+ * Restore var/let/const/params Series state from a snapshot.
175
+ * Truncates each Series' data array back to the snapshotted length.
176
+ * @private
177
+ */
178
+ private _restoreVarState;
151
179
  /**
152
180
  * Initialize a new context for running Pine Script code
153
181
  * @private
@@ -1,3 +1,17 @@
1
+ /**
2
+ * Normalize a Pine Script timeframe string to a canonical form.
3
+ * e.g. "1D" → "D", "60" → "60", "1W" → "W", "" → ""
4
+ */
5
+ export declare function normalizeTimeframe(tf: string): string;
6
+ /**
7
+ * Compute the opening timestamp of the higher-timeframe bar that contains the given timestamp.
8
+ *
9
+ * For intraday TFs (minutes): floor to the nearest multiple of the TF duration within the day.
10
+ * For daily: floor to UTC day start (00:00 UTC).
11
+ * For weekly: floor to Monday 00:00 UTC.
12
+ * For monthly: floor to 1st of month 00:00 UTC.
13
+ */
14
+ export declare function alignToTimeframe(timestamp: number, tf: string): number;
1
15
  interface DateParts {
2
16
  year: number;
3
17
  month: number;
@@ -28,7 +42,7 @@ export declare class TimeHelper {
28
42
  constructor(context: any, dataField?: string);
29
43
  get __value(): any;
30
44
  param(source: any, index?: number): any;
31
- any(...args: any[]): any;
45
+ any(...args: any[]): number;
32
46
  /**
33
47
  * Basic session check: parses "HHMM-HHMM" format and tests if
34
48
  * the timestamp falls within the session window.
@@ -17,6 +17,14 @@ export declare class Timeframe {
17
17
  get isseconds(): boolean;
18
18
  get isminutes(): boolean;
19
19
  get isintraday(): boolean;
20
+ /**
21
+ * Detects changes in the specified timeframe.
22
+ * Returns true on the first bar of a new HTF period, false otherwise.
23
+ *
24
+ * Works by aligning current and previous bar timestamps to the target
25
+ * timeframe and comparing — if they differ, a new period has started.
26
+ */
27
+ change(timeframe: any): boolean;
20
28
  from_seconds(seconds: number): string | number;
21
29
  in_seconds(timeframe?: string): number;
22
30
  }
@@ -16,6 +16,11 @@ export declare class BoxHelper {
16
16
  */
17
17
  private _resolveColor;
18
18
  private _createBox;
19
+ /**
20
+ * Enforce max_boxes_count: auto-delete the oldest non-deleted boxes
21
+ * when the active count exceeds the limit (FIFO eviction).
22
+ */
23
+ private _enforceMaxCount;
19
24
  new(...args: any[]): BoxObject;
20
25
  any(...args: any[]): BoxObject;
21
26
  set_left(id: BoxObject, left: number): void;
@@ -15,6 +15,7 @@ export declare class LabelHelper {
15
15
  */
16
16
  private _resolve;
17
17
  private _createLabel;
18
+ private _enforceMaxCount;
18
19
  new(...args: any[]): LabelObject;
19
20
  any(...args: any[]): LabelObject;
20
21
  set_x(id: LabelObject, x: number): void;
@@ -16,6 +16,7 @@ export declare class LineHelper {
16
16
  */
17
17
  private _resolve;
18
18
  private _createLine;
19
+ private _enforceMaxCount;
19
20
  new(...args: any[]): LineObject;
20
21
  any(...args: any[]): LineObject;
21
22
  set_x1(id: LineObject, x: number): void;
@@ -20,6 +20,7 @@ export declare class PolylineHelper {
20
20
  */
21
21
  private _extractPoints;
22
22
  new(...args: any[]): PolylineObject;
23
+ private _enforceMaxCount;
23
24
  any(...args: any[]): PolylineObject;
24
25
  delete(id: PolylineObject): void;
25
26
  get all(): PolylineObject[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinets",
3
- "version": "0.9.9",
3
+ "version": "0.9.11",
4
4
  "description": "Run Pine Script anywhere. PineTS is an open-source transpiler and runtime that brings Pine Script logic to Node.js and the browser with 1:1 syntax compatibility. Reliably write, port, and run indicators or strategies on your own infrastructure.",
5
5
  "keywords": [
6
6
  "Pine Script",