@saltcorn/data 1.6.0-alpha.2 → 1.6.0-alpha.3

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 (190) hide show
  1. package/dist/base-plugin/actions.d.ts +1 -1
  2. package/dist/base-plugin/index.d.ts.map +1 -1
  3. package/dist/base-plugin/viewtemplates/edit.js +1 -1
  4. package/dist/base-plugin/viewtemplates/edit.js.map +1 -1
  5. package/dist/base-plugin/viewtemplates/filter.js +1 -1
  6. package/dist/base-plugin/viewtemplates/filter.js.map +1 -1
  7. package/dist/base-plugin/viewtemplates/list.js +1 -1
  8. package/dist/base-plugin/viewtemplates/list.js.map +1 -1
  9. package/dist/base-plugin/viewtemplates/listshowlist.js +1 -1
  10. package/dist/base-plugin/viewtemplates/listshowlist.js.map +1 -1
  11. package/dist/base-plugin/viewtemplates/room.js +1 -1
  12. package/dist/base-plugin/viewtemplates/room.js.map +1 -1
  13. package/dist/base-plugin/viewtemplates/show.js +1 -1
  14. package/dist/base-plugin/viewtemplates/show.js.map +1 -1
  15. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts +2 -187
  16. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts.map +1 -1
  17. package/dist/base-plugin/viewtemplates/viewable_fields.js +2 -1898
  18. package/dist/base-plugin/viewtemplates/viewable_fields.js.map +1 -1
  19. package/dist/base-plugin/viewtemplates/workflow-room.js +1 -1
  20. package/dist/base-plugin/viewtemplates/workflow-room.js.map +1 -1
  21. package/dist/db/connect.d.ts.map +1 -1
  22. package/dist/db/connect.js +19 -2
  23. package/dist/db/connect.js.map +1 -1
  24. package/dist/diagram/node_extract_utils.js +1 -1
  25. package/dist/diagram/node_extract_utils.js.map +1 -1
  26. package/dist/models/file.d.ts +1 -1
  27. package/dist/models/file.d.ts.map +1 -1
  28. package/dist/models/page.d.ts.map +1 -1
  29. package/dist/models/page.js +28 -1
  30. package/dist/models/page.js.map +1 -1
  31. package/dist/models/table.d.ts.map +1 -1
  32. package/dist/models/table.js +5 -1
  33. package/dist/models/table.js.map +1 -1
  34. package/dist/models/workflow_step.d.ts +5 -0
  35. package/dist/models/workflow_step.d.ts.map +1 -1
  36. package/dist/models/workflow_step.js +142 -0
  37. package/dist/models/workflow_step.js.map +1 -1
  38. package/dist/plugin-helper.d.ts +1 -1
  39. package/dist/plugin-helper.d.ts.map +1 -1
  40. package/dist/plugin-helper.js +18 -7
  41. package/dist/plugin-helper.js.map +1 -1
  42. package/dist/plugin-testing.js +1 -1
  43. package/dist/plugin-testing.js.map +1 -1
  44. package/dist/viewable_fields.d.ts +16 -0
  45. package/dist/viewable_fields.d.ts.map +1 -1
  46. package/dist/viewable_fields.js +342 -4
  47. package/dist/viewable_fields.js.map +1 -1
  48. package/dist/web-mobile-commons.js +1 -1
  49. package/dist/web-mobile-commons.js.map +1 -1
  50. package/package.json +8 -8
  51. package/dist/models/s3_helpers.d.ts +0 -54
  52. package/dist/models/s3_helpers.d.ts.map +0 -1
  53. package/dist/models/s3_helpers.js +0 -505
  54. package/dist/models/s3_helpers.js.map +0 -1
  55. package/dist/test-utils/mocks.d.ts +0 -203
  56. package/dist/test-utils/mocks.d.ts.map +0 -1
  57. package/dist/test-utils/mocks.js +0 -329
  58. package/dist/test-utils/mocks.js.map +0 -1
  59. package/dist/tests/actions.test.d.ts +0 -2
  60. package/dist/tests/actions.test.d.ts.map +0 -1
  61. package/dist/tests/actions.test.js +0 -860
  62. package/dist/tests/actions.test.js.map +0 -1
  63. package/dist/tests/auth.test.d.ts +0 -2
  64. package/dist/tests/auth.test.d.ts.map +0 -1
  65. package/dist/tests/auth.test.js +0 -790
  66. package/dist/tests/auth.test.js.map +0 -1
  67. package/dist/tests/auxtest.test.d.ts +0 -2
  68. package/dist/tests/auxtest.test.d.ts.map +0 -1
  69. package/dist/tests/auxtest.test.js +0 -556
  70. package/dist/tests/auxtest.test.js.map +0 -1
  71. package/dist/tests/base.test.d.ts +0 -2
  72. package/dist/tests/base.test.d.ts.map +0 -1
  73. package/dist/tests/base.test.js +0 -30
  74. package/dist/tests/base.test.js.map +0 -1
  75. package/dist/tests/calc.test.d.ts +0 -2
  76. package/dist/tests/calc.test.d.ts.map +0 -1
  77. package/dist/tests/calc.test.js +0 -1081
  78. package/dist/tests/calc.test.js.map +0 -1
  79. package/dist/tests/composite_pk.test.d.ts +0 -2
  80. package/dist/tests/composite_pk.test.d.ts.map +0 -1
  81. package/dist/tests/composite_pk.test.js +0 -98
  82. package/dist/tests/composite_pk.test.js.map +0 -1
  83. package/dist/tests/config.test.d.ts +0 -2
  84. package/dist/tests/config.test.d.ts.map +0 -1
  85. package/dist/tests/config.test.js +0 -86
  86. package/dist/tests/config.test.js.map +0 -1
  87. package/dist/tests/db.test.d.ts +0 -2
  88. package/dist/tests/db.test.d.ts.map +0 -1
  89. package/dist/tests/db.test.js +0 -178
  90. package/dist/tests/db.test.js.map +0 -1
  91. package/dist/tests/discover.test.d.ts +0 -2
  92. package/dist/tests/discover.test.d.ts.map +0 -1
  93. package/dist/tests/discover.test.js +0 -245
  94. package/dist/tests/discover.test.js.map +0 -1
  95. package/dist/tests/edit.test.d.ts +0 -2
  96. package/dist/tests/edit.test.d.ts.map +0 -1
  97. package/dist/tests/edit.test.js +0 -1161
  98. package/dist/tests/edit.test.js.map +0 -1
  99. package/dist/tests/email.test.d.ts +0 -2
  100. package/dist/tests/email.test.d.ts.map +0 -1
  101. package/dist/tests/email.test.js +0 -255
  102. package/dist/tests/email.test.js.map +0 -1
  103. package/dist/tests/exact_views.test.d.ts +0 -2
  104. package/dist/tests/exact_views.test.d.ts.map +0 -1
  105. package/dist/tests/exact_views.test.js +0 -1363
  106. package/dist/tests/exact_views.test.js.map +0 -1
  107. package/dist/tests/field.test.d.ts +0 -2
  108. package/dist/tests/field.test.d.ts.map +0 -1
  109. package/dist/tests/field.test.js +0 -588
  110. package/dist/tests/field.test.js.map +0 -1
  111. package/dist/tests/fieldviews.test.d.ts +0 -2
  112. package/dist/tests/fieldviews.test.d.ts.map +0 -1
  113. package/dist/tests/fieldviews.test.js +0 -74
  114. package/dist/tests/fieldviews.test.js.map +0 -1
  115. package/dist/tests/file.test.d.ts +0 -2
  116. package/dist/tests/file.test.d.ts.map +0 -1
  117. package/dist/tests/file.test.js +0 -148
  118. package/dist/tests/file.test.js.map +0 -1
  119. package/dist/tests/filter.test.d.ts +0 -2
  120. package/dist/tests/filter.test.d.ts.map +0 -1
  121. package/dist/tests/filter.test.js +0 -496
  122. package/dist/tests/filter.test.js.map +0 -1
  123. package/dist/tests/form.test.d.ts +0 -2
  124. package/dist/tests/form.test.d.ts.map +0 -1
  125. package/dist/tests/form.test.js +0 -199
  126. package/dist/tests/form.test.js.map +0 -1
  127. package/dist/tests/list.test.d.ts +0 -2
  128. package/dist/tests/list.test.d.ts.map +0 -1
  129. package/dist/tests/list.test.js +0 -1037
  130. package/dist/tests/list.test.js.map +0 -1
  131. package/dist/tests/mail_queue.test.d.ts +0 -2
  132. package/dist/tests/mail_queue.test.d.ts.map +0 -1
  133. package/dist/tests/mail_queue.test.js +0 -122
  134. package/dist/tests/mail_queue.test.js.map +0 -1
  135. package/dist/tests/models.test.d.ts +0 -2
  136. package/dist/tests/models.test.d.ts.map +0 -1
  137. package/dist/tests/models.test.js +0 -417
  138. package/dist/tests/models.test.js.map +0 -1
  139. package/dist/tests/page.test.d.ts +0 -2
  140. package/dist/tests/page.test.d.ts.map +0 -1
  141. package/dist/tests/page.test.js +0 -26
  142. package/dist/tests/page.test.js.map +0 -1
  143. package/dist/tests/page_group.test.d.ts +0 -2
  144. package/dist/tests/page_group.test.d.ts.map +0 -1
  145. package/dist/tests/page_group.test.js +0 -51
  146. package/dist/tests/page_group.test.js.map +0 -1
  147. package/dist/tests/plugin.test.d.ts +0 -2
  148. package/dist/tests/plugin.test.d.ts.map +0 -1
  149. package/dist/tests/plugin.test.js +0 -60
  150. package/dist/tests/plugin.test.js.map +0 -1
  151. package/dist/tests/show.test.d.ts +0 -2
  152. package/dist/tests/show.test.d.ts.map +0 -1
  153. package/dist/tests/show.test.js +0 -561
  154. package/dist/tests/show.test.js.map +0 -1
  155. package/dist/tests/state.test.d.ts +0 -2
  156. package/dist/tests/state.test.d.ts.map +0 -1
  157. package/dist/tests/state.test.js +0 -82
  158. package/dist/tests/state.test.js.map +0 -1
  159. package/dist/tests/table.test.d.ts +0 -2
  160. package/dist/tests/table.test.d.ts.map +0 -1
  161. package/dist/tests/table.test.js +0 -2717
  162. package/dist/tests/table.test.js.map +0 -1
  163. package/dist/tests/table_history.test.d.ts +0 -2
  164. package/dist/tests/table_history.test.d.ts.map +0 -1
  165. package/dist/tests/table_history.test.js +0 -413
  166. package/dist/tests/table_history.test.js.map +0 -1
  167. package/dist/tests/table_sync_info.test.d.ts +0 -2
  168. package/dist/tests/table_sync_info.test.d.ts.map +0 -1
  169. package/dist/tests/table_sync_info.test.js +0 -62
  170. package/dist/tests/table_sync_info.test.js.map +0 -1
  171. package/dist/tests/tag.test.d.ts +0 -2
  172. package/dist/tests/tag.test.d.ts.map +0 -1
  173. package/dist/tests/tag.test.js +0 -97
  174. package/dist/tests/tag.test.js.map +0 -1
  175. package/dist/tests/user.test.d.ts +0 -2
  176. package/dist/tests/user.test.d.ts.map +0 -1
  177. package/dist/tests/user.test.js +0 -390
  178. package/dist/tests/user.test.js.map +0 -1
  179. package/dist/tests/view.test.d.ts +0 -2
  180. package/dist/tests/view.test.d.ts.map +0 -1
  181. package/dist/tests/view.test.js +0 -699
  182. package/dist/tests/view.test.js.map +0 -1
  183. package/dist/tests/workflow.test.d.ts +0 -2
  184. package/dist/tests/workflow.test.d.ts.map +0 -1
  185. package/dist/tests/workflow.test.js +0 -303
  186. package/dist/tests/workflow.test.js.map +0 -1
  187. package/dist/tests/workflow_run.test.d.ts +0 -2
  188. package/dist/tests/workflow_run.test.d.ts.map +0 -1
  189. package/dist/tests/workflow_run.test.js +0 -826
  190. package/dist/tests/workflow_run.test.js.map +0 -1
