@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.
Files changed (209) hide show
  1. package/dist/approval/approval.enum.d.ts +2 -7
  2. package/dist/approval/approval.enum.d.ts.map +1 -1
  3. package/dist/approval/approval.enum.js +20 -26
  4. package/dist/approval/approval.event.d.ts +108 -114
  5. package/dist/approval/approval.event.d.ts.map +1 -1
  6. package/dist/approval/approval.event.js +103 -210
  7. package/dist/approval/approval.handler.d.ts +17 -18
  8. package/dist/approval/approval.handler.d.ts.map +1 -1
  9. package/dist/approval/approval.operations.d.ts +429 -435
  10. package/dist/approval/approval.operations.d.ts.map +1 -1
  11. package/dist/approval/approval.operations.js +364 -339
  12. package/dist/approval/approval.schema.d.ts +86 -91
  13. package/dist/approval/approval.schema.d.ts.map +1 -1
  14. package/dist/approval/approval.schema.js +71 -107
  15. package/dist/approval/index.d.ts +8 -5
  16. package/dist/approval/index.d.ts.map +1 -0
  17. package/dist/approval/index.js +484 -5
  18. package/dist/browser/approval/approval.enum.js +22 -0
  19. package/dist/browser/approval/approval.event.js +112 -0
  20. package/dist/browser/approval/approval.operations.js +369 -0
  21. package/dist/browser/approval/approval.schema.js +73 -0
  22. package/dist/browser/approval/index.js +484 -0
  23. package/dist/browser/docs/index.js +103 -0
  24. package/dist/browser/docs/workflow-system.docblock.js +103 -0
  25. package/dist/browser/entities/approval.js +119 -0
  26. package/dist/browser/entities/index.js +508 -0
  27. package/dist/browser/entities/instance.js +161 -0
  28. package/dist/browser/entities/step.js +124 -0
  29. package/dist/browser/entities/workflow.js +82 -0
  30. package/dist/browser/example.js +42 -0
  31. package/dist/browser/handlers/index.js +253 -0
  32. package/dist/browser/handlers/workflow.handlers.js +253 -0
  33. package/dist/browser/index.js +3120 -0
  34. package/dist/browser/instance/index.js +677 -0
  35. package/dist/browser/instance/instance.enum.js +15 -0
  36. package/dist/browser/instance/instance.event.js +164 -0
  37. package/dist/browser/instance/instance.handler.js +356 -0
  38. package/dist/browser/instance/instance.operations.js +9 -0
  39. package/dist/browser/instance/instance.schema.js +101 -0
  40. package/dist/browser/presentations/index.js +109 -0
  41. package/dist/browser/seeders/index.js +3 -0
  42. package/dist/browser/shared/index.js +3 -0
  43. package/dist/browser/shared/mock-data.js +11 -0
  44. package/dist/browser/shared/types.js +0 -0
  45. package/dist/browser/state-machine/index.js +6 -0
  46. package/dist/browser/tests/operations.test-spec.js +6 -0
  47. package/dist/browser/ui/WorkflowDashboard.js +3 -0
  48. package/dist/browser/ui/hooks/index.js +50 -0
  49. package/dist/browser/ui/hooks/useWorkflowList.js +50 -0
  50. package/dist/browser/ui/index.js +54 -0
  51. package/dist/browser/ui/renderers/index.js +227 -0
  52. package/dist/browser/ui/renderers/workflow.markdown.js +227 -0
  53. package/dist/browser/workflow/index.js +21 -0
  54. package/dist/browser/workflow/workflow.enum.js +36 -0
  55. package/dist/browser/workflow/workflow.event.js +6 -0
  56. package/dist/browser/workflow/workflow.handler.js +5 -0
  57. package/dist/browser/workflow/workflow.operations.js +8 -0
  58. package/dist/browser/workflow/workflow.schema.js +151 -0
  59. package/dist/browser/workflow-system.capability.js +5 -0
  60. package/dist/browser/workflow-system.feature.js +3 -0
  61. package/dist/docs/index.d.ts +2 -1
  62. package/dist/docs/index.d.ts.map +1 -0
  63. package/dist/docs/index.js +104 -1
  64. package/dist/docs/workflow-system.docblock.d.ts +2 -1
  65. package/dist/docs/workflow-system.docblock.d.ts.map +1 -0
  66. package/dist/docs/workflow-system.docblock.js +45 -56
  67. package/dist/entities/approval.d.ts +35 -40
  68. package/dist/entities/approval.d.ts.map +1 -1
  69. package/dist/entities/approval.js +116 -124
  70. package/dist/entities/index.d.ts +132 -137
  71. package/dist/entities/index.d.ts.map +1 -1
  72. package/dist/entities/index.js +506 -29
  73. package/dist/entities/instance.d.ts +46 -51
  74. package/dist/entities/instance.d.ts.map +1 -1
  75. package/dist/entities/instance.js +158 -164
  76. package/dist/entities/step.d.ts +31 -36
  77. package/dist/entities/step.d.ts.map +1 -1
  78. package/dist/entities/step.js +122 -132
  79. package/dist/entities/workflow.d.ts +22 -27
  80. package/dist/entities/workflow.d.ts.map +1 -1
  81. package/dist/entities/workflow.js +80 -99
  82. package/dist/example.d.ts +2 -6
  83. package/dist/example.d.ts.map +1 -1
  84. package/dist/example.js +41 -55
  85. package/dist/handlers/index.d.ts +2 -2
  86. package/dist/handlers/index.d.ts.map +1 -0
  87. package/dist/handlers/index.js +254 -3
  88. package/dist/handlers/workflow.handlers.d.ts +107 -106
  89. package/dist/handlers/workflow.handlers.d.ts.map +1 -1
  90. package/dist/handlers/workflow.handlers.js +237 -246
  91. package/dist/index.d.ts +15 -26
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.js +3121 -26
  94. package/dist/instance/index.d.ts +8 -5
  95. package/dist/instance/index.d.ts.map +1 -0
  96. package/dist/instance/index.js +677 -5
  97. package/dist/instance/instance.enum.d.ts +1 -6
  98. package/dist/instance/instance.enum.d.ts.map +1 -1
  99. package/dist/instance/instance.enum.js +14 -18
  100. package/dist/instance/instance.event.d.ts +313 -319
  101. package/dist/instance/instance.event.d.ts.map +1 -1
  102. package/dist/instance/instance.event.js +151 -279
  103. package/dist/instance/instance.handler.d.ts +21 -22
  104. package/dist/instance/instance.handler.d.ts.map +1 -1
  105. package/dist/instance/instance.handler.js +352 -89
  106. package/dist/instance/instance.operations.d.ts +819 -825
  107. package/dist/instance/instance.operations.d.ts.map +1 -1
  108. package/dist/instance/instance.operations.js +10 -464
  109. package/dist/instance/instance.schema.d.ts +196 -201
  110. package/dist/instance/instance.schema.d.ts.map +1 -1
  111. package/dist/instance/instance.schema.js +97 -167
  112. package/dist/presentations/index.d.ts +23 -28
  113. package/dist/presentations/index.d.ts.map +1 -1
  114. package/dist/presentations/index.js +104 -334
  115. package/dist/seeders/index.d.ts +4 -8
  116. package/dist/seeders/index.d.ts.map +1 -1
  117. package/dist/seeders/index.js +4 -19
  118. package/dist/shared/index.d.ts +6 -3
  119. package/dist/shared/index.d.ts.map +1 -0
  120. package/dist/shared/index.js +4 -3
  121. package/dist/shared/mock-data.d.ts +16 -16
  122. package/dist/shared/mock-data.d.ts.map +1 -1
  123. package/dist/shared/mock-data.js +11 -11
  124. package/dist/shared/types.d.ts +69 -72
  125. package/dist/shared/types.d.ts.map +1 -1
  126. package/dist/shared/types.js +1 -0
  127. package/dist/state-machine/index.d.ts +92 -95
  128. package/dist/state-machine/index.d.ts.map +1 -1
  129. package/dist/state-machine/index.js +6 -157
  130. package/dist/tests/operations.test-spec.d.ts +4 -9
  131. package/dist/tests/operations.test-spec.d.ts.map +1 -1
  132. package/dist/tests/operations.test-spec.js +7 -123
  133. package/dist/ui/WorkflowDashboard.d.ts +1 -6
  134. package/dist/ui/WorkflowDashboard.d.ts.map +1 -1
  135. package/dist/ui/WorkflowDashboard.js +3 -222
  136. package/dist/ui/hooks/index.d.ts +2 -2
  137. package/dist/ui/hooks/index.d.ts.map +1 -0
  138. package/dist/ui/hooks/index.js +51 -5
  139. package/dist/ui/hooks/useWorkflowList.d.ts +15 -19
  140. package/dist/ui/hooks/useWorkflowList.d.ts.map +1 -1
  141. package/dist/ui/hooks/useWorkflowList.js +47 -51
  142. package/dist/ui/index.d.ts +7 -6
  143. package/dist/ui/index.d.ts.map +1 -0
  144. package/dist/ui/index.js +55 -6
  145. package/dist/ui/renderers/index.d.ts +2 -2
  146. package/dist/ui/renderers/index.d.ts.map +1 -0
  147. package/dist/ui/renderers/index.js +227 -2
  148. package/dist/ui/renderers/workflow.markdown.d.ts +13 -14
  149. package/dist/ui/renderers/workflow.markdown.d.ts.map +1 -1
  150. package/dist/ui/renderers/workflow.markdown.js +223 -229
  151. package/dist/workflow/index.d.ts +8 -5
  152. package/dist/workflow/index.d.ts.map +1 -0
  153. package/dist/workflow/index.js +22 -6
  154. package/dist/workflow/workflow.enum.d.ts +4 -9
  155. package/dist/workflow/workflow.enum.d.ts.map +1 -1
  156. package/dist/workflow/workflow.enum.js +32 -42
  157. package/dist/workflow/workflow.event.d.ts +112 -118
  158. package/dist/workflow/workflow.event.d.ts.map +1 -1
  159. package/dist/workflow/workflow.event.js +7 -150
  160. package/dist/workflow/workflow.handler.d.ts +23 -24
  161. package/dist/workflow/workflow.handler.d.ts.map +1 -1
  162. package/dist/workflow/workflow.handler.js +6 -66
  163. package/dist/workflow/workflow.operations.d.ts +847 -853
  164. package/dist/workflow/workflow.operations.d.ts.map +1 -1
  165. package/dist/workflow/workflow.operations.js +9 -345
  166. package/dist/workflow/workflow.schema.d.ts +229 -234
  167. package/dist/workflow/workflow.schema.d.ts.map +1 -1
  168. package/dist/workflow/workflow.schema.js +146 -243
  169. package/dist/workflow-system.capability.d.ts +3 -8
  170. package/dist/workflow-system.capability.d.ts.map +1 -1
  171. package/dist/workflow-system.capability.js +6 -34
  172. package/dist/workflow-system.feature.d.ts +1 -6
  173. package/dist/workflow-system.feature.d.ts.map +1 -1
  174. package/dist/workflow-system.feature.js +4 -346
  175. package/package.json +415 -93
  176. package/dist/approval/approval.enum.js.map +0 -1
  177. package/dist/approval/approval.event.js.map +0 -1
  178. package/dist/approval/approval.handler.js +0 -72
  179. package/dist/approval/approval.handler.js.map +0 -1
  180. package/dist/approval/approval.operations.js.map +0 -1
  181. package/dist/approval/approval.schema.js.map +0 -1
  182. package/dist/docs/workflow-system.docblock.js.map +0 -1
  183. package/dist/entities/approval.js.map +0 -1
  184. package/dist/entities/index.js.map +0 -1
  185. package/dist/entities/instance.js.map +0 -1
  186. package/dist/entities/step.js.map +0 -1
  187. package/dist/entities/workflow.js.map +0 -1
  188. package/dist/example.js.map +0 -1
  189. package/dist/handlers/workflow.handlers.js.map +0 -1
  190. package/dist/instance/instance.enum.js.map +0 -1
  191. package/dist/instance/instance.event.js.map +0 -1
  192. package/dist/instance/instance.handler.js.map +0 -1
  193. package/dist/instance/instance.operations.js.map +0 -1
  194. package/dist/instance/instance.schema.js.map +0 -1
  195. package/dist/presentations/index.js.map +0 -1
  196. package/dist/seeders/index.js.map +0 -1
  197. package/dist/shared/mock-data.js.map +0 -1
  198. package/dist/state-machine/index.js.map +0 -1
  199. package/dist/tests/operations.test-spec.js.map +0 -1
  200. package/dist/ui/WorkflowDashboard.js.map +0 -1
  201. package/dist/ui/hooks/useWorkflowList.js.map +0 -1
  202. package/dist/ui/renderers/workflow.markdown.js.map +0 -1
  203. package/dist/workflow/workflow.enum.js.map +0 -1
  204. package/dist/workflow/workflow.event.js.map +0 -1
  205. package/dist/workflow/workflow.handler.js.map +0 -1
  206. package/dist/workflow/workflow.operations.js.map +0 -1
  207. package/dist/workflow/workflow.schema.js.map +0 -1
  208. package/dist/workflow-system.capability.js.map +0 -1
  209. package/dist/workflow-system.feature.js.map +0 -1
