@budibase/backend-core 2.26.2 → 2.27.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.
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) {
@@ -57639,6 +57696,11 @@ var Replication = class {
57639
57696
  constructor({ source, target }) {
57640
57697
  this.source = getPouchDB(source);
57641
57698
  this.target = getPouchDB(target);
57699
+ if (source.startsWith("app_dev" /* APP_DEV */) && target.startsWith("app" /* APP */)) {
57700
+ this.direction = "toProduction" /* TO_PRODUCTION */;
57701
+ } else if (source.startsWith("app" /* APP */) && target.startsWith("app_dev" /* APP_DEV */)) {
57702
+ this.direction = "toDev" /* TO_DEV */;
57703
+ }
57642
57704
  }
57643
57705
  async close() {
57644
57706
  await Promise.all([closePouchDB(this.source), closePouchDB(this.target)]);
@@ -57659,11 +57721,16 @@ var Replication = class {
57659
57721
  return opts;
57660
57722
  }
57661
57723
  const filter = opts.filter;
57724
+ const direction = this.direction;
57725
+ const toDev = direction === "toDev" /* TO_DEV */;
57662
57726
  delete opts.filter;
57663
57727
  return {
57664
57728
  ...opts,
57665
57729
  filter: (doc, params2) => {
57666
- if (doc._id && doc._id.startsWith("log_au" /* AUTOMATION_LOG */)) {
57730
+ if (toDev && doc._id?.startsWith("_design")) {
57731
+ return false;
57732
+ }
57733
+ if (doc._id?.startsWith("log_au" /* AUTOMATION_LOG */)) {
57667
57734
  return false;
57668
57735
  }
57669
57736
  if (doc._id === "app_metadata" /* APP_METADATA */) {