@contractspec/example.workflow-system 1.57.0 → 1.58.0
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.d.ts +2 -7
- package/dist/approval/approval.enum.d.ts.map +1 -1
- package/dist/approval/approval.enum.js +20 -26
- package/dist/approval/approval.event.d.ts +108 -114
- package/dist/approval/approval.event.d.ts.map +1 -1
- package/dist/approval/approval.event.js +103 -210
- package/dist/approval/approval.handler.d.ts +17 -18
- package/dist/approval/approval.handler.d.ts.map +1 -1
- package/dist/approval/approval.operations.d.ts +429 -435
- package/dist/approval/approval.operations.d.ts.map +1 -1
- package/dist/approval/approval.operations.js +364 -339
- package/dist/approval/approval.schema.d.ts +86 -91
- package/dist/approval/approval.schema.d.ts.map +1 -1
- package/dist/approval/approval.schema.js +71 -107
- package/dist/approval/index.d.ts +8 -5
- package/dist/approval/index.d.ts.map +1 -0
- package/dist/approval/index.js +484 -5
- package/dist/browser/approval/approval.enum.js +22 -0
- package/dist/browser/approval/approval.event.js +112 -0
- package/dist/browser/approval/approval.operations.js +369 -0
- package/dist/browser/approval/approval.schema.js +73 -0
- package/dist/browser/approval/index.js +484 -0
- package/dist/browser/docs/index.js +103 -0
- package/dist/browser/docs/workflow-system.docblock.js +103 -0
- package/dist/browser/entities/approval.js +119 -0
- package/dist/browser/entities/index.js +508 -0
- package/dist/browser/entities/instance.js +161 -0
- package/dist/browser/entities/step.js +124 -0
- package/dist/browser/entities/workflow.js +82 -0
- package/dist/browser/example.js +42 -0
- package/dist/browser/handlers/index.js +253 -0
- package/dist/browser/handlers/workflow.handlers.js +253 -0
- package/dist/browser/index.js +3120 -0
- package/dist/browser/instance/index.js +677 -0
- package/dist/browser/instance/instance.enum.js +15 -0
- package/dist/browser/instance/instance.event.js +164 -0
- package/dist/browser/instance/instance.handler.js +356 -0
- package/dist/browser/instance/instance.operations.js +9 -0
- package/dist/browser/instance/instance.schema.js +101 -0
- package/dist/browser/presentations/index.js +109 -0
- package/dist/browser/seeders/index.js +3 -0
- package/dist/browser/shared/index.js +3 -0
- package/dist/browser/shared/mock-data.js +11 -0
- package/dist/browser/shared/types.js +0 -0
- package/dist/browser/state-machine/index.js +6 -0
- package/dist/browser/tests/operations.test-spec.js +6 -0
- package/dist/browser/ui/WorkflowDashboard.js +3 -0
- package/dist/browser/ui/hooks/index.js +50 -0
- package/dist/browser/ui/hooks/useWorkflowList.js +50 -0
- package/dist/browser/ui/index.js +54 -0
- package/dist/browser/ui/renderers/index.js +227 -0
- package/dist/browser/ui/renderers/workflow.markdown.js +227 -0
- package/dist/browser/workflow/index.js +21 -0
- package/dist/browser/workflow/workflow.enum.js +36 -0
- package/dist/browser/workflow/workflow.event.js +6 -0
- package/dist/browser/workflow/workflow.handler.js +5 -0
- package/dist/browser/workflow/workflow.operations.js +8 -0
- package/dist/browser/workflow/workflow.schema.js +151 -0
- package/dist/browser/workflow-system.capability.js +5 -0
- package/dist/browser/workflow-system.feature.js +3 -0
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +104 -1
- package/dist/docs/workflow-system.docblock.d.ts +2 -1
- package/dist/docs/workflow-system.docblock.d.ts.map +1 -0
- package/dist/docs/workflow-system.docblock.js +45 -56
- package/dist/entities/approval.d.ts +35 -40
- package/dist/entities/approval.d.ts.map +1 -1
- package/dist/entities/approval.js +116 -124
- package/dist/entities/index.d.ts +132 -137
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/index.js +506 -29
- package/dist/entities/instance.d.ts +46 -51
- package/dist/entities/instance.d.ts.map +1 -1
- package/dist/entities/instance.js +158 -164
- package/dist/entities/step.d.ts +31 -36
- package/dist/entities/step.d.ts.map +1 -1
- package/dist/entities/step.js +122 -132
- package/dist/entities/workflow.d.ts +22 -27
- package/dist/entities/workflow.d.ts.map +1 -1
- package/dist/entities/workflow.js +80 -99
- package/dist/example.d.ts +2 -6
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +41 -55
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +254 -3
- package/dist/handlers/workflow.handlers.d.ts +107 -106
- package/dist/handlers/workflow.handlers.d.ts.map +1 -1
- package/dist/handlers/workflow.handlers.js +237 -246
- package/dist/index.d.ts +15 -26
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3121 -26
- package/dist/instance/index.d.ts +8 -5
- package/dist/instance/index.d.ts.map +1 -0
- package/dist/instance/index.js +677 -5
- package/dist/instance/instance.enum.d.ts +1 -6
- package/dist/instance/instance.enum.d.ts.map +1 -1
- package/dist/instance/instance.enum.js +14 -18
- package/dist/instance/instance.event.d.ts +313 -319
- package/dist/instance/instance.event.d.ts.map +1 -1
- package/dist/instance/instance.event.js +151 -279
- package/dist/instance/instance.handler.d.ts +21 -22
- package/dist/instance/instance.handler.d.ts.map +1 -1
- package/dist/instance/instance.handler.js +352 -89
- package/dist/instance/instance.operations.d.ts +819 -825
- package/dist/instance/instance.operations.d.ts.map +1 -1
- package/dist/instance/instance.operations.js +10 -464
- package/dist/instance/instance.schema.d.ts +196 -201
- package/dist/instance/instance.schema.d.ts.map +1 -1
- package/dist/instance/instance.schema.js +97 -167
- package/dist/presentations/index.d.ts +23 -28
- package/dist/presentations/index.d.ts.map +1 -1
- package/dist/presentations/index.js +104 -334
- package/dist/seeders/index.d.ts +4 -8
- package/dist/seeders/index.d.ts.map +1 -1
- package/dist/seeders/index.js +4 -19
- package/dist/shared/index.d.ts +6 -3
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +4 -3
- package/dist/shared/mock-data.d.ts +16 -16
- package/dist/shared/mock-data.d.ts.map +1 -1
- package/dist/shared/mock-data.js +11 -11
- package/dist/shared/types.d.ts +69 -72
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/shared/types.js +1 -0
- package/dist/state-machine/index.d.ts +92 -95
- package/dist/state-machine/index.d.ts.map +1 -1
- package/dist/state-machine/index.js +6 -157
- package/dist/tests/operations.test-spec.d.ts +4 -9
- package/dist/tests/operations.test-spec.d.ts.map +1 -1
- package/dist/tests/operations.test-spec.js +7 -123
- package/dist/ui/WorkflowDashboard.d.ts +1 -6
- package/dist/ui/WorkflowDashboard.d.ts.map +1 -1
- package/dist/ui/WorkflowDashboard.js +3 -222
- package/dist/ui/hooks/index.d.ts +2 -2
- package/dist/ui/hooks/index.d.ts.map +1 -0
- package/dist/ui/hooks/index.js +51 -5
- package/dist/ui/hooks/useWorkflowList.d.ts +15 -19
- package/dist/ui/hooks/useWorkflowList.d.ts.map +1 -1
- package/dist/ui/hooks/useWorkflowList.js +47 -51
- package/dist/ui/index.d.ts +7 -6
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +55 -6
- package/dist/ui/renderers/index.d.ts +2 -2
- package/dist/ui/renderers/index.d.ts.map +1 -0
- package/dist/ui/renderers/index.js +227 -2
- package/dist/ui/renderers/workflow.markdown.d.ts +13 -14
- package/dist/ui/renderers/workflow.markdown.d.ts.map +1 -1
- package/dist/ui/renderers/workflow.markdown.js +223 -229
- package/dist/workflow/index.d.ts +8 -5
- package/dist/workflow/index.d.ts.map +1 -0
- package/dist/workflow/index.js +22 -6
- package/dist/workflow/workflow.enum.d.ts +4 -9
- package/dist/workflow/workflow.enum.d.ts.map +1 -1
- package/dist/workflow/workflow.enum.js +32 -42
- package/dist/workflow/workflow.event.d.ts +112 -118
- package/dist/workflow/workflow.event.d.ts.map +1 -1
- package/dist/workflow/workflow.event.js +7 -150
- package/dist/workflow/workflow.handler.d.ts +23 -24
- package/dist/workflow/workflow.handler.d.ts.map +1 -1
- package/dist/workflow/workflow.handler.js +6 -66
- package/dist/workflow/workflow.operations.d.ts +847 -853
- package/dist/workflow/workflow.operations.d.ts.map +1 -1
- package/dist/workflow/workflow.operations.js +9 -345
- package/dist/workflow/workflow.schema.d.ts +229 -234
- package/dist/workflow/workflow.schema.d.ts.map +1 -1
- package/dist/workflow/workflow.schema.js +146 -243
- package/dist/workflow-system.capability.d.ts +3 -8
- package/dist/workflow-system.capability.d.ts.map +1 -1
- package/dist/workflow-system.capability.js +6 -34
- package/dist/workflow-system.feature.d.ts +1 -6
- package/dist/workflow-system.feature.d.ts.map +1 -1
- package/dist/workflow-system.feature.js +4 -346
- package/package.json +415 -93
- package/dist/approval/approval.enum.js.map +0 -1
- package/dist/approval/approval.event.js.map +0 -1
- package/dist/approval/approval.handler.js +0 -72
- package/dist/approval/approval.handler.js.map +0 -1
- package/dist/approval/approval.operations.js.map +0 -1
- package/dist/approval/approval.schema.js.map +0 -1
- package/dist/docs/workflow-system.docblock.js.map +0 -1
- package/dist/entities/approval.js.map +0 -1
- package/dist/entities/index.js.map +0 -1
- package/dist/entities/instance.js.map +0 -1
- package/dist/entities/step.js.map +0 -1
- package/dist/entities/workflow.js.map +0 -1
- package/dist/example.js.map +0 -1
- package/dist/handlers/workflow.handlers.js.map +0 -1
- package/dist/instance/instance.enum.js.map +0 -1
- package/dist/instance/instance.event.js.map +0 -1
- package/dist/instance/instance.handler.js.map +0 -1
- package/dist/instance/instance.operations.js.map +0 -1
- package/dist/instance/instance.schema.js.map +0 -1
- package/dist/presentations/index.js.map +0 -1
- package/dist/seeders/index.js.map +0 -1
- package/dist/shared/mock-data.js.map +0 -1
- package/dist/state-machine/index.js.map +0 -1
- package/dist/tests/operations.test-spec.js.map +0 -1
- package/dist/ui/WorkflowDashboard.js.map +0 -1
- package/dist/ui/hooks/useWorkflowList.js.map +0 -1
- package/dist/ui/renderers/workflow.markdown.js.map +0 -1
- package/dist/workflow/workflow.enum.js.map +0 -1
- package/dist/workflow/workflow.event.js.map +0 -1
- package/dist/workflow/workflow.handler.js.map +0 -1
- package/dist/workflow/workflow.operations.js.map +0 -1
- package/dist/workflow/workflow.schema.js.map +0 -1
- package/dist/workflow-system.capability.js.map +0 -1
- package/dist/workflow-system.feature.js.map +0 -1
package/dist/shared/types.d.ts
CHANGED
|
@@ -1,81 +1,78 @@
|
|
|
1
|
-
//#region src/shared/types.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Shared types for workflow system handlers.
|
|
4
3
|
*/
|
|
5
|
-
interface WorkflowDefinitionRecord {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
export interface WorkflowDefinitionRecord {
|
|
5
|
+
id: string;
|
|
6
|
+
key: string;
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
version: string;
|
|
10
|
+
status: 'DRAFT' | 'ACTIVE' | 'DEPRECATED' | 'ARCHIVED';
|
|
11
|
+
triggerType: 'MANUAL' | 'EVENT' | 'SCHEDULED' | 'API';
|
|
12
|
+
initialStepId?: string;
|
|
13
|
+
featureFlagKey?: string;
|
|
14
|
+
organizationId: string;
|
|
15
|
+
createdBy: string;
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
updatedAt: Date;
|
|
18
|
+
publishedAt?: Date;
|
|
20
19
|
}
|
|
21
|
-
interface WorkflowStepRecord {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
export interface WorkflowStepRecord {
|
|
21
|
+
id: string;
|
|
22
|
+
workflowDefinitionId: string;
|
|
23
|
+
key: string;
|
|
24
|
+
name: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
type: 'START' | 'APPROVAL' | 'TASK' | 'CONDITION' | 'PARALLEL' | 'WAIT' | 'ACTION' | 'END';
|
|
27
|
+
position: number;
|
|
28
|
+
transitions: Record<string, string>;
|
|
29
|
+
approvalMode?: 'ANY' | 'ALL' | 'MAJORITY' | 'SEQUENTIAL';
|
|
30
|
+
approverRoles: string[];
|
|
31
|
+
timeoutSeconds?: number;
|
|
32
|
+
createdAt: Date;
|
|
33
|
+
updatedAt: Date;
|
|
35
34
|
}
|
|
36
|
-
interface WorkflowInstanceRecord {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
export interface WorkflowInstanceRecord {
|
|
36
|
+
id: string;
|
|
37
|
+
workflowDefinitionId: string;
|
|
38
|
+
referenceId?: string;
|
|
39
|
+
referenceType?: string;
|
|
40
|
+
status: 'PENDING' | 'RUNNING' | 'WAITING' | 'PAUSED' | 'COMPLETED' | 'CANCELLED' | 'FAILED' | 'TIMEOUT';
|
|
41
|
+
currentStepId?: string;
|
|
42
|
+
contextData: Record<string, unknown>;
|
|
43
|
+
triggeredBy: string;
|
|
44
|
+
organizationId: string;
|
|
45
|
+
priority: number;
|
|
46
|
+
dueAt?: Date;
|
|
47
|
+
outcome?: string;
|
|
48
|
+
resultData?: Record<string, unknown>;
|
|
49
|
+
errorMessage?: string;
|
|
50
|
+
createdAt: Date;
|
|
51
|
+
updatedAt: Date;
|
|
52
|
+
startedAt?: Date;
|
|
53
|
+
completedAt?: Date;
|
|
55
54
|
}
|
|
56
|
-
interface ApprovalRequestRecord {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
55
|
+
export interface ApprovalRequestRecord {
|
|
56
|
+
id: string;
|
|
57
|
+
workflowInstanceId: string;
|
|
58
|
+
stepExecutionId: string;
|
|
59
|
+
approverId: string;
|
|
60
|
+
approverRole?: string;
|
|
61
|
+
title: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
status: 'PENDING' | 'APPROVED' | 'REJECTED' | 'DELEGATED' | 'ESCALATED' | 'WITHDRAWN' | 'EXPIRED';
|
|
64
|
+
decision?: 'APPROVE' | 'REJECT' | 'REQUEST_CHANGES' | 'DELEGATE' | 'ABSTAIN';
|
|
65
|
+
decisionComment?: string;
|
|
66
|
+
decidedAt?: Date;
|
|
67
|
+
dueAt?: Date;
|
|
68
|
+
contextSnapshot?: Record<string, unknown>;
|
|
69
|
+
sequenceOrder: number;
|
|
70
|
+
createdAt: Date;
|
|
71
|
+
updatedAt: Date;
|
|
73
72
|
}
|
|
74
|
-
interface HandlerContext {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
export interface HandlerContext {
|
|
74
|
+
userId: string;
|
|
75
|
+
userRoles: string[];
|
|
76
|
+
organizationId: string;
|
|
78
77
|
}
|
|
79
|
-
//#endregion
|
|
80
|
-
export { ApprovalRequestRecord, HandlerContext, WorkflowDefinitionRecord, WorkflowInstanceRecord, WorkflowStepRecord };
|
|
81
78
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,GAAG,QAAQ,GAAG,YAAY,GAAG,UAAU,CAAC;IACvD,WAAW,EAAE,QAAQ,GAAG,OAAO,GAAG,WAAW,GAAG,KAAK,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 @@
|
|
|
1
|
+
// @bun
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/state-machine/index.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Workflow State Machine Engine
|
|
4
3
|
*
|
|
@@ -9,140 +8,138 @@
|
|
|
9
8
|
/**
|
|
10
9
|
* Represents a transition definition in a workflow step.
|
|
11
10
|
*/
|
|
12
|
-
interface TransitionDefinition {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
export interface TransitionDefinition {
|
|
12
|
+
/** The action that triggers this transition (e.g., "approve", "reject") */
|
|
13
|
+
action: string;
|
|
14
|
+
/** The target step key to transition to */
|
|
15
|
+
targetStepKey: string;
|
|
16
|
+
/** Optional condition expression for conditional transitions */
|
|
17
|
+
condition?: string;
|
|
18
|
+
/** Optional guard roles - only users with these roles can take this action */
|
|
19
|
+
allowedRoles?: string[];
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
22
|
* Step definition for state machine.
|
|
24
23
|
*/
|
|
25
|
-
interface StateMachineStep {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
export interface StateMachineStep {
|
|
25
|
+
key: string;
|
|
26
|
+
name: string;
|
|
27
|
+
type: 'START' | 'APPROVAL' | 'TASK' | 'CONDITION' | 'PARALLEL' | 'WAIT' | 'ACTION' | 'END';
|
|
28
|
+
/** Map of action -> transition definition */
|
|
29
|
+
transitions: Record<string, string | TransitionDefinition>;
|
|
30
|
+
/** For approval steps: how approvals are handled */
|
|
31
|
+
approvalMode?: 'ANY' | 'ALL' | 'MAJORITY' | 'SEQUENTIAL';
|
|
32
|
+
/** Roles that can approve/act on this step */
|
|
33
|
+
allowedRoles?: string[];
|
|
34
|
+
/** Timeout in seconds */
|
|
35
|
+
timeoutSeconds?: number;
|
|
36
|
+
/** Condition expression for CONDITION type */
|
|
37
|
+
conditionExpression?: string;
|
|
39
38
|
}
|
|
40
39
|
/**
|
|
41
40
|
* Workflow state machine definition.
|
|
42
41
|
*/
|
|
43
|
-
interface StateMachineDefinition {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
export interface StateMachineDefinition {
|
|
43
|
+
key: string;
|
|
44
|
+
name: string;
|
|
45
|
+
version: string;
|
|
46
|
+
initialStepKey: string;
|
|
47
|
+
steps: Record<string, StateMachineStep>;
|
|
49
48
|
}
|
|
50
49
|
/**
|
|
51
50
|
* Current state of an instance.
|
|
52
51
|
*/
|
|
53
|
-
interface StateMachineState {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
export interface StateMachineState {
|
|
53
|
+
currentStepKey: string;
|
|
54
|
+
status: 'PENDING' | 'RUNNING' | 'WAITING' | 'PAUSED' | 'COMPLETED' | 'CANCELLED' | 'FAILED' | 'TIMEOUT';
|
|
55
|
+
contextData: Record<string, unknown>;
|
|
56
|
+
history: {
|
|
57
|
+
stepKey: string;
|
|
58
|
+
action: string;
|
|
59
|
+
timestamp: Date;
|
|
60
|
+
executedBy: string;
|
|
61
|
+
}[];
|
|
63
62
|
}
|
|
64
63
|
/**
|
|
65
64
|
* Result of a transition attempt.
|
|
66
65
|
*/
|
|
67
|
-
interface TransitionResult {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
export interface TransitionResult {
|
|
67
|
+
success: boolean;
|
|
68
|
+
previousStepKey: string;
|
|
69
|
+
currentStepKey: string | null;
|
|
70
|
+
status: StateMachineState['status'];
|
|
71
|
+
error?: string;
|
|
73
72
|
}
|
|
74
73
|
/**
|
|
75
74
|
* Context for transition validation.
|
|
76
75
|
*/
|
|
77
|
-
interface TransitionContext {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
export interface TransitionContext {
|
|
77
|
+
userId: string;
|
|
78
|
+
userRoles: string[];
|
|
79
|
+
data?: Record<string, unknown>;
|
|
81
80
|
}
|
|
82
81
|
/**
|
|
83
82
|
* State machine engine interface.
|
|
84
83
|
* Implementation should be provided at runtime.
|
|
85
84
|
*/
|
|
86
|
-
interface IStateMachineEngine {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
85
|
+
export interface IStateMachineEngine {
|
|
86
|
+
/**
|
|
87
|
+
* Validate that a transition is allowed.
|
|
88
|
+
*/
|
|
89
|
+
canTransition(definition: StateMachineDefinition, state: StateMachineState, action: string, context: TransitionContext): {
|
|
90
|
+
allowed: boolean;
|
|
91
|
+
reason?: string;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Get available actions for the current step.
|
|
95
|
+
*/
|
|
96
|
+
getAvailableActions(definition: StateMachineDefinition, state: StateMachineState, context: TransitionContext): string[];
|
|
97
|
+
/**
|
|
98
|
+
* Execute a transition.
|
|
99
|
+
*/
|
|
100
|
+
transition(definition: StateMachineDefinition, state: StateMachineState, action: string, context: TransitionContext): TransitionResult;
|
|
101
|
+
/**
|
|
102
|
+
* Evaluate a condition expression.
|
|
103
|
+
*/
|
|
104
|
+
evaluateCondition(expression: string, contextData: Record<string, unknown>): boolean;
|
|
106
105
|
}
|
|
107
106
|
/**
|
|
108
107
|
* Basic state machine engine implementation.
|
|
109
108
|
* This is a reference implementation for spec validation.
|
|
110
109
|
*/
|
|
111
|
-
declare class BasicStateMachineEngine implements IStateMachineEngine {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
110
|
+
export declare class BasicStateMachineEngine implements IStateMachineEngine {
|
|
111
|
+
canTransition(definition: StateMachineDefinition, state: StateMachineState, action: string, context: TransitionContext): {
|
|
112
|
+
allowed: boolean;
|
|
113
|
+
reason?: string;
|
|
114
|
+
};
|
|
115
|
+
getAvailableActions(definition: StateMachineDefinition, state: StateMachineState, context: TransitionContext): string[];
|
|
116
|
+
transition(definition: StateMachineDefinition, state: StateMachineState, action: string, context: TransitionContext): TransitionResult;
|
|
117
|
+
evaluateCondition(expression: string, contextData: Record<string, unknown>): boolean;
|
|
119
118
|
}
|
|
120
119
|
/**
|
|
121
120
|
* Create a new state machine engine instance.
|
|
122
121
|
*/
|
|
123
|
-
declare function createStateMachineEngine(): IStateMachineEngine;
|
|
122
|
+
export declare function createStateMachineEngine(): IStateMachineEngine;
|
|
124
123
|
/**
|
|
125
124
|
* Build a state machine definition from workflow entities.
|
|
126
125
|
*/
|
|
127
|
-
declare function buildStateMachineDefinition(workflow: {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
126
|
+
export declare function buildStateMachineDefinition(workflow: {
|
|
127
|
+
key: string;
|
|
128
|
+
name: string;
|
|
129
|
+
version: string;
|
|
130
|
+
initialStepId: string | null;
|
|
132
131
|
}, steps: {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
132
|
+
key: string;
|
|
133
|
+
name: string;
|
|
134
|
+
type: string;
|
|
135
|
+
transitions: Record<string, string | TransitionDefinition>;
|
|
136
|
+
approvalMode?: string;
|
|
137
|
+
approverRoles?: string[];
|
|
138
|
+
timeoutSeconds?: number;
|
|
139
|
+
conditionExpression?: string;
|
|
141
140
|
}[]): StateMachineDefinition;
|
|
142
141
|
/**
|
|
143
142
|
* Create initial state for a new workflow instance.
|
|
144
143
|
*/
|
|
145
|
-
declare function createInitialState(definition: StateMachineDefinition, contextData?: Record<string, unknown>): StateMachineState;
|
|
146
|
-
//#endregion
|
|
147
|
-
export { BasicStateMachineEngine, IStateMachineEngine, StateMachineDefinition, StateMachineState, StateMachineStep, TransitionContext, TransitionDefinition, TransitionResult, buildStateMachineDefinition, createInitialState, createStateMachineEngine };
|
|
144
|
+
export declare function createInitialState(definition: StateMachineDefinition, contextData?: Record<string, unknown>): StateMachineState;
|
|
148
145
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/state-machine/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EACA,OAAO,GACP,UAAU,GACV,MAAM,GACN,WAAW,GACX,UAAU,GACV,MAAM,GACN,QAAQ,GACR,KAAK,CAAC;IACV,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAAC,CAAC;IAC3D,oDAAoD;IACpD,YAAY,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,UAAU,GAAG,YAAY,CAAC;IACzD,8CAA8C;IAC9C,YAAY,CAAC,EAAE,MAAM,EAAE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AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE;IACR,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,EACD,KAAK,EAAE;IACL,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAAC,CAAC;IAC3D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,EAAE,GACF,sBAAsB,CA2BxB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,sBAAsB,EAClC,WAAW,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACxC,iBAAiB,CAOnB"}
|
|
@@ -1,158 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
canTransition(definition, state, action, context) {
|
|
8
|
-
if (state.status !== "RUNNING" && state.status !== "WAITING") return {
|
|
9
|
-
allowed: false,
|
|
10
|
-
reason: `Workflow is ${state.status}, cannot transition`
|
|
11
|
-
};
|
|
12
|
-
const currentStep = definition.steps[state.currentStepKey];
|
|
13
|
-
if (!currentStep) return {
|
|
14
|
-
allowed: false,
|
|
15
|
-
reason: `Step ${state.currentStepKey} not found`
|
|
16
|
-
};
|
|
17
|
-
const transition = currentStep.transitions[action];
|
|
18
|
-
if (!transition) return {
|
|
19
|
-
allowed: false,
|
|
20
|
-
reason: `Action ${action} not available in step ${state.currentStepKey}`
|
|
21
|
-
};
|
|
22
|
-
if (currentStep.allowedRoles && currentStep.allowedRoles.length > 0) {
|
|
23
|
-
if (!currentStep.allowedRoles.some((role) => context.userRoles.includes(role))) return {
|
|
24
|
-
allowed: false,
|
|
25
|
-
reason: `User lacks required role for this action`
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
if (typeof transition === "object" && transition.allowedRoles && transition.allowedRoles.length > 0) {
|
|
29
|
-
if (!transition.allowedRoles.some((role) => context.userRoles.includes(role))) return {
|
|
30
|
-
allowed: false,
|
|
31
|
-
reason: `User lacks required role for action ${action}`
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return { allowed: true };
|
|
35
|
-
}
|
|
36
|
-
getAvailableActions(definition, state, context) {
|
|
37
|
-
if (state.status !== "RUNNING" && state.status !== "WAITING") return [];
|
|
38
|
-
const currentStep = definition.steps[state.currentStepKey];
|
|
39
|
-
if (!currentStep) return [];
|
|
40
|
-
return Object.keys(currentStep.transitions).filter((action) => {
|
|
41
|
-
return this.canTransition(definition, state, action, context).allowed;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
transition(definition, state, action, context) {
|
|
45
|
-
const validation = this.canTransition(definition, state, action, context);
|
|
46
|
-
if (!validation.allowed) return {
|
|
47
|
-
success: false,
|
|
48
|
-
previousStepKey: state.currentStepKey,
|
|
49
|
-
currentStepKey: state.currentStepKey,
|
|
50
|
-
status: state.status,
|
|
51
|
-
error: validation.reason
|
|
52
|
-
};
|
|
53
|
-
const currentStep = definition.steps[state.currentStepKey];
|
|
54
|
-
if (!currentStep) return {
|
|
55
|
-
success: false,
|
|
56
|
-
previousStepKey: state.currentStepKey,
|
|
57
|
-
currentStepKey: state.currentStepKey,
|
|
58
|
-
status: state.status,
|
|
59
|
-
error: `Current step ${state.currentStepKey} not found`
|
|
60
|
-
};
|
|
61
|
-
const transition = currentStep.transitions[action];
|
|
62
|
-
if (!transition) return {
|
|
63
|
-
success: false,
|
|
64
|
-
previousStepKey: state.currentStepKey,
|
|
65
|
-
currentStepKey: state.currentStepKey,
|
|
66
|
-
status: state.status,
|
|
67
|
-
error: `Transition for action ${action} not found`
|
|
68
|
-
};
|
|
69
|
-
const targetStepKey = typeof transition === "string" ? transition : transition.targetStepKey;
|
|
70
|
-
const targetStep = definition.steps[targetStepKey];
|
|
71
|
-
if (!targetStep) return {
|
|
72
|
-
success: false,
|
|
73
|
-
previousStepKey: state.currentStepKey,
|
|
74
|
-
currentStepKey: state.currentStepKey,
|
|
75
|
-
status: state.status,
|
|
76
|
-
error: `Target step ${targetStepKey} not found`
|
|
77
|
-
};
|
|
78
|
-
let newStatus = "RUNNING";
|
|
79
|
-
if (targetStep.type === "END") newStatus = "COMPLETED";
|
|
80
|
-
else if (targetStep.type === "APPROVAL" || targetStep.type === "WAIT") newStatus = "WAITING";
|
|
81
|
-
return {
|
|
82
|
-
success: true,
|
|
83
|
-
previousStepKey: state.currentStepKey,
|
|
84
|
-
currentStepKey: targetStepKey,
|
|
85
|
-
status: newStatus
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
evaluateCondition(expression, contextData) {
|
|
89
|
-
try {
|
|
90
|
-
const match = expression.match(/^(\w+)\s*(>=|<=|>|<|===|!==|==|!=)\s*(.+)$/);
|
|
91
|
-
if (match) {
|
|
92
|
-
const [, prop, operator, value] = match;
|
|
93
|
-
if (!prop || !operator || value === void 0) return false;
|
|
94
|
-
const propValue = contextData[prop];
|
|
95
|
-
const compareValue = JSON.parse(value);
|
|
96
|
-
switch (operator) {
|
|
97
|
-
case ">": return Number(propValue) > Number(compareValue);
|
|
98
|
-
case "<": return Number(propValue) < Number(compareValue);
|
|
99
|
-
case ">=": return Number(propValue) >= Number(compareValue);
|
|
100
|
-
case "<=": return Number(propValue) <= Number(compareValue);
|
|
101
|
-
case "===":
|
|
102
|
-
case "==": return propValue === compareValue;
|
|
103
|
-
case "!==":
|
|
104
|
-
case "!=": return propValue !== compareValue;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (expression in contextData) return Boolean(contextData[expression]);
|
|
108
|
-
return false;
|
|
109
|
-
} catch {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
1
|
+
// @bun
|
|
2
|
+
export {
|
|
3
|
+
createStateMachineEngine,
|
|
4
|
+
createInitialState,
|
|
5
|
+
buildStateMachineDefinition,
|
|
6
|
+
BasicStateMachineEngine
|
|
113
7
|
};
|
|
114
|
-
/**
|
|
115
|
-
* Create a new state machine engine instance.
|
|
116
|
-
*/
|
|
117
|
-
function createStateMachineEngine() {
|
|
118
|
-
return new BasicStateMachineEngine();
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Build a state machine definition from workflow entities.
|
|
122
|
-
*/
|
|
123
|
-
function buildStateMachineDefinition(workflow, steps) {
|
|
124
|
-
const stepMap = {};
|
|
125
|
-
for (const step of steps) stepMap[step.key] = {
|
|
126
|
-
key: step.key,
|
|
127
|
-
name: step.name,
|
|
128
|
-
type: step.type,
|
|
129
|
-
transitions: step.transitions,
|
|
130
|
-
approvalMode: step.approvalMode,
|
|
131
|
-
allowedRoles: step.approverRoles,
|
|
132
|
-
timeoutSeconds: step.timeoutSeconds,
|
|
133
|
-
conditionExpression: step.conditionExpression
|
|
134
|
-
};
|
|
135
|
-
const initialStepKey = steps.find((s) => s.type === "START")?.key ?? steps[0]?.key ?? "";
|
|
136
|
-
return {
|
|
137
|
-
key: workflow.key,
|
|
138
|
-
name: workflow.name,
|
|
139
|
-
version: workflow.version,
|
|
140
|
-
initialStepKey,
|
|
141
|
-
steps: stepMap
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Create initial state for a new workflow instance.
|
|
146
|
-
*/
|
|
147
|
-
function createInitialState(definition, contextData = {}) {
|
|
148
|
-
return {
|
|
149
|
-
currentStepKey: definition.initialStepKey,
|
|
150
|
-
status: "RUNNING",
|
|
151
|
-
contextData,
|
|
152
|
-
history: []
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
//#endregion
|
|
157
|
-
export { BasicStateMachineEngine, buildStateMachineDefinition, createInitialState, createStateMachineEngine };
|
|
158
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const
|
|
5
|
-
declare const InstanceListTest: _contractspec_lib_contracts0.TestSpec;
|
|
6
|
-
declare const ApprovalListMineTest: _contractspec_lib_contracts0.TestSpec;
|
|
7
|
-
declare const ApprovalDecideTest: _contractspec_lib_contracts0.TestSpec;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { ApprovalDecideTest, ApprovalListMineTest, DefinitionListTest, InstanceListTest };
|
|
1
|
+
export declare const DefinitionListTest: import("@contractspec/lib.contracts").TestSpec;
|
|
2
|
+
export declare const InstanceListTest: import("@contractspec/lib.contracts").TestSpec;
|
|
3
|
+
export declare const ApprovalListMineTest: import("@contractspec/lib.contracts").TestSpec;
|
|
4
|
+
export declare const ApprovalDecideTest: import("@contractspec/lib.contracts").TestSpec;
|
|
10
5
|
//# sourceMappingURL=operations.test-spec.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.test-spec.d.ts","
|
|
1
|
+
{"version":3,"file":"operations.test-spec.d.ts","sourceRoot":"","sources":["../../src/tests/operations.test-spec.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,gDAyB7B,CAAC;AAEH,eAAO,MAAM,gBAAgB,gDAyB3B,CAAC;AAEH,eAAO,MAAM,oBAAoB,gDAyB/B,CAAC;AAEH,eAAO,MAAM,kBAAkB,gDAyB7B,CAAC"}
|