From 3431700c38d02e82d2fcf131ec34cb4f6a4ac3ef Mon Sep 17 00:00:00 2001 From: John Colvin Date: Fri, 31 Oct 2025 15:14:48 -0400 Subject: [PATCH] chore: Add IDataStreamFactory for FilterStream --- .../StreamFactories/FilterStreamFactory.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/DataStreamSuite/SharedStreams/StreamFactories/FilterStreamFactory.cs diff --git a/src/DataStreamSuite/SharedStreams/StreamFactories/FilterStreamFactory.cs b/src/DataStreamSuite/SharedStreams/StreamFactories/FilterStreamFactory.cs new file mode 100644 index 000000000..19c2bb445 --- /dev/null +++ b/src/DataStreamSuite/SharedStreams/StreamFactories/FilterStreamFactory.cs @@ -0,0 +1,42 @@ +namespace Bts.SharedStreams.StreamFactories; + +using BCG; + +using Bts.DataStreamCore; +using Bts.DataStreamExpressions; + +using System.Collections.Generic; + +public class FilterStreamFactory : IRecursiveDataStreamFactory { + IDataStreamFactory? compositeFactory; + + public ViewStream? Create(string streamId, IEnumerable<(string? Name, int? Index, object? Value)> args) { + if (SupportedStreams.Filter.IsMatch(streamId)) { + return createFilter(args); + } + return null; + } + + public IEnumerable GetSupportedStreams() { + yield return SupportedStreams.Filter; + } + + public void OnCompositeFactory(IDataStreamFactory compositeFactory) => + this.compositeFactory = compositeFactory; + + ViewStream? createFilter(IEnumerable<(string? Name, int? Index, object? Value)> args) { + if (compositeFactory is null || !args.TryGetSingle(out var arg)) { + return null; + } + if (arg.Value is FunctionDefinition fnDef) { + fnDef.ToPredicate(new Dictionary(0), new Dictionary(0), compositeFactory); + } + throw new NotImplementedException(); + } + + static class SupportedStreams { + public static readonly DataStreamMetadata Filter = new() { + Name = "filter" + }; + } +}