@saltcorn/data 1.6.0-alpha.9 → 1.6.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/dist/base-plugin/actions.d.ts +3 -3
  2. package/dist/base-plugin/actions.d.ts.map +1 -1
  3. package/dist/base-plugin/actions.js +59 -17
  4. package/dist/base-plugin/actions.js.map +1 -1
  5. package/dist/base-plugin/index.d.ts +10 -5
  6. package/dist/base-plugin/index.d.ts.map +1 -1
  7. package/dist/base-plugin/types.d.ts +7 -2
  8. package/dist/base-plugin/types.d.ts.map +1 -1
  9. package/dist/base-plugin/types.js +9 -4
  10. package/dist/base-plugin/types.js.map +1 -1
  11. package/dist/base-plugin/viewtemplates/edit.d.ts.map +1 -1
  12. package/dist/base-plugin/viewtemplates/edit.js +3 -0
  13. package/dist/base-plugin/viewtemplates/edit.js.map +1 -1
  14. package/dist/base-plugin/viewtemplates/filter.d.ts.map +1 -1
  15. package/dist/base-plugin/viewtemplates/filter.js +11 -3
  16. package/dist/base-plugin/viewtemplates/filter.js.map +1 -1
  17. package/dist/base-plugin/viewtemplates/list.d.ts +2 -1
  18. package/dist/base-plugin/viewtemplates/list.d.ts.map +1 -1
  19. package/dist/base-plugin/viewtemplates/list.js +6 -1
  20. package/dist/base-plugin/viewtemplates/list.js.map +1 -1
  21. package/dist/base-plugin/viewtemplates/show.d.ts.map +1 -1
  22. package/dist/base-plugin/viewtemplates/show.js +3 -0
  23. package/dist/base-plugin/viewtemplates/show.js.map +1 -1
  24. package/dist/db/state.d.ts +4 -0
  25. package/dist/db/state.d.ts.map +1 -1
  26. package/dist/db/state.js +27 -4
  27. package/dist/db/state.js.map +1 -1
  28. package/dist/migrate.d.ts.map +1 -1
  29. package/dist/migrate.js +9 -4
  30. package/dist/migrate.js.map +1 -1
  31. package/dist/migrations/202603101553.d.ts +4 -0
  32. package/dist/migrations/202603101553.d.ts.map +1 -0
  33. package/dist/migrations/202603101553.js +22 -0
  34. package/dist/migrations/202603101553.js.map +1 -0
  35. package/dist/mobile-mocks/node/assert.d.ts +1 -0
  36. package/dist/mobile-mocks/node/assert.d.ts.map +1 -0
  37. package/dist/mobile-mocks/node/assert.js +2 -0
  38. package/dist/mobile-mocks/node/assert.js.map +1 -0
  39. package/dist/models/expression.d.ts +1 -1
  40. package/dist/models/expression.d.ts.map +1 -1
  41. package/dist/models/expression.js +51 -16
  42. package/dist/models/expression.js.map +1 -1
  43. package/dist/models/field.d.ts.map +1 -1
  44. package/dist/models/field.js +67 -10
  45. package/dist/models/field.js.map +1 -1
  46. package/dist/models/index.d.ts +1 -1
  47. package/dist/models/index.d.ts.map +1 -1
  48. package/dist/models/internal/push_message_helper.d.ts.map +1 -1
  49. package/dist/models/internal/push_message_helper.js +5 -2
  50. package/dist/models/internal/push_message_helper.js.map +1 -1
  51. package/dist/models/metadata.d.ts +2 -1
  52. package/dist/models/metadata.d.ts.map +1 -1
  53. package/dist/models/metadata.js +5 -0
  54. package/dist/models/metadata.js.map +1 -1
  55. package/dist/models/page.d.ts.map +1 -1
  56. package/dist/models/page.js +3 -1
  57. package/dist/models/page.js.map +1 -1
  58. package/dist/models/plugin.d.ts +2 -2
  59. package/dist/models/plugin.d.ts.map +1 -1
  60. package/dist/models/plugin.js +2 -2
  61. package/dist/models/plugin.js.map +1 -1
  62. package/dist/models/table.d.ts +8 -0
  63. package/dist/models/table.d.ts.map +1 -1
  64. package/dist/models/table.js +196 -83
  65. package/dist/models/table.js.map +1 -1
  66. package/dist/models/trigger.d.ts.map +1 -1
  67. package/dist/models/trigger.js +20 -9
  68. package/dist/models/trigger.js.map +1 -1
  69. package/dist/models/user.d.ts.map +1 -1
  70. package/dist/models/user.js +4 -0
  71. package/dist/models/user.js.map +1 -1
  72. package/dist/models/workflow.d.ts.map +1 -1
  73. package/dist/models/workflow.js +6 -0
  74. package/dist/models/workflow.js.map +1 -1
  75. package/dist/plugin-helper.d.ts.map +1 -1
  76. package/dist/plugin-helper.js +4 -0
  77. package/dist/plugin-helper.js.map +1 -1
  78. package/dist/viewable_fields.d.ts +2 -2
  79. package/dist/viewable_fields.d.ts.map +1 -1
  80. package/dist/viewable_fields.js +13 -8
  81. package/dist/viewable_fields.js.map +1 -1
  82. package/package.json +8 -8
  83. package/webpack.config.js +1 -0
  84. package/dist/tests/actions.test.d.ts +0 -2
  85. package/dist/tests/actions.test.d.ts.map +0 -1
  86. package/dist/tests/actions.test.js +0 -936
  87. package/dist/tests/actions.test.js.map +0 -1
  88. package/dist/tests/auth.test.d.ts +0 -2
  89. package/dist/tests/auth.test.d.ts.map +0 -1
  90. package/dist/tests/auth.test.js +0 -824
  91. package/dist/tests/auth.test.js.map +0 -1
  92. package/dist/tests/auxtest.test.d.ts +0 -2
  93. package/dist/tests/auxtest.test.d.ts.map +0 -1
  94. package/dist/tests/auxtest.test.js +0 -562
  95. package/dist/tests/auxtest.test.js.map +0 -1
  96. package/dist/tests/base.test.d.ts +0 -2
  97. package/dist/tests/base.test.d.ts.map +0 -1
  98. package/dist/tests/base.test.js +0 -30
  99. package/dist/tests/base.test.js.map +0 -1
  100. package/dist/tests/calc.test.d.ts +0 -2
  101. package/dist/tests/calc.test.d.ts.map +0 -1
  102. package/dist/tests/calc.test.js +0 -1081
  103. package/dist/tests/calc.test.js.map +0 -1
  104. package/dist/tests/composite_pk.test.d.ts +0 -2
  105. package/dist/tests/composite_pk.test.d.ts.map +0 -1
  106. package/dist/tests/composite_pk.test.js +0 -98
  107. package/dist/tests/composite_pk.test.js.map +0 -1
  108. package/dist/tests/config.test.d.ts +0 -2
  109. package/dist/tests/config.test.d.ts.map +0 -1
  110. package/dist/tests/config.test.js +0 -86
  111. package/dist/tests/config.test.js.map +0 -1
  112. package/dist/tests/db.test.d.ts +0 -2
  113. package/dist/tests/db.test.d.ts.map +0 -1
  114. package/dist/tests/db.test.js +0 -178
  115. package/dist/tests/db.test.js.map +0 -1
  116. package/dist/tests/discover.test.d.ts +0 -2
  117. package/dist/tests/discover.test.d.ts.map +0 -1
  118. package/dist/tests/discover.test.js +0 -245
  119. package/dist/tests/discover.test.js.map +0 -1
  120. package/dist/tests/edit.test.d.ts +0 -2
  121. package/dist/tests/edit.test.d.ts.map +0 -1
  122. package/dist/tests/edit.test.js +0 -1161
  123. package/dist/tests/edit.test.js.map +0 -1
  124. package/dist/tests/email.test.d.ts +0 -2
  125. package/dist/tests/email.test.d.ts.map +0 -1
  126. package/dist/tests/email.test.js +0 -255
  127. package/dist/tests/email.test.js.map +0 -1
  128. package/dist/tests/exact_views.test.d.ts +0 -2
  129. package/dist/tests/exact_views.test.d.ts.map +0 -1
  130. package/dist/tests/exact_views.test.js +0 -1363
  131. package/dist/tests/exact_views.test.js.map +0 -1
  132. package/dist/tests/field.test.d.ts +0 -2
  133. package/dist/tests/field.test.d.ts.map +0 -1
  134. package/dist/tests/field.test.js +0 -588
  135. package/dist/tests/field.test.js.map +0 -1
  136. package/dist/tests/fieldviews.test.d.ts +0 -2
  137. package/dist/tests/fieldviews.test.d.ts.map +0 -1
  138. package/dist/tests/fieldviews.test.js +0 -74
  139. package/dist/tests/fieldviews.test.js.map +0 -1
  140. package/dist/tests/file.test.d.ts +0 -2
  141. package/dist/tests/file.test.d.ts.map +0 -1
  142. package/dist/tests/file.test.js +0 -148
  143. package/dist/tests/file.test.js.map +0 -1
  144. package/dist/tests/filter.test.d.ts +0 -2
  145. package/dist/tests/filter.test.d.ts.map +0 -1
  146. package/dist/tests/filter.test.js +0 -496
  147. package/dist/tests/filter.test.js.map +0 -1
  148. package/dist/tests/form.test.d.ts +0 -2
  149. package/dist/tests/form.test.d.ts.map +0 -1
  150. package/dist/tests/form.test.js +0 -264
  151. package/dist/tests/form.test.js.map +0 -1
  152. package/dist/tests/list.test.d.ts +0 -2
  153. package/dist/tests/list.test.d.ts.map +0 -1
  154. package/dist/tests/list.test.js +0 -1037
  155. package/dist/tests/list.test.js.map +0 -1
  156. package/dist/tests/models.test.d.ts +0 -2
  157. package/dist/tests/models.test.d.ts.map +0 -1
  158. package/dist/tests/models.test.js +0 -417
  159. package/dist/tests/models.test.js.map +0 -1
  160. package/dist/tests/page.test.d.ts +0 -2
  161. package/dist/tests/page.test.d.ts.map +0 -1
  162. package/dist/tests/page.test.js +0 -26
  163. package/dist/tests/page.test.js.map +0 -1
  164. package/dist/tests/page_group.test.d.ts +0 -2
  165. package/dist/tests/page_group.test.d.ts.map +0 -1
  166. package/dist/tests/page_group.test.js +0 -51
  167. package/dist/tests/page_group.test.js.map +0 -1
  168. package/dist/tests/plugin.test.d.ts +0 -2
  169. package/dist/tests/plugin.test.d.ts.map +0 -1
  170. package/dist/tests/plugin.test.js +0 -60
  171. package/dist/tests/plugin.test.js.map +0 -1
  172. package/dist/tests/show.test.d.ts +0 -2
  173. package/dist/tests/show.test.d.ts.map +0 -1
  174. package/dist/tests/show.test.js +0 -561
  175. package/dist/tests/show.test.js.map +0 -1
  176. package/dist/tests/state.test.d.ts +0 -2
  177. package/dist/tests/state.test.d.ts.map +0 -1
  178. package/dist/tests/state.test.js +0 -82
  179. package/dist/tests/state.test.js.map +0 -1
  180. package/dist/tests/table.test.d.ts +0 -2
  181. package/dist/tests/table.test.d.ts.map +0 -1
  182. package/dist/tests/table.test.js +0 -2717
  183. package/dist/tests/table.test.js.map +0 -1
  184. package/dist/tests/table_history.test.d.ts +0 -2
  185. package/dist/tests/table_history.test.d.ts.map +0 -1
  186. package/dist/tests/table_history.test.js +0 -413
  187. package/dist/tests/table_history.test.js.map +0 -1
  188. package/dist/tests/tag.test.d.ts +0 -2
  189. package/dist/tests/tag.test.d.ts.map +0 -1
  190. package/dist/tests/tag.test.js +0 -97
  191. package/dist/tests/tag.test.js.map +0 -1
  192. package/dist/tests/user.test.d.ts +0 -2
  193. package/dist/tests/user.test.d.ts.map +0 -1
  194. package/dist/tests/user.test.js +0 -441
  195. package/dist/tests/user.test.js.map +0 -1
  196. package/dist/tests/view.test.d.ts +0 -2
  197. package/dist/tests/view.test.d.ts.map +0 -1
  198. package/dist/tests/view.test.js +0 -699
  199. package/dist/tests/view.test.js.map +0 -1
  200. package/dist/tests/workflow.test.d.ts +0 -2
  201. package/dist/tests/workflow.test.d.ts.map +0 -1
  202. package/dist/tests/workflow.test.js +0 -303
  203. package/dist/tests/workflow.test.js.map +0 -1
  204. package/dist/tests/workflow_run.test.d.ts +0 -2
  205. package/dist/tests/workflow_run.test.d.ts.map +0 -1
  206. package/dist/tests/workflow_run.test.js +0 -922
  207. package/dist/tests/workflow_run.test.js.map +0 -1
