@saltcorn/data 0.6.3-beta.3 → 0.6.4-beta.3

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 (192) hide show
  1. package/dist/base-plugin/actions.d.ts.map +1 -1
  2. package/dist/base-plugin/actions.js +1 -1
  3. package/dist/base-plugin/actions.js.map +1 -1
  4. package/dist/base-plugin/index.d.ts +34 -8
  5. package/dist/base-plugin/index.d.ts.map +1 -1
  6. package/dist/base-plugin/types.d.ts +114 -85
  7. package/dist/base-plugin/types.d.ts.map +1 -1
  8. package/dist/base-plugin/types.js +47 -3
  9. package/dist/base-plugin/types.js.map +1 -1
  10. package/dist/base-plugin/viewtemplates/edit.d.ts +3 -3
  11. package/dist/base-plugin/viewtemplates/edit.d.ts.map +1 -1
  12. package/dist/base-plugin/viewtemplates/edit.js +63 -8
  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 +13 -0
  16. package/dist/base-plugin/viewtemplates/filter.js.map +1 -1
  17. package/dist/base-plugin/viewtemplates/list.d.ts +1 -1
  18. package/dist/base-plugin/viewtemplates/list.d.ts.map +1 -1
  19. package/dist/base-plugin/viewtemplates/list.js +64 -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 +8 -6
  23. package/dist/base-plugin/viewtemplates/show.js.map +1 -1
  24. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts +13 -0
  25. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts.map +1 -1
  26. package/dist/base-plugin/viewtemplates/viewable_fields.js +27 -13
  27. package/dist/base-plugin/viewtemplates/viewable_fields.js.map +1 -1
  28. package/dist/contracts.d.ts.map +1 -1
  29. package/dist/contracts.js +10 -2
  30. package/dist/contracts.js.map +1 -1
  31. package/dist/db/connect.d.ts.map +1 -1
  32. package/dist/db/connect.js +7 -1
  33. package/dist/db/connect.js.map +1 -1
  34. package/dist/db/reset_schema.d.ts.map +1 -1
  35. package/dist/db/reset_schema.js +21 -19
  36. package/dist/db/reset_schema.js.map +1 -1
  37. package/dist/db/state.d.ts +8 -10
  38. package/dist/db/state.d.ts.map +1 -1
  39. package/dist/db/state.js +11 -34
  40. package/dist/db/state.js.map +1 -1
  41. package/dist/models/backup.d.ts +1 -1
  42. package/dist/models/backup.js.map +1 -1
  43. package/dist/models/config.js +2 -2
  44. package/dist/models/config.js.map +1 -1
  45. package/dist/models/crash.d.ts +1 -1
  46. package/dist/models/crash.d.ts.map +1 -1
  47. package/dist/models/crash.js.map +1 -1
  48. package/dist/models/discovery.d.ts +17 -25
  49. package/dist/models/discovery.d.ts.map +1 -1
  50. package/dist/models/discovery.js +38 -26
  51. package/dist/models/discovery.js.map +1 -1
  52. package/dist/models/email.d.ts +1 -1
  53. package/dist/models/email.d.ts.map +1 -1
  54. package/dist/models/email.js +11 -8
  55. package/dist/models/email.js.map +1 -1
  56. package/dist/models/eventlog.d.ts +1 -1
  57. package/dist/models/eventlog.d.ts.map +1 -1
  58. package/dist/models/eventlog.js.map +1 -1
  59. package/dist/models/expression.d.ts +11 -9
  60. package/dist/models/expression.d.ts.map +1 -1
  61. package/dist/models/expression.js +15 -13
  62. package/dist/models/expression.js.map +1 -1
  63. package/dist/models/field.d.ts +10 -45
  64. package/dist/models/field.d.ts.map +1 -1
  65. package/dist/models/field.js +5 -4
  66. package/dist/models/field.js.map +1 -1
  67. package/dist/models/file.d.ts +1 -1
  68. package/dist/models/file.d.ts.map +1 -1
  69. package/dist/models/file.js.map +1 -1
  70. package/dist/models/library.d.ts +1 -1
  71. package/dist/models/library.d.ts.map +1 -1
  72. package/dist/models/pack.d.ts +10 -7
  73. package/dist/models/pack.d.ts.map +1 -1
  74. package/dist/models/pack.js +0 -4
  75. package/dist/models/pack.js.map +1 -1
  76. package/dist/models/page.d.ts +4 -5
  77. package/dist/models/page.d.ts.map +1 -1
  78. package/dist/models/page.js +3 -1
  79. package/dist/models/page.js.map +1 -1
  80. package/dist/models/plugin.d.ts +4 -4
  81. package/dist/models/plugin.d.ts.map +1 -1
  82. package/dist/models/plugin.js +2 -2
  83. package/dist/models/plugin.js.map +1 -1
  84. package/dist/models/random.d.ts +18 -21
  85. package/dist/models/random.d.ts.map +1 -1
  86. package/dist/models/random.js +31 -29
  87. package/dist/models/random.js.map +1 -1
  88. package/dist/models/scheduler.d.ts +1 -7
  89. package/dist/models/scheduler.d.ts.map +1 -1
  90. package/dist/models/scheduler.js +1 -2
  91. package/dist/models/scheduler.js.map +1 -1
  92. package/dist/models/table.d.ts +8 -8
  93. package/dist/models/table.d.ts.map +1 -1
  94. package/dist/models/table.js +32 -8
  95. package/dist/models/table.js.map +1 -1
  96. package/dist/models/table_constraints.d.ts +1 -1
  97. package/dist/models/table_constraints.d.ts.map +1 -1
  98. package/dist/models/table_constraints.js +4 -1
  99. package/dist/models/table_constraints.js.map +1 -1
  100. package/dist/models/tenant.d.ts +16 -60
  101. package/dist/models/tenant.d.ts.map +1 -1
  102. package/dist/models/tenant.js +52 -30
  103. package/dist/models/tenant.js.map +1 -1
  104. package/dist/models/trigger.d.ts +1 -1
  105. package/dist/models/trigger.d.ts.map +1 -1
  106. package/dist/models/trigger.js +1 -1
  107. package/dist/models/trigger.js.map +1 -1
  108. package/dist/models/user.d.ts +3 -1
  109. package/dist/models/user.d.ts.map +1 -1
  110. package/dist/models/user.js.map +1 -1
  111. package/dist/models/view.d.ts +3 -2
  112. package/dist/models/view.d.ts.map +1 -1
  113. package/dist/models/view.js +1 -3
  114. package/dist/models/view.js.map +1 -1
  115. package/dist/models/workflow.d.ts +4 -4
  116. package/dist/models/workflow.d.ts.map +1 -1
  117. package/dist/models/workflow.js.map +1 -1
  118. package/dist/plugin-helper.d.ts.map +1 -1
  119. package/dist/plugin-helper.js +58 -26
  120. package/dist/plugin-helper.js.map +1 -1
  121. package/dist/tests/actions.test.d.ts.map +1 -1
  122. package/dist/tests/actions.test.js +102 -82
  123. package/dist/tests/actions.test.js.map +1 -1
  124. package/dist/tests/assertions.d.ts +13 -0
  125. package/dist/tests/assertions.d.ts.map +1 -0
  126. package/dist/tests/assertions.js +35 -0
  127. package/dist/tests/assertions.js.map +1 -0
  128. package/dist/tests/auxtest.test.d.ts.map +1 -1
  129. package/dist/tests/auxtest.test.js +33 -29
  130. package/dist/tests/auxtest.test.js.map +1 -1
  131. package/dist/tests/backup.test.d.ts.map +1 -1
  132. package/dist/tests/backup.test.js +62 -49
  133. package/dist/tests/backup.test.js.map +1 -1
  134. package/dist/tests/calc.test.d.ts.map +1 -1
  135. package/dist/tests/calc.test.js +106 -88
  136. package/dist/tests/calc.test.js.map +1 -1
  137. package/dist/tests/config.test.d.ts.map +1 -1
  138. package/dist/tests/config.test.js +39 -36
  139. package/dist/tests/config.test.js.map +1 -1
  140. package/dist/tests/discover.test.d.ts.map +1 -1
  141. package/dist/tests/discover.test.js +23 -17
  142. package/dist/tests/discover.test.js.map +1 -1
  143. package/dist/tests/email.test.d.ts +2 -0
  144. package/dist/tests/email.test.d.ts.map +1 -0
  145. package/dist/tests/email.test.js +38 -0
  146. package/dist/tests/email.test.js.map +1 -0
  147. package/dist/tests/exact_views.test.d.ts.map +1 -1
  148. package/dist/tests/exact_views.test.js +66 -25
  149. package/dist/tests/exact_views.test.js.map +1 -1
  150. package/dist/tests/field.test.d.ts.map +1 -1
  151. package/dist/tests/field.test.js +104 -93
  152. package/dist/tests/field.test.js.map +1 -1
  153. package/dist/tests/form.test.d.ts.map +1 -1
  154. package/dist/tests/form.test.js +71 -63
  155. package/dist/tests/form.test.js.map +1 -1
  156. package/dist/tests/mocks.d.ts +101 -105
  157. package/dist/tests/mocks.d.ts.map +1 -1
  158. package/dist/tests/mocks.js +19 -14
  159. package/dist/tests/mocks.js.map +1 -1
  160. package/dist/tests/models.test.d.ts.map +1 -1
  161. package/dist/tests/models.test.js +95 -80
  162. package/dist/tests/models.test.js.map +1 -1
  163. package/dist/tests/pack.test.d.ts.map +1 -1
  164. package/dist/tests/pack.test.js +54 -47
  165. package/dist/tests/pack.test.js.map +1 -1
  166. package/dist/tests/plugin.test.d.ts.map +1 -1
  167. package/dist/tests/plugin.test.js +31 -24
  168. package/dist/tests/plugin.test.js.map +1 -1
  169. package/dist/tests/random.test.d.ts.map +1 -1
  170. package/dist/tests/random.test.js +61 -50
  171. package/dist/tests/random.test.js.map +1 -1
  172. package/dist/tests/table.test.d.ts.map +1 -1
  173. package/dist/tests/table.test.js +557 -436
  174. package/dist/tests/table.test.js.map +1 -1
  175. package/dist/tests/tenant.test.d.ts.map +1 -1
  176. package/dist/tests/tenant.test.js +30 -23
  177. package/dist/tests/tenant.test.js.map +1 -1
  178. package/dist/tests/user.test.d.ts.map +1 -1
  179. package/dist/tests/user.test.js +128 -100
  180. package/dist/tests/user.test.js.map +1 -1
  181. package/dist/tests/view.test.d.ts.map +1 -1
  182. package/dist/tests/view.test.js +109 -85
  183. package/dist/tests/view.test.js.map +1 -1
  184. package/dist/tests/workflow.test.d.ts.map +1 -1
  185. package/dist/tests/workflow.test.js +40 -29
  186. package/dist/tests/workflow.test.js.map +1 -1
  187. package/dist/tsconfig.ref.tsbuildinfo +1 -1
  188. package/dist/utils.d.ts +29 -20
  189. package/dist/utils.d.ts.map +1 -1
  190. package/dist/utils.js +20 -5
  191. package/dist/utils.js.map +1 -1
  192. package/package.json +20 -16
@@ -1,49 +1,57 @@
1
1
  "use strict";
2
- const Table = require("../models/table");
3
- const TableConstraint = require("../models/table_constraints");
4
- const Field = require("../models/field");
5
- const View = require("../models/view");
6
- const db = require("../db");
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 table_constraints_1 = __importDefault(require("../models/table_constraints"));
8
+ const field_1 = __importDefault(require("../models/field"));
9
+ const view_1 = __importDefault(require("../models/view"));
10
+ const db_1 = __importDefault(require("../db"));
7
11
  const { getState } = require("../db/state");
