@tanstack/db-ivm
Version:
Incremental View Maintenance for TanStack DB based on Differential Dataflow
1 lines • 2.12 kB
Source Map (JSON)
{"version":3,"file":"map.cjs","sources":["../../../src/operators/map.ts"],"sourcesContent":["import { DifferenceStreamWriter, LinearUnaryOperator } from \"../graph.js\"\nimport { StreamBuilder } from \"../d2.js\"\nimport type { IStreamBuilder, PipedOperator } from \"../types.js\"\nimport type { DifferenceStreamReader } from \"../graph.js\"\nimport type { MultiSet } from \"../multiset.js\"\n\n/**\n * Operator that applies a function to each element in the input stream\n */\nexport class MapOperator<T, U> extends LinearUnaryOperator<T, U> {\n #f: (data: T) => U\n\n constructor(\n id: number,\n inputA: DifferenceStreamReader<T>,\n output: DifferenceStreamWriter<U>,\n f: (data: T) => U\n ) {\n super(id, inputA, output)\n this.#f = f\n }\n\n inner(collection: MultiSet<T>): MultiSet<U> {\n return collection.map(this.#f)\n }\n}\n\n/**\n * Applies a function to each element in the input stream\n * @param f - The function to apply to each element\n */\nexport function map<T, O>(f: (data: T) => O): PipedOperator<T, O> {\n return (stream: IStreamBuilder<T>): IStreamBuilder<O> => {\n const output = new StreamBuilder<O>(\n stream.graph,\n new DifferenceStreamWriter<O>()\n )\n const operator = new MapOperator<T, O>(\n stream.graph.getNextOperatorId(),\n stream.connectReader(),\n output.writer,\n f\n )\n stream.graph.addOperator(operator)\n stream.graph.addStream(output.connectReader())\n return output\n }\n}\n"],"names":["LinearUnaryOperator","StreamBuilder","DifferenceStreamWriter"],"mappings":";;;;;;;;;;;;AASO,MAAM,oBAA0BA,MAAAA,oBAA0B;AAAA,EAG/D,YACE,IACA,QACA,QACA,GACA;AACA,UAAM,IAAI,QAAQ,MAAM;AAR1B;AASE,uBAAK,IAAK;AAAA,EACZ;AAAA,EAEA,MAAM,YAAsC;AAC1C,WAAO,WAAW,IAAI,mBAAK,GAAE;AAAA,EAC/B;AACF;AAfE;AAqBK,SAAS,IAAU,GAAwC;AAChE,SAAO,CAAC,WAAiD;AACvD,UAAM,SAAS,IAAIC,GAAAA;AAAAA,MACjB,OAAO;AAAA,MACP,IAAIC,MAAAA,uBAAA;AAAA,IAA0B;AAEhC,UAAM,WAAW,IAAI;AAAA,MACnB,OAAO,MAAM,kBAAA;AAAA,MACb,OAAO,cAAA;AAAA,MACP,OAAO;AAAA,MACP;AAAA,IAAA;AAEF,WAAO,MAAM,YAAY,QAAQ;AACjC,WAAO,MAAM,UAAU,OAAO,cAAA,CAAe;AAC7C,WAAO;AAAA,EACT;AACF;;;"}