meteor-publish-composite icon indicating copy to clipboard operation
meteor-publish-composite copied to clipboard

Is transform working in publishComposite expected behaviour?

Open jrkinclus opened this issue 6 months ago • 2 comments

Describe the bug The Meteor docs say that transform is not applied to Cursors returned from publications. So, if one wanted to not publish individual elements in an array field, they can't do this:

// Publication that wants to omit individual elements from an array field
Meteor.publish('myPub', function () {
  return MyCollection.find({}, {
    transform: (obj) => {
      // This function never gets called, so this won't work
      obj.someArrayField = obj.someArrayField.filter(element => element !== 'someValue');
      return obj;
    },
  });
});

However, this does work:

// Publication that wants to omit individual elements from an array field
Meteor.publishComposite('myCompositePub', function () {
  return {
    find() {
      return MyCollection.find({}, {
        transform: (obj) => {
          // This function does get called and modifies the published object
          obj.someArrayField = obj.someArrayField.filter(element => element !== 'someValue');
          return obj;
        },
      });
    },
  };
});

Expected behavior I would've expected the transform to not work for publishComposite too. Is this intended behaviour or an accidental feature?

Tested on v1.8.6

jrkinclus avatar Aug 19 '24 12:08 jrkinclus