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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/source/util.js +24 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baton-issue-tracker",
3
- "version": "1.11.1",
3
+ "version": "1.11.2",
4
4
  "description": "A CLI issue tracker for AI agents",
5
5
  "type": "module",
6
6
  "bin": {
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
- * All commands should serialize through this before building their envelope.
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
- return {
210
- id: issue.id,
211
- title: issue.title,
212
- status: toJsonEnum(issue.status),
213
- priority: toJsonEnum(issue.priority),
214
- description: issue.description ?? null,
215
- token_limit: issue.tokenLimit ?? issue.token_limit ?? null,
216
- attempt_num: issue.attemptNum ?? issue.attempt_num ?? 0,
217
- created_at: issue.createdAt ?? issue.created_at ?? null,
218
- last_updated: issue.lastUpdated ?? issue.last_updated ?? null,
219
- assignees: issue.assignees ?? null,
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
  /**