The Rain language server protocol (LSP) services implementation (language services) and .rain composer written in rust and made available for NodeJs and broswers through wasm-bindgen in Typescript/Javascript which makes it well suited for editors and IDEs (as it is used in Rainlang vscode and codemirror language extension).
- Dotrain specs can be found here
- Rainlang specs can be found here
- Dotrain has been implemented for vscode and codemirror, see rainlang-vscode and rainlang-codemirror repositories for more details.
- Dotrain vscode extension can be found here.
The primary goal of the Rain language is to make smart contract development accessible for as many people as possible. This is fundamentally grounded in our belief that accessibility is the difference between theoretical and practical decentralisation. There are many people who would like to participate in authoring and auditing crypto code but currently cannot. When someone wants/needs to do something but cannot, then they delegate to someone who can, this is by definition centralisation.
For more info and details, please read this article
If you find an issue or you want to propose an improvement, please feel free to post it on: issues
To get started, install the package:
npm install @rainlanguage/dotrainor
yarn add @rainlanguage/dotrain// importsimport{MetaStore,RainLanguageServices,TextDocumentItem,}from"@rainlanguage/dotrain";// instantiate a MetaStore which is a in-memory CAS for Rain metadataconstmetaStore=newMetaStore();// some text documentconsttextDocument=TextDocumentItem.create("file:///file-name.rain","rainlang",0,"some dotrain text",);// initiating the services (metaStore is optional)constlangServices=newRainLanguageServices(metaStore);// getting validation results (lsp Diagnostics)constdiagnostics=awaitlangServices.doValidate(textDocument);// instantiate a new RainDocumentconstrainDocument=awaitlangServices.newRainDocument(textDocument);// composing a RainDocument to get rainlang stringconstrainlangText=awaitrainDocument.compose(["entrypoint-1","entrypoint-2",]);To get started, install the package:
cargo add dotraincli: A clap based module (CLI app) for functionalities of this library, this features is required for building the binaryjs-api: includes wrappers around main structs and functionalities to provide an API through wasm-bindgen
use std::sync::{Arc,RwLock};use dotrain::{Store,RainDocument};let text = "some text".to_string();// instantiate arc locked Storelet meta_store = Arc::new(RwLock::new(Store::default()));// instantiatelet rain_document = RainDocument::new(text,Some(meta_store));// compose this instance of RainDocument to get rainlang stringlet rainlang_text = rain_document.compose(&vec!["entrypoint1","entrypoint2"],None)?;To get started, install the package:
cargo add dotrain-lspjs-api: includes wrappers around main structs and functionalities to provide an API through wasm-bindgen
use std::sync::{Arc,RwLock};use dotrain::{Store,RainLanguageServices,TextDocumentItem,LanguageServiceParams,RainDocument};// instantiate arc locked Storelet meta_store = Arc::new(RwLock::new(Store::default()));// the following needs 'lsp' feature to be enabledlet lang_params = LanguageServiceParams{meta_store:Some(meta_store)}// a LSP TextdocumentItemlet text_document = TextDocumentItem{
uri,
text,version:0,language_id:"rainlang".to_string()}// instantiate RainLanguageServiceslet lang_services = RainLanguageServices::new(lang_params);// get LSP diagnostics of the given text documentlet diagnostics = lang_services.do_validate(&text_document,true);The CLI app can be built using nix (requires nix package manager to be installed):
nix build github:rainlanguage/dotrainor installed with the following command from cargo:
cargo install dotrainthis will install the dotrain binary in your path which then can be used to compose .rain files and generate outputs.
composes a .rain file with specified entrypoints
dotrain compose --input path/to/some.rain --entrypoints first --entrypoints secondoptionally, path to rainconfig.json can be provided:
dotrain -c path/to/rainconfig.json --input path/to/some.rain --entrypoints first --entrypoints secondDotrain cli is also available in Rain CLI app which can be easily run with nix:
nix run github:rainlanguage/rain.cli -- --helpConfiguration details for .rain composer (source files and subgraphs). Following command will print info about rainconfig and its fields:
dotrain rainconfig <COMMAND>Here is an example of a rainconfig.json:
{
"include": ["./folder1", "./folder2"],
"subgraphs": [
"https://subgraph1-url",
"https://subgraph2-url",
"https://subgraph3-url"
]
}From the root of this repo, simply run the following to build the js bindings:
nix develop -c build-js-bindingsThis will build the rust library with wasm32-unknown-unknown target in release
mode with js-api feature enabled and then generates bindings using
wasm-bindgen-cli into ./dist directory by encoding the wasm binary into a
json as importing json is native in js/ts and eliminates the need for using
fetch/fs operations when loading the wasm module.
To generate js/ts documents:
nix develop -c js-bindings-docsTo run tests:
nix develop -c test-js-bindings