@saltcorn/data 0.9.4-beta.8 → 0.9.4

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 (137) hide show
  1. package/dist/base-plugin/actions.d.ts +137 -71
  2. package/dist/base-plugin/actions.d.ts.map +1 -1
  3. package/dist/base-plugin/actions.js +105 -22
  4. package/dist/base-plugin/actions.js.map +1 -1
  5. package/dist/base-plugin/fieldviews.d.ts.map +1 -1
  6. package/dist/base-plugin/fieldviews.js +19 -9
  7. package/dist/base-plugin/fieldviews.js.map +1 -1
  8. package/dist/base-plugin/fileviews.d.ts +13 -0
  9. package/dist/base-plugin/fileviews.js +42 -2
  10. package/dist/base-plugin/fileviews.js.map +1 -1
  11. package/dist/base-plugin/index.d.ts +208 -204
  12. package/dist/base-plugin/index.d.ts.map +1 -1
  13. package/dist/base-plugin/types.d.ts.map +1 -1
  14. package/dist/base-plugin/types.js +25 -10
  15. package/dist/base-plugin/types.js.map +1 -1
  16. package/dist/base-plugin/viewtemplates/edit.d.ts +4 -1
  17. package/dist/base-plugin/viewtemplates/edit.d.ts.map +1 -1
  18. package/dist/base-plugin/viewtemplates/edit.js +181 -81
  19. package/dist/base-plugin/viewtemplates/edit.js.map +1 -1
  20. package/dist/base-plugin/viewtemplates/feed.d.ts.map +1 -1
  21. package/dist/base-plugin/viewtemplates/feed.js +4 -1
  22. package/dist/base-plugin/viewtemplates/feed.js.map +1 -1
  23. package/dist/base-plugin/viewtemplates/filter.d.ts.map +1 -1
  24. package/dist/base-plugin/viewtemplates/filter.js +89 -7
  25. package/dist/base-plugin/viewtemplates/filter.js.map +1 -1
  26. package/dist/base-plugin/viewtemplates/list.d.ts +3 -2
  27. package/dist/base-plugin/viewtemplates/list.d.ts.map +1 -1
  28. package/dist/base-plugin/viewtemplates/list.js +274 -38
  29. package/dist/base-plugin/viewtemplates/list.js.map +1 -1
  30. package/dist/base-plugin/viewtemplates/show.d.ts.map +1 -1
  31. package/dist/base-plugin/viewtemplates/show.js +116 -56
  32. package/dist/base-plugin/viewtemplates/show.js.map +1 -1
  33. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts +4 -3
  34. package/dist/base-plugin/viewtemplates/viewable_fields.d.ts.map +1 -1
  35. package/dist/base-plugin/viewtemplates/viewable_fields.js +173 -57
  36. package/dist/base-plugin/viewtemplates/viewable_fields.js.map +1 -1
  37. package/dist/db/connect.d.ts.map +1 -1
  38. package/dist/db/connect.js +20 -0
  39. package/dist/db/connect.js.map +1 -1
  40. package/dist/db/fixtures.d.ts.map +1 -1
  41. package/dist/db/fixtures.js +196 -30
  42. package/dist/db/fixtures.js.map +1 -1
  43. package/dist/db/state.d.ts +5 -0
  44. package/dist/db/state.d.ts.map +1 -1
  45. package/dist/db/state.js +20 -0
  46. package/dist/db/state.js.map +1 -1
  47. package/dist/migrate.d.ts +1 -0
  48. package/dist/migrate.d.ts.map +1 -1
  49. package/dist/migrate.js +6 -3
  50. package/dist/migrate.js.map +1 -1
  51. package/dist/migrations/202402071125.d.ts +2 -0
  52. package/dist/migrations/202402071125.d.ts.map +1 -0
  53. package/dist/migrations/202402071125.js +4 -0
  54. package/dist/migrations/202402071125.js.map +1 -0
  55. package/dist/models/config.d.ts.map +1 -1
  56. package/dist/models/config.js +27 -0
  57. package/dist/models/config.js.map +1 -1
  58. package/dist/models/email.d.ts.map +1 -1
  59. package/dist/models/email.js +6 -2
  60. package/dist/models/email.js.map +1 -1
  61. package/dist/models/field.d.ts +1 -1
  62. package/dist/models/field.d.ts.map +1 -1
  63. package/dist/models/field.js +4 -4
  64. package/dist/models/field.js.map +1 -1
  65. package/dist/models/file.d.ts +2 -0
  66. package/dist/models/file.d.ts.map +1 -1
  67. package/dist/models/file.js +9 -0
  68. package/dist/models/file.js.map +1 -1
  69. package/dist/models/index.d.ts +1 -1
  70. package/dist/models/internal/query.d.ts +6 -0
  71. package/dist/models/internal/query.d.ts.map +1 -0
  72. package/dist/models/internal/query.js +86 -0
  73. package/dist/models/internal/query.js.map +1 -0
  74. package/dist/models/page.d.ts.map +1 -1
  75. package/dist/models/page.js +4 -0
  76. package/dist/models/page.js.map +1 -1
  77. package/dist/models/page_group.d.ts +1 -0
  78. package/dist/models/page_group.d.ts.map +1 -1
  79. package/dist/models/page_group.js +1 -0
  80. package/dist/models/page_group.js.map +1 -1
  81. package/dist/models/table.d.ts +18 -4
  82. package/dist/models/table.d.ts.map +1 -1
  83. package/dist/models/table.js +84 -52
  84. package/dist/models/table.js.map +1 -1
  85. package/dist/models/tag_entry.d.ts.map +1 -1
  86. package/dist/models/tag_entry.js +9 -0
  87. package/dist/models/tag_entry.js.map +1 -1
  88. package/dist/models/trigger.d.ts +3 -3
  89. package/dist/models/trigger.d.ts.map +1 -1
  90. package/dist/models/trigger.js +69 -7
  91. package/dist/models/trigger.js.map +1 -1
  92. package/dist/models/user.d.ts.map +1 -1
  93. package/dist/models/user.js +5 -4
  94. package/dist/models/user.js.map +1 -1
  95. package/dist/models/view.d.ts +1 -0
  96. package/dist/models/view.d.ts.map +1 -1
  97. package/dist/models/view.js +6 -0
  98. package/dist/models/view.js.map +1 -1
  99. package/dist/plugin-helper.d.ts +7 -19
  100. package/dist/plugin-helper.d.ts.map +1 -1
  101. package/dist/plugin-helper.js +79 -70
  102. package/dist/plugin-helper.js.map +1 -1
  103. package/dist/tests/actions.test.js +143 -2
  104. package/dist/tests/actions.test.js.map +1 -1
  105. package/dist/tests/auth.test.js +101 -1
  106. package/dist/tests/auth.test.js.map +1 -1
  107. package/dist/tests/auxtest.test.js +4 -0
  108. package/dist/tests/auxtest.test.js.map +1 -1
  109. package/dist/tests/calc.test.js +20 -0
  110. package/dist/tests/calc.test.js.map +1 -1
  111. package/dist/tests/edit.test.js +558 -0
  112. package/dist/tests/edit.test.js.map +1 -1
  113. package/dist/tests/filter.test.d.ts +2 -0
  114. package/dist/tests/filter.test.d.ts.map +1 -0
  115. package/dist/tests/filter.test.js +438 -0
  116. package/dist/tests/filter.test.js.map +1 -0
  117. package/dist/tests/list.test.d.ts +2 -0
  118. package/dist/tests/list.test.d.ts.map +1 -0
  119. package/dist/tests/list.test.js +903 -0
  120. package/dist/tests/list.test.js.map +1 -0
  121. package/dist/tests/show.test.d.ts +2 -0
  122. package/dist/tests/show.test.d.ts.map +1 -0
  123. package/dist/tests/show.test.js +325 -0
  124. package/dist/tests/show.test.js.map +1 -0
  125. package/dist/tests/table.test.js +213 -56
  126. package/dist/tests/table.test.js.map +1 -1
  127. package/dist/tests/table_history.test.js +51 -0
  128. package/dist/tests/table_history.test.js.map +1 -1
  129. package/dist/tests/tag.test.js +1 -1
  130. package/dist/tests/tag.test.js.map +1 -1
  131. package/dist/tests/view.test.js +16 -2
  132. package/dist/tests/view.test.js.map +1 -1
  133. package/dist/utils.d.ts +2 -17
  134. package/dist/utils.d.ts.map +1 -1
  135. package/dist/utils.js +19 -32
  136. package/dist/utils.js.map +1 -1
  137. package/package.json +8 -7
