@saltcorn/data 1.5.0-beta.8 → 1.5.0-rc.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 (146) hide show
  1. package/dist/base-plugin/actions.d.ts +221 -145
  2. package/dist/base-plugin/actions.d.ts.map +1 -1
  3. package/dist/base-plugin/actions.js +80 -12
  4. package/dist/base-plugin/actions.js.map +1 -1
  5. package/dist/base-plugin/fileviews.d.ts +3 -3
  6. package/dist/base-plugin/fileviews.js +20 -9
  7. package/dist/base-plugin/fileviews.js.map +1 -1
  8. package/dist/base-plugin/index.d.ts +2 -2
  9. package/dist/base-plugin/index.d.ts.map +1 -1
  10. package/dist/base-plugin/types.d.ts.map +1 -1
  11. package/dist/base-plugin/types.js +8 -5
  12. package/dist/base-plugin/types.js.map +1 -1
  13. package/dist/base-plugin/viewtemplates/edit.d.ts +6 -2
  14. package/dist/base-plugin/viewtemplates/edit.d.ts.map +1 -1
  15. package/dist/base-plugin/viewtemplates/edit.js +17 -341
  16. package/dist/base-plugin/viewtemplates/edit.js.map +1 -1
  17. package/dist/base-plugin/viewtemplates/filter.d.ts.map +1 -1
  18. package/dist/base-plugin/viewtemplates/filter.js +9 -3
  19. package/dist/base-plugin/viewtemplates/filter.js.map +1 -1
  20. package/dist/base-plugin/viewtemplates/show.d.ts.map +1 -1
  21. package/dist/base-plugin/viewtemplates/show.js +1 -0
  22. package/dist/base-plugin/viewtemplates/show.js.map +1 -1
  23. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts +16 -0
  24. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts.map +1 -1
  25. package/dist/base-plugin/viewtemplates/viewable_fields.js +340 -3
  26. package/dist/base-plugin/viewtemplates/viewable_fields.js.map +1 -1
  27. package/dist/base-plugin/viewtemplates/workflow-room.d.ts.map +1 -1
  28. package/dist/base-plugin/viewtemplates/workflow-room.js +1 -1
  29. package/dist/base-plugin/viewtemplates/workflow-room.js.map +1 -1
  30. package/dist/db/connect.d.ts.map +1 -1
  31. package/dist/db/connect.js +4 -1
  32. package/dist/db/connect.js.map +1 -1
  33. package/dist/db/state.d.ts +11 -7
  34. package/dist/db/state.d.ts.map +1 -1
  35. package/dist/db/state.js +78 -12
  36. package/dist/db/state.js.map +1 -1
  37. package/dist/mobile-mocks/npm/dockerode.d.ts +1 -0
  38. package/dist/mobile-mocks/npm/dockerode.d.ts.map +1 -0
  39. package/dist/mobile-mocks/npm/dockerode.js +2 -0
  40. package/dist/mobile-mocks/npm/dockerode.js.map +1 -0
  41. package/dist/models/config.d.ts.map +1 -1
  42. package/dist/models/config.js +55 -12
  43. package/dist/models/config.js.map +1 -1
  44. package/dist/models/email.js.map +1 -1
  45. package/dist/models/expression.d.ts.map +1 -1
  46. package/dist/models/expression.js +29 -0
  47. package/dist/models/expression.js.map +1 -1
  48. package/dist/models/field.d.ts +5 -3
  49. package/dist/models/field.d.ts.map +1 -1
  50. package/dist/models/field.js +8 -2
  51. package/dist/models/field.js.map +1 -1
  52. package/dist/models/file.d.ts +18 -1
  53. package/dist/models/file.d.ts.map +1 -1
  54. package/dist/models/file.js +361 -43
  55. package/dist/models/file.js.map +1 -1
  56. package/dist/models/form.d.ts.map +1 -1
  57. package/dist/models/form.js.map +1 -1
  58. package/dist/models/index.d.ts.map +1 -1
  59. package/dist/models/internal/push_message_helper.d.ts +42 -12
  60. package/dist/models/internal/push_message_helper.d.ts.map +1 -1
  61. package/dist/models/internal/push_message_helper.js +117 -50
  62. package/dist/models/internal/push_message_helper.js.map +1 -1
  63. package/dist/models/internal/s3_helpers.d.ts +54 -0
  64. package/dist/models/internal/s3_helpers.d.ts.map +1 -0
  65. package/dist/models/internal/s3_helpers.js +561 -0
  66. package/dist/models/internal/s3_helpers.js.map +1 -0
  67. package/dist/models/model.d.ts +1 -1
  68. package/dist/models/model.d.ts.map +1 -1
  69. package/dist/models/model.js.map +1 -1
  70. package/dist/models/notification.d.ts.map +1 -1
  71. package/dist/models/notification.js +2 -5
  72. package/dist/models/notification.js.map +1 -1
  73. package/dist/models/page.d.ts +1 -0
  74. package/dist/models/page.d.ts.map +1 -1
  75. package/dist/models/page.js +27 -24
  76. package/dist/models/page.js.map +1 -1
  77. package/dist/models/plugin.d.ts +11 -3
  78. package/dist/models/plugin.d.ts.map +1 -1
  79. package/dist/models/plugin.js +51 -12
  80. package/dist/models/plugin.js.map +1 -1
  81. package/dist/models/s3_helpers.d.ts +54 -0
  82. package/dist/models/s3_helpers.d.ts.map +1 -0
  83. package/dist/models/s3_helpers.js +505 -0
  84. package/dist/models/s3_helpers.js.map +1 -0
  85. package/dist/models/scheduler.d.ts.map +1 -1
  86. package/dist/models/scheduler.js +4 -1
  87. package/dist/models/scheduler.js.map +1 -1
  88. package/dist/models/table.d.ts +8 -3
  89. package/dist/models/table.d.ts.map +1 -1
  90. package/dist/models/table.js +121 -32
  91. package/dist/models/table.js.map +1 -1
  92. package/dist/models/user.d.ts +4 -4
  93. package/dist/models/user.d.ts.map +1 -1
  94. package/dist/models/user.js.map +1 -1
  95. package/dist/models/view.js +1 -1
  96. package/dist/models/view.js.map +1 -1
  97. package/dist/models/workflow_run.d.ts +1 -1
  98. package/dist/models/workflow_run.d.ts.map +1 -1
  99. package/dist/models/workflow_run.js +8 -2
  100. package/dist/models/workflow_run.js.map +1 -1
  101. package/dist/models/workflow_step.js +1 -1
  102. package/dist/models/workflow_step.js.map +1 -1
  103. package/dist/plugin-helper.d.ts.map +1 -1
  104. package/dist/plugin-helper.js +139 -15
  105. package/dist/plugin-helper.js.map +1 -1
  106. package/dist/standard-menu.js +2 -2
  107. package/dist/standard-menu.js.map +1 -1
  108. package/dist/test-utils/mocks.d.ts +203 -0
  109. package/dist/test-utils/mocks.d.ts.map +1 -0
  110. package/dist/test-utils/mocks.js +329 -0
  111. package/dist/test-utils/mocks.js.map +1 -0
  112. package/dist/tests/assertions.d.ts.map +1 -1
  113. package/dist/tests/assertions.js +10 -9
  114. package/dist/tests/assertions.js.map +1 -1
  115. package/dist/tests/auth.test.js +0 -68
  116. package/dist/tests/auth.test.js.map +1 -1
  117. package/dist/tests/calc.test.js +3 -62
  118. package/dist/tests/calc.test.js.map +1 -1
  119. package/dist/tests/exact_views.test.js +14 -14
  120. package/dist/tests/exact_views.test.js.map +1 -1
  121. package/dist/tests/show.test.js +1 -1
  122. package/dist/tests/show.test.js.map +1 -1
  123. package/dist/tests/table.test.js +0 -37
  124. package/dist/tests/table.test.js.map +1 -1
  125. package/dist/tests/table_sync_info.test.d.ts +2 -0
  126. package/dist/tests/table_sync_info.test.d.ts.map +1 -0
  127. package/dist/tests/table_sync_info.test.js +62 -0
  128. package/dist/tests/table_sync_info.test.js.map +1 -0
  129. package/dist/tests/user.test.js +4 -29
  130. package/dist/tests/user.test.js.map +1 -1
  131. package/dist/tests/view.test.js +0 -3
  132. package/dist/tests/view.test.js.map +1 -1
  133. package/dist/utils.d.ts +11 -1
  134. package/dist/utils.d.ts.map +1 -1
  135. package/dist/utils.js +33 -3
  136. package/dist/utils.js.map +1 -1
  137. package/dist/viewable_fields.d.ts +172 -0
  138. package/dist/viewable_fields.d.ts.map +1 -0
  139. package/dist/viewable_fields.js +1562 -0
  140. package/dist/viewable_fields.js.map +1 -0
  141. package/dist/web-mobile-commons.d.ts +1 -1
  142. package/dist/web-mobile-commons.d.ts.map +1 -1
  143. package/dist/web-mobile-commons.js +19 -3
  144. package/dist/web-mobile-commons.js.map +1 -1
  145. package/package.json +14 -9
  146. package/webpack.config.js +3 -0
