@seneca/repl
Advanced tools
Comparing version 4.0.1 to 5.0.1
{ | ||
"name": "@seneca/repl", | ||
"description": "Provides a client and server REPL for Seneca microservice systems.", | ||
"version": "4.0.1", | ||
"version": "5.0.1", | ||
"main": "repl.js", | ||
@@ -29,3 +29,3 @@ "license": "MIT", | ||
"repo-publish": "npm run clean && npm i --registry=http://registry.npmjs.org && npm run repo-publish-quick", | ||
"repo-publish-quick": "npm run prettier && npm test && npm run repo-tag && npm publish --access public --registry=http://registry.npmjs.org" | ||
"repo-publish-quick": "npm run prettier && npm test && npm run repo-tag && npm publish --access public --registry=https://registry.npmjs.org" | ||
}, | ||
@@ -44,3 +44,3 @@ "keywords": [ | ||
"@seneca/vorpal": "^2.1.1", | ||
"inks": "^1.1.1" | ||
"inks": "^2.0.0" | ||
}, | ||
@@ -51,13 +51,13 @@ "devDependencies": { | ||
"@hapi/lab": "^24.0.0", | ||
"acorn": "^8.0.2", | ||
"async": "^3.2.0", | ||
"coveralls": "^3.1.0", | ||
"gex": "^2.1.0", | ||
"prettier": "^2.1.2", | ||
"acorn": "^8.7.1", | ||
"async": "^3.2.4", | ||
"coveralls": "^3.1.1", | ||
"gex": "^4.0.1", | ||
"prettier": "^2.7.1", | ||
"seneca": "plugin", | ||
"seneca-doc": "^2.1.3", | ||
"seneca-entity": "^10.1.0", | ||
"seneca-mem-store": "^4.0.1", | ||
"seneca-entity": "^18.4.0", | ||
"seneca-mem-store": "^7.0.1", | ||
"seneca-plugin-validator": "0.6.1", | ||
"seneca-promisify": "^2.0.0" | ||
"seneca-promisify": "^3.4.0" | ||
}, | ||
@@ -64,0 +64,0 @@ "files": [ |
202
repl.js
@@ -1,2 +0,2 @@ | ||
/* Copyright © 2015-2020 Richard Rodger and other contributors, MIT License. */ | ||
/* Copyright © 2015-2021 Richard Rodger and other contributors, MIT License. */ | ||
'use strict' | ||
@@ -46,2 +46,4 @@ | ||
list: intern.cmd_list, | ||
find: intern.cmd_find, | ||
prior: intern.cmd_prior, | ||
history: intern.cmd_history, | ||
@@ -56,6 +58,6 @@ log: intern.cmd_log, | ||
function repl(options) { | ||
var seneca = this | ||
var export_address = {} | ||
let seneca = this | ||
let export_address = {} | ||
var cmd_map = Object.assign({}, default_cmds, options.cmds) | ||
let cmd_map = Object.assign({}, default_cmds, options.cmds) | ||
@@ -66,4 +68,4 @@ seneca.add('sys:repl,add:cmd', add_cmd) | ||
function add_cmd(msg, reply) { | ||
var name = msg.name | ||
var action = msg.action | ||
let name = msg.name | ||
let action = msg.action | ||
@@ -81,22 +83,26 @@ if ('string' === typeof name && 'function' === typeof action) { | ||
seneca.init(function (reply) { | ||
var server = intern.start_repl(seneca, options, cmd_map) | ||
try { | ||
let server = intern.start_repl(seneca, options, cmd_map) | ||
server.on('listening', function () { | ||
var address = server.address() | ||
server.on('listening', function () { | ||
let address = server.address() | ||
export_address.port = address.port | ||
export_address.host = address.address | ||
export_address.family = address.family | ||
export_address.port = address.port | ||
export_address.host = address.address | ||
export_address.family = address.family | ||
seneca.log.info({ | ||
kind: 'notice', | ||
notice: 'REPL listening on ' + address.address + ':' + address.port, | ||
seneca.log.info({ | ||
kind: 'notice', | ||
notice: 'REPL listening on ' + address.address + ':' + address.port, | ||
}) | ||
reply() | ||
}) | ||
reply() | ||
}) | ||
server.on('error', function (err) { | ||
seneca.log.error(err) | ||
}) | ||
server.on('error', function (err) { | ||
seneca.log.error(err) | ||
}) | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
}) | ||
@@ -115,12 +121,13 @@ | ||
start_repl: function (seneca, options, cmd_map) { | ||
var alias = options.alias | ||
let alias = options.alias | ||
var server = Net.createServer(function (socket) { | ||
let server = Net.createServer(function (socket) { | ||
let sd = seneca.root.delegate({ repl$: true, fatal$: false }) | ||
// TODO: pass this up to init so it can fail properly | ||
socket.on('error', function (err) { | ||
sd.log.debug('repl-socket', err) | ||
sd.log.error('repl-socket', err) | ||
}) | ||
var sd = seneca.root.delegate({ repl$: true, fatal$: false }) | ||
var r = Repl.start({ | ||
let r = Repl.start({ | ||
prompt: 'seneca ' + seneca.version + ' ' + seneca.id + '> ', | ||
@@ -139,3 +146,3 @@ input: socket, | ||
r.on('error', function (err) { | ||
sd.log.debug('repl', err) | ||
sd.log.error('repl', err) | ||
}) | ||
@@ -171,3 +178,3 @@ | ||
const inspect = context.inspekt | ||
var cmd_history = context.history | ||
let cmd_history = context.history | ||
@@ -186,6 +193,6 @@ cmdtext = cmdtext.trim() | ||
var m = cmdtext.match(/^(\S+)/) | ||
var cmd = m && m[1] | ||
let m = cmdtext.match(/^(\S+)/) | ||
let cmd = m && m[1] | ||
var argtext = | ||
let argtext = | ||
'string' === typeof cmd ? cmdtext.substring(cmd.length) : '' | ||
@@ -198,3 +205,3 @@ | ||
var cmd_func = cmd_map[cmd] | ||
let cmd_func = cmd_map[cmd] | ||
// console.log('CMD', cmd, !!cmd_func) | ||
@@ -214,4 +221,4 @@ | ||
try { | ||
var msg = cmdtext | ||
var m = msg.split(/\s*=>\s*/) | ||
let msg = cmdtext | ||
let m = msg.split(/\s*=>\s*/) | ||
if (2 === m.length) { | ||
@@ -221,4 +228,4 @@ msg = m[0] | ||
var injected_msg = Inks(msg, context) | ||
var args = seneca.util.Jsonic(injected_msg) | ||
let injected_msg = Inks(msg, context) | ||
let args = seneca.util.Jsonic(injected_msg) | ||
context.s.ready(() => { | ||
@@ -230,3 +237,3 @@ context.s.act(args, function (err, out) { | ||
if (m[1]) { | ||
var ma = m[1].split(/\s*=\s*/) | ||
let ma = m[1].split(/\s*=\s*/) | ||
if (2 === ma.length) { | ||
@@ -259,7 +266,8 @@ context[ma[0]] = Hoek.reach({ out: out, err: err }, ma[1]) | ||
try { | ||
var script = Vm.createScript(cmdtext, { | ||
let script = Vm.createScript(cmdtext, { | ||
filename: filename, | ||
displayErrors: false, | ||
}) | ||
var result = script.runInContext(context, { | ||
let result = script.runInContext(context, { | ||
displayErrors: false, | ||
@@ -271,4 +279,43 @@ }) | ||
} catch (e) { | ||
return respond(e.message) | ||
if ('SyntaxError' === e.name && e.message.startsWith('await')) { | ||
let wrapper = '(async () => { return (' + cmdtext + ') })()' | ||
try { | ||
let script = Vm.createScript(wrapper, { | ||
filename: filename, | ||
displayErrors: false, | ||
}) | ||
let out = script.runInContext(context, { | ||
displayErrors: false, | ||
}) | ||
out | ||
.then((result) => { | ||
result = result === seneca ? null : result | ||
respond(null, result) | ||
}) | ||
.catch((e) => { | ||
return respond(e.message) | ||
}) | ||
} catch (e) { | ||
return respond(e.message) | ||
} | ||
} else { | ||
return respond(e.message) | ||
} | ||
} | ||
// // let out = script.runInContext(context, { | ||
// // out | ||
// // .then(result=>{ | ||
// // }) | ||
// // .catch(e => { | ||
// // return respond(e.message) | ||
// // }) | ||
// } catch (e) { | ||
// console.log(e) | ||
// return respond(e.message) | ||
// } | ||
} | ||
@@ -284,8 +331,8 @@ } | ||
var part = /([^.]+)\.+/g | ||
var m | ||
var out = {} | ||
var cur = out | ||
var po = out | ||
var pn | ||
let part = /([^.]+)\.+/g | ||
let m | ||
let out = {} | ||
let cur = out | ||
let po = out | ||
let pn | ||
@@ -318,4 +365,4 @@ while (null != (m = part.exec(optpath))) { | ||
if (context.log_capture) { | ||
var seneca = context.seneca | ||
var out = seneca.__build_test_log__$$ | ||
let seneca = context.seneca | ||
let out = seneca.__build_test_log__$$ | ||
? seneca.__build_test_log__$$(seneca, 'test', data) | ||
@@ -338,3 +385,3 @@ : context.inspekt(data).replace(/\n/g, ' ') | ||
var actid = (meta || args.meta$ || {}).id | ||
let actid = (meta || args.meta$ || {}).id | ||
context.socket.write( | ||
@@ -366,3 +413,3 @@ 'IN ' + | ||
var actid = (meta || out.meta$ || {}).id | ||
let actid = (meta || out.meta$ || {}).id | ||
@@ -374,3 +421,3 @@ out = | ||
var cur_index = context.act_index_map[actid] | ||
let cur_index = context.act_index_map[actid] | ||
context.socket.write( | ||
@@ -386,6 +433,6 @@ 'OUT ' + intern.fmt_index(cur_index) + ': ' + out + '\n' | ||
var actid = (meta || err.meta$ || {}).id | ||
let actid = (meta || err.meta$ || {}).id | ||
if (actid) { | ||
var cur_index = context.act_index_map[actid] | ||
let cur_index = context.act_index_map[actid] | ||
context.socket.write( | ||
@@ -399,5 +446,5 @@ 'ERR ' + intern.fmt_index(cur_index) + ': ' + err.message + '\n' | ||
cmd_get: function (cmd, argtext, context, options, respond) { | ||
var option_path = argtext.trim() | ||
var options = context.seneca.options() | ||
var out = Hoek.reach(options, option_path) | ||
let option_path = argtext.trim() | ||
let sopts = context.seneca.options() | ||
let out = Hoek.reach(sopts, option_path) | ||
return respond(null, out) | ||
@@ -407,3 +454,3 @@ }, | ||
cmd_depth: function (cmd, argtext, context, options, respond) { | ||
var depth = parseInt(argtext, 10) | ||
let depth = parseInt(argtext, 10) | ||
depth = isNaN(depth) ? null : depth | ||
@@ -427,6 +474,35 @@ context.inspekt = intern.make_inspect(context, { | ||
cmd_list: function (cmd, argtext, context, options, respond) { | ||
var narrow = context.seneca.util.Jsonic(argtext) | ||
let narrow = context.seneca.util.Jsonic(argtext) | ||
respond(null, context.seneca.list(narrow)) | ||
}, | ||
cmd_find: function (cmd, argtext, context, options, respond) { | ||
let narrow = context.seneca.util.Jsonic(argtext) | ||
respond(null, context.seneca.find(narrow)) | ||
}, | ||
cmd_prior: function (cmd, argtext, context, options, respond) { | ||
let pdesc = (actdef) => { | ||
let d = { | ||
id: actdef.id, | ||
plugin: actdef.plugin_fullname, | ||
pattern: actdef.pattern, | ||
} | ||
if (actdef.callpoint) { | ||
d.callpoint = actdef.callpoint | ||
} | ||
return d | ||
} | ||
let narrow = context.seneca.util.Jsonic(argtext) | ||
let actdef = context.seneca.find(narrow) | ||
let priors = [pdesc(actdef)] | ||
let pdef = actdef | ||
while (null != (pdef = pdef.priordef)) { | ||
priors.push(pdesc(pdef)) | ||
} | ||
respond(null, priors) | ||
}, | ||
cmd_history: function (cmd, argtext, context, options, respond) { | ||
@@ -438,3 +514,3 @@ return respond(null, context.history.join('\n')) | ||
context.log_capture = !context.log_capture | ||
var m = null | ||
let m = null | ||
@@ -454,6 +530,6 @@ if (!context.log_capture) { | ||
cmd_set: function (cmd, argtext, context, options, respond) { | ||
var m = argtext.match(/^\s*(\S+)\s+(\S+)/) | ||
let m = argtext.match(/^\s*(\S+)\s+(\S+)/) | ||
if (m) { | ||
var setopt = intern.parse_option( | ||
let setopt = intern.parse_option( | ||
m[1], | ||
@@ -475,3 +551,3 @@ context.seneca.util.Jsonic('$:' + m[2]).$ | ||
cmd_alias: function (cmd, argtext, context, options, respond) { | ||
var m = argtext.match(/^\s*(\S+)\s+(.+)[\r\n]?/) | ||
let m = argtext.match(/^\s*(\S+)\s+(.+)[\r\n]?/) | ||
@@ -478,0 +554,0 @@ if (m) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25790
547
+ Addedinks@2.0.0(transitive)
- Removedinks@1.1.1(transitive)
Updatedinks@^2.0.0