Replicating $by_category

I want to replicate the behaviour of the $by_category system projection however I’m not getting all the streams I’d expect

This is my user projection:

fromAll()
.when({
    $any: function (s, e) {
         if(e.streamId !== undefined && e.streamId !== null){
         linkTo('$ce-' + e.streamId.split("-")[0], e);
        }
    }
});

Which works for most events, however it does not catch events created by this second projection:

 if (true) {
                 linkTo('FOO-' + 12345, e);
               
             }

I don’t get a $ce-FOO stream. I assume it’s because the $all filters the links, is that true and if so how can i work around this?

Thanks

What are you trying to achieve by replicating that behavior ?

Note:

  linkTo('$ce-' + e.streamId.split("-")[0], e);

Don’t write to stream prefixed by $ directly, those are considered system streams and if appened by user code there is no guarentee what will happen later.

as for the behavior, the easiest is to look here :