Fix Komodo tag IDs in Mongo Extended JSON responses

This commit is contained in:
2026-09-17 09:41:27 -04:00
parent e6b5705478
commit 516dfeb4c3
2 changed files with 93 additions and 2 deletions
+5 -2
View File
@@ -525,13 +525,16 @@ export type KomodoTagResult =
| { ok: true; id: string }
| { ok: false; message: string };
// Komodo serializes Mongo ObjectIds as `_id` in the raw mongo docs and as
// `id` in the API DTOs (rust serde default). Accept either everywhere.
// Accept API string IDs and raw Mongo Extended JSON: { _id: { $oid: "..." } }.
function extractTagId(t: unknown): string | null {
if (!t || typeof t !== 'object') return null;
const o = t as { id?: unknown; _id?: unknown };
if (typeof o.id === 'string' && o.id.length > 0) return o.id;
if (typeof o._id === 'string' && o._id.length > 0) return o._id;
if (o._id && typeof o._id === 'object') {
const oid = (o._id as { $oid?: unknown }).$oid;
if (typeof oid === 'string' && oid.length > 0) return oid;
}
return null;
}