baton-issue-tracker 1.11.1 → 1.11.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/package.json +1 -1
- package/source/util.js +24 -13
package/package.json
CHANGED
package/source/util.js
CHANGED
|
@@ -199,25 +199,36 @@ function toJsonEnum(value) {
|
|
|
199
199
|
return value?.toLowerCase().replace(/-/g, '_') ?? null;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Converts a camelCase string to snake_case.
|
|
204
|
+
* @param {string} str
|
|
205
|
+
* @returns {string}
|
|
206
|
+
*/
|
|
207
|
+
function camelToSnake(str) {
|
|
208
|
+
return str.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
|
|
209
|
+
}
|
|
210
|
+
|
|
202
211
|
/**
|
|
203
212
|
* Normalizes a DB row or Issue instance into a stable JSON-friendly shape.
|
|
204
|
-
*
|
|
213
|
+
* Dynamically built from issueSchema so the output always matches the schema.
|
|
205
214
|
* @param {object} issue
|
|
206
215
|
* @returns {object}
|
|
207
216
|
*/
|
|
208
217
|
export function serializeIssue(issue) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
218
|
+
const skip = new Set(['limit', 'offset']);
|
|
219
|
+
const result = {};
|
|
220
|
+
|
|
221
|
+
for (const [key, config] of Object.entries(issueSchema)) {
|
|
222
|
+
if (skip.has(key)) continue;
|
|
223
|
+
const snakeKey = camelToSnake(key);
|
|
224
|
+
const value = issue[key] ?? issue[snakeKey] ?? null;
|
|
225
|
+
result[snakeKey] = config.type === 'enum' ? toJsonEnum(value) : value;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
result.created_at = issue.createdAt ?? issue.created_at ?? null;
|
|
229
|
+
result.last_updated = issue.lastUpdated ?? issue.last_updated ?? null;
|
|
230
|
+
|
|
231
|
+
return result;
|
|
221
232
|
}
|
|
222
233
|
|
|
223
234
|
/**
|