@@ -248,6 +248,24 @@ jest.setTimeout(30000);
248
248
  (0, globals_1.expect)(michaels.length).toStrictEqual(2);
249
249
  (0, globals_1.expect)(Math.round(michaels[0].avg_temp)).toBe(38);
250
250
  });
251
+ (0, globals_1.it)("should get joined rows with filtered aggregations", async () => {
252
+ const patients = table_1.default.findOne({ name: "patients" });
253
+ (0, assertions_1.assertIsSet)(patients);
254
+ const michaels = await patients.getJoinedRows({
255
+ orderBy: "id",
256
+ aggregations: {
257
+ avg_temp: {
258
+ table: "readings",
259
+ ref: "patient_id",
260
+ field: "temperature",
261
+ aggregate: "avg",
262
+ where: { normalised: true },
263
+ },
264
+ },
265
+ });
266
+ (0, globals_1.expect)(michaels.length).toStrictEqual(2);
267
+ (0, globals_1.expect)(Math.round(michaels[0].avg_temp)).toBe(37);
268
+ });
251
269
  (0, globals_1.it)("should get joined rows with unique count aggregations", async () => {
252
270
  const patients = table_1.default.findOne({ name: "patients" });
253
271
  (0, assertions_1.assertIsSet)(patients);
@@ -424,6 +442,24 @@ jest.setTimeout(30000);
424
442
  (0, globals_1.expect)(Math.round(michaels[0].avg_temp)).toBe(38);
425
443
  (0, globals_1.expect)(michaels[1].author).toBe("Leo Tolstoy");
426
444
  });
