Skip to content

Commit

Permalink
update sandbox compiler, ncc.
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenbitbyte committed Oct 23, 2023
1 parent 88078c4 commit 8bbb1c6
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion examples/test-service-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function main(){
//const uri = 'mongodb://localhost:27017/server-party-test'
//debug('db location', uri)

const path = '/data/datparty/srv-party'
const path = '/data/dataparty/example-host-party'

let party = new Dataparty.TingoParty({
path,
Expand Down
4 changes: 2 additions & 2 deletions jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{
"title": "Github",
"id": "github",
"link": "https://github.com/datapartyjs/api"
"link": "https://github.com/datapartyjs/dataparty-api"
},
{
"title": "npm",
Expand Down Expand Up @@ -59,4 +59,4 @@
"hardwrap": false,
"idInHeadings": true
}
}
}
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"frontend": {
"context": "browser",
"source": "src/index-browser.js",
"optimize": false,
"optimize": true,
"outputFormat": "global",
"includeNodeModules": true,
"engines": {
"browsers": "Chrome 80"
}
Expand Down Expand Up @@ -63,11 +64,9 @@
"@dataparty/tasker": "^0.0.2",
"@diva.exchange/i2p-sam": "^4.1.8",
"@markwylde/liferaft": "^1.3.4",
"@vercel/ncc": "^0.36.1",
"@zeit/ncc": "^0.22.3",
"@sevenbitbyte/ncc": "0.0.2",
"ajv": "6.9.1",
"axios": "^0.27.2",
"bleno": "npm:@abandonware/bleno@^0.5.1-4",
"body-parser": "^1.19.0",
"bson": "^4.6.1",
"bson-objectid": "^1.3.0",
Expand All @@ -91,7 +90,6 @@
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
"nconf": "^0.10.0",
"noble": "npm:@abandonware/noble@^1.9.2-20",
"node-mocks-http": "^1.12.1",
"node-persist": "^3.0.1",
"origin-router": "^1.6.4",
Expand Down Expand Up @@ -127,7 +125,6 @@
"https-browserify": "^1.0.0",
"jsdoc": "^3.6.2",
"minami": "^1.2.3",
"mongodb-client-encryption": "^2.2.1",
"parcel": "^2.3.1",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
Expand Down
8 changes: 4 additions & 4 deletions public/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
config = new Dataparty.Config.MemoryConfig({
basePath:'demo',
cloud: {
uri: 'http://172.16.3.1:4001'
uri: 'http://10.10.10.201:4000'
}
})

Expand All @@ -40,14 +40,14 @@
})*/


const remoteIdentity = await Dataparty.Comms.RestComms.HttpGet( config.read('cloud.uri') + '/identity')
const remoteIdentity = await Dataparty.Comms.RestComms.HttpGet( await config.read('cloud.uri') + '/identity')

console.log('cloud.uri -',config.read('cloud.uri'))
console.log('\tremoteIdentity', remoteIdentity)

let party = new Dataparty.PeerParty({
comms: new Dataparty.Comms.WebsocketComms({
uri:'ws://172.16.3.1:4001/ws',
uri:'ws://10.10.10.201:4001/ws',
discoverRemoteIdentity: false,
remoteIdentity: remoteIdentity,
session: Math.random().toString(36).slice(2)
Expand All @@ -68,7 +68,7 @@
})

timeTopic.subscribe((msg)=>{
console.log(name, msg)
console.log(timeTopic.name, msg)
})


Expand Down
9 changes: 5 additions & 4 deletions src/sandbox/endpoint-info-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ module.exports = async ()=>{
}
try{
let Lib = ${code}
var self = {}
${code}
return {
Name: Lib.Name,
Description: Lib.Description,
MiddlewareConfig: Lib.MiddlewareConfig
Name: self.Lib.Name,
Description: self.Lib.Description,
MiddlewareConfig: self.Lib.MiddlewareConfig
}
}
catch(err){
Expand Down
5 changes: 3 additions & 2 deletions src/sandbox/middleware-exec-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ module.exports = async (ctx, static_ctx)=>{
}
try{
let Lib = ${code}
var self = {}
${code}
return await Lib.${func}(ctx, static_ctx)
return await self.Lib.${func}(ctx, static_ctx)
}
catch(err){
Expand Down
11 changes: 6 additions & 5 deletions src/sandbox/middleware-info-sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ module.exports = async ()=>{
}
try{
let Lib = ${code}
var self = {}
${code}
return {
Name: Lib.Name,
Type: Lib.Type,
Description: Lib.Description,
ConfigSchema: Lib.ConfigSchema
Name: self.Lib.Name,
Type: self.Lib.Type,
Description: self.Lib.Description,
ConfigSchema: self.Lib.ConfigSchema
}
}
catch(err){
Expand Down
3 changes: 2 additions & 1 deletion src/sandbox/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Sandbox {
this.offsetToken = offsetToken
this.offset = code.split(this.offsetToken)[0].split('\n').length-1
this.script = new VMScript(code).compile()
debug(code)
}

async loadSourceMap(){
Expand All @@ -26,7 +27,7 @@ class Sandbox {
}

async run(context, sandbox){
//debug('running')
debug('running')
try{

let vm = new NodeVM({
Expand Down
10 changes: 7 additions & 3 deletions src/service/iservice.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs')
const Path = require('path')
//const NCC = require('@vercel/ncc')
const NCC = require('@zeit/ncc')
const NCC = require('@sevenbitbyte/ncc')
//const NCC = require('@zeit/ncc')
const Hoek = require('@hapi/hoek')
const {JSONPath} = require('jsonpath-plus')
const gitRepoInfo = require('git-repo-info')
Expand Down Expand Up @@ -92,7 +92,11 @@ module.exports = class IService {
watch: false, // default
v8cache: false, // default
quiet: false, // default
debugLog: false // default
debugLog: false, // default
//target: 'es2015'
esm: false,
moduleType: 'self',
libraryName: 'Lib'
}

if(build){
Expand Down
11 changes: 8 additions & 3 deletions src/service/service-runner-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@ class ServiceRunnerNode {

if(!this.useNative){
const build = Hoek.reach(this.service, `compiled.endpoints.${name}`)
//debug('build', build)
endpoint = eval(build.code/*, build.map*/)
debug('build', build.code)
var self={}
eval(build.code, build.map)
endpoint = self.Lib
debug('obj Lib', self)
}
else{
endpoint = this.service.constructors.endpoints[name]
Expand Down Expand Up @@ -218,7 +221,9 @@ class ServiceRunnerNode {
let middle=null

if(!this.useNative){
middle = eval(build.code/*, build.map*/)
let self={}
eval(build.code, build.map)
middle = self.Lib
}
else{
middle = this.service.constructors.middleware[type][name]
Expand Down

0 comments on commit 8bbb1c6

Please sign in to comment.