@vqp/core
Version:
Core VQP protocol implementation - adapter-agnostic
129 lines • 4.39 kB
TypeScript
/**
* Core VQP Service - Pure business logic following hexagonal architecture
* This service is completely isolated from external concerns
*/
import { VQPQuery, VQPResponse } from './types.js';
import { DataAccessPort, CryptographicPort, VocabularyPort, AuditPort, QueryEvaluationPort, ResponseModePort } from './ports/secondary.js';
export interface VocabularyMapping {
/**
* Map vocabulary field to vault path
* @param field The field name from the vocabulary
* @param vocabularyUri The vocabulary URI for context
* @returns Array representing the path in the vault
*/
toVaultPath(field: string, vocabularyUri?: string): string[];
/**
* Map vault path back to vocabulary field
* @param path The path in the vault
* @param vocabularyUri The vocabulary URI for context
* @returns The field name as it should appear in the vocabulary
*/
toVocabularyField(path: string[], vocabularyUri?: string): string;
}
/**
* Default vocabulary mapping for standard VQP vocabularies
*/
export declare class StandardVocabularyMapping implements VocabularyMapping {
toVaultPath(field: string, vocabularyUri?: string): string[];
toVocabularyField(path: string[], vocabularyUri?: string): string;
}
/**
* Simple flat vocabulary mapping (all fields at top level)
*/
export declare class FlatVocabularyMapping implements VocabularyMapping {
toVaultPath(field: string, _vocabularyUri?: string): string[];
toVocabularyField(path: string[], _vocabularyUri?: string): string;
}
export declare class VQPService {
private dataAccess;
private crypto;
private audit;
private queryEvaluation;
private responseMode;
private vocabulary?;
private config;
private vocabularyMapping;
constructor(dataAccess: DataAccessPort, crypto: CryptographicPort, audit: AuditPort, queryEvaluation: QueryEvaluationPort, responseMode: ResponseModePort, // New: Response Mode port
vocabulary?: VocabularyPort | undefined, // Now optional
config?: {
maxQueryComplexity?: number;
allowedVocabularies?: string[];
rateLimits?: {
queriesPerHour: number;
queriesPerDay: number;
};
vocabularyMapping?: VocabularyMapping;
});
/**
* Main entry point for processing VQP queries
*
* @param query The VQP query to process
* @param providedVocabulary Optional vocabulary schema. If not provided, will use vocabulary adapter
*/
processQuery(query: VQPQuery, providedVocabulary?: any): Promise<VQPResponse>;
/**
* Validate the basic structure and timing of a query
*/
private validateQueryStructure;
/**
* Extract data paths from JSONLogic expression and map them to vault paths
*/
private extractDataPaths;
/**
* Map vocabulary field to actual vault path using configurable mapping
*/
private mapVocabularyToVaultPath;
/**
* Gather data for all required paths and reconstruct for vocabulary format
*/
private gatherData;
/**
* Map vault path back to vocabulary field name using configurable mapping
*/
private mapVaultPathToVocabulary;
/**
* Evaluate query using the injected evaluation port
*/
private evaluateQuery;
/**
* Generate cryptographic proof for the response
*/
private generateProof;
/**
* Calculate query complexity (for rate limiting)
*/
private calculateQueryComplexity;
/**
* Get the DID of this responder
*/
private getResponderDID;
/**
* Create a VQP error with consistent structure
*/
private createError;
/**
* Get vocabulary either from provided parameter or vocabulary adapter
*/
private getVocabulary;
/**
* Check if vocabulary is allowed
*/
private isVocabularyAllowed;
/**
* Validate query expression against vocabulary
*/
private validateAgainstVocabulary;
/**
* Check if expression contains unknown properties (but don't treat as error)
*/
private hasUnknownProperties;
/**
* Basic vocabulary validation when no adapter is available
*/
private basicVocabularyValidation;
/**
* Check if a data path is allowed by the vocabulary
*/
private isPathAllowedInVocabulary;
}
//# sourceMappingURL=vqp-service.d.ts.map