From fb56fec531b45fa97e380b12e7577f9abcde11ac Mon Sep 17 00:00:00 2001 From: Marc Stirner Date: Wed, 3 Jan 2024 12:46:24 +0100 Subject: [PATCH 1/4] fix #394 --- components/endpoints/class.command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/endpoints/class.command.js b/components/endpoints/class.command.js index f39f4e4..77bfe26 100644 --- a/components/endpoints/class.command.js +++ b/components/endpoints/class.command.js @@ -273,7 +273,7 @@ module.exports = class Command { //payload: Joi.string().allow(null).default(null), payload: Joi.alternatives().try(Joi.string(), Joi.binary()).allow(null).default(null), description: Joi.string().allow(null).default(null), - params: Joi.array().items(Param.schema()) + params: Joi.array().items(Param.schema()).default([]) }); } From 15590969c3f2aa9a6f2651be08f0b3193a494af7 Mon Sep 17 00:00:00 2001 From: Marc Stirner Date: Wed, 3 Jan 2024 12:46:54 +0100 Subject: [PATCH 2/4] fix #392 --- components/scenes/class.scene.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/scenes/class.scene.js b/components/scenes/class.scene.js index 700f063..626a66c 100644 --- a/components/scenes/class.scene.js +++ b/components/scenes/class.scene.js @@ -80,7 +80,8 @@ module.exports = class Scene extends Item { name: Joi.string().required(), makros: Joi.array().items(Makro.schema()).default([]), triggers: Joi.array().items(Trigger.schema()).default([]), - visible: Joi.boolean().default(true) + visible: Joi.boolean().default(true), + icon: Joi.string().allow(null).default(null) }); } From e6c838c09add43eb40833c0575c3d72372d41634 Mon Sep 17 00:00:00 2001 From: Marc Stirner Date: Wed, 3 Jan 2024 14:56:18 +0100 Subject: [PATCH 3/4] fix #395 --- components/store/class.store.js | 8 +++++--- components/store/class.value.js | 1 + components/store/index.js | 4 ++++ postman.json | 4 ++-- tests/components/store.js | 16 ++++++++-------- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/components/store/class.store.js b/components/store/class.store.js index b47b934..25848cf 100644 --- a/components/store/class.store.js +++ b/components/store/class.store.js @@ -67,11 +67,13 @@ module.exports = class Store extends Item { _id: Joi.string().pattern(/^[0-9a-fA-F]{24}$/).default(() => { return String(new mongodb.ObjectId()); }), + name: Joi.string().required(), + description: Joi.string().allow(null).default(null), config: Joi.array().min(1).items(Value.schema()).required(), - item: Joi.string().allow(null).default(null), - namespace: Joi.string().default(() => { + //item: Joi.string().allow(null).default(null), + uuid: Joi.string().default(() => { return uuid.v4(); - }), + }) }); } diff --git a/components/store/class.value.js b/components/store/class.value.js index 9a20df1..3daa0ff 100644 --- a/components/store/class.value.js +++ b/components/store/class.value.js @@ -60,6 +60,7 @@ class Value { _id: Joi.string().pattern(/^[0-9a-fA-F]{24}$/).default(() => { return String(new mongodb.ObjectId()); }), + name: Joi.string().required(), key: Joi.string().required(), value: Joi.when("type", { is: "number", diff --git a/components/store/index.js b/components/store/index.js index 012c478..d49fb60 100644 --- a/components/store/index.js +++ b/components/store/index.js @@ -39,6 +39,10 @@ class C_STORE extends COMPONENT { next(null, new Store(data, this)); }); + this.collection.createIndex("uuid", { + unique: true + }); + } } diff --git a/postman.json b/postman.json index a619ad3..c5a51c6 100644 --- a/postman.json +++ b/postman.json @@ -2378,7 +2378,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\n \"_id\": \"65818986ca5133d8de2bb4a1\",\n \"config\": [{\n \"_id\": \"6581a14f1c6d01f32129dabc\",\n \"key\": \"pairing\",\n \"type\": \"boolean\",\n \"value\": false,\n \"description\": \"Is the Gateway ready for pairing?\"\n }, {\n \"_id\": \"6581a1520bcb15659d48b207\",\n \"key\": \"interval\",\n \"type\": \"number\",\n \"value\": 3000,\n \"description\": \"Sync intervall for Endpoints\"\n }]\n}", + "raw": "{\n \"name\": \"Store item #1\",\n \"description\": \"Configuration settings for pluginx xyz\",\n \"_id\": \"65818986ca5133d8de2bb4a1\",\n \"config\": [{\n \"_id\": \"6581a14f1c6d01f32129dabc\",\n \"name\": \"Gateway Pairing\",\n \"key\": \"pairing\",\n \"type\": \"boolean\",\n \"value\": false,\n \"description\": \"Is the Gateway ready for pairing?\"\n }, {\n \"_id\": \"6581a1520bcb15659d48b207\",\n \"name\": \"Polling Interval\",\n \"key\": \"interval\",\n \"type\": \"number\",\n \"value\": 3000,\n \"description\": \"Sync intervall for Endpoints\"\n }]\n}", "options": { "raw": { "language": "json" @@ -2525,7 +2525,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\n \"item\": \"6375343d0b555ccd42460a2e\",\n \"labels\": [\n \"device=65818918d32dad8dab53e433\",\n \"endpoint=658189336fa19198939caa21\"\n ]\n}", + "raw": "{\n \"labels\": [\n \"device=65818918d32dad8dab53e433\",\n \"endpoint=658189336fa19198939caa21\"\n ]\n}", "options": { "raw": { "language": "json" diff --git a/tests/components/store.js b/tests/components/store.js index 1677cb3..3e9e594 100644 --- a/tests/components/store.js +++ b/tests/components/store.js @@ -10,17 +10,20 @@ try { const workflow = require("./test.workflow.js"); let _id = String(new mongodb.ObjectId()); - let namespace = String(new mongodb.ObjectId()); + let uuid = uuidv4(); workflow(C_COMPONENT, "add", (done, { event }) => { C_COMPONENT.add({ _id, + name: "Test store", + description: "Test item for unit tests", config: [{ + name: "Test Key", key: "key", type: "string", description: "Test key" }], - namespace + uuid }, (err, item) => { // check event arguments @@ -57,16 +60,13 @@ try { workflow(C_COMPONENT, "update", (done) => { - let uuid = uuidv4(); - C_COMPONENT.update(_id, { - item: uuid + name: "Updated Name" }, (err, item) => { try { assert.ok(err === null); assert.equal(item instanceof Store, true); - assert.equal(item.item, uuid); done(err); @@ -85,12 +85,12 @@ try { // update call 1 C_COMPONENT.update(_id, { - item: uuidv4() + uuid: uuidv4() }), // update call 2 C_COMPONENT.update(_id, { - item: uuidv4() + name: "New config/store name" }) ]).then(() => { From 451fa5ebdc720e401704b81532515185e48404fc Mon Sep 17 00:00:00 2001 From: Marc Stirner Date: Thu, 4 Jan 2024 10:47:58 +0100 Subject: [PATCH 4/4] note added --- system/component/class.component.js | 1 + 1 file changed, 1 insertion(+) diff --git a/system/component/class.component.js b/system/component/class.component.js index 2ea63bc..d6359c4 100644 --- a/system/component/class.component.js +++ b/system/component/class.component.js @@ -340,6 +340,7 @@ module.exports = class COMPONENT extends COMMON { let item = this.items.find((item) => { + // NOTE: rename value to key return Object.keys(err.keyValue).every((value) => { // fixing "Duplicate unique key/index in database, but no matching item"