@redpanda-data/docs-extensions-and-macros 4.12.2 → 4.12.4

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.
@@ -104,7 +104,12 @@ module.exports = function renderConnectFields(children, prefix = '') {
104
104
  }
105
105
  // Complex object/array
106
106
  else if (typeof child.default === 'object') {
107
- const defYaml = yaml.stringify(child.default).trim();
107
+ const defYaml = yaml.stringify(child.default, {
108
+ defaultStringType: 'PLAIN',
109
+ defaultKeyType: 'PLAIN',
110
+ lineWidth: 0,
111
+ simpleKeys: false
112
+ }).trim();
108
113
  block += `*Default*:\n[source,yaml]\n----\n${defYaml}\n----\n\n`;
109
114
  }
110
115
  // Primitive
@@ -138,61 +143,77 @@ module.exports = function renderConnectFields(children, prefix = '') {
138
143
  if (child.examples && child.examples.length) {
139
144
  block += `[source,yaml]\n----\n# Examples:\n`;
140
145
  if (child.kind === 'array') {
141
- child.examples.forEach(example => {
146
+ child.examples.forEach((example, exampleIndex) => {
142
147
  if (Array.isArray(example)) {
143
148
  // Check if array contains any objects
144
149
  const hasObjects = example.some(item => typeof item === 'object' && item !== null);
145
150
 
151
+ // Always use block style for arrays
146
152
  if (hasObjects) {
147
- // Use block style for arrays of objects
153
+ // Arrays of objects
148
154
  block += renderYamlList(child.name, [example]);
149
155
  } else {
150
- // Use flow style for arrays of primitives: fieldName: [item1, item2, ...]
151
- const items = example.map(item => {
156
+ // Arrays of primitives - use block style
157
+ block += `${child.name}:\n`;
158
+ example.forEach(item => {
159
+ let value;
152
160
  if (typeof item === 'string') {
153
161
  // Check if already quoted (starts and ends with quotes)
154
162
  const alreadyQuoted = item.startsWith('"') && item.endsWith('"');
155
163
 
156
164
  if (alreadyQuoted) {
157
165
  // Already quoted, return as-is
158
- return item;
166
+ value = item;
167
+ } else {
168
+ // Check if quoting is needed
169
+ const needsQuoting = item === '' ||
170
+ item === '*' ||
171
+ /^(true|false|null|yes|no|on|off)$/i.test(item) ||
172
+ /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/.test(item) ||
173
+ /[:\[\]\{\},&>|%@`"]/.test(item) ||
174
+ /\s/.test(item); // any whitespace
175
+
176
+ if (needsQuoting) {
177
+ // Escape backslashes first, then double quotes
178
+ const escaped = item.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
179
+ value = `"${escaped}"`;
180
+ } else {
181
+ value = item;
182
+ }
159
183
  }
160
-
161
- // Check if quoting is needed
162
- const needsQuoting = item === '' ||
163
- item === '*' ||
164
- /^(true|false|null|yes|no|on|off)$/i.test(item) ||
165
- /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/.test(item) ||
166
- /[:\[\]\{\},&>|%@`"]/.test(item) ||
167
- /\s/.test(item); // any whitespace
168
-
169
- if (needsQuoting) {
170
- // Escape backslashes first, then double quotes
171
- const escaped = item.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
172
- return `"${escaped}"`;
184
+ } else {
185
+ // For primitives (numbers, booleans, etc.), convert to string
186
+ const strValue = String(item);
187
+ // Check if the stringified value needs quoting
188
+ if (/[:\[\]\{\},&>|%@`"]/.test(strValue) || /\s/.test(strValue)) {
189
+ const escaped = strValue.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
190
+ value = `"${escaped}"`;
191
+ } else {
192
+ value = strValue;
173
193
  }
174
- return item;
175
- }
176
- // For primitives (numbers, booleans, etc.), convert to string
177
- const strValue = String(item);
178
- // Check if the stringified value needs quoting
179
- if (/[:\[\]\{\},&>|%@`"]/.test(strValue) || /\s/.test(strValue)) {
180
- const escaped = strValue.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
181
- return `"${escaped}"`;
182
194
  }
183
- return strValue;
195
+ block += ` - ${value}\n`;
184
196
  });
185
- block += `${child.name}: [${items.join(', ')}]\n`;
186
197
  }
187
198
  } else {
188
199
  // Fallback for non-array examples (shouldn't happen for array fields)
189
200
  block += `${child.name}: ${example}\n`;
190
201
  }
202
+
203
+ // Add separator between examples, but not after the last one
204
+ if (exampleIndex < child.examples.length - 1) {
205
+ block += `\n# ---\n\n`;
206
+ }
191
207
  });
192
208
  } else {
193
- child.examples.forEach(example => {
209
+ child.examples.forEach((example, exampleIndex) => {
194
210
  if (typeof example === 'object') {
195
- const snippet = yaml.stringify(example).trim();
211
+ const snippet = yaml.stringify(example, {
212
+ defaultStringType: 'PLAIN',
213
+ defaultKeyType: 'PLAIN',
214
+ lineWidth: 0,
215
+ simpleKeys: false
216
+ }).trim();
196
217
  block += `${child.name}:\n`;
197
218
  block += snippet.split('\n').map(line => ' ' + line).join('\n') + '\n';
198
219
  } else if (typeof example === 'string' && example.includes('\n')) {
@@ -202,6 +223,11 @@ module.exports = function renderConnectFields(children, prefix = '') {
202
223
  // Primitive values
203
224
  block += `${child.name}: ${example}\n`;
204
225
  }
226
+
227
+ // Add separator between examples, but not after the last one
228
+ if (exampleIndex < child.examples.length - 1) {
229
+ block += `\n# ---\n\n`;
230
+ }
205
231
  });
206
232
  }
207
233
  block += `----\n\n`;
@@ -31,7 +31,7 @@ module.exports = function renderLeafField(field, indentLevel) {
31
31
 
32
32
  // If a default is provided, use it:
33
33
  if (field.default !== undefined) {
34
- // Empty array inline
34
+ // Empty array - use block style
35
35
  if (Array.isArray(field.default) && field.default.length === 0) {
36
36
  return `${indent}${name}: []`;
37
37
  }
@@ -45,10 +45,16 @@ module.exports = function renderLeafField(field, indentLevel) {
45
45
  return `${indent}${name}: {}`;
46
46
  }
47
47
 
48
- // Complex object/array: dump as YAML block
48
+ // Complex object/array: dump as YAML block style
49
49
  if (typeof field.default === 'object') {
50
50
  try {
51
- const rawYaml = yaml.stringify(field.default).trim();
51
+ // Force block style for all arrays and nested structures
52
+ const rawYaml = yaml.stringify(field.default, {
53
+ defaultStringType: 'PLAIN',
54
+ defaultKeyType: 'PLAIN',
55
+ lineWidth: 0, // Disable line wrapping to prevent flow style
56
+ simpleKeys: false
57
+ }).trim();
52
58
  const indentedYaml = rawYaml
53
59
  .split('\n')
54
60
  .map(line => ' '.repeat(indentLevel + 2) + line)
@@ -79,6 +85,7 @@ module.exports = function renderLeafField(field, indentLevel) {
79
85
  }
80
86
 
81
87
  // No default → choose representation
88
+ // Note: Empty arrays still use [] for brevity when showing placeholder with comment
82
89
  if (field.kind === 'array') {
83
90
  return `${indent}${name}: [] ${comment}`;
84
91
  } else {
@@ -24,8 +24,13 @@ module.exports = function renderYamlList(name, exampleGroups) {
24
24
  }
25
25
  out += ` - ${value}\n`;
26
26
  } else {
27
- // Objects/arrays: stringify with indentation
28
- const snippet = yaml.stringify(item).trim();
27
+ // Objects/arrays: stringify with indentation using block style
28
+ const snippet = yaml.stringify(item, {
29
+ defaultStringType: 'PLAIN',
30
+ defaultKeyType: 'PLAIN',
31
+ lineWidth: 0,
32
+ simpleKeys: false
33
+ }).trim();
29
34
  const lines = snippet.split('\n');
30
35
  out += lines
31
36
  .map((line, idx) => (idx === 0 ? ` - ${line}` : ` ${line}`))
@@ -1,11 +1,16 @@
1
1
  const yaml = require('yaml');
2
-
2
+
3
3
  /**
4
- * Converts an object to a YAML string.
4
+ * Converts an object to a YAML string using block style for arrays.
5
5
  *
6
6
  * @param {Object} obj - The object to convert.
7
7
  * @returns {string} The YAML representation of the object, trimmed.
8
8
  */
9
9
  module.exports = function toYaml(obj) {
10
- return yaml.stringify(obj).trim();
10
+ return yaml.stringify(obj, {
11
+ defaultStringType: 'PLAIN',
12
+ defaultKeyType: 'PLAIN',
13
+ lineWidth: 0, // Disable line wrapping to prevent flow style
14
+ simpleKeys: false
15
+ }).trim();
11
16
  }
@@ -101,6 +101,9 @@ function generateConnectorDiffJson(oldIndex, newIndex, opts = {}) {
101
101
 
102
102
  // Newly deprecated fields (exist in both versions but became deprecated)
103
103
  const deprecatedFields = [];
104
+ // Changed default values
105
+ const changedDefaults = [];
106
+
104
107
  Object.keys(newMap).forEach(cKey => {
105
108
  if (!(cKey in oldMap)) return;
106
109
  const oldFieldsArr = oldMap[cKey].fields || [];
@@ -137,6 +140,26 @@ function generateConnectorDiffJson(oldIndex, newIndex, opts = {}) {
137
140
  description: newFieldObj && newFieldObj.description
138
141
  });
139
142
  }
143
+
144
+ // Check for changed default values
145
+ if (oldFieldObj && newFieldObj) {
146
+ const oldDefault = oldFieldObj.default;
147
+ const newDefault = newFieldObj.default;
148
+
149
+ // Compare defaults using JSON stringification to handle objects/arrays
150
+ const oldDefaultStr = JSON.stringify(oldDefault);
151
+ const newDefaultStr = JSON.stringify(newDefault);
152
+
153
+ if (oldDefaultStr !== newDefaultStr) {
154
+ changedDefaults.push({
155
+ component: cKey,
156
+ field: fName,
157
+ oldDefault: oldDefault,
158
+ newDefault: newDefault,
159
+ description: newFieldObj && newFieldObj.description
160
+ });
161
+ }
162
+ }
140
163
  });
141
164
  });
142
165
 
@@ -152,7 +175,8 @@ function generateConnectorDiffJson(oldIndex, newIndex, opts = {}) {
152
175
  newFields: newFields.length,
153
176
  removedFields: removedFields.length,
154
177
  deprecatedComponents: deprecatedComponents.length,
155
- deprecatedFields: deprecatedFields.length
178
+ deprecatedFields: deprecatedFields.length,
179
+ changedDefaults: changedDefaults.length
156
180
  },
157
181
  details: {
158
182
  newComponents,
@@ -160,7 +184,8 @@ function generateConnectorDiffJson(oldIndex, newIndex, opts = {}) {
160
184
  newFields,
161
185
  removedFields,
162
186
  deprecatedComponents,
163
- deprecatedFields
187
+ deprecatedFields,
188
+ changedDefaults
164
189
  }
165
190
  };
166
191
  }
@@ -281,6 +306,9 @@ function printDeltaReport(oldIndex, newIndex) {
281
306
 
282
307
  // Newly deprecated fields
283
308
  const deprecatedFieldsList = [];
309
+ // Changed default values
310
+ const changedDefaultsList = [];
311
+
284
312
  Object.keys(newMap).forEach(cKey => {
285
313
  if (!(cKey in oldMap)) return;
286
314
  const oldFieldsArr = oldMap[cKey].fields || [];
@@ -306,6 +334,25 @@ function printDeltaReport(oldIndex, newIndex) {
306
334
  if (!oldDeprecated && newDeprecated) {
307
335
  deprecatedFieldsList.push({ component: cKey, field: fName });
308
336
  }
337
+
338
+ // Check for changed default values
339
+ if (oldFieldObj && newFieldObj) {
340
+ const oldDefault = oldFieldObj.default;
341
+ const newDefault = newFieldObj.default;
342
+
343
+ // Compare defaults using JSON stringification to handle objects/arrays
344
+ const oldDefaultStr = JSON.stringify(oldDefault);
345
+ const newDefaultStr = JSON.stringify(newDefault);
346
+
347
+ if (oldDefaultStr !== newDefaultStr) {
348
+ changedDefaultsList.push({
349
+ component: cKey,
350
+ field: fName,
351
+ oldDefault: oldDefault,
352
+ newDefault: newDefault
353
+ });
354
+ }
355
+ }
309
356
  });
310
357
  });
311
358
 
@@ -365,6 +412,21 @@ function printDeltaReport(oldIndex, newIndex) {
365
412
  } else {
366
413
  console.log('➤ No newly deprecated fields.\n');
367
414
  }
415
+
416
+ if (changedDefaultsList.length) {
417
+ console.log('➤ Changed default values:');
418
+ changedDefaultsList.forEach(entry => {
419
+ const { component, field, oldDefault, newDefault } = entry;
420
+ const oldStr = JSON.stringify(oldDefault);
421
+ const newStr = JSON.stringify(newDefault);
422
+ console.log(` • ${component} → ${field}`);
423
+ console.log(` Old: ${oldStr}`);
424
+ console.log(` New: ${newStr}`);
425
+ });
426
+ console.log('');
427
+ } else {
428
+ console.log('➤ No changed default values.\n');
429
+ }
368
430
  }
369
431
 
370
432
  module.exports = {