@budibase/backend-core 2.26.3 → 2.27.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
@@ -55423,6 +55423,7 @@ var allowDisplayColumnByType = {
55423
55423
  ["array" /* ARRAY */]: false,
55424
55424
  ["attachment" /* ATTACHMENTS */]: false,
55425
55425
  ["attachment_single" /* ATTACHMENT_SINGLE */]: false,
55426
+ ["signature_single" /* SIGNATURE_SINGLE */]: false,
55426
55427
  ["link" /* LINK */]: false,
55427
55428
  ["json" /* JSON */]: false,
55428
55429
  ["bb_reference" /* BB_REFERENCE */]: false,
@@ -55443,6 +55444,7 @@ var allowSortColumnByType = {
55443
55444
  ["formula" /* FORMULA */]: false,
55444
55445
  ["attachment" /* ATTACHMENTS */]: false,
55445
55446
  ["attachment_single" /* ATTACHMENT_SINGLE */]: false,
55447
+ ["signature_single" /* SIGNATURE_SINGLE */]: false,
55446
55448
  ["array" /* ARRAY */]: false,
55447
55449
  ["link" /* LINK */]: false,
55448
55450
  ["bb_reference" /* BB_REFERENCE */]: false,
@@ -55684,6 +55686,7 @@ var environment = {
55684
55686
  API_ENCRYPTION_KEY: getAPIEncryptionKey(),
55685
55687
  COUCH_DB_URL: process.env.COUCH_DB_URL || "http://localhost:4005",
55686
55688
  COUCH_DB_SQL_URL: process.env.COUCH_DB_SQL_URL || "http://localhost:4006",
55689
+ SQS_SEARCH_ENABLE: process.env.SQS_SEARCH_ENABLE,
55687
55690
  COUCH_DB_USERNAME: process.env.COUCH_DB_USER,
55688
55691
  COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD,
55689
55692
  GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
@@ -56052,9 +56055,12 @@ var DDInstrumentedDatabase = class {
56052
56055
  return this.db.getMultiple(ids, opts);
56053
56056
  });
56054
56057
  }
56055
- remove(id, rev) {
56058
+ remove(idOrDoc, rev) {
56056
56059
  return import_dd_trace.default.trace("db.remove", (span) => {
56057
- span?.addTags({ db_name: this.name, doc_id: id });
56060
+ span?.addTags({ db_name: this.name, doc_id: idOrDoc });
56061
+ const isDocument2 = typeof idOrDoc === "object";
56062
+ const id = isDocument2 ? idOrDoc._id : idOrDoc;
56063
+ rev = isDocument2 ? idOrDoc._rev : rev;
56058
56064
  return this.db.remove(id, rev);
56059
56065
  });
56060
56066
  }
@@ -56130,6 +56136,18 @@ var DDInstrumentedDatabase = class {
56130
56136
  return this.db.sql(sql, parameters);
56131
56137
  });
56132
56138
  }
56139
+ sqlPurgeDocument(docIds) {
56140
+ return import_dd_trace.default.trace("db.sqlPurgeDocument", (span) => {
56141
+ span?.addTags({ db_name: this.name });
56142
+ return this.db.sqlPurgeDocument(docIds);
56143
+ });
56144
+ }
56145
+ sqlDiskCleanup() {
56146
+ return import_dd_trace.default.trace("db.sqlDiskCleanup", (span) => {
56147
+ span?.addTags({ db_name: this.name });
56148
+ return this.db.sqlDiskCleanup();
56149
+ });
56150
+ }
56133
56151
  };
56134
56152
 
56135
56153
  // src/db/couch/DatabaseImpl.ts
@@ -56324,22 +56342,51 @@ var DatabaseImpl = class _DatabaseImpl {
56324
56342
  return () => db.list(params2);
56325
56343
  });
56326
56344
  }
