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:31:29 -05:00
parent 5e255d7e30
commit 373936c312
6 changed files with 168 additions and 129 deletions

View file

@ -47,58 +47,34 @@ export interface OpenQuestDbPgExecutorOptions {
const SAFE_ERROR_CODE_RE = /^[A-Z0-9_]{1,32}$/;
function isQuestDbUrlTlsParamKey(rawKey: string): boolean {
const key = rawKey.trim().toLowerCase();
return key === 'uselibpqcompat' || key === 'ssl' || key.startsWith('ssl');
}
/**
* Returns `true` when an explicit boolean `ssl` setting conflicts with SSL
* query parameters (`sslmode`, `ssl`, `sslcert`, `sslkey`, `sslrootcert`)
* embedded in `rawUrl`.
* Returns `true` when `rawUrl` contains any TLS/SSL query parameter
* (`ssl`, `sslmode`, `sslcert`, `sslkey`, `sslrootcert`, `uselibpqcompat`, or
* any other `ssl*` parameter).
*
* TLS settings must have a single source of truth: either configure TLS in the
* URL query string (omitting the explicit `ssl` flag) or pass the explicit
* `ssl` flag with a URL that contains no TLS query parameters.
*/
export function hasConflictingQuestDbUrlSsl(rawUrl: string, explicitSsl: boolean): boolean {
export function hasQuestDbUrlTlsOptions(rawUrl: string): boolean {
let parsed: URL;
try {
parsed = new URL(rawUrl);
} catch {
return false;
try {
parsed = new URL(rawUrl, 'postgres://base');
} catch {
return false;
}
}
for (const [rawKey, rawValue] of parsed.searchParams.entries()) {
const key = rawKey.toLowerCase();
const value = rawValue.trim().toLowerCase();
if (key === 'sslmode') {
if (value === 'disable') {
if (explicitSsl) {
return true;
}
} else if (
value === 'require' ||
value === 'verify-ca' ||
value === 'verify-full' ||
value === 'no-verify'
) {
if (!explicitSsl) {
return true;
}
} else {
// `allow`, `prefer`, or any unrecognized sslmode conflicts with an explicit boolean override.
return true;
}
} else if (key === 'ssl') {
if (value === 'false' || value === '0') {
if (explicitSsl) {
return true;
}
} else if (value === 'true' || value === '1') {
if (!explicitSsl) {
return true;
}
} else {
return true;
}
} else if (
(key === 'sslcert' || key === 'sslkey' || key === 'sslrootcert') &&
value.length > 0 &&
!explicitSsl
) {
for (const [rawKey] of parsed.searchParams.entries()) {
if (isQuestDbUrlTlsParamKey(rawKey)) {
return true;
}
}
@ -107,13 +83,21 @@ export function hasConflictingQuestDbUrlSsl(rawUrl: string, explicitSsl: boolean
}
/**
* Throws a credential-free `RangeError` if `explicitSsl` conflicts with SSL
* query parameters in `rawUrl`.
* Returns `true` when an explicit boolean `ssl` setting is combined with any
* TLS/SSL query parameter embedded in `rawUrl`.
*/
export function assertNoConflictingQuestDbSsl(rawUrl: string, explicitSsl: boolean): void {
if (hasConflictingQuestDbUrlSsl(rawUrl, explicitSsl)) {
export function hasConflictingQuestDbUrlSsl(rawUrl: string, _explicitSsl?: boolean): boolean {
return hasQuestDbUrlTlsOptions(rawUrl);
}
/**
* Throws a credential-free `RangeError` if an explicit `ssl` option is combined
* with any TLS/SSL query parameter in `rawUrl`.
*/
export function assertNoConflictingQuestDbSsl(rawUrl: string, _explicitSsl?: boolean): void {
if (hasQuestDbUrlTlsOptions(rawUrl)) {
throw new RangeError(
'Conflicting QuestDB SSL configuration: explicit "ssl" option conflicts with SSL query parameters in the QuestDB URL.'
'Conflicting QuestDB TLS/SSL configuration: cannot combine an explicit "ssl" option with TLS/SSL query parameters in the QuestDB URL. Configure TLS in either the URL or the explicit "ssl" option, not both.'
);
}
}