@@ -1,826 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const workflow_run_1 = __importDefault(require("../models/workflow_run"));
7
- const workflow_step_1 = __importDefault(require("../models/workflow_step"));
8
- const trigger_1 = __importDefault(require("../models/trigger"));
9
- const db_1 = __importDefault(require("../db"));
10
- const assertions_1 = require("./assertions");
11
- const globals_1 = require("@jest/globals");
12
- const multi_tenant_1 = require("@saltcorn/db-common/multi-tenant");
13
- const { getState } = require("../db/state");
14
- getState().registerPlugin("base", require("../base-plugin"));
15
- const mocks_1 = __importDefault(require("./mocks"));
16
- const user_1 = __importDefault(require("../models/user"));
17
- const table_1 = __importDefault(require("../models/table"));
18
- const workflow_trace_1 = __importDefault(require("../models/workflow_trace"));
19
- const { mockReqRes } = mocks_1.default;
20
- (0, globals_1.afterAll)(db_1.default.close);
21
- beforeAll(async () => {
22
- await require("../db/reset_schema")();
23
- await require("../db/fixtures")();
24
- });
25
- jest.setTimeout(10000);
26
- (0, globals_1.describe)("Workflow run steps", () => {
27
- (0, globals_1.it)("should create steps", async () => {
28
- const trigger = await trigger_1.default.create({
29
- action: "Workflow",
30
- when_trigger: "Never",
31
- name: "mywf",
32
- });
33
- await workflow_step_1.default.create({
34
- trigger_id: trigger.id,
35
- name: "first_step",
36
- next_step: "second_step",
37
- action_name: "run_js_code",
38
- initial_step: true,
39
- configuration: { code: `return {x:1}` },
40
- });
41
- await workflow_step_1.default.create({
42
- trigger_id: trigger.id,
43
- name: "second_step",
44
- next_step: "third_step",
45
- action_name: "SetContext",
46
- initial_step: false,
47
- configuration: { ctx_values: `{y:await x+1}` },
48
- });
49
- await workflow_step_1.default.create({
50
- trigger_id: trigger.id,
51
- name: "third_step",
52
- next_step: "x>2 ? fifth_step : fourth_step ",
53
- only_if: "y>4",
54
- action_name: "run_js_code",
55
- initial_step: false,
56
- configuration: { code: `return {x:3}` },
57
- });
58
- await workflow_step_1.default.create({
59
- trigger_id: trigger.id,
60
- name: "fourth_step",
61
- action_name: "run_js_code",
62
- initial_step: false,
63
- configuration: { code: `return {last:1}` },
64
- });
65
- await workflow_step_1.default.create({
66
- trigger_id: trigger.id,
67
- name: "fifth_step",
68
- action_name: "run_js_code",
69
- initial_step: false,
70
- configuration: { code: `return {last:2}` },
71
- });
72
- });
73
- (0, globals_1.it)("should run", async () => {
74
- const user = await user_1.default.findOne({ id: 1 });
75
- (0, assertions_1.assertIsSet)(user);
76
- const trigger = trigger_1.default.findOne({ name: "mywf" });
77
- (0, assertions_1.assertIsSet)(trigger);
78
- const wfrun = await workflow_run_1.default.create({
79
- trigger_id: trigger.id,
80
- });
81
- await wfrun.run({ user });
82
- (0, globals_1.expect)(wfrun.context.x).toBe(1);
83
- (0, globals_1.expect)(wfrun.context.y).toBe(2);
84
- (0, globals_1.expect)(wfrun.context.last).toBe(1);
85
- (0, globals_1.expect)(wfrun.current_step[0]).toBe("fourth_step");
86
- (0, globals_1.expect)(wfrun.current_step_name).toBe("fourth_step");
87
- });
88
- (0, globals_1.it)("should run through trigger", async () => {
89
- const user = await user_1.default.findOne({ id: 1 });
90
- (0, assertions_1.assertIsSet)(user);
91
- const trigger = trigger_1.default.findOne({ name: "mywf" });
92
- (0, assertions_1.assertIsSet)(trigger);
93
- const result = await trigger.runWithoutRow({ user });
94
- (0, globals_1.expect)(result.x).toBe(1);
95
- (0, globals_1.expect)(result.y).toBe(2);
96
- (0, globals_1.expect)(result.last).toBe(1);
97
- });
98
- (0, globals_1.it)("should run with traces", async () => {
99
- const user = await user_1.default.findOne({ id: 1 });
100
- (0, assertions_1.assertIsSet)(user);
101
- const trigger0 = trigger_1.default.findOne({ name: "mywf" });
102
- (0, assertions_1.assertIsSet)(trigger0);
103
- await trigger_1.default.update(trigger0.id, { configuration: { save_traces: true } });
104
- const trigger = trigger_1.default.findOne({ name: "mywf" });
105
- (0, assertions_1.assertIsSet)(trigger);
106
- const result = await trigger.runWithoutRow({ user });
107
- (0, globals_1.expect)(result.x).toBe(1);
108
- (0, globals_1.expect)(result.y).toBe(2);
109
- (0, globals_1.expect)(result.last).toBe(1);
110
- const traces = await workflow_trace_1.default.find({ run_id: result.__wf_run_id });
111
- (0, globals_1.expect)(traces.length).toBe(3);
112
- });
113
- });
114
- (0, globals_1.describe)("Workflow run forloop", () => {
115
- (0, globals_1.it)("should create steps", async () => {
116
- const trigger = await trigger_1.default.create({
117
- action: "Workflow",
118
- when_trigger: "Never",
119
- name: "wfForLoop",
120
- });
121
- await workflow_step_1.default.create({
122
- trigger_id: trigger.id,
123
- name: "first_step",
124
- next_step: "second_step",
125
- action_name: "SetContext",
126
- initial_step: true,
127
- configuration: { ctx_values: "{xs: [1,2,3], ys: []}" },
128
- });
129
- await workflow_step_1.default.create({
130
- trigger_id: trigger.id,
131
- name: "second_step",
132
- next_step: "third_step",
133
- action_name: "ForLoop",
134
- initial_step: false,
135
- configuration: {
136
- array_expression: "xs",
137
- item_variable: "x",
138
- loop_body_initial_step: "body0",
139
- },
140
- });
141
- await workflow_step_1.default.create({
142
- trigger_id: trigger.id,
143
- name: "third_step",
144
- action_name: "SetContext",
145
- initial_step: false,
146
- configuration: { ctx_values: `{done:true}` },
147
- });
148
- await workflow_step_1.default.create({
149
- trigger_id: trigger.id,
150
- name: "body0",
151
- next_step: "body1",
152
- action_name: "run_js_code",
153
- initial_step: false,
154
- configuration: { code: `return {ys:[...ys, x+3]}` },
155
- });
156
- await workflow_step_1.default.create({
157
- trigger_id: trigger.id,
158
- name: "body1",
159
- action_name: "run_js_code",
160
- initial_step: false,
161
- configuration: { code: `return {inloop: x}` },
162
- });
163
- });
164
- (0, globals_1.it)("should run", async () => {
165
- const user = await user_1.default.findOne({ id: 1 });
166
- (0, assertions_1.assertIsSet)(user);
167
- const trigger = trigger_1.default.findOne({ name: "wfForLoop" });
168
- (0, assertions_1.assertIsSet)(trigger);
169
- const wfrun = await workflow_run_1.default.create({
170
- trigger_id: trigger.id,
171
- });
172
- await wfrun.run({ user });
173
- (0, globals_1.expect)(wfrun.context.ys).toStrictEqual([4, 5, 6]);
174
- //expect(wfrun.context.y).toBe(2);
175
- //expect(wfrun.context.last).toBe(1);
176
- });
177
- });
178
- (0, globals_1.describe)("Workflow run error handling", () => {
179
- (0, globals_1.it)("should create steps", async () => {
180
- const trigger = await trigger_1.default.create({
181
- action: "Workflow",
182
- when_trigger: "Never",
183
- name: "mywf1",
184
- });
185
- await workflow_step_1.default.create({
186
- trigger_id: trigger.id,
187
- name: "first_step",
188
- next_step: "second_step",
189
- action_name: "SetErrorHandler",
190
- initial_step: true,
191
- configuration: { error_handling_step: "ehan" },
192
- });
193
- await workflow_step_1.default.create({
194
- trigger_id: trigger.id,
195
- name: "second_step",
196
- next_step: "third_step",
197
- action_name: "run_js_code",
198
- initial_step: false,
199
- configuration: { code: `throw new Error("HAHA")` },
200
- });
201
- await workflow_step_1.default.create({
202
- trigger_id: trigger.id,
203
- name: "third_step",
204
- action_name: "run_js_code",
205
- initial_step: false,
206
- configuration: { code: `return {afterCrash:1}` },
207
- });
208
- await workflow_step_1.default.create({
209
- trigger_id: trigger.id,
210
- name: "ehan",
211
- action_name: "run_js_code",
212
- next_step: "fifth_step",
213
- initial_step: false,
214
- configuration: { code: `return {runEhan:1}` },
215
- });
216
- await workflow_step_1.default.create({
217
- trigger_id: trigger.id,
218
- name: "fifth_step",
219
- action_name: "run_js_code",
220
- initial_step: false,
221
- configuration: { code: `return {afterEhan:1}` },
222
- });
223
- });
224
- (0, globals_1.it)("should run", async () => {
225
- const user = await user_1.default.findOne({ id: 1 });
226
- (0, assertions_1.assertIsSet)(user);
227
- const trigger = trigger_1.default.findOne({ name: "mywf1" });
228
- (0, assertions_1.assertIsSet)(trigger);
229
- const wfrun = await workflow_run_1.default.create({
230
- trigger_id: trigger.id,
231
- });
232
- await wfrun.run({ user });
233
- (0, globals_1.expect)(wfrun.context.afterCrash).toBe(undefined);
234
- (0, globals_1.expect)(wfrun.context.runEhan).toBe(1);
235
- (0, globals_1.expect)(wfrun.context.afterEhan).toBe(1);
236
- });
237
- });
238
- (0, globals_1.describe)("Workflow run error handling with transaction and database ops", () => {
239
- (0, globals_1.it)("should create steps", async () => {
240
- const trigger = await trigger_1.default.create({
241
- action: "Workflow",
242
- when_trigger: "Never",
243
- name: "mywferrdb",
244
- });
245
- await workflow_step_1.default.create({
246
- trigger_id: trigger.id,
247
- name: "first_step",
248
- next_step: "second_step",
249
- action_name: "SetErrorHandler",
250
- initial_step: true,
251
- configuration: { error_handling_step: "ehan" },
252
- });
253
- await workflow_step_1.default.create({
254
- trigger_id: trigger.id,
255
- name: "second_step",
256
- next_step: "third_step",
257
- action_name: "run_js_code",
258
- initial_step: false,
259
- configuration: {
260
- code: `await Table.findOne("books").insertRow({author:"Simon Marlow", pages: 223, foo:3})`,
261
- },
262
- });
263
- await workflow_step_1.default.create({
264
- trigger_id: trigger.id,
265
- name: "third_step",
266
- action_name: "run_js_code",
267
- initial_step: false,
268
- configuration: { code: `return {afterCrash:1}` },
269
- });
270
- await workflow_step_1.default.create({
271
- trigger_id: trigger.id,
272
- name: "ehan",
273
- action_name: "run_js_code",
274
- next_step: "fifth_step",
275
- initial_step: false,
276
- configuration: { code: `return {runEhan:1}` },
277
- });
278
- await workflow_step_1.default.create({
279
- trigger_id: trigger.id,
280
- name: "fifth_step",
281
- action_name: "run_js_code",
282
- initial_step: false,
283
- configuration: {
284
- code: `await Table.findOne("books").insertRow({author:"Simon Marlow", pages: 234})`,
285
- },
286
- });
287
- });
288
- (0, globals_1.it)("should run", async () => {
289
- await (0, multi_tenant_1.runWithTenant)("public", async () => {
290
- await db_1.default.withTransaction(async () => {
291
- const user = await user_1.default.findOne({ id: 1 });
292
- (0, assertions_1.assertIsSet)(user);
293
- const trigger = trigger_1.default.findOne({ name: "mywferrdb" });
294
- (0, assertions_1.assertIsSet)(trigger);
295
- const wfrun = await workflow_run_1.default.create({
296
- trigger_id: trigger.id,
297
- });
298
- await wfrun.run({ user });
299
- (0, globals_1.expect)(wfrun.context.afterCrash).toBe(undefined);
300
- (0, globals_1.expect)(wfrun.context.runEhan).toBe(1);
301
- const books = await table_1.default.findOne("books")?.getRows({
302
- author: "Simon Marlow",
303
- });
304
- (0, globals_1.expect)(books?.length).toBe(1);
305
- (0, globals_1.expect)(books?.[0].pages).toBe(234);
306
- });
307
- });
308
- });
309
- });
310
- (0, globals_1.describe)("Workflow run subworkflows", () => {
311
- (0, globals_1.it)("should create steps", async () => {
312
- const main = await trigger_1.default.create({
313
- action: "Workflow",
314
- when_trigger: "Never",
315
- name: "wfmain",
316
- });
317
- const sub = await trigger_1.default.create({
318
- action: "Workflow",
319
- when_trigger: "Never",
320
- name: "wfsub",
321
- });
322
- await workflow_step_1.default.create({
323
- trigger_id: main.id,
324
- name: "first_step",
325
- next_step: "second_step",
326
- action_name: "SetContext",
327
- initial_step: true,
328
- configuration: { ctx_values: "{foo: {x:1}, bar: {y:2}}" },
329
- });
330
- await workflow_step_1.default.create({
331
- trigger_id: main.id,
332
- name: "second_step",
333
- next_step: "third_step",
334
- action_name: "wfsub",
335
- initial_step: false,
336
- configuration: { subcontext: "foo" },
337
- });
338
- await workflow_step_1.default.create({
339
- trigger_id: main.id,
340
- name: "third_step",
341
- next_step: "",
342
- action_name: "SetContext",
343
- initial_step: false,
344
- configuration: { ctx_values: `{done: true}` },
345
- });
346
- await workflow_step_1.default.create({
347
- trigger_id: sub.id,
348
- name: "first_step",
349
- next_step: "second_step",
350
- action_name: "run_js_code",
351
- initial_step: true,
352
- configuration: { code: `return {w:5+x}` },
353
- });
354
- await workflow_step_1.default.create({
355
- trigger_id: sub.id,
356
- name: "second_step",
357
- action_name: "run_js_code",
358
- initial_step: false,
359
- configuration: { code: `return {z:9}` },
360
- });
361
- });
362
- (0, globals_1.it)("should run", async () => {
363
- const user = await user_1.default.findOne({ id: 1 });
364
- (0, assertions_1.assertIsSet)(user);
365
- const trigger = trigger_1.default.findOne({ name: "wfmain" });
366
- (0, assertions_1.assertIsSet)(trigger);
367
- const wfrun = await workflow_run_1.default.create({
368
- trigger_id: trigger.id,
369
- });
370
- await wfrun.run({ user });
371
- //console.log(wfrun.context);
372
- (0, globals_1.expect)(wfrun.context.done).toBe(true);
373
- (0, globals_1.expect)(wfrun.context.foo.w).toBe(6);
374
- (0, globals_1.expect)(wfrun.context.foo.z).toBe(9);
375
- (0, globals_1.expect)(wfrun.context.bar.y).toBe(2);
376
- (0, globals_1.expect)(wfrun.context.foo.x).toBe(1);
377
- });
378
- });
379
- (0, globals_1.describe)("Workflow run actions", () => {
380
- (0, globals_1.it)("should create steps", async () => {
381
- const table = table_1.default.findOne({ name: "books" });
382
- (0, assertions_1.assertIsSet)(table);
383
- await trigger_1.default.create({
384
- action: "run_js_code",
385
- table_id: table.id,
386
- name: "InsertBook",
387
- when_trigger: "Never",
388
- configuration: {
389
- code: `await table.insertRow({author: "Mary Contrary", pages: 124, publisher: row.publisher})`,
390
- },
391
- });
392
- const main = await trigger_1.default.create({
393
- action: "Workflow",
394
- when_trigger: "Never",
395
- name: "wfrunaction",
396
- });
397
- await workflow_step_1.default.create({
398
- trigger_id: main.id,
399
- name: "first_step",
400
- next_step: "second_step",
401
- action_name: "SetContext",
402
- initial_step: true,
403
- configuration: { ctx_values: "{foo: {x:1}}" },
404
- });
405
- await workflow_step_1.default.create({
406
- trigger_id: main.id,
407
- name: "second_step",
408
- next_step: "third_step",
409
- action_name: "InsertBook",
410
- initial_step: false,
411
- configuration: { row_expr: "{publisher: thepub}" },
412
- });
413
- await workflow_step_1.default.create({
414
- trigger_id: main.id,
415
- name: "third_step",
416
- next_step: "",
417
- action_name: "TableQuery",
418
- initial_step: false,
419
- configuration: {
420
- query_table: "books",
421
- query_object: "{pages: 124}",
422
- query_variable: "books",
423
- },
424
- });
425
- });
426
- (0, globals_1.it)("should run", async () => {
427
- const user = await user_1.default.findOne({ id: 1 });
428
- (0, assertions_1.assertIsSet)(user);
429
- const trigger = trigger_1.default.findOne({ name: "wfrunaction" });
430
- (0, assertions_1.assertIsSet)(trigger);
431
- const wfrun = await workflow_run_1.default.create({
432
- trigger_id: trigger.id,
433
- context: { thepub: 2 },
434
- });
435
- await wfrun.run({ user });
436
- (0, globals_1.expect)(wfrun.context.foo.x).toBe(1);
437
- (0, globals_1.expect)(wfrun.context.books.length).toBe(1);
438
- (0, globals_1.expect)(wfrun.context.books[0].pages).toBe(124);
439
- (0, globals_1.expect)(wfrun.context.books[0].author).toBe("Mary Contrary");
440
- (0, globals_1.expect)(wfrun.context.books[0].publisher).toBe(2);
441
- });
442
- (0, globals_1.it)("should dereference key row fields", async () => {
443
- const user = await user_1.default.findOne({ id: 1 });
444
- (0, assertions_1.assertIsSet)(user);
445
- const table = table_1.default.findOne({ name: "books" });
446
- (0, assertions_1.assertIsSet)(table);
447
- await table.deleteRows({ pages: 124 });
448
- const trigger = trigger_1.default.findOne({ name: "wfrunaction" });
449
- (0, assertions_1.assertIsSet)(trigger);
450
- const wfrun = await workflow_run_1.default.create({
451
- trigger_id: trigger.id,
452
- context: { thepub: "No starch" },
453
- });
454
- await wfrun.run({ user });
455
- (0, globals_1.expect)(wfrun.context.foo.x).toBe(1);
456
- (0, globals_1.expect)(wfrun.context.books.length).toBe(1);
457
- (0, globals_1.expect)(wfrun.context.books[0].pages).toBe(124);
458
- (0, globals_1.expect)(wfrun.context.books[0].author).toBe("Mary Contrary");
459
- (0, globals_1.expect)(wfrun.context.books[0].publisher).toBe(2);
460
- });
461
- });
462
- (0, globals_1.describe)("Workflow run userform", () => {
463
- (0, globals_1.it)("should create steps", async () => {
464
- const trigger = await trigger_1.default.create({
465
- action: "Workflow",
466
- when_trigger: "Never",
467
- name: "uformwf",
468
- });
469
- await workflow_step_1.default.create({
470
- trigger_id: trigger.id,
471
- name: "first_step",
472
- next_step: "second_step",
473
- action_name: "run_js_code",
474
- initial_step: true,
475
- configuration: { code: `return {x:1}` },
476
- });
477
- await workflow_step_1.default.create({
478
- trigger_id: trigger.id,
479
- name: "second_step",
480
- next_step: "third",
481
- action_name: "UserForm",
482
- initial_step: false,
483
- configuration: {
484
- form_header: "",
485
- user_id_expression: "",
486
- user_form_questions: [
487
- {
488
- label: "What is your name",
489
- qtype: "Free text",
490
- var_name: "name",
491
- },
492
- ],
493
- },
494
- });
495
- await workflow_step_1.default.create({
496
- trigger_id: trigger.id,
497
- name: "third",
498
- next_step: "",
499
- action_name: "Output",
500
- initial_step: false,
501
- configuration: {
502
- markdown: false,
503
- output_text: "hello {{name}}",
504
- },
505
- });
506
- });
507
- (0, globals_1.it)("should run", async () => {
508
- const user = await user_1.default.findOne({ id: 1 });
509
- (0, assertions_1.assertIsSet)(user);
510
- const trigger = trigger_1.default.findOne({ name: "uformwf" });
511
- (0, assertions_1.assertIsSet)(trigger);
512
- const wfrun = await workflow_run_1.default.create({
513
- trigger_id: trigger.id,
514
- });
515
- await wfrun.run({ user });
516
- (0, globals_1.expect)(wfrun.context.x).toBe(1);
517
- (0, globals_1.expect)(wfrun.status).toBe("Waiting");
518
- (0, globals_1.expect)(wfrun.wait_info).toStrictEqual({ form: true, user_id: 1 });
519
- await wfrun.provide_form_input({ name: "Tom" });
520
- await wfrun.run({
521
- user,
522
- });
523
- (0, globals_1.expect)(wfrun.status).toBe("Waiting");
524
- (0, globals_1.expect)(wfrun.context.name).toBe("Tom");
525
- (0, globals_1.expect)(wfrun.wait_info.output).toBe("hello Tom");
526
- await wfrun.provide_form_input({});
527
- await wfrun.run({
528
- user,
529
- });
530
- (0, globals_1.expect)(wfrun.status).toBe("Finished");
531
- });
532
- (0, globals_1.it)("should run interactively", async () => {
533
- const user = await user_1.default.findOne({ id: 1 });
534
- (0, assertions_1.assertIsSet)(user);
535
- const trigger = trigger_1.default.findOne({ name: "uformwf" });
536
- (0, assertions_1.assertIsSet)(trigger);
537
- const wfrun = await workflow_run_1.default.create({
538
- trigger_id: trigger.id,
539
- });
540
- const runres0 = await wfrun.run({ user, interactive: true });
541
- (0, globals_1.expect)(runres0.popup).toContain("/actions/fill-workflow-form/");
542
- (0, globals_1.expect)(runres0.popup).toContain("?resume=");
543
- (0, globals_1.expect)(wfrun.context.x).toBe(1);
544
- (0, globals_1.expect)(wfrun.status).toBe("Waiting");
545
- (0, globals_1.expect)(wfrun.wait_info).toStrictEqual({ form: true, user_id: 1 });
546
- await wfrun.provide_form_input({ name: "Tom" });
547
- const runres1 = await wfrun.run({
548
- user,
549
- interactive: true,
550
- });
551
- (0, globals_1.expect)(runres1.popup).toContain("/actions/fill-workflow-form/");
552
- (0, globals_1.expect)(runres1.popup).toContain("?resume=");
553
- (0, globals_1.expect)(wfrun.status).toBe("Waiting");
554
- (0, globals_1.expect)(wfrun.wait_info.output).toBe("hello Tom");
555
- (0, globals_1.expect)(wfrun.context.name).toBe("Tom");
556
- await wfrun.provide_form_input({});
557
- await wfrun.run({
558
- user,
559
- });
560
- (0, globals_1.expect)(wfrun.status).toBe("Finished");
561
- });
562
- (0, globals_1.it)("should skip form on only-if", async () => {
563
- const trigger = await trigger_1.default.create({
564
- action: "Workflow",
565
- when_trigger: "Never",
566
- name: "uformwf0",
567
- });
568
- await workflow_step_1.default.create({
569
- trigger_id: trigger.id,
570
- name: "first_step",
571
- next_step: "second_step",
572
- action_name: "run_js_code",
573
- initial_step: true,
574
- configuration: { code: `return {x:1}` },
575
- });
576
- await workflow_step_1.default.create({
577
- trigger_id: trigger.id,
578
- name: "second_step",
579
- next_step: "third",
580
- action_name: "UserForm",
581
- initial_step: false,
582
- only_if: "x>5",
583
- configuration: {
584
- form_header: "",
585
- user_id_expression: "",
586
- user_form_questions: [
587
- {
588
- label: "What is your name",
589
- qtype: "Free text",
590
- var_name: "name",
591
- },
592
- ],
593
- },
594
- });
595
- await workflow_step_1.default.create({
596
- trigger_id: trigger.id,
597
- name: "third",
598
- next_step: "",
599
- action_name: "run_js_code",
600
- initial_step: false,
601
- configuration: { code: `return {x:2}` },
602
- });
603
- const user = await user_1.default.findOne({ id: 1 });
604
- (0, assertions_1.assertIsSet)(user);
605
- const wfrun = await workflow_run_1.default.create({
606
- trigger_id: trigger.id,
607
- });
608
- await wfrun.run({ user });
609
- (0, globals_1.expect)(wfrun.context.x).toBe(2);
610
- (0, globals_1.expect)(wfrun.status).toBe("Finished");
611
- });
612
- });
613
- (0, globals_1.describe)("Workflow step operations", () => {
614
- (0, globals_1.it)("should generate a diagram", async () => {
615
- const trigger = await trigger_1.default.create({
616
- action: "Workflow",
617
- when_trigger: "Never",
618
- name: "diagramTrigger",
619
- });
620
- await workflow_step_1.default.create({
621
- trigger_id: trigger.id,
622
- name: "startStep",
623
- next_step: "endStep",
624
- action_name: "SetContext",
625
- initial_step: true,
626
- configuration: { ctx_values: "{x: 1}" },
627
- });
628
- await workflow_step_1.default.create({
629
- trigger_id: trigger.id,
630
- name: "endStep",
631
- initial_step: false,
632
- action_name: "SetContext",
633
- configuration: { ctx_values: "{y: 2}" },
634
- });
635
- const steps = await workflow_step_1.default.find({ trigger_id: trigger.id });
636
- const diagram = workflow_step_1.default.generate_diagram(steps);
637
- (0, globals_1.expect)(diagram).toContain("startStep");
638
- (0, globals_1.expect)(diagram).toContain("endStep");
639
- });
640
- (0, globals_1.it)("should handle delete with connect_prev_next", async () => {
641
- const trigger = await trigger_1.default.create({
642
- action: "Workflow",
643
- when_trigger: "Never",
644
- name: "deleteTrigger",
645
- });
646
- await workflow_step_1.default.create({
647
- trigger_id: trigger.id,
648
- name: "step1",
649
- next_step: "step2",
650
- action_name: "SetContext",
651
- initial_step: true,
652
- configuration: { ctx_values: "{x: 1}" },
653
- });
654
- await workflow_step_1.default.create({
655
- trigger_id: trigger.id,
656
- name: "step2",
657
- next_step: "step3",
658
- action_name: "SetContext",
659
- initial_step: false,
660
- configuration: { ctx_values: "{y: 2}" },
661
- });
662
- await workflow_step_1.default.create({
663
- trigger_id: trigger.id,
664
- name: "step3",
665
- action_name: "SetContext",
666
- initial_step: false,
667
- configuration: { ctx_values: "{z: 3}" },
668
- });
669
- const step2 = await workflow_step_1.default.findOne({ name: "step2" });
670
- (0, assertions_1.assertIsSet)(step2);
671
- await step2.delete(true);
672
- const updatedStep1 = await workflow_step_1.default.findOne({ name: "step1" });
673
- (0, assertions_1.assertIsSet)(updatedStep1);
674
- (0, globals_1.expect)(updatedStep1.next_step).toBe("step3");
675
- });
676
- (0, globals_1.it)("should find steps with specific conditions", async () => {
677
- const trigger = await trigger_1.default.create({
678
- action: "Workflow",
679
- when_trigger: "Never",
680
- name: "findTrigger",
681
- });
682
- await workflow_step_1.default.create({
683
- trigger_id: trigger.id,
684
- name: "findStep1",
685
- next_step: "findStep2",
686
- action_name: "SetContext",
687
- initial_step: true,
688
- configuration: { ctx_values: "{x: 1}" },
689
- });
690
- await workflow_step_1.default.create({
691
- trigger_id: trigger.id,
692
- name: "findStep2",
693
- action_name: "SetContext",
694
- initial_step: false,
695
- configuration: { ctx_values: "{y: 2}" },
696
- });
697
- const steps = await workflow_step_1.default.find({ trigger_id: trigger.id });
698
- (0, globals_1.expect)(steps.length).toBe(2);
699
- (0, globals_1.expect)(steps[0].name).toBe("findStep1");
700
- (0, globals_1.expect)(steps[1].name).toBe("findStep2");
701
- });
702
- // More tests for update, delete, and 'get diagram loop link backs'
703
- (0, globals_1.it)("should update a workflow steop", async () => {
704
- const trigger = await trigger_1.default.create({
705
- action: "Workflow",
706
- when_trigger: "Never",
707
- name: "updateTrigger",
708
- });
709
- const step = await workflow_step_1.default.create({
710
- trigger_id: trigger.id,
711
- name: "updateStep",
712
- next_step: "nextStep",
713
- action_name: "SetContext",
714
- initial_step: true,
715
- configuration: { ctx_values: "{x: 1}" },
716
- });
717
- const fetchedStep = await workflow_step_1.default.findOne({ name: "updateStep" });
718
- (0, assertions_1.assertIsSet)(fetchedStep);
719
- await fetchedStep.update({
720
- next_step: "updatedNextStep",
721
- });
722
- const updatedStep = await workflow_step_1.default.findOne({ name: "updateStep" });
723
- (0, assertions_1.assertIsSet)(updatedStep);
724
- (0, globals_1.expect)(updatedStep.next_step).toBe("updatedNextStep");
725
- });
726
- (0, globals_1.it)("should get diagram loop link backs", async () => {
727
- const trigger = await trigger_1.default.create({
728
- action: "Workflow",
729
- when_trigger: "Never",
730
- name: "loopTrigger",
731
- });
732
- await workflow_step_1.default.create({
733
- trigger_id: trigger.id,
734
- name: "forLoopStep",
735
- action_name: "ForLoop",
736
- initial_step: true,
737
- configuration: {
738
- loop_body_initial_step: "loopBodyStep",
739
- },
740
- });
741
- await workflow_step_1.default.create({
742
- trigger_id: trigger.id,
743
- name: "loopBodyStep",
744
- next_step: "endStep",
745
- action_name: "SetContext",
746
- initial_step: false,
747
- configuration: { ctx_values: `return {y: 2}` },
748
- });
749
- await workflow_step_1.default.create({
750
- trigger_id: trigger.id,
751
- name: "endStep",
752
- action_name: "SetContext",
753
- initial_step: false,
754
- configuration: { ctx_values: `return {z: 3}` },
755
- });
756
- const steps = await workflow_step_1.default.find({ trigger_id: trigger.id });
757
- const loopLinks = workflow_step_1.default.getDiagramLoopLinkBacks(steps);
758
- (0, globals_1.expect)(loopLinks["endStep"]).toBe("forLoopStep");
759
- });
760
- (0, globals_1.it)("should delet a workflow step and connect previous to next", async () => {
761
- const trigger = await trigger_1.default.create({
762
- action: "Workflow",
763
- when_trigger: "Never",
764
- name: "deleteConnectTrigger",
765
- });
766
- await workflow_step_1.default.create({
767
- trigger_id: trigger.id,
768
- name: "stepA",
769
- next_step: "stepB",
770
- action_name: "SetContext",
771
- initial_step: true,
772
- configuration: { ctx_values: "{x: 1}" },
773
- });
774
- await workflow_step_1.default.create({
775
- trigger_id: trigger.id,
776
- name: "stepB",
777
- next_step: "stepC",
778
- action_name: "SetContext",
779
- initial_step: false,
780
- configuration: { ctx_values: "{y: 2}" },
781
- });
782
- await workflow_step_1.default.create({
783
- trigger_id: trigger.id,
784
- name: "stepC",
785
- action_name: "SetContext",
786
- initial_step: false,
787
- configuration: { ctx_values: "{z: 3}" },
788
- });
789
- const stepB = await workflow_step_1.default.findOne({ name: "stepB" });
790
- (0, assertions_1.assertIsSet)(stepB);
791
- await stepB.delete(true);
792
- const updatedStepA = await workflow_step_1.default.findOne({ name: "stepA" });
793
- (0, assertions_1.assertIsSet)(updatedStepA);
794
- (0, globals_1.expect)(updatedStepA.next_step).toBe("stepC");
795
- });
796
- (0, globals_1.it)("should handle reserved names in mermaid diagram generation", async () => {
797
- const trigger = await trigger_1.default.create({
798
- action: "Workflow",
799
- when_trigger: "Never",
800
- name: "reservedNamesTrigger",
801
- });
802
- await workflow_step_1.default.create({
803
- trigger_id: trigger.id,
804
- name: "end",
805
- next_step: "subgraph",
806
- action_name: "SetContext",
807
- initial_step: true,
808
- configuration: { ctx_values: "{x: 1}" },
809
- });
810
- await workflow_step_1.default.create({
811
- trigger_id: trigger.id,
812
- name: "subgraph",
813
- action_name: "SetContext",
814
- initial_step: false,
815
- configuration: { ctx_values: "{y: 2}" },
816
- });
817
- const steps = await workflow_step_1.default.find({ trigger_id: trigger.id });
818
- const diagram = workflow_step_1.default.generate_diagram(steps);
819
- (0, globals_1.expect)(diagram).toContain("flowchart TD");
820
- (0, globals_1.expect)(diagram).toContain('_end_["`**end**\n SetContext`"]:::wfstep');
821
- (0, globals_1.expect)(diagram).toContain('_subgraph_["`**subgraph**\n SetContext`"]:::wfstep');
822
- (0, globals_1.expect)(diagram).toContain("_Start--");
823
- (0, globals_1.expect)(diagram).toContain("--> _End__subgraph_");
824
- });
825
- });
826
- //# sourceMappingURL=workflow_run.test.js.map