🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

chainscript

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chainscript

Client for chainscript.io

Source
npmnpm
Version
0.7.1
Version published
Weekly downloads
60
-25.93%
Maintainers
1
Weekly downloads
 
Created
Source

Chainscript Javascript Client

Example

Creating a new script

var Chainscript = require('chainscript-client');

// You pass the initial script
new Chainscript({body: {content: {name: 'My Document'}}})
  // Add a snapshot command
  .snapshot()
  // Add a notarize command
  .notarize()
  // Add a send mail command
  .email('stephan.florquin+test@gmail.com')
  // Run the script (returns a promise)
  .run()
  .then(function(cs) {
    console.log(cs.toJSON());
  })
  .fail(function(err) {
    console.error(err.message);
  });

Starting from an existing script

var Chainscript = require('chainscript-client');

Chainscript.load('chainscript:document:3940c155-d17d-421a-b34e-8bf5a458299e')
  .then(function(cs) {
    console.log(cs.toJSON());
    // You can add commands to the loaded script and run the script
    return cs
      .email('stephan.florquin+test@gmail.com')
      .run();
  }).then(function(cs) {
    // New script executed with added commands
    console.log(cs.toJSON());
  })
  .fail(function(err) {
    console.error(err.message);
  });

API

Chainscript

new Chainscript(script, immutable = false)

Creates a new Chainscript from a JSON object.

If immutable is true, THE INSTANCE IS IMMUTABLE. It is never modified after initialization. Adding commands to a script returns a new instance.

Chainscript.load(uuid, immutable = false)

Loads an existing script. Returns a promise that resolves with an instance of Chainscript.

Chainscript#get(path)

Returns the value at specified path, or undefined if the path doesn't exist.

Ex:

var value = new Chainscript({body: {content: {name: 'My Document'}}})
  .get('body.content.name'));

console.log(value); // My Document

Chainscript#snapshot()

Adds a snapshot command to a script. Returns a new instance of Chainscript if immutable, otherwise returns the instance.

Chainscript#update(updates)

Adds an update command to a script. Returns a new instance of Chainscript if immutable, otherwise returns the instance.

Chainscript#notarize()

Adds a notarize command to a script. Returns a new instance of Chainscript if immutable, otherwise returns the instance.

Chainscript#email(to)

Adds a send_email command to a script. Returns a new instance of Chainscript if immutable, otherwise returns the instance.

Chainscript#change(fn)

Adds an update command to a script that applies granular updates to the content. Returns a new instance of Chainscript if immutable, otherwise returns the instance.

Ex:

new Chainscript({body: {content: {name: 'My Document', val: true}}})
  .change(function(content) {
    delete content.val;
    content.name += ' V2';
    content.meta = {
      author: 'Stephan Florquin',
      time: Date.now()
    };
  })
  .run()
  .then(function(cs) {
    console.log(cs.get('body.content'));
  })
  .fail(function(err) {
    console.error(err.message);
  });

Chainscript#delta(body)

Adds an update command to a script that applies the necessary changes to update the current content to the given content. Returns a new instance of Chainscript if immutable, otherwise returns the instance.

Ex:

var content = {
  name: 'My Document'
};

var cs = new Chainscript({body: {content: content}});

content.name = 'My Document V2';
content.meta = {
  author: 'Stephan Florquin',
  time: Date.now()
};

cs.delta(content).run().then(function() {
  console.log(cs.get('body.content'));
});

Chainscript#toJSON()

Returns the script as a JSON object.

Chainscript#run()

Runs the Chainscript. Returns a promise that resolves with a new instance of Chainscript if immutable, otherwise with the instance.

Chainscript#clone()

Clones Chainscript. Returns a new instance of Chainscript.

Mutable extensions

This only applies when immutable is false (the default value).

You may change the script directly via Chainscript#script. If you can change the body content directly, an update command will be issued if needed when you call run.

var cs = new Chainscript({body: {content: {name: 'My Document'}}});

cs.script.body.content.name += ' V2';
cs.script.body.content.meta = {
  author: 'Stephan Florquin',
  time: Date.now()
};

script
  .run()
  .then(function() {
    console.log(script.toJSON());
  });

Keywords

chainscript

FAQs

Package last updated on 16 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts