@contractspec/example.workflow-system 1.44.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/LICENSE +21 -0
- package/README.md +124 -0
- package/dist/approval/approval.enum.d.ts +14 -0
- package/dist/approval/approval.enum.d.ts.map +1 -0
- package/dist/approval/approval.enum.js +29 -0
- package/dist/approval/approval.enum.js.map +1 -0
- package/dist/approval/approval.event.d.ts +131 -0
- package/dist/approval/approval.event.d.ts.map +1 -0
- package/dist/approval/approval.event.js +220 -0
- package/dist/approval/approval.event.js.map +1 -0
- package/dist/approval/approval.handler.d.ts +23 -0
- package/dist/approval/approval.handler.d.ts.map +1 -0
- package/dist/approval/approval.handler.js +72 -0
- package/dist/approval/approval.handler.js.map +1 -0
- package/dist/approval/approval.operations.d.ts +535 -0
- package/dist/approval/approval.operations.d.ts.map +1 -0
- package/dist/approval/approval.operations.js +345 -0
- package/dist/approval/approval.operations.js.map +1 -0
- package/dist/approval/approval.schema.d.ts +100 -0
- package/dist/approval/approval.schema.d.ts.map +1 -0
- package/dist/approval/approval.schema.js +110 -0
- package/dist/approval/approval.schema.js.map +1 -0
- package/dist/approval/index.d.ts +5 -0
- package/dist/approval/index.js +6 -0
- package/dist/docs/index.d.ts +1 -0
- package/dist/docs/index.js +1 -0
- package/dist/docs/workflow-system.docblock.d.ts +1 -0
- package/dist/docs/workflow-system.docblock.js +115 -0
- package/dist/docs/workflow-system.docblock.js.map +1 -0
- package/dist/entities/approval.d.ts +58 -0
- package/dist/entities/approval.d.ts.map +1 -0
- package/dist/entities/approval.js +128 -0
- package/dist/entities/approval.js.map +1 -0
- package/dist/entities/index.d.ts +139 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +32 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/entities/instance.d.ts +69 -0
- package/dist/entities/instance.d.ts.map +1 -0
- package/dist/entities/instance.js +168 -0
- package/dist/entities/instance.js.map +1 -0
- package/dist/entities/step.d.ts +50 -0
- package/dist/entities/step.d.ts.map +1 -0
- package/dist/entities/step.js +135 -0
- package/dist/entities/step.js.map +1 -0
- package/dist/entities/workflow.d.ts +41 -0
- package/dist/entities/workflow.d.ts.map +1 -0
- package/dist/entities/workflow.js +102 -0
- package/dist/entities/workflow.js.map +1 -0
- package/dist/example.d.ts +40 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +51 -0
- package/dist/example.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -0
- package/dist/instance/index.d.ts +5 -0
- package/dist/instance/index.js +6 -0
- package/dist/instance/instance.enum.d.ts +10 -0
- package/dist/instance/instance.enum.d.ts.map +1 -0
- package/dist/instance/instance.enum.js +20 -0
- package/dist/instance/instance.enum.js.map +1 -0
- package/dist/instance/instance.event.d.ts +356 -0
- package/dist/instance/instance.event.d.ts.map +1 -0
- package/dist/instance/instance.event.js +293 -0
- package/dist/instance/instance.event.js.map +1 -0
- package/dist/instance/instance.handler.d.ts +27 -0
- package/dist/instance/instance.handler.d.ts.map +1 -0
- package/dist/instance/instance.handler.js +94 -0
- package/dist/instance/instance.handler.js.map +1 -0
- package/dist/instance/instance.operations.d.ts +1024 -0
- package/dist/instance/instance.operations.d.ts.map +1 -0
- package/dist/instance/instance.operations.js +464 -0
- package/dist/instance/instance.operations.js.map +1 -0
- package/dist/instance/instance.schema.d.ts +223 -0
- package/dist/instance/instance.schema.d.ts.map +1 -0
- package/dist/instance/instance.schema.js +172 -0
- package/dist/instance/instance.schema.js.map +1 -0
- package/dist/presentations/index.d.ts +64 -0
- package/dist/presentations/index.d.ts.map +1 -0
- package/dist/presentations/index.js +337 -0
- package/dist/presentations/index.js.map +1 -0
- package/dist/shared/index.d.ts +3 -0
- package/dist/shared/index.js +3 -0
- package/dist/shared/mock-data.d.ts +19 -0
- package/dist/shared/mock-data.d.ts.map +1 -0
- package/dist/shared/mock-data.js +12 -0
- package/dist/shared/mock-data.js.map +1 -0
- package/dist/shared/types.d.ts +81 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +0 -0
- package/dist/state-machine/index.d.ts +148 -0
- package/dist/state-machine/index.d.ts.map +1 -0
- package/dist/state-machine/index.js +158 -0
- package/dist/state-machine/index.js.map +1 -0
- package/dist/workflow/index.d.ts +5 -0
- package/dist/workflow/index.js +6 -0
- package/dist/workflow/workflow.enum.d.ts +22 -0
- package/dist/workflow/workflow.enum.d.ts.map +1 -0
- package/dist/workflow/workflow.enum.js +47 -0
- package/dist/workflow/workflow.enum.js.map +1 -0
- package/dist/workflow/workflow.event.d.ts +135 -0
- package/dist/workflow/workflow.event.d.ts.map +1 -0
- package/dist/workflow/workflow.event.js +150 -0
- package/dist/workflow/workflow.event.js.map +1 -0
- package/dist/workflow/workflow.handler.d.ts +29 -0
- package/dist/workflow/workflow.handler.d.ts.map +1 -0
- package/dist/workflow/workflow.handler.js +66 -0
- package/dist/workflow/workflow.handler.js.map +1 -0
- package/dist/workflow/workflow.operations.d.ts +1011 -0
- package/dist/workflow/workflow.operations.d.ts.map +1 -0
- package/dist/workflow/workflow.operations.js +345 -0
- package/dist/workflow/workflow.operations.js.map +1 -0
- package/dist/workflow/workflow.schema.d.ts +265 -0
- package/dist/workflow/workflow.schema.d.ts.map +1 -0
- package/dist/workflow/workflow.schema.js +249 -0
- package/dist/workflow/workflow.schema.js.map +1 -0
- package/dist/workflow-system.feature.d.ts +12 -0
- package/dist/workflow-system.feature.d.ts.map +1 -0
- package/dist/workflow-system.feature.js +339 -0
- package/dist/workflow-system.feature.js.map +1 -0
- package/package.json +124 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
//#region src/state-machine/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Basic state machine engine implementation.
|
|
4
|
+
* This is a reference implementation for spec validation.
|
|
5
|
+
*/
|
|
6
|
+
var BasicStateMachineEngine = class {
|
|
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
|
+
}
|
|
113
|
+
};
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["newStatus: StateMachineState['status']","stepMap: Record<string, StateMachineStep>"],"sources":["../../src/state-machine/index.ts"],"sourcesContent":["/**\n * Workflow State Machine Engine\n *\n * Provides state machine logic for workflow transitions.\n * This is a spec-level abstraction that defines the interface\n * for workflow state transitions.\n */\n\n// ============ Types ============\n\n/**\n * Represents a transition definition in a workflow step.\n */\nexport interface TransitionDefinition {\n /** The action that triggers this transition (e.g., \"approve\", \"reject\") */\n action: string;\n /** The target step key to transition to */\n targetStepKey: string;\n /** Optional condition expression for conditional transitions */\n condition?: string;\n /** Optional guard roles - only users with these roles can take this action */\n allowedRoles?: string[];\n}\n\n/**\n * Step definition for state machine.\n */\nexport interface StateMachineStep {\n key: string;\n name: string;\n type:\n | 'START'\n | 'APPROVAL'\n | 'TASK'\n | 'CONDITION'\n | 'PARALLEL'\n | 'WAIT'\n | 'ACTION'\n | 'END';\n /** Map of action -> transition definition */\n transitions: Record<string, string | TransitionDefinition>;\n /** For approval steps: how approvals are handled */\n approvalMode?: 'ANY' | 'ALL' | 'MAJORITY' | 'SEQUENTIAL';\n /** Roles that can approve/act on this step */\n allowedRoles?: string[];\n /** Timeout in seconds */\n timeoutSeconds?: number;\n /** Condition expression for CONDITION type */\n conditionExpression?: string;\n}\n\n/**\n * Workflow state machine definition.\n */\nexport interface StateMachineDefinition {\n key: string;\n name: string;\n version: number;\n initialStepKey: string;\n steps: Record<string, StateMachineStep>;\n}\n\n/**\n * Current state of an instance.\n */\nexport interface StateMachineState {\n currentStepKey: string;\n status:\n | 'PENDING'\n | 'RUNNING'\n | 'WAITING'\n | 'PAUSED'\n | 'COMPLETED'\n | 'CANCELLED'\n | 'FAILED'\n | 'TIMEOUT';\n contextData: Record<string, unknown>;\n history: {\n stepKey: string;\n action: string;\n timestamp: Date;\n executedBy: string;\n }[];\n}\n\n/**\n * Result of a transition attempt.\n */\nexport interface TransitionResult {\n success: boolean;\n previousStepKey: string;\n currentStepKey: string | null;\n status: StateMachineState['status'];\n error?: string;\n}\n\n/**\n * Context for transition validation.\n */\nexport interface TransitionContext {\n userId: string;\n userRoles: string[];\n data?: Record<string, unknown>;\n}\n\n// ============ State Machine Engine ============\n\n/**\n * State machine engine interface.\n * Implementation should be provided at runtime.\n */\nexport interface IStateMachineEngine {\n /**\n * Validate that a transition is allowed.\n */\n canTransition(\n definition: StateMachineDefinition,\n state: StateMachineState,\n action: string,\n context: TransitionContext\n ): { allowed: boolean; reason?: string };\n\n /**\n * Get available actions for the current step.\n */\n getAvailableActions(\n definition: StateMachineDefinition,\n state: StateMachineState,\n context: TransitionContext\n ): string[];\n\n /**\n * Execute a transition.\n */\n transition(\n definition: StateMachineDefinition,\n state: StateMachineState,\n action: string,\n context: TransitionContext\n ): TransitionResult;\n\n /**\n * Evaluate a condition expression.\n */\n evaluateCondition(\n expression: string,\n contextData: Record<string, unknown>\n ): boolean;\n}\n\n/**\n * Basic state machine engine implementation.\n * This is a reference implementation for spec validation.\n */\nexport class BasicStateMachineEngine implements IStateMachineEngine {\n canTransition(\n definition: StateMachineDefinition,\n state: StateMachineState,\n action: string,\n context: TransitionContext\n ): { allowed: boolean; reason?: string } {\n // Check if state allows transitions\n if (state.status !== 'RUNNING' && state.status !== 'WAITING') {\n return {\n allowed: false,\n reason: `Workflow is ${state.status}, cannot transition`,\n };\n }\n\n const currentStep = definition.steps[state.currentStepKey];\n if (!currentStep) {\n return {\n allowed: false,\n reason: `Step ${state.currentStepKey} not found`,\n };\n }\n\n // Check if action exists for this step\n const transition = currentStep.transitions[action];\n if (!transition) {\n return {\n allowed: false,\n reason: `Action ${action} not available in step ${state.currentStepKey}`,\n };\n }\n\n // Check role-based access\n if (currentStep.allowedRoles && currentStep.allowedRoles.length > 0) {\n const hasRole = currentStep.allowedRoles.some((role) =>\n context.userRoles.includes(role)\n );\n if (!hasRole) {\n return {\n allowed: false,\n reason: `User lacks required role for this action`,\n };\n }\n }\n\n // Check transition-specific roles if defined\n if (\n typeof transition === 'object' &&\n transition.allowedRoles &&\n transition.allowedRoles.length > 0\n ) {\n const hasRole = transition.allowedRoles.some((role) =>\n context.userRoles.includes(role)\n );\n if (!hasRole) {\n return {\n allowed: false,\n reason: `User lacks required role for action ${action}`,\n };\n }\n }\n\n return { allowed: true };\n }\n\n getAvailableActions(\n definition: StateMachineDefinition,\n state: StateMachineState,\n context: TransitionContext\n ): string[] {\n if (state.status !== 'RUNNING' && state.status !== 'WAITING') {\n return [];\n }\n\n const currentStep = definition.steps[state.currentStepKey];\n if (!currentStep) {\n return [];\n }\n\n return Object.keys(currentStep.transitions).filter((action) => {\n const result = this.canTransition(definition, state, action, context);\n return result.allowed;\n });\n }\n\n transition(\n definition: StateMachineDefinition,\n state: StateMachineState,\n action: string,\n context: TransitionContext\n ): TransitionResult {\n const validation = this.canTransition(definition, state, action, context);\n if (!validation.allowed) {\n return {\n success: false,\n previousStepKey: state.currentStepKey,\n currentStepKey: state.currentStepKey,\n status: state.status,\n error: validation.reason,\n };\n }\n\n const currentStep = definition.steps[state.currentStepKey];\n if (!currentStep) {\n return {\n success: false,\n previousStepKey: state.currentStepKey,\n currentStepKey: state.currentStepKey,\n status: state.status,\n error: `Current step ${state.currentStepKey} not found`,\n };\n }\n const transition = currentStep.transitions[action];\n if (!transition) {\n return {\n success: false,\n previousStepKey: state.currentStepKey,\n currentStepKey: state.currentStepKey,\n status: state.status,\n error: `Transition for action ${action} not found`,\n };\n }\n const targetStepKey =\n typeof transition === 'string' ? transition : transition.targetStepKey;\n const targetStep = definition.steps[targetStepKey];\n\n if (!targetStep) {\n return {\n success: false,\n previousStepKey: state.currentStepKey,\n currentStepKey: state.currentStepKey,\n status: state.status,\n error: `Target step ${targetStepKey} not found`,\n };\n }\n\n // Determine new status\n let newStatus: StateMachineState['status'] = 'RUNNING';\n if (targetStep.type === 'END') {\n newStatus = 'COMPLETED';\n } else if (targetStep.type === 'APPROVAL' || targetStep.type === 'WAIT') {\n newStatus = 'WAITING';\n }\n\n return {\n success: true,\n previousStepKey: state.currentStepKey,\n currentStepKey: targetStepKey,\n status: newStatus,\n };\n }\n\n evaluateCondition(\n expression: string,\n contextData: Record<string, unknown>\n ): boolean {\n // Basic condition evaluation\n // In production, this should use a proper expression language\n try {\n // Simple property checks like \"amount > 1000\"\n const match = expression.match(\n /^(\\w+)\\s*(>=|<=|>|<|===|!==|==|!=)\\s*(.+)$/\n );\n if (match) {\n const [, prop, operator, value] = match;\n if (!prop || !operator || value === undefined) {\n return false;\n }\n const propValue = contextData[prop];\n const compareValue = JSON.parse(value);\n\n switch (operator) {\n case '>':\n return Number(propValue) > Number(compareValue);\n case '<':\n return Number(propValue) < Number(compareValue);\n case '>=':\n return Number(propValue) >= Number(compareValue);\n case '<=':\n return Number(propValue) <= Number(compareValue);\n case '===':\n case '==':\n return propValue === compareValue;\n case '!==':\n case '!=':\n return propValue !== compareValue;\n }\n }\n\n // Check for boolean property\n if (expression in contextData) {\n return Boolean(contextData[expression]);\n }\n\n return false;\n } catch {\n return false;\n }\n }\n}\n\n/**\n * Create a new state machine engine instance.\n */\nexport function createStateMachineEngine(): IStateMachineEngine {\n return new BasicStateMachineEngine();\n}\n\n// ============ Utility Functions ============\n\n/**\n * Build a state machine definition from workflow entities.\n */\nexport function buildStateMachineDefinition(\n workflow: {\n key: string;\n name: string;\n version: number;\n initialStepId: string | null;\n },\n steps: {\n key: string;\n name: string;\n type: string;\n transitions: Record<string, string | TransitionDefinition>;\n approvalMode?: string;\n approverRoles?: string[];\n timeoutSeconds?: number;\n conditionExpression?: string;\n }[]\n): StateMachineDefinition {\n const stepMap: Record<string, StateMachineStep> = {};\n\n for (const step of steps) {\n stepMap[step.key] = {\n key: step.key,\n name: step.name,\n type: step.type as StateMachineStep['type'],\n transitions: step.transitions,\n approvalMode: step.approvalMode as StateMachineStep['approvalMode'],\n allowedRoles: step.approverRoles,\n timeoutSeconds: step.timeoutSeconds,\n conditionExpression: step.conditionExpression,\n };\n }\n\n // Find initial step\n const startStep = steps.find((s) => s.type === 'START');\n const initialStepKey = startStep?.key ?? steps[0]?.key ?? '';\n\n return {\n key: workflow.key,\n name: workflow.name,\n version: workflow.version,\n initialStepKey,\n steps: stepMap,\n };\n}\n\n/**\n * Create initial state for a new workflow instance.\n */\nexport function createInitialState(\n definition: StateMachineDefinition,\n contextData: Record<string, unknown> = {}\n): StateMachineState {\n return {\n currentStepKey: definition.initialStepKey,\n status: 'RUNNING',\n contextData,\n history: [],\n };\n}\n"],"mappings":";;;;;AA0JA,IAAa,0BAAb,MAAoE;CAClE,cACE,YACA,OACA,QACA,SACuC;AAEvC,MAAI,MAAM,WAAW,aAAa,MAAM,WAAW,UACjD,QAAO;GACL,SAAS;GACT,QAAQ,eAAe,MAAM,OAAO;GACrC;EAGH,MAAM,cAAc,WAAW,MAAM,MAAM;AAC3C,MAAI,CAAC,YACH,QAAO;GACL,SAAS;GACT,QAAQ,QAAQ,MAAM,eAAe;GACtC;EAIH,MAAM,aAAa,YAAY,YAAY;AAC3C,MAAI,CAAC,WACH,QAAO;GACL,SAAS;GACT,QAAQ,UAAU,OAAO,yBAAyB,MAAM;GACzD;AAIH,MAAI,YAAY,gBAAgB,YAAY,aAAa,SAAS,GAIhE;OAAI,CAHY,YAAY,aAAa,MAAM,SAC7C,QAAQ,UAAU,SAAS,KAAK,CACjC,CAEC,QAAO;IACL,SAAS;IACT,QAAQ;IACT;;AAKL,MACE,OAA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AAE1D,QAAO;EACL,KAAK,SAAS;EACd,MAAM,SAAS;EACf,SAAS,SAAS;EAClB;EACA,OAAO;EACR;;;;;AAMH,SAAgB,mBACd,YACA,cAAuC,EAAE,EACtB;AACnB,QAAO;EACL,gBAAgB,WAAW;EAC3B,QAAQ;EACR;EACA,SAAS,EAAE;EACZ"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ApprovalModeEnum, StepTypeEnum, TriggerTypeEnum, WorkflowStatusEnum } from "./workflow.enum.js";
|
|
2
|
+
import { AddStepInputModel, CreateWorkflowInputModel, UpdateWorkflowInputModel, WorkflowDefinitionModel, WorkflowStepModel } from "./workflow.schema.js";
|
|
3
|
+
import { AddStepContract, CreateWorkflowContract, GetWorkflowContract, ListWorkflowsContract, PublishWorkflowContract, UpdateWorkflowContract } from "./workflow.operations.js";
|
|
4
|
+
import { StepAddedEvent, WorkflowCreatedEvent, WorkflowPublishedEvent, WorkflowUpdatedEvent } from "./workflow.event.js";
|
|
5
|
+
export { AddStepContract, AddStepInputModel, ApprovalModeEnum, CreateWorkflowContract, CreateWorkflowInputModel, GetWorkflowContract, ListWorkflowsContract, PublishWorkflowContract, StepAddedEvent, StepTypeEnum, TriggerTypeEnum, UpdateWorkflowContract, UpdateWorkflowInputModel, WorkflowCreatedEvent, WorkflowDefinitionModel, WorkflowPublishedEvent, WorkflowStatusEnum, WorkflowStepModel, WorkflowUpdatedEvent };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ApprovalModeEnum, StepTypeEnum, TriggerTypeEnum, WorkflowStatusEnum } from "./workflow.enum.js";
|
|
2
|
+
import { AddStepInputModel, CreateWorkflowInputModel, UpdateWorkflowInputModel, WorkflowDefinitionModel, WorkflowStepModel } from "./workflow.schema.js";
|
|
3
|
+
import { AddStepContract, CreateWorkflowContract, GetWorkflowContract, ListWorkflowsContract, PublishWorkflowContract, UpdateWorkflowContract } from "./workflow.operations.js";
|
|
4
|
+
import { StepAddedEvent, WorkflowCreatedEvent, WorkflowPublishedEvent, WorkflowUpdatedEvent } from "./workflow.event.js";
|
|
5
|
+
|
|
6
|
+
export { AddStepContract, AddStepInputModel, ApprovalModeEnum, CreateWorkflowContract, CreateWorkflowInputModel, GetWorkflowContract, ListWorkflowsContract, PublishWorkflowContract, StepAddedEvent, StepTypeEnum, TriggerTypeEnum, UpdateWorkflowContract, UpdateWorkflowInputModel, WorkflowCreatedEvent, WorkflowDefinitionModel, WorkflowPublishedEvent, WorkflowStatusEnum, WorkflowStepModel, WorkflowUpdatedEvent };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as _contractspec_lib_schema901 from "@contractspec/lib.schema";
|
|
2
|
+
|
|
3
|
+
//#region src/workflow/workflow.enum.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Workflow status enum.
|
|
6
|
+
*/
|
|
7
|
+
declare const WorkflowStatusEnum: _contractspec_lib_schema901.EnumType<[string, string, string, string]>;
|
|
8
|
+
/**
|
|
9
|
+
* Trigger type enum.
|
|
10
|
+
*/
|
|
11
|
+
declare const TriggerTypeEnum: _contractspec_lib_schema901.EnumType<[string, string, string, string]>;
|
|
12
|
+
/**
|
|
13
|
+
* Step type enum.
|
|
14
|
+
*/
|
|
15
|
+
declare const StepTypeEnum: _contractspec_lib_schema901.EnumType<[string, string, string, string, string, string, string, string]>;
|
|
16
|
+
/**
|
|
17
|
+
* Approval mode enum.
|
|
18
|
+
*/
|
|
19
|
+
declare const ApprovalModeEnum: _contractspec_lib_schema901.EnumType<[string, string, string, string]>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ApprovalModeEnum, StepTypeEnum, TriggerTypeEnum, WorkflowStatusEnum };
|
|
22
|
+
//# sourceMappingURL=workflow.enum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.enum.d.ts","names":[],"sources":["../../src/workflow/workflow.enum.ts"],"sourcesContent":[],"mappings":";;;;;;AAKa,cAAA,kBAKX,EAAA,2BAAA,CAL6B,QAAA,CAAA,CAAA,MAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,CAAA;AAU/B;AAUA;AAcA;cAxBa,iBAKX,2BAAA,CAL0B;;;;cAUf,cASX,2BAAA,CATuB;;;;cAcZ,kBAKX,2BAAA,CAL2B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { defineEnum } from "@contractspec/lib.schema";
|
|
2
|
+
|
|
3
|
+
//#region src/workflow/workflow.enum.ts
|
|
4
|
+
/**
|
|
5
|
+
* Workflow status enum.
|
|
6
|
+
*/
|
|
7
|
+
const WorkflowStatusEnum = defineEnum("WorkflowStatus", [
|
|
8
|
+
"DRAFT",
|
|
9
|
+
"ACTIVE",
|
|
10
|
+
"DEPRECATED",
|
|
11
|
+
"ARCHIVED"
|
|
12
|
+
]);
|
|
13
|
+
/**
|
|
14
|
+
* Trigger type enum.
|
|
15
|
+
*/
|
|
16
|
+
const TriggerTypeEnum = defineEnum("WorkflowTriggerType", [
|
|
17
|
+
"MANUAL",
|
|
18
|
+
"EVENT",
|
|
19
|
+
"SCHEDULED",
|
|
20
|
+
"API"
|
|
21
|
+
]);
|
|
22
|
+
/**
|
|
23
|
+
* Step type enum.
|
|
24
|
+
*/
|
|
25
|
+
const StepTypeEnum = defineEnum("StepType", [
|
|
26
|
+
"START",
|
|
27
|
+
"APPROVAL",
|
|
28
|
+
"TASK",
|
|
29
|
+
"CONDITION",
|
|
30
|
+
"PARALLEL",
|
|
31
|
+
"WAIT",
|
|
32
|
+
"ACTION",
|
|
33
|
+
"END"
|
|
34
|
+
]);
|
|
35
|
+
/**
|
|
36
|
+
* Approval mode enum.
|
|
37
|
+
*/
|
|
38
|
+
const ApprovalModeEnum = defineEnum("ApprovalMode", [
|
|
39
|
+
"ANY",
|
|
40
|
+
"ALL",
|
|
41
|
+
"MAJORITY",
|
|
42
|
+
"SEQUENTIAL"
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { ApprovalModeEnum, StepTypeEnum, TriggerTypeEnum, WorkflowStatusEnum };
|
|
47
|
+
//# sourceMappingURL=workflow.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.enum.js","names":[],"sources":["../../src/workflow/workflow.enum.ts"],"sourcesContent":["import { defineEnum } from '@contractspec/lib.schema';\n\n/**\n * Workflow status enum.\n */\nexport const WorkflowStatusEnum = defineEnum('WorkflowStatus', [\n 'DRAFT',\n 'ACTIVE',\n 'DEPRECATED',\n 'ARCHIVED',\n]);\n\n/**\n * Trigger type enum.\n */\nexport const TriggerTypeEnum = defineEnum('WorkflowTriggerType', [\n 'MANUAL',\n 'EVENT',\n 'SCHEDULED',\n 'API',\n]);\n\n/**\n * Step type enum.\n */\nexport const StepTypeEnum = defineEnum('StepType', [\n 'START',\n 'APPROVAL',\n 'TASK',\n 'CONDITION',\n 'PARALLEL',\n 'WAIT',\n 'ACTION',\n 'END',\n]);\n\n/**\n * Approval mode enum.\n */\nexport const ApprovalModeEnum = defineEnum('ApprovalMode', [\n 'ANY',\n 'ALL',\n 'MAJORITY',\n 'SEQUENTIAL',\n]);\n"],"mappings":";;;;;;AAKA,MAAa,qBAAqB,WAAW,kBAAkB;CAC7D;CACA;CACA;CACA;CACD,CAAC;;;;AAKF,MAAa,kBAAkB,WAAW,uBAAuB;CAC/D;CACA;CACA;CACA;CACD,CAAC;;;;AAKF,MAAa,eAAe,WAAW,YAAY;CACjD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;AAKF,MAAa,mBAAmB,WAAW,gBAAgB;CACzD;CACA;CACA;CACA;CACD,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as _contractspec_lib_schema905 from "@contractspec/lib.schema";
|
|
2
|
+
import * as _contractspec_lib_contracts24 from "@contractspec/lib.contracts";
|
|
3
|
+
|
|
4
|
+
//#region src/workflow/workflow.event.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* WorkflowCreatedEvent - A new workflow definition has been created.
|
|
7
|
+
*/
|
|
8
|
+
declare const WorkflowCreatedEvent: _contractspec_lib_contracts24.EventSpec<_contractspec_lib_schema905.SchemaModel<{
|
|
9
|
+
workflowId: {
|
|
10
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
11
|
+
isOptional: false;
|
|
12
|
+
};
|
|
13
|
+
key: {
|
|
14
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
15
|
+
isOptional: false;
|
|
16
|
+
};
|
|
17
|
+
name: {
|
|
18
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
19
|
+
isOptional: false;
|
|
20
|
+
};
|
|
21
|
+
version: {
|
|
22
|
+
type: _contractspec_lib_schema905.FieldType<number, number>;
|
|
23
|
+
isOptional: false;
|
|
24
|
+
};
|
|
25
|
+
organizationId: {
|
|
26
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
27
|
+
isOptional: false;
|
|
28
|
+
};
|
|
29
|
+
createdBy: {
|
|
30
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
31
|
+
isOptional: false;
|
|
32
|
+
};
|
|
33
|
+
timestamp: {
|
|
34
|
+
type: _contractspec_lib_schema905.FieldType<Date, string>;
|
|
35
|
+
isOptional: false;
|
|
36
|
+
};
|
|
37
|
+
}>>;
|
|
38
|
+
/**
|
|
39
|
+
* WorkflowUpdatedEvent - A workflow definition has been updated.
|
|
40
|
+
*/
|
|
41
|
+
declare const WorkflowUpdatedEvent: _contractspec_lib_contracts24.EventSpec<_contractspec_lib_schema905.SchemaModel<{
|
|
42
|
+
workflowId: {
|
|
43
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
44
|
+
isOptional: false;
|
|
45
|
+
};
|
|
46
|
+
key: {
|
|
47
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
48
|
+
isOptional: false;
|
|
49
|
+
};
|
|
50
|
+
name: {
|
|
51
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
52
|
+
isOptional: false;
|
|
53
|
+
};
|
|
54
|
+
version: {
|
|
55
|
+
type: _contractspec_lib_schema905.FieldType<number, number>;
|
|
56
|
+
isOptional: false;
|
|
57
|
+
};
|
|
58
|
+
organizationId: {
|
|
59
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
60
|
+
isOptional: false;
|
|
61
|
+
};
|
|
62
|
+
createdBy: {
|
|
63
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
64
|
+
isOptional: false;
|
|
65
|
+
};
|
|
66
|
+
timestamp: {
|
|
67
|
+
type: _contractspec_lib_schema905.FieldType<Date, string>;
|
|
68
|
+
isOptional: false;
|
|
69
|
+
};
|
|
70
|
+
}>>;
|
|
71
|
+
/**
|
|
72
|
+
* WorkflowPublishedEvent - A workflow definition has been published.
|
|
73
|
+
*/
|
|
74
|
+
declare const WorkflowPublishedEvent: _contractspec_lib_contracts24.EventSpec<_contractspec_lib_schema905.SchemaModel<{
|
|
75
|
+
workflowId: {
|
|
76
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
77
|
+
isOptional: false;
|
|
78
|
+
};
|
|
79
|
+
key: {
|
|
80
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
81
|
+
isOptional: false;
|
|
82
|
+
};
|
|
83
|
+
name: {
|
|
84
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
85
|
+
isOptional: false;
|
|
86
|
+
};
|
|
87
|
+
version: {
|
|
88
|
+
type: _contractspec_lib_schema905.FieldType<number, number>;
|
|
89
|
+
isOptional: false;
|
|
90
|
+
};
|
|
91
|
+
organizationId: {
|
|
92
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
93
|
+
isOptional: false;
|
|
94
|
+
};
|
|
95
|
+
createdBy: {
|
|
96
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
97
|
+
isOptional: false;
|
|
98
|
+
};
|
|
99
|
+
timestamp: {
|
|
100
|
+
type: _contractspec_lib_schema905.FieldType<Date, string>;
|
|
101
|
+
isOptional: false;
|
|
102
|
+
};
|
|
103
|
+
}>>;
|
|
104
|
+
/**
|
|
105
|
+
* StepAddedEvent - A step has been added to a workflow definition.
|
|
106
|
+
*/
|
|
107
|
+
declare const StepAddedEvent: _contractspec_lib_contracts24.EventSpec<_contractspec_lib_schema905.SchemaModel<{
|
|
108
|
+
stepId: {
|
|
109
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
110
|
+
isOptional: false;
|
|
111
|
+
};
|
|
112
|
+
workflowId: {
|
|
113
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
114
|
+
isOptional: false;
|
|
115
|
+
};
|
|
116
|
+
stepKey: {
|
|
117
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
118
|
+
isOptional: false;
|
|
119
|
+
};
|
|
120
|
+
stepType: {
|
|
121
|
+
type: _contractspec_lib_schema905.FieldType<string, string>;
|
|
122
|
+
isOptional: false;
|
|
123
|
+
};
|
|
124
|
+
position: {
|
|
125
|
+
type: _contractspec_lib_schema905.FieldType<number, number>;
|
|
126
|
+
isOptional: false;
|
|
127
|
+
};
|
|
128
|
+
timestamp: {
|
|
129
|
+
type: _contractspec_lib_schema905.FieldType<Date, string>;
|
|
130
|
+
isOptional: false;
|
|
131
|
+
};
|
|
132
|
+
}>>;
|
|
133
|
+
//#endregion
|
|
134
|
+
export { StepAddedEvent, WorkflowCreatedEvent, WorkflowPublishedEvent, WorkflowUpdatedEvent };
|
|
135
|
+
//# sourceMappingURL=workflow.event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.event.d.ts","names":[],"sources":["../../src/workflow/workflow.event.ts"],"sourcesContent":[],"mappings":";;;;;;;cA0Ca,sBAAoB,6BAAA,CAAA,sCAAA;EAApB,UAAA,EAAA;IAUX,IAAA,EAAA,2BAAA,CAAA,SAAA,CAAA,MAAA,EAAA,MAAA,CAAA;;;;;;;;+CAV+B,CAAA,MAAA,EAAA,MAAA,CAAA;IAAA,UAAA,EAAA,KAAA;EAAA,CAAA;EAepB,OAAA,EAAA;IAUX,IAAA,uCAAA,CAAA,MAAA,EAAA,MAAA,CAAA;;;;;;;;+CAV+B,CAAA,MAAA,EAAA,MAAA,CAAA;IAAA,UAAA,EAAA,KAAA;EAAA,CAAA;EAepB,SAAA,EAAA;IAUX,IAAA,uCAAA,KAAA,EAAA,MAAA,CAAA;;;;;;;cAzBW,sBAAoB,6BAAA,CAAA,sCAAA;;IAeE,IAAA,EALjC,2BAAA,CAAA,SAKiC,CAAA,MAAA,EAAA,MAAA,CAAA;IAAA,UAAA,EAAA,KAAA;EAetB,CAAA;EAUX,GAAA,EAAA;;;;;;;;EAVyB,OAAA,EAAA;IAAA,IAAA,uCAAA,CAAA,MAAA,EAAA,MAAA,CAAA;;;;;;;;;;;;;;;;;;;cAfd,wBAAsB,6BAAA,CAAA,sCAAA;;UAUjC,2BAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAKW,gBAAc,6BAAA,CAAA,sCAAA;;UAUzB,2BAAA,CAAA"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
2
|
+
import { defineEvent, defineSchemaModel as defineSchemaModel$1 } from "@contractspec/lib.contracts";
|
|
3
|
+
|
|
4
|
+
//#region src/workflow/workflow.event.ts
|
|
5
|
+
/**
|
|
6
|
+
* Payload for workflow definition events.
|
|
7
|
+
*/
|
|
8
|
+
const WorkflowDefinitionPayload = defineSchemaModel$1({
|
|
9
|
+
name: "WorkflowDefinitionEventPayload",
|
|
10
|
+
description: "Payload for workflow definition events",
|
|
11
|
+
fields: {
|
|
12
|
+
workflowId: {
|
|
13
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
14
|
+
isOptional: false
|
|
15
|
+
},
|
|
16
|
+
key: {
|
|
17
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
18
|
+
isOptional: false
|
|
19
|
+
},
|
|
20
|
+
name: {
|
|
21
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
22
|
+
isOptional: false
|
|
23
|
+
},
|
|
24
|
+
version: {
|
|
25
|
+
type: ScalarTypeEnum.Int_unsecure(),
|
|
26
|
+
isOptional: false
|
|
27
|
+
},
|
|
28
|
+
organizationId: {
|
|
29
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
30
|
+
isOptional: false
|
|
31
|
+
},
|
|
32
|
+
createdBy: {
|
|
33
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
34
|
+
isOptional: false
|
|
35
|
+
},
|
|
36
|
+
timestamp: {
|
|
37
|
+
type: ScalarTypeEnum.DateTime(),
|
|
38
|
+
isOptional: false
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Payload when a step is added.
|
|
44
|
+
*/
|
|
45
|
+
const StepAddedPayload = defineSchemaModel$1({
|
|
46
|
+
name: "StepAddedEventPayload",
|
|
47
|
+
description: "Payload when a step is added",
|
|
48
|
+
fields: {
|
|
49
|
+
stepId: {
|
|
50
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
51
|
+
isOptional: false
|
|
52
|
+
},
|
|
53
|
+
workflowId: {
|
|
54
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
55
|
+
isOptional: false
|
|
56
|
+
},
|
|
57
|
+
stepKey: {
|
|
58
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
59
|
+
isOptional: false
|
|
60
|
+
},
|
|
61
|
+
stepType: {
|
|
62
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
63
|
+
isOptional: false
|
|
64
|
+
},
|
|
65
|
+
position: {
|
|
66
|
+
type: ScalarTypeEnum.Int_unsecure(),
|
|
67
|
+
isOptional: false
|
|
68
|
+
},
|
|
69
|
+
timestamp: {
|
|
70
|
+
type: ScalarTypeEnum.DateTime(),
|
|
71
|
+
isOptional: false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* WorkflowCreatedEvent - A new workflow definition has been created.
|
|
77
|
+
*/
|
|
78
|
+
const WorkflowCreatedEvent = defineEvent({
|
|
79
|
+
meta: {
|
|
80
|
+
key: "workflow.definition.created",
|
|
81
|
+
version: 1,
|
|
82
|
+
description: "A new workflow definition has been created.",
|
|
83
|
+
stability: "stable",
|
|
84
|
+
owners: ["@workflow-team"],
|
|
85
|
+
tags: [
|
|
86
|
+
"workflow",
|
|
87
|
+
"definition",
|
|
88
|
+
"created"
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
payload: WorkflowDefinitionPayload
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* WorkflowUpdatedEvent - A workflow definition has been updated.
|
|
95
|
+
*/
|
|
96
|
+
const WorkflowUpdatedEvent = defineEvent({
|
|
97
|
+
meta: {
|
|
98
|
+
key: "workflow.definition.updated",
|
|
99
|
+
version: 1,
|
|
100
|
+
description: "A workflow definition has been updated.",
|
|
101
|
+
stability: "stable",
|
|
102
|
+
owners: ["@workflow-team"],
|
|
103
|
+
tags: [
|
|
104
|
+
"workflow",
|
|
105
|
+
"definition",
|
|
106
|
+
"updated"
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
payload: WorkflowDefinitionPayload
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* WorkflowPublishedEvent - A workflow definition has been published.
|
|
113
|
+
*/
|
|
114
|
+
const WorkflowPublishedEvent = defineEvent({
|
|
115
|
+
meta: {
|
|
116
|
+
key: "workflow.definition.published",
|
|
117
|
+
version: 1,
|
|
118
|
+
description: "A workflow definition has been published and is now active.",
|
|
119
|
+
stability: "stable",
|
|
120
|
+
owners: ["@workflow-team"],
|
|
121
|
+
tags: [
|
|
122
|
+
"workflow",
|
|
123
|
+
"definition",
|
|
124
|
+
"published"
|
|
125
|
+
]
|
|
126
|
+
},
|
|
127
|
+
payload: WorkflowDefinitionPayload
|
|
128
|
+
});
|
|
129
|
+
/**
|
|
130
|
+
* StepAddedEvent - A step has been added to a workflow definition.
|
|
131
|
+
*/
|
|
132
|
+
const StepAddedEvent = defineEvent({
|
|
133
|
+
meta: {
|
|
134
|
+
key: "workflow.step.added",
|
|
135
|
+
version: 1,
|
|
136
|
+
description: "A step has been added to a workflow definition.",
|
|
137
|
+
stability: "stable",
|
|
138
|
+
owners: ["@workflow-team"],
|
|
139
|
+
tags: [
|
|
140
|
+
"workflow",
|
|
141
|
+
"step",
|
|
142
|
+
"added"
|
|
143
|
+
]
|
|
144
|
+
},
|
|
145
|
+
payload: StepAddedPayload
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
//#endregion
|
|
149
|
+
export { StepAddedEvent, WorkflowCreatedEvent, WorkflowPublishedEvent, WorkflowUpdatedEvent };
|
|
150
|
+
//# sourceMappingURL=workflow.event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.event.js","names":["defineSchemaModel"],"sources":["../../src/workflow/workflow.event.ts"],"sourcesContent":["import { defineEvent, defineSchemaModel } from '@contractspec/lib.contracts';\nimport { ScalarTypeEnum } from '@contractspec/lib.schema';\n\n/**\n * Payload for workflow definition events.\n */\nconst WorkflowDefinitionPayload = defineSchemaModel({\n name: 'WorkflowDefinitionEventPayload',\n description: 'Payload for workflow definition events',\n fields: {\n workflowId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n key: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n version: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n organizationId: {\n type: ScalarTypeEnum.String_unsecure(),\n isOptional: false,\n },\n createdBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n },\n});\n\n/**\n * Payload when a step is added.\n */\nconst StepAddedPayload = defineSchemaModel({\n name: 'StepAddedEventPayload',\n description: 'Payload when a step is added',\n fields: {\n stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n workflowId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n stepKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n stepType: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },\n position: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },\n timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false },\n },\n});\n\n/**\n * WorkflowCreatedEvent - A new workflow definition has been created.\n */\nexport const WorkflowCreatedEvent = defineEvent({\n meta: {\n key: 'workflow.definition.created',\n version: 1,\n description: 'A new workflow definition has been created.',\n stability: 'stable',\n owners: ['@workflow-team'],\n tags: ['workflow', 'definition', 'created'],\n },\n payload: WorkflowDefinitionPayload,\n});\n\n/**\n * WorkflowUpdatedEvent - A workflow definition has been updated.\n */\nexport const WorkflowUpdatedEvent = defineEvent({\n meta: {\n key: 'workflow.definition.updated',\n version: 1,\n description: 'A workflow definition has been updated.',\n stability: 'stable',\n owners: ['@workflow-team'],\n tags: ['workflow', 'definition', 'updated'],\n },\n payload: WorkflowDefinitionPayload,\n});\n\n/**\n * WorkflowPublishedEvent - A workflow definition has been published.\n */\nexport const WorkflowPublishedEvent = defineEvent({\n meta: {\n key: 'workflow.definition.published',\n version: 1,\n description: 'A workflow definition has been published and is now active.',\n stability: 'stable',\n owners: ['@workflow-team'],\n tags: ['workflow', 'definition', 'published'],\n },\n payload: WorkflowDefinitionPayload,\n});\n\n/**\n * StepAddedEvent - A step has been added to a workflow definition.\n */\nexport const StepAddedEvent = defineEvent({\n meta: {\n key: 'workflow.step.added',\n version: 1,\n description: 'A step has been added to a workflow definition.',\n stability: 'stable',\n owners: ['@workflow-team'],\n tags: ['workflow', 'step', 'added'],\n },\n payload: StepAddedPayload,\n});\n"],"mappings":";;;;;;;AAMA,MAAM,4BAA4BA,oBAAkB;CAClD,MAAM;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,YAAY;CAChD,MAAM;EACJ,KAAK;EACL,SAAS;EACT,aAAa;EACb,WAAW;EACX,QAAQ,CAAC,iBAAiB;EAC1B,MAAM;GAAC;GAAY;GAAc;GAAY;EAC9C;CACD,SAAS;CACV,CAAC;;;;AAKF,MAAa,iBAAiB,YAAY;CACxC,MAAM;EACJ,KAAK;EACL,SAAS;EACT,aAAa;EACb,WAAW;EACX,QAAQ,CAAC,iBAAiB;EAC1B,MAAM;GAAC;GAAY;GAAQ;GAAQ;EACpC;CACD,SAAS;CACV,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { HandlerContext, WorkflowDefinitionRecord, WorkflowStepRecord } from "../shared/types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/workflow/workflow.handler.d.ts
|
|
4
|
+
|
|
5
|
+
declare function handleCreateWorkflow(input: {
|
|
6
|
+
name: string;
|
|
7
|
+
key: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
triggerType?: 'MANUAL' | 'EVENT' | 'SCHEDULED' | 'API';
|
|
10
|
+
featureFlagKey?: string;
|
|
11
|
+
}, context: HandlerContext): Promise<WorkflowDefinitionRecord>;
|
|
12
|
+
declare function handleAddStep(input: {
|
|
13
|
+
workflowId: string;
|
|
14
|
+
key: string;
|
|
15
|
+
name: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
type: 'START' | 'APPROVAL' | 'TASK' | 'CONDITION' | 'PARALLEL' | 'WAIT' | 'ACTION' | 'END';
|
|
18
|
+
position?: number;
|
|
19
|
+
transitions: Record<string, string>;
|
|
20
|
+
approvalMode?: 'ANY' | 'ALL' | 'MAJORITY' | 'SEQUENTIAL';
|
|
21
|
+
approverRoles?: string[];
|
|
22
|
+
timeoutSeconds?: number;
|
|
23
|
+
}, _context: HandlerContext): Promise<WorkflowStepRecord>;
|
|
24
|
+
declare function handlePublishWorkflow(input: {
|
|
25
|
+
workflowId: string;
|
|
26
|
+
}, _context: HandlerContext): Promise<WorkflowDefinitionRecord>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { handleAddStep, handleCreateWorkflow, handlePublishWorkflow };
|
|
29
|
+
//# sourceMappingURL=workflow.handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.handler.d.ts","names":[],"sources":["../../src/workflow/workflow.handler.ts"],"sourcesContent":[],"mappings":";;;;AAmBW,iBARW,oBAAA,CAQX,KAAA,EAAA;EACA,IAAA,EAAA,MAAA;EAAR,GAAA,EAAA,MAAA;EAAO,WAAA,CAAA,EAAA,MAAA;EAuBY,WAAA,CAAA,EAAA,QAAa,GAAA,OAAA,GAAA,WAAA,GAAA,KAAA;EAgBlB,cAAA,CAAA,EAAA,MAAA;CAKL,EAAA,OAAA,EA7CD,cA6CC,CAAA,EA5CT,OA4CS,CA5CD,wBA4CC,CAAA;AACD,iBAtBW,aAAA,CAsBX,KAAA,EAAA;EAAR,UAAA,EAAA,MAAA;EAAO,GAAA,EAAA,MAAA;EAwCY,IAAA,EAAA,MAAA;EAEV,WAAA,CAAA,EAAA,MAAA;EACD,IAAA,EAAA,OAAA,GAAA,UAAA,GAAA,MAAA,GAAA,WAAA,GAAA,UAAA,GAAA,MAAA,GAAA,QAAA,GAAA,KAAA;EAAR,QAAA,CAAA,EAAA,MAAA;EAAO,WAAA,EAjDO,MAiDP,CAAA,MAAA,EAAA,MAAA,CAAA;;;;aA5CE,iBACT,QAAQ;iBAwCW,qBAAA;;aAEV,iBACT,QAAQ"}
|