[
  {
    "path": ".github/workflows/build.yaml",
    "content": "name: build\non: [push, pull_request]\njobs:\n  lint:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v1\n      - uses: DeLaGuardo/clojure-lint-action@v1\n        with:\n          clj-kondo-args: --lint .\n          github_token: ${{ secrets.GITHUB_TOKEN }}\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v1\n      - uses: actions/cache@v1\n        with:\n          path: ~/.m2/repository\n          key: ${{ runner.os }}-maven-${{ hashFiles('**/deps.edn') }}\n      - uses: actions/cache@v1\n        with:\n          path: ~/.gitlibs\n          key: ${{ runner.os }}-gitlibs-${{ hashFiles('**/deps.edn') }}\n      - uses: actions/cache@v1\n        with:\n          path: ~/.npm\n          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}\n      - uses: actions/setup-node@v1\n        with:\n          node-version: '10.x'\n      - run: npm install\n      - uses: actions/setup-java@v1\n        with:\n          java-version: '1.8'\n      - uses: DeLaGuardo/setup-clojure@2.0\n        with:\n          tools-deps: '1.10.1.469'\n      - run: clojure -A:dev:test\n"
  },
  {
    "path": ".gitignore",
    "content": ".cpcache\n.nrepl-port\ntarget\n/.clj-kondo\n**/cdk.out\n**/classes\n**/node_modules\n"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   Copyright 2019 Stedi, Inc.\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# Current Status (January 16, 2020)\n\nAfter developing and using this Clojure wrapper for [AWS CDK][1] for the past\nsix months, we've decided to use TypeScript and AWS' library directly. We are\ndiscontinuing maintenance moving forward. If a member of the community would\nlike to volunteer for future maintenance, please file an issue or reach out\ndirectly to discuss a possible transfer.\n\n# cdk-clj\n\n[![GitHub Action Status](https://github.com/stediinc/cdk-clj/workflows/build/badge.svg)](https://github.com/stediinc/cdk-clj/actions)\n\n[#cdk-clj on Clojurians](https://clojurians.slack.com/archives/CQVV1N7QD)\n\nThis library is a Clojure wrapper for [AWS Cloud Development Kit (AWS CDK)][1].\n\nThis is an alpha release. We use this library internally and consider it\nstable. Nonetheless, we may still make minor changes to the API.\n\n## Purpose\n\nFrom [AWS][1]:\n\n>The AWS Cloud Development Kit (AWS CDK) is an open-source software development\n>framework to define cloud infrastructure in code and provision it through AWS\n>CloudFormation.\n>\n>It offers a high-level object-oriented abstraction to define AWS resources\n>imperatively using the power of modern programming languages. Using the CDK's\n>library of infrastructure constructs, you can easily encapsulate AWS best\n>practices in your infrastructure definition and share it without worrying about\n>boilerplate logic.\n\nCDK is built on Amazon's [jsii][2] project, which allows TypeScript projects to\nbe shared across Python, JavaScript, Java and C# via code generation.\n\n`cdk-clj` taps into this ecosystem directly by consuming the `jsii` protocol and\nbringing infrastructure to the REPL. REPL-driven infrastructure turns a\nfrustrating practice with long feedback cycles into an enjoyable experience with\nimmediate feedback and makes it possible for Clojure code to be deployed to AWS\nwith minimal configuration.\n\nFor a general introduction, watch the Clojure/Conj talk:\n\n[![Goodbye YAML: Infrastructure as Code in Clojure](https://img.youtube.com/vi/TbDmupZyuXk/0.jpg)][video]\n\n## Prerequisites\n\n`cdk-clj` requires:\n\n1. [Clojure][clojure]\n1. [Node.js][node-js]\n1. [AWS CDK CLI][cdk-cli]\n\n## Quick Start\n\n0. Ensure you have configured appropriate [AWS Credentials][aws-creds].\n   The following commands assume a [default profile][aws-profile].\n\n1. Install `aws-cdk`:\n\n``` shell\nnpm install -g aws-cdk\n```\n\n2. Create a new project directory with the following in a `deps.edn`\n   file. You will also need to include the Maven dependency for any\n   CDK modules you are using. You can find all the available modules\n   [here][maven-deps].\n\n``` clojure\n{:paths   [\"src\"]\n :deps    {org.clojure/clojure {:mvn/version \"1.10.1\"}}\n :aliases {:dev {:extra-paths [\"cdk\"]\n                 :extra-deps  {stedi/cdk-clj {:git/url \"https://github.com/StediInc/cdk-clj.git\"\n                                              :sha     \"<LATEST SHA HERE>\"}\n                               ;; Required in order to use the \"@aws-cdk/aws-s3\" module below\n                               software.amazon.awscdk/s3 {:mvn/version \"1.20.0\"}\n                               }}}}\n```\n\n3. Create a CDK infrastructure file with the path `./cdk/stedi/my_app/cdk.clj`.\n\n``` clojure\n(ns stedi.my-app.cdk\n  (:require [stedi.cdk.alpha :as cdk]))\n\n(cdk/import [[Stack] :from \"@aws-cdk/core\"]\n            [[Bucket] :from \"@aws-cdk/aws-s3\"])\n\n(defn AppStack\n  [scope id props]\n  (let [stack (Stack scope id props)]\n    (Bucket stack \"my-bucket\" {:versioned true})))\n\n(cdk/defapp app\n  [this]\n  (AppStack this \"my-app-dev\" {}))\n```\n\n4. Create\n   [`cdk.json`](https://docs.aws.amazon.com/cdk/latest/guide/tools.html#cli) in\n   the root of your project to tell the CDK toolchain how to invoke the app:\n```json\n{\"app\":\"clojure -A:dev -i cdk/stedi/my_app/cdk.clj\"}\n```\n\nwhere the argument to `-i` is the path to the file in which the cdk-clj app is\ndefined.\n\n5. List your stacks to verify correct configuration:\n\n``` shell\ncdk ls\n# should return `my-app-dev`\n```\n\n6. See the YAML that this deployment will produce for CloudFormation:\n\n```\ncdk synth my-app-dev\n```\n\n7. Deploy the stack to AWS:\n\n```\ncdk deploy my-app-dev\n```\n\n## Implementation Details\n\n[jsii][2] is a protocol that allows TypeScript classes and objects to be\nconsumed via an RPC protocol. This protocol exposes the ability to:\n\n- Create objects from classes with optionally overloaded methods\n- Get properties from objects\n- Set properties on objects\n- Call methods on objects\n- Get static properties on classes\n- Set static properties on classes\n- Call static methods on classes\n- Respond to callbacks on overloaded objects\n\nCDK exposes its functionality via this API to allow non-JavaScript programming\nlanguages to benefit from the functionality it provides.\n`cdk-clj` maps these operations into Clojure friendly equivalents. The CDK library\nrelies heavily on object oriented principles and `cdk-clj` does not shy away from\nthose concepts. Instead, it embraces them and maps them into a Clojure-friendly\ninterface. In doing so, it makes the [CDK documentation][3] directly mappable to\nClojure.\n\nThere are two types introduced by this library: `CDKClass` and\n`CDKObject`. Together, they expose all of the functionality of the `jsii`\nprotocol by implementing the `clojure.lang.ILookup` and `clojure.lang.IFn`\ninterfaces:\n\n**Instantiate an object from a class**\n\n``` clojure\n;; Creates a bucket based on the CDK class @aws-cdk/aws-s3.Bucket\n(cdk/import [[Bucket] :from \"@aws-cdk/aws-s3\"])\n(def bucket (Bucket parent \"my-bucket\" {}))\n```\n\n**Get property of an object**\n``` clojure\n;; Gets the bucketArn property off of the bucket instance\n(:bucketArn bucket)\n```\n\n**Set property of an object**\n``` clojure\n;; TODO: not implemented yet\n```\n\n**Call a method on an object**\n``` clojure\n;; Grants READ permission to the lambda-function object\n(cdk/import [[Bucket] :from \"@aws-cdk/aws-s3\"])\n(Bucket/grantRead bucket lambda-function)\n```\n\n**Get static property of a class**\n``` clojure\n(cdk/import [[Runtime] :from \"@aws-cdk/aws-lambda\"])\n;; Get the JAVA8 runtime instance\n(:JAVA_8 Runtime)\n```\n\n**Set static property of an object**\n``` clojure\n;; TODO: not implemented yet\n```\n\n**Call static method on class**\n``` clojure\n(cdk/import [[Code] :from \"@aws-cdk/aws-lambda\"])\n;; Refer to the src directory as an asset to be uploaded\n(Code/asset \"src\")\n```\n\n## Next Steps\n\n* Check out the [example app][4] to see the minimum setup required to get a\n  [Lambda][stedilambda] deployed behind API Gateway\n* Check out the [CDK API Docs][5] to see what modules are available and how to\n  use them\n\n## Troubleshooting\n\n### Cannot find the 'jsii-runtime' executable (JSII_RUNTIME or PATH)\n\n[This error][jsii-404] is non-specific and is raised on any failure to launch\nthe runtime process, not just the missing executable named; that the causative\nexception is not chained makes this harder to debug.\n\nOne possible cause is not having the [Node.js][node-js] executable (i.e.,\n`node`) on the `PATH` given to the JVM. If you're using a Node version or\n[virtual environment][nodeenv] manager, add the appropriate directory to the JVM\nenvironment.\n\n## Contributing\n\nContributors are welcome to submit issues, bug reports, and feature\nrequests. Presently, we do not accept pull requests.\n\n## License\n\ncdk-clj is distributed under the [Apache License, Version 2.0][apache-2].\n\nSee [LICENSE](LICENSE) for more information.\n\n[1]: https://github.com/aws/aws-cdk#aws-cloud-development-kit-aws-cdk\n[2]: https://github.com/aws/jsii\n[3]: https://docs.aws.amazon.com/cdk/api/latest/\n[4]: https://github.com/StediInc/cdk-clj/tree/master/examples/basics\n[5]: https://docs.aws.amazon.com/cdk/api/latest/docs/aws-construct-library.html\n\n[apache-2]: https://www.apache.org/licenses/LICENSE-2.0\n[aws-creds]: https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html\n[aws-profile]: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html\n[cdk-cli]: https://docs.aws.amazon.com/cdk/latest/guide/tools.html\n[clojure]: https://clojure.org/guides/getting_started\n[jsii-404]: https://github.com/aws/jsii/blob/850f42bea4218f2563d221aff28926da16692f62/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiRuntime.java#L220\n[node-js]: https://nodejs.org/en/\n[nodeenv]: https://github.com/ekalinin/nodeenv\n[stedilambda]: https://github.com/StediInc/lambda\n[maven-deps]: https://search.maven.org/search?q=software.amazon.awscdk\n[video]: https://www.youtube.com/watch?v=TbDmupZyuXk\n"
  },
  {
    "path": "deps.edn",
    "content": "{:paths   [\"resources\" \"src\"]\n :deps    {org.clojure/clojure                 {:mvn/version \"1.10.1\"}\n           org.apache.commons/commons-compress {:mvn/version \"1.19\"}\n           org.clojure/data.json               {:mvn/version \"0.2.6\"}\n           org.clojure/tools.cli               {:mvn/version \"0.4.2\"}\n           org.clojure/tools.namespace         {:mvn/version \"0.3.1\"}\n           software.amazon.awscdk/core         {:mvn/version \"1.20.0\"}}\n :aliases {:dev  {:extra-paths [\"test\"]\n                  :extra-deps  {clj-kondo                     {:mvn/version \"2019.09.22-alpha\"}\n                                com.cognitect/test-runner\n                                {:git/url \"https://github.com/cognitect-labs/test-runner.git\"\n                                 :sha     \"209b64504cb3bd3b99ecfec7937b358a879f55c1\"}\n                                software.amazon.awscdk/lambda {:mvn/version \"1.20.0\"}}}\n           :lint {:main-opts [\"-m\" \"clj-kondo.main\" \"--lint\" \".\"]}\n           :unit {:main-opts [\"-m\" \"cognitect.test-runner\" \"--exclude\" \"integration\"]}\n           :test {:main-opts [\"-m\" \"cognitect.test-runner\"]}}}\n"
  },
  {
    "path": "examples/basics/cdk/stedi/basics/cdk.clj",
    "content": "(ns stedi.basics.cdk\n  (:require [clojure.edn :as edn]\n            [clojure.java.io :as io]\n            [stedi.cdk.alpha :as cdk]\n            [uberdeps.api :as uberdeps]))\n\n;; CDK is a framework released by Amazon that allows developers to\n;; deploy CloudFormation-based infrastructure using their prefered\n;; language.\n\n;; It is built from TypeScript and made available to other languages\n;; through the JSii protocol by Amazon. JSii allows other languages to\n;; interact with JavaScript classes through an RPC protocol.\n\n;; cdk-clj wraps the JSii protocol for CDK classes in Clojure.\n\n;; The best way of getting information about what is availble via CDK\n;; is to call `(cdk/browse)` in the REPL. This will take you to the\n;; AWS CDK API reference documentation.\n\n(comment\n  (cdk/browse)\n  )\n\n;; CDK applications consist of Constructs arranged into a tree\n;; structure. Constructs represent one or more AWS resources. All CDK\n;; applications have an App construct at the root of the\n;; tree. `cdk-clj` exposes access to these constructs through the\n;; `cdk/import` macro.\n\n(cdk/import [[App] :from \"@aws-cdk/core\"])\n\n;; Import does two things:\n;; 1. makes App resolvable to a jsii-class in the local namespace\n;; 2. aliases the ns for \"@aws-cdk/core.App\" to App\n\n;; App will now resolve to a jsii-class\nApp\n\n;; Invoking the class calls its constructor and returns a\n;; jsii-instance:\n(def app (App))\n\n;; These constructor vars also have docstrings\nApp\n\n;; Import also makes an alias to the ns that contains all the static\n;; and instance methods for App\nApp/isApp\nApp/synth\n\n;; You can also browse to a constructs documentation via browse on\n;; the constructor or an instance:\n\n(comment\n  (cdk/browse app)\n  (cdk/browse App)\n  )\n\n;; Applications are composed of one or more Stacks, each representing\n;; a CloudFormation Stack. A Stack is a Construct as well.\n\n(cdk/import [[Stack] :from \"@aws-cdk/core\"])\n\n;; Child constructs are connected to their parent by passing in the\n;; parent as the scope of the child's constructor function.\n\n(def stack (Stack app \"cdk-clj-basics\"))\n\n;; Class instances implement the ILookup interface so they work with\n;; keyword lookups\n\n(:stackName stack)\n\n;; A stack needs at least one resource Construct in order to be\n;; deployable so lets add a bucket.\n\n(cdk/import [[Bucket] :from \"@aws-cdk/aws-s3\"])\n\n;; cdk-clj generates specs for and instruments all jsii constructors\n;; and functions:\n\n(comment\n  (Bucket stack nil) ; Fails with spec error\n\n  ;; Worth noting that the CDK specs are closed\n\n  (Bucket stack \"id\" {:does-not-exist :foo}) ; Fails due to specs being closed\n  )\n\n(def bucket (Bucket stack \"bucket\"))\n\n;; Buckets aren't particularly interesting, and lambdas + serverless\n;; are all the rage so lets add a lambda function as well.\n\n(cdk/import [[Code Function Runtime] :from \"@aws-cdk/aws-lambda\"])\n\n(defn- clean\n  []\n  (->> (io/file \"classes\")\n       (file-seq)\n       (reverse)\n       (map io/delete-file)\n       (dorun)))\n\n(def jarpath \"target/app.jar\")\n\n;; Build an uberjar with the compiled source + dependency classes\n\n(let [deps (edn/read-string (slurp \"deps.edn\"))]\n  (when (.exists (io/file \"classes\")) (clean))\n  (with-out-str\n    (io/make-parents \"classes/.\")\n    (io/make-parents jarpath)\n    (compile 'stedi.lambada)\n    (uberdeps/package deps jarpath {:aliases [:classes]})))\n\n(comment\n  (cdk/browse Function)\n  )\n\n(def my-fn\n  (Function stack\n            \"my-fn\"\n            {:code        (Code/fromAsset jarpath)        ;; Calling a static method\n             :handler     \"stedi.cdk.basics.Hello\"\n             :runtime     (:JAVA_8 Runtime)               ;; Getting a static property\n             :environment {\"BUCKET\" (:bucketName bucket)} ;; Getting an instance property\n             }))\n\n(comment\n  ;; See it bound to the construct tree\n  (map (comp :path :node)\n       (get-in stack [:node :children]))\n  )\n\n;; We can grant the function write access to the bucket using an\n;; instance method\n\n(Bucket/grantWrite bucket my-fn)\n\n;; CDK constructs often have functions for granting permissions,\n;; adding metrics and triggering events.\n\n;; This app can now be deployed using `cdk-cli` in a shell with AWS\n;; credentials configured.\n\n;; Synth:\n;; cdk synth\n\n;; Deploy:\n;; cdk deploy\n\n;; Destroy:\n;; cdk destroy\n"
  },
  {
    "path": "examples/basics/cdk.json",
    "content": "{\"app\":\"clojure -C:dev -R:dev -m stedi.cdk.main synth\"}"
  },
  {
    "path": "examples/basics/deps.edn",
    "content": "{:paths   [\"src\"]\n :deps    {org.clojure/clojure {:mvn/version \"1.10.1\"}\n           uswitch/lambada     {:mvn/version \"0.1.2\"}}\n :aliases {:cdk     {:main-opts [\"-m\" \"stedi.cdk.main\"]}\n           :classes {:extra-paths [\"classes\"]}\n           :dev     {:extra-paths [\"cdk\"]\n                     :extra-deps  {software.amazon.awscdk/s3     {:mvn/version \"1.20.0\"}\n                                   software.amazon.awscdk/lambda {:mvn/version \"1.20.0\"}\n                                   stedi/cdk-clj                 {:local/root \"../../\"}\n                                   uberdeps                      {:mvn/version \"0.1.6\"}}}}}\n"
  },
  {
    "path": "examples/basics/src/stedi/lambada.clj",
    "content": "(ns stedi.lambada\n  (:require [uswitch.lambada.core :refer [deflambdafn]]))\n\n(deflambdafn stedi.cdk.basics.Hello\n  [in out ctx]\n  (let [bucket-name (System/getenv \"BUCKET\")]\n    (.write out (.getBytes (format \"Hello! Bucket Name: %s\" bucket-name)))))\n"
  },
  {
    "path": "examples/depswatch/cdk/depswatch/cdk.clj",
    "content": "(ns depswatch.cdk\n  (:require [clojure.edn :as edn]\n            [clojure.java.io :as io]\n            [stedi.cdk.alpha :as cdk]\n            [uberdeps.api :as uberdeps]))\n\n(cdk/import [[App Construct Duration Stack] :from \"@aws-cdk/core\"]\n            [[LambdaRestApi] :from \"@aws-cdk/aws-apigateway\"]\n            [[AttributeType Table] :from \"@aws-cdk/aws-dynamodb\"]\n            [[Rule Schedule] :from \"@aws-cdk/aws-events\"]\n            [[SfnStateMachine] :from \"@aws-cdk/aws-events-targets\"]\n            [[Code Function Runtime Tracing] :from \"@aws-cdk/aws-lambda\"]\n            [[Chain Choice Condition Data\n              Map StateMachine Succeed Task] :from \"@aws-cdk/aws-stepfunctions\"]\n            [[InvokeFunction StartExecution] :from \"@aws-cdk/aws-stepfunctions-tasks\"])\n\n(defn- clean\n  []\n  (let [f (io/file \"classes\")]\n    (when (.exists f)\n      (->> f\n           (file-seq)\n           (reverse)\n           (map io/delete-file)\n           (dorun)))))\n\n(def code\n  (let [jarpath \"target/app.jar\"\n        deps    (edn/read-string (slurp \"deps.edn\"))]\n    (with-out-str\n      (clean)\n      (io/make-parents \"classes/.\")\n      (io/make-parents jarpath)\n      (compile 'depswatch.lambada)\n      (uberdeps/package deps jarpath {:aliases [:classes]}))\n    (Code/fromAsset jarpath)))\n\n(defn LambadaFunction\n  [scope id props]\n  (Function scope\n            id\n            (merge {:code       code\n                    :memorySize 2048\n                    :runtime    (:JAVA_8 Runtime)\n                    :tracing    Tracing/ACTIVE}\n                   props)))\n\n(defn TaskFunction\n  [scope id {:keys [handler resultPath]}]\n  (let [construct (Construct scope id)\n        fn        (LambadaFunction construct \"fn\" {:handler handler})\n        task      (Task construct\n                        id\n                        {:task       (InvokeFunction fn)\n                         :resultPath (or resultPath \"$\")})]\n    task))\n\n(defn RunJobStateMachine\n  [scope id]\n  (let [construct (Construct scope id)\n        definition\n        (-> (Chain/start\n              (TaskFunction construct\n                            \"get-deps-edn\"\n                            {:handler    \"depswatch.GetDepsEdn\"\n                             :resultPath \"$.depsEdn\"}))\n            (Chain/next\n              (TaskFunction construct\n                            \"check-newer\"\n                            {:handler    \"depswatch.CheckNewer\"\n                             :resultPath \"$.newer\"}))\n            (Chain/next\n              (TaskFunction construct\n                            \"check-sent\"\n                            {:handler    \"depswatch.CheckSent\"\n                             :resultPath \"$.sent\"}))\n            (Chain/next\n              (doto (Choice construct \"was-sent\")\n                (Choice/when (Condition/booleanEquals \"$.sent\" true)\n                  (Succeed construct \"already-sent\"))\n\n                (Choice/when (Condition/booleanEquals \"$.sent\" false)\n                  (TaskFunction construct\n                                \"notify-slack\"\n                                {:handler \"depswatch.NotifySlack\"})))))]\n    (StateMachine construct \"sfn\" {:definition definition})))\n\n(defn StartJobsStateMachine\n  [scope id {:keys [run-job]}]\n  (let [construct (Construct scope id)\n        task      (StartExecution run-job\n                                  {:input {:owner (Data/stringAt \"$.owner\")\n                                           :repo  (Data/stringAt \"$.repo\")}})\n        definition\n        (doto (TaskFunction construct\n                            \"get-repos\"\n                            {:handler \"depswatch.GetRepos\"})\n          (Task/next\n            (doto (Map construct \"run-jobs\")\n              (Map/iterator\n                (Task construct \"run-job\" {:task task})))))]\n    (StateMachine construct \"sfn\" {:definition definition})))\n\n(defn AppStack\n  [scope id {:keys [timer?]}]\n  (let [stack         (Stack scope id)\n        watched-repos (Table stack\n                             \"watched-repos\"\n                             {:partitionKey {:name \"owner\"\n                                             :type AttributeType/STRING}})\n        slack-hook    (LambadaFunction stack\n                                       \"slack-hook\"\n                                       {:handler \"depswatch.SlackHook\"\n                                        :environment\n                                        {\"WATCHED_REPOS\" (:tableName watched-repos)}})\n        run-job       (RunJobStateMachine stack \"run-job\")\n        start-jobs    (StartJobsStateMachine stack \"start-jobs\" {:run-job run-job})]\n    (when timer?\n      (Rule stack\n            \"timer\"\n            {:schedule (Schedule/rate\n                         (Duration/minutes 1))\n             :targets  [(SfnStateMachine start-jobs)]}))\n    (Table/grantReadWriteData watched-repos slack-hook)\n    (LambdaRestApi slack-hook \"api\" {:handler slack-hook})\n    stack))\n\n(def app (App))\n\n(AppStack app \"depswatch-dev\" {:timer? false})\n(AppStack app \"depswatch-prod\" {:timer? true})\n"
  },
  {
    "path": "examples/depswatch/cdk.json",
    "content": "{\"app\":\"clojure -C:dev -R:dev -m stedi.cdk.main synth\"}"
  },
  {
    "path": "examples/depswatch/deps.edn",
    "content": "{:paths [\"src\"]\n :deps  {org.clojure/clojure {:mvn/version \"1.10.1\"}\n\n         org.clojure/data.json {:mvn/version \"0.2.6\"}\n         uswitch/lambada       {:mvn/version \"0.1.2\"}}\n :aliases {:cdk     {:main-opts [\"-m\" \"stedi.cdk.main\"]}\n           :classes {:extra-paths [\"classes\"]}\n           :dev     {:extra-paths [\"cdk\"]\n                     :extra-deps  {stediinc/cdk-clj {:local/root \"../../\"}\n\n                                   uberdeps {:mvn/version \"0.1.6\"}\n\n                                   software.amazon.awscdk/apigateway          {:mvn/version \"1.20.0\"}\n                                   software.amazon.awscdk/dynamodb            {:mvn/version \"1.20.0\"}\n                                   software.amazon.awscdk/events              {:mvn/version \"1.20.0\"}\n                                   software.amazon.awscdk/events-targets      {:mvn/version \"1.20.0\"}\n                                   software.amazon.awscdk/lambda              {:mvn/version \"1.20.0\"}\n                                   software.amazon.awscdk/stepfunctions       {:mvn/version \"1.20.0\"}\n                                   software.amazon.awscdk/stepfunctions-tasks {:mvn/version \"1.20.0\"}}}}}\n"
  },
  {
    "path": "examples/depswatch/src/depswatch/lambada.clj",
    "content": "(ns depswatch.lambada\n  (:require [clojure.data.json :as json]\n            [uswitch.lambada.core :refer [deflambdafn]]))\n\n(deflambdafn depswatch.GetRepos\n  [in out ctx]\n  (.write out\n          (.getBytes\n            (json/write-str\n              [{:owner \"stediinc\"\n                :repo  \"cdk-clj\"}]))))\n\n(deflambdafn depswatch.GetDepsEdn\n  [in out ctx]\n  (.write out\n          (.getBytes\n            (json/write-str\n              (pr-str\n                {:deps {'midje {:mvn/version \"1.9.8\"}}})))))\n\n(deflambdafn depswatch.CheckNewer\n  [in out ctx]\n  (.write out\n          (.getBytes\n            (json/write-str\n              (pr-str\n                {'midje {:old-version \"1.9.8\"\n                         :new-version \"1.9.9\"}})))))\n\n(deflambdafn depswatch.CheckSent\n  [in out ctx]\n  (.write out\n          (.getBytes\n            (json/write-str\n              false))))\n\n(deflambdafn depswatch.NotifySlack\n  [in out ctx]\n  (.write out\n          (.getBytes\n            (json/write-str\n              \"Slack notified\"))))\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"cdk-clj\",\n  \"version\": \"1.0.0\",\n  \"description\": \"This library is a Clojure wrapper for [AWS Cloud Development Kit (AWS CDK)][1].\",\n  \"main\": \"index.js\",\n  \"directories\": {\n    \"example\": \"examples\",\n    \"test\": \"test\"\n  },\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/stediinc/cdk-clj.git\"\n  },\n  \"keywords\": [],\n  \"author\": \"\",\n  \"license\": \"ISC\",\n  \"bugs\": {\n    \"url\": \"https://github.com/stediinc/cdk-clj/issues\"\n  },\n  \"homepage\": \"https://github.com/stediinc/cdk-clj#readme\",\n  \"devDependencies\": {\n    \"aws-cdk\": \"^1.16.3\"\n  }\n}\n"
  },
  {
    "path": "src/stedi/cdk/alpha.clj",
    "content": "(ns stedi.cdk.alpha\n  (:refer-clojure :exclude [import])\n  (:require [clojure.java.browse :as browse]\n            [clojure.spec.alpha :as s]\n            [clojure.string :as string]\n            [stedi.jsii.alpha :as jsii]))\n\n(def ^:private docs-prefix\n  \"https://docs.aws.amazon.com/cdk/api/latest\")\n\n(defn browse\n  \"Browse to CDK documentation by CDK fqn, CDK object or CDK\n  class. Calling without any arguments opens the root documentation.\n\n  Examples:\n\n  ;; Opening module documentation\n  (cdk/browse \\\"@aws-cdk/core\\\") ;; open core module\n  (cdk/browse \\\"core\\\") ;; also opens core module\n\n  ;; Opening class documentation\n  (import [\\\"@aws-cdk/core\\\" Stack])\n\n  (cdk/browse \\\"@aws-cdk/aws-lambda.Stack\\\")\n  (cdk/browse Stack)   ;; can open docs from a class\n  (cdk/browse (Stack)) ;; can also open docs from an instance\n  \"\n  ([] (browse/browse-url docs-prefix))\n  ([obj-class-or-fqn]\n   (letfn [(cdk-class? [fqn]\n             (re-find #\"\\.[A-Za-z]+$\" fqn))\n\n           (fqn->url [fqn]\n             (let [url-formatted-fqn\n                   (if (cdk-class? fqn)\n                     (string/replace fqn \"/\" \"_\")\n                     (str (string/replace fqn \"@aws-cdk/\" \"\")\n                          \"-readme\"))]\n               (format \"%s/docs/%s.html\" docs-prefix url-formatted-fqn)))]\n     (cond\n       (string? obj-class-or-fqn)\n       (browse/browse-url (fqn->url obj-class-or-fqn))\n\n       (jsii/jsii-primitive? obj-class-or-fqn)\n       (browse (jsii/fqn obj-class-or-fqn))))))\n\n(s/def ::bindings\n  (s/+\n    (s/alt :alias (s/cat :alias symbol?)\n           :as    (s/cat :class symbol?\n                         :as    #{:as}\n                         :alias symbol?))))\n\n(s/def ::import-args\n  (s/or :v0 (s/coll-of\n              (s/cat :module string?\n                     :bindings ::bindings))\n        :v1 (s/coll-of\n              (s/cat :bindings (s/spec ::bindings)\n                     :from #{:from}\n                     :module string?))))\n\n(s/fdef import\n  :args ::import-args\n  :ret  any?)\n\n(defmacro import\n  \"Imports jsii classes and binds them to an alias. Allows for multiple\n  module requirement bindings.\n\n  Example:\n\n  (cdk/import [[App Stack] :from \\\"@aws-cdk/core\\\"])\"\n  [& imports]\n  (let [[version import-list] (s/conform ::import-args imports)]\n    (when (= :v0 version)\n      (println\n       (str \"Warning: Using outdated import format. Please use \"\n            \"the :from syntax. See `cdk/import` docstring for \"\n            \"example.\")))\n    (doseq [{:keys [module bindings]} import-list\n\n            [_ {:keys [class alias]}] bindings]\n      (jsii/import-fqn (str module \".\" (or class alias)) alias))))\n\n(defmacro defapp\n  \"The @aws-cdk/core.App class is the main class for a CDK project.\n\n  `defapp` is a convenience macro that creates an extension for an app\n  with a signature similar to defn. The first argument will be the app\n  itself and is to be used in the body to wire in children constructs.\n\n  After declaring itself, the app extension instantiates itself which\n  forces cdk validations to occur to streamline the repl-workflow.\n\n  Example:\n\n  (cdk/defapp app\n    [this]\n    (stack this \\\"MyDevStack\\\" {}))\"\n  [name args & body]\n  (jsii/reset-runtime!)\n  `(do (import [[~'App] :from \"@aws-cdk/core\"])\n       (let [app# (~'App {})]\n         ((fn ~args ~@body) app#)\n         (def ~name\n           (doto app#\n             (App/synth))))))\n"
  },
  {
    "path": "src/stedi/cdk/main.clj",
    "content": "(ns stedi.cdk.main\n  (:require [clojure.data.json :as json]\n            [clojure.java.classpath :as cp]\n            [clojure.tools.cli :as cli]\n            [clojure.tools.namespace.find :as ctn.find]\n            [stedi.cdk.alpha :as cdk]\n            [stedi.jsii.alpha :as jsii]))\n\n(cdk/import [[App] :from \"@aws-cdk/core\"])\n\n(defn load-project-files\n  []\n  (->> (cp/classpath-directories)\n       (ctn.find/find-namespaces)\n       (map #(try (require %) % (catch Exception _)))\n       (remove nil?)\n       (doall)))\n\n(defn find-app\n  []\n  (let [apps (->> (load-project-files)\n                  (mapcat ns-publics)\n                  (map second)\n                  (filter (comp #(and (jsii/jsii-primitive? %)\n                                      (App/isApp %))\n                                deref)))]\n    (assert (not-empty apps) \"No app was found.\")\n    (assert (= 1 (count apps)) \"More than one app was found.\")\n    (deref (first apps))))\n\n(defn config\n  [{:keys [aliases]}]\n  (spit \"cdk.json\"\n        (json/write-str\n          {:app (str \"clojure\"\n                     (when aliases\n                       (str \" -C:\" aliases \" -R:\" aliases))\n                     \" -m stedi.cdk.main synth\")}\n          :escape-slash false)))\n\n(defn synth\n  [_]\n  (let [app (find-app)]\n    (App/synth app)))\n\n(def actions\n  {:config {:cli-options [[nil \"--aliases ALIASES\" \"Colon seperated classpath aliases to use during synth\"]]\n            :handler     config}\n   :synth  {:handler synth}})\n\n(defn do-main\n  [args]\n  (let [action-kw         (keyword (first args))\n        {:keys [cli-options\n                handler]} (get actions action-kw)\n        {:keys [options]} (cli/parse-opts args (or cli-options []))]\n    (handler options)))\n\n(defn -main [& args]\n  (try\n    (do-main args)\n    (finally\n      (shutdown-agents))))\n"
  },
  {
    "path": "src/stedi/jsii/alpha/assembly.clj",
    "content": "(ns stedi.jsii.alpha.assembly\n  (:require [clojure.data.json :as json]\n            [clojure.java.io :as io]\n            [clojure.string :as string])\n  (:import (java.util.zip GZIPInputStream)\n           (org.apache.commons.compress.archivers.tar TarArchiveInputStream))\n  (:refer-clojure :exclude [methods]))\n\n(defn- classpath-jsii-archives\n  []\n  (->> (-> (System/getProperty \"java.class.path\")\n           (string/split #\":\"))\n       (filter #(string/ends-with? % \".jar\"))\n       (map io/file)\n       (map #(java.util.jar.JarFile. %))\n       (mapcat (comp enumeration-seq #(.entries %)))\n       (filter (comp #(.endsWith % \"jsii.tgz\") str))\n       (map str)))\n\n(defn- keywordize-alpha\n  [x]\n  (if (and (string? x)\n           (re-find #\"^[A-Za-z]\" x))\n    (keyword x)\n    x))\n\n(defn- read-spec\n  [input-stream]\n  (-> input-stream\n      (io/reader)\n      (json/read :key-fn keywordize-alpha)))\n\n(defn- load-assembly-resource [resource]\n  (with-open [is (-> resource\n                     (io/resource)\n                     (io/input-stream)\n                     (GZIPInputStream.)\n                     (TarArchiveInputStream.))]\n    (loop []\n      (when-let [entry (.getNextTarEntry is)]\n        (if (= (.getName entry) \"package/.jsii\")\n          (assoc (read-spec is) ::bundle (str \"/\" resource))\n          (recur))))))\n\n(defn- load-all-assemblies\n  []\n  (into []\n        (map load-assembly-resource)\n        (classpath-jsii-archives)))\n\n(defn- indexed-types\n  []\n  (->> (load-all-assemblies)\n       (map :types)\n       (apply merge)))\n\n(defonce ^:private all-types* (map second (indexed-types)))\n\n(defn all-types [] all-types*)\n\n(def get-type\n  (memoize\n    (fn [fqn]\n      (->> (all-types)\n           (filter (comp #{fqn} :fqn))\n           (first)))))\n\n(def get-assembly\n  (memoize\n    (fn [module-name]\n      (->> (load-all-assemblies)\n           (filter (comp #{module-name} :name))\n           (first)))))\n\n(defn arities\n  [parameters]\n  (let [base     (take-while (complement :optional) parameters)\n        optional (drop-while (complement :optional) parameters)]\n    (concat\n      (list base)\n      (for [n (map inc (range (count optional)))]\n        (concat base (take n optional))))))\n\n(defn- interfaces*\n  [fqn]\n  (let [t            (get-type fqn)\n        t-interfaces (:interfaces t)]\n    (lazy-cat (when (= \"interface\" (:kind t))\n                (list fqn))\n              t-interfaces\n              (mapcat interfaces* t-interfaces)\n              (when-let [base (:base t)]\n                (interfaces* base)))))\n\n(defn interfaces\n  [fqn]\n  (set (interfaces* fqn)))\n\n(defn class-heirarchy\n  [fqn]\n  (when-let [t (get-type fqn)]\n    (lazy-seq (cons fqn (class-heirarchy (:base t))))))\n\n(defn- dedupe-by-name\n  [coll]\n  (sequence (comp (map second)\n                  (map last))\n            (group-by :name coll)))\n\n(defn- properties*\n  [fqn]\n  (when-let [t (get-type fqn)]\n    (lazy-cat (when-let [interfaces (:interfaces t)]\n                (mapcat properties* interfaces))\n              (when-let [base (:base t)]\n                (properties* base))\n              (:properties t))))\n\n(defn properties\n  [fqn]\n  (dedupe-by-name (remove :protected (properties* fqn))))\n\n(defn- methods*\n  [fqn]\n  (when-let [t (get-type fqn)]\n    (lazy-cat (when-let [base (:base t)]\n                (methods* base))\n              (:methods t))))\n\n(defn methods\n  [fqn]\n  (dedupe-by-name (remove :protected (methods* fqn))))\n"
  },
  {
    "path": "src/stedi/jsii/alpha/client.clj",
    "content": "(ns stedi.jsii.alpha.client\n  (:require [clojure.data.json :as json]\n            [clojure.string :as string]\n            [stedi.jsii.alpha.assembly :as assm])\n  (:import (com.fasterxml.jackson.databind ObjectMapper)\n           (software.amazon.jsii JsiiRuntime JsiiModule JsiiObjectRef)))\n\n(defonce ^:private object-mapper (ObjectMapper.))\n\n(defonce ^:private jsii-runtime (atom (JsiiRuntime.)))\n\n(defonce ^:private loaded-modules (atom #{}))\n\n(defn- ->module [{:keys [module-name module-version module-bundle]}]\n  (let [this (proxy [JsiiModule] [module-name module-version nil module-bundle])]\n    (proxy [JsiiModule] [module-name module-version (class this) module-bundle])))\n\n(defn reset-runtime!\n  []\n  (reset! jsii-runtime (JsiiRuntime.))\n  (reset! loaded-modules #{}))\n\n(defn- client\n  []\n  (.getClient @jsii-runtime))\n\n(defn load-module [fqn]\n  (let [module-name (first (string/split fqn #\"\\.\"))]\n    (when-not (@loaded-modules module-name)\n      (let [{:keys [::assm/bundle\n                    version\n                    dependencies]} (assm/get-assembly module-name)\n\n            module (->module {:module-name    module-name\n                              :module-version version\n                              :module-bundle  bundle})]\n        (doseq [dep (map first dependencies)]\n          (load-module dep))\n        (.loadModule (client) module)\n        (swap! loaded-modules conj module-name)))))\n\n(defn- json-node->edn [json-node]\n  (some-> json-node\n          (.toString)\n          (json/read-str)))\n\n(defn- edn->json-node [data]\n  (->> data\n       (json/write-str)\n       (.readTree object-mapper)))\n\n(defn create-object\n  ([fqn initializer-args]\n   (load-module fqn)\n   (let [initializer-args (map edn->json-node initializer-args)\n         overrides []\n         interfaces []]\n     (-> (.createObject (client) fqn initializer-args overrides interfaces)\n         (.toJson)\n         (json-node->edn)))))\n\n(defn delete-object\n  [object-ref]\n  (.deleteObject (client) object-ref))\n\n(defn get-property-value\n  [object-id property]\n  (let [object-ref (JsiiObjectRef/fromObjId object-id)]\n    (-> (.getPropertyValue (client) object-ref property)\n        (json-node->edn))))\n\n(defn set-property-value\n  [object-ref property value]\n  (.setPropertyValue (client) object-ref property (edn->json-node value)))\n\n(defn get-static-property-value\n  [fqn property]\n  (load-module fqn)\n  (-> (.getStaticPropertyValue (client) fqn property)\n      (json-node->edn)))\n\n(defn set-static-property-value\n  [fqn property value]\n  (load-module fqn)\n  (.setStaticPropertyValue (client) fqn property (edn->json-node value)))\n\n(defn call-static-method\n  [fqn method args]\n  (load-module fqn)\n  (-> (.callStaticMethod (client) fqn method (edn->json-node args))\n      (json-node->edn)))\n\n(defn call-method\n  [object-id method args]\n  (let [object-ref (JsiiObjectRef/fromObjId object-id)]\n    (-> (.callMethod (client) object-ref method (edn->json-node args))\n        (json-node->edn))))\n"
  },
  {
    "path": "src/stedi/jsii/alpha/fqn.clj",
    "content": "(ns stedi.jsii.alpha.fqn\n  (:require [clojure.string :as string]))\n\n(defn- tokenize\n  [fqn & parts]\n  (-> (string/join \".\" (concat [fqn] parts))\n      (string/replace \"@\" \"\")\n      (string/replace \"/\" \".\")\n      (string/split #\"\\.\")))\n\n(defn fqn->ns-sym\n  [fqn & parts]\n  (symbol\n    (->> (apply tokenize fqn parts)\n         (string/join \".\"))))\n\n(defn fqn->qualified-keyword\n  [fqn & parts]\n  (-> (apply tokenize fqn parts)\n      ((juxt butlast last))\n      (update 0 (partial string/join \".\"))\n      ((partial string/join \"/\"))\n      (keyword)))\n\n(defn fqn->qualified-symbol\n  [fqn & parts]\n  (symbol\n    (apply fqn->qualified-keyword fqn parts)))\n"
  },
  {
    "path": "src/stedi/jsii/alpha/impl.clj",
    "content": "(ns stedi.jsii.alpha.impl\n  (:require [clojure.data.json :as json]\n            [clojure.walk :as walk]\n            [stedi.jsii.alpha.assembly :as assm]\n            [stedi.jsii.alpha.client :as client]\n            [stedi.jsii.alpha.fqn :as fqn])\n  (:import (software.amazon.jsii JsiiObjectRef)))\n\n(def ^:private valid-tokens\n  #{\"$jsii.byref\"\n    \"$jsii.enum\"\n    \"$jsii.date\"\n    \"$jsii.map\"})\n\n(defn- jsii-type\n  [x]\n  (and (map? x)\n       (some valid-tokens (keys x))))\n\n;; This is to encompass conversions of different JSON-serialized jsii\n;; types. Only $jsii.byref is currently implemented because we have\n;; not seen examples of the other serializations yet. However, the\n;; link below implies that we may run into additional types that need\n;; to be implemented.\n;; https://github.com/aws/jsii/blob/master/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObjectMapper.java\n(defmulti ^:private ->type jsii-type)\n\n(defn- ->clj\n  [m]\n  (walk/postwalk\n    (fn [x]\n      (if (jsii-type x)\n        (->type x)\n        x))\n    m))\n\n(defprotocol Invocable\n  (-invoke [_ req]))\n\n(defn get-type-info\n  [t]\n  (assm/get-type (.-fqn t)))\n\n(defn- props\n  [x pred?]\n  (into #{}\n        (comp (filter pred?)\n              (map :name)\n              (map keyword))\n        (assm/properties (.-fqn x))))\n\n(deftype JsiiObject [fqn interfaces objId]\n  clojure.lang.ILookup\n  (valAt [this k]\n    (->clj (client/get-property-value objId (name k))))\n\n  Invocable\n  (-invoke [_ {:keys [op args]}]\n    (->clj (client/call-method objId (name op) (or args []))))\n\n  java.lang.Object\n  (toString [this]\n    (when (some (comp #{\"toString\"} :name)\n                (assm/methods fqn))\n      (-invoke this {:op :toString})))\n\n  json/JSONWriter\n  (-write [object out]\n    (.write out (format \"{\\\"$jsii.byref\\\": \\\"%s\\\"}\" objId))))\n\n(defmethod ->type \"$jsii.byref\"\n  [x]\n  (let [id         (-> x first second)\n        interfaces (get x \"$jsii.interfaces\" [])\n        ref        (JsiiObjectRef/fromObjId id)]\n    (->JsiiObject (.getFqn ref) interfaces id)))\n\n(defmethod print-method JsiiObject\n  [this w]\n  (.write w (format \"#jsii-object[%s]\"\n                    (pr-str {:id         (.-objId this)\n                             :interfaces (.-interfaces this)\n                             :props      (props this (complement :static))}))))\n\n(defn- call-initializer\n  [this args]\n  (let [sym  (fqn/fqn->qualified-symbol (.-fqn this) \"impl\" \"-initializer\")\n        ctor (requiring-resolve sym)]\n    (apply ctor args)))\n\n(deftype JsiiClass [fqn]\n  clojure.lang.ILookup\n  (valAt [this k]\n    (->clj (client/get-static-property-value fqn (name k))))\n\n  Invocable\n  (-invoke [_ {:keys [op args]}]\n    (->clj (client/call-static-method fqn (name op) (or args []))))\n\n  clojure.lang.IFn\n  (applyTo [this arglist]\n    (call-initializer this arglist))\n  (invoke [this]\n    (call-initializer this []))\n  (invoke [this a1]\n    (call-initializer this [a1]))\n  (invoke [this a1 a2]\n    (call-initializer this [a1 a2]))\n  (invoke [this a1 a2 a3]\n    (call-initializer this [a1 a2 a3])))\n\n(defmethod print-method JsiiClass\n  [this w]\n  (.write w (format \"#jsii-class[%s]\"\n                    (pr-str {:fqn   (.-fqn this)\n                             :props (props this :static)}))))\n\n(deftype JsiiEnumMember [fqn value]\n  json/JSONWriter\n  (-write [object out]\n    (.write out (format \"{\\\"$jsii.enum\\\": \\\"%s\\\"}\"\n                        (str fqn \"/\" (name value))))))\n\n(defmethod print-method JsiiEnumMember\n  [this w]\n  (.write w (format \"#jsii-enum-member[%s]\"\n                    (pr-str (str (.-fqn this) \"/\" (name (.-value this)))))))\n\n(declare member-values)\n\n(deftype JsiiEnumClass [fqn]\n  clojure.lang.ILookup\n  (valAt [_ k]\n    (let [valid-values (member-values fqn)\n          value\n          (or (valid-values k)\n              (throw (ex-info \"Invalid enumeration value\"\n                              {:k            k\n                               :valid-values valid-values})))]\n      (JsiiEnumMember. fqn value))))\n\n(defmethod print-method JsiiEnumClass\n  [this w]\n  (.write w (format \"#jsii-enum-class[%s]\"\n                    (pr-str {:fqn     (.-fqn this)\n                             :members (member-values (.-fqn this))}))))\n\n;;------------------------------------------------------------------------------\n\n(defn create\n  [c args]\n  (let [fqn        (.-fqn c)\n        object     (client/create-object fqn (or args []))\n        interfaces (get object \"$jsii.interfaces\" [])\n        oid        (get object \"$jsii.byref\")]\n    (->JsiiObject fqn interfaces oid)))\n\n(defn get-class\n  [fqn]\n  (let [{:keys [kind]}\n        (or (assm/get-type fqn)\n            (throw (Exception.\n                     (str \"No class available for fqn: \" fqn))))]\n    (case kind\n      \"enum\"  (->JsiiEnumClass fqn)\n      \"class\" (->JsiiClass fqn))))\n\n(defn member-values\n  [fqn]\n  (->> (:members (assm/get-type fqn))\n       (map :name)\n       (map keyword)\n       (set)))\n\n(defn class-instance?\n  [fqn x]\n  (boolean\n    (and (instance? JsiiObject x)\n         (some #{fqn} (assm/class-heirarchy (.-fqn x))))))\n\n(defn enum-member?\n  [fqn x]\n  (boolean\n    (and (instance? JsiiEnumMember x)\n         (= fqn (.-fqn x))\n         ((member-values fqn) (.-value x)))))\n\n(defn satisfies-interface?\n  [fqn x]\n  (boolean\n    (and (instance? JsiiObject x)\n         (let [interfaces (.-interfaces x)]\n           (some #{fqn} (into #{}\n                              (mapcat assm/interfaces)\n                              (conj interfaces (.-fqn x))))))))\n"
  },
  {
    "path": "src/stedi/jsii/alpha/import.clj",
    "content": "(ns stedi.jsii.alpha.import\n  (:require [clojure.spec.test.alpha :as stest]\n            [clojure.string :as string]\n            [stedi.jsii.alpha.assembly :as assm]\n            [stedi.jsii.alpha.fqn :as fqn]\n            [stedi.jsii.alpha.impl :as impl]\n            [stedi.jsii.alpha.spec :as spec]))\n\n(defn- arg-lists\n  [parameters]\n  (reverse\n    (into (list)\n          (map (partial into []\n                        (mapcat (fn [{:keys [variadic name]}]\n                                  (if variadic\n                                    (list '& (symbol name))\n                                    (list (symbol name)))))))\n          (assm/arities parameters))))\n\n(defn- render-constructor-docstring\n  [{:keys [docs]}]\n  (let [{:keys [default stability summary deprecated remarks]} docs]\n    (->> [(str)\n          (when stability (format \"stability: [%s]\" stability))\n          (str)\n          (when summary summary)\n          (when deprecated deprecated)\n          (when default (format \"default: %s\" stability))\n          (when remarks (format \"remarks: %s\" remarks))]\n         (remove nil?)\n         (string/join \"\\n\"))))\n\n(defn- intern-initializer\n  [impl-ns-sym class-sym c]\n  (let [fqs\n        (symbol\n          (intern impl-ns-sym '-initializer\n                  (fn [& args]\n                    (impl/create c args))))\n        assembly   (assm/get-type (.-fqn c))\n        parameters (-> assembly\n                       (:initializer)\n                       (:parameters))]\n    (spec/load-spec fqs)\n    (stest/instrument fqs)\n    (intern impl-ns-sym\n            (with-meta class-sym\n              {:arglists (arg-lists parameters)\n               :doc      (render-constructor-docstring assembly)})\n            c)\n    (spec/load-spec (symbol (name impl-ns-sym) (name class-sym)))))\n\n(defn- render-method-docstring\n  [{:keys [docs]}]\n  (let [{:keys [default stability summary deprecated]} docs]\n    (->> [(str)\n          (when stability (format \"stability: [%s]\" stability))\n          (str)\n          (when summary summary)\n          (when deprecated deprecated)\n          (when default (format \"default: %s\" stability))]\n         (remove nil?)\n         (string/join \"\\n\"))))\n\n(defn- intern-methods\n  [target-ns-sym methods c]\n  (doseq [{:keys [static] :as method} methods]\n    (let [method-sym (-> method (:name) (symbol))\n          parameters (:parameters method)\n          deprecated (get-in method [:docs :deprecated])\n          fqs\n          (symbol\n            (intern target-ns-sym\n                    (with-meta method-sym\n                      (cond-> {:arglists (arg-lists\n                                           (concat (when-not static\n                                                     (list {:name \"this\"}))\n                                                   parameters))\n                               :doc      (render-method-docstring method)}\n                        deprecated (assoc :deprecated true)))\n                    (fn [& args]\n                      (impl/-invoke\n                        (if static c (first args))\n                        {:op   method-sym\n                         :args (if static args (rest args))}))))]\n      (spec/load-spec fqs)\n      (stest/instrument fqs))))\n\n(defn- intern-enum-members\n  [target-ns-sym members c]\n  (doseq [member members]\n    (let [member-sym  (-> member (:name) (symbol))\n          member-k    (keyword member-sym)\n          enum-member (get c member-k)]\n      (intern target-ns-sym member-sym enum-member))))\n\n(defn import-fqn\n  [fqn alias-sym]\n  (let [target-ns-sym (fqn/fqn->ns-sym fqn)\n        class-sym     (-> fqn (string/split #\"\\.\") (last) (symbol))\n        impl-ns-sym   (symbol (str target-ns-sym \".impl\"))\n        c             (impl/get-class fqn)\n\n        {:keys [members]} (impl/get-type-info c)\n        methods           (assm/methods fqn)]\n    (create-ns target-ns-sym)\n    (create-ns impl-ns-sym)\n    (ns-unmap impl-ns-sym class-sym)\n    (intern-initializer impl-ns-sym class-sym c)\n    (intern-methods target-ns-sym methods c)\n    (intern-enum-members target-ns-sym members c)\n    (alias alias-sym target-ns-sym)\n    (ns-unmap *ns* alias-sym)\n    (refer impl-ns-sym\n           :only [class-sym]\n           :rename {class-sym alias-sym})))\n"
  },
  {
    "path": "src/stedi/jsii/alpha/spec.clj",
    "content": "(ns stedi.jsii.alpha.spec\n  (:require [clojure.spec.alpha :as s]\n            [clojure.spec.gen.alpha :as sgen]\n            [stedi.jsii.alpha.assembly :as assm]\n            [stedi.jsii.alpha.fqn :as fqn]\n            [stedi.jsii.alpha.impl :as impl]))\n\n(s/def ::string-like\n  (s/or :string string?\n        :keyword keyword?))\n\n(s/def ::json\n  (s/or :string ::string-like\n        :int integer?\n        :float float?\n        :boolean boolean?\n        :vector (s/coll-of ::json :kind vector?)\n        :map (s/map-of ::string-like ::json)))\n\n(defn- metatype\n  [{:keys [datatype kind]}]\n  (cond\n    datatype :datatype\n    :else    (keyword kind)))\n\n(defmulti ^:private spec-form ffirst)\n\n(defmethod spec-form :union\n  [{:keys [union]}]\n  (let [{:keys [types]} union]\n    `(s/or ~@(mapcat (juxt (constantly :opt)\n                           spec-form)\n                     types))))\n\n(defmethod spec-form :fqn\n  [{:keys [fqn]}]\n  (fqn/fqn->qualified-keyword fqn))\n\n(defmethod spec-form :primitive\n  [{:keys [primitive]}]\n  (case primitive\n    \"string\"  `string?\n    \"any\"     `any?\n    \"boolean\" `boolean?\n    \"number\"  `number?\n    \"date\"    `inst?\n    \"json\"    ::json))\n\n(defmethod spec-form :collection\n  [{:keys [collection]}]\n  (let [{:keys [elementtype kind]} collection\n        element-form               (spec-form elementtype)]\n    (case kind\n      \"map\"   `(s/map-of ::string-like ~element-form)\n      \"array\" `(s/coll-of ~element-form :kind vector?))))\n\n(defn- prop-spec-k\n  [t prop]\n  (fqn/fqn->qualified-keyword (:fqn t) (:name prop)))\n\n(defn gen-class-instance\n  [fqn]\n  (sgen/return (impl/->JsiiObject fqn [] nil)))\n\n(defn- class-spec-definition\n  [{:keys [fqn]}]\n  `(s/def ~(fqn/fqn->qualified-keyword fqn)\n     (s/spec #(impl/class-instance? ~fqn %)\n             :gen (partial gen-class-instance ~fqn))))\n\n(defn gen-enum-member\n  [fqn]\n  (sgen/bind\n    (sgen/elements (impl/member-values fqn))\n    (fn [value]\n      (sgen/return\n        (impl/->JsiiEnumMember fqn value)))))\n\n(defn- enum-spec-definition\n  [{:keys [fqn]}]\n  `(s/def ~(fqn/fqn->qualified-keyword fqn)\n     (s/spec #(impl/enum-member? ~fqn %)\n             :gen (partial gen-enum-member ~fqn))))\n\n(defn gen-satisfies-interface\n  [fqn]\n  (sgen/return\n    ;; TODO: fqn for object-id is no longer a correct assumption\n    (impl/->JsiiObject fqn [fqn] nil)))\n\n(defn- interface-spec-definition\n  [{:keys [fqn]}]\n  `(s/def ~(fqn/fqn->qualified-keyword fqn)\n     (s/spec #(impl/satisfies-interface? ~fqn %)\n             :gen (partial gen-satisfies-interface ~fqn))))\n\n(defn- datatype-spec-definition\n  [{:keys [fqn] :as t}]\n  (let [properties (assm/properties fqn)\n        req-un     (into []\n                         (comp (remove :optional)\n                               (map (partial prop-spec-k t)))\n                         properties)\n        opt-un     (into []\n                         (comp (filter :optional)\n                               (map (partial prop-spec-k t)))\n                         properties)]\n    `(s/def ~(fqn/fqn->qualified-keyword fqn)\n       (s/and (s/keys :req-un ~req-un\n                      :opt-un ~opt-un)\n              #(every? ~(into #{}\n                              (comp (map name)\n                                    (map keyword))\n                              (concat req-un opt-un))\n                       (keys %))))))\n\n(defn- method-arity-form\n  [parameters]\n  `(s/cat ~@(mapcat (juxt (comp keyword :name)\n                          (fn [{:keys [optional variadic] :as param}]\n                            (let [form (spec-form (:type param))]\n                              (cond optional `(s/nilable ~form)\n                                    variadic `(s/* ~form)\n                                    :else    form))))\n                    parameters)))\n\n(defn- method-arg-spec-form\n  [{:keys [fqn]} {:keys [static parameters overrides]}]\n  (let [arities* (assm/arities\n                   (concat (when-not static\n                             (list {:name \"this\"\n                                    :type (if overrides\n                                            {:fqn overrides}\n                                            {:fqn fqn})}))\n                           parameters))]\n    (if (= 1 (count arities*))\n      (method-arity-form (first arities*))\n      `(s/alt\n         ~@(mapcat\n             (fn [arity-params]\n               [(keyword (str \"arity\" (count arity-params)))\n                (method-arity-form arity-params)])\n             arities*)))))\n\n(defn- method-spec-definition\n  [{:keys [fqn] :as t} {:keys [name returns] :as method}]\n  `(s/fdef ~(fqn/fqn->qualified-symbol fqn name)\n                :args ~(method-arg-spec-form t method)\n                :ret  ~(or (some-> returns (:type) (spec-form)) `nil?)))\n\n(defn- initializer-spec-definition\n  [{:keys [fqn] :as t} method]\n  `(s/fdef ~(fqn/fqn->qualified-symbol fqn \"impl\" \"-initializer\")\n     :args ~(method-arg-spec-form t (assoc method :static true))\n     :ret  ~(fqn/fqn->qualified-keyword fqn)))\n\n(defn- class-initializer-spec-definition\n  [{:keys [fqn name] :as t} method]\n  `(s/fdef ~(fqn/fqn->qualified-symbol fqn \"impl\" name)\n     :args ~(method-arg-spec-form t (assoc method :static true))\n     :ret  ~(fqn/fqn->qualified-keyword fqn)))\n\n(defn- prop-spec-definition\n  [t prop]\n  `(s/def ~(prop-spec-k t prop)\n     ~(spec-form (:type prop))))\n\n(defn spec-definitions\n  [t]\n  (try\n    (let [{:keys [initializer]} t\n\n          methods    (some-> t (:fqn) (assm/methods))\n          properties (some-> t (:fqn) (assm/properties))\n\n          type-definition\n          (case (metatype t)\n            :class     (class-spec-definition t)\n            :enum      (enum-spec-definition t)\n            :datatype  (datatype-spec-definition t)\n            :interface (interface-spec-definition t))\n\n          initializer-definition            (initializer-spec-definition t initializer)\n          class-initializer-spec-definition (class-initializer-spec-definition t initializer)]\n      (doall\n        (concat (list type-definition\n                      initializer-definition\n                      class-initializer-spec-definition)\n                (map (partial method-spec-definition t) methods)\n                (map (partial prop-spec-definition t) properties))))\n    (catch Throwable e\n      (throw (ex-info \"Unable to build spec definition\" {:t t} e)))))\n\n(defn- index-spec-forms\n  []\n  (into {}\n        (comp (mapcat spec-definitions)\n              (map (juxt second identity)))\n        (assm/all-types)))\n\n(defonce ^:private indexed-specs (index-spec-forms))\n\n(defn load-spec\n  [k]\n  (or (s/get-spec k)\n      (let [definition (or (get indexed-specs k)\n                           (throw (Exception. (str \"No spec for k \" k))))\n            deps       (->> (drop 2 definition)\n                            (tree-seq seqable? seq)\n                            (filter qualified-keyword?))]\n        ;; This is a little bit of a hack, it is possible for specs to\n        ;; have circular dependencies so we load the current spec with\n        ;; a placeholder before loading its dependencies.\n        (eval `(s/def ~k any?))\n        (dorun (map load-spec deps))\n        (eval definition)))\n  true)\n"
  },
  {
    "path": "src/stedi/jsii/alpha.clj",
    "content": "(ns stedi.jsii.alpha\n  \"A Clojure-based interface into jsii modules.\"\n  (:require [stedi.jsii.alpha.client :as client]\n            [stedi.jsii.alpha.impl :as impl]\n            [stedi.jsii.alpha.import :as import]))\n\n(defn get-class\n  \"Gets the jsii class for a given fqn.\"\n  [fqn]\n  (impl/get-class fqn))\n\n(defn jsii-primitive?\n  \"Returns true if x is a jsii primitive.\"\n  [x]\n  (boolean\n    (some #(instance? % x)\n          [stedi.jsii.alpha.impl.JsiiObject\n           stedi.jsii.alpha.impl.JsiiClass\n           stedi.jsii.alpha.impl.JsiiEnumClass\n           stedi.jsii.alpha.impl.JsiiEnumMember])))\n\n(defn fqn\n  \"Returns the fqn of a jsii primitive.\"\n  [x]\n  (.-fqn x))\n\n(defn describe\n  \"Describes a jsii type (class, enum or object).\"\n  [x]\n  (impl/get-type-info x))\n\n(defn import-fqn\n  \"Imports a jsii class or enum by fqn as alias-sym and refers the jsii\n  class or enum artifact as alias-sym.\"\n  [fqn alias-sym]\n  (import/import-fqn fqn alias-sym))\n\n(defn reset-runtime!\n  \"Resets the jsii runtime unloading any loaded modules.\"\n  []\n  (client/reset-runtime!))\n"
  },
  {
    "path": "test/stedi/cdk/alpha_test.clj",
    "content": "(ns stedi.cdk.alpha-test\n  \"Provides examples of interacting with CDK constructs and classes.\"\n  (:require [clojure.test :refer [deftest is testing]]\n            [stedi.cdk.alpha :as cdk]))\n\n(cdk/import [[App :as A, Stack] :from \"@aws-cdk/core\"]\n            [[Function Runtime] :from \"@aws-cdk/aws-lambda\"]\n            [[StringParameter] :from \"@aws-cdk/aws-ssm\"])\n\n(deftest cdk-example-test\n  (testing \"instantiating an object\"\n    (is (Stack nil \"my-stack\")))\n  (testing \"getting a property of an instance\"\n    (is (:region (Stack nil \"my-stack\"))))\n  (testing \"calling an instance method\"\n    (is (Stack/toString (Stack nil \"my-stack\"))))\n  (testing \"calling a static method\"\n    (is (Stack/isStack (Stack nil \"my-stack\"))))\n  (testing \"getting a static property of a class\"\n    (is (:JAVA_8 Runtime)))\n  (testing \"renaming an alias\"\n    (is (A/isApp (A))))\n  (testing \"calling a method on a returned interface\"\n    (let [s (Stack)]\n      (is (StringParameter/grantRead\n            (StringParameter/fromStringParameterName s \"param\" \"param-name\")\n            (Function/fromFunctionArn s \"fn\" \"function-arn\"))))))\n\n(defmacro with-url-spy\n  \"Evaluates `form` in the context of a redefintion of browse-url, capturing the\n  arguments and returning them.\"\n  [form]\n  `(let [spy# (atom [])]\n     (with-redefs [clojure.java.browse/browse-url\n                   (fn [url#] (swap! spy# conj url#))]\n       (do ~form\n           (deref spy#)))))\n\n(deftest browse-test\n  (testing \"opening documentation with no arguments\"\n    (is (= [\"https://docs.aws.amazon.com/cdk/api/latest\"]\n           (with-url-spy (cdk/browse)))))\n  (testing \"opening module documentation with full path\"\n    (is (= [\"https://docs.aws.amazon.com/cdk/api/latest/docs/core-readme.html\"]\n           (with-url-spy (cdk/browse \"@aws-cdk/core\")))))\n  (testing \"opening module documentation for `core`\"\n    (is (= [\"https://docs.aws.amazon.com/cdk/api/latest/docs/core-readme.html\"]\n           (with-url-spy (cdk/browse \"core\")))))\n  (testing \"opening fully qualified documentation for a class\"\n    (is (= [\"https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Stack.html\"]\n           (with-url-spy (cdk/browse \"@aws-cdk/core.Stack\")))))\n  (testing \"opening documentation for a class\"\n    (is (= [\"https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Stack.html\"]\n           (with-url-spy (cdk/browse Stack)))))\n  (testing \"opening documentation for an instance\"\n    (is (= [\"https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Stack.html\"]\n           (with-url-spy (cdk/browse (Stack)))))))\n"
  },
  {
    "path": "test/stedi/cdk/examples_test.clj",
    "content": "(ns stedi.cdk.examples-test\n  (:require [clojure.java.io :as io]\n            [clojure.java.shell :as sh]\n            [clojure.string :as string]\n            [clojure.test :refer [deftest testing is]]))\n\n(def cdk-bin-path \"node_modules/aws-cdk/bin/cdk\")\n\n(defn example-projects\n  []\n  (->> (file-seq (io/file \"examples\"))\n     (map #(.split (str %) \"/\"))\n     (filter #(= 2 (count %)))\n     (map second)))\n\n(defn synth\n  [project]\n  (let [{:keys [exit out err]}\n        (sh/with-sh-dir (format \"examples/%s\" project)\n          (sh/sh (str \"../../\" cdk-bin-path) \"synth\"))]\n    (when-not (= 0 exit)\n      (println (format \"===== [%s] failed to synth! =====\" project))\n      (when-not (string/blank? out)\n        (println)\n        (println \"Out:\")\n        (println)\n        (println out))\n      (when-not (string/blank? err)\n        (println)\n        (println \"Err:\")\n        (println)\n        (println err))\n      (throw (Exception. (str \"An error occured running cdk synth. \"\n                              \"Check logs for more info.\"))))\n    true))\n\n(deftest ^:integration synth-examples-test\n  (assert (.exists (io/file cdk-bin-path)) \"Could not find cdk executable. Did you run `npm install`?\")\n  (doseq [project (example-projects)]\n    (testing (str \"cdk synth \" project)\n      (is (synth project)))))\n"
  },
  {
    "path": "test/stedi/jsii/alpha_test.clj",
    "content": "(ns stedi.jsii.alpha-test\n  (:require [clojure.spec.alpha :as s]\n            [clojure.test :as t :refer [deftest testing is]]\n            [stedi.jsii.alpha :as jsii]))\n\n(jsii/import-fqn \"@aws-cdk/core.App\" 'App)\n(jsii/import-fqn \"@aws-cdk/core.Reference\" 'Reference)\n(jsii/import-fqn \"@aws-cdk/core.Stack\" 'Stack)\n(jsii/import-fqn \"@aws-cdk/core.TagType\" 'TagType)\n(jsii/import-fqn \"@aws-cdk/aws-s3.Bucket\" 'Bucket)\n\n(deftest jsii-class-test\n  (let [C (jsii/get-class \"@aws-cdk/core.Stack\")]\n    (is (instance? stedi.jsii.alpha.impl.JsiiClass C))\n\n    (testing \"invoking a class invokes the constructor\"\n      (let [stack (C)]\n        (is (instance? stedi.jsii.alpha.impl.JsiiObject stack))))\n\n    (testing \"classes extend ILookup for static property access\"\n      (is (:ACCOUNT_ID (jsii/get-class \"@aws-cdk/core.Aws\"))))))\n\n(deftest jsii-object-test\n  (let [C (jsii/get-class \"@aws-cdk/core.Stack\")\n        stack (C nil \"my-stack\")]\n    (testing \"objects extend ILookup for property access\"\n      (is (= \"my-stack\" (:stackName stack))))\n\n    (testing \"toString\"\n      (is (.contains (str (Reference \"hello\" (Stack))) \"TOKEN\")))))\n\n(deftest import-fqn-test\n  (testing \"refers a jsii primitive into the current namespace\"\n    (is (jsii/jsii-primitive? App)))\n\n  (testing \"creates a namespace for the specified jsii class\"\n    (is (find-ns 'aws-cdk.core.App)))\n\n  (testing \"aliases created namespace to the specified symbol\"\n    (is (= (find-ns 'aws-cdk.core.App)\n           (-> (ns-aliases (find-ns 'stedi.jsii.alpha-test))\n               (get 'App))))))\n\n(deftest importing-a-class-test\n  (testing \"refers a jsii class into the current namespace\"\n    (is (instance? stedi.jsii.alpha.impl.JsiiClass App)))\n\n  (testing \"interns class functions into created namespace\"\n    (let [interned-symbols\n          (->> (find-ns 'aws-cdk.core.App)\n               (ns-map)\n               (map second)\n               (filter var?)\n               (map symbol)\n               (set))]\n      (is (= '#{aws-cdk.core.App/synth\n                aws-cdk.core.App/isApp\n                aws-cdk.core.App/isConstruct\n                aws-cdk.core.App/toString}\n             interned-symbols))))\n\n  (testing \"interned functions are specced\"\n    (s/get-spec 'aws-cdk.core.App/synth))\n\n  (testing \"interned functions are instrumented\"\n    (is (.contains (str aws-cdk.core.App/synth)\n                   \"spec_checking_fn\")))\n\n  (testing \"map specs are closed\"\n    (let [ex (is (thrown? Exception (Bucket (Stack) \"bucket\" {:does-not-exist \"foo\"})))]\n      (is (:clojure.spec.alpha/problems (ex-data ex)))))\n\n  (testing \"interned static functions have the correct arglists\"\n    (is (= '([x])\n           (-> (resolve 'aws-cdk.core.Stack/isStack)\n               (meta)\n               (:arglists)))))\n\n  (testing \"interned instance functions have the correct arglists\"\n    (is (= '([this target] [this target reason])\n           (-> (resolve 'aws-cdk.core.Stack/addDependency)\n               (meta)\n               (:arglists))))))\n\n(deftest importing-an-enum-test\n  (testing \"refers a jsii enum into the current namespace\"\n    (is (instance? stedi.jsii.alpha.impl.JsiiEnumClass TagType)))\n\n  (testing \"interns enum members into created namespace\"\n    (let [interned-symbols\n          (->> (find-ns 'aws-cdk.core.TagType)\n               (ns-map)\n               (map second)\n               (filter var?)\n               (map symbol)\n               (set))]\n      (is (= '#{aws-cdk.core.TagType/STANDARD\n                aws-cdk.core.TagType/AUTOSCALING_GROUP\n                aws-cdk.core.TagType/MAP\n                aws-cdk.core.TagType/NOT_TAGGABLE\n                aws-cdk.core.TagType/KEY_VALUE}\n             interned-symbols))))\n\n  (testing \"interned members are enum members\"\n    (is (instance? stedi.jsii.alpha.impl.JsiiEnumMember TagType/STANDARD))))\n\n(comment\n  (t/run-tests)\n\n )\n"
  }
]