@saltcorn/data 1.6.0-beta.7 → 1.6.0-beta.9

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 (46) hide show
  1. package/dist/base-plugin/actions.d.ts +189 -62
  2. package/dist/base-plugin/actions.d.ts.map +1 -1
  3. package/dist/base-plugin/actions.js +151 -58
  4. package/dist/base-plugin/actions.js.map +1 -1
  5. package/dist/base-plugin/index.d.ts +189 -62
  6. package/dist/base-plugin/index.d.ts.map +1 -1
  7. package/dist/base-plugin/viewtemplates/list.d.ts.map +1 -1
  8. package/dist/base-plugin/viewtemplates/list.js +1 -0
  9. package/dist/base-plugin/viewtemplates/list.js.map +1 -1
  10. package/dist/db/state.d.ts.map +1 -1
  11. package/dist/db/state.js +9 -0
  12. package/dist/db/state.js.map +1 -1
  13. package/dist/models/expression.d.ts.map +1 -1
  14. package/dist/models/expression.js +20 -9
  15. package/dist/models/expression.js.map +1 -1
  16. package/dist/models/field.d.ts.map +1 -1
  17. package/dist/models/field.js +5 -2
  18. package/dist/models/field.js.map +1 -1
  19. package/dist/models/page.d.ts.map +1 -1
  20. package/dist/models/page.js +31 -19
  21. package/dist/models/page.js.map +1 -1
  22. package/dist/models/plugin.d.ts.map +1 -1
  23. package/dist/models/plugin.js +4 -1
  24. package/dist/models/plugin.js.map +1 -1
  25. package/dist/models/table.d.ts.map +1 -1
  26. package/dist/models/table.js +2 -1
  27. package/dist/models/table.js.map +1 -1
  28. package/dist/models/trigger.d.ts +1 -0
  29. package/dist/models/trigger.d.ts.map +1 -1
  30. package/dist/models/trigger.js +9 -0
  31. package/dist/models/trigger.js.map +1 -1
  32. package/dist/models/workflow_run.d.ts.map +1 -1
  33. package/dist/models/workflow_run.js +2 -1
  34. package/dist/models/workflow_run.js.map +1 -1
  35. package/dist/models/workflow_step.d.ts +1 -1
  36. package/dist/models/workflow_step.d.ts.map +1 -1
  37. package/dist/models/workflow_step.js +2 -1
  38. package/dist/models/workflow_step.js.map +1 -1
  39. package/dist/utils.d.ts +2 -0
  40. package/dist/utils.d.ts.map +1 -1
  41. package/dist/utils.js +25 -5
  42. package/dist/utils.js.map +1 -1
  43. package/dist/viewable_fields.d.ts.map +1 -1
  44. package/dist/viewable_fields.js +4 -0
  45. package/dist/viewable_fields.js.map +1 -1
  46. package/package.json +9 -8
