@budibase/backend-core 2.21.3 → 2.21.4

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
@@ -57055,21 +57055,16 @@ async function queryGlobalViewRaw(viewName, params2, opts) {
57055
57055
 
57056
57056
  // src/db/Replication.ts
57057
57057
  var Replication = class {
57058
- /**
57059
- *
57060
- * @param source - the DB you want to replicate or rollback to
57061
- * @param target - the DB you want to replicate to, or rollback from
57062
- */
57063
57058
  constructor({ source, target }) {
57064
57059
  this.source = getPouchDB(source);
57065
57060
  this.target = getPouchDB(target);
57066
57061
  }
57067
- close() {
57068
- return Promise.all([closePouchDB(this.source), closePouchDB(this.target)]);
57062
+ async close() {
57063
+ await Promise.all([closePouchDB(this.source), closePouchDB(this.target)]);
57069
57064
  }
57070
- promisify(operation, opts = {}) {
57065
+ replicate(opts = {}) {
57071
57066
  return new Promise((resolve) => {
57072
- operation(this.target, opts).on("denied", function(err) {
57067
+ this.source.replicate.to(this.target, opts).on("denied", function(err) {
57073
57068
  throw new Error(`Denied: Document failed to replicate ${err}`);
57074
57069
  }).on("complete", function(info) {
57075
57070
  return resolve(info);
@@ -57078,29 +57073,22 @@ var Replication = class {
57078
57073
  });
57079
57074
  });
57080
57075
  }
57081
- /**
57082
- * Two way replication operation, intended to be promise based.
57083
- * @param opts - PouchDB replication options
57084
- */
57085
- sync(opts = {}) {
57086
- this.replication = this.promisify(this.source.sync, opts);
57087
- return this.replication;
57088
- }
57089
- /**
57090
- * One way replication operation, intended to be promise based.
57091
- * @param opts - PouchDB replication options
57092
- */
57093
- replicate(opts = {}) {
57094
- this.replication = this.promisify(this.source.replicate.to, opts);
57095
- return this.replication;
57096
- }
57097
- appReplicateOpts() {
57076
+ appReplicateOpts(opts = {}) {
57077
+ if (typeof opts.filter === "string") {
57078
+ return opts;
57079
+ }
57080
+ const filter = opts.filter;
57081
+ delete opts.filter;
57098
57082
  return {
57099
- filter: (doc) => {
57083
+ ...opts,
57084
+ filter: (doc, params2) => {
57100
57085
  if (doc._id && doc._id.startsWith("log_au" /* AUTOMATION_LOG */)) {
57101
57086
  return false;
57102
57087
  }
57103
- return doc._id !== "app_metadata" /* APP_METADATA */;
57088
+ if (doc._id === "app_metadata" /* APP_METADATA */) {
57089
+ return false;
57090
+ }
57091
+ return filter ? filter(doc, params2) : true;
57104
57092
  }
57105
57093
  };
57106
57094
  }
@@ -57112,9 +57100,6 @@ var Replication = class {
57112
57100
  this.target = getPouchDB(this.target.name);
57113
57101
  await this.replicate();
57114
57102
  }
57115
- cancel() {
57116
- this.replication.cancel();
57117
- }
57118
57103
  };
57119
57104
  var Replication_default = Replication;
57120
57105
 
@@ -58676,7 +58661,10 @@ var RedisWrapper = class {
58676
58661
  let node = this.getClient().nodes("master");
58677
58662
  stream2 = node[0].scanStream({ match: key + "*", count: 100 });
58678
58663
  } else {
58679
- stream2 = this.getClient().scanStream({ match: key + "*", count: 100 });
58664
+ stream2 = this.getClient().scanStream({
58665
+ match: key + "*",
58666
+ count: 100
58667
+ });
58680
58668
  }
58681
58669
  return promisifyStream(stream2, this.getClient());
58682
58670
  }
@@ -58690,7 +58678,7 @@ var RedisWrapper = class {
58690
58678
  }
58691
58679
  async get(key) {
58692
58680
  const db = this._db;
58693
- let response = await this.getClient().get(addDbPrefix(db, key));
58681
+ const response = await this.getClient().get(addDbPrefix(db, key));
58694
58682
  if (response != null && response.key) {
58695
58683
  response.key = key;
58696
58684
  }
@@ -58738,6 +58726,21 @@ var RedisWrapper = class {
58738
58726
  await this.getClient().expire(prefixedKey, expirySeconds);
58739
58727
  }
58740
58728
  }
58729
+ async bulkStore(data, expirySeconds = null) {
58730
+ const client = this.getClient();
58731
+ const dataToStore = Object.entries(data).reduce((acc, [key, value]) => {
58732
+ acc[addDbPrefix(this._db, key)] = typeof value === "object" ? JSON.stringify(value) : value;
58733
+ return acc;
58734
+ }, {});
58735
+ const pipeline = client.pipeline();
58736
+ pipeline.mset(dataToStore);
58737
+ if (expirySeconds !== null) {
58738
+ for (const key of Object.keys(dataToStore)) {
58739
+ pipeline.expire(key, expirySeconds);
58740
+ }
58741
+ }
58742
+ await pipeline.exec();
58743
+ }
58741
58744
  async getTTL(key) {
58742
58745
  const db = this._db;
58743
58746
  const prefixedKey = addDbPrefix(db, key);
@@ -58756,6 +58759,22 @@ var RedisWrapper = class {
58756
58759
  let items = await this.scan();
58757
58760
  await Promise.all(items.map((obj) => this.delete(obj.key)));
58758
58761
  }
58762
+ async increment(key) {
58763
+ const result = await this.getClient().incr(addDbPrefix(this._db, key));
58764
+ if (isNaN(result)) {
58765
+ throw new Error(`Redis ${key} does not contain a number`);
58766
+ }
58767
+ return result;
58768
+ }
58769
+ async deleteIfValue(key, value) {
58770
+ const client = this.getClient();
58771
+ const luaScript = `
58772
+ if redis.call('GET', KEYS[1]) == ARGV[1] then
58773
+ redis.call('DEL', KEYS[1])
58774
+ end
58775
+ `;
58776
+ await client.eval(luaScript, 1, addDbPrefix(this._db, key), value);
58777
+ }
58759
58778
  };
58760
58779
  var redis_default = RedisWrapper;
58761
58780
 
@@ -60243,9 +60262,6 @@ function getBuiltinRole(roleId) {
60243
60262
  return (0, import_cloneDeep2.default)(role);
60244
60263
  }
60245
60264
  function builtinRoleToNumber(id) {
60246
- if (!id) {
60247
- return 0;
60248
- }
60249
60265
  const builtins = getBuiltinRoles();
60250
60266
  const MAX = Object.values(builtins).length + 1;
60251
60267
  if (id === BUILTIN_IDS.ADMIN || id === BUILTIN_IDS.BUILDER) {