@@ -1,699 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const table_1 = __importDefault(require("../models/table"));
7
- const field_1 = __importDefault(require("../models/field"));
8
- const view_1 = __importDefault(require("../models/view"));
9
- const db_1 = __importDefault(require("../db"));
10
- const mocks_1 = __importDefault(require("./mocks"));
11
- const { plugin_with_routes, mockReqRes } = mocks_1.default;
12
- const { getState } = require("../db/state");
13
- const assertions_1 = require("./assertions");
14
- const globals_1 = require("@jest/globals");
15
- const remote_query_helper_1 = require("./remote_query_helper");
16
- const common_helpers_1 = require("./common_helpers");
17
- getState().registerPlugin("base", require("../base-plugin"));
18
- (0, globals_1.afterAll)(db_1.default.close);
19
- (0, globals_1.beforeAll)(async () => {
20
- await require("../db/reset_schema")();
21
- await require("../db/fixtures")();
22
- });
23
- (0, globals_1.describe)("Misc view tests", () => {
24
- (0, globals_1.it)("should run with no query", async () => {
25
- const v = await view_1.default.findOne({ name: "authorlist" });
26
- (0, assertions_1.assertIsSet)(v);
27
- (0, globals_1.expect)(v.min_role).toBe(100);
28
- const res = await v.run({}, mockReqRes);
29
- (0, globals_1.expect)(res.length > 0).toBe(true);
30
- });
31
- (0, globals_1.it)("should run on page", async () => {
32
- const v = await view_1.default.findOne({ name: "authorlist" });
33
- (0, assertions_1.assertIsSet)(v);
34
- const res = await v.run_possibly_on_page({}, mockReqRes.req, mockReqRes.res);
35
- (0, globals_1.expect)(typeof res === "string" && res.length > 0).toBe(true);
36
- });
37
- (0, globals_1.it)("should run with string query", async () => {
38
- const v = await view_1.default.findOne({ name: "authorlist" });
39
- (0, assertions_1.assertIsSet)(v);
40
- const res = await v.run({ author: "Mel" }, mockReqRes);
41
- (0, globals_1.expect)(res.length > 0).toBe(true);
42
- });
43
- (0, globals_1.it)("should run with integer query as int", async () => {
44
- const v = await view_1.default.findOne({ name: "authorlist" });
45
- (0, assertions_1.assertIsSet)(v);
46
- const res = await v.run({ pages: 967 }, mockReqRes);
47
- (0, globals_1.expect)(res.length > 0).toBe(true);
48
- });
49
- (0, globals_1.it)("should run with integer query as string", async () => {
50
- const v = await view_1.default.findOne({ name: "authorlist" });
51
- (0, assertions_1.assertIsSet)(v);
52
- const res = await v.run({ pages: "967" }, mockReqRes);
53
- (0, globals_1.expect)(res.length > 0).toBe(true);
54
- });
55
- (0, globals_1.it)("should get config flow", async () => {
56
- const v = await view_1.default.findOne({ name: "authorlist" });
57
- (0, assertions_1.assertIsSet)(v);
58
- const res = await v.get_config_flow({ __: (s) => s });
59
- (0, globals_1.expect)(res.constructor.name).toBe("Workflow");
60
- (0, globals_1.expect)(res.steps.length > 0).toBe(true);
61
- });
62
- (0, globals_1.it)("should runMany with no query", async () => {
63
- const v = await view_1.default.findOne({ name: "authorshow" });
64
- (0, assertions_1.assertIsSet)(v);
65
- const res = await v.runMany({}, mockReqRes);
66
- (0, globals_1.expect)(res.length > 0).toBe(true);
67
- });
68
- (0, globals_1.it)("should runMany with operator", async () => {
69
- const v = await view_1.default.findOne({ name: "authorshow" });
70
- (0, assertions_1.assertIsSet)(v);
71
- const res = await v.runMany({ _orderBy: { operator: "near", field: "pages", target: 950 } }, mockReqRes);
72
- (0, globals_1.expect)(res[0].row.pages).toBe(967);
73
- const res1 = await v.runMany({ _orderBy: { operator: "near", field: "pages", target: 720 } }, mockReqRes);
74
- (0, globals_1.expect)(res1[0].row.pages).toBe(728);
75
- });
76
- (0, globals_1.it)("should runPost", async () => {
77
- const v = await view_1.default.findOne({ name: "authoredit" });
78
- (0, assertions_1.assertIsSet)(v);
79
- await v.runPost({}, { author: "James Joyce" }, mockReqRes);
80
- const rows = await db_1.default.select("books", {});
81
- (0, globals_1.expect)(rows).toContainEqual({
82
- author: "James Joyce",
83
- id: 3,
84
- pages: 678,
85
- publisher: null,
86
- });
87
- });
88
- (0, globals_1.it)("should runPost with edit in edit", async () => {
89
- const readingsTbl = table_1.default.findOne({ name: "readings" });
90
- (0, assertions_1.assertIsSet)(readingsTbl);
91
- await view_1.default.create({
92
- name: "innerReads",
93
- table_id: readingsTbl.id,
94
- min_role: 100,
95
- configuration: remote_query_helper_1.renderEditInEditConfig.innerEdit,
96
- viewtemplate: "Edit",
97
- });
98
- const patientsTable = table_1.default.findOne({ name: "patients" });
99
- (0, assertions_1.assertIsSet)(patientsTable);
100
- const v = await view_1.default.create({
101
- table_id: patientsTable.id,
102
- name: "PatientEditWithReads",
103
- viewtemplate: "Edit",
104
- configuration: remote_query_helper_1.renderEditInEditConfig.outerEdit,
105
- min_role: 100,
106
- });
107
- await v.runPost({}, { id: 1, favbook: 1, name: "foo", parent: 2 }, mockReqRes);
108
- const rows = await db_1.default.select("patients", {});
109
- (0, globals_1.expect)(rows).toContainEqual({
110
- favbook: 1,
111
- name: "foo",
112
- parent: 2,
113
- id: 1,
114
- });
115
- });
116
- (0, globals_1.it)("should find", async () => {
117
- const table = table_1.default.findOne({ name: "books" });
118
- (0, assertions_1.assertIsSet)(table);
119
- const link_views = await view_1.default.find({
120
- table_id: table.id,
121
- });
122
- (0, globals_1.expect)(link_views.length).toBe(11);
123
- });
124
- (0, globals_1.it)("should find where", async () => {
125
- const link_views = await view_1.default.find_all_views_where(({ viewrow }) => viewrow.name === "authorshow");
126
- (0, globals_1.expect)(link_views.length).toBe(1);
127
- });
128
- (0, globals_1.it)("should create and delete", async () => {
129
- const table = table_1.default.findOne({ name: "books" });
130
- (0, assertions_1.assertIsSet)(table);
131
- const v = await view_1.default.create({
132
- table_id: table.id,
133
- name: "anewview",
134
- viewtemplate: "List",
135
- configuration: { columns: [], default_state: { foo: "bar" } },
136
- min_role: 100,
137
- });
138
- (0, globals_1.expect)(typeof v.id).toBe("number");
139
- (0, globals_1.expect)(typeof v.viewtemplateObj).toBe("object");
140
- const st = v.combine_state_and_default_state({ baz: 3 });
141
- (0, globals_1.expect)(st).toStrictEqual({ baz: 3, foo: "bar" });
142
- await v.delete();
143
- const v1 = await view_1.default.create({
144
- table_id: table.id,
145
- name: "anewview",
146
- viewtemplate: "List",
147
- configuration: { columns: [], default_state: { foo: "bar" } },
148
- min_role: 100,
149
- });
150
- (0, assertions_1.assertIsSet)(v1.id);
151
- await view_1.default.update({ name: "anewestview" }, v1.id);
152
- await view_1.default.delete({ name: "anewestview" });
153
- });
154
- (0, globals_1.it)("should clone", async () => {
155
- const v = await view_1.default.findOne({ name: "authorlist" });
156
- (0, assertions_1.assertIsSet)(v);
157
- await v.clone();
158
- await v.clone();
159
- const v1 = await view_1.default.findOne({ name: "authorlist-copy" });
160
- (0, assertions_1.assertIsSet)(v1);
161
- (0, globals_1.expect)(!!v1).toBe(true);
162
- const v2 = await view_1.default.findOne({ name: "authorlist-copy-1" });
163
- (0, assertions_1.assertIsSet)(v2);
164
- (0, globals_1.expect)(!!v2).toBe(true);
165
- const res = await v1.run({ author: "Mel" }, mockReqRes);
166
- (0, globals_1.expect)(res.length > 0).toBe(true);
167
- });
168
- (0, globals_1.it)("list join-aggs", async () => {
169
- const table = table_1.default.findOne({ name: "books" });
170
- (0, assertions_1.assertIsSet)(table);
171
- const v = await view_1.default.create({
172
- table_id: table.id,
173
- name: "AggJoinTest",
174
- viewtemplate: "List",
175
- configuration: {
176
- columns: [
177
- {
178
- type: "Field",
179
- fieldview: "as_text",
180
- field_name: "author",
181
- state_field: "on",
182
- },
183
- {
184
- stat: "Count",
185
- type: "Aggregation",
186
- aggwhere: "",
187
- agg_field: "id",
188
- col_width: "",
189
- agg_relation: "publisher->books.publisher",
190
- header_label: "",
191
- },
192
- ],
193
- default_state: {},
194
- },
195
- min_role: 100,
196
- });
197
- const res = await v.run({}, mockReqRes);
198
- (0, globals_1.expect)(res).toBe('<div class="table-responsive"><table class="table table-sm table-valign-middle "><thead><tr><th><span onclick="sortby(\'author\', false, \'249ab\', this)" class="link-style">Author</span></th><th><span onclick="sortby(\'count_books_publisher_id_\', false, \'249ab\', this)" class="link-style">Count books</span></th></tr></thead><tbody><tr data-row-id="1"><td>Herman Melville</td><td>0</td></tr><tr data-row-id="2"><td>Leo Tolstoy</td><td>1</td></tr><tr data-row-id="3"><td>James Joyce</td><td>0</td></tr></tbody></table></div>');
199
- });
200
- (0, globals_1.it)("should interpolate titles string in Show", async () => {
201
- const v = await view_1.default.findOne({ name: "authorshow" });
202
- (0, assertions_1.assertIsSet)(v);
203
- const title = await v.interpolate_title_string("Hello {{author}} from {{publisher.name}}", { id: 2 });
204
- (0, globals_1.expect)(title).toBe("Hello Leo Tolstoy from AK Press");
205
- });
206
- (0, globals_1.it)("should interpolate titles string in Edit", async () => {
207
- const v = await view_1.default.findOne({ name: "authoredit" });
208
- (0, assertions_1.assertIsSet)(v);
209
- const title = await v.interpolate_title_string("Hello {{row?.author}}", {
210
- id: 2,
211
- });
212
- (0, globals_1.expect)(title).toBe("Hello Leo Tolstoy");
213
- });
214
- (0, globals_1.it)("should interpolate titles string in Edit", async () => {
215
- const v = await view_1.default.findOne({ name: "authoredit" });
216
- (0, assertions_1.assertIsSet)(v);
217
- const title = await v.interpolate_title_string("Hello {{row?.author}}", {});
218
- (0, globals_1.expect)(title).toBe("Hello ");
219
- });
220
- });
221
- (0, globals_1.describe)("View with routes", () => {
222
- (0, globals_1.it)("should create and delete", async () => {
223
- getState().registerPlugin("mock_plugin", plugin_with_routes());
224
- (0, globals_1.expect)(getState().viewtemplates.ViewWithRoutes.name).toBe("ViewWithRoutes");
225
- var html, json;
226
- const spy = {
227
- ...mockReqRes.res,
228
- send(h) {
229
- html = h;
230
- },
231
- json(h) {
232
- json = h;
233
- },
234
- };
235
- const table = table_1.default.findOne({ name: "books" });
236
- (0, assertions_1.assertIsSet)(table);
237
- const v = await view_1.default.create({
238
- table_id: table.id,
239
- name: "aviewwithroutes",
240
- viewtemplate: "ViewWithRoutes",
241
- configuration: {},
242
- min_role: 100,
243
- });
244
- await v.runRoute("the_json_route", {}, spy, mockReqRes);
245
- await v.runRoute("the_html_route", {}, spy, mockReqRes);
246
- await v.runRoute("the_null_route", {}, spy, mockReqRes);
247
- (0, globals_1.expect)(json).toEqual({ success: "ok" });
248
- (0, globals_1.expect)(html).toEqual("<div>Hello</div>");
249
- });
250
- });
251
- (0, globals_1.describe)("nested views", () => {
252
- (0, globals_1.it)("should create and run", async () => {
253
- const table = table_1.default.findOne({ name: "books" });
254
- (0, assertions_1.assertIsSet)(table);
255
- const small = await view_1.default.create({
256
- table_id: table.id,
257
- name: "small",
258
- viewtemplate: "Show",
259
- configuration: {
260
- layout: {
261
- above: [
262
- {
263
- aligns: ["left", "left"],
264
- widths: [2, 10],
265
- besides: [
266
- { above: [null, { type: "blank", contents: "Pages" }] },
267
- {
268
- above: [
269
- null,
270
- { type: "field", fieldview: "show", field_name: "pages" },
271
- ],
272
- },
273
- ],
274
- },
275
- { type: "line_break" },
276
- ],
277
- },
278
- columns: [{ type: "Field", fieldview: "show", field_name: "pages" }],
279
- viewname: "small",
280
- },
281
- min_role: 100,
282
- });
283
- const medium = await view_1.default.create({
284
- table_id: table.id,
285
- name: "medium",
286
- viewtemplate: "Show",
287
- configuration: {
288
- layout: {
289
- above: [
290
- {
291
- aligns: ["left", "left"],
292
- widths: [2, 10],
293
- besides: [
294
- { above: [null, { type: "blank", contents: "Author" }] },
295
- {
296
- above: [
297
- null,
298
- {
299
- type: "field",
300
- fieldview: "as_text",
301
- field_name: "author",
302
- },
303
- ],
304
- },
305
- ],
306
- },
307
- { type: "line_break" },
308
- { name: "64063e", type: "view", view: "small", state: "shared" },
309
- ],
310
- },
311
- columns: [
312
- { type: "Field", fieldview: "as_text", field_name: "author" },
313
- ],
314
- viewname: "medium",
315
- },
316
- min_role: 100,
317
- });
318
- const res = await medium.run({ id: 2 }, mockReqRes);
319
- (0, globals_1.expect)(res).toContain("Tolstoy");
320
- (0, globals_1.expect)(res).toContain("728");
321
- (0, globals_1.expect)(res).not.toContain("967");
322
- (0, globals_1.expect)(res).not.toContain("Melville");
323
- });
324
- (0, globals_1.it)("should create and run feed of nested", async () => {
325
- const table = table_1.default.findOne({ name: "books" });
326
- (0, assertions_1.assertIsSet)(table);
327
- const large = await view_1.default.create({
328
- table_id: table.id,
329
- name: "large",
330
- viewtemplate: "Feed",
331
- configuration: {
332
- cols_lg: 1,
333
- cols_md: 1,
334
- cols_sm: 1,
335
- cols_xl: 1,
336
- in_card: false,
337
- viewname: "large",
338
- show_view: "medium",
339
- descending: false,
340
- order_field: "author",
341
- view_to_create: "",
342
- create_view_display: "Link",
343
- },
344
- min_role: 100,
345
- });
346
- const res = await large.run({}, mockReqRes);
347
- (0, globals_1.expect)(res).toContain("Tolstoy");
348
- (0, globals_1.expect)(res).toContain("728");
349
- (0, globals_1.expect)(res).toContain("967");
350
- (0, globals_1.expect)(res).toContain("Melville");
351
- });
352
- });
353
- (0, globals_1.describe)("view with two level select", () => {
354
- (0, globals_1.it)("should preselect the state value", async () => {
355
- const v = view_1.default.findOne({ name: "view_with_two_level_select" });
356
- (0, assertions_1.assertIsSet)(v);
357
- const resA = await v.run({ album: 1 }, mockReqRes);
358
- (0, globals_1.expect)(resA).toContain(`value=\"1\" selected`);
359
- (0, globals_1.expect)(resA).toContain(`data-selected=\"1\"`);
360
- const resB = await v.run({ album: 2 }, mockReqRes);
361
- (0, globals_1.expect)(resB).toContain(`value=\"2\" selected`);
362
- (0, globals_1.expect)(resB).toContain(`data-selected=\"2\"`);
363
- });
364
- (0, globals_1.it)("should render without any state", async () => {
365
- const v = view_1.default.findOne({ name: "view_with_two_level_select" });
366
- (0, assertions_1.assertIsSet)(v);
367
- const resA = await v.run({ album: 1 }, mockReqRes);
368
- (0, globals_1.expect)(resA).toContain(`value=\"1\" selected`);
369
- (0, globals_1.expect)(resA).toContain(`data-selected=\"1\"`);
370
- });
371
- });
372
- (0, globals_1.describe)("subviews with relations", () => {
373
- (0, globals_1.it)("show_user_with_independent_feed", async () => {
374
- const testser = (res) => {
375
- (0, globals_1.expect)(res).toContain("Content of post APost A");
376
- (0, globals_1.expect)(res).toContain("Content of post BPost B");
377
- (0, globals_1.expect)(res).toContain("Content of post CPost C");
378
- (0, globals_1.expect)(res).toContain("blog_posts_feed");
379
- };
380
- const v = view_1.default.findOne({ name: "show_user_with_independent_feed" });
381
- (0, assertions_1.assertIsSet)(v);
382
- testser(await v.run({ id: 1 }, mockReqRes));
383
- testser(await v.run({ id: 2 }, mockReqRes));
384
- testser(await v.run({ id: 3 }, mockReqRes));
385
- });
386
- (0, globals_1.it)("blog_posts_feed with inbound relation", async () => {
387
- const v = view_1.default.findOne({ name: "show_user_with_blog_posts_feed" });
388
- (0, assertions_1.assertIsSet)(v);
389
- {
390
- const res = await v.run({ id: 1 }, mockReqRes);
391
- (0, globals_1.expect)(res).toContain("Content of post APost A");
392
- (0, globals_1.expect)(res).toContain("Content of post BPost B");
393
- (0, globals_1.expect)(res).toContain("Content of post CPost C");
394
- }
395
- {
396
- const res = await v.run({ id: 2 }, mockReqRes);
397
- (0, globals_1.expect)(res.length > 0).toBe(true);
398
- (0, globals_1.expect)(res.search("Content of post APost A")).toBe(-1);
399
- (0, globals_1.expect)(res.search("Content of post BPost B") >= 0).toBe(true);
400
- (0, globals_1.expect)(res.search("Content of post CPost C")).toBe(-1);
401
- }
402
- {
403
- const res = await v.run({ id: 3 }, mockReqRes);
404
- (0, globals_1.expect)(res.length > 0).toBe(true);
405
- (0, globals_1.expect)(res).toContain("Content of post APost A");
406
- (0, globals_1.expect)(res).toContain("Content of post BPost B");
407
- (0, globals_1.expect)(res).toContain("Content of post CPost C");
408
- }
409
- });
410
- (0, globals_1.it)("blog_in_topic_feed with inbound relation", async () => {
411
- const v = view_1.default.findOne({ name: "show_user_with_blog_in_topic_feed" });
412
- (0, assertions_1.assertIsSet)(v);
413
- {
414
- const res = await v.run({ id: 1 }, mockReqRes);
415
- (0, globals_1.expect)(res.length > 0).toBe(true);
416
- (0, globals_1.expect)(res.search("Post ATopic A") >= 0).toBe(true);
417
- (0, globals_1.expect)(res.search("Post BTopic A") >= 0).toBe(true);
418
- (0, globals_1.expect)(res.search("Post CTopic A") >= 0).toBe(true);
419
- }
420
- {
421
- const res = await v.run({ id: 2 }, mockReqRes);
422
- (0, globals_1.expect)(res.length > 0).toBe(true);
423
- (0, globals_1.expect)(res.search("Post BTopic B") >= 0).toBe(true);
424
- }
425
- {
426
- const res = await v.run({ id: 3 }, mockReqRes);
427
- (0, globals_1.expect)(res.length > 0).toBe(true);
428
- (0, globals_1.expect)(res.search("Post ATopic A") >= 0).toBe(true);
429
- (0, globals_1.expect)(res.search("Post BTopic A") >= 0).toBe(true);
430
- (0, globals_1.expect)(res.search("Post CTopic A") >= 0).toBe(true);
431
- (0, globals_1.expect)(res.search("Post BTopic B") >= 0).toBe(true);
432
- }
433
- });
434
- (0, globals_1.it)("two levels inbound", async () => {
435
- const v = view_1.default.findOne({
436
- name: "show_user_with_blog_posts_feed_two_levels",
437
- });
438
- (0, assertions_1.assertIsSet)(v);
439
- const res = await v.run({ id: 1 }, mockReqRes);
440
- (0, globals_1.expect)(res.length > 0).toBe(true);
441
- (0, globals_1.expect)(res.search("Content of post APost A") >= 0).toBe(true);
442
- (0, globals_1.expect)(res.search("Content of post BPost B")).toBe(-1);
443
- (0, globals_1.expect)(res.search("Content of post CPost C") >= 0).toBe(true);
444
- });
445
- (0, globals_1.it)("three levels inbound", async () => {
446
- /*
447
- inbound_level_two bp_inbound post
448
- inbound_level_three -> inbound_inbound -> blog_post_inbound -> blog_posts
449
- */
450
- const levelThreeInbound = await table_1.default.create("inbound_level_three");
451
- const inbound_inbound = table_1.default.findOne({ name: "inbound_inbound" });
452
- (0, assertions_1.assertIsSet)(inbound_inbound);
453
- const topics = table_1.default.findOne({ name: "topics" });
454
- (0, assertions_1.assertIsSet)(topics);
455
- await field_1.default.create({
456
- table: levelThreeInbound,
457
- name: "inbound_level_two",
458
- reftable: inbound_inbound,
459
- label: "inbound to level 2",
460
- type: "Key",
461
- attributes: { summary_field: "id" },
462
- });
463
- await field_1.default.create({
464
- table: levelThreeInbound,
465
- name: "topic",
466
- reftable: topics,
467
- label: "Topic",
468
- type: "Key",
469
- attributes: { summary_field: "id" },
470
- });
471
- await db_1.default.insert("blog_post_inbound", {
472
- post: 1,
473
- }, {
474
- ignoreExisting: true,
475
- });
476
- await db_1.default.insert("blog_post_inbound", {
477
- post: 3,
478
- }, {
479
- ignoreExisting: true,
480
- });
481
- await db_1.default.insert("inbound_inbound", {
482
- bp_inbound: 1,
483
- topic: 1,
484
- }, {
485
- ignoreExisting: true,
486
- });
487
- await db_1.default.insert("inbound_inbound", {
488
- bp_inbound: 2,
489
- topic: 1,
490
- }, {
491
- ignoreExisting: true,
492
- });
493
- const v = await view_1.default.create({
494
- table_id: 1,
495
- name: "show_user_with_blog_posts_feed_three_levels",
496
- viewtemplate: "Show",
497
- configuration: {
498
- columns: [],
499
- layout: {
500
- above: [
501
- {
502
- type: "view",
503
- view: "blog_posts_feed",
504
- relation: ".users.user_interested_in_topic$user.topic.inbound_level_three$topic.inbound_level_two.bp_inbound.post",
505
- name: "bc653",
506
- state: "shared",
507
- },
508
- ],
509
- },
510
- },
511
- min_role: 100,
512
- });
513
- {
514
- const res = await v.run({ id: 1 }, mockReqRes);
515
- (0, globals_1.expect)(res.length > 0).toBe(true);
516
- (0, globals_1.expect)(res.search("Content of post APost A")).toBe(-1);
517
- (0, globals_1.expect)(res.search("Content of post BPost B")).toBe(-1);
518
- (0, globals_1.expect)(res.search("Content of post CPost C")).toBe(-1);
519
- }
520
- await db_1.default.insert("inbound_level_three", {
521
- inbound_level_two: 1,
522
- topic: 1,
523
- });
524
- await db_1.default.insert("inbound_level_three", {
525
- inbound_level_two: 2,
526
- topic: 1,
527
- });
528
- {
529
- const res = await v.run({ id: 1 }, mockReqRes);
530
- (0, globals_1.expect)(res.length > 0).toBe(true);
531
- (0, globals_1.expect)(res.search("Content of post APost A") >= 0).toBe(true);
532
- (0, globals_1.expect)(res.search("Content of post BPost B")).toBe(-1);
533
- (0, globals_1.expect)(res.search("Content of post CPost C") >= 0).toBe(true);
534
- }
535
- });
536
- (0, globals_1.it)("employee department relation", async () => {
537
- const v = view_1.default.findOne({ name: "show_employee" });
538
- (0, assertions_1.assertIsSet)(v);
539
- {
540
- const res = await v.run({ id: 1 }, mockReqRes);
541
- (0, globals_1.expect)(res.length > 0).toBe(true);
542
- (0, globals_1.expect)(res.match(/manager/g).length).toBe(5);
543
- }
544
- {
545
- const res = await v.run({ id: 2 }, mockReqRes);
546
- (0, globals_1.expect)(res.length > 0).toBe(true);
547
- (0, globals_1.expect)(res).toContain("my_employee");
548
- (0, globals_1.expect)(res).toContain("manager");
549
- }
550
- });
551
- (0, globals_1.it)("simple post topic relation", async () => {
552
- await (0, common_helpers_1.prepareSimpleTopicPostRelation)();
553
- const v = view_1.default.findOne({ name: "show_user_with_simple_posts_list" });
554
- (0, assertions_1.assertIsSet)(v);
555
- {
556
- const res = await v.run({ id: 1 }, mockReqRes);
557
- (0, globals_1.expect)(res.length > 0).toBe(true);
558
- (0, globals_1.expect)(res.search("first post in topic A") >= 0).toBe(true);
559
- (0, globals_1.expect)(res.search("second post in topic A") >= 0).toBe(true);
560
- (0, globals_1.expect)(res.search("post in topic B")).toBe(-1);
561
- }
562
- {
563
- const res = await v.run({ id: 2 }, mockReqRes);
564
- (0, globals_1.expect)(res.length > 0).toBe(true);
565
- (0, globals_1.expect)(res.search("first post in topic A")).toBe(-1);
566
- (0, globals_1.expect)(res.search("second post in topic A")).toBe(-1);
567
- (0, globals_1.expect)(res.search("post in topic B")).toBe(-1);
568
- }
569
- {
570
- const res = await v.run({ id: 3 }, mockReqRes);
571
- (0, globals_1.expect)(res.length > 0).toBe(true);
572
- (0, globals_1.expect)(res.search("first post in topic A")).toBe(-1);
573
- (0, globals_1.expect)(res.search("second post in topic A")).toBe(-1);
574
- (0, globals_1.expect)(res.search("post in topic B")).toBe(-1);
575
- }
576
- const vlevels = view_1.default.findOne({
577
- name: "show_user_with_simple_posts_list_levels",
578
- });
579
- (0, assertions_1.assertIsSet)(vlevels);
580
- {
581
- const res = await vlevels.run({ id: 1 }, mockReqRes);
582
- (0, globals_1.expect)(res.length > 0).toBe(true);
583
- (0, globals_1.expect)(res.search("first post in topic A") >= 0).toBe(true);
584
- (0, globals_1.expect)(res.search("second post in topic A")).toBe(-1);
585
- (0, globals_1.expect)(res.search("post in topic B")).toBe(-1);
586
- }
587
- {
588
- const res = await vlevels.run({ id: 2 }, mockReqRes);
589
- (0, globals_1.expect)(res.length > 0).toBe(true);
590
- (0, globals_1.expect)(res.search("first post in topic A")).toBe(-1);
591
- (0, globals_1.expect)(res.search("second post in topic A")).toBe(-1);
592
- (0, globals_1.expect)(res.search("post in topic B")).toBe(-1);
593
- }
594
- {
595
- const res = await vlevels.run({ id: 3 }, mockReqRes);
596
- (0, globals_1.expect)(res.length > 0).toBe(true);
597
- (0, globals_1.expect)(res.search("first post in topic A")).toBe(-1);
598
- (0, globals_1.expect)(res.search("second post in topic A")).toBe(-1);
599
- (0, globals_1.expect)(res.search("post in topic B")).toBe(-1);
600
- }
601
- });
602
- });
603
- (0, globals_1.describe)("edit dest", () => {
604
- (0, globals_1.it)("standard list view", async () => {
605
- mockReqRes.reset();
606
- const v = await view_1.default.findOne({ name: "authoredit" });
607
- (0, assertions_1.assertIsSet)(v);
608
- v.configuration.view_when_done = "authorlist";
609
- await v.runPost({}, { author: "James Joyce" }, mockReqRes);
610
- (0, globals_1.expect)(mockReqRes.getStored().url).toBe("/view/authorlist");
611
- });
612
- (0, globals_1.it)("standard show view", async () => {
613
- mockReqRes.reset();
614
- const v = await view_1.default.findOne({ name: "authoredit" });
615
- (0, assertions_1.assertIsSet)(v);
616
- v.configuration.view_when_done = "authorshow";
617
- await v.runPost({}, { author: "James Joyce" }, mockReqRes);
618
- (0, globals_1.expect)(mockReqRes.getStored().url).toContain("/view/authorshow?id=");
619
- });
620
- (0, globals_1.it)("back to referrer", async () => {
621
- mockReqRes.reset();
622
- const v = await view_1.default.findOne({ name: "authoredit" });
623
- (0, assertions_1.assertIsSet)(v);
624
- v.configuration.destination_type = "Back to referer";
625
- mockReqRes.req.headers = { referer: "/bananas" };
626
- const res = await v.run({}, mockReqRes);
627
- (0, globals_1.expect)(res).toContain('<input type="hidden" class="form-control " name="_referer" value="/bananas">');
628
- await v.runPost({}, { author: "James Joyce", _referer: "/bananas" }, mockReqRes);
629
- (0, globals_1.expect)(mockReqRes.getStored().url).toBe("/bananas");
630
- });
631
- (0, globals_1.it)("url formula", async () => {
632
- mockReqRes.reset();
633
- const v = await view_1.default.findOne({ name: "authoredit" });
634
- (0, assertions_1.assertIsSet)(v);
635
- v.configuration.destination_type = "URL formula";
636
- v.configuration.dest_url_formula = "'/view/foo/'+author";
637
- await v.runPost({}, { author: "James Joyce" }, mockReqRes);
638
- (0, globals_1.expect)(mockReqRes.getStored().url).toBe("/view/foo/James Joyce");
639
- });
640
- (0, globals_1.it)("formula", async () => {
641
- mockReqRes.reset();
642
- const v = await view_1.default.findOne({ name: "authoredit" });
643
- (0, assertions_1.assertIsSet)(v);
644
- v.configuration.destination_type = "Formulas";
645
- v.configuration.formula_destinations = [
646
- {
647
- expression: "author.length>7",
648
- view: "authorlist",
649
- },
650
- {
651
- expression: "author.length<=7",
652
- view: "authorshow",
653
- },
654
- ];
655
- (0, assertions_1.assertIsSet)(v.viewtemplateObj);
656
- await v.viewtemplateObj.configCheck?.(v);
657
- await v.runPost({}, { author: "James Joyce" }, mockReqRes);
658
- (0, globals_1.expect)(mockReqRes.getStored().url).toBe("/view/authorlist");
659
- await v.runPost({}, { author: "T. Lin" }, mockReqRes);
660
- (0, globals_1.expect)(mockReqRes.getStored().url).toContain("/view/authorshow?id=");
661
- });
662
- (0, globals_1.it)("self", async () => {
663
- mockReqRes.reset();
664
- const v = await view_1.default.findOne({ name: "authoredit" });
665
- (0, assertions_1.assertIsSet)(v);
666
- v.configuration.view_when_done = "authoredit";
667
- await v.runPost({}, { author: "James Joyce" }, mockReqRes);
668
- (0, globals_1.expect)(mockReqRes.getStored().url).toBe("/view/authoredit");
669
- });
670
- });
671
- (0, globals_1.describe)("view slug", () => {
672
- (0, globals_1.it)("should enable and run", async () => {
673
- const v = await view_1.default.findOne({ name: "authorshow" });
674
- (0, assertions_1.assertIsSet)(v);
675
- const slug = {
676
- label: "/:id",
677
- steps: [
678
- {
679
- field: "id",
680
- unique: true,
681
- transform: null,
682
- },
683
- ],
684
- };
685
- v.slug = slug;
686
- await view_1.default.update({ slug }, v.id);
687
- const query = {};
688
- v.rewrite_query_from_slug(query, ["1"]);
689
- (0, globals_1.expect)(query.id).toBe("1");
690
- //const res = await v.run({}, mockReqRes);
691
- });
692
- (0, globals_1.it)("set link", async () => {
693
- const v = await view_1.default.findOne({ name: "authorlist" });
694
- (0, assertions_1.assertIsSet)(v);
695
- const res = await v.run({}, mockReqRes);
696
- (0, globals_1.expect)(res).toContain('<a href="/view/authorshow/1">authorshow</a>');
697
- });
698
- });
699
- //# sourceMappingURL=view.test.js.map