From c70b690d0b76511075db49c84015b7cebbc4d5ed Mon Sep 17 00:00:00 2001 From: Florian Maunier Date: Thu, 21 Mar 2024 17:40:15 +0100 Subject: [PATCH] feat(ask): import typed ask / onAsk from device-manager --- index.ts | 9 +++++---- lib/utils/Ask.ts | 29 +++++++++++++++++++++++++++++ lib/utils/index.ts | 1 + 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 lib/utils/Ask.ts create mode 100644 lib/utils/index.ts diff --git a/index.ts b/index.ts index ad1402f..9041747 100644 --- a/index.ts +++ b/index.ts @@ -1,8 +1,9 @@ -export * from './lib/engine'; +export * from "./lib/engine"; -export * from './lib/synchronizer'; +export * from "./lib/synchronizer"; -export * from './lib/config'; +export * from "./lib/config"; -export * from './lib/crud'; +export * from "./lib/crud"; +export * from "./lib/utils"; diff --git a/lib/utils/Ask.ts b/lib/utils/Ask.ts new file mode 100644 index 0000000..82421fa --- /dev/null +++ b/lib/utils/Ask.ts @@ -0,0 +1,29 @@ +export type AskEventDefinition = { + name: string; + payload: any; + result: any; +}; + +export type AskEventHandler< + TAskEventDefinition extends AskEventDefinition = AskEventDefinition +> = ( + payload?: TAskEventDefinition["payload"] +) => Promise; + +export function onAsk< + TAskEventDefinition extends AskEventDefinition = AskEventDefinition +>( + event: TAskEventDefinition["name"], + handler: AskEventHandler +) { + return global.kuzzle.onAsk(event, handler); +} + +export async function ask< + TAskEventDefinition extends AskEventDefinition = AskEventDefinition +>( + event: TAskEventDefinition["name"], + payload?: TAskEventDefinition["payload"] +): Promise { + return global.kuzzle.ask(event, payload); +} diff --git a/lib/utils/index.ts b/lib/utils/index.ts new file mode 100644 index 0000000..b575e31 --- /dev/null +++ b/lib/utils/index.ts @@ -0,0 +1 @@ +export * from "./Ask";