@saltcorn/data 0.6.1-beta.0 → 0.6.1

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 (60) hide show
  1. package/base-plugin/actions.js +172 -1
  2. package/base-plugin/fieldviews.js +63 -0
  3. package/base-plugin/fileviews.js +41 -0
  4. package/base-plugin/index.js +35 -0
  5. package/base-plugin/types.js +345 -9
  6. package/base-plugin/viewtemplates/edit.js +107 -0
  7. package/base-plugin/viewtemplates/feed.js +46 -0
  8. package/base-plugin/viewtemplates/filter.js +43 -0
  9. package/base-plugin/viewtemplates/list.js +73 -1
  10. package/base-plugin/viewtemplates/listshowlist.js +54 -3
  11. package/base-plugin/viewtemplates/room.js +100 -0
  12. package/base-plugin/viewtemplates/show.js +86 -0
  13. package/base-plugin/viewtemplates/viewable_fields.js +124 -0
  14. package/contracts.js +58 -0
  15. package/db/connect.js +13 -5
  16. package/db/db.test.js +0 -154
  17. package/db/fixtures.js +13 -1
  18. package/db/index.js +42 -3
  19. package/db/reset_schema.js +11 -0
  20. package/db/state.js +105 -36
  21. package/index.js +13 -0
  22. package/migrate.js +4 -1
  23. package/models/backup.js +78 -0
  24. package/models/config.js +113 -22
  25. package/models/crash.js +44 -0
  26. package/models/discovery.js +13 -11
  27. package/models/email.js +17 -0
  28. package/models/eventlog.js +51 -0
  29. package/models/expression.js +49 -1
  30. package/models/field.js +88 -9
  31. package/models/fieldrepeat.js +33 -0
  32. package/models/file.js +23 -4
  33. package/models/form.js +34 -0
  34. package/models/index.js +42 -0
  35. package/models/layout.js +33 -0
  36. package/models/library.js +44 -0
  37. package/models/pack.js +88 -0
  38. package/models/page.js +13 -3
  39. package/models/plugin.js +9 -2
  40. package/models/random.js +36 -0
  41. package/models/role.js +36 -0
  42. package/models/scheduler.js +28 -0
  43. package/models/table.js +34 -15
  44. package/models/table_constraints.js +44 -0
  45. package/models/tenant.js +46 -9
  46. package/models/trigger.js +24 -11
  47. package/models/user.js +33 -8
  48. package/models/view.js +89 -8
  49. package/models/workflow.js +31 -0
  50. package/package.json +7 -5
  51. package/plugin-helper.js +102 -44
  52. package/plugin-testing.js +4 -0
  53. package/tests/exact_views.test.js +5 -5
  54. package/utils.js +4 -0
  55. package/db/internal.js +0 -229
  56. package/db/multi-tenant.js +0 -24
  57. package/db/pg.js +0 -374
  58. package/db/single-tenant.js +0 -8
  59. package/db/sqlite.js +0 -280
  60. package/db/tenants.js +0 -6
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Action description
3
- *
3
+ * @category saltcorn-data
4
+ * @module base-plugin/actions
5
+ * @subcategory base-plugin
4
6
  */
5
7
 
6
8
  const fetch = require("node-fetch");
@@ -25,6 +27,16 @@ const db = require("../db");
25
27
  //action use cases: field modify, like/rate (insert join), notify, send row to webhook
26
28
  // todo add translation
27
29
 
