@tidal-ts/core 0.25.0 → 0.26.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/dist/derive.d.ts CHANGED
@@ -48,6 +48,38 @@ export type DeriveOp = TidalOp | (string & {});
48
48
  * (PND-PROCJOIN — position 5 on pond#543).
49
49
  */
50
50
  export declare const COMPARE_PREFIX = "cmp_";
51
+ /**
52
+ * The column prefix for a series of a **locked symbol** — a compare whose
53
+ * other side is a fixed ticker (`SPY`) rather than the bar's comparison:
54
+ * `cmp_@SPY_close`. It starts with {@link COMPARE_PREFIX} on purpose: a
55
+ * locked-symbol column IS another symbol's reading, so everything that treats
56
+ * comparison columns specially (the dashed texture, the refusal to compare a
57
+ * compare, the joins) treats it the same way. The `@` keeps it apart from the
58
+ * comparison's own columns, which never start with one.
59
+ */
60
+ export declare const pinnedPrefix: (symbol: string) => string;
61
+ /**
62
+ * A column with any other-symbol prefix taken off — the comparison's (`cmp_`)
63
+ * or a locked symbol's (`cmp_@SPY_`): `cmp_@SPY_iv21` and `cmp_iv21` both give
64
+ * `iv21`. The name to look up a label or a unit by, which does not depend on
65
+ * whose reading it is. A column with neither prefix comes back as it is.
66
+ */
67
+ export declare function stripOtherSymbol(column: string): string;
68
+ /** Whether `symbol` can name a locked symbol's columns: letters, digits and
69
+ * `.` `-` `^` only — never `_`, which ends the prefix. */
70
+ export declare const isPinnableSymbol: (symbol: string) => boolean;
71
+ /**
72
+ * Rebind an input onto the columns under `prefix`: the prefix lands on the
73
+ * raw column LEAVES, so a nested spec keeps its shape and reads another
74
+ * symbol's columns — `sma(close)` under `cmp_@SPY_` reads `cmp_@SPY_close`.
75
+ * A leaf already reading another symbol (any {@link COMPARE_PREFIX} column)
76
+ * is left alone: prefixing it again would name a column no join carries.
77
+ */
78
+ export declare function underPrefix(input: DeriveInput, prefix: string): DeriveInput;
79
+ /** Whether any raw column `spec` reads, at any depth, passes `test`. */
80
+ export declare function readsColumn(spec: DeriveSpec, test: (column: string) => boolean): boolean;
81
+ /** Whether any raw column `spec` reads, at any depth, starts with `prefix`. */
82
+ export declare const readsPrefix: (spec: DeriveSpec, prefix: string) => boolean;
51
83
  /** The two-input (pair) subset of {@link DeriveOp}. */
52
84
  export type PairOp = 'diff' | 'ratio' | 'logRatio';
53
85
  /** True if `op` takes a second input. */
package/dist/derive.js CHANGED
@@ -11,6 +11,61 @@ import { bind, columnsOf, createRegistry, int, num, run, specId, explain, } from
11
11
  * (PND-PROCJOIN — position 5 on pond#543).
12
12
  */
13
13
  export const COMPARE_PREFIX = 'cmp_';
14
+ /**
15
+ * The column prefix for a series of a **locked symbol** — a compare whose
16
+ * other side is a fixed ticker (`SPY`) rather than the bar's comparison:
17
+ * `cmp_@SPY_close`. It starts with {@link COMPARE_PREFIX} on purpose: a
18
+ * locked-symbol column IS another symbol's reading, so everything that treats
19
+ * comparison columns specially (the dashed texture, the refusal to compare a
20
+ * compare, the joins) treats it the same way. The `@` keeps it apart from the
21
+ * comparison's own columns, which never start with one.
22
+ */
23
+ export const pinnedPrefix = (symbol) => `${COMPARE_PREFIX}@${symbol}_`;
24
+ /**
25
+ * A column with any other-symbol prefix taken off — the comparison's (`cmp_`)
26
+ * or a locked symbol's (`cmp_@SPY_`): `cmp_@SPY_iv21` and `cmp_iv21` both give
27
+ * `iv21`. The name to look up a label or a unit by, which does not depend on
28
+ * whose reading it is. A column with neither prefix comes back as it is.
29
+ */
30
+ export function stripOtherSymbol(column) {
31
+ if (!column.startsWith(COMPARE_PREFIX))
32
+ return column;
33
+ const rest = column.slice(COMPARE_PREFIX.length);
34
+ if (!rest.startsWith('@'))
35
+ return rest;
36
+ // A pinnable symbol never holds `_`, so the first one ends the prefix.
37
+ const end = rest.indexOf('_');
38
+ return end > 1 ? rest.slice(end + 1) : rest;
39
+ }
40
+ /** Whether `symbol` can name a locked symbol's columns: letters, digits and
41
+ * `.` `-` `^` only — never `_`, which ends the prefix. */
42
+ export const isPinnableSymbol = (symbol) => /^[A-Za-z0-9.^-]{1,32}$/.test(symbol);
43
+ /**
44
+ * Rebind an input onto the columns under `prefix`: the prefix lands on the
45
+ * raw column LEAVES, so a nested spec keeps its shape and reads another
46
+ * symbol's columns — `sma(close)` under `cmp_@SPY_` reads `cmp_@SPY_close`.
47
+ * A leaf already reading another symbol (any {@link COMPARE_PREFIX} column)
48
+ * is left alone: prefixing it again would name a column no join carries.
49
+ */
50
+ export function underPrefix(input, prefix) {
51
+ if (typeof input === 'string')
52
+ return input.startsWith(COMPARE_PREFIX) ? input : `${prefix}${input}`;
53
+ if (isPickedInput(input))
54
+ return { from: underPrefix(input.from, prefix), output: input.output };
55
+ return { ...input, inputs: (input.inputs ?? []).map((i) => underPrefix(i, prefix)) };
56
+ }
57
+ /** Whether any raw column `spec` reads, at any depth, passes `test`. */
58
+ export function readsColumn(spec, test) {
59
+ // `Array.isArray`: persisted state is untyped here, and a stored spec with a
60
+ // non-array `inputs` reads as "reads nothing", never a throw mid-fold.
61
+ if (!isSpecLike(spec) || !Array.isArray(spec.inputs))
62
+ return false;
63
+ return spec.inputs.some((i) => typeof i === 'string'
64
+ ? test(i)
65
+ : readsColumn(isPickedInput(i) ? i.from : i, test));
66
+ }
67
+ /** Whether any raw column `spec` reads, at any depth, starts with `prefix`. */
68
+ export const readsPrefix = (spec, prefix) => readsColumn(spec, (column) => column.startsWith(prefix));
14
69
  /** True if `op` takes a second input. */
15
70
  export const isPairOp = (op) => op === 'diff' || op === 'ratio' || op === 'logRatio';
16
71
  /** True if an input picks one output of a nested spec. Total over persisted
@@ -439,7 +494,7 @@ export function usesCompare(spec) {
439
494
  * `underCompare`, used to name a leg independently of the role it reads. */
440
495
  function unCompare(input) {
441
496
  if (typeof input === 'string')
442
- return input.startsWith(COMPARE_PREFIX) ? input.slice(COMPARE_PREFIX.length) : input;
497
+ return stripOtherSymbol(input);
443
498
  if (isPickedInput(input))
444
499
  return { from: unCompare(input.from), output: input.output };
445
500
  if (!isSpecLike(input))
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { BAR_INTERVAL_MS, type Instrument, type InstrumentKind, type BarInterval
2
2
  export { generatePriceSeries, buildPriceSeries, DEMO_INSTRUMENTS, PRICE_SCHEMA, type PriceSeriesOptions, type PriceSeries, type PriceRow, } from './fixture.js';
3
3
  export { generateVolSeries, buildVolSeries, VOL_SCHEMA, VOL_TENORS, DEFAULT_VOL_TENOR, impliedCol, hvCol, rvCol, rvCenCol, skewCol, type VolSeries, type VolColumns, type VolTenor, type VolSeriesOptions, } from './vol.js';
4
4
  export { aggregateColumn, floorToWindow, liveWindowMs, ohlcWindow, sessionGrid, WINDOW_MS, WINDOW_LADDER, MIN_BAR_PX, autoBarWindow, type BarReducer, type SeriesWindow, } from './aggregate.js';
5
- export { applyDerived, applyDerivedReport, COMPARE_PREFIX, deriveId, deriveLineage, inputNames, substituteInput, hasPairOp, isBrokenId, isPairOp, isValidSpec, opHasPeriod, PERIOD_BOUNDS, readNumericColumn, partStudyLabel, readPart, readPairParts, specUnit, studyCatalog, TIDAL_OPS, BAND_OUTPUTS, opParams, isStudyOp, studyTag, opIsBand, opInputs, opIsMulti, opOutputs, primaryOutput, studyInputOf, studyPick, fanPick, withFanOutput, withStudyOutput, studyColumn, BAR_PRICE_COLUMNS, withStudyColumn, type StudyPick, isPickedInput, opNeedsColumns, TARGET_ROLES, opSharesSourceAxis, type OpParam, usesCompare, type DeriveSkip, type DeriveNodeTiming, type PairPart, type PartStudy, type StudyOption, type NumericColumnReader, DEFAULT_PERIOD, type DeriveInput, type PickedDeriveOutput, type DeriveSpec, type DeriveOp, type TidalOp, type PairOp, } from './derive.js';
5
+ export { applyDerived, applyDerivedReport, COMPARE_PREFIX, pinnedPrefix, isPinnableSymbol, underPrefix, readsPrefix, readsColumn, stripOtherSymbol, deriveId, deriveLineage, inputNames, substituteInput, hasPairOp, isBrokenId, isPairOp, isValidSpec, opHasPeriod, PERIOD_BOUNDS, readNumericColumn, partStudyLabel, readPart, readPairParts, specUnit, studyCatalog, TIDAL_OPS, BAND_OUTPUTS, opParams, isStudyOp, studyTag, opIsBand, opInputs, opIsMulti, opOutputs, primaryOutput, studyInputOf, studyPick, fanPick, withFanOutput, withStudyOutput, studyColumn, BAR_PRICE_COLUMNS, withStudyColumn, type StudyPick, isPickedInput, opNeedsColumns, TARGET_ROLES, opSharesSourceAxis, type OpParam, usesCompare, type DeriveSkip, type DeriveNodeTiming, type PairPart, type PartStudy, type StudyOption, type NumericColumnReader, DEFAULT_PERIOD, type DeriveInput, type PickedDeriveOutput, type DeriveSpec, type DeriveOp, type TidalOp, type PairOp, } from './derive.js';
6
6
  export { joinUnderPrefix } from './join.js';
7
7
  export { columnExtent } from './extent.js';
8
8
  export { snapshotToTimeSeries, appendToRows, type PondSnapshot, type PondAppend, type PondValue, type WireColumnSpec, } from './columnar.js';
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ export { BAR_INTERVAL_MS, } from './types.js';
2
2
  export { generatePriceSeries, buildPriceSeries, DEMO_INSTRUMENTS, PRICE_SCHEMA, } from './fixture.js';
3
3
  export { generateVolSeries, buildVolSeries, VOL_SCHEMA, VOL_TENORS, DEFAULT_VOL_TENOR, impliedCol, hvCol, rvCol, rvCenCol, skewCol, } from './vol.js';
4
4
  export { aggregateColumn, floorToWindow, liveWindowMs, ohlcWindow, sessionGrid, WINDOW_MS, WINDOW_LADDER, MIN_BAR_PX, autoBarWindow, } from './aggregate.js';
5
- export { applyDerived, applyDerivedReport, COMPARE_PREFIX, deriveId, deriveLineage, inputNames, substituteInput, hasPairOp, isBrokenId, isPairOp, isValidSpec, opHasPeriod, PERIOD_BOUNDS, readNumericColumn, partStudyLabel, readPart, readPairParts, specUnit, studyCatalog, TIDAL_OPS, BAND_OUTPUTS, opParams, isStudyOp, studyTag, opIsBand, opInputs, opIsMulti, opOutputs, primaryOutput, studyInputOf, studyPick, fanPick, withFanOutput, withStudyOutput, studyColumn, BAR_PRICE_COLUMNS, withStudyColumn, isPickedInput, opNeedsColumns, TARGET_ROLES, opSharesSourceAxis, usesCompare, DEFAULT_PERIOD, } from './derive.js';
5
+ export { applyDerived, applyDerivedReport, COMPARE_PREFIX, pinnedPrefix, isPinnableSymbol, underPrefix, readsPrefix, readsColumn, stripOtherSymbol, deriveId, deriveLineage, inputNames, substituteInput, hasPairOp, isBrokenId, isPairOp, isValidSpec, opHasPeriod, PERIOD_BOUNDS, readNumericColumn, partStudyLabel, readPart, readPairParts, specUnit, studyCatalog, TIDAL_OPS, BAND_OUTPUTS, opParams, isStudyOp, studyTag, opIsBand, opInputs, opIsMulti, opOutputs, primaryOutput, studyInputOf, studyPick, fanPick, withFanOutput, withStudyOutput, studyColumn, BAR_PRICE_COLUMNS, withStudyColumn, isPickedInput, opNeedsColumns, TARGET_ROLES, opSharesSourceAxis, usesCompare, DEFAULT_PERIOD, } from './derive.js';
6
6
  export { joinUnderPrefix } from './join.js';
7
7
  export { columnExtent } from './extent.js';
8
8
  export { snapshotToTimeSeries, appendToRows, } from './columnar.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-ts/core",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "private": false,
5
5
  "description": "Financial time-series vocabulary on pond-ts: the study/derive seam, the vol schema, bar windows, the columnar adapter and session helpers.",
6
6
  "license": "MIT",