Skip to content

Commit 3133d09

Browse files
committed
feat: Add a warning when an indexedField is missing in query selector
This replies to #1506 (comment)
1 parent 66e8275 commit 3133d09

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

packages/cozy-pouch-link/src/helpers.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import startsWith from 'lodash/startsWith'
22

3+
import logger from './logger'
4+
35
const helpers = {}
46

57
// https://github.com/pouchdb/pouchdb/issues/7011
@@ -66,6 +68,10 @@ helpers.normalizeFindSelector = (selector, indexedFields) => {
6668
if (indexedFields) {
6769
for (const indexedField of indexedFields) {
6870
if (!Object.keys(findSelector).includes(indexedField)) {
71+
const selectorJson = JSON.stringify(selector)
72+
logger.warn(
73+
`${indexedField} was missing in selector, it has been automatically added from indexed fields. Please consider adding this field to your query's selector as required by PouchDB. The query's selector is: ${selectorJson}`
74+
)
6975
findSelector[indexedField] = {
7076
$gt: null
7177
}

0 commit comments

Comments
 (0)