signalk-parquet
Version:
SignalK plugin to save marine data directly to Parquet files with regimen-based control
268 lines • 7.06 kB
TypeScript
import { Context, Path, ServerAPI, NormalizedDelta, SourceRef } from '@signalk/server-api';
export { NormalizedDelta, SourceRef };
import { Request, Response, Router } from 'express';
export interface SignalKPlugin {
id: string;
name: string;
description: string;
schema: any;
start: (options: Partial<PluginConfig>) => void;
stop: () => void;
registerWithRouter?: (router: Router) => void;
}
export interface PluginConfig {
bufferSize: number;
saveIntervalSeconds: number;
outputDirectory: string;
filenamePrefix: string;
retentionDays: number;
fileFormat: 'json' | 'csv' | 'parquet';
vesselMMSI: string;
s3Upload: S3UploadConfig;
}
export interface PathConfig {
path: Path;
name?: string;
enabled?: boolean;
regimen?: string;
source?: string;
context?: Context;
excludeMMSI?: string[];
}
export interface CommandConfig {
command: string;
path: string;
registered: string;
description?: string;
active?: boolean;
lastExecuted?: string;
}
export interface CommandRegistrationState {
registeredCommands: Map<string, CommandConfig>;
putHandlers: Map<string, CommandPutHandler>;
}
export interface CommandExecutionRequest {
command: string;
value: boolean;
timestamp?: string;
}
export interface CommandRegistrationRequest {
command: string;
description?: string;
}
export interface WebAppPathConfig {
paths: PathConfig[];
commands: CommandConfig[];
}
export interface S3UploadConfig {
enabled: boolean;
timing?: 'realtime' | 'consolidation';
bucket?: string;
region?: string;
keyPrefix?: string;
accessKeyId?: string;
secretAccessKey?: string;
deleteAfterUpload?: boolean;
}
export interface SignalKSubscription {
context: string;
subscribe: Array<{
path: string;
period: number;
}>;
}
export interface DataRecord {
received_timestamp: string;
signalk_timestamp: string;
context: string;
path: string;
value: any;
value_json?: string;
source?: string;
source_label?: string;
source_type?: string;
source_pgn?: number;
source_src?: string;
meta?: string;
[key: string]: any;
}
export interface ParquetWriterOptions {
format: 'json' | 'csv' | 'parquet';
app?: ServerAPI;
}
export interface FileInfo {
name: string;
path: string;
size: number;
modified: string;
}
export interface PathInfo {
path: string;
directory: string;
fileCount: number;
}
export interface ApiResponse<T = any> {
success: boolean;
data?: T;
error?: string;
message?: string;
}
export interface CommandApiResponse extends ApiResponse {
commands?: CommandConfig[];
command?: CommandConfig;
count?: number;
}
export interface CommandExecutionResponse extends ApiResponse {
command?: string;
value?: boolean;
executed?: boolean;
timestamp?: string;
}
export interface PathsApiResponse extends ApiResponse {
dataDirectory?: string;
paths?: PathInfo[];
}
export interface FilesApiResponse extends ApiResponse {
path?: string;
directory?: string;
files?: FileInfo[];
}
export interface QueryApiResponse extends ApiResponse {
query?: string;
rowCount?: number;
data?: any[];
}
export interface SampleApiResponse extends ApiResponse {
path?: string;
file?: string;
columns?: string[];
rowCount?: number;
data?: any[];
}
export interface ConfigApiResponse extends ApiResponse {
paths?: PathConfig[];
}
export interface HealthApiResponse extends ApiResponse {
status?: string;
timestamp?: string;
duckdb?: string;
}
export interface S3TestApiResponse extends ApiResponse {
bucket?: string;
region?: string;
keyPrefix?: string;
}
export interface TypedRequest<T = any> extends Request {
body: T;
params: {
[key: string]: string;
};
query: {
[key: string]: string;
};
}
export interface TypedResponse<T = any> extends Response {
json: (body: T) => this;
status: (code: number) => this;
}
export interface PluginState {
unsubscribes: Array<() => void>;
streamSubscriptions?: any[];
dataBuffers: Map<string, DataRecord[]>;
activeRegimens: Set<string>;
subscribedPaths: Set<string>;
saveInterval?: NodeJS.Timeout;
consolidationInterval?: NodeJS.Timeout;
parquetWriter?: ParquetWriter;
s3Client?: any;
currentConfig?: PluginConfig;
commandState: CommandRegistrationState;
}
export interface ParquetWriter {
writeRecords(filepath: string, records: DataRecord[]): Promise<string>;
writeJSON(filepath: string, records: DataRecord[]): Promise<string>;
writeCSV(filepath: string, records: DataRecord[]): Promise<string>;
writeParquet(filepath: string, records: DataRecord[]): Promise<string>;
consolidateDaily(outputDirectory: string, date: Date, filenamePrefix: string): Promise<number>;
}
export interface DuckDBConnection {
runAndReadAll(query: string): Promise<DuckDBResult>;
disconnectSync(): void;
}
export interface DuckDBResult {
getRowObjects(): any[];
}
export interface DuckDBInstance {
connect(): Promise<DuckDBConnection>;
}
export interface S3Config {
region: string;
credentials?: {
accessKeyId: string;
secretAccessKey: string;
};
}
export interface QueryRequest {
query: string;
}
export interface PathConfigRequest {
path: Path;
name?: string;
enabled?: boolean;
regimen?: string;
source?: string;
context?: Context;
}
export type CommandPutHandler = (context: string, path: string, value: any, callback?: (result: CommandExecutionResult) => void) => CommandExecutionResult;
export interface CommandExecutionResult {
state: 'COMPLETED' | 'PENDING' | 'FAILED';
statusCode?: number;
message?: string;
timestamp: string;
}
export interface CommandHistoryEntry {
command: string;
action: 'EXECUTE' | 'STOP' | 'REGISTER' | 'UNREGISTER';
value?: boolean;
timestamp: string;
success: boolean;
error?: string;
}
export declare enum CommandStatus {
ACTIVE = "ACTIVE",
INACTIVE = "INACTIVE",
PENDING = "PENDING",
ERROR = "ERROR"
}
export type FileFormat = 'json' | 'csv' | 'parquet';
export type UploadTiming = 'realtime' | 'consolidation';
export type BufferKey = string;
export interface PluginError extends Error {
code?: string;
details?: any;
}
export interface ConsolidationOptions {
outputDirectory: string;
date: Date;
filenamePrefix: string;
}
export interface ConsolidationResult {
processedPaths: number;
consolidatedFiles: string[];
errors: string[];
}
export interface ParquetField {
type: string;
optional?: boolean;
repeated?: boolean;
}
export interface ParquetSchema {
[fieldName: string]: ParquetField;
}
export interface ProcessingStats {
totalBuffers: number;
buffersWithData: number;
totalRecords: number;
processedPaths: string[];
}
//# sourceMappingURL=types.d.ts.map