@iobroker/repochecker 5.18.2 → 5.18.3

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,7 +25,7 @@ Example:
25
25
  Placeholder for the next version (at the beginning of the line):
26
26
  ### **WORK IN PROGRESS**
27
27
  -->
28
- ### 5.18.2 (2026-06-05)
28
+ ### 5.18.3 (2026-06-06)
29
29
 
30
30
  - (mcm1957) Support for objectStructure check added
31
31
 
@@ -9,8 +9,10 @@ const ROOT_OBJECT_SCHEMA = {
9
9
  ts: { type: 'number', optional: true },
10
10
  acl: { type: 'object', optional: true },
11
11
  user: { type: 'string', optional: true },
12
- ack: { type: 'boolean', optional: true },
13
- val: { optional: true, matchesCommonType: true },
12
+ ack: { type: 'boolean', optional: true, stateOnly: true },
13
+ val: { optional: true, matchesCommonType: true, stateOnly: true },
14
+ q: { type: 'number', optional: true, stateOnly: true },
15
+ lc: { type: 'number', optional: true, stateOnly: true },
14
16
  };
15
17
 
16
18
  const ALLOWED_OBJECT_TYPES = new Set([
@@ -54,7 +56,7 @@ const STATE_SCHEMA = {
54
56
  'common.unit': { types: ['string'] },
55
57
  'common.def': { any: true, matchesCommonType: true },
56
58
  'common.defAck': { types: ['boolean'] },
57
- 'common.desc': { types: ['string'] },
59
+ 'common.desc': { i18n: true },
58
60
  'common.read': { types: ['boolean'], required: true },
59
61
  'common.write': { types: ['boolean'], required: true },
60
62
  'common.role': { types: ['string'], required: true, role: true },
@@ -62,7 +64,7 @@ const STATE_SCHEMA = {
62
64
  'common.workingID': { any: true },
63
65
  'common.custom': { any: true },
64
66
  'common.type': { types: ['string'], required: true },
65
- 'common.name': { required: true, name: true },
67
+ 'common.name': { required: true, i18n: true },
66
68
  'common.expert': { types: ['boolean'] },
67
69
  'common.dontDelete':{ types: ['boolean'] },
68
70
  'common.color': { types: ['string'] },
@@ -72,11 +72,53 @@ function isPlainObject(value) {
72
72
  return getValueType(value) === 'object';
73
73
  }
74
74
 
75
- function isStringOrI18nObject(value) {
76
- if (typeof value === 'string') return true;
77
- if (!isPlainObject(value)) return false;
78
- const vals = Object.values(value);
79
- return vals.length > 0 && vals.every(v => typeof v === 'string');
75
+ const I18N_REQUIRED_KEYS = ['en', 'de'];
76
+ const I18N_ALLOWED_KEYS = new Set(['en', 'de', 'ru', 'pt', 'nl', 'fr', 'it', 'es', 'pl', 'uk', 'zh-cn']);
77
+ const I18N_RECOMMENDED_KEYS = ['ru', 'pt', 'nl', 'fr', 'it', 'es', 'pl', 'uk', 'zh-cn'];
78
+
79
+ /**
80
+ * Validates a value that must be either a plain string or an i18n object.
81
+ * Returns an array of error/warning strings (empty = valid).
82
+ *
83
+ * @param {*} value - The value to validate.
84
+ * @param {string} fieldPath - Human-readable path for error messages (e.g. "common.desc").
85
+ * @returns {{ errors: string[], warnings: string[] }}
86
+ */
87
+ function validateI18n(value, fieldPath) {
88
+ const errors = [];
89
+ const warnings = [];
90
+
91
+ if (typeof value === 'string') return { errors, warnings };
92
+
93
+ if (!isPlainObject(value)) {
94
+ errors.push(`"${fieldPath}" must be a string or an i18n object.`);
95
+ return { errors, warnings };
96
+ }
97
+
98
+ // Must be an object — validate as i18n
99
+ const keys = Object.keys(value);
100
+
101
+ for (const key of keys) {
102
+ if (!I18N_ALLOWED_KEYS.has(key)) {
103
+ errors.push(`"${fieldPath}" i18n object contains unknown key "${key}".`);
104
+ }
105
+ if (typeof value[key] !== 'string') {
106
+ errors.push(`"${fieldPath}" i18n object key "${key}" must be a string.`);
107
+ }
108
+ }
109
+
110
+ for (const required of I18N_REQUIRED_KEYS) {
111
+ if (!Object.prototype.hasOwnProperty.call(value, required)) {
112
+ errors.push(`"${fieldPath}" i18n object is missing required key "${required}".`);
113
+ }
114
+ }
115
+
116
+ const missingRecommended = I18N_RECOMMENDED_KEYS.filter(k => !Object.prototype.hasOwnProperty.call(value, k));
117
+ if (missingRecommended.length > 0) {
118
+ warnings.push(`"${fieldPath}" i18n object is missing recommended keys: ${missingRecommended.join(', ')}.`);
119
+ }
120
+
121
+ return { errors, warnings };
80
122
  }
81
123
 
82
124
  function matchesCommonType(value, commonType) {
@@ -223,8 +265,14 @@ function validateStateCommon(stateId, common, collector, roleRuleMaps) {
223
265
  );
224
266
  }
225
267
 
226
- if (schema.name && !isStringOrI18nObject(value)) {
227
- collector.error('E1007', `Object "${stateId}": "${schemaKey}" must be a string or an i18n object.`);
268
+ if (schema.i18n) {
269
+ const { errors: i18nErrors, warnings: i18nWarnings } = validateI18n(value, schemaKey);
270
+ for (const msg of i18nErrors) {
271
+ collector.error('E1007', `Object "${stateId}": ${msg}`);
272
+ }
273
+ for (const msg of i18nWarnings) {
274
+ collector.warning('W1001', `Object "${stateId}": ${msg}`);
275
+ }
228
276
  }
229
277
 
230
278
  if (schema.role) {
@@ -337,6 +385,14 @@ function validateObjectDump(objects, adapter, collector) {
337
385
  // optional + absent → silently skip
338
386
  continue;
339
387
  }
388
+ // stateOnly keys are only permitted on objects of type 'state'
389
+ if (descriptor.stateOnly && objectData.type !== 'state') {
390
+ collector.error(
391
+ 'E3005',
392
+ `Object "${objectId}": key "${schemaKey}" is only allowed on objects of type "state".`,
393
+ );
394
+ continue;
395
+ }
340
396
  const actualType = getValueType(objectData[schemaKey]);
341
397
  if (descriptor.type && actualType !== descriptor.type) {
342
398
  collector.error(
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.18.2",
2
+ "version": "5.18.3",
3
3
  "name": "@iobroker/repochecker",
4
4
  "dependencies": {
5
5
  "ajv": "^8.20.0",