@contractspec/example.workflow-system 3.8.8 → 3.8.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/approval/approval.enum.js +1 -22
- package/dist/approval/approval.event.js +1 -112
- package/dist/approval/approval.operations.js +1 -369
- package/dist/approval/approval.schema.js +1 -73
- package/dist/approval/index.js +1 -484
- package/dist/browser/approval/approval.enum.js +1 -22
- package/dist/browser/approval/approval.event.js +1 -112
- package/dist/browser/approval/approval.operations.js +1 -369
- package/dist/browser/approval/approval.schema.js +1 -73
- package/dist/browser/approval/index.js +1 -484
- package/dist/browser/docs/index.js +5 -49
- package/dist/browser/docs/workflow-system.docblock.js +5 -49
- package/dist/browser/entities/approval.js +1 -119
- package/dist/browser/entities/index.js +1 -508
- package/dist/browser/entities/instance.js +1 -161
- package/dist/browser/entities/step.js +1 -124
- package/dist/browser/entities/workflow.js +1 -82
- package/dist/browser/example.js +1 -42
- package/dist/browser/handlers/index.js +8 -253
- package/dist/browser/handlers/workflow.handlers.js +8 -253
- package/dist/browser/index.js +13 -3524
- package/dist/browser/instance/index.js +1 -677
- package/dist/browser/instance/instance.enum.js +1 -15
- package/dist/browser/instance/instance.event.js +1 -164
- package/dist/browser/instance/instance.handler.js +1 -356
- package/dist/browser/instance/instance.operations.js +1 -9
- package/dist/browser/instance/instance.schema.js +1 -101
- package/dist/browser/presentations/index.js +1 -109
- package/dist/browser/seeders/index.js +1 -3
- package/dist/browser/shared/demo-scenario.js +1 -213
- package/dist/browser/shared/index.js +1 -3
- package/dist/browser/shared/mock-data.js +1 -11
- package/dist/browser/state-machine/index.js +1 -6
- package/dist/browser/tests/operations.test-spec.js +1 -6
- package/dist/browser/ui/WorkflowDashboard.js +1 -3
- package/dist/browser/ui/WorkflowDashboard.visualizations.js +1 -239
- package/dist/browser/ui/hooks/index.js +1 -3
- package/dist/browser/ui/hooks/useWorkflowList.js +1 -52
- package/dist/browser/ui/index.js +1 -56
- package/dist/browser/ui/renderers/index.js +5 -562
- package/dist/browser/ui/renderers/workflow.markdown.js +5 -562
- package/dist/browser/visualizations/catalog.js +1 -132
- package/dist/browser/visualizations/index.js +1 -133
- package/dist/browser/visualizations/selectors.js +1 -195
- package/dist/browser/workflow/index.js +1 -21
- package/dist/browser/workflow/workflow.enum.js +1 -36
- package/dist/browser/workflow/workflow.event.js +1 -6
- package/dist/browser/workflow/workflow.handler.js +1 -5
- package/dist/browser/workflow/workflow.operations.js +1 -8
- package/dist/browser/workflow/workflow.schema.js +1 -151
- package/dist/browser/workflow-system.capability.js +1 -5
- package/dist/browser/workflow-system.feature.js +1 -3
- package/dist/docs/index.js +5 -49
- package/dist/docs/workflow-system.docblock.js +5 -49
- package/dist/entities/approval.js +1 -119
- package/dist/entities/index.js +1 -508
- package/dist/entities/instance.js +1 -161
- package/dist/entities/step.js +1 -124
- package/dist/entities/workflow.js +1 -82
- package/dist/example.js +1 -42
- package/dist/handlers/index.js +8 -253
- package/dist/handlers/workflow.handlers.js +8 -253
- package/dist/index.js +13 -3524
- package/dist/instance/index.js +1 -677
- package/dist/instance/instance.enum.js +1 -15
- package/dist/instance/instance.event.js +1 -164
- package/dist/instance/instance.handler.js +1 -356
- package/dist/instance/instance.operations.js +1 -9
- package/dist/instance/instance.schema.js +1 -101
- package/dist/presentations/index.js +1 -109
- package/dist/seeders/index.js +1 -3
- package/dist/shared/demo-scenario.js +1 -213
- package/dist/shared/index.js +1 -3
- package/dist/shared/mock-data.js +1 -11
- package/dist/state-machine/index.js +1 -6
- package/dist/tests/operations.test-spec.js +1 -6
- package/dist/ui/WorkflowDashboard.js +1 -3
- package/dist/ui/WorkflowDashboard.visualizations.js +1 -239
- package/dist/ui/hooks/index.js +1 -3
- package/dist/ui/hooks/useWorkflowList.js +1 -52
- package/dist/ui/index.js +1 -56
- package/dist/ui/renderers/index.js +5 -562
- package/dist/ui/renderers/workflow.markdown.js +5 -562
- package/dist/visualizations/catalog.js +1 -132
- package/dist/visualizations/index.js +1 -133
- package/dist/visualizations/selectors.js +1 -195
- package/dist/workflow/index.js +1 -21
- package/dist/workflow/workflow.enum.js +1 -36
- package/dist/workflow/workflow.event.js +1 -6
- package/dist/workflow/workflow.handler.js +1 -5
- package/dist/workflow/workflow.operations.js +1 -8
- package/dist/workflow/workflow.schema.js +1 -151
- package/dist/workflow-system.capability.js +1 -5
- package/dist/workflow-system.feature.js +1 -3
- package/package.json +11 -11
|
@@ -1,16 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { defineEnum } from "@contractspec/lib.schema";
|
|
4
|
-
var InstanceStatusEnum = defineEnum("InstanceStatus", [
|
|
5
|
-
"PENDING",
|
|
6
|
-
"RUNNING",
|
|
7
|
-
"WAITING",
|
|
8
|
-
"PAUSED",
|
|
9
|
-
"COMPLETED",
|
|
10
|
-
"CANCELLED",
|
|
11
|
-
"FAILED",
|
|
12
|
-
"TIMEOUT"
|
|
13
|
-
]);
|
|
14
|
-
export {
|
|
15
|
-
InstanceStatusEnum
|
|
16
|
-
};
|
|
2
|
+
import{defineEnum as g}from"@contractspec/lib.schema";var k=g("InstanceStatus",["PENDING","RUNNING","WAITING","PAUSED","COMPLETED","CANCELLED","FAILED","TIMEOUT"]);export{k as InstanceStatusEnum};
|
|
@@ -1,165 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
4
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
5
|
-
var InstanceEventPayload = defineSchemaModel({
|
|
6
|
-
name: "InstanceEventPayload",
|
|
7
|
-
description: "Base payload for instance events",
|
|
8
|
-
fields: {
|
|
9
|
-
instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
10
|
-
workflowId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
11
|
-
workflowKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
12
|
-
status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
13
|
-
referenceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
14
|
-
referenceType: {
|
|
15
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
16
|
-
isOptional: true
|
|
17
|
-
},
|
|
18
|
-
triggeredBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
19
|
-
organizationId: {
|
|
20
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
21
|
-
isOptional: false
|
|
22
|
-
},
|
|
23
|
-
timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
var StepTransitionPayload = defineSchemaModel({
|
|
27
|
-
name: "StepTransitionEventPayload",
|
|
28
|
-
description: "Payload for step transition events",
|
|
29
|
-
fields: {
|
|
30
|
-
instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
31
|
-
workflowId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
32
|
-
fromStepKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
33
|
-
toStepKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
34
|
-
action: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
35
|
-
executedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
36
|
-
timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
var InstanceCompletedPayload = defineSchemaModel({
|
|
40
|
-
name: "InstanceCompletedEventPayload",
|
|
41
|
-
description: "Payload when instance completes",
|
|
42
|
-
fields: {
|
|
43
|
-
instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
44
|
-
workflowId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
45
|
-
workflowKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
46
|
-
outcome: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
47
|
-
referenceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
48
|
-
referenceType: {
|
|
49
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
50
|
-
isOptional: true
|
|
51
|
-
},
|
|
52
|
-
duration: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
53
|
-
timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
var InstanceStartedEvent = defineEvent({
|
|
57
|
-
meta: {
|
|
58
|
-
key: "workflow.instance.started",
|
|
59
|
-
version: "1.0.0",
|
|
60
|
-
description: "A new workflow instance has been started.",
|
|
61
|
-
stability: "stable",
|
|
62
|
-
owners: ["@workflow-team"],
|
|
63
|
-
tags: ["workflow", "instance", "started"]
|
|
64
|
-
},
|
|
65
|
-
payload: InstanceEventPayload
|
|
66
|
-
});
|
|
67
|
-
var StepEnteredEvent = defineEvent({
|
|
68
|
-
meta: {
|
|
69
|
-
key: "workflow.step.entered",
|
|
70
|
-
version: "1.0.0",
|
|
71
|
-
description: "A workflow instance has entered a new step.",
|
|
72
|
-
stability: "stable",
|
|
73
|
-
owners: ["@workflow-team"],
|
|
74
|
-
tags: ["workflow", "step", "entered"]
|
|
75
|
-
},
|
|
76
|
-
payload: StepTransitionPayload
|
|
77
|
-
});
|
|
78
|
-
var StepExitedEvent = defineEvent({
|
|
79
|
-
meta: {
|
|
80
|
-
key: "workflow.step.exited",
|
|
81
|
-
version: "1.0.0",
|
|
82
|
-
description: "A workflow instance has exited a step.",
|
|
83
|
-
stability: "stable",
|
|
84
|
-
owners: ["@workflow-team"],
|
|
85
|
-
tags: ["workflow", "step", "exited"]
|
|
86
|
-
},
|
|
87
|
-
payload: StepTransitionPayload
|
|
88
|
-
});
|
|
89
|
-
var InstanceCompletedEvent = defineEvent({
|
|
90
|
-
meta: {
|
|
91
|
-
key: "workflow.instance.completed",
|
|
92
|
-
version: "1.0.0",
|
|
93
|
-
description: "A workflow instance has completed.",
|
|
94
|
-
stability: "stable",
|
|
95
|
-
owners: ["@workflow-team"],
|
|
96
|
-
tags: ["workflow", "instance", "completed"]
|
|
97
|
-
},
|
|
98
|
-
payload: InstanceCompletedPayload
|
|
99
|
-
});
|
|
100
|
-
var InstanceCancelledEvent = defineEvent({
|
|
101
|
-
meta: {
|
|
102
|
-
key: "workflow.instance.cancelled",
|
|
103
|
-
version: "1.0.0",
|
|
104
|
-
description: "A workflow instance has been cancelled.",
|
|
105
|
-
stability: "stable",
|
|
106
|
-
owners: ["@workflow-team"],
|
|
107
|
-
tags: ["workflow", "instance", "cancelled"]
|
|
108
|
-
},
|
|
109
|
-
payload: InstanceEventPayload
|
|
110
|
-
});
|
|
111
|
-
var InstancePausedEvent = defineEvent({
|
|
112
|
-
meta: {
|
|
113
|
-
key: "workflow.instance.paused",
|
|
114
|
-
version: "1.0.0",
|
|
115
|
-
description: "A workflow instance has been paused.",
|
|
116
|
-
stability: "stable",
|
|
117
|
-
owners: ["@workflow-team"],
|
|
118
|
-
tags: ["workflow", "instance", "paused"]
|
|
119
|
-
},
|
|
120
|
-
payload: InstanceEventPayload
|
|
121
|
-
});
|
|
122
|
-
var InstanceResumedEvent = defineEvent({
|
|
123
|
-
meta: {
|
|
124
|
-
key: "workflow.instance.resumed",
|
|
125
|
-
version: "1.0.0",
|
|
126
|
-
description: "A workflow instance has been resumed.",
|
|
127
|
-
stability: "stable",
|
|
128
|
-
owners: ["@workflow-team"],
|
|
129
|
-
tags: ["workflow", "instance", "resumed"]
|
|
130
|
-
},
|
|
131
|
-
payload: InstanceEventPayload
|
|
132
|
-
});
|
|
133
|
-
var InstanceFailedEvent = defineEvent({
|
|
134
|
-
meta: {
|
|
135
|
-
key: "workflow.instance.failed",
|
|
136
|
-
version: "1.0.0",
|
|
137
|
-
description: "A workflow instance has failed.",
|
|
138
|
-
stability: "stable",
|
|
139
|
-
owners: ["@workflow-team"],
|
|
140
|
-
tags: ["workflow", "instance", "failed"]
|
|
141
|
-
},
|
|
142
|
-
payload: InstanceEventPayload
|
|
143
|
-
});
|
|
144
|
-
var InstanceTimedOutEvent = defineEvent({
|
|
145
|
-
meta: {
|
|
146
|
-
key: "workflow.instance.timedOut",
|
|
147
|
-
version: "1.0.0",
|
|
148
|
-
description: "A workflow instance has timed out.",
|
|
149
|
-
stability: "stable",
|
|
150
|
-
owners: ["@workflow-team"],
|
|
151
|
-
tags: ["workflow", "instance", "timeout"]
|
|
152
|
-
},
|
|
153
|
-
payload: InstanceEventPayload
|
|
154
|
-
});
|
|
155
|
-
export {
|
|
156
|
-
StepExitedEvent,
|
|
157
|
-
StepEnteredEvent,
|
|
158
|
-
InstanceTimedOutEvent,
|
|
159
|
-
InstanceStartedEvent,
|
|
160
|
-
InstanceResumedEvent,
|
|
161
|
-
InstancePausedEvent,
|
|
162
|
-
InstanceFailedEvent,
|
|
163
|
-
InstanceCompletedEvent,
|
|
164
|
-
InstanceCancelledEvent
|
|
165
|
-
};
|
|
2
|
+
import{defineEvent as j}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as q,ScalarTypeEnum as g}from"@contractspec/lib.schema";var k=q({name:"InstanceEventPayload",description:"Base payload for instance events",fields:{instanceId:{type:g.String_unsecure(),isOptional:!1},workflowId:{type:g.String_unsecure(),isOptional:!1},workflowKey:{type:g.String_unsecure(),isOptional:!1},status:{type:g.String_unsecure(),isOptional:!1},referenceId:{type:g.String_unsecure(),isOptional:!0},referenceType:{type:g.String_unsecure(),isOptional:!0},triggeredBy:{type:g.String_unsecure(),isOptional:!1},organizationId:{type:g.String_unsecure(),isOptional:!1},timestamp:{type:g.DateTime(),isOptional:!1}}}),w=q({name:"StepTransitionEventPayload",description:"Payload for step transition events",fields:{instanceId:{type:g.String_unsecure(),isOptional:!1},workflowId:{type:g.String_unsecure(),isOptional:!1},fromStepKey:{type:g.String_unsecure(),isOptional:!0},toStepKey:{type:g.String_unsecure(),isOptional:!1},action:{type:g.String_unsecure(),isOptional:!0},executedBy:{type:g.String_unsecure(),isOptional:!1},timestamp:{type:g.DateTime(),isOptional:!1}}}),x=q({name:"InstanceCompletedEventPayload",description:"Payload when instance completes",fields:{instanceId:{type:g.String_unsecure(),isOptional:!1},workflowId:{type:g.String_unsecure(),isOptional:!1},workflowKey:{type:g.String_unsecure(),isOptional:!1},outcome:{type:g.String_unsecure(),isOptional:!1},referenceId:{type:g.String_unsecure(),isOptional:!0},referenceType:{type:g.String_unsecure(),isOptional:!0},duration:{type:g.Int_unsecure(),isOptional:!1},timestamp:{type:g.DateTime(),isOptional:!1}}}),B=j({meta:{key:"workflow.instance.started",version:"1.0.0",description:"A new workflow instance has been started.",stability:"stable",owners:["@workflow-team"],tags:["workflow","instance","started"]},payload:k}),D=j({meta:{key:"workflow.step.entered",version:"1.0.0",description:"A workflow instance has entered a new step.",stability:"stable",owners:["@workflow-team"],tags:["workflow","step","entered"]},payload:w}),F=j({meta:{key:"workflow.step.exited",version:"1.0.0",description:"A workflow instance has exited a step.",stability:"stable",owners:["@workflow-team"],tags:["workflow","step","exited"]},payload:w}),G=j({meta:{key:"workflow.instance.completed",version:"1.0.0",description:"A workflow instance has completed.",stability:"stable",owners:["@workflow-team"],tags:["workflow","instance","completed"]},payload:x}),H=j({meta:{key:"workflow.instance.cancelled",version:"1.0.0",description:"A workflow instance has been cancelled.",stability:"stable",owners:["@workflow-team"],tags:["workflow","instance","cancelled"]},payload:k}),J=j({meta:{key:"workflow.instance.paused",version:"1.0.0",description:"A workflow instance has been paused.",stability:"stable",owners:["@workflow-team"],tags:["workflow","instance","paused"]},payload:k}),K=j({meta:{key:"workflow.instance.resumed",version:"1.0.0",description:"A workflow instance has been resumed.",stability:"stable",owners:["@workflow-team"],tags:["workflow","instance","resumed"]},payload:k}),L=j({meta:{key:"workflow.instance.failed",version:"1.0.0",description:"A workflow instance has failed.",stability:"stable",owners:["@workflow-team"],tags:["workflow","instance","failed"]},payload:k}),N=j({meta:{key:"workflow.instance.timedOut",version:"1.0.0",description:"A workflow instance has timed out.",stability:"stable",owners:["@workflow-team"],tags:["workflow","instance","timeout"]},payload:k});export{F as StepExitedEvent,D as StepEnteredEvent,N as InstanceTimedOutEvent,B as InstanceStartedEvent,K as InstanceResumedEvent,J as InstancePausedEvent,L as InstanceFailedEvent,G as InstanceCompletedEvent,H as InstanceCancelledEvent};
|
|
@@ -1,357 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
var mockDataStore = {
|
|
4
|
-
workflows: new Map,
|
|
5
|
-
steps: new Map,
|
|
6
|
-
instances: new Map,
|
|
7
|
-
approvals: new Map,
|
|
8
|
-
stepExecutions: new Map
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
// src/state-machine/index.ts
|
|
12
|
-
class BasicStateMachineEngine {
|
|
13
|
-
canTransition(definition, state, action, context) {
|
|
14
|
-
if (state.status !== "RUNNING" && state.status !== "WAITING") {
|
|
15
|
-
return {
|
|
16
|
-
allowed: false,
|
|
17
|
-
reason: `Workflow is ${state.status}, cannot transition`
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
const currentStep = definition.steps[state.currentStepKey];
|
|
21
|
-
if (!currentStep) {
|
|
22
|
-
return {
|
|
23
|
-
allowed: false,
|
|
24
|
-
reason: `Step ${state.currentStepKey} not found`
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
const transition = currentStep.transitions[action];
|
|
28
|
-
if (!transition) {
|
|
29
|
-
return {
|
|
30
|
-
allowed: false,
|
|
31
|
-
reason: `Action ${action} not available in step ${state.currentStepKey}`
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (currentStep.allowedRoles && currentStep.allowedRoles.length > 0) {
|
|
35
|
-
const hasRole = currentStep.allowedRoles.some((role) => context.userRoles.includes(role));
|
|
36
|
-
if (!hasRole) {
|
|
37
|
-
return {
|
|
38
|
-
allowed: false,
|
|
39
|
-
reason: `User lacks required role for this action`
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (typeof transition === "object" && transition.allowedRoles && transition.allowedRoles.length > 0) {
|
|
44
|
-
const hasRole = transition.allowedRoles.some((role) => context.userRoles.includes(role));
|
|
45
|
-
if (!hasRole) {
|
|
46
|
-
return {
|
|
47
|
-
allowed: false,
|
|
48
|
-
reason: `User lacks required role for action ${action}`
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return { allowed: true };
|
|
53
|
-
}
|
|
54
|
-
getAvailableActions(definition, state, context) {
|
|
55
|
-
if (state.status !== "RUNNING" && state.status !== "WAITING") {
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
|
-
const currentStep = definition.steps[state.currentStepKey];
|
|
59
|
-
if (!currentStep) {
|
|
60
|
-
return [];
|
|
61
|
-
}
|
|
62
|
-
return Object.keys(currentStep.transitions).filter((action) => {
|
|
63
|
-
const result = this.canTransition(definition, state, action, context);
|
|
64
|
-
return result.allowed;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
transition(definition, state, action, context) {
|
|
68
|
-
const validation = this.canTransition(definition, state, action, context);
|
|
69
|
-
if (!validation.allowed) {
|
|
70
|
-
return {
|
|
71
|
-
success: false,
|
|
72
|
-
previousStepKey: state.currentStepKey,
|
|
73
|
-
currentStepKey: state.currentStepKey,
|
|
74
|
-
status: state.status,
|
|
75
|
-
error: validation.reason
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
const currentStep = definition.steps[state.currentStepKey];
|
|
79
|
-
if (!currentStep) {
|
|
80
|
-
return {
|
|
81
|
-
success: false,
|
|
82
|
-
previousStepKey: state.currentStepKey,
|
|
83
|
-
currentStepKey: state.currentStepKey,
|
|
84
|
-
status: state.status,
|
|
85
|
-
error: `Current step ${state.currentStepKey} not found`
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
const transition = currentStep.transitions[action];
|
|
89
|
-
if (!transition) {
|
|
90
|
-
return {
|
|
91
|
-
success: false,
|
|
92
|
-
previousStepKey: state.currentStepKey,
|
|
93
|
-
currentStepKey: state.currentStepKey,
|
|
94
|
-
status: state.status,
|
|
95
|
-
error: `Transition for action ${action} not found`
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
const targetStepKey = typeof transition === "string" ? transition : transition.targetStepKey;
|
|
99
|
-
const targetStep = definition.steps[targetStepKey];
|
|
100
|
-
if (!targetStep) {
|
|
101
|
-
return {
|
|
102
|
-
success: false,
|
|
103
|
-
previousStepKey: state.currentStepKey,
|
|
104
|
-
currentStepKey: state.currentStepKey,
|
|
105
|
-
status: state.status,
|
|
106
|
-
error: `Target step ${targetStepKey} not found`
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
let newStatus = "RUNNING";
|
|
110
|
-
if (targetStep.type === "END") {
|
|
111
|
-
newStatus = "COMPLETED";
|
|
112
|
-
} else if (targetStep.type === "APPROVAL" || targetStep.type === "WAIT") {
|
|
113
|
-
newStatus = "WAITING";
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
success: true,
|
|
117
|
-
previousStepKey: state.currentStepKey,
|
|
118
|
-
currentStepKey: targetStepKey,
|
|
119
|
-
status: newStatus
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
evaluateCondition(expression, contextData) {
|
|
123
|
-
try {
|
|
124
|
-
const match = expression.match(/^(\w+)\s*(>=|<=|>|<|===|!==|==|!=)\s*(.+)$/);
|
|
125
|
-
if (match) {
|
|
126
|
-
const [, prop, operator, value] = match;
|
|
127
|
-
if (!prop || !operator || value === undefined) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
const propValue = contextData[prop];
|
|
131
|
-
const compareValue = JSON.parse(value);
|
|
132
|
-
switch (operator) {
|
|
133
|
-
case ">":
|
|
134
|
-
return Number(propValue) > Number(compareValue);
|
|
135
|
-
case "<":
|
|
136
|
-
return Number(propValue) < Number(compareValue);
|
|
137
|
-
case ">=":
|
|
138
|
-
return Number(propValue) >= Number(compareValue);
|
|
139
|
-
case "<=":
|
|
140
|
-
return Number(propValue) <= Number(compareValue);
|
|
141
|
-
case "===":
|
|
142
|
-
case "==":
|
|
143
|
-
return propValue === compareValue;
|
|
144
|
-
case "!==":
|
|
145
|
-
case "!=":
|
|
146
|
-
return propValue !== compareValue;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (expression in contextData) {
|
|
150
|
-
return Boolean(contextData[expression]);
|
|
151
|
-
}
|
|
152
|
-
return false;
|
|
153
|
-
} catch {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function createStateMachineEngine() {
|
|
159
|
-
return new BasicStateMachineEngine;
|
|
160
|
-
}
|
|
161
|
-
function buildStateMachineDefinition(workflow, steps) {
|
|
162
|
-
const stepMap = {};
|
|
163
|
-
for (const step of steps) {
|
|
164
|
-
stepMap[step.key] = {
|
|
165
|
-
key: step.key,
|
|
166
|
-
name: step.name,
|
|
167
|
-
type: step.type,
|
|
168
|
-
transitions: step.transitions,
|
|
169
|
-
approvalMode: step.approvalMode,
|
|
170
|
-
allowedRoles: step.approverRoles,
|
|
171
|
-
timeoutSeconds: step.timeoutSeconds,
|
|
172
|
-
conditionExpression: step.conditionExpression
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
const startStep = steps.find((s) => s.type === "START");
|
|
176
|
-
const initialStepKey = startStep?.key ?? steps[0]?.key ?? "";
|
|
177
|
-
return {
|
|
178
|
-
key: workflow.key,
|
|
179
|
-
name: workflow.name,
|
|
180
|
-
version: workflow.version,
|
|
181
|
-
initialStepKey,
|
|
182
|
-
steps: stepMap
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
function createInitialState(definition, contextData = {}) {
|
|
186
|
-
return {
|
|
187
|
-
currentStepKey: definition.initialStepKey,
|
|
188
|
-
status: "RUNNING",
|
|
189
|
-
contextData,
|
|
190
|
-
history: []
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// src/approval/approval.handler.ts
|
|
195
|
-
async function createApprovalRequests(instance, step, _context) {
|
|
196
|
-
const now = new Date;
|
|
197
|
-
for (let i = 0;i < step.approverRoles.length; i++) {
|
|
198
|
-
const role = step.approverRoles[i];
|
|
199
|
-
const id = `approval_${Date.now()}_${i}`;
|
|
200
|
-
const request = {
|
|
201
|
-
id,
|
|
202
|
-
workflowInstanceId: instance.id,
|
|
203
|
-
stepExecutionId: `exec_${instance.id}_${step.id}`,
|
|
204
|
-
approverId: `user_${role}`,
|
|
205
|
-
approverRole: role,
|
|
206
|
-
title: `Approval required for ${step.name}`,
|
|
207
|
-
description: step.description,
|
|
208
|
-
status: "PENDING",
|
|
209
|
-
contextSnapshot: instance.contextData,
|
|
210
|
-
sequenceOrder: i,
|
|
211
|
-
createdAt: now,
|
|
212
|
-
updatedAt: now
|
|
213
|
-
};
|
|
214
|
-
mockDataStore.approvals.set(id, request);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
async function handleSubmitDecision(input, context) {
|
|
218
|
-
const request = mockDataStore.approvals.get(input.requestId);
|
|
219
|
-
if (!request) {
|
|
220
|
-
throw new Error(`Approval request ${input.requestId} not found`);
|
|
221
|
-
}
|
|
222
|
-
if (request.approverId !== context.userId && !context.userRoles.includes(request.approverRole ?? "")) {
|
|
223
|
-
throw new Error("User is not authorized to make this decision");
|
|
224
|
-
}
|
|
225
|
-
const now = new Date;
|
|
226
|
-
request.decision = input.decision;
|
|
227
|
-
request.decisionComment = input.comment;
|
|
228
|
-
request.decidedAt = now;
|
|
229
|
-
request.updatedAt = now;
|
|
230
|
-
if (input.decision === "APPROVE") {
|
|
231
|
-
request.status = "APPROVED";
|
|
232
|
-
await handleTransitionWorkflow({
|
|
233
|
-
instanceId: request.workflowInstanceId,
|
|
234
|
-
action: "approve",
|
|
235
|
-
data: input.data,
|
|
236
|
-
comment: input.comment
|
|
237
|
-
}, context);
|
|
238
|
-
} else if (input.decision === "REJECT") {
|
|
239
|
-
request.status = "REJECTED";
|
|
240
|
-
await handleTransitionWorkflow({
|
|
241
|
-
instanceId: request.workflowInstanceId,
|
|
242
|
-
action: "reject",
|
|
243
|
-
data: input.data,
|
|
244
|
-
comment: input.comment
|
|
245
|
-
}, context);
|
|
246
|
-
}
|
|
247
|
-
return request;
|
|
248
|
-
}
|
|
249
|
-
async function handleListMyApprovals(input, context) {
|
|
250
|
-
let requests = Array.from(mockDataStore.approvals.values()).filter((r) => r.approverId === context.userId || context.userRoles.includes(r.approverRole ?? ""));
|
|
251
|
-
const pendingCount = requests.filter((r) => r.status === "PENDING").length;
|
|
252
|
-
if (input.status) {
|
|
253
|
-
requests = requests.filter((r) => r.status === input.status);
|
|
254
|
-
}
|
|
255
|
-
const total = requests.length;
|
|
256
|
-
const offset = input.offset ?? 0;
|
|
257
|
-
const limit = input.limit ?? 20;
|
|
258
|
-
requests = requests.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime()).slice(offset, offset + limit);
|
|
259
|
-
return { requests, total, pendingCount };
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// src/instance/instance.handler.ts
|
|
263
|
-
async function handleStartWorkflow(input, context) {
|
|
264
|
-
const workflow = Array.from(mockDataStore.workflows.values()).find((w) => w.key === input.workflowKey && w.status === "ACTIVE" && w.organizationId === context.organizationId);
|
|
265
|
-
if (!workflow) {
|
|
266
|
-
throw new Error(`Active workflow ${input.workflowKey} not found`);
|
|
267
|
-
}
|
|
268
|
-
const id = `inst_${Date.now()}`;
|
|
269
|
-
const now = new Date;
|
|
270
|
-
const instance = {
|
|
271
|
-
id,
|
|
272
|
-
workflowDefinitionId: workflow.id,
|
|
273
|
-
referenceId: input.referenceId,
|
|
274
|
-
referenceType: input.referenceType,
|
|
275
|
-
status: "RUNNING",
|
|
276
|
-
currentStepId: workflow.initialStepId,
|
|
277
|
-
contextData: input.contextData ?? {},
|
|
278
|
-
triggeredBy: context.userId,
|
|
279
|
-
organizationId: context.organizationId,
|
|
280
|
-
priority: input.priority ?? 0,
|
|
281
|
-
dueAt: input.dueAt,
|
|
282
|
-
createdAt: now,
|
|
283
|
-
updatedAt: now,
|
|
284
|
-
startedAt: now
|
|
285
|
-
};
|
|
286
|
-
mockDataStore.instances.set(id, instance);
|
|
287
|
-
if (workflow.initialStepId) {
|
|
288
|
-
const firstStep = mockDataStore.steps.get(workflow.initialStepId);
|
|
289
|
-
if (firstStep?.type === "APPROVAL") {
|
|
290
|
-
instance.status = "WAITING";
|
|
291
|
-
await createApprovalRequests(instance, firstStep, context);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
return instance;
|
|
295
|
-
}
|
|
296
|
-
async function handleTransitionWorkflow(input, context) {
|
|
297
|
-
const instance = mockDataStore.instances.get(input.instanceId);
|
|
298
|
-
if (!instance) {
|
|
299
|
-
throw new Error(`Instance ${input.instanceId} not found`);
|
|
300
|
-
}
|
|
301
|
-
const workflow = mockDataStore.workflows.get(instance.workflowDefinitionId);
|
|
302
|
-
if (!workflow) {
|
|
303
|
-
throw new Error(`Workflow ${instance.workflowDefinitionId} not found`);
|
|
304
|
-
}
|
|
305
|
-
const steps = Array.from(mockDataStore.steps.values()).filter((s) => s.workflowDefinitionId === workflow.id);
|
|
306
|
-
const definition = buildStateMachineDefinition({
|
|
307
|
-
key: workflow.key,
|
|
308
|
-
name: workflow.name,
|
|
309
|
-
version: workflow.version,
|
|
310
|
-
initialStepId: workflow.initialStepId ?? null
|
|
311
|
-
}, steps);
|
|
312
|
-
const currentStep = steps.find((s) => s.id === instance.currentStepId);
|
|
313
|
-
const state = {
|
|
314
|
-
currentStepKey: currentStep?.key ?? "",
|
|
315
|
-
status: instance.status,
|
|
316
|
-
contextData: instance.contextData,
|
|
317
|
-
history: []
|
|
318
|
-
};
|
|
319
|
-
const transitionContext = {
|
|
320
|
-
userId: context.userId,
|
|
321
|
-
userRoles: context.userRoles,
|
|
322
|
-
data: input.data
|
|
323
|
-
};
|
|
324
|
-
const engine = createStateMachineEngine();
|
|
325
|
-
const result = engine.transition(definition, state, input.action, transitionContext);
|
|
326
|
-
if (!result.success) {
|
|
327
|
-
return {
|
|
328
|
-
success: false,
|
|
329
|
-
instance,
|
|
330
|
-
message: result.error
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
const previousStepKey = currentStep?.key;
|
|
334
|
-
const newStep = steps.find((s) => s.key === result.currentStepKey);
|
|
335
|
-
instance.currentStepId = newStep?.id;
|
|
336
|
-
instance.status = result.status;
|
|
337
|
-
instance.contextData = { ...instance.contextData, ...input.data };
|
|
338
|
-
instance.updatedAt = new Date;
|
|
339
|
-
if (result.status === "COMPLETED") {
|
|
340
|
-
instance.completedAt = new Date;
|
|
341
|
-
instance.outcome = input.action;
|
|
342
|
-
}
|
|
343
|
-
if (newStep?.type === "APPROVAL") {
|
|
344
|
-
instance.status = "WAITING";
|
|
345
|
-
await createApprovalRequests(instance, newStep, context);
|
|
346
|
-
}
|
|
347
|
-
return {
|
|
348
|
-
success: true,
|
|
349
|
-
instance,
|
|
350
|
-
previousStepKey,
|
|
351
|
-
currentStepKey: result.currentStepKey ?? undefined
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
export {
|
|
355
|
-
handleTransitionWorkflow,
|
|
356
|
-
handleStartWorkflow
|
|
357
|
-
};
|
|
2
|
+
var J={workflows:new Map,steps:new Map,instances:new Map,approvals:new Map,stepExecutions:new Map};class Y{canTransition(W,R,I,z){if(R.status!=="RUNNING"&&R.status!=="WAITING")return{allowed:!1,reason:`Workflow is ${R.status}, cannot transition`};let j=W.steps[R.currentStepKey];if(!j)return{allowed:!1,reason:`Step ${R.currentStepKey} not found`};let b=j.transitions[I];if(!b)return{allowed:!1,reason:`Action ${I} not available in step ${R.currentStepKey}`};if(j.allowedRoles&&j.allowedRoles.length>0){if(!j.allowedRoles.some((F)=>z.userRoles.includes(F)))return{allowed:!1,reason:"User lacks required role for this action"}}if(typeof b==="object"&&b.allowedRoles&&b.allowedRoles.length>0){if(!b.allowedRoles.some((F)=>z.userRoles.includes(F)))return{allowed:!1,reason:`User lacks required role for action ${I}`}}return{allowed:!0}}getAvailableActions(W,R,I){if(R.status!=="RUNNING"&&R.status!=="WAITING")return[];let z=W.steps[R.currentStepKey];if(!z)return[];return Object.keys(z.transitions).filter((j)=>{return this.canTransition(W,R,j,I).allowed})}transition(W,R,I,z){let j=this.canTransition(W,R,I,z);if(!j.allowed)return{success:!1,previousStepKey:R.currentStepKey,currentStepKey:R.currentStepKey,status:R.status,error:j.reason};let b=W.steps[R.currentStepKey];if(!b)return{success:!1,previousStepKey:R.currentStepKey,currentStepKey:R.currentStepKey,status:R.status,error:`Current step ${R.currentStepKey} not found`};let A=b.transitions[I];if(!A)return{success:!1,previousStepKey:R.currentStepKey,currentStepKey:R.currentStepKey,status:R.status,error:`Transition for action ${I} not found`};let F=typeof A==="string"?A:A.targetStepKey,L=W.steps[F];if(!L)return{success:!1,previousStepKey:R.currentStepKey,currentStepKey:R.currentStepKey,status:R.status,error:`Target step ${F} not found`};let O="RUNNING";if(L.type==="END")O="COMPLETED";else if(L.type==="APPROVAL"||L.type==="WAIT")O="WAITING";return{success:!0,previousStepKey:R.currentStepKey,currentStepKey:F,status:O}}evaluateCondition(W,R){try{let I=W.match(/^(\w+)\s*(>=|<=|>|<|===|!==|==|!=)\s*(.+)$/);if(I){let[,z,j,b]=I;if(!z||!j||b===void 0)return!1;let A=R[z],F=JSON.parse(b);switch(j){case">":return Number(A)>Number(F);case"<":return Number(A)<Number(F);case">=":return Number(A)>=Number(F);case"<=":return Number(A)<=Number(F);case"===":case"==":return A===F;case"!==":case"!=":return A!==F}}if(W in R)return Boolean(R[W]);return!1}catch{return!1}}}function Z(){return new Y}function _(W,R){let I={};for(let b of R)I[b.key]={key:b.key,name:b.name,type:b.type,transitions:b.transitions,approvalMode:b.approvalMode,allowedRoles:b.approverRoles,timeoutSeconds:b.timeoutSeconds,conditionExpression:b.conditionExpression};let j=R.find((b)=>b.type==="START")?.key??R[0]?.key??"";return{key:W.key,name:W.name,version:W.version,initialStepKey:j,steps:I}}function H(W,R={}){return{currentStepKey:W.initialStepKey,status:"RUNNING",contextData:R,history:[]}}async function X(W,R,I){let z=new Date;for(let j=0;j<R.approverRoles.length;j++){let b=R.approverRoles[j],A=`approval_${Date.now()}_${j}`,F={id:A,workflowInstanceId:W.id,stepExecutionId:`exec_${W.id}_${R.id}`,approverId:`user_${b}`,approverRole:b,title:`Approval required for ${R.name}`,description:R.description,status:"PENDING",contextSnapshot:W.contextData,sequenceOrder:j,createdAt:z,updatedAt:z};J.approvals.set(A,F)}}async function B(W,R){let I=J.approvals.get(W.requestId);if(!I)throw Error(`Approval request ${W.requestId} not found`);if(I.approverId!==R.userId&&!R.userRoles.includes(I.approverRole??""))throw Error("User is not authorized to make this decision");let z=new Date;if(I.decision=W.decision,I.decisionComment=W.comment,I.decidedAt=z,I.updatedAt=z,W.decision==="APPROVE")I.status="APPROVED",await Q({instanceId:I.workflowInstanceId,action:"approve",data:W.data,comment:W.comment},R);else if(W.decision==="REJECT")I.status="REJECTED",await Q({instanceId:I.workflowInstanceId,action:"reject",data:W.data,comment:W.comment},R);return I}async function C(W,R){let I=Array.from(J.approvals.values()).filter((F)=>F.approverId===R.userId||R.userRoles.includes(F.approverRole??"")),z=I.filter((F)=>F.status==="PENDING").length;if(W.status)I=I.filter((F)=>F.status===W.status);let j=I.length,b=W.offset??0,A=W.limit??20;return I=I.sort((F,L)=>L.createdAt.getTime()-F.createdAt.getTime()).slice(b,b+A),{requests:I,total:j,pendingCount:z}}async function V(W,R){let I=Array.from(J.workflows.values()).find((A)=>A.key===W.workflowKey&&A.status==="ACTIVE"&&A.organizationId===R.organizationId);if(!I)throw Error(`Active workflow ${W.workflowKey} not found`);let z=`inst_${Date.now()}`,j=new Date,b={id:z,workflowDefinitionId:I.id,referenceId:W.referenceId,referenceType:W.referenceType,status:"RUNNING",currentStepId:I.initialStepId,contextData:W.contextData??{},triggeredBy:R.userId,organizationId:R.organizationId,priority:W.priority??0,dueAt:W.dueAt,createdAt:j,updatedAt:j,startedAt:j};if(J.instances.set(z,b),I.initialStepId){let A=J.steps.get(I.initialStepId);if(A?.type==="APPROVAL")b.status="WAITING",await X(b,A,R)}return b}async function Q(W,R){let I=J.instances.get(W.instanceId);if(!I)throw Error(`Instance ${W.instanceId} not found`);let z=J.workflows.get(I.workflowDefinitionId);if(!z)throw Error(`Workflow ${I.workflowDefinitionId} not found`);let j=Array.from(J.steps.values()).filter((N)=>N.workflowDefinitionId===z.id),b=_({key:z.key,name:z.name,version:z.version,initialStepId:z.initialStepId??null},j),A=j.find((N)=>N.id===I.currentStepId),F={currentStepKey:A?.key??"",status:I.status,contextData:I.contextData,history:[]},L={userId:R.userId,userRoles:R.userRoles,data:W.data},M=Z().transition(b,F,W.action,L);if(!M.success)return{success:!1,instance:I,message:M.error};let $=A?.key,P=j.find((N)=>N.key===M.currentStepKey);if(I.currentStepId=P?.id,I.status=M.status,I.contextData={...I.contextData,...W.data},I.updatedAt=new Date,M.status==="COMPLETED")I.completedAt=new Date,I.outcome=W.action;if(P?.type==="APPROVAL")I.status="WAITING",await X(I,P,R);return{success:!0,instance:I,previousStepKey:$,currentStepKey:M.currentStepKey??void 0}}export{Q as handleTransitionWorkflow,V as handleStartWorkflow};
|
|
@@ -1,10 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
export
|
|
3
|
-
TransitionWorkflowContract,
|
|
4
|
-
StartWorkflowContract,
|
|
5
|
-
ResumeWorkflowContract,
|
|
6
|
-
PauseWorkflowContract,
|
|
7
|
-
ListInstancesContract,
|
|
8
|
-
GetInstanceContract,
|
|
9
|
-
CancelWorkflowContract
|
|
10
|
-
};
|
|
2
|
+
export{TransitionWorkflowContract,StartWorkflowContract,ResumeWorkflowContract,PauseWorkflowContract,ListInstancesContract,GetInstanceContract,CancelWorkflowContract};
|
|
@@ -1,102 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { defineEnum } from "@contractspec/lib.schema";
|
|
4
|
-
var InstanceStatusEnum = defineEnum("InstanceStatus", [
|
|
5
|
-
"PENDING",
|
|
6
|
-
"RUNNING",
|
|
7
|
-
"WAITING",
|
|
8
|
-
"PAUSED",
|
|
9
|
-
"COMPLETED",
|
|
10
|
-
"CANCELLED",
|
|
11
|
-
"FAILED",
|
|
12
|
-
"TIMEOUT"
|
|
13
|
-
]);
|
|
14
|
-
|
|
15
|
-
// src/instance/instance.schema.ts
|
|
16
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
17
|
-
var WorkflowInstanceModel = defineSchemaModel({
|
|
18
|
-
name: "WorkflowInstanceModel",
|
|
19
|
-
description: "A running workflow instance",
|
|
20
|
-
fields: {
|
|
21
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
22
|
-
workflowDefinitionId: {
|
|
23
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
24
|
-
isOptional: false
|
|
25
|
-
},
|
|
26
|
-
referenceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
27
|
-
referenceType: {
|
|
28
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
29
|
-
isOptional: true
|
|
30
|
-
},
|
|
31
|
-
status: { type: InstanceStatusEnum, isOptional: false },
|
|
32
|
-
currentStepId: {
|
|
33
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
34
|
-
isOptional: true
|
|
35
|
-
},
|
|
36
|
-
contextData: { type: ScalarTypeEnum.JSON(), isOptional: true },
|
|
37
|
-
triggeredBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
38
|
-
organizationId: {
|
|
39
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
40
|
-
isOptional: false
|
|
41
|
-
},
|
|
42
|
-
priority: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
43
|
-
dueAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
44
|
-
outcome: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
45
|
-
resultData: { type: ScalarTypeEnum.JSON(), isOptional: true },
|
|
46
|
-
errorMessage: {
|
|
47
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
48
|
-
isOptional: true
|
|
49
|
-
},
|
|
50
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
51
|
-
startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
52
|
-
completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true }
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
var StartWorkflowInputModel = defineSchemaModel({
|
|
56
|
-
name: "StartWorkflowInput",
|
|
57
|
-
description: "Input for starting a workflow",
|
|
58
|
-
fields: {
|
|
59
|
-
workflowKey: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
60
|
-
contextData: { type: ScalarTypeEnum.JSON(), isOptional: true },
|
|
61
|
-
referenceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
62
|
-
referenceType: {
|
|
63
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
64
|
-
isOptional: true
|
|
65
|
-
},
|
|
66
|
-
priority: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
|
|
67
|
-
dueAt: { type: ScalarTypeEnum.DateTime(), isOptional: true }
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
var TransitionInputModel = defineSchemaModel({
|
|
71
|
-
name: "TransitionInput",
|
|
72
|
-
description: "Input for transitioning a workflow",
|
|
73
|
-
fields: {
|
|
74
|
-
instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
75
|
-
action: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
76
|
-
data: { type: ScalarTypeEnum.JSON(), isOptional: true },
|
|
77
|
-
comment: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
var TransitionResultModel = defineSchemaModel({
|
|
81
|
-
name: "TransitionResult",
|
|
82
|
-
description: "Result of a workflow transition",
|
|
83
|
-
fields: {
|
|
84
|
-
success: { type: ScalarTypeEnum.Boolean(), isOptional: false },
|
|
85
|
-
instance: { type: WorkflowInstanceModel, isOptional: false },
|
|
86
|
-
previousStepKey: {
|
|
87
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
88
|
-
isOptional: true
|
|
89
|
-
},
|
|
90
|
-
currentStepKey: {
|
|
91
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
92
|
-
isOptional: true
|
|
93
|
-
},
|
|
94
|
-
message: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
export {
|
|
98
|
-
WorkflowInstanceModel,
|
|
99
|
-
TransitionResultModel,
|
|
100
|
-
TransitionInputModel,
|
|
101
|
-
StartWorkflowInputModel
|
|
102
|
-
};
|
|
2
|
+
import{defineEnum as v}from"@contractspec/lib.schema";var q=v("InstanceStatus",["PENDING","RUNNING","WAITING","PAUSED","COMPLETED","CANCELLED","FAILED","TIMEOUT"]);import{defineSchemaModel as j,ScalarTypeEnum as g}from"@contractspec/lib.schema";var x=j({name:"WorkflowInstanceModel",description:"A running workflow instance",fields:{id:{type:g.String_unsecure(),isOptional:!1},workflowDefinitionId:{type:g.String_unsecure(),isOptional:!1},referenceId:{type:g.String_unsecure(),isOptional:!0},referenceType:{type:g.String_unsecure(),isOptional:!0},status:{type:q,isOptional:!1},currentStepId:{type:g.String_unsecure(),isOptional:!0},contextData:{type:g.JSON(),isOptional:!0},triggeredBy:{type:g.String_unsecure(),isOptional:!1},organizationId:{type:g.String_unsecure(),isOptional:!1},priority:{type:g.Int_unsecure(),isOptional:!1},dueAt:{type:g.DateTime(),isOptional:!0},outcome:{type:g.String_unsecure(),isOptional:!0},resultData:{type:g.JSON(),isOptional:!0},errorMessage:{type:g.String_unsecure(),isOptional:!0},createdAt:{type:g.DateTime(),isOptional:!1},startedAt:{type:g.DateTime(),isOptional:!0},completedAt:{type:g.DateTime(),isOptional:!0}}}),D=j({name:"StartWorkflowInput",description:"Input for starting a workflow",fields:{workflowKey:{type:g.NonEmptyString(),isOptional:!1},contextData:{type:g.JSON(),isOptional:!0},referenceId:{type:g.String_unsecure(),isOptional:!0},referenceType:{type:g.String_unsecure(),isOptional:!0},priority:{type:g.Int_unsecure(),isOptional:!0},dueAt:{type:g.DateTime(),isOptional:!0}}}),F=j({name:"TransitionInput",description:"Input for transitioning a workflow",fields:{instanceId:{type:g.String_unsecure(),isOptional:!1},action:{type:g.NonEmptyString(),isOptional:!1},data:{type:g.JSON(),isOptional:!0},comment:{type:g.String_unsecure(),isOptional:!0}}}),G=j({name:"TransitionResult",description:"Result of a workflow transition",fields:{success:{type:g.Boolean(),isOptional:!1},instance:{type:x,isOptional:!1},previousStepKey:{type:g.String_unsecure(),isOptional:!0},currentStepKey:{type:g.String_unsecure(),isOptional:!0},message:{type:g.String_unsecure(),isOptional:!0}}});export{x as WorkflowInstanceModel,G as TransitionResultModel,F as TransitionInputModel,D as StartWorkflowInputModel};
|