From b5672d676fd2aebbe7b2539febfa8ebb424b531d Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 29 Jan 2024 17:38:52 +0000 Subject: [PATCH 01/32] Add a check to stringSplit that gives a nicer error message is a non-string is passed. --- packages/server/src/automations/automationUtils.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/server/src/automations/automationUtils.ts b/packages/server/src/automations/automationUtils.ts index 3e25665a60..8f63b1d0dd 100644 --- a/packages/server/src/automations/automationUtils.ts +++ b/packages/server/src/automations/automationUtils.ts @@ -131,6 +131,9 @@ export function stringSplit(value: string | string[]) { if (value == null || Array.isArray(value)) { return value || [] } + if (typeof value !== "string") { + throw new Error(`Unable to split value of type ${typeof value}: ${value}`) + } if (value.split("\n").length > 1) { value = value.split("\n") } else { From 2bfa4c6f91a4cb5428b3be8a742b5ef2986abc16 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 29 Jan 2024 17:43:08 +0000 Subject: [PATCH 02/32] Mild refactor of stringSplit to make it easier to understand. --- .../server/src/automations/automationUtils.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/server/src/automations/automationUtils.ts b/packages/server/src/automations/automationUtils.ts index 8f63b1d0dd..662cecbb25 100644 --- a/packages/server/src/automations/automationUtils.ts +++ b/packages/server/src/automations/automationUtils.ts @@ -128,18 +128,20 @@ export function substituteLoopStep(hbsString: string, substitute: string) { } export function stringSplit(value: string | string[]) { - if (value == null || Array.isArray(value)) { - return value || [] + if (value == null) { + return [] + } + if (Array.isArray(value)) { + return value } if (typeof value !== "string") { throw new Error(`Unable to split value of type ${typeof value}: ${value}`) } - if (value.split("\n").length > 1) { - value = value.split("\n") - } else { - value = value.split(",") + const splitOnNewLine = value.split("\n") + if (splitOnNewLine.length > 1) { + return splitOnNewLine } - return value + return value.split(",") } export function typecastForLooping(loopStep: LoopStep, input: LoopInput) { From b36c8ad476317baf0f87276406026c3f41970b22 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 25 Jan 2024 15:56:02 +0100 Subject: [PATCH 03/32] Move cleanups out of the actual test --- .../string-templates/test/manifest.spec.js | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/packages/string-templates/test/manifest.spec.js b/packages/string-templates/test/manifest.spec.js index 506f2eb6f7..be3b055bf4 100644 --- a/packages/string-templates/test/manifest.spec.js +++ b/packages/string-templates/test/manifest.spec.js @@ -27,10 +27,32 @@ const manifest = JSON.parse( const collections = Object.keys(manifest) const examples = collections.reduce((acc, collection) => { - const functions = Object.keys(manifest[collection]).filter( - fnc => manifest[collection][fnc].example - ) - if (functions.length) { + const functions = Object.entries(manifest[collection]) + .filter(([_, details]) => details.example) + .map(([name, details]) => { + const example = details.example + let [hbs, js] = example.split("->").map(x => x.trim()) + if (!js) { + // The function has no return value + return + } + + // Trim 's + js = js.replace(/^\'|\'$/g, "") + if ((parsedExpected = tryParseJson(js))) { + if (Array.isArray(parsedExpected)) { + if (typeof parsedExpected[0] === "object") { + js = JSON.stringify(parsedExpected) + } else { + js = parsedExpected.join(",") + } + } + } + return [name, hbs, js] + }) + .filter(x => !!x) + + if (Object.keys(functions).length) { acc[collection] = functions } return acc @@ -55,11 +77,7 @@ function tryParseJson(str) { describe("manifest", () => { describe("examples are valid", () => { describe.each(Object.keys(examples))("%s", collection => { - it.each(examples[collection])("%s", async func => { - const example = manifest[collection][func].example - - let [hbs, js] = example.split("->").map(x => x.trim()) - + it.each(examples[collection])("%s", async (_, hbs, js) => { const context = { double: i => i * 2, isString: x => typeof x === "string", @@ -71,23 +89,7 @@ describe("manifest", () => { context[`array${i}`] = JSON.parse(arrayString.replace(/\'/g, '"')) }) - if (js === undefined) { - // The function has no return value - return - } - let result = await processString(hbs, context) - // Trim 's - js = js.replace(/^\'|\'$/g, "") - if ((parsedExpected = tryParseJson(js))) { - if (Array.isArray(parsedExpected)) { - if (typeof parsedExpected[0] === "object") { - js = JSON.stringify(parsedExpected) - } else { - js = parsedExpected.join(",") - } - } - } result = result.replace(/ /g, " ") expect(result).toEqual(js) }) From ceb7fc04f404fbceed429febdab94e8393998870 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 25 Jan 2024 16:15:20 +0100 Subject: [PATCH 04/32] Add js tests (not all working) --- .../string-templates/test/manifest.spec.js | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/string-templates/test/manifest.spec.js b/packages/string-templates/test/manifest.spec.js index be3b055bf4..c48bc9c9fc 100644 --- a/packages/string-templates/test/manifest.spec.js +++ b/packages/string-templates/test/manifest.spec.js @@ -16,11 +16,21 @@ jest.mock("@budibase/handlebars-helpers/lib/uuid", () => { }) const fs = require("fs") -const { processString } = require("../src/index.cjs") +const { + processString, + convertToJS, + processStringSync, + encodeJSBinding, +} = require("../src/index.cjs") const tk = require("timekeeper") + tk.freeze("2021-01-21T12:00:00") +const processJS = (js, context) => { + return processStringSync(encodeJSBinding(js), context) +} + const manifest = JSON.parse( fs.readFileSync(require.resolve("../manifest.json"), "utf8") ) @@ -95,4 +105,28 @@ describe("manifest", () => { }) }) }) + + describe("can be parsed and run as js", () => { + describe.each(Object.keys(examples))("%s", collection => { + it.each(examples[collection])("%s", async (_, hbs, js) => { + const context = { + double: i => i * 2, + isString: x => typeof x === "string", + } + + const arrays = hbs.match(/\[[^/\]]+\]/) + arrays?.forEach((arrayString, i) => { + hbs = hbs.replace(new RegExp(escapeRegExp(arrayString)), `array${i}`) + context[`array${i}`] = JSON.parse(arrayString.replace(/\'/g, '"')) + }) + + let convertedJs = convertToJS(hbs) + convertedJs = convertedJs.replace(/\n/g, "\n") + + let result = processJS(convertedJs, context) + result = result.replace(/ /g, " ") + expect(result).toEqual(js) + }) + }) + }) }) From 5a1d73ff2f7521a5391ba0ec5646586359c46baf Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 25 Jan 2024 17:24:47 +0100 Subject: [PATCH 05/32] Fix avg helper --- packages/string-templates/src/helpers/list.js | 11 +++++++++++ packages/string-templates/test/manifest.spec.js | 1 - 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/string-templates/src/helpers/list.js b/packages/string-templates/src/helpers/list.js index b59efb1ef3..6d5241cdd8 100644 --- a/packages/string-templates/src/helpers/list.js +++ b/packages/string-templates/src/helpers/list.js @@ -21,6 +21,17 @@ module.exports.getHelperList = () => { for (let key of Object.keys(externalHandlebars.addedHelpers)) { helpers[key] = externalHandlebars.addedHelpers[key] } + + helpers = adjustJsHelpers(helpers) Object.freeze(helpers) return helpers } + +function adjustJsHelpers(helpers) { + const result = { ...helpers } + + result.avg = function (...params) { + return helpers.avg(...params, {}) + } + return result +} diff --git a/packages/string-templates/test/manifest.spec.js b/packages/string-templates/test/manifest.spec.js index c48bc9c9fc..af0b6630a4 100644 --- a/packages/string-templates/test/manifest.spec.js +++ b/packages/string-templates/test/manifest.spec.js @@ -121,7 +121,6 @@ describe("manifest", () => { }) let convertedJs = convertToJS(hbs) - convertedJs = convertedJs.replace(/\n/g, "\n") let result = processJS(convertedJs, context) result = result.replace(/ /g, " ") From a14ff42b14969355e92a89cb1f4fca6e61d62dda Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 25 Jan 2024 17:35:00 +0100 Subject: [PATCH 06/32] Fix duration as js --- packages/string-templates/src/helpers/date.js | 2 +- packages/string-templates/src/helpers/list.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/string-templates/src/helpers/date.js b/packages/string-templates/src/helpers/date.js index 27554d1d9e..6fe8b288d6 100644 --- a/packages/string-templates/src/helpers/date.js +++ b/packages/string-templates/src/helpers/date.js @@ -115,7 +115,7 @@ module.exports.duration = (str, pattern, format) => { setLocale(config.str, config.pattern) const duration = dayjs.duration(config.str, config.pattern) - if (!isOptions(format)) { + if (format && !isOptions(format)) { return duration.format(format) } else { return duration.humanize() diff --git a/packages/string-templates/src/helpers/list.js b/packages/string-templates/src/helpers/list.js index 6d5241cdd8..92f5ee03ce 100644 --- a/packages/string-templates/src/helpers/list.js +++ b/packages/string-templates/src/helpers/list.js @@ -27,6 +27,7 @@ module.exports.getHelperList = () => { return helpers } +// Some helpers depend on handlebars injecting some parameters. This function adjust the helpers when required function adjustJsHelpers(helpers) { const result = { ...helpers } From db14f9afabc6f3045e8d2ebb7db3558d310d59e7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 25 Jan 2024 19:48:34 +0100 Subject: [PATCH 07/32] Inject {} at the end of the helper calls --- packages/string-templates/src/helpers/list.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/packages/string-templates/src/helpers/list.js b/packages/string-templates/src/helpers/list.js index 92f5ee03ce..739d8b50be 100644 --- a/packages/string-templates/src/helpers/list.js +++ b/packages/string-templates/src/helpers/list.js @@ -15,24 +15,14 @@ module.exports.getHelperList = () => { } for (let collection of constructed) { for (let [key, func] of Object.entries(collection)) { - helpers[key] = func + // Handlebars injects the hbs options to the helpers by default. We are adding an empty {} as a last parameter to simulate it + helpers[key] = (...props) => func(...props, {}) } } for (let key of Object.keys(externalHandlebars.addedHelpers)) { helpers[key] = externalHandlebars.addedHelpers[key] } - helpers = adjustJsHelpers(helpers) Object.freeze(helpers) return helpers } - -// Some helpers depend on handlebars injecting some parameters. This function adjust the helpers when required -function adjustJsHelpers(helpers) { - const result = { ...helpers } - - result.avg = function (...params) { - return helpers.avg(...params, {}) - } - return result -} From db9e4513c2e441dc304ed5382f8555034792d441 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 26 Jan 2024 13:11:25 +0100 Subject: [PATCH 08/32] Update manifest examples --- packages/string-templates/manifest.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/string-templates/manifest.json b/packages/string-templates/manifest.json index 9dd8260350..12155fe752 100644 --- a/packages/string-templates/manifest.json +++ b/packages/string-templates/manifest.json @@ -163,7 +163,7 @@ "options" ], "numArgs": 2, - "example": "{{#eachIndex [1, 2, 3]}} {{item}} is {{index}} {{/eachIndex}}", + "example": "{{#eachIndex [1, 2, 3]}} {{item}} is {{index}} {{/eachIndex}} -> ' 1 is 0 2 is 1 3 is 2 '", "description": "

Iterates the array, listing an item and the index of it.

\n" }, "filter": { @@ -173,7 +173,7 @@ "options" ], "numArgs": 3, - "example": "{{#filter [1, 2, 3] 2}}2 Found{{else}}2 not found{{/filter}}", + "example": "{{#filter [1, 2, 3] 2}}2 Found{{else}}2 not found{{/filter}} -> 2 Found", "description": "

Block helper that filters the given array and renders the block for values that evaluate to true, otherwise the inverse block is returned.

\n" }, "first": { @@ -190,7 +190,7 @@ "array" ], "numArgs": 1, - "example": "{{#forEach [{ 'name': 'John' }] }} {{ name }} {{/forEach}}", + "example": "{{#forEach [{ 'name': 'John' }] }} {{ name }} {{/forEach}} -> ' John '", "description": "

Iterates over each item in an array and exposes the current item in the array as context to the inner block. In addition to the current array item, the helper exposes the following variables to the inner block: - index - total - isFirst - isLast Also, @index is exposed as a private variable, and additional private variables may be defined as hash arguments.

\n" }, "inArray": { @@ -327,7 +327,7 @@ "options" ], "numArgs": 3, - "example": "{{ withAfter [1, 2, 3] 1 }} {{this}} {{/withAfter}}", + "example": "{{#withAfter [1, 2, 3] 1 }} {{this}} {{/withAfter}} -> ' 2 3 '", "description": "

Use the items in the array after the specified index as context inside a block. Opposite of withBefore.

\n" }, "withBefore": { @@ -337,7 +337,7 @@ "options" ], "numArgs": 3, - "example": "{{ withBefore [1, 2, 3] 2 }} {{this}} {{/withBefore}}", + "example": "{{#withBefore [1, 2, 3] 2 }} {{this}} {{/withBefore}} -> ' 1 '", "description": "

Use the items in the array before the specified index as context inside a block. Opposite of withAfter.

\n" }, "withFirst": { @@ -462,7 +462,7 @@ "precision" ], "numArgs": 2, - "example": "{{toPrecision '1.1234' 2}}", + "example": "{{toPrecision '1.1234' 2}} -> 1.1", "description": "

Returns a string representing the Number object to the specified precision.

\n" } }, @@ -825,7 +825,7 @@ "options" ], "numArgs": 3, - "example": "{{#and great magnificent}}both{{else}}no{{/and}}", + "example": "{{#and great magnificent}}both{{else}}no{{/and}} -> no", "description": "

Helper that renders the block if both of the given values are truthy. If an inverse block is specified it will be rendered when falsy. Works as a block helper, inline helper or subexpression.

\n" }, "compare": { @@ -847,7 +847,7 @@ "options" ], "numArgs": 4, - "example": "{{#contains ['a', 'b', 'c'] 'd'}} This will not be rendered. {{else}} This will be rendered. {{/contains}}", + "example": "{{#contains ['a', 'b', 'c'] 'd'}} This will not be rendered. {{else}} This will be rendered. {{/contains}} -> ' This will be rendered. '", "description": "

Block helper that renders the block if collection has the given value, using strict equality (===) for comparison, otherwise the inverse block is rendered (if specified). If a startIndex is specified and is negative, it is used as the offset from the end of the collection.

\n" }, "default": { From 5b5228d8b0677095fd40944ef2322b89ddc392b2 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 26 Jan 2024 13:37:28 +0100 Subject: [PATCH 09/32] Type params --- packages/string-templates/test/manifest.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/string-templates/test/manifest.spec.js b/packages/string-templates/test/manifest.spec.js index af0b6630a4..ccfef3e50a 100644 --- a/packages/string-templates/test/manifest.spec.js +++ b/packages/string-templates/test/manifest.spec.js @@ -58,7 +58,7 @@ const examples = collections.reduce((acc, collection) => { } } } - return [name, hbs, js] + return [name, { hbs, js }] }) .filter(x => !!x) @@ -87,7 +87,7 @@ function tryParseJson(str) { describe("manifest", () => { describe("examples are valid", () => { describe.each(Object.keys(examples))("%s", collection => { - it.each(examples[collection])("%s", async (_, hbs, js) => { + it.each(examples[collection])("%s", async (_, { hbs, js }) => { const context = { double: i => i * 2, isString: x => typeof x === "string", @@ -108,7 +108,7 @@ describe("manifest", () => { describe("can be parsed and run as js", () => { describe.each(Object.keys(examples))("%s", collection => { - it.each(examples[collection])("%s", async (_, hbs, js) => { + it.each(examples[collection])("%s", async (_, { hbs, js }) => { const context = { double: i => i * 2, isString: x => typeof x === "string", From eac30aa787be7080f3676638cd692a58a2de115f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 30 Jan 2024 10:20:52 +0100 Subject: [PATCH 10/32] isBlock to manifest --- packages/string-templates/manifest.json | 414 ++++++++++++------ .../scripts/gen-collection-info.js | 2 + 2 files changed, 275 insertions(+), 141 deletions(-) diff --git a/packages/string-templates/manifest.json b/packages/string-templates/manifest.json index 12155fe752..cd787bc850 100644 --- a/packages/string-templates/manifest.json +++ b/packages/string-templates/manifest.json @@ -6,7 +6,8 @@ ], "numArgs": 1, "example": "{{ abs 12012.1000 }} -> 12012.1", - "description": "

Return the magnitude of a.

\n" + "description": "

Return the magnitude of a.

\n", + "isBlock": false }, "add": { "args": [ @@ -15,7 +16,8 @@ ], "numArgs": 2, "example": "{{ add 1 2 }} -> 3", - "description": "

Return the sum of a plus b.

\n" + "description": "

Return the sum of a plus b.

\n", + "isBlock": false }, "avg": { "args": [ @@ -23,7 +25,8 @@ ], "numArgs": 1, "example": "{{ avg 1 2 3 4 5 }} -> 3", - "description": "

Returns the average of all numbers in the given array.

\n" + "description": "

Returns the average of all numbers in the given array.

\n", + "isBlock": false }, "ceil": { "args": [ @@ -31,7 +34,8 @@ ], "numArgs": 1, "example": "{{ ceil 1.2 }} -> 2", - "description": "

Get the Math.ceil() of the given value.

\n" + "description": "

Get the Math.ceil() of the given value.

\n", + "isBlock": false }, "divide": { "args": [ @@ -40,7 +44,8 @@ ], "numArgs": 2, "example": "{{ divide 10 5 }} -> 2", - "description": "

Divide a by b

\n" + "description": "

Divide a by b

\n", + "isBlock": false }, "floor": { "args": [ @@ -48,7 +53,8 @@ ], "numArgs": 1, "example": "{{ floor 1.2 }} -> 1", - "description": "

Get the Math.floor() of the given value.

\n" + "description": "

Get the Math.floor() of the given value.

\n", + "isBlock": false }, "minus": { "args": [ @@ -57,7 +63,8 @@ ], "numArgs": 2, "example": "{{ subtract 10 5 }} -> 5", - "description": "

Return the product of a minus b.

\n" + "description": "

Return the product of a minus b.

\n", + "isBlock": false }, "modulo": { "args": [ @@ -66,7 +73,8 @@ ], "numArgs": 2, "example": "{{ modulo 10 5 }} -> 0", - "description": "

Get the remainder of a division operation.

\n" + "description": "

Get the remainder of a division operation.

\n", + "isBlock": false }, "multiply": { "args": [ @@ -75,7 +83,8 @@ ], "numArgs": 2, "example": "{{ multiply 10 5 }} -> 50", - "description": "

Multiply number a by number b.

\n" + "description": "

Multiply number a by number b.

\n", + "isBlock": false }, "plus": { "args": [ @@ -84,7 +93,8 @@ ], "numArgs": 2, "example": "{{ plus 10 5 }} -> 15", - "description": "

Add a by b.

\n" + "description": "

Add a by b.

\n", + "isBlock": false }, "random": { "args": [ @@ -93,7 +103,8 @@ ], "numArgs": 2, "example": "{{ random 0 20 }} -> 10", - "description": "

Generate a random number between two values

\n" + "description": "

Generate a random number between two values

\n", + "isBlock": false }, "remainder": { "args": [ @@ -102,7 +113,8 @@ ], "numArgs": 2, "example": "{{ remainder 10 6 }} -> 4", - "description": "

Get the remainder when a is divided by b.

\n" + "description": "

Get the remainder when a is divided by b.

\n", + "isBlock": false }, "round": { "args": [ @@ -110,7 +122,8 @@ ], "numArgs": 1, "example": "{{ round 10.3 }} -> 10", - "description": "

Round the given number.

\n" + "description": "

Round the given number.

\n", + "isBlock": false }, "subtract": { "args": [ @@ -119,7 +132,8 @@ ], "numArgs": 2, "example": "{{ subtract 10 5 }} -> 5", - "description": "

Return the product of a minus b.

\n" + "description": "

Return the product of a minus b.

\n", + "isBlock": false }, "sum": { "args": [ @@ -127,7 +141,8 @@ ], "numArgs": 1, "example": "{{ sum [1, 2, 3] }} -> 6", - "description": "

Returns the sum of all numbers in the given array.

\n" + "description": "

Returns the sum of all numbers in the given array.

\n", + "isBlock": false } }, "array": { @@ -138,7 +153,8 @@ ], "numArgs": 2, "example": "{{ after ['a', 'b', 'c', 'd'] 2}} -> ['c', 'd']", - "description": "

Returns all of the items in an array after the specified index. Opposite of before.

\n" + "description": "

Returns all of the items in an array after the specified index. Opposite of before.

\n", + "isBlock": false }, "arrayify": { "args": [ @@ -146,7 +162,8 @@ ], "numArgs": 1, "example": "{{ arrayify 'foo' }} -> ['foo']", - "description": "

Cast the given value to an array.

\n" + "description": "

Cast the given value to an array.

\n", + "isBlock": false }, "before": { "args": [ @@ -155,7 +172,8 @@ ], "numArgs": 2, "example": "{{ before ['a', 'b', 'c', 'd'] 3}} -> ['a', 'b']", - "description": "

Return all of the items in the collection before the specified count. Opposite of after.

\n" + "description": "

Return all of the items in the collection before the specified count. Opposite of after.

\n", + "isBlock": false }, "eachIndex": { "args": [ @@ -164,7 +182,8 @@ ], "numArgs": 2, "example": "{{#eachIndex [1, 2, 3]}} {{item}} is {{index}} {{/eachIndex}} -> ' 1 is 0 2 is 1 3 is 2 '", - "description": "

Iterates the array, listing an item and the index of it.

\n" + "description": "

Iterates the array, listing an item and the index of it.

\n", + "isBlock": true }, "filter": { "args": [ @@ -174,7 +193,8 @@ ], "numArgs": 3, "example": "{{#filter [1, 2, 3] 2}}2 Found{{else}}2 not found{{/filter}} -> 2 Found", - "description": "

Block helper that filters the given array and renders the block for values that evaluate to true, otherwise the inverse block is returned.

\n" + "description": "

Block helper that filters the given array and renders the block for values that evaluate to true, otherwise the inverse block is returned.

\n", + "isBlock": true }, "first": { "args": [ @@ -183,15 +203,18 @@ ], "numArgs": 2, "example": "{{first [1, 2, 3, 4] 2}} -> 1,2", - "description": "

Returns the first item, or first n items of an array.

\n" + "description": "

Returns the first item, or first n items of an array.

\n", + "isBlock": false }, "forEach": { "args": [ - "array" + "array", + "options" ], - "numArgs": 1, + "numArgs": 2, "example": "{{#forEach [{ 'name': 'John' }] }} {{ name }} {{/forEach}} -> ' John '", - "description": "

Iterates over each item in an array and exposes the current item in the array as context to the inner block. In addition to the current array item, the helper exposes the following variables to the inner block: - index - total - isFirst - isLast Also, @index is exposed as a private variable, and additional private variables may be defined as hash arguments.

\n" + "description": "

Iterates over each item in an array and exposes the current item in the array as context to the inner block. In addition to the current array item, the helper exposes the following variables to the inner block: - index - total - isFirst - isLast Also, @index is exposed as a private variable, and additional private variables may be defined as hash arguments.

\n", + "isBlock": true }, "inArray": { "args": [ @@ -201,7 +224,8 @@ ], "numArgs": 3, "example": "{{#inArray [1, 2, 3] 2}} 2 exists {{else}} 2 does not exist {{/inArray}} -> ' 2 exists '", - "description": "

Block helper that renders the block if an array has the given value. Optionally specify an inverse block to render when the array does not have the given value.

\n" + "description": "

Block helper that renders the block if an array has the given value. Optionally specify an inverse block to render when the array does not have the given value.

\n", + "isBlock": true }, "isArray": { "args": [ @@ -209,7 +233,8 @@ ], "numArgs": 1, "example": "{{isArray [1, 2]}} -> true", - "description": "

Returns true if value is an es5 array.

\n" + "description": "

Returns true if value is an es5 array.

\n", + "isBlock": false }, "itemAt": { "args": [ @@ -218,7 +243,8 @@ ], "numArgs": 2, "example": "{{itemAt [1, 2, 3] 1}} -> 2", - "description": "

Returns the item from array at index idx.

\n" + "description": "

Returns the item from array at index idx.

\n", + "isBlock": false }, "join": { "args": [ @@ -227,17 +253,18 @@ ], "numArgs": 2, "example": "{{join [1, 2, 3]}} -> 1, 2, 3", - "description": "

Join all elements of array into a string, optionally using a given separator.

\n" + "description": "

Join all elements of array into a string, optionally using a given separator.

\n", + "isBlock": false }, "equalsLength": { "args": [ "value", - "length", - "options" + "length" ], - "numArgs": 3, + "numArgs": 2, "example": "{{equalsLength [1, 2, 3] 3}} -> true", - "description": "

Returns true if the the length of the given value is equal to the given length. Can be used as a block or inline helper.

\n" + "description": "

Returns true if the the length of the given value is equal to the given length. Can be used as a block or inline helper.

\n", + "isBlock": true }, "last": { "args": [ @@ -246,7 +273,8 @@ ], "numArgs": 2, "example": "{{last [1, 2, 3]}} -> 3", - "description": "

Returns the last item, or last n items of an array or string. Opposite of first.

\n" + "description": "

Returns the last item, or last n items of an array or string. Opposite of first.

\n", + "isBlock": false }, "length": { "args": [ @@ -254,17 +282,18 @@ ], "numArgs": 1, "example": "{{length [1, 2, 3]}} -> 3", - "description": "

Returns the length of the given string or array.

\n" + "description": "

Returns the length of the given string or array.

\n", + "isBlock": false }, "lengthEqual": { "args": [ "value", - "length", - "options" + "length" ], - "numArgs": 3, + "numArgs": 2, "example": "{{equalsLength [1, 2, 3] 3}} -> true", - "description": "

Returns true if the the length of the given value is equal to the given length. Can be used as a block or inline helper.

\n" + "description": "

Returns true if the the length of the given value is equal to the given length. Can be used as a block or inline helper.

\n", + "isBlock": true }, "map": { "args": [ @@ -273,7 +302,8 @@ ], "numArgs": 2, "example": "{{map [1, 2, 3] double}} -> [2, 4, 6]", - "description": "

Returns a new array, created by calling function on each element of the given array. For example,

\n" + "description": "

Returns a new array, created by calling function on each element of the given array. For example,

\n", + "isBlock": false }, "pluck": { "args": [ @@ -282,7 +312,8 @@ ], "numArgs": 2, "example": "{{pluck [{ 'name': 'Bob' }] 'name' }} -> ['Bob']", - "description": "

Map over the given object or array or objects and create an array of values from the given prop. Dot-notation may be used (as a string) to get nested properties.

\n" + "description": "

Map over the given object or array or objects and create an array of values from the given prop. Dot-notation may be used (as a string) to get nested properties.

\n", + "isBlock": false }, "reverse": { "args": [ @@ -290,7 +321,8 @@ ], "numArgs": 1, "example": "{{reverse [1, 2, 3]}} -> [3, 2, 1]", - "description": "

Reverse the elements in an array, or the characters in a string.

\n" + "description": "

Reverse the elements in an array, or the characters in a string.

\n", + "isBlock": false }, "some": { "args": [ @@ -300,7 +332,8 @@ ], "numArgs": 3, "example": "{{#some [1, \"b\", 3] isString}} string found {{else}} No string found {{/some}} -> ' string found '", - "description": "

Block helper that returns the block if the callback returns true for some value in the given array.

\n" + "description": "

Block helper that returns the block if the callback returns true for some value in the given array.

\n", + "isBlock": true }, "sort": { "args": [ @@ -309,7 +342,8 @@ ], "numArgs": 2, "example": "{{ sort ['b', 'a', 'c'] }} -> ['a', 'b', 'c']", - "description": "

Sort the given array. If an array of objects is passed, you may optionally pass a key to sort on as the second argument. You may alternatively pass a sorting function as the second argument.

\n" + "description": "

Sort the given array. If an array of objects is passed, you may optionally pass a key to sort on as the second argument. You may alternatively pass a sorting function as the second argument.

\n", + "isBlock": false }, "sortBy": { "args": [ @@ -318,7 +352,8 @@ ], "numArgs": 2, "example": "{{ sortBy [{'a': 'zzz'}, {'a': 'aaa'}] 'a' }} -> [{'a':'aaa'},{'a':'zzz'}]", - "description": "

Sort an array. If an array of objects is passed, you may optionally pass a key to sort on as the second argument. You may alternatively pass a sorting function as the second argument.

\n" + "description": "

Sort an array. If an array of objects is passed, you may optionally pass a key to sort on as the second argument. You may alternatively pass a sorting function as the second argument.

\n", + "isBlock": false }, "withAfter": { "args": [ @@ -328,7 +363,8 @@ ], "numArgs": 3, "example": "{{#withAfter [1, 2, 3] 1 }} {{this}} {{/withAfter}} -> ' 2 3 '", - "description": "

Use the items in the array after the specified index as context inside a block. Opposite of withBefore.

\n" + "description": "

Use the items in the array after the specified index as context inside a block. Opposite of withBefore.

\n", + "isBlock": true }, "withBefore": { "args": [ @@ -338,7 +374,8 @@ ], "numArgs": 3, "example": "{{#withBefore [1, 2, 3] 2 }} {{this}} {{/withBefore}} -> ' 1 '", - "description": "

Use the items in the array before the specified index as context inside a block. Opposite of withAfter.

\n" + "description": "

Use the items in the array before the specified index as context inside a block. Opposite of withAfter.

\n", + "isBlock": true }, "withFirst": { "args": [ @@ -348,7 +385,8 @@ ], "numArgs": 3, "example": "{{#withFirst [1, 2, 3] }}{{this}}{{/withFirst}} -> 1", - "description": "

Use the first item in a collection inside a handlebars block expression. Opposite of withLast.

\n" + "description": "

Use the first item in a collection inside a handlebars block expression. Opposite of withLast.

\n", + "isBlock": true }, "withGroup": { "args": [ @@ -358,7 +396,8 @@ ], "numArgs": 3, "example": "{{#withGroup [1, 2, 3, 4] 2}}{{#each this}}{{.}}{{/each}}
{{/withGroup}} -> 12
34
", - "description": "

Block helper that groups array elements by given group size.

\n" + "description": "

Block helper that groups array elements by given group size.

\n", + "isBlock": true }, "withLast": { "args": [ @@ -368,7 +407,8 @@ ], "numArgs": 3, "example": "{{#withLast [1, 2, 3, 4]}}{{this}}{{/withLast}} -> 4", - "description": "

Use the last item or n items in an array as context inside a block. Opposite of withFirst.

\n" + "description": "

Use the last item or n items in an array as context inside a block. Opposite of withFirst.

\n", + "isBlock": true }, "withSort": { "args": [ @@ -378,7 +418,8 @@ ], "numArgs": 3, "example": "{{#withSort ['b', 'a', 'c']}}{{this}}{{/withSort}} -> abc", - "description": "

Block helper that sorts a collection and exposes the sorted collection as context inside the block.

\n" + "description": "

Block helper that sorts a collection and exposes the sorted collection as context inside the block.

\n", + "isBlock": true }, "unique": { "args": [ @@ -387,7 +428,8 @@ ], "numArgs": 2, "example": "{{#each (unique ['a', 'a', 'c', 'b', 'e', 'e']) }}{{.}}{{/each}} -> acbe", - "description": "

Block helper that return an array with all duplicate values removed. Best used along with a each helper.

\n" + "description": "

Block helper that return an array with all duplicate values removed. Best used along with a each helper.

\n", + "isBlock": true } }, "number": { @@ -397,7 +439,8 @@ ], "numArgs": 1, "example": "{{ bytes 1386 1 }} -> 1.4 kB", - "description": "

Format a number to it's equivalent in bytes. If a string is passed, it's length will be formatted and returned. Examples: - 'foo' => 3 B - 13661855 => 13.66 MB - 825399 => 825.39 kB - 1396 => 1.4 kB

\n" + "description": "

Format a number to it's equivalent in bytes. If a string is passed, it's length will be formatted and returned. Examples: - 'foo' => 3 B - 13661855 => 13.66 MB - 825399 => 825.39 kB - 1396 => 1.4 kB

\n", + "isBlock": false }, "addCommas": { "args": [ @@ -405,7 +448,8 @@ ], "numArgs": 1, "example": "{{ addCommas 1000000 }} -> 1,000,000", - "description": "

Add commas to numbers

\n" + "description": "

Add commas to numbers

\n", + "isBlock": false }, "phoneNumber": { "args": [ @@ -413,7 +457,8 @@ ], "numArgs": 1, "example": "{{ phoneNumber 8005551212 }} -> (800) 555-1212", - "description": "

Convert a string or number to a formatted phone number.

\n" + "description": "

Convert a string or number to a formatted phone number.

\n", + "isBlock": false }, "toAbbr": { "args": [ @@ -422,7 +467,8 @@ ], "numArgs": 2, "example": "{{ toAbbr 10123 2 }} -> 10.12k", - "description": "

Abbreviate numbers to the given number of precision. This for general numbers, not size in bytes.

\n" + "description": "

Abbreviate numbers to the given number of precision. This for general numbers, not size in bytes.

\n", + "isBlock": false }, "toExponential": { "args": [ @@ -431,7 +477,8 @@ ], "numArgs": 2, "example": "{{ toExponential 10123 2 }} -> 1.01e+4", - "description": "

Returns a string representing the given number in exponential notation.

\n" + "description": "

Returns a string representing the given number in exponential notation.

\n", + "isBlock": false }, "toFixed": { "args": [ @@ -440,21 +487,24 @@ ], "numArgs": 2, "example": "{{ toFixed 1.1234 2 }} -> 1.12", - "description": "

Formats the given number using fixed-point notation.

\n" + "description": "

Formats the given number using fixed-point notation.

\n", + "isBlock": false }, "toFloat": { "args": [ "number" ], "numArgs": 1, - "description": "

Convert input to a float.

\n" + "description": "

Convert input to a float.

\n", + "isBlock": false }, "toInt": { "args": [ "number" ], "numArgs": 1, - "description": "

Convert input to an integer.

\n" + "description": "

Convert input to an integer.

\n", + "isBlock": false }, "toPrecision": { "args": [ @@ -463,7 +513,8 @@ ], "numArgs": 2, "example": "{{toPrecision '1.1234' 2}} -> 1.1", - "description": "

Returns a string representing the Number object to the specified precision.

\n" + "description": "

Returns a string representing the Number object to the specified precision.

\n", + "isBlock": false } }, "url": { @@ -473,7 +524,8 @@ ], "numArgs": 1, "example": "{{ encodeURI 'https://myurl?Hello There' }} -> https%3A%2F%2Fmyurl%3FHello%20There", - "description": "

Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.

\n" + "description": "

Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.

\n", + "isBlock": false }, "escape": { "args": [ @@ -481,7 +533,8 @@ ], "numArgs": 1, "example": "{{ escape 'https://myurl?Hello+There' }} -> https%3A%2F%2Fmyurl%3FHello%2BThere", - "description": "

Escape the given string by replacing characters with escape sequences. Useful for allowing the string to be used in a URL, etc.

\n" + "description": "

Escape the given string by replacing characters with escape sequences. Useful for allowing the string to be used in a URL, etc.

\n", + "isBlock": false }, "decodeURI": { "args": [ @@ -489,7 +542,8 @@ ], "numArgs": 1, "example": "{{ decodeURI 'https://myurl?Hello%20There' }} -> https://myurl?Hello There", - "description": "

Decode a Uniform Resource Identifier (URI) component.

\n" + "description": "

Decode a Uniform Resource Identifier (URI) component.

\n", + "isBlock": false }, "urlResolve": { "args": [ @@ -498,7 +552,8 @@ ], "numArgs": 2, "example": "{{ urlResolve 'https://myurl' '/api/test' }} -> https://myurl/api/test", - "description": "

Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.

\n" + "description": "

Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.

\n", + "isBlock": false }, "urlParse": { "args": [ @@ -506,7 +561,8 @@ ], "numArgs": 1, "example": "{{ urlParse 'https://myurl/api/test' }}", - "description": "

Parses a url string into an object.

\n" + "description": "

Parses a url string into an object.

\n", + "isBlock": false }, "stripQuerystring": { "args": [ @@ -514,7 +570,8 @@ ], "numArgs": 1, "example": "{{ stripQuerystring 'https://myurl/api/test?foo=bar' }} -> 'https://myurl/api/test'", - "description": "

Strip the query string from the given url.

\n" + "description": "

Strip the query string from the given url.

\n", + "isBlock": false }, "stripProtocol": { "args": [ @@ -522,7 +579,8 @@ ], "numArgs": 1, "example": "{{ stripProtocol 'https://myurl/api/test' }} -> '//myurl/api/test'", - "description": "

Strip protocol from a url. Useful for displaying media that may have an 'http' protocol on secure connections.

\n" + "description": "

Strip protocol from a url. Useful for displaying media that may have an 'http' protocol on secure connections.

\n", + "isBlock": false } }, "string": { @@ -533,7 +591,8 @@ ], "numArgs": 2, "example": "{{append 'index' '.html'}} -> index.html", - "description": "

Append the specified suffix to the given string.

\n" + "description": "

Append the specified suffix to the given string.

\n", + "isBlock": false }, "camelcase": { "args": [ @@ -541,7 +600,8 @@ ], "numArgs": 1, "example": "{{camelcase 'foo bar baz'}} -> fooBarBaz", - "description": "

camelCase the characters in the given string.

\n" + "description": "

camelCase the characters in the given string.

\n", + "isBlock": false }, "capitalize": { "args": [ @@ -549,7 +609,8 @@ ], "numArgs": 1, "example": "{{capitalize 'foo bar baz'}} -> Foo bar baz", - "description": "

Capitalize the first word in a sentence.

\n" + "description": "

Capitalize the first word in a sentence.

\n", + "isBlock": false }, "capitalizeAll": { "args": [ @@ -557,7 +618,8 @@ ], "numArgs": 1, "example": "{{ capitalizeAll 'foo bar baz'}} -> Foo Bar Baz", - "description": "

Capitalize all words in a string.

\n" + "description": "

Capitalize all words in a string.

\n", + "isBlock": false }, "center": { "args": [ @@ -566,7 +628,8 @@ ], "numArgs": 2, "example": "{{ center 'test' 1}} -> ' test '", - "description": "

Center a string using non-breaking spaces

\n" + "description": "

Center a string using non-breaking spaces

\n", + "isBlock": false }, "chop": { "args": [ @@ -574,7 +637,8 @@ ], "numArgs": 1, "example": "{{ chop ' ABC '}} -> ABC", - "description": "

Like trim, but removes both extraneous whitespace and non-word characters from the beginning and end of a string.

\n" + "description": "

Like trim, but removes both extraneous whitespace and non-word characters from the beginning and end of a string.

\n", + "isBlock": false }, "dashcase": { "args": [ @@ -582,7 +646,8 @@ ], "numArgs": 1, "example": "{{dashcase 'a-b-c d_e'}} -> a-b-c-d-e", - "description": "

dash-case the characters in string. Replaces non-word characters and periods with hyphens.

\n" + "description": "

dash-case the characters in string. Replaces non-word characters and periods with hyphens.

\n", + "isBlock": false }, "dotcase": { "args": [ @@ -590,7 +655,8 @@ ], "numArgs": 1, "example": "{{dotcase 'a-b-c d_e'}} -> a.b.c.d.e", - "description": "

dot.case the characters in string.

\n" + "description": "

dot.case the characters in string.

\n", + "isBlock": false }, "downcase": { "args": [ @@ -598,7 +664,8 @@ ], "numArgs": 1, "example": "{{downcase 'aBcDeF'}} -> abcdef", - "description": "

Lowercase all of the characters in the given string. Alias for lowercase.

\n" + "description": "

Lowercase all of the characters in the given string. Alias for lowercase.

\n", + "isBlock": false }, "ellipsis": { "args": [ @@ -607,7 +674,8 @@ ], "numArgs": 2, "example": "{{ellipsis 'foo bar baz' 7}} -> foo bar…", - "description": "

Truncates a string to the specified length, and appends it with an elipsis, .

\n" + "description": "

Truncates a string to the specified length, and appends it with an elipsis, .

\n", + "isBlock": false }, "hyphenate": { "args": [ @@ -615,7 +683,8 @@ ], "numArgs": 1, "example": "{{hyphenate 'foo bar baz qux'}} -> foo-bar-baz-qux", - "description": "

Replace spaces in a string with hyphens.

\n" + "description": "

Replace spaces in a string with hyphens.

\n", + "isBlock": false }, "isString": { "args": [ @@ -623,7 +692,8 @@ ], "numArgs": 1, "example": "{{isString 'foo'}} -> true", - "description": "

Return true if value is a string.

\n" + "description": "

Return true if value is a string.

\n", + "isBlock": false }, "lowercase": { "args": [ @@ -631,7 +701,8 @@ ], "numArgs": 1, "example": "{{lowercase 'Foo BAR baZ'}} -> foo bar baz", - "description": "

Lowercase all characters in the given string.

\n" + "description": "

Lowercase all characters in the given string.

\n", + "isBlock": false }, "occurrences": { "args": [ @@ -640,7 +711,8 @@ ], "numArgs": 2, "example": "{{occurrences 'foo bar foo bar baz' 'foo'}} -> 2", - "description": "

Return the number of occurrences of substring within the given string.

\n" + "description": "

Return the number of occurrences of substring within the given string.

\n", + "isBlock": false }, "pascalcase": { "args": [ @@ -648,7 +720,8 @@ ], "numArgs": 1, "example": "{{pascalcase 'foo bar baz'}} -> FooBarBaz", - "description": "

PascalCase the characters in string.

\n" + "description": "

PascalCase the characters in string.

\n", + "isBlock": false }, "pathcase": { "args": [ @@ -656,7 +729,8 @@ ], "numArgs": 1, "example": "{{pathcase 'a-b-c d_e'}} -> a/b/c/d/e", - "description": "

path/case the characters in string.

\n" + "description": "

path/case the characters in string.

\n", + "isBlock": false }, "plusify": { "args": [ @@ -664,7 +738,8 @@ ], "numArgs": 1, "example": "{{plusify 'foo bar baz'}} -> foo+bar+baz", - "description": "

Replace spaces in the given string with pluses.

\n" + "description": "

Replace spaces in the given string with pluses.

\n", + "isBlock": false }, "prepend": { "args": [ @@ -673,7 +748,8 @@ ], "numArgs": 2, "example": "{{prepend 'bar' 'foo-'}} -> foo-bar", - "description": "

Prepends the given string with the specified prefix.

\n" + "description": "

Prepends the given string with the specified prefix.

\n", + "isBlock": false }, "remove": { "args": [ @@ -682,7 +758,8 @@ ], "numArgs": 2, "example": "{{remove 'a b a b a b' 'a '}} -> b b b", - "description": "

Remove all occurrences of substring from the given str.

\n" + "description": "

Remove all occurrences of substring from the given str.

\n", + "isBlock": false }, "removeFirst": { "args": [ @@ -691,7 +768,8 @@ ], "numArgs": 2, "example": "{{removeFirst 'a b a b a b' 'a'}} -> ' b a b a b'", - "description": "

Remove the first occurrence of substring from the given str.

\n" + "description": "

Remove the first occurrence of substring from the given str.

\n", + "isBlock": false }, "replace": { "args": [ @@ -701,7 +779,8 @@ ], "numArgs": 3, "example": "{{replace 'a b a b a b' 'a' 'z'}} -> z b z b z b", - "description": "

Replace all occurrences of substring a with substring b.

\n" + "description": "

Replace all occurrences of substring a with substring b.

\n", + "isBlock": false }, "replaceFirst": { "args": [ @@ -711,7 +790,8 @@ ], "numArgs": 3, "example": "{{replaceFirst 'a b a b a b' 'a' 'z'}} -> z b a b a b", - "description": "

Replace the first occurrence of substring a with substring b.

\n" + "description": "

Replace the first occurrence of substring a with substring b.

\n", + "isBlock": false }, "sentence": { "args": [ @@ -719,7 +799,8 @@ ], "numArgs": 1, "example": "{{sentence 'hello world. goodbye world.'}} -> Hello world. Goodbye world.", - "description": "

Sentence case the given string

\n" + "description": "

Sentence case the given string

\n", + "isBlock": false }, "snakecase": { "args": [ @@ -727,7 +808,8 @@ ], "numArgs": 1, "example": "{{snakecase 'a-b-c d_e'}} -> a_b_c_d_e", - "description": "

snake_case the characters in the given string.

\n" + "description": "

snake_case the characters in the given string.

\n", + "isBlock": false }, "split": { "args": [ @@ -735,7 +817,8 @@ ], "numArgs": 1, "example": "{{split 'a,b,c'}} -> ['a', 'b', 'c']", - "description": "

Split string by the given character.

\n" + "description": "

Split string by the given character.

\n", + "isBlock": false }, "startsWith": { "args": [ @@ -745,7 +828,8 @@ ], "numArgs": 3, "example": "{{#startsWith 'Goodbye' 'Hello, world!'}}Yep{{else}}Nope{{/startsWith}} -> Nope", - "description": "

Tests whether a string begins with the given prefix.

\n" + "description": "

Tests whether a string begins with the given prefix.

\n", + "isBlock": true }, "titleize": { "args": [ @@ -753,7 +837,8 @@ ], "numArgs": 1, "example": "{{titleize 'this is title case' }} -> This Is Title Case", - "description": "

Title case the given string.

\n" + "description": "

Title case the given string.

\n", + "isBlock": false }, "trim": { "args": [ @@ -761,7 +846,8 @@ ], "numArgs": 1, "example": "{{trim ' ABC ' }} -> ABC", - "description": "

Removes extraneous whitespace from the beginning and end of a string.

\n" + "description": "

Removes extraneous whitespace from the beginning and end of a string.

\n", + "isBlock": false }, "trimLeft": { "args": [ @@ -769,7 +855,8 @@ ], "numArgs": 1, "example": "{{trimLeft ' ABC ' }} -> 'ABC '", - "description": "

Removes extraneous whitespace from the beginning of a string.

\n" + "description": "

Removes extraneous whitespace from the beginning of a string.

\n", + "isBlock": false }, "trimRight": { "args": [ @@ -777,7 +864,8 @@ ], "numArgs": 1, "example": "{{trimRight ' ABC ' }} -> ' ABC'", - "description": "

Removes extraneous whitespace from the end of a string.

\n" + "description": "

Removes extraneous whitespace from the end of a string.

\n", + "isBlock": false }, "truncate": { "args": [ @@ -787,7 +875,8 @@ ], "numArgs": 3, "example": "{{truncate 'foo bar baz' 7 }} -> foo bar", - "description": "

Truncate a string to the specified length. Also see ellipsis.

\n" + "description": "

Truncate a string to the specified length. Also see ellipsis.

\n", + "isBlock": false }, "truncateWords": { "args": [ @@ -797,7 +886,8 @@ ], "numArgs": 3, "example": "{{truncateWords 'foo bar baz' 1 }} -> foo…", - "description": "

Truncate a string to have the specified number of words. Also see truncate.

\n" + "description": "

Truncate a string to have the specified number of words. Also see truncate.

\n", + "isBlock": false }, "upcase": { "args": [ @@ -805,7 +895,8 @@ ], "numArgs": 1, "example": "{{upcase 'aBcDef'}} -> ABCDEF", - "description": "

Uppercase all of the characters in the given string. Alias for uppercase.

\n" + "description": "

Uppercase all of the characters in the given string. Alias for uppercase.

\n", + "isBlock": false }, "uppercase": { "args": [ @@ -814,7 +905,8 @@ ], "numArgs": 2, "example": "{{uppercase 'aBcDef'}} -> ABCDEF", - "description": "

Uppercase all of the characters in the given string. If used as a block helper it will uppercase the entire block. This helper does not support inverse blocks.

\n" + "description": "

Uppercase all of the characters in the given string. If used as a block helper it will uppercase the entire block. This helper does not support inverse blocks.

\n", + "isBlock": true } }, "comparison": { @@ -826,7 +918,8 @@ ], "numArgs": 3, "example": "{{#and great magnificent}}both{{else}}no{{/and}} -> no", - "description": "

Helper that renders the block if both of the given values are truthy. If an inverse block is specified it will be rendered when falsy. Works as a block helper, inline helper or subexpression.

\n" + "description": "

Helper that renders the block if both of the given values are truthy. If an inverse block is specified it will be rendered when falsy. Works as a block helper, inline helper or subexpression.

\n", + "isBlock": true }, "compare": { "args": [ @@ -837,7 +930,8 @@ ], "numArgs": 4, "example": "{{compare 10 '<' 5 }} -> false", - "description": "

Render a block when a comparison of the first and third arguments returns true. The second argument is the [arithemetic operator][operators] to use. You may also optionally specify an inverse block to render when falsy.

\n" + "description": "

Render a block when a comparison of the first and third arguments returns true. The second argument is the [arithemetic operator][operators] to use. You may also optionally specify an inverse block to render when falsy.

\n", + "isBlock": true }, "contains": { "args": [ @@ -848,7 +942,8 @@ ], "numArgs": 4, "example": "{{#contains ['a', 'b', 'c'] 'd'}} This will not be rendered. {{else}} This will be rendered. {{/contains}} -> ' This will be rendered. '", - "description": "

Block helper that renders the block if collection has the given value, using strict equality (===) for comparison, otherwise the inverse block is rendered (if specified). If a startIndex is specified and is negative, it is used as the offset from the end of the collection.

\n" + "description": "

Block helper that renders the block if collection has the given value, using strict equality (===) for comparison, otherwise the inverse block is rendered (if specified). If a startIndex is specified and is negative, it is used as the offset from the end of the collection.

\n", + "isBlock": true }, "default": { "args": [ @@ -857,7 +952,8 @@ ], "numArgs": 2, "example": "{{default null null 'default'}} -> default", - "description": "

Returns the first value that is not undefined, otherwise the 'default' value is returned.

\n" + "description": "

Returns the first value that is not undefined, otherwise the 'default' value is returned.

\n", + "isBlock": false }, "eq": { "args": [ @@ -867,7 +963,8 @@ ], "numArgs": 3, "example": "{{#eq 3 3}}equal{{else}}not equal{{/eq}} -> equal", - "description": "

Block helper that renders a block if a is equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n" + "description": "

Block helper that renders a block if a is equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", + "isBlock": true }, "gt": { "args": [ @@ -877,7 +974,8 @@ ], "numArgs": 3, "example": "{{#gt 4 3}} greater than{{else}} not greater than{{/gt}} -> ' greater than'", - "description": "

Block helper that renders a block if a is greater than b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n" + "description": "

Block helper that renders a block if a is greater than b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", + "isBlock": true }, "gte": { "args": [ @@ -887,7 +985,8 @@ ], "numArgs": 3, "example": "{{#gte 4 3}} greater than or equal{{else}} not greater than{{/gte}} -> ' greater than or equal'", - "description": "

Block helper that renders a block if a is greater than or equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n" + "description": "

Block helper that renders a block if a is greater than or equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", + "isBlock": true }, "has": { "args": [ @@ -897,7 +996,8 @@ ], "numArgs": 3, "example": "{{#has 'foobar' 'foo'}}has it{{else}}doesn't{{/has}} -> has it", - "description": "

Block helper that renders a block if value has pattern. If an inverse block is specified it will be rendered when falsy.

\n" + "description": "

Block helper that renders a block if value has pattern. If an inverse block is specified it will be rendered when falsy.

\n", + "isBlock": true }, "isFalsey": { "args": [ @@ -906,7 +1006,8 @@ ], "numArgs": 2, "example": "{{isFalsey '' }} -> true", - "description": "

Returns true if the given value is falsey. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.

\n" + "description": "

Returns true if the given value is falsey. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.

\n", + "isBlock": false }, "isTruthy": { "args": [ @@ -915,7 +1016,8 @@ ], "numArgs": 2, "example": "{{isTruthy '12' }} -> true", - "description": "

Returns true if the given value is truthy. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.

\n" + "description": "

Returns true if the given value is truthy. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.

\n", + "isBlock": false }, "ifEven": { "args": [ @@ -924,7 +1026,8 @@ ], "numArgs": 2, "example": "{{#ifEven 2}} even {{else}} odd {{/ifEven}} -> ' even '", - "description": "

Return true if the given value is an even number.

\n" + "description": "

Return true if the given value is an even number.

\n", + "isBlock": true }, "ifNth": { "args": [ @@ -934,7 +1037,8 @@ ], "numArgs": 3, "example": "{{#ifNth 2 10}}remainder{{else}}no remainder{{/ifNth}} -> remainder", - "description": "

Conditionally renders a block if the remainder is zero when b operand is divided by a. If an inverse block is specified it will be rendered when the remainder is not zero.

\n" + "description": "

Conditionally renders a block if the remainder is zero when b operand is divided by a. If an inverse block is specified it will be rendered when the remainder is not zero.

\n", + "isBlock": true }, "ifOdd": { "args": [ @@ -943,7 +1047,8 @@ ], "numArgs": 2, "example": "{{#ifOdd 3}}odd{{else}}even{{/ifOdd}} -> odd", - "description": "

Block helper that renders a block if value is an odd number. If an inverse block is specified it will be rendered when falsy.

\n" + "description": "

Block helper that renders a block if value is an odd number. If an inverse block is specified it will be rendered when falsy.

\n", + "isBlock": true }, "is": { "args": [ @@ -953,7 +1058,8 @@ ], "numArgs": 3, "example": "{{#is 3 3}} is {{else}} is not {{/is}} -> ' is '", - "description": "

Block helper that renders a block if a is equal to b. If an inverse block is specified it will be rendered when falsy. Similar to eq but does not do strict equality.

\n" + "description": "

Block helper that renders a block if a is equal to b. If an inverse block is specified it will be rendered when falsy. Similar to eq but does not do strict equality.

\n", + "isBlock": true }, "isnt": { "args": [ @@ -963,7 +1069,8 @@ ], "numArgs": 3, "example": "{{#isnt 3 3}} isnt {{else}} is {{/isnt}} -> ' is '", - "description": "

Block helper that renders a block if a is not equal to b. If an inverse block is specified it will be rendered when falsy. Similar to unlessEq but does not use strict equality for comparisons.

\n" + "description": "

Block helper that renders a block if a is not equal to b. If an inverse block is specified it will be rendered when falsy. Similar to unlessEq but does not use strict equality for comparisons.

\n", + "isBlock": true }, "lt": { "args": [ @@ -972,7 +1079,8 @@ ], "numArgs": 2, "example": "{{#lt 2 3}} less than {{else}} more than or equal {{/lt}} -> ' less than '", - "description": "

Block helper that renders a block if a is less than b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n" + "description": "

Block helper that renders a block if a is less than b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", + "isBlock": true }, "lte": { "args": [ @@ -982,7 +1090,8 @@ ], "numArgs": 3, "example": "{{#lte 2 3}} less than or equal {{else}} more than {{/lte}} -> ' less than or equal '", - "description": "

Block helper that renders a block if a is less than or equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n" + "description": "

Block helper that renders a block if a is less than or equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", + "isBlock": true }, "neither": { "args": [ @@ -992,7 +1101,8 @@ ], "numArgs": 3, "example": "{{#neither null null}}both falsey{{else}}both not falsey{{/neither}} -> both falsey", - "description": "

Block helper that renders a block if neither of the given values are truthy. If an inverse block is specified it will be rendered when falsy.

\n" + "description": "

Block helper that renders a block if neither of the given values are truthy. If an inverse block is specified it will be rendered when falsy.

\n", + "isBlock": true }, "not": { "args": [ @@ -1001,7 +1111,8 @@ ], "numArgs": 2, "example": "{{#not undefined }}falsey{{else}}not falsey{{/not}} -> falsey", - "description": "

Returns true if val is falsey. Works as a block or inline helper.

\n" + "description": "

Returns true if val is falsey. Works as a block or inline helper.

\n", + "isBlock": true }, "or": { "args": [ @@ -1010,7 +1121,8 @@ ], "numArgs": 2, "example": "{{#or 1 2 undefined }} at least one truthy {{else}} all falsey {{/or}} -> ' at least one truthy '", - "description": "

Block helper that renders a block if any of the given values is truthy. If an inverse block is specified it will be rendered when falsy.

\n" + "description": "

Block helper that renders a block if any of the given values is truthy. If an inverse block is specified it will be rendered when falsy.

\n", + "isBlock": true }, "unlessEq": { "args": [ @@ -1020,7 +1132,8 @@ ], "numArgs": 3, "example": "{{#unlessEq 2 1 }} not equal {{else}} equal {{/unlessEq}} -> ' not equal '", - "description": "

Block helper that always renders the inverse block unless a is equal to b.

\n" + "description": "

Block helper that always renders the inverse block unless a is equal to b.

\n", + "isBlock": true }, "unlessGt": { "args": [ @@ -1030,7 +1143,8 @@ ], "numArgs": 3, "example": "{{#unlessGt 20 1 }} not greater than {{else}} greater than {{/unlessGt}} -> ' greater than '", - "description": "

Block helper that always renders the inverse block unless a is greater than b.

\n" + "description": "

Block helper that always renders the inverse block unless a is greater than b.

\n", + "isBlock": true }, "unlessLt": { "args": [ @@ -1040,7 +1154,8 @@ ], "numArgs": 3, "example": "{{#unlessLt 20 1 }}greater than or equal{{else}}less than{{/unlessLt}} -> greater than or equal", - "description": "

Block helper that always renders the inverse block unless a is less than b.

\n" + "description": "

Block helper that always renders the inverse block unless a is less than b.

\n", + "isBlock": true }, "unlessGteq": { "args": [ @@ -1050,7 +1165,8 @@ ], "numArgs": 3, "example": "{{#unlessGteq 20 1 }} less than {{else}}greater than or equal to{{/unlessGteq}} -> greater than or equal to", - "description": "

Block helper that always renders the inverse block unless a is greater than or equal to b.

\n" + "description": "

Block helper that always renders the inverse block unless a is greater than or equal to b.

\n", + "isBlock": true }, "unlessLteq": { "args": [ @@ -1060,7 +1176,8 @@ ], "numArgs": 3, "example": "{{#unlessLteq 20 1 }} greater than {{else}} less than or equal to {{/unlessLteq}} -> ' greater than '", - "description": "

Block helper that always renders the inverse block unless a is less than or equal to b.

\n" + "description": "

Block helper that always renders the inverse block unless a is less than or equal to b.

\n", + "isBlock": true } }, "object": { @@ -1069,7 +1186,8 @@ "objects" ], "numArgs": 1, - "description": "

Extend the context with the properties of other objects. A shallow merge is performed to avoid mutating the context.

\n" + "description": "

Extend the context with the properties of other objects. A shallow merge is performed to avoid mutating the context.

\n", + "isBlock": false }, "forIn": { "args": [ @@ -1077,7 +1195,8 @@ "options" ], "numArgs": 2, - "description": "

Block helper that iterates over the properties of an object, exposing each key and value on the context.

\n" + "description": "

Block helper that iterates over the properties of an object, exposing each key and value on the context.

\n", + "isBlock": true }, "forOwn": { "args": [ @@ -1085,14 +1204,16 @@ "options" ], "numArgs": 2, - "description": "

Block helper that iterates over the own properties of an object, exposing each key and value on the context.

\n" + "description": "

Block helper that iterates over the own properties of an object, exposing each key and value on the context.

\n", + "isBlock": true }, "toPath": { "args": [ "prop" ], "numArgs": 1, - "description": "

Take arguments and, if they are string or number, convert them to a dot-delineated object property path.

\n" + "description": "

Take arguments and, if they are string or number, convert them to a dot-delineated object property path.

\n", + "isBlock": false }, "get": { "args": [ @@ -1101,7 +1222,8 @@ "options" ], "numArgs": 3, - "description": "

Use property paths (a.b.c) to get a value or nested value from the context. Works as a regular helper or block helper.

\n" + "description": "

Use property paths (a.b.c) to get a value or nested value from the context. Works as a regular helper or block helper.

\n", + "isBlock": true }, "getObject": { "args": [ @@ -1109,7 +1231,8 @@ "context" ], "numArgs": 2, - "description": "

Use property paths (a.b.c) to get an object from the context. Differs from the get helper in that this helper will return the actual object, including the given property key. Also, this helper does not work as a block helper.

\n" + "description": "

Use property paths (a.b.c) to get an object from the context. Differs from the get helper in that this helper will return the actual object, including the given property key. Also, this helper does not work as a block helper.

\n", + "isBlock": false }, "hasOwn": { "args": [ @@ -1117,28 +1240,32 @@ "context" ], "numArgs": 2, - "description": "

Return true if key is an own, enumerable property of the given context object.

\n" + "description": "

Return true if key is an own, enumerable property of the given context object.

\n", + "isBlock": false }, "isObject": { "args": [ "value" ], "numArgs": 1, - "description": "

Return true if value is an object.

\n" + "description": "

Return true if value is an object.

\n", + "isBlock": false }, "JSONparse": { "args": [ "string" ], "numArgs": 1, - "description": "

Parses the given string using JSON.parse.

\n" + "description": "

Parses the given string using JSON.parse.

\n", + "isBlock": true }, "JSONstringify": { "args": [ "obj" ], "numArgs": 1, - "description": "

Stringify an object using JSON.stringify.

\n" + "description": "

Stringify an object using JSON.stringify.

\n", + "isBlock": false }, "merge": { "args": [ @@ -1146,14 +1273,16 @@ "objects" ], "numArgs": 2, - "description": "

Deeply merge the properties of the given objects with the context object.

\n" + "description": "

Deeply merge the properties of the given objects with the context object.

\n", + "isBlock": false }, "parseJSON": { "args": [ "string" ], "numArgs": 1, - "description": "

Parses the given string using JSON.parse.

\n" + "description": "

Parses the given string using JSON.parse.

\n", + "isBlock": true }, "pick": { "args": [ @@ -1162,14 +1291,16 @@ "options" ], "numArgs": 3, - "description": "

Pick properties from the context object.

\n" + "description": "

Pick properties from the context object.

\n", + "isBlock": true }, "stringify": { "args": [ "obj" ], "numArgs": 1, - "description": "

Stringify an object using JSON.stringify.

\n" + "description": "

Stringify an object using JSON.stringify.

\n", + "isBlock": false } }, "uuid": { @@ -1177,7 +1308,8 @@ "args": [], "numArgs": 0, "example": "{{ uuid }} -> f34ebc66-93bd-4f7c-b79b-92b5569138bc", - "description": "

Generates a UUID, using the V4 method (identical to the browser crypto.randomUUID function).

\n" + "description": "

Generates a UUID, using the V4 method (identical to the browser crypto.randomUUID function).

\n", + "isBlock": false } }, "date": { diff --git a/packages/string-templates/scripts/gen-collection-info.js b/packages/string-templates/scripts/gen-collection-info.js index b487c4dde4..004aee4778 100644 --- a/packages/string-templates/scripts/gen-collection-info.js +++ b/packages/string-templates/scripts/gen-collection-info.js @@ -115,6 +115,7 @@ function getCommentInfo(file, func) { docs.example = docs.example.replace("product", "multiply") } docs.description = blocks[0].trim() + docs.isBlock = docs.tags.some(el => el.title === "block") return docs } @@ -159,6 +160,7 @@ function run() { numArgs: args.length, example: jsDocInfo.example || undefined, description: jsDocInfo.description, + isBlock: jsDocInfo.isBlock, }) } outputJSON[collection] = collectionInfo From 061d1589afe9a4c5e38d8887b69d2531e13c1cff Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 30 Jan 2024 10:21:33 +0100 Subject: [PATCH 11/32] Run js only for non-block --- packages/string-templates/test/manifest.spec.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/string-templates/test/manifest.spec.js b/packages/string-templates/test/manifest.spec.js index ccfef3e50a..762726e2f3 100644 --- a/packages/string-templates/test/manifest.spec.js +++ b/packages/string-templates/test/manifest.spec.js @@ -58,7 +58,8 @@ const examples = collections.reduce((acc, collection) => { } } } - return [name, { hbs, js }] + const hasHbsBody = details.isBlock + return [name, { hbs, js, hasHbsBody }] }) .filter(x => !!x) @@ -108,7 +109,9 @@ describe("manifest", () => { describe("can be parsed and run as js", () => { describe.each(Object.keys(examples))("%s", collection => { - it.each(examples[collection])("%s", async (_, { hbs, js }) => { + it.each( + examples[collection].filter(([_, { hasHbsBody }]) => !hasHbsBody) + )("%s", async (_, { hbs, js }) => { const context = { double: i => i * 2, isString: x => typeof x === "string", From 669b0743ac5a6db0418f7d29333f0db27a558aaf Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 30 Jan 2024 10:00:44 +0000 Subject: [PATCH 12/32] Typing improvements around automation loop tests. --- packages/server/src/automations/automationUtils.ts | 5 +++-- packages/server/src/automations/tests/loop.spec.ts | 12 +++++++----- packages/server/src/definitions/automations.ts | 6 ++---- packages/server/src/tests/utilities/structures.ts | 8 ++++++-- packages/server/src/threads/automation.ts | 9 +++------ 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/packages/server/src/automations/automationUtils.ts b/packages/server/src/automations/automationUtils.ts index 3e25665a60..256f46f19f 100644 --- a/packages/server/src/automations/automationUtils.ts +++ b/packages/server/src/automations/automationUtils.ts @@ -5,7 +5,7 @@ import { } from "@budibase/string-templates" import sdk from "../sdk" import { Row } from "@budibase/types" -import { LoopStep, LoopStepType, LoopInput } from "../definitions/automations" +import { LoopStep, LoopStepType } from "../definitions/automations" /** * When values are input to the system generally they will be of type string as this is required for template strings. @@ -139,7 +139,8 @@ export function stringSplit(value: string | string[]) { return value } -export function typecastForLooping(loopStep: LoopStep, input: LoopInput) { +export function typecastForLooping(loopStep: LoopStep) { + const input = loopStep.inputs if (!input || !input.binding) { return null } diff --git a/packages/server/src/automations/tests/loop.spec.ts b/packages/server/src/automations/tests/loop.spec.ts index b64f7b16f8..70b771c445 100644 --- a/packages/server/src/automations/tests/loop.spec.ts +++ b/packages/server/src/automations/tests/loop.spec.ts @@ -3,11 +3,13 @@ import * as triggers from "../triggers" import { loopAutomation } from "../../tests/utilities/structures" import { context } from "@budibase/backend-core" import * as setup from "./utilities" +import { Row, Table } from "@budibase/types" +import { LoopInput, LoopStepType } from "../../definitions/automations" describe("Attempt to run a basic loop automation", () => { let config = setup.getConfig(), - table: any, - row: any + table: Table, + row: Row beforeEach(async () => { await automation.init() @@ -18,12 +20,12 @@ describe("Attempt to run a basic loop automation", () => { afterAll(setup.afterAll) - async function runLoop(loopOpts?: any) { + async function runLoop(loopOpts?: LoopInput) { const appId = config.getAppId() return await context.doInAppContext(appId, async () => { const params = { fields: { appId } } return await triggers.externalTrigger( - loopAutomation(table._id, loopOpts), + loopAutomation(table._id!, loopOpts), params, { getResponses: true } ) @@ -37,7 +39,7 @@ describe("Attempt to run a basic loop automation", () => { it("test a loop with a string", async () => { const resp = await runLoop({ - type: "String", + option: LoopStepType.STRING, binding: "a,b,c", }) expect(resp.steps[2].outputs.iterations).toBe(3) diff --git a/packages/server/src/definitions/automations.ts b/packages/server/src/definitions/automations.ts index 7e86608bf3..48a66408ca 100644 --- a/packages/server/src/definitions/automations.ts +++ b/packages/server/src/definitions/automations.ts @@ -6,13 +6,11 @@ export enum LoopStepType { } export interface LoopStep extends AutomationStep { - inputs: { - option: LoopStepType - [key: string]: any - } + inputs: LoopInput } export interface LoopInput { + option: LoopStepType binding: string[] | string } diff --git a/packages/server/src/tests/utilities/structures.ts b/packages/server/src/tests/utilities/structures.ts index b1c2c494a5..fe82311810 100644 --- a/packages/server/src/tests/utilities/structures.ts +++ b/packages/server/src/tests/utilities/structures.ts @@ -23,6 +23,7 @@ import { TableSourceType, Query, } from "@budibase/types" +import { LoopInput, LoopStepType } from "../../definitions/automations" const { BUILTIN_ROLE_IDS } = roles @@ -204,10 +205,13 @@ export function serverLogAutomation(appId?: string): Automation { } } -export function loopAutomation(tableId: string, loopOpts?: any): Automation { +export function loopAutomation( + tableId: string, + loopOpts?: LoopInput +): Automation { if (!loopOpts) { loopOpts = { - option: "Array", + option: LoopStepType.ARRAY, binding: "{{ steps.1.rows }}", } } diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 4447899f96..1c3f921147 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -23,7 +23,6 @@ import { } from "@budibase/types" import { AutomationContext, - LoopInput, LoopStep, TriggerOutput, } from "../definitions/automations" @@ -47,9 +46,8 @@ function getLoopIterations(loopStep: LoopStep) { if (!binding) { return 0 } - const isString = typeof binding === "string" try { - if (isString) { + if (typeof binding === "string") { binding = JSON.parse(binding) } } catch (err) { @@ -58,7 +56,7 @@ function getLoopIterations(loopStep: LoopStep) { if (Array.isArray(binding)) { return binding.length } - if (isString) { + if (typeof binding === "string") { return automationUtils.stringSplit(binding).length } return 0 @@ -331,8 +329,7 @@ class Orchestrator { } try { loopStep.inputs.binding = automationUtils.typecastForLooping( - loopStep as LoopStep, - loopStep.inputs as LoopInput + loopStep as LoopStep ) } catch (err) { this.updateContextAndOutput( From 67a848bb868530ab2d00af4c248d53c0670fe481 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 30 Jan 2024 10:23:11 +0000 Subject: [PATCH 13/32] Fix tests. --- packages/server/scripts/test.sh | 8 +-- .../unitTests/automationUtils.spec.ts | 50 +++++++++---------- .../server/src/definitions/automations.ts | 2 +- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/server/scripts/test.sh b/packages/server/scripts/test.sh index eb1cf67b01..7f871ac337 100644 --- a/packages/server/scripts/test.sh +++ b/packages/server/scripts/test.sh @@ -5,10 +5,10 @@ if [[ -n $CI ]] then # Running in ci, where resources are limited export NODE_OPTIONS="--max-old-space-size=4096" - echo "jest --coverage --maxWorkers=2 --forceExit --workerIdleMemoryLimit=2000MB --bail" - jest --coverage --maxWorkers=2 --forceExit --workerIdleMemoryLimit=2000MB --bail + echo "jest --coverage --maxWorkers=2 --forceExit --workerIdleMemoryLimit=2000MB --bail $@" + jest --coverage --maxWorkers=2 --forceExit --workerIdleMemoryLimit=2000MB --bail $@ else # --maxWorkers performs better in development - echo "jest --coverage --maxWorkers=2 --forceExit" - jest --coverage --maxWorkers=2 --forceExit + echo "jest --coverage --maxWorkers=2 --forceExit $@" + jest --coverage --maxWorkers=2 --forceExit $@ fi \ No newline at end of file diff --git a/packages/server/src/automations/unitTests/automationUtils.spec.ts b/packages/server/src/automations/unitTests/automationUtils.spec.ts index 2291df9bc2..af1dea4070 100644 --- a/packages/server/src/automations/unitTests/automationUtils.spec.ts +++ b/packages/server/src/automations/unitTests/automationUtils.spec.ts @@ -1,10 +1,15 @@ -const automationUtils = require("../automationUtils") +import { LoopStep, LoopStepType } from "../../definitions/automations" +import { + typecastForLooping, + cleanInputValues, + substituteLoopStep, +} from "../automationUtils" describe("automationUtils", () => { describe("substituteLoopStep", () => { it("should allow multiple loop binding substitutes", () => { expect( - automationUtils.substituteLoopStep( + substituteLoopStep( `{{ loop.currentItem._id }} {{ loop.currentItem._id }} {{ loop.currentItem._id }}`, "step.2" ) @@ -15,7 +20,7 @@ describe("automationUtils", () => { it("should handle not subsituting outside of curly braces", () => { expect( - automationUtils.substituteLoopStep( + substituteLoopStep( `loop {{ loop.currentItem._id }}loop loop{{ loop.currentItem._id }}loop`, "step.2" ) @@ -28,37 +33,32 @@ describe("automationUtils", () => { describe("typeCastForLooping", () => { it("should parse to correct type", () => { expect( - automationUtils.typecastForLooping( - { inputs: { option: "Array" } }, - { binding: [1, 2, 3] } - ) + typecastForLooping({ + inputs: { option: LoopStepType.ARRAY, binding: [1, 2, 3] }, + } as LoopStep) ).toEqual([1, 2, 3]) expect( - automationUtils.typecastForLooping( - { inputs: { option: "Array" } }, - { binding: "[1, 2, 3]" } - ) + typecastForLooping({ + inputs: { option: LoopStepType.ARRAY, binding: "[1,2,3]" }, + } as LoopStep) ).toEqual([1, 2, 3]) expect( - automationUtils.typecastForLooping( - { inputs: { option: "String" } }, - { binding: [1, 2, 3] } - ) + typecastForLooping({ + inputs: { option: LoopStepType.STRING, binding: [1, 2, 3] }, + } as LoopStep) ).toEqual("1,2,3") }) it("should handle null values", () => { // expect it to handle where the binding is null expect( - automationUtils.typecastForLooping( - { inputs: { option: "Array" } }, - { binding: null } - ) + typecastForLooping({ + inputs: { option: LoopStepType.ARRAY }, + } as LoopStep) ).toEqual(null) expect(() => - automationUtils.typecastForLooping( - { inputs: { option: "Array" } }, - { binding: "test" } - ) + typecastForLooping({ + inputs: { option: LoopStepType.ARRAY, binding: "test" }, + } as LoopStep) ).toThrow() }) }) @@ -80,7 +80,7 @@ describe("automationUtils", () => { }, } expect( - automationUtils.cleanInputValues( + cleanInputValues( { row: { relationship: `[{"_id": "ro_ta_users_us_3"}]`, @@ -113,7 +113,7 @@ describe("automationUtils", () => { }, } expect( - automationUtils.cleanInputValues( + cleanInputValues( { row: { relationship: `ro_ta_users_us_3`, diff --git a/packages/server/src/definitions/automations.ts b/packages/server/src/definitions/automations.ts index 48a66408ca..b0b25e5cfa 100644 --- a/packages/server/src/definitions/automations.ts +++ b/packages/server/src/definitions/automations.ts @@ -11,7 +11,7 @@ export interface LoopStep extends AutomationStep { export interface LoopInput { option: LoopStepType - binding: string[] | string + binding?: string[] | string | number[] } export interface TriggerOutput { From 456817ee7b582ce399b9970ce054ccaf1f79f396 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 30 Jan 2024 10:37:23 +0000 Subject: [PATCH 14/32] More loop step typing improvements. --- .../server/src/automations/automationUtils.ts | 7 +++--- .../unitTests/automationUtils.spec.ts | 22 +++++-------------- .../server/src/definitions/automations.ts | 2 ++ packages/server/src/threads/automation.ts | 12 +++++----- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/packages/server/src/automations/automationUtils.ts b/packages/server/src/automations/automationUtils.ts index 256f46f19f..227122bccc 100644 --- a/packages/server/src/automations/automationUtils.ts +++ b/packages/server/src/automations/automationUtils.ts @@ -5,7 +5,7 @@ import { } from "@budibase/string-templates" import sdk from "../sdk" import { Row } from "@budibase/types" -import { LoopStep, LoopStepType } from "../definitions/automations" +import { LoopInput, LoopStep, LoopStepType } from "../definitions/automations" /** * When values are input to the system generally they will be of type string as this is required for template strings. @@ -139,13 +139,12 @@ export function stringSplit(value: string | string[]) { return value } -export function typecastForLooping(loopStep: LoopStep) { - const input = loopStep.inputs +export function typecastForLooping(input: LoopInput) { if (!input || !input.binding) { return null } try { - switch (loopStep.inputs.option) { + switch (input.option) { case LoopStepType.ARRAY: if (typeof input.binding === "string") { return JSON.parse(input.binding) diff --git a/packages/server/src/automations/unitTests/automationUtils.spec.ts b/packages/server/src/automations/unitTests/automationUtils.spec.ts index af1dea4070..7de4a2e35b 100644 --- a/packages/server/src/automations/unitTests/automationUtils.spec.ts +++ b/packages/server/src/automations/unitTests/automationUtils.spec.ts @@ -33,32 +33,20 @@ describe("automationUtils", () => { describe("typeCastForLooping", () => { it("should parse to correct type", () => { expect( - typecastForLooping({ - inputs: { option: LoopStepType.ARRAY, binding: [1, 2, 3] }, - } as LoopStep) + typecastForLooping({ option: LoopStepType.ARRAY, binding: [1, 2, 3] }) ).toEqual([1, 2, 3]) expect( - typecastForLooping({ - inputs: { option: LoopStepType.ARRAY, binding: "[1,2,3]" }, - } as LoopStep) + typecastForLooping({ option: LoopStepType.ARRAY, binding: "[1,2,3]" }) ).toEqual([1, 2, 3]) expect( - typecastForLooping({ - inputs: { option: LoopStepType.STRING, binding: [1, 2, 3] }, - } as LoopStep) + typecastForLooping({ option: LoopStepType.STRING, binding: [1, 2, 3] }) ).toEqual("1,2,3") }) it("should handle null values", () => { // expect it to handle where the binding is null - expect( - typecastForLooping({ - inputs: { option: LoopStepType.ARRAY }, - } as LoopStep) - ).toEqual(null) + expect(typecastForLooping({ option: LoopStepType.ARRAY })).toEqual(null) expect(() => - typecastForLooping({ - inputs: { option: LoopStepType.ARRAY, binding: "test" }, - } as LoopStep) + typecastForLooping({ option: LoopStepType.ARRAY, binding: "test" }) ).toThrow() }) }) diff --git a/packages/server/src/definitions/automations.ts b/packages/server/src/definitions/automations.ts index b0b25e5cfa..c205149a5b 100644 --- a/packages/server/src/definitions/automations.ts +++ b/packages/server/src/definitions/automations.ts @@ -12,6 +12,8 @@ export interface LoopStep extends AutomationStep { export interface LoopInput { option: LoopStepType binding?: string[] | string | number[] + iterations?: string + failure?: any } export interface TriggerOutput { diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 1c3f921147..56d9280f31 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -23,6 +23,7 @@ import { } from "@budibase/types" import { AutomationContext, + LoopInput, LoopStep, TriggerOutput, } from "../definitions/automations" @@ -254,7 +255,7 @@ class Orchestrator { this._context.env = await sdkUtils.getEnvironmentVariables() let automation = this._automation let stopped = false - let loopStep: AutomationStep | undefined = undefined + let loopStep: LoopStep | undefined = undefined let stepCount = 0 let loopStepNumber: any = undefined @@ -309,7 +310,7 @@ class Orchestrator { stepCount++ if (step.stepId === LOOP_STEP_ID) { - loopStep = step + loopStep = step as LoopStep loopStepNumber = stepCount continue } @@ -329,7 +330,7 @@ class Orchestrator { } try { loopStep.inputs.binding = automationUtils.typecastForLooping( - loopStep as LoopStep + loopStep.inputs as LoopInput ) } catch (err) { this.updateContextAndOutput( @@ -345,7 +346,7 @@ class Orchestrator { loopStep = undefined break } - let item = [] + let item: any[] = [] if ( typeof loopStep.inputs.binding === "string" && loopStep.inputs.option === "String" @@ -396,7 +397,8 @@ class Orchestrator { if ( index === env.AUTOMATION_MAX_ITERATIONS || - index === parseInt(loopStep.inputs.iterations) + (loopStep.inputs.iterations && + index === parseInt(loopStep.inputs.iterations)) ) { this.updateContextAndOutput( loopStepNumber, From 72d63d0c006379096fcaa6a78992715d01978333 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 30 Jan 2024 10:13:45 +0000 Subject: [PATCH 15/32] Rename executeSynchronously to be a bit less confusing, as it does not execute synchronously. --- packages/server/src/automations/triggers.ts | 5 ++--- packages/server/src/threads/automation.ts | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/server/src/automations/triggers.ts b/packages/server/src/automations/triggers.ts index 17a33e4394..08e3199a11 100644 --- a/packages/server/src/automations/triggers.ts +++ b/packages/server/src/automations/triggers.ts @@ -9,7 +9,7 @@ import * as utils from "./utils" import env from "../environment" import { context, db as dbCore } from "@budibase/backend-core" import { Automation, Row, AutomationData, AutomationJob } from "@budibase/types" -import { executeSynchronously } from "../threads/automation" +import { executeInThread } from "../threads/automation" export const TRIGGER_DEFINITIONS = definitions const JOB_OPTS = { @@ -117,8 +117,7 @@ export async function externalTrigger( appId: context.getAppId(), automation, } - const job = { data } as AutomationJob - return executeSynchronously(job) + return executeInThread({ data } as AutomationJob) } else { return automationQueue.add(data, JOB_OPTS) } diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 56d9280f31..ed0203797d 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -614,7 +614,7 @@ export function execute(job: Job, callback: WorkerCallback) { }) } -export function executeSynchronously(job: Job) { +export async function executeInThread(job: Job) { const appId = job.data.event.appId if (!appId) { throw new Error("Unable to execute, event doesn't contain app ID.") @@ -626,10 +626,10 @@ export function executeSynchronously(job: Job) { }, job.data.event.timeout || 12000) }) - return context.doInAppContext(appId, async () => { + return await context.doInAppContext(appId, async () => { const envVars = await sdkUtils.getEnvironmentVariables() // put into automation thread for whole context - return context.doInEnvironmentContext(envVars, async () => { + return await context.doInEnvironmentContext(envVars, async () => { const automationOrchestrator = new Orchestrator(job) return await Promise.race([ automationOrchestrator.execute(), From b3c949b091fbd7a162e08ea75cebdc9ae9f431e8 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 30 Jan 2024 11:06:09 +0000 Subject: [PATCH 16/32] Fix case where if a binding returned an int it would throw an error. --- packages/server/src/automations/tests/loop.spec.ts | 8 ++++++++ packages/server/src/threads/automation.ts | 10 ++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/server/src/automations/tests/loop.spec.ts b/packages/server/src/automations/tests/loop.spec.ts index 70b771c445..68ab694c5d 100644 --- a/packages/server/src/automations/tests/loop.spec.ts +++ b/packages/server/src/automations/tests/loop.spec.ts @@ -44,4 +44,12 @@ describe("Attempt to run a basic loop automation", () => { }) expect(resp.steps[2].outputs.iterations).toBe(3) }) + + it("test a loop with a binding that returns an integer", async () => { + const resp = await runLoop({ + option: LoopStepType.ARRAY, + binding: "{{ 1 }}", + }) + expect(resp.steps[2].outputs.iterations).toBe(1) + }) }) diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index ed0203797d..a828af5d19 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -43,20 +43,18 @@ const CRON_STEP_ID = triggerDefs.CRON.stepId const STOPPED_STATUS = { success: true, status: AutomationStatus.STOPPED } function getLoopIterations(loopStep: LoopStep) { - let binding = loopStep.inputs.binding + const binding = loopStep.inputs.binding if (!binding) { return 0 } try { - if (typeof binding === "string") { - binding = JSON.parse(binding) + const json = typeof binding === "string" ? JSON.parse(binding) : binding + if (Array.isArray(json)) { + return json.length } } catch (err) { // ignore error - wasn't able to parse } - if (Array.isArray(binding)) { - return binding.length - } if (typeof binding === "string") { return automationUtils.stringSplit(binding).length } From 51aeda26ced1567afead1f33c659f3c8a3285302 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 30 Jan 2024 12:53:51 +0000 Subject: [PATCH 17/32] Fix for #12909 - the relationship modal was too small, cutting table names and making it hard to use, expanding the modal to be easier to use on normal screens. --- .../backend/Datasources/CreateEditRelationship.svelte | 1 + .../src/components/common/RelationshipSelector.svelte | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte index f9b688210a..91329525c3 100644 --- a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte @@ -373,6 +373,7 @@ confirmText="Save" onConfirm={saveRelationship} disabled={!valid} + size="L" >
Tables diff --git a/packages/builder/src/components/common/RelationshipSelector.svelte b/packages/builder/src/components/common/RelationshipSelector.svelte index 0636deaf08..63f0357a8f 100644 --- a/packages/builder/src/components/common/RelationshipSelector.svelte +++ b/packages/builder/src/components/common/RelationshipSelector.svelte @@ -17,7 +17,7 @@
-
+
From 710083d9fca049b2700d6afcd06b6c1bf7c47908 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 30 Jan 2024 15:12:09 +0100 Subject: [PATCH 18/32] Use require.resolve to get the manifest on generation --- packages/string-templates/scripts/gen-collection-info.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/string-templates/scripts/gen-collection-info.js b/packages/string-templates/scripts/gen-collection-info.js index 004aee4778..48bf503ade 100644 --- a/packages/string-templates/scripts/gen-collection-info.js +++ b/packages/string-templates/scripts/gen-collection-info.js @@ -10,8 +10,8 @@ const marked = require("marked") * https://github.com/budibase/handlebars-helpers */ const { join } = require("path") +const path = require("path") -const DIRECTORY = join(__dirname, "..", "..", "..") const COLLECTIONS = [ "math", "array", @@ -128,7 +128,7 @@ function run() { const foundNames = [] for (let collection of COLLECTIONS) { const collectionFile = fs.readFileSync( - `${DIRECTORY}/node_modules/${HELPER_LIBRARY}/lib/${collection}.js`, + `${path.dirname(require.resolve(HELPER_LIBRARY))}/lib/${collection}.js`, "utf8" ) const collectionInfo = {} From f94e1e105a866dd2688af339cf90fdf66d7b9b6d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 30 Jan 2024 15:49:18 +0100 Subject: [PATCH 19/32] Renames --- packages/string-templates/manifest.json | 266 +++++++++--------- .../scripts/gen-collection-info.js | 4 +- .../string-templates/test/manifest.spec.js | 8 +- 3 files changed, 140 insertions(+), 138 deletions(-) diff --git a/packages/string-templates/manifest.json b/packages/string-templates/manifest.json index cd787bc850..d06a01f606 100644 --- a/packages/string-templates/manifest.json +++ b/packages/string-templates/manifest.json @@ -7,7 +7,7 @@ "numArgs": 1, "example": "{{ abs 12012.1000 }} -> 12012.1", "description": "

Return the magnitude of a.

\n", - "isBlock": false + "requiresBlock": false }, "add": { "args": [ @@ -17,7 +17,7 @@ "numArgs": 2, "example": "{{ add 1 2 }} -> 3", "description": "

Return the sum of a plus b.

\n", - "isBlock": false + "requiresBlock": false }, "avg": { "args": [ @@ -26,7 +26,7 @@ "numArgs": 1, "example": "{{ avg 1 2 3 4 5 }} -> 3", "description": "

Returns the average of all numbers in the given array.

\n", - "isBlock": false + "requiresBlock": false }, "ceil": { "args": [ @@ -35,7 +35,7 @@ "numArgs": 1, "example": "{{ ceil 1.2 }} -> 2", "description": "

Get the Math.ceil() of the given value.

\n", - "isBlock": false + "requiresBlock": false }, "divide": { "args": [ @@ -45,7 +45,7 @@ "numArgs": 2, "example": "{{ divide 10 5 }} -> 2", "description": "

Divide a by b

\n", - "isBlock": false + "requiresBlock": false }, "floor": { "args": [ @@ -54,7 +54,7 @@ "numArgs": 1, "example": "{{ floor 1.2 }} -> 1", "description": "

Get the Math.floor() of the given value.

\n", - "isBlock": false + "requiresBlock": false }, "minus": { "args": [ @@ -64,7 +64,7 @@ "numArgs": 2, "example": "{{ subtract 10 5 }} -> 5", "description": "

Return the product of a minus b.

\n", - "isBlock": false + "requiresBlock": false }, "modulo": { "args": [ @@ -74,7 +74,7 @@ "numArgs": 2, "example": "{{ modulo 10 5 }} -> 0", "description": "

Get the remainder of a division operation.

\n", - "isBlock": false + "requiresBlock": false }, "multiply": { "args": [ @@ -84,7 +84,7 @@ "numArgs": 2, "example": "{{ multiply 10 5 }} -> 50", "description": "

Multiply number a by number b.

\n", - "isBlock": false + "requiresBlock": false }, "plus": { "args": [ @@ -94,7 +94,7 @@ "numArgs": 2, "example": "{{ plus 10 5 }} -> 15", "description": "

Add a by b.

\n", - "isBlock": false + "requiresBlock": false }, "random": { "args": [ @@ -104,7 +104,7 @@ "numArgs": 2, "example": "{{ random 0 20 }} -> 10", "description": "

Generate a random number between two values

\n", - "isBlock": false + "requiresBlock": false }, "remainder": { "args": [ @@ -114,7 +114,7 @@ "numArgs": 2, "example": "{{ remainder 10 6 }} -> 4", "description": "

Get the remainder when a is divided by b.

\n", - "isBlock": false + "requiresBlock": false }, "round": { "args": [ @@ -123,7 +123,7 @@ "numArgs": 1, "example": "{{ round 10.3 }} -> 10", "description": "

Round the given number.

\n", - "isBlock": false + "requiresBlock": false }, "subtract": { "args": [ @@ -133,7 +133,7 @@ "numArgs": 2, "example": "{{ subtract 10 5 }} -> 5", "description": "

Return the product of a minus b.

\n", - "isBlock": false + "requiresBlock": false }, "sum": { "args": [ @@ -142,7 +142,7 @@ "numArgs": 1, "example": "{{ sum [1, 2, 3] }} -> 6", "description": "

Returns the sum of all numbers in the given array.

\n", - "isBlock": false + "requiresBlock": false } }, "array": { @@ -154,7 +154,7 @@ "numArgs": 2, "example": "{{ after ['a', 'b', 'c', 'd'] 2}} -> ['c', 'd']", "description": "

Returns all of the items in an array after the specified index. Opposite of before.

\n", - "isBlock": false + "requiresBlock": false }, "arrayify": { "args": [ @@ -163,7 +163,7 @@ "numArgs": 1, "example": "{{ arrayify 'foo' }} -> ['foo']", "description": "

Cast the given value to an array.

\n", - "isBlock": false + "requiresBlock": false }, "before": { "args": [ @@ -173,7 +173,7 @@ "numArgs": 2, "example": "{{ before ['a', 'b', 'c', 'd'] 3}} -> ['a', 'b']", "description": "

Return all of the items in the collection before the specified count. Opposite of after.

\n", - "isBlock": false + "requiresBlock": false }, "eachIndex": { "args": [ @@ -183,7 +183,7 @@ "numArgs": 2, "example": "{{#eachIndex [1, 2, 3]}} {{item}} is {{index}} {{/eachIndex}} -> ' 1 is 0 2 is 1 3 is 2 '", "description": "

Iterates the array, listing an item and the index of it.

\n", - "isBlock": true + "requiresBlock": true }, "filter": { "args": [ @@ -194,7 +194,7 @@ "numArgs": 3, "example": "{{#filter [1, 2, 3] 2}}2 Found{{else}}2 not found{{/filter}} -> 2 Found", "description": "

Block helper that filters the given array and renders the block for values that evaluate to true, otherwise the inverse block is returned.

\n", - "isBlock": true + "requiresBlock": true }, "first": { "args": [ @@ -204,7 +204,7 @@ "numArgs": 2, "example": "{{first [1, 2, 3, 4] 2}} -> 1,2", "description": "

Returns the first item, or first n items of an array.

\n", - "isBlock": false + "requiresBlock": false }, "forEach": { "args": [ @@ -214,7 +214,7 @@ "numArgs": 2, "example": "{{#forEach [{ 'name': 'John' }] }} {{ name }} {{/forEach}} -> ' John '", "description": "

Iterates over each item in an array and exposes the current item in the array as context to the inner block. In addition to the current array item, the helper exposes the following variables to the inner block: - index - total - isFirst - isLast Also, @index is exposed as a private variable, and additional private variables may be defined as hash arguments.

\n", - "isBlock": true + "requiresBlock": true }, "inArray": { "args": [ @@ -225,7 +225,7 @@ "numArgs": 3, "example": "{{#inArray [1, 2, 3] 2}} 2 exists {{else}} 2 does not exist {{/inArray}} -> ' 2 exists '", "description": "

Block helper that renders the block if an array has the given value. Optionally specify an inverse block to render when the array does not have the given value.

\n", - "isBlock": true + "requiresBlock": true }, "isArray": { "args": [ @@ -234,7 +234,7 @@ "numArgs": 1, "example": "{{isArray [1, 2]}} -> true", "description": "

Returns true if value is an es5 array.

\n", - "isBlock": false + "requiresBlock": false }, "itemAt": { "args": [ @@ -244,7 +244,7 @@ "numArgs": 2, "example": "{{itemAt [1, 2, 3] 1}} -> 2", "description": "

Returns the item from array at index idx.

\n", - "isBlock": false + "requiresBlock": false }, "join": { "args": [ @@ -254,7 +254,7 @@ "numArgs": 2, "example": "{{join [1, 2, 3]}} -> 1, 2, 3", "description": "

Join all elements of array into a string, optionally using a given separator.

\n", - "isBlock": false + "requiresBlock": false }, "equalsLength": { "args": [ @@ -264,7 +264,7 @@ "numArgs": 2, "example": "{{equalsLength [1, 2, 3] 3}} -> true", "description": "

Returns true if the the length of the given value is equal to the given length. Can be used as a block or inline helper.

\n", - "isBlock": true + "requiresBlock": true }, "last": { "args": [ @@ -274,7 +274,7 @@ "numArgs": 2, "example": "{{last [1, 2, 3]}} -> 3", "description": "

Returns the last item, or last n items of an array or string. Opposite of first.

\n", - "isBlock": false + "requiresBlock": false }, "length": { "args": [ @@ -283,7 +283,7 @@ "numArgs": 1, "example": "{{length [1, 2, 3]}} -> 3", "description": "

Returns the length of the given string or array.

\n", - "isBlock": false + "requiresBlock": false }, "lengthEqual": { "args": [ @@ -293,7 +293,7 @@ "numArgs": 2, "example": "{{equalsLength [1, 2, 3] 3}} -> true", "description": "

Returns true if the the length of the given value is equal to the given length. Can be used as a block or inline helper.

\n", - "isBlock": true + "requiresBlock": true }, "map": { "args": [ @@ -303,7 +303,7 @@ "numArgs": 2, "example": "{{map [1, 2, 3] double}} -> [2, 4, 6]", "description": "

Returns a new array, created by calling function on each element of the given array. For example,

\n", - "isBlock": false + "requiresBlock": false }, "pluck": { "args": [ @@ -313,7 +313,7 @@ "numArgs": 2, "example": "{{pluck [{ 'name': 'Bob' }] 'name' }} -> ['Bob']", "description": "

Map over the given object or array or objects and create an array of values from the given prop. Dot-notation may be used (as a string) to get nested properties.

\n", - "isBlock": false + "requiresBlock": false }, "reverse": { "args": [ @@ -322,7 +322,7 @@ "numArgs": 1, "example": "{{reverse [1, 2, 3]}} -> [3, 2, 1]", "description": "

Reverse the elements in an array, or the characters in a string.

\n", - "isBlock": false + "requiresBlock": false }, "some": { "args": [ @@ -333,7 +333,7 @@ "numArgs": 3, "example": "{{#some [1, \"b\", 3] isString}} string found {{else}} No string found {{/some}} -> ' string found '", "description": "

Block helper that returns the block if the callback returns true for some value in the given array.

\n", - "isBlock": true + "requiresBlock": true }, "sort": { "args": [ @@ -343,7 +343,7 @@ "numArgs": 2, "example": "{{ sort ['b', 'a', 'c'] }} -> ['a', 'b', 'c']", "description": "

Sort the given array. If an array of objects is passed, you may optionally pass a key to sort on as the second argument. You may alternatively pass a sorting function as the second argument.

\n", - "isBlock": false + "requiresBlock": false }, "sortBy": { "args": [ @@ -353,7 +353,7 @@ "numArgs": 2, "example": "{{ sortBy [{'a': 'zzz'}, {'a': 'aaa'}] 'a' }} -> [{'a':'aaa'},{'a':'zzz'}]", "description": "

Sort an array. If an array of objects is passed, you may optionally pass a key to sort on as the second argument. You may alternatively pass a sorting function as the second argument.

\n", - "isBlock": false + "requiresBlock": false }, "withAfter": { "args": [ @@ -364,7 +364,7 @@ "numArgs": 3, "example": "{{#withAfter [1, 2, 3] 1 }} {{this}} {{/withAfter}} -> ' 2 3 '", "description": "

Use the items in the array after the specified index as context inside a block. Opposite of withBefore.

\n", - "isBlock": true + "requiresBlock": true }, "withBefore": { "args": [ @@ -375,7 +375,7 @@ "numArgs": 3, "example": "{{#withBefore [1, 2, 3] 2 }} {{this}} {{/withBefore}} -> ' 1 '", "description": "

Use the items in the array before the specified index as context inside a block. Opposite of withAfter.

\n", - "isBlock": true + "requiresBlock": true }, "withFirst": { "args": [ @@ -386,7 +386,7 @@ "numArgs": 3, "example": "{{#withFirst [1, 2, 3] }}{{this}}{{/withFirst}} -> 1", "description": "

Use the first item in a collection inside a handlebars block expression. Opposite of withLast.

\n", - "isBlock": true + "requiresBlock": true }, "withGroup": { "args": [ @@ -397,7 +397,7 @@ "numArgs": 3, "example": "{{#withGroup [1, 2, 3, 4] 2}}{{#each this}}{{.}}{{/each}}
{{/withGroup}} -> 12
34
", "description": "

Block helper that groups array elements by given group size.

\n", - "isBlock": true + "requiresBlock": true }, "withLast": { "args": [ @@ -408,7 +408,7 @@ "numArgs": 3, "example": "{{#withLast [1, 2, 3, 4]}}{{this}}{{/withLast}} -> 4", "description": "

Use the last item or n items in an array as context inside a block. Opposite of withFirst.

\n", - "isBlock": true + "requiresBlock": true }, "withSort": { "args": [ @@ -419,7 +419,7 @@ "numArgs": 3, "example": "{{#withSort ['b', 'a', 'c']}}{{this}}{{/withSort}} -> abc", "description": "

Block helper that sorts a collection and exposes the sorted collection as context inside the block.

\n", - "isBlock": true + "requiresBlock": true }, "unique": { "args": [ @@ -429,7 +429,7 @@ "numArgs": 2, "example": "{{#each (unique ['a', 'a', 'c', 'b', 'e', 'e']) }}{{.}}{{/each}} -> acbe", "description": "

Block helper that return an array with all duplicate values removed. Best used along with a each helper.

\n", - "isBlock": true + "requiresBlock": true } }, "number": { @@ -440,7 +440,7 @@ "numArgs": 1, "example": "{{ bytes 1386 1 }} -> 1.4 kB", "description": "

Format a number to it's equivalent in bytes. If a string is passed, it's length will be formatted and returned. Examples: - 'foo' => 3 B - 13661855 => 13.66 MB - 825399 => 825.39 kB - 1396 => 1.4 kB

\n", - "isBlock": false + "requiresBlock": false }, "addCommas": { "args": [ @@ -449,7 +449,7 @@ "numArgs": 1, "example": "{{ addCommas 1000000 }} -> 1,000,000", "description": "

Add commas to numbers

\n", - "isBlock": false + "requiresBlock": false }, "phoneNumber": { "args": [ @@ -458,7 +458,7 @@ "numArgs": 1, "example": "{{ phoneNumber 8005551212 }} -> (800) 555-1212", "description": "

Convert a string or number to a formatted phone number.

\n", - "isBlock": false + "requiresBlock": false }, "toAbbr": { "args": [ @@ -468,7 +468,7 @@ "numArgs": 2, "example": "{{ toAbbr 10123 2 }} -> 10.12k", "description": "

Abbreviate numbers to the given number of precision. This for general numbers, not size in bytes.

\n", - "isBlock": false + "requiresBlock": false }, "toExponential": { "args": [ @@ -478,7 +478,7 @@ "numArgs": 2, "example": "{{ toExponential 10123 2 }} -> 1.01e+4", "description": "

Returns a string representing the given number in exponential notation.

\n", - "isBlock": false + "requiresBlock": false }, "toFixed": { "args": [ @@ -488,7 +488,7 @@ "numArgs": 2, "example": "{{ toFixed 1.1234 2 }} -> 1.12", "description": "

Formats the given number using fixed-point notation.

\n", - "isBlock": false + "requiresBlock": false }, "toFloat": { "args": [ @@ -496,7 +496,7 @@ ], "numArgs": 1, "description": "

Convert input to a float.

\n", - "isBlock": false + "requiresBlock": false }, "toInt": { "args": [ @@ -504,7 +504,7 @@ ], "numArgs": 1, "description": "

Convert input to an integer.

\n", - "isBlock": false + "requiresBlock": false }, "toPrecision": { "args": [ @@ -514,7 +514,7 @@ "numArgs": 2, "example": "{{toPrecision '1.1234' 2}} -> 1.1", "description": "

Returns a string representing the Number object to the specified precision.

\n", - "isBlock": false + "requiresBlock": false } }, "url": { @@ -525,7 +525,7 @@ "numArgs": 1, "example": "{{ encodeURI 'https://myurl?Hello There' }} -> https%3A%2F%2Fmyurl%3FHello%20There", "description": "

Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.

\n", - "isBlock": false + "requiresBlock": false }, "escape": { "args": [ @@ -534,7 +534,7 @@ "numArgs": 1, "example": "{{ escape 'https://myurl?Hello+There' }} -> https%3A%2F%2Fmyurl%3FHello%2BThere", "description": "

Escape the given string by replacing characters with escape sequences. Useful for allowing the string to be used in a URL, etc.

\n", - "isBlock": false + "requiresBlock": false }, "decodeURI": { "args": [ @@ -543,7 +543,7 @@ "numArgs": 1, "example": "{{ decodeURI 'https://myurl?Hello%20There' }} -> https://myurl?Hello There", "description": "

Decode a Uniform Resource Identifier (URI) component.

\n", - "isBlock": false + "requiresBlock": false }, "urlResolve": { "args": [ @@ -553,7 +553,7 @@ "numArgs": 2, "example": "{{ urlResolve 'https://myurl' '/api/test' }} -> https://myurl/api/test", "description": "

Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.

\n", - "isBlock": false + "requiresBlock": false }, "urlParse": { "args": [ @@ -562,7 +562,7 @@ "numArgs": 1, "example": "{{ urlParse 'https://myurl/api/test' }}", "description": "

Parses a url string into an object.

\n", - "isBlock": false + "requiresBlock": false }, "stripQuerystring": { "args": [ @@ -571,7 +571,7 @@ "numArgs": 1, "example": "{{ stripQuerystring 'https://myurl/api/test?foo=bar' }} -> 'https://myurl/api/test'", "description": "

Strip the query string from the given url.

\n", - "isBlock": false + "requiresBlock": false }, "stripProtocol": { "args": [ @@ -580,7 +580,7 @@ "numArgs": 1, "example": "{{ stripProtocol 'https://myurl/api/test' }} -> '//myurl/api/test'", "description": "

Strip protocol from a url. Useful for displaying media that may have an 'http' protocol on secure connections.

\n", - "isBlock": false + "requiresBlock": false } }, "string": { @@ -592,7 +592,7 @@ "numArgs": 2, "example": "{{append 'index' '.html'}} -> index.html", "description": "

Append the specified suffix to the given string.

\n", - "isBlock": false + "requiresBlock": false }, "camelcase": { "args": [ @@ -601,7 +601,7 @@ "numArgs": 1, "example": "{{camelcase 'foo bar baz'}} -> fooBarBaz", "description": "

camelCase the characters in the given string.

\n", - "isBlock": false + "requiresBlock": false }, "capitalize": { "args": [ @@ -610,7 +610,7 @@ "numArgs": 1, "example": "{{capitalize 'foo bar baz'}} -> Foo bar baz", "description": "

Capitalize the first word in a sentence.

\n", - "isBlock": false + "requiresBlock": false }, "capitalizeAll": { "args": [ @@ -619,7 +619,7 @@ "numArgs": 1, "example": "{{ capitalizeAll 'foo bar baz'}} -> Foo Bar Baz", "description": "

Capitalize all words in a string.

\n", - "isBlock": false + "requiresBlock": false }, "center": { "args": [ @@ -629,7 +629,7 @@ "numArgs": 2, "example": "{{ center 'test' 1}} -> ' test '", "description": "

Center a string using non-breaking spaces

\n", - "isBlock": false + "requiresBlock": false }, "chop": { "args": [ @@ -638,7 +638,7 @@ "numArgs": 1, "example": "{{ chop ' ABC '}} -> ABC", "description": "

Like trim, but removes both extraneous whitespace and non-word characters from the beginning and end of a string.

\n", - "isBlock": false + "requiresBlock": false }, "dashcase": { "args": [ @@ -647,7 +647,7 @@ "numArgs": 1, "example": "{{dashcase 'a-b-c d_e'}} -> a-b-c-d-e", "description": "

dash-case the characters in string. Replaces non-word characters and periods with hyphens.

\n", - "isBlock": false + "requiresBlock": false }, "dotcase": { "args": [ @@ -656,7 +656,7 @@ "numArgs": 1, "example": "{{dotcase 'a-b-c d_e'}} -> a.b.c.d.e", "description": "

dot.case the characters in string.

\n", - "isBlock": false + "requiresBlock": false }, "downcase": { "args": [ @@ -665,7 +665,7 @@ "numArgs": 1, "example": "{{downcase 'aBcDeF'}} -> abcdef", "description": "

Lowercase all of the characters in the given string. Alias for lowercase.

\n", - "isBlock": false + "requiresBlock": false }, "ellipsis": { "args": [ @@ -675,7 +675,7 @@ "numArgs": 2, "example": "{{ellipsis 'foo bar baz' 7}} -> foo bar…", "description": "

Truncates a string to the specified length, and appends it with an elipsis, .

\n", - "isBlock": false + "requiresBlock": false }, "hyphenate": { "args": [ @@ -684,7 +684,7 @@ "numArgs": 1, "example": "{{hyphenate 'foo bar baz qux'}} -> foo-bar-baz-qux", "description": "

Replace spaces in a string with hyphens.

\n", - "isBlock": false + "requiresBlock": false }, "isString": { "args": [ @@ -693,7 +693,7 @@ "numArgs": 1, "example": "{{isString 'foo'}} -> true", "description": "

Return true if value is a string.

\n", - "isBlock": false + "requiresBlock": false }, "lowercase": { "args": [ @@ -702,7 +702,7 @@ "numArgs": 1, "example": "{{lowercase 'Foo BAR baZ'}} -> foo bar baz", "description": "

Lowercase all characters in the given string.

\n", - "isBlock": false + "requiresBlock": false }, "occurrences": { "args": [ @@ -712,7 +712,7 @@ "numArgs": 2, "example": "{{occurrences 'foo bar foo bar baz' 'foo'}} -> 2", "description": "

Return the number of occurrences of substring within the given string.

\n", - "isBlock": false + "requiresBlock": false }, "pascalcase": { "args": [ @@ -721,7 +721,7 @@ "numArgs": 1, "example": "{{pascalcase 'foo bar baz'}} -> FooBarBaz", "description": "

PascalCase the characters in string.

\n", - "isBlock": false + "requiresBlock": false }, "pathcase": { "args": [ @@ -730,7 +730,7 @@ "numArgs": 1, "example": "{{pathcase 'a-b-c d_e'}} -> a/b/c/d/e", "description": "

path/case the characters in string.

\n", - "isBlock": false + "requiresBlock": false }, "plusify": { "args": [ @@ -739,7 +739,7 @@ "numArgs": 1, "example": "{{plusify 'foo bar baz'}} -> foo+bar+baz", "description": "

Replace spaces in the given string with pluses.

\n", - "isBlock": false + "requiresBlock": false }, "prepend": { "args": [ @@ -749,7 +749,7 @@ "numArgs": 2, "example": "{{prepend 'bar' 'foo-'}} -> foo-bar", "description": "

Prepends the given string with the specified prefix.

\n", - "isBlock": false + "requiresBlock": false }, "remove": { "args": [ @@ -759,7 +759,7 @@ "numArgs": 2, "example": "{{remove 'a b a b a b' 'a '}} -> b b b", "description": "

Remove all occurrences of substring from the given str.

\n", - "isBlock": false + "requiresBlock": false }, "removeFirst": { "args": [ @@ -769,7 +769,7 @@ "numArgs": 2, "example": "{{removeFirst 'a b a b a b' 'a'}} -> ' b a b a b'", "description": "

Remove the first occurrence of substring from the given str.

\n", - "isBlock": false + "requiresBlock": false }, "replace": { "args": [ @@ -780,7 +780,7 @@ "numArgs": 3, "example": "{{replace 'a b a b a b' 'a' 'z'}} -> z b z b z b", "description": "

Replace all occurrences of substring a with substring b.

\n", - "isBlock": false + "requiresBlock": false }, "replaceFirst": { "args": [ @@ -791,7 +791,7 @@ "numArgs": 3, "example": "{{replaceFirst 'a b a b a b' 'a' 'z'}} -> z b a b a b", "description": "

Replace the first occurrence of substring a with substring b.

\n", - "isBlock": false + "requiresBlock": false }, "sentence": { "args": [ @@ -800,7 +800,7 @@ "numArgs": 1, "example": "{{sentence 'hello world. goodbye world.'}} -> Hello world. Goodbye world.", "description": "

Sentence case the given string

\n", - "isBlock": false + "requiresBlock": false }, "snakecase": { "args": [ @@ -809,7 +809,7 @@ "numArgs": 1, "example": "{{snakecase 'a-b-c d_e'}} -> a_b_c_d_e", "description": "

snake_case the characters in the given string.

\n", - "isBlock": false + "requiresBlock": false }, "split": { "args": [ @@ -818,7 +818,7 @@ "numArgs": 1, "example": "{{split 'a,b,c'}} -> ['a', 'b', 'c']", "description": "

Split string by the given character.

\n", - "isBlock": false + "requiresBlock": false }, "startsWith": { "args": [ @@ -829,7 +829,7 @@ "numArgs": 3, "example": "{{#startsWith 'Goodbye' 'Hello, world!'}}Yep{{else}}Nope{{/startsWith}} -> Nope", "description": "

Tests whether a string begins with the given prefix.

\n", - "isBlock": true + "requiresBlock": true }, "titleize": { "args": [ @@ -838,7 +838,7 @@ "numArgs": 1, "example": "{{titleize 'this is title case' }} -> This Is Title Case", "description": "

Title case the given string.

\n", - "isBlock": false + "requiresBlock": false }, "trim": { "args": [ @@ -847,7 +847,7 @@ "numArgs": 1, "example": "{{trim ' ABC ' }} -> ABC", "description": "

Removes extraneous whitespace from the beginning and end of a string.

\n", - "isBlock": false + "requiresBlock": false }, "trimLeft": { "args": [ @@ -856,7 +856,7 @@ "numArgs": 1, "example": "{{trimLeft ' ABC ' }} -> 'ABC '", "description": "

Removes extraneous whitespace from the beginning of a string.

\n", - "isBlock": false + "requiresBlock": false }, "trimRight": { "args": [ @@ -865,7 +865,7 @@ "numArgs": 1, "example": "{{trimRight ' ABC ' }} -> ' ABC'", "description": "

Removes extraneous whitespace from the end of a string.

\n", - "isBlock": false + "requiresBlock": false }, "truncate": { "args": [ @@ -876,7 +876,7 @@ "numArgs": 3, "example": "{{truncate 'foo bar baz' 7 }} -> foo bar", "description": "

Truncate a string to the specified length. Also see ellipsis.

\n", - "isBlock": false + "requiresBlock": false }, "truncateWords": { "args": [ @@ -887,7 +887,7 @@ "numArgs": 3, "example": "{{truncateWords 'foo bar baz' 1 }} -> foo…", "description": "

Truncate a string to have the specified number of words. Also see truncate.

\n", - "isBlock": false + "requiresBlock": false }, "upcase": { "args": [ @@ -896,7 +896,7 @@ "numArgs": 1, "example": "{{upcase 'aBcDef'}} -> ABCDEF", "description": "

Uppercase all of the characters in the given string. Alias for uppercase.

\n", - "isBlock": false + "requiresBlock": false }, "uppercase": { "args": [ @@ -906,7 +906,7 @@ "numArgs": 2, "example": "{{uppercase 'aBcDef'}} -> ABCDEF", "description": "

Uppercase all of the characters in the given string. If used as a block helper it will uppercase the entire block. This helper does not support inverse blocks.

\n", - "isBlock": true + "requiresBlock": true } }, "comparison": { @@ -919,7 +919,7 @@ "numArgs": 3, "example": "{{#and great magnificent}}both{{else}}no{{/and}} -> no", "description": "

Helper that renders the block if both of the given values are truthy. If an inverse block is specified it will be rendered when falsy. Works as a block helper, inline helper or subexpression.

\n", - "isBlock": true + "requiresBlock": true }, "compare": { "args": [ @@ -931,7 +931,7 @@ "numArgs": 4, "example": "{{compare 10 '<' 5 }} -> false", "description": "

Render a block when a comparison of the first and third arguments returns true. The second argument is the [arithemetic operator][operators] to use. You may also optionally specify an inverse block to render when falsy.

\n", - "isBlock": true + "requiresBlock": true }, "contains": { "args": [ @@ -943,7 +943,7 @@ "numArgs": 4, "example": "{{#contains ['a', 'b', 'c'] 'd'}} This will not be rendered. {{else}} This will be rendered. {{/contains}} -> ' This will be rendered. '", "description": "

Block helper that renders the block if collection has the given value, using strict equality (===) for comparison, otherwise the inverse block is rendered (if specified). If a startIndex is specified and is negative, it is used as the offset from the end of the collection.

\n", - "isBlock": true + "requiresBlock": true }, "default": { "args": [ @@ -953,7 +953,7 @@ "numArgs": 2, "example": "{{default null null 'default'}} -> default", "description": "

Returns the first value that is not undefined, otherwise the 'default' value is returned.

\n", - "isBlock": false + "requiresBlock": false }, "eq": { "args": [ @@ -964,7 +964,7 @@ "numArgs": 3, "example": "{{#eq 3 3}}equal{{else}}not equal{{/eq}} -> equal", "description": "

Block helper that renders a block if a is equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", - "isBlock": true + "requiresBlock": true }, "gt": { "args": [ @@ -975,7 +975,7 @@ "numArgs": 3, "example": "{{#gt 4 3}} greater than{{else}} not greater than{{/gt}} -> ' greater than'", "description": "

Block helper that renders a block if a is greater than b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", - "isBlock": true + "requiresBlock": true }, "gte": { "args": [ @@ -986,7 +986,7 @@ "numArgs": 3, "example": "{{#gte 4 3}} greater than or equal{{else}} not greater than{{/gte}} -> ' greater than or equal'", "description": "

Block helper that renders a block if a is greater than or equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", - "isBlock": true + "requiresBlock": true }, "has": { "args": [ @@ -997,7 +997,7 @@ "numArgs": 3, "example": "{{#has 'foobar' 'foo'}}has it{{else}}doesn't{{/has}} -> has it", "description": "

Block helper that renders a block if value has pattern. If an inverse block is specified it will be rendered when falsy.

\n", - "isBlock": true + "requiresBlock": true }, "isFalsey": { "args": [ @@ -1007,7 +1007,7 @@ "numArgs": 2, "example": "{{isFalsey '' }} -> true", "description": "

Returns true if the given value is falsey. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.

\n", - "isBlock": false + "requiresBlock": false }, "isTruthy": { "args": [ @@ -1017,7 +1017,7 @@ "numArgs": 2, "example": "{{isTruthy '12' }} -> true", "description": "

Returns true if the given value is truthy. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.

\n", - "isBlock": false + "requiresBlock": false }, "ifEven": { "args": [ @@ -1027,7 +1027,7 @@ "numArgs": 2, "example": "{{#ifEven 2}} even {{else}} odd {{/ifEven}} -> ' even '", "description": "

Return true if the given value is an even number.

\n", - "isBlock": true + "requiresBlock": true }, "ifNth": { "args": [ @@ -1038,7 +1038,7 @@ "numArgs": 3, "example": "{{#ifNth 2 10}}remainder{{else}}no remainder{{/ifNth}} -> remainder", "description": "

Conditionally renders a block if the remainder is zero when b operand is divided by a. If an inverse block is specified it will be rendered when the remainder is not zero.

\n", - "isBlock": true + "requiresBlock": true }, "ifOdd": { "args": [ @@ -1048,7 +1048,7 @@ "numArgs": 2, "example": "{{#ifOdd 3}}odd{{else}}even{{/ifOdd}} -> odd", "description": "

Block helper that renders a block if value is an odd number. If an inverse block is specified it will be rendered when falsy.

\n", - "isBlock": true + "requiresBlock": true }, "is": { "args": [ @@ -1059,7 +1059,7 @@ "numArgs": 3, "example": "{{#is 3 3}} is {{else}} is not {{/is}} -> ' is '", "description": "

Block helper that renders a block if a is equal to b. If an inverse block is specified it will be rendered when falsy. Similar to eq but does not do strict equality.

\n", - "isBlock": true + "requiresBlock": true }, "isnt": { "args": [ @@ -1070,7 +1070,7 @@ "numArgs": 3, "example": "{{#isnt 3 3}} isnt {{else}} is {{/isnt}} -> ' is '", "description": "

Block helper that renders a block if a is not equal to b. If an inverse block is specified it will be rendered when falsy. Similar to unlessEq but does not use strict equality for comparisons.

\n", - "isBlock": true + "requiresBlock": true }, "lt": { "args": [ @@ -1080,7 +1080,7 @@ "numArgs": 2, "example": "{{#lt 2 3}} less than {{else}} more than or equal {{/lt}} -> ' less than '", "description": "

Block helper that renders a block if a is less than b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", - "isBlock": true + "requiresBlock": true }, "lte": { "args": [ @@ -1091,7 +1091,7 @@ "numArgs": 3, "example": "{{#lte 2 3}} less than or equal {{else}} more than {{/lte}} -> ' less than or equal '", "description": "

Block helper that renders a block if a is less than or equal to b. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare='' hash argument for the second value.

\n", - "isBlock": true + "requiresBlock": true }, "neither": { "args": [ @@ -1102,7 +1102,7 @@ "numArgs": 3, "example": "{{#neither null null}}both falsey{{else}}both not falsey{{/neither}} -> both falsey", "description": "

Block helper that renders a block if neither of the given values are truthy. If an inverse block is specified it will be rendered when falsy.

\n", - "isBlock": true + "requiresBlock": true }, "not": { "args": [ @@ -1112,7 +1112,7 @@ "numArgs": 2, "example": "{{#not undefined }}falsey{{else}}not falsey{{/not}} -> falsey", "description": "

Returns true if val is falsey. Works as a block or inline helper.

\n", - "isBlock": true + "requiresBlock": true }, "or": { "args": [ @@ -1122,7 +1122,7 @@ "numArgs": 2, "example": "{{#or 1 2 undefined }} at least one truthy {{else}} all falsey {{/or}} -> ' at least one truthy '", "description": "

Block helper that renders a block if any of the given values is truthy. If an inverse block is specified it will be rendered when falsy.

\n", - "isBlock": true + "requiresBlock": true }, "unlessEq": { "args": [ @@ -1133,7 +1133,7 @@ "numArgs": 3, "example": "{{#unlessEq 2 1 }} not equal {{else}} equal {{/unlessEq}} -> ' not equal '", "description": "

Block helper that always renders the inverse block unless a is equal to b.

\n", - "isBlock": true + "requiresBlock": true }, "unlessGt": { "args": [ @@ -1144,7 +1144,7 @@ "numArgs": 3, "example": "{{#unlessGt 20 1 }} not greater than {{else}} greater than {{/unlessGt}} -> ' greater than '", "description": "

Block helper that always renders the inverse block unless a is greater than b.

\n", - "isBlock": true + "requiresBlock": true }, "unlessLt": { "args": [ @@ -1155,7 +1155,7 @@ "numArgs": 3, "example": "{{#unlessLt 20 1 }}greater than or equal{{else}}less than{{/unlessLt}} -> greater than or equal", "description": "

Block helper that always renders the inverse block unless a is less than b.

\n", - "isBlock": true + "requiresBlock": true }, "unlessGteq": { "args": [ @@ -1166,7 +1166,7 @@ "numArgs": 3, "example": "{{#unlessGteq 20 1 }} less than {{else}}greater than or equal to{{/unlessGteq}} -> greater than or equal to", "description": "

Block helper that always renders the inverse block unless a is greater than or equal to b.

\n", - "isBlock": true + "requiresBlock": true }, "unlessLteq": { "args": [ @@ -1177,7 +1177,7 @@ "numArgs": 3, "example": "{{#unlessLteq 20 1 }} greater than {{else}} less than or equal to {{/unlessLteq}} -> ' greater than '", "description": "

Block helper that always renders the inverse block unless a is less than or equal to b.

\n", - "isBlock": true + "requiresBlock": true } }, "object": { @@ -1187,7 +1187,7 @@ ], "numArgs": 1, "description": "

Extend the context with the properties of other objects. A shallow merge is performed to avoid mutating the context.

\n", - "isBlock": false + "requiresBlock": false }, "forIn": { "args": [ @@ -1196,7 +1196,7 @@ ], "numArgs": 2, "description": "

Block helper that iterates over the properties of an object, exposing each key and value on the context.

\n", - "isBlock": true + "requiresBlock": true }, "forOwn": { "args": [ @@ -1205,7 +1205,7 @@ ], "numArgs": 2, "description": "

Block helper that iterates over the own properties of an object, exposing each key and value on the context.

\n", - "isBlock": true + "requiresBlock": true }, "toPath": { "args": [ @@ -1213,7 +1213,7 @@ ], "numArgs": 1, "description": "

Take arguments and, if they are string or number, convert them to a dot-delineated object property path.

\n", - "isBlock": false + "requiresBlock": false }, "get": { "args": [ @@ -1223,7 +1223,7 @@ ], "numArgs": 3, "description": "

Use property paths (a.b.c) to get a value or nested value from the context. Works as a regular helper or block helper.

\n", - "isBlock": true + "requiresBlock": true }, "getObject": { "args": [ @@ -1232,7 +1232,7 @@ ], "numArgs": 2, "description": "

Use property paths (a.b.c) to get an object from the context. Differs from the get helper in that this helper will return the actual object, including the given property key. Also, this helper does not work as a block helper.

\n", - "isBlock": false + "requiresBlock": false }, "hasOwn": { "args": [ @@ -1241,7 +1241,7 @@ ], "numArgs": 2, "description": "

Return true if key is an own, enumerable property of the given context object.

\n", - "isBlock": false + "requiresBlock": false }, "isObject": { "args": [ @@ -1249,7 +1249,7 @@ ], "numArgs": 1, "description": "

Return true if value is an object.

\n", - "isBlock": false + "requiresBlock": false }, "JSONparse": { "args": [ @@ -1257,7 +1257,7 @@ ], "numArgs": 1, "description": "

Parses the given string using JSON.parse.

\n", - "isBlock": true + "requiresBlock": true }, "JSONstringify": { "args": [ @@ -1265,7 +1265,7 @@ ], "numArgs": 1, "description": "

Stringify an object using JSON.stringify.

\n", - "isBlock": false + "requiresBlock": false }, "merge": { "args": [ @@ -1274,7 +1274,7 @@ ], "numArgs": 2, "description": "

Deeply merge the properties of the given objects with the context object.

\n", - "isBlock": false + "requiresBlock": false }, "parseJSON": { "args": [ @@ -1282,7 +1282,7 @@ ], "numArgs": 1, "description": "

Parses the given string using JSON.parse.

\n", - "isBlock": true + "requiresBlock": true }, "pick": { "args": [ @@ -1292,7 +1292,7 @@ ], "numArgs": 3, "description": "

Pick properties from the context object.

\n", - "isBlock": true + "requiresBlock": true }, "stringify": { "args": [ @@ -1300,7 +1300,7 @@ ], "numArgs": 1, "description": "

Stringify an object using JSON.stringify.

\n", - "isBlock": false + "requiresBlock": false } }, "uuid": { @@ -1309,7 +1309,7 @@ "numArgs": 0, "example": "{{ uuid }} -> f34ebc66-93bd-4f7c-b79b-92b5569138bc", "description": "

Generates a UUID, using the V4 method (identical to the browser crypto.randomUUID function).

\n", - "isBlock": false + "requiresBlock": false } }, "date": { diff --git a/packages/string-templates/scripts/gen-collection-info.js b/packages/string-templates/scripts/gen-collection-info.js index 48bf503ade..1b540c829c 100644 --- a/packages/string-templates/scripts/gen-collection-info.js +++ b/packages/string-templates/scripts/gen-collection-info.js @@ -115,7 +115,7 @@ function getCommentInfo(file, func) { docs.example = docs.example.replace("product", "multiply") } docs.description = blocks[0].trim() - docs.isBlock = docs.tags.some(el => el.title === "block") + docs.requiresBlock = docs.tags.some(el => el.title === "block") return docs } @@ -160,7 +160,7 @@ function run() { numArgs: args.length, example: jsDocInfo.example || undefined, description: jsDocInfo.description, - isBlock: jsDocInfo.isBlock, + requiresBlock: jsDocInfo.requiresBlock, }) } outputJSON[collection] = collectionInfo diff --git a/packages/string-templates/test/manifest.spec.js b/packages/string-templates/test/manifest.spec.js index 762726e2f3..01fb088bbc 100644 --- a/packages/string-templates/test/manifest.spec.js +++ b/packages/string-templates/test/manifest.spec.js @@ -58,8 +58,8 @@ const examples = collections.reduce((acc, collection) => { } } } - const hasHbsBody = details.isBlock - return [name, { hbs, js, hasHbsBody }] + const requiresHbsBody = details.requiresBlock + return [name, { hbs, js, requiresHbsBody }] }) .filter(x => !!x) @@ -110,7 +110,9 @@ describe("manifest", () => { describe("can be parsed and run as js", () => { describe.each(Object.keys(examples))("%s", collection => { it.each( - examples[collection].filter(([_, { hasHbsBody }]) => !hasHbsBody) + examples[collection].filter( + ([_, { requiresHbsBody }]) => !requiresHbsBody + ) )("%s", async (_, { hbs, js }) => { const context = { double: i => i * 2, From f5157c41847764ad2b41ee974f2f490d6b42afa7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 30 Jan 2024 15:54:00 +0100 Subject: [PATCH 20/32] Fix other tests --- packages/string-templates/manifest.json | 8 ++++---- packages/string-templates/scripts/gen-collection-info.js | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/string-templates/manifest.json b/packages/string-templates/manifest.json index d06a01f606..dce4af8665 100644 --- a/packages/string-templates/manifest.json +++ b/packages/string-templates/manifest.json @@ -264,7 +264,7 @@ "numArgs": 2, "example": "{{equalsLength [1, 2, 3] 3}} -> true", "description": "

Returns true if the the length of the given value is equal to the given length. Can be used as a block or inline helper.

\n", - "requiresBlock": true + "requiresBlock": false }, "last": { "args": [ @@ -293,7 +293,7 @@ "numArgs": 2, "example": "{{equalsLength [1, 2, 3] 3}} -> true", "description": "

Returns true if the the length of the given value is equal to the given length. Can be used as a block or inline helper.

\n", - "requiresBlock": true + "requiresBlock": false }, "map": { "args": [ @@ -906,7 +906,7 @@ "numArgs": 2, "example": "{{uppercase 'aBcDef'}} -> ABCDEF", "description": "

Uppercase all of the characters in the given string. If used as a block helper it will uppercase the entire block. This helper does not support inverse blocks.

\n", - "requiresBlock": true + "requiresBlock": false } }, "comparison": { @@ -931,7 +931,7 @@ "numArgs": 4, "example": "{{compare 10 '<' 5 }} -> false", "description": "

Render a block when a comparison of the first and third arguments returns true. The second argument is the [arithemetic operator][operators] to use. You may also optionally specify an inverse block to render when falsy.

\n", - "requiresBlock": true + "requiresBlock": false }, "contains": { "args": [ diff --git a/packages/string-templates/scripts/gen-collection-info.js b/packages/string-templates/scripts/gen-collection-info.js index 1b540c829c..ed57fe7fae 100644 --- a/packages/string-templates/scripts/gen-collection-info.js +++ b/packages/string-templates/scripts/gen-collection-info.js @@ -115,7 +115,8 @@ function getCommentInfo(file, func) { docs.example = docs.example.replace("product", "multiply") } docs.description = blocks[0].trim() - docs.requiresBlock = docs.tags.some(el => el.title === "block") + docs.acceptsBlock = docs.tags.some(el => el.title === "block") + docs.acceptsInline = docs.tags.some(el => el.title === "inline") return docs } @@ -160,7 +161,7 @@ function run() { numArgs: args.length, example: jsDocInfo.example || undefined, description: jsDocInfo.description, - requiresBlock: jsDocInfo.requiresBlock, + requiresBlock: jsDocInfo.acceptsBlock && !jsDocInfo.acceptsInline, }) } outputJSON[collection] = collectionInfo From 43e536e7a6f0049528ac33b5850a151544b07412 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 30 Jan 2024 16:52:25 +0100 Subject: [PATCH 21/32] Test only js helpers --- packages/string-templates/src/helpers/list.js | 5 +++++ packages/string-templates/test/manifest.spec.js | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/string-templates/src/helpers/list.js b/packages/string-templates/src/helpers/list.js index 739d8b50be..c10a732371 100644 --- a/packages/string-templates/src/helpers/list.js +++ b/packages/string-templates/src/helpers/list.js @@ -3,6 +3,8 @@ const helperList = require("@budibase/handlebars-helpers") let helpers = undefined +const helpersToRemove = ["sortBy"] + module.exports.getHelperList = () => { if (helpers) { return helpers @@ -23,6 +25,9 @@ module.exports.getHelperList = () => { helpers[key] = externalHandlebars.addedHelpers[key] } + for (const toRemove of helpersToRemove) { + delete helpers[toRemove] + } Object.freeze(helpers) return helpers } diff --git a/packages/string-templates/test/manifest.spec.js b/packages/string-templates/test/manifest.spec.js index 01fb088bbc..7c794d8c23 100644 --- a/packages/string-templates/test/manifest.spec.js +++ b/packages/string-templates/test/manifest.spec.js @@ -24,6 +24,7 @@ const { } = require("../src/index.cjs") const tk = require("timekeeper") +const { getHelperList } = require("../src/helpers") tk.freeze("2021-01-21T12:00:00") @@ -108,9 +109,15 @@ describe("manifest", () => { }) describe("can be parsed and run as js", () => { - describe.each(Object.keys(examples))("%s", collection => { + const jsHelpers = getHelperList() + const jsExamples = Object.keys(examples).reduce((acc, v) => { + acc[v] = examples[v].filter(([key]) => jsHelpers[key]) + return acc + }, {}) + + describe.each(Object.keys(jsExamples))("%s", collection => { it.each( - examples[collection].filter( + jsExamples[collection].filter( ([_, { requiresHbsBody }]) => !requiresHbsBody ) )("%s", async (_, { hbs, js }) => { From 82b4af1436d6992a7fd0ce4eaf079409efd31415 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 30 Jan 2024 17:09:41 +0100 Subject: [PATCH 22/32] Update handlebars-helpers package --- packages/string-templates/package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/string-templates/package.json b/packages/string-templates/package.json index dfbff1a24b..36f95060b4 100644 --- a/packages/string-templates/package.json +++ b/packages/string-templates/package.json @@ -25,7 +25,7 @@ "manifest": "node ./scripts/gen-collection-info.js" }, "dependencies": { - "@budibase/handlebars-helpers": "^0.13.0", + "@budibase/handlebars-helpers": "^0.13.1", "dayjs": "^1.10.8", "handlebars": "^4.7.6", "lodash.clonedeep": "^4.5.0", diff --git a/yarn.lock b/yarn.lock index d2fb6f5236..80d1420edf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2031,10 +2031,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/handlebars-helpers@^0.13.0": - version "0.13.0" - resolved "https://registry.yarnpkg.com/@budibase/handlebars-helpers/-/handlebars-helpers-0.13.0.tgz#224333d14e3900b7dacf48286af1e624a9fd62ea" - integrity sha512-g8+sFrMNxsIDnK+MmdUICTVGr6ReUFtnPp9hJX0VZwz1pN3Ynolpk/Qbu6rEWAvoU1sEqY1mXr9uo/+kEfeGbQ== +"@budibase/handlebars-helpers@^0.13.1": + version "0.13.1" + resolved "https://registry.yarnpkg.com/@budibase/handlebars-helpers/-/handlebars-helpers-0.13.1.tgz#d02e73c0df8305cd675e70dc37f8427eb0842080" + integrity sha512-v4RbXhr3igvK3i2pj5cNltu/4NMxdPIzcUt/o0RoInhesNH1VSLRdweSFr6/Y34fsCR5jHZ6vltdcz2RgrTKgw== dependencies: get-object "^0.2.0" get-value "^3.0.1" From d1712bda5275e57b2496999d135d06000367a232 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 30 Jan 2024 17:37:09 +0100 Subject: [PATCH 23/32] Remove helpers not available in js --- .../src/components/common/bindings/BindingPicker.svelte | 7 ++++--- packages/builder/src/constants/completions.js | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/common/bindings/BindingPicker.svelte b/packages/builder/src/components/common/bindings/BindingPicker.svelte index 93d9d62021..1f35e3fbab 100644 --- a/packages/builder/src/components/common/bindings/BindingPicker.svelte +++ b/packages/builder/src/components/common/bindings/BindingPicker.svelte @@ -47,9 +47,10 @@ }) $: filteredHelpers = helpers?.filter(helper => { return ( - !search || - helper.label.match(searchRgx) || - helper.description.match(searchRgx) + (!search || + helper.label.match(searchRgx) || + helper.description.match(searchRgx)) && + (mode.name !== "javascript" || !helper.requiresBlock) ) }) diff --git a/packages/builder/src/constants/completions.js b/packages/builder/src/constants/completions.js index 32de934324..ab0e5fd52d 100644 --- a/packages/builder/src/constants/completions.js +++ b/packages/builder/src/constants/completions.js @@ -11,6 +11,7 @@ export function handlebarsCompletions() { label: helperName, displayText: helperName, description: helperConfig.description, + requiresBlock: helperConfig.requiresBlock, })) ) } From 70d49bbd6b25eac519b670b236b805279eab1b58 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 31 Jan 2024 09:59:59 +0100 Subject: [PATCH 24/32] Renames --- .../builder/src/components/common/bindings/BindingPicker.svelte | 2 +- packages/builder/src/constants/completions.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/components/common/bindings/BindingPicker.svelte b/packages/builder/src/components/common/bindings/BindingPicker.svelte index 1f35e3fbab..d85a0a2bbb 100644 --- a/packages/builder/src/components/common/bindings/BindingPicker.svelte +++ b/packages/builder/src/components/common/bindings/BindingPicker.svelte @@ -50,7 +50,7 @@ (!search || helper.label.match(searchRgx) || helper.description.match(searchRgx)) && - (mode.name !== "javascript" || !helper.requiresBlock) + (mode.name !== "javascript" || helper.allowsJs) ) }) diff --git a/packages/builder/src/constants/completions.js b/packages/builder/src/constants/completions.js index ab0e5fd52d..4af0bad38d 100644 --- a/packages/builder/src/constants/completions.js +++ b/packages/builder/src/constants/completions.js @@ -11,7 +11,7 @@ export function handlebarsCompletions() { label: helperName, displayText: helperName, description: helperConfig.description, - requiresBlock: helperConfig.requiresBlock, + allowsJs: !helperConfig.requiresBlock, })) ) } From e5d5dea5e626cb593281fb0bb47ce6a17e4dc123 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 31 Jan 2024 10:00:41 +0100 Subject: [PATCH 25/32] Renames --- packages/string-templates/src/conversion/index.js | 4 ++-- packages/string-templates/src/helpers/index.js | 4 ++-- packages/string-templates/src/helpers/javascript.js | 4 ++-- packages/string-templates/src/helpers/list.js | 2 +- packages/string-templates/test/manifest.spec.js | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/string-templates/src/conversion/index.js b/packages/string-templates/src/conversion/index.js index 30e2510b55..10aaef0d2f 100644 --- a/packages/string-templates/src/conversion/index.js +++ b/packages/string-templates/src/conversion/index.js @@ -1,4 +1,4 @@ -const { getHelperList } = require("../helpers") +const { getJsHelperList } = require("../helpers") function getLayers(fullBlock) { let layers = [] @@ -109,7 +109,7 @@ module.exports.convertHBSBlock = (block, blockNumber) => { const layers = getLayers(block) let value = null - const list = getHelperList() + const list = getJsHelperList() for (let layer of layers) { const parts = splitBySpace(layer) if (value || parts.length > 1 || list[parts[0]]) { diff --git a/packages/string-templates/src/helpers/index.js b/packages/string-templates/src/helpers/index.js index bed3d0c3e3..5e6dcbd2b9 100644 --- a/packages/string-templates/src/helpers/index.js +++ b/packages/string-templates/src/helpers/index.js @@ -7,7 +7,7 @@ const { HelperFunctionBuiltin, LITERAL_MARKER, } = require("./constants") -const { getHelperList } = require("./list") +const { getJsHelperList } = require("./list") const HTML_SWAPS = { "<": "<", @@ -97,4 +97,4 @@ module.exports.unregisterAll = handlebars => { externalHandlebars.unregisterAll(handlebars) } -module.exports.getHelperList = getHelperList +module.exports.getJsHelperList = getJsHelperList diff --git a/packages/string-templates/src/helpers/javascript.js b/packages/string-templates/src/helpers/javascript.js index 0b63400deb..eff125dd72 100644 --- a/packages/string-templates/src/helpers/javascript.js +++ b/packages/string-templates/src/helpers/javascript.js @@ -1,7 +1,7 @@ const { atob } = require("../utilities") const cloneDeep = require("lodash.clonedeep") const { LITERAL_MARKER } = require("../helpers/constants") -const { getHelperList } = require("./list") +const { getJsHelperList } = require("./list") // The method of executing JS scripts depends on the bundle being built. // This setter is used in the entrypoint (either index.cjs or index.mjs). @@ -49,7 +49,7 @@ module.exports.processJS = (handlebars, context) => { // app context. const sandboxContext = { $: path => getContextValue(path, cloneDeep(context)), - helpers: getHelperList(), + helpers: getJsHelperList(), } // Create a sandbox with our context and run the JS diff --git a/packages/string-templates/src/helpers/list.js b/packages/string-templates/src/helpers/list.js index c10a732371..edbdcbdf05 100644 --- a/packages/string-templates/src/helpers/list.js +++ b/packages/string-templates/src/helpers/list.js @@ -5,7 +5,7 @@ let helpers = undefined const helpersToRemove = ["sortBy"] -module.exports.getHelperList = () => { +module.exports.getJsHelperList = () => { if (helpers) { return helpers } diff --git a/packages/string-templates/test/manifest.spec.js b/packages/string-templates/test/manifest.spec.js index 7c794d8c23..3e39d775f5 100644 --- a/packages/string-templates/test/manifest.spec.js +++ b/packages/string-templates/test/manifest.spec.js @@ -24,7 +24,7 @@ const { } = require("../src/index.cjs") const tk = require("timekeeper") -const { getHelperList } = require("../src/helpers") +const { getJsHelperList } = require("../src/helpers") tk.freeze("2021-01-21T12:00:00") @@ -109,7 +109,7 @@ describe("manifest", () => { }) describe("can be parsed and run as js", () => { - const jsHelpers = getHelperList() + const jsHelpers = getJsHelperList() const jsExamples = Object.keys(examples).reduce((acc, v) => { acc[v] = examples[v].filter(([key]) => jsHelpers[key]) return acc From cd4fccbd6e06c012908537d0dacb19a5181bcfd2 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 31 Jan 2024 10:34:49 +0100 Subject: [PATCH 26/32] Allow excluding js helpers --- packages/builder/src/constants/completions.js | 6 ++++-- packages/string-templates/src/helpers/list.js | 5 +++-- packages/string-templates/src/index.cjs | 1 + packages/string-templates/src/index.js | 2 ++ packages/string-templates/src/index.mjs | 1 + 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/constants/completions.js b/packages/builder/src/constants/completions.js index 4af0bad38d..e539a8084a 100644 --- a/packages/builder/src/constants/completions.js +++ b/packages/builder/src/constants/completions.js @@ -1,4 +1,4 @@ -import { getManifest } from "@budibase/string-templates" +import { getManifest, helpersToRemoveForJs } from "@budibase/string-templates" export function handlebarsCompletions() { const manifest = getManifest() @@ -11,7 +11,9 @@ export function handlebarsCompletions() { label: helperName, displayText: helperName, description: helperConfig.description, - allowsJs: !helperConfig.requiresBlock, + allowsJs: + !helperConfig.requiresBlock && + !helpersToRemoveForJs.includes(helperName), })) ) } diff --git a/packages/string-templates/src/helpers/list.js b/packages/string-templates/src/helpers/list.js index edbdcbdf05..e956958865 100644 --- a/packages/string-templates/src/helpers/list.js +++ b/packages/string-templates/src/helpers/list.js @@ -3,7 +3,8 @@ const helperList = require("@budibase/handlebars-helpers") let helpers = undefined -const helpersToRemove = ["sortBy"] +const helpersToRemoveForJs = ["sortBy"] +module.exports.helpersToRemoveForJs = helpersToRemoveForJs module.exports.getJsHelperList = () => { if (helpers) { @@ -25,7 +26,7 @@ module.exports.getJsHelperList = () => { helpers[key] = externalHandlebars.addedHelpers[key] } - for (const toRemove of helpersToRemove) { + for (const toRemove of helpersToRemoveForJs) { delete helpers[toRemove] } Object.freeze(helpers) diff --git a/packages/string-templates/src/index.cjs b/packages/string-templates/src/index.cjs index aedb7fc052..7d3aa02be8 100644 --- a/packages/string-templates/src/index.cjs +++ b/packages/string-templates/src/index.cjs @@ -20,6 +20,7 @@ module.exports.findHBSBlocks = templates.findHBSBlocks module.exports.convertToJS = templates.convertToJS module.exports.setJSRunner = templates.setJSRunner module.exports.FIND_ANY_HBS_REGEX = templates.FIND_ANY_HBS_REGEX +module.exports.helpersToRemoveForJs = templates.helpersToRemoveForJs if (!process.env.NO_JS) { const { VM } = require("vm2") diff --git a/packages/string-templates/src/index.js b/packages/string-templates/src/index.js index 63da7fde4d..eb9a8ac81d 100644 --- a/packages/string-templates/src/index.js +++ b/packages/string-templates/src/index.js @@ -10,6 +10,7 @@ const { } = require("./utilities") const { convertHBSBlock } = require("./conversion") const javascript = require("./helpers/javascript") +const { helpersToRemoveForJs } = require("./helpers/list") const hbsInstance = handlebars.create() registerAll(hbsInstance) @@ -394,3 +395,4 @@ module.exports.convertToJS = hbs => { } module.exports.FIND_ANY_HBS_REGEX = FIND_ANY_HBS_REGEX +module.exports.helpersToRemoveForJs = helpersToRemoveForJs diff --git a/packages/string-templates/src/index.mjs b/packages/string-templates/src/index.mjs index 43cda8183f..ad93a7bed4 100644 --- a/packages/string-templates/src/index.mjs +++ b/packages/string-templates/src/index.mjs @@ -21,6 +21,7 @@ export const findHBSBlocks = templates.findHBSBlocks export const convertToJS = templates.convertToJS export const setJSRunner = templates.setJSRunner export const FIND_ANY_HBS_REGEX = templates.FIND_ANY_HBS_REGEX +export const helpersToRemoveForJs = templates.helpersToRemoveForJs if (process && !process.env.NO_JS) { /** From f3e0dfd46686a12a031e3484d11d7daa99ad3de6 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 31 Jan 2024 11:55:29 +0000 Subject: [PATCH 27/32] Update to @budibase/nano 10.1.5 --- packages/backend-core/package.json | 2 +- packages/types/package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/backend-core/package.json b/packages/backend-core/package.json index d6325e1de9..85644488f5 100644 --- a/packages/backend-core/package.json +++ b/packages/backend-core/package.json @@ -21,7 +21,7 @@ "test:watch": "jest --watchAll" }, "dependencies": { - "@budibase/nano": "10.1.4", + "@budibase/nano": "10.1.5", "@budibase/pouchdb-replication-stream": "1.2.10", "@budibase/shared-core": "0.0.0", "@budibase/types": "0.0.0", diff --git a/packages/types/package.json b/packages/types/package.json index 5111339c7b..ce4fce95fb 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -15,7 +15,7 @@ }, "jest": {}, "devDependencies": { - "@budibase/nano": "10.1.4", + "@budibase/nano": "10.1.5", "@types/koa": "2.13.4", "@types/pouchdb": "6.4.0", "@types/redlock": "4.0.3", diff --git a/yarn.lock b/yarn.lock index 80d1420edf..2c12097fb5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2050,10 +2050,10 @@ to-gfm-code-block "^0.1.1" uuid "^9.0.1" -"@budibase/nano@10.1.4": - version "10.1.4" - resolved "https://registry.yarnpkg.com/@budibase/nano/-/nano-10.1.4.tgz#5c2670d0b4c12d736ddd6581c57d47c0aa45efad" - integrity sha512-J+IVaAljGideDvJss/AUxXA1599HEIUJo5c0LLlmc1KMA3GZWZjyX+w2fxAw3qF7hqFvX+qAStQgdcD3+/GPMA== +"@budibase/nano@10.1.5": + version "10.1.5" + resolved "https://registry.yarnpkg.com/@budibase/nano/-/nano-10.1.5.tgz#eeaded7bfc707ecabf8fde604425b865a90c06ec" + integrity sha512-q1eKIsYKo+iK17zsJYd3VBl+5ufQMPpHYLec0wVsid8wnJVrTQk7RNpBlBUn/EDgXM7t8XNNHlERqHu+CxJu8Q== dependencies: "@types/tough-cookie" "^4.0.2" axios "^1.1.3" From a23f76b8c813fd4a6043c816bcc79a69d311fee8 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 31 Jan 2024 08:57:54 -0300 Subject: [PATCH 28/32] update expiry time for attachments/images --- packages/backend-core/src/objectStore/cloudfront.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend-core/src/objectStore/cloudfront.ts b/packages/backend-core/src/objectStore/cloudfront.ts index 866fe9e880..3bca97d11e 100644 --- a/packages/backend-core/src/objectStore/cloudfront.ts +++ b/packages/backend-core/src/objectStore/cloudfront.ts @@ -23,7 +23,7 @@ const getCloudfrontSignParams = () => { return { keypairId: env.CLOUDFRONT_PUBLIC_KEY_ID!, privateKeyString: getPrivateKey(), - expireTime: new Date().getTime() + 1000 * 60 * 60, // 1 hour + expireTime: new Date().getTime() + 1000 * 60 * 60 * 24, // 1 day } } From c5fd92cd94eca5a237e887137a987b8d2fe33e82 Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Wed, 31 Jan 2024 13:19:02 +0000 Subject: [PATCH 29/32] Bump version to 2.16.1 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index f91c51d4bb..328e7f720a 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.16.0", + "version": "2.16.1", "npmClient": "yarn", "packages": [ "packages/*", From 63cc5447d572017005e4370094b5c3d7d7fecca9 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 31 Jan 2024 10:47:27 -0300 Subject: [PATCH 30/32] adding lint rule for console.log --- .eslintrc.json | 6 ++++++ packages/builder/src/builderStore/dataBinding.js | 1 - packages/builder/src/builderStore/websocket.js | 2 +- packages/builder/src/components/common/CodeEditor/index.js | 2 +- .../src/components/portal/onboarding/TourPopover.svelte | 2 +- .../builder/src/components/portal/onboarding/tourHandler.js | 4 ++-- packages/builder/src/components/portal/onboarding/tours.js | 2 +- packages/builder/src/helpers/urlStateSync.js | 2 +- .../app/[application]/_components/BuilderSidePanel.svelte | 2 +- .../[componentId]/_components/Screen/GeneralPanel.svelte | 2 +- .../design/_components/NewScreen/CreateScreenModal.svelte | 2 +- packages/builder/src/pages/builder/auth/login.svelte | 2 +- 12 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 79f7e56712..4f08698fec 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -45,6 +45,12 @@ "no-prototype-builtins": "off", "local-rules/no-budibase-imports": "error" } + }, + { + "files": ["packages/builder/**/*"], + "rules": { + "no-console": ["error", { "allow": ["warn", "error", "debug"] } ] + } } ], "rules": { diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index cc3851c318..86aecd466f 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -364,7 +364,6 @@ const getContextBindings = (asset, componentId) => { * Generates a set of bindings for a given component context */ const generateComponentContextBindings = (asset, componentContext) => { - console.log("Hello ") const { component, definition, contexts } = componentContext if (!component || !definition || !contexts?.length) { return [] diff --git a/packages/builder/src/builderStore/websocket.js b/packages/builder/src/builderStore/websocket.js index ca3f49e9a3..4482e3ae1e 100644 --- a/packages/builder/src/builderStore/websocket.js +++ b/packages/builder/src/builderStore/websocket.js @@ -21,7 +21,7 @@ export const createBuilderWebsocket = appId => { }) }) socket.on("connect_error", err => { - console.log("Failed to connect to builder websocket:", err.message) + console.error("Failed to connect to builder websocket:", err.message) }) socket.on("disconnect", () => { userStore.actions.reset() diff --git a/packages/builder/src/components/common/CodeEditor/index.js b/packages/builder/src/components/common/CodeEditor/index.js index 7987deff52..da0e727e4e 100644 --- a/packages/builder/src/components/common/CodeEditor/index.js +++ b/packages/builder/src/components/common/CodeEditor/index.js @@ -312,7 +312,7 @@ export const insertBinding = (view, from, to, text, mode) => { } else if (mode.name == "handlebars") { parsedInsert = hbInsert(view.state.doc?.toString(), from, to, text) } else { - console.log("Unsupported") + console.warn("Unsupported") return } diff --git a/packages/builder/src/components/portal/onboarding/TourPopover.svelte b/packages/builder/src/components/portal/onboarding/TourPopover.svelte index d959a6ef95..cc56715284 100644 --- a/packages/builder/src/components/portal/onboarding/TourPopover.svelte +++ b/packages/builder/src/components/portal/onboarding/TourPopover.svelte @@ -67,7 +67,7 @@ })) navigateStep(target) } else { - console.log("Could not retrieve step") + console.warn("Could not retrieve step") } } else { if (typeof tourStep.onComplete === "function") { diff --git a/packages/builder/src/components/portal/onboarding/tourHandler.js b/packages/builder/src/components/portal/onboarding/tourHandler.js index d4a564f23a..5b44bdc96f 100644 --- a/packages/builder/src/components/portal/onboarding/tourHandler.js +++ b/packages/builder/src/components/portal/onboarding/tourHandler.js @@ -3,11 +3,11 @@ import { get } from "svelte/store" const registerNode = async (node, tourStepKey) => { if (!node) { - console.log("Tour Handler - an anchor node is required") + console.warn("Tour Handler - an anchor node is required") } if (!get(store).tourKey) { - console.log("Tour Handler - No active tour ", tourStepKey, node) + console.error("Tour Handler - No active tour ", tourStepKey, node) return } diff --git a/packages/builder/src/components/portal/onboarding/tours.js b/packages/builder/src/components/portal/onboarding/tours.js index e82026da94..55fd4c4a9b 100644 --- a/packages/builder/src/components/portal/onboarding/tours.js +++ b/packages/builder/src/components/portal/onboarding/tours.js @@ -45,7 +45,7 @@ const endUserOnboarding = async ({ skipped = false } = {}) => { onboarding: false, })) } catch (e) { - console.log("Onboarding failed", e) + console.error("Onboarding failed", e) return false } return true diff --git a/packages/builder/src/helpers/urlStateSync.js b/packages/builder/src/helpers/urlStateSync.js index 2408dde2f1..9337393f06 100644 --- a/packages/builder/src/helpers/urlStateSync.js +++ b/packages/builder/src/helpers/urlStateSync.js @@ -52,7 +52,7 @@ export const syncURLToState = options => { let cachedPage = get(routify.page) let previousParamsHash = null let debug = false - const log = (...params) => debug && console.log(`[${urlParam}]`, ...params) + const log = (...params) => debug && console.debug(`[${urlParam}]`, ...params) // Navigate to a certain URL const gotoUrl = (url, params) => { diff --git a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte index 33116094eb..cd00b36186 100644 --- a/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_components/BuilderSidePanel.svelte @@ -107,7 +107,7 @@ return } if (!prodAppId) { - console.log("Application id required") + console.error("Application id required") return } await usersFetch.update({ diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/GeneralPanel.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/GeneralPanel.svelte index fb9ee2c8a5..b2bcd3daa4 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/GeneralPanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/GeneralPanel.svelte @@ -66,7 +66,7 @@ try { await store.actions.screens.updateSetting(get(selectedScreen), key, value) } catch (error) { - console.log(error) + console.error(error) notifications.error("Error saving screen settings") } } diff --git a/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/CreateScreenModal.svelte b/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/CreateScreenModal.svelte index a9d64afd19..5e3a7a0f37 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/CreateScreenModal.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/_components/NewScreen/CreateScreenModal.svelte @@ -71,7 +71,7 @@ $goto(`./${screenId}`) store.actions.screens.select(screenId) } catch (error) { - console.log(error) + console.error(error) notifications.error("Error creating screens") } } diff --git a/packages/builder/src/pages/builder/auth/login.svelte b/packages/builder/src/pages/builder/auth/login.svelte index 0ba7e6448b..7bb2a3ad49 100644 --- a/packages/builder/src/pages/builder/auth/login.svelte +++ b/packages/builder/src/pages/builder/auth/login.svelte @@ -31,7 +31,7 @@ async function login() { form.validate() if (Object.keys(errors).length > 0) { - console.log("errors", errors) + console.error("errors", errors) return } try { From 475070a495778bcc87738225fbddf87e26db734f Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 31 Jan 2024 10:53:53 -0300 Subject: [PATCH 31/32] client and frontend core --- .eslintrc.json | 6 +++++- .../src/components/app/embedded-map/EmbeddedMap.svelte | 2 +- packages/client/src/components/app/forms/CodeScanner.svelte | 2 +- packages/client/src/stores/org.js | 2 +- packages/frontend-core/src/components/grid/lib/websocket.js | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 4f08698fec..917443014b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -47,7 +47,11 @@ } }, { - "files": ["packages/builder/**/*"], + "files": [ + "packages/builder/**/*", + "packages/client/**/*", + "packages/frontend-core/**/*" + ], "rules": { "no-console": ["error", { "allow": ["warn", "error", "debug"] } ] } diff --git a/packages/client/src/components/app/embedded-map/EmbeddedMap.svelte b/packages/client/src/components/app/embedded-map/EmbeddedMap.svelte index 3bb7d5606d..979cb0e085 100644 --- a/packages/client/src/components/app/embedded-map/EmbeddedMap.svelte +++ b/packages/client/src/components/app/embedded-map/EmbeddedMap.svelte @@ -307,7 +307,7 @@ // Reset view resetView() } catch (e) { - console.log("There was a problem with the map", e) + console.error("There was a problem with the map", e) } } diff --git a/packages/client/src/components/app/forms/CodeScanner.svelte b/packages/client/src/components/app/forms/CodeScanner.svelte index 2a546eb64c..008c0f5727 100644 --- a/packages/client/src/components/app/forms/CodeScanner.svelte +++ b/packages/client/src/components/app/forms/CodeScanner.svelte @@ -61,7 +61,7 @@ resolve({ initialised: true }) }) .catch(err => { - console.log("There was a problem scanning the image", err) + console.error("There was a problem scanning the image", err) resolve({ initialised: false }) }) }) diff --git a/packages/client/src/stores/org.js b/packages/client/src/stores/org.js index af0fc955f9..d8a17f7c32 100644 --- a/packages/client/src/stores/org.js +++ b/packages/client/src/stores/org.js @@ -14,7 +14,7 @@ const createOrgStore = () => { const settingsConfigDoc = await API.getTenantConfig(tenantId) set({ logoUrl: settingsConfigDoc.config.logoUrl }) } catch (e) { - console.log("Could not init org ", e) + console.error("Could not init org ", e) } } diff --git a/packages/frontend-core/src/components/grid/lib/websocket.js b/packages/frontend-core/src/components/grid/lib/websocket.js index af34acd530..b0fd236989 100644 --- a/packages/frontend-core/src/components/grid/lib/websocket.js +++ b/packages/frontend-core/src/components/grid/lib/websocket.js @@ -29,7 +29,7 @@ export const createGridWebsocket = context => { connectToDatasource(get(datasource)) }) socket.on("connect_error", err => { - console.log("Failed to connect to grid websocket:", err.message) + console.error("Failed to connect to grid websocket:", err.message) }) // User events From 3c6246e03fed7f71f43f30db2eaa961c3636f69d Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Wed, 31 Jan 2024 15:16:08 +0000 Subject: [PATCH 32/32] Bump version to 2.16.2 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index 328e7f720a..38dff33c7e 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.16.1", + "version": "2.16.2", "npmClient": "yarn", "packages": [ "packages/*",