Merge pull request #12572 from Budibase/feature/uuid-helper

HBS/JS UUID helper
This commit is contained in:
Michael Drury 2023-12-18 12:37:03 +00:00 committed by GitHub
commit 22c0e81308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 70 additions and 745 deletions

View File

@ -79,6 +79,7 @@
bind:this={popover} bind:this={popover}
anchor={popoverAnchor} anchor={popoverAnchor}
maxWidth={300} maxWidth={300}
maxHeight={300}
dismissible={false} dismissible={false}
> >
<Layout gap="S"> <Layout gap="S">

View File

@ -1180,6 +1180,14 @@
"description": "<p>Stringify an object using <code>JSON.stringify</code>.</p>\n" "description": "<p>Stringify an object using <code>JSON.stringify</code>.</p>\n"
} }
}, },
"uuid": {
"uuid": {
"args": [],
"numArgs": 0,
"example": "{{ uuid }} -> f34ebc66-93bd-4f7c-b79b-92b5569138bc",
"description": "<p>Generates a UUID, using the V4 method (identical to the browser crypto.randomUUID function).</p>\n"
}
},
"date": { "date": {
"date": { "date": {
"args": [ "args": [

View File

@ -25,7 +25,7 @@
"manifest": "node ./scripts/gen-collection-info.js" "manifest": "node ./scripts/gen-collection-info.js"
}, },
"dependencies": { "dependencies": {
"@budibase/handlebars-helpers": "^0.11.9", "@budibase/handlebars-helpers": "^0.11.11",
"dayjs": "^1.10.8", "dayjs": "^1.10.8",
"handlebars": "^4.7.6", "handlebars": "^4.7.6",
"lodash": "4.17.21", "lodash": "4.17.21",

View File

@ -20,6 +20,7 @@ const COLLECTIONS = [
"string", "string",
"comparison", "comparison",
"object", "object",
"uuid",
] ]
const FILENAME = join(__dirname, "..", "manifest.json") const FILENAME = join(__dirname, "..", "manifest.json")
const outputJSON = {} const outputJSON = {}

View File

@ -16,6 +16,7 @@ const EXTERNAL_FUNCTION_COLLECTIONS = [
"comparison", "comparison",
"object", "object",
"regex", "regex",
"uuid",
] ]
const ADDED_HELPERS = { const ADDED_HELPERS = {

View File

@ -0,0 +1,2 @@
module.exports.UUID_REGEX =
/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i

View File

@ -1,6 +1,7 @@
const { processString, processObject, isValid } = require("../src/index.cjs") const { processString, processObject, isValid } = require("../src/index.cjs")
const tableJson = require("./examples/table.json") const tableJson = require("./examples/table.json")
const dayjs = require("dayjs") const dayjs = require("dayjs")
const { UUID_REGEX } = require("./constants")
describe("test the custom helpers we have applied", () => { describe("test the custom helpers we have applied", () => {
it("should be able to use the object helper", async () => { it("should be able to use the object helper", async () => {
@ -477,3 +478,10 @@ describe("Cover a few complex use cases", () => {
expect(output.dataProvider).toBe("%5B%221%22%2C%221%22%5D") expect(output.dataProvider).toBe("%5B%221%22%2C%221%22%5D")
}) })
}) })
describe("uuid", () => {
it("should be able to generate a UUID", async () => {
const output = await processString("{{ uuid }}", {})
expect(output).toMatch(UUID_REGEX)
})
})

View File

@ -1,4 +1,5 @@
const { processStringSync, encodeJSBinding } = require("../src/index.cjs") const { processStringSync, encodeJSBinding } = require("../src/index.cjs")
const { UUID_REGEX } = require("./constants")
const processJS = (js, context) => { const processJS = (js, context) => {
return processStringSync(encodeJSBinding(js), context) return processStringSync(encodeJSBinding(js), context)
@ -140,4 +141,9 @@ describe("check JS helpers", () => {
const output = processJS(`return helpers.toInt(4.3)`) const output = processJS(`return helpers.toInt(4.3)`)
expect(output).toBe(4) expect(output).toBe(4)
}) })
it("should be able to use uuid", () => {
const output = processJS(`return helpers.uuid()`)
expect(output).toMatch(UUID_REGEX)
})
}) })

786
yarn.lock

File diff suppressed because it is too large Load Diff