typedrequest-interfaces/ts/index.ts

136 lines
2.6 KiB
TypeScript
Raw Normal View History

2019-08-22 13:40:10 +00:00
export interface ITypedRequest {
2020-07-13 01:13:29 +00:00
/**
* the method that the request response data is meant for
*/
2019-08-22 13:40:10 +00:00
method: string;
2020-07-13 01:13:29 +00:00
/**
* any needed auth data
*/
2020-07-04 16:57:05 +00:00
authInfo?: {
jwt: string;
};
2020-07-13 01:13:29 +00:00
2024-02-20 19:47:12 +00:00
/**
* localData tracks things within typedrequest.
* needed for VirtualStreams
*/
localData?: {
2024-02-20 23:34:24 +00:00
firstTypedrouter?: any;
2024-02-23 14:48:31 +00:00
};
2024-02-20 19:47:12 +00:00
2020-07-13 01:13:29 +00:00
/**
* server data that is added for dealing with the request server side. Will be omitted when sending the response
*/
2020-07-04 16:57:05 +00:00
serverData?: {
jwtData: any;
jwtValid: boolean;
};
2020-07-13 01:13:29 +00:00
/**
* the request data
*/
2019-08-22 13:40:10 +00:00
request: object;
2020-07-13 01:13:29 +00:00
/**
* the response data
*/
2019-08-22 13:40:10 +00:00
response: object;
2020-07-13 01:13:29 +00:00
/**
* any error information that might be encountered while dealing with a request
*/
2020-02-10 21:08:52 +00:00
error?: { text: string; data: any };
2020-07-13 01:13:29 +00:00
/**
* retry information for smartly advising the client to retry at a later point in time
*/
2020-02-10 21:06:51 +00:00
retry?: {
waitForMs: number;
reason: string;
};
2020-07-13 01:13:29 +00:00
/**
2022-10-26 09:35:19 +00:00
* a correlation id that
2024-02-20 19:47:12 +00:00
* used for matching request and response
* !important. Don't remove.
2020-07-13 01:13:29 +00:00
*/
correlation?: {
id: string;
2022-10-26 09:35:19 +00:00
phase: 'request' | 'response';
2020-07-13 01:13:29 +00:00
};
2019-08-23 14:57:45 +00:00
}
2019-09-24 16:40:37 +00:00
2020-02-10 21:06:51 +00:00
export type implementsTR<T, U extends T> = {};
2020-02-20 22:01:58 +00:00
export interface ITypedEvent<T> {
2019-11-10 15:35:43 +00:00
name: string;
2019-09-24 16:40:37 +00:00
uniqueEventId: string;
payload: T;
}
2022-10-26 09:24:41 +00:00
export interface ITag {
name: string;
payload: any;
}
export type implementsTag<T, U extends T> = {};
2024-02-21 00:55:49 +00:00
2024-02-23 14:48:31 +00:00
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
2024-02-24 10:10:03 +00:00
* chunk: indicates a binary chunk of data
* read: indicates the introduction to send data
2024-02-23 14:48:31 +00:00
* end: indicates the end of a stream
* feedback: indicates a feedback message
*/
2024-02-24 10:10:03 +00:00
mainPurpose: 'start' | 'chunk' | 'read' | 'end' | 'feedback' | 'keepAlive';
2024-02-23 14:48:31 +00:00
/**
* the data package
*/
chunkData?: any;
/**
* feedback message
*/
2024-02-23 15:00:36 +00:00
feedback?: {
2024-02-23 14:48:31 +00:00
message?: string;
data?: any;
sha265?: string;
};
/**
* keepAlive boolean
*/
keepAlive?: boolean;
/**
2024-02-23 19:18:19 +00:00
* is backpressure detected on the readable side?
*/
backpressure?: boolean;
/**
* does the writable side have more data scheduled to be sent?
2024-02-23 14:48:31 +00:00
*/
next?: boolean;
2024-02-22 14:15:44 +00:00
}
2024-02-23 14:48:31 +00:00
export interface IStreamRequest extends implementsTR<ITypedRequest, IStreamRequest> {
2024-02-22 14:15:44 +00:00
method: '##VirtualStream##';
2024-02-23 14:48:31 +00:00
request: IUnifiedStreamDataPackage;
response: IUnifiedStreamDataPackage;
2024-02-21 00:55:49 +00:00
}