A mono-repo for a session type API code generation toolchain for modern web programming.
This project was originally built for Anson Miu's undergraduate Master's thesis at Imperial College London.
It was forked and extended for Neil Sayers' Master's thesis at Imperial College London.
nuscr
contains 𝝼Scr, for handling multiparty protocol descriptions, a dependency of our toolchain.codegen
contains the source code of our code generator, written in Python, which generates TypeScript code for implementing the provided multiparty protocol.protocols
contains various Scribble protocol descriptions, including those used in the case studies.case-studies
contains 5 case studies of implementing interactive web applications with our toolchain, namely Noughts and Crosses, Travel Agency, Battleships, Online Wallet, Codenames.web-sandbox
contains configuration files for the web development, e.g. TypeScript configurations and NPMpackage.json
files.
Refer to the helptext for detailed information:
$ python -m codegen --help
We illustrate how to use our toolchain to generate TypeScript APIs:
The following command reads as follows:
$ python -m codegen protocols/TravelAgency.scr TravelAgency S \
node -o case-studies/TravelAgency/src
-
Generate APIs for role
S
of theTravelAgency
protocol specified inprotocols/TravelAgency.scr
; -
Role
S
is implemented as anode
(server-side) endpoint; -
Output the generated APIs under the path
case-studies/TravelAgency/src
The following command reads as follows:
$ python -m codegen protocols/TravelAgency.scr TravelAgency A \
browser -s S -o case-studies/TravelAgency/client/src
-
Generate APIs for role
A
of theTravelAgency
protocol specified inprotocols/TravelAgency.scr
; -
Role
A
is implemented as abrowser
endpoint, and assume roleS
to be the server; -
Output the generated APIs under the path
case-studies/TravelAgency/client/src
To run the end-to-end tests:
$ cd web-sandbox/node
$ npm i
$ cd ../browser
$ npm i
$ cd ../..
$ python -m codegen.tests.system
The end-to-end tests verify that
- The toolchain correctly parses the Scribble protocol specification files, and,
- The toolchain correctly generates TypeScript APIs, and,
- The generated APIs can be type-checked by the TypeScript Compiler successfully.
The protocol specification files, describing the multiparty communication, are located in the protocols
folder.
The generated APIs are saved under web-sandbox
(which is a sandbox environment set up for the TypeScript Compiler) and are deleted when the test finishes.
We include five case studies of realistic web applications implemented using the generated APIs.
For example, to generate the APIs for the case study OnlineWallet
:
$ cd case-studies/OnlineWallet
$ npm i
$ cd client
$ npm i
$ cd ..
$ npm run build
$ npm start
and visit http://localhost:8080
.
Consult the wiki for more documentation.