@muze-nl/simplystore 0.7.3 → 0.8.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 +4 -4
- package/src/command-worker-module.mjs +13 -9
- package/src/load-worker.mjs +4 -5
- package/src/query-worker-module.mjs +13 -51
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muze-nl/simplystore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"main": "src/server.mjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -16,9 +16,9 @@
|
|
|
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.
|
|
20
|
-
"@muze-nl/jsontag": "^0.
|
|
21
|
-
"@muze-nl/od-jsontag": "^0.
|
|
19
|
+
"@muze-nl/jaqt": "^0.10.2",
|
|
20
|
+
"@muze-nl/jsontag": "^0.10.2",
|
|
21
|
+
"@muze-nl/od-jsontag": "^0.4.1",
|
|
22
22
|
"codemirror": "^6.0.1",
|
|
23
23
|
"express": "^4.18.1",
|
|
24
24
|
"json-pointer": "^0.6.2",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import JSONTag from '@muze-nl/jsontag'
|
|
2
2
|
import {getIndex, resultSet} from '@muze-nl/od-jsontag/src/symbols.mjs'
|
|
3
|
-
import
|
|
3
|
+
import Parser from '@muze-nl/od-jsontag/src/parse.mjs'
|
|
4
4
|
import serialize from '@muze-nl/od-jsontag/src/serialize.mjs'
|
|
5
5
|
import writeFileAtomic from 'write-file-atomic'
|
|
6
6
|
|
|
@@ -13,10 +13,12 @@ let metaProxy = {
|
|
|
13
13
|
index: {
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
const parser = new Parser()
|
|
17
|
+
parser.immutable = false
|
|
16
18
|
|
|
17
19
|
export const metaIdProxy = {
|
|
18
20
|
forEach: (callback) => {
|
|
19
|
-
meta.index.id.forEach((ref,id) => {
|
|
21
|
+
parser.meta.index.id.forEach((ref,id) => {
|
|
20
22
|
callback({
|
|
21
23
|
deref: () => {
|
|
22
24
|
return resultArr[ref]
|
|
@@ -25,19 +27,19 @@ export const metaIdProxy = {
|
|
|
25
27
|
})
|
|
26
28
|
},
|
|
27
29
|
set: (id,ref) => {
|
|
28
|
-
if (!meta.index.id.has(id)) {
|
|
30
|
+
if (!parser.meta.index.id.has(id)) {
|
|
29
31
|
if (ref[getIndex]) {
|
|
30
|
-
meta.index.id.set(id, ref[getIndex])
|
|
32
|
+
parser.meta.index.id.set(id, ref[getIndex])
|
|
31
33
|
} else {
|
|
32
34
|
throw new Error('cannot set index.id for non-proxy')
|
|
33
35
|
}
|
|
34
36
|
} else {
|
|
35
|
-
let line = meta.index.id.get(id)
|
|
37
|
+
let line = parser.meta.index.id.get(id)
|
|
36
38
|
resultArr[line] = ref
|
|
37
39
|
}
|
|
38
40
|
},
|
|
39
41
|
get: (id) => {
|
|
40
|
-
let index = meta.index.id.get(id)
|
|
42
|
+
let index = parser.meta.index.id.get(id)
|
|
41
43
|
if (index || index===0) {
|
|
42
44
|
return {
|
|
43
45
|
deref: () => {
|
|
@@ -47,7 +49,7 @@ export const metaIdProxy = {
|
|
|
47
49
|
}
|
|
48
50
|
},
|
|
49
51
|
has: (id) => {
|
|
50
|
-
return meta.index.id.has(id)
|
|
52
|
+
return parser.meta.index.id.has(id)
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
|
|
@@ -59,8 +61,11 @@ const metaReadProxy = {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
export async function initialize(task) {
|
|
64
|
+
if (task.meta) {
|
|
65
|
+
parser.meta = task.meta
|
|
66
|
+
}
|
|
62
67
|
for(let jsontag of task.data) {
|
|
63
|
-
dataspace = parse(jsontag
|
|
68
|
+
dataspace = parser.parse(jsontag)
|
|
64
69
|
}
|
|
65
70
|
resultArr = dataspace[resultSet]
|
|
66
71
|
meta = task.meta
|
|
@@ -88,7 +93,6 @@ export default async function runCommand(commandStr, request) {
|
|
|
88
93
|
let time = Date.now()
|
|
89
94
|
commands[task.name](dataspace, task, request, metaProxy)
|
|
90
95
|
//TODO: if command/task makes no changes, skip updating data.jsontag and writing it, skip response.data
|
|
91
|
-
JSONTag.setAttribute(dataspace, 'command', task.id)
|
|
92
96
|
|
|
93
97
|
const uint8sab = serialize(dataspace, {meta, changes: true}) // serialize only changes
|
|
94
98
|
response.data = uint8sab
|
package/src/load-worker.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { parentPort } from 'node:worker_threads'
|
|
2
2
|
import JSONTag from '@muze-nl/jsontag'
|
|
3
|
-
import
|
|
3
|
+
import Parser from '@muze-nl/od-jsontag/src/parse.mjs'
|
|
4
4
|
import fs from 'fs'
|
|
5
5
|
import serialize from '@muze-nl/od-jsontag/src/serialize.mjs'
|
|
6
6
|
|
|
7
|
+
const parser = new Parser()
|
|
7
8
|
parentPort.on('message', (files) => {
|
|
8
9
|
let meta = {
|
|
9
10
|
index: {
|
|
@@ -17,22 +18,20 @@ parentPort.on('message', (files) => {
|
|
|
17
18
|
let count = 0
|
|
18
19
|
let data
|
|
19
20
|
let jsontag
|
|
20
|
-
let tempMeta = {}
|
|
21
21
|
let datafile = files.dataFile
|
|
22
22
|
let commands = files.commands
|
|
23
23
|
commands.push('done')
|
|
24
24
|
do {
|
|
25
25
|
if (fs.existsSync(datafile)) {
|
|
26
26
|
jsontag = fs.readFileSync(datafile)
|
|
27
|
-
data = parse(jsontag
|
|
27
|
+
data = parser.parse(jsontag)
|
|
28
28
|
count++
|
|
29
29
|
}
|
|
30
30
|
datafile = basefile + '.' + commands.shift() + '.' + extension
|
|
31
31
|
} while(commands.length)
|
|
32
|
-
meta.parts = count
|
|
33
32
|
if (files.schemaFile) {
|
|
34
33
|
jsontag = fs.readFileSync(files.schemaFile, 'utf-8')
|
|
35
|
-
meta.schema = JSONTag.parse(jsontag
|
|
34
|
+
meta.schema = JSONTag.parse(jsontag)
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
const sab = serialize(data, {meta})
|
|
@@ -2,66 +2,28 @@ import pointer from 'json-pointer'
|
|
|
2
2
|
import {VM} from 'vm2'
|
|
3
3
|
import { memoryUsage } from 'node:process'
|
|
4
4
|
import JSONTag from '@muze-nl/jsontag'
|
|
5
|
-
import * as odJSONTag from '@muze-nl/od-jsontag/src/jsontag.mjs'
|
|
6
5
|
import {source} from '@muze-nl/od-jsontag/src/symbols.mjs'
|
|
7
|
-
import
|
|
6
|
+
import Parser from '@muze-nl/od-jsontag/src/parse.mjs'
|
|
8
7
|
import {_,from,not,anyOf,allOf,asc,desc,sum,count,avg,max,min,many,one,distinct} from '@muze-nl/jaqt'
|
|
9
8
|
import process from 'node:process'
|
|
10
9
|
|
|
11
10
|
let dataspace
|
|
12
|
-
let meta = {}
|
|
13
11
|
let metaProxy = {
|
|
14
12
|
index: {
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
if (target[source]) {
|
|
20
|
-
throw new Error('Data is immutable')
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const myJSONTag = {
|
|
25
|
-
getAttribute: odJSONTag.getAttribute,
|
|
26
|
-
getAttributes: odJSONTag.getAttributes,
|
|
27
|
-
getType: odJSONTag.getType,
|
|
28
|
-
getTypeString: odJSONTag.getTypeString,
|
|
29
|
-
setAttribute: (target, name, value) => {
|
|
30
|
-
protect(target)
|
|
31
|
-
return odJSONTag.setAttribute(target, name, value)
|
|
32
|
-
},
|
|
33
|
-
setType: (target, type) => {
|
|
34
|
-
protect(target)
|
|
35
|
-
return odJSONTag.setType(target, type)
|
|
36
|
-
},
|
|
37
|
-
setAttributes: (target, attributes) => {
|
|
38
|
-
protect(target)
|
|
39
|
-
return odJSONTag.setAttributes(target, attributes)
|
|
40
|
-
},
|
|
41
|
-
addAttribute: (target, name, value) => {
|
|
42
|
-
protect(target)
|
|
43
|
-
return odJSONTag.addAttribute(target, name, value)
|
|
44
|
-
},
|
|
45
|
-
removeAttribute: (target, name) => {
|
|
46
|
-
protect(target)
|
|
47
|
-
return odJSONTag.removeAttribute(target, name)
|
|
48
|
-
},
|
|
49
|
-
getAttributesString: odJSONTag.getAttributesString,
|
|
50
|
-
isNull: odJSONTag.isNull,
|
|
51
|
-
clone: JSONTag.clone,
|
|
52
|
-
Link: JSONTag.Link,
|
|
53
|
-
Null: JSONTag.Null
|
|
54
|
-
}
|
|
16
|
+
const parser = new Parser()
|
|
55
17
|
|
|
56
18
|
const metaIdProxy = {
|
|
57
19
|
get: (id) => {
|
|
58
|
-
let index = meta.index.id.get(id)
|
|
20
|
+
let index = parser.meta.index.id.get(id)
|
|
59
21
|
if (index || index===0) {
|
|
60
|
-
return meta.resultArray[index]
|
|
22
|
+
return parser.meta.resultArray[index]
|
|
61
23
|
}
|
|
62
24
|
},
|
|
63
25
|
has: (id) => {
|
|
64
|
-
return meta.index.id.has(id)
|
|
26
|
+
return parser.meta.index.id.has(id)
|
|
65
27
|
}
|
|
66
28
|
}
|
|
67
29
|
|
|
@@ -70,27 +32,27 @@ const tasks = {
|
|
|
70
32
|
if (task.req.access) {
|
|
71
33
|
task.req.access = await import(task.req.access)
|
|
72
34
|
task.req.access = task.req.access.default
|
|
73
|
-
meta.access = task.req.access
|
|
35
|
+
parser.meta.access = task.req.access
|
|
74
36
|
}
|
|
75
37
|
if (task.req.meta.index) {
|
|
76
|
-
meta.index = task.req.meta.index
|
|
38
|
+
parser.meta.index = task.req.meta.index
|
|
77
39
|
}
|
|
78
40
|
if (task.req.meta.schema) {
|
|
79
|
-
meta.schema = task.req.meta.schema
|
|
41
|
+
parser.meta.schema = task.req.meta.schema
|
|
80
42
|
}
|
|
81
43
|
for (let sab of task.req.body) { //body contains an array of sharedArrayBuffers with initial data and changes
|
|
82
|
-
dataspace = parse(sab
|
|
44
|
+
dataspace = parser.parse(sab)
|
|
83
45
|
}
|
|
84
46
|
metaProxy.index.id = metaIdProxy
|
|
85
|
-
metaProxy.schema = meta.schema
|
|
47
|
+
metaProxy.schema = parser.meta.schema
|
|
86
48
|
//@TODO: add meta.index.references? and baseURL
|
|
87
49
|
return true
|
|
88
50
|
},
|
|
89
51
|
update: async (task) => {
|
|
90
52
|
if (task.req.meta.index) {
|
|
91
|
-
meta.index = task.req.meta.index
|
|
53
|
+
parser.meta.index = task.req.meta.index
|
|
92
54
|
}
|
|
93
|
-
dataspace = parse(task.req.body
|
|
55
|
+
dataspace = parser.parse(task.req.body) //update only has a single changeset
|
|
94
56
|
return true
|
|
95
57
|
},
|
|
96
58
|
query: async (task) => {
|
|
@@ -139,7 +101,7 @@ export function runQuery(pointer, request, query) {
|
|
|
139
101
|
one,
|
|
140
102
|
distinct,
|
|
141
103
|
// console: connectConsole(res),
|
|
142
|
-
JSONTag
|
|
104
|
+
JSONTag,
|
|
143
105
|
request
|
|
144
106
|
},
|
|
145
107
|
wasm: false
|