@@ -279,28 +279,64 @@ module.exports = {
279
279
  * @returns {object[]}
280
280
  */
281
281
  description: "Emit an event",
282
- configFields: () => [
283
- {
284
- name: "eventType",
285
- label: "Event type",
286
- required: true,
287
- input_type: "select",
288
- options: trigger_1.default.when_options,
289
- },
290
- {
291
- name: "channel",
292
- label: "Channel",
293
- type: "String",
294
- fieldview: "textarea",
295
- },
296
- {
297
- name: "payload",
298
- label: "Payload JSON",
299
- sublabel: "Leave blank to use row from table",
300
- type: "String",
301
- fieldview: "textarea",
302
- },
303
- ],
282
+ configFields: async ({ table }) => {
283
+ const evTypes = trigger_1.default.when_options;
284
+ const hasChannel = [];
285
+ const hasTable = [];
286
+ evTypes.forEach((ty) => {
287
+ if (eventlog_1.default.hasChannel(ty))
288
+ hasChannel.push(ty);
289
+ if (eventlog_1.default.hasTable(ty))
290
+ hasTable.push(ty);
291
+ });
292
+ const allTables = await table_1.default.find({}, { cached: true });
293
+ return [
294
+ {
295
+ name: "eventType",
296
+ label: "Event type",
297
+ required: true,
298
+ input_type: "select",
299
+ options: evTypes,
300
+ },
301
+ {
302
+ name: "channel",
303
+ label: "Channel",
304
+ type: "String",
305
+ showIf: { eventType: hasChannel },
306
+ help: {
307
+ topic: "Event channel and payload",
308
+ },
309
+ },
310
+ {
311
+ name: "channel",
312
+ label: "Table",
313
+ type: "String",
314
+ showIf: { eventType: hasTable },
315
+ required: true,
316
+ attributes: { options: allTables.map((t) => t.name) },
317
+ help: {
318
+ topic: "Event channel and payload",
319
+ },
320
+ },
321
+ {
322
+ name: "payload",
323
+ label: "Payload JSON",
324
+ sublabel: `Leave blank to use row from table. <code>user</code> ${table ? `and field variables ` : ""}in scope`,
325
+ input_type: "code",
326
+ attributes: {
327
+ mode: "application/javascript",
328
+ compact: true,
329
+ expression_type: "row",
330
+ table: table?.name,
331
+ nojoins: true,
332
+ user: true,
333
+ },
334
+ help: {
335
+ topic: "Event channel and payload",
336
+ },
337
+ },
338
+ ];
339
+ },
304
340
  /**
305
341
  * @param {object} opts
306
342
  * @param {object} opts.row
@@ -338,7 +374,7 @@ module.exports = {
338
374
  {
339
375
  name: "where",
340
376
  label: "Where",
341
- sublabel: "Where-expression for subset of rows to loop over",
377
+ sublabel: `Where-expression for subset of rows to loop over. For example: <code>{status: "Active"}</code>`,
342
378
  input_type: "code",
343
379
  attributes: {
344
380
  mode: "application/javascript",
@@ -443,7 +479,7 @@ module.exports = {
443
479
  name: "url",
444
480
  label: "URL",
445
481
  type: "String",
446
- sublabel: "Trigger will call specified URL",
482
+ sublabel: "Trigger will call specified URL. Interpolations <code>{{ }}</code> can be used",
447
483
  },
448
484
  {
449
485
  name: "method",
@@ -455,16 +491,23 @@ module.exports = {
455
491
  {
456
492
  name: "body",
457
493
  label: "JSON body",
458
- sublabel: "Leave blank to use row from table",
459
- type: "String",
460
- fieldview: "textarea",
461
494
  showIf: { method: ["POST", "PUT", "DELETE", "PATCH"] },
495
+ sublabel: `Leave blank to use row from table.${table ? ` <code>user</code> and field variables in scope` : ""}`,
496
+ input_type: "code",
497
+ attributes: {
498
+ mode: "application/javascript",
499
+ compact: true,
500
+ expression_type: "row",
501
+ table: table?.name,
502
+ nojoins: true,
503
+ user: true,
504
+ },
462
505
  },
463
506
  {
464
507
  name: "authorization",
465
508
  label: "Authorization header",
466
509
  type: "String",
467
- sublabel: "For example <code>Bearer xxxx</code>",
510
+ sublabel: "For example <code>Bearer xxxx</code>. Interpolations <code>{{ }}</code> can be used",
468
511
  },
469
512
  ...(field_opts.length
470
513
  ? [
@@ -495,7 +538,7 @@ module.exports = {
495
538
  * @returns {Promise<object>}
496
539
  */
497
540
  run: async ({ row, user, table, configuration: { url, body, authorization, response_field, response_var, method, }, }) => {
498
- let url1 = interpolate(url, row, user, "Webhook URL");
541
+ let url1 = interpolate(url, row || {}, user, "Webhook URL");
499
542
  const fetchOpts = {
500
543
  method: (method || "post").toLowerCase(),
501
544
  headers: { "Content-Type": "application/json" },
@@ -1087,12 +1130,13 @@ module.exports = {
1087
1130
  {
1088
1131
  name: "where",
1089
1132
  label: "Recalculate where",
1090
- sublabel: "Where-expression for subset of rows to recalculate",
1133
+ sublabel: "Where-expression for subset of rows to recalculate. Example: <code>{manager: id}</code>",
1091
1134
  input_type: "code",
1092
1135
  attributes: {
1093
1136
  mode: "application/javascript",
1094
1137
  singleline: true,
1095
1138
  expression_type: "query",
1139
+ ...(table ? { table: table.name } : {}),
1096
1140
  },
1097
1141
  },
1098
1142
  ];
@@ -1137,7 +1181,7 @@ module.exports = {
1137
1181
  * @returns {Promise<object[]>}
1138
1182
  */
1139
1183
  description: "insert a row into any table, using a formula expression",
1140
- configFields: async ({ mode }) => {
1184
+ configFields: async ({ mode, table }) => {
1141
1185
  const tables = await table_1.default.find({}, { cached: true });
1142
1186
  return [
1143
1187
  {
@@ -1151,11 +1195,14 @@ module.exports = {
1151
1195
  name: "row_expr",
1152
1196
  label: "Row expression",
1153
1197
  sublabel: "Expression for JavaScript object or array of objects. Example: <code>{first_name: name.split(' ')[0]}</code>",
1154
- type: "String",
1155
- fieldview: "textarea",
1156
- class: "validate-expression",
1198
+ input_type: "code",
1157
1199
  attributes: {
1158
- spellcheck: false,
1200
+ mode: "application/javascript",
1201
+ compact: true,
1202
+ expression_type: "row",
1203
+ table: table?.name,
1204
+ nojoins: true,
1205
+ user: true,
1159
1206
  },
1160
1207
  },
1161
1208
  ...(mode === "workflow"
@@ -1233,7 +1280,7 @@ module.exports = {
1233
1280
  */
1234
1281
  modify_row: {
1235
1282
  description: "Modify the triggering row",
1236
- configFields: async ({ mode, when_trigger, }) => {
1283
+ configFields: async ({ mode, when_trigger, table, }) => {
1237
1284
  return [
1238
1285
  {
1239
1286
  name: "row_expr",
@@ -1244,6 +1291,9 @@ module.exports = {
1244
1291
  mode: "application/javascript",
1245
1292
  compact: true,
1246
1293
  expression_type: "row",
1294
+ table: table?.name,
1295
+ nojoins: true,
1296
+ user: true,
1247
1297
  },
1248
1298
  },
1249
1299
  ...(mode === "edit" ||
@@ -1334,7 +1384,7 @@ module.exports = {
1334
1384
  * @returns {Promise<object[]>}
1335
1385
  */
1336
1386
  description: "Modify the triggering row",
1337
- configFields: async ({ mode, when_trigger }) => {
1387
+ configFields: async ({ mode, table, when_trigger }) => {
1338
1388
  const tables = await table_1.default.find({}, { cached: true });
1339
1389
  return [
1340
1390
  ...(mode === "workflow"
@@ -1357,10 +1407,15 @@ module.exports = {
1357
1407
  {
1358
1408
  name: "delete_where",
1359
1409
  label: "Delete where",
1360
- type: "String",
1410
+ input_type: "code",
1411
+ attributes: {
1412
+ mode: "application/javascript",
1413
+ singleline: true,
1414
+ expression_type: "query",
1415
+ ...(table ? { table: table.name } : {}),
1416
+ },
1361
1417
  sublabel: "Where expression, ex. <code>{manager: id}</code>",
1362
1418
  required: true,
1363
- class: "validate-expression",
1364
1419
  showIf: mode === "workflow" ? undefined : { delete_triggering_row: false },
1365
1420
  },
1366
1421
  ];
@@ -1373,7 +1428,7 @@ module.exports = {
1373
1428
  await table.deleteRows({ [table.pk_name]: row[table.pk_name] }, user, false, resultCollector);
1374
1429
  return resultCollector;
1375
1430
  }
1376
- const where = eval_expression(delete_where, row || {}, user, "recalculate_stored_fields where");
1431
+ const where = eval_expression(delete_where, row || {}, user, "delete_rows where");
1377
1432
  const tbl = table_1.default.findOne({ name: table_name });
1378
1433
  await tbl.deleteRows(where, user, false, resultCollector);
1379
1434
  return resultCollector;
@@ -1392,7 +1447,7 @@ module.exports = {
1392
1447
  * @returns {Promise<object[]>}
1393
1448
  */
1394
1449
  description: "Navigation action",
1395
- configFields: async () => {
1450
+ configFields: async ({ table }) => {
1396
1451
  const pages = await page_1.default.find({}, { cached: true });
1397
1452
  const views = await view_1.default.find({}, { cached: true });
1398
1453
  return [
@@ -1420,6 +1475,7 @@ module.exports = {
1420
1475
  type: "String",
1421
1476
  required: true,
1422
1477
  showIf: { nav_action: ["Go to URL", "Popup modal"] },
1478
+ sublabel: "Use interpolations <code>{{ }}</code> to access row variables",
1423
1479
  },
1424
1480
  {
1425
1481
  name: "page",
@@ -1438,9 +1494,20 @@ module.exports = {
1438
1494
  {
1439
1495
  name: "state_formula",
1440
1496
  label: "State",
1441
- type: "String",
1442
- class: "validate-expression",
1497
+ input_type: "code",
1498
+ attributes: {
1499
+ mode: "application/javascript",
1500
+ singleline: true,
1501
+ expression_type: "query",
1502
+ ...(table ? { table: table.name } : {}),
1503
+ },
1443
1504
  showIf: { nav_action: ["Go to Page", "Go to View"] },
1505
+ sublabel: `Additional state passed to the page. Example: <code>{id: 5}</code>`,
1506
+ help: {
1507
+ topic: "Extra state formula",
1508
+ context: table ? { srcTable: table.name } : {},
1509
+ dynContext: ["view"],
1510
+ },
1444
1511
  },
1445
1512
  {
1446
1513
  name: "new_tab",
@@ -1551,18 +1618,26 @@ module.exports = {
1551
1618
  {
1552
1619
  name: "form_action",
1553
1620
  label: "Form Action",
1554
- type: "String",
1621
+ input_type: "select",
1555
1622
  required: true,
1556
1623
  attributes: {
1557
- options: [
1558
- "RequestSubmit",
1559
- "Submit",
1560
- "Save",
1561
- "Reset",
1562
- "Submit with Ajax",
1563
- "Ajax Save Form Data",
1564
- ],
1624
+ explainers: {
1625
+ RequestSubmit: "Validate the form, and submit if no errors, or display errors",
1626
+ Submit: "Submit the form, skipping validation",
1627
+ Save: "Save the form contents on the server, stay on the form page",
1628
+ Reset: "Reset the form to the state it was in at page load time",
1629
+ "Submit with Ajax": "Submit the form with Ajax and follow the set destination if there are no errors",
1630
+ "Ajax Save Form Data": "Submit the form with Ajax and close the open popup ",
1631
+ },
1565
1632
  },
1633
+ options: [
1634
+ "RequestSubmit",
1635
+ "Submit",
1636
+ "Save",
1637
+ "Reset",
1638
+ "Submit with Ajax",
1639
+ "Ajax Save Form Data",
1640
+ ],
1566
1641
  },
1567
1642
  ],
1568
1643
  run: async ({ row, table, user, req, configuration: { form_action }, ...rest }) => {
@@ -1684,12 +1759,13 @@ module.exports = {
1684
1759
  label: "Text",
1685
1760
  type: "String",
1686
1761
  required: true,
1762
+ sublabel: "Interpolations <code>{{ }}</code> can be used",
1687
1763
  },
1688
1764
  {
1689
1765
  name: "title",
1690
1766
  label: "Title",
1691
- sublabel: "Optional",
1692
1767
  type: "String",
1768
+ sublabel: "Optional. Interpolations <code>{{ }}</code> can be used",
1693
1769
  },
1694
1770
  {
1695
1771
  name: "remove_delay",
@@ -2173,7 +2249,7 @@ module.exports = {
2173
2249
  },
2174
2250
  reload_embedded_view: {
2175
2251
  description: "Reload an embedded view without full page reload",
2176
- configFields: async () => {
2252
+ configFields: async ({ table }) => {
2177
2253
  const views = await view_1.default.find({});
2178
2254
  return [
2179
2255
  {
@@ -2187,8 +2263,19 @@ module.exports = {
2187
2263
  {
2188
2264
  name: "new_state_fml",
2189
2265
  label: "New state formula",
2190
- type: "String",
2191
- class: "validate-expression",
2266
+ input_type: "code",
2267
+ attributes: {
2268
+ mode: "application/javascript",
2269
+ singleline: true,
2270
+ expression_type: "row",
2271
+ ...(table ? { table: table.name } : {}),
2272
+ },
2273
+ sublabel: `Optional. Updated view state. Example: <code>{id: 5}</code>. Leave blank to keep existing state`,
2274
+ help: {
2275
+ topic: "Extra state formula",
2276
+ context: table ? { srcTable: table.name } : {},
2277
+ dynContext: ["view"],
2278
+ },
2192
2279
  },
2193
2280
  {
2194
2281
  name: "interval",
@@ -2232,7 +2319,7 @@ module.exports = {
2232
2319
  type: "String",
2233
2320
  class: "validate-identifier",
2234
2321
  required: true,
2235
- sublabel: "A valid JavaScript identifier for updating existing progress toasts",
2322
+ sublabel: "A valid JavaScript identifier for updating existing progress toasts. Interpolations <code>{{ }}</code> can be used",
2236
2323
  showIf: { blocking: false },
2237
2324
  },
2238
2325
  {
@@ -2253,12 +2340,14 @@ module.exports = {
2253
2340
  label: "Title",
2254
2341
  type: "String",
2255
2342
  showIf: { close: false },
2343
+ sublabel: "Use interpolations <code>{{ }}</code> to access row variables",
2256
2344
  },
2257
2345
  {
2258
2346
  name: "message",
2259
2347
  label: "Message",
2260
2348
  type: "String",
2261
2349
  showIf: { close: false },
2350
+ sublabel: "Use interpolations <code>{{ }}</code> to access row variables",
2262
2351
  },
2263
2352
  {
2264
2353
  name: "percent",
@@ -2330,27 +2419,31 @@ module.exports = {
2330
2419
  },
2331
2420
  notify_user: {
2332
2421
  description: "Send a notification to a specific user",
2333
- configFields: () => [
2422
+ configFields: ({ table }) => [
2334
2423
  {
2335
2424
  name: "user_spec",
2336
2425
  label: "User where or email",
2337
2426
  type: "String",
2427
+ sublabel: `Valid input: <code>*</code> for all, a valid email address, or a where object, e.g. <code>{department: "Finance"}</code>${table ? ". Row values are in scope for where object." : ""}`,
2338
2428
  },
2339
2429
  {
2340
2430
  name: "title",
2341
2431
  label: "Title",
2342
2432
  required: true,
2343
2433
  type: "String",
2434
+ sublabel: "<code>{{ }}</code> interpolations usable",
2344
2435
  },
2345
2436
  {
2346
2437
  name: "body",
2347
2438
  label: "Body",
2348
2439
  type: "String",
2440
+ sublabel: "<code>{{ }}</code> interpolations usable",
2349
2441
  },
2350
2442
  {
2351
2443
  name: "link",
2352
2444
  label: "Link",
2353
2445
  type: "String",
2446
+ sublabel: "<code>{{ }}</code> interpolations usable",
2354
2447
  },
2355
2448
  ],
2356
2449
  /**