445
+ (0, globals_1.it)("should get percent true aggregations", async () => {
446
+ const patients = table_1.default.findOne({ name: "patients" });
447
+ (0, assertions_1.assertIsSet)(patients);
448
+ const michaels = await patients.getJoinedRows({
449
+ orderBy: "id",
450
+ aggregations: {
451
+ pcnt_norm: {
452
+ table: "readings",
453
+ ref: "patient_id",
454
+ field: "normalised",
455
+ aggregate: "Percent true",
456
+ },
457
+ },
458
+ });
459
+ (0, globals_1.expect)(michaels.length).toStrictEqual(2);
460
+ (0, globals_1.expect)(Math.round(michaels[0].pcnt_norm)).toBe(50);
461
+ (0, globals_1.expect)(Math.round(michaels[1].pcnt_norm)).toBe(0);
462
+ });
427
463
  (0, globals_1.it)("should support full text search", async () => {
428
464
  const table = table_1.default.findOne({ name: "patients" });
429
465
  (0, assertions_1.assertIsSet)(table);
@@ -544,6 +580,150 @@ jest.setTimeout(30000);
544
580
  (0, globals_1.expect)(reads[0].pages).toBe(967);
545
581
  });
546
582
  });
583
+ (0, globals_1.describe)("Table aggregationQuery", () => {
584
+ (0, globals_1.it)("should get avg aggregations", async () => {
585
+ const readings = table_1.default.findOne({ name: "readings" });
586
+ (0, assertions_1.assertIsSet)(readings);
587
+ const aggs = await readings.aggregationQuery({
588
+ avg_temp: {
589
+ field: "temperature",
590
+ aggregate: "avg",
591
+ },
592
+ });
593
+ (0, globals_1.expect)(Math.round(aggs.avg_temp)).toBe(38);
594
+ });
595
+ (0, globals_1.it)("should get filtered avg aggregations", async () => {
596
+ const readings = table_1.default.findOne({ name: "readings" });
597
+ (0, assertions_1.assertIsSet)(readings);
598
+ const aggs = await readings.aggregationQuery({
599
+ avg_temp: {
600
+ field: "temperature",
601
+ aggregate: "avg",
602
+ },
603
+ }, { where: { normalised: true } });
604
+ (0, globals_1.expect)(Math.round(aggs.avg_temp)).toBe(37);
605
+ });
606
+ (0, globals_1.it)("should get percent true aggregations", async () => {
607
+ const readings = table_1.default.findOne({ name: "readings" });
608
+ (0, assertions_1.assertIsSet)(readings);
609
+ const aggs = await readings.aggregationQuery({
610
+ pcnt_norm: {
611
+ field: "normalised",
612
+ aggregate: "Percent true",
613
+ },
614
+ });
615
+ (0, globals_1.expect)(Math.round(aggs.pcnt_norm)).toBe(33);
616
+ });
617
+ (0, globals_1.it)("should get array aggregations", async () => {
618
+ const readings = table_1.default.findOne({ name: "readings" });
619
+ (0, assertions_1.assertIsSet)(readings);
620
+ if (!db_1.default.isSQLite) {
621
+ const aggs = await readings.aggregationQuery({
622
+ ids: {
623
+ field: "id",
624
+ aggregate: "array_agg",
625
+ },
626
+ });
627
+ (0, globals_1.expect)(aggs.ids).toStrictEqual([1, 2, 3]);
628
+ }
629
+ });
630
+ (0, globals_1.it)("should get filtered array aggregations", async () => {
631
+ const readings = table_1.default.findOne({ name: "readings" });
632
+ (0, assertions_1.assertIsSet)(readings);
633
+ if (!db_1.default.isSQLite) {
634
+ const aggs = await readings.aggregationQuery({
635
+ ids: {
636
+ field: "id",
637
+ aggregate: "array_agg",
638
+ },
639
+ }, { where: { normalised: true } });
640
+ (0, globals_1.expect)(aggs.ids).toStrictEqual([1]);
641
+ }
642
+ });
643
+ (0, globals_1.it)("should get grouped aggregations", async () => {
644
+ const readings = table_1.default.findOne({ name: "readings" });
645
+ (0, assertions_1.assertIsSet)(readings);
646
+ if (!db_1.default.isSQLite) {
647
+ const aggs = await readings.aggregationQuery({
648
+ temps: {
649
+ field: "id",
650
+ aggregate: "count",
651
+ },
652
+ }, { groupBy: ["patient_id"] });
653
+ (0, globals_1.expect)(aggs).toStrictEqual([
654
+ { patient_id: 2, temps: "1" },
655
+ { patient_id: 1, temps: "2" },
656
+ ]);
657
+ }
658
+ });
659
+ (0, globals_1.it)("sets up new fields", async () => {
660
+ const table = table_1.default.findOne({ name: "books" });
661
+ (0, assertions_1.assertIsSet)(table);
662
+ await field_1.default.create({
663
+ table,
664
+ name: "published",
665
+ label: "Published",
666
+ type: "Date",
667
+ });
668
+ await table.updateRow({ published: new Date("1971-05.04") }, 1);
669
+ await table.updateRow({ published: new Date("1972-05.04") }, 2);
670
+ });
671
+ (0, globals_1.it)("should get latest by field", async () => {
672
+ const books = table_1.default.findOne({ name: "books" });
673
+ (0, assertions_1.assertIsSet)(books);
674
+ if (!db_1.default.isSQLite) {
675
+ const aggs = await books.aggregationQuery({
676
+ pages: {
677
+ field: "pages",
678
+ aggregate: "Latest published",
679
+ },
680
+ });
681
+ (0, globals_1.expect)(aggs).toStrictEqual({ pages: 728 });
682
+ }
683
+ });
684
+ (0, globals_1.it)("should get latest by field, qualified", async () => {
685
+ const books = table_1.default.findOne({ name: "books" });
686
+ (0, assertions_1.assertIsSet)(books);
687
+ if (!db_1.default.isSQLite) {
688
+ const aggs = await books.aggregationQuery({
689
+ pages: {
690
+ field: "pages",
691
+ aggregate: "Latest published",
692
+ },
693
+ }, { where: { author: "Herman Melville" } });
694
+ (0, globals_1.expect)(aggs).toStrictEqual({ pages: 967 });
695
+ }
696
+ });
697
+ (0, globals_1.it)("should get latest by field, grouped", async () => {
698
+ const books = table_1.default.findOne({ name: "books" });
699
+ (0, assertions_1.assertIsSet)(books);
700
+ if (!db_1.default.isSQLite) {
701
+ const aggs = await books.aggregationQuery({
702
+ pages: {
703
+ field: "pages",
704
+ aggregate: "Latest published",
705
+ },
706
+ }, { groupBy: "author" });
707
+ (0, globals_1.expect)(aggs).toStrictEqual([
708
+ { author: "Leo Tolstoy", pages: 728 },
709
+ { author: "Herman Melville", pages: 967 },
710
+ ]);
711
+ }
712
+ });
713
+ (0, globals_1.it)("should get latest by field, grouped and qualified", async () => {
714
+ const books = table_1.default.findOne({ name: "books" });
715
+ (0, assertions_1.assertIsSet)(books);
716
+ if (!db_1.default.isSQLite) {
717
+ const aggs = await books.aggregationQuery({
718
+ pages: {
719
+ field: "pages",
720
+ aggregate: "Latest published",
721
+ },
722
+ }, { groupBy: "author", where: { author: "Herman Melville" } });
723
+ (0, globals_1.expect)(aggs).toStrictEqual([{ author: "Herman Melville", pages: 967 }]);
724
+ }
725
+ });
726
+ });
547
727
  (0, globals_1.describe)("relations", () => {
548
728
  (0, globals_1.it)("get parent relations", async () => {
549
729
  const table = table_1.default.findOne({ name: "patients" });
@@ -597,54 +777,20 @@ jest.setTimeout(30000);
597
777
  const table = table_1.default.findOne({ name: "readings" });
598
778
  (0, assertions_1.assertIsSet)(table);
599
779
  const rels = await table.get_parent_relations(true);
600
- const expected = [
601
- "patient_id.favbook",
602
- "patient_id.favbook.author",
603
- "patient_id.favbook.id",
604
- "patient_id.favbook.pages",
605
- "patient_id.favbook.publisher",
606
- "patient_id.id",
607
- "patient_id.name",
608
- "patient_id.parent",
609
- "patient_id.parent.favbook",
610
- "patient_id.parent.id",
611
- "patient_id.parent.name",
612
- "patient_id.parent.parent",
613
- ];
614
- (0, globals_1.expect)(rels.parent_field_list).toHaveLength(expected.length);
615
- (0, globals_1.expect)(rels.parent_field_list).toEqual(globals_1.expect.arrayContaining(expected));
780
+ (0, globals_1.expect)(rels.parent_field_list.length).toBeGreaterThan(10);
781
+ (0, globals_1.expect)(rels.parent_field_list).toContain("patient_id.favbook.publisher");
782
+ (0, globals_1.expect)(rels.parent_field_list).toContain("patient_id.name");
616
783
  (0, globals_1.expect)(rels.parent_relations.length).toBe(3);
617
784
  });
618
785
  (0, globals_1.it)("get triple relations", async () => {
619
786
  const table = table_1.default.findOne({ name: "readings" });
620
787
  (0, assertions_1.assertIsSet)(table);
621
788
  const rels = await table.get_parent_relations(true, true);
622
- const expected = [
623
- "patient_id.favbook",
624
- "patient_id.favbook.author",
625
- "patient_id.favbook.id",
626
- "patient_id.favbook.pages",
627
- "patient_id.favbook.publisher",
628
- "patient_id.favbook.publisher.id",
629
- "patient_id.favbook.publisher.name",
630
- "patient_id.id",
631
- "patient_id.name",
632
- "patient_id.parent",
633
- "patient_id.parent.favbook",
634
- "patient_id.parent.favbook.author",
635
- "patient_id.parent.favbook.id",
636
- "patient_id.parent.favbook.pages",
637
- "patient_id.parent.favbook.publisher",
638
- "patient_id.parent.id",
639
- "patient_id.parent.name",
640
- "patient_id.parent.parent",
641
- "patient_id.parent.parent.favbook",
642
- "patient_id.parent.parent.id",
643
- "patient_id.parent.parent.name",
644
- "patient_id.parent.parent.parent",
645
- ];
646
- (0, globals_1.expect)(rels.parent_field_list).toHaveLength(expected.length);
647
- (0, globals_1.expect)(rels.parent_field_list).toEqual(globals_1.expect.arrayContaining(expected));
789
+ (0, globals_1.expect)(rels.parent_field_list.length).toBeGreaterThan(10);
790
+ (0, globals_1.expect)(rels.parent_field_list).toContain("patient_id.parent.favbook.author");
791
+ (0, globals_1.expect)(rels.parent_field_list).toContain("patient_id.favbook.publisher.name");
792
+ (0, globals_1.expect)(rels.parent_field_list).toContain("patient_id.favbook.author");
793
+ (0, globals_1.expect)(rels.parent_field_list).toContain("patient_id.name");
648
794
  (0, globals_1.expect)(rels.parent_relations.length).toBe(3);
649
795
  });
650
796
  });
