UNPKG

@tanstack/db-ivm

Version:

Incremental View Maintenance for TanStack DB based on Differential Dataflow

1 lines 1.59 kB
{"version":3,"file":"filterBy.cjs","sources":["../../../src/operators/filterBy.ts"],"sourcesContent":["import { map } from \"./map.js\"\nimport { innerJoin } from \"./join.js\"\nimport { consolidate } from \"./consolidate.js\"\nimport type { KeyValue } from \"../types.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types\"\n\n/**\n * Filters the elements of a keyed stream, by keys of another stream.\n * This allows you to build pipelies where you have multiple outputs that are related,\n * such as a streams of issues and comments for a project.\n *\n * @param other - The other stream to filter by, which must have the same key type as the input stream\n */\nexport function filterBy<\n K,\n V1 extends T extends KeyValue<infer _KT, infer VT> ? VT : never,\n T,\n>(\n other: IStreamBuilder<KeyValue<K, unknown>>\n): PipedOperator<T, KeyValue<K, V1>> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<KeyValue<K, V1>> => {\n const otherKeys = other.pipe(\n map(([key, _]) => [key, null] as KeyValue<K, null>)\n )\n return stream.pipe(\n innerJoin(otherKeys),\n map(([key, [value, _]]) => [key, value] as KeyValue<K, V1>),\n consolidate()\n )\n }\n}\n"],"names":["map","innerJoin","consolidate"],"mappings":";;;;;AAaO,SAAS,SAKd,OACmC;AACnC,SAAO,CAAC,WAA+D;AACrE,UAAM,YAAY,MAAM;AAAA,MACtBA,IAAAA,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAsB;AAAA,IAAA;AAEpD,WAAO,OAAO;AAAA,MACZC,KAAAA,UAAU,SAAS;AAAA,MACnBD,QAAI,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,CAAoB;AAAA,MAC1DE,YAAAA,YAAA;AAAA,IAAY;AAAA,EAEhB;AACF;;"}