30
+ /**
31
+ * @param {object} opts
32
+ * @param {object} opts.row
33
+ * @param {object} opts.table
34
+ * @param {object} opts.channel
35
+ * @param {object} opts.configuration
36
+ * @param {object} opts.user
37
+ * @param {...*} opts.rest
38
+ * @returns {Promise<object>}
39
+ */
28
40
  const run_code = async ({
29
41
  row,
30
42
  table,
@@ -79,6 +91,11 @@ const run_code = async ({
79
91
  };
80
92
 
81
93
  module.exports = {
94
+ /**
95
+ * @namespace
96
+ * @category saltcorn-data
97
+ * @subcategory actions
98
+ */
82
99
  blocks: {
83
100
  disableInBuilder: true,
84
101
  disableInList: true,
@@ -92,9 +109,22 @@ module.exports = {
92
109
  input_type: "hidden",
93
110
  },
94
111
  ],
112
+ /**
113
+ * @type {base-plugin/actions~run_code}
114
+ * @see base-plugin/actions~run_code
115
+ */
95
116
  run: run_code,
96
117
  },
118
+
119
+ /**
120
+ * @namespace
121
+ * @category saltcorn-data
122
+ * @subcategory actions
123
+ */
97
124
  emit_event: {
125
+ /**
126
+ * @returns {object[]}
127
+ */
98
128
  configFields: () => [
99
129
  {
100
130
  name: "eventType",
@@ -117,6 +147,13 @@ module.exports = {
117
147
  fieldview: "textarea",
118
148
  },
119
149
  ],
150
+ /**
151
+ * @param {object} opts
152
+ * @param {object} opts.row
153
+ * @param {object} opts.configuration
154
+ * @param {object} opts.user
155
+ * @returns {Promise<void>}
156
+ */
120
157
  run: async ({
121
158
  row,
122
159
  configuration: { eventType, channel, payload },
@@ -130,6 +167,12 @@ module.exports = {
130
167
  );
131
168
  },
132
169
  },
170
+
171
+ /**
172
+ * @namespace
173
+ * @category saltcorn-data
174
+ * @subcategory actions
175
+ */
133
176
  webhook: {
134
177
  configFields: [
135
178
  {
@@ -146,6 +189,12 @@ module.exports = {
146
189
  fieldview: "textarea", // I think that textarea is better
147
190
  },
148
191
  ],
192
+ /**
193
+ * @param {object} opts
194
+ * @param {string} opts.url
195
+ * @param {object} opts.body
196
+ * @returns {Promise<object>}
197
+ */
149
198
  run: async ({ row, configuration: { url, body } }) => {
150
199
  return await fetch(url, {
151
200
  method: "post",
@@ -154,7 +203,16 @@ module.exports = {
154
203
  });
155
204
  },
156
205
  },
206
+
207
+ /**
208
+ * @namespace
209
+ * @category saltcorn-data
210
+ * @subcategory actions
211
+ */
157
212
  find_or_create_dm_room: {
213
+ /**
214
+ * @returns {Promise<object[]>}
215
+ */
158
216
  configFields: async () => {
159
217
  const views = await View.find_all_views_where(
160
218
  ({ viewrow }) => viewrow.viewtemplate === "Room"
@@ -171,6 +229,15 @@ module.exports = {
171
229
  },
172
230
  ];
173
231
  },
232
+
233
+ /**
234
+ * @param {object} opts
235
+ * @param {object} opts.row
236
+ * @param {*} opts.table
237
+ * @param {object} opts.configuration
238
+ * @param {object} opts.user
239
+ * @returns {Promise<object>}
240
+ */
174
241
  run: async ({ row, table, configuration: { viewname }, user }) => {
175
242
  const view = await View.findOne({ name: viewname });
176
243
  const { participant_field } = view.configuration;
@@ -214,7 +281,18 @@ module.exports = {
214
281
  }
215
282
  },
216
283
  },
284
+
285
+ /**
286
+ * @namespace
287
+ * @category saltcorn-data
288
+ * @subcategory actions
289
+ */
217
290
  send_email: {
291
+ /**
292
+ * @param {object} opts
293
+ * @param {object} opts.table
294
+ * @returns {Promise<object[]>}
295
+ */
218
296
  configFields: async ({ table }) => {
219
297
  if (!table) return [];
220
298
  const views = await View.find_table_views_where(
@@ -277,6 +355,14 @@ module.exports = {
277
355
  ];
278
356
  },
279
357
  requireRow: true,
358
+ /**
359
+ * @param {object} opts
360
+ * @param {object} opts.row
361
+ * @param {object} opts.table
362
+ * @param {object} opts.configuration
363
+ * @param {object} opts.user
364
+ * @returns {Promise<object>}
365
+ */
280
366
  run: async ({
281
367
  row,
282
368
  table,
@@ -329,7 +415,18 @@ module.exports = {
329
415
  return { notify: `E-mail sent to ${to_addr}` };
330
416
  },
331
417
  },
418
+
419
+ /**
420
+ * @namespace
421
+ * @category saltcorn-data
422
+ * @subcategory actions
423
+ */
332
424
  insert_joined_row: {
425
+ /**
426
+ * @param {object} opts
427
+ * @param {object} opts.table
428
+ * @returns {Promise<object[]>}
429
+ */
333
430
  configFields: async ({ table }) => {
334
431
  if (!table) return [];
335
432
  const { child_field_list } = await table.get_child_relations();
@@ -344,6 +441,14 @@ module.exports = {
344
441
  ];
345
442
  },
346
443
  requireRow: true,
444
+ /**
445
+ * @param {object} opts
446
+ * @param {object} opts.row
447
+ * @param {object} opts.table
448
+ * @param {object} opts.configuration
449
+ * @param {object} opts.user
450
+ * @returns {Promise<object>}
451
+ */
347
452
  run: async ({ row, table, configuration: { joined_table }, user }) => {
348
453
  const [join_table_name, join_field] = joined_table.split(".");
349
454
  const joinTable = await Table.findOne({ name: join_table_name });
@@ -361,9 +466,25 @@ module.exports = {
361
466
  return await joinTable.insertRow(newRow);
362
467
  },
363
468
  },
469
+
470
+ /**
471
+ * @namespace
472
+ * @category saltcorn-data
473
+ * @subcategory actions
474
+ */
364
475
  duplicate_row: {
476
+ /**
477
+ * @returns {Promise<object[]>}
478
+ */
365
479
  configFields: () => [],
366
480
  requireRow: true,
481
+ /**
482
+ * @param {object} opts
483
+ * @param {object} opts.row
484
+ * @param {object} opts.table
485
+ * @param {*} opts.user
486
+ * @returns {Promise<object>}
487
+ */
367
488
  run: async ({ row, table, user }) => {
368
489
  const newRow = { ...row };
369
490
  await table.getFields();
@@ -372,7 +493,18 @@ module.exports = {
372
493
  return { reload_page: true };
373
494
  },
374
495
  },
496
+
497
+ /**
498
+ * @namespace
499
+ * @category saltcorn-data
500
+ * @subcategory actions
501
+ */
375
502
  recalculate_stored_fields: {
503
+ /**
504
+ * @param {object} opts
505
+ * @param {object} opts.table
506
+ * @returns {Promise<object[]>}
507
+ */
376
508
  configFields: async ({ table }) => {
377
509
  const tables = await Table.find();
378
510
  return [
@@ -385,12 +517,28 @@ module.exports = {
385
517
  },
386
518
  ];
387
519
  },
520
+ /**
521
+ * @param {object} opts
522
+ * @param {object} opts.configuration
523
+ * @returns {Promise<void>}
524
+ */
388
525
  run: async ({ configuration: { table } }) => {
389
526
  const table_for_recalc = await Table.findOne({ name: table });
390
527
  recalculate_for_stored(table_for_recalc);
391
528
  },
392
529
  },
530
+
531
+ /**
532
+ * @namespace
533
+ * @category saltcorn-data
534
+ * @subcategory actions
535
+ */
393
536
  insert_any_row: {
537
+ /**
538
+ * @param {object} opts
539
+ * @param {*} opts.table
540
+ * @returns {Promise<object[]>}
541
+ */
394
542
  configFields: async ({ table }) => {
395
543
  const tables = await Table.find();
396
544
  return [
@@ -410,6 +558,14 @@ module.exports = {
410
558
  },
411
559
  ];
412
560
  },
561
+ /**
562
+ * @param {object} opts
563
+ * @param {object} opts.row
564
+ * @param {object} opts.configuration
565
+ * @param {object} opts.user
566
+ * @param {...*} opts.rest
567
+ * @returns {Promise<object|boolean>}
568
+ */
413
569
  run: async ({ row, configuration: { row_expr, table }, user, ...rest }) => {
414
570
  const f = get_async_expression_function(row_expr, [], {
415
571
  row: row || {},
@@ -423,7 +579,18 @@ module.exports = {
423
579
  else return true;
424
580
  },
425
581
  },
582
+
583
+ /**
584
+ * @namespace
585
+ * @category saltcorn-data
586
+ * @subcategory actions
587
+ */
426
588
  run_js_code: {
589
+ /**
590
+ * @param {object} opts
591
+ * @param {object} opts.table
592
+ * @returns {Promise<object[]>}
593
+ */
427
594
  configFields: async ({ table }) => {
428
595
  const fields = table ? (await table.getFields()).map((f) => f.name) : [];
429
596
  const vars = [
@@ -453,6 +620,10 @@ module.exports = {
453
620
  },
454
621
  ];
455
622
  },
623
+ /**
624
+ * @type {base-plugin/actions~run_code}
625
+ * @see base-plugin/actions~run_code
626
+ **/
456
627
  run: run_code,
457
628
  },
458
629
  };
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @category saltcorn-data
3
+ * @module base-plugin/fieldviews
4
+ * @subcategory base-plugin
5
+ */
6
+
1
7
  const View = require("../models/view");
2
8
  const Table = require("../models/table");
3
9
  const {
@@ -12,9 +18,19 @@ const {
12
18
  const tags = require("@saltcorn/markup/tags");
13
19
  const { select_options, radio_group } = require("@saltcorn/markup/helpers");
14
20
 
21
+ /**
22
+ * select namespace
23
+ * @namespace
24
+ * @category saltcorn-data
25
+ */
15
26
  const select = {
27
+ /** @type {string} */
16
28
  type: "Key",
29
+ /** @type {boolean} */
17
30
  isEdit: true,
31
+ /**
32
+ * @type {object[]}
33
+ */
18
34
  configFields: () => [
19
35
  {
20
36
  name: "neutral_label",
@@ -29,6 +45,16 @@ const select = {
29
45
  type: "Bool",
30
46
  },
31
47
  ],
48
+
49
+ /**
50
+ * @param {*} nm
51
+ * @param {*} v
52
+ * @param {*} attrs
53
+ * @param {*} cls
54
+ * @param {*} reqd
55
+ * @param {*} field
56
+ * @returns {object}
57
+ */
32
58
  run: (nm, v, attrs, cls, reqd, field) => {
33
59
  if (attrs.disabled)
34
60
  return (
@@ -58,9 +84,25 @@ const select = {
58
84
  },
59
85
  };
60
86
 
87
+ /**
88
+ * radio_select namespace
89
+ * @namespace
90
+ * @category saltcorn-data
91
+ */
61
92
  const radio_select = {
93
+ /** @type {string} */
62
94
  type: "Key",
95
+ /** @type {boolean} */
63
96
  isEdit: true,
97
+ /**
98
+ * @param {*} nm
99
+ * @param {*} v
100
+ * @param {*} attrs
101
+ * @param {*} cls
102
+ * @param {*} reqd
103
+ * @param {*} field
104
+ * @returns {object}
105
+ */
64
106
  run: (nm, v, attrs, cls, reqd, field) =>
65
107
  radio_group({
66
108
  class: `${cls} ${field.class || ""}`,
@@ -70,9 +112,20 @@ const radio_select = {
70
112
  }),
71
113
  };
72
114
 
115
+ /**
116
+ * select namespace
117
+ * @namespace
118
+ * @category saltcorn-data
119
+ */
73
120
  const search_or_create = {
121
+ /** @type {string} */
74
122
  type: "Key",
123
+ /** @type {boolean} */
75
124
  isEdit: true,
125
+ /**
126
+ * @param {object} field
127
+ * @returns {Promise<object[]>}
128
+ */
76
129
  configFields: async (field) => {
77
130
  const reftable = await Table.findOne({ name: field.reftable_name });
78
131
  const views = await View.find({ table_id: reftable.id });
@@ -91,6 +144,16 @@ const search_or_create = {
91
144
  },
92
145
  ];
93
146
  },
147
+
148
+ /**
149
+ * @param {*} nm
150
+ * @param {*} v
151
+ * @param {*} attrs
152
+ * @param {*} cls
153
+ * @param {*} reqd
154
+ * @param {*} field
155
+ * @returns {object}
156
+ */
94
157
  run: (nm, v, attrs, cls, reqd, field) => {
95
158
  return (
96
159
  tags.select(
@@ -1,23 +1,64 @@
1
+ /**
2
+ * @category saltcorn-data
3
+ * @module base-plugin/fileview
4
+ * @subcategory base-plugin
5
+ */
1
6
  const { text, a, img } = require("@saltcorn/markup/tags");
2
7
  const { link } = require("@saltcorn/markup");
3
8
 
4
9
  module.exports = {
10
+ /**
11
+ * @namespace
12
+ * @category saltcorn-data
13
+ */
5
14
  "Download link": {
15
+ /**
16
+ * @param {string} file_id
17
+ * @param {string} file_name
18
+ * @returns {link}
19
+ */
6
20
  run: (file_id, file_name) =>
7
21
  link(`/files/download/${file_id}`, file_name || "Download"),
8
22
  },
23
+ /**
24
+ * @namespace
25
+ * @category saltcorn-data
26
+ */
9
27
  Link: {
28
+ /**
29
+ * @param {string} file_id
30
+ * @param {string} file_name
31
+ * @returns {link}
32
+ */
10
33
  run: (file_id, file_name) =>
11
34
  link(`/files/serve/${file_id}`, file_name || "Open"),
12
35
  },
36
+ /**
37
+ * @namespace
38
+ * @category saltcorn-data
39
+ */
13
40
  "Link (new tab)": {
41
+ /**
42
+ * @param {string} file_id
43
+ * @param {string} file_name
44
+ * @returns {a}
45
+ */
14
46
  run: (file_id, file_name) =>
15
47
  a(
16
48
  { href: `/files/serve/${file_id}`, target: "_blank" },
17
49
  file_name || "Open"
18
50
  ),
19
51
  },
52
+ /**
53
+ * @namespace
54
+ * @category saltcorn-data
55
+ */
20
56
  "Show Image": {
57
+ /**
58
+ * @param {string} file_id
59
+ * @param {string} file_name
60
+ * @returns {img}
61
+ */
21
62
  run: (file_id, file_name) =>
22
63
  img({ src: `/files/download/${file_id}`, style: "width: 100%" }),
23
64
  },
@@ -1,3 +1,30 @@
1
+ /**
2
+ * @category saltcorn-data
3
+ * @module base-plugin/index
4
+ * @subcategory base-plugin
5
+ */
6
+
7
+ /**
8
+ * All files in the base-plugin module.
9
+ * @namespace base-plugin_overview
10
+ * @property {module:base-plugin/actions} actions
11
+ * @property {module:base-plugin/fieldviews} fieldviews
12
+ * @property {module:base-plugin/fileview} fileview
13
+ * @property {module:base-plugin/types} types
14
+ *
15
+ * @property {module:base-plugin/viewtemplates/edit} edit
16
+ * @property {module:base-plugin/viewtemplates/feed} feed
17
+ * @property {module:base-plugin/viewtemplates/filter} filter
18
+ * @property {module:base-plugin/viewtemplates/list} list
19
+ * @property {module:base-plugin/viewtemplates/listshowlist} listshowlist
20
+ * @property {module:base-plugin/viewtemplates/room} room
21
+ * @property {module:base-plugin/viewtemplates/show} show
22
+ * @property {module:base-plugin/viewtemplates/viewable_fields} viewable_fields
23
+ *
24
+ *
25
+ * @category saltcorn-data
26
+ * @subcategory base-plugin
27
+ */
1
28
  const listshowlist = require("./viewtemplates/listshowlist");
2
29
  const list = require("./viewtemplates/list");
3
30
  const show = require("./viewtemplates/show");
@@ -14,13 +41,21 @@ const types = [string, int, bool, date, float, color];
14
41
  const viewtemplates = [list, edit, show, listshowlist, feed, filter, room];
15
42
 
16
43
  module.exports = {
44
+ /** @type {number} */
17
45
  sc_plugin_api_version: 1,
46
+ /** @type {object[]} */
18
47
  types,
48
+ /** @type {object[]} */
19
49
  viewtemplates,
50
+ /** @type {base-plugin/fileviews} */
20
51
  fileviews,
52
+ /** @type {base-plugin/actions} */
21
53
  actions,
54
+ /** @type {base-plugin/fieldviews} */
22
55
  fieldviews,
56
+ /** @type {object} */
23
57
  serve_dependencies: {
24
58
  blockly: require.resolve("blockly/package.json"),
25
59
  },
26
60
  };
61
+