@budibase/shared-core 2.32.7 → 2.32.9

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.
@@ -2,3 +2,4 @@ export * from "./helpers";
2
2
  export * from "./integrations";
3
3
  export * as cron from "./cron";
4
4
  export * as schema from "./schema";
5
+ export * as views from "./views";
@@ -6,3 +6,4 @@ export declare function isDeprecatedSingleUserColumn(schema: Pick<FieldSchema, "
6
6
  export declare function isRequired(constraints: FieldConstraints | undefined): boolean;
7
7
  export declare function encodeNonAscii(str: string): string;
8
8
  export declare function decodeNonAscii(str: string): string;
9
+ export declare function isNumeric(field: FieldSchema): boolean;
@@ -0,0 +1,8 @@
1
+ import { BasicViewFieldMetadata, ViewCalculationFieldMetadata, ViewFieldMetadata, ViewV2 } from "@budibase/types";
2
+ export declare function isCalculationField(field: ViewFieldMetadata): field is ViewCalculationFieldMetadata;
3
+ export declare function isBasicViewField(field: ViewFieldMetadata): field is BasicViewFieldMetadata;
4
+ type UnsavedViewV2 = Omit<ViewV2, "id" | "version">;
5
+ export declare function isCalculationView(view: UnsavedViewV2): boolean;
6
+ export declare function calculationFields(view: UnsavedViewV2): import("lodash").Dictionary<ViewCalculationFieldMetadata>;
7
+ export declare function basicFields(view: UnsavedViewV2): import("lodash").Dictionary<ViewFieldMetadata>;
8
+ export {};
package/dist/index.js CHANGED
@@ -4720,12 +4720,12 @@ var require_lodash = __commonJS({
4720
4720
  return result2;
4721
4721
  });
4722
4722
  function omitBy(object, predicate) {
4723
- return pickBy(object, negate(getIteratee(predicate)));
4723
+ return pickBy2(object, negate(getIteratee(predicate)));
4724
4724
  }
4725
4725
  var pick = flatRest(function(object, paths) {
4726
4726
  return object == null ? {} : basePick(object, paths);
4727
4727
  });
4728
- function pickBy(object, predicate) {
4728
+ function pickBy2(object, predicate) {
4729
4729
  if (object == null) {
4730
4730
  return {};
4731
4731
  }
@@ -5401,7 +5401,7 @@ var require_lodash = __commonJS({
5401
5401
  lodash.partialRight = partialRight;
5402
5402
  lodash.partition = partition;
5403
5403
  lodash.pick = pick;
5404
- lodash.pickBy = pickBy;
5404
+ lodash.pickBy = pickBy2;
5405
5405
  lodash.property = property;
5406
5406
  lodash.propertyOf = propertyOf;
5407
5407
  lodash.pull = pull;
@@ -10453,6 +10453,7 @@ __export(helpers_exports, {
10453
10453
  isGoogleSheets: () => isGoogleSheets,
10454
10454
  isSQL: () => isSQL,
10455
10455
  schema: () => schema_exports,
10456
+ views: () => views_exports,
10456
10457
  withTimeout: () => withTimeout
10457
10458
  });
10458
10459
 
@@ -10603,6 +10604,7 @@ __export(schema_exports, {
10603
10604
  decodeNonAscii: () => decodeNonAscii,
10604
10605
  encodeNonAscii: () => encodeNonAscii,
10605
10606
  isDeprecatedSingleUserColumn: () => isDeprecatedSingleUserColumn,
10607
+ isNumeric: () => isNumeric,
10606
10608
  isRequired: () => isRequired
10607
10609
  });
10608
10610
  function isDeprecatedSingleUserColumn(schema) {
@@ -10624,9 +10626,38 @@ function decodeNonAscii(str) {
10624
10626
  (match, p1) => String.fromCharCode(parseInt(p1, 16))
10625
10627
  );
10626
10628
  }
10629
+ function isNumeric(field) {
10630
+ return field.type === "number" /* NUMBER */ || field.type === "bigint" /* BIGINT */;
10631
+ }
10627
10632
 
10628
- // src/filters.ts
10633
+ // src/helpers/views.ts
10634
+ var views_exports = {};
10635
+ __export(views_exports, {
10636
+ basicFields: () => basicFields,
10637
+ calculationFields: () => calculationFields,
10638
+ isBasicViewField: () => isBasicViewField,
10639
+ isCalculationField: () => isCalculationField,
10640
+ isCalculationView: () => isCalculationView
10641
+ });
10629
10642
  var import_lodash = __toESM(require_lodash());
10643
+ function isCalculationField(field) {
10644
+ return "calculationType" in field;
10645
+ }
10646
+ function isBasicViewField(field) {
10647
+ return !isCalculationField(field);
10648
+ }
10649
+ function isCalculationView(view) {
10650
+ return Object.values(view.schema || {}).some(isCalculationField);
10651
+ }
10652
+ function calculationFields(view) {
10653
+ return (0, import_lodash.pickBy)(view.schema || {}, isCalculationField);
10654
+ }
10655
+ function basicFields(view) {
10656
+ return (0, import_lodash.pickBy)(view.schema || {}, (field) => !isCalculationField(field));
10657
+ }
10658
+
10659
+ // src/filters.ts
10660
+ var import_lodash2 = __toESM(require_lodash());
10630
10661
  var HBS_REGEX = /{{([^{].*?)}}/g;
10631
10662
  var LOGICAL_OPERATORS = Object.values(LogicalOperator);
10632
10663
  var SEARCH_OPERATORS = [
@@ -10695,7 +10726,7 @@ var NoEmptyFilterStrings = [
10695
10726
  ];
10696
10727
  function recurseLogicalOperators(filters, fn) {
10697
10728
  for (const logical of LOGICAL_OPERATORS) {
10698
- if (filters[logical]) {
10729
+ if (filters?.[logical]) {
10699
10730
  filters[logical].conditions = filters[logical].conditions.map(
10700
10731
  (condition) => fn(condition)
10701
10732
  );
@@ -10904,7 +10935,7 @@ var buildQuery = (filter) => {
10904
10935
  function fixupFilterArrays(filters) {
10905
10936
  for (const searchField of Object.values(ArrayOperator)) {
10906
10937
  const field = filters[searchField];
10907
- if (field == null || !(0, import_lodash.isPlainObject)(field)) {
10938
+ if (field == null || !(0, import_lodash2.isPlainObject)(field)) {
10908
10939
  continue;
10909
10940
  }
10910
10941
  for (const key of Object.keys(field)) {
@@ -10991,10 +11022,10 @@ function runQuery(docs, query) {
10991
11022
  if (docValue == null || docValue === "") {
10992
11023
  return false;
10993
11024
  }
10994
- if ((0, import_lodash.isPlainObject)(testValue.low) && (0, import_lodash.isEmpty)(testValue.low)) {
11025
+ if ((0, import_lodash2.isPlainObject)(testValue.low) && (0, import_lodash2.isEmpty)(testValue.low)) {
10995
11026
  testValue.low = void 0;
10996
11027
  }
10997
- if ((0, import_lodash.isPlainObject)(testValue.high) && (0, import_lodash.isEmpty)(testValue.high)) {
11028
+ if ((0, import_lodash2.isPlainObject)(testValue.high) && (0, import_lodash2.isEmpty)(testValue.high)) {
10998
11029
  testValue.high = void 0;
10999
11030
  }
11000
11031
  if (testValue.low == null && testValue.high == null) {
@@ -11246,6 +11277,7 @@ var utils_exports = {};
11246
11277
  __export(utils_exports, {
11247
11278
  filterValueToLabel: () => filterValueToLabel,
11248
11279
  hasSchema: () => hasSchema,
11280
+ isSupportedUserSearch: () => isSupportedUserSearch,
11249
11281
  parallelForeach: () => parallelForeach,
11250
11282
  trimOtherProps: () => trimOtherProps,
11251
11283
  unreachable: () => unreachable
@@ -11301,6 +11333,29 @@ function trimOtherProps(object, allowedProps) {
11301
11333
  );
11302
11334
  return result;
11303
11335
  }
11336
+ function isSupportedUserSearch(query) {
11337
+ const allowed = [
11338
+ { op: "string" /* STRING */, key: "email" },
11339
+ { op: "equal" /* EQUAL */, key: "_id" },
11340
+ { op: "oneOf" /* ONE_OF */, key: "_id" }
11341
+ ];
11342
+ for (let [key, operation] of Object.entries(query)) {
11343
+ if (typeof operation !== "object") {
11344
+ return false;
11345
+ }
11346
+ const fields = Object.keys(operation || {});
11347
+ if (fields.length === 0) {
11348
+ continue;
11349
+ }
11350
+ const allowedOperation = allowed.find(
11351
+ (allow) => allow.op === key && fields.length === 1 && fields[0] === allow.key
11352
+ );
11353
+ if (!allowedOperation) {
11354
+ return false;
11355
+ }
11356
+ }
11357
+ return true;
11358
+ }
11304
11359
 
11305
11360
  // src/sdk/index.ts
11306
11361
  var sdk_exports = {};