From a72b53de011d35602c0f68577c30e28386046583 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 22 Dec 2023 20:27:10 -0500 Subject: Type safety for TemplateRendererProxy (#428) * Type safety for TemplateRendererProxy * Simplify --- types/ext/template-renderer-frame-api.d.ts | 24 ------- types/ext/template-renderer-proxy.d.ts | 102 +++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 24 deletions(-) delete mode 100644 types/ext/template-renderer-frame-api.d.ts create mode 100644 types/ext/template-renderer-proxy.d.ts (limited to 'types/ext') diff --git a/types/ext/template-renderer-frame-api.d.ts b/types/ext/template-renderer-frame-api.d.ts deleted file mode 100644 index e00a0711..00000000 --- a/types/ext/template-renderer-frame-api.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2023 Yomitan Authors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -import type * as Core from './core'; - -export type MessageData = { - action: string; - params: Core.SerializableObject; - id: string; -}; diff --git a/types/ext/template-renderer-proxy.d.ts b/types/ext/template-renderer-proxy.d.ts new file mode 100644 index 00000000..74e95b54 --- /dev/null +++ b/types/ext/template-renderer-proxy.d.ts @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2023 Yomitan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import type {Response} from 'core'; +import type {RenderMode, NoteData} from 'anki-templates'; +import type {CompositeRenderData, PartialOrCompositeRenderData, RenderMultiItem, RenderResult} from 'template-renderer'; +import type { + ApiMap as BaseApiMap, + ApiMapInit as BaseApiMapInit, + ApiHandler as BaseApiHandler, + ApiParams as BaseApiParams, + ApiNames as BaseApiNames, + ApiReturn as BaseApiReturn, + ApiReturnAny as BaseApiReturnAny, +} from './api-map'; + +// Frontend API + +type FrontendApiSurface = { + render: { + params: { + template: string; + data: PartialOrCompositeRenderData; + type: RenderMode; + }; + return: RenderResult; + }; + renderMulti: { + params: { + items: RenderMultiItem[]; + }; + return: Response[]; + }; + getModifiedData: { + params: { + data: CompositeRenderData; + type: RenderMode; + }; + return: NoteData; + }; +}; + +type FrontendApiParams = BaseApiParams; + +type FrontendApiNames = BaseApiNames; + +type FrontendApiReturnAny = BaseApiReturnAny; + +export type FrontendMessage = { + action: TName; + params: FrontendApiParams; + id: string; +}; + +export type FrontendMessageAny = FrontendMessage; + +export type FrontendApiReturn = BaseApiReturn; + +export type FrontendApiMap = BaseApiMap; + +export type FrontendApiMapInit = BaseApiMapInit; + +export type FrontendApiHandler = BaseApiHandler; + +// Backend API + +export type BackendApiSurface = { + ready: { + params: void; + return: void; + }; + response: { + params: Response; + return: void; + }; +}; + +type BackendApiNames = BaseApiNames; + +type BackendApiParams = BaseApiParams; + +export type BackendMessage = { + action: TName; + params: BackendApiParams; + id: string | null; +}; + +export type BackendMessageAny = BackendMessage; -- cgit v1.2.3