Skip to content

Commit

Permalink
Rename daml2ts to daml2js (digital-asset#5394)
Browse files Browse the repository at this point in the history
This is pretty much a search and replace over the whole repo, including
file names.

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
hurryabit authored Apr 3, 2020
1 parent 446892a commit 31c78d5
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 118 deletions.
10 changes: 5 additions & 5 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ alias(
)

alias(
name = "daml2ts",
actual = "//language-support/ts/codegen:daml2ts",
name = "daml2js",
actual = "//language-support/ts/codegen:daml2js",
)

alias(
name = "daml2ts@ghci",
actual = "//language-support/ts/codegen:daml2ts@ghci",
name = "daml2js@ghci",
actual = "//language-support/ts/codegen:daml2js@ghci",
)

alias(
Expand Down Expand Up @@ -282,6 +282,6 @@ da_haskell_repl(
"//daml-assistant/integration-tests",
"//language-support/hs/bindings:hs-ledger",
"//language-support/hs/bindings:test",
"//language-support/ts/codegen:daml2ts",
"//language-support/ts/codegen:daml2js",
],
)
2 changes: 1 addition & 1 deletion daml-assistant/daml-helper/src/DA/Daml/Helper/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ runCommand = \case
Codegen {..} ->
case lang of
TypeScript ->
runDaml2ts remainingArguments
runDaml2js remainingArguments
Java ->
runJar
"daml-sdk/daml-sdk.jar"
Expand Down
12 changes: 6 additions & 6 deletions daml-assistant/daml-helper/src/DA/Daml/Helper/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module DA.Daml.Helper.Run
, runInit
, runNew
, runJar
, runDaml2ts
, runDaml2js
, runListTemplates
, runStart

Expand Down Expand Up @@ -325,11 +325,11 @@ runJar jarPath mbLogbackPath remainingArgs = do
mbLogbackArg <- traverse getLogbackArg mbLogbackPath
withJar jarPath (toList mbLogbackArg) remainingArgs (const $ pure ())

runDaml2ts :: [String] -> IO ()
runDaml2ts remainingArgs = do
daml2ts <- fmap (</> "daml2ts" </> "daml2ts") getSdkPath
withProcessWait_' (proc daml2ts remainingArgs) (const $ pure ()) `catchIO`
(\e -> hPutStrLn stderr "Failed to invoke daml2ts." *> throwIO e)
runDaml2js :: [String] -> IO ()
runDaml2js remainingArgs = do
daml2js <- fmap (</> "daml2js" </> "daml2js") getSdkPath
withProcessWait_' (proc daml2js remainingArgs) (const $ pure ()) `catchIO`
(\e -> hPutStrLn stderr "Failed to invoke daml2js." *> throwIO e)

getLogbackArg :: FilePath -> IO String
getLogbackArg relPath = do
Expand Down
2 changes: 1 addition & 1 deletion daml-assistant/integration-tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ da_haskell_test(
"//:sdk-version-hs-lib",
"//compiler/damlc/daml-opts:daml-opts-types",
"//daml-assistant/daml-helper:daml-helper-lib",
"//language-support/ts/codegen/tests:daml2ts-test-helpers",
"//language-support/ts/codegen/tests:daml2js-test-helpers",
"//libs-haskell/bazel-runfiles",
"//libs-haskell/da-hs-base",
"//libs-haskell/test-utils",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import DA.Directory
import DA.Bazel.Runfiles
import DA.Daml.Assistant.FreePort (getFreePort,socketHints)
import DA.Daml.Helper.Run (waitForHttpServer,waitForConnectionOnPort)
import DA.Test.Daml2TsUtils (writeRootPackageJson)
import DA.Test.Daml2jsUtils (writeRootPackageJson)
import DA.Test.Process (callCommandSilent,callProcessSilent)
import DA.Test.Util
import SdkVersion
Expand Down Expand Up @@ -524,7 +524,7 @@ codegenTests codegenDir damlTypes = testGroup "daml codegen" (
, codegenTestFor "scala" (Just "com.cookiemonster.nomnomnom")
] ++
-- The 'daml-types' NPM package is not available on Windows which
-- is required by 'daml2ts'.
-- is required by 'daml2js'.
[ codegenTestFor "ts" Nothing | not isWindows ]
)
where
Expand Down
2 changes: 1 addition & 1 deletion docs/configs/pdf/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Experimental features
triggers/index
daml-repl/index
tools/visual
daml2ts/index
daml2js/index
getting-started/index
getting-started/testing

Expand Down
2 changes: 1 addition & 1 deletion docs/source/app-dev/app-arch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ JSON <json-api>` endpoints. In addition, we provide support libraries for :ref:`

.. TODO (drsk) add and point to javascript bindings.
.. If you choose a different Javascript based frontend framework, the packages ``@daml/ledger``,
.. ``@daml/types`` and the generated ``@daml2ts`` package provide you with the necessary interface code
.. ``@daml/types`` and the generated ``@daml2js`` package provide you with the necessary interface code
.. to connect and issue commands against your ledger.
We provide two libraries to build your React frontend for a DAML application.
Expand Down
20 changes: 10 additions & 10 deletions docs/source/daml2ts/index.rst → docs/source/daml2js/index.rst
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
.. Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
.. SPDX-License-Identifier: Apache-2.0
``daml2ts`` - TypeScript code generator for DAML
``daml2js`` - TypeScript code generator for DAML
################################################

daml2ts : TypeScript of DAML
daml2js : TypeScript of DAML
============================

Introduction
------------

``daml2ts`` generates TypeScript for interacting with DAML via the `json-api <../json-api/index.html>`_ .
``daml2js`` generates TypeScript for interacting with DAML via the `json-api <../json-api/index.html>`_ .

``daml2ts`` inputs are compiled DAML modules. ``daml2ts`` outputs are TypeScript source files containing definitions modeling the DAML entities found.
``daml2js`` inputs are compiled DAML modules. ``daml2js`` outputs are TypeScript source files containing definitions modeling the DAML entities found.

The code ``daml2ts`` generates uses the library `@daml/types <https://github.com/digital-asset/daml/tree/master/language-support/ts/daml-types>`_.
The code ``daml2js`` generates uses the library `@daml/types <https://github.com/digital-asset/daml/tree/master/language-support/ts/daml-types>`_.

Usage
-----

``daml2ts`` is invoked via the DAML SDK assistant.
``daml2js`` is invoked via the DAML SDK assistant.

In outline, the command to generate JavaScript and TypeScript typings from DAML is ``daml codegen ts DAR -o OUTDIR`` where ``DAR`` is the path to a DAR file (generated via ``daml build``) and ``OUTDIR`` is a directory where you want the JavaScript to be written.

Expand All @@ -31,11 +31,11 @@ Here's a complete example that generates TypeScript from a project produced from
daml new my-proj skeleton # Create a new project based off the skeleton template
cd my-proj # Enter the newly created project directory
daml build # Compile the project's DAML files into a DAR
daml codegen ts .daml/dist/my-proj-0.0.1.dar -o daml2ts # Generate script bindings from the DAR
daml codegen ts .daml/dist/my-proj-0.0.1.dar -o daml2js # Generate script bindings from the DAR
- On execution of these commands:

- The directory ``my-proj/daml2ts`` contains generated TypeScript and Javascript artifacts;
- The directory ``my-proj/daml2js`` contains generated TypeScript and Javascript artifacts;
- The files are arranged into directories;
- One of those directories will be named as my-proj-0.0.1 and will contain the definitions corresponding to the DAML files in the project;
- For example, ``generated/ts/my-proj/src/Main.ts`` contains the definitions for ``daml/Main.daml``;
Expand All @@ -47,7 +47,7 @@ To get a quickstart idea of how to use what has been generated, you may wish to
Primitive DAML types: @daml/types
---------------------------------

To understand the TypeScript code generated by ``daml2ts``, it is helpful to keep in mind this quick review of the TypeScript equivalents of the primitive DAML types provided by @daml/types.
To understand the TypeScript code generated by ``daml2js``, it is helpful to keep in mind this quick review of the TypeScript equivalents of the primitive DAML types provided by @daml/types.

**Interfaces**:

Expand Down Expand Up @@ -233,7 +233,7 @@ Here is a DAML template of a basic 'IOU' contract.
do
create this with owner = newOwner
``daml2ts`` generates types for each of the choices defined on the template as well as the template itself.
``daml2js`` generates types for each of the choices defined on the template as well as the template itself.

.. code-block:: typescript
:linenos:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ DAML SDK documentation
DAML Triggers <triggers/index>
DAML Repl <daml-repl/index>
tools/visual
daml2ts/index
daml2js/index
getting-started/index
getting-started/testing

Expand Down
6 changes: 3 additions & 3 deletions language-support/ts/codegen/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load("//bazel_tools:haskell.bzl", "da_haskell_binary")
load("//bazel_tools/packaging:packaging.bzl", "package_app")

da_haskell_binary(
name = "daml2ts",
name = "daml2js",
srcs = glob(["src/**/*.hs"]),
hackage_deps = [
"aeson",
Expand Down Expand Up @@ -37,7 +37,7 @@ da_haskell_binary(
)

package_app(
name = "daml2ts-dist",
binary = ":daml2ts",
name = "daml2js-dist",
binary = ":daml2js",
visibility = ["//visibility:public"],
)
32 changes: 16 additions & 16 deletions language-support/ts/codegen/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# daml2ts
# daml2js

This is a code generator for a TypeScript interface to a DAML package. To run it, you must execute
```console
$ bazel run //:daml2ts
Usage: daml2ts DAR-FILE -o DIR
$ bazel run //:daml2js
Usage: daml2js DAR-FILE -o DIR
Generate TypeScript bindings from a DAR
```
somewhere in this repository. The `DAR-FILE` is the DAR for which you want to
generate the TypeScript interface. `daml2ts` will generate interfaces for
generate the TypeScript interface. `daml2js` will generate interfaces for
all DALFs in that DAR. The output will be written into the directory `DIR`
you specify via the `-o` option.

Currently, the generated interfaces are tailored towards the
[`ledger.ts`](https://github.com/digital-asset/davl/blob/master/ui/src/ledger/ledger.ts)
module of DAVL.

## How to develop daml2ts
## How to develop daml2js

The full test suite is started via
```
Expand All @@ -27,11 +27,11 @@ development. To make things more responsive, you can run the following
trinity of shell scripts, all in parallel and each in its own terminal:
- `./tests/watch-damlc.sh`: Build a DAR out of the `.daml` files in
`./tests/daml` whenever they change.
- `./tests/watch-daml2ts.sh`: Re-interpret `daml2ts` and run it on the DAR
- `./tests/watch-daml2js.sh`: Re-interpret `daml2js` and run it on the DAR
produced by `./tests/watch-damlc.sh`.
- `./tests/watch-yarn`: Build all the TypeScript libraries in dependency
order and run the TypeScript compiler in watch mode on the TypeScript
generated by `./tests/watch-daml2ts.sh`. This script does not recompile
generated by `./tests/watch-daml2js.sh`. This script does not recompile
any changes made to the TypeScript libraries `@daml/types` or
`@daml/ledger`. Changes to these libraries must be manually
recompiled using `yarn build` in the respective directories. (You can also
Expand All @@ -40,10 +40,10 @@ trinity of shell scripts, all in parallel and each in its own terminal:
All these steps only check that everything compiles. They do _not_ run any
tests. To run the tests suite, you need to issue the command above.

### How to run daml2ts on a set of DARs from bazel
### How to run daml2js on a set of DARs from bazel

Running the code-generator outside of the SDK means having to take
into account the dependency of daml2ts generated packages on a version
into account the dependency of daml2js generated packages on a version
of `daml-types` that is not available on NPM. The folllowing recipe
shows how it's done (obviously you'll need to adapt paths in the below
to your own environment).
Expand All @@ -53,7 +53,7 @@ cd ~/tmp/davl
cat > package.json<<EOF
{
"private": true,
"workspaces": ["daml2ts"],
"workspaces": ["daml2js"],
"resolutions": {
"@daml/types": "file:daml-types"
}
Expand All @@ -62,12 +62,12 @@ EOF
cd ~/project/daml.git
bazel build //language-support/ts/daml-types:npm_package
cp -R bazel-bin/language-support/ts/daml-types/npm_package ~/tmp/davl/daml-types
bazel run //language-support/ts/codegen:daml2ts -- -o ~/tmp/davl/daml2ts ~/project/davl.git/released/*.dar
bazel run //language-support/ts/codegen:daml2js -- -o ~/tmp/davl/daml2js ~/project/davl.git/released/*.dar
```

## What `daml2ts` generates
## What `daml2js` generates

The DAML SDK documentation contains [a page](https://github.com/digital-asset/daml/tree/master/docs/source/daml2ts) on `daml2ts`. It is recommended that you start with this. The remainder of this section contains additional detail (mostly about serialization code). The code that `daml2ts` generates uses the [@daml/types](https://github.com/digital-asset/daml/tree/master/language-support/ts/daml-types) and [@mojotech/json-type-validation](https://github.com/mojotech/json-type-validation) libraries. All TypeScript modules generated by `daml2ts` begin with the following fragment:
The DAML SDK documentation contains [a page](https://github.com/digital-asset/daml/tree/master/docs/source/daml2js) on `daml2js`. It is recommended that you start with this. The remainder of this section contains additional detail (mostly about serialization code). The code that `daml2js` generates uses the [@daml/types](https://github.com/digital-asset/daml/tree/master/language-support/ts/daml-types) and [@mojotech/json-type-validation](https://github.com/mojotech/json-type-validation) libraries. All TypeScript modules generated by `daml2js` begin with the following fragment:
```typescript
import * as jtv from '@mojotech/json-type-validation';
import * as daml from '@daml/types';
Expand All @@ -78,7 +78,7 @@ import * as daml from '@daml/types';

#### Types

See the [SDK docs](https://github.com/digital-asset/daml/tree/master/docs/source/daml2ts).
See the [SDK docs](https://github.com/digital-asset/daml/tree/master/docs/source/daml2js).

#### Interfaces

Expand Down Expand Up @@ -220,7 +220,7 @@ A DAML enumeration.
data Color = Red | Blue | Yellow
```

In TypeScript, `daml2ts` produces this.
In TypeScript, `daml2js` produces this.

```typescript
export enum Color {
Expand Down Expand Up @@ -315,7 +315,7 @@ export namespace Iou {
daml.registerTemplate(Iou);
```

`daml2ts` has produced:
`daml2js` has produced:
- Type definitions corresponding to the `Transfer` choice and the `Iou` template;
- Companion objects for those types;
- An `Iou` template associated type definition `Key` in the `Iou` namespace;
Expand Down
18 changes: 9 additions & 9 deletions language-support/ts/codegen/src/TsCodeGenMain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ main = do
Nothing -> id
Just pkgName -> unPackageName pkgName <> " (hash: " <> id <> ")"
T.putStrLn $ "Generating " <> pkgDesc
daml2ts Daml2TsParams{..}
daml2js Daml2jsParams{..}
buildPackages sdkVersion optScope optOutputDir dependencies

packageNameText :: PackageId -> Maybe PackageName -> T.Text
Expand All @@ -155,7 +155,7 @@ packageNameText pkgId mbPkgIdent = maybe (unPackageId pkgId) unPackageName mbPkg
newtype Scope = Scope {unScope :: T.Text}
newtype Dependency = Dependency {unDependency :: T.Text} deriving (Eq, Ord)

data Daml2TsParams = Daml2TsParams
data Daml2jsParams = Daml2jsParams
{ opts :: Options -- cli args
, pkgMap :: Map.Map PackageId (Maybe PackageName, Package)
, pkgId :: PackageId
Expand All @@ -165,15 +165,15 @@ data Daml2TsParams = Daml2TsParams
}

-- Write the files for a single package.
daml2ts :: Daml2TsParams -> IO (T.Text, [Dependency])
daml2ts Daml2TsParams {..} = do
daml2js :: Daml2jsParams -> IO (T.Text, [Dependency])
daml2js Daml2jsParams {..} = do
let Options {..} = opts
scopeDir = optOutputDir
-- The directory into which we generate packages e.g. '/path/to/daml2ts'.
-- The directory into which we generate packages e.g. '/path/to/daml2js'.
packageDir = scopeDir </> T.unpack pkgName
-- The directory into which we write this package e.g. '/path/to/daml2ts/davl-0.0.4'.
-- The directory into which we write this package e.g. '/path/to/daml2js/davl-0.0.4'.
packageSrcDir = packageDir </> "src"
-- Where the source files of this package are written e.g. '/path/to/daml2ts/davl-0.0.4/src'.
-- Where the source files of this package are written e.g. '/path/to/daml2js/davl-0.0.4/src'.
scope = optScope
-- The scope e.g. '@daml.js'.
-- We use this, for example, when generating import declarations e.g.
Expand Down Expand Up @@ -564,7 +564,7 @@ writePackageJson packageDir sdkVersion (Scope scope) depends =
, "version" .= versionToText sdkVersion
, "main" .= ("lib/index.js" :: T.Text)
, "types" .= ("lib/index.d.ts" :: T.Text)
, "description" .= ("Generated by daml2ts" :: T.Text)
, "description" .= ("Generated by daml2js" :: T.Text)
, "dependencies" .= object
[ pkg .= path
| Dependency pkgName <- depends
Expand All @@ -590,7 +590,7 @@ buildPackages sdkVersion optScope optOutputDir dependencies = do
where
packageJson :: Value
packageJson = object
[ "name" .= ("daml2ts" :: T.Text)
[ "name" .= ("daml2js" :: T.Text)
, "version" .= version
, "dependencies" .= object
[ "@mojotech/json-type-validation" .= jtvVersion
Expand Down
Loading

0 comments on commit 31c78d5

Please sign in to comment.