summaryrefslogtreecommitdiff
path: root/client/simple/src/js/loader.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/simple/src/js/loader.ts')
-rw-r--r--client/simple/src/js/loader.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/client/simple/src/js/loader.ts b/client/simple/src/js/loader.ts
new file mode 100644
index 000000000..ed374a2d8
--- /dev/null
+++ b/client/simple/src/js/loader.ts
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import type { Plugin } from "./Plugin.ts";
+import { type EndpointsKeys, endpoint } from "./toolkit.ts";
+
+type Options =
+ | {
+ on: "global";
+ }
+ | {
+ on: "endpoint";
+ where: EndpointsKeys[];
+ };
+
+export const load = <T extends Plugin>(instance: () => Promise<T>, options: Options): void => {
+ if (!check(options)) return;
+
+ void instance();
+};
+
+const check = (options: Options): boolean => {
+ // biome-ignore lint/style/useDefaultSwitchClause: options is typed
+ switch (options.on) {
+ case "global": {
+ return true;
+ }
+ case "endpoint": {
+ if (!options.where.includes(endpoint)) {
+ // not on the expected endpoint
+ return false;
+ }
+
+ return true;
+ }
+ }
+};