Require requests and responses for RequestChannels be JsonValues for serialization

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-tursoandJanne Savolainen committed 2022-05-30 13:13:06 +03:00
1 parent c156dcf4ae
commit 2fc30f6ce5
5 files changed
+11 -7

No files matched your search

@@ -7,7 +7,7 @@ import type { RequestChannel } from "./request-channel-injection-token";
import type { RequestChannelListener } from "./request-channel-listener-injection-token";
export type EnlistRequestChannelListener = <
TChannel extends RequestChannel<unknown, unknown>,
TChannel extends RequestChannel<any, any>,
>(listener: RequestChannelListener<TChannel>) => () => void;
export const enlistRequestChannelListenerInjectionToken =
@@ -4,8 +4,12 @@
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { JsonValue } from "type-fest";
export interface RequestChannel<Request = void, Response = void> {
export interface RequestChannel<
Request extends JsonValue | void = void,
Response extends JsonValue | void = void,
> {
id: string;
_requestSignature?: Request;
_responseSignature?: Response;
@@ -7,7 +7,7 @@ import type { SetRequired } from "type-fest";
import type { RequestChannel } from "./request-channel-injection-token";
export type RequestFromChannel = <
TChannel extends RequestChannel<unknown, unknown>,
TChannel extends RequestChannel<any, any>,
>(
channel: TChannel,
...request: TChannel["_requestSignature"] extends void
@@ -8,7 +8,7 @@ import { requestChannelInjectionToken } from "../channel/request-channel-injecti
export type SyncBoxInitialValueChannel = RequestChannel<
void,
{ id: string; value: unknown }[]
{ id: string; value: any }[]
>;
const syncBoxInitialValueChannelInjectable = getInjectable({
@@ -11,7 +11,7 @@ import requestFromChannelInjectable from "../../renderer/channel/request-from-ch
export const overrideRequestingFromWindowToMain = (mainDi: DiContainer) => {
const requestChannelListenerFakesForMain = new Map<
string,
RequestChannelListener<RequestChannel<unknown, unknown>>
RequestChannelListener<RequestChannel<any, any>>
>();
mainDi.override(
@@ -27,9 +27,9 @@ export const overrideRequestingFromWindowToMain = (mainDi: DiContainer) => {
requestChannelListenerFakesForMain.set(
listener.channel.id,
// TODO: Figure out typingo
// TODO: Figure out typing
listener as unknown as RequestChannelListener<
RequestChannel<unknown, unknown>
RequestChannel<any, any>
>,
);