slicejs-cli 4.4.0 → 4.5.0

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.
@@ -43,10 +43,27 @@ export function validateAgainstSchema(value, schema, at = 'sliceConfig') {
43
43
  }
44
44
  }
45
45
 
46
+ if (Object.prototype.hasOwnProperty.call(schema || {}, 'const') && value !== schema.const) {
47
+ issues.push({ path: at, message: `must be ${JSON.stringify(schema.const)}` });
48
+ }
49
+
46
50
  if (Array.isArray(schema?.enum) && !schema.enum.some((option) => option === value)) {
47
51
  issues.push({ path: at, message: `must be one of ${schema.enum.map((option) => JSON.stringify(option)).join(', ')}` });
48
52
  }
49
53
 
54
+ if (typeof value === 'string' && typeof schema?.minLength === 'number' && value.length < schema.minLength) {
55
+ issues.push({ path: at, message: `must be at least ${schema.minLength} character(s)` });
56
+ }
57
+
58
+ if (Array.isArray(value) && schema?.uniqueItems === true) {
59
+ const seen = new Set();
60
+ value.forEach((item, index) => {
61
+ const id = JSON.stringify(item);
62
+ if (seen.has(id)) issues.push({ path: `${at}[${index}]`, message: 'is duplicated (uniqueItems)' });
63
+ seen.add(id);
64
+ });
65
+ }
66
+
50
67
  for (const required of schema?.required || []) {
51
68
  if (value?.[required] === undefined) issues.push({ path: `${at}.${required}`, message: 'is required' });
52
69
  }
@@ -55,12 +72,29 @@ export function validateAgainstSchema(value, schema, at = 'sliceConfig') {
55
72
  for (const [key, child] of Object.entries(schema?.properties || {})) {
56
73
  if (value[key] !== undefined) issues.push(...validateAgainstSchema(value[key], child, `${at}.${key}`));
57
74
  }
75
+ if (schema?.additionalProperties === false) {
76
+ for (const key of Object.keys(value)) {
77
+ if (!Object.prototype.hasOwnProperty.call(schema.properties || {}, key)) {
78
+ issues.push({ path: `${at}.${key}`, message: 'is not a known option' });
79
+ }
80
+ }
81
+ }
58
82
  }
59
83
 
60
84
  if (Array.isArray(value) && schema?.items) {
61
85
  value.forEach((item, index) => issues.push(...validateAgainstSchema(item, schema.items, `${at}[${index}]`)));
62
86
  }
63
87
 
88
+ // Conditional schema (`if`/`then`/`else`), e.g. enabled: true requires defaultLocale.
89
+ if (schema?.if) {
90
+ const condition = validateAgainstSchema(value, schema.if, at);
91
+ if (condition.length === 0 && schema.then) {
92
+ issues.push(...validateAgainstSchema(value, schema.then, at));
93
+ } else if (condition.length > 0 && schema.else) {
94
+ issues.push(...validateAgainstSchema(value, schema.else, at));
95
+ }
96
+ }
97
+
64
98
  return issues;
65
99
  }
66
100
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-cli",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "Command client for developing web applications with Slice.js framework",
5
5
  "main": "client.js",
6
6
  "bin": {