Skip to content

Commit c964660

Browse files
authored
Merge pull request #28 from datapartyjs/nodejs-bundle
Nodejs bundle
2 parents a10baa8 + 657fea8 commit c964660

38 files changed

Lines changed: 766 additions & 484 deletions

examples/party/example-build.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const Path = require('path')
2+
const debug = require('debug')('example.build')
3+
4+
const Pkg = require('../../package.json')
5+
const ExampleService = require('./example-service')
6+
7+
async function main(){
8+
const service = new ExampleService({ name: Pkg.name, version: Pkg.version })
9+
10+
11+
const build = await service.compile(Path.join(__dirname,'../dataparty'), true)
12+
13+
debug('compiled')
14+
}
15+
16+
main().catch(err=>{
17+
console.error('CRASH')
18+
console.error(err)
19+
})

examples/party/example-service.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const Dataparty = require('../../src/index')
2+
const debug = require('debug')('example.service')
3+
4+
const Path = require('path')
5+
6+
class ExampleService extends Dataparty.IService {
7+
constructor(opts){
8+
super(opts)
9+
10+
this.addSchema(Path.join(__dirname, './schema/user.js'))
11+
this.addSchema(Path.join(__dirname, './schema/basic_types.js'))
12+
13+
}
14+
15+
}
16+
17+
module.exports = ExampleService
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict'
2+
3+
const ISchema = require('../../../src/index').Bouncer.ISchema
4+
5+
class BasicTypes extends ISchema {
6+
7+
static get Type () { return 'basic_types' }
8+
9+
static get Schema(){
10+
return {
11+
number: {type: Number, index: true},
12+
string: {type: String, index: true},
13+
time: {type: Date, index: true},
14+
bool: Boolean,
15+
}
16+
}
17+
18+
static setupSchema(schema){
19+
return schema
20+
}
21+
22+
static permissions (context) {
23+
return {
24+
read: true,
25+
new: true,
26+
change: true
27+
}
28+
}
29+
}
30+
31+
32+
module.exports = BasicTypes

examples/party/schema/user.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict'
2+
3+
const ISchema = require('../../../src/index').Bouncer.ISchema
4+
5+
const Utils = ISchema.Utils
6+
7+
class User extends ISchema {
8+
9+
static get Type () { return 'user' }
10+
11+
static get Schema(){
12+
return {
13+
name: { type: String, maxlength: 50, minlength: 3, unique: true },
14+
photo: { type: String, maxlength: 500, description: 'user photo url' },
15+
created: Utils.created,
16+
enabled: Boolean,
17+
profile: Utils.profile,
18+
tutorial: {
19+
done: Boolean
20+
}
21+
}
22+
}
23+
24+
static setupSchema(schema){
25+
return schema
26+
}
27+
28+
static permissions (context) {
29+
return {
30+
read: true,
31+
new: true,
32+
change: true
33+
}
34+
}
35+
}
36+
37+
38+
module.exports = User

