@electric-sql/d2ts
Version:
D2TS is a TypeScript implementation of Differential Dataflow.
25 lines • 1.2 kB
JavaScript
import { map } from '../../operators/map.js';
import { innerJoin } from './join.js';
import { consolidate } from './consolidate.js';
import { SQLiteContext } from '../context.js';
/**
* Filters the elements of a keyed stream, by keys of another stream.
* This allows you to build pipelies where you have multiple outputs that are related,
* such as a streams of issues and comments for a project.
*
* @param other - The other stream to filter by, which must have the same key type as the input stream
* @param db - Optional SQLite database (can be injected via context)
*/
export function filterBy(other, db) {
return (stream) => {
// Get database from context if not provided explicitly
const database = db || SQLiteContext.getDb();
if (!database) {
throw new Error('SQLite database is required for filterBy operator. ' +
'Provide it as a parameter or use withSQLite() to inject it.');
}
const otherKeys = other.pipe(map(([key, _]) => [key, null]), consolidate(database));
return stream.pipe(innerJoin(otherKeys, database), map(([key, [value, _]]) => [key, value]));
};
}
//# sourceMappingURL=filterBy.js.map