diff --git a/packages/element-web-module-api/src/api.test.ts b/packages/element-web-module-api/src/api.test.ts deleted file mode 100644 index 62dd3973aa..0000000000 --- a/packages/element-web-module-api/src/api.test.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2025 New Vector Ltd. - -SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE files in the repository root for full details. -*/ - -import { expect, test } from "vitest"; - -import { Api } from "."; -import { isModule } from "./api.js"; - -const TestModule = { - default: class TestModule { - public static moduleApiVersion = "1.0.0"; - public constructor(private readonly api: Api) {} - public async load(): Promise {} - }, -}; - -test("isModule correctly identifies valid modules", () => { - expect(isModule(TestModule)).toBe(true); -}); diff --git a/packages/element-web-module-api/src/api.ts b/packages/element-web-module-api/src/api.ts deleted file mode 100644 index 5534411375..0000000000 --- a/packages/element-web-module-api/src/api.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* -Copyright 2025 New Vector Ltd. - -SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial -Please see LICENSE files in the repository root for full details. -*/ - -import { LegacyModuleApiExtension } from "./legacy-modules"; -import { LegacyCustomisationsApiExtension } from "./legacy-customisations"; - -/** - * Module interface for modules to implement. - * @public - */ -export interface Module { - load(): Promise; -} - -const moduleSignature: Record = { - load: "function", -}; - -/** - * Module interface for modules to export as the default export. - * @public - */ -export interface ModuleFactory { - readonly moduleApiVersion: string; - new (api: Api): Module; - readonly prototype: Module; -} - -const moduleFactorySignature: Record = { - moduleApiVersion: "string", - prototype: "object", -}; - -export interface ModuleExport { - default: ModuleFactory; -} - -const moduleExportSignature: Record = { - default: "function", -}; - -type Type = "function" | "string" | "number" | "boolean" | "object"; - -function isInterface(obj: unknown, type: "object" | "function", keys: Record): obj is T { - if (obj === null || typeof obj !== type) return false; - for (const key in keys) { - if (typeof (obj as Record)[key] !== keys[key]) return false; - } - return true; -} - -export function isModule(module: unknown): module is ModuleExport { - return ( - isInterface(module, "object", moduleExportSignature) && - isInterface(module.default, "function", moduleFactorySignature) && - isInterface(module.default.prototype, "object", moduleSignature) - ); -} - -/** - * The configuration for the application. - * Should be extended via declaration merging. - * @public - */ -export interface Config { - // The branding name of the application - brand: string; - // Other config options are available but not specified in the types as that would make it difficult to change for element-web - // they are accessible at runtime all the same, see list at https://github.com/element-hq/element-web/blob/develop/docs/config.md -} - -/** - * API for accessing the configuration. - * @public - */ -export interface ConfigApi { - get(): Config; - get(key: K): Config[K]; - get(key?: K): Config | Config[K]; -} - -/** - * The API for modules to interact with the application. - * @public - */ -export interface Api extends LegacyModuleApiExtension, LegacyCustomisationsApiExtension { - config: ConfigApi; -}