/** * Helper: Normalize DocumentQuery to standard {id?: number, path?: string} format */ export function normalizeDocumentQuery(query) { // string => path if (typeof query === 'string') return { path: query }; // number => id if (typeof query === 'number') return { id: query }; // object shapes if (query && typeof query === 'object') { // Route => use document_id (ignore route.id) if ('document_id' in query && typeof query.document_id === 'number') { return { id: query.document_id }; } const queryWithId = query; const queryWithPath = query; const hasId = 'id' in query && typeof queryWithId.id === 'number'; const hasPath = 'path' in query && typeof queryWithPath.path === 'string'; // DualDocument (has both id and path) => prefer id if (hasId && hasPath) { return { id: queryWithId.id }; } if (hasId) return { id: queryWithId.id }; if (hasPath) return { path: queryWithPath.path }; // Fallback: handle objects with non-standard types or empty objects const result = {}; if ('id' in query && queryWithId.id !== undefined && queryWithId.id !== null) { result.id = queryWithId.id; } if ('path' in query && queryWithPath.path !== undefined && queryWithPath.path !== null) { result.path = queryWithPath.path; } // If both are present (e.g., OptimisticDocument), prefer id if (result.id !== undefined && result.path !== undefined) { return { id: result.id }; } return result; } throw new Error('Invalid DocumentQuery format'); } //# sourceMappingURL=normalizeDocumentQuery.js.map