@@ -0,0 +1,677 @@
1
+ // src/instance/instance.enum.ts
2
+ import { defineEnum } from "@contractspec/lib.schema";
3
+ var InstanceStatusEnum = defineEnum("InstanceStatus", [
4
+ "PENDING",
5
+ "RUNNING",
6
+ "WAITING",
7
+ "PAUSED",
8
+ "COMPLETED",
9
+ "CANCELLED",
10
+ "FAILED",
11
+ "TIMEOUT"
12
+ ]);
13
+
14
+ // src/instance/instance.schema.ts
15
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
16
+ var WorkflowInstanceModel = defineSchemaModel({
17
+ name: "WorkflowInstanceModel",
18
+ description: "A running workflow instance",
19
+ fields: {
20
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
21
+ workflowDefinitionId: {
22
+ type: ScalarTypeEnum.String_unsecure(),
23
+ isOptional: false
24
+ },
25
+ referenceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
26
+ referenceType: {
27
+ type: ScalarTypeEnum.String_unsecure(),
28
+ isOptional: true
29
+ },
30
+ status: { type: InstanceStatusEnum, isOptional: false },
31
+ currentStepId: {
32
+ type: ScalarTypeEnum.String_unsecure(),
33
+ isOptional: true
34
+ },
35
+ contextData: { type: ScalarTypeEnum.JSON(), isOptional: true },
36
+ triggeredBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
37
+ organizationId: {
38
+ type: ScalarTypeEnum.String_unsecure(),
39
+ isOptional: false
40
+ },
41
+ priority: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
42
+ dueAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
43
+ outcome: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
44
+ resultData: { type: ScalarTypeEnum.JSON(), isOptional: true },
45
+ errorMessage: {
46
+ type: ScalarTypeEnum.String_unsecure(),
47
+ isOptional: true
48
+ },
49
+ createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
50
+ startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
51
+ completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true }
52
+ }
53
+ });
54
+ var StartWorkflowInputModel = defineSchemaModel({
55
+ name: "StartWorkflowInput",
56
+ description: "Input for starting a workflow",
57
+ fields: {
58
+ workflowKey: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
59
+ contextData: { type: ScalarTypeEnum.JSON(), isOptional: true },
60
+ referenceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
61
+ referenceType: {
62
+ type: ScalarTypeEnum.String_unsecure(),
63
+ isOptional: true
64
+ },
65
+ priority: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
66
+ dueAt: { type: ScalarTypeEnum.DateTime(), isOptional: true }
67
+ }
68
+ });
69
+ var TransitionInputModel = defineSchemaModel({
70
+ name: "TransitionInput",
71
+ description: "Input for transitioning a workflow",
72
+ fields: {
73
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
74
+ action: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
75
+ data: { type: ScalarTypeEnum.JSON(), isOptional: true },
76
+ comment: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
77
+ }
78
+ });
79
+ var TransitionResultModel = defineSchemaModel({
80
+ name: "TransitionResult",
81
+ description: "Result of a workflow transition",
82
+ fields: {
83
+ success: { type: ScalarTypeEnum.Boolean(), isOptional: false },
84
+ instance: { type: WorkflowInstanceModel, isOptional: false },
85
+ previousStepKey: {
86
+ type: ScalarTypeEnum.String_unsecure(),
87
+ isOptional: true
88
+ },
89
+ currentStepKey: {
90
+ type: ScalarTypeEnum.String_unsecure(),
91
+ isOptional: true
92
+ },
93
+ message: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
94
+ }
95
+ });
96
+
97
+ // src/instance/instance.operations.ts
98
+ import {
99
+ defineCommand,
100
+ defineQuery
101
+ } from "@contractspec/lib.contracts/operations";
102
+ import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
103
+ var OWNERS = ["@example.workflow-system"];
104
+ var StartWorkflowContract = defineCommand({
105
+ meta: {
106
+ key: "workflow.instance.start",
107
+ version: "1.0.0",
108
+ stability: "stable",
109
+ owners: [...OWNERS],
110
+ tags: ["workflow", "instance", "start"],
111
+ description: "Start a new workflow instance.",
112
+ goal: "Initiate a workflow for a business process.",
113
+ context: "Order creation, request submission, etc."
114
+ },
115
+ io: {
116
+ input: StartWorkflowInputModel,
117
+ output: WorkflowInstanceModel
118
+ },
119
+ policy: { auth: "user" },
120
+ sideEffects: {
121
+ emits: [
122
+ {
123
+ key: "workflow.instance.started",
124
+ version: "1.0.0",
125
+ when: "Workflow starts",
126
+ payload: WorkflowInstanceModel
127
+ },
128
+ {
129
+ key: "workflow.step.entered",
130
+ version: "1.0.0",
131
+ when: "First step entered",
132
+ payload: WorkflowInstanceModel
133
+ }
134
+ ],
135
+ audit: ["workflow.instance.started"]
136
+ },
137
+ acceptance: {
138
+ scenarios: [
139
+ {
140
+ key: "start-workflow-happy-path",
141
+ given: ["Workflow definition exists"],
142
+ when: ["User starts workflow"],
143
+ then: ["Instance is created and started"]
144
+ }
145
+ ],
146
+ examples: [
147
+ {
148
+ key: "start-onboarding",
149
+ input: {
150
+ workflowKey: "onboarding-v1",
151
+ context: { employeeId: "emp-123" }
152
+ },
153
+ output: { id: "inst-456", status: "running" }
154
+ }
155
+ ]
156
+ }
157
+ });
158
+ var TransitionWorkflowContract = defineCommand({
159
+ meta: {
160
+ key: "workflow.instance.transition",
161
+ version: "1.0.0",
162
+ stability: "stable",
163
+ owners: [...OWNERS],
164
+ tags: ["workflow", "instance", "transition", "state-machine"],
165
+ description: "Transition a workflow instance to the next step.",
166
+ goal: "Move workflow forward based on action.",
167
+ context: "Task completion, approval decisions."
168
+ },
169
+ io: {
170
+ input: TransitionInputModel,
171
+ output: TransitionResultModel
172
+ },
173
+ policy: { auth: "user" },
174
+ sideEffects: {
175
+ emits: [
176
+ {
177
+ key: "workflow.step.exited",
178
+ version: "1.0.0",
179
+ when: "Step is exited",
180
+ payload: WorkflowInstanceModel
181
+ },
182
+ {
183
+ key: "workflow.step.entered",
184
+ version: "1.0.0",
185
+ when: "New step is entered",
186
+ payload: WorkflowInstanceModel
187
+ },
188
+ {
189
+ key: "workflow.instance.completed",
190
+ version: "1.0.0",
191
+ when: "Workflow reaches end",
192
+ payload: WorkflowInstanceModel
193
+ }
194
+ ],
195
+ audit: ["workflow.instance.transitioned"]
196
+ },
197
+ acceptance: {
198
+ scenarios: [
199
+ {
200
+ key: "transition-workflow-happy-path",
201
+ given: ["Workflow instance is waiting at step"],
202
+ when: ["User provides input"],
203
+ then: ["Instance moves to next step"]
204
+ }
205
+ ],
206
+ examples: [
207
+ {
208
+ key: "complete-task",
209
+ input: {
210
+ instanceId: "inst-456",
211
+ action: "complete",
212
+ data: { approved: true }
213
+ },
214
+ output: { success: true, nextStep: "notify-hr" }
215
+ }
216
+ ]
217
+ }
218
+ });
219
+ var PauseWorkflowContract = defineCommand({
220
+ meta: {
221
+ key: "workflow.instance.pause",
222
+ version: "1.0.0",
223
+ stability: "stable",
224
+ owners: [...OWNERS],
225
+ tags: ["workflow", "instance", "pause"],
226
+ description: "Pause a running workflow instance.",
227
+ goal: "Temporarily halt workflow execution.",
228
+ context: "Administrative action, emergency stop."
229
+ },
230
+ io: {
231
+ input: defineSchemaModel2({
232
+ name: "PauseResumeInput",
233
+ fields: {
234
+ instanceId: {
235
+ type: ScalarTypeEnum2.String_unsecure(),
236
+ isOptional: false
237
+ },
238
+ reason: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
239
+ }
240
+ }),
241
+ output: WorkflowInstanceModel
242
+ },
243
+ policy: { auth: "user" },
244
+ sideEffects: {
245
+ emits: [
246
+ {
247
+ key: "workflow.instance.paused",
248
+ version: "1.0.0",
249
+ when: "Workflow is paused",
250
+ payload: WorkflowInstanceModel
251
+ }
252
+ ],
253
+ audit: ["workflow.instance.paused"]
254
+ },
255
+ acceptance: {
256
+ scenarios: [
257
+ {
258
+ key: "pause-workflow-happy-path",
259
+ given: ["Workflow is running"],
260
+ when: ["Admin pauses workflow"],
261
+ then: ["Instance status becomes PAUSED"]
262
+ }
263
+ ],
264
+ examples: [
265
+ {
266
+ key: "pause-maintenance",
267
+ input: { instanceId: "inst-456", reason: "System maintenance" },
268
+ output: { id: "inst-456", status: "paused" }
269
+ }
270
+ ]
271
+ }
272
+ });
273
+ var ResumeWorkflowContract = defineCommand({
274
+ meta: {
275
+ key: "workflow.instance.resume",
276
+ version: "1.0.0",
277
+ stability: "stable",
278
+ owners: [...OWNERS],
279
+ tags: ["workflow", "instance", "resume"],
280
+ description: "Resume a paused workflow instance.",
281
+ goal: "Continue workflow execution.",
282
+ context: "Administrative action."
283
+ },
284
+ io: {
285
+ input: defineSchemaModel2({
286
+ name: "PauseResumeInput",
287
+ fields: {
288
+ instanceId: {
289
+ type: ScalarTypeEnum2.String_unsecure(),
290
+ isOptional: false
291
+ },
292
+ reason: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
293
+ }
294
+ }),
295
+ output: WorkflowInstanceModel
296
+ },
297
+ policy: { auth: "user" },
298
+ sideEffects: {
299
+ emits: [
300
+ {
301
+ key: "workflow.instance.resumed",
302
+ version: "1.0.0",
303
+ when: "Workflow is resumed",
304
+ payload: WorkflowInstanceModel
305
+ }
306
+ ],
307
+ audit: ["workflow.instance.resumed"]
308
+ },
309
+ acceptance: {
310
+ scenarios: [
311
+ {
312
+ key: "resume-workflow-happy-path",
313
+ given: ["Workflow is paused"],
314
+ when: ["Admin resumes workflow"],
315
+ then: ["Instance status becomes RUNNING"]
316
+ }
317
+ ],
318
+ examples: [
319
+ {
320
+ key: "resume-normal",
321
+ input: { instanceId: "inst-456", reason: "Issue resolved" },
322
+ output: { id: "inst-456", status: "running" }
323
+ }
324
+ ]
325
+ }
326
+ });
327
+ var CancelWorkflowContract = defineCommand({
328
+ meta: {
329
+ key: "workflow.instance.cancel",
330
+ version: "1.0.0",
331
+ stability: "stable",
332
+ owners: [...OWNERS],
333
+ tags: ["workflow", "instance", "cancel"],
334
+ description: "Cancel a workflow instance.",
335
+ goal: "Terminate workflow without completion.",
336
+ context: "User request, system cancellation."
337
+ },
338
+ io: {
339
+ input: defineSchemaModel2({
340
+ name: "CancelWorkflowInput",
341
+ fields: {
342
+ instanceId: {
343
+ type: ScalarTypeEnum2.String_unsecure(),
344
+ isOptional: false
345
+ },
346
+ reason: {
347
+ type: ScalarTypeEnum2.String_unsecure(),
348
+ isOptional: false
349
+ }
350
+ }
351
+ }),
352
+ output: WorkflowInstanceModel
353
+ },
354
+ policy: { auth: "user" },
355
+ sideEffects: {
356
+ emits: [
357
+ {
358
+ key: "workflow.instance.cancelled",
359
+ version: "1.0.0",
360
+ when: "Workflow is cancelled",
361
+ payload: WorkflowInstanceModel
362
+ }
363
+ ],
364
+ audit: ["workflow.instance.cancelled"]
365
+ },
366
+ acceptance: {
367
+ scenarios: [
368
+ {
369
+ key: "cancel-workflow-happy-path",
370
+ given: ["Workflow is running"],
371
+ when: ["User cancels workflow"],
372
+ then: ["Instance status becomes CANCELLED"]
373
+ }
374
+ ],
375
+ examples: [
376
+ {
377
+ key: "cancel-mistake",
378
+ input: { instanceId: "inst-456", reason: "Created by mistake" },
379
+ output: { id: "inst-456", status: "cancelled" }
380
+ }
381
+ ]
382
+ }
383
+ });
384
+ var ListInstancesContract = defineQuery({
385
+ meta: {
386
+ key: "workflow.instance.list",
387
+ version: "1.0.0",
388
+ stability: "stable",
389
+ owners: [...OWNERS],
390
+ tags: ["workflow", "instance", "list"],
391
+ description: "List workflow instances with filtering.",
392
+ goal: "Browse and search running workflows.",
393
+ context: "Dashboard, monitoring."
394
+ },
395
+ io: {
396
+ input: defineSchemaModel2({
397
+ name: "ListInstancesInput",
398
+ fields: {
399
+ workflowKey: {
400
+ type: ScalarTypeEnum2.String_unsecure(),
401
+ isOptional: true
402
+ },
403
+ status: { type: InstanceStatusEnum, isOptional: true },
404
+ referenceType: {
405
+ type: ScalarTypeEnum2.String_unsecure(),
406
+ isOptional: true
407
+ },
408
+ referenceId: {
409
+ type: ScalarTypeEnum2.String_unsecure(),
410
+ isOptional: true
411
+ },
412
+ triggeredBy: {
413
+ type: ScalarTypeEnum2.String_unsecure(),
414
+ isOptional: true
415
+ },
416
+ limit: {
417
+ type: ScalarTypeEnum2.Int_unsecure(),
418
+ isOptional: true,
419
+ defaultValue: 20
420
+ },
421
+ offset: {
422
+ type: ScalarTypeEnum2.Int_unsecure(),
423
+ isOptional: true,
424
+ defaultValue: 0
425
+ }
426
+ }
427
+ }),
428
+ output: defineSchemaModel2({
429
+ name: "ListInstancesOutput",
430
+ fields: {
431
+ instances: {
432
+ type: WorkflowInstanceModel,
433
+ isArray: true,
434
+ isOptional: false
435
+ },
436
+ total: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false }
437
+ }
438
+ })
439
+ },
440
+ policy: { auth: "user" },
441
+ acceptance: {
442
+ scenarios: [
443
+ {
444
+ key: "list-instances-happy-path",
445
+ given: ["Workflow instances exist"],
446
+ when: ["User lists instances"],
447
+ then: ["List of instances is returned"]
448
+ }
449
+ ],
450
+ examples: [
451
+ {
452
+ key: "list-running",
453
+ input: { status: "running", limit: 10 },
454
+ output: { instances: [], total: 5 }
455
+ }
456
+ ]
457
+ }
458
+ });
459
+ var GetInstanceContract = defineQuery({
460
+ meta: {
461
+ key: "workflow.instance.get",
462
+ version: "1.0.0",
463
+ stability: "stable",
464
+ owners: [...OWNERS],
465
+ tags: ["workflow", "instance", "get"],
466
+ description: "Get a workflow instance with details.",
467
+ goal: "View workflow instance details.",
468
+ context: "Instance detail view."
469
+ },
470
+ io: {
471
+ input: defineSchemaModel2({
472
+ name: "GetInstanceInput",
473
+ fields: {
474
+ instanceId: {
475
+ type: ScalarTypeEnum2.String_unsecure(),
476
+ isOptional: false
477
+ }
478
+ }
479
+ }),
480
+ output: WorkflowInstanceModel
481
+ },
482
+ policy: { auth: "user" },
483
+ acceptance: {
484
+ scenarios: [
485
+ {
486
+ key: "get-instance-happy-path",
487
+ given: ["Instance exists"],
488
+ when: ["User requests instance details"],
489
+ then: ["Instance details are returned"]
490
+ }
491
+ ],
492
+ examples: [
493
+ {
494
+ key: "get-details",
495
+ input: { instanceId: "inst-456" },
496
+ output: { id: "inst-456", workflowKey: "onboarding-v1" }
497
+ }
498
+ ]
499
+ }
500
+ });
501
+
502
+ // src/instance/instance.event.ts
503
+ import { defineEvent, defineSchemaModel as defineSchemaModel3 } from "@contractspec/lib.contracts";
504
+ import { ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
505
+ var InstanceEventPayload = defineSchemaModel3({
506
+ name: "InstanceEventPayload",
507
+ description: "Base payload for instance events",
508
+ fields: {
509
+ instanceId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
510
+ workflowId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
511
+ workflowKey: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
512
+ status: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
513
+ referenceId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
514
+ referenceType: {
515
+ type: ScalarTypeEnum3.String_unsecure(),
516
+ isOptional: true
517
+ },
518
+ triggeredBy: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
519
+ organizationId: {
520
+ type: ScalarTypeEnum3.String_unsecure(),
521
+ isOptional: false
522
+ },
523
+ timestamp: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
524
+ }
525
+ });
526
+ var StepTransitionPayload = defineSchemaModel3({
527
+ name: "StepTransitionEventPayload",
528
+ description: "Payload for step transition events",
529
+ fields: {
530
+ instanceId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
531
+ workflowId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
532
+ fromStepKey: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
533
+ toStepKey: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
534
+ action: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
535
+ executedBy: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
536
+ timestamp: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
537
+ }
538
+ });
539
+ var InstanceCompletedPayload = defineSchemaModel3({
540
+ name: "InstanceCompletedEventPayload",
541
+ description: "Payload when instance completes",
542
+ fields: {
543
+ instanceId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
544
+ workflowId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
545
+ workflowKey: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
546
+ outcome: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
547
+ referenceId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
548
+ referenceType: {
549
+ type: ScalarTypeEnum3.String_unsecure(),
550
+ isOptional: true
551
+ },
552
+ duration: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
553
+ timestamp: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
554
+ }
555
+ });
556
+ var InstanceStartedEvent = defineEvent({
557
+ meta: {
558
+ key: "workflow.instance.started",
559
+ version: "1.0.0",
560
+ description: "A new workflow instance has been started.",
561
+ stability: "stable",
562
+ owners: ["@workflow-team"],
563
+ tags: ["workflow", "instance", "started"]
564
+ },
565
+ payload: InstanceEventPayload
566
+ });
567
+ var StepEnteredEvent = defineEvent({
568
+ meta: {
569
+ key: "workflow.step.entered",
570
+ version: "1.0.0",
571
+ description: "A workflow instance has entered a new step.",
572
+ stability: "stable",
573
+ owners: ["@workflow-team"],
574
+ tags: ["workflow", "step", "entered"]
575
+ },
576
+ payload: StepTransitionPayload
577
+ });
578
+ var StepExitedEvent = defineEvent({
579
+ meta: {
580
+ key: "workflow.step.exited",
581
+ version: "1.0.0",
582
+ description: "A workflow instance has exited a step.",
583
+ stability: "stable",
584
+ owners: ["@workflow-team"],
585
+ tags: ["workflow", "step", "exited"]
586
+ },
587
+ payload: StepTransitionPayload
588
+ });
589
+ var InstanceCompletedEvent = defineEvent({
590
+ meta: {
591
+ key: "workflow.instance.completed",
592
+ version: "1.0.0",
593
+ description: "A workflow instance has completed.",
594
+ stability: "stable",
595
+ owners: ["@workflow-team"],
596
+ tags: ["workflow", "instance", "completed"]
597
+ },
598
+ payload: InstanceCompletedPayload
599
+ });
600
+ var InstanceCancelledEvent = defineEvent({
601
+ meta: {
602
+ key: "workflow.instance.cancelled",
603
+ version: "1.0.0",
604
+ description: "A workflow instance has been cancelled.",
605
+ stability: "stable",
606
+ owners: ["@workflow-team"],
607
+ tags: ["workflow", "instance", "cancelled"]
608
+ },
609
+ payload: InstanceEventPayload
610
+ });
611
+ var InstancePausedEvent = defineEvent({
612
+ meta: {
613
+ key: "workflow.instance.paused",
614
+ version: "1.0.0",
615
+ description: "A workflow instance has been paused.",
616
+ stability: "stable",
617
+ owners: ["@workflow-team"],
618
+ tags: ["workflow", "instance", "paused"]
619
+ },
620
+ payload: InstanceEventPayload
621
+ });
622
+ var InstanceResumedEvent = defineEvent({
623
+ meta: {
624
+ key: "workflow.instance.resumed",
625
+ version: "1.0.0",
626
+ description: "A workflow instance has been resumed.",
627
+ stability: "stable",
628
+ owners: ["@workflow-team"],
629
+ tags: ["workflow", "instance", "resumed"]
630
+ },
631
+ payload: InstanceEventPayload
632
+ });
633
+ var InstanceFailedEvent = defineEvent({
634
+ meta: {
635
+ key: "workflow.instance.failed",
636
+ version: "1.0.0",
637
+ description: "A workflow instance has failed.",
638
+ stability: "stable",
639
+ owners: ["@workflow-team"],
640
+ tags: ["workflow", "instance", "failed"]
641
+ },
642
+ payload: InstanceEventPayload
643
+ });
644
+ var InstanceTimedOutEvent = defineEvent({
645
+ meta: {
646
+ key: "workflow.instance.timedOut",
647
+ version: "1.0.0",
648
+ description: "A workflow instance has timed out.",
649
+ stability: "stable",
650
+ owners: ["@workflow-team"],
651
+ tags: ["workflow", "instance", "timeout"]
652
+ },
653
+ payload: InstanceEventPayload
654
+ });
655
+ export {
656
+ WorkflowInstanceModel,
657
+ TransitionWorkflowContract,
658
+ TransitionResultModel,
659
+ TransitionInputModel,
660
+ StepExitedEvent,
661
+ StepEnteredEvent,
662
+ StartWorkflowInputModel,
663
+ StartWorkflowContract,
664
+ ResumeWorkflowContract,
665
+ PauseWorkflowContract,
666
+ ListInstancesContract,
667
+ InstanceTimedOutEvent,
668
+ InstanceStatusEnum,
669
+ InstanceStartedEvent,
670
+ InstanceResumedEvent,
671
+ InstancePausedEvent,
672
+ InstanceFailedEvent,
673
+ InstanceCompletedEvent,
674
+ InstanceCancelledEvent,
675
+ GetInstanceContract,
676
+ CancelWorkflowContract
677
+ };
@@ -0,0 +1,15 @@
1
+ // src/instance/instance.enum.ts
2
+ import { defineEnum } from "@contractspec/lib.schema";
3
+ var InstanceStatusEnum = defineEnum("InstanceStatus", [
4
+ "PENDING",
5
+ "RUNNING",
6
+ "WAITING",
7
+ "PAUSED",
8
+ "COMPLETED",
9
+ "CANCELLED",
10
+ "FAILED",
11
+ "TIMEOUT"
12
+ ]);
13
+ export {
14
+ InstanceStatusEnum
15
+ };