@saltcorn/data 1.6.0-alpha.1 → 1.6.0-alpha.11

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 (211) hide show
  1. package/dist/base-plugin/actions.d.ts +1850 -1653
  2. package/dist/base-plugin/actions.d.ts.map +1 -1
  3. package/dist/base-plugin/actions.js +130 -104
  4. package/dist/base-plugin/actions.js.map +1 -1
  5. package/dist/base-plugin/fieldviews.d.ts +284 -114
  6. package/dist/base-plugin/fieldviews.d.ts.map +1 -1
  7. package/dist/base-plugin/fieldviews.js +23 -69
  8. package/dist/base-plugin/fieldviews.js.map +1 -1
  9. package/dist/base-plugin/fileviews.d.ts +18 -14
  10. package/dist/base-plugin/fileviews.d.ts.map +1 -1
  11. package/dist/base-plugin/fileviews.js +35 -23
  12. package/dist/base-plugin/fileviews.js.map +1 -1
  13. package/dist/base-plugin/index.d.ts +3369 -1299
  14. package/dist/base-plugin/index.d.ts.map +1 -1
  15. package/dist/base-plugin/index.js +39 -25
  16. package/dist/base-plugin/index.js.map +1 -1
  17. package/dist/base-plugin/types.d.ts +1438 -1029
  18. package/dist/base-plugin/types.d.ts.map +1 -1
  19. package/dist/base-plugin/types.js +3 -2
  20. package/dist/base-plugin/types.js.map +1 -1
  21. package/dist/base-plugin/viewtemplates/edit.d.ts +133 -257
  22. package/dist/base-plugin/viewtemplates/edit.d.ts.map +1 -1
  23. package/dist/base-plugin/viewtemplates/edit.js +306 -348
  24. package/dist/base-plugin/viewtemplates/edit.js.map +1 -1
  25. package/dist/base-plugin/viewtemplates/feed.d.ts +30 -81
  26. package/dist/base-plugin/viewtemplates/feed.d.ts.map +1 -1
  27. package/dist/base-plugin/viewtemplates/feed.js +37 -30
  28. package/dist/base-plugin/viewtemplates/feed.js.map +1 -1
  29. package/dist/base-plugin/viewtemplates/filter.d.ts +42 -64
  30. package/dist/base-plugin/viewtemplates/filter.d.ts.map +1 -1
  31. package/dist/base-plugin/viewtemplates/filter.js +100 -81
  32. package/dist/base-plugin/viewtemplates/filter.js.map +1 -1
  33. package/dist/base-plugin/viewtemplates/list.d.ts +40 -118
  34. package/dist/base-plugin/viewtemplates/list.d.ts.map +1 -1
  35. package/dist/base-plugin/viewtemplates/list.js +169 -168
  36. package/dist/base-plugin/viewtemplates/list.js.map +1 -1
  37. package/dist/base-plugin/viewtemplates/listshowlist.d.ts +65 -49
  38. package/dist/base-plugin/viewtemplates/listshowlist.d.ts.map +1 -1
  39. package/dist/base-plugin/viewtemplates/listshowlist.js +33 -58
  40. package/dist/base-plugin/viewtemplates/listshowlist.js.map +1 -1
  41. package/dist/base-plugin/viewtemplates/room.d.ts +102 -109
  42. package/dist/base-plugin/viewtemplates/room.d.ts.map +1 -1
  43. package/dist/base-plugin/viewtemplates/room.js +53 -50
  44. package/dist/base-plugin/viewtemplates/room.js.map +1 -1
  45. package/dist/base-plugin/viewtemplates/show.d.ts +72 -136
  46. package/dist/base-plugin/viewtemplates/show.d.ts.map +1 -1
  47. package/dist/base-plugin/viewtemplates/show.js +86 -181
  48. package/dist/base-plugin/viewtemplates/show.js.map +1 -1
  49. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts +2 -187
  50. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts.map +1 -1
  51. package/dist/base-plugin/viewtemplates/viewable_fields.js +3 -1898
  52. package/dist/base-plugin/viewtemplates/viewable_fields.js.map +1 -1
  53. package/dist/base-plugin/viewtemplates/workflow-room.d.ts +37 -61
  54. package/dist/base-plugin/viewtemplates/workflow-room.d.ts.map +1 -1
  55. package/dist/base-plugin/viewtemplates/workflow-room.js +42 -65
  56. package/dist/base-plugin/viewtemplates/workflow-room.js.map +1 -1
  57. package/dist/contracts.d.ts +4 -48
  58. package/dist/contracts.d.ts.map +1 -1
  59. package/dist/contracts.js +18 -2
  60. package/dist/contracts.js.map +1 -1
  61. package/dist/db/connect.d.ts.map +1 -1
  62. package/dist/db/connect.js +20 -2
  63. package/dist/db/connect.js.map +1 -1
  64. package/dist/db/fixtures.d.ts +2 -7
  65. package/dist/db/fixtures.d.ts.map +1 -1
  66. package/dist/db/fixtures.js +2349 -2352
  67. package/dist/db/fixtures.js.map +1 -1
  68. package/dist/db/reset_schema.d.ts +3 -3
  69. package/dist/db/reset_schema.d.ts.map +1 -1
  70. package/dist/db/reset_schema.js +10 -10
  71. package/dist/db/reset_schema.js.map +1 -1
  72. package/dist/db/state.d.ts +31 -28
  73. package/dist/db/state.d.ts.map +1 -1
  74. package/dist/db/state.js +9 -32
  75. package/dist/db/state.js.map +1 -1
  76. package/dist/diagram/node_extract_utils.js +1 -1
  77. package/dist/diagram/node_extract_utils.js.map +1 -1
  78. package/dist/index.d.ts +5 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +1 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/migrate.d.ts +9 -3
  83. package/dist/migrate.d.ts.map +1 -1
  84. package/dist/migrate.js +26 -20
  85. package/dist/migrate.js.map +1 -1
  86. package/dist/mobile-mocks/npm/apns2.d.ts +1 -0
  87. package/dist/mobile-mocks/npm/apns2.d.ts.map +1 -0
  88. package/dist/mobile-mocks/npm/apns2.js +2 -0
  89. package/dist/mobile-mocks/npm/apns2.js.map +1 -0
  90. package/dist/mobile-mocks/npm/vm2.d.ts +1 -0
  91. package/dist/mobile-mocks/npm/vm2.d.ts.map +1 -0
  92. package/dist/mobile-mocks/npm/vm2.js +2 -0
  93. package/dist/mobile-mocks/npm/vm2.js.map +1 -0
  94. package/dist/mobile-mocks/npm/xml2js.d.ts +1 -0
  95. package/dist/mobile-mocks/npm/xml2js.d.ts.map +1 -0
  96. package/dist/mobile-mocks/npm/xml2js.js +2 -0
  97. package/dist/mobile-mocks/npm/xml2js.js.map +1 -0
  98. package/dist/model-helper.d.ts +18 -17
  99. package/dist/model-helper.d.ts.map +1 -1
  100. package/dist/model-helper.js +46 -29
  101. package/dist/model-helper.js.map +1 -1
  102. package/dist/models/config.d.ts +5 -0
  103. package/dist/models/config.d.ts.map +1 -1
  104. package/dist/models/config.js +32 -0
  105. package/dist/models/config.js.map +1 -1
  106. package/dist/models/field.d.ts +1 -1
  107. package/dist/models/field.d.ts.map +1 -1
  108. package/dist/models/field.js +3 -2
  109. package/dist/models/field.js.map +1 -1
  110. package/dist/models/file.d.ts +2 -2
  111. package/dist/models/file.d.ts.map +1 -1
  112. package/dist/models/file.js.map +1 -1
  113. package/dist/models/form.d.ts +2 -0
  114. package/dist/models/form.d.ts.map +1 -1
  115. package/dist/models/form.js +2 -1
  116. package/dist/models/form.js.map +1 -1
  117. package/dist/models/index.d.ts +5 -0
  118. package/dist/models/index.d.ts.map +1 -1
  119. package/dist/models/internal/push_message_helper.d.ts +63 -24
  120. package/dist/models/internal/push_message_helper.d.ts.map +1 -1
  121. package/dist/models/internal/push_message_helper.js +221 -42
  122. package/dist/models/internal/push_message_helper.js.map +1 -1
  123. package/dist/models/layout.d.ts +1 -1
  124. package/dist/models/layout.d.ts.map +1 -1
  125. package/dist/models/layout.js +12 -0
  126. package/dist/models/layout.js.map +1 -1
  127. package/dist/models/page.d.ts.map +1 -1
  128. package/dist/models/page.js +30 -1
  129. package/dist/models/page.js.map +1 -1
  130. package/dist/models/plugin.d.ts +5 -2
  131. package/dist/models/plugin.d.ts.map +1 -1
  132. package/dist/models/plugin.js +15 -1
  133. package/dist/models/plugin.js.map +1 -1
  134. package/dist/models/scheduler.js +1 -1
  135. package/dist/models/scheduler.js.map +1 -1
  136. package/dist/models/table.d.ts.map +1 -1
  137. package/dist/models/table.js +13 -4
  138. package/dist/models/table.js.map +1 -1
  139. package/dist/models/trigger.d.ts +2 -1
  140. package/dist/models/trigger.d.ts.map +1 -1
  141. package/dist/models/trigger.js +3 -1
  142. package/dist/models/trigger.js.map +1 -1
  143. package/dist/models/view.js +4 -4
  144. package/dist/models/view.js.map +1 -1
  145. package/dist/models/workflow.d.ts.map +1 -1
  146. package/dist/models/workflow.js +6 -0
  147. package/dist/models/workflow.js.map +1 -1
  148. package/dist/models/workflow_step.d.ts +5 -0
  149. package/dist/models/workflow_step.d.ts.map +1 -1
  150. package/dist/models/workflow_step.js +142 -0
  151. package/dist/models/workflow_step.js.map +1 -1
  152. package/dist/plugin-helper.d.ts +218 -191
  153. package/dist/plugin-helper.d.ts.map +1 -1
  154. package/dist/plugin-helper.js +259 -192
  155. package/dist/plugin-helper.js.map +1 -1
  156. package/dist/plugin-testing.d.ts +6 -6
  157. package/dist/plugin-testing.d.ts.map +1 -1
  158. package/dist/plugin-testing.js +66 -31
  159. package/dist/plugin-testing.js.map +1 -1
  160. package/dist/standard-menu.d.ts +6 -1
  161. package/dist/standard-menu.d.ts.map +1 -1
  162. package/dist/standard-menu.js +20 -0
  163. package/dist/standard-menu.js.map +1 -1
  164. package/dist/tests/actions.test.js +76 -0
  165. package/dist/tests/actions.test.js.map +1 -1
  166. package/dist/tests/auth.test.js +34 -0
  167. package/dist/tests/auth.test.js.map +1 -1
  168. package/dist/tests/auxtest.test.js +6 -0
  169. package/dist/tests/auxtest.test.js.map +1 -1
  170. package/dist/tests/calc.test.js +1 -1
  171. package/dist/tests/calc.test.js.map +1 -1
  172. package/dist/tests/edit.test.js +2 -2
  173. package/dist/tests/edit.test.js.map +1 -1
  174. package/dist/tests/exact_views.test.js +4 -4
  175. package/dist/tests/exact_views.test.js.map +1 -1
  176. package/dist/tests/form.test.js +65 -0
  177. package/dist/tests/form.test.js.map +1 -1
  178. package/dist/tests/user.test.js +52 -1
  179. package/dist/tests/user.test.js.map +1 -1
  180. package/dist/tests/workflow_run.test.js +96 -0
  181. package/dist/tests/workflow_run.test.js.map +1 -1
  182. package/dist/utils.d.ts +6 -0
  183. package/dist/utils.d.ts.map +1 -1
  184. package/dist/utils.js +69 -5
  185. package/dist/utils.js.map +1 -1
  186. package/dist/viewable_fields.d.ts +151 -96
  187. package/dist/viewable_fields.d.ts.map +1 -1
  188. package/dist/viewable_fields.js +452 -91
  189. package/dist/viewable_fields.js.map +1 -1
  190. package/dist/web-mobile-commons.d.ts +1 -2
  191. package/dist/web-mobile-commons.d.ts.map +1 -1
  192. package/dist/web-mobile-commons.js +4 -4
  193. package/dist/web-mobile-commons.js.map +1 -1
  194. package/package.json +12 -9
  195. package/webpack.config.js +3 -0
  196. package/dist/models/s3_helpers.d.ts +0 -54
  197. package/dist/models/s3_helpers.d.ts.map +0 -1
  198. package/dist/models/s3_helpers.js +0 -505
  199. package/dist/models/s3_helpers.js.map +0 -1
  200. package/dist/test-utils/mocks.d.ts +0 -203
  201. package/dist/test-utils/mocks.d.ts.map +0 -1
  202. package/dist/test-utils/mocks.js +0 -329
  203. package/dist/test-utils/mocks.js.map +0 -1
  204. package/dist/tests/mail_queue.test.d.ts +0 -2
  205. package/dist/tests/mail_queue.test.d.ts.map +0 -1
  206. package/dist/tests/mail_queue.test.js +0 -122
  207. package/dist/tests/mail_queue.test.js.map +0 -1
  208. package/dist/tests/table_sync_info.test.d.ts +0 -2
  209. package/dist/tests/table_sync_info.test.d.ts.map +0 -1
  210. package/dist/tests/table_sync_info.test.js +0 -62
  211. package/dist/tests/table_sync_info.test.js.map +0 -1
