Options
All
  • Public
  • Public/Protected
  • All
Menu

Package muster-repl

@dws/muster-repl

Introduction

A REPL for the Muster library.

Installation

npm install -g @dws/muster-repl@next

Usage

To start the Muster REPL simply run:

muster-repl

Muster REPL supports following commands:

  • <graph_node> - evaluate a graph node
  • subscribe <graph_node> - subscribe to a graph node
  • sub <graph_node> - alias for the subscribe
  • subscribe:<name> <graph_node> - subscribe to a graph node and name the subscription
  • unsubscribe <name> - remove a named subscription
  • unsub <name> - alias for the unsubscribe
  • subscriptions - list all open subscriptions and their values
  • subs - alias for the subscriptions
  • load <file_path> - load an external muster graph

Example REPL queries

Muster version: 5.0.0-rc.6
Muster REPL version: 5.0.0-rc.6

> value('Hello, world') 'value({value: "Hello, world"})' > computed([value('world')], (name) => Hello, ${<span class="hljs-type">name</span>}) 'value({value: "Hello, world"})' > muster({ name: 'Bob' }) 'Created a new muster instance.' > ref('name') 'value({value: "Bob"})'

Open and close subscriptions

Muster version: 5.0.0-rc.6
Muster REPL version: 5.0.0-rc.6

> muster({ name: variable('Bob') }) 'Created a new muster instance.' > subscribe ref('name') Subscription 1: value({value: "Bob"}) 'Subscription "1" opened' > set('name', 'Jane') Subscription 1: value({value: "Jane"}) 'value({value: "Jane"})' > unsubscribe 1 'Subscription "1" closed.'

Named subscriptions

Muster version: 5.0.0-rc.6
Muster REPL version: 5.0.0-rc.6

> muster({ name: variable('Bob') }) 'Created a new muster instance.' > subscribe:userName ref('name') Subscription userName: value({value: "Bob"}) 'Subscription "userName" opened' > unsubscribe userName 'Subscription "userName" closed.'

List open subscriptions

Muster version: 5.0.0-rc.6
Muster REPL version: 5.0.0-rc.6

> subscriptions 'No open subscriptions.' > subscribe value('asdf') Subscription 1: value({value: "asdf"}) 'Subscription "1" opened' > subscriptions ID "1": value('asdf') Last value: value({value: "asdf"}) undefined

Load external muster graph

Given a graph.js:

module.exports = muster({
  firstName: variable('Jane'),
  lastName: variable('Doe'),
  fullName: computed(
    [ref('firstName'), ref('lastName')],
    (firstName, lastName) => `${firstName} ${lastName}`,
  ),
});

You can load that file in REPL:

Muster version: 5.0.0-rc.7
Muster REPL version: 5.0.0-rc.7

> load ~/Desktop/graph.js Loaded muster instance. > ref('firstName') value({value: "Jane"}) > ref('lastName') value({value: "Doe"})

Index

Type aliases

CommandCallback

CommandCallback: function

Type declaration

    • (error: any, output?: any): any
    • Parameters

      • error: any
      • Optional output: any

      Returns any

CommandEvaluator

CommandEvaluator: function

Type declaration

CommandMatcher

CommandMatcher: function

Type declaration

    • (input: string): boolean
    • Parameters

      • input: string

      Returns boolean

Variables

Const Module

Module: any = require('module')

Const chalk

chalk: any = require('chalk')

Const commands

commands: Command[] = [subscriptions, subscribe, unsubscribe, load, eval]

Const fs

fs: any = require('mz/fs')

Const highlight

highlight: any = require('cli-highlight').highlight

Const musterPackage

musterPackage: any = require('@dws/muster/package.json')

Const musterRepl

musterRepl: any = repl.start({prompt: '> ',eval: runReplCommand,writer: identity,})

Const musterReplPackage

musterReplPackage: any = require('../../package.json')

Let nextSubscriptionId

nextSubscriptionId: number = 1

Const repl

repl: any = require('repl')

Const repl

repl: any = require('repl')

Const repl

repl: any = require('repl')

Const untildify

untildify: any = require('untildify')

Const vm

vm: any = require('vm')

Const vm

vm: any = require('vm')

Const vm

vm: any = require('vm')

Functions

findMatchingCommand

  • findMatchingCommand(input: string): Command | undefined

findNamedSubscription

formatCode

  • formatCode(input: any): string

formatError

  • formatError(input: any): string

formatString

  • formatString(input: any): string

getLoadRegex

  • getLoadRegex(): RegExp

getSubscribeRegex

  • getSubscribeRegex(): RegExp

getUnsubscribeRegex

  • getUnsubscribeRegex(): RegExp

injectMuster

  • injectMuster(context: any): any

isRecoverableError

  • isRecoverableError(error: any): boolean

loadModule

  • loadModule(sourcePath: string): Promise<Muster | undefined>

parseSubscribeInput

runReplCommand

  • runReplCommand(input: string, context: any, filename: string, callback: CommandCallback): Promise<void>

showReplInformation

  • showReplInformation(): void

Object literals

Const evalCommand

evalCommand: object

evaluate

isMatch

  • isMatch(): boolean

Const loadCommand

loadCommand: object

evaluate

isMatch

  • isMatch(input: string): boolean

Let state

state: object

subscriptions

subscriptions: never[] = []

Const subscribeCommand

subscribeCommand: object

evaluate

isMatch

  • isMatch(input: string): boolean

Const subscriptionsCommand

subscriptionsCommand: object

evaluate

isMatch

  • isMatch(input: string): boolean

Const unsubscribeCommand

unsubscribeCommand: object

evaluate

isMatch

  • isMatch(input: string): boolean