Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream typescript auto-generated definitions #41

Open
fredericbarthelet opened this issue Apr 13, 2021 · 1 comment · May be fixed by serverless/serverless#9297
Open

Stream typescript auto-generated definitions #41

fredericbarthelet opened this issue Apr 13, 2021 · 1 comment · May be fixed by serverless/serverless#9297

Comments

@fredericbarthelet
Copy link
Collaborator

Not a directly related question but I would appreciate your guidance. Now that type definitions are auto-generated, certain things are much clearer and certain things are not. Please take a look at stream event definition:

I do this:

      events: [
        {
          stream: {
            arn: {
              'Fn::GetAtt': ['MyTable', 'StreamArm'],
            },
            batchSize: 1,
          },
        },
      ],

and serverless fails fast on functions.propagate.events[0].stream.arn': should be string with configValidationMode: 'error'. If I turn off configValidationMode, serverless package fails on EventSourceArn.split is not a function. This has been talked about long time ago here serverless/serverless#2365 and later fixed here serverless/serverless#3111.

The fix was simple - adding an explicit type attribute to the stream event definition. DefinitelyTyped has it (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/serverless/plugins/aws/provider/awsProvider.d.ts#L408):

    interface Stream {
        arn: string | { [key: string]: any };
        batchSize?: number | string;
        startingPosition?: number | string;
        enabled?: boolean;
        type?: 'dynamodb' | 'kinesis';
    }

but it's lost in auto-generated types:

        {
            stream:
              | AwsArnString
              | (
                  | {
                      arn: AwsCfFunction;
                      [k: string]: unknown;
                    }
                  | {
                      arn: AwsArnString;
                      [k: string]: unknown;
                    }
                );
          }

So my question is - where to submit a PR or an Issue to get back those typed attributes into the generated type definitions? Adding type solved my problem but it would be nice if it was visible on the type def and thus accessible via auto-complete

Thanks!

Originally posted by @pveller in #38 (comment)

@fredericbarthelet
Copy link
Collaborator Author

Hi @pveller and thanks for reporting your issue.
Regarding your issue, the code that will be used for typescript definition generation is https://github.com/serverless/serverless/blob/19805d71eabb68bd7fd4046aa23090ef85fb1c36/lib/plugins/aws/package/compile/events/stream.js#L15-L90

This JSON schema definition can be improved to ensure generated type stills give you information on the expected type property. I give such an exemple in the PR I just opened.

In the future, do not hesitate to open a separate issue with your problem description (which was very clear by the way :) ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant