From cdef4ead8cfe28cc13423ab3302e2d2219954556 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 15 Jan 2021 14:38:10 +0000 Subject: [PATCH] Removing mention of mustache from the server package. --- packages/server/package.json | 1 - .../server/src/api/controllers/application.js | 4 +-- .../server/src/automations/automationUtils.js | 12 ++++----- packages/server/src/automations/thread.js | 6 ++--- packages/server/src/events/index.js | 2 +- .../utilities/{mustache.js => handlebars.js} | 26 +++++++++---------- packages/server/yarn.lock | 8 +++--- 7 files changed, 29 insertions(+), 30 deletions(-) rename packages/server/src/utilities/{mustache.js => handlebars.js} (64%) diff --git a/packages/server/package.json b/packages/server/package.json index 9014c8ad62..ee2028782c 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -78,7 +78,6 @@ "koa-session": "^5.12.0", "koa-static": "^5.0.0", "lodash": "^4.17.13", - "mustache": "^4.0.1", "node-fetch": "^2.6.0", "open": "^7.3.0", "pino-pretty": "^4.0.0", diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index 1d259ac425..ae980be53c 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -31,7 +31,7 @@ const { createLoginScreen, } = require("../../constants/screens") const { cloneDeep } = require("lodash/fp") -const { recurseMustache } = require("../../utilities/mustache") +const { recurseHandlebars } = require("../../utilities/handlebars") const { USERS_TABLE_SCHEMA } = require("../../constants") const APP_PREFIX = DocumentTypes.APP + SEPARATOR @@ -214,7 +214,7 @@ const createEmptyAppPackage = async (ctx, app) => { for (let layout of BASE_LAYOUTS) { const cloned = cloneDeep(layout) cloned.title = app.name - screensAndLayouts.push(recurseMustache(cloned, app)) + screensAndLayouts.push(recurseHandlebars(cloned, app)) } const homeScreen = createHomeScreen(app) diff --git a/packages/server/src/automations/automationUtils.js b/packages/server/src/automations/automationUtils.js index ac0d9bf721..07c4a5c2a9 100644 --- a/packages/server/src/automations/automationUtils.js +++ b/packages/server/src/automations/automationUtils.js @@ -1,10 +1,10 @@ const CouchDB = require("../db") /** - * When values are input to the system generally they will be of type string as this is required for mustache. This can + * When values are input to the system generally they will be of type string as this is required for handlebars. This can * generate some odd scenarios as the Schema of the automation requires a number but the builder might supply a string - * with mustache syntax to get the number from the rest of the context. To support this the server has to make sure that - * the post mustache statement can be cast into the correct type, this function does this for numbers and booleans. + * with handlebars syntax to get the number from the rest of the context. To support this the server has to make sure that + * the post handlebars statement can be cast into the correct type, this function does this for numbers and booleans. * * @param {object} inputs An object of inputs, please note this will not recurse down into any objects within, it simply * cleanses the top level inputs, however it can be used by recursively calling it deeper into the object structures if @@ -54,7 +54,7 @@ module.exports.cleanInputValues = (inputs, schema) => { * * @param {string} appId The instance which the Table/Table is contained under. * @param {string} tableId The ID of the Table/Table which the schema is to be retrieved for. - * @param {object} row The input row structure which requires clean-up after having been through mustache statements. + * @param {object} row The input row structure which requires clean-up after having been through handlebars statements. * @returns {Promise} The cleaned up rows object, will should now have all the required primitive types. */ module.exports.cleanUpRow = async (appId, tableId, row) => { @@ -66,11 +66,11 @@ module.exports.cleanUpRow = async (appId, tableId, row) => { /** * A utility function for the cleanUpRow, which can be used if only the row ID is known (not the table ID) to clean - * up a row after mustache statements have been replaced. This is specifically useful for the update row action. + * up a row after handlebars statements have been replaced. This is specifically useful for the update row action. * * @param {string} appId The instance which the Table/Table is contained under. * @param {string} rowId The ID of the row from which the tableId will be extracted, to get the Table/Table schema. - * @param {object} row The input row structure which requires clean-up after having been through mustache statements. + * @param {object} row The input row structure which requires clean-up after having been through handlebars statements. * @returns {Promise} The cleaned up rows object, which will now have all the required primitive types. */ module.exports.cleanUpRowById = async (appId, rowId, row) => { diff --git a/packages/server/src/automations/thread.js b/packages/server/src/automations/thread.js index 771de65463..e7046ee7ea 100644 --- a/packages/server/src/automations/thread.js +++ b/packages/server/src/automations/thread.js @@ -3,7 +3,7 @@ const actions = require("./actions") const logic = require("./logic") const automationUtils = require("./automationUtils") const AutomationEmitter = require("../events/AutomationEmitter") -const { recurseMustache } = require("../utilities/mustache") +const { recurseHandlebars } = require("../utilities/handlebars") handlebars.registerHelper("object", value => { return new handlebars.SafeString(JSON.stringify(value)) @@ -24,7 +24,7 @@ class Orchestrator { // remove from context delete triggerOutput.appId delete triggerOutput.metadata - // step zero is never used as the mustache is zero indexed for customer facing + // step zero is never used as the handlebars is zero indexed for customer facing this._context = { steps: [{}], trigger: triggerOutput } this._automation = automation // create an emitter which has the chain count for this automation run in it, so it can block @@ -49,7 +49,7 @@ class Orchestrator { let automation = this._automation for (let step of automation.definition.steps) { let stepFn = await this.getStepFunctionality(step.type, step.stepId) - step.inputs = recurseMustache(step.inputs, this._context) + step.inputs = recurseHandlebars(step.inputs, this._context) step.inputs = automationUtils.cleanInputValues( step.inputs, step.schema.inputs diff --git a/packages/server/src/events/index.js b/packages/server/src/events/index.js index 6fd97487d6..93fdd69d6b 100644 --- a/packages/server/src/events/index.js +++ b/packages/server/src/events/index.js @@ -9,7 +9,7 @@ const { rowEmission, tableEmission } = require("./utils") /** * Extending the standard emitter to some syntactic sugar and standardisation to the emitted event. - * This is specifically quite important for mustache used in automations. + * This is specifically quite important for handlebars used in automations. */ class BudibaseEmitter extends EventEmitter { emitRow(eventName, appId, row, table = null) { diff --git a/packages/server/src/utilities/mustache.js b/packages/server/src/utilities/handlebars.js similarity index 64% rename from packages/server/src/utilities/mustache.js rename to packages/server/src/utilities/handlebars.js index 0428bdc03d..15fc512b5d 100644 --- a/packages/server/src/utilities/mustache.js +++ b/packages/server/src/utilities/handlebars.js @@ -5,17 +5,17 @@ handlebars.registerHelper("object", value => { }) /** - * When running mustache statements to execute on the context of the automation it possible user's may input mustache - * in a few different forms, some of which are invalid but are logically valid. An example of this would be the mustache + * When running handlebars statements to execute on the context of the automation it possible user's may input handlebars + * in a few different forms, some of which are invalid but are logically valid. An example of this would be the handlebars * statement "{{steps[0].revision}}" here it is obvious the user is attempting to access an array or object using array - * like operators. These are not supported by Mustache and therefore the statement will fail. This function will clean up - * the mustache statement so it instead reads as "{{steps.0.revision}}" which is valid and will work. It may also be expanded - * to include any other mustache statement cleanup that has been deemed necessary for the system. + * like operators. These are not supported by handlebars and therefore the statement will fail. This function will clean up + * the handlebars statement so it instead reads as "{{steps.0.revision}}" which is valid and will work. It may also be expanded + * to include any other handlebars statement cleanup that has been deemed necessary for the system. * - * @param {string} string The string which *may* contain mustache statements, it is OK if it does not contain any. - * @returns {string} The string that was input with cleaned up mustache statements as required. + * @param {string} string The string which *may* contain handlebars statements, it is OK if it does not contain any. + * @returns {string} The string that was input with cleaned up handlebars statements as required. */ -function cleanMustache(string) { +function cleanHandlebars(string) { let charToReplace = { "[": ".", "]": "", @@ -42,13 +42,13 @@ function cleanMustache(string) { /** * Given an input object this will recurse through all props to try and update - * any handlebars/mustache statements within. + * any handlebars statements within. * @param {object|array} inputs The input structure which is to be recursed, it is important to note that * if the structure contains any cycles then this will fail. * @param {object} context The context that handlebars should fill data from. * @returns {object|array} The structure input, as fully updated as possible. */ -function recurseMustache(inputs, context) { +function recurseHandlebars(inputs, context) { // JSON stringify will fail if there are any cycles, stops infinite recursion try { JSON.stringify(inputs) @@ -58,16 +58,16 @@ function recurseMustache(inputs, context) { for (let key of Object.keys(inputs)) { let val = inputs[key] if (typeof val === "string") { - val = cleanMustache(inputs[key]) + val = cleanHandlebars(inputs[key]) const template = handlebars.compile(val) inputs[key] = template(context) } // this covers objects and arrays else if (typeof val === "object") { - inputs[key] = recurseMustache(inputs[key], context) + inputs[key] = recurseHandlebars(inputs[key], context) } } return inputs } -exports.recurseMustache = recurseMustache +exports.recurseHandlebars = recurseHandlebars diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index 88ec4fa357..3fcf4f8240 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -200,10 +200,10 @@ lodash "^4.17.19" to-fast-properties "^2.0.0" -"@budibase/client@^0.4.3": - version "0.4.3" - resolved "https://registry.yarnpkg.com/@budibase/client/-/client-0.4.3.tgz#eaf1ac83ed04722c29ea51907ac7c2190bd09b74" - integrity sha512-gfVIU7P1HCMuH9rgmqgv2pD5oFDwwuX0QF3+FXuKR3/Cr6JW+bstVsNZHGgwOrmbxT3oAxfeNX186zrQupJ42w== +"@budibase/client@^0.5.3": + version "0.5.3" + resolved "https://registry.yarnpkg.com/@budibase/client/-/client-0.5.3.tgz#d2406b9a5b25ac446ba0f776b0ef3a38777a131a" + integrity sha512-pv8pMH5vxgvIAEl+2zjp1ScWAtqVWqeH65e9EDqX6oVK2AsnJe9r0HxywOHN5mCgOFxou972+39c6fYR9/enyw== dependencies: deep-equal "^2.0.1" mustache "^4.0.1"