Require messages for MessageChannels 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 authored and Janne Savolainen committed 2022-06-03 07:49:45 +03:00
1 parent 5f612b774a
commit 8432131b1e
10 files changed
+20 -15

No files matched your search

@@ -3,6 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { JsonObject } from "type-fest";
import type { MessageChannel } from "../channel/message-channel-injection-token";
import { messageChannelInjectionToken } from "../channel/message-channel-injection-token";
@@ -12,7 +13,7 @@ export type ApplicationUpdateStatusEventId =
| "download-for-update-started"
| "download-for-update-failed";
export interface ApplicationUpdateStatusChannelMessage { eventId: ApplicationUpdateStatusEventId; version?: string }
export interface ApplicationUpdateStatusChannelMessage extends JsonObject { eventId: ApplicationUpdateStatusEventId; version?: string }
export type ApplicationUpdateStatusChannel = MessageChannel<ApplicationUpdateStatusChannelMessage>;
const applicationUpdateStatusChannelInjectable = getInjectable({
@@ -3,10 +3,11 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { JsonObject } from "type-fest";
import type { MessageChannel } from "../channel/message-channel-injection-token";
import { messageChannelInjectionToken } from "../channel/message-channel-injection-token";
export interface AskBooleanQuestionParameters { id: string; title: string; question: string }
export interface AskBooleanQuestionParameters extends JsonObject { id: string; title: string; question: string }
export type AskBooleanQuestionChannel = MessageChannel<AskBooleanQuestionParameters>;
const askBooleanQuestionChannelInjectable = getInjectable({
@@ -7,7 +7,7 @@ import type { MessageChannel } from "./message-channel-injection-token";
import type { MessageChannelListener } from "./message-channel-listener-injection-token";
export type EnlistMessageChannelListener = <
TChannel extends MessageChannel<unknown>,
TChannel extends MessageChannel<any>,
>(listener: MessageChannelListener<TChannel>) => () => void;
export const enlistMessageChannelListenerInjectionToken =
@@ -4,8 +4,9 @@
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { JsonValue } from "type-fest";
export interface MessageChannel<Message = void> {
export interface MessageChannel<Message extends JsonValue | void = void> {
id: string;
_messageSignature?: Message;
}
@@ -3,6 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectionToken } from "@ogre-tools/injectable";
import type { SetRequired } from "type-fest";
import type { MessageChannel } from "./message-channel-injection-token";
export interface MessageToChannel {
@@ -10,9 +11,9 @@ export interface MessageToChannel {
channel: TChannel,
): void;
<TChannel extends MessageChannel<TMessage>, TMessage>(
<TChannel extends MessageChannel<any>>(
channel: TChannel,
message: TMessage
message: SetRequired<TChannel, "_messageSignature">["_messageSignature"],
): void;
}