@muze-nl/simplystore 0.4.7 → 0.5.1
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 +14 -7
- package/scripts/convert.mjs +25 -0
- package/src/command-worker-module.mjs +100 -0
- package/src/command-worker.mjs +13 -0
- package/src/fastParse.mjs +1036 -0
- package/src/fastStringify.mjs +200 -0
- package/src/load-worker.mjs +33 -0
- package/src/{worker-query.mjs → query-worker-module.mjs} +138 -83
- package/src/query-worker.mjs +12 -0
- package/src/server.mjs +303 -218
- package/src/statusCodes.mjs +70 -0
- package/src/symbols.mjs +6 -0
- package/src/util.mjs +3 -3
- package/src/workerPool.mjs +99 -0
- package/data.jsontag +0 -20
- package/src/share.mjs +0 -142
- package/src/worker-query-init.mjs +0 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muze-nl/simplystore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"main": "src/server.mjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -16,18 +16,25 @@
|
|
|
16
16
|
"bugs": "https://github.com/simplyedit/simplystore/issues",
|
|
17
17
|
"homepage": "https://github.com/simplyedit/simplystore#readme",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@muze-nl/jsontag": "^0.
|
|
20
|
-
"array-where-select": "^0.4.
|
|
19
|
+
"@muze-nl/jsontag": "^0.9.1",
|
|
20
|
+
"array-where-select": "^0.4.7",
|
|
21
21
|
"codemirror": "^6.0.1",
|
|
22
22
|
"express": "^4.18.1",
|
|
23
23
|
"json-pointer": "^0.6.2",
|
|
24
24
|
"jsonpath-plus": "^7.2.0",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"vm2": "^3.9.13",
|
|
26
|
+
"write-file-atomic": "^5.0.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"eslint": "^8.48.0",
|
|
30
30
|
"process": "^0.11.10",
|
|
31
31
|
"tap": "^16.3.8"
|
|
32
|
-
}
|
|
33
|
-
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE",
|
|
36
|
+
"src/",
|
|
37
|
+
"www/",
|
|
38
|
+
"scripts/"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import JSONTag from '@muze-nl/jsontag'
|
|
2
|
+
import fastStringify from '../src/fastStringify.mjs'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
|
|
5
|
+
if (process.argv.length<=3) {
|
|
6
|
+
console.log('usage: node ./convert.mjs {inputfile} {outputfile}')
|
|
7
|
+
process.exit()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// parse command line
|
|
11
|
+
let inputFile = process.argv[2]
|
|
12
|
+
let outputFile = process.argv[3]
|
|
13
|
+
|
|
14
|
+
// load file
|
|
15
|
+
let input = fs.readFileSync(inputFile, 'utf-8')
|
|
16
|
+
|
|
17
|
+
// parse jsontag
|
|
18
|
+
let data = JSONTag.parse(input)
|
|
19
|
+
|
|
20
|
+
// write resultset to output
|
|
21
|
+
let strData = fastStringify(data)
|
|
22
|
+
|
|
23
|
+
fs.writeFileSync(outputFile, strData)
|
|
24
|
+
|
|
25
|
+
console.log('Converted data written to ',outputFile)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import JSONTag from '@muze-nl/jsontag'
|
|
2
|
+
import {source} from './symbols.mjs'
|
|
3
|
+
import fastParse from './fastParse.mjs'
|
|
4
|
+
import {stringToSAB,resultSetStringify} from './fastStringify.mjs'
|
|
5
|
+
import writeFileAtomic from 'write-file-atomic'
|
|
6
|
+
|
|
7
|
+
let commands = {}
|
|
8
|
+
let resultSet = []
|
|
9
|
+
let dataspace
|
|
10
|
+
let datafile
|
|
11
|
+
let meta = {}
|
|
12
|
+
let metaProxy = {
|
|
13
|
+
index: {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const metaIdProxy = {
|
|
18
|
+
forEach: (callback) => {
|
|
19
|
+
meta.index.id.forEach((ref,id) => {
|
|
20
|
+
callback({
|
|
21
|
+
deref: () => {
|
|
22
|
+
return resultSet[ref]
|
|
23
|
+
}
|
|
24
|
+
},id)
|
|
25
|
+
})
|
|
26
|
+
},
|
|
27
|
+
set: (id,ref) => {
|
|
28
|
+
//FICME: is this correct?
|
|
29
|
+
meta.index.id.set(id, resultSet.length-1)
|
|
30
|
+
},
|
|
31
|
+
get: (id) => {
|
|
32
|
+
let index = meta.index.id.get(id)
|
|
33
|
+
if (index || index===0) {
|
|
34
|
+
return {
|
|
35
|
+
deref: () => {
|
|
36
|
+
return resultSet[index]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
has: (id) => {
|
|
42
|
+
return meta.index.id.has(id)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const FastJSONTag = {
|
|
47
|
+
getType: (obj) => JSONTag.getType(obj[source]),
|
|
48
|
+
getAttribute: (obj, attr) => JSONTag.getAttribute(obj[source],attr),
|
|
49
|
+
setAttribute: (obj, attr, value) => JSONTag.setAttribute(obj[source], attr, value),
|
|
50
|
+
getAttributes: (obj) => JSONTag.getAttributes(obj[source]),
|
|
51
|
+
getAttributeString: (obj) => JSONTag.getAttributesString(obj[source]),
|
|
52
|
+
getTypeString: (obj) => JSONTag.getTypeString(obj[source])
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function initialize(task) {
|
|
56
|
+
resultSet = fastParse(task.data, task.meta, false) // false means mutable
|
|
57
|
+
dataspace = resultSet[0]
|
|
58
|
+
meta = task.meta
|
|
59
|
+
metaProxy.index.id = metaIdProxy
|
|
60
|
+
datafile = task.datafile
|
|
61
|
+
commands = await import(task.commandsFile).then(mod => {
|
|
62
|
+
return mod.default
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default async function runCommand(commandStr, request) {
|
|
67
|
+
let task = JSONTag.parse(commandStr, null, metaProxy)
|
|
68
|
+
if (!task.id) { throw new Error('missing command id')}
|
|
69
|
+
if (!task.name) { throw new Error('missing command name parameter')}
|
|
70
|
+
let response = {
|
|
71
|
+
jsontag: true
|
|
72
|
+
}
|
|
73
|
+
if (commands[task.name]) {
|
|
74
|
+
try {
|
|
75
|
+
commands[task.name](dataspace, task, request, metaProxy)
|
|
76
|
+
FastJSONTag.setAttribute(dataspace, 'command', task.id)
|
|
77
|
+
|
|
78
|
+
const strData = resultSetStringify(resultSet)
|
|
79
|
+
const uint8sab = stringToSAB(strData)
|
|
80
|
+
response.data = uint8sab
|
|
81
|
+
response.meta = {
|
|
82
|
+
index: {
|
|
83
|
+
id: meta.index.id
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
await writeFileAtomic(datafile, uint8sab)
|
|
88
|
+
} catch(err) {
|
|
89
|
+
console.error('error',err)
|
|
90
|
+
response.code = 422;
|
|
91
|
+
response.body = '<object class="Error">{"message":'+JSON.stringify(''+err)+',"code":422}'
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
console.error('Command not found', task.name, commands)
|
|
95
|
+
response.code = 404
|
|
96
|
+
response.body = '<object class="Error">{"message":"Command '+task.name+' not found","code":404}'
|
|
97
|
+
}
|
|
98
|
+
return response
|
|
99
|
+
}
|
|
100
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { parentPort } from 'node:worker_threads'
|
|
2
|
+
import runCommand, { initialize } from '../src/command-worker-module.mjs'
|
|
3
|
+
|
|
4
|
+
parentPort.on('message', async data => {
|
|
5
|
+
let result
|
|
6
|
+
try {
|
|
7
|
+
await initialize(data)
|
|
8
|
+
result = await runCommand(data.command)
|
|
9
|
+
} catch(err) {
|
|
10
|
+
result = { error: err.message }
|
|
11
|
+
}
|
|
12
|
+
parentPort.postMessage(result)
|
|
13
|
+
})
|