feat(research): retain immutable strategy versions and review history
This commit is contained in:
parent
b106c1ca85
commit
4a2e5ad362
36 changed files with 3236 additions and 148 deletions
|
|
@ -3,11 +3,16 @@ import type { Hono, MiddlewareHandler } from 'hono';
|
|||
|
||||
type Role = 'read' | 'admin' | 'service';
|
||||
const verifiedPrincipals = new WeakMap<Request, 'operator' | 'service'>();
|
||||
const credentialRequests = new WeakSet<Request>();
|
||||
|
||||
/** Server-owned identity established only after successful HTTP authorization. */
|
||||
export function getVerifiedHttpPrincipal(request: Request): 'operator' | 'service' | undefined {
|
||||
return verifiedPrincipals.get(request);
|
||||
}
|
||||
/** Catalog authorship/review needs a credential, not the loopback development bypass. */
|
||||
export function getCredentialHttpPrincipal(request: Request): 'operator' | 'service' | undefined {
|
||||
return credentialRequests.has(request) ? verifiedPrincipals.get(request) : undefined;
|
||||
}
|
||||
export interface HttpSecurityOptions {
|
||||
readToken?: string;
|
||||
adminToken?: string;
|
||||
|
|
@ -149,6 +154,7 @@ export function createHttpSecurity(options: HttpSecurityOptions = httpSecurityOp
|
|||
}
|
||||
function authorize(request: Request, admin = false): Response | undefined {
|
||||
verifiedPrincipals.delete(request);
|
||||
credentialRequests.delete(request);
|
||||
const identity = authenticate(request);
|
||||
if (!identity) {
|
||||
return Response.json(
|
||||
|
|
@ -170,6 +176,9 @@ export function createHttpSecurity(options: HttpSecurityOptions = httpSecurityOp
|
|||
}
|
||||
if (identity.role !== 'read') {
|
||||
verifiedPrincipals.set(request, identity.role === 'service' ? 'service' : 'operator');
|
||||
if (!disabled) {
|
||||
credentialRequests.add(request);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ export {
|
|||
httpSecurityOptions,
|
||||
authenticatedServiceFetch,
|
||||
getVerifiedHttpPrincipal,
|
||||
getCredentialHttpPrincipal,
|
||||
} from './http/security';
|
||||
export type { HttpSecurity, HttpSecurityOptions } from './http/security';
|
||||
export { calculatePoolSize, getServicePoolSize, getHandlerPoolSize } from './pool-size-calculator';
|
||||
|
|
|
|||
|
|
@ -129,6 +129,12 @@ export {
|
|||
validateHistoricalDataRequest,
|
||||
} from './historical-data';
|
||||
export type { HistoricalDatasetCatalogEntry, BacktestRunDatasetSelection } from './dataset-catalog';
|
||||
export type {
|
||||
StrategyParameterValue,
|
||||
StrategyParameterProperty,
|
||||
StrategyParameterSchema,
|
||||
StrategyVersionPackage,
|
||||
} from './strategy-version';
|
||||
export type {
|
||||
InstrumentIdentity,
|
||||
HistoricalDataPolicy,
|
||||
|
|
|
|||
41
libs/core/types/src/strategy-version.ts
Normal file
41
libs/core/types/src/strategy-version.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
export type StrategyParameterValue = string | number | boolean;
|
||||
export interface StrategyParameterProperty {
|
||||
type: 'integer' | 'number' | 'string' | 'boolean';
|
||||
minimum?: number;
|
||||
maximum?: number;
|
||||
exclusiveMinimum?: number;
|
||||
exclusiveMaximum?: number;
|
||||
enum?: StrategyParameterValue[];
|
||||
default?: StrategyParameterValue;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
/** Deliberately small JSON schema subset for parameter forms, not executable code. */
|
||||
export interface StrategyParameterSchema {
|
||||
version: 1;
|
||||
type: 'object';
|
||||
additionalProperties: false;
|
||||
properties: Record<string, StrategyParameterProperty>;
|
||||
required: string[];
|
||||
}
|
||||
|
||||
/** Retained executable bytes; registration never imports or compiles this content. */
|
||||
export interface StrategyVersionPackage {
|
||||
version: 1;
|
||||
program: {
|
||||
strategyId: string;
|
||||
strategyVersion: string;
|
||||
apiVersion: string;
|
||||
checkpointVersion: string;
|
||||
};
|
||||
artifact: {
|
||||
format: 'esm-bundle/v1';
|
||||
entryExport: string;
|
||||
content: string;
|
||||
sha256: string;
|
||||
};
|
||||
dependencyLock: { format: 'bun-lock/v1'; content: string; sha256: string };
|
||||
parameterSchema: StrategyParameterSchema;
|
||||
source: { revision: string; dirty: boolean };
|
||||
build: { tool: 'bun'; version: string; target: 'browser' };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue