Commit Graph

2 Commits

Author SHA1 Message Date
Martin Huschenbett
712231c963 daml2ts: Don't produce unused imports (#3689)
Instead of importing _all_ other modules referenced from a module, only
import those that are actually referenced from the generated code. First,
this produces less noise within each generated file. Second and probably
more important, this allows for not generating files without any actual
definition at all.

https://github.com/digital-asset/davl/pull/81 demonstrates the effect of
this change on DAVL.
2019-12-01 11:38:56 +00:00
Martin Huschenbett
c33517cf9f MVP for a daml2ts codegen (#3441)
* MVP for a daml2ts codegen

This PR adds an MVP for a codegen for TypeScript.

Given a DAR, daml2ts replicates the structure of the serializable type
definitions in it as TypeScript type definitions following our JSON
representation of DAML-LF types. It also adds decoders for all these types,
which can be used to check where an arbitray JSON value has the given type.
Finally, daml2ts also produces one JavaScript object for each template, which
reflects the type information of that template.

All produces objects implement some interfaces defined in a TypeScript
library currently called `@digitalasset/daml-json-types`. This libary is not
yet uploaded to NPM but rather included in the `tests/ts/daml-json-types`
directory. This libary also contains the JSON decoders for all of DAML-LF's
builtin types.

There are quite a few limitations right now. Most notably, variant and enum
types are not properly typed right now but rather gradually "typed" as
`unknown`. We also don't support nested `Optional`s, the `Numeric` type or
sum-of-product types in DAML. These issues are tracked in #3518.

There is currently one test. It takes a very simple DAML model, generates
the TypeScript for it and checks that it compiles and contains no linter
warnings/errors. Proper integration tests against the JSON API will follow.

* Address @cocreature's comments

* Make test work on Windows
2019-11-19 15:51:17 +00:00