T-210: M2.3s — Implement MarketDataStore.macroAsOf, crossSection, QuestDB fx('1m'), and copilot 1m routing

This commit is contained in:
Studio 2026-12-04 15:06:51 -05:00
parent a3a31f7562
commit 0c33d8ae19
23 changed files with 2440 additions and 82 deletions

View file

@ -6,6 +6,14 @@ import type { ColumnSchema, QuestDBQueryable, TableSchema } from './types';
export type M2IntradayTableName = 'bars_1m' | 'fx_1m' | 'bar_revisions';
export const M2_INTRADAY_TABLE_NAMES = [
'bars_1m',
'fx_1m',
'bar_revisions',
] as const satisfies readonly M2IntradayTableName[];
const M2_INTRADAY_TABLE_NAME_SET: ReadonlySet<string> = new Set<string>(M2_INTRADAY_TABLE_NAMES);
/**
* Contract schemas for M2 QuestDB 10.2.0 intraday tables (`design/DATA-CONTRACTS.md` §3.B).
* Kept opt-in (outside `QuestDBSchemaManager.initializeDatabase()`).
@ -144,6 +152,68 @@ export function getM2IntradayDDL(): Record<M2IntradayTableName, string> {
};
}
export interface ApplyM2IntradayDDLOptions {
/** Subset of M2 intraday tables to initialize. Defaults to all three (`bars_1m`, `fx_1m`, `bar_revisions`). */
readonly tables?: readonly M2IntradayTableName[];
}
export interface ApplyM2IntradayDDLResult {
readonly appliedTables: readonly M2IntradayTableName[];
readonly statements: readonly string[];
}
/**
* Opt-in initializer that executes `CREATE TABLE IF NOT EXISTS` DDL from
* {@link getM2IntradayDDL} for `bars_1m`, `fx_1m`, and `bar_revisions`.
*
* Kept strictly opt-in and never invoked by `QuestDBSchemaManager.initializeDatabase()`
* or `QuestDBClient.connect()`.
*/
export async function applyM2IntradayDDL(
client: { query(sql: string, params?: readonly unknown[]): Promise<unknown> },
options?: ApplyM2IntradayDDLOptions
): Promise<ApplyM2IntradayDDLResult> {
if (typeof client !== 'object' || client === null || typeof client.query !== 'function') {
throw new Error('Expected a QuestDB queryable client with a query(sql) method.');
}
let tables: M2IntradayTableName[];
if (options?.tables === undefined) {
tables = [...M2_INTRADAY_TABLE_NAMES];
} else {
if (!Array.isArray(options.tables) || options.tables.length === 0) {
throw new Error('Expected a non-empty array of M2 intraday table names.');
}
const seen = new Set<M2IntradayTableName>();
tables = [];
for (const rawName of options.tables) {
if (typeof rawName !== 'string' || !M2_INTRADAY_TABLE_NAME_SET.has(rawName)) {
throw new Error(
`Unknown M2 intraday table "${String(rawName)}". Expected one of: ${M2_INTRADAY_TABLE_NAMES.join(', ')}.`
);
}
const name = rawName as M2IntradayTableName;
if (!seen.has(name)) {
seen.add(name);
tables.push(name);
}
}
}
const ddl = getM2IntradayDDL();
const statements: string[] = [];
for (const table of tables) {
const sql = ddl[table];
await client.query(sql);
statements.push(sql);
}
return {
appliedTables: tables,
statements,
};
}
/**
* QuestDB Schema Manager
*