@@ -706,6 +852,29 @@ Peter Rossi, 212,9,200`;
706
852
  (0, globals_1.expect)(row?.pages).toBe(540);
707
853
  await table.updateRow({ author: "Herman Melville" }, 1);
708
854
  });
855
+ (0, globals_1.it)("should replace when id given in preview", async () => {
856
+ const csv = `id,author,Pages
857
+ 1, Noam Chomsky, 540
858
+ 18, Cornel West, 678`;
859
+ const fnm = "/tmp/testreplaceid.csv";
860
+ await (0, promises_1.writeFile)(fnm, csv);
861
+ const table = table_1.default.findOne({ name: "books" });
862
+ (0, assertions_1.assertIsSet)(table);
863
+ (0, globals_1.expect)(!!table).toBe(true);
864
+ const impres = await table.import_csv_file(fnm, { no_table_write: true });
865
+ (0, assertions_1.assertsIsSuccessMessage)(impres);
866
+ const rows = impres.rows;
867
+ (0, assertions_1.assertIsSet)(rows);
868
+ (0, globals_1.expect)(rows.length).toBe(2);
869
+ const row = rows.find((r) => r.id == 1);
870
+ (0, globals_1.expect)(row?.pages).toBe(540);
871
+ (0, globals_1.expect)(row.author).toBe("Noam Chomsky");
872
+ const row1 = rows.find((r) => r.id == 18);
873
+ (0, globals_1.expect)(row1?.pages).toBe(678);
874
+ const rowDB = await table.getRow({ id: 1 });
875
+ (0, assertions_1.assertIsSet)(rowDB);
876
+ (0, globals_1.expect)(rowDB.author).toBe("Herman Melville");
877
+ });
709
878
  (0, globals_1.it)("fail on required field", async () => {
710
879
  const csv = `author,Pagez
711
880
  Joe Celko, 856
@@ -1648,20 +1817,8 @@ Pencil, 0.5,2, t`;
1648
1817
  (0, globals_1.it)("should find one-level join fields", async () => {
1649
1818
  const table = table_1.default.findOne({ name: "patients" });
1650
1819
  const opts = await table?.field_options(1);
1651
- (0, globals_1.expect)(opts).toStrictEqual([
1652
- "favbook",
1653
- "id",
1654
- "name",
1655
- "parent",
1656
- "favbook.author",
1657
- "favbook.id",
1658
- "favbook.pages",
1659
- "favbook.publisher",
1660
- "parent.favbook",
1661
- "parent.id",
1662
- "parent.name",
1663
- "parent.parent",
1664
- ]);
1820
+ (0, globals_1.expect)(opts).toContain("parent.name");
1821
+ (0, globals_1.expect)(opts).toContain("favbook.pages");
1665
1822
  });
1666
1823
  (0, globals_1.it)("should find string fields", async () => {
1667
1824
  const table = table_1.default.findOne({ name: "patients" });