Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next #16

Merged
merged 3 commits into from
Jan 26, 2024
Merged

Next #16

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
17 changes: 15 additions & 2 deletions src/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,21 @@ export class Service<
.getWorkflow(input.workflowId)
.pipe(Effect.map((w) => w.context));
},
updateWorkflowContext(context: unknown) {
return state.updateWorkflowContext(input.workflowId, context);
updateWorkflowContext(contextOrUpdater: unknown) {
return Effect.gen(function* ($) {
if (typeof contextOrUpdater === 'function') {
const workflow = yield* $(state.getWorkflow(input.workflowId));
return yield* $(
state.updateWorkflowContext(
input.workflowId,
contextOrUpdater(workflow.context)
)
);
}
return yield* $(
state.updateWorkflowContext(input.workflowId, contextOrUpdater)
);
});
},
},
queue: {
Expand Down
9 changes: 9 additions & 0 deletions src/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ export interface State {
taskName: TaskName
): Effect.Effect<never, TaskDoesNotExistInStore, TaskInstanceState>;

getTaskPath(
workflowId: WorkflowId,
taskName: TaskName
): Effect.Effect<
never,
TaskDoesNotExistInStore | WorkflowDoesNotExist,
string[]
>;

getCondition(
workflowId: WorkflowId,
conditionName: ConditionName
Expand Down
62 changes: 62 additions & 0 deletions src/__tests__/__snapshots__/auto-advancing-tasks.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`handles series of auto advancing tasks 1`] = `
{
"conditions": [
{
"marking": 0,
"name": "start",
"workflowId": "workflow-1",
"workflowName": "activities",
},
{
"marking": 1,
"name": "end",
"workflowId": "workflow-1",
"workflowName": "activities",
},
{
"marking": 0,
"name": "implicit:t1->t2",
"workflowId": "workflow-1",
"workflowName": "activities",
},
],
"tasks": [
{
"generation": 1,
"name": "t1",
"state": "completed",
"workflowId": "workflow-1",
"workflowName": "activities",
},
{
"generation": 1,
"name": "t2",
"state": "completed",
"workflowId": "workflow-1",
"workflowName": "activities",
},
],
"workItems": [
{
"id": "workItem-1",
"payload": null,
"state": "completed",
"taskGeneration": 1,
"taskName": "t1",
"workflowId": "workflow-1",
"workflowName": "activities",
},
],
"workflows": [
{
"context": undefined,
"id": "workflow-1",
"name": "activities",
"parent": null,
"state": "completed",
},
],
}
`;
223 changes: 223 additions & 0 deletions src/__tests__/__snapshots__/update-workflow-context.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`handles context update when updater function is passed 1`] = `
{
"conditions": [
{
"marking": 0,
"name": "start",
"workflowId": "workflow-1",
"workflowName": "activities",
},
{
"marking": 0,
"name": "end",
"workflowId": "workflow-1",
"workflowName": "activities",
},
],
"tasks": [
{
"generation": 1,
"name": "t1",
"state": "started",
"workflowId": "workflow-1",
"workflowName": "activities",
},
],
"workItems": [],
"workflows": [
{
"context": {
"count": 2,
},
"id": "workflow-1",
"name": "activities",
"parent": null,
"state": "started",
},
],
}
`;

exports[`handles context update when value is passed 1`] = `
{
"conditions": [
{
"marking": 0,
"name": "start",
"workflowId": "workflow-1",
"workflowName": "activities",
},
{
"marking": 0,
"name": "end",
"workflowId": "workflow-1",
"workflowName": "activities",
},
],
"tasks": [
{
"generation": 1,
"name": "t1",
"state": "started",
"workflowId": "workflow-1",
"workflowName": "activities",
},
],
"workItems": [],
"workflows": [
{
"context": {
"count": 2,
},
"id": "workflow-1",
"name": "activities",
"parent": null,
"state": "started",
},
],
}
`;

exports[`handles parent context update when updater function is passed 1`] = `
{
"conditions": [
{
"marking": 0,
"name": "start",
"workflowId": "workflow-1",
"workflowName": "activities",
},
{
"marking": 0,
"name": "end",
"workflowId": "workflow-1",
"workflowName": "activities",
},
{
"marking": 1,
"name": "start",
"workflowId": "workflow-2",
"workflowName": "sub",
},
{
"marking": 0,
"name": "end",
"workflowId": "workflow-2",
"workflowName": "sub",
},
],
"tasks": [
{
"generation": 1,
"name": "t1",
"state": "started",
"workflowId": "workflow-1",
"workflowName": "activities",
},
{
"generation": 0,
"name": "subT1",
"state": "enabled",
"workflowId": "workflow-2",
"workflowName": "sub",
},
],
"workItems": [],
"workflows": [
{
"context": {
"count": 1,
},
"id": "workflow-1",
"name": "activities",
"parent": null,
"state": "started",
},
{
"context": undefined,
"id": "workflow-2",
"name": "sub",
"parent": {
"taskGeneration": 1,
"taskName": "t1",
"workflowId": "workflow-1",
"workflowName": "activities",
},
"state": "started",
},
],
}
`;

exports[`handles parent context update when value is passed 1`] = `
{
"conditions": [
{
"marking": 0,
"name": "start",
"workflowId": "workflow-1",
"workflowName": "activities",
},
{
"marking": 0,
"name": "end",
"workflowId": "workflow-1",
"workflowName": "activities",
},
{
"marking": 1,
"name": "start",
"workflowId": "workflow-2",
"workflowName": "sub",
},
{
"marking": 0,
"name": "end",
"workflowId": "workflow-2",
"workflowName": "sub",
},
],
"tasks": [
{
"generation": 1,
"name": "t1",
"state": "started",
"workflowId": "workflow-1",
"workflowName": "activities",
},
{
"generation": 0,
"name": "subT1",
"state": "enabled",
"workflowId": "workflow-2",
"workflowName": "sub",
},
],
"workItems": [],
"workflows": [
{
"context": {
"count": 1,
},
"id": "workflow-1",
"name": "activities",
"parent": null,
"state": "started",
},
{
"context": undefined,
"id": "workflow-2",
"name": "sub",
"parent": {
"taskGeneration": 1,
"taskName": "t1",
"workflowId": "workflow-1",
"workflowName": "activities",
},
"state": "started",
},
],
}
`;
Loading
Loading