Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

abstract-confine-runtime

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-confine-runtime - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

47

index.js
const EventEmitter = require('events')
module.exports = class AbstractConfineRuntime extends EventEmitter {
exports.AbstractConfineRuntime = class AbstractConfineRuntime extends EventEmitter {
constructor (opts = {}) {
super()
this.source = opts.source
this.ipc = opts.ipc
this.opts = opts

@@ -20,5 +19,47 @@ }

async handleRequest (body) {
describeAPI () {
return new APIDescription()
}
async handleAPICall (methodName, params) {
throw new MethodNotFound()
}
}
exports.APIDescription = class APIObject {
constructor (children = []) {
this.type = 'api'
this.children = children
}
}
exports.APIObject = class APIObject {
constructor (name, children) {
this.type = 'object'
this.name = name
this.children = children
}
}
exports.APIMethod = class APIMethod {
constructor (name) {
this.type = 'method'
this.name = name
}
}
class RuntimeError extends Error {
constructor (code, message, data) {
super(message);
this.name = this.constructor.name;
this.code = code;
this.data = data;
}
}
exports.MethodNotFound = class MethodNotFound extends RuntimeError {
static CODE = -1
constructor (msg, data) {
super(MethodNotFound.CODE, msg || 'Method not found', data)
}
}

4

package.json
{
"name": "abstract-confine-runtime",
"version": "0.2.0",
"description": "The base class for confine runtimes. ",
"version": "0.3.0",
"description": "The base class for confine runtimes.",
"main": "index.js",

@@ -6,0 +6,0 @@ "scripts": {

@@ -13,3 +13,3 @@ # Abstract Confine Runtime

const fs = require('fs')
const AbstractConfineRuntime = require('abstract-confine-runtime')
const { AbstractConfineRuntime, APIDescription, APIObject, APIMethod, MethodNotFound } = require('abstract-confine-runtime')

@@ -19,3 +19,3 @@ module.exports = class MyConfineRuntime extends AbstractConfineRuntime {

super(opts)
// sets this.source, this.ipc, and this.opts
// ^ sets this.source, and this.opts
}

@@ -40,10 +40,33 @@

async handleRequest (body) {
// handle requests sent to the runtime by the host environment
describeAPI () {
// return a tree structure to describe the api, see below
return new APIDescription()
}
async handleAPICall (methodName, params) {
// handle any API calls sent to the runtime by the host environment
// if the method does not exist, throw MethodNotFound
throw new MethodNotFound()
}
}
```
The `describeAPI()` method needs to provide a tree of `APIDescription`, `APIObject`, and `APIMethod` objects, like so:
```js
/* The API we want to represent: */
// hello()
// sub.method()
// zed()
return new APIDescription([
new APIMethod('hello'),
new APIObject('sub', [
new APIMethod('method')
]),
new APIMethod('zed')
])
```
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc