mostlyright 0.1.0-rc.7
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/bounds-KSTXL77E.mjs +46 -0
- package/dist/bounds-KSTXL77E.mjs.map +1 -0
- package/dist/chunk-6ERO2BIY.mjs +436 -0
- package/dist/chunk-6ERO2BIY.mjs.map +1 -0
- package/dist/chunk-J5LGTIGS.mjs +10 -0
- package/dist/chunk-J5LGTIGS.mjs.map +1 -0
- package/dist/chunk-UKIFUUDX.mjs +108 -0
- package/dist/chunk-UKIFUUDX.mjs.map +1 -0
- package/dist/chunk-VESWR46G.mjs +82 -0
- package/dist/chunk-VESWR46G.mjs.map +1 -0
- package/dist/chunk-WYZFDCNR.mjs +1609 -0
- package/dist/chunk-WYZFDCNR.mjs.map +1 -0
- package/dist/iem-5RVPI3TY.mjs +11 -0
- package/dist/iem-5RVPI3TY.mjs.map +1 -0
- package/dist/iem-asos-O4CQWBXK.mjs +15 -0
- package/dist/iem-asos-O4CQWBXK.mjs.map +1 -0
- package/dist/index.bundle.mjs +4033 -0
- package/dist/index.bundle.mjs.map +1 -0
- package/dist/index.cjs +967 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +295 -0
- package/dist/index.d.ts +295 -0
- package/dist/index.global.js +6350 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.mjs +953 -0
- package/dist/index.mjs.map +1 -0
- package/dist/src-5L5C2EE7.mjs +88 -0
- package/dist/src-5L5C2EE7.mjs.map +1 -0
- package/package.json +46 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { SourceMismatchRole } from '@mostlyrightmd/core';
|
|
2
|
+
import * as core from '@mostlyrightmd/core';
|
|
3
|
+
export { core };
|
|
4
|
+
export { LiveStreamError, NoLiveDataError, SourceMismatchRole, helloCore } from '@mostlyrightmd/core';
|
|
5
|
+
import { Observation } from '@mostlyrightmd/weather';
|
|
6
|
+
import * as weather from '@mostlyrightmd/weather';
|
|
7
|
+
export { weather };
|
|
8
|
+
export { LatestOptions, LiveObservation, LiveSource, LiveSourceTag, POLITE_FLOORS_S, SOURCE_IDENTITY_TAGS, SUPPORTED_SOURCES, StreamOptions, helloWeather, isLiveSource, latest, sourceTag, stream, validatePollSeconds, validateSource } from '@mostlyrightmd/weather';
|
|
9
|
+
import * as markets from '@mostlyrightmd/markets';
|
|
10
|
+
export { markets };
|
|
11
|
+
export { helloMarkets } from '@mostlyrightmd/markets';
|
|
12
|
+
import { CacheStore } from '@mostlyrightmd/core/internal/cache';
|
|
13
|
+
import { PairsRow } from '@mostlyrightmd/core/internal/pairs';
|
|
14
|
+
export { PairsRow } from '@mostlyrightmd/core/internal/pairs';
|
|
15
|
+
|
|
16
|
+
/** The four mutually-exclusive selector names. */
|
|
17
|
+
declare const SELECTOR_NAMES: readonly ["station", "city", "contract", "contracts"];
|
|
18
|
+
type SelectorName = (typeof SELECTOR_NAMES)[number];
|
|
19
|
+
/**
|
|
20
|
+
* Structured warning emitted when `stationOverride` deliberately
|
|
21
|
+
* mismatches the contract's canonical settlement station. The output
|
|
22
|
+
* row carries `settlementMismatch: true`.
|
|
23
|
+
*
|
|
24
|
+
* JS has no `warnings.warn()` analogue; callers receive these via the
|
|
25
|
+
* `onWarning?` callback in ResearchOptions.
|
|
26
|
+
*/
|
|
27
|
+
interface StationOverrideWarning {
|
|
28
|
+
readonly kind: "StationOverrideWarning";
|
|
29
|
+
readonly contractStation: string;
|
|
30
|
+
readonly overrideStation: string;
|
|
31
|
+
readonly message: string;
|
|
32
|
+
}
|
|
33
|
+
/** Selector kwargs accepted by research(). Exactly one MUST be provided. */
|
|
34
|
+
interface SelectorArgs {
|
|
35
|
+
readonly station?: string;
|
|
36
|
+
readonly city?: string;
|
|
37
|
+
readonly contract?: string;
|
|
38
|
+
readonly contracts?: ReadonlyArray<string>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validate selector arity. Returns the active selector name; throws when
|
|
42
|
+
* zero or >1 selectors are provided.
|
|
43
|
+
*/
|
|
44
|
+
declare function validateSelectors(args: SelectorArgs): SelectorName;
|
|
45
|
+
/**
|
|
46
|
+
* Resolve a `"<issuer>:<id>"` contract id to `[station, issuer]`.
|
|
47
|
+
*
|
|
48
|
+
* Supported: `kalshi:KHIGH<CITY>` / `kalshi:KXHIGH<CITY>-<DATE>-<STRIKE>`
|
|
49
|
+
* and `kalshi:KLOW<CITY>` / `kalshi:KXLOW<CITY>-<DATE>-<STRIKE>`.
|
|
50
|
+
*
|
|
51
|
+
* Polymarket contract resolution requires an event_id → station lookup
|
|
52
|
+
* (via polymarket-discover); Phase 10 v0.2 defers to v0.3 and throws.
|
|
53
|
+
*/
|
|
54
|
+
declare function resolveContract(contractId: string): readonly [string, string];
|
|
55
|
+
/**
|
|
56
|
+
* Resolve a city slug to all stations any issuer settles against.
|
|
57
|
+
* Returns deduplicated array in stable order: Kalshi → Polymarket default/high/low
|
|
58
|
+
* → Polymarket denylist backstops.
|
|
59
|
+
*/
|
|
60
|
+
declare function resolveCity(city: string): readonly string[];
|
|
61
|
+
/**
|
|
62
|
+
* Return the list of `"<issuer>:<ticker>"` markers that settle against
|
|
63
|
+
* `station` for `city`. Empty array when no issuer settles against this
|
|
64
|
+
* station (typically a denylist backstop).
|
|
65
|
+
*/
|
|
66
|
+
declare function annotateSettlesFor(station: string, city: string | null): readonly string[];
|
|
67
|
+
/**
|
|
68
|
+
* Build a structured `StationOverrideWarning` payload. Callers receive
|
|
69
|
+
* these via the optional `onWarning?` callback on research options.
|
|
70
|
+
*/
|
|
71
|
+
declare function buildOverrideWarning(contractStation: string, overrideStation: string): StationOverrideWarning;
|
|
72
|
+
|
|
73
|
+
interface ResearchOptions {
|
|
74
|
+
/** Forward to all underlying fetchers; aborts the whole pipeline. */
|
|
75
|
+
signal?: AbortSignal;
|
|
76
|
+
/** AWC lookback window in hours. Default 168 (AWC max). Clamped by the fetcher. */
|
|
77
|
+
awcHours?: number;
|
|
78
|
+
/** Polite-delay (ms) between successive IEM ASOS year chunks. Default 1000. */
|
|
79
|
+
iemPolitenessMs?: number;
|
|
80
|
+
/** Polite-delay (ms) between successive GHCNh year requests. Default 1000. */
|
|
81
|
+
ghcnhPolitenessMs?: number;
|
|
82
|
+
/** Polite-delay (ms) between successive CLI year requests. Default 1000. */
|
|
83
|
+
cliPolitenessMs?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Reference clock for the AWC-window overlap check (test-only seam).
|
|
86
|
+
* Defaults to `new Date()`. Pass an override to force-include AWC for
|
|
87
|
+
* historical date ranges in unit tests.
|
|
88
|
+
*/
|
|
89
|
+
now?: Date;
|
|
90
|
+
/**
|
|
91
|
+
* Pluggable cache backend (TS-W3). When omitted, uses
|
|
92
|
+
* `defaultCacheStore()` (auto-detects IndexedDB → FsStore → MemoryStore).
|
|
93
|
+
* Pass `null` to opt out of caching entirely.
|
|
94
|
+
*/
|
|
95
|
+
cache?: CacheStore | null;
|
|
96
|
+
/** Cross-issuer city selector. Returns rows for every station that any
|
|
97
|
+
* issuer settles against (Kalshi + Polymarket + denylist backstops). */
|
|
98
|
+
city?: string;
|
|
99
|
+
/** Single-contract selector. Format: `"<issuer>:<id>"` (e.g.
|
|
100
|
+
* `"kalshi:KXHIGHNYC-25MAY26-T79"`). Auto-resolves to the contract's
|
|
101
|
+
* canonical settlement station via the Phase 8 catalog. */
|
|
102
|
+
contract?: string;
|
|
103
|
+
/** Multi-contract selector for basis-trade research. */
|
|
104
|
+
contracts?: ReadonlyArray<string>;
|
|
105
|
+
/** Override the contract's canonical settlement station. Emits a
|
|
106
|
+
* StationOverrideWarning via `onWarning?`; output row carries
|
|
107
|
+
* `settlementMismatch: true`. Only valid with `contract` selector. */
|
|
108
|
+
stationOverride?: string;
|
|
109
|
+
/** Mode 1 source subset — dedupe within. Mutually exclusive with `source`. */
|
|
110
|
+
sources?: ReadonlyArray<string>;
|
|
111
|
+
/** Mode 2 single-source pin — error on mismatch. Mutually exclusive with `sources`. */
|
|
112
|
+
source?: string;
|
|
113
|
+
/** Attach per-issuer trade timeseries via @mostlyrightmd/markets/trades.
|
|
114
|
+
* Requires `contract` or `contracts`. */
|
|
115
|
+
includeTrades?: boolean;
|
|
116
|
+
/** Callback receiving Phase 10 StationOverrideWarning (no `warnings.warn()`
|
|
117
|
+
* analogue in JS). */
|
|
118
|
+
onWarning?: (w: StationOverrideWarning) => void;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Build daily research rows for a station + date window.
|
|
122
|
+
*
|
|
123
|
+
* @param station NWS 3-letter code (e.g. "NYC") OR 4-letter ICAO (e.g. "KNYC").
|
|
124
|
+
* @param fromDate Inclusive start date, ISO YYYY-MM-DD (LST).
|
|
125
|
+
* @param toDate Inclusive end date, ISO YYYY-MM-DD (LST).
|
|
126
|
+
* @param opts See {@link ResearchOptions}.
|
|
127
|
+
*
|
|
128
|
+
* Returns an immutable array of frozen {@link PairsRow}s — one per LST day
|
|
129
|
+
* in `[fromDate, toDate]`. Each row carries:
|
|
130
|
+
* - `cli_*` populated from IEM CLI (final preferred per `mergeClimate`).
|
|
131
|
+
* - `obs_*` daily aggregates over the 3-source merged observations
|
|
132
|
+
* (AWC > IEM > GHCNh per `mergeObservations`).
|
|
133
|
+
* - `fcst_*` unconditionally null (Mode 1).
|
|
134
|
+
* - `market_close_utc` formatted `YYYY-MM-DDTHH:MM:SSZ`.
|
|
135
|
+
*
|
|
136
|
+
* Throws on unknown station, malformed dates, or fromDate > toDate.
|
|
137
|
+
* AbortSignal propagates from underlying fetchers.
|
|
138
|
+
*/
|
|
139
|
+
declare function research(station: string, fromDate: string, toDate: string, opts?: ResearchOptions): Promise<ReadonlyArray<PairsRow>>;
|
|
140
|
+
|
|
141
|
+
/** Mode 2 canonical source vocabulary. Exactly four dotted values. */
|
|
142
|
+
declare const MODE2_SOURCES: readonly ["iem.archive", "iem.live", "awc.live", "ghcnh.archive"];
|
|
143
|
+
/**
|
|
144
|
+
* Mode 2 source-identity type. Const-union derived from the
|
|
145
|
+
* `MODE2_SOURCES` tuple-literal (NOT a TS `enum` — `enum` defeats
|
|
146
|
+
* tree-shaking per TS Architect rubric §5).
|
|
147
|
+
*/
|
|
148
|
+
type Mode2Source = (typeof MODE2_SOURCES)[number];
|
|
149
|
+
/**
|
|
150
|
+
* Map each canonical dotted source to the bare parser-emitted tags
|
|
151
|
+
* that satisfy it. Parsers emit bare `iem`/`awc`/`ghcnh` per
|
|
152
|
+
* packages-ts/weather; mostlyright' canonical vocab is dotted. The
|
|
153
|
+
* alias table bridges both at the boundary without rewriting the
|
|
154
|
+
* per-row source — downstream consumers see the truthful
|
|
155
|
+
* parser-emitted tag.
|
|
156
|
+
*
|
|
157
|
+
* Mirrors packages/core/src/mostlyright/mode2.py:55-63.
|
|
158
|
+
*/
|
|
159
|
+
declare const SOURCE_ALIASES: ReadonlyMap<Mode2Source, ReadonlySet<string>>;
|
|
160
|
+
/**
|
|
161
|
+
* Type-guard: narrow an unknown value to {@link Mode2Source}. Returns
|
|
162
|
+
* true iff `value` is one of the four canonical dotted strings.
|
|
163
|
+
* Bare-form inputs (`'iem'`, `'awc'`, `'ghcnh'`) return false — TS
|
|
164
|
+
* narrows what Python widens.
|
|
165
|
+
*/
|
|
166
|
+
declare function isMode2Source(value: unknown): value is Mode2Source;
|
|
167
|
+
/**
|
|
168
|
+
* Throw {@link SourceMismatchError} if any row's `source` field
|
|
169
|
+
* disagrees with the expected source vocabulary. Rows missing the
|
|
170
|
+
* `source` field (undefined / null / non-string) are skipped
|
|
171
|
+
* (matches Python mode2.py:181-182 — `if "source" not in df.columns:
|
|
172
|
+
* return`). Empty `rows` passes silently.
|
|
173
|
+
*
|
|
174
|
+
* The `expected` parameter accepts EITHER:
|
|
175
|
+
*
|
|
176
|
+
* - a single string — the most common case; downstream callers
|
|
177
|
+
* can pass `"iem.archive"` and the check is `src === "iem.archive"`.
|
|
178
|
+
* - a `ReadonlySet<string>` — used by `researchBySource` to pass
|
|
179
|
+
* the {@link SOURCE_ALIASES} entry so bare-form parser tags
|
|
180
|
+
* (`'iem'`) are accepted alongside the dotted canonical form
|
|
181
|
+
* (`'iem.archive'`). Without this, the per-row source-preserved
|
|
182
|
+
* invariant (Python mode2.py:161-166) would force the assertion
|
|
183
|
+
* to fire on every Mode 2 call.
|
|
184
|
+
*
|
|
185
|
+
* @param rows rows to check (any shape with `source?: string`)
|
|
186
|
+
* @param expected the source string OR alias-set the caller asked for
|
|
187
|
+
* @param role role-name vocabulary; defaults to 'observations'
|
|
188
|
+
*
|
|
189
|
+
* @throws SourceMismatchError with `schemaSource` = the expected label
|
|
190
|
+
* (the input string, or `[...accept].sort().join("|")`
|
|
191
|
+
* when an alias-set was passed), `dataSource` =
|
|
192
|
+
* first sorted distinct mismatched source,
|
|
193
|
+
* `role` = the caller-provided role,
|
|
194
|
+
* `catalogWarning` = null.
|
|
195
|
+
*/
|
|
196
|
+
declare function assertSourceIdentity<Row extends {
|
|
197
|
+
source?: string | null | undefined;
|
|
198
|
+
}>(rows: ReadonlyArray<Row>, expected: string | ReadonlySet<string>, role?: SourceMismatchRole): void;
|
|
199
|
+
/** Mode 2 caller-supplied options. Subset of `ResearchOptions` — Mode 2
|
|
200
|
+
* returns observations only, so forecast + climate + cache opts are
|
|
201
|
+
* intentionally excluded. */
|
|
202
|
+
interface ResearchBySourceOptions {
|
|
203
|
+
/** Forward to the underlying fetcher; aborts the dispatch. */
|
|
204
|
+
signal?: AbortSignal;
|
|
205
|
+
/** AWC lookback window in hours (clamped by the fetcher). Default 168. */
|
|
206
|
+
awcHours?: number;
|
|
207
|
+
/** Polite-delay (ms) between IEM ASOS yearly chunks. Default 1000. */
|
|
208
|
+
iemPolitenessMs?: number;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Mode 2 source-explicit observation fetch.
|
|
212
|
+
*
|
|
213
|
+
* Dispatches to a single source's fetcher (no merge) and returns raw
|
|
214
|
+
* {@link Observation}s tagged with that source. Mirrors Python
|
|
215
|
+
* `mostlyright.mode2.research_by_source` (packages/core/src/mostlyright/mode2.py).
|
|
216
|
+
*
|
|
217
|
+
* The four supported sources:
|
|
218
|
+
*
|
|
219
|
+
* - `'iem.archive'` → IEM ASOS historical CSVs (METAR + SPECI).
|
|
220
|
+
* - `'iem.live'` → v0.1.0 parity gap; throws. Use `'iem.archive'`.
|
|
221
|
+
* - `'awc.live'` → AWC live METAR JSON (≤168h lookback).
|
|
222
|
+
* - `'ghcnh.archive'` → NCEI GHCNh PSV (US stations only).
|
|
223
|
+
*
|
|
224
|
+
* The returned rows preserve the parser-emitted per-row `source` field
|
|
225
|
+
* verbatim — NEVER rewritten to the dotted canonical form. Bare tags
|
|
226
|
+
* (`'iem'`, `'awc'`, `'ghcnh'`) survive intact so downstream Validator
|
|
227
|
+
* schemas see the truthful provenance. Mode 2 still calls
|
|
228
|
+
* {@link assertSourceIdentity} internally (defense-in-depth) before
|
|
229
|
+
* returning — using the {@link SOURCE_ALIASES} entry so the bare-form
|
|
230
|
+
* tags pass.
|
|
231
|
+
*
|
|
232
|
+
* @param station NWS 3-letter code (e.g. `"NYC"`) OR 4-letter ICAO (e.g. `"KNYC"`).
|
|
233
|
+
* @param source One of {@link MODE2_SOURCES}.
|
|
234
|
+
* @param fromDate Inclusive start, ISO `YYYY-MM-DD`.
|
|
235
|
+
* @param toDate Inclusive end, ISO `YYYY-MM-DD`.
|
|
236
|
+
* @param opts See {@link ResearchBySourceOptions}.
|
|
237
|
+
*
|
|
238
|
+
* @returns Frozen array of {@link Observation}s whose `source` is in
|
|
239
|
+
* `SOURCE_ALIASES.get(source)`. Empty array on no data
|
|
240
|
+
* (NOT a throw).
|
|
241
|
+
*
|
|
242
|
+
* @throws Error if `source` is not one of {@link MODE2_SOURCES}.
|
|
243
|
+
* Throws BEFORE any network call — no quota burn
|
|
244
|
+
* on invalid input.
|
|
245
|
+
* @throws Error if `source === 'iem.live'` (v0.1.0 parity gap;
|
|
246
|
+
* v0.2 will add per-month live IEM).
|
|
247
|
+
* @throws Error if `station` is unknown, or dates are malformed.
|
|
248
|
+
* @throws NotFoundError if `source === 'ghcnh.archive'` and `station`
|
|
249
|
+
* is non-US (GHCNh PSV files are US-only).
|
|
250
|
+
* @throws SourceMismatchError if a row's `source` disagrees with the alias
|
|
251
|
+
* set for `source` (defense-in-depth; should
|
|
252
|
+
* never fire under correct fetcher behavior).
|
|
253
|
+
*/
|
|
254
|
+
declare function researchBySource(station: string, source: Mode2Source, fromDate: string, toDate: string, opts?: ResearchBySourceOptions): Promise<ReadonlyArray<Observation>>;
|
|
255
|
+
|
|
256
|
+
/** One row per station in the resolved city neighborhood. */
|
|
257
|
+
interface DiscoverRow {
|
|
258
|
+
/** Echo of the input city. */
|
|
259
|
+
readonly city: string;
|
|
260
|
+
/** 4-char K-prefix ICAO. */
|
|
261
|
+
readonly station: string;
|
|
262
|
+
/**
|
|
263
|
+
* `"<issuer>:<ticker>"` markers that resolve against this station.
|
|
264
|
+
* Empty array = denylist backstop surfaced for explicit awareness.
|
|
265
|
+
*/
|
|
266
|
+
readonly settlesFor: ReadonlyArray<string>;
|
|
267
|
+
}
|
|
268
|
+
/** Envelope mirrors the Python `df.attrs` pattern. */
|
|
269
|
+
interface DiscoverResult {
|
|
270
|
+
readonly rows: ReadonlyArray<DiscoverRow>;
|
|
271
|
+
readonly city: string;
|
|
272
|
+
readonly source: "discover";
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Return per-station discovery table for `city`.
|
|
276
|
+
*
|
|
277
|
+
* Each row shows one settlement station + the issuer:ticker markers that
|
|
278
|
+
* resolve against it. Stations in the per-city Polymarket denylist also
|
|
279
|
+
* appear with empty `settlesFor` so quants see the full neighborhood
|
|
280
|
+
* before deciding whether to use `stationOverride`.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* const result = discover({ city: "NYC" });
|
|
284
|
+
* // rows include {station: "KNYC", settlesFor: ["kalshi:NYC"]},
|
|
285
|
+
* // {station: "KLGA", settlesFor: ["polymarket:nyc"]},
|
|
286
|
+
* // {station: "KJFK", settlesFor: []}, // denylist
|
|
287
|
+
* // {station: "KEWR", settlesFor: []}.
|
|
288
|
+
*/
|
|
289
|
+
declare function discover(args: {
|
|
290
|
+
readonly city: string;
|
|
291
|
+
}): DiscoverResult;
|
|
292
|
+
|
|
293
|
+
declare const version = "0.0.0";
|
|
294
|
+
|
|
295
|
+
export { type DiscoverResult, type DiscoverRow, MODE2_SOURCES, type Mode2Source, type ResearchBySourceOptions, type ResearchOptions, SELECTOR_NAMES, SOURCE_ALIASES, type SelectorArgs, type SelectorName, type StationOverrideWarning, annotateSettlesFor, assertSourceIdentity, buildOverrideWarning, discover, isMode2Source, research, researchBySource, resolveCity, resolveContract, validateSelectors, version };
|