56345
+ async _sqlQuery(url, method, body2) {
56346
+ url = checkSlashesInUrl(`${this.couchInfo.sqlUrl}/${url}`);
56347
+ const args = {
56348
+ url,
56349
+ method,
56350
+ cookie: this.couchInfo.cookie
56351
+ };
56352
+ if (body2) {
56353
+ args.body = body2;
56354
+ }
56355
+ return this.performCall(() => {
56356
+ return async () => {
56357
+ const response = await directCouchUrlCall(args);
56358
+ const json = await response.json();
56359
+ if (response.status > 300) {
56360
+ throw json;
56361
+ }
56362
+ return json;
56363
+ };
56364
+ });
56365
+ }
56327
56366
  async sql(sql, parameters) {
56328
56367
  const dbName = this.name;
56329
56368
  const url = `/${dbName}/${SQLITE_DESIGN_DOC_ID}`;
56330
- const response = await directCouchUrlCall({
56331
- url: `${this.couchInfo.sqlUrl}/${url}`,
56332
- method: "POST",
56333
- cookie: this.couchInfo.cookie,
56334
- body: {
56335
- query: sql,
56336
- args: parameters
56337
- }
56369
+ return await this._sqlQuery(url, "POST", {
56370
+ query: sql,
56371
+ args: parameters
56338
56372
  });
56339
- if (response.status > 300) {
56340
- throw new Error(await response.text());
56373
+ }
56374
+ // checks design document is accurate (cleans up tables)
56375
+ // this will check the design document and remove anything from
56376
+ // disk which is not supposed to be there
56377
+ async sqlDiskCleanup() {
56378
+ const dbName = this.name;
56379
+ const url = `/${dbName}/_cleanup`;
56380
+ return await this._sqlQuery(url, "POST");
56381
+ }
56382
+ // removes a document from sqlite
56383
+ async sqlPurgeDocument(docIds) {
56384
+ if (!Array.isArray(docIds)) {
56385
+ docIds = [docIds];
56341
56386
  }
56342
- return await response.json();
56387
+ const dbName = this.name;
56388
+ const url = `/${dbName}/_purge`;
56389
+ return await this._sqlQuery(url, "POST", { docs: docIds });
56343
56390
  }
56344
56391
  async query(viewName, params2) {
56345
56392
  return this.performCall((db) => {
@@ -56349,6 +56396,16 @@ var DatabaseImpl = class _DatabaseImpl {
56349
56396
  }
56350
56397
  async destroy() {
56351
56398
  try {
56399
+ if (environment_default.SQS_SEARCH_ENABLE) {
56400
+ try {
56401
+ const definition = await this.get(
56402
+ SQLITE_DESIGN_DOC_ID
56403
+ );
56404
+ await this.remove(SQLITE_DESIGN_DOC_ID, definition._rev);
56405
+ } finally {
56406
+ await this.sqlDiskCleanup();
56407
+ }
56408
+ }
56352
56409
  return await this.nano().db.destroy(this.name);
56353
56410
  } catch (err) {
56354
56411
  if (err.statusCode === 404) {
@@ -57050,6 +57107,7 @@ __export(db_exports, {
57050
57107
  generatePluginID: () => generatePluginID,
57051
57108
  generateRoleID: () => generateRoleID,
57052
57109
  generateRowID: () => generateRowID,
57110
+ generateTableID: () => generateTableID,
57053
57111
  generateTemplateID: () => generateTemplateID,
57054
57112
  generateUserMetadataID: () => generateUserMetadataID,
57055
57113
  generateWorkspaceID: () => generateWorkspaceID,
@@ -57171,6 +57229,7 @@ __export(docIds_exports, {
57171
57229
  generatePluginID: () => generatePluginID,
57172
57230
  generateRoleID: () => generateRoleID,
57173
57231
  generateRowID: () => generateRowID,
57232
+ generateTableID: () => generateTableID,
57174
57233
  generateTemplateID: () => generateTemplateID,
57175
57234
  generateUserMetadataID: () => generateUserMetadataID,
57176
57235
  generateWorkspaceID: () => generateWorkspaceID,
@@ -57200,6 +57259,9 @@ var generateAppID = (tenantId) => {
57200
57259
  }
57201
57260
  return `${id}${newid()}`;
57202
57261
  };
57262
+ function generateTableID() {
57263
+ return `${"ta" /* TABLE */}${SEPARATOR}${newid()}`;
57264
+ }
57203
57265
  function generateRowID(tableId, id) {
57204
57266
  id = id || newid();
57205
57267
  return `${"ro" /* ROW */}${SEPARATOR}${tableId}${SEPARATOR}${id}`;
@@ -57639,6 +57701,11 @@ var Replication = class {
57639
57701
  constructor({ source, target }) {
57640
57702
  this.source = getPouchDB(source);
57641
57703
  this.target = getPouchDB(target);
57704
+ if (source.startsWith("app_dev" /* APP_DEV */) && target.startsWith("app" /* APP */)) {
57705
+ this.direction = "toProduction" /* TO_PRODUCTION */;
57706
+ } else if (source.startsWith("app" /* APP */) && target.startsWith("app_dev" /* APP_DEV */)) {
57707
+ this.direction = "toDev" /* TO_DEV */;
57708
+ }
57642
57709
  }
57643
57710
  async close() {
57644
57711
  await Promise.all([closePouchDB(this.source), closePouchDB(this.target)]);
@@ -57659,11 +57726,16 @@ var Replication = class {
57659
57726
  return opts;
57660
57727
  }
57661
57728
  const filter = opts.filter;
57729
+ const direction = this.direction;
57730
+ const toDev = direction === "toDev" /* TO_DEV */;
57662
57731
  delete opts.filter;
57663
57732
  return {
57664
57733
  ...opts,
57665
57734
  filter: (doc, params2) => {
57666
- if (doc._id && doc._id.startsWith("log_au" /* AUTOMATION_LOG */)) {
57735
+ if (toDev && doc._id?.startsWith("_design")) {
57736
+ return false;
57737
+ }
57738
+ if (doc._id?.startsWith("log_au" /* AUTOMATION_LOG */)) {
57667
57739
  return false;
57668
57740
  }
57669
57741
  if (doc._id === "app_metadata" /* APP_METADATA */) {