Skip to content

Commit

Permalink
Merge pull request #8 from kuzzleio/feature/ask
Browse files Browse the repository at this point in the history
Import typed ask / onAsk from device-manager
  • Loading branch information
fmauNeko authored Mar 21, 2024
2 parents 86b1019 + c70b690 commit 09770ee
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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";
29 changes: 29 additions & 0 deletions lib/utils/Ask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export type AskEventDefinition = {
name: string;
payload: any;
result: any;
};

export type AskEventHandler<
TAskEventDefinition extends AskEventDefinition = AskEventDefinition
> = (
payload?: TAskEventDefinition["payload"]
) => Promise<TAskEventDefinition["result"]>;

export function onAsk<
TAskEventDefinition extends AskEventDefinition = AskEventDefinition
>(
event: TAskEventDefinition["name"],
handler: AskEventHandler<TAskEventDefinition>
) {
return global.kuzzle.onAsk(event, handler);
}

export async function ask<
TAskEventDefinition extends AskEventDefinition = AskEventDefinition
>(
event: TAskEventDefinition["name"],
payload?: TAskEventDefinition["payload"]
): Promise<TAskEventDefinition["result"]> {
return global.kuzzle.ask(event, payload);
}
1 change: 1 addition & 0 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Ask";

0 comments on commit 09770ee

Please sign in to comment.