@iobroker/repochecker 5.18.0 → 5.18.1

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 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.0 (2026-06-05)
28
+ ### 5.18.1 (2026-06-05)
29
29
 
30
- - (mcm1957) Support for objectStructure chek added
30
+ - (mcm1957) Support for objectStructure check added
31
31
 
32
32
  ### 5.17.9 (2026-06-04)
33
33
 
@@ -1,14 +1,14 @@
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
12
  };
13
13
 
14
14
  const ALLOWED_OBJECT_TYPES = new Set([
@@ -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 = /[^a-zA-Z0-9_,-.]+/g;
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) return '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)) return false;
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': return true;
85
- case 'array': return Array.isArray(value);
86
- case 'boolean': return typeof value === 'boolean';
87
- case 'number': return typeof value === 'number' && Number.isFinite(value);
88
- case 'object': return isPlainObject(value);
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': return typeof value === 'string';
92
- case 'multistate': return ['string', 'number', 'boolean'].includes(typeof value);
93
- default: return false;
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 = new Map();
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: (code, message) => errors.push({ code, message }),
152
+ error: (code, message) => errors.push({ code, message }),
145
153
  warning: (code, message) => warnings.push({ code, message }),
146
- get errors() { return errors; },
147
- get warnings() { return warnings; },
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('E1002',
176
- `Object "${stateId}": common contains unsupported keys: ${unsupportedKeys.join(', ')}.`);
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 = schemaKey.slice('common.'.length);
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('E1004',
195
- `Object "${stateId}": "${schemaKey}" must be of type ${schema.types.join(' or ')}.`);
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('E1005',
201
- `Object "${stateId}": "${schemaKey}" is only allowed for common.type = ${schema.onlyForTypes.join(' or ')}.`);
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('E1006',
206
- `Object "${stateId}": "${schemaKey}" value must match common.type "${common.type}".`);
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('E1009',
224
- `Object "${stateId}": role "${value}" does not support common.type "${common.type}".`);
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('E1010',
229
- `Object "${stateId}": role "${value}" requires common.read = ${roleRule.read}.`);
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('E1011',
234
- `Object "${stateId}": role "${value}" requires common.write = ${roleRule.write}.`);
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 = levels.slice(0, i).join('.');
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
- chain.slice(firstChannelIdx + 1).some(e => e.type === 'device')) {
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,55 @@ 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('E3002',
299
- `Root object "${rootKey}": invalid — expected a plain object with _id === "${rootKey}".`);
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 [requiredKey, expectedType] of Object.entries(ROOT_OBJECT_SCHEMA)) {
316
- if (!Object.prototype.hasOwnProperty.call(objectData, requiredKey)) {
317
- collector.error('E3004',
318
- `Object "${objectId}": missing required key "${requiredKey}".`);
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[requiredKey]);
322
- if (actualType !== expectedType) {
323
- collector.error('E3005',
324
- `Object "${objectId}": key "${requiredKey}" must be type ${expectedType}, got ${actualType}.`);
340
+ const actualType = getValueType(objectData[schemaKey]);
341
+ if (actualType !== descriptor.type) {
342
+ collector.error(
343
+ 'E3005',
344
+ `Object "${objectId}": key "${schemaKey}" must be type ${descriptor.type}, got ${actualType}.`,
345
+ );
325
346
  }
326
347
  }
327
348
 
328
349
  // --- No extra root keys ---
329
- const unsupportedKeys = Object.keys(objectData)
330
- .filter(k => !Object.prototype.hasOwnProperty.call(ROOT_OBJECT_SCHEMA, k));
350
+ const unsupportedKeys = Object.keys(objectData).filter(
351
+ k => !Object.prototype.hasOwnProperty.call(ROOT_OBJECT_SCHEMA, k),
352
+ );
331
353
  if (unsupportedKeys.length > 0) {
332
- collector.error('E3006',
333
- `Object "${objectId}": contains unsupported root keys: ${unsupportedKeys.join(', ')}.`);
354
+ collector.error(
355
+ 'E3006',
356
+ `Object "${objectId}": contains unsupported root keys: ${unsupportedKeys.join(', ')}.`,
357
+ );
334
358
  }
335
359
 
336
360
  // --- Known object type ---
337
361
  if (!ALLOWED_OBJECT_TYPES.has(objectData.type)) {
338
- collector.error('E3007',
339
- `Object "${objectId}": unknown type "${objectData.type}".`);
362
+ collector.error('E3007', `Object "${objectId}": unknown type "${objectData.type}".`);
340
363
  }
341
364
 
342
365
  if (HIERARCHY_TYPES.has(objectData.type)) {
@@ -347,15 +370,19 @@ function validateObjectDump(objects, adapter, collector) {
347
370
  FORBIDDEN_ID_CHARS_REGEX.lastIndex = 0;
348
371
  if (FORBIDDEN_ID_CHARS_REGEX.test(objectId)) {
349
372
  const sanitized = objectId.replace(FORBIDDEN_ID_CHARS_REGEX, '');
350
- collector.error('E3008',
351
- `Object id "${objectId}": contains forbidden characters. Suggested id: "${sanitized}".`);
373
+ collector.error(
374
+ 'E3008',
375
+ `Object id "${objectId}": contains forbidden characters. Suggested id: "${sanitized}".`,
376
+ );
352
377
  }
353
378
 
354
379
  const suggestionMatches = objectId.match(ID_SUGGESTION_REGEX);
355
380
  if (suggestionMatches) {
356
381
  const uniqueChars = [...new Set(suggestionMatches.join('').split(''))].join('');
357
- collector.warning('W3001',
358
- `Object id "${objectId}": contains non [a-zA-Z0-9_,-] characters (${uniqueChars}). Consider removing them.`);
382
+ collector.warning(
383
+ 'W3001',
384
+ `Object id "${objectId}": contains non [a-zA-Z0-9_,-] characters (${uniqueChars}). Consider removing them.`,
385
+ );
359
386
  }
360
387
  }
361
388
 
@@ -366,8 +393,7 @@ function validateObjectDump(objects, adapter, collector) {
366
393
  for (let i = 3; i < levels.length; i++) {
367
394
  const prefix = levels.slice(0, i).join('.');
368
395
  if (!Object.prototype.hasOwnProperty.call(objects, prefix)) {
369
- collector.error('E3009',
370
- `Object "${objectId}": missing intermediate object "${prefix}".`);
396
+ collector.error('E3009', `Object "${objectId}": missing intermediate object "${prefix}".`);
371
397
  }
372
398
  }
373
399
  }
@@ -381,16 +407,13 @@ function validateObjectDump(objects, adapter, collector) {
381
407
 
382
408
  const common = objectData.common;
383
409
 
384
- if (!isPlainObject(common) ||
385
- !Object.prototype.hasOwnProperty.call(common, 'type')) {
386
- collector.error('E3010',
387
- `Object "${objectId}": state must define common.type.`);
410
+ if (!isPlainObject(common) || !Object.prototype.hasOwnProperty.call(common, 'type')) {
411
+ collector.error('E3010', `Object "${objectId}": state must define common.type.`);
388
412
  continue;
389
413
  }
390
414
 
391
415
  if (!VALID_STATE_TYPES.has(common.type)) {
392
- collector.error('E3011',
393
- `Object "${objectId}": invalid common.type "${common.type}".`);
416
+ collector.error('E3011', `Object "${objectId}": invalid common.type "${common.type}".`);
394
417
  }
395
418
 
396
419
  validateStateCommon(objectId, common, collector, roleRuleMaps);
@@ -421,7 +444,7 @@ function checkObjectStructure(objects, adapter) {
421
444
  return {
422
445
  adapter,
423
446
  objectCount,
424
- errors: collector.errors,
447
+ errors: collector.errors,
425
448
  warnings: collector.warnings,
426
449
  };
427
450
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.18.0",
2
+ "version": "5.18.1",
3
3
  "name": "@iobroker/repochecker",
4
4
  "dependencies": {
5
5
  "ajv": "^8.20.0",