@muze-nl/simplystore 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -5
- package/src/query-worker-module.mjs +4 -4
- package/src/server.mjs +9 -10
- package/src/statusCodes.mjs +0 -2
- package/src/workerPool.mjs +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muze-nl/simplystore",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"main": "src/server.mjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -16,20 +16,21 @@
|
|
|
16
16
|
"bugs": "https://github.com/simplyedit/simplystore/issues",
|
|
17
17
|
"homepage": "https://github.com/simplyedit/simplystore#readme",
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"@muze-nl/jaqt": "^0.10.1",
|
|
19
20
|
"@muze-nl/jsontag": "^0.9.11",
|
|
20
21
|
"@muze-nl/od-jsontag": "^0.3.3",
|
|
21
22
|
"codemirror": "^6.0.1",
|
|
22
23
|
"express": "^4.18.1",
|
|
23
|
-
"@muze-nl/jaqt": "^0.9.8",
|
|
24
24
|
"json-pointer": "^0.6.2",
|
|
25
|
-
"jsonpath-plus": "^7.2.0",
|
|
26
25
|
"vm2": "^3.9.13",
|
|
27
26
|
"write-file-atomic": "^5.0.1"
|
|
28
27
|
},
|
|
29
28
|
"devDependencies": {
|
|
30
|
-
"eslint": "^
|
|
29
|
+
"@eslint/js": "^9.36.0",
|
|
30
|
+
"eslint": "^9.36.0",
|
|
31
|
+
"globals": "^16.4.0",
|
|
31
32
|
"process": "^0.11.10",
|
|
32
|
-
"tap": "^
|
|
33
|
+
"tap": "^21.1.0"
|
|
33
34
|
},
|
|
34
35
|
"files": [
|
|
35
36
|
"README.md",
|
|
@@ -3,9 +3,9 @@ import {VM} from 'vm2'
|
|
|
3
3
|
import { memoryUsage } from 'node:process'
|
|
4
4
|
import JSONTag from '@muze-nl/jsontag'
|
|
5
5
|
import * as odJSONTag from '@muze-nl/od-jsontag/src/jsontag.mjs'
|
|
6
|
-
import {source
|
|
6
|
+
import {source} from '@muze-nl/od-jsontag/src/symbols.mjs'
|
|
7
7
|
import parse from '@muze-nl/od-jsontag/src/parse.mjs'
|
|
8
|
-
import {_,from,not,anyOf,allOf,asc,desc,sum,count,avg,max,min,distinct} from '@muze-nl/jaqt'
|
|
8
|
+
import {_,from,not,anyOf,allOf,asc,desc,sum,count,avg,max,min,many,one,distinct} from '@muze-nl/jaqt'
|
|
9
9
|
|
|
10
10
|
let dataspace
|
|
11
11
|
let meta = {}
|
|
@@ -134,6 +134,8 @@ export function runQuery(pointer, request, query) {
|
|
|
134
134
|
avg,
|
|
135
135
|
max,
|
|
136
136
|
min,
|
|
137
|
+
many,
|
|
138
|
+
one,
|
|
137
139
|
distinct,
|
|
138
140
|
// console: connectConsole(res),
|
|
139
141
|
JSONTag: myJSONTag,
|
|
@@ -188,7 +190,6 @@ function parseAllObjects(o, reset=true) {
|
|
|
188
190
|
return
|
|
189
191
|
}
|
|
190
192
|
if (o && typeof o == 'object') {
|
|
191
|
-
let temp = o[source]
|
|
192
193
|
seen.set(o, true)
|
|
193
194
|
if (Array.isArray(o)) {
|
|
194
195
|
for (let v of o) {
|
|
@@ -231,7 +232,6 @@ export function getDataSpace(path, dataspace) {
|
|
|
231
232
|
|
|
232
233
|
export function linkReplacer(data, baseURL) {
|
|
233
234
|
let type = JSONTag.getType(data)
|
|
234
|
-
let attributes = JSONTag.getAttributes(data)
|
|
235
235
|
if (Array.isArray(data)) {
|
|
236
236
|
data = data.map((entry,index) => {
|
|
237
237
|
return linkReplacer(data[index], baseURL+index+'/')
|
package/src/server.mjs
CHANGED
|
@@ -7,7 +7,6 @@ import { fileURLToPath } from 'url'
|
|
|
7
7
|
import {appendFile} from './util.mjs'
|
|
8
8
|
import path from 'path'
|
|
9
9
|
import httpStatusCodes from './statusCodes.mjs'
|
|
10
|
-
import writeFileAtomic from 'write-file-atomic'
|
|
11
10
|
|
|
12
11
|
const server = express()
|
|
13
12
|
const __dirname = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
|
|
@@ -35,7 +34,7 @@ async function main(options) {
|
|
|
35
34
|
|
|
36
35
|
// allow access to raw body, used to parse a query send as post body
|
|
37
36
|
server.use(express.raw({
|
|
38
|
-
type: (
|
|
37
|
+
type: () => true, // parse body on all requests
|
|
39
38
|
limit: '50MB'
|
|
40
39
|
}))
|
|
41
40
|
|
|
@@ -71,12 +70,12 @@ async function main(options) {
|
|
|
71
70
|
server.get('/command/:id', handleGetCommand)
|
|
72
71
|
|
|
73
72
|
try {
|
|
74
|
-
|
|
73
|
+
await fetch(`http://localhost:${port}`, {
|
|
75
74
|
signal: AbortSignal.timeout(2000)
|
|
76
75
|
})
|
|
77
76
|
console.error(`Port ${port} is already occupied, aborting.`)
|
|
78
77
|
process.exit()
|
|
79
|
-
} catch(
|
|
78
|
+
} catch(err) {
|
|
80
79
|
server.listen(port, () => {
|
|
81
80
|
console.log('SimplyStore listening on port '+port)
|
|
82
81
|
let used = Math.round(process.memoryUsage().rss / 1024 / 1024);
|
|
@@ -145,20 +144,21 @@ async function main(options) {
|
|
|
145
144
|
})
|
|
146
145
|
}
|
|
147
146
|
|
|
148
|
-
async function handleGetQuery(req, res
|
|
147
|
+
async function handleGetQuery(req, res) {
|
|
149
148
|
let start = Date.now()
|
|
150
149
|
if ( !accept(req,res,
|
|
151
150
|
['application/jsontag','application/json','text/html','text/javascript','image/*'],
|
|
152
151
|
function(req, res, accept) {
|
|
152
|
+
let result = true
|
|
153
153
|
switch(accept) {
|
|
154
154
|
case 'text/html':
|
|
155
155
|
case 'image/*':
|
|
156
156
|
case 'text/javascript':
|
|
157
157
|
handleWebRequest(req,res,{root:wwwroot});
|
|
158
|
-
|
|
158
|
+
result = false
|
|
159
159
|
break
|
|
160
160
|
}
|
|
161
|
-
return
|
|
161
|
+
return result
|
|
162
162
|
}
|
|
163
163
|
)) {
|
|
164
164
|
// done
|
|
@@ -307,7 +307,6 @@ async function main(options) {
|
|
|
307
307
|
})
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
|
-
let l = Object.assign({command:command.id}, s)
|
|
311
310
|
appendFile(commandStatus, JSONTag.stringify(Object.assign({command:command.id}, s)))
|
|
312
311
|
},
|
|
313
312
|
//reject()
|
|
@@ -357,7 +356,7 @@ async function main(options) {
|
|
|
357
356
|
sendResponse({code: 422, body: JSON.stringify(error)}, res)
|
|
358
357
|
return false
|
|
359
358
|
} else if (status.has(command.id)) {
|
|
360
|
-
sendResponse({body: JSON.stringify(
|
|
359
|
+
sendResponse({body: JSON.stringify(commandOK)}, res)
|
|
361
360
|
return false
|
|
362
361
|
} else if (!command.name) {
|
|
363
362
|
error = {
|
|
@@ -419,7 +418,7 @@ function accept(req, res, mimetypes, handler) {
|
|
|
419
418
|
function handleWebRequest(req,res,options)
|
|
420
419
|
{
|
|
421
420
|
let path = req.path;
|
|
422
|
-
path = path.replace(/[^a-z0-9_
|
|
421
|
+
path = path.replace(/[^a-z0-9_.\-/]*/gi, '') // whitelist acceptable file paths
|
|
423
422
|
path = path.replace(/\.+/g, '.') // blacklist '..'
|
|
424
423
|
if (!path) {
|
|
425
424
|
path = '/'
|
package/src/statusCodes.mjs
CHANGED
package/src/workerPool.mjs
CHANGED
|
@@ -103,7 +103,7 @@ export default class WorkerPool extends EventEmitter {
|
|
|
103
103
|
|
|
104
104
|
memoryUsage() {
|
|
105
105
|
for (let worker of this.freeWorkers) {
|
|
106
|
-
worker[kTaskInfo] = new WorkerPoolTaskInfo((
|
|
106
|
+
worker[kTaskInfo] = new WorkerPoolTaskInfo(() => {})
|
|
107
107
|
worker.postMessage({name:'memoryUsage'})
|
|
108
108
|
}
|
|
109
109
|
}
|