api_tool/types.d.ts
2025-06-23 17:00:54 +02:00

100 lines
2.1 KiB
TypeScript

type EventPayloadMapping = {};
/**
* Extends the Main "Window" Interface
*/
interface Window {
electron: {
ping: () => Promise<string>;
};
}
type UnsubscribeFunction = () => void;
type SubscribeFunction<Event extends keyof EventPayloadMapping> = (payload: EventPayloadMapping[Event]) => void;
// --- Prodress R2 Request ---
/**
* structure of a handler based prodress r2 request schema
*/
type Pdr2_Schema = {
handler: string;
actions: Pdr2_ActionSchema[];
};
/**
* structure of an action based prodress r2 request subschema
*/
type Pdr2_ActionSchema = {
action: string;
additionalInformation: Pdr2_RequestTupel[];
arguments: Pdr2_RequestTupel[];
response: Pdr2_ResponseSchema;
};
/**
* structure of the prodressd r2 request header
*/
interface Pdr2_Header {
port?: number;
host?: string;
database: string;
handler: string;
action: string;
}
/**
* mapping for string alias to scalar type with pdr2 read and write methods
*/
interface Pdr2_DataTypeConversion {
string: () => string;
integer: () => number;
float: () => number;
date: () => Date | null;
date_time: () => Date | null;
}
/**
* structrue of a response object which is already read
*/
interface Pdr2_ResponseObject {
[key: string]: ReturnType<Pdr2_DataTypeConversion[keyof Pdr2_DataTypeConversion]>;
}
/**
* structure of a response tupel used inside of the response schema
*/
type Pdr2_ResponseTupel = [string, keyof Pdr2_DataTypeConversion];
/**
* strucutre of a request tupel used inside the request body and schema
*/
type Pdr2_RequestTupel = {
[K in keyof Pdr2_DataTypeConversion]: [K, NonNullable<ReturnType<Pdr2_DataTypeConversion[K]>>];
}[keyof Pdr2_DataTypeConversion];
/**
* structure of a prodress r2 request object recieved by the user
*/
type Pdr2_Request = {
header: Pdr2_Header;
body: Pdr2_RequestBody;
response: Pdr2_ResponseSchema;
};
/**
* structure of a prodress r2 request body
*/
type Pdr2_RequestBody = {
additionalInformation: Pdr2_RequestTupel[];
arguments: Pdr2_RequestTupel[][];
};
/**
* structure of a prodress r2 response schema
*/
type Pdr2_ResponseSchema = {
isStatic: boolean;
responseTupel: Pdr2_ResponseTupel[];
};