T-122: M1.3g — @stock-bot/research: Vault-fenced universe planner + adapter method (survivorship-free active listings on a date from curated bars_1d Parquet, US_EQ / CA_EQ / US_CA_EQ) with tests and local benchmark (no new dependencies)
This commit is contained in:
parent
91c7411ed9
commit
0df1ef92ac
2 changed files with 114 additions and 24 deletions
|
|
@ -82,6 +82,10 @@ const INT32_MIN = -2_147_483_648;
|
|||
const INT32_MAX = 2_147_483_647;
|
||||
const MAX_ECMASCRIPT_EPOCH_MS = 8_640_000_000_000_000;
|
||||
const MS_PER_DAY = 86_400_000;
|
||||
// 0000-01-01T00:00:00.000Z: earliest epoch ms that formats as unsigned YYYY-MM-DD.
|
||||
const MIN_ISO_DATE_EPOCH_MS = -62_167_219_200_000;
|
||||
// 9999-12-31T00:00:00.000Z: latest UTC midnight representable as YYYY-MM-DD.
|
||||
const MAX_ISO_DATE_MIDNIGHT_MS = 253_402_214_400_000;
|
||||
const DATE_ONLY_RE = /^\d{4}-\d{2}-\d{2}$/;
|
||||
const ISO_FRACTIONAL_RE = /\.(\d+)(?:Z|[+-]\d{2}:\d{2})$/;
|
||||
const STRICT_INT_RE = /^-?\d+$/;
|
||||
|
|
@ -603,17 +607,42 @@ function validateUniverseRef(raw: unknown): readonly string[] {
|
|||
);
|
||||
}
|
||||
|
||||
function validateUniverseLookbackDays(raw: unknown): number {
|
||||
if (raw === undefined) {
|
||||
return DEFAULT_UNIVERSE_LOOKBACK_DAYS;
|
||||
}
|
||||
if (typeof raw !== 'number' || !Number.isSafeInteger(raw) || raw < 1) {
|
||||
function validateUniverseLookbackDays(raw: unknown, vaultCutoffTs?: number): number {
|
||||
const days = raw === undefined ? DEFAULT_UNIVERSE_LOOKBACK_DAYS : raw;
|
||||
if (typeof days !== 'number' || !Number.isSafeInteger(days) || days < 1) {
|
||||
throw new MarketDataStoreValidationError(
|
||||
`Invalid universeLookbackDays "${String(raw)}". Expected a positive safe integer.`,
|
||||
'universeLookbackDays'
|
||||
);
|
||||
}
|
||||
return raw;
|
||||
|
||||
const lookbackMs = days * MS_PER_DAY;
|
||||
if (
|
||||
!Number.isSafeInteger(lookbackMs) ||
|
||||
MAX_ISO_DATE_MIDNIGHT_MS - lookbackMs < MIN_ISO_DATE_EPOCH_MS
|
||||
) {
|
||||
throw new MarketDataStoreValidationError(
|
||||
`Invalid universeLookbackDays "${days}". Lookback window exceeds supported YYYY-MM-DD UTC date range.`,
|
||||
'universeLookbackDays'
|
||||
);
|
||||
}
|
||||
|
||||
if (vaultCutoffTs !== undefined) {
|
||||
const latestPermittedDateMs =
|
||||
Math.floor(Math.min(vaultCutoffTs - 1, MAX_ISO_DATE_MIDNIGHT_MS) / MS_PER_DAY) * MS_PER_DAY;
|
||||
const latestLookbackStartMs = latestPermittedDateMs - lookbackMs;
|
||||
if (
|
||||
!Number.isSafeInteger(latestLookbackStartMs) ||
|
||||
latestLookbackStartMs < MIN_ISO_DATE_EPOCH_MS
|
||||
) {
|
||||
throw new MarketDataStoreValidationError(
|
||||
`Invalid universeLookbackDays "${days}". Lookback window exceeds supported YYYY-MM-DD UTC date range for vaultCutoffTs.`,
|
||||
'universeLookbackDays'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return days;
|
||||
}
|
||||
|
||||
function validateContext(ctx: DuckDbPlanContext): string {
|
||||
|
|
@ -1508,17 +1537,10 @@ export function planUniverseQuery(q: UniverseQuery, ctx: DuckDbPlanContext): Pla
|
|||
throw err;
|
||||
}
|
||||
|
||||
const lookbackMs = lookbackDays * MS_PER_DAY;
|
||||
if (!Number.isSafeInteger(lookbackMs)) {
|
||||
const lookbackStartMs = fencedDate.fromMs - lookbackDays * MS_PER_DAY;
|
||||
if (!Number.isSafeInteger(lookbackStartMs) || lookbackStartMs < MIN_ISO_DATE_EPOCH_MS) {
|
||||
throw new MarketDataStoreValidationError(
|
||||
`Invalid universeLookbackDays "${lookbackDays}". Lookback window overflows safe millisecond range.`,
|
||||
'universeLookbackDays'
|
||||
);
|
||||
}
|
||||
const lookbackStartMs = fencedDate.fromMs - lookbackMs;
|
||||
if (!Number.isSafeInteger(lookbackStartMs) || lookbackStartMs < -MAX_ECMASCRIPT_EPOCH_MS) {
|
||||
throw new MarketDataStoreValidationError(
|
||||
`Invalid universeLookbackDays "${lookbackDays}". Lookback start precedes supported UTC date range.`,
|
||||
`Invalid universeLookbackDays "${lookbackDays}". Lookback start precedes supported YYYY-MM-DD UTC date range.`,
|
||||
'universeLookbackDays'
|
||||
);
|
||||
}
|
||||
|
|
@ -1875,7 +1897,10 @@ export function createDuckDbMarketDataStore(options: DuckDbMarketDataStoreOption
|
|||
);
|
||||
}
|
||||
|
||||
const universeLookbackDays = validateUniverseLookbackDays(options.universeLookbackDays);
|
||||
const universeLookbackDays = validateUniverseLookbackDays(
|
||||
options.universeLookbackDays,
|
||||
vaultCutoffTs
|
||||
);
|
||||
|
||||
const budget = resolveDuckDbConnectionBudget(options.env);
|
||||
const planCtx: DuckDbPlanContext = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue