@budibase/string-templates 2.17.8 → 2.18.1

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.
@@ -0,0 +1,4 @@
1
+ export class JsErrorTimeout extends Error {
2
+ constructor();
3
+ code: string;
4
+ }
package/dist/index.d.mts CHANGED
@@ -19,3 +19,4 @@ export const convertToJS: (hbs: any) => string;
19
19
  export const setJSRunner: (runner: any) => any;
20
20
  export const FIND_ANY_HBS_REGEX: RegExp;
21
21
  export const helpersToRemoveForJs: string[];
22
+ export * from "./errors.js";
package/dist/index.d.ts CHANGED
@@ -15,4 +15,4 @@ export function doesContainString(template: string, string: string): boolean;
15
15
  export function convertToJS(hbs: any): string;
16
16
  import { FIND_ANY_HBS_REGEX } from "./utilities";
17
17
  import { helpersToRemoveForJs } from "./helpers/list";
18
- export { setJSRunner, FIND_ANY_HBS_REGEX, helpersToRemoveForJs };
18
+ export { setJSRunner, FIND_ANY_HBS_REGEX, JsErrorTimeout, helpersToRemoveForJs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budibase/string-templates",
3
- "version": "2.17.8",
3
+ "version": "2.18.1",
4
4
  "description": "Handlebars wrapper for Budibase templating.",
5
5
  "main": "src/index.cjs",
6
6
  "module": "dist/bundle.mjs",
@@ -11,7 +11,8 @@
11
11
  "require": "./src/index.cjs",
12
12
  "import": "./dist/bundle.mjs"
13
13
  },
14
- "./package.json": "./package.json"
14
+ "./package.json": "./package.json",
15
+ "./test/utils": "./test/utils.js"
15
16
  },
16
17
  "files": [
17
18
  "dist",
@@ -20,7 +21,7 @@
20
21
  ],
21
22
  "scripts": {
22
23
  "build": "tsc && rollup -c",
23
- "dev": "tsc && rollup -cw",
24
+ "dev": "concurrently \"tsc --watch\" \"rollup -cw\"",
24
25
  "test": "jest",
25
26
  "manifest": "node ./scripts/gen-collection-info.js"
26
27
  },
@@ -34,6 +35,7 @@
34
35
  "devDependencies": {
35
36
  "@rollup/plugin-commonjs": "^17.1.0",
36
37
  "@rollup/plugin-json": "^4.1.0",
38
+ "concurrently": "^8.2.2",
37
39
  "doctrine": "^3.0.0",
38
40
  "jest": "29.7.0",
39
41
  "marked": "^4.0.10",
@@ -45,5 +47,5 @@
45
47
  "rollup-plugin-terser": "^7.0.2",
46
48
  "typescript": "5.2.2"
47
49
  },
48
- "gitHead": "1e44b9f893e4a4c44e5759837f1354e5c2464341"
50
+ "gitHead": "bacb888b699e362e38c2be211a2a524e3172c347"
49
51
  }
package/src/errors.js ADDED
@@ -0,0 +1,11 @@
1
+ class JsErrorTimeout extends Error {
2
+ code = "ERR_SCRIPT_EXECUTION_TIMEOUT"
3
+
4
+ constructor() {
5
+ super()
6
+ }
7
+ }
8
+
9
+ module.exports = {
10
+ JsErrorTimeout,
11
+ }
@@ -42,7 +42,7 @@ module.exports.processJS = (handlebars, context) => {
42
42
  try {
43
43
  // Wrap JS in a function and immediately invoke it.
44
44
  // This is required to allow the final `return` statement to be valid.
45
- const js = `function run(){${atob(handlebars)}};run();`
45
+ const js = `(function(){${atob(handlebars)}})();`
46
46
 
47
47
  // Our $ context function gets a value from context.
48
48
  // We clone the context to avoid mutation in the binding affecting real
@@ -1,29 +1,42 @@
1
- const externalHandlebars = require("./external")
2
- const helperList = require("@budibase/handlebars-helpers")
1
+ const { date, duration } = require("./date")
3
2
 
4
- let helpers = undefined
3
+ // https://github.com/evanw/esbuild/issues/56
4
+ const externalCollections = {
5
+ math: require("@budibase/handlebars-helpers/lib/math"),
6
+ array: require("@budibase/handlebars-helpers/lib/array"),
7
+ number: require("@budibase/handlebars-helpers/lib/number"),
8
+ url: require("@budibase/handlebars-helpers/lib/url"),
9
+ string: require("@budibase/handlebars-helpers/lib/string"),
10
+ comparison: require("@budibase/handlebars-helpers/lib/comparison"),
11
+ object: require("@budibase/handlebars-helpers/lib/object"),
12
+ regex: require("@budibase/handlebars-helpers/lib/regex"),
13
+ uuid: require("@budibase/handlebars-helpers/lib/uuid"),
14
+ }
5
15
 
6
16
  const helpersToRemoveForJs = ["sortBy"]
7
17
  module.exports.helpersToRemoveForJs = helpersToRemoveForJs
8
18
 
19
+ const addedHelpers = {
20
+ date: date,
21
+ duration: duration,
22
+ }
23
+
24
+ let helpers = undefined
25
+
9
26
  module.exports.getJsHelperList = () => {
10
27
  if (helpers) {
11
28
  return helpers
12
29
  }
13
30
 
14
31
  helpers = {}
15
- let constructed = []
16
- for (let collection of externalHandlebars.externalCollections) {
17
- constructed.push(helperList[collection]())
18
- }
19
- for (let collection of constructed) {
32
+ for (let collection of Object.values(externalCollections)) {
20
33
  for (let [key, func] of Object.entries(collection)) {
21
34
  // Handlebars injects the hbs options to the helpers by default. We are adding an empty {} as a last parameter to simulate it
22
35
  helpers[key] = (...props) => func(...props, {})
23
36
  }
24
37
  }
25
- for (let key of Object.keys(externalHandlebars.addedHelpers)) {
26
- helpers[key] = externalHandlebars.addedHelpers[key]
38
+ for (let key of Object.keys(addedHelpers)) {
39
+ helpers[key] = addedHelpers[key]
27
40
  }
28
41
 
29
42
  for (const toRemove of helpersToRemoveForJs) {
package/src/index.cjs CHANGED
@@ -36,3 +36,8 @@ if (!process.env.NO_JS) {
36
36
  return vm.run(js)
37
37
  })
38
38
  }
39
+
40
+ const errors = require("./errors")
41
+ for (const error in errors) {
42
+ module.exports[error] = errors[error]
43
+ }
package/src/index.js CHANGED
@@ -395,4 +395,9 @@ module.exports.convertToJS = hbs => {
395
395
  }
396
396
 
397
397
  module.exports.FIND_ANY_HBS_REGEX = FIND_ANY_HBS_REGEX
398
+
399
+ const errors = require("./errors")
400
+ // We cannot use dynamic exports, otherwise the typescript file will not be generating it
401
+ module.exports.JsErrorTimeout = errors.JsErrorTimeout
402
+
398
403
  module.exports.helpersToRemoveForJs = helpersToRemoveForJs
package/src/index.mjs CHANGED
@@ -38,3 +38,5 @@ if (process && !process.env.NO_JS) {
38
38
  return vm.runInNewContext(js, context, { timeout: 1000 })
39
39
  })
40
40
  }
41
+
42
+ export * from "./errors.js"