@@ -2400,6 +2400,10 @@ const json_list_to_external_table = (get_json_list, fields0, methods = {}) => {
2400
2400
  return await getRows(where || {}, rest || {});
2401
2401
  },
2402
2402
  async getJoinedRow(opts = {}) {
2403
+ if (methods?.getJoinedRows) {
2404
+ const rows = await methods.getJoinedRows(opts);
2405
+ return rows.length > 0 ? rows[0] : null;
2406
+ }
2403
2407
  const { where, ...rest } = opts;
2404
2408
  const rows = await getRows(where || {}, rest || {});
2405
2409
  return rows.length > 0 ? rows[0] : null;
@@ -2418,10 +2422,11 @@ const json_list_to_external_table = (get_json_list, fields0, methods = {}) => {
2418
2422
  let data_in = await get_json_list(where, opts);
2419
2423
  return data_in.length;
2420
2424
  },
2421
- async get_child_relations() {
2422
- const child_relations = [];
2423
- const child_field_list = [];
2424
- const cfields = await Field.find({ reftable_name: this.name }, { cached: true });
2425
+ //copied from table
2426
+ async get_child_relations(allow_join_aggregations) {
2427
+ const cfields = await Field.find({ reftable_name: tbl.name }, { cached: true });
2428
+ let child_relations = [];
2429
+ let child_field_list = [];
2425
2430
  for (const f of cfields) {
2426
2431
  if (f.is_fkey) {
2427
2432
  const table = Table.findOne({ id: f.table_id });
@@ -2433,9 +2438,24 @@ const json_list_to_external_table = (get_json_list, fields0, methods = {}) => {
2433
2438
  child_relations.push({ key_field: f, table });
2434
2439
  }
2435
2440
  }
2436
- return { child_relations, child_field_list: [] };
2441
+ if (allow_join_aggregations) {
2442
+ for (const f of fields) {
2443
+ if (f.is_fkey && f.type !== "File") {
2444
+ const refTable = Table.findOne({ name: f.reftable_name });
2445
+ if (!refTable)
2446
+ throw new Error(`Unable to find table '${f.reftable_name}`);
2447
+ const join_crels = await refTable.get_child_relations(false);
2448
+ join_crels.child_relations.forEach(({ key_field, table }) => {
2449
+ child_field_list.push(`${f.name}->${table.name}.${key_field.name}`);
2450
+ child_relations.push({ key_field, table, through: f });
2451
+ });
2452
+ }
2453
+ }
2454
+ }
2455
+ return { child_relations, child_field_list };
2437
2456
  },
2438
- get_parent_relations() {
2457
+ //copied from table
2458
+ async get_parent_relations(allow_double, allow_triple) {
2439
2459
  let parent_relations = [];
2440
2460
  let parent_field_list = [];
2441
2461
  for (const f of fields) {
@@ -2443,39 +2463,143 @@ const json_list_to_external_table = (get_json_list, fields0, methods = {}) => {
2443
2463
  const table = Table.findOne({ name: f.reftable_name });
2444
2464
  if (!table)
2445
2465
  throw new Error(`Unable to find table '${f.reftable_name}`);
2466
+ table.getFields();
2446
2467
  if (!table.fields)
2447
2468
  throw new Error(`The table '${f.reftable_name} has no fields.`);
2448
2469
  for (const pf of table.fields.filter((f) => !f.calculated || f.stored)) {
2449
2470
  parent_field_list.push(`${f.name}.${pf.name}`);
2450
- parent_relations.push({ key_field: f, table });
2471
+ if (pf.is_fkey && pf.type !== "File" && allow_double) {
2472
+ const table1 = Table.findOne({ name: pf.reftable_name });
2473
+ if (!table1)
2474
+ throw new Error(`Unable to find table '${pf.reftable_name}`);
2475
+ await table1.getFields();
2476
+ if (!table1.fields)
2477
+ throw new Error(`The table '${pf.reftable_name} has no fields.`);
2478
+ if (table1.fields)
2479
+ for (const gpf of table1.fields.filter((f) => !f.calculated || f.stored)) {
2480
+ parent_field_list.push(`${f.name}.${pf.name}.${gpf.name}`);
2481
+ if (allow_triple && gpf.is_fkey && gpf.type !== "File") {
2482
+ const gpfTbl = Table.findOne({
2483
+ name: gpf.reftable_name,
2484
+ });
2485
+ if (gpfTbl) {
2486
+ const gpfFields = await gpfTbl.getFields();
2487
+ for (const ggpf of gpfFields.filter((f) => !f.calculated || f.stored)) {
2488
+ parent_field_list.push(`${f.name}.${pf.name}.${gpf.name}.${ggpf.name}`);
2489
+ }
2490
+ }
2491
+ }
2492
+ }
2493
+ parent_relations.push({
2494
+ key_field: pf,
2495
+ through: f,
2496
+ table: table1,
2497
+ });
2498
+ }
2499
+ }
2500
+ parent_relations.push({ key_field: f, table });
2501
+ }
2502
+ }
2503
+ const o2o_rels = await Field.find({
2504
+ reftable_name: tbl.name,
2505
+ is_unique: true,
2506
+ }, { cached: true });
2507
+ for (const relation of o2o_rels) {
2508
+ const related_table = Table.findOne({ id: relation.table_id });
2509
+ if (related_table) {
2510
+ const relfields = await related_table.getFields();
2511
+ for (const relfield of relfields) {
2512
+ parent_field_list.push(`${related_table.name}.${relation.name}->${relfield.name}`);
2513
+ parent_relations.push({
2514
+ key_field: relation,
2515
+ ontable: related_table,
2516
+ });
2451
2517
  }
2452
2518
  }
2453
2519
  }
2454
2520
  return { parent_relations, parent_field_list };
2455
2521
  },
2456
- get_relation_options() {
2457
- return [];
2522
+ //copied from table
2523
+ async get_relation_options() {
2524
+ return await Promise.all((await tbl.get_relation_data()).map(async ({ relationTable, relationField }) => {
2525
+ const path = `${relationTable.name}.${relationField.name}`;
2526
+ const relFields = await relationTable.getFields();
2527
+ const names = relFields
2528
+ .filter((f) => f.type !== "Key")
2529
+ .map((f) => f.name);
2530
+ return { relationPath: path, relationFields: names };
2531
+ }));
2458
2532
  },
2459
- get_relation_data() {
2460
- return [];
2533
+ //copied from table
2534
+ async get_relation_data(unique = true) {
2535
+ const result = [];
2536
+ const o2o_rels = await Field.find({
2537
+ reftable_name: tbl.name,
2538
+ is_unique: unique,
2539
+ }, { cached: true });
2540
+ for (const field of o2o_rels) {
2541
+ const relTbl = Table.findOne({ id: field.table_id });
2542
+ if (relTbl)
2543
+ result.push({ relationTable: relTbl, relationField: field });
2544
+ }
2545
+ return result;
2461
2546
  },
2462
- get_join_field_options() {
2547
+ //copied from table
2548
+ async get_join_field_options(allow_double, allow_triple) {
2463
2549
  const result = [];
2464
2550
  for (const f of fields) {
2465
2551
  if (f.is_fkey && f.type !== "File") {
2466
2552
  const table = Table.findOne({ name: f.reftable_name });
2553
+ if (!table)
2554
+ throw new Error(`Unable to find table '${f.reftable_name}`);
2555
+ table.getFields();
2556
+ if (!table.fields)
2557
+ throw new Error(`The table '${f.reftable_name} has no fields.`);
2467
2558
  const subOne = {
2468
2559
  name: f.name,
2469
2560
  table: table.name,
2470
- subFields: new Array(),
2561
+ subFields: [],
2471
2562
  fieldPath: f.name,
2472
2563
  };
2473
2564
  for (const pf of table.fields.filter((f) => !f.calculated || f.stored)) {
2474
2565
  const subTwo = {
2475
2566
  name: pf.name,
2476
- subFields: new Array(),
2567
+ subFields: [],
2477
2568
  fieldPath: `${f.name}.${pf.name}`,
2478
2569
  };
2570
+ if (pf.is_fkey && pf.type !== "File" && allow_double) {
2571
+ const table1 = Table.findOne({ name: pf.reftable_name });
2572
+ if (!table1)
2573
+ throw new Error(`Unable to find table '${pf.reftable_name}`);
2574
+ await table1.getFields();
2575
+ subTwo.table = table1.name;
2576
+ if (!table1.fields)
2577
+ throw new Error(`The table '${pf.reftable_name} has no fields.`);
2578
+ if (table1.fields)
2579
+ for (const gpf of table1.fields.filter((f) => !f.calculated || f.stored)) {
2580
+ const subThree = {
2581
+ name: gpf.name,
2582
+ subFields: [],
2583
+ fieldPath: `${f.name}.${pf.name}.${gpf.name}`,
2584
+ };
2585
+ if (allow_triple && gpf.is_fkey && gpf.type !== "File") {
2586
+ const gpfTbl = Table.findOne({
2587
+ name: gpf.reftable_name,
2588
+ });
2589
+ if (gpfTbl) {
2590
+ subThree.table = gpfTbl.name;
2591
+ const gpfFields = await gpfTbl.getFields();
2592
+ for (const ggpf of gpfFields.filter((f) => !f.calculated || f.stored)) {
2593
+ subThree.subFields.push({
2594
+ name: ggpf.name,
2595
+ fieldPath: `${f.name}.${pf.name}.${gpf.name}.${ggpf.name}`,
2596
+ });
2597
+ }
2598
+ }
2599
+ }
2600
+ subTwo.subFields.push(subThree);
2601
+ }
2602
+ }
2479
2603
  subOne.subFields.push(subTwo);
2480
2604
  }
2481
2605
  result.push(subOne);
@@ -2601,7 +2725,7 @@ const run_action_column = async ({ col, req, ...rest }) => {
2601
2725
  };
2602
2726
  const failureAsyncHandler = (err) => {
2603
2727
  const state = getState();
2604
- state.log(2, `Asynchronous action error: ${err.message || err}`);
2728
+ state.log(2, `Asynchronous action error`, err);
2605
2729
  if (req.headers["page-load-tag"]) {
2606
2730
  state.emitDynamicUpdate(db.getTenantSchema(), {
2607
2731
  error: err.message || err,