feat(research): inspect scoped stored market data (RP01)

This commit is contained in:
Boki 2026-10-27 00:25:19 -04:00
parent b4ac6460ef
commit 5bfaf37d08
12 changed files with 1592 additions and 3 deletions

View file

@ -64,6 +64,10 @@
"./paper-deployments": {
"types": "./dist/contracts/paper-deployments.d.ts",
"import": "./dist/contracts/paper-deployments.js"
},
"./stored-source": {
"types": "./dist/contracts/stored-source.d.ts",
"default": "./dist/contracts/stored-source.js"
}
},
"scripts": {

View file

@ -0,0 +1,89 @@
/** Read-only source diagnostics. These do not certify a dataset or retain source evidence. */
import { z } from 'zod';
import { parseInstrumentId } from '@stock-bot/types';
const count = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
const instant = z.number().int().nonnegative().max(8_640_000_000_000_000);
export const storedSourceIntervalSchema = z.enum(['1m', '5m', '1h']);
const instrument = z.string().refine(value => {
try {
return parseInstrumentId(value).id === value;
} catch {
return false;
}
}, 'Expected a provider instrument identity, for example AAPL.US');
export const storedSourceSelectionSchema = z
.object({ instrumentId: instrument, interval: storedSourceIntervalSchema })
.strict();
export type StoredSourceSelection = z.infer<typeof storedSourceSelectionSchema>;
export const storedSourceQuerySchema = storedSourceSelectionSchema
.extend({
start: instant,
end: instant,
})
.strict()
.refine(value => value.start < value.end, 'End must be after start');
export type StoredSourceQuery = z.infer<typeof storedSourceQuerySchema>;
export const storedSourceCoverageSchema = z
.object({
version: z.literal('stored-eod-coverage/v1'),
observedAt: instant,
query: storedSourceSelectionSchema,
series: z
.array(
z
.object({
instrumentId: instrument,
interval: storedSourceIntervalSchema,
rowCount: count,
firstTimestamp: instant.nullable(),
lastTimestamp: instant.nullable(),
invalidTimestampRows: count,
})
.strict()
)
.max(1),
})
.strict();
export type StoredSourceCoverage = z.infer<typeof storedSourceCoverageSchema>;
export const storedSourceIssueSchema = z.enum([
'identity-mismatch',
'invalid-timestamp',
'outside-range',
'invalid-prices',
'null-volume',
'invalid-volume',
'duplicate-timestamp',
]);
export const storedSourceInspectionSchema = z
.object({
version: z.literal('stored-eod-inspection/v1'),
observedAt: instant,
query: storedSourceQuerySchema,
rowCount: count,
invalidRows: count,
nullVolumeRows: count,
duplicateRows: count,
firstTimestamp: instant.nullable(),
lastTimestamp: instant.nullable(),
days: z.array(
z
.object({
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
rowCount: count,
invalidRows: count,
})
.strict()
),
issues: z.array(
z
.object({
code: storedSourceIssueSchema,
rowCount: count,
timestamps: z.array(instant.nullable()),
})
.strict()
),
})
.strict();
export type StoredSourceInspection = z.infer<typeof storedSourceInspectionSchema>;