2018-11-05 14:29:27 +00:00
|
|
|
# Syndicate/js
|
|
|
|
|
2021-12-02 13:42:23 +00:00
|
|
|
A fourth-generation implementation of Dataspaces and Syndicate for
|
2021-04-26 13:13:30 +00:00
|
|
|
TypeScript and JavaScript, in both node.js and the browser. The
|
|
|
|
implementation techniques herein are the subject of a forthcoming
|
|
|
|
paper.
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-05-12 13:24:01 +00:00
|
|
|
## Branches
|
|
|
|
|
|
|
|
The `main` branch is where active development happens:
|
|
|
|
|
|
|
|
git clone -b main https://git.syndicate-lang.org/syndicate-lang/syndicate-js
|
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
## Building
|
2018-11-05 21:37:43 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
This project uses [`yarn`](https://yarnpkg.com/), not `npm`.
|
2018-11-13 15:36:50 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
The repository is a monorepo, using
|
|
|
|
[yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/).
|
|
|
|
[Lerna](https://lerna.js.org/) is used as a thin
|
|
|
|
[veneer atop yarn workspaces](https://medium.com/@jsilvax/a-workflow-guide-for-lerna-with-yarn-workspaces-60f97481149d),
|
|
|
|
providing convenient automation for package version management and
|
|
|
|
publication.
|
2018-11-13 15:35:16 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
After a checkout, run:
|
2018-11-13 15:35:16 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
```shell
|
|
|
|
make bootstrap
|
|
|
|
```
|
2018-11-13 15:36:50 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
Alternatively, running:
|
2018-11-05 21:37:43 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
```shell
|
|
|
|
yarn install
|
|
|
|
./node_modules/.bin/lerna exec yarn prepare
|
|
|
|
```
|
2018-11-05 21:37:43 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
will download and install all dependencies and then build all the
|
|
|
|
packages.
|
2018-11-05 21:37:43 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
## Licence
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-12-02 13:42:23 +00:00
|
|
|
@syndicate-lang, an implementation of Syndicate for TypeScript and JavaScript.
|
2021-04-26 13:13:30 +00:00
|
|
|
Copyright (C) 2016-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-11-05 14:29:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- ## Quickstart -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- ### Option 1. Create a new program/library using Syndicate/js. -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- Use `npx @syndicate-lang/create DIRECTORY` or `npm init -->
|
|
|
|
<!-- @syndicate-lang DIRECTORY`: -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- npm init @syndicate-lang myprogram -->
|
|
|
|
<!-- cd myprogram -->
|
|
|
|
<!-- npm i . -->
|
|
|
|
<!-- npm run build -->
|
|
|
|
<!-- node lib/index.js -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- ### Option 2. Add Syndicate/js to an existing program/library. -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- Install a few packages from the -->
|
|
|
|
<!-- [@syndicate-lang](https://www.npmjs.com/org/syndicate-lang) scope on -->
|
|
|
|
<!-- npmjs.com: -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- npm i --save-dev @syndicate-lang/syntax @babel/preset-env -->
|
|
|
|
<!-- npm i --save @syndicate-lang/core -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- Then, add the `@syndicate-lang/syntax/plugin` to your `.babelrc`. Use -->
|
|
|
|
<!-- `npx syndicate-babel` in place of `npx babel` to compile your code. -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- ## Creating a new Syndicate/js project -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- Create a skeletal `package.json`: -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- { -->
|
|
|
|
<!-- "main": "lib/index.js", -->
|
|
|
|
<!-- "scripts": { -->
|
|
|
|
<!-- "build": "npx syndicate-babel src --out-dir lib", -->
|
|
|
|
<!-- "clean": "rm -rf lib" -->
|
|
|
|
<!-- } -->
|
|
|
|
<!-- } -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- The entry point will be `lib/index.js`; the corresponding *source* -->
|
|
|
|
<!-- file will be `src/index.js`. -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- Two `npm run` scripts are defined: one which compiles Syndicate/js -->
|
|
|
|
<!-- source files in `src` to plain JavaScript in `lib`. The compiler uses -->
|
|
|
|
<!-- Babel; we will configure Babel next. -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- Create a `.babelrc` file: -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- { -->
|
|
|
|
<!-- "presets": [ "@babel/preset-env" ], -->
|
|
|
|
<!-- "plugins": [ "@syndicate-lang/syntax/plugin" ] -->
|
|
|
|
<!-- } -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- Now, install the necessary dependencies. Babel and the Syndicate/js -->
|
|
|
|
<!-- extensions are needed at build-time: -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- npm i --save-dev @syndicate-lang/syntax @babel/preset-env -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- The Syndicate/js runtime and as many drivers as you would like to use -->
|
|
|
|
<!-- are needed at run-time: -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- npm i --save @syndicate-lang/core -->
|
|
|
|
<!-- npm i --save @syndicate-lang/driver-timer -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- Finally, create the main program file. Create a directory `src`, and -->
|
|
|
|
<!-- then a file `src/index.js`: -->
|
|
|
|
|
|
|
|
<!-- ```javascript -->
|
2023-02-06 15:08:12 +00:00
|
|
|
<!-- const { LaterThan } = activate require("@syndicate-lang/driver-timer"); -->
|
2021-04-26 13:13:30 +00:00
|
|
|
|
|
|
|
<!-- spawn named 'ticker' { -->
|
|
|
|
<!-- field this.counter = 0; -->
|
2023-02-06 15:08:12 +00:00
|
|
|
<!-- field this.deadline = +(new Date()) / 1000.0; -->
|
2021-04-26 13:13:30 +00:00
|
|
|
|
|
|
|
<!-- on start { console.log('ticker starting'); } -->
|
|
|
|
<!-- on stop { console.log('ticker stopping'); } -->
|
|
|
|
|
2023-02-06 15:08:12 +00:00
|
|
|
<!-- on asserted LaterThan(this.deadline) { -->
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- this.counter++; -->
|
|
|
|
<!-- console.log('tick', new Date(), this.counter); -->
|
2023-02-06 15:08:12 +00:00
|
|
|
<!-- this.deadline += 1; -->
|
2021-04-26 13:13:30 +00:00
|
|
|
<!-- } -->
|
|
|
|
|
|
|
|
<!-- stop on (this.counter == 5); -->
|
|
|
|
<!-- } -->
|
|
|
|
<!-- ``` -->
|
|
|
|
|
|
|
|
<!-- Now, compile the project: -->
|
|
|
|
|
|
|
|
<!-- npm run build -->
|
|
|
|
|
|
|
|
<!-- Finally, run the program: -->
|
|
|
|
|
|
|
|
<!-- node lib/index.js -->
|
|
|
|
|
|
|
|
<!-- The output should be something like: -->
|
|
|
|
|
|
|
|
<!-- ticker starting -->
|
|
|
|
<!-- tick 2018-11-05T14:23:27.713Z 1 -->
|
|
|
|
<!-- tick 2018-11-05T14:23:28.705Z 2 -->
|
|
|
|
<!-- tick 2018-11-05T14:23:29.706Z 3 -->
|
|
|
|
<!-- tick 2018-11-05T14:23:30.706Z 4 -->
|
|
|
|
<!-- tick 2018-11-05T14:23:31.707Z 5 -->
|
|
|
|
<!-- ticker stopping -->
|
2018-11-05 14:29:27 +00:00
|
|
|
|
2023-11-17 13:12:14 +00:00
|
|
|
## Older versions
|
|
|
|
|
|
|
|
An earlier TypeScript+JavaScript implementation from early 2021 (the
|
|
|
|
primary difference to `main` being a lack of object-capability
|
|
|
|
support) can be found on the `typescript1` branch:
|
|
|
|
|
|
|
|
git clone -b typescript1 https://git.syndicate-lang.org/syndicate-lang/syndicate-js
|
|
|
|
|
|
|
|
Finally, the `babel-based` branch is from 2018, and is an
|
|
|
|
implementation for JavaScript only. It extends babel with new syntax
|
|
|
|
and new plugins (rather than implementing its own error-tolerant
|
|
|
|
parser, like `typescript1` and `main`):
|
|
|
|
|
|
|
|
git clone -b babel-based https://git.syndicate-lang.org/syndicate-lang/syndicate-js
|
|
|
|
|