8
12
  getState().registerPlugin("base", require("../base-plugin"));
9
- const fs = require("fs").promises;
10
- const { rick_file, plugin_with_routes, mockReqRes } = require("./mocks");
11
- afterAll(db.close);
12
- beforeAll(async () => {
13
+ const promises_1 = require("fs/promises");
14
+ const mocks_1 = __importDefault(require("./mocks"));
15
+ const { rick_file, plugin_with_routes, mockReqRes } = mocks_1.default;
16
+ const assertions_1 = require("./assertions");
17
+ const globals_1 = require("@jest/globals");
18
+ (0, globals_1.afterAll)(db_1.default.close);
19
+ (0, globals_1.beforeAll)(async () => {
13
20
  await require("../db/reset_schema")();
14
21
  await require("../db/fixtures")();
15
22
  });
16
23
  jest.setTimeout(30000);
17
- describe("TableIO", () => {
18
- it("should store attributes", async () => {
19
- const tc = await Table.create("mytesttable");
20
- await Field.create({
24
+ (0, globals_1.describe)("TableIO", () => {
25
+ (0, globals_1.it)("should store attributes", async () => {
26
+ const tc = await table_1.default.create("mytesttable");
27
+ await field_1.default.create({
21
28
  table: tc,
22
29
  name: "foo_height1",
23
30
  label: "height1",
24
31
  type: "Integer",
25
32
  attributes: { max: 18 },
26
33
  });
27
- const fs = await db.selectOne("_sc_fields", { name: "foo_height1" });
28
- expect(fs.table_id).toBe(tc.id);
29
- expect(fs.table_id > 0).toBe(true);
30
- expect(fs.id > 0).toBe(true);
34
+ const fs = await db_1.default.selectOne("_sc_fields", { name: "foo_height1" });
35
+ (0, globals_1.expect)(fs.table_id).toBe(tc.id);
36
+ (0, globals_1.expect)(fs.table_id > 0).toBe(true);
37
+ (0, globals_1.expect)(fs.id > 0).toBe(true);
31
38
  const fields = await tc.getFields();
32
- expect(fields[1].attributes).toStrictEqual({ max: 18 });
39
+ (0, globals_1.expect)(fields[1].attributes).toStrictEqual({ max: 18 });
33
40
  });
34
41
  });
35
- describe("Table create", () => {
36
- it("should create", async () => {
37
- const tc = await Table.create("mytable1");
38
- const tf = await Table.findOne({ id: tc.id });
39
- expect(tf.external).toBe(false);
40
- expect(tc.external).toBe(false);
41
- expect(tf.name).toStrictEqual("mytable1");
42
- expect(tf.sql_name).toStrictEqual(db.isSQLite ? '"mytable1"' : '"public"."mytable1"');
43
- });
44
- it("toggle bools", async () => {
45
- const tc = await Table.create("mytable17");
46
- await Field.create({
42
+ (0, globals_1.describe)("Table create", () => {
43
+ (0, globals_1.it)("should create", async () => {
44
+ const tc = await table_1.default.create("mytable1");
45
+ const tf = await table_1.default.findOne({ id: tc.id });
46
+ (0, assertions_1.assertIsSet)(tf);
47
+ (0, globals_1.expect)(tf.external).toBe(false);
48
+ (0, globals_1.expect)(tc.external).toBe(false);
49
+ (0, globals_1.expect)(tf.name).toStrictEqual("mytable1");
50
+ (0, globals_1.expect)(tf.sql_name).toStrictEqual(db_1.default.isSQLite ? '"mytable1"' : '"public"."mytable1"');
51
+ });
52
+ (0, globals_1.it)("toggle bools", async () => {
53
+ const tc = await table_1.default.create("mytable17");
54
+ await field_1.default.create({
47
55
  table: tc,
48
56
  label: "Group",
49
57
  type: "Bool",
@@ -52,12 +60,13 @@ describe("Table create", () => {
52
60
  const tall_id = await tc.insertRow({ group: true });
53
61
  await tc.toggleBool(tall_id, "group");
54
62
  const row = await tc.getRow({ id: tall_id });
55
- expect(row.group).toBe(false);
63
+ (0, assertions_1.assertIsSet)(row);
64
+ (0, globals_1.expect)(row.group).toBe(false);
56
65
  });
57
- it("should create required field in empty table without default", async () => {
58
- const mytable1 = await Table.findOne({ name: "mytable1" });
59
- expect(!!mytable1).toBe(true);
60
- await Field.create({
66
+ (0, globals_1.it)("should create required field in empty table without default", async () => {
67
+ const mytable1 = await table_1.default.findOne({ name: "mytable1" });
68
+ (0, globals_1.expect)(!!mytable1).toBe(true);
69
+ await field_1.default.create({
61
70
  table: mytable1,
62
71
  name: "height1",
63
72
  label: "height1",
@@ -65,86 +74,98 @@ describe("Table create", () => {
65
74
  required: true,
66
75
  });
67
76
  });
68
- it("should insert", async () => {
69
- const mytable1 = await Table.findOne({ name: "mytable1" });
70
- expect(mytable1.name).toBe("mytable1");
71
- const id = await db.insert(mytable1.name, { height1: 6 });
72
- expect(typeof id).toBe("number");
73
- expect(id > 0).toBe(true);
74
- const row = await db.selectOne(mytable1.name, { id });
75
- expect(row.height1).toBe(6);
76
- await db.update(mytable1.name, { height1: 7 }, id);
77
- const rowup = await db.selectOne(mytable1.name, { id });
78
- expect(rowup.height1).toBe(7);
79
- });
80
- it("should select one or zero", async () => {
81
- const rows = await db.select("mytable1", {});
82
- expect(rows.length).toBe(1);
83
- const row = await db.selectMaybeOne("mytable1", { id: rows[0].id });
84
- expect(row.height1).toBe(7);
85
- const norow = await db.selectMaybeOne("mytable1", { id: 789 });
86
- expect(norow).toBe(null);
87
- await expect((async () => await db.selectOne("mytable1", { id: 789 }))()).rejects.toThrow(Error);
88
- });
89
- it("should get distinct values", async () => {
90
- const table = await Table.findOne({ name: "mytable1" });
77
+ (0, globals_1.it)("should insert", async () => {
78
+ const mytable1 = await table_1.default.findOne({ name: "mytable1" });
79
+ (0, assertions_1.assertIsSet)(mytable1);
80
+ (0, globals_1.expect)(mytable1.name).toBe("mytable1");
81
+ const id = await db_1.default.insert(mytable1.name, { height1: 6 });
82
+ (0, globals_1.expect)(typeof id).toBe("number");
83
+ (0, globals_1.expect)(id > 0).toBe(true);
84
+ const row = await db_1.default.selectOne(mytable1.name, { id });
85
+ (0, globals_1.expect)(row.height1).toBe(6);
86
+ await db_1.default.update(mytable1.name, { height1: 7 }, id);
87
+ const rowup = await db_1.default.selectOne(mytable1.name, { id });
88
+ (0, globals_1.expect)(rowup.height1).toBe(7);
89
+ });
90
+ (0, globals_1.it)("should select one or zero", async () => {
91
+ const rows = await db_1.default.select("mytable1", {});
92
+ (0, globals_1.expect)(rows.length).toBe(1);
93
+ const row = await db_1.default.selectMaybeOne("mytable1", { id: rows[0].id });
94
+ (0, globals_1.expect)(row.height1).toBe(7);
95
+ const norow = await db_1.default.selectMaybeOne("mytable1", { id: 789 });
96
+ (0, globals_1.expect)(norow).toBe(null);
97
+ await (0, globals_1.expect)((async () => await db_1.default.selectOne("mytable1", { id: 789 }))()).rejects.toThrow();
98
+ });
99
+ (0, globals_1.it)("should get distinct values", async () => {
100
+ const table = await table_1.default.findOne({ name: "mytable1" });
101
+ (0, assertions_1.assertIsSet)(table);
91
102
  const vs = await table.distinctValues("height1");
92
- expect(vs).toEqual([7]);
103
+ (0, globals_1.expect)(vs).toEqual([7]);
93
104
  });
94
- it("should delete", async () => {
95
- const table = await Table.findOne({ name: "mytable1" });
105
+ (0, globals_1.it)("should delete", async () => {
106
+ const table = await table_1.default.findOne({ name: "mytable1" });
107
+ (0, assertions_1.assertIsSet)(table);
96
108
  await table.delete();
97
- const table1 = await Table.find({ name: "mytable1" });
98
- expect(table1.length).toBe(0);
109
+ const table1 = await table_1.default.find({ name: "mytable1" });
110
+ (0, globals_1.expect)(table1.length).toBe(0);
99
111
  });
100
112
  });
101
- describe("Table get data", () => {
102
- it("should get rows", async () => {
103
- const patients = await Table.findOne({ name: "patients" });
113
+ (0, globals_1.describe)("Table get data", () => {
114
+ (0, globals_1.it)("should get rows", async () => {
115
+ const patients = await table_1.default.findOne({ name: "patients" });
116
+ (0, assertions_1.assertIsSet)(patients);
104
117
  const all = await patients.getRows();
105
- expect(all.length).toStrictEqual(2);
118
+ (0, globals_1.expect)(all.length).toStrictEqual(2);
106
119
  });
107
- it("should get rows where name is Michael", async () => {
108
- const patients = await Table.findOne({ name: "patients" });
120
+ (0, globals_1.it)("should get rows where name is Michael", async () => {
121
+ const patients = await table_1.default.findOne({ name: "patients" });
122
+ (0, assertions_1.assertIsSet)(patients);
109
123
  const michaels = await patients.getRows({ name: "Michael Douglas" });
110
- expect(michaels.length).toStrictEqual(1);
124
+ (0, assertions_1.assertIsSet)(michaels);
125
+ (0, globals_1.expect)(michaels.length).toStrictEqual(1);
111
126
  });
112
- it("should get limited rows", async () => {
113
- const patients = await Table.findOne({ name: "patients" });
127
+ (0, globals_1.it)("should get limited rows", async () => {
128
+ const patients = await table_1.default.findOne({ name: "patients" });
129
+ (0, assertions_1.assertIsSet)(patients);
114
130
  const michaels = await patients.getRows({ name: { ilike: "Douglas" } }, { limit: 1, orderBy: "id", offset: 1 });
115
- expect(michaels.length).toStrictEqual(1);
116
- expect(michaels[0].name).toStrictEqual("Michael Douglas");
131
+ (0, globals_1.expect)(michaels.length).toStrictEqual(1);
132
+ (0, globals_1.expect)(michaels[0].name).toStrictEqual("Michael Douglas");
117
133
  });
118
- it("should get rows by slug", async () => {
119
- const books = await Table.findOne({ name: "books" });
134
+ (0, globals_1.it)("should get rows by slug", async () => {
135
+ const books = await table_1.default.findOne({ name: "books" });
136
+ (0, assertions_1.assertIsSet)(books);
120
137
  const all = await books.getRows({
121
138
  author: { slugify: "herman-melville" },
122
139
  });
123
- expect(all.length).toStrictEqual(1);
124
- expect(all[0].pages).toStrictEqual(967);
140
+ (0, globals_1.expect)(all.length).toStrictEqual(1);
141
+ (0, globals_1.expect)(all[0].pages).toStrictEqual(967);
125
142
  });
126
- it("should get joined rows where name is Michael", async () => {
127
- const patients = await Table.findOne({ name: "patients" });
143
+ (0, globals_1.it)("should get joined rows where name is Michael", async () => {
144
+ const patients = await table_1.default.findOne({ name: "patients" });
145
+ (0, assertions_1.assertIsSet)(patients);
128
146
  const michaels = await patients.getJoinedRows({
129
147
  where: { name: "Michael Douglas" },
130
148
  });
131
- expect(michaels.length).toStrictEqual(1);
132
- expect(michaels[0].favbook).toBe(2);
149
+ (0, globals_1.expect)(michaels.length).toStrictEqual(1);
150
+ (0, globals_1.expect)(michaels[0].favbook).toBe(2);
133
151
  });
134
- it("should get joined rows where name is not null", async () => {
135
- const patients = await Table.findOne({ name: "patients" });
152
+ (0, globals_1.it)("should get joined rows where name is not null", async () => {
153
+ const patients = await table_1.default.findOne({ name: "patients" });
154
+ (0, assertions_1.assertIsSet)(patients);
136
155
  const nameds = await patients.getJoinedRows({
137
156
  where: { not: { name: null } },
138
157
  });
139
- expect(nameds.length).toStrictEqual(2);
158
+ (0, globals_1.expect)(nameds.length).toStrictEqual(2);
140
159
  });
141
- it("should get rows in id range", async () => {
142
- const patients = await Table.findOne({ name: "patients" });
160
+ (0, globals_1.it)("should get rows in id range", async () => {
161
+ const patients = await table_1.default.findOne({ name: "patients" });
162
+ (0, assertions_1.assertIsSet)(patients);
143
163
  const rows = await patients.getRows({ id: [{ gt: 0 }, { lt: 10 }] });
144
- expect(rows.length).toStrictEqual(2);
164
+ (0, globals_1.expect)(rows.length).toStrictEqual(2);
145
165
  });
146
- it("should get rows by subselect", async () => {
147
- const books = await Table.findOne({ name: "books" });
166
+ (0, globals_1.it)("should get rows by subselect", async () => {
167
+ const books = await table_1.default.findOne({ name: "books" });
168
+ (0, assertions_1.assertIsSet)(books);
148
169
  const nrows = await books.countRows({
149
170
  id: {
150
171
  inSelect: {
@@ -154,29 +175,32 @@ describe("Table get data", () => {
154
175
  },
155
176
  },
156
177
  });
157
- expect(nrows).toStrictEqual(1);
178
+ (0, globals_1.expect)(nrows).toStrictEqual(1);
158
179
  });
159
- it("should get joined rows with limit and order", async () => {
160
- const patients = await Table.findOne({ name: "patients" });
180
+ (0, globals_1.it)("should get joined rows with limit and order", async () => {
181
+ const patients = await table_1.default.findOne({ name: "patients" });
182
+ (0, assertions_1.assertIsSet)(patients);
161
183
  const all = await patients.getJoinedRows({
162
184
  limit: 2,
163
185
  orderBy: "id",
164
186
  });
165
- expect(all.length).toStrictEqual(2);
166
- expect(all[1].favbook).toBe(2);
187
+ (0, globals_1.expect)(all.length).toStrictEqual(2);
188
+ (0, globals_1.expect)(all[1].favbook).toBe(2);
167
189
  });
168
- it("should get joined rows with limit and desc order", async () => {
169
- const patients = await Table.findOne({ name: "patients" });
190
+ (0, globals_1.it)("should get joined rows with limit and desc order", async () => {
191
+ const patients = await table_1.default.findOne({ name: "patients" });
192
+ (0, assertions_1.assertIsSet)(patients);
170
193
  const all = await patients.getJoinedRows({
171
194
  limit: 2,
172
195
  orderBy: "id",
173
196
  orderDesc: true,
174
197
  });
175
- expect(all.length).toStrictEqual(2);
176
- expect(all[0].favbook).toBe(2);
198
+ (0, globals_1.expect)(all.length).toStrictEqual(2);
199
+ (0, globals_1.expect)(all[0].favbook).toBe(2);
177
200
  });
178
- it("should get joined rows with aggregations", async () => {
179
- const patients = await Table.findOne({ name: "patients" });
201
+ (0, globals_1.it)("should get joined rows with aggregations", async () => {
202
+ const patients = await table_1.default.findOne({ name: "patients" });
203
+ (0, assertions_1.assertIsSet)(patients);
180
204
  const michaels = await patients.getJoinedRows({
181
205
  orderBy: "id",
182
206
  aggregations: {
@@ -188,11 +212,12 @@ describe("Table get data", () => {
188
212
  },
189
213
  },
190
214
  });
191
- expect(michaels.length).toStrictEqual(2);
192
- expect(Math.round(michaels[0].avg_temp)).toBe(38);
215
+ (0, globals_1.expect)(michaels.length).toStrictEqual(2);
216
+ (0, globals_1.expect)(Math.round(michaels[0].avg_temp)).toBe(38);
193
217
  });
194
- it("should get joined rows with latest aggregations", async () => {
195
- const patients = await Table.findOne({ name: "patients" });
218
+ (0, globals_1.it)("should get joined rows with latest aggregations", async () => {
219
+ const patients = await table_1.default.findOne({ name: "patients" });
220
+ (0, assertions_1.assertIsSet)(patients);
196
221
  const michaels = await patients.getJoinedRows({
197
222
  orderBy: "id",
198
223
  aggregations: {
@@ -204,22 +229,24 @@ describe("Table get data", () => {
204
229
  },
205
230
  },
206
231
  });
207
- expect(michaels.length).toStrictEqual(2);
208
- expect(Math.round(michaels[0].last_temp)).toBe(37);
232
+ (0, globals_1.expect)(michaels.length).toStrictEqual(2);
233
+ (0, globals_1.expect)(Math.round(michaels[0].last_temp)).toBe(37);
209
234
  });
210
- it("should get double joined rows", async () => {
211
- const readings = await Table.findOne({ name: "readings" });
235
+ (0, globals_1.it)("should get double joined rows", async () => {
236
+ const readings = await table_1.default.findOne({ name: "readings" });
237
+ (0, assertions_1.assertIsSet)(readings);
212
238
  const reads = await readings.getJoinedRows({
213
239
  orderBy: "id",
214
240
  joinFields: {
215
241
  author: { ref: "patient_id", through: "favbook", target: "author" },
216
242
  },
217
243
  });
218
- expect(reads.length).toStrictEqual(3);
219
- expect(reads[0].author).toBe("Herman Melville");
244
+ (0, globals_1.expect)(reads.length).toStrictEqual(3);
245
+ (0, globals_1.expect)(reads[0].author).toBe("Herman Melville");
220
246
  });
221
- it("should get joined rows with aggregations and joins", async () => {
222
- const patients = await Table.findOne({ name: "patients" });
247
+ (0, globals_1.it)("should get joined rows with aggregations and joins", async () => {
248
+ const patients = await table_1.default.findOne({ name: "patients" });
249
+ (0, assertions_1.assertIsSet)(patients);
223
250
  const michaels = await patients.getJoinedRows({
224
251
  orderBy: "id",
225
252
  aggregations: {
@@ -235,54 +262,61 @@ describe("Table get data", () => {
235
262
  author: { ref: "favbook", target: "author" },
236
263
  },
237
264
  });
238
- expect(michaels.length).toStrictEqual(2);
239
- expect(Math.round(michaels[0].avg_temp)).toBe(38);
240
- expect(michaels[1].author).toBe("Leo Tolstoy");
265
+ (0, globals_1.expect)(michaels.length).toStrictEqual(2);
266
+ (0, globals_1.expect)(Math.round(michaels[0].avg_temp)).toBe(38);
267
+ (0, globals_1.expect)(michaels[1].author).toBe("Leo Tolstoy");
241
268
  });
242
- it("should support full text search", async () => {
243
- const table = await Table.findOne({ name: "patients" });
269
+ (0, globals_1.it)("should support full text search", async () => {
270
+ const table = await table_1.default.findOne({ name: "patients" });
271
+ (0, assertions_1.assertIsSet)(table);
244
272
  const fields = await table.getFields();
245
- const rows = await db.select("patients", {
273
+ const rows = await db_1.default.select("patients", {
246
274
  _fts: { fields, searchTerm: "Douglas" },
247
275
  });
248
- expect(rows.length).toBe(2);
276
+ (0, globals_1.expect)(rows.length).toBe(2);
249
277
  });
250
- it("should enable versioning", async () => {
251
- const table = await Table.findOne({ name: "patients" });
278
+ (0, globals_1.it)("should enable versioning", async () => {
279
+ const table = await table_1.default.findOne({ name: "patients" });
280
+ (0, assertions_1.assertIsSet)(table);
252
281
  table.versioned = true;
253
282
  await table.update(table);
254
283
  });
255
- it("should save version on insert", async () => {
256
- const table = await Table.findOne({ name: "patients" });
284
+ (0, globals_1.it)("should save version on insert", async () => {
285
+ const table = await table_1.default.findOne({ name: "patients" });
286
+ (0, assertions_1.assertIsSet)(table);
257
287
  await table.insertRow({ name: "Bunny foo-foo", favbook: 1 });
258
288
  const bunnyFooFoo = await table.getRow({ name: "Bunny foo-foo" });
289
+ (0, assertions_1.assertIsSet)(bunnyFooFoo);
259
290
  const history1 = await table.get_history(bunnyFooFoo.id);
260
- expect(history1.length).toBe(1);
261
- expect(history1[0].id).toBe(bunnyFooFoo.id);
262
- expect(history1[0]._version).toBe(1);
263
- expect(history1[0].name).toBe("Bunny foo-foo");
264
- });
265
- it("should save version on update", async () => {
266
- const table = await Table.findOne({ name: "patients" });
291
+ (0, globals_1.expect)(history1.length).toBe(1);
292
+ (0, globals_1.expect)(history1[0].id).toBe(bunnyFooFoo.id);
293
+ (0, globals_1.expect)(history1[0]._version).toBe(1);
294
+ (0, globals_1.expect)(history1[0].name).toBe("Bunny foo-foo");
295
+ });
296
+ (0, globals_1.it)("should save version on update", async () => {
297
+ const table = await table_1.default.findOne({ name: "patients" });
298
+ (0, assertions_1.assertIsSet)(table);
267
299
  const bunnyFooFoo = await table.getRow({ name: "Bunny foo-foo" });
300
+ (0, assertions_1.assertIsSet)(bunnyFooFoo);
268
301
  await table.updateRow({ name: "Goon" }, bunnyFooFoo.id);
269
302
  const history2 = await table.get_history(bunnyFooFoo.id);
270
- expect(history2.length).toBe(2);
271
- expect(history2[0].id).toBe(bunnyFooFoo.id);
272
- expect(history2[0]._version).toBe(1);
273
- expect(history2[0].name).toBe("Bunny foo-foo");
274
- expect(history2[0].favbook).toBe(1);
275
- expect(history2[1].id).toBe(bunnyFooFoo.id);
276
- expect(history2[1]._version).toBe(2);
277
- expect(history2[1].name).toBe("Goon");
278
- expect(history2[1].favbook).toBe(1);
303
+ (0, globals_1.expect)(history2.length).toBe(2);
304
+ (0, globals_1.expect)(history2[0].id).toBe(bunnyFooFoo.id);
305
+ (0, globals_1.expect)(history2[0]._version).toBe(1);
306
+ (0, globals_1.expect)(history2[0].name).toBe("Bunny foo-foo");
307
+ (0, globals_1.expect)(history2[0].favbook).toBe(1);
308
+ (0, globals_1.expect)(history2[1].id).toBe(bunnyFooFoo.id);
309
+ (0, globals_1.expect)(history2[1]._version).toBe(2);
310
+ (0, globals_1.expect)(history2[1].name).toBe("Goon");
311
+ (0, globals_1.expect)(history2[1].favbook).toBe(1);
279
312
  const goon = await table.getRow({ id: bunnyFooFoo.id });
280
- expect(goon.name).toBe("Goon");
281
- expect(goon.favbook).toBe(1);
313
+ (0, assertions_1.assertIsSet)(goon);
314
+ (0, globals_1.expect)(goon.name).toBe("Goon");
315
+ (0, globals_1.expect)(goon.favbook).toBe(1);
282
316
  });
283
- it("create field on version table", async () => {
284
- const table = await Table.findOne({ name: "patients" });
285
- const fc = await Field.create({
317
+ (0, globals_1.it)("create field on version table", async () => {
318
+ const table = await table_1.default.findOne({ name: "patients" });
319
+ const fc = await field_1.default.create({
286
320
  table: table,
287
321
  name: "Height19",
288
322
  label: "height19",
@@ -292,27 +326,28 @@ describe("Table get data", () => {
292
326
  });
293
327
  await fc.delete();
294
328
  });
295
- it("should disable versioning", async () => {
296
- const table = await Table.findOne({ name: "patients" });
329
+ (0, globals_1.it)("should disable versioning", async () => {
330
+ const table = await table_1.default.findOne({ name: "patients" });
331
+ (0, assertions_1.assertIsSet)(table);
297
332
  await table.getFields();
298
333
  await table.update({ versioned: false });
299
334
  });
300
- it("should rename", async () => {
301
- const table = await Table.create("notsurename");
302
- await Field.create({
335
+ (0, globals_1.it)("should rename", async () => {
336
+ const table = await table_1.default.create("notsurename");
337
+ await field_1.default.create({
303
338
  table,
304
339
  label: "tall",
305
340
  type: "Bool",
306
341
  required: true,
307
342
  });
308
- const table1 = await Table.create("refsunsure");
309
- await Field.create({
343
+ const table1 = await table_1.default.create("refsunsure");
344
+ await field_1.default.create({
310
345
  table: table1,
311
346
  label: "also_tall",
312
347
  type: "Bool",
313
348
  required: true,
314
349
  });
315
- await Field.create({
350
+ await field_1.default.create({
316
351
  table: table1,
317
352
  label: "theref",
318
353
  type: "Key to notsurename",
@@ -322,23 +357,26 @@ describe("Table get data", () => {
322
357
  await table1.insertRow({ also_tall: true, theref: id });
323
358
  const joinFields = { reftall: { ref: "theref", target: "tall" } };
324
359
  const rows = await table1.getJoinedRows({ joinFields });
325
- expect(rows[0].theref).toBe(id);
326
- expect(!!rows[0].reftall).toBe(false); //for sqlite
327
- if (!db.isSQLite) {
360
+ (0, globals_1.expect)(rows[0].theref).toBe(id);
361
+ (0, globals_1.expect)(!!rows[0].reftall).toBe(false); //for sqlite
362
+ if (!db_1.default.isSQLite) {
328
363
  await table.rename("isthisbetter");
329
- const table3 = await Table.findOne({ name: "refsunsure" });
364
+ const table3 = await table_1.default.findOne({ name: "refsunsure" });
365
+ (0, assertions_1.assertIsSet)(table3);
330
366
  const rows1 = await table3.getJoinedRows({ joinFields });
331
- expect(rows1[0].theref).toBe(id);
332
- expect(rows1[0].reftall).toBe(false);
333
- const table2 = await Table.findOne({ name: "isthisbetter" });
334
- expect(!!table2).toBe(true);
367
+ (0, globals_1.expect)(rows1[0].theref).toBe(id);
368
+ (0, globals_1.expect)(rows1[0].reftall).toBe(false);
369
+ const table2 = await table_1.default.findOne({ name: "isthisbetter" });
370
+ (0, assertions_1.assertIsSet)(table2);
371
+ (0, globals_1.expect)(!!table2).toBe(true);
335
372
  table2.versioned = true;
336
373
  await table2.update(table2);
337
374
  await table2.rename("thisisthebestname");
338
375
  }
339
376
  });
340
- it("should get joined rows with arbitrary fieldnames", async () => {
341
- const patients = await Table.findOne({ name: "patients" });
377
+ (0, globals_1.it)("should get joined rows with arbitrary fieldnames", async () => {
378
+ const patients = await table_1.default.findOne({ name: "patients" });
379
+ (0, assertions_1.assertIsSet)(patients);
342
380
  const michaels = await patients.getJoinedRows({
343
381
  where: { name: "Michael Douglas" },
344
382
  joinFields: {
@@ -346,27 +384,29 @@ describe("Table get data", () => {
346
384
  author: { ref: "favbook", target: "author" },
347
385
  },
348
386
  });
349
- expect(michaels.length).toStrictEqual(1);
350
- expect(michaels[0].pages).toBe(728);
351
- expect(michaels[0].author).toBe("Leo Tolstoy");
387
+ (0, globals_1.expect)(michaels.length).toStrictEqual(1);
388
+ (0, globals_1.expect)(michaels[0].pages).toBe(728);
389
+ (0, globals_1.expect)(michaels[0].author).toBe("Leo Tolstoy");
352
390
  });
353
- it("should get joined rows with one-to-one relations", async () => {
354
- const ratings = await Table.create("myreviews");
355
- await Field.create({
391
+ (0, globals_1.it)("should get joined rows with one-to-one relations", async () => {
392
+ const ratings = await table_1.default.create("myreviews");
393
+ (0, assertions_1.assertIsSet)(ratings);
394
+ await field_1.default.create({
356
395
  name: "book",
357
396
  label: "Book",
358
397
  type: "Key to books",
359
398
  is_unique: true,
360
399
  table: ratings,
361
400
  });
362
- await Field.create({
401
+ await field_1.default.create({
363
402
  name: "rating",
364
403
  label: "Rating",
365
404
  type: "Integer",
366
405
  table: ratings,
367
406
  });
368
407
  await ratings.insertRow({ book: 1, rating: 7 });
369
- const books = await Table.findOne({ name: "books" });
408
+ const books = await table_1.default.findOne({ name: "books" });
409
+ (0, assertions_1.assertIsSet)(books);
370
410
  //db.set_sql_logging();
371
411
  const reads = await books.getJoinedRows({
372
412
  orderBy: "id",
@@ -375,42 +415,46 @@ describe("Table get data", () => {
375
415
  rating: { ref: "book", ontable: "myreviews", target: "rating" },
376
416
  },
377
417
  });
378
- expect(reads.length).toStrictEqual(1);
379
- expect(reads[0].rating).toBe(7);
380
- expect(reads[0].author).toBe("Herman Melville");
381
- expect(reads[0].pages).toBe(967);
418
+ (0, globals_1.expect)(reads.length).toStrictEqual(1);
419
+ (0, globals_1.expect)(reads[0].rating).toBe(7);
420
+ (0, globals_1.expect)(reads[0].author).toBe("Herman Melville");
421
+ (0, globals_1.expect)(reads[0].pages).toBe(967);
382
422
  });
383
423
  });
384
- describe("relations", () => {
385
- it("get parent relations", async () => {
386
- const table = await Table.findOne({ name: "patients" });
424
+ (0, globals_1.describe)("relations", () => {
425
+ (0, globals_1.it)("get parent relations", async () => {
426
+ const table = await table_1.default.findOne({ name: "patients" });
427
+ (0, assertions_1.assertIsSet)(table);
387
428
  const rels = await table.get_parent_relations();
388
- expect(rels.parent_field_list).toContain("favbook.author");
389
- expect(rels.parent_relations.length).toBe(2);
429
+ (0, globals_1.expect)(rels.parent_field_list).toContain("favbook.author");
430
+ (0, globals_1.expect)(rels.parent_relations.length).toBe(2);
390
431
  });
391
- it("get parent relations with one-to-one", async () => {
392
- const table = await Table.findOne({ name: "books" });
432
+ (0, globals_1.it)("get parent relations with one-to-one", async () => {
433
+ const table = await table_1.default.findOne({ name: "books" });
434
+ (0, assertions_1.assertIsSet)(table);
393
435
  const rels = await table.get_parent_relations();
394
- expect(rels.parent_field_list).toEqual([
436
+ (0, globals_1.expect)(rels.parent_field_list).toEqual([
395
437
  "myreviews.book->book",
396
438
  "myreviews.book->id",
397
439
  "myreviews.book->rating",
398
440
  ]);
399
441
  });
400
- it("get child relations", async () => {
401
- const table = await Table.findOne({ name: "books" });
442
+ (0, globals_1.it)("get child relations", async () => {
443
+ const table = await table_1.default.findOne({ name: "books" });
444
+ (0, assertions_1.assertIsSet)(table);
402
445
  const rels = await table.get_child_relations();
403
- expect(rels.child_field_list).toEqual([
446
+ (0, globals_1.expect)(rels.child_field_list).toEqual([
404
447
  "discusses_books.book",
405
448
  "myreviews.book",
406
449
  "patients.favbook",
407
450
  ]);
408
- expect(rels.child_relations.length).toBe(3);
451
+ (0, globals_1.expect)(rels.child_relations.length).toBe(3);
409
452
  });
410
- it("get grandparent relations", async () => {
411
- const table = await Table.findOne({ name: "readings" });
453
+ (0, globals_1.it)("get grandparent relations", async () => {
454
+ const table = await table_1.default.findOne({ name: "readings" });
455
+ (0, assertions_1.assertIsSet)(table);
412
456
  const rels = await table.get_parent_relations(true);
413
- expect(rels.parent_field_list).toEqual([
457
+ (0, globals_1.expect)(rels.parent_field_list).toEqual([
414
458
  "patient_id.favbook",
415
459
  "patient_id.favbook.author",
416
460
  "patient_id.favbook.id",
@@ -423,209 +467,266 @@ describe("relations", () => {
423
467
  "patient_id.parent.name",
424
468
  "patient_id.parent.parent",
425
469
  ]);
426
- expect(rels.parent_relations.length).toBe(3);
470
+ (0, globals_1.expect)(rels.parent_relations.length).toBe(3);
427
471
  });
428
472
  });
429
- describe("CSV import", () => {
430
- it("should import into existing table", async () => {
473
+ (0, globals_1.describe)("CSV import", () => {
474
+ (0, globals_1.it)("should import into existing table", async () => {
431
475
  const csv = `author,Pages
432
476
  Joe Celko, 856
433
477
  Gordon Kane, 217`;
434
478
  const fnm = "/tmp/test1ok.csv";
435
- await fs.writeFile(fnm, csv);
436
- const table = await Table.findOne({ name: "books" });
437
- expect(!!table).toBe(true);
479
+ await (0, promises_1.writeFile)(fnm, csv);
480
+ const table = await table_1.default.findOne({ name: "books" });
481
+ (0, assertions_1.assertIsSet)(table);
482
+ (0, globals_1.expect)(!!table).toBe(true);
438
483
  const impres = await table.import_csv_file(fnm);
439
- expect(impres).toEqual({ success: "Imported 2 rows into table books" });
484
+ (0, globals_1.expect)(impres).toEqual({ success: "Imported 2 rows into table books" });
440
485
  const rows = await table.getRows({ author: "Gordon Kane" });
441
- expect(rows.length).toBe(1);
442
- expect(rows[0].pages).toBe(217);
486
+ (0, globals_1.expect)(rows.length).toBe(1);
487
+ (0, globals_1.expect)(rows[0].pages).toBe(217);
443
488
  });
444
- it("fail on required field", async () => {
489
+ (0, globals_1.it)("fail on required field", async () => {
445
490
  const csv = `author,Pagez
446
491
  Joe Celko, 856
447
492
  Gordon Kane, 217`;
448
493
  const fnm = "/tmp/test1f.csv";
449
- await fs.writeFile(fnm, csv);
450
- const table = await Table.findOne({ name: "books" });
451
- expect(!!table).toBe(true);
494
+ await (0, promises_1.writeFile)(fnm, csv);
495
+ const table = await table_1.default.findOne({ name: "books" });
496
+ (0, assertions_1.assertIsSet)(table);
497
+ (0, globals_1.expect)(!!table).toBe(true);
452
498
  const impres = await table.import_csv_file(fnm);
453
- expect(impres).toEqual({ error: "Required field missing: Pages" });
499
+ (0, globals_1.expect)(impres).toEqual({ error: "Required field missing: Pages" });
454
500
  });
455
- it("fail on strings in ints", async () => {
501
+ (0, globals_1.it)("fail on strings in ints", async () => {
456
502
  const csv = `author,Pages
457
503
  Leonardo Boff, 99
458
504
  David MacKay, ITILA`;
459
505
  const fnm = "/tmp/test1.csv";
460
- await fs.writeFile(fnm, csv);
461
- const table = await Table.create("books_not_req_pages", {
506
+ await (0, promises_1.writeFile)(fnm, csv);
507
+ const table = await table_1.default.create("books_not_req_pages", {
462
508
  min_role_read: 10,
463
509
  });
464
- await Field.create({
510
+ await field_1.default.create({
465
511
  table,
466
512
  name: "author",
467
513
  label: "Author",
468
514
  type: "String",
469
515
  required: true,
470
516
  });
471
- await Field.create({
517
+ await field_1.default.create({
472
518
  table,
473
519
  name: "pages",
474
520
  label: "Pages",
475
521
  type: "Integer",
476
522
  attributes: { min: 0 },
477
523
  });
478
- expect(!!table).toBe(true);
524
+ (0, globals_1.expect)(!!table).toBe(true);
479
525
  const impres = await table.import_csv_file(fnm);
480
- expect(impres).toEqual({
526
+ (0, globals_1.expect)(impres).toEqual({
481
527
  success: "Imported 1 rows into table books_not_req_pages. Rejected 1 rows.",
482
528
  });
483
529
  const rows = await table.getRows({ author: "David MacKay" });
484
- expect(rows.length).toBe(0);
530
+ (0, globals_1.expect)(rows.length).toBe(0);
485
531
  });
486
- it("should create by importing", async () => {
532
+ (0, globals_1.it)("should create by importing", async () => {
487
533
  //db.set_sql_logging();
488
534
  const csv = `item,cost,count, vatable
489
535
  Book, 5,4, f
490
536
  Pencil, 0.5,2, t`;
491
537
  const fnm = "/tmp/test2impok.csv";
492
- await fs.writeFile(fnm, csv);
493
- const { table } = await Table.create_from_csv("Invoice", fnm);
538
+ await (0, promises_1.writeFile)(fnm, csv);
539
+ const result = await table_1.default.create_from_csv("Invoice", fnm);
540
+ (0, assertions_1.assertsIsSuccessMessage)(result);
541
+ const { table } = result;
542
+ (0, assertions_1.assertIsSet)(table);
494
543
  const fields = await table.getFields();
495
544
  const vatField = fields.find((f) => f.name === "vatable");
496
- expect(vatField.type.name).toBe("Bool");
545
+ (0, assertions_1.assertIsSet)(vatField);
546
+ (0, assertions_1.assertIsType)(vatField.type);
547
+ (0, globals_1.expect)(vatField.type.name).toBe("Bool");
497
548
  const costField = fields.find((f) => f.name === "cost");
498
- expect(costField.type.name).toBe("Float");
549
+ (0, assertions_1.assertIsSet)(costField);
550
+ (0, assertions_1.assertIsType)(costField.type);
551
+ (0, globals_1.expect)(costField.type.name).toBe("Float");
499
552
  const countField = fields.find((f) => f.name === "count");
500
- expect(countField.type.name).toBe("Integer");
553
+ (0, assertions_1.assertIsSet)(countField);
554
+ (0, assertions_1.assertIsType)(countField.type);
555
+ (0, globals_1.expect)(countField.type.name).toBe("Integer");
501
556
  const rows = await table.getRows({ item: "Pencil" });
502
- expect(rows.length).toBe(1);
503
- expect(rows[0].vatable).toBe(true);
557
+ (0, globals_1.expect)(rows.length).toBe(1);
558
+ (0, globals_1.expect)(rows[0].vatable).toBe(true);
504
559
  const allrows = await table.getRows();
505
- expect(allrows.length).toBe(2);
560
+ (0, globals_1.expect)(allrows.length).toBe(2);
506
561
  });
507
- it("should fail on bad col nm", async () => {
562
+ (0, globals_1.it)("should fail on bad col nm", async () => {
508
563
  const csv = `item,cost,!, vatable
509
564
  Book, 5,4, f
510
565
  Pencil, 0.5,2, t`;
511
566
  const fnm = "/tmp/test2.csv";
512
- await fs.writeFile(fnm, csv);
513
- const res = await Table.create_from_csv("Invoice1", fnm);
514
- expect(res).toEqual({
567
+ await (0, promises_1.writeFile)(fnm, csv);
568
+ const res = await table_1.default.create_from_csv("Invoice1", fnm);
569
+ (0, globals_1.expect)(res).toEqual({
515
570
  error: "Invalid column name ! - Use A-Z, a-z, 0-9, _ only",
516
571
  });
517
- const table = await Table.findOne({ name: "Invoice1" });
518
- expect(table).toBe(null);
572
+ const table = await table_1.default.findOne({ name: "Invoice1" });
573
+ (0, globals_1.expect)(table).toBe(null);
519
574
  });
520
- it("ignores a col on duplicate col nm", async () => {
575
+ (0, globals_1.it)("ignores a col on duplicate col nm", async () => {
521
576
  const csv = `item,cost,cost, vatable
522
577
  Book, 5,4, f
523
578
  Pencil, 0.5,2, t`;
524
579
  const fnm = "/tmp/test2.csv";
525
- await fs.writeFile(fnm, csv);
526
- const res = await Table.create_from_csv("Invoice1", fnm);
527
- expect(res.table.fields.length).toEqual(4); //and id
580
+ await (0, promises_1.writeFile)(fnm, csv);
581
+ const res = await table_1.default.create_from_csv("Invoice1", fnm);
582
+ (0, assertions_1.assertsIsSuccessMessage)(res);
583
+ (0, globals_1.expect)(res.table.fields.length).toEqual(4); //and id
528
584
  });
529
- it("should fail non-int id", async () => {
585
+ (0, globals_1.it)("should fail non-int id", async () => {
530
586
  const csv = `id,cost,!, vatable
531
587
  Book, 5,4, f
532
588
  Pencil, 0.5,2, t`;
533
589
  const fnm = "/tmp/test2.csv";
534
- await fs.writeFile(fnm, csv);
535
- const res = await Table.create_from_csv("Invoice2", fnm);
536
- expect(res).toEqual({
590
+ await (0, promises_1.writeFile)(fnm, csv);
591
+ const res = await table_1.default.create_from_csv("Invoice2", fnm);
592
+ (0, globals_1.expect)(res).toEqual({
537
593
  error: `Columns named "id" must have only integers`,
538
594
  });
539
- const table = await Table.findOne({ name: "Invoice2" });
540
- expect(table).toBe(null);
595
+ const table = await table_1.default.findOne({ name: "Invoice2" });
596
+ (0, globals_1.expect)(table).toBe(null);
541
597
  });
542
- it("should fail missing id", async () => {
598
+ (0, globals_1.it)("should fail missing id", async () => {
543
599
  const csv = `id,cost,!, vatable
544
600
  1, 5,4, f
545
601
  , 0.5,2, t`;
546
602
  const fnm = "/tmp/test2.csv";
547
- await fs.writeFile(fnm, csv);
548
- const res = await Table.create_from_csv("Invoice3", fnm);
549
- expect(res).toEqual({
603
+ await (0, promises_1.writeFile)(fnm, csv);
604
+ const res = await table_1.default.create_from_csv("Invoice3", fnm);
605
+ (0, globals_1.expect)(res).toEqual({
550
606
  error: `Columns named "id" must not have missing values`,
551
607
  });
552
- const table = await Table.findOne({ name: "Invoice3" });
553
- expect(table).toBe(null);
608
+ const table = await table_1.default.findOne({ name: "Invoice3" });
609
+ (0, globals_1.expect)(table).toBe(null);
554
610
  });
555
- it("should succeed on good id", async () => {
611
+ (0, globals_1.it)("should succeed on good id", async () => {
556
612
  const csv = `id,cost,count, vatable
557
613
  1, 5,4, f
558
614
  2, 0.5,2, t`;
559
615
  const fnm = "/tmp/test2.csv";
560
- await fs.writeFile(fnm, csv);
561
- const res = await Table.create_from_csv("Invoice3", fnm);
562
- expect(res.table.fields.length).toEqual(4); // incl id
563
- const table = await Table.findOne({ name: "Invoice3" });
616
+ await (0, promises_1.writeFile)(fnm, csv);
617
+ const res = await table_1.default.create_from_csv("Invoice3", fnm);
618
+ (0, assertions_1.assertsIsSuccessMessage)(res);
619
+ (0, globals_1.expect)(res.table.fields.length).toEqual(4); // incl id
620
+ const table = await table_1.default.findOne({ name: "Invoice3" });
621
+ (0, assertions_1.assertIsSet)(table);
564
622
  const rows = await table.getRows();
565
- expect(rows.length).toBe(2);
623
+ (0, globals_1.expect)(rows.length).toBe(2);
566
624
  await table.insertRow({ cost: 0.2, count: 1, vatable: true });
567
625
  const rows3 = await table.getRows();
568
- expect(rows3.length).toBe(3);
626
+ (0, globals_1.expect)(rows3.length).toBe(3);
569
627
  });
570
- it("should fail on repeat id", async () => {
628
+ (0, globals_1.it)("should fail on repeat id", async () => {
571
629
  const csv = `id,cost,count, vatable
572
630
  1, 5,4, f
573
631
  1, 0.5,2, t`;
574
632
  const fnm = "/tmp/test2.csv";
575
- await fs.writeFile(fnm, csv);
576
- const res = await Table.create_from_csv("Invoice4", fnm);
577
- expect(res.error).toContain("Invoice4");
578
- const table = await Table.findOne({ name: "Invoice4" });
579
- expect(table).toBe(null);
580
- });
581
- it("should import with missing", async () => {
633
+ await (0, promises_1.writeFile)(fnm, csv);
634
+ const res = await table_1.default.create_from_csv("Invoice4", fnm);
635
+ (0, assertions_1.assertIsErrorMsg)(res);
636
+ (0, globals_1.expect)(res.error).toContain("Invoice4");
637
+ const table = await table_1.default.findOne({ name: "Invoice4" });
638
+ (0, globals_1.expect)(table).toBe(null);
639
+ });
640
+ (0, globals_1.it)("should import with missing", async () => {
582
641
  const csv = `item,cost,count, vatable
583
642
  Book, 5,4, f
584
643
  Pencil, 0.5,, t`;
585
644
  const fnm = "/tmp/test2.csv";
586
- await fs.writeFile(fnm, csv);
587
- const { table, error } = await Table.create_from_csv("InvoiceMissing", fnm);
588
- expect(error).toBe(undefined);
589
- expect(!!table).toBe(true);
645
+ await (0, promises_1.writeFile)(fnm, csv);
646
+ const result = await table_1.default.create_from_csv("InvoiceMissing", fnm);
647
+ (0, assertions_1.assertsIsSuccessMessage)(result);
648
+ const { table } = result;
649
+ (0, assertions_1.assertIsSet)(table);
650
+ (0, globals_1.expect)(!!table).toBe(true);
590
651
  const fields = await table.getFields();
591
652
  const countField = fields.find((f) => f.name === "count");
592
- expect(countField.type.name).toBe("Integer");
593
- expect(countField.required).toBe(false);
653
+ (0, assertions_1.assertIsSet)(countField);
654
+ (0, assertions_1.assertIsType)(countField.type);
655
+ (0, globals_1.expect)(countField.type.name).toBe("Integer");
656
+ (0, globals_1.expect)(countField.required).toBe(false);
594
657
  const rows = await table.getRows({ item: "Pencil" });
595
- expect(rows.length).toBe(1);
596
- expect(rows[0].count).toBe(null);
658
+ (0, globals_1.expect)(rows.length).toBe(1);
659
+ (0, globals_1.expect)(rows[0].count).toBe(null);
597
660
  const brows = await table.getRows({ item: "Book" });
598
- expect(brows[0].count).toBe(4);
661
+ (0, globals_1.expect)(brows[0].count).toBe(4);
662
+ });
663
+ (0, globals_1.it)("should import with space in name", async () => {
664
+ //db.set_sql_logging();
665
+ const csv = `Item Name,cost,count, vatable
666
+ Book, 5,4, f
667
+ Pencil, 0.5,2, t`;
668
+ const fnm = "/tmp/test2impok.csv";
669
+ await (0, promises_1.writeFile)(fnm, csv);
670
+ const result = await table_1.default.create_from_csv("Invoice5", fnm);
671
+ (0, assertions_1.assertsIsSuccessMessage)(result);
672
+ const { table } = result;
673
+ const fields = await table.getFields();
674
+ const nameField = fields.find((f) => f.name === "item_name");
675
+ (0, globals_1.expect)(nameField.type.name).toBe("String");
676
+ (0, globals_1.expect)(nameField.label).toBe("Item Name");
677
+ const allrows = await table.getRows();
678
+ (0, globals_1.expect)(allrows.length).toBe(2);
679
+ });
680
+ (0, globals_1.it)("should import with underscore in name", async () => {
681
+ //db.set_sql_logging();
682
+ const csv = `Item_Name,cost,count, vatable
683
+ Book, 5,4, f
684
+ Pencil, 0.5,2, t`;
685
+ const fnm = "/tmp/test2impok.csv";
686
+ await (0, promises_1.writeFile)(fnm, csv);
687
+ const result = await table_1.default.create_from_csv("Invoice6", fnm);
688
+ (0, assertions_1.assertsIsSuccessMessage)(result);
689
+ const { table } = result;
690
+ const fields = await table.getFields();
691
+ (0, globals_1.expect)(fields.map((f) => f.name)).toContain("item_name");
692
+ const nameField = fields.find((f) => f.name === "item_name");
693
+ (0, globals_1.expect)(nameField.type.name).toBe("String");
694
+ (0, globals_1.expect)(nameField.label).toBe("Item Name");
695
+ const allrows = await table.getRows();
696
+ (0, globals_1.expect)(allrows.length).toBe(2);
599
697
  });
600
698
  });
601
- describe("Table field uppercase", () => {
602
- it("should create by importing", async () => {
699
+ (0, globals_1.describe)("Table field uppercase", () => {
700
+ (0, globals_1.it)("should create by importing", async () => {
603
701
  const csv = `Item,cost,Count,Vatable
604
702
  Book, 5,4, f
605
703
  Pencil, 0.5,2, t`;
606
704
  const fnm = "/tmp/test_uc.csv";
607
- await fs.writeFile(fnm, csv);
608
- const { table } = await Table.create_from_csv("InvoiceUC", fnm);
705
+ await (0, promises_1.writeFile)(fnm, csv);
706
+ const result = await table_1.default.create_from_csv("InvoiceUC", fnm);
707
+ (0, assertions_1.assertsIsSuccessMessage)(result);
708
+ const { table } = result;
709
+ (0, assertions_1.assertIsSet)(table);
609
710
  const fields = await table.getFields();
610
711
  const rows1 = await table.getJoinedRows({
611
712
  where: { item: { ilike: "East" } },
612
713
  });
613
- expect(rows1.length).toBe(0);
714
+ (0, globals_1.expect)(rows1.length).toBe(0);
614
715
  const rows2 = await table.getJoinedRows({
615
716
  where: { count: 2 },
616
717
  });
617
- expect(rows2.length).toBe(1);
718
+ (0, globals_1.expect)(rows2.length).toBe(1);
618
719
  const rows3 = await table.getJoinedRows({
619
720
  where: { _fts: { searchTerm: "Book", fields } },
620
721
  });
621
- expect(rows3.length).toBe(1);
722
+ (0, globals_1.expect)(rows3.length).toBe(1);
622
723
  });
623
724
  });
624
- describe("Table unique constraint", () => {
625
- it("should create table", async () => {
725
+ (0, globals_1.describe)("Table unique constraint", () => {
726
+ (0, globals_1.it)("should create table", async () => {
626
727
  //db.set_sql_logging()
627
- const table = await Table.create("TableWithUniques");
628
- const field = await Field.create({
728
+ const table = await table_1.default.create("TableWithUniques");
729
+ const field = await field_1.default.create({
629
730
  table,
630
731
  name: "name",
631
732
  type: "String",
@@ -634,38 +735,40 @@ describe("Table unique constraint", () => {
634
735
  await table.insertRow({ name: "Bill" });
635
736
  const ted_id = await table.insertRow({ name: "Ted" });
636
737
  const ins_res = await table.tryInsertRow({ name: "Bill" });
637
- expect(ins_res).toEqual({
738
+ (0, globals_1.expect)(ins_res).toEqual({
638
739
  error: "Duplicate value for unique field: name",
639
740
  });
640
741
  const ins_res1 = await table.tryInsertRow({ name: "Billy" });
641
- expect(typeof ins_res1.success).toEqual("number");
742
+ (0, assertions_1.assertsIsSuccessMessage)(ins_res1);
743
+ (0, globals_1.expect)(typeof ins_res1.success).toEqual("number");
642
744
  const upd_res = await table.tryUpdateRow({ name: "Bill" }, ted_id);
643
- expect(upd_res).toEqual({
745
+ (0, globals_1.expect)(upd_res).toEqual({
644
746
  error: "Duplicate value for unique field: name",
645
747
  });
646
748
  const upd_res1 = await table.tryUpdateRow({ name: "teddy" }, ted_id);
647
- expect(upd_res1.success).toEqual(true);
749
+ (0, assertions_1.assertsIsSuccessMessage)(upd_res1);
750
+ (0, globals_1.expect)(upd_res1.success).toEqual(true);
648
751
  await field.update({ is_unique: false });
649
- const field1 = await Field.findOne({ id: field.id });
650
- expect(field1.is_unique).toBe(false);
752
+ const field1 = await field_1.default.findOne({ id: field.id });
753
+ (0, globals_1.expect)(field1.is_unique).toBe(false);
651
754
  //const bill2_id = await table.insertRow({ name: "Bill" });
652
755
  await field1.update({ is_unique: true });
653
- const field2 = await Field.findOne({ id: field.id });
654
- expect(field2.is_unique).toBe(true);
655
- expect(field1.is_unique).toBe(true);
756
+ const field2 = await field_1.default.findOne({ id: field.id });
757
+ (0, globals_1.expect)(field2.is_unique).toBe(true);
758
+ (0, globals_1.expect)(field1.is_unique).toBe(true);
656
759
  });
657
760
  });
658
- describe("Table not null constraint", () => {
659
- it("should create table", async () => {
761
+ (0, globals_1.describe)("Table not null constraint", () => {
762
+ (0, globals_1.it)("should create table", async () => {
660
763
  //db.set_sql_logging()
661
- const table = await Table.create("TableWithNotNulls");
662
- const field = await Field.create({
764
+ const table = await table_1.default.create("TableWithNotNulls");
765
+ const field = await field_1.default.create({
663
766
  table,
664
767
  name: "name",
665
768
  type: "String",
666
769
  required: true,
667
770
  });
668
- await Field.create({
771
+ await field_1.default.create({
669
772
  table,
670
773
  name: "age",
671
774
  type: "Integer",
@@ -673,70 +776,73 @@ describe("Table not null constraint", () => {
673
776
  await table.insertRow({ name: "Bill", age: 13 });
674
777
  await table.insertRow({ name: "Bill", age: 13 });
675
778
  const ins_res = await table.tryInsertRow({ age: 17, name: null });
676
- expect(!!ins_res.error).toBe(true);
677
- expect(ins_res.error).toContain("name");
678
- if (!db.isSQLite) {
779
+ (0, assertions_1.assertIsErrorMsg)(ins_res);
780
+ (0, globals_1.expect)(!!ins_res.error).toBe(true);
781
+ (0, globals_1.expect)(ins_res.error).toContain("name");
782
+ if (!db_1.default.isSQLite) {
679
783
  await field.update({ required: false });
680
784
  const ted_id = await table.insertRow({ age: 17 });
681
785
  await table.deleteRows({ id: ted_id });
682
786
  await field.update({ required: true });
683
787
  const ins_res1 = await table.tryInsertRow({ age: 167 });
684
- expect(!!ins_res1.error).toBe(true);
788
+ (0, assertions_1.assertIsErrorMsg)(ins_res1);
789
+ (0, globals_1.expect)(!!ins_res1.error).toBe(true);
685
790
  }
686
791
  });
687
- it("should query null", async () => {
688
- const table = await Table.findOne({ name: "TableWithNotNulls" });
792
+ (0, globals_1.it)("should query null", async () => {
793
+ const table = await table_1.default.findOne({ name: "TableWithNotNulls" });
794
+ (0, assertions_1.assertIsSet)(table);
689
795
  await table.insertRow({ name: "Ageless", age: null });
690
796
  const rows = await table.getRows({ age: null });
691
- expect(rows.length).toBe(1);
692
- expect(rows[0].name).toBe("Ageless");
797
+ (0, globals_1.expect)(rows.length).toBe(1);
798
+ (0, globals_1.expect)(rows[0].name).toBe("Ageless");
693
799
  const rows1 = await table.getRows({ age: null, name: "Ageless" });
694
- expect(rows1.length).toBe(1);
695
- expect(rows1[0].name).toBe("Ageless");
800
+ (0, globals_1.expect)(rows1.length).toBe(1);
801
+ (0, globals_1.expect)(rows1[0].name).toBe("Ageless");
696
802
  const rows2 = await table.getRows({ name: "Ageless", age: null });
697
- expect(rows2.length).toBe(1);
698
- expect(rows2[0].name).toBe("Ageless");
803
+ (0, globals_1.expect)(rows2.length).toBe(1);
804
+ (0, globals_1.expect)(rows2[0].name).toBe("Ageless");
699
805
  });
700
806
  });
701
- describe("Table with users and files", () => {
702
- it("should create table", async () => {
807
+ (0, globals_1.describe)("Table with users and files", () => {
808
+ (0, globals_1.it)("should create table", async () => {
703
809
  //db.set_sql_logging()
704
810
  const rick = await rick_file();
705
- const table = await Table.create("TableWithUsers");
706
- await Field.create({
811
+ const table = await table_1.default.create("TableWithUsers");
812
+ await field_1.default.create({
707
813
  table,
708
814
  name: "name",
709
815
  type: "String",
710
816
  is_unique: true,
711
817
  });
712
- await Field.create({
818
+ await field_1.default.create({
713
819
  table,
714
820
  name: "owner",
715
821
  type: "Key to users",
716
822
  });
717
- await Field.create({
823
+ await field_1.default.create({
718
824
  table,
719
825
  name: "mugshot",
720
826
  type: "File",
721
827
  });
722
828
  await table.insertRow({ name: "Rocket", owner: 1, mugshot: rick.id });
723
829
  const rels = await table.get_parent_relations();
724
- expect(rels.parent_field_list).toEqual(["owner.email", "owner.id"]);
830
+ (0, globals_1.expect)(rels.parent_field_list).toEqual(["owner.email", "owner.id"]);
725
831
  const joined = await table.getJoinedRows();
726
832
  // expect(joined).toEqual("rick.png")
727
- expect(joined[0].mugshot__filename).toEqual("rick.png");
833
+ (0, globals_1.expect)(joined[0].mugshot__filename).toEqual("rick.png");
728
834
  });
729
835
  });
730
- describe("Table and view deletion ", () => {
731
- it("should setup", async () => {
732
- const tc = await Table.create("mytable19");
733
- await Field.create({
836
+ (0, globals_1.describe)("Table and view deletion ", () => {
837
+ (0, globals_1.it)("should setup", async () => {
838
+ const tc = await table_1.default.create("mytable19");
839
+ await field_1.default.create({
734
840
  table: tc,
735
841
  name: "name",
736
842
  type: "String",
737
843
  is_unique: true,
738
844
  });
739
- const v = await View.create({
845
+ const v = await view_1.default.create({
740
846
  table_id: tc.id,
741
847
  name: "anewview",
742
848
  viewtemplate: "List",
@@ -753,17 +859,17 @@ describe("Table and view deletion ", () => {
753
859
  //expect(error).toBeInstanceOf(Error); - not on SQLite
754
860
  await v.delete();
755
861
  });
756
- it("should delete table after view delete", async () => {
757
- const tc = await Table.findOne({ name: "mytable19" });
862
+ (0, globals_1.it)("should delete table after view delete", async () => {
863
+ const tc = await table_1.default.findOne({ name: "mytable19" });
758
864
  if (tc)
759
865
  await tc.delete();
760
866
  });
761
867
  });
762
- describe("Table with date", () => {
763
- it("should create table", async () => {
868
+ (0, globals_1.describe)("Table with date", () => {
869
+ (0, globals_1.it)("should create table", async () => {
764
870
  //db.set_sql_logging()
765
- const table = await Table.create("TableWithDates");
766
- await Field.create({
871
+ const table = await table_1.default.create("TableWithDates");
872
+ await field_1.default.create({
767
873
  table,
768
874
  name: "time",
769
875
  type: "Date",
@@ -771,25 +877,25 @@ describe("Table with date", () => {
771
877
  await table.insertRow({ time: new Date() });
772
878
  const rows = await table.getRows();
773
879
  var dif = new Date(rows[0].time).getTime() - new Date().getTime();
774
- expect(Math.abs(dif)).toBeLessThanOrEqual(1000);
880
+ (0, globals_1.expect)(Math.abs(dif)).toBeLessThanOrEqual(1000);
775
881
  });
776
882
  });
777
- describe("Tables with name clashes", () => {
778
- it("should create tables", async () => {
883
+ (0, globals_1.describe)("Tables with name clashes", () => {
884
+ (0, globals_1.it)("should create tables", async () => {
779
885
  //db.set_sql_logging()
780
- const cars = await Table.create("TableClashCar");
781
- const persons = await Table.create("TableClashPerson");
782
- await Field.create({
886
+ const cars = await table_1.default.create("TableClashCar");
887
+ const persons = await table_1.default.create("TableClashPerson");
888
+ await field_1.default.create({
783
889
  table: persons,
784
890
  name: "name",
785
891
  type: "String",
786
892
  });
787
- await Field.create({
893
+ await field_1.default.create({
788
894
  table: cars,
789
895
  name: "name",
790
896
  type: "String",
791
897
  });
792
- await Field.create({
898
+ await field_1.default.create({
793
899
  table: cars,
794
900
  name: "owner",
795
901
  type: "Key to TableClashPerson",
@@ -797,23 +903,25 @@ describe("Tables with name clashes", () => {
797
903
  const sally = await persons.insertRow({ name: "Sally" });
798
904
  await cars.insertRow({ name: "Mustang", owner: sally });
799
905
  });
800
- it("should query", async () => {
801
- const cars = await Table.findOne({ name: "TableClashCar" });
906
+ (0, globals_1.it)("should query", async () => {
907
+ const cars = await table_1.default.findOne({ name: "TableClashCar" });
908
+ (0, assertions_1.assertIsSet)(cars);
802
909
  const rows = await cars.getJoinedRows({
803
910
  joinFields: {
804
911
  owner_name: { ref: "owner", target: "name" },
805
912
  },
806
913
  });
807
- expect(rows[0]).toEqual({
914
+ (0, globals_1.expect)(rows[0]).toEqual({
808
915
  id: 1,
809
916
  name: "Mustang",
810
917
  owner: 1,
811
918
  owner_name: "Sally",
812
919
  });
813
920
  });
814
- it("should show list view", async () => {
815
- const cars = await Table.findOne({ name: "TableClashCar" });
816
- const v = await View.create({
921
+ (0, globals_1.it)("should show list view", async () => {
922
+ const cars = await table_1.default.findOne({ name: "TableClashCar" });
923
+ (0, assertions_1.assertIsSet)(cars);
924
+ const v = await view_1.default.create({
817
925
  table_id: cars.id,
818
926
  name: "patientlist",
819
927
  viewtemplate: "List",
@@ -826,12 +934,13 @@ describe("Tables with name clashes", () => {
826
934
  min_role: 10,
827
935
  });
828
936
  const res = await v.run({}, mockReqRes);
829
- expect(res).toContain("Mustang");
830
- expect(res).toContain("Sally");
937
+ (0, globals_1.expect)(res).toContain("Mustang");
938
+ (0, globals_1.expect)(res).toContain("Sally");
831
939
  });
832
- it("should show show view", async () => {
833
- const cars = await Table.findOne({ name: "TableClashCar" });
834
- const v = await View.create({
940
+ (0, globals_1.it)("should show show view", async () => {
941
+ const cars = await table_1.default.findOne({ name: "TableClashCar" });
942
+ (0, assertions_1.assertIsSet)(cars);
943
+ const v = await view_1.default.create({
835
944
  table_id: cars.id,
836
945
  name: "patientlist",
837
946
  viewtemplate: "Show",
@@ -850,115 +959,123 @@ describe("Tables with name clashes", () => {
850
959
  min_role: 10,
851
960
  });
852
961
  const res = await v.run({ id: 1 }, mockReqRes);
853
- expect(res).toContain("Mustang");
854
- expect(res).toContain("Sally");
962
+ (0, globals_1.expect)(res).toContain("Mustang");
963
+ (0, globals_1.expect)(res).toContain("Sally");
855
964
  });
856
965
  });
857
- describe("Table joint unique constraint", () => {
858
- it("should create table", async () => {
859
- const table = await Table.findOne({ name: "books" });
966
+ (0, globals_1.describe)("Table joint unique constraint", () => {
967
+ (0, globals_1.it)("should create table", async () => {
968
+ const table = await table_1.default.findOne({ name: "books" });
969
+ (0, assertions_1.assertIsSet)(table);
970
+ (0, assertions_1.assertIsSet)(table.id);
860
971
  const rows = await table.getRows();
861
972
  const { id, ...row0 } = rows[0];
862
- const tc = await TableConstraint.create({
973
+ const tc = await table_constraints_1.default.create({
863
974
  table_id: table.id,
864
975
  type: "Unique",
865
976
  configuration: { fields: ["author", "pages"] },
866
977
  });
867
978
  const res = await table.tryInsertRow(row0);
868
- expect(!!res.error).toBe(true);
979
+ (0, assertions_1.assertIsErrorMsg)(res);
980
+ (0, globals_1.expect)(!!res.error).toBe(true);
869
981
  await tc.delete();
870
982
  const res1 = await table.tryInsertRow(row0);
871
- expect(!!res1.error).toBe(false);
983
+ (0, assertions_1.assertIsErrorMsg)(res1);
984
+ (0, globals_1.expect)(!!res1.error).toBe(false);
872
985
  });
873
986
  });
874
- describe("Table with row ownership", () => {
875
- it("should create and delete table", async () => {
876
- const persons = await Table.create("TableOwned");
877
- const name = await Field.create({
987
+ (0, globals_1.describe)("Table with row ownership", () => {
988
+ (0, globals_1.it)("should create and delete table", async () => {
989
+ const persons = await table_1.default.create("TableOwned");
990
+ const name = await field_1.default.create({
878
991
  table: persons,
879
992
  name: "name",
880
993
  type: "String",
881
994
  });
882
- const age = await Field.create({
995
+ const age = await field_1.default.create({
883
996
  table: persons,
884
997
  name: "age",
885
998
  type: "String",
886
999
  });
887
- const owner = await Field.create({
1000
+ const owner = await field_1.default.create({
888
1001
  table: persons,
889
1002
  name: "owner",
890
1003
  type: "Key to users",
891
1004
  });
892
1005
  await persons.update({ ownership_field_id: owner.id });
893
- if (!db.isSQLite) {
1006
+ if (!db_1.default.isSQLite) {
894
1007
  await age.update({ type: "Integer" });
895
1008
  await name.update({ name: "lastname" });
896
1009
  await persons.insertRow({ lastname: "Joe", age: 12 });
897
1010
  await persons.insertRow({ lastname: "Sam", age: 13, owner: 1 });
898
1011
  const row = await persons.getRow({ age: 12 });
899
- expect(row.lastname).toBe("Joe");
900
- expect(row.age).toBe(12);
1012
+ (0, assertions_1.assertIsSet)(row);
1013
+ (0, globals_1.expect)(row.lastname).toBe("Joe");
1014
+ (0, globals_1.expect)(row.age).toBe(12);
901
1015
  const owner_fnm = await persons.owner_fieldname();
902
- expect(owner_fnm).toBe("owner");
1016
+ (0, globals_1.expect)(owner_fnm).toBe("owner");
903
1017
  const is_owner = await persons.is_owner({ id: 6 }, row);
904
- expect(is_owner).toBe(false);
1018
+ (0, globals_1.expect)(is_owner).toBe(false);
905
1019
  const row1 = await persons.getRow({ age: 13 });
1020
+ (0, assertions_1.assertIsSet)(row1);
906
1021
  const is_owner1 = await persons.is_owner({ id: 1 }, row1);
907
- expect(is_owner1).toBe(true);
1022
+ (0, globals_1.expect)(is_owner1).toBe(true);
908
1023
  }
909
1024
  await persons.delete();
910
1025
  });
911
1026
  });
912
- describe("Table with row ownership", () => {
913
- it("should create and delete table", async () => {
914
- const persons = await Table.create("TableOwnedFml");
915
- const name = await Field.create({
1027
+ (0, globals_1.describe)("Table with row ownership", () => {
1028
+ (0, globals_1.it)("should create and delete table", async () => {
1029
+ const persons = await table_1.default.create("TableOwnedFml");
1030
+ const name = await field_1.default.create({
916
1031
  table: persons,
917
1032
  name: "name",
918
1033
  type: "String",
919
1034
  });
920
- const age = await Field.create({
1035
+ const age = await field_1.default.create({
921
1036
  table: persons,
922
1037
  name: "age",
923
1038
  type: "String",
924
1039
  });
925
- const owner = await Field.create({
1040
+ const owner = await field_1.default.create({
926
1041
  table: persons,
927
1042
  name: "owner",
928
1043
  type: "Key to users",
929
1044
  });
930
1045
  await persons.update({ ownership_formula: "user.id===owner" });
931
- if (!db.isSQLite) {
1046
+ if (!db_1.default.isSQLite) {
932
1047
  await age.update({ type: "Integer" });
933
1048
  await name.update({ name: "lastname" });
934
1049
  await persons.insertRow({ lastname: "Joe", age: 12 });
935
1050
  await persons.insertRow({ lastname: "Sam", age: 13, owner: 1 });
936
1051
  const row = await persons.getRow({ age: 12 });
937
- expect(row.lastname).toBe("Joe");
938
- expect(row.age).toBe(12);
1052
+ (0, assertions_1.assertIsSet)(row);
1053
+ (0, globals_1.expect)(row.lastname).toBe("Joe");
1054
+ (0, globals_1.expect)(row.age).toBe(12);
939
1055
  const is_owner = await persons.is_owner({ id: 6 }, row);
940
- expect(is_owner).toBe(false);
1056
+ (0, globals_1.expect)(is_owner).toBe(false);
941
1057
  const row1 = await persons.getRow({ age: 13 });
1058
+ (0, assertions_1.assertIsSet)(row1);
942
1059
  const is_owner1 = await persons.is_owner({ id: 1 }, row1);
943
- expect(is_owner1).toBe(true);
1060
+ (0, globals_1.expect)(is_owner1).toBe(true);
944
1061
  }
945
1062
  await persons.delete();
946
1063
  });
947
1064
  });
948
- describe("Table with UUID pks", () => {
949
- if (!db.isSQLite) {
950
- it("should select uuid", async () => {
951
- await db.query('create extension if not exists "uuid-ossp";');
952
- const { rows } = await db.query("select uuid_generate_v4();");
953
- expect(rows.length).toBe(1);
954
- expect(typeof rows[0].uuid_generate_v4).toBe("string");
955
- });
956
- it("should create and insert stuff in table", async () => {
1065
+ (0, globals_1.describe)("Table with UUID pks", () => {
1066
+ if (!db_1.default.isSQLite) {
1067
+ (0, globals_1.it)("should select uuid", async () => {
1068
+ await db_1.default.query('create extension if not exists "uuid-ossp";');
1069
+ const { rows } = await db_1.default.query("select uuid_generate_v4();");
1070
+ (0, globals_1.expect)(rows.length).toBe(1);
1071
+ (0, globals_1.expect)(typeof rows[0].uuid_generate_v4).toBe("string");
1072
+ });
1073
+ (0, globals_1.it)("should create and insert stuff in table", async () => {
957
1074
  getState().registerPlugin("mock_plugin", plugin_with_routes);
958
- const table = await Table.create("TableUUID");
1075
+ const table = await table_1.default.create("TableUUID");
959
1076
  const [pk] = await table.getFields();
960
1077
  await pk.update({ type: "UUID" });
961
- const name = await Field.create({
1078
+ const name = await field_1.default.create({
962
1079
  table: table,
963
1080
  name: "name",
964
1081
  type: "String",
@@ -966,44 +1083,47 @@ describe("Table with UUID pks", () => {
966
1083
  table.fields = null;
967
1084
  await table.insertRow({ name: "Sam" });
968
1085
  const rows = await table.getRows();
969
- expect(rows.length).toBe(1);
970
- expect(typeof rows[0].id).toBe("string");
971
- expect(rows[0].id.length > 10).toBe(true);
972
- expect(rows[0].name).toBe("Sam");
1086
+ (0, globals_1.expect)(rows.length).toBe(1);
1087
+ (0, globals_1.expect)(typeof rows[0].id).toBe("string");
1088
+ (0, globals_1.expect)(rows[0].id.length > 10).toBe(true);
1089
+ (0, globals_1.expect)(rows[0].name).toBe("Sam");
973
1090
  await table.updateRow({ name: "Jim" }, rows[0].id);
974
1091
  const rows1 = await table.getJoinedRows();
975
- expect(rows1.length).toBe(1);
976
- expect(typeof rows1[0].id).toBe("string");
977
- expect(rows1[0].id).toBe(rows[0].id);
978
- expect(rows1[0].name).toBe("Jim");
1092
+ (0, globals_1.expect)(rows1.length).toBe(1);
1093
+ (0, globals_1.expect)(typeof rows1[0].id).toBe("string");
1094
+ (0, globals_1.expect)(rows1[0].id).toBe(rows[0].id);
1095
+ (0, globals_1.expect)(rows1[0].name).toBe("Jim");
979
1096
  const row = await table.getRow({ id: rows[0].id });
980
- expect(row.name).toBe("Jim");
1097
+ (0, assertions_1.assertIsSet)(row);
1098
+ (0, globals_1.expect)(row.name).toBe("Jim");
981
1099
  });
982
- it("should import json", async () => {
1100
+ (0, globals_1.it)("should import json", async () => {
983
1101
  const json = [
984
1102
  { name: "Alex", id: "750d07fc-943d-4afc-9084-3911bcdbd0f7" },
985
1103
  ];
986
1104
  const fnm = "/tmp/test1.json";
987
- await fs.writeFile(fnm, JSON.stringify(json));
988
- const table = await Table.findOne({ name: "TableUUID" });
989
- expect(!!table).toBe(true);
1105
+ await (0, promises_1.writeFile)(fnm, JSON.stringify(json));
1106
+ const table = await table_1.default.findOne({ name: "TableUUID" });
1107
+ (0, assertions_1.assertIsSet)(table);
1108
+ (0, globals_1.expect)(!!table).toBe(true);
990
1109
  const impres = await table.import_json_file(fnm);
991
- expect(impres).toEqual({
1110
+ (0, globals_1.expect)(impres).toEqual({
992
1111
  success: "Imported 1 rows into table TableUUID",
993
1112
  });
994
1113
  const rows = await table.getRows();
995
- expect(rows.length).toBe(2);
1114
+ (0, globals_1.expect)(rows.length).toBe(2);
996
1115
  });
997
- it("should be joinable to", async () => {
998
- const uuidtable1 = await Table.findOne({ name: "TableUUID" });
999
- const table = await Table.create("JoinUUID");
1000
- await Field.create({
1116
+ (0, globals_1.it)("should be joinable to", async () => {
1117
+ const uuidtable1 = await table_1.default.findOne({ name: "TableUUID" });
1118
+ (0, assertions_1.assertIsSet)(uuidtable1);
1119
+ const table = await table_1.default.create("JoinUUID");
1120
+ await field_1.default.create({
1001
1121
  table: table,
1002
1122
  name: "myname",
1003
1123
  type: "String",
1004
1124
  });
1005
1125
  //db.set_sql_logging();
1006
- await Field.create({
1126
+ await field_1.default.create({
1007
1127
  table: table,
1008
1128
  name: "follows",
1009
1129
  type: "Key to TableUUID",
@@ -1021,15 +1141,15 @@ describe("Table with UUID pks", () => {
1021
1141
  const allRows = await table.getRows();
1022
1142
  console.log(allRows);
1023
1143
  }
1024
- expect(rows.length).toBe(1);
1025
- expect(rows[0].leader).toBe("Jim");
1026
- expect(rows[0].myname).toBe("Fred");
1144
+ (0, globals_1.expect)(rows.length).toBe(1);
1145
+ (0, globals_1.expect)(rows[0].leader).toBe("Jim");
1146
+ (0, globals_1.expect)(rows[0].myname).toBe("Fred");
1027
1147
  await table.delete();
1028
1148
  await uuidtable1.delete();
1029
1149
  });
1030
- it("should create and delete table", async () => {
1150
+ (0, globals_1.it)("should create and delete table", async () => {
1031
1151
  getState().registerPlugin("mock_plugin", plugin_with_routes);
1032
- const table = await Table.create("TableUUID1");
1152
+ const table = await table_1.default.create("TableUUID1");
1033
1153
  const [pk] = await table.getFields();
1034
1154
  await pk.update({ type: "UUID" });
1035
1155
  table.fields = null;
@@ -1039,41 +1159,41 @@ describe("Table with UUID pks", () => {
1039
1159
  });
1040
1160
  }
1041
1161
  });
1042
- describe("external tables", () => {
1043
- it("should register plugin", async () => {
1162
+ (0, globals_1.describe)("external tables", () => {
1163
+ (0, globals_1.it)("should register plugin", async () => {
1044
1164
  getState().registerPlugin("mock_plugin", plugin_with_routes);
1045
1165
  });
1046
- it("should find table", async () => {
1047
- const table = await Table.findOne({ name: "exttab" });
1048
- expect(!!table).toBe(true);
1049
- const notable = await Table.findOne({ name: "exttnosuchab" });
1050
- expect(!!notable).toBe(false);
1051
- const tables = await Table.find_with_external();
1052
- expect(tables.map((t) => t.name)).toContain("exttab");
1053
- expect(tables.map((t) => t.name)).toContain("books");
1054
- const etables = await Table.find_with_external({ external: true });
1055
- expect(etables.map((t) => t.name)).toEqual(["exttab"]);
1056
- const dbtables = await Table.find_with_external({ external: false });
1057
- expect(dbtables.map((t) => t.name)).not.toContain("exttab");
1058
- expect(dbtables.map((t) => t.name)).toContain("books");
1166
+ (0, globals_1.it)("should find table", async () => {
1167
+ const table = await table_1.default.findOne({ name: "exttab" });
1168
+ (0, globals_1.expect)(!!table).toBe(true);
1169
+ const notable = await table_1.default.findOne({ name: "exttnosuchab" });
1170
+ (0, globals_1.expect)(!!notable).toBe(false);
1171
+ const tables = await table_1.default.find_with_external();
1172
+ (0, globals_1.expect)(tables.map((t) => t.name)).toContain("exttab");
1173
+ (0, globals_1.expect)(tables.map((t) => t.name)).toContain("books");
1174
+ const etables = await table_1.default.find_with_external({ external: true });
1175
+ (0, globals_1.expect)(etables.map((t) => t.name)).toEqual(["exttab"]);
1176
+ const dbtables = await table_1.default.find_with_external({ external: false });
1177
+ (0, globals_1.expect)(dbtables.map((t) => t.name)).not.toContain("exttab");
1178
+ (0, globals_1.expect)(dbtables.map((t) => t.name)).toContain("books");
1059
1179
  });
1060
1180
  });
1061
- describe("distance ordering", () => {
1062
- it("should create table", async () => {
1063
- const tc = await Table.create("geotable1");
1064
- await Field.create({
1181
+ (0, globals_1.describe)("distance ordering", () => {
1182
+ (0, globals_1.it)("should create table", async () => {
1183
+ const tc = await table_1.default.create("geotable1");
1184
+ await field_1.default.create({
1065
1185
  table: tc,
1066
1186
  label: "Name",
1067
1187
  type: "String",
1068
1188
  required: true,
1069
1189
  });
1070
- await Field.create({
1190
+ await field_1.default.create({
1071
1191
  table: tc,
1072
1192
  label: "Lat",
1073
1193
  type: "Float",
1074
1194
  required: true,
1075
1195
  });
1076
- await Field.create({
1196
+ await field_1.default.create({
1077
1197
  table: tc,
1078
1198
  label: "Long",
1079
1199
  type: "Float",
@@ -1082,22 +1202,23 @@ describe("distance ordering", () => {
1082
1202
  await tc.insertRow({ name: "Fred", lat: 10, long: 10 });
1083
1203
  await tc.insertRow({ name: "George", lat: 20, long: 20 });
1084
1204
  });
1085
- it("should query", async () => {
1086
- const table = await Table.findOne({ name: "geotable1" });
1205
+ (0, globals_1.it)("should query", async () => {
1206
+ const table = await table_1.default.findOne({ name: "geotable1" });
1207
+ (0, assertions_1.assertIsSet)(table);
1087
1208
  const fred_rows = await table.getRows({}, {
1088
1209
  orderBy: {
1089
1210
  distance: { lat: 11, long: 11, latField: "lat", longField: "long" },
1090
1211
  },
1091
1212
  });
1092
- expect(fred_rows.length).toBe(2);
1093
- expect(fred_rows[0].name).toBe("Fred");
1213
+ (0, globals_1.expect)(fred_rows.length).toBe(2);
1214
+ (0, globals_1.expect)(fred_rows[0].name).toBe("Fred");
1094
1215
  const george_rows = await table.getJoinedRows({
1095
1216
  orderBy: {
1096
1217
  distance: { lat: 19, long: 19, latField: "lat", longField: "long" },
1097
1218
  },
1098
1219
  });
1099
- expect(george_rows.length).toBe(2);
1100
- expect(george_rows[0].name).toBe("George");
1220
+ (0, globals_1.expect)(george_rows.length).toBe(2);
1221
+ (0, globals_1.expect)(george_rows[0].name).toBe("George");
1101
1222
  });
1102
1223
  });
1103
1224
  //# sourceMappingURL=table.test.js.map