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";