@budibase/shared-core 2.23.5 → 2.23.7

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.
@@ -0,0 +1,6 @@
1
+ import { FieldType } from "@budibase/types";
2
+ type SwitchableTypes = Partial<{
3
+ [K in FieldType]: [K, ...FieldType[]];
4
+ }>;
5
+ export declare const SWITCHABLE_TYPES: SwitchableTypes;
6
+ export {};
@@ -1,4 +1,5 @@
1
1
  export * from "./api";
2
+ export * from "./fields";
2
3
  export declare const OperatorOptions: {
3
4
  Equals: {
4
5
  value: string;
package/dist/filters.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { Datasource, FieldSubtype, FieldType, SearchFilter, SearchQuery, SearchQueryOperators, SortDirection, SortType } from "@budibase/types";
1
+ import { Datasource, FieldSubtype, FieldType, FormulaType, SearchFilter, SearchFilters, SearchFilterOperator, SortDirection, SortType } from "@budibase/types";
2
2
  /**
3
3
  * Returns the valid operator options for a certain data type
4
4
  */
5
5
  export declare const getValidOperatorsForType: (fieldType: {
6
6
  type: FieldType;
7
7
  subtype?: FieldSubtype;
8
+ formulaType?: FormulaType;
8
9
  }, field: string, datasource: Datasource & {
9
10
  tableId: any;
10
11
  }) => {
@@ -14,18 +15,22 @@ export declare const getValidOperatorsForType: (fieldType: {
14
15
  /**
15
16
  * Operators which do not support empty strings as values
16
17
  */
17
- export declare const NoEmptyFilterStrings: SearchQueryOperators[];
18
+ export declare const NoEmptyFilterStrings: SearchFilterOperator[];
19
+ /**
20
+ * Removes a numeric prefix on field names designed to give fields uniqueness
21
+ */
22
+ export declare const removeKeyNumbering: (key: string) => string;
18
23
  /**
19
24
  * Builds a lucene JSON query from the filter structure generated in the builder
20
25
  * @param filter the builder filter structure
21
26
  */
22
- export declare const buildLuceneQuery: (filter: SearchFilter[]) => SearchQuery;
27
+ export declare const buildLuceneQuery: (filter: SearchFilter[]) => SearchFilters;
23
28
  /**
24
29
  * Performs a client-side lucene search on an array of data
25
30
  * @param docs the data
26
31
  * @param query the JSON lucene query
27
32
  */
28
- export declare const runLuceneQuery: (docs: any[], query?: SearchQuery) => any[];
33
+ export declare const runLuceneQuery: (docs: any[], query?: SearchFilters) => any[];
29
34
  /**
30
35
  * Performs a client-side sort from the equivalent server-side lucene sort
31
36
  * parameters.
@@ -42,4 +47,4 @@ export declare const luceneSort: (docs: any[], sort: string, sortOrder: SortDire
42
47
  * @param limit the number of docs to limit to
43
48
  */
44
49
  export declare const luceneLimit: (docs: any[], limit: string) => any[];
45
- export declare const hasFilters: (query?: SearchQuery) => boolean;
50
+ export declare const hasFilters: (query?: SearchFilters) => boolean;
package/dist/index.js CHANGED
@@ -4537,6 +4537,7 @@ __export(src_exports, {
4537
4537
  InvalidFileExtensions: () => InvalidFileExtensions,
4538
4538
  OperatorOptions: () => OperatorOptions,
4539
4539
  REBOOT_CRON: () => REBOOT_CRON,
4540
+ SWITCHABLE_TYPES: () => SWITCHABLE_TYPES,
4540
4541
  SocketEvent: () => SocketEvent,
4541
4542
  SocketSessionTTL: () => SocketSessionTTL,
4542
4543
  SqlNumberTypeRangeMap: () => SqlNumberTypeRangeMap,
@@ -4575,6 +4576,124 @@ var Header = /* @__PURE__ */ ((Header2) => {
4575
4576
  return Header2;
4576
4577
  })(Header || {});
4577
4578
 
4579
+ // ../types/src/sdk/events/event.ts
4580
+ var UserGroupSyncEvents = [
4581
+ "user:created" /* USER_CREATED */,
4582
+ "user:updated" /* USER_UPDATED */,
4583
+ "user:deleted" /* USER_DELETED */,
4584
+ "user:admin:assigned" /* USER_PERMISSION_ADMIN_ASSIGNED */,
4585
+ "user:admin:removed" /* USER_PERMISSION_ADMIN_REMOVED */,
4586
+ "user:builder:assigned" /* USER_PERMISSION_BUILDER_ASSIGNED */,
4587
+ "user:builder:removed" /* USER_PERMISSION_BUILDER_REMOVED */,
4588
+ "user_group:created" /* USER_GROUP_CREATED */,
4589
+ "user_group:updated" /* USER_GROUP_UPDATED */,
4590
+ "user_group:deleted" /* USER_GROUP_DELETED */,
4591
+ "user_group:user_added" /* USER_GROUP_USERS_ADDED */,
4592
+ "user_group:users_deleted" /* USER_GROUP_USERS_REMOVED */,
4593
+ "user_group:permissions_edited" /* USER_GROUP_PERMISSIONS_EDITED */
4594
+ ];
4595
+ var AsyncEvents = [...UserGroupSyncEvents];
4596
+
4597
+ // ../types/src/sdk/cli/constants.ts
4598
+ var AnalyticsEvent = {
4599
+ OptOut: "analytics:opt:out",
4600
+ OptIn: "analytics:opt:in",
4601
+ SelfHostInit: "hosting:init",
4602
+ PluginInit: "plugin:init" /* PLUGIN_INIT */
4603
+ };
4604
+
4605
+ // ../types/src/documents/app/automation.ts
4606
+ var AutomationTriggerStepId = /* @__PURE__ */ ((AutomationTriggerStepId2) => {
4607
+ AutomationTriggerStepId2["ROW_SAVED"] = "ROW_SAVED";
4608
+ AutomationTriggerStepId2["ROW_UPDATED"] = "ROW_UPDATED";
4609
+ AutomationTriggerStepId2["ROW_DELETED"] = "ROW_DELETED";
4610
+ AutomationTriggerStepId2["WEBHOOK"] = "WEBHOOK";
4611
+ AutomationTriggerStepId2["APP"] = "APP";
4612
+ AutomationTriggerStepId2["CRON"] = "CRON";
4613
+ return AutomationTriggerStepId2;
4614
+ })(AutomationTriggerStepId || {});
4615
+ var AutomationActionStepId = /* @__PURE__ */ ((AutomationActionStepId2) => {
4616
+ AutomationActionStepId2["SEND_EMAIL_SMTP"] = "SEND_EMAIL_SMTP";
4617
+ AutomationActionStepId2["CREATE_ROW"] = "CREATE_ROW";
4618
+ AutomationActionStepId2["UPDATE_ROW"] = "UPDATE_ROW";
4619
+ AutomationActionStepId2["DELETE_ROW"] = "DELETE_ROW";
4620
+ AutomationActionStepId2["EXECUTE_BASH"] = "EXECUTE_BASH";
4621
+ AutomationActionStepId2["OUTGOING_WEBHOOK"] = "OUTGOING_WEBHOOK";
4622
+ AutomationActionStepId2["EXECUTE_SCRIPT"] = "EXECUTE_SCRIPT";
4623
+ AutomationActionStepId2["EXECUTE_QUERY"] = "EXECUTE_QUERY";
4624
+ AutomationActionStepId2["SERVER_LOG"] = "SERVER_LOG";
4625
+ AutomationActionStepId2["DELAY"] = "DELAY";
4626
+ AutomationActionStepId2["FILTER"] = "FILTER";
4627
+ AutomationActionStepId2["QUERY_ROWS"] = "QUERY_ROWS";
4628
+ AutomationActionStepId2["LOOP"] = "LOOP";
4629
+ AutomationActionStepId2["COLLECT"] = "COLLECT";
4630
+ AutomationActionStepId2["OPENAI"] = "OPENAI";
4631
+ AutomationActionStepId2["TRIGGER_AUTOMATION_RUN"] = "TRIGGER_AUTOMATION_RUN";
4632
+ AutomationActionStepId2["discord"] = "discord";
4633
+ AutomationActionStepId2["slack"] = "slack";
4634
+ AutomationActionStepId2["zapier"] = "zapier";
4635
+ AutomationActionStepId2["integromat"] = "integromat";
4636
+ AutomationActionStepId2["n8n"] = "n8n";
4637
+ return AutomationActionStepId2;
4638
+ })(AutomationActionStepId || {});
4639
+ var AutomationStepIdArray = [
4640
+ ...Object.values(AutomationActionStepId),
4641
+ ...Object.values(AutomationTriggerStepId)
4642
+ ];
4643
+
4644
+ // ../types/src/documents/document.ts
4645
+ var SEPARATOR = "_";
4646
+ var prefixed = (type) => `${type}${SEPARATOR}`;
4647
+
4648
+ // ../types/src/documents/global/plugin.ts
4649
+ var PluginType = /* @__PURE__ */ ((PluginType2) => {
4650
+ PluginType2["DATASOURCE"] = "datasource";
4651
+ PluginType2["COMPONENT"] = "component";
4652
+ PluginType2["AUTOMATION"] = "automation";
4653
+ return PluginType2;
4654
+ })(PluginType || {});
4655
+ var PLUGIN_TYPE_ARR = Object.values(PluginType);
4656
+
4657
+ // ../types/src/documents/global/quotas.ts
4658
+ var APP_QUOTA_NAMES = [
4659
+ "rows" /* ROWS */,
4660
+ "queries" /* QUERIES */,
4661
+ "automations" /* AUTOMATIONS */
4662
+ ];
4663
+ var BREAKDOWN_QUOTA_NAMES = [
4664
+ "queries" /* QUERIES */,
4665
+ "automations" /* AUTOMATIONS */
4666
+ ];
4667
+
4668
+ // src/constants/fields.ts
4669
+ var SWITCHABLE_TYPES = {
4670
+ ["string" /* STRING */]: [
4671
+ "string" /* STRING */,
4672
+ "options" /* OPTIONS */,
4673
+ "longform" /* LONGFORM */,
4674
+ "barcodeqr" /* BARCODEQR */
4675
+ ],
4676
+ ["options" /* OPTIONS */]: [
4677
+ "options" /* OPTIONS */,
4678
+ "string" /* STRING */,
4679
+ "longform" /* LONGFORM */,
4680
+ "barcodeqr" /* BARCODEQR */
4681
+ ],
4682
+ ["longform" /* LONGFORM */]: [
4683
+ "longform" /* LONGFORM */,
4684
+ "string" /* STRING */,
4685
+ "options" /* OPTIONS */,
4686
+ "barcodeqr" /* BARCODEQR */
4687
+ ],
4688
+ ["barcodeqr" /* BARCODEQR */]: [
4689
+ "barcodeqr" /* BARCODEQR */,
4690
+ "string" /* STRING */,
4691
+ "options" /* OPTIONS */,
4692
+ "longform" /* LONGFORM */
4693
+ ],
4694
+ ["number" /* NUMBER */]: ["number" /* NUMBER */, "boolean" /* BOOLEAN */]
4695
+ };
4696
+
4578
4697
  // src/constants/index.ts
4579
4698
  var OperatorOptions = {
4580
4699
  Equals: {
@@ -4760,99 +4879,9 @@ __export(filters_exports, {
4760
4879
  hasFilters: () => hasFilters,
4761
4880
  luceneLimit: () => luceneLimit,
4762
4881
  luceneSort: () => luceneSort,
4882
+ removeKeyNumbering: () => removeKeyNumbering,
4763
4883
  runLuceneQuery: () => runLuceneQuery
4764
4884
  });
4765
-
4766
- // ../types/src/sdk/events/event.ts
4767
- var UserGroupSyncEvents = [
4768
- "user:created" /* USER_CREATED */,
4769
- "user:updated" /* USER_UPDATED */,
4770
- "user:deleted" /* USER_DELETED */,
4771
- "user:admin:assigned" /* USER_PERMISSION_ADMIN_ASSIGNED */,
4772
- "user:admin:removed" /* USER_PERMISSION_ADMIN_REMOVED */,
4773
- "user:builder:assigned" /* USER_PERMISSION_BUILDER_ASSIGNED */,
4774
- "user:builder:removed" /* USER_PERMISSION_BUILDER_REMOVED */,
4775
- "user_group:created" /* USER_GROUP_CREATED */,
4776
- "user_group:updated" /* USER_GROUP_UPDATED */,
4777
- "user_group:deleted" /* USER_GROUP_DELETED */,
4778
- "user_group:user_added" /* USER_GROUP_USERS_ADDED */,
4779
- "user_group:users_deleted" /* USER_GROUP_USERS_REMOVED */,
4780
- "user_group:permissions_edited" /* USER_GROUP_PERMISSIONS_EDITED */
4781
- ];
4782
- var AsyncEvents = [...UserGroupSyncEvents];
4783
-
4784
- // ../types/src/sdk/cli/constants.ts
4785
- var AnalyticsEvent = {
4786
- OptOut: "analytics:opt:out",
4787
- OptIn: "analytics:opt:in",
4788
- SelfHostInit: "hosting:init",
4789
- PluginInit: "plugin:init" /* PLUGIN_INIT */
4790
- };
4791
-
4792
- // ../types/src/documents/app/automation.ts
4793
- var AutomationTriggerStepId = /* @__PURE__ */ ((AutomationTriggerStepId2) => {
4794
- AutomationTriggerStepId2["ROW_SAVED"] = "ROW_SAVED";
4795
- AutomationTriggerStepId2["ROW_UPDATED"] = "ROW_UPDATED";
4796
- AutomationTriggerStepId2["ROW_DELETED"] = "ROW_DELETED";
4797
- AutomationTriggerStepId2["WEBHOOK"] = "WEBHOOK";
4798
- AutomationTriggerStepId2["APP"] = "APP";
4799
- AutomationTriggerStepId2["CRON"] = "CRON";
4800
- return AutomationTriggerStepId2;
4801
- })(AutomationTriggerStepId || {});
4802
- var AutomationActionStepId = /* @__PURE__ */ ((AutomationActionStepId2) => {
4803
- AutomationActionStepId2["SEND_EMAIL_SMTP"] = "SEND_EMAIL_SMTP";
4804
- AutomationActionStepId2["CREATE_ROW"] = "CREATE_ROW";
4805
- AutomationActionStepId2["UPDATE_ROW"] = "UPDATE_ROW";
4806
- AutomationActionStepId2["DELETE_ROW"] = "DELETE_ROW";
4807
- AutomationActionStepId2["EXECUTE_BASH"] = "EXECUTE_BASH";
4808
- AutomationActionStepId2["OUTGOING_WEBHOOK"] = "OUTGOING_WEBHOOK";
4809
- AutomationActionStepId2["EXECUTE_SCRIPT"] = "EXECUTE_SCRIPT";
4810
- AutomationActionStepId2["EXECUTE_QUERY"] = "EXECUTE_QUERY";
4811
- AutomationActionStepId2["SERVER_LOG"] = "SERVER_LOG";
4812
- AutomationActionStepId2["DELAY"] = "DELAY";
4813
- AutomationActionStepId2["FILTER"] = "FILTER";
4814
- AutomationActionStepId2["QUERY_ROWS"] = "QUERY_ROWS";
4815
- AutomationActionStepId2["LOOP"] = "LOOP";
4816
- AutomationActionStepId2["COLLECT"] = "COLLECT";
4817
- AutomationActionStepId2["OPENAI"] = "OPENAI";
4818
- AutomationActionStepId2["TRIGGER_AUTOMATION_RUN"] = "TRIGGER_AUTOMATION_RUN";
4819
- AutomationActionStepId2["discord"] = "discord";
4820
- AutomationActionStepId2["slack"] = "slack";
4821
- AutomationActionStepId2["zapier"] = "zapier";
4822
- AutomationActionStepId2["integromat"] = "integromat";
4823
- AutomationActionStepId2["n8n"] = "n8n";
4824
- return AutomationActionStepId2;
4825
- })(AutomationActionStepId || {});
4826
- var AutomationStepIdArray = [
4827
- ...Object.values(AutomationActionStepId),
4828
- ...Object.values(AutomationTriggerStepId)
4829
- ];
4830
-
4831
- // ../types/src/documents/document.ts
4832
- var SEPARATOR = "_";
4833
- var prefixed = (type) => `${type}${SEPARATOR}`;
4834
-
4835
- // ../types/src/documents/global/plugin.ts
4836
- var PluginType = /* @__PURE__ */ ((PluginType2) => {
4837
- PluginType2["DATASOURCE"] = "datasource";
4838
- PluginType2["COMPONENT"] = "component";
4839
- PluginType2["AUTOMATION"] = "automation";
4840
- return PluginType2;
4841
- })(PluginType || {});
4842
- var PLUGIN_TYPE_ARR = Object.values(PluginType);
4843
-
4844
- // ../types/src/documents/global/quotas.ts
4845
- var APP_QUOTA_NAMES = [
4846
- "rows" /* ROWS */,
4847
- "queries" /* QUERIES */,
4848
- "automations" /* AUTOMATIONS */
4849
- ];
4850
- var BREAKDOWN_QUOTA_NAMES = [
4851
- "queries" /* QUERIES */,
4852
- "automations" /* AUTOMATIONS */
4853
- ];
4854
-
4855
- // src/filters.ts
4856
4885
  var import_dayjs = __toESM(require_dayjs_min());
4857
4886
 
4858
4887
  // src/helpers/index.ts
@@ -5009,7 +5038,7 @@ var getValidOperatorsForType = (fieldType, field, datasource) => {
5009
5038
  Op.In
5010
5039
  ];
5011
5040
  let ops = [];
5012
- const { type, subtype } = fieldType;
5041
+ const { type, subtype, formulaType } = fieldType;
5013
5042
  if (type === "string" /* STRING */) {
5014
5043
  ops = stringOps;
5015
5044
  } else if (type === "number" /* NUMBER */ || type === "bigint" /* BIGINT */) {
@@ -5024,7 +5053,7 @@ var getValidOperatorsForType = (fieldType, field, datasource) => {
5024
5053
  ops = stringOps;
5025
5054
  } else if (type === "datetime" /* DATETIME */) {
5026
5055
  ops = numOps;
5027
- } else if (type === "formula" /* FORMULA */) {
5056
+ } else if (type === "formula" /* FORMULA */ && formulaType === "static" /* STATIC */) {
5028
5057
  ops = stringOps.concat([Op.MoreThan, Op.LessThan]);
5029
5058
  } else if (type === "bb_reference" /* BB_REFERENCE */ && subtype == "user" /* USER */) {
5030
5059
  ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In];
@@ -5050,12 +5079,13 @@ var cleanupQuery = (query) => {
5050
5079
  return query;
5051
5080
  }
5052
5081
  for (let filterField of NoEmptyFilterStrings) {
5053
- if (!query[filterField]) {
5082
+ const operator = filterField;
5083
+ if (!query[operator]) {
5054
5084
  continue;
5055
5085
  }
5056
- for (let [key, value] of Object.entries(query[filterField])) {
5086
+ for (let [key, value] of Object.entries(query[operator])) {
5057
5087
  if (value == null || value === "") {
5058
- delete query[filterField][key];
5088
+ delete query[operator][key];
5059
5089
  }
5060
5090
  }
5061
5091
  }
@@ -5089,6 +5119,7 @@ var buildLuceneQuery = (filter) => {
5089
5119
  }
5090
5120
  filter.forEach((expression) => {
5091
5121
  let { operator, field, type, value, externalType, onEmptyFilter } = expression;
5122
+ const queryOperator = operator;
5092
5123
  const isHbs = typeof value === "string" && (value.match(HBS_REGEX) || []).length > 0;
5093
5124
  if (operator === "allOr") {
5094
5125
  query.allOr = true;
@@ -5098,7 +5129,7 @@ var buildLuceneQuery = (filter) => {
5098
5129
  query.onEmptyFilter = onEmptyFilter;
5099
5130
  return;
5100
5131
  }
5101
- if (type === "datetime" && !isHbs && operator !== "empty" && operator !== "notEmpty") {
5132
+ if (type === "datetime" && !isHbs && queryOperator !== "empty" && queryOperator !== "notEmpty") {
5102
5133
  if (!value) {
5103
5134
  return;
5104
5135
  }
@@ -5109,7 +5140,7 @@ var buildLuceneQuery = (filter) => {
5109
5140
  }
5110
5141
  }
5111
5142
  if (type === "number" && typeof value === "string" && !isHbs) {
5112
- if (operator === "oneOf") {
5143
+ if (queryOperator === "oneOf") {
5113
5144
  value = value.split(",").map((item) => parseFloat(item));
5114
5145
  } else {
5115
5146
  value = parseFloat(value);
@@ -5135,21 +5166,21 @@ var buildLuceneQuery = (filter) => {
5135
5166
  } else if (operator === "rangeHigh" && value != null && value !== "") {
5136
5167
  query.range[field].high = value;
5137
5168
  }
5138
- } else if (query[operator] && operator !== "onEmptyFilter") {
5169
+ } else if (query[queryOperator] && operator !== "onEmptyFilter") {
5139
5170
  if (type === "boolean") {
5140
- if (operator === "equal" && value === false) {
5171
+ if (queryOperator === "equal" && value === false) {
5141
5172
  query.notEqual = query.notEqual || {};
5142
5173
  query.notEqual[field] = true;
5143
- } else if (operator === "notEqual" && value === false) {
5174
+ } else if (queryOperator === "notEqual" && value === false) {
5144
5175
  query.equal = query.equal || {};
5145
5176
  query.equal[field] = true;
5146
5177
  } else {
5147
- query[operator] = query[operator] || {};
5148
- query[operator][field] = value;
5178
+ query[queryOperator] = query[queryOperator] || {};
5179
+ query[queryOperator][field] = value;
5149
5180
  }
5150
5181
  } else {
5151
- query[operator] = query[operator] || {};
5152
- query[operator][field] = value;
5182
+ query[queryOperator] = query[queryOperator] || {};
5183
+ query[queryOperator][field] = value;
5153
5184
  }
5154
5185
  }
5155
5186
  });
@@ -5579,6 +5610,7 @@ function canBeSortColumn(type) {
5579
5610
  InvalidFileExtensions,
5580
5611
  OperatorOptions,
5581
5612
  REBOOT_CRON,
5613
+ SWITCHABLE_TYPES,
5582
5614
  SocketEvent,
5583
5615
  SocketSessionTTL,
5584
5616
  SqlNumberTypeRangeMap,