@budibase/shared-core 2.29.0 → 2.29.2

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.
@@ -1,5 +1,6 @@
1
1
  export * from "./api";
2
2
  export * from "./fields";
3
+ export * from "./rows";
3
4
  export declare const OperatorOptions: {
4
5
  Equals: {
5
6
  value: string;
@@ -111,3 +112,4 @@ export declare enum BpmStatusValue {
111
112
  VERIFYING_EMAIL = "verifying_email",
112
113
  COMPLETED = "completed"
113
114
  }
115
+ export declare const DEFAULT_BB_DATASOURCE_ID = "datasource_internal_bb_default";
@@ -0,0 +1,3 @@
1
+ export declare const CONSTANT_INTERNAL_ROW_COLS: readonly ["_id", "_rev", "type", "createdAt", "updatedAt", "tableId"];
2
+ export declare const CONSTANT_EXTERNAL_ROW_COLS: readonly ["_id", "_rev", "tableId"];
3
+ export declare function isInternalColumnName(name: string): boolean;
package/dist/filters.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Datasource, BBReferenceFieldSubType, FieldType, FormulaType, SearchFilter, SearchFilters, SearchFilterOperator, SortType, FieldConstraints, SortOrder, RowSearchParams } from "@budibase/types";
1
+ import { Datasource, BBReferenceFieldSubType, FieldType, FormulaType, SearchFilter, SearchFilters, SearchFilterOperator, SortType, FieldConstraints, SortOrder, RowSearchParams, SearchResponse } from "@budibase/types";
2
2
  /**
3
3
  * Returns the valid operator options for a certain data type
4
4
  */
@@ -26,7 +26,7 @@ export declare const removeKeyNumbering: (key: string) => string;
26
26
  * @param filter the builder filter structure
27
27
  */
28
28
  export declare const buildQuery: (filter: SearchFilter[]) => SearchFilters;
29
- export declare const search: (docs: Record<string, any>[], query: RowSearchParams) => Record<string, any>[];
29
+ export declare const search: (docs: Record<string, any>[], query: RowSearchParams) => SearchResponse<Record<string, any>>;
30
30
  /**
31
31
  * Performs a client-side search on an array of data
32
32
  * @param docs the data
package/dist/index.js CHANGED
@@ -1044,10 +1044,10 @@ var require_lodash = __commonJS({
1044
1044
  }();
1045
1045
  var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow = Date2 && Date2.now !== root.Date.now && Date2.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
1046
1046
  var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : undefined2, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow = Date2.now, nativeParseInt = context.parseInt, nativeRandom = Math2.random, nativeReverse = arrayProto.reverse;
1047
- var DataView = getNative(context, "DataView"), Map = getNative(context, "Map"), Promise2 = getNative(context, "Promise"), Set = getNative(context, "Set"), WeakMap = getNative(context, "WeakMap"), nativeCreate = getNative(Object2, "create");
1047
+ var DataView = getNative(context, "DataView"), Map = getNative(context, "Map"), Promise2 = getNative(context, "Promise"), Set2 = getNative(context, "Set"), WeakMap = getNative(context, "WeakMap"), nativeCreate = getNative(Object2, "create");
1048
1048
  var metaMap = WeakMap && new WeakMap();
1049
1049
  var realNames = {};
1050
- var dataViewCtorString = toSource(DataView), mapCtorString = toSource(Map), promiseCtorString = toSource(Promise2), setCtorString = toSource(Set), weakMapCtorString = toSource(WeakMap);
1050
+ var dataViewCtorString = toSource(DataView), mapCtorString = toSource(Map), promiseCtorString = toSource(Promise2), setCtorString = toSource(Set2), weakMapCtorString = toSource(WeakMap);
1051
1051
  var symbolProto = Symbol2 ? Symbol2.prototype : undefined2, symbolValueOf = symbolProto ? symbolProto.valueOf : undefined2, symbolToString = symbolProto ? symbolProto.toString : undefined2;
1052
1052
  function lodash(value) {
1053
1053
  if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
@@ -2801,8 +2801,8 @@ var require_lodash = __commonJS({
2801
2801
  return func(number);
2802
2802
  };
2803
2803
  }
2804
- var createSet = !(Set && 1 / setToArray(new Set([, -0]))[1] == INFINITY) ? noop : function(values3) {
2805
- return new Set(values3);
2804
+ var createSet = !(Set2 && 1 / setToArray(new Set2([, -0]))[1] == INFINITY) ? noop : function(values3) {
2805
+ return new Set2(values3);
2806
2806
  };
2807
2807
  function createToPairs(keysFunc) {
2808
2808
  return function(object) {
@@ -3101,7 +3101,7 @@ var require_lodash = __commonJS({
3101
3101
  return result2;
3102
3102
  };
3103
3103
  var getTag = baseGetTag;
3104
- if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map && getTag(new Map()) != mapTag || Promise2 && getTag(Promise2.resolve()) != promiseTag || Set && getTag(new Set()) != setTag || WeakMap && getTag(new WeakMap()) != weakMapTag) {
3104
+ if (DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map && getTag(new Map()) != mapTag || Promise2 && getTag(Promise2.resolve()) != promiseTag || Set2 && getTag(new Set2()) != setTag || WeakMap && getTag(new WeakMap()) != weakMapTag) {
3105
3105
  getTag = function(value) {
3106
3106
  var result2 = baseGetTag(value), Ctor = result2 == objectTag ? value.constructor : undefined2, ctorString = Ctor ? toSource(Ctor) : "";
3107
3107
  if (ctorString) {
@@ -10013,6 +10013,9 @@ __export(src_exports, {
10013
10013
  BpmStatusKey: () => BpmStatusKey,
10014
10014
  BpmStatusValue: () => BpmStatusValue,
10015
10015
  BuilderSocketEvent: () => BuilderSocketEvent,
10016
+ CONSTANT_EXTERNAL_ROW_COLS: () => CONSTANT_EXTERNAL_ROW_COLS,
10017
+ CONSTANT_INTERNAL_ROW_COLS: () => CONSTANT_INTERNAL_ROW_COLS,
10018
+ DEFAULT_BB_DATASOURCE_ID: () => DEFAULT_BB_DATASOURCE_ID,
10016
10019
  GridSocketEvent: () => GridSocketEvent,
10017
10020
  Header: () => Header,
10018
10021
  InvalidFileExtensions: () => InvalidFileExtensions,
@@ -10028,7 +10031,9 @@ __export(src_exports, {
10028
10031
  canBeDisplayColumn: () => canBeDisplayColumn,
10029
10032
  canBeSortColumn: () => canBeSortColumn,
10030
10033
  dataFilters: () => filters_exports,
10034
+ findDuplicateInternalColumns: () => findDuplicateInternalColumns,
10031
10035
  helpers: () => helpers_exports,
10036
+ isInternalColumnName: () => isInternalColumnName,
10032
10037
  sdk: () => sdk_exports,
10033
10038
  utils: () => utils_exports
10034
10039
  });
@@ -10175,6 +10180,20 @@ var SWITCHABLE_TYPES = {
10175
10180
  ["number" /* NUMBER */]: ["number" /* NUMBER */, "boolean" /* BOOLEAN */]
