From af7dd37ba43866a83803ef531ff42f749848eeb0 Mon Sep 17 00:00:00 2001 From: RDW Date: Wed, 17 Nov 2021 14:43:28 +0100 Subject: [PATCH 1/5] Repo: Add the uuid package as a regular dependency This can be used to easily generate unique identifiers. --- package-lock.json | 16 +++++++++++++++- package.json | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index c316416..1f9b840 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,8 @@ "bmp-js": "^0.1.0", "joi": "17.4.1", "maxrects-packer": "2.7.2", - "tippy.js": "6.3.6" + "tippy.js": "6.3.6", + "uuid": "8.3.2" }, "devDependencies": { "electron": "13.3.0", @@ -4685,6 +4686,14 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "dev": true }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", @@ -8484,6 +8493,11 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "dev": true }, + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + }, "v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", diff --git a/package.json b/package.json index f55506c..9868bff 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "bmp-js": "^0.1.0", "joi": "17.4.1", "maxrects-packer": "2.7.2", - "tippy.js": "6.3.6" + "tippy.js": "6.3.6", + "uuid": "8.3.2" }, "devDependencies": { "electron": "13.3.0", From fd3d7f638e0f8ddc0d17f76e2b916ba04e9ea9db Mon Sep 17 00:00:00 2001 From: RDW Date: Wed, 17 Nov 2021 14:57:22 +0100 Subject: [PATCH 2/5] Core: Add a global UniqueID builtin --- Config/eslint.json | 1 + Core/Builtins/UniqueID.js | 8 ++++++++ index.html | 1 + 3 files changed, 10 insertions(+) create mode 100644 Core/Builtins/UniqueID.js diff --git a/Config/eslint.json b/Config/eslint.json index a23575e..2865c37 100644 --- a/Config/eslint.json +++ b/Config/eslint.json @@ -88,6 +88,7 @@ "Table": "writable", "TerrainMap": "writable", "UIParent": "writable", + "UniqueID": "writable", "validateString": "writable", "validateNumber": "writable", "Vector3D": "writable", diff --git a/Core/Builtins/UniqueID.js b/Core/Builtins/UniqueID.js new file mode 100644 index 0000000..4b0468f --- /dev/null +++ b/Core/Builtins/UniqueID.js @@ -0,0 +1,8 @@ +class UniqueID { + constructor() { + this.identifier = UUID.v4(); + } + toString() { + return this.identifier; + } +} diff --git a/index.html b/index.html index 64796a3..7418e9e 100644 --- a/index.html +++ b/index.html @@ -141,4 +141,5 @@ + From 3e6e79742abba6d8f026bcd949e5b0691a51699d Mon Sep 17 00:00:00 2001 From: RDW Date: Wed, 17 Nov 2021 14:58:04 +0100 Subject: [PATCH 3/5] Core: Expose global UUID alias for the uuid API --- Config/eslint.json | 1 + Core/Aliases.js | 1 + 2 files changed, 2 insertions(+) diff --git a/Config/eslint.json b/Config/eslint.json index 2865c37..f8fb8cb 100644 --- a/Config/eslint.json +++ b/Config/eslint.json @@ -88,6 +88,7 @@ "Table": "writable", "TerrainMap": "writable", "UIParent": "writable", + "UUID": "writable", "UniqueID": "writable", "validateString": "writable", "validateNumber": "writable", diff --git a/Core/Aliases.js b/Core/Aliases.js index c6af883..4e75729 100644 --- a/Core/Aliases.js +++ b/Core/Aliases.js @@ -9,6 +9,7 @@ const BABYLON = require("babylonjs/babylon.max"); // C_WebGL & C_Sound const BITMAP = require("bmp-js"); // C_Bitmap const MESSAGEPACK = require("@msgpack/msgpack"); // C_Message const JOI = require("joi"); // C_Validation +const UUID = require("uuid"); // UniqueID builtin function dump(...data) { console.log(data); From 312ca1de5abedf2df7e6d5e8b82de59c3a4665e0 Mon Sep 17 00:00:00 2001 From: RDW Date: Wed, 17 Nov 2021 14:59:06 +0100 Subject: [PATCH 4/5] Tests: Create a basic test suite for the global aliases --- Core/Aliases.js | 8 ++++++++ Tests/SharedConstants/Aliases.js | 16 ++++++++++++++++ Tests/run-renderer-tests.js | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Tests/SharedConstants/Aliases.js diff --git a/Core/Aliases.js b/Core/Aliases.js index 4e75729..94efc63 100644 --- a/Core/Aliases.js +++ b/Core/Aliases.js @@ -19,3 +19,11 @@ function printf(message, ...rest) { // If we don't check the length, it will print an empty array when there are no parameters rest.length > 0 ? console.log(message, ...rest) : console.log(message); } + +// Explicitly export so that their presence can be tested for more easily +// BABYLON already exports itself globally by default +window.BITMAP = BITMAP; +window.JOI = JOI; +window.MESSAGEPACK = MESSAGEPACK; +window.NODE = NODE; +window.UUID = UUID; diff --git a/Tests/SharedConstants/Aliases.js b/Tests/SharedConstants/Aliases.js new file mode 100644 index 0000000..c8a181d --- /dev/null +++ b/Tests/SharedConstants/Aliases.js @@ -0,0 +1,16 @@ +describe("Aliases", () => { + const exportedObjects = ["BABYLON", "BITMAP", "JOI", "MESSAGEPACK", "NODE", "UUID"]; + const exportedFunctions = ["dump", "printf"]; + + exportedObjects.forEach((namedExport) => { + it("should export global object " + namedExport, () => { + assertEquals(typeof window[namedExport], "object"); + }); + }); + + exportedFunctions.forEach((namedExport) => { + it("should export global function " + namedExport, () => { + assertEquals(typeof window[namedExport], "function"); + }); + }); +}); diff --git a/Tests/run-renderer-tests.js b/Tests/run-renderer-tests.js index 8f3b82c..12121d2 100644 --- a/Tests/run-renderer-tests.js +++ b/Tests/run-renderer-tests.js @@ -1,6 +1,6 @@ const testSuites = { - SharedConstants: ["SharedConstants/Paths.js"], Builtins: ["Builtins/Assertions.js", "Builtins/LocalCacheTests.js", "Builtins/Validators.js"], + SharedConstants: ["SharedConstants/Aliases.js", "SharedConstants/Paths.js"], C_Settings: [ "API/C_Settings/validate.js", "API/C_Settings/validateDefaultSettings.js", From 5fc77c959792f3ab430da5d1e18daf51482c1693 Mon Sep 17 00:00:00 2001 From: RDW Date: Wed, 17 Nov 2021 14:59:22 +0100 Subject: [PATCH 5/5] Tests: Create a basic test suite for the UniqueID builtin --- Tests/Builtins/UniqueID.js | 13 +++++++++++++ Tests/run-renderer-tests.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 Tests/Builtins/UniqueID.js diff --git a/Tests/Builtins/UniqueID.js b/Tests/Builtins/UniqueID.js new file mode 100644 index 0000000..bcc5883 --- /dev/null +++ b/Tests/Builtins/UniqueID.js @@ -0,0 +1,13 @@ +describe("UniqueID", () => { + it("should be exported into the global environment", () => { + assertEquals(UniqueID.name, "UniqueID"); + }); + + let exportedApiSurface = ["toString"]; + + exportedApiSurface.forEach((namedExport) => { + it("should export function " + namedExport, () => { + assertEquals(typeof UniqueID[namedExport], "function"); + }); + }); +}); diff --git a/Tests/run-renderer-tests.js b/Tests/run-renderer-tests.js index 12121d2..65f2316 100644 --- a/Tests/run-renderer-tests.js +++ b/Tests/run-renderer-tests.js @@ -1,6 +1,6 @@ const testSuites = { - Builtins: ["Builtins/Assertions.js", "Builtins/LocalCacheTests.js", "Builtins/Validators.js"], SharedConstants: ["SharedConstants/Aliases.js", "SharedConstants/Paths.js"], + Builtins: ["Builtins/Assertions.js", "Builtins/LocalCacheTests.js", "Builtins/UniqueID.js", "Builtins/Validators.js"], C_Settings: [ "API/C_Settings/validate.js", "API/C_Settings/validateDefaultSettings.js",