@@ -1,28 +1,25 @@
1
1
  "use strict";
2
- /**
3
- * @category saltcorn-data
4
- * @module base-plugin/viewtemplates/show
5
- * @subcategory base-plugin
6
- */
7
- const Form = require("../../models/form");
8
- const User = require("../../models/user");
9
- const Field = require("../../models/field");
10
- const View = require("../../models/view");
11
- const File = require("../../models/file");
12
- const Table = require("../../models/table");
13
- const Page = require("../../models/page");
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const user_1 = __importDefault(require("../../models/user"));
6
+ const field_1 = __importDefault(require("../../models/field"));
7
+ const view_1 = __importDefault(require("../../models/view"));
8
+ const table_1 = __importDefault(require("../../models/table"));
9
+ const page_1 = __importDefault(require("../../models/page"));
10
+ const crash_1 = __importDefault(require("../../models/crash"));
11
+ const workflow_1 = __importDefault(require("../../models/workflow"));
12
+ const trigger_1 = __importDefault(require("../../models/trigger"));
13
+ const file_1 = __importDefault(require("../../models/file"));
14
14
  const PageGroup = require("../../models/page_group");
15
- const Crash = require("../../models/crash");
16
- const Workflow = require("../../models/workflow");
17
- const Trigger = require("../../models/trigger");
18
15
  const { Relation } = require("@saltcorn/common-code");
19
16
  const { getState } = require("../../db/state");
20
17
  const { eachView, traverse, getStringsForI18n, translateLayout, splitLayoutContainerFields, findLayoutBranchWith, } = require("../../models/layout");
21
18
  const { check_view_columns } = require("../../plugin-testing");
22
19
  const { div, text, span, a, text_attr, i, button, script, domReady, } = require("@saltcorn/markup/tags");
23
20
  const renderLayout = require("@saltcorn/markup/layout");
24
- const { stateFieldsToWhere, stateFieldsToQuery, picked_fields_to_query, initial_config_all_fields, calcfldViewOptions, calcrelViewOptions, calcfldViewConfig, getActionConfigFields, run_action_column, readState, add_free_variables_to_joinfields, stateToQueryString, pathToState, displayType, } = require("../../plugin-helper");
25
- const { action_url, view_linker, parse_view_select, action_link, splitUniques, standardBlockDispatch, standardLayoutRowVisitor, } = require("./viewable_fields");
21
+ const plugin_helper_1 = require("../../plugin-helper");
22
+ const viewable_fields_1 = require("../../viewable_fields");
26
23
  const db = require("../../db");
27
24
  const { asyncMap, structuredClone, InvalidConfiguration, mergeIntoWhere, isWeb, hashState, getSafeBaseUrl, dollarizeObject, getSessionId, interpolate, validSqlId, renderServerSide, } = require("../../utils");
28
25
  const { traverseSync } = require("../../models/layout");
@@ -31,16 +28,12 @@ const { get_base_url } = require("../../models/config");
31
28
  const Library = require("../../models/library");
32
29
  const { extractFromLayout } = require("../../diagram/node_extract_utils");
33
30
  const _ = require("underscore");
34
- /**
35
- * @param {object} req
36
- * @returns {Workflow}
37
- */
38
- const configuration_workflow = (req) => new Workflow({
31
+ const configuration_workflow = (req) => new workflow_1.default({
39
32
  steps: [
40
33
  {
41
34
  name: req.__("Layout"),
42
35
  builder: async (context) => {
43
- const table = Table.findOne(context.table_id || context.exttable_name);
36
+ const table = table_1.default.findOne(context.table_id || context.exttable_name);
44
37
  const fields = table.getFields();
45
38
  const boolfields = fields.filter((f) => f.type && f.type.name === "Bool");
46
39
  const stateActions = Object.entries(getState().actions).filter(([k, v]) => !v.disableInBuilder && !v.disableIf?.());
@@ -49,11 +42,11 @@ const configuration_workflow = (req) => new Workflow({
49
42
  "GoBack",
50
43
  ...boolfields.map((f) => `Toggle ${f.name}`),
51
44
  ];
52
- const triggerActions = Trigger.trigger_actions({
45
+ const triggerActions = trigger_1.default.trigger_actions({
53
46
  tableTriggers: table.id,
54
47
  apiNeverTriggers: true,
55
48
  });
56
- const actions = Trigger.action_options({
49
+ const actions = trigger_1.default.action_options({
57
50
  tableTriggers: table.id,
58
51
  apiNeverTriggers: true,
59
52
  forBuilder: true,
@@ -62,7 +55,7 @@ const configuration_workflow = (req) => new Workflow({
62
55
  });
63
56
  for (const field of fields) {
64
57
  if (field.type === "Key") {
65
- field.reftable = Table.findOne({
58
+ field.reftable = table_1.default.findOne({
66
59
  name: field.reftable_name,
67
60
  });
68
61
  if (field.reftable)
@@ -90,17 +83,32 @@ const configuration_workflow = (req) => new Workflow({
90
83
  };
91
84
  for (const [name, action] of stateActions) {
92
85
  if (action.configFields) {
93
- actionConfigForms[name] = await getActionConfigFields(action, table, { mode: "show", req });
86
+ actionConfigForms[name] = await (0, plugin_helper_1.getActionConfigFields)(action, table, { mode: "show", req });
94
87
  }
95
88
  }
89
+ const workflowActions = trigger_1.default.trigger_actions({
90
+ tableTriggers: table.id,
91
+ apiNeverTriggers: true,
92
+ onlyWorkflows: true,
93
+ });
94
+ for (const name of workflowActions) {
95
+ actionConfigForms[name] = [
96
+ {
97
+ name: "initial_context",
98
+ label: "Additional context",
99
+ type: "String",
100
+ class: "validate-expression",
101
+ },
102
+ ];
103
+ }
96
104
  //const fieldViewConfigForms = await calcfldViewConfig(fields, false);
97
- const { field_view_options, handlesTextStyle } = calcfldViewOptions(fields, "show");
105
+ const { field_view_options, handlesTextStyle } = (0, plugin_helper_1.calcfldViewOptions)(fields, "show");
98
106
  if (table.name === "users") {
99
- fields.push(new Field({
107
+ fields.push(new field_1.default({
100
108
  name: "verification_url",
101
109
  label: "Verification URL",
102
110
  type: "String",
103
- }), new Field({
111
+ }), new field_1.default({
104
112
  name: "reset_password_url",
105
113
  label: "Reset Password URL",
106
114
  type: "String",
@@ -108,8 +116,8 @@ const configuration_workflow = (req) => new Workflow({
108
116
  field_view_options.verification_url = ["as_text", "as_link"];
109
117
  field_view_options.reset_password_url = ["as_text", "as_link"];
110
118
  }
111
- const rel_field_view_options = await calcrelViewOptions(table, "show");
112
- const roles = await User.get_roles();
119
+ const rel_field_view_options = await (0, plugin_helper_1.calcrelViewOptions)(table, "show");
120
+ const roles = await user_1.default.get_roles();
113
121
  const { parent_field_list } = await table.get_parent_relations(true, true);
114
122
  const { child_field_list, child_relations } = await table.get_child_relations(true);
115
123
  var agg_field_opts = {};
@@ -132,13 +140,13 @@ const configuration_workflow = (req) => new Workflow({
132
140
  .filter(([k, v]) => !v.isEdit && !v.isFilter)
133
141
  .map(([k, v]) => k);
134
142
  });
135
- const pages = await Page.find();
143
+ const pages = await page_1.default.find();
136
144
  const groups = (await PageGroup.find()).map((g) => ({
137
145
  name: g.name,
138
146
  }));
139
- const images = await File.find({ mime_super: "image" });
147
+ const images = await file_1.default.find({ mime_super: "image" });
140
148
  const library = (await Library.find({})).filter((l) => l.suitableFor("show"));
141
- const myviewrow = View.findOne({ name: context.viewname });
149
+ const myviewrow = view_1.default.findOne({ name: context.viewname });
142
150
  return {
143
151
  tableName: table.name,
144
152
  fields: fields.map((f) => f.toBuilder),
@@ -172,9 +180,6 @@ const configuration_workflow = (req) => new Workflow({
172
180
  },
173
181
  ],
174
182
  });
175
- /**
176
- * @returns {object[]}
177
- */
178
183
  const get_state_fields = () => [
179
184
  {
180
185
  name: "id",
@@ -183,33 +188,18 @@ const get_state_fields = () => [
183
188
  primary_key: true,
184
189
  },
185
190
  ];
186
- /** @type {function} */
187
- const initial_config = initial_config_all_fields(false);
188
- /**
189
- * @param {string} table_id
190
- * @param {string} viewname
191
- * @param {object} opts
192
- * @param {object[]} opts.columns
193
- * @param {object} opts.layout
194
- * @param {string} [opts.page_title]
195
- * @param {boolean} opts.page_title_formula
196
- * @param {object} state
197
- * @param {object} extra
198
- * @returns {Promise<string>}
199
- */
200
- const run = async (table_id, viewname, { columns, layout, page_title, page_title_formula }, state, extra, { showQuery }) => {
201
- //console.log(columns);
202
- //console.log(layout);
191
+ const initial_config = (0, plugin_helper_1.initial_config_all_fields)(false);
192
+ const run = async (table_id, viewname, { columns, layout, page_title, page_title_formula, }, state, extra, { showQuery }) => {
203
193
  if (!columns || !layout)
204
194
  return "View not yet built";
205
- const tbl = Table.findOne(table_id);
195
+ const tbl = table_1.default.findOne(table_id);
206
196
  const fields = await tbl.getFields();
207
197
  if (tbl.name === "users") {
208
- fields.push(new Field({
198
+ fields.push(new field_1.default({
209
199
  name: "verification_token",
210
200
  label: "Verification Token",
211
201
  type: "String",
212
- }), new Field({
202
+ }), new field_1.default({
213
203
  name: "reset_password_token",
214
204
  label: "Reset Password Token",
215
205
  type: "String",
@@ -234,11 +224,11 @@ const run = async (table_id, viewname, { columns, layout, page_title, page_title
234
224
  return extra.req.__("No row selected");
235
225
  if (tbl.name === "users") {
236
226
  const base = get_base_url(extra.req);
237
- fields.push(new Field({
227
+ fields.push(new field_1.default({
238
228
  name: "verification_url",
239
229
  label: "Verification URL",
240
230
  type: "String",
241
- }), new Field({
231
+ }), new field_1.default({
242
232
  name: "reset_password_url",
243
233
  label: "Reset Password URL",
244
234
  type: "String",
@@ -274,12 +264,6 @@ const run = async (table_id, viewname, { columns, layout, page_title, page_title
274
264
  return rendered;
275
265
  }
276
266
  };
277
- /**
278
- * @param {object} opts
279
- * @param {object} opts.layout
280
- * @param {object[]} opts.fields
281
- * @returns {Promise<void>}
282
- */
283
267
  const set_load_actions_join_fieldviews = async ({ table, layout, fields, req, res, row, isPreview, }) => {
284
268
  await traverse(layout, {
285
269
  join_field: async (segment) => {
@@ -307,7 +291,7 @@ const set_load_actions_join_fieldviews = async ({ table, layout, fields, req, re
307
291
  //run action
308
292
  if (isPreview)
309
293
  return;
310
- const actionResult = await run_action_column({
294
+ const actionResult = await (0, plugin_helper_1.run_action_column)({
311
295
  col: { ...segment },
312
296
  referrer: req?.get?.("Referrer"),
313
297
  req,
@@ -325,19 +309,7 @@ const set_load_actions_join_fieldviews = async ({ table, layout, fields, req, re
325
309
  },
326
310
  });
327
311
  };
328
- /**
329
- * @param {object} table
330
- * @param {string} viewname
331
- * @param {object} opts
332
- * @param {object[]} opts.columns
333
- * @param {object} opts.layout
334
- * @param {object} extra
335
- * @param {object[]} rows
336
- * @returns {Promise<string>}
337
- */
338
312
  const renderRows = async (table, viewname, { columns, layout }, extra, rows, state) => {
339
- //console.log(columns);
340
- //console.log(layout);
341
313
  if (!columns || !layout)
342
314
  return "View not yet built";
343
315
  const fields = table.getFields();
@@ -346,14 +318,14 @@ const renderRows = async (table, viewname, { columns, layout }, extra, rows, sta
346
318
  const getView = async (name, relation) => {
347
319
  if (views[name])
348
320
  return views[name];
349
- const view_select = parse_view_select(name, relation);
350
- const view = View.findOne({ name: view_select.viewname });
321
+ const view_select = (0, viewable_fields_1.parse_view_select)(name, relation);
322
+ const view = view_1.default.findOne({ name: view_select.viewname });
351
323
  if (!view)
352
324
  return false;
353
325
  if (view.table_id === table.id)
354
326
  view.table = table;
355
327
  else
356
- view.table = Table.findOne({ id: view.table_id });
328
+ view.table = table_1.default.findOne({ id: view.table_id });
357
329
  view.view_select = view_select;
358
330
  views[name] = view;
359
331
  return view;
@@ -394,9 +366,9 @@ const renderRows = async (table, viewname, { columns, layout }, extra, rows, sta
394
366
  };
395
367
  const get_user_id = () => (extra.req.user ? extra.req.user.id : 0);
396
368
  if (view.view_select.type === "RelationPath" && view.table_id) {
397
- const targetTbl = Table.findOne({ id: view.table_id });
398
- const relation = new Relation(segment.relation, targetTbl.name, displayType(await view.get_state_fields()));
399
- state1 = pathToState(relation, relation.isFixedRelation() ? get_user_id : get_row_val);
369
+ const targetTbl = table_1.default.findOne({ id: view.table_id });
370
+ const relation = new Relation(segment.relation, targetTbl.name, (0, plugin_helper_1.displayType)(await view.get_state_fields()));
371
+ state1 = (0, plugin_helper_1.pathToState)(relation, relation.isFixedRelation() ? get_user_id : get_row_val);
400
372
  }
401
373
  else {
402
374
  switch (view.view_select.type) {
@@ -433,7 +405,7 @@ const renderRows = async (table, viewname, { columns, layout }, extra, rows, sta
433
405
  //console.log(segment);
434
406
  if (segment.state === "local") {
435
407
  const state2 = { ...state1, ...extra_state };
436
- const qs = stateToQueryString(state2, true);
408
+ const qs = (0, plugin_helper_1.stateToQueryString)(state2, true);
437
409
  if (view.name === viewname &&
438
410
  JSON.stringify(state) === JSON.stringify(state2))
439
411
  throw new InvalidConfiguration(`View ${view.name} embeds itself with same state; inifinite loop detected`);
@@ -450,7 +422,7 @@ const renderRows = async (table, viewname, { columns, layout }, extra, rows, sta
450
422
  }
451
423
  else {
452
424
  const state2 = { ...outerState, ...state1, ...extra_state };
453
- const qs = stateToQueryString(state2, true);
425
+ const qs = (0, plugin_helper_1.stateToQueryString)(state2, true);
454
426
  if (view.name === viewname &&
455
427
  JSON.stringify(state) === JSON.stringify(state2))
456
428
  throw new InvalidConfiguration(`View ${view.name} embeds itself with same state; inifinite loop detected`);
@@ -466,7 +438,7 @@ const renderRows = async (table, viewname, { columns, layout }, extra, rows, sta
466
438
  }
467
439
  }
468
440
  }, state);
469
- await Page.renderEachEmbeddedPageInLayout(layout, state, extra);
441
+ await page_1.default.renderEachEmbeddedPageInLayout(layout, state, extra);
470
442
  const user_id = extra.req.user ? extra.req.user.id : null;
471
443
  const is_owner = table.ownership_formula && user_id && role > table.min_role_read
472
444
  ? await table.is_owner(extra.req.user, row)
@@ -474,18 +446,8 @@ const renderRows = async (table, viewname, { columns, layout }, extra, rows, sta
474
446
  return render(row, fields, layout, viewname, table, role, extra.req, is_owner, state, extra);
475
447
  });
476
448
  };
477
- /**
478
- * @param {number} table_id
479
- * @param {string} viewname
480
- * @param {object} opts
481
- * @param {object[]} opts.columns
482
- * @param {object} opts.layout
483
- * @param {object} state
484
- * @param {object} extra
485
- * @returns {Promise<object[]>}
486
- */
487
449
  const runMany = async (table_id, viewname, { columns, layout }, state, extra, { runManyQuery }) => {
488
- const tbl = Table.findOne({ id: table_id });
450
+ const tbl = table_1.default.findOne({ id: table_id });
489
451
  const rows = await runManyQuery(state, {
490
452
  where: extra.where,
491
453
  joinFieldsExtra: extra.joinFields,
@@ -497,25 +459,13 @@ const runMany = async (table_id, viewname, { columns, layout }, state, extra, {
497
459
  const rendered = await renderRows(tbl, viewname, { columns, layout }, extra, rows, state);
498
460
  return rendered.map((html, ix) => ({ html, row: rows[ix] }));
499
461
  };
500
- /**
501
- * @param {object} row
502
- * @param {Field[]} fields
503
- * @param {Layout} layout0
504
- * @param {string} viewname
505
- * @param {Table} table
506
- * @param {Role} role
507
- * @param {object} req
508
- * @param {object} is_owner
509
- * @throws {Error}
510
- * @returns {Layout}
511
- */
512
462
  const render = (row, fields, layout0, viewname, table, role, req, is_owner, state, extra) => {
513
463
  const locale = req.getLocale();
514
464
  const layout = structuredClone(layout0);
515
465
  translateLayout(layout, locale);
516
- traverseSync(layout, standardLayoutRowVisitor(viewname, state, table, row, req));
466
+ traverseSync(layout, (0, viewable_fields_1.standardLayoutRowVisitor)(viewname, state, table, row, req));
517
467
  return renderLayout({
518
- blockDispatch: standardBlockDispatch(viewname, state, table, extra, row),
468
+ blockDispatch: (0, viewable_fields_1.standardBlockDispatch)(viewname, state, table, extra, row),
519
469
  layout,
520
470
  role,
521
471
  is_owner,
@@ -523,28 +473,16 @@ const render = (row, fields, layout0, viewname, table, role, req, is_owner, stat
523
473
  hints: getState().getLayout(req.user).hints || {},
524
474
  });
525
475
  };
526
- /**
527
- * @param {number} table_id
528
- * @param {*} viewname
529
- * @param {object} opts
530
- * @param {object[]} opts.columns
531
- * @param {*} opts.layout
532
- * @param {*} body
533
- * @param {object} optsTwo
534
- * @param {object} optsTwo.req
535
- * @param {*} optsTwo.res
536
- * @returns {Promise<object>}
537
- */
538
476
  const run_action = async (table_id, viewname, { columns, layout }, body, { req, res }, { actionQuery }) => {
539
477
  const result = await actionQuery();
540
478
  if (result.json.error) {
541
- Crash.create({ message: result.json.error, stack: "" }, req);
479
+ crash_1.default.create({ message: result.json.error, stack: "" }, req);
542
480
  }
543
481
  return result;
544
482
  };
545
483
  const createBasicView = async ({ table, viewname, template_view, template_table, all_views_created, }) => {
546
484
  if (!template_view) {
547
- const configuration = await initial_config_all_fields(false)({
485
+ const configuration = await (0, plugin_helper_1.initial_config_all_fields)(false)({
548
486
  table_id: table.id,
549
487
  });
550
488
  return configuration;
@@ -595,13 +533,10 @@ const createBasicView = async ({ table, viewname, template_view, template_table,
595
533
  layout: outer({ above: inners }),
596
534
  columns,
597
535
  };
598
- //console.log("show cfg", cfg);
599
536
  return cfg;
600
537
  };
601
538
  module.exports = {
602
- /** @type {string} */
603
539
  name: "Show",
604
- /** @type {string} */
605
540
  description: "Show a single row, with flexible layout",
606
541
  get_state_fields,
607
542
  configuration_workflow,
@@ -611,21 +546,16 @@ module.exports = {
611
546
  initial_config,
612
547
  createBasicView,
613
548
  routes: { run_action },
614
- /**
615
- * @param {object} opts
616
- * @param {object} opts.layout
617
- * @returns {string[]}
618
- */
619
549
  getStringsForI18n({ layout }) {
620
550
  return getStringsForI18n(layout);
621
551
  },
622
552
  async interpolate_title_string(table_id, title, state) {
623
- const tbl = Table.findOne(table_id);
553
+ const tbl = table_1.default.findOne(table_id);
624
554
  if (state?.[tbl.pk_name]) {
625
555
  const freeVars = freeVariablesInInterpolation(title);
626
556
  const joinFields = {};
627
557
  const aggregations = {};
628
- add_free_variables_to_joinfields(freeVars, joinFields, tbl.fields);
558
+ (0, plugin_helper_1.add_free_variables_to_joinfields)(freeVars, joinFields, tbl.fields);
629
559
  add_free_variables_to_aggregations(freeVars, aggregations, tbl);
630
560
  const row = await tbl.getJoinedRow({
631
561
  where: { [tbl.pk_name]: state[tbl.pk_name] },
@@ -637,29 +567,26 @@ module.exports = {
637
567
  else
638
568
  return title;
639
569
  },
640
- /*authorise_get: async ({ query, table_id }, { authorizeGetQuery }) => {
641
- return await authorizeGetQuery(query, table_id);
642
- },*/
643
570
  queries: ({ table_id, exttable_name, name, // viewname
644
571
  configuration: { columns, layout }, req, res, }) => ({
645
572
  async showQuery(state) {
646
- const tbl = Table.findOne(table_id || exttable_name);
573
+ const tbl = table_1.default.findOne(table_id || exttable_name);
647
574
  const fields = tbl.getFields();
648
575
  if (tbl.name === "users") {
649
- fields.push(new Field({
576
+ fields.push(new field_1.default({
650
577
  name: "verification_token",
651
578
  label: "Verification Token",
652
579
  type: "String",
653
- }), {
580
+ }), new field_1.default({
654
581
  name: "reset_password_token",
655
582
  label: "Reset Password Token",
656
583
  type: "String",
657
- });
584
+ }));
658
585
  }
659
- const { joinFields, aggregations } = picked_fields_to_query(columns, fields, layout, req, tbl);
586
+ const { joinFields, aggregations } = (0, plugin_helper_1.picked_fields_to_query)(columns, fields, layout, req, tbl);
660
587
  const unhashed_reset_password_token = state._unhashed_reset_password_token;
661
- readState(state, fields);
662
- const qstate = stateFieldsToWhere({
588
+ (0, plugin_helper_1.readState)(state, fields);
589
+ const qstate = (0, plugin_helper_1.stateFieldsToWhere)({
663
590
  fields,
664
591
  state,
665
592
  approximate: true,
@@ -673,7 +600,7 @@ module.exports = {
673
600
  };
674
601
  if (tbl.ownership_formula) {
675
602
  const freeVars = freeVariables(tbl.ownership_formula);
676
- add_free_variables_to_joinfields(freeVars, joinFields, fields);
603
+ (0, plugin_helper_1.add_free_variables_to_joinfields)(freeVars, joinFields, fields);
677
604
  }
678
605
  const rows = await tbl.getJoinedRows({
679
606
  where: qstate,
@@ -694,19 +621,19 @@ module.exports = {
694
621
  };
695
622
  },
696
623
  async runManyQuery(state, { where, limit, offset, joinFieldsExtra, orderBy, orderDesc }) {
697
- const tbl = Table.findOne({ id: table_id });
624
+ const tbl = table_1.default.findOne({ id: table_id });
698
625
  const fields = await tbl.getFields();
699
- readState(state, fields);
700
- const { joinFields, aggregations } = picked_fields_to_query(columns, fields, layout, req, tbl);
626
+ (0, plugin_helper_1.readState)(state, fields);
627
+ const { joinFields, aggregations } = (0, plugin_helper_1.picked_fields_to_query)(columns, fields, layout, req, tbl);
701
628
  Object.assign(joinFields, joinFieldsExtra || {});
702
629
  const stateHash = hashState(state, name);
703
- const qstate = stateFieldsToWhere({
630
+ const qstate = (0, plugin_helper_1.stateFieldsToWhere)({
704
631
  fields,
705
632
  state,
706
633
  table: tbl,
707
634
  prefix: "a.",
708
635
  });
709
- const q = stateFieldsToQuery({ state, fields, stateHash });
636
+ const q = (0, plugin_helper_1.stateFieldsToQuery)({ state, fields, stateHash });
710
637
  if (where)
711
638
  mergeIntoWhere(qstate, where);
712
639
  const role = req && req.user ? req.user.role_id : 100;
@@ -722,7 +649,7 @@ module.exports = {
722
649
  }
723
650
  if (tbl.ownership_formula && role > tbl.min_role_read) {
724
651
  const freeVars = freeVariables(tbl.ownership_formula);
725
- add_free_variables_to_joinfields(freeVars, joinFields, fields);
652
+ (0, plugin_helper_1.add_free_variables_to_joinfields)(freeVars, joinFields, fields);
726
653
  }
727
654
  let rows = await tbl.getJoinedRows({
728
655
  where: qstate,
@@ -745,12 +672,12 @@ module.exports = {
745
672
  return await db.withTransaction(async () => {
746
673
  const body = req.body || {};
747
674
  const col = columns.find((c) => c.type === "Action" && c.rndid === body.rndid && body.rndid);
748
- const table = Table.findOne({ id: table_id });
675
+ const table = table_1.default.findOne({ id: table_id });
749
676
  let row;
750
677
  if (table.ownership_formula) {
751
678
  const freeVars = freeVariables(table.ownership_formula);
752
679
  const joinFields = {};
753
- add_free_variables_to_joinfields(freeVars, joinFields, table.fields);
680
+ (0, plugin_helper_1.add_free_variables_to_joinfields)(freeVars, joinFields, table.fields);
754
681
  row = await table.getJoinedRow({
755
682
  where: { [table.pk_name]: body[table.pk_name] },
756
683
  joinFields,
@@ -770,12 +697,12 @@ module.exports = {
770
697
  });
771
698
  if (!container)
772
699
  return { json: { error: "Action not found" } };
773
- const trigger = Trigger.findOne({ name: body.click_action });
700
+ const trigger = trigger_1.default.findOne({ name: body.click_action });
774
701
  if (!trigger)
775
702
  throw new Error(`View ${name}: Container click action ${body.click_action} not found`);
776
703
  const result = await trigger.runWithoutRow({
777
704
  table,
778
- Table,
705
+ Table: table_1.default,
779
706
  req,
780
707
  row,
781
708
  user: req.user,
@@ -783,7 +710,7 @@ module.exports = {
783
710
  });
784
711
  return { json: { success: "ok", ...(result || {}) } };
785
712
  }
786
- const result = await run_action_column({
713
+ const result = await (0, plugin_helper_1.run_action_column)({
787
714
  col,
788
715
  req,
789
716
  table,
@@ -796,28 +723,6 @@ module.exports = {
796
723
  return { json: { error: e.message || e } };
797
724
  });
798
725
  },
799
- /*async authorizeGetQuery(query, table_id) {
800
- let body = query || {};
801
- const user_id = req.user ? req.user.id : null;
802
-
803
- if (user_id && Object.keys(body).length == 1) {
804
- const table = Table.findOne({ id: table_id });
805
- if (table.ownership_field_id || table.ownership_formula) {
806
- const fields = table.getFields();
807
- const { uniques } = splitUniques(fields, body);
808
- if (Object.keys(uniques).length > 0) {
809
- const row = await table.getJoinedRows({
810
- where: uniques,
811
- forPublic: !req.user,
812
- forUser: req.user,
813
- });
814
- if (row.length > 0) return true;
815
- else return false;
816
- }
817
- }
818
- }
819
- return false;
820
- },*/
821
726
  }),
822
727
  configCheck: async (view) => {
823
728
  return await check_view_columns(view, view.configuration.columns);