npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rainlanguage/dotrain

v6.0.1-alpha.21

Published

Rain language composer (.rain to rainlang composition) and language server protocol implementation for NodeJs and Browser

Downloads

7,999

Readme

Rain Language Composer and LSP

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


Tutorial

Javascript/Typescript

To get started, install the package:

npm install @rainlanguage/dotrain

or

yarn add @rainlanguage/dotrain
// imports
import { RainLanguageServices, MetaStore, TextDocumentItem } from "@rainlanguage/dotrain";

// instantiate a MetaStore which is a in-memory CAS for Rain metadata
const metaStore = new MetaStore();

// some text document
const textDocument = TextDocumentItem.create(
  "file:///file-name.rain",
  "rainlang",
  0,
  "some dotrain text"
);

// initiating the services (metaStore is optional)
const langServices = new RainLanguageServices(metaStore);

// getting validation results (lsp Diagnostics)
const diagnostics = await langServices.doValidate(textDocument);

// instantiate a new RainDocument
const rainDocument = await langServices.newRainDocument(textDocument)

// composing a RainDocument to get rainlang string
const rainlangText = await rainDocument.compose(["entrypoint-1" , "entrypoint-2"]);

Rust

dotrain crate

To get started, install the package:

cargo add dotrain

Features

  • cli: A clap based module (CLI app) for functionalities of this library, this features is required for building the binary
  • js-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 Store
let meta_store = Arc::new(RwLock::new(Store::default()));

// instantiate
let rain_document = RainDocument::new(text, Some(meta_store));

// compose this instance of RainDocument to get rainlang string
let rainlang_text = rain_document.compose(&vec!["entrypoint1", "entrypoint2"], None)?;

dotrain_lsp crate

To get started, install the package:

cargo add dotrain-lsp

Features

  • js-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 Store
let meta_store = Arc::new(RwLock::new(Store::default()));

// the following needs 'lsp' feature to be enabled
let lang_params = LanguageServiceParams {
  meta_store: Some(meta_store)
}

// a LSP TextdocumentItem
let text_document = TextDocumentItem {
  uri,
  text,
  version: 0,
  language_id: "rainlang".to_string()
}

// instantiate RainLanguageServices
let lang_services = RainLanguageServices::new(lang_params);

// get LSP diagnostics of the given text document
let diagnostics = lang_services.do_validate(&text_document, true);

CLI

The CLI app can be built using nix (requires nix package manager to be installed):

nix build github:rainlanguage/dotrain

or installed with the following command from cargo:

cargo install dotrain

this will install the dotrain binary in your path which then can be used to compose .rain files and generate outputs.

Examples

composes a .rain file with specified entrypoints

dotrain compose --input path/to/some.rain --entrypoints first --entrypoints second

optionally, path to rainconfig.json can be provided:

dotrain -c path/to/rainconfig.json --input path/to/some.rain --entrypoints first --entrypoints second

Dotrain cli is also available in Rain CLI app which can be easily run with nix:

nix run github:rainlanguage/rain.cli -- --help

rainconfig

Configuration 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"
  ]
}

Building JS/TS Bindings

From the root of this repo, simply run the following to build the js bindings:

nix develop -c build-js-bindings

This 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-docs

To run tests:

nix develop -c test-js-bindings