ion icon indicating copy to clipboard operation
ion copied to clipboard

sns subscription transform no longer works

Open ravenscar opened this issue 9 months ago • 2 comments

code below used to work pre 0.0.312

/// <reference path="./.sst/platform/config.d.ts" />
export default $config({
  app(input) {
    return {
      name: "sns-sub",
      home: "aws",
    };
  },
  async run() {
    const q = new sst.aws.Queue('TestQueue');
    const topic = new sst.aws.SnsTopic("TestTopic");
    topic.subscribeQueue(q.arn, {
      transform: {
        subscription: (args) => ({
          ...args,
          rawMessageDelivery: true,
        })
      },
    });
  },
}

after 312 it does not work properly due to the transform function returning an object instead of mutating the args in place. I note this was changed in pkg/platform/src/components/component.ts of this commit

the fix is easy, change the transform function to mutate

      transform: {
        subscription: (args) => {
          args.rawMessageDelivery = true;
        }
      },

or

      transform: {
        subscription: {
          rawMessageDelivery: true,
        }
      },

However the original will not show up as a type error as the return type was void ignoring the return type, where it would have better been undefined

e.g. export type Transform<T> = T | ((args: T) => void); to export type Transform<T> = T | ((args: T) => undefined);

ravenscar avatar May 16 '24 02:05 ravenscar