@muze-nl/simplystore 0.7.1 → 0.7.3
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 +7 -6
- package/src/query-worker-module.mjs +2 -3
- package/src/server.mjs +10 -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.3",
|
|
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
|
-
"@muze-nl/od-jsontag": "^0.3.
|
|
21
|
+
"@muze-nl/od-jsontag": "^0.3.4",
|
|
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,10 @@ 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
8
|
import {_,from,not,anyOf,allOf,asc,desc,sum,count,avg,max,min,many,one,distinct} from '@muze-nl/jaqt'
|
|
9
|
+
import process from 'node:process'
|
|
9
10
|
|
|
10
11
|
let dataspace
|
|
11
12
|
let meta = {}
|
|
@@ -190,7 +191,6 @@ function parseAllObjects(o, reset=true) {
|
|
|
190
191
|
return
|
|
191
192
|
}
|
|
192
193
|
if (o && typeof o == 'object') {
|
|
193
|
-
let temp = o[source]
|
|
194
194
|
seen.set(o, true)
|
|
195
195
|
if (Array.isArray(o)) {
|
|
196
196
|
for (let v of o) {
|
|
@@ -233,7 +233,6 @@ export function getDataSpace(path, dataspace) {
|
|
|
233
233
|
|
|
234
234
|
export function linkReplacer(data, baseURL) {
|
|
235
235
|
let type = JSONTag.getType(data)
|
|
236
|
-
let attributes = JSONTag.getAttributes(data)
|
|
237
236
|
if (Array.isArray(data)) {
|
|
238
237
|
data = data.map((entry,index) => {
|
|
239
238
|
return linkReplacer(data[index], baseURL+index+'/')
|
package/src/server.mjs
CHANGED
|
@@ -7,7 +7,7 @@ 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
|
|
10
|
+
import process from 'node:process'
|
|
11
11
|
|
|
12
12
|
const server = express()
|
|
13
13
|
const __dirname = path.dirname(path.dirname(fileURLToPath(import.meta.url)))
|
|
@@ -35,7 +35,7 @@ async function main(options) {
|
|
|
35
35
|
|
|
36
36
|
// allow access to raw body, used to parse a query send as post body
|
|
37
37
|
server.use(express.raw({
|
|
38
|
-
type: (
|
|
38
|
+
type: () => true, // parse body on all requests
|
|
39
39
|
limit: '50MB'
|
|
40
40
|
}))
|
|
41
41
|
|
|
@@ -71,12 +71,12 @@ async function main(options) {
|
|
|
71
71
|
server.get('/command/:id', handleGetCommand)
|
|
72
72
|
|
|
73
73
|
try {
|
|
74
|
-
|
|
74
|
+
await fetch(`http://localhost:${port}`, {
|
|
75
75
|
signal: AbortSignal.timeout(2000)
|
|
76
76
|
})
|
|
77
77
|
console.error(`Port ${port} is already occupied, aborting.`)
|
|
78
78
|
process.exit()
|
|
79
|
-
} catch(
|
|
79
|
+
} catch(err) {
|
|
80
80
|
server.listen(port, () => {
|
|
81
81
|
console.log('SimplyStore listening on port '+port)
|
|
82
82
|
let used = Math.round(process.memoryUsage().rss / 1024 / 1024);
|
|
@@ -145,20 +145,21 @@ async function main(options) {
|
|
|
145
145
|
})
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
async function handleGetQuery(req, res
|
|
148
|
+
async function handleGetQuery(req, res) {
|
|
149
149
|
let start = Date.now()
|
|
150
150
|
if ( !accept(req,res,
|
|
151
151
|
['application/jsontag','application/json','text/html','text/javascript','image/*'],
|
|
152
152
|
function(req, res, accept) {
|
|
153
|
+
let result = true
|
|
153
154
|
switch(accept) {
|
|
154
155
|
case 'text/html':
|
|
155
156
|
case 'image/*':
|
|
156
157
|
case 'text/javascript':
|
|
157
158
|
handleWebRequest(req,res,{root:wwwroot});
|
|
158
|
-
|
|
159
|
+
result = false
|
|
159
160
|
break
|
|
160
161
|
}
|
|
161
|
-
return
|
|
162
|
+
return result
|
|
162
163
|
}
|
|
163
164
|
)) {
|
|
164
165
|
// done
|
|
@@ -307,7 +308,6 @@ async function main(options) {
|
|
|
307
308
|
})
|
|
308
309
|
}
|
|
309
310
|
}
|
|
310
|
-
let l = Object.assign({command:command.id}, s)
|
|
311
311
|
appendFile(commandStatus, JSONTag.stringify(Object.assign({command:command.id}, s)))
|
|
312
312
|
},
|
|
313
313
|
//reject()
|
|
@@ -357,7 +357,7 @@ async function main(options) {
|
|
|
357
357
|
sendResponse({code: 422, body: JSON.stringify(error)}, res)
|
|
358
358
|
return false
|
|
359
359
|
} else if (status.has(command.id)) {
|
|
360
|
-
sendResponse({body: JSON.stringify(
|
|
360
|
+
sendResponse({body: JSON.stringify(commandOK)}, res)
|
|
361
361
|
return false
|
|
362
362
|
} else if (!command.name) {
|
|
363
363
|
error = {
|
|
@@ -419,7 +419,7 @@ function accept(req, res, mimetypes, handler) {
|
|
|
419
419
|
function handleWebRequest(req,res,options)
|
|
420
420
|
{
|
|
421
421
|
let path = req.path;
|
|
422
|
-
path = path.replace(/[^a-z0-9_
|
|
422
|
+
path = path.replace(/[^a-z0-9_.\-/]*/gi, '') // whitelist acceptable file paths
|
|
423
423
|
path = path.replace(/\.+/g, '.') // blacklist '..'
|
|
424
424
|
if (!path) {
|
|
425
425
|
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
|
}
|