@naturalcycles/db-lib 10.64.0 → 10.64.1

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.
@@ -1,13 +1,15 @@
1
1
  import { comparators } from '@naturalcycles/js-lib/array';
2
2
  import { _get, _pick } from '@naturalcycles/js-lib/object/object.util.js';
3
+ // Datastore (and Firestore) treat an array-valued property as multi-valued:
4
+ // `==` matches when any element equals the value, `in` when any element is among the values.
3
5
  const FILTER_FNS = {
4
- '==': (v, val) => v === val,
6
+ '==': (v, val) => (Array.isArray(v) ? v.includes(val) : v === val),
5
7
  '!=': (v, val) => v !== val,
6
8
  '<': (v, val) => v < val,
7
9
  '<=': (v, val) => v <= val,
8
10
  '>': (v, val) => v > val,
9
11
  '>=': (v, val) => v >= val,
10
- in: (v, val) => (val || []).includes(v),
12
+ in: (v, val) => Array.isArray(v) ? v.some(item => (val || []).includes(item)) : (val || []).includes(v),
11
13
  'not-in': (v, val) => !(val || []).includes(v),
12
14
  'array-contains': (v, val) => (v || []).includes(val),
13
15
  'array-contains-any': (v, val) => (v && val && v.some(item => val.includes(item))) || false,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/db-lib",
3
3
  "type": "module",
4
- "version": "10.64.0",
4
+ "version": "10.64.1",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@naturalcycles/nodejs-lib": "^15"
@@ -4,14 +4,17 @@ import type { ObjectWithId } from '@naturalcycles/js-lib/types'
4
4
  import type { DBQuery, DBQueryFilterOperator } from '../query/dbQuery.js'
5
5
 
6
6
  type FilterFn = (v: any, val: any) => boolean
7
+ // Datastore (and Firestore) treat an array-valued property as multi-valued:
8
+ // `==` matches when any element equals the value, `in` when any element is among the values.
7
9
  const FILTER_FNS: Record<DBQueryFilterOperator, FilterFn> = {
8
- '==': (v, val) => v === val,
10
+ '==': (v, val) => (Array.isArray(v) ? v.includes(val) : v === val),
9
11
  '!=': (v, val) => v !== val,
10
12
  '<': (v, val) => v < val,
11
13
  '<=': (v, val) => v <= val,
12
14
  '>': (v, val) => v > val,
13
15
  '>=': (v, val) => v >= val,
14
- in: (v, val?: readonly any[]) => (val || []).includes(v),
16
+ in: (v, val?: readonly any[]) =>
17
+ Array.isArray(v) ? v.some(item => (val || []).includes(item)) : (val || []).includes(v),
15
18
  'not-in': (v, val?: readonly any[]) => !(val || []).includes(v),
16
19
  'array-contains': (v?: readonly any[], val?: any) => (v || []).includes(val),
17
20
  'array-contains-any': (v?: readonly any[], val?: readonly any[]) =>