How to use the mojiscript.allPass function in mojiscript

To help you get started, we’ve selected a few mojiscript examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github joelnet / the-terminal-daemon / src / commands / coind.command.js View on Github external
// TODO: use strategy pattern, like wallet
const chalk = require('chalk')
const { allPass } = require('mojiscript')
const { isCommand, getArgs } = require('../lib/command')
const actions = require('../actions')
const { tables } = require('../stores/fs')
const { doesServerHavePackage } = require('./lib/doesServerHavePackage')
const tutorial = require('../tutorial')

const name = 'coind'
const commands = ['start', 'stop', 'status', '--help']

const isCommandValid = command =>
  command != null && commands.some(o => o === command)

const test = allPass([isCommand(name), doesServerHavePackage(name)])

const exec = req => {
  const { username } = req.session
  const [command] = getArgs(req.body.line)

  if (command != null || command === '--help') {
    if (!isCommandValid(command)) {
      return [actions.echo(`${name}: ${command}: Invalid command`)]
    }

    const server = tables.servers.find({
      address: { $eq: req.session.env.HOST }
    })[0]

    const state = server.state || (server.state = {})
github joelnet / the-terminal-daemon / src / commands / wallet / wallet.command.js View on Github external
//@ts-check
const { allPass } = require('mojiscript')
const path = require('path')
const { isCommand } = require('../../lib/command')
const { doesServerHavePackage } = require('../lib/doesServerHavePackage')
const { execStrategy, getStrategies } = require('../../lib/strategies')

const name = 'wallet'

const strategyPath = path.join(__dirname, '**/*.strategy.js')
const strategies = getStrategies(strategyPath)

/**
 * @type { import('../../types/strategy').StrategyTest }
 */
const test = allPass([isCommand(name), doesServerHavePackage(name)])

/**
 * @type { import('../../types/strategy').StrategyExec }
 */
const exec = execStrategy(strategies)

module.exports = {
  sort: 10,
  test: test,
  exec: exec,
  name
}
github joelnet / the-terminal-daemon / src / commands / cryptolock / cryptolock.command.js View on Github external
//@ts-check
const { allPass } = require('mojiscript')
const path = require('path')
const { doesServerHavePackage } = require('../lib/doesServerHavePackage')
const { isCommand } = require('../../lib/command')
const { execStrategy, getStrategies } = require('../../lib/strategies')

const name = 'cryptolock'

const strategyPath = path.join(__dirname, '**/*.strategy.js')
const strategies = getStrategies(strategyPath)

/**
 * @type { import('../../types/strategy').StrategyTest }
 */
const test = allPass([isCommand(name), doesServerHavePackage(name)])

/**
 * @type { import('../../types/strategy').StrategyExec }
 */
const exec = execStrategy(strategies)

module.exports = {
  sort: 10,
  test: test,
  exec: exec
}
github joelnet / the-terminal-daemon / src / commands / coind / coind.command.js View on Github external
//@ts-check
const { allPass } = require('mojiscript')
const path = require('path')
const { isCommand } = require('../../lib/command')
const { doesServerHavePackage } = require('../lib/doesServerHavePackage')
const { execStrategy, getStrategies } = require('../../lib/strategies')

const name = 'coind'

const strategyPath = path.join(__dirname, '**/*.strategy.js')
const strategies = getStrategies(strategyPath)

/**
 * @type { import('../../types/strategy').StrategyTest }
 */
const test = allPass([isCommand(name), doesServerHavePackage(name)])

/**
 * @type { import('../../types/strategy').StrategyExec }
 */
const exec = execStrategy(strategies)

module.exports = {
  sort: 10,
  test: test,
  exec: exec,
  name
}
github joelnet / the-terminal-daemon / src / commands / wallet / strategies / collect.strategy.js View on Github external
const calculateTotalCollected = req => {
  const servers = tables.servers
    .find({ owner: { $eq: req.session.username } })
    .filter(allPass([hasCoind, isOn]))

  const total = Number((reward * servers.length).toFixed(8))
  return total
}
github joelnet / the-terminal-daemon / src / commands / nscan / nscan.command.js View on Github external
//@ts-check
const { allPass } = require('mojiscript')
const path = require('path')
const { isCommand } = require('../../lib/command')
const { doesServerHavePackage } = require('../lib/doesServerHavePackage')
const { execStrategy, getStrategies } = require('../../lib/strategies')

const name = 'nscan'

const strategies = getStrategies(path.join(__dirname, '**/*.strategy.js'))

/**
 * @type { import('../../types/strategy').StrategyTest }
 */
const test = allPass([isCommand(name), doesServerHavePackage(name)])

/**
 * @type { import('../../types/strategy').StrategyExec }
 */
const exec = execStrategy(strategies)

module.exports = {
  sort: 10,
  test,
  exec,
  name
}
github joelnet / the-terminal-daemon / src / commands / xssh / xssh.command.js View on Github external
const ansi = require('ansi-escapes')
const { allPass } = require('mojiscript')
const { getArgs, isCommand } = require('../../lib/command')
const { animateProgressBar } = require('../../lib/progressbar')

const actions = require('../../actions')
const { tables } = require('../../stores/fs')
const { doesServerHavePackage } = require('../lib/doesServerHavePackage')

const name = 'xssh'
const UP = ansi.cursorPrevLine

/**
 * @type { import('../../types/strategy').StrategyTest }
 */
const test = allPass([isCommand(name), doesServerHavePackage(name)])

/**
 * @type { import('../../types/strategy').StrategyExec }
 */
const exec = req => {
  const [address] = getArgs(req.body.line)

  if (address == null) {
    return [actions.echo(`Usage: ${name} address`)]
  }

  const server =
    address !== 'home'
      ? tables.servers.find({ address: { $eq: address } })[0]
      : null
github joelnet / the-terminal-daemon / src / commands / nscan.command.js View on Github external
const logger = require('../logger')

const name = 'nscan'

const spawnServer = (username, type = 0) => {
  const address = randomIpv6()
  return tables.servers.insert({ owner: username, address, type })
}

const isUserLucky = ({ servers }) =>
  servers.length < 2 || Math.random() <= config.get('luck.nscan')

const isScanRunning = ({ nscan_end_at }) =>
  nscan_end_at && Date.parse(nscan_end_at) - Date.now() >= 0

const test = allPass([isCommand(name), doesServerHavePackage(name)])

const exec = req => {
  const { username } = req.session
  const { nscan_end_at } = req.state
  const servers = tables.servers.find({ owner: { $eq: username } })

  const isLucky = isUserLucky({ username, servers })
  const isStarted = nscan_end_at != null
  const shouldDiscoverServer =
    (!isStarted && isLucky) || (isStarted && !isScanRunning(req.state))

  if (shouldDiscoverServer) {
    logger.info(`\`${username}\`: \`nscan\` found new server`)
    delete req.state.nscan_end_at
    tables.state.update(req.state)
github joelnet / the-terminal-daemon / src / commands / train / train.command.js View on Github external
chalk`{bgCyan.black  training: } Training of {cyan.bold ${lesson}} is complete.`
    ),
    ...rewards.map(reward => {
      if (reward.startsWith('pkg:')) {
        const pkg = reward.substr(4)
        return actions.echo(chalk`package {cyan.bold ${pkg}} is available.
type {cyan.bold pkg install ${pkg}} to install.`)
      }
    })
  ]
}

/**
 * @type { import('../../types/strategy').StrategyTest }
 */
const test = allPass([isCommand(name), doesServerHavePackage(name)])

/**
 * @type { import('../../types/strategy').StrategyExec }
 */
const exec = req => {
  const [arg] = getArgs(req.body.line)

  const myTraining = getAvailableTraining({
    session: req.session,
    state: req.state
  })

  if ((req.state.training || []).some(t => t === arg)) {
    return [
      actions.echo(chalk`${name}: You have already trained {cyan.bold ${arg}}`)
    ]

mojiscript

MojiScript is an Async First, opinionated, and functional language designed to have 100% compatibility with JavaScript engines.

MIT
Latest version published 4 years ago

Package Health Score

51 / 100
Full package analysis