typedrequest-interfaces/ts/index.ts
2024-02-24 11:10:03 +01:00

136 lines
2.6 KiB
TypeScript

export interface ITypedRequest {
/**
* the method that the request response data is meant for
*/
method: string;
/**
* any needed auth data
*/
authInfo?: {
jwt: string;
};
/**
* localData tracks things within typedrequest.
* needed for VirtualStreams
*/
localData?: {
firstTypedrouter?: any;
};
/**
* server data that is added for dealing with the request server side. Will be omitted when sending the response
*/
serverData?: {
jwtData: any;
jwtValid: boolean;
};
/**
* the request data
*/
request: object;
/**
* the response data
*/
response: object;
/**
* any error information that might be encountered while dealing with a request
*/
error?: { text: string; data: any };
/**
* retry information for smartly advising the client to retry at a later point in time
*/
retry?: {
waitForMs: number;
reason: string;
};
/**
* a correlation id that
* used for matching request and response
* !important. Don't remove.
*/
correlation?: {
id: string;
phase: 'request' | 'response';
};
}
export type implementsTR<T, U extends T> = {};
export interface ITypedEvent<T> {
name: string;
uniqueEventId: string;
payload: T;
}
export interface ITag {
name: string;
payload: any;
}
export type implementsTag<T, U extends T> = {};
export interface IUnifiedStreamDataPackage {
/**
* the stream id, so Virtual Streams can talk to each other
*/
streamId: string;
/**
* stream data is sent in cycles. This id is used to match the request and response
*/
cycleId: string;
cycle: 'request' | 'response';
/**
* the main purpose of the data package
* start: indicates the start of a stream
* chunk: indicates a binary chunk of data
* read: indicates the introduction to send data
* end: indicates the end of a stream
* feedback: indicates a feedback message
*/
mainPurpose: 'start' | 'chunk' | 'read' | 'end' | 'feedback' | 'keepAlive';
/**
* the data package
*/
chunkData?: any;
/**
* feedback message
*/
feedback?: {
message?: string;
data?: any;
sha265?: string;
};
/**
* keepAlive boolean
*/
keepAlive?: boolean;
/**
* is backpressure detected on the readable side?
*/
backpressure?: boolean;
/**
* does the writable side have more data scheduled to be sent?
*/
next?: boolean;
}
export interface IStreamRequest extends implementsTR<ITypedRequest, IStreamRequest> {
method: '##VirtualStream##';
request: IUnifiedStreamDataPackage;
response: IUnifiedStreamDataPackage;
}