@budibase/shared-core 2.19.1 → 2.19.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.
@@ -92,4 +92,5 @@ export declare enum BuilderSocketEvent {
92
92
  export declare const SocketSessionTTL = 60;
93
93
  export declare const ValidQueryNameRegex: RegExp;
94
94
  export declare const ValidColumnNameRegex: RegExp;
95
+ export declare const REBOOT_CRON = "@reboot";
95
96
  export declare const InvalidFileExtensions: string[];
@@ -0,0 +1,6 @@
1
+ export declare function validate(cronExpression: string): {
2
+ valid: false;
3
+ err: string[];
4
+ } | {
5
+ valid: true;
6
+ };
@@ -1,2 +1,3 @@
1
1
  export * from "./helpers";
2
2
  export * from "./integrations";
3
+ export * as cron from "./cron";
package/dist/index.js CHANGED
@@ -4532,6 +4532,7 @@ __export(src_exports, {
4532
4532
  Header: () => Header,
4533
4533
  InvalidFileExtensions: () => InvalidFileExtensions,
4534
4534
  OperatorOptions: () => OperatorOptions,
4535
+ REBOOT_CRON: () => REBOOT_CRON,
4535
4536
  SocketEvent: () => SocketEvent,
4536
4537
  SocketSessionTTL: () => SocketSessionTTL,
4537
4538
  SqlNumberTypeRangeMap: () => SqlNumberTypeRangeMap,
@@ -4665,6 +4666,7 @@ var BuilderSocketEvent = /* @__PURE__ */ ((BuilderSocketEvent2) => {
4665
4666
  var SocketSessionTTL = 60;
4666
4667
  var ValidQueryNameRegex = /^[^()]*$/;
4667
4668
  var ValidColumnNameRegex = /^[_a-zA-Z0-9\s]*$/g;
4669
+ var REBOOT_CRON = "@reboot";
4668
4670
  var InvalidFileExtensions = [
4669
4671
  "7z",
4670
4672
  "action",
@@ -4829,6 +4831,7 @@ var import_dayjs = __toESM(require_dayjs_min());
4829
4831
  // src/helpers/index.ts
4830
4832
  var helpers_exports = {};
4831
4833
  __export(helpers_exports, {
4834
+ cron: () => cron_exports,
4832
4835
  deepGet: () => deepGet,
4833
4836
  getUserColor: () => getUserColor,
4834
4837
  getUserInitials: () => getUserInitials,
@@ -4909,6 +4912,53 @@ function isSQL(datasource) {
4909
4912
  return SQL.indexOf(datasource.source) !== -1 || datasource.isSQL === true;
4910
4913
  }
4911
4914
 
4915
+ // src/helpers/cron.ts
4916
+ var cron_exports = {};
4917
+ __export(cron_exports, {
4918
+ validate: () => validate
4919
+ });
4920
+ var import_cron_validate = __toESM(require("cron-validate"));
4921
+ var INPUT_CRON_START = "(Input cron: ";
4922
+ var ERROR_SWAPS = {
4923
+ "smaller than lower limit": "less than",
4924
+ "bigger than upper limit": "greater than",
4925
+ daysOfMonth: "'days of the month'",
4926
+ daysOfWeek: "'days of the week'",
4927
+ years: "'years'",
4928
+ months: "'months'",
4929
+ hours: "'hours'",
4930
+ minutes: "'minutes'",
4931
+ seconds: "'seconds'"
4932
+ };
4933
+ function improveErrors(errors) {
4934
+ const finalErrors = [];
4935
+ for (let error of errors) {
4936
+ if (error.includes(INPUT_CRON_START)) {
4937
+ error = error.split(INPUT_CRON_START)[0].trim();
4938
+ }
4939
+ for (let [oldErr, newErr] of Object.entries(ERROR_SWAPS)) {
4940
+ if (error.includes(oldErr)) {
4941
+ error = error.replace(new RegExp(oldErr, "g"), newErr);
4942
+ }
4943
+ }
4944
+ finalErrors.push(error);
4945
+ }
4946
+ return finalErrors;
4947
+ }
4948
+ function validate(cronExpression) {
4949
+ const result = (0, import_cron_validate.default)(cronExpression, {
4950
+ preset: "npm-node-cron",
4951
+ override: {
4952
+ useSeconds: false
4953
+ }
4954
+ });
4955
+ if (!result.isValid()) {
4956
+ return { valid: false, err: improveErrors(result.getError()) };
4957
+ } else {
4958
+ return { valid: true };
4959
+ }
4960
+ }
4961
+
4912
4962
  // src/filters.ts
4913
4963
  var HBS_REGEX = /{{([^{].*?)}}/g;
4914
4964
  var getValidOperatorsForType = (fieldType, field, datasource) => {
@@ -5468,6 +5518,7 @@ function canBeSortColumn(type) {
5468
5518
  Header,
5469
5519
  InvalidFileExtensions,
5470
5520
  OperatorOptions,
5521
+ REBOOT_CRON,
5471
5522
  SocketEvent,
5472
5523
  SocketSessionTTL,
5473
5524
  SqlNumberTypeRangeMap,