Skip to content

Commit 0a538a9

Browse files
authored
Merge pull request #17 from datapartyjs/dataparty-service
Dataparty service
2 parents 30cbe55 + 27d5c52 commit 0a538a9

26 files changed

Lines changed: 899 additions & 19 deletions

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,30 @@
1313
"build": "webpack",
1414
"prepare": "yarn build",
1515
"watch": "webpack --watch",
16-
"watch-test": "nodemon test/test-server-party-generic-model.js",
16+
"watch-test": "DEBUG=* nodemon --ignore service test/test-service-compile.js",
1717
"build-docs": "npx jsdoc -c jsdoc.json"
1818
},
1919
"dependencies": {
2020
"@dataparty/bouncer-db": "1.0.1",
2121
"@dataparty/crypto": "1.0.1",
22+
"@zeit/ncc": "^0.22.3",
2223
"ajv": "6.9.1",
24+
"body-parser": "^1.19.0",
2325
"bson-objectid": "^1.3.0",
2426
"colors": "1.3.1",
27+
"cors": "^2.8.5",
2528
"debug": "^3.1.0",
2629
"deep-set": "^1.0.1",
2730
"dom-storage": "^2.1.0",
31+
"express": "^4.17.1",
32+
"express-list-routes": "^0.1.4",
33+
"git-repo-info": "^2.1.1",
2834
"jsonpath-plus": "^0.20.1",
2935
"last-eventemitter": "^1.1.1",
3036
"lodash": "^4.17.4",
3137
"lokijs": "1.5.6",
3238
"mkdirp": "^0.5.1",
39+
"morgan": "^1.10.0",
3340
"nconf": "^0.10.0",
3441
"node-persist": "^3.0.1",
3542
"nodemon-webpack-plugin": "^3.0.1",
@@ -42,6 +49,7 @@
4249
"touch": "^3.1.0",
4350
"url-parse": "^1.4.7",
4451
"uuid": "^3.2.1",
52+
"vm2": "^3.9.2",
4553
"websocket": "^1.0.26",
4654
"wreck": "14.0.2",
4755
"wrtc": "^0.4.4"

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
const Comms = require('./comms')
22
const Config = require('./config')
33
const Party = require('./party')
4+
const Service = require('./service')
5+
const Sandbox = require('./sandbox')
46

57
module.exports = {
68
Comms,
79
Config,
8-
...Party
10+
...Party,
11+
...Service,
12+
...Sandbox
913
}

src/party/idocument.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class IDocument extends EventEmitter {
6060
*/
6161
get version(){ return reach(this._data, '$meta.version') }
6262

63+
static get DocumentSchema(){
64+
return 'document'
65+
}
6366

6467
/**
6568
* @typedef {Object} IdObj

src/party/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const IParty = require('./iparty')
22
const PeerParty = require('./peer/peer-party')
33
const CloudParty = require('./cloud/cloud-party')
44
const LocalParty = require('./local/local-party')
5-
const ServerParty = require('./server/server-party')
5+
const MongoParty = require('./mongo/mongo-party')
66

77
const IDocument = require('./idocument')
88
const DocumentFactory = require('./document-factory')
@@ -13,6 +13,6 @@ const LokiDb = require('./local/loki-db')
1313
module.exports = {
1414
IDocument, IParty, DocumentFactory,
1515
CloudDocument,
16-
CloudParty, LocalParty, PeerParty, ServerParty,
16+
CloudParty, LocalParty, PeerParty, MongoParty,
1717
LokiDb
1818
}

src/party/iparty.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ class IParty {
134134
return this._identity.toJSON(false)
135135
}
136136

137+
get privateIdentity(){
138+
if (!this.hasIdentity()){ return undefined }
139+
return this._identity
140+
}
141+
137142
/** @type {IdObj} */
138143
get actor(){
139144
if (this.actors && this.actors[0]){
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
'use strict'
22

33
const BouncerDb = require('@dataparty/bouncer-db')
4-
const debug = require('debug')('dataparty.server-party')
4+
const debug = require('debug')('dataparty.mongo-party')
55

66
const IParty = require('../iparty')
77
const Qb = require('../qb')
88

99

1010
/**
1111
* @class
12-
* @alias module:dataparty.LocalParty
12+
* @alias module:dataparty.MongoParty
1313
* @interface
1414
*/
15-
class ServerParty extends IParty {
15+
class MongoParty extends IParty {
1616

1717
constructor ({uri, mongoOptions, serverModels, ...options}) {
1818
super(options)
@@ -46,4 +46,4 @@ class ServerParty extends IParty {
4646
}
4747
}
4848

49-
module.exports = ServerParty
49+
module.exports = MongoParty

src/party/peer/peer-party.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const RTCSocketComms = require('../../comms/rtc-socket-comms')
1515
*/
1616
class PeerParty extends IParty {
1717

18-
constructor ({remoteIdentity, path, host, wrtc, trickle, ...options}) {
18+
constructor ({remoteIdentity, host, hostParty, wrtc, trickle=true, ...options}) {
1919
super(options)
2020

2121
this.comms = new RTCSocketComms({remoteIdentity, host, party: this, wrtc, trickle})
@@ -25,20 +25,18 @@ class PeerParty extends IParty {
2525
cache: this.cache
2626
})
2727

28-
this.db = null
28+
this.hostParty = null
2929

3030
if(this.comms.host){
31-
this.db = new LokiDb({
32-
path, factory: this.factory
33-
})
31+
this.hostParty = hostParty
3432
}
3533
}
3634

3735
async start(){
3836
await super.start()
3937
if(this.comms.host){
4038
debug('start - host')
41-
await this.db.start()
39+
await this.hostParty.start()
4240
}
4341
else {
4442
debug('start - client')
@@ -52,7 +50,7 @@ class PeerParty extends IParty {
5250

5351
if(this.comms.host){
5452
debug('handleCall - host')
55-
return await this.db.handleCall(ask)
53+
return await this.hostParty.handleCall(ask)
5654
} else {
5755
debug('handleCall - client')
5856
return await this.comms.call('api-v2-peer-bouncer', ask)

src/party/query.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const debug=require('debug')('dataparty.query')
34
const cloneDeep = require('lodash/cloneDeep')
45
const Clerk = require('./clerk.js')
56

@@ -76,7 +77,7 @@ module.exports = class Query {
7677

7778
if(hydrate){
7879
const results = await this.qb.find(this.spec)
79-
console.log('hydrating', results)
80+
debug('hydrating', results)
8081
return this.model.hydrate(results)
8182
}
8283

src/sandbox/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
Sandbox: require('./sandbox'),
3+
SandboxError: require('./sandbox-error'),
4+
MiddlewareInfoSandbox: require('./middleware-info-sandbox')
5+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//const debug = require('debug')('dataparty.MiddlewareInfoSandbox')
2+
const Sandbox = require('./sandbox')
3+
4+
class MiddlewareInfoSandbox extends Sandbox {
5+
constructor(code){
6+
super(`
7+
8+
module.exports = async ()=>{
9+
10+
class ErrorError extends Error {
11+
constructor(msg){
12+
super()
13+
this.code = 'ErrorError'
14+
this.message = 'You did not throw an error object, always throw an Error object! - [' + msg + ']'
15+
}
16+
}
17+
18+
try{
19+
let Lib = ${code}
20+
21+
return {
22+
Name: Lib.Name,
23+
Type: Lib.Type,
24+
Description: Lib.Description,
25+
ConfigSchema: Lib.ConfigSchema
26+
}
27+
}
28+
catch(err){
29+
30+
if(!err || !err.stack){
31+
err = new ErrorError(err)
32+
}
33+
34+
throw err
35+
}
36+
37+
}
38+
`)
39+
40+
this.info = null
41+
}
42+
43+
async run(){
44+
45+
46+
this.info = await super.run()
47+
48+
return this.info
49+
}
50+
51+
}
52+
53+
module.exports = MiddlewareInfoSandbox

0 commit comments

Comments
 (0)