package.json

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
{
22
"name": "@dataparty/api",
33
"private": false,
4-
"version": "1.2.9",
4+
"version": "1.2.11",
55
"main": "dist/dataparty.js",
6-
"browser": "src/index-browser.js",
7-
"source": "src/index.js",
86
"frontend": "dist/dataparty-browser.js",
97
"backend": "dist/dataparty.js",
8+
"embedded": "dist/dataparty-embedded.js",
9+
"alias": {
10+
"events": "eventemitter3"
11+
},
1012
"targets": {
1113
"frontend": {
1214
"context": "browser",
1315
"source": "src/index-browser.js",
16+
"includeNodeModules": true,
1417
"engines": {
1518
"browsers": "Chrome 80"
1619
}
1720
},
1821
"backend": {
1922
"context": "node",
2023
"source": "src/index.js",
24+
"optimize": false,
25+
"includeNodeModules": false,
26+
"engines": {
27+
"node": ">= 12"
28+
}
29+
},
30+
"embedded": {
31+
"context": "electron-main",
32+
"source": "src/index-embedded.js",
33+
"optimize": false,
34+
"includeNodeModules": true,
2135
"engines": {
2236
"node": ">= 12"
2337
}
@@ -32,13 +46,15 @@
3246
"build": "parcel build --no-scope-hoist",
3347
"prepare": "npm run build",
3448
"watch": "parcel watch",
49+
"build-test": "node ./examples/party/example-build.js",
3550
"watch-test": "DEBUG=* nodemon --ignore service test/test-service-compile.js",
3651
"build-docs": "npx jsdoc -c jsdoc.json"
3752
},
3853
"dependencies": {
3954
"@dataparty/bouncer-db": "1.0.1",
40-
"@dataparty/crypto": "1.0.1",
55+
"@dataparty/crypto": "datapartyjs/dataparty-crypto#parcel-build",
4156
"@hapi/joi": "^17.1.1",
57+
"@hapi/wreck": "18.0.0",
4258
"@zeit/ncc": "^0.22.3",
4359
"ajv": "6.9.1",
4460
"body-parser": "^1.19.0",
@@ -49,14 +65,17 @@
4965
"debug": "^3.1.0",
5066
"deep-set": "^1.0.1",
5167
"dom-storage": "^2.1.0",
68+
"eventemitter3": "^4.0.7",
5269
"express": "^4.17.1",
5370
"express-list-routes": "^0.1.4",
5471
"git-repo-info": "^2.1.1",
72+
"jshashes": "^1.0.8",
5573
"jsonpath-plus": "^0.20.1",
5674
"last-eventemitter": "^1.1.1",
5775
"lodash": "^4.17.4",
5876
"lokijs": "1.5.6",
5977
"mkdirp": "^0.5.1",
78+
"moment": "^2.29.4",
6079
"morgan": "^1.10.0",
6180
"nconf": "^0.10.0",
6281
"node-persist": "^3.0.1",
@@ -76,24 +95,19 @@
7695
"uuid": "^3.2.1",
7796
"uuidv4": "^6.2.12",
7897
"vm2": "^3.9.2",
79-
"websocket": "^1.0.26",
80-
"wreck": "14.0.2"
98+
"websocket": "github:sevenbitbyte/WebSocket-Node#parcel-build"
8199
},
82100
"devDependencies": {
83101
"@dataparty/bouncer-model": "1.4.3",
84102
"@hapi/code": "^9.0.1",
85103
"@hapi/lab": "^25.0.1",
86104
"better-docs": "^1.1.6",
87-
"compression-webpack-plugin": "^2.0.0",
88105
"docdash": "^1.1.1",
89106
"jsdoc": "^3.6.2",
90107
"minami": "^1.2.3",
108+
"mongodb-client-encryption": "^2.2.1",
91109
"parcel": "^2.3.1",
92110
"tmp": "^0.2.1",
93-
"webpack": "^4.17.2",
94-
"webpack-bundle-analyzer": "^3.8.0",
95-
"webpack-cli": "^3.1.0",
96-
"webpack-node-externals": "^1.7.2",
97111
"wrtc": "^0.4.7"
98112
},
99113
"repository": {

src/bouncer/crufler-admin.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = class AdminCrufler extends ICrufler {
2020
for(let crufl of ask.crufls){
2121
let result = {
2222
op: crufl.op,
23+
type: crufl.type,
2324
uuid: crufl.uuid,
2425
msgs: [],
2526
complete: true,
@@ -51,6 +52,7 @@ module.exports = class AdminCrufler extends ICrufler {
5152
}
5253
}
5354
catch(err){
55+
debug('crufl error')
5456
debug(err)
5557
result.error = err
5658

@@ -74,17 +76,24 @@ module.exports = class AdminCrufler extends ICrufler {
7476

7577
debug('replying', JSON.stringify(freshness,null,2))
7678

77-
return {freshness: results }
79+
80+
return freshness
7881
}
7982

8083

8184
async applyFind(crufl, includeData = false){
8285
debug('find', JSON.stringify(crufl,null,2))
83-
let mongoQuery = new MongoQuery(crufl.spec)
8486

85-
let query = mongoQuery.getQueryDoc()
87+
let spec = crufl.spec ? crufl.spec : {
88+
ids: crufl.msgs.map(m=>{ debug(typeof m.$meta.id); return m.$meta.id}),
89+
type: crufl.type
90+
}
91+
92+
let mongoQuery = new MongoQuery(spec)
93+
94+
8695

87-
let resultSet = await this.db.find(crufl.type, query)
96+
let resultSet = await this.db.find(crufl.type, mongoQuery)
8897

8998
debug('set',resultSet)
9099

src/bouncer/db/loki-db.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ const debug = require('debug')('dataparty.local.loki-db')
1414

1515
module.exports = class LokiDb extends IDb {
1616

17-
constructor ({path, factory, dbAdapter}) {
17+
constructor ({path, factory, dbAdapter, lokiOptions}) {
1818
super(factory)
1919
debug('constructor')
2020
this.loki = null
21+
this.lokiOptions = lokiOptions
2122
this.path = path
2223
this.dbAdapter = dbAdapter || new LFSA()
2324
this.error = null
@@ -32,7 +33,8 @@ module.exports = class LokiDb extends IDb {
3233
this.loki = new Loki(
3334
this.path,
3435
{
35-
adapter : this.dbAdapter
36+
adapter : this.dbAdapter,
37+
...this.lokiOptions
3638
}
3739
)
3840

@@ -185,12 +187,25 @@ module.exports = class LokiDb extends IDb {
185187
return {freshness: results }
186188
}*/
187189

188-
async find(collectionName, query){
190+
async find(collectionName, mongoQuery){
191+
192+
let query = mongoQuery.getQueryDoc()
193+
189194
debug('find collection=', collectionName, ' query=', JSON.stringify(query,null,2))
190195
let collection = await this.getCollection(collectionName)
191-
let resultArray = collection.find(query)
196+
let resultSet = collection.chain().find(query)
197+
198+
199+
if(mongoQuery.hasLimit()){
200+
resultSet = resultSet.limit(mongoQuery.getLimit())
201+
}
202+
203+
if(mongoQuery.hasSort()){
204+
let sortPath = Object.keys(mongoQuery.getSort())[0]
205+
resultSet = resultSet.simplesort( sortPath )
206+
}
192207

193-
return resultArray.map(this.documentToObject) || []
208+
return resultSet.data().map(this.documentToObject) || []
194209
}
195210

196211
async insertMany(collectionName, docs){
@@ -232,7 +247,7 @@ module.exports = class LokiDb extends IDb {
232247
return resultSet
233248

234249
}
235-
250+
236251
async update(collectionName, docs){
237252
debug('update collection', collectionName, ' docs', docs)
238253

0 commit comments

Comments
 (0)