Skip to content

Commit

Permalink
feat(pouch-link): Support empty selector for PouchDB
Browse files Browse the repository at this point in the history
With CouchDB, it is possible to provide an empty selector

It is however not possible with PouchDB that will throw an error

So we force a selector on the `_id` for such cases
  • Loading branch information
Ldoppea committed Sep 9, 2024
1 parent d4d0f2c commit 54d82fa
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/cozy-pouch-link/src/CozyPouchLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,18 +556,28 @@ class PouchLink extends CozyLink {
res = withoutDesignDocuments(res)
withRows = true
} else {
let findSelector = selector
const shouldAddId = !findSelector
if (shouldAddId) {
findSelector = {}
}
if (indexedFields) {
for (const indexedField of indexedFields) {
if (!Object.keys(selector).includes(indexedField)) {
selector[indexedField] = {
if (!Object.keys(findSelector).includes(indexedField)) {
findSelector[indexedField] = {
$gt: null
}
}
}
}
if (shouldAddId) {
findSelector['_id'] = {
$gt: null
}
}
const findOpts = {
sort,
selector,
selector: findSelector,
// same selector as Document Collection. We force _id.
// Fix https://github.com/cozy/cozy-client/issues/985
fields: fields ? [...fields, '_id', '_type', 'class'] : undefined,
Expand Down

0 comments on commit 54d82fa

Please sign in to comment.