10176
10181
  };
10177
10182
 
10183
+ // src/constants/rows.ts
10184
+ var CONSTANT_INTERNAL_ROW_COLS = [
10185
+ "_id",
10186
+ "_rev",
10187
+ "type",
10188
+ "createdAt",
10189
+ "updatedAt",
10190
+ "tableId"
10191
+ ];
10192
+ var CONSTANT_EXTERNAL_ROW_COLS = ["_id", "_rev", "tableId"];
10193
+ function isInternalColumnName(name) {
10194
+ return CONSTANT_INTERNAL_ROW_COLS.includes(name);
10195
+ }
10196
+
10178
10197
  // src/constants/index.ts
10179
10198
  var OperatorOptions = {
10180
10199
  Equals: {
@@ -10350,6 +10369,7 @@ var BpmStatusValue = /* @__PURE__ */ ((BpmStatusValue2) => {
10350
10369
  BpmStatusValue2["COMPLETED"] = "completed";
10351
10370
  return BpmStatusValue2;
10352
10371
  })(BpmStatusValue || {});
10372
+ var DEFAULT_BB_DATASOURCE_ID = "datasource_internal_bb_default";
10353
10373
 
10354
10374
  // src/filters.ts
10355
10375
  var filters_exports = {};
@@ -10696,10 +10716,15 @@ var search = (docs, query) => {
10696
10716
  if (query.sort) {
10697
10717
  result = sort(result, query.sort, query.sortOrder || "ascending" /* ASCENDING */);
10698
10718
  }
10719
+ let totalRows = result.length;
10699
10720
  if (query.limit) {
10700
10721
  result = limit(result, query.limit.toString());
10701
10722
  }
10702
- return result;
10723
+ const response = { rows: result };
10724
+ if (query.countRows) {
10725
+ response.totalRows = totalRows;
10726
+ }
10727
+ return response;
10703
10728
  };
10704
10729
  var runQuery = (docs, query) => {
10705
10730
  if (!docs || !Array.isArray(docs)) {
@@ -11208,6 +11233,20 @@ function canBeDisplayColumn(type) {
11208
11233
  function canBeSortColumn(type) {
11209
11234
  return !!allowSortColumnByType[type];
11210
11235
  }
11236
+ function findDuplicateInternalColumns(table) {
11237
+ const columnNames = Object.keys(table.schema).concat(CONSTANT_INTERNAL_ROW_COLS).map((colName) => colName.toLowerCase());
11238
+ const set = new Set(columnNames);
11239
+ let duplicates = [];
11240
+ if (set.size !== columnNames.length) {
11241
+ for (let key of set.keys()) {
11242
+ const count = columnNames.filter((name) => name === key).length;
11243
+ if (count > 1) {
11244
+ duplicates.push(key);
11245
+ }
11246
+ }
11247
+ }
11248
+ return duplicates;
11249
+ }
11211
11250
  // Annotate the CommonJS export names for ESM import in node:
11212
11251
  0 && (module.exports = {
11213
11252
  BpmCorrelationKey,
@@ -11215,6 +11254,9 @@ function canBeSortColumn(type) {
11215
11254
  BpmStatusKey,
11216
11255
  BpmStatusValue,
11217
11256
  BuilderSocketEvent,
11257
+ CONSTANT_EXTERNAL_ROW_COLS,
11258
+ CONSTANT_INTERNAL_ROW_COLS,
11259
+ DEFAULT_BB_DATASOURCE_ID,
11218
11260
  GridSocketEvent,
11219
11261
  Header,
11220
11262
  InvalidFileExtensions,
@@ -11230,7 +11272,9 @@ function canBeSortColumn(type) {
11230
11272
  canBeDisplayColumn,
11231
11273
  canBeSortColumn,
11232
11274
  dataFilters,
11275
+ findDuplicateInternalColumns,
11233
11276
  helpers,
11277
+ isInternalColumnName,
11234
11278
  sdk,
11235
11279
  utils
11236
11280
  });