@budibase/backend-core 2.29.1 → 2.29.3

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.
package/dist/index.js CHANGED
@@ -54131,8 +54131,8 @@ var require_lib9 = __commonJS({
54131
54131
  var src_exports = {};
54132
54132
  __export(src_exports, {
54133
54133
  APP_DEV: () => APP_DEV,
54134
- APP_DEV_PREFIX: () => APP_DEV_PREFIX,
54135
- APP_PREFIX: () => APP_PREFIX,
54134
+ APP_DEV_PREFIX: () => APP_DEV_PREFIX2,
54135
+ APP_PREFIX: () => APP_PREFIX2,
54136
54136
  AutomationViewMode: () => AutomationViewMode,
54137
54137
  BUDIBASE_DATASOURCE_TYPE: () => BUDIBASE_DATASOURCE_TYPE,
54138
54138
  BadRequestError: () => BadRequestError,
@@ -54659,8 +54659,8 @@ var BREAKDOWN_QUOTA_NAMES = [
54659
54659
  var constants_exports2 = {};
54660
54660
  __export(constants_exports2, {
54661
54661
  APP_DEV: () => APP_DEV,
54662
- APP_DEV_PREFIX: () => APP_DEV_PREFIX,
54663
- APP_PREFIX: () => APP_PREFIX,
54662
+ APP_DEV_PREFIX: () => APP_DEV_PREFIX2,
54663
+ APP_PREFIX: () => APP_PREFIX2,
54664
54664
  AutomationViewMode: () => AutomationViewMode,
54665
54665
  BUDIBASE_DATASOURCE_TYPE: () => BUDIBASE_DATASOURCE_TYPE,
54666
54666
  Config: () => Config,
@@ -54687,69 +54687,6 @@ __export(constants_exports2, {
54687
54687
  ViewName: () => ViewName
54688
54688
  });
54689
54689
 
54690
- // src/constants/db.ts
54691
- var AutomationViewMode = /* @__PURE__ */ ((AutomationViewMode2) => {
54692
- AutomationViewMode2["ALL"] = "all";
54693
- AutomationViewMode2["AUTOMATION"] = "automation";
54694
- AutomationViewMode2["STATUS"] = "status";
54695
- return AutomationViewMode2;
54696
- })(AutomationViewMode || {});
54697
- var ViewName = /* @__PURE__ */ ((ViewName3) => {
54698
- ViewName3["USER_BY_APP"] = "by_app";
54699
- ViewName3["USER_BY_EMAIL"] = "by_email2";
54700
- ViewName3["BY_API_KEY"] = "by_api_key";
54701
- ViewName3["LINK"] = "by_link";
54702
- ViewName3["ROUTING"] = "screen_routes";
54703
- ViewName3["AUTOMATION_LOGS"] = "automation_logs";
54704
- ViewName3["ACCOUNT_BY_EMAIL"] = "account_by_email";
54705
- ViewName3["PLATFORM_USERS_LOWERCASE"] = "platform_users_lowercase_2";
54706
- ViewName3["USER_BY_GROUP"] = "user_by_group";
54707
- ViewName3["APP_BACKUP_BY_TRIGGER"] = "by_trigger";
54708
- return ViewName3;
54709
- })(ViewName || {});
54710
- var DeprecatedViews = {
54711
- ["by_email2" /* USER_BY_EMAIL */]: [
54712
- // removed due to inaccuracy in view doc filter logic
54713
- "by_email"
54714
- ]
54715
- };
54716
- var StaticDatabases = {
54717
- GLOBAL: {
54718
- name: "global-db",
54719
- docs: {
54720
- apiKeys: "apikeys",
54721
- usageQuota: "usage_quota",
54722
- licenseInfo: "license_info",
54723
- environmentVariables: "environmentvariables"
54724
- }
54725
- },
54726
- // contains information about tenancy and so on
54727
- PLATFORM_INFO: {
54728
- name: "global-info",
54729
- docs: {
54730
- tenants: "tenants",
54731
- install: "install"
54732
- }
54733
- },
54734
- AUDIT_LOGS: {
54735
- name: "audit-logs"
54736
- },
54737
- SCIM_LOGS: {
54738
- name: "scim-logs"
54739
- }
54740
- };
54741
- var APP_PREFIX = prefixed("app" /* APP */);
54742
- var APP_DEV = prefixed("app_dev" /* APP_DEV */);
54743
- var APP_DEV_PREFIX = APP_DEV;
54744
- var SQS_DATASOURCE_INTERNAL = "internal";
54745
- var BUDIBASE_DATASOURCE_TYPE = "budibase";
54746
- var SQLITE_DESIGN_DOC_ID = "_design/sqlite";
54747
- var DEFAULT_JOBS_TABLE_ID = "ta_bb_jobs";
54748
- var DEFAULT_INVENTORY_TABLE_ID = "ta_bb_inventory";
54749
- var DEFAULT_EXPENSES_TABLE_ID = "ta_bb_expenses";
54750
- var DEFAULT_EMPLOYEE_TABLE_ID = "ta_bb_employee";
54751
- var DEFAULT_BB_DATASOURCE_ID = "datasource_internal_bb_default";
54752
-
54753
54690
  // ../shared-core/src/constants/api.ts
54754
54691
  var Header = /* @__PURE__ */ ((Header2) => {
54755
54692
  Header2["API_KEY"] = "x-budibase-api-key";
@@ -54802,20 +54739,6 @@ var SWITCHABLE_TYPES = {
54802
54739
  ["number" /* NUMBER */]: ["number" /* NUMBER */, "boolean" /* BOOLEAN */]
54803
54740
  };
54804
54741
 
54805
- // ../shared-core/src/constants/rows.ts
54806
- var CONSTANT_INTERNAL_ROW_COLS = [
54807
- "_id",
54808
- "_rev",
54809
- "type",
54810
- "createdAt",
54811
- "updatedAt",
54812
- "tableId"
54813
- ];
54814
- var CONSTANT_EXTERNAL_ROW_COLS = ["_id", "_rev", "tableId"];
54815
- function isInternalColumnName(name) {
54816
- return CONSTANT_INTERNAL_ROW_COLS.includes(name);
54817
- }
54818
-
54819
54742
  // ../shared-core/src/constants/index.ts
54820
54743
  var OperatorOptions = {
54821
54744
  Equals: {
@@ -54885,6 +54808,7 @@ var SqlNumberTypeRangeMap = {
54885
54808
  min: -8388608
54886
54809
  }
54887
54810
  };
54811
+ var DEFAULT_BB_DATASOURCE_ID = "datasource_internal_bb_default";
54888
54812
 
54889
54813
  // ../shared-core/src/filters.ts
54890
54814
  var filters_exports = {};
@@ -55564,31 +55488,31 @@ __export(applications_exports, {
55564
55488
  getDevAppID: () => getDevAppID,
55565
55489
  getProdAppID: () => getProdAppID
55566
55490
  });
55567
- var APP_PREFIX2 = prefixed("app" /* APP */);
55568
- var APP_DEV_PREFIX2 = prefixed("app_dev" /* APP_DEV */);
55491
+ var APP_PREFIX = prefixed("app" /* APP */);
55492
+ var APP_DEV_PREFIX = prefixed("app_dev" /* APP_DEV */);
55569
55493
  function getDevAppID(appId) {
55570
55494
  if (!appId) {
55571
55495
  throw new Error("No app ID provided");
55572
55496
  }
55573
- if (appId.startsWith(APP_DEV_PREFIX2)) {
55497
+ if (appId.startsWith(APP_DEV_PREFIX)) {
55574
55498
  return appId;
55575
55499
  }
55576
- const split = appId.split(APP_PREFIX2);
55500
+ const split = appId.split(APP_PREFIX);
55577
55501
  split.shift();
55578
- const rest = split.join(APP_PREFIX2);
55579
- return `${APP_DEV_PREFIX2}${rest}`;
55502
+ const rest = split.join(APP_PREFIX);
55503
+ return `${APP_DEV_PREFIX}${rest}`;
55580
55504
  }
55581
55505
  function getProdAppID(appId) {
55582
55506
  if (!appId) {
55583
55507
  throw new Error("No app ID provided");
55584
55508
  }
55585
- if (!appId.startsWith(APP_DEV_PREFIX2)) {
55509
+ if (!appId.startsWith(APP_DEV_PREFIX)) {
55586
55510
  return appId;
55587
55511
  }
55588
- const split = appId.split(APP_DEV_PREFIX2);
55512
+ const split = appId.split(APP_DEV_PREFIX);
55589
55513
  split.shift();
55590
- const rest = split.join(APP_DEV_PREFIX2);
55591
- return `${APP_PREFIX2}${rest}`;
55514
+ const rest = split.join(APP_DEV_PREFIX);
55515
+ return `${APP_PREFIX}${rest}`;
55592
55516
  }
55593
55517
 
55594
55518
  // ../shared-core/src/sdk/documents/users.ts
@@ -55743,6 +55667,68 @@ var allowSortColumnByType = {
55743
55667
  ["bb_reference_single" /* BB_REFERENCE_SINGLE */]: false
55744
55668
  };
55745
55669
 
55670
+ // src/constants/db.ts
55671
+ var AutomationViewMode = /* @__PURE__ */ ((AutomationViewMode2) => {
55672
+ AutomationViewMode2["ALL"] = "all";
55673
+ AutomationViewMode2["AUTOMATION"] = "automation";
55674
+ AutomationViewMode2["STATUS"] = "status";
55675
+ return AutomationViewMode2;
55676
+ })(AutomationViewMode || {});
55677
+ var ViewName = /* @__PURE__ */ ((ViewName3) => {
55678
+ ViewName3["USER_BY_APP"] = "by_app";
55679
+ ViewName3["USER_BY_EMAIL"] = "by_email2";
55680
+ ViewName3["BY_API_KEY"] = "by_api_key";
55681
+ ViewName3["LINK"] = "by_link";
55682
+ ViewName3["ROUTING"] = "screen_routes";
55683
+ ViewName3["AUTOMATION_LOGS"] = "automation_logs";
55684
+ ViewName3["ACCOUNT_BY_EMAIL"] = "account_by_email";
55685
+ ViewName3["PLATFORM_USERS_LOWERCASE"] = "platform_users_lowercase_2";
55686
+ ViewName3["USER_BY_GROUP"] = "user_by_group";
55687
+ ViewName3["APP_BACKUP_BY_TRIGGER"] = "by_trigger";
55688
+ return ViewName3;
55689
+ })(ViewName || {});
55690
+ var DeprecatedViews = {
55691
+ ["by_email2" /* USER_BY_EMAIL */]: [
55692
+ // removed due to inaccuracy in view doc filter logic
55693
+ "by_email"
55694
+ ]
55695
+ };
55696
+ var StaticDatabases = {
55697
+ GLOBAL: {
55698
+ name: "global-db",
55699
+ docs: {
55700
+ apiKeys: "apikeys",
55701
+ usageQuota: "usage_quota",
55702
+ licenseInfo: "license_info",
55703
+ environmentVariables: "environmentvariables"
55704
+ }
55705
+ },
55706
+ // contains information about tenancy and so on
55707
+ PLATFORM_INFO: {
55708
+ name: "global-info",
55709
+ docs: {
55710
+ tenants: "tenants",
55711
+ install: "install"
55712
+ }
55713
+ },
55714
+ AUDIT_LOGS: {
55715
+ name: "audit-logs"
55716
+ },
55717
+ SCIM_LOGS: {
55718
+ name: "scim-logs"
55719
+ }
55720
+ };
55721
+ var APP_PREFIX2 = prefixed("app" /* APP */);
55722
+ var APP_DEV = prefixed("app_dev" /* APP_DEV */);
55723
+ var APP_DEV_PREFIX2 = APP_DEV;
55724
+ var SQS_DATASOURCE_INTERNAL = "internal";
55725
+ var BUDIBASE_DATASOURCE_TYPE = "budibase";
55726
+ var SQLITE_DESIGN_DOC_ID = "_design/sqlite";
55727
+ var DEFAULT_JOBS_TABLE_ID = "ta_bb_jobs";
55728
+ var DEFAULT_INVENTORY_TABLE_ID = "ta_bb_inventory";
55729
+ var DEFAULT_EXPENSES_TABLE_ID = "ta_bb_expenses";
55730
+ var DEFAULT_EMPLOYEE_TABLE_ID = "ta_bb_employee";
55731
+
55746
55732
  // src/constants/misc.ts
55747
55733
  var UserStatus = /* @__PURE__ */ ((UserStatus3) => {
55748
55734
  UserStatus3["ACTIVE"] = "active";
@@ -56090,13 +56076,13 @@ function isDevAppID(appId) {
56090
56076
  if (!appId) {
56091
56077
  throw NO_APP_ERROR;
56092
56078
  }
56093
- return appId.startsWith(APP_DEV_PREFIX);
56079
+ return appId.startsWith(APP_DEV_PREFIX2);
56094
56080
  }
56095
56081
  function isProdAppID(appId) {
56096
56082
  if (!appId) {
56097
56083
  throw NO_APP_ERROR;
56098
56084
  }
56099
- return appId.startsWith(APP_PREFIX) && !isDevAppID(appId);
56085
+ return appId.startsWith(APP_PREFIX2) && !isDevAppID(appId);
56100
56086
  }
56101
56087
  function isDevApp(app) {
56102
56088
  if (!app) {
@@ -56105,23 +56091,23 @@ function isDevApp(app) {
56105
56091
  return isDevAppID(app.appId);
56106
56092
  }
56107
56093
  function getDevelopmentAppID(appId) {
56108
- if (!appId || appId.startsWith(APP_DEV_PREFIX)) {
56094
+ if (!appId || appId.startsWith(APP_DEV_PREFIX2)) {
56109
56095
  return appId;
56110
56096
  }
56111
- const split = appId.split(APP_PREFIX);
56097
+ const split = appId.split(APP_PREFIX2);
56112
56098
  split.shift();
56113
- const rest = split.join(APP_PREFIX);
56114
- return `${APP_DEV_PREFIX}${rest}`;
56099
+ const rest = split.join(APP_PREFIX2);
56100
+ return `${APP_DEV_PREFIX2}${rest}`;
56115
56101
  }
56116
56102
  var getDevAppID2 = getDevelopmentAppID;
56117
56103
  function getProdAppID2(appId) {
56118
- if (!appId || !appId.startsWith(APP_DEV_PREFIX)) {
56104
+ if (!appId || !appId.startsWith(APP_DEV_PREFIX2)) {
56119
56105
  return appId;
56120
56106
  }
56121
- const split = appId.split(APP_DEV_PREFIX);
56107
+ const split = appId.split(APP_DEV_PREFIX2);
56122
56108
  split.shift();
56123
- const rest = split.join(APP_DEV_PREFIX);
56124
- return `${APP_PREFIX}${rest}`;
56109
+ const rest = split.join(APP_DEV_PREFIX2);
56110
+ return `${APP_PREFIX2}${rest}`;
56125
56111
  }
56126
56112
  function extractAppUUID(id) {
56127
56113
  const split = id?.split("_") || [];
@@ -56747,6 +56733,20 @@ var DatabaseImpl = class _DatabaseImpl {
56747
56733
  }
56748
56734
  };
56749
56735
 
56736
+ // src/db/constants.ts
56737
+ var CONSTANT_INTERNAL_ROW_COLS = [
56738
+ "_id",
56739
+ "_rev",
56740
+ "type",
56741
+ "createdAt",
56742
+ "updatedAt",
56743
+ "tableId"
56744
+ ];
56745
+ var CONSTANT_EXTERNAL_ROW_COLS = ["_id", "_rev", "tableId"];
56746
+ function isInternalColumnName(name) {
56747
+ return CONSTANT_INTERNAL_ROW_COLS.includes(name);
56748
+ }
56749
+
56750
56750
  // src/db/db.ts
56751
56751
  function getDB(dbName, opts) {
56752
56752
  return new DDInstrumentedDatabase(new DatabaseImpl(dbName, opts));
@@ -57353,8 +57353,8 @@ var import_uuid2 = require("uuid");
57353
57353
  var db_exports = {};
57354
57354
  __export(db_exports, {
57355
57355
  APP_DEV: () => APP_DEV,
57356
- APP_DEV_PREFIX: () => APP_DEV_PREFIX,
57357
- APP_PREFIX: () => APP_PREFIX,
57356
+ APP_DEV_PREFIX: () => APP_DEV_PREFIX2,
57357
+ APP_PREFIX: () => APP_PREFIX2,
57358
57358
  AutomationViewMode: () => AutomationViewMode,
57359
57359
  BUDIBASE_DATASOURCE_TYPE: () => BUDIBASE_DATASOURCE_TYPE,
57360
57360
  CONSTANT_EXTERNAL_ROW_COLS: () => CONSTANT_EXTERNAL_ROW_COLS,
@@ -57548,7 +57548,7 @@ __export(docIds_exports, {
57548
57548
 
57549
57549
  // src/docIds/ids.ts
57550
57550
  var generateAppID = (tenantId) => {
57551
- let id = APP_PREFIX;
57551
+ let id = APP_PREFIX2;
57552
57552
  if (tenantId) {
57553
57553
  id += `${tenantId}${SEPARATOR}`;
57554
57554
  }
@@ -58708,7 +58708,7 @@ function sanitizeKey(input) {
58708
58708
  return sanitize(sanitizeBucket(input)).replace(/\\/g, "/");
58709
58709
  }
58710
58710
  function sanitizeBucket(input) {
58711
- return input.replace(new RegExp(APP_DEV_PREFIX, "g"), APP_PREFIX);
58711
+ return input.replace(new RegExp(APP_DEV_PREFIX2, "g"), APP_PREFIX2);
58712
58712
  }
58713
58713
  function ObjectStore(bucket, opts = { presigning: false }) {
58714
58714
  const config = {
@@ -67112,15 +67112,15 @@ function buildExternalTableId(datasourceId, tableName) {
67112
67112
  return `${datasourceId}${DOUBLE_SEPARATOR}${tableName}`;
67113
67113
  }
67114
67114
  function breakExternalTableId(tableId) {
67115
- if (!tableId) {
67116
- return {};
67117
- }
67118
67115
  const parts = tableId.split(DOUBLE_SEPARATOR);
67119
67116
  let datasourceId = parts.shift();
67120
67117
  let tableName = parts.join(DOUBLE_SEPARATOR);
67121
67118
  if (tableName.includes(ENCODED_SPACE)) {
67122
67119
  tableName = decodeURIComponent(tableName);
67123
67120
  }
67121
+ if (!datasourceId || !tableName) {
67122
+ throw new Error("Unable to get datasource/table name from table ID");
67123
+ }
67124
67124
  return { datasourceId, tableName };
67125
67125
  }
67126
67126
  function generateRowIdField(keyProps = []) {
@@ -67296,8 +67296,10 @@ function generateSchema(schema, table, tables, oldTable = null, renamed) {
67296
67296
  }
67297
67297
  const { tableName } = breakExternalTableId(column.tableId);
67298
67298
  const relatedTable = tables[tableName];
67299
- if (!relatedTable) {
67300
- throw new Error("Referenced table doesn't exist");
67299
+ if (!relatedTable || !relatedTable.primary) {
67300
+ throw new Error(
67301
+ "Referenced table doesn't exist or has no primary keys"
67302
+ );
67301
67303
  }
67302
67304
  const relatedPrimary = relatedTable.primary[0];
67303
67305
  const externalType = relatedTable.schema[relatedPrimary].externalType;
@@ -67778,7 +67780,9 @@ var InternalBuilder = class {
67778
67780
  query = query.orderBy(`${aliased}.${key}`, direction, nulls);
67779
67781
  }
67780
67782
  }
67781
- query = query.orderBy(`${aliased}.${primaryKey[0]}`);
67783
+ if (!sort2 || sort2[primaryKey[0]] === void 0) {
67784
+ query = query.orderBy(`${aliased}.${primaryKey[0]}`);
67785
+ }
67782
67786
  return query;
67783
67787
  }
67784
67788
  tableNameWithSchema(tableName, opts) {
@@ -67894,7 +67898,8 @@ var InternalBuilder = class {
67894
67898
  if (!primary) {
67895
67899
  throw new Error("Primary key is required for upsert");
67896
67900
  }
67897
- return query.insert(parsedBody).onConflict(primary).merge();
67901
+ const ret = query.insert(parsedBody).onConflict(primary).merge();
67902
+ return ret;
67898
67903
  } else if (this.client === "mssql" /* MS_SQL */) {
67899
67904
  return query.insert(parsedBody);
67900
67905
  }