Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/packages/emmett/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './testing';
export * from './typing';
export * from './utils';
export * from './validation';
export * from './workflows';
1 change: 0 additions & 1 deletion src/packages/emmett/src/typing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export * from './message';
export * from './messageHandling';

export * from './decider';
export * from './workflow';

export type Brand<K, T> = K & { readonly __brand: T };
export type Flavour<K, T> = K & { readonly __brand?: T };
Expand Down
108 changes: 0 additions & 108 deletions src/packages/emmett/src/typing/workflow.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/packages/emmett/src/workflows/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './workflow';
export * from './workflowProcessor';
39 changes: 39 additions & 0 deletions src/packages/emmett/src/workflows/workflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { EmmettError } from '../errors';
import type { AnyCommand } from '../typing/command';
import type { AnyEvent } from '../typing/event';

/// Inspired by https://blog.bittacklr.be/the-workflow-pattern.html

export type Workflow<
Input extends AnyEvent | AnyCommand,
State,
Output extends AnyEvent | AnyCommand,
> = {
name?: string;
decide: (command: Input, state: State) => WorkflowOutput<Output>;
evolve: (currentState: State, event: WorkflowEvent<Input | Output>) => State;
initialState: () => State;
};

export type WorkflowEvent<Output extends AnyEvent | AnyCommand> = Extract<
Output,
{ kind?: 'Event' }
>;

export type WorkflowCommand<Output extends AnyEvent | AnyCommand> = Extract<
Output,
{ kind?: 'Command' }
>;

export type WorkflowOutput<Output extends AnyEvent | AnyCommand | EmmettError> =
Output | Output[];

export const Workflow = <
Input extends AnyEvent | AnyCommand,
State,
Output extends AnyEvent | AnyCommand,
>(
workflow: Workflow<Input, State, Output>,
): Workflow<Input, State, Output> => {
return workflow;
};
Loading