amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

refactor: allow creation of JS resolvers with S3 assets

Open atierian opened this issue 1 year ago • 1 comments

[!IMPORTANT] No snapshots were harmed in the making of this PR. No behavioral changes are included in this PR. This is prerequisite work to allow S3 asset JS resolver functions.

This is followup work to https://github.com/aws-amplify/amplify-category-api/pull/2812.

Description of changes

  • Adds a few types to represent VTL and JS runtime mapping templates (reference).
export type VTLRuntimeTemplate = { requestMappingTemplate?: MappingTemplateProvider; responseMappingTemplate?: MappingTemplateProvider };
export type JSRuntimeTemplate = { codeMappingTemplate: MappingTemplateProvider };
export type FunctionRuntimeTemplate = VTLRuntimeTemplate | JSRuntimeTemplate;
  • Updates addToSlot to take FunctionRuntimeTemplate (reference)

  • Adds S3MappingJSResolverFunctionCode class for JS runtime specific S3MappingTemplateProvider (reference)

  • Adds MappingTemplate.s3MappingFunctionCodeFromString function to allow creation of (S3) asset based JS runtime resolver functions. (reference)

  • Updates TransformerResolver APIs and implementation to accept new FunctionRuntimeTemplate type.

  • Updates TransformerResolver API callsites in various transformers for new FunctionRuntimeTemplate type. See commits for individual changes made to each transformer. Commit names follow the format "update <name>-transformer for FunctionRuntimeTemplate input" for reviewing changes in isolation.

  • Updates conversation and generation transformers to use JSRuntimeTemplate.

[!NOTE] I recommend conducting a very surface level review of the conversation and generation changes. This PR is a prerequisite to two follow up PRs (for conversation and generation respectively) that migrate to using S3 asset based resolver functions. The majority of the conversation and generation transformer specific changes in this PR are again changed in these subsequent PRs. This was done to isolate the changes in the PR as much as possible, while not breaking the conversation and generation transformers.

CDK / CloudFormation Parameters Changed

N/A

Issue #, if available

N/A

Description of how you validated changes

Checklist

  • [x] PR description included
  • [x] yarn test passes
  • [x] Tests are changed or added
  • [ ] ~Relevant documentation is changed or added (and PR referenced)~
  • [ ] ~New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies~
  • [ ] ~Any CDK or CloudFormation parameter changes are called out explicitly~

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

atierian avatar Sep 18 '24 15:09 atierian