Documentation
    Preparing search index...
    • Define a Restate workflow.

      Type Parameters

      • P extends string
      • M

      Parameters

      • workflow: {
            description?: string;
            handlers: {
                run: (ctx: WorkflowContext<any>, argument: any) => Promise<any>;
            } & {
                [K in string
                | number
                | symbol]: K extends | "workflowSubmit"
                | "workflowAttach"
                | "workflowOutput"
                    ? `${K<K>} is a reserved keyword`
                    : K extends "run"
                        ? M[K<K>] extends WorkflowHandler<M[K<K>], WorkflowContext<any>>
                            ? any[any]
                            : "An handler named 'run' must take as a first argument a WorkflowContext, and must return a Promise"
                        : M[K] extends WorkflowSharedHandler<M[K], WorkflowSharedContext<any>>
                            ? any[any]
                            : "An handler other then 'run' must accept as a first argument a WorkflowSharedContext"
            } & ThisType<M>;
            metadata?: Record<string, string>;
            name: P;
            options?: WorkflowOptions;
        }

      Returns WorkflowDefinition<P, M>

      const mywf = workflow({
      name: "mywf",
      handlers: {
      run: async (ctx: WorkflowContext, argument: any) => {
      return "Hello World";
      }
      }
      });
      • That a workflow must contain exactly one handler named 'run', and this handler must accept as a first argument a WorkflowContext.
      • The workflow handlers other than 'run' must accept as a first argument a WorkflowSharedContext.
      • The workflow handlers can not be named 'workflowSubmit', 'workflowAttach', 'workflowOutput' - as these are reserved keywords.
      endpoint.bind(mywf)
      
      const client = ctx.workflowClient<typeof mywf>({ name: "mywf"});
      const res = await client.run("Hello");

      To use the workflow client from any other environment (like a browser), please refer to the documentation. https://docs.restate.dev