feat(research): prepare and retain explicit source datasets in the web workbench
This commit is contained in:
parent
06039d17ba
commit
366bee810b
21 changed files with 2677 additions and 76 deletions
|
|
@ -0,0 +1,23 @@
|
|||
import { validateDatasetV2 } from './historical-dataset-v2';
|
||||
|
||||
export interface RetainedDatasetStore {
|
||||
query(text: string, values?: unknown[]): Promise<{ rows: Record<string, unknown>[] }>;
|
||||
}
|
||||
|
||||
/** Content-addressed custody shared by explicit CLI import and web source preparation. */
|
||||
export async function retainResearchDataset(database: RetainedDatasetStore, input: unknown) {
|
||||
const dataset = validateDatasetV2(input);
|
||||
await database.query(
|
||||
'INSERT INTO backtest_datasets(hash,payload) VALUES($1,$2::jsonb) ON CONFLICT(hash) DO NOTHING',
|
||||
[dataset.manifest.hash, JSON.stringify(dataset)]
|
||||
);
|
||||
const stored = (
|
||||
await database.query('SELECT payload FROM backtest_datasets WHERE hash=$1', [
|
||||
dataset.manifest.hash,
|
||||
])
|
||||
).rows[0];
|
||||
if (!stored || validateDatasetV2(stored.payload).manifest.hash !== dataset.manifest.hash) {
|
||||
throw new Error('Retained dataset content does not match the imported identity');
|
||||
}
|
||||
return dataset.manifest;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue