@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,73 +1,76 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  /**
3
6
  * @category saltcorn-data
4
7
  * @module base-plugin/viewtemplates/edit
5
8
  * @subcategory base-plugin
6
9
  */
7
- const Field = require("../../models/field");
8
- const File = require("../../models/file");
9
- const Table = require("../../models/table");
10
- const User = require("../../models/user");
11
- const Crash = require("../../models/crash");
12
- const Form = require("../../models/form");
13
- const Page = require("../../models/page");
10
+ const field_1 = __importDefault(require("../../models/field"));
11
+ const table_1 = __importDefault(require("../../models/table"));
12
+ const user_1 = __importDefault(require("../../models/user"));
13
+ const crash_1 = __importDefault(require("../../models/crash"));
14
+ const form_1 = __importDefault(require("../../models/form"));
15
+ const page_1 = __importDefault(require("../../models/page"));
16
+ const view_1 = __importDefault(require("../../models/view"));
17
+ const workflow_1 = __importDefault(require("../../models/workflow"));
18
+ const trigger_1 = __importDefault(require("../../models/trigger"));
19
+ const file_1 = __importDefault(require("../../models/file"));
14
20
  const PageGroup = require("../../models/page_group");
15
- const View = require("../../models/view");
16
- const Workflow = require("../../models/workflow");
17
- const Trigger = require("../../models/trigger");
18
- const { getState } = require("../../db/state");
19
- const { text, text_attr, script, domReady, div, button, i, pre, } = require("@saltcorn/markup/tags");
20
- const { renderForm } = require("@saltcorn/markup");
21
21
  const FieldRepeat = require("../../models/fieldrepeat");
22
- const { get_expression_function, expressionChecker, eval_expression, freeVariables, freeVariablesInInterpolation, add_free_variables_to_aggregations, } = require("../../models/expression");
23
- const { InvalidConfiguration, isNode, isWeb, isTest, mergeIntoWhere, dollarizeObject, getSessionId, interpolate, asyncMap, removeEmptyStrings, renderServerSide, } = require("../../utils");
24
22
  const Library = require("../../models/library");
25
- const { check_view_columns } = require("../../plugin-testing");
26
- const { initial_config_all_fields, calcfldViewOptions, calcfldViewConfig, get_parent_views, picked_fields_to_query, stateFieldsToWhere, stateFieldsToQuery, getActionConfigFields, run_action_column, add_free_variables_to_joinfields, readState, stateToQueryString, pathToState, displayType, runCollabEvents, } = require("../../plugin-helper");
27
- const { splitUniques, getForm, setDateLocales, transformForm, fill_presets, parse_view_select, get_view_link_query, objToQueryString, action_url, action_link, view_linker, edit_build_in_actions, updateViewSelect, } = require("./viewable_fields");
28
- const { traverse, getStringsForI18n, translateLayout, traverseSync, splitLayoutContainerFields, findLayoutBranchWith, } = require("../../models/layout");
29
- const { extractFromLayout } = require("../../diagram/node_extract_utils");
30
- const db = require("../../db");
31
- const { prepare_update_row } = require("../../web-mobile-commons");
32
- const _ = require("underscore");
23
+ const { getState } = require("../../db/state");
24
+ const tags_1 = require("@saltcorn/markup/tags");
25
+ const { renderForm } = require("@saltcorn/markup");
26
+ const expression_1 = __importDefault(require("../../models/expression"));
27
+ const { get_expression_function, expressionChecker, eval_expression, freeVariables, freeVariablesInInterpolation, add_free_variables_to_aggregations, } = expression_1.default;
28
+ const utils_1 = __importDefault(require("../../utils"));
29
+ const { InvalidConfiguration, isNode, isWeb, isTest, mergeIntoWhere, interpolate, asyncMap, removeEmptyStrings, structuredClone, } = utils_1.default;
30
+ const plugin_testing_1 = require("../../plugin-testing");
31
+ const plugin_helper_1 = require("../../plugin-helper");
32
+ const viewable_fields_1 = require("../../viewable_fields");
33
+ const layout_1 = __importDefault(require("../../models/layout"));
34
+ const { traverse, getStringsForI18n, traverseSync, splitLayoutContainerFields, findLayoutBranchWith, } = layout_1.default;
35
+ const node_extract_utils_1 = require("../../diagram/node_extract_utils");
36
+ const db_1 = __importDefault(require("../../db"));
33
37
  const { Relation, RelationType } = require("@saltcorn/common-code");
34
38
  /**
35
- * @param {object} req
36
- * @returns {Workflow}
39
+ * @param req
40
+ * @returns
37
41
  */
38
- const configuration_workflow = (req) => new Workflow({
42
+ const configuration_workflow = (req) => new workflow_1.default({
39
43
  steps: [
40
44
  {
41
45
  name: req.__("Layout"),
42
46
  builder: async (context) => {
43
- const table = Table.findOne({ id: context.table_id });
47
+ const table = table_1.default.findOne({ id: context.table_id });
44
48
  const fields = table
45
49
  .getFields()
46
50
  .filter((f) => !f.primary_key || f.attributes?.NonSerial);
47
51
  for (const field of fields) {
48
52
  if (field.type === "Key") {
49
- field.reftable = Table.findOne({
53
+ field.reftable = table_1.default.findOne({
50
54
  name: field.reftable_name,
51
55
  });
52
56
  if (field.reftable)
53
57
  await field.reftable.getFields();
54
58
  }
55
59
  }
56
- const { field_view_options, handlesTextStyle, blockDisplay } = calcfldViewOptions(fields, "edit");
57
- //const fieldViewConfigForms = await calcfldViewConfig(fields, true);
58
- const roles = await User.get_roles();
59
- const images = await File.find({ mime_super: "image" });
60
+ const { field_view_options, handlesTextStyle, blockDisplay } = (0, plugin_helper_1.calcfldViewOptions)(fields, "edit");
61
+ const roles = await user_1.default.get_roles();
62
+ const images = await file_1.default.find({ mime_super: "image" });
60
63
  const stateActions = Object.entries(getState().actions).filter(([k, v]) => !v.disableInBuilder && !v.disableIf?.());
61
- const triggerActions = Trigger.trigger_actions({
64
+ const triggerActions = trigger_1.default.trigger_actions({
62
65
  tableTriggers: table.id,
63
66
  apiNeverTriggers: true,
64
67
  });
65
- const actions = Trigger.action_options({
68
+ const actions = trigger_1.default.action_options({
66
69
  tableTriggers: table.id,
67
70
  apiNeverTriggers: true,
68
71
  forBuilder: true,
69
72
  builtInLabel: "Edit Actions",
70
- builtIns: edit_build_in_actions,
73
+ builtIns: viewable_fields_1.edit_build_in_actions,
71
74
  });
72
75
  const actionConfigForms = {
73
76
  Delete: [
@@ -98,38 +101,53 @@ const configuration_workflow = (req) => new Workflow({
98
101
  };
99
102
  for (const [name, action] of stateActions) {
100
103
  if (action.configFields) {
101
- actionConfigForms[name] = await getActionConfigFields(action, table, { mode: "edit", req });
104
+ actionConfigForms[name] = await (0, plugin_helper_1.getActionConfigFields)(action, table, { mode: "edit", req });
102
105
  }
103
106
  }
107
+ const workflowActions = trigger_1.default.trigger_actions({
108
+ tableTriggers: table.id,
109
+ apiNeverTriggers: true,
110
+ onlyWorkflows: true,
111
+ });
112
+ for (const name of workflowActions) {
113
+ actionConfigForms[name] = [
114
+ {
115
+ name: "initial_context",
116
+ label: "Additional context",
117
+ type: "String",
118
+ class: "validate-expression",
119
+ },
120
+ ];
121
+ }
104
122
  if (table.name === "users") {
105
123
  actions.push("Login");
106
124
  actions.push("Sign up");
107
125
  Object.entries(getState().auth_methods).forEach(([k, v]) => {
108
126
  actions.push(`Login with ${k}`);
109
127
  });
110
- fields.push({
128
+ fields.push(new field_1.default({
111
129
  name: "password",
112
130
  label: req.__("Password"),
113
131
  type: "String",
114
- });
115
- fields.push({
132
+ }));
133
+ fields.push(new field_1.default({
116
134
  name: "passwordRepeat",
117
135
  label: req.__("Password Repeat"),
118
136
  type: "String",
119
- });
120
- fields.push({
137
+ }));
138
+ fields.push(new field_1.default({
121
139
  name: "remember",
122
140
  label: req.__("Remember me"),
123
141
  type: "Bool",
124
- });
142
+ }));
125
143
  field_view_options.password = ["password"];
126
144
  field_view_options.passwordRepeat = ["password"];
127
145
  field_view_options.remember = ["edit"];
128
146
  }
129
147
  const library = (await Library.find({})).filter((l) => l.suitableFor("edit"));
130
- const myviewrow = View.findOne({ name: context.viewname });
148
+ const myviewrow = view_1.default.findOne({ name: context.viewname });
131
149
  const { parent_field_list } = await table.get_parent_relations(true, true);
132
- const pages = await Page.find();
150
+ const pages = await page_1.default.find();
133
151
  const groups = (await PageGroup.find()).map((g) => ({
134
152
  name: g.name,
135
153
  }));
@@ -143,8 +161,7 @@ const configuration_workflow = (req) => new Workflow({
143
161
  roles,
144
162
  actions,
145
163
  triggerActions,
146
- builtInActions: edit_build_in_actions,
147
- //fieldViewConfigForms,
164
+ builtInActions: viewable_fields_1.edit_build_in_actions,
148
165
  actionConfigForms,
149
166
  images,
150
167
  allowMultiStepAction: true,
@@ -164,7 +181,7 @@ const configuration_workflow = (req) => new Workflow({
164
181
  name: req.__("Fixed and blocked fields"),
165
182
  contextField: "fixed",
166
183
  onlyWhen: async (context) => {
167
- const table = Table.findOne({ id: context.table_id });
184
+ const table = table_1.default.findOne({ id: context.table_id });
168
185
  const fields = table.getFields();
169
186
  const in_form_fields = context.columns.map((f) => f.field_name);
170
187
  return fields.some((f) => !in_form_fields.includes(f.name) &&
@@ -172,7 +189,7 @@ const configuration_workflow = (req) => new Workflow({
172
189
  !f.primary_key);
173
190
  },
174
191
  form: async (context) => {
175
- const table = Table.findOne({ id: context.table_id });
192
+ const table = table_1.default.findOne({ id: context.table_id });
176
193
  const fields = table.getFields();
177
194
  const in_form_fields = context.columns.map((f) => f.field_name);
178
195
  const omitted_fields = fields.filter((f) => !in_form_fields.includes(f.name) &&
@@ -187,7 +204,7 @@ const configuration_workflow = (req) => new Workflow({
187
204
  }
188
205
  formFields.push(f);
189
206
  if (f.presets) {
190
- formFields.push(new Field({
207
+ formFields.push(new field_1.default({
191
208
  name: "preset_" + f.name,
192
209
  label: req.__("Preset %s", f.label),
193
210
  type: "String",
@@ -200,7 +217,7 @@ const configuration_workflow = (req) => new Workflow({
200
217
  label: f.label,
201
218
  });
202
219
  });
203
- const form = new Form({
220
+ const form = new form_1.default({
204
221
  fields: [
205
222
  {
206
223
  input_type: "section_header",
@@ -221,26 +238,26 @@ const configuration_workflow = (req) => new Workflow({
221
238
  {
222
239
  name: req.__("Edit options"),
223
240
  form: async (context) => {
224
- const own_views = await View.find_all_views_where(({ state_fields, viewrow }) => viewrow.table_id === context.table_id ||
241
+ const own_views = await view_1.default.find_all_views_where(({ state_fields, viewrow }) => viewrow.table_id === context.table_id ||
225
242
  state_fields.every((sf) => !sf.required));
226
- const table = Table.findOne({ id: context.table_id });
243
+ const table = table_1.default.findOne({ id: context.table_id });
227
244
  own_views.forEach((v) => {
228
245
  if (!v.table && v.table_id === table.id)
229
246
  v.table = table;
230
247
  else if (!v.table && v.table_id) {
231
- const vtable = Table.findOne({ id: v.table_id });
248
+ const vtable = table_1.default.findOne({ id: v.table_id });
232
249
  v.table = vtable;
233
250
  }
234
251
  });
235
- const parent_views = await get_parent_views(table, context.viewname);
252
+ const parent_views = await (0, plugin_helper_1.get_parent_views)(table, context.viewname);
236
253
  const done_view_opts = own_views.map((v) => v.select_option);
237
254
  parent_views.forEach(({ relation, related_table, views }) => views.forEach((v) => {
238
255
  done_view_opts.push(`${v.name}.${relation.name}`);
239
256
  }));
240
- const pages = await Page.find();
257
+ const pages = await page_1.default.find();
241
258
  const groups = await PageGroup.find();
242
- const triggers = Trigger.find();
243
- return new Form({
259
+ const triggers = trigger_1.default.find();
260
+ return new form_1.default({
244
261
  fields: [
245
262
  {
246
263
  name: "auto_save",
@@ -302,7 +319,6 @@ const configuration_workflow = (req) => new Workflow({
302
319
  type: "String",
303
320
  required: true,
304
321
  sublabel: req.__("This is the view to which the user will be sent when the form is submitted. The view you specify here can be ignored depending on the context of the form, for instance if it appears in a pop-up the redirect will not take place."),
305
- //fieldview: "radio_group",
306
322
  attributes: {
307
323
  options: [
308
324
  "Back to referer",
@@ -381,11 +397,10 @@ const configuration_workflow = (req) => new Workflow({
381
397
  ],
382
398
  });
383
399
  /**
384
- * @param {*} table_id
385
- * @param {*} viewname
386
- * @param {object} opts
387
- * @param {*} opts.columns
388
- * @returns {Promise<object[]>}
400
+ * @param table_id
401
+ * @param viewname
402
+ * @param param2
403
+ * @returns
389
404
  */
390
405
  const get_state_fields = async (table_id, viewname, { columns }) => [
391
406
  {
@@ -394,37 +409,28 @@ const get_state_fields = async (table_id, viewname, { columns }) => [
394
409
  primary_key: true,
395
410
  },
396
411
  ];
412
+ const initial_config = (0, plugin_helper_1.initial_config_all_fields)(true);
397
413
  /**
398
- * @param {Form} form
399
- * @param {string} locale
400
- */
401
- /** @type {function} */
402
- const initial_config = initial_config_all_fields(true);
403
- /**
404
- * @param {number} table_id
405
- * @param {string} viewname
406
- * @param {object} optsOne
407
- * @param {*} optsOne.columns
408
- * @param {*} optsOne.layout
409
- * @param {string} state
410
- * @param {object} optsTwo
411
- * @param {object} optsTwo.req
412
- * @param {object} optsTwo.res
413
- * @returns {Promise<Form>}
414
+ * @param table_id
415
+ * @param viewname
416
+ * @param cfg
417
+ * @param state
418
+ * @param param4
419
+ * @param param5
420
+ * @returns
414
421
  */
415
- const run = async (table_id, viewname, cfg, state, { res, req, isPreview, hiddenLoginDest }, { editQuery }) => {
422
+ const run = async (table_id, viewname, cfg, state, { res, req, isPreview, hiddenLoginDest, }, { editQuery }) => {
416
423
  const mobileReferrer = isWeb(req) ? undefined : req?.headers?.referer;
417
424
  return await editQuery(state, mobileReferrer, isPreview, hiddenLoginDest);
418
425
  };
419
426
  /**
420
- * @param {number} table_id
421
- * @param {string} viewname
422
- * @param {object} opts
423
- * @param {*} opts.columns
424
- * @param {*} opts.layout
425
- * @param {State} state
426
- * @param {object} extra
427
- * @returns {Promise<Form[]>}
427
+ * @param table_id
428
+ * @param viewname
429
+ * @param param2
430
+ * @param state
431
+ * @param extra
432
+ * @param param5
433
+ * @returns
428
434
  */
429
435
  const runMany = async (table_id, viewname, { columns, layout, auto_save, split_paste, confirm_leave, enable_realtime, update_events, }, state, extra, { editManyQuery, getRowQuery, optionsQuery }) => {
430
436
  let { table, fields, rows } = await editManyQuery(state, {
@@ -435,7 +441,7 @@ const runMany = async (table_id, viewname, { columns, layout, auto_save, split_p
435
441
  where: extra.where,
436
442
  });
437
443
  if (!isNode()) {
438
- table = Table.findOne({ id: table.id });
444
+ table = table_1.default.findOne({ id: table.id });
439
445
  fields = table.getFields();
440
446
  }
441
447
  const isRemote = !isWeb(extra.req);
@@ -462,19 +468,9 @@ const runMany = async (table_id, viewname, { columns, layout, auto_save, split_p
462
468
  return { html, row };
463
469
  });
464
470
  };
465
- /**
466
- * @param {object} opts
467
- * @param {Form} opts.form
468
- * @param {Table} opts.table
469
- * @param {object} opts.req
470
- * @param {object} opts.row
471
- * @param {object} opts.res
472
- * @throws {InvalidConfiguration}
473
- * @returns {Promise<void>}
474
- */
475
471
  const realTimeScript = (viewname, table_id, row, scriptId) => {
476
- const view = View.findOne({ name: viewname });
477
- const table = Table.findOne({ id: table_id });
472
+ const view = view_1.default.findOne({ name: viewname });
473
+ const table = table_1.default.findOne({ id: table_id });
478
474
  const rowId = row[table.pk_name];
479
475
  return `
480
476
  const collabCfg = {
@@ -500,21 +496,8 @@ const realTimeScript = (viewname, table_id, row, scriptId) => {
500
496
  };
501
497
  init_collab_room('${viewname}', collabCfg);`.trim();
502
498
  };
503
- /**
504
- * @param {object} opts
505
- * @param {Table} opts.table
506
- * @param {Fields[]} opts.fields
507
- * @param {string} opts.viewname
508
- * @param {object[]} opts.columns
509
- * @param {Layout} opts.layout
510
- * @param {object} opts.row
511
- * @param {object} opts.req
512
- * @param {object} opts.state
513
- * @param {object} opts.res
514
- * @returns {Promise<Form>}
515
- */
516
499
  const render = async ({ table, fields, viewname, columns, layout, row, req, state, res, auto_save, destination_type, isRemote, getRowQuery, optionsQuery, split_paste, mobileReferrer, confirm_leave, delete_unchanged_auto_create, isPreview, auto_created_row, hiddenLoginDest, enable_realtime, }) => {
517
- const form = await getForm(table, viewname, columns, layout, state[table.pk_name], req, isRemote);
500
+ const form = await (0, viewable_fields_1.getForm)(table, viewname, columns, layout, state[table.pk_name], req, isRemote);
518
501
  if (split_paste)
519
502
  form.splitPaste = true;
520
503
  if (row) {
@@ -523,12 +506,12 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
523
506
  if (isWeb(req)) {
524
507
  for (const field of file_fields) {
525
508
  if (field.fieldviewObj?.valueIsFilename && row[field.name]) {
526
- const file = await File.findOne({ id: row[field.name] });
509
+ const file = await file_1.default.findOne({ id: row[field.name] });
527
510
  if (file?.id)
528
511
  form.values[field.name] = file.filename;
529
512
  }
530
513
  if (field.fieldviewObj?.editContent && row[field.name]) {
531
- const file = await File.findOne(row[field.name]);
514
+ const file = await file_1.default.findOne(row[field.name]);
532
515
  if (file && file.min_role_read >= (req.user?.role_id || 100))
533
516
  form.values[`_content_${field.name}`] = await file.get_contents();
534
517
  }
@@ -539,10 +522,9 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
539
522
  const owner_field = await table.owner_fieldname();
540
523
  if (table.ownership_formula && user_id) {
541
524
  const freeVars = freeVariables(table.ownership_formula);
542
- //need to fetch with joinfields
543
525
  if (freeVars.size > 0) {
544
526
  const joinFields = {};
545
- add_free_variables_to_joinfields(freeVars, joinFields, fields);
527
+ (0, plugin_helper_1.add_free_variables_to_joinfields)(freeVars, joinFields, fields);
546
528
  const row_joined = await table.getJoinedRow({
547
529
  where: { [table.pk_name]: row[table.pk_name] },
548
530
  forPublic: !req.user,
@@ -581,7 +563,7 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
581
563
  else {
582
564
  const tbl_field = fields.find((f) => f.name === k);
583
565
  if (tbl_field && !field) {
584
- form.fields.push(new Field({ name: k, input_type: "hidden" }));
566
+ form.fields.push(new field_1.default({ name: k, input_type: "hidden" }));
585
567
  form.values[k] = tbl_field.type.read
586
568
  ? tbl_field.type.read(v, tbl_field.attributes)
587
569
  : v;
@@ -593,18 +575,19 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
593
575
  const need_join_fields = new Set(columns
594
576
  .filter((c) => c.type === "JoinField")
595
577
  .map((c) => c.join_field.split(".")[0]));
596
- const colFields = new Set(columns.filter((c) => c.type === "Field").map((c) => c.field_name));
578
+ const colFields = new Set(columns
579
+ .filter((c) => c.type === "Field")
580
+ .map((c) => c.field_name));
597
581
  const formFields = new Set(form.fields.map((f) => f.name));
598
582
  fields.forEach((f) => {
599
583
  if (!colFields.has(f.name) &&
600
584
  !formFields.has(f.name) &&
601
585
  typeof row[f.name] !== "undefined" &&
602
586
  need_join_fields.has(f.name))
603
- form.fields.push(new Field({ name: f.name, input_type: "hidden" }));
587
+ form.fields.push(new field_1.default({ name: f.name, input_type: "hidden" }));
604
588
  });
605
589
  }
606
590
  // no autosave if new and save button exists
607
- // !row && hasSave
608
591
  let hasSave = false;
609
592
  traverseSync(layout, {
610
593
  action({ action_name }) {
@@ -617,7 +600,7 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
617
600
  if (actually_auto_save)
618
601
  form.onChange = `saveAndContinueDelayed(this, ${!isWeb(req) ? `'${form.action}'` : undefined}, event);`;
619
602
  let reloadAfterCloseInModalScript = actually_auto_save && req.xhr
620
- ? script(domReady(`
603
+ ? (0, tags_1.script)((0, tags_1.domReady)(`
621
604
  $("#scmodal").on("hidden.bs.modal", function (e) {
622
605
  const on_close_reload_view = $("#scmodal").attr(
623
606
  "data-on-close-reload-view"
@@ -630,15 +613,13 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
630
613
  : "";
631
614
  let confirmLeaveScript = "";
632
615
  if (confirm_leave) {
633
- //add to onchange
634
616
  if (!form.onChange)
635
617
  form.onChange = "";
636
618
  form.onChange += "this.setAttribute('data-unsaved-changes','true');";
637
619
  if (!form.onSubmit)
638
620
  form.onSubmit = "";
639
621
  form.onSubmit += "this.removeAttribute('data-unsaved-changes')";
640
- //beforeunload script
641
- confirmLeaveScript = script(`((curScript)=>{window.addEventListener("beforeunload", (e) => check_unsaved_form(e, curScript));})(document.currentScript)`);
622
+ confirmLeaveScript = (0, tags_1.script)(`((curScript)=>{window.addEventListener("beforeunload", (e) => check_unsaved_form(e, curScript));})(document.currentScript)`);
642
623
  }
643
624
  let deleteUnchangedScript = "";
644
625
  if (auto_created_row && delete_unchanged_auto_create && !isPreview) {
@@ -652,23 +633,23 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
652
633
  form.onChange = "";
653
634
  form.onChange += "this.setAttribute('data-form-changed','true');";
654
635
  }
655
- deleteUnchangedScript = script(`((curScript)=>{window.addEventListener("beforeunload", () => check_delete_unsaved("${table.name}", curScript));})(document.currentScript)`);
636
+ deleteUnchangedScript = (0, tags_1.script)(`((curScript)=>{window.addEventListener("beforeunload", () => check_delete_unsaved("${table.name}", curScript));})(document.currentScript)`);
656
637
  }
657
638
  const formId = isTest()
658
639
  ? "test-form-id"
659
640
  : `form${Math.floor(Math.random() * 16777215).toString(16)}`;
660
- const identicalFieldsScript = script(domReady(`const editForm = document.getElementById('${formId}'); if (editForm) editForm.addEventListener("change", handle_identical_fields, true);`));
641
+ const identicalFieldsScript = (0, tags_1.script)((0, tags_1.domReady)(`const editForm = document.getElementById('${formId}'); if (editForm) editForm.addEventListener("change", handle_identical_fields, true);`));
661
642
  const dynamic_updates_enabled = getState().getConfig("enable_dynamic_updates", true);
662
643
  const rndid = isTest()
663
644
  ? "test-script-id"
664
645
  : Math.floor(Math.random() * 16777215).toString(16);
665
646
  const realTimeCollabScript = enable_realtime && row && !(req.headers?.pjaxpageload === "true")
666
647
  ? (!dynamic_updates_enabled
667
- ? script({
668
- src: `/static_assets/${db.connectObj.version_tag}/socket.io.min.js`,
648
+ ? (0, tags_1.script)({
649
+ src: `/static_assets/${db_1.default.connectObj.version_tag}/socket.io.min.js`,
669
650
  })
670
651
  : "") +
671
- script({ id: rndid }, domReady(realTimeScript(viewname, table.id, row, rndid)))
652
+ (0, tags_1.script)({ id: rndid }, (0, tags_1.domReady)(realTimeScript(viewname, table.id, row, rndid)))
672
653
  : "";
673
654
  if (actually_auto_save) {
674
655
  for (const field of form.fields) {
@@ -676,11 +657,11 @@ const render = async ({ table, fields, viewname, columns, layout, row, req, stat
676
657
  }
677
658
  }
678
659
  await form.fill_fkey_options(false, optionsQuery, req.user);
679
- await transformForm({
660
+ await (0, viewable_fields_1.transformForm)({
680
661
  form,
681
662
  table,
682
663
  req,
683
- row,
664
+ row: row,
684
665
  res,
685
666
  getRowQuery,
686
667
  viewname,
@@ -709,40 +690,32 @@ const identicalFieldNames = (columns) => {
709
690
  return result;
710
691
  };
711
692
  const prepSafeBody = (body, columns) => {
712
- const safeBody = { ...body }; // avoid mutation (shallow copy should be enough)
693
+ const safeBody = { ...body };
713
694
  const identicalFields = identicalFieldNames(columns);
714
695
  for (const field of identicalFields) {
715
696
  if (body && body[field] && Array.isArray(body[field])) {
716
- // should all be the same (see saltcorn.js handle_identical_fields())
717
- // or at least the submit still works (e.g. different plugin fieldviews)
718
697
  safeBody[field] = body[field][0];
719
698
  }
720
699
  }
721
700
  return safeBody;
722
701
  };
723
702
  /**
724
- * @param {number} table_id
725
- * @param {string} viewname
726
- * @param {object} optsOne
727
- * @param {object[]} optsOne.columns
728
- * @param {Layout} optsOne.layout
729
- * @param {object} optsOne.fixed
730
- * @param {boolean} optsOne.view_when_done
731
- * @param {object[]} optsOne.formula_destinations
732
- * @param {object} state
733
- * @param {*} body
734
- * @param {object} optsTwo
735
- * @param {object} optsTwo.res
736
- * @param {object} optsTwo.req
737
- * @param {string} optsTwo.redirect
738
- * @returns {Promise<void>}
703
+ * @param table_id
704
+ * @param viewname
705
+ * @param param2
706
+ * @param state
707
+ * @param body
708
+ * @param param5
709
+ * @param param6
710
+ * @param remote
711
+ * @returns
739
712
  */
740
713
  const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_done, formula_destinations, auto_save, destination_type, dest_url_formula, page_when_done, page_group_when_done, }, state, body, { res, req, redirect }, { tryInsertQuery, tryUpdateQuery, getRowQuery, saveFileQuery, saveFileFromContentsQuery, optionsQuery, getRowByIdQuery, }, remote) => {
741
714
  const safeBody = prepSafeBody(body, columns);
742
- const table = Table.findOne({ id: table_id });
715
+ const table = table_1.default.findOne({ id: table_id });
743
716
  const fields = table.getFields();
744
- if (safeBody?.password && table_id === User.table.id) {
745
- safeBody.password = await User.hashPassword(safeBody.password);
717
+ if (safeBody?.password && table_id === user_1.default.table.id) {
718
+ safeBody.password = await user_1.default.hashPassword(safeBody.password);
746
719
  }
747
720
  const prepResult = await prepare(viewname, table, fields, {
748
721
  columns,
@@ -756,7 +729,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
756
729
  optionsQuery,
757
730
  getRowByIdQuery,
758
731
  }, remote);
759
- const view = View.findOne({ name: viewname });
732
+ const view = view_1.default.findOne({ name: viewname });
760
733
  const pagetitle = { title: viewname, no_menu: view?.attributes?.no_menu };
761
734
  if (prepResult) {
762
735
  let { form, row, pk, id } = prepResult;
@@ -766,7 +739,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
766
739
  let ins_upd_error;
767
740
  if (!cancel) {
768
741
  getState().log(6, `Edit POST ready to insert/update into ${table.name} Row=${JSON.stringify(row)} ID=${id} Ajax=${!!req.xhr}`);
769
- const doReturn = await db.withTransaction(async (rollback) => {
742
+ const doReturn = await db_1.default.withTransaction(async (rollback) => {
770
743
  if (typeof id === "undefined") {
771
744
  const ins_res = await tryInsertQuery(row);
772
745
  if (ins_res.success) {
@@ -781,7 +754,6 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
781
754
  else {
782
755
  if (table.composite_pk_names ||
783
756
  table.getField(table.pk_name).attributes.NonSerial) {
784
- //console.log("edit", { id });
785
757
  const upd_res = await tryInsertOrUpdateImpl(row, id, table, req);
786
758
  if (upd_res.error) {
787
759
  ins_upd_error = upd_res.error;
@@ -805,7 +777,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
805
777
  }
806
778
  else {
807
779
  await form.fill_fkey_options(false, optionsQuery, req.user);
808
- req.flash("error", text_attr(ins_upd_error));
780
+ req.flash("error", (0, tags_1.text_attr)(ins_upd_error));
809
781
  for (const file_field of fields.filter((f) => f.type === "File")) {
810
782
  if (!form.values[file_field.name])
811
783
  continue;
@@ -818,19 +790,19 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
818
790
  return true;
819
791
  }
820
792
  for (const field of form.fields.filter((f) => f.isRepeat)) {
821
- const view_select = parse_view_select(field.metadata.view, field.metadata.relation_path);
793
+ const view_select = (0, viewable_fields_1.parse_view_select)(field.metadata.view, field.metadata.relation_path);
822
794
  const order_field = field.metadata.order_field;
823
- const childView = View.findOne({ name: view_select.viewname });
795
+ const childView = view_1.default.findOne({ name: view_select.viewname });
824
796
  if (!childView)
825
797
  throw new InvalidConfiguration(`Cannot find embedded view: ${view_select.viewname}`);
826
798
  if (field.metadata.relation_path &&
827
799
  view_select.type === "RelationPath") {
828
- const targetTbl = Table.findOne({ id: childView.table_id });
829
- const relation = new Relation(field.metadata.relation_path, targetTbl.name, displayType(await childView.get_state_fields()));
800
+ const targetTbl = table_1.default.findOne({ id: childView.table_id });
801
+ const relation = new Relation(field.metadata.relation_path, targetTbl.name, (0, plugin_helper_1.displayType)(await childView.get_state_fields()));
830
802
  if (relation.type === RelationType.CHILD_LIST)
831
- updateViewSelect(view_select);
803
+ (0, viewable_fields_1.updateViewSelect)(view_select);
832
804
  }
833
- const childTable = Table.findOne({ id: field.metadata?.table_id });
805
+ const childTable = table_1.default.findOne({ id: field.metadata?.table_id });
834
806
  const submitted_row_ids = new Set((form.values[field.name] || []).map((srow) => `${srow[childTable.pk_name]}`));
835
807
  const childFields = new Set(childTable.fields.map((f) => f.name));
836
808
  let repeatIx = 0;
@@ -841,8 +813,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
841
813
  if (typeof childRow[k] === "undefined" &&
842
814
  !k.startsWith("_block_") &&
843
815
  childFields.has(k) &&
844
- (v || v === 0) //no nulls or empty string, but allow 0
845
- )
816
+ (v || v === 0))
846
817
  childRow[k] = v;
847
818
  }
848
819
  if (order_field && !childRow[order_field])
@@ -851,7 +822,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
851
822
  const key = `${file_field.name}_${repeatIx}`;
852
823
  if (req.files?.[key] &&
853
824
  (!file_field.fieldviewObj || file_field.fieldviewObj.isEdit)) {
854
- const file = await File.from_req_files(req.files[key], req.user ? req.user.id : null, (file_field.attributes &&
825
+ const file = await file_1.default.from_req_files(req.files[key], req.user ? req.user.id : undefined, (file_field.attributes &&
855
826
  +file_field.attributes.min_role_read) ||
856
827
  1, file_field?.attributes?.folder);
857
828
  childRow[file_field.name] = file.field_value;
@@ -863,7 +834,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
863
834
  if (upd_res.error) {
864
835
  await rollback();
865
836
  getState().log(6, `Update child row failure ${JSON.stringify(upd_res)}`);
866
- req.flash("error", text_attr(upd_res.error));
837
+ req.flash("error", (0, tags_1.text_attr)(upd_res.error));
867
838
  res.sendWrap(pagetitle, renderForm(form, req.csrfToken()));
868
839
  return true;
869
840
  }
@@ -873,7 +844,7 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
873
844
  if (ins_res.error) {
874
845
  await rollback();
875
846
  getState().log(6, `Insert child row failure ${JSON.stringify(ins_res)}`);
876
- req.flash("error", text_attr(ins_res.error));
847
+ req.flash("error", (0, tags_1.text_attr)(ins_res.error));
877
848
  res.sendWrap(pagetitle, renderForm(form, req.csrfToken()));
878
849
  return true;
879
850
  }
@@ -906,14 +877,14 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
906
877
  }
907
878
  trigger_return = trigger_return || {};
908
879
  if (trigger_return.notify && trigger_return.details)
909
- req.flash("success", div({ class: "d-inline" }, trigger_return.notify, button({
880
+ req.flash("success", (0, tags_1.div)({ class: "d-inline" }, trigger_return.notify, (0, tags_1.button)({
910
881
  class: "btn btn-sm btn-outline-secondary btn-xs",
911
882
  type: "button",
912
883
  "data-bs-toggle": "collapse",
913
884
  "data-bs-target": "#notifyDetails",
914
885
  "aria-expanded": "false",
915
886
  "aria-controls": "notifyDetails",
916
- }, i({ class: "fas fa-plus" })), div({ class: "collapse", id: "notifyDetails" }, pre(trigger_return.details))));
887
+ }, (0, tags_1.i)({ class: "fas fa-plus" })), (0, tags_1.div)({ class: "collapse", id: "notifyDetails" }, (0, tags_1.pre)(trigger_return.details))));
917
888
  else if (trigger_return.notify)
918
889
  req.flash("success", trigger_return.notify);
919
890
  if (trigger_return.error)
@@ -922,13 +893,6 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
922
893
  res.redirect(trigger_return.goto);
923
894
  return;
924
895
  }
925
- /*if (req.xhr && !originalID && !req.smr) {
926
- res.json({ id, view_when_done, ...trigger_return });
927
- return;
928
- } else if (req.xhr && !req.smr) {
929
- res.json({ view_when_done, ...trigger_return });
930
- return;
931
- }*/
932
896
  await whenDone(viewname, table_id, fields, pk, {
933
897
  view_when_done,
934
898
  formula_destinations,
@@ -940,20 +904,22 @@ const runPost = async (table_id, viewname, { columns, layout, fixed, view_when_d
940
904
  }, req, res, safeBody, row, !originalID ? { id, ...trigger_return } : trigger_return, true, originalID, table);
941
905
  }
942
906
  };
943
- const doAuthPost = async ({ body, table_id, req }) => {
944
- const table = Table.findOne({ id: table_id });
907
+ const doAuthPost = async ({ body, table_id, req, }) => {
908
+ const table = table_1.default.findOne({ id: table_id });
945
909
  const user_id = req.user ? req.user.id : null;
946
910
  if (table.ownership_field_id && user_id) {
947
911
  const field_name = await table.owner_fieldname();
948
- if (typeof body[field_name] === "undefined") {
912
+ if (typeof body[field_name || ""] === "undefined") {
949
913
  const fields = table.getFields();
950
- const { uniques } = splitUniques(fields, body);
914
+ const { uniques } = (0, viewable_fields_1.splitUniques)(fields, body);
951
915
  if (Object.keys(uniques).length > 0) {
952
- body = await table.getRow(uniques, {
916
+ const dbrow = await table.getRow(uniques, {
953
917
  forUser: req.user,
954
918
  forPublic: !req.user,
955
919
  });
956
- return table.is_owner(req.user, body);
920
+ if (!dbrow)
921
+ return false;
922
+ return table.is_owner(req.user, dbrow);
957
923
  }
958
924
  }
959
925
  else
@@ -966,7 +932,7 @@ const doAuthPost = async ({ body, table_id, req }) => {
966
932
  if (table.ownership_formula) {
967
933
  const fields = table.getFields();
968
934
  const freeVars = freeVariables(table.ownership_formula);
969
- add_free_variables_to_joinfields(freeVars, joinFields, fields);
935
+ (0, plugin_helper_1.add_free_variables_to_joinfields)(freeVars, joinFields, fields);
970
936
  }
971
937
  const dbrow = await table.getJoinedRows({
972
938
  where: {
@@ -978,21 +944,19 @@ const doAuthPost = async ({ body, table_id, req }) => {
978
944
  row = { ...body, ...dbrow[0] };
979
945
  }
980
946
  else {
981
- // need to check new row conforms to ownership fml
982
947
  const freeVars = freeVariables(table.ownership_formula);
983
948
  const fields = table.getFields();
984
949
  const field_names = new Set(fields.map((f) => f.name));
985
- // loop free vars, substitute in row
986
950
  for (const fv of freeVars) {
987
951
  const kpath = fv.split(".");
988
952
  if (field_names.has(kpath[0]) && kpath.length > 1) {
989
953
  const field = fields.find((f) => f.name === kpath[0]);
990
954
  if (!field)
991
955
  throw new Error("Invalid formula:" + table.ownership_formula);
992
- const reftable = Table.findOne({ name: field.reftable_name });
956
+ const reftable = table_1.default.findOne({ name: field.reftable_name });
993
957
  const joinFields = {};
994
958
  const [kpath0, ...kpathrest] = kpath;
995
- add_free_variables_to_joinfields(new Set([kpathrest.join(".")]), joinFields, fields);
959
+ (0, plugin_helper_1.add_free_variables_to_joinfields)(new Set([kpathrest.join(".")]), joinFields, fields);
996
960
  const rows = await reftable.getJoinedRows({
997
961
  where: {
998
962
  [reftable.pk_name]: body[kpath0],
@@ -1011,17 +975,26 @@ const doAuthPost = async ({ body, table_id, req }) => {
1011
975
  return false;
1012
976
  };
1013
977
  /**
1014
- * @param {object} opts
1015
- * @param {object} opts.body
1016
- * @param {string} opts.table_id
1017
- * @param {object} opts.req
1018
- * @returns {Promise<boolean>}
978
+ * @param param0
979
+ * @param param1
980
+ * @returns
1019
981
  */
1020
- const authorise_post = async ({ body, table_id, req }, { authorizePostQuery }) => {
982
+ const authorise_post = async ({ body, table_id, req, }, { authorizePostQuery }) => {
1021
983
  return await authorizePostQuery(body, table_id);
1022
984
  };
985
+ /**
986
+ * @param tableId
987
+ * @param viewName
988
+ * @param id
989
+ * @param fieldName
990
+ * @param fieldView
991
+ * @param user
992
+ * @param configuration
993
+ * @param targetOpts
994
+ * @returns
995
+ */
1023
996
  const openDataStream = async (tableId, viewName, id, fieldName, fieldView, user, configuration, targetOpts) => {
1024
- const table = Table.findOne({ id: tableId });
997
+ const table = table_1.default.findOne({ id: tableId });
1025
998
  const field = table.getField(fieldName);
1026
999
  if (!field)
1027
1000
  throw new InvalidConfiguration(`Field ${fieldName} not found`);
@@ -1033,64 +1006,55 @@ const openDataStream = async (tableId, viewName, id, fieldName, fieldView, user,
1033
1006
  return await fileView.openDataStream(tableId, id, fieldName, user, cfgCol.configuration, targetOpts);
1034
1007
  }
1035
1008
  };
1036
- // TODO is owner check
1009
+ /**
1010
+ * @param view
1011
+ * @param id
1012
+ * @param fieldName
1013
+ * @param user
1014
+ * @param targetOpts
1015
+ * @returns
1016
+ */
1037
1017
  const authorizeDataStream = async (view, id, fieldName, user, targetOpts) => {
1038
1018
  if (!user || user.role_id > view.min_role)
1039
1019
  return false;
1040
1020
  else {
1041
- const table = Table.findOne({ id: view.table_id });
1021
+ const table = table_1.default.findOne({ id: view.table_id });
1042
1022
  if (!table || user.role_id > table.min_role_write)
1043
1023
  return false;
1044
1024
  else {
1045
1025
  const field = table.getField(fieldName);
1046
1026
  if (field.type === "File") {
1047
1027
  if (targetOpts?.oldTarget) {
1048
- // continue old file ?
1049
- const file = await File.findOne(targetOpts.oldTarget);
1028
+ const file = await file_1.default.findOne(targetOpts.oldTarget);
1050
1029
  if (file)
1051
1030
  return file.min_role_read >= user.role_id;
1052
1031
  }
1053
1032
  else if (id) {
1054
- // continue file of existing row ?
1055
1033
  const row = await table.getRow({ [table.pk_name]: id });
1056
1034
  const fileCol = row[fieldName];
1057
1035
  if (fileCol) {
1058
- const file = await File.findOne(row[fieldName]);
1036
+ const file = await file_1.default.findOne(row[fieldName]);
1059
1037
  if (file)
1060
1038
  return file.min_role_read >= user.role_id;
1061
1039
  }
1062
1040
  }
1063
- // stream is new or the file does not exist
1064
1041
  return true;
1065
1042
  }
1066
1043
  else {
1067
- // only files for now
1068
1044
  return false;
1069
1045
  }
1070
1046
  }
1071
1047
  }
1072
1048
  };
1073
- /**
1074
- * @param {number} table_id
1075
- * @param {*} viewname
1076
- * @param {object} opts
1077
- * @param {object[]} opts.columns
1078
- * @param {*} opts.layout
1079
- * @param {*} body
1080
- * @param {object} optsTwo
1081
- * @param {object} optsTwo.req
1082
- * @param {*} optsTwo.res
1083
- * @returns {Promise<object>}
1084
- */
1085
1049
  const run_action = async (table_id, viewname, { columns, layout }, body, { req, res }, { actionQuery }) => {
1086
1050
  const result = await actionQuery();
1087
1051
  if (result.json.error) {
1088
- Crash.create({ message: result.json.error, stack: "" }, req);
1052
+ crash_1.default.create({ message: result.json.error, stack: "" }, req);
1089
1053
  }
1090
1054
  return result;
1091
1055
  };
1092
1056
  const update_matching_rows = async (table_id, viewname, { columns, layout, fixed, view_when_done, formula_destinations, auto_save, destination_type, dest_url_formula, page_when_done, page_group_when_done, }, body, { req, res, redirect }, { updateMatchingQuery, getRowQuery, saveFileQuery, saveFileFromContentsQuery, optionsQuery, getRowByIdQuery, }) => {
1093
- const table = Table.findOne({ id: table_id });
1057
+ const table = table_1.default.findOne({ id: table_id });
1094
1058
  const fields = table.getFields();
1095
1059
  const prepResult = await prepare(viewname, table, fields, {
1096
1060
  columns,
@@ -1107,9 +1071,9 @@ const update_matching_rows = async (table_id, viewname, { columns, layout, fixed
1107
1071
  if (prepResult) {
1108
1072
  let { form, row, pk } = prepResult;
1109
1073
  const state = req?.query
1110
- ? readState(removeEmptyStrings(req.query), fields, req)
1074
+ ? (0, plugin_helper_1.readState)(removeEmptyStrings(req.query), fields, req)
1111
1075
  : {};
1112
- const where = stateFieldsToWhere({ fields, state, table });
1076
+ const where = (0, plugin_helper_1.stateFieldsToWhere)({ fields, state, table });
1113
1077
  const repeatFields = form.fields.filter((f) => f.isRepeat);
1114
1078
  const childRows = {};
1115
1079
  for (const field of repeatFields)
@@ -1118,7 +1082,7 @@ const update_matching_rows = async (table_id, viewname, { columns, layout, fixed
1118
1082
  const uptResults = await updateMatchingQuery(where, rest, repeatFields, childRows);
1119
1083
  if (uptResults.error || uptResults.rowError || uptResults.inEditError) {
1120
1084
  res.status(422);
1121
- req.flash("error", text_attr(uptResults.error || uptResults.rowError || uptResults.inEditError));
1085
+ req.flash("error", (0, tags_1.text_attr)(uptResults.error || uptResults.rowError || uptResults.inEditError));
1122
1086
  res.sendWrap(viewname, renderForm(form, req.csrfToken()));
1123
1087
  return;
1124
1088
  }
@@ -1144,38 +1108,25 @@ const update_matching_rows = async (table_id, viewname, { columns, layout, fixed
1144
1108
  }, req, res, body, row);
1145
1109
  }
1146
1110
  };
1147
- /**
1148
- * preparations for the form and the data row
1149
- * @param {*} viewname
1150
- * @param {*} table table of the view
1151
- * @param {*} fields all fields in table
1152
- * @param {*} param3 columns, layout, fixed, auto_save
1153
- * @param {*} param4 req, res
1154
- * @param {*} body request body
1155
- * @param {*} param6 getRowQuery, saveFileQuery, saveFileFromContentsQuery, optionsQuery, getRowByIdQuery
1156
- * @param {*} remote
1157
- * @returns null on error, { form, row, pk, id } on success
1158
- */
1159
1111
  const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_save }, { req, res }, body, { getRowQuery, saveFileQuery, saveFileFromContentsQuery, optionsQuery, getRowByIdQuery, }, remote) => {
1160
1112
  const isRemote = !isWeb(req);
1161
- const form = await getForm(table, viewname, columns, layout, body.id, req, isRemote);
1113
+ const form = await (0, viewable_fields_1.getForm)(table, viewname, columns, layout, body.id, req, isRemote);
1162
1114
  if (auto_save)
1163
1115
  form.onChange = `saveAndContinueDelayed(this, ${!isWeb(req) ? `'${form.action}'` : undefined}, event);`;
1164
1116
  Object.entries(body).forEach(([k, v]) => {
1165
1117
  const form_field = form.fields.find((f) => f.name === k);
1166
1118
  const tbl_field = fields.find((f) => f.name === k);
1167
1119
  if (tbl_field && !form_field && !fixed?.[`_block_${k}`]) {
1168
- form.fields.push(new Field({ name: k, input_type: "hidden" }));
1120
+ form.fields.push(new field_1.default({ name: k, input_type: "hidden" }));
1169
1121
  }
1170
1122
  });
1171
- setDateLocales(form, req.getLocale());
1172
- await transformForm({
1123
+ (0, viewable_fields_1.setDateLocales)(form, req.getLocale());
1124
+ await (0, viewable_fields_1.transformForm)({
1173
1125
  form,
1174
1126
  table,
1175
1127
  req,
1176
- row: body[table.pk_name]
1177
- ? { [table.pk_name]: body[table.pk_name] }
1178
- : undefined,
1128
+ res,
1129
+ row: body[table.pk_name] ? { [table.pk_name]: body[table.pk_name] } : null,
1179
1130
  getRowQuery,
1180
1131
  viewname,
1181
1132
  optionsQuery,
@@ -1189,7 +1140,7 @@ const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_s
1189
1140
  if (req.xhr)
1190
1141
  res.status(422);
1191
1142
  await form.fill_fkey_options(false, optionsQuery, req.user);
1192
- const view = View.findOne({ name: viewname });
1143
+ const view = view_1.default.findOne({ name: viewname });
1193
1144
  res.sendWrap({ title: viewname, no_menu: view?.attributes?.no_menu }, renderForm(form, req.csrfToken ? req.csrfToken() : false));
1194
1145
  return null;
1195
1146
  }
@@ -1208,7 +1159,7 @@ const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_s
1208
1159
  id = pk.type.read(body[pk.name]);
1209
1160
  }
1210
1161
  if (typeof id === "undefined") {
1211
- const use_fixed = await fill_presets(table, req, fixed);
1162
+ const use_fixed = await (0, viewable_fields_1.fill_presets)(table, req, fixed);
1212
1163
  row = { ...use_fixed, ...form.values };
1213
1164
  }
1214
1165
  else if (cancel) {
@@ -1233,7 +1184,7 @@ const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_s
1233
1184
  if (body[field.name]) {
1234
1185
  if (body[field.name].startsWith("data:")) {
1235
1186
  const path_to_serve = await saveFileQuery(body[field.name], field.id, field.fieldview, row);
1236
- const storedValue = File.fieldValueFromRelative(path_to_serve);
1187
+ const storedValue = file_1.default.fieldValueFromRelative(path_to_serve);
1237
1188
  row[field.name] = storedValue;
1238
1189
  form.values[field.name] = storedValue;
1239
1190
  }
@@ -1242,7 +1193,7 @@ const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_s
1242
1193
  else if (field.fieldviewObj?.editContent) {
1243
1194
  if (body[field.name]) {
1244
1195
  const path_to_serve = await saveFileFromContentsQuery(body[`_content_${field.name}`], field.id, field.fieldview, row, body[field.name], "utf8");
1245
- const storedValue = File.fieldValueFromRelative(path_to_serve);
1196
+ const storedValue = file_1.default.fieldValueFromRelative(path_to_serve);
1246
1197
  row[field.name] = storedValue;
1247
1198
  form.values[field.name] = storedValue;
1248
1199
  }
@@ -1252,21 +1203,21 @@ const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_s
1252
1203
  throw new Error("The mobile-app supports no local files, please use a remote table.");
1253
1204
  }
1254
1205
  if (isWeb(req)) {
1255
- const file = await File.from_req_files(req.files[field.name], req.user ? req.user.id : null, (field.attributes && +field.attributes.min_role_read) || 1, field?.attributes?.folder);
1206
+ const file = await file_1.default.from_req_files(req.files[field.name], req.user ? req.user.id : undefined, (field.attributes && +field.attributes.min_role_read) || 1, field?.attributes?.folder);
1256
1207
  row[field.name] = file.field_value;
1257
1208
  form.values[field.name] = file.field_value;
1258
1209
  }
1259
1210
  else {
1260
1211
  const file = req.files[field.name];
1261
1212
  if (file) {
1262
- const serverResp = await File.upload(req.files[field.name]);
1213
+ const serverResp = await file_1.default.upload(req.files[field.name]);
1263
1214
  if (serverResp?.location)
1264
- row[field.name] = File.normalizeFieldValueInput(serverResp.location);
1215
+ row[field.name] = file_1.default.normalizeFieldValueInput(serverResp.location);
1265
1216
  }
1266
1217
  }
1267
1218
  }
1268
1219
  else if (typeof body[`__exisiting_file_${field.name}`] === "string") {
1269
- row[field.name] = File.normalizeFieldValueInput(body[`__exisiting_file_${field.name}`]);
1220
+ row[field.name] = file_1.default.normalizeFieldValueInput(body[`__exisiting_file_${field.name}`]);
1270
1221
  form.values[field.name] = row[field.name];
1271
1222
  }
1272
1223
  else {
@@ -1275,19 +1226,6 @@ const prepare = async (viewname, table, fields, { columns, layout, fixed, auto_s
1275
1226
  }
1276
1227
  return { form, row, pk, id };
1277
1228
  };
1278
- /**
1279
- * take care of final redirect
1280
- * @param {*} viewname
1281
- * @param {*} table_id id of the table of the view
1282
- * @param {*} fields all fields in table
1283
- * @param {*} pk private key field
1284
- * @param {*} param4 view_when_done, formula_destinations, destination_type, dest_url_formula, page_when_done, page_group_when_done, redirect
1285
- * @param {*} req
1286
- * @param {*} res
1287
- * @param {*} body reuqest body
1288
- * @param {*} row row of the form
1289
- * @returns
1290
- */
1291
1229
  const whenDone = async (viewname, table_id, fields, pk, { view_when_done, formula_destinations, destination_type, dest_url_formula, page_when_done, page_group_when_done, redirect, }, req, res, body, row0, trigger_return, check_ajax, originalID, table) => {
1292
1230
  const res_redirect = (url) => {
1293
1231
  if (check_ajax && req.xhr && !req.smr)
@@ -1315,7 +1253,6 @@ const whenDone = async (viewname, table_id, fields, pk, { view_when_done, formul
1315
1253
  if (table &&
1316
1254
  ((originalID && destination_type === "URL formula") ||
1317
1255
  (use_view_when_done || "").includes("."))) {
1318
- // Refetch row as there can be fields not included in form
1319
1256
  const db_row = await table.getRow({ [table.pk_name]: originalID });
1320
1257
  row = { ...db_row, ...row0 };
1321
1258
  }
@@ -1353,20 +1290,20 @@ const whenDone = async (viewname, table_id, fields, pk, { view_when_done, formul
1353
1290
  return;
1354
1291
  }
1355
1292
  const [viewname_when_done, relation] = use_view_when_done.split(".");
1356
- const nxview = View.findOne({ name: viewname_when_done });
1293
+ const nxview = view_1.default.findOne({ name: viewname_when_done });
1357
1294
  if (!nxview) {
1358
1295
  req.flash("warning", `View "${use_view_when_done}" not found - change "View when done" in "${viewname}" view`);
1359
1296
  res_redirect(`/`);
1360
1297
  }
1361
1298
  else {
1362
1299
  const state_fields = await nxview.get_state_fields();
1363
- let target = `/view/${text(viewname_when_done)}`;
1300
+ let target = `/view/${(0, tags_1.text)(viewname_when_done)}`;
1364
1301
  let query = "";
1365
1302
  if ((nxview.table_id === table_id || relation) &&
1366
1303
  state_fields.some((sf) => sf.name === pk.name) &&
1367
1304
  viewname_when_done !== viewname) {
1368
- const get_query = get_view_link_query(fields, nxview);
1369
- query = relation ? `?${pk.name}=${text(row[relation])}` : get_query(row);
1305
+ const get_query = (0, viewable_fields_1.get_view_link_query)(fields, nxview);
1306
+ query = relation ? `?${pk.name}=${(0, tags_1.text)(row[relation])}` : get_query(row);
1370
1307
  }
1371
1308
  const redirectPath = `${target}${query}`;
1372
1309
  if (!isWeb(req)) {
@@ -1377,29 +1314,25 @@ const whenDone = async (viewname, table_id, fields, pk, { view_when_done, formul
1377
1314
  }
1378
1315
  }
1379
1316
  };
1380
- /**
1381
- * @param {*} results results from updateMatchingQuery
1382
- * @returns success, danger, goto
1383
- */
1384
1317
  const combineResults = (results) => {
1385
1318
  const combined = { success: [], danger: [] };
1386
1319
  for (const uptResult of results) {
1387
1320
  const trigger_return = uptResult.trigger_return || {};
1388
1321
  if (trigger_return.notify && trigger_return.details)
1389
- combined.success.push(div({ class: "d-inline" }, trigger_return.notify, button({
1322
+ combined.success.push((0, tags_1.div)({ class: "d-inline" }, trigger_return.notify, (0, tags_1.button)({
1390
1323
  class: "btn btn-sm btn-outline-secondary btn-xs",
1391
1324
  type: "button",
1392
1325
  "data-bs-toggle": "collapse",
1393
1326
  "data-bs-target": "#notifyDetails",
1394
1327
  "aria-expanded": "false",
1395
1328
  "aria-controls": "notifyDetails",
1396
- }, i({ class: "fas fa-plus" })), div({ class: "collapse", id: "notifyDetails" }, pre(trigger_return.details))));
1329
+ }, (0, tags_1.i)({ class: "fas fa-plus" })), (0, tags_1.div)({ class: "collapse", id: "notifyDetails" }, (0, tags_1.pre)(trigger_return.details))));
1397
1330
  else if (trigger_return.notify)
1398
1331
  combined.success.push(trigger_return.notify);
1399
1332
  if (trigger_return.error)
1400
1333
  combined.danger.push(trigger_return.error);
1401
1334
  if (trigger_return.goto && !combined.goto)
1402
- combined.trigger_return.goto;
1335
+ combined.goto = trigger_return.goto;
1403
1336
  }
1404
1337
  return combined;
1405
1338
  };
@@ -1424,9 +1357,13 @@ const tryInsertOrUpdateImpl = async (row, id, table, req) => {
1424
1357
  return ins_res;
1425
1358
  }
1426
1359
  };
1360
+ /**
1361
+ * @param param0
1362
+ * @returns
1363
+ */
1427
1364
  const createBasicView = async ({ table, viewname, template_view, template_table, all_views_created, }) => {
1428
1365
  if (!template_view) {
1429
- const configuration = await initial_config_all_fields(true)({
1366
+ const configuration = await (0, plugin_helper_1.initial_config_all_fields)(true)({
1430
1367
  table_id: table.id,
1431
1368
  });
1432
1369
  if (all_views_created.List) {
@@ -1441,9 +1378,11 @@ const createBasicView = async ({ table, viewname, template_view, template_table,
1441
1378
  templateFieldTypes[field.name] = field.type_name;
1442
1379
  templateFieldLabels[field.name] = field.label;
1443
1380
  }
1444
- const defaultBranch = findLayoutBranchWith(inner.above || inner.contents.above, (s) => {
1445
- return s.type === "field";
1446
- });
1381
+ const defaultBranch = inner
1382
+ ? findLayoutBranchWith(inner.above || inner.contents.above, (s) => {
1383
+ return s.type === "field";
1384
+ })
1385
+ : null;
1447
1386
  const inners = [], columns = [];
1448
1387
  for (const field of table.fields) {
1449
1388
  if (field.primary_key)
@@ -1453,11 +1392,12 @@ const createBasicView = async ({ table, viewname, template_view, template_table,
1453
1392
  templateFieldTypes[s.field_name] === field.type_name);
1454
1393
  }) || defaultBranch;
1455
1394
  let oldField;
1456
- traverseSync(branch, {
1457
- field(s) {
1458
- oldField = template_table.getField(s.field_name);
1459
- },
1460
- });
1395
+ if (branch)
1396
+ traverseSync(branch, {
1397
+ field(s) {
1398
+ oldField = template_table.getField(s.field_name);
1399
+ },
1400
+ });
1461
1401
  const newBranch = structuredClone(branch);
1462
1402
  let newCol = {};
1463
1403
  traverseSync(newBranch, {
@@ -1482,7 +1422,7 @@ const createBasicView = async ({ table, viewname, template_view, template_table,
1482
1422
  //clone any actions in inner
1483
1423
  for (const tmpl_inner of inner.above || inner.contents.above) {
1484
1424
  let hasField = false;
1485
- let hasAction = null;
1425
+ let hasAction = false;
1486
1426
  const theActions = [];
1487
1427
  traverseSync(tmpl_inner, {
1488
1428
  field() {
@@ -1513,22 +1453,27 @@ const createBasicView = async ({ table, viewname, template_view, template_table,
1513
1453
  cfg.split_paste = template_view.configuration.split_paste;
1514
1454
  return cfg;
1515
1455
  };
1456
+ /**
1457
+ * @param table_id
1458
+ * @param viewname
1459
+ * @param param2
1460
+ * @returns
1461
+ */
1516
1462
  const virtual_triggers = (table_id, viewname, { enable_realtime, update_events }) => {
1517
1463
  if (!enable_realtime)
1518
1464
  return [];
1519
- const table = Table.findOne({ id: table_id });
1520
- const view = View.findOne({ name: viewname });
1465
+ const table = table_1.default.findOne({ id: table_id });
1466
+ const view = view_1.default.findOne({ name: viewname });
1521
1467
  return [
1522
1468
  {
1523
1469
  when_trigger: "Update",
1524
1470
  table_id: table_id,
1525
1471
  run: async (row, { old_row, user }) => {
1526
1472
  getState().log(6, `Virtual trigger Update for ${viewname} on table ${table.name}`);
1527
- // find changed columns within the layout
1528
1473
  const fields = table.getFields();
1529
1474
  const changedFields = fields.filter((f) => {
1530
1475
  if (f.name === table.pk_name)
1531
- return false; // no id changes
1476
+ return false;
1532
1477
  const a = row[f.name];
1533
1478
  const b = old_row[f.name];
1534
1479
  if (f.type?.equals)
@@ -1548,14 +1493,13 @@ const virtual_triggers = (table_id, viewname, { enable_realtime, update_events }
1548
1493
  getState().log(6, "No layout fields changed, skipping real-time update");
1549
1494
  }
1550
1495
  else {
1551
- // build and emit updates
1552
1496
  const updates = {};
1553
1497
  for (const fieldName of changedLayoutFields) {
1554
1498
  const newVal = row[fieldName];
1555
1499
  updates[fieldName] = newVal;
1556
1500
  }
1557
1501
  const rowId = row[table.pk_name];
1558
- const actionResults = await runCollabEvents(update_events, user, {
1502
+ const actionResults = await (0, plugin_helper_1.runCollabEvents)(update_events, user, {
1559
1503
  new_row: row,
1560
1504
  old_row: old_row,
1561
1505
  updates: updates,
@@ -1587,34 +1531,35 @@ module.exports = {
1587
1531
  authorise_post,
1588
1532
  virtual_triggers,
1589
1533
  /**
1590
- * @param {object} opts
1591
- * @param {object} opts.query
1592
- * @param {...*} opts.rest
1593
- * @returns {Promise<boolean>}
1534
+ * @param param0
1535
+ * @param param1
1536
+ * @returns
1594
1537
  */
1595
- authorise_get: async ({ query, table_id, req }, { authorizeGetQuery }) => {
1538
+ authorise_get: async ({ query, table_id, req, }, { authorizeGetQuery }) => {
1596
1539
  return await authorizeGetQuery(query, table_id);
1597
1540
  },
1598
1541
  /**
1599
- * @param {object} opts
1600
- * @param {Layout} opts.layout
1601
- * @returns {string[]}
1542
+ * @param param0
1543
+ * @returns
1602
1544
  */
1603
1545
  getStringsForI18n({ layout }) {
1604
1546
  return getStringsForI18n(layout);
1605
1547
  },
1548
+ /**
1549
+ * @param param0
1550
+ * @returns
1551
+ */
1606
1552
  queries: ({ table_id, name, configuration: { columns, default_state, layout, auto_save, split_paste, destination_type, fixed, confirm_leave, auto_create, delete_unchanged_auto_create, enable_realtime, update_events, }, req, res, }) => ({
1607
1553
  async editQuery(state, mobileReferrer, isPreview, hiddenLoginDest) {
1608
- const table = Table.findOne({ id: table_id });
1554
+ const table = table_1.default.findOne({ id: table_id });
1609
1555
  const fields = table.getFields();
1610
- const { uniques } = splitUniques(fields, state);
1556
+ const { uniques } = (0, viewable_fields_1.splitUniques)(fields, state);
1611
1557
  let row = null;
1612
1558
  let auto_created_row = false;
1613
1559
  const unique_constraints = table.constraints.filter((tc) => tc.type === "Unique");
1614
1560
  const getRow = async (where) => {
1615
- // add joinfields from certain locations if they are not fields in columns
1616
1561
  const joinFields = {};
1617
- const picked = picked_fields_to_query([], fields, layout, req, table);
1562
+ const picked = (0, plugin_helper_1.picked_fields_to_query)([], fields, layout, req, table);
1618
1563
  const colFields = new Set(columns.map((c) => c.join_field ? c.join_field.split(".")[0] : c.field_name));
1619
1564
  Object.entries(picked.joinFields).forEach(([nm, jfv]) => {
1620
1565
  if (!colFields.has(jfv.ref))
@@ -1658,7 +1603,7 @@ module.exports = {
1658
1603
  else if (f.type.sql_name === "text")
1659
1604
  row[f.name] = "";
1660
1605
  });
1661
- const use_fixed = await fill_presets(table, req, fixed);
1606
+ const use_fixed = await (0, viewable_fields_1.fill_presets)(table, req, fixed);
1662
1607
  row = { ...row, ...use_fixed };
1663
1608
  row.id = await table.insertRow(row, req.user);
1664
1609
  auto_created_row = true;
@@ -1689,16 +1634,16 @@ module.exports = {
1689
1634
  });
1690
1635
  },
1691
1636
  async editManyQuery(state, { limit, offset, orderBy, orderDesc, where }) {
1692
- const table = Table.findOne({ id: table_id });
1637
+ const table = table_1.default.findOne({ id: table_id });
1693
1638
  const fields = table.getFields();
1694
- const { joinFields, aggregations } = picked_fields_to_query(columns, fields, undefined, req, table);
1695
- const qstate = stateFieldsToWhere({
1639
+ const { joinFields, aggregations } = (0, plugin_helper_1.picked_fields_to_query)(columns, fields, undefined, req, table);
1640
+ const qstate = (0, plugin_helper_1.stateFieldsToWhere)({
1696
1641
  fields,
1697
1642
  state,
1698
1643
  table,
1699
1644
  prefix: "a.",
1700
1645
  });
1701
- const q = stateFieldsToQuery({ state, fields });
1646
+ const q = (0, plugin_helper_1.stateFieldsToQuery)({ state, fields });
1702
1647
  if (where)
1703
1648
  mergeIntoWhere(qstate, where);
1704
1649
  const rows = await table.getJoinedRows({
@@ -1720,18 +1665,18 @@ module.exports = {
1720
1665
  };
1721
1666
  },
1722
1667
  async tryInsertQuery(row) {
1723
- const table = Table.findOne({ id: table_id });
1668
+ const table = table_1.default.findOne({ id: table_id });
1724
1669
  const result = {};
1725
1670
  const ins_res = await table.tryInsertRow(row, req.user || { role_id: 100 }, result);
1726
1671
  ins_res.trigger_return = result;
1727
1672
  return ins_res;
1728
1673
  },
1729
1674
  async tryUpdateQuery(row, id) {
1730
- const table = Table.findOne(table_id);
1675
+ const table = table_1.default.findOne(table_id);
1731
1676
  return await tryUpdateImpl(row, id, table, req);
1732
1677
  },
1733
1678
  async saveFileQuery(fieldVal, fieldId, fieldView, row) {
1734
- const field = await Field.findOne({ id: fieldId });
1679
+ const field = await field_1.default.findOne({ id: fieldId });
1735
1680
  const column = columns.find((c) => c.type === "Field" && c.field_name === field.name);
1736
1681
  field.fieldviewObj = getState().fileviews[fieldView];
1737
1682
  const [pre, allData] = fieldVal.split(",");
@@ -1746,11 +1691,11 @@ module.exports = {
1746
1691
  ...field.attributes,
1747
1692
  ...(column?.configuration || {}),
1748
1693
  });
1749
- const file = await File.from_contents(filename, mimetype, buffer, req.user?.id, field.attributes.min_role_read || 1, folder);
1750
- return File.fieldValueFromRelative(file.path_to_serve);
1694
+ const file = await file_1.default.from_contents(filename, mimetype, buffer, req.user?.id, field.attributes.min_role_read || 1, folder);
1695
+ return file_1.default.fieldValueFromRelative(file.path_to_serve);
1751
1696
  },
1752
1697
  async saveFileFromContentsQuery(fieldVal, fieldId, fieldView, row, filename, encoding = "base64") {
1753
- const field = await Field.findOne({ id: fieldId });
1698
+ const field = await field_1.default.findOne({ id: fieldId });
1754
1699
  const column = columns.find((c) => c.type === "Field" && c.field_name === field.name);
1755
1700
  field.fieldviewObj = getState().fileviews[fieldView];
1756
1701
  let mimetype, allData;
@@ -1762,38 +1707,38 @@ module.exports = {
1762
1707
  else {
1763
1708
  allData = fieldVal;
1764
1709
  mimetype =
1765
- (filename && File.nameToMimeType(filename)) ||
1710
+ (filename && file_1.default.nameToMimeType(filename)) ||
1766
1711
  "application/octet-stream";
1767
1712
  }
1768
1713
  const buffer = require("buffer/").Buffer.from(allData, encoding);
1769
1714
  const filename1 = filename || "file";
1770
- const existing_file = await File.findOne(filename1);
1715
+ const existing_file = await file_1.default.findOne(filename1);
1771
1716
  if (existing_file) {
1772
1717
  if (existing_file.min_role_read >= (req.user?.role_id || 100)) {
1773
1718
  await existing_file.overwrite_contents(buffer);
1774
- return File.fieldValueFromRelative(existing_file.path_to_serve);
1719
+ return file_1.default.fieldValueFromRelative(existing_file.path_to_serve);
1775
1720
  }
1776
1721
  else
1777
1722
  throw new Error("Not authorized to write file");
1778
1723
  }
1779
- const file = await File.from_contents(filename1, mimetype, buffer, req.user?.id, field.attributes.min_role_read || 1);
1780
- return File.fieldValueFromRelative(file.path_to_serve);
1724
+ const file = await file_1.default.from_contents(filename1, mimetype, buffer, req.user?.id, field.attributes.min_role_read || 1);
1725
+ return file_1.default.fieldValueFromRelative(file.path_to_serve);
1781
1726
  },
1782
- async authorizePostQuery(body, table_id /*overwrites*/) {
1727
+ async authorizePostQuery(body, table_id) {
1783
1728
  return await doAuthPost({ body, table_id, req });
1784
1729
  },
1785
1730
  async authorizeGetQuery(query, table_id) {
1786
1731
  let body = query || {};
1787
- const table = Table.findOne({ id: table_id });
1732
+ const table = table_1.default.findOne({ id: table_id });
1788
1733
  if (Object.keys(body).length == 1) {
1789
1734
  if (table.ownership_field_id || table.ownership_formula) {
1790
1735
  const fields = table.getFields();
1791
- const { uniques } = splitUniques(fields, body);
1736
+ const { uniques } = (0, viewable_fields_1.splitUniques)(fields, body);
1792
1737
  if (Object.keys(uniques).length > 0) {
1793
1738
  const joinFields = {};
1794
1739
  if (table.ownership_formula) {
1795
1740
  const freeVars = freeVariables(table.ownership_formula);
1796
- add_free_variables_to_joinfields(freeVars, joinFields, fields);
1741
+ (0, plugin_helper_1.add_free_variables_to_joinfields)(freeVars, joinFields, fields);
1797
1742
  }
1798
1743
  const row = await table.getJoinedRows({
1799
1744
  where: uniques,
@@ -1802,7 +1747,7 @@ module.exports = {
1802
1747
  if (row.length > 0)
1803
1748
  return table.is_owner(req.user, row[0]);
1804
1749
  else
1805
- return true; // TODO ??
1750
+ return true;
1806
1751
  }
1807
1752
  else {
1808
1753
  return true;
@@ -1815,7 +1760,7 @@ module.exports = {
1815
1760
  return doAuthPost({ body, table_id, req });
1816
1761
  },
1817
1762
  async getRowQuery(table_id, view_select, row_id, order_field) {
1818
- const childTable = Table.findOne({ id: table_id });
1763
+ const childTable = table_1.default.findOne({ id: table_id });
1819
1764
  return await childTable.getRows({
1820
1765
  [view_select.field_name]: row_id,
1821
1766
  }, {
@@ -1825,7 +1770,7 @@ module.exports = {
1825
1770
  });
1826
1771
  },
1827
1772
  async getRowByIdQuery(id) {
1828
- const table = Table.findOne({ id: table_id });
1773
+ const table = table_1.default.findOne({ id: table_id });
1829
1774
  return await table.getRow(typeof id === "object" ? id : { id }, {
1830
1775
  forUser: req.user,
1831
1776
  forPublic: !req.user,
@@ -1833,7 +1778,7 @@ module.exports = {
1833
1778
  },
1834
1779
  async actionQuery() {
1835
1780
  const { rndid, _csrf, onchange_action, onchange_field, click_action, ...body } = req.body || {};
1836
- const table = Table.findOne({ id: table_id });
1781
+ const table = table_1.default.findOne({ id: table_id });
1837
1782
  const pk_name = table.pk_name;
1838
1783
  let row = body[pk_name]
1839
1784
  ? (await table.getRow({ [pk_name]: body[pk_name] }, {
@@ -1849,14 +1794,14 @@ module.exports = {
1849
1794
  row[f.name] = valres.success;
1850
1795
  });
1851
1796
  if (fixed) {
1852
- const use_fixed = await fill_presets(table, req, fixed);
1797
+ const use_fixed = await (0, viewable_fields_1.fill_presets)(table, req, fixed);
1853
1798
  Object.keys(use_fixed).forEach((k) => {
1854
1799
  if (row[k] === null || typeof row[k] === "undefined")
1855
1800
  row[k] = use_fixed[k];
1856
1801
  });
1857
1802
  }
1858
1803
  try {
1859
- return await db.withTransaction(async () => {
1804
+ return await db_1.default.withTransaction(async () => {
1860
1805
  if (click_action) {
1861
1806
  let container;
1862
1807
  traverseSync(layout, {
@@ -1867,12 +1812,12 @@ module.exports = {
1867
1812
  });
1868
1813
  if (!container)
1869
1814
  return { json: { error: "Action not found" } };
1870
- const trigger = Trigger.findOne({ name: click_action });
1815
+ const trigger = trigger_1.default.findOne({ name: click_action });
1871
1816
  if (!trigger)
1872
1817
  throw new Error(`View ${name}: Container click action ${click_action} not found`);
1873
1818
  const result = await trigger.runWithoutRow({
1874
1819
  table,
1875
- Table,
1820
+ Table: table_1.default,
1876
1821
  req,
1877
1822
  row,
1878
1823
  referrer: req?.get?.("Referrer"),
@@ -1885,12 +1830,12 @@ module.exports = {
1885
1830
  c.onchange_action === onchange_action);
1886
1831
  if (!fldCol)
1887
1832
  return { json: { error: "Field not found" } };
1888
- const trigger = Trigger.findOne({ name: onchange_action });
1833
+ const trigger = trigger_1.default.findOne({ name: onchange_action });
1889
1834
  if (!trigger)
1890
1835
  throw new Error(`View ${name}: On change action ${onchange_action} for field ${onchange_field} not found`);
1891
1836
  const result = await trigger.runWithoutRow({
1892
1837
  table,
1893
- Table,
1838
+ Table: table_1.default,
1894
1839
  req,
1895
1840
  row,
1896
1841
  referrer: req?.get?.("Referrer"),
@@ -1900,7 +1845,7 @@ module.exports = {
1900
1845
  }
1901
1846
  else {
1902
1847
  const col = columns.find((c) => c.type === "Action" && c.rndid === rndid && rndid);
1903
- const result = await run_action_column({
1848
+ const result = await (0, plugin_helper_1.run_action_column)({
1904
1849
  col,
1905
1850
  req,
1906
1851
  table,
@@ -1910,7 +1855,6 @@ module.exports = {
1910
1855
  columns,
1911
1856
  viewname: name,
1912
1857
  });
1913
- //console.log("result", result);
1914
1858
  return { json: { success: "ok", ...(result || {}) } };
1915
1859
  }
1916
1860
  });
@@ -1921,7 +1865,7 @@ module.exports = {
1921
1865
  }
1922
1866
  },
1923
1867
  async optionsQuery(reftable_name, type, attributes, where) {
1924
- const refTable = Table.findOne({ name: reftable_name });
1868
+ const refTable = table_1.default.findOne({ name: reftable_name });
1925
1869
  const rows = await refTable.getRows(where, {
1926
1870
  forUser: req.user,
1927
1871
  forPublic: !req.user,
@@ -1929,7 +1873,7 @@ module.exports = {
1929
1873
  return rows;
1930
1874
  },
1931
1875
  async updateMatchingQuery(where, updateVals, repeatFields, childRows) {
1932
- const table = Table.findOne(table_id);
1876
+ const table = table_1.default.findOne(table_id);
1933
1877
  const rows = await table.getRows(where, {
1934
1878
  forUser: req.user,
1935
1879
  forPublic: !req.user,
@@ -1939,18 +1883,18 @@ module.exports = {
1939
1883
  try {
1940
1884
  if (rows.length === 0)
1941
1885
  return results;
1942
- await db.begin();
1886
+ await db_1.default.begin();
1943
1887
  inTransaction = true;
1944
1888
  for (const row of rows) {
1945
1889
  const uptRes = await tryUpdateImpl(updateVals, row.id, table, req);
1946
1890
  if (uptRes.error) {
1947
1891
  inTransaction = false;
1948
- await db.rollback();
1892
+ await db_1.default.rollback();
1949
1893
  return { rowError: uptRes.error };
1950
1894
  }
1951
1895
  results.push(uptRes);
1952
1896
  for (const field of repeatFields) {
1953
- const childTable = Table.findOne({ id: field.metadata?.table_id });
1897
+ const childTable = table_1.default.findOne({ id: field.metadata?.table_id });
1954
1898
  await childTable.deleteRows({ [field.metadata?.relation]: row.id }, req.user || { role_id: 100 });
1955
1899
  for (const childRow of childRows[field.name]) {
1956
1900
  childRow[field.metadata?.relation] = row.id;
@@ -1959,31 +1903,37 @@ module.exports = {
1959
1903
  const insRes = await childTable.tryInsertRow(insRow, req.user || { role_id: 100 });
1960
1904
  if (insRes.error) {
1961
1905
  inTransaction = false;
1962
- await db.rollback();
1906
+ await db_1.default.rollback();
1963
1907
  return { inEditError: insRes.error };
1964
1908
  }
1965
1909
  }
1966
1910
  }
1967
1911
  }
1968
1912
  if (inTransaction)
1969
- await db.commit();
1913
+ await db_1.default.commit();
1970
1914
  }
1971
1915
  catch (error) {
1972
1916
  if (inTransaction)
1973
- await db.rollback();
1917
+ await db_1.default.rollback();
1974
1918
  return { error: error.message };
1975
1919
  }
1976
1920
  return results;
1977
1921
  },
1978
1922
  }),
1979
1923
  routes: { run_action, update_matching_rows },
1924
+ /**
1925
+ * @param table_id
1926
+ * @param title
1927
+ * @param state
1928
+ * @returns
1929
+ */
1980
1930
  async interpolate_title_string(table_id, title, state) {
1981
- const tbl = Table.findOne(table_id);
1931
+ const tbl = table_1.default.findOne(table_id);
1982
1932
  if (state?.[tbl.pk_name]) {
1983
1933
  const freeVars = freeVariablesInInterpolation(title);
1984
1934
  const joinFields = {};
1985
1935
  const aggregations = {};
1986
- add_free_variables_to_joinfields(freeVars, joinFields, tbl.fields);
1936
+ (0, plugin_helper_1.add_free_variables_to_joinfields)(freeVars, joinFields, tbl.fields);
1987
1937
  add_free_variables_to_aggregations(freeVars, aggregations, tbl);
1988
1938
  const row = await tbl.getJoinedRow({
1989
1939
  where: { [tbl.pk_name]: state[tbl.pk_name] },
@@ -1996,19 +1946,23 @@ module.exports = {
1996
1946
  return interpolate(title, null, null, "Edit view title string");
1997
1947
  }
1998
1948
  },
1949
+ /**
1950
+ * @param view
1951
+ * @returns
1952
+ */
1999
1953
  configCheck: async (view) => {
2000
1954
  const { name, configuration: { view_when_done, destination_type, dest_url_formula, formula_destinations, page_when_done, page_group_when_done, }, } = view;
2001
1955
  const errs = [];
2002
1956
  const warnings = [];
2003
1957
  if (!destination_type || destination_type === "View") {
2004
- const vwd = View.findOne({
1958
+ const vwd = view_1.default.findOne({
2005
1959
  name: (view_when_done || "").split(".")[0],
2006
1960
  });
2007
1961
  if (!vwd)
2008
1962
  warnings.push(`In View ${name}, view when done ${view_when_done} not found`);
2009
1963
  }
2010
1964
  if (destination_type === "Page") {
2011
- const page = Page.findOne({ name: page_when_done });
1965
+ const page = page_1.default.findOne({ name: page_when_done });
2012
1966
  if (!page)
2013
1967
  errs.push(`In View ${name}, page when done ${page_when_done} not found`);
2014
1968
  }
@@ -2026,13 +1980,17 @@ module.exports = {
2026
1980
  if (destination_type === "URL Formula") {
2027
1981
  expressionChecker(dest_url_formula, `In View ${name}, URL formula ${dest_url_formula} error: `, errs);
2028
1982
  }
2029
- const colcheck = await check_view_columns(view, view.configuration.columns);
1983
+ const colcheck = await (0, plugin_testing_1.check_view_columns)(view, view.configuration.columns);
2030
1984
  errs.push(...colcheck.errors);
2031
1985
  warnings.push(...colcheck.warnings);
2032
1986
  return { errors: errs, warnings };
2033
1987
  },
1988
+ /**
1989
+ * @param configuration
1990
+ * @returns
1991
+ */
2034
1992
  connectedObjects: async (configuration) => {
2035
- return extractFromLayout(configuration.layout);
1993
+ return (0, node_extract_utils_1.extractFromLayout)(configuration.layout);
2036
1994
  },
2037
1995
  };
2038
1996
  //# sourceMappingURL=edit.js.map