Skip to content

Commit 3f1e1cd

Browse files
committed
switch venue to using a LocalParty so we don't have to solve every issue in MongoParty right now
1 parent d0d771e commit 3f1e1cd

7 files changed

Lines changed: 75 additions & 19 deletions

File tree

src/party/document-factory.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,36 @@ const Ajv = require('ajv')
22
const debug = require('debug')('dataparty.document-factory')
33
const IDocument = require('./idocument')
44

5+
class DocumentValidationError extends Error {
6+
constructor(ajvErrors){
7+
super()
8+
9+
/*[
10+
{
11+
"keyword": "required",
12+
"dataPath": "",
13+
"schemaPath": "#/required",
14+
"params": {
15+
"missingProperty": "name"
16+
},
17+
"message": "should have required property 'name'"
18+
}
19+
]
20+
*/
21+
22+
this.message='Validation failure\n'
23+
24+
for(let i=0; i<ajvErrors.length; i++){
25+
const error = ajvErrors[i]
26+
this.message += error.message + 'at data.'+error.dataPath
27+
}
28+
29+
this.stack=''
30+
this.name='DocumentValidationError'
31+
this.code=this.name
32+
}
33+
}
34+
535
/**
636
* @class
737
*/
@@ -111,6 +141,7 @@ class DocumentFactory {
111141
* @param {*} data
112142
*/
113143
validate(type, data){
144+
debug('validate',type)
114145
return new Promise((resolve, reject)=>{
115146

116147
if(!this.validators[type]){
@@ -122,7 +153,8 @@ class DocumentFactory {
122153

123154
if(!valid){
124155
let errors = this.validators[type].errors
125-
return reject({error: errors})
156+
157+
return reject(new DocumentValidationError(errors))
126158
}
127159

128160
return resolve(data)

src/party/idocument.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ class IDocument extends EventEmitter {
124124
* @returns {object}
125125
*/
126126
async setData(input){
127+
debug('setData start')
127128
let valid = await this.party.factory.validate(this.type, input)
129+
debug('setData done')
128130
this._data = valid
129131
}
130132

@@ -138,6 +140,7 @@ class IDocument extends EventEmitter {
138140
delete value.$meta.version
139141
delete value.__v
140142

143+
debug('asign data')
141144
await this.setData(value)
142145
debug('data set')
143146
await this.party.update(value)

src/party/local/loki-db.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = class LokiDb extends EventEmitter {
3939
autoload: true,
4040
autoloadCallback : resolve,
4141
autosave: true,
42-
autosaveInterval: 10000
42+
autosaveInterval: 1000
4343
}
4444
)
4545

src/sandbox/sandbox.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ class Sandbox {
3333
sandbox,
3434
require: {
3535
external: {
36-
modules: ['debug', '@dataparty/crypto', '@hapi/joi', '@hapi/hoek']
36+
modules: ['debug', '@dataparty/crypto', '@hapi/joi', '@hapi/hoek', ]
3737
},
38-
//builtin: ['*']
38+
builtin: ['*'], //! This should be empty typically
39+
import: ['fs', 'readline', 'stream']
3940
}
4041
})
4142

src/venue/endpoints/create-service.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,30 @@ module.exports = class CreateSrvEndpoint extends IEndpoint {
6262
debug('service created')
6363
}
6464
else{
65-
debug('updating service')
66-
debug(srvDoc.data)
67-
await srvDoc.mergeData({
68-
package: compiledSrv.package,
69-
//schemas: compiledSrv.schemas,
70-
//endpoints: compiledSrv.endpoints,
71-
//midddleware: compiledSrv.middleware,
72-
middleware_order: compiledSrv.middleware_order
73-
})
7465

75-
debug(srvDoc.data)
7666

7767
try{
68+
69+
debug('updating service')
70+
debug(srvDoc.data)
71+
await srvDoc.mergeData({
72+
package: compiledSrv.package,
73+
schemas: compiledSrv.schemas,
74+
endpoints: compiledSrv.endpoints,
75+
midddleware: compiledSrv.middleware,
76+
middleware_order: compiledSrv.middleware_order
77+
})
78+
79+
//debug(srvDoc.data)
80+
81+
debug('saving doc')
82+
83+
7884
await srvDoc.save()
7985
}
80-
catch(err){}
86+
catch(err){
87+
console.log(err)
88+
}
8189
debug('updated service')
8290
}
8391

src/venue/schema/venue_service.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ class VenueSrv extends Dataparty.ISchema {
5454

5555
static permissions (context) {
5656
return {
57-
read: false,
58-
new: false,
59-
change: false
57+
read: true,
58+
new: true,
59+
change: true
6060
}
6161
}
6262
}

src/venue/venue-host.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,25 @@ async function main(){
5959
}
6060
}
6161

62-
let party = new Dataparty.MongoParty({
62+
/*let party = new Dataparty.MongoParty({
6363
uri,
6464
model: build.schemas,
6565
serverModels,
6666
config: new Dataparty.Config.MemoryConfig()
67+
})*/
68+
69+
const dbPath = 'dataparty-venue.db'
70+
71+
debug('party db location', dbPath)
72+
73+
let party = new Dataparty.LocalParty({
74+
path: dbPath,
75+
model: build.schemas,
76+
config: new Dataparty.Config.MemoryConfig()
6777
})
6878

79+
80+
6981
debug('partying')
7082

7183
const runner = new Dataparty.ServiceRunner({

0 commit comments

Comments
 (0)