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

refactor(core): improvements to Construct API #2767

Merged
merged 26 commits into from
Jun 6, 2019
Merged

Conversation

eladb
Copy link
Contributor

@eladb eladb commented Jun 6, 2019

Closes #1934

BREAKING CHANGE:

  • core: node.stack is now Stack.of(construct) (fixes Deprecate node.stack #2766)
  • core: node.resolve has been moved to stack.resolve.
  • core: node.stringifyJson has been moved to stack.stringifyJson.
  • core: node.validateTree is now ConstructNode.validate(node)
  • core: node.prepareTree is now ConstructNode.prepare(node)
  • core: node.getContext is now node.tryGetContext
  • core: node.recordReference is now node.addReference
  • core: node.apply is now node.applyAspect
  • core: node.ancestors() is now node.scopes
  • core: node.required has been removed.
  • core: node.typename has been removed.
  • core: node.addChild is now private
  • core: node.findReferences() is now node.references
  • core: node.findDependencies() is now node.dependencies
  • core: stack.dependencies() is now stack.dependencies
  • core: CfnElement.stackPath has been removed.
  • core: CloudFormationLang is now internal (use stack.toJsonString())

Pull Request Checklist

  • Testing
    • Unit test added (prefer not to modify an existing test, otherwise, it's probably a breaking change)
    • CLI change?: coordinate update of integration tests with team
    • cdk-init template change?: coordinated update of integration tests with team
  • Docs
    • jsdocs: All public APIs documented
    • README: README and/or documentation topic updated
    • Design: For significant features, design document added to design folder
  • Title and Description
    • Change type: title prefixed with fix, feat and module name in parens, which will appear in changelog
    • Title: use lower-case and doesn't end with a period
    • Breaking?: last paragraph: "BREAKING CHANGE: <describe what changed + link for details>"
    • Issues: Indicate issues fixed via: "Fixes #xxx" or "Closes #xxx"
  • Sensitive Modules (requires 2 PR approvers)
    • IAM Policy Document (in @aws-cdk/aws-iam)
    • EC2 Security Groups and ACLs (in @aws-cdk/aws-ec2)
    • Grant APIs (only if not based on official documentation with a reference)

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

Elad Ben-Israel added 16 commits June 4, 2019 02:13
Ensure documentation coverage and clean up of the various APIs.

Fixes #1891


BREAKING CHANGE:
* **core:** `StackProps.autoDeploy` has been removed and replaced by `StackProps.hide` (with negated logic).
* **core:** `ISynthesizable.synthesize` now accepts an `ISynthesisSession` which contains the `CloudAssemblyBuilder` object.
* **cx-api:** Multiple changes to the cloud assembly APIs to reduce surface area and clean up.
BREAKING CHANGE:
- `StackProps.autoDeploy` renamed to `entrypoint` (still true by default).
- CLI must be upgraded to 0.34.0 (cx protocol changes)
BREAKING CHANGE:
* **core:** `node.validateTree` is now `ConstructNode.validate(node)`
* **core:** `node.prepareTree` is now `ConstructNode.prepare(node)`
* **core:** `node.getContext` is now `node.tryGetContext`
* **core:** `node.recordReference` is now `node.addReference`
* **core:** `node.apply` is now `node.applyAspect`
* **core:** `node.ancestors()` is now `node.scopes`
* **core:** `node.required` has been removed.
* **core:** `node.typename` has been removed.
* **core:** `node.addChild` is now private
* **core:** `node.findReferences()` is now `node.references`
* **core:** `node.findDependencieS()` is now `node.dependencies`
* **core:** `stack.dependencies()` is now `stack.dependencies`
* **core:** `construct.node.stack` is now `Stack.of(construct)`
* **core:** `CfnElement.stackPath` has been removed.
@eladb eladb requested review from RomainMuller, skinny85 and a team as code owners June 6, 2019 07:26
@eladb eladb requested a review from SoManyHs as a code owner June 6, 2019 09:37
Elad Ben-Israel added 2 commits June 6, 2019 13:01
BREAKING CHANGE:
* **core:** `node.resolve` has been moved to `stack.resolve`.
* **core:** `node.stringifyJson` has been moved to `stack.stringifyJson`.
@rix0rrr
Copy link
Contributor

rix0rrr commented Jun 6, 2019

I think the last commit does things that aren't necessary:

node.resolve has been moved to stack.resolve.

Weren't we talking about removing resolve() altogether? Better to do that than to move it then.

node.stringifyJson has been moved to stack.stringifyJson.

Actually this method could go as well. It does nothing that CloudFormationLang.toJSON() doesn't do, so the usage sites could be replaced.

Yes, this couples it to CloudFormation (we lose target language abstraction), but in all instances where we're calling it, we're calling it from the context of a Construct Library resource which already knows it's going to be deployed using CloudFormation (same situation as where we would be using Stack.of()) so the coupling is justified.

@eladb
Copy link
Contributor Author

eladb commented Jun 6, 2019

Weren't we talking about removing resolve() altogether? Better to do that than to move it then.

I tried to look into moving resolve() into the synthesis session, and realized it's going to be too hard. It is needed in some "prepare" contexts as well and an infinite number of tests. I was concerned that it was under node, but under stack it feels better, especially given it uses CloudFormation functions for concatenations, etc. So I am comfortable with stack.resolve for now. If you feel strongly about it, I am willing to give this another try.

Actually this method could go as well. It does nothing that CloudFormationLang.toJSON() doesn't do, so the usage sites could be replaced.

I think stack.stringifyJson is more discoverable and easy to reason about than CloudFormationLang.toJSON() which we should make internal. And it is used quite a lot (every time there's a "document" resource property), and I believe customers will potentially use it with "leaky" custom resources as well.

packages/@aws-cdk/cdk/lib/stack.ts Outdated Show resolved Hide resolved
/**
* Convert an object, potentially containing tokens, to a JSON string
*/
public stringifyJson(obj: any): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not stringify JSON, it stringifies stuff to CFN-y Json. I don't love that method name, and I kinda think stringify or toJsonString is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I like toJsonString.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rix0rrr what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah cool

* stringifyJson => toJsonString
* node.resolve => stack.resolve
* CloudFormationLang is now toJsonString
@mergify
Copy link
Contributor

mergify bot commented Sep 23, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

This was referenced Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate node.stack Cleanup/revisit Construct API
4 participants