Skip to content

Commit

Permalink
Use xstate function to bind machines to a restate endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman committed Oct 8, 2024
1 parent 6c7f4f1 commit d210a66
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions examples/auth/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import * as restate from "@restatedev/restate-sdk";
import { bindXStateRouter, fromPromise } from "@restatedev/xstate";
import { xstate, fromPromise } from "@restatedev/xstate";
import { createMachine, sendTo } from "xstate";

const authServerMachine = createMachine(
Expand Down Expand Up @@ -77,4 +77,4 @@ const authClientMachine = createMachine({
},
});

await bindXStateRouter(restate.endpoint(), "auth", authClientMachine).listen();
await restate.endpoint().bind(xstate("auth", authClientMachine)).listen();
4 changes: 2 additions & 2 deletions examples/payment/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log, setup } from "xstate";
import * as restate from "@restatedev/restate-sdk";
import { fromPromise, bindXStateRouter } from "@restatedev/xstate";
import { fromPromise, xstate } from "@restatedev/xstate";

export const machine = setup({
types: {
Expand Down Expand Up @@ -130,4 +130,4 @@ export const machine = setup({
},
});

await bindXStateRouter(restate.endpoint(), "payment", machine).listen();
await restate.endpoint().bind(xstate("payment", machine)).listen();
7 changes: 3 additions & 4 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,11 @@ const actorObject = <TLogic extends AnyStateMachine>(
});
};

export const bindXStateRouter = <TLogic extends AnyStateMachine>(
server: restate.RestateEndpoint,
export const xstate = <TLogic extends AnyStateMachine>(
path: string,
logic: TLogic
): restate.RestateEndpoint => {
return server.bind(actorObject(path, logic));
) => {
return actorObject(path, logic);
};

export const xStateApi = <TLogic extends AnyStateMachine>(
Expand Down
2 changes: 1 addition & 1 deletion src/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { bindXStateRouter } from "./lib.js";
export { xstate } from "./lib.js";
export { fromPromise } from "./promise.js";

0 comments on commit d210a66

Please sign in to comment.