@budibase/server 2.6.19-alpha.41 → 2.6.19-alpha.42

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
@@ -1710,7 +1710,6 @@ var init_environment2 = __esm({
1710
1710
  REDIS_URL: process.env.REDIS_URL || "localhost:6379",
1711
1711
  REDIS_PASSWORD: process.env.REDIS_PASSWORD,
1712
1712
  REDIS_CLUSTERED: process.env.REDIS_CLUSTERED,
1713
- MOCK_REDIS: process.env.MOCK_REDIS,
1714
1713
  MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
1715
1714
  MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
1716
1715
  AWS_REGION: process.env.AWS_REGION,
@@ -1737,6 +1736,7 @@ var init_environment2 = __esm({
1737
1736
  GLOBAL_BUCKET_NAME: process.env.GLOBAL_BUCKET_NAME || DefaultBucketName.GLOBAL,
1738
1737
  PLUGIN_BUCKET_NAME: process.env.PLUGIN_BUCKET_NAME || DefaultBucketName.PLUGINS,
1739
1738
  USE_COUCH: process.env.USE_COUCH || true,
1739
+ MOCK_REDIS: process.env.MOCK_REDIS,
1740
1740
  DEFAULT_LICENSE: process.env.DEFAULT_LICENSE,
1741
1741
  SERVICE: process.env.SERVICE || "budibase",
1742
1742
  LOG_LEVEL: process.env.LOG_LEVEL || "info",
@@ -2612,7 +2612,7 @@ function getRedisOptions() {
2612
2612
  opts.port = port;
2613
2613
  opts.password = password;
2614
2614
  }
2615
- return { opts, host, port, redisProtocolUrl };
2615
+ return { opts, host, port: parseInt(port), redisProtocolUrl };
2616
2616
  }
2617
2617
  function addDbPrefix(db2, key) {
2618
2618
  if (key.includes(db2)) {
@@ -2733,6 +2733,7 @@ function connectionError(selectDb, timeout2, err) {
2733
2733
  }, RETRY_PERIOD_MS);
2734
2734
  }
2735
2735
  function init2(selectDb = DEFAULT_SELECT_DB) {
2736
+ const RedisCore = environment_default.MOCK_REDIS ? MockRedis : import_ioredis.default;
2736
2737
  let timeout2;
2737
2738
  CLOSED = false;
2738
2739
  let client3 = pickClient(selectDb);
@@ -2740,7 +2741,7 @@ function init2(selectDb = DEFAULT_SELECT_DB) {
2740
2741
  return;
2741
2742
  }
2742
2743
  if (environment_default.MOCK_REDIS) {
2743
- CLIENTS[selectDb] = new Redis(getRedisOptions());
2744
+ CLIENTS[selectDb] = new RedisCore(getRedisOptions());
2744
2745
  }
2745
2746
  timeout2 = setTimeout(() => {
2746
2747
  if (!CONNECTED) {
@@ -2756,11 +2757,11 @@ function init2(selectDb = DEFAULT_SELECT_DB) {
2756
2757
  }
2757
2758
  const { redisProtocolUrl, opts, host, port } = getRedisOptions();
2758
2759
  if (CLUSTERED) {
2759
- client3 = new Redis.Cluster([{ host, port }], opts);
2760
+ client3 = new RedisCore.Cluster([{ host, port }], opts);
2760
2761
  } else if (redisProtocolUrl) {
2761
- client3 = new Redis(redisProtocolUrl);
2762
+ client3 = new RedisCore(redisProtocolUrl);
2762
2763
  } else {
2763
- client3 = new Redis(opts);
2764
+ client3 = new RedisCore(opts);
2764
2765
  }
2765
2766
  client3.on("end", (err) => {
2766
2767
  if (environment_default.isTest()) {
@@ -2824,13 +2825,14 @@ function promisifyStream(stream3, client3) {
2824
2825
  });
2825
2826
  });
2826
2827
  }
2827
- var Redis, RETRY_PERIOD_MS, STARTUP_TIMEOUT_MS, CLUSTERED, DEFAULT_SELECT_DB, CLOSED, CLIENTS, CONNECTED, RedisWrapper, redis_default;
2828
+ var import_ioredis, MockRedis, RETRY_PERIOD_MS, STARTUP_TIMEOUT_MS, CLUSTERED, DEFAULT_SELECT_DB, CLOSED, CLIENTS, CONNECTED, RedisWrapper, redis_default;
2828
2829
  var init_redis = __esm({
2829
2830
  "../backend-core/src/redis/redis.ts"() {
2830
2831
  init_environment2();
2832
+ import_ioredis = __toESM(require("ioredis"));
2831
2833
  init_utils2();
2832
2834
  init_timers2();
2833
- Redis = environment_default.MOCK_REDIS ? require("ioredis-mock") : require("ioredis");
2835
+ MockRedis = require("ioredis-mock");
2834
2836
  RETRY_PERIOD_MS = 2e3;
2835
2837
  STARTUP_TIMEOUT_MS = 5e3;
2836
2838
  CLUSTERED = environment_default.REDIS_CLUSTERED;
@@ -11861,6 +11863,7 @@ var init_src2 = __esm({
11861
11863
  init_cache();
11862
11864
  init_objectStore2();
11863
11865
  init_redis2();
11866
+ init_redis2();
11864
11867
  init_redlockImpl();
11865
11868
  init_utils5();
11866
11869
  init_errors3();
@@ -21814,7 +21817,9 @@ async function init17() {
21814
21817
  await debounceClient.init();
21815
21818
  await flagClient.init();
21816
21819
  socketClient2 = await redis_exports.clients.getSocketClient();
21817
- socketSubClient = socketClient2.getClient().duplicate();
21820
+ if (!environment_default2.isTest()) {
21821
+ socketSubClient = socketClient2.getClient().duplicate();
21822
+ }
21818
21823
  }
21819
21824
  async function shutdown6() {
21820
21825
  console.log("REDIS SHUTDOWN");
@@ -21889,6 +21894,7 @@ var init_redis4 = __esm({
21889
21894
  "src/utilities/redis.ts"() {
21890
21895
  init_src2();
21891
21896
  init_utils9();
21897
+ init_environment3();
21892
21898
  APP_DEV_LOCK_SECONDS = 600;
21893
21899
  AUTOMATION_TEST_FLAG_SECONDS = 60;
21894
21900
  }
@@ -29612,11 +29618,11 @@ var init_firebase = __esm({
29612
29618
  });
29613
29619
 
29614
29620
  // src/integrations/redis.ts
29615
- var import_ioredis, SCHEMA14, RedisIntegration, redis_default2;
29621
+ var import_ioredis2, SCHEMA14, RedisIntegration, redis_default2;
29616
29622
  var init_redis5 = __esm({
29617
29623
  "src/integrations/redis.ts"() {
29618
29624
  init_src();
29619
- import_ioredis = __toESM(require("ioredis"));
29625
+ import_ioredis2 = __toESM(require("ioredis"));
29620
29626
  SCHEMA14 = {
29621
29627
  docs: "https://redis.io/docs/",
29622
29628
  description: "Redis is a caching tool, providing powerful key-value store capabilities.",
@@ -29697,7 +29703,7 @@ var init_redis5 = __esm({
29697
29703
  RedisIntegration = class {
29698
29704
  constructor(config) {
29699
29705
  this.config = config;
29700
- this.client = new import_ioredis.default({
29706
+ this.client = new import_ioredis2.default({
29701
29707
  host: this.config.host,
29702
29708
  port: this.config.port,
29703
29709
  username: this.config.username,
@@ -29761,7 +29767,13 @@ var init_redis5 = __esm({
29761
29767
  }
29762
29768
  const pipeline = this.client.pipeline(pipelineCommands);
29763
29769
  const result = await pipeline.exec();
29764
- return result.map((output) => output[1]);
29770
+ return result == null ? void 0 : result.map((output) => {
29771
+ if (typeof output === "string") {
29772
+ return output;
29773
+ } else if (Array.isArray(output)) {
29774
+ return output[1];
29775
+ }
29776
+ });
29765
29777
  });
29766
29778
  }
29767
29779
  };
@@ -31655,7 +31667,7 @@ var init_builder2 = __esm({
31655
31667
  super(app2, server2, "/socket/builder", [authorized_default(permissions_exports.BUILDER)]);
31656
31668
  }
31657
31669
  async onConnect(socket) {
31658
- socket.on("SelectApp" /* SelectApp */, async (appId, callback) => {
31670
+ socket == null ? void 0 : socket.on("SelectApp" /* SelectApp */, async (appId, callback) => {
31659
31671
  await this.joinRoom(socket, appId);
31660
31672
  const sessions = await this.getRoomSessions(appId);
31661
31673
  callback({ users: sessions });
@@ -31677,12 +31689,14 @@ var init_builder2 = __esm({
31677
31689
  }
31678
31690
  }
31679
31691
  emitTableUpdate(ctx, table2) {
31692
+ var _a2;
31680
31693
  this.io.in(ctx.appId).emit("TableChange" /* TableChange */, { id: table2._id, table: table2 });
31681
- gridSocket.emitTableUpdate(table2);
31694
+ (_a2 = gridSocket) == null ? void 0 : _a2.emitTableUpdate(table2);
31682
31695
  }
31683
31696
  emitTableDeletion(ctx, id) {
31697
+ var _a2;
31684
31698
  this.io.in(ctx.appId).emit("TableChange" /* TableChange */, { id, table: null });
31685
- gridSocket.emitTableDeletion(id);
31699
+ (_a2 = gridSocket) == null ? void 0 : _a2.emitTableDeletion(id);
31686
31700
  }
31687
31701
  emitDatasourceUpdate(ctx, datasource2) {
31688
31702
  this.io.in(ctx.appId).emit("DatasourceChange" /* DatasourceChange */, {
@@ -31704,10 +31718,13 @@ var init_websockets = __esm({
31704
31718
  init_client2();
31705
31719
  init_grid();
31706
31720
  init_builder2();
31721
+ init_environment3();
31707
31722
  initialise = (app2, server2) => {
31708
- clientAppSocket = new ClientAppWebsocket(app2, server2);
31709
- gridSocket = new GridSocket(app2, server2);
31710
- builderSocket = new BuilderSocket(app2, server2);
31723
+ if (!environment_default2.isTest()) {
31724
+ clientAppSocket = new ClientAppWebsocket(app2, server2);
31725
+ gridSocket = new GridSocket(app2, server2);
31726
+ builderSocket = new BuilderSocket(app2, server2);
31727
+ }
31711
31728
  };
31712
31729
  }
31713
31730
  });
@@ -31737,14 +31754,14 @@ async function fetch17(type) {
31737
31754
  }
31738
31755
  }
31739
31756
  async function processUploaded(plugin, source) {
31740
- var _a2;
31757
+ var _a2, _b2;
31741
31758
  const { metadata, directory } = await fileUpload(plugin);
31742
31759
  plugin_exports.validate(metadata == null ? void 0 : metadata.schema);
31743
31760
  if (!environment_default2.SELF_HOSTED && ((_a2 = metadata == null ? void 0 : metadata.schema) == null ? void 0 : _a2.type) !== "component" /* COMPONENT */) {
31744
31761
  throw new Error("Only component plugins are supported outside of self-host");
31745
31762
  }
31746
31763
  const doc = await sdk_exports.plugins.storePlugin(metadata, directory, source);
31747
- clientAppSocket.emit("plugin-update", { name: doc.name, hash: doc.hash });
31764
+ (_b2 = clientAppSocket) == null ? void 0 : _b2.emit("plugin-update", { name: doc.name, hash: doc.hash });
31748
31765
  return doc;
31749
31766
  }
31750
31767
  var init_plugins4 = __esm({
@@ -34436,6 +34453,20 @@ async function getConnector(datasource2) {
34436
34453
  }
34437
34454
  return new Connector(datasource2.config);
34438
34455
  }
34456
+ async function getAndMergeDatasource(datasource2) {
34457
+ let existingDatasource;
34458
+ if (datasource2._id) {
34459
+ existingDatasource = await sdk_default.datasources.get(datasource2._id);
34460
+ }
34461
+ let enrichedDatasource = datasource2;
34462
+ if (existingDatasource) {
34463
+ enrichedDatasource = sdk_default.datasources.mergeConfigs(
34464
+ datasource2,
34465
+ existingDatasource
34466
+ );
34467
+ }
34468
+ return await sdk_default.datasources.enrich(enrichedDatasource);
34469
+ }
34439
34470
  async function buildSchemaHelper(datasource2) {
34440
34471
  const connector = await getConnector(datasource2);
34441
34472
  await connector.buildSchema(datasource2._id, datasource2.entities);
@@ -34496,17 +34527,7 @@ async function fetch22(ctx) {
34496
34527
  }
34497
34528
  async function verify(ctx) {
34498
34529
  const { datasource: datasource2 } = ctx.request.body;
34499
- let existingDatasource;
34500
- if (datasource2._id) {
34501
- existingDatasource = await sdk_default.datasources.get(datasource2._id);
34502
- }
34503
- let enrichedDatasource = datasource2;
34504
- if (existingDatasource) {
34505
- enrichedDatasource = sdk_default.datasources.mergeConfigs(
34506
- datasource2,
34507
- existingDatasource
34508
- );
34509
- }
34530
+ const enrichedDatasource = await getAndMergeDatasource(datasource2);
34510
34531
  const connector = await getConnector(enrichedDatasource);
34511
34532
  if (!connector.testConnection) {
34512
34533
  ctx.throw(400, "Connection information verification not supported");
@@ -34518,9 +34539,9 @@ async function verify(ctx) {
34518
34539
  };
34519
34540
  }
34520
34541
  async function information(ctx) {
34521
- const datasourceId = ctx.params.datasourceId;
34522
- const datasource2 = await sdk_default.datasources.get(datasourceId, { enriched: true });
34523
- const connector = await getConnector(datasource2);
34542
+ const { datasource: datasource2 } = ctx.request.body;
34543
+ const enrichedDatasource = await getAndMergeDatasource(datasource2);
34544
+ const connector = await getConnector(enrichedDatasource);
34524
34545
  if (!connector.getTableNames) {
34525
34546
  ctx.throw(400, "Table name fetching not supported by datasource");
34526
34547
  }
@@ -34594,7 +34615,7 @@ async function invalidateVariables(existingDatasource, updatedDatasource) {
34594
34615
  await invalidateDynamicVariables(toInvalidate);
34595
34616
  }
34596
34617
  async function update7(ctx) {
34597
- var _a2, _b2;
34618
+ var _a2, _b2, _c;
34598
34619
  const db2 = context_exports.getAppDB();
34599
34620
  const datasourceId = ctx.params.datasourceId;
34600
34621
  let datasource2 = await sdk_default.datasources.get(datasourceId);
@@ -34623,9 +34644,10 @@ async function update7(ctx) {
34623
34644
  ctx.body = {
34624
34645
  datasource: await sdk_default.datasources.removeSecretSingle(datasource2)
34625
34646
  };
34626
- builderSocket.emitDatasourceUpdate(ctx, datasource2);
34647
+ (_c = builderSocket) == null ? void 0 : _c.emitDatasourceUpdate(ctx, datasource2);
34627
34648
  }
34628
34649
  async function save13(ctx) {
34650
+ var _a2;
34629
34651
  const db2 = context_exports.getAppDB();
34630
34652
  const plus = ctx.request.body.datasource.plus;
34631
34653
  const fetchSchema = ctx.request.body.fetchSchema;
@@ -34657,7 +34679,7 @@ async function save13(ctx) {
34657
34679
  response2.error = schemaError;
34658
34680
  }
34659
34681
  ctx.body = response2;
34660
- builderSocket.emitDatasourceUpdate(ctx, datasource2);
34682
+ (_a2 = builderSocket) == null ? void 0 : _a2.emitDatasourceUpdate(ctx, datasource2);
34661
34683
  }
34662
34684
  async function destroyInternalTablesBySourceId(datasourceId) {
34663
34685
  const db2 = context_exports.getAppDB();
@@ -34684,6 +34706,7 @@ async function destroyInternalTablesBySourceId(datasourceId) {
34684
34706
  }
34685
34707
  }
34686
34708
  async function destroy12(ctx) {
34709
+ var _a2;
34687
34710
  const db2 = context_exports.getAppDB();
34688
34711
  const datasourceId = ctx.params.datasourceId;
34689
34712
  const datasource2 = await sdk_default.datasources.get(datasourceId);
@@ -34703,7 +34726,7 @@ async function destroy12(ctx) {
34703
34726
  await events_exports.datasource.deleted(datasource2);
34704
34727
  ctx.message = `Datasource deleted.`;
34705
34728
  ctx.status = 200;
34706
- builderSocket.emitDatasourceDeletion(ctx, datasourceId);
34729
+ (_a2 = builderSocket) == null ? void 0 : _a2.emitDatasourceDeletion(ctx, datasourceId);
34707
34730
  }
34708
34731
  async function find8(ctx) {
34709
34732
  const database = context_exports.getAppDB();
@@ -36805,6 +36828,7 @@ async function find10(ctx) {
36805
36828
  ctx.body = await sdk_default.tables.getTable(tableId);
36806
36829
  }
36807
36830
  async function save16(ctx) {
36831
+ var _a2;
36808
36832
  const appId = ctx.appId;
36809
36833
  const table2 = ctx.request.body;
36810
36834
  const isImport = table2.rows;
@@ -36821,9 +36845,10 @@ async function save16(ctx) {
36821
36845
  ctx.message = `Table ${table2.name} saved successfully.`;
36822
36846
  ctx.eventEmitter && ctx.eventEmitter.emitTable(`table:save`, appId, savedTable);
36823
36847
  ctx.body = savedTable;
36824
- builderSocket.emitTableUpdate(ctx, savedTable);
36848
+ (_a2 = builderSocket) == null ? void 0 : _a2.emitTableUpdate(ctx, savedTable);
36825
36849
  }
36826
36850
  async function destroy15(ctx) {
36851
+ var _a2;
36827
36852
  const appId = ctx.appId;
36828
36853
  const tableId = ctx.params.tableId;
36829
36854
  const deletedTable = await pickApi2({ tableId }).destroy(ctx);
@@ -36832,7 +36857,7 @@ async function destroy15(ctx) {
36832
36857
  ctx.status = 200;
36833
36858
  ctx.table = deletedTable;
36834
36859
  ctx.body = { message: `Table ${tableId} deleted.` };
36835
- builderSocket.emitTableDeletion(ctx, tableId);
36860
+ (_a2 = builderSocket) == null ? void 0 : _a2.emitTableDeletion(ctx, tableId);
36836
36861
  }
36837
36862
  async function bulkImport3(ctx) {
36838
36863
  const tableId = ctx.params.tableId;
@@ -37727,10 +37752,17 @@ function getLoopIterations(loopStep) {
37727
37752
  if (!binding) {
37728
37753
  return 0;
37729
37754
  }
37755
+ const isString = typeof binding === "string";
37756
+ try {
37757
+ if (isString) {
37758
+ binding = JSON.parse(binding);
37759
+ }
37760
+ } catch (err) {
37761
+ }
37730
37762
  if (Array.isArray(binding)) {
37731
37763
  return binding.length;
37732
37764
  }
37733
- if (typeof binding === "string") {
37765
+ if (isString) {
37734
37766
  return stringSplit(binding).length;
37735
37767
  }
37736
37768
  return 0;
@@ -39773,6 +39805,7 @@ async function fetch32(ctx) {
39773
39805
  ctx.body = await getViews();
39774
39806
  }
39775
39807
  async function save18(ctx) {
39808
+ var _a2;
39776
39809
  const db2 = context_exports.getAppDB();
39777
39810
  const { originalName, ...viewToSave } = ctx.request.body;
39778
39811
  const existingTable = await db2.get(ctx.request.body.tableId);
@@ -39799,7 +39832,7 @@ async function save18(ctx) {
39799
39832
  await db2.put(table2);
39800
39833
  await handleViewEvents(existingTable.views[viewName], table2.views[viewName]);
39801
39834
  ctx.body = table2.views[viewName];
39802
- builderSocket.emitTableUpdate(ctx, table2);
39835
+ (_a2 = builderSocket) == null ? void 0 : _a2.emitTableUpdate(ctx, table2);
39803
39836
  }
39804
39837
  async function calculationEvents(existingView, newView) {
39805
39838
  const existingCalculation = existingView && existingView.calculation;
@@ -39837,6 +39870,7 @@ async function handleViewEvents(existingView, newView) {
39837
39870
  await filterEvents(existingView, newView);
39838
39871
  }
39839
39872
  async function destroy18(ctx) {
39873
+ var _a2;
39840
39874
  const db2 = context_exports.getAppDB();
39841
39875
  const viewName = decodeURIComponent(ctx.params.viewName);
39842
39876
  const view2 = await deleteView(viewName);
@@ -39845,7 +39879,7 @@ async function destroy18(ctx) {
39845
39879
  await db2.put(table2);
39846
39880
  await events_exports.view.deleted(view2);
39847
39881
  ctx.body = view2;
39848
- builderSocket.emitTableUpdate(ctx, table2);
39882
+ (_a2 = builderSocket) == null ? void 0 : _a2.emitTableUpdate(ctx, table2);
39849
39883
  }
39850
39884
  async function exportView(ctx) {
39851
39885
  const viewName = decodeURIComponent(ctx.query.view);
@@ -41344,8 +41378,8 @@ var init_datasource6 = __esm({
41344
41378
  "/api/datasources/verify",
41345
41379
  authorized_default(permissions_exports.BUILDER),
41346
41380
  verify
41347
- ).get(
41348
- "/api/datasources/:datasourceId/info",
41381
+ ).post(
41382
+ "/api/datasources/info",
41349
41383
  authorized_default(permissions_exports.BUILDER),
41350
41384
  information
41351
41385
  ).get(
@@ -42962,7 +42996,7 @@ async function upload2(ctx) {
42962
42996
  }
42963
42997
  }
42964
42998
  async function create8(ctx) {
42965
- var _a2;
42999
+ var _a2, _b2;
42966
43000
  const { source, url, headers, githubToken } = ctx.request.body;
42967
43001
  try {
42968
43002
  let metadata;
@@ -42993,7 +43027,7 @@ async function create8(ctx) {
42993
43027
  );
42994
43028
  }
42995
43029
  const doc = await sdk_exports.plugins.storePlugin(metadata, directory, source);
42996
- clientAppSocket.emit("plugins-update", { name, hash: doc.hash });
43030
+ (_b2 = clientAppSocket) == null ? void 0 : _b2.emit("plugins-update", { name, hash: doc.hash });
42997
43031
  ctx.body = {
42998
43032
  message: "Plugin uploaded successfully",
42999
43033
  plugins: [doc]