import { ApplogValue, DatomPart } from '../applog/datom-types.ts' export function includes(str: string) { return (vl: DatomPart) => vl?.includes?.(str) } export function includedIn(arr: string[]) { return (vl: DatomPart) => arr?.includes?.(vl) } /** * Set-membership matcher: matches when the field equals any of `vals`. Use this instead of a * bare array in a query pattern — bare arrays are rejected by the matcher (a bare array is * ambiguous now that `vl` can hold a literal array value). * * Returns a `Set`, which the matcher engine checks via `.has` (O(1)). Members must be * primitives: `Set.has` is referential, so object/array members would silently never match — * we throw rather than fail silently. For object membership, use a predicate matcher, e.g. * `(v) => members.some(m => isEqual(v, m))`. */ export function anyOf(...vals: T[]): ReadonlySet { for (const v of vals) { if (v !== null && typeof v === 'object') { throw new Error( `[anyOf] object/array members are not supported (referential Set membership would silently never match).` + ` Use a predicate matcher instead, e.g. (v) => members.some(m => isEqual(v, m)).`, ) } } return new Set(vals) }