@iobroker/repochecker 5.18.0 → 5.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/config_StateRoles.js +10 -8
- package/lib/objectStructure.js +117 -85
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,9 +25,9 @@ Example:
|
|
|
25
25
|
Placeholder for the next version (at the beginning of the line):
|
|
26
26
|
### **WORK IN PROGRESS**
|
|
27
27
|
-->
|
|
28
|
-
### 5.18.
|
|
28
|
+
### 5.18.2 (2026-06-05)
|
|
29
29
|
|
|
30
|
-
- (mcm1957) Support for objectStructure
|
|
30
|
+
- (mcm1957) Support for objectStructure check added
|
|
31
31
|
|
|
32
32
|
### 5.17.9 (2026-06-04)
|
|
33
33
|
|
package/lib/config_StateRoles.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const ROOT_OBJECT_SCHEMA = {
|
|
4
|
-
_id: 'string',
|
|
5
|
-
type: 'string',
|
|
6
|
-
common: 'object',
|
|
7
|
-
native: 'object',
|
|
8
|
-
from: 'string',
|
|
9
|
-
ts: 'number',
|
|
10
|
-
acl: 'object',
|
|
11
|
-
user: 'string',
|
|
4
|
+
_id: { type: 'string' },
|
|
5
|
+
type: { type: 'string' },
|
|
6
|
+
common: { type: 'object' },
|
|
7
|
+
native: { type: 'object' },
|
|
8
|
+
from: { type: 'string', optional: true },
|
|
9
|
+
ts: { type: 'number', optional: true },
|
|
10
|
+
acl: { type: 'object', optional: true },
|
|
11
|
+
user: { type: 'string', optional: true },
|
|
12
|
+
ack: { type: 'boolean', optional: true },
|
|
13
|
+
val: { optional: true, matchesCommonType: true },
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
const ALLOWED_OBJECT_TYPES = new Set([
|
package/lib/objectStructure.js
CHANGED
|
@@ -56,7 +56,7 @@ const ROLE_RULES = (() => {
|
|
|
56
56
|
})();
|
|
57
57
|
|
|
58
58
|
const FORBIDDEN_ID_CHARS_REGEX = /[^._\-/ :!#$%&()+=@^{}|~\p{Ll}\p{Lu}\p{Nd}]+/gu;
|
|
59
|
-
const ID_SUGGESTION_REGEX
|
|
59
|
+
const ID_SUGGESTION_REGEX = /[^a-zA-Z0-9_,-.]+/g;
|
|
60
60
|
|
|
61
61
|
// ---------------------------------------------------------------------------
|
|
62
62
|
// Internal helpers
|
|
@@ -64,7 +64,7 @@ const ID_SUGGESTION_REGEX = /[^a-zA-Z0-9_,-.]+/g;
|
|
|
64
64
|
|
|
65
65
|
function getValueType(value) {
|
|
66
66
|
if (Array.isArray(value)) return 'array';
|
|
67
|
-
if (value === null)
|
|
67
|
+
if (value === null) return 'null';
|
|
68
68
|
return typeof value;
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -74,23 +74,31 @@ function isPlainObject(value) {
|
|
|
74
74
|
|
|
75
75
|
function isStringOrI18nObject(value) {
|
|
76
76
|
if (typeof value === 'string') return true;
|
|
77
|
-
if (!isPlainObject(value))
|
|
77
|
+
if (!isPlainObject(value)) return false;
|
|
78
78
|
const vals = Object.values(value);
|
|
79
79
|
return vals.length > 0 && vals.every(v => typeof v === 'string');
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
function matchesCommonType(value, commonType) {
|
|
83
83
|
switch (commonType) {
|
|
84
|
-
case 'mixed':
|
|
85
|
-
|
|
86
|
-
case '
|
|
87
|
-
|
|
88
|
-
case '
|
|
84
|
+
case 'mixed':
|
|
85
|
+
return true;
|
|
86
|
+
case 'array':
|
|
87
|
+
return Array.isArray(value);
|
|
88
|
+
case 'boolean':
|
|
89
|
+
return typeof value === 'boolean';
|
|
90
|
+
case 'number':
|
|
91
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
92
|
+
case 'object':
|
|
93
|
+
return isPlainObject(value);
|
|
89
94
|
case 'string':
|
|
90
95
|
case 'file':
|
|
91
|
-
case 'json':
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
case 'json':
|
|
97
|
+
return typeof value === 'string';
|
|
98
|
+
case 'multistate':
|
|
99
|
+
return ['string', 'number', 'boolean'].includes(typeof value);
|
|
100
|
+
default:
|
|
101
|
+
return false;
|
|
94
102
|
}
|
|
95
103
|
}
|
|
96
104
|
|
|
@@ -99,7 +107,7 @@ function matchesCommonType(value, commonType) {
|
|
|
99
107
|
// ---------------------------------------------------------------------------
|
|
100
108
|
|
|
101
109
|
function createRoleRuleMaps() {
|
|
102
|
-
const exactRules
|
|
110
|
+
const exactRules = new Map();
|
|
103
111
|
const prefixRules = [];
|
|
104
112
|
|
|
105
113
|
for (const [role, rule] of Object.entries(ROLE_RULES)) {
|
|
@@ -137,14 +145,18 @@ function getRoleRule(role, { exactRules, prefixRules }) {
|
|
|
137
145
|
// ---------------------------------------------------------------------------
|
|
138
146
|
|
|
139
147
|
function createCollector() {
|
|
140
|
-
const errors
|
|
148
|
+
const errors = [];
|
|
141
149
|
const warnings = [];
|
|
142
150
|
|
|
143
151
|
return {
|
|
144
|
-
error:
|
|
152
|
+
error: (code, message) => errors.push({ code, message }),
|
|
145
153
|
warning: (code, message) => warnings.push({ code, message }),
|
|
146
|
-
get errors()
|
|
147
|
-
|
|
154
|
+
get errors() {
|
|
155
|
+
return errors;
|
|
156
|
+
},
|
|
157
|
+
get warnings() {
|
|
158
|
+
return warnings;
|
|
159
|
+
},
|
|
148
160
|
};
|
|
149
161
|
}
|
|
150
162
|
|
|
@@ -166,23 +178,22 @@ function validateStateCommon(stateId, common, collector, roleRuleMaps) {
|
|
|
166
178
|
}
|
|
167
179
|
|
|
168
180
|
// Allowed bare keys derived from schema
|
|
169
|
-
const schemaKeys = new Set(
|
|
170
|
-
Object.keys(STATE_SCHEMA).map(k => k.slice('common.'.length))
|
|
171
|
-
);
|
|
181
|
+
const schemaKeys = new Set(Object.keys(STATE_SCHEMA).map(k => k.slice('common.'.length)));
|
|
172
182
|
|
|
173
183
|
const unsupportedKeys = Object.keys(common).filter(k => !schemaKeys.has(k));
|
|
174
184
|
if (unsupportedKeys.length > 0) {
|
|
175
|
-
collector.error(
|
|
176
|
-
|
|
185
|
+
collector.error(
|
|
186
|
+
'E1002',
|
|
187
|
+
`Object "${stateId}": common contains unsupported keys: ${unsupportedKeys.join(', ')}.`,
|
|
188
|
+
);
|
|
177
189
|
}
|
|
178
190
|
|
|
179
191
|
for (const [schemaKey, schema] of Object.entries(STATE_SCHEMA)) {
|
|
180
|
-
const bareKey
|
|
192
|
+
const bareKey = schemaKey.slice('common.'.length);
|
|
181
193
|
const hasValue = Object.prototype.hasOwnProperty.call(common, bareKey);
|
|
182
194
|
|
|
183
195
|
if (schema.required && !hasValue) {
|
|
184
|
-
collector.error('E1003',
|
|
185
|
-
`Object "${stateId}": common is missing required key "${schemaKey}".`);
|
|
196
|
+
collector.error('E1003', `Object "${stateId}": common is missing required key "${schemaKey}".`);
|
|
186
197
|
continue;
|
|
187
198
|
}
|
|
188
199
|
|
|
@@ -191,47 +202,57 @@ function validateStateCommon(stateId, common, collector, roleRuleMaps) {
|
|
|
191
202
|
const value = common[bareKey];
|
|
192
203
|
|
|
193
204
|
if (schema.types && !schema.types.includes(getValueType(value))) {
|
|
194
|
-
collector.error(
|
|
195
|
-
|
|
205
|
+
collector.error(
|
|
206
|
+
'E1004',
|
|
207
|
+
`Object "${stateId}": "${schemaKey}" must be of type ${schema.types.join(' or ')}.`,
|
|
208
|
+
);
|
|
196
209
|
continue;
|
|
197
210
|
}
|
|
198
211
|
|
|
199
212
|
if (schema.onlyForTypes && !schema.onlyForTypes.includes(common.type)) {
|
|
200
|
-
collector.error(
|
|
201
|
-
|
|
213
|
+
collector.error(
|
|
214
|
+
'E1005',
|
|
215
|
+
`Object "${stateId}": "${schemaKey}" is only allowed for common.type = ${schema.onlyForTypes.join(' or ')}.`,
|
|
216
|
+
);
|
|
202
217
|
}
|
|
203
218
|
|
|
204
219
|
if (schema.matchesCommonType && common.type && !matchesCommonType(value, common.type)) {
|
|
205
|
-
collector.error(
|
|
206
|
-
|
|
220
|
+
collector.error(
|
|
221
|
+
'E1006',
|
|
222
|
+
`Object "${stateId}": "${schemaKey}" value must match common.type "${common.type}".`,
|
|
223
|
+
);
|
|
207
224
|
}
|
|
208
225
|
|
|
209
226
|
if (schema.name && !isStringOrI18nObject(value)) {
|
|
210
|
-
collector.error('E1007',
|
|
211
|
-
`Object "${stateId}": "${schemaKey}" must be a string or an i18n object.`);
|
|
227
|
+
collector.error('E1007', `Object "${stateId}": "${schemaKey}" must be a string or an i18n object.`);
|
|
212
228
|
}
|
|
213
229
|
|
|
214
230
|
if (schema.role) {
|
|
215
231
|
const roleRule = getRoleRule(value, roleRuleMaps);
|
|
216
232
|
if (!roleRule) {
|
|
217
|
-
collector.error('E1008',
|
|
218
|
-
`Object "${stateId}": unknown role "${value}".`);
|
|
233
|
+
collector.error('E1008', `Object "${stateId}": unknown role "${value}".`);
|
|
219
234
|
continue;
|
|
220
235
|
}
|
|
221
236
|
|
|
222
237
|
if (Array.isArray(roleRule.types) && common.type && !roleRule.types.includes(common.type)) {
|
|
223
|
-
collector.error(
|
|
224
|
-
|
|
238
|
+
collector.error(
|
|
239
|
+
'E1009',
|
|
240
|
+
`Object "${stateId}": role "${value}" does not support common.type "${common.type}".`,
|
|
241
|
+
);
|
|
225
242
|
}
|
|
226
243
|
|
|
227
244
|
if (typeof roleRule.read === 'boolean' && common.read !== roleRule.read) {
|
|
228
|
-
collector.error(
|
|
229
|
-
|
|
245
|
+
collector.error(
|
|
246
|
+
'E1010',
|
|
247
|
+
`Object "${stateId}": role "${value}" requires common.read = ${roleRule.read}.`,
|
|
248
|
+
);
|
|
230
249
|
}
|
|
231
250
|
|
|
232
251
|
if (typeof roleRule.write === 'boolean' && common.write !== roleRule.write) {
|
|
233
|
-
collector.error(
|
|
234
|
-
|
|
252
|
+
collector.error(
|
|
253
|
+
'E1011',
|
|
254
|
+
`Object "${stateId}": role "${value}" requires common.write = ${roleRule.write}.`,
|
|
255
|
+
);
|
|
235
256
|
}
|
|
236
257
|
}
|
|
237
258
|
}
|
|
@@ -244,36 +265,31 @@ function validateStateCommon(stateId, common, collector, roleRuleMaps) {
|
|
|
244
265
|
function validateHierarchyObjectOrder(objectsById, idsToCheck, collector) {
|
|
245
266
|
for (const objectId of idsToCheck) {
|
|
246
267
|
const levels = objectId.split('.');
|
|
247
|
-
const chain
|
|
268
|
+
const chain = [];
|
|
248
269
|
|
|
249
270
|
for (let i = 3; i <= levels.length; i++) {
|
|
250
|
-
const levelId
|
|
271
|
+
const levelId = levels.slice(0, i).join('.');
|
|
251
272
|
const levelObj = objectsById[levelId];
|
|
252
273
|
if (levelObj) chain.push({ id: levelId, type: levelObj.type });
|
|
253
274
|
}
|
|
254
275
|
|
|
255
276
|
const hasHierarchyMember = chain.some(e => HIERARCHY_TYPES.has(e.type));
|
|
256
277
|
if (hasHierarchyMember && chain.some(e => !HIERARCHY_TYPES.has(e.type))) {
|
|
257
|
-
collector.error('E2001',
|
|
258
|
-
`Object "${objectId}": hierarchy contains non-hierarchy object types.`);
|
|
278
|
+
collector.error('E2001', `Object "${objectId}": hierarchy contains non-hierarchy object types.`);
|
|
259
279
|
}
|
|
260
280
|
|
|
261
281
|
if (chain.filter(e => e.type === 'device').length > 1) {
|
|
262
|
-
collector.error('E2002',
|
|
263
|
-
`Object "${objectId}": hierarchy contains more than one device.`);
|
|
282
|
+
collector.error('E2002', `Object "${objectId}": hierarchy contains more than one device.`);
|
|
264
283
|
}
|
|
265
284
|
|
|
266
285
|
const firstChannelIdx = chain.findIndex(e => e.type === 'channel');
|
|
267
|
-
if (firstChannelIdx !== -1 &&
|
|
268
|
-
|
|
269
|
-
collector.error('E2003',
|
|
270
|
-
`Object "${objectId}": hierarchy contains a device after a channel.`);
|
|
286
|
+
if (firstChannelIdx !== -1 && chain.slice(firstChannelIdx + 1).some(e => e.type === 'device')) {
|
|
287
|
+
collector.error('E2003', `Object "${objectId}": hierarchy contains a device after a channel.`);
|
|
271
288
|
}
|
|
272
289
|
|
|
273
290
|
for (let i = 0; i < chain.length - 1; i++) {
|
|
274
291
|
if (chain[i].type === 'state') {
|
|
275
|
-
collector.error('E2004',
|
|
276
|
-
`Object "${objectId}": state object "${chain[i].id}" has children.`);
|
|
292
|
+
collector.error('E2004', `Object "${objectId}": state object "${chain[i].id}" has children.`);
|
|
277
293
|
break;
|
|
278
294
|
}
|
|
279
295
|
}
|
|
@@ -295,48 +311,64 @@ function validateObjectDump(objects, adapter, collector) {
|
|
|
295
311
|
// Every root key must match its record's _id
|
|
296
312
|
for (const [rootKey, rootObj] of entries) {
|
|
297
313
|
if (!isPlainObject(rootObj) || rootObj._id !== rootKey) {
|
|
298
|
-
collector.error(
|
|
299
|
-
|
|
314
|
+
collector.error(
|
|
315
|
+
'E3002',
|
|
316
|
+
`Root object "${rootKey}": invalid — expected a plain object with _id === "${rootKey}".`,
|
|
317
|
+
);
|
|
300
318
|
}
|
|
301
319
|
}
|
|
302
320
|
|
|
303
321
|
if (collector.errors.length > 0) {
|
|
304
|
-
collector.error('E3003',
|
|
305
|
-
'Input is not a valid ioBroker object dump — processing aborted.');
|
|
322
|
+
collector.error('E3003', 'Input is not a valid ioBroker object dump — processing aborted.');
|
|
306
323
|
return [];
|
|
307
324
|
}
|
|
308
325
|
|
|
309
326
|
const roleRuleMaps = createRoleRuleMaps();
|
|
310
|
-
const relevantIds
|
|
327
|
+
const relevantIds = [];
|
|
311
328
|
|
|
312
329
|
for (const [objectId, objectData] of entries) {
|
|
313
|
-
|
|
314
330
|
// --- Root-schema key presence and types ---
|
|
315
|
-
for (const [
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
331
|
+
for (const [schemaKey, descriptor] of Object.entries(ROOT_OBJECT_SCHEMA)) {
|
|
332
|
+
const present = Object.prototype.hasOwnProperty.call(objectData, schemaKey);
|
|
333
|
+
if (!present) {
|
|
334
|
+
if (!descriptor.optional) {
|
|
335
|
+
collector.error('E3004', `Object "${objectId}": missing required key "${schemaKey}".`);
|
|
336
|
+
}
|
|
337
|
+
// optional + absent → silently skip
|
|
319
338
|
continue;
|
|
320
339
|
}
|
|
321
|
-
const actualType = getValueType(objectData[
|
|
322
|
-
if (actualType !==
|
|
323
|
-
collector.error(
|
|
324
|
-
|
|
340
|
+
const actualType = getValueType(objectData[schemaKey]);
|
|
341
|
+
if (descriptor.type && actualType !== descriptor.type) {
|
|
342
|
+
collector.error(
|
|
343
|
+
'E3005',
|
|
344
|
+
`Object "${objectId}": key "${schemaKey}" must be type ${descriptor.type}, got ${actualType}.`,
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
if (descriptor.matchesCommonType) {
|
|
348
|
+
const commonType = objectData.common && objectData.common.type;
|
|
349
|
+
if (commonType && !matchesCommonType(objectData[schemaKey], commonType)) {
|
|
350
|
+
collector.error(
|
|
351
|
+
'E3005',
|
|
352
|
+
`Object "${objectId}": key "${schemaKey}" must match common.type "${commonType}".`,
|
|
353
|
+
);
|
|
354
|
+
}
|
|
325
355
|
}
|
|
326
356
|
}
|
|
327
357
|
|
|
328
358
|
// --- No extra root keys ---
|
|
329
|
-
const unsupportedKeys = Object.keys(objectData)
|
|
330
|
-
|
|
359
|
+
const unsupportedKeys = Object.keys(objectData).filter(
|
|
360
|
+
k => !Object.prototype.hasOwnProperty.call(ROOT_OBJECT_SCHEMA, k),
|
|
361
|
+
);
|
|
331
362
|
if (unsupportedKeys.length > 0) {
|
|
332
|
-
collector.error(
|
|
333
|
-
|
|
363
|
+
collector.error(
|
|
364
|
+
'E3006',
|
|
365
|
+
`Object "${objectId}": contains unsupported root keys: ${unsupportedKeys.join(', ')}.`,
|
|
366
|
+
);
|
|
334
367
|
}
|
|
335
368
|
|
|
336
369
|
// --- Known object type ---
|
|
337
370
|
if (!ALLOWED_OBJECT_TYPES.has(objectData.type)) {
|
|
338
|
-
collector.error('E3007',
|
|
339
|
-
`Object "${objectId}": unknown type "${objectData.type}".`);
|
|
371
|
+
collector.error('E3007', `Object "${objectId}": unknown type "${objectData.type}".`);
|
|
340
372
|
}
|
|
341
373
|
|
|
342
374
|
if (HIERARCHY_TYPES.has(objectData.type)) {
|
|
@@ -347,15 +379,19 @@ function validateObjectDump(objects, adapter, collector) {
|
|
|
347
379
|
FORBIDDEN_ID_CHARS_REGEX.lastIndex = 0;
|
|
348
380
|
if (FORBIDDEN_ID_CHARS_REGEX.test(objectId)) {
|
|
349
381
|
const sanitized = objectId.replace(FORBIDDEN_ID_CHARS_REGEX, '');
|
|
350
|
-
collector.error(
|
|
351
|
-
|
|
382
|
+
collector.error(
|
|
383
|
+
'E3008',
|
|
384
|
+
`Object id "${objectId}": contains forbidden characters. Suggested id: "${sanitized}".`,
|
|
385
|
+
);
|
|
352
386
|
}
|
|
353
387
|
|
|
354
388
|
const suggestionMatches = objectId.match(ID_SUGGESTION_REGEX);
|
|
355
389
|
if (suggestionMatches) {
|
|
356
390
|
const uniqueChars = [...new Set(suggestionMatches.join('').split(''))].join('');
|
|
357
|
-
collector.warning(
|
|
358
|
-
|
|
391
|
+
collector.warning(
|
|
392
|
+
'W3001',
|
|
393
|
+
`Object id "${objectId}": contains non [a-zA-Z0-9_,-] characters (${uniqueChars}). Consider removing them.`,
|
|
394
|
+
);
|
|
359
395
|
}
|
|
360
396
|
}
|
|
361
397
|
|
|
@@ -366,8 +402,7 @@ function validateObjectDump(objects, adapter, collector) {
|
|
|
366
402
|
for (let i = 3; i < levels.length; i++) {
|
|
367
403
|
const prefix = levels.slice(0, i).join('.');
|
|
368
404
|
if (!Object.prototype.hasOwnProperty.call(objects, prefix)) {
|
|
369
|
-
collector.error('E3009',
|
|
370
|
-
`Object "${objectId}": missing intermediate object "${prefix}".`);
|
|
405
|
+
collector.error('E3009', `Object "${objectId}": missing intermediate object "${prefix}".`);
|
|
371
406
|
}
|
|
372
407
|
}
|
|
373
408
|
}
|
|
@@ -381,16 +416,13 @@ function validateObjectDump(objects, adapter, collector) {
|
|
|
381
416
|
|
|
382
417
|
const common = objectData.common;
|
|
383
418
|
|
|
384
|
-
if (!isPlainObject(common) ||
|
|
385
|
-
|
|
386
|
-
collector.error('E3010',
|
|
387
|
-
`Object "${objectId}": state must define common.type.`);
|
|
419
|
+
if (!isPlainObject(common) || !Object.prototype.hasOwnProperty.call(common, 'type')) {
|
|
420
|
+
collector.error('E3010', `Object "${objectId}": state must define common.type.`);
|
|
388
421
|
continue;
|
|
389
422
|
}
|
|
390
423
|
|
|
391
424
|
if (!VALID_STATE_TYPES.has(common.type)) {
|
|
392
|
-
collector.error('E3011',
|
|
393
|
-
`Object "${objectId}": invalid common.type "${common.type}".`);
|
|
425
|
+
collector.error('E3011', `Object "${objectId}": invalid common.type "${common.type}".`);
|
|
394
426
|
}
|
|
395
427
|
|
|
396
428
|
validateStateCommon(objectId, common, collector, roleRuleMaps);
|
|
@@ -421,7 +453,7 @@ function checkObjectStructure(objects, adapter) {
|
|
|
421
453
|
return {
|
|
422
454
|
adapter,
|
|
423
455
|
objectCount,
|
|
424
|
-
errors:
|
|
456
|
+
errors: collector.errors,
|
|
425
457
|
warnings: collector.warnings,
|
|
426
458
|
};
|
|
427
459
|
}
|
package/package.json
CHANGED