From 4be86d6ebcecb7ea5d7272879c232a0d8c9134f7 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sun, 26 Nov 2023 10:58:09 +0100 Subject: [PATCH] Update extension types #743 --- extension/package.json | 2 +- src/backend/model/extension/ExtensionDecorator.ts | 4 ++-- src/backend/model/extension/ExtensionEvent.ts | 6 +++--- src/backend/model/extension/IExtension.ts | 4 +--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/extension/package.json b/extension/package.json index 46a161233..09bd6fe5b 100644 --- a/extension/package.json +++ b/extension/package.json @@ -1,6 +1,6 @@ { "name": "pigallery2-extension-kit", - "version": "2.0.3-edge", + "version": "2.0.3-edge3", "description": "Interfaces for developing extensions for pigallery2", "author": "Patrik J. Braun", "homepage": "https://github.com/bpatrik/pigallery2", diff --git a/src/backend/model/extension/ExtensionDecorator.ts b/src/backend/model/extension/ExtensionDecorator.ts index 811659606..28784596e 100644 --- a/src/backend/model/extension/ExtensionDecorator.ts +++ b/src/backend/model/extension/ExtensionDecorator.ts @@ -25,13 +25,13 @@ export const ExtensionDecorator = (fn: (ee: IExtensionEv const event = fn(ExtensionDecoratorObject.events) as ExtensionEvent; const eventObj = {stopPropagation: false}; - const input = await event.triggerBefore({inputs: args}, eventObj); + const input = await event.triggerBefore(args, eventObj); // skip the rest of the execution if the before handler asked for stop propagation if (eventObj.stopPropagation) { return input as O; } - const out = await targetMethod.apply(this, args); + const out = await targetMethod.apply(this, input); return await event.triggerAfter(out); }; diff --git a/src/backend/model/extension/ExtensionEvent.ts b/src/backend/model/extension/ExtensionEvent.ts index f92572056..526ed4097 100644 --- a/src/backend/model/extension/ExtensionEvent.ts +++ b/src/backend/model/extension/ExtensionEvent.ts @@ -27,15 +27,15 @@ export class ExtensionEvent implements IExtensionEvent { - let pipe: { inputs: I} | O = input; + public async triggerBefore(input: I, event: { stopPropagation: boolean }): Promise { + let pipe: I | O = input; if (this.beforeHandlers && this.beforeHandlers.length > 0) { const s = this.beforeHandlers.slice(0); for (let i = 0; i < s.length; ++i) { if (event.stopPropagation) { break; } - pipe = await s[i](pipe as { inputs: I }, event); + pipe = await s[i](pipe as I, event); } } return pipe; diff --git a/src/backend/model/extension/IExtension.ts b/src/backend/model/extension/IExtension.ts index aa5b6f53a..3ef100498 100644 --- a/src/backend/model/extension/IExtension.ts +++ b/src/backend/model/extension/IExtension.ts @@ -18,9 +18,7 @@ import {ParentDirectoryDTO} from '../../../common/entities/DirectoryDTO'; import {DirectoryScanSettings} from '../fileaccess/DiskManager'; -export type IExtensionBeforeEventHandler = (input: { inputs: I }, event: { stopPropagation: boolean }) => Promise<{ - inputs: I -} | O>; +export type IExtensionBeforeEventHandler = (input: I, event: { stopPropagation: boolean }) => Promise; export type IExtensionAfterEventHandler = (output: O) => Promise;