@muze-nl/simplystore 0.5.6 → 0.5.8
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 +1 -1
- package/src/command-worker-module.mjs +17 -8
- package/src/fastParse.mjs +22 -4
- package/src/server.mjs +3 -3
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import JSONTag from '@muze-nl/jsontag'
|
|
2
|
-
import {source, isChanged} from './symbols.mjs'
|
|
2
|
+
import {source, isChanged, getIndex} from './symbols.mjs'
|
|
3
3
|
import fastParse from './fastParse.mjs'
|
|
4
4
|
import {stringToSAB,resultSetStringify} from './fastStringify.mjs'
|
|
5
5
|
import writeFileAtomic from 'write-file-atomic'
|
|
@@ -25,8 +25,16 @@ export const metaIdProxy = {
|
|
|
25
25
|
})
|
|
26
26
|
},
|
|
27
27
|
set: (id,ref) => {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (!meta.index.id.has(id)) {
|
|
29
|
+
if (ref[getIndex]) {
|
|
30
|
+
meta.index.id.set(id, ref[getIndex])
|
|
31
|
+
} else {
|
|
32
|
+
throw new Error('cannot set index.id for non-proxy')
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
let line = meta.index.id.get(id)
|
|
36
|
+
resultSet[line] = ref
|
|
37
|
+
}
|
|
30
38
|
},
|
|
31
39
|
get: (id) => {
|
|
32
40
|
let index = meta.index.id.get(id)
|
|
@@ -44,15 +52,16 @@ export const metaIdProxy = {
|
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
export const FastJSONTag = {
|
|
47
|
-
getType: (obj) => JSONTag.getType(obj[source]),
|
|
48
|
-
getAttribute: (obj, attr) => JSONTag.getAttribute(obj[source],attr),
|
|
55
|
+
getType: (obj) => JSONTag.getType(obj?.[source]),
|
|
56
|
+
getAttribute: (obj, attr) => JSONTag.getAttribute(obj?.[source],attr),
|
|
49
57
|
setAttribute: (obj, attr, value) => {
|
|
58
|
+
if (!obj) return
|
|
50
59
|
obj[isChanged] = true
|
|
51
60
|
return JSONTag.setAttribute(obj[source], attr, value)
|
|
52
61
|
},
|
|
53
|
-
getAttributes: (obj) => JSONTag.getAttributes(obj[source]),
|
|
54
|
-
getAttributeString: (obj) => JSONTag.getAttributesString(obj[source]),
|
|
55
|
-
getTypeString: (obj) => JSONTag.getTypeString(obj[source])
|
|
62
|
+
getAttributes: (obj) => JSONTag.getAttributes(obj?.[source]),
|
|
63
|
+
getAttributeString: (obj) => JSONTag.getAttributesString(obj?.[source]),
|
|
64
|
+
getTypeString: (obj) => JSONTag.getTypeString(obj?.[source])
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
export async function initialize(task) {
|
package/src/fastParse.mjs
CHANGED
|
@@ -726,7 +726,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
726
726
|
if (JSONTag.getType(value)==='object' && !value[isProxy]) {
|
|
727
727
|
value = getNewValueProxy(value)
|
|
728
728
|
}
|
|
729
|
-
target[prop] =
|
|
729
|
+
target[prop] = value
|
|
730
730
|
return true
|
|
731
731
|
}
|
|
732
732
|
}
|
|
@@ -761,11 +761,15 @@ export default function parse(input, meta, immutable=true)
|
|
|
761
761
|
get(target, prop) {
|
|
762
762
|
if (target[prop] instanceof Function) {
|
|
763
763
|
if (['copyWithin','fill','pop','push','reverse','shift','sort','splice','unshift'].indexOf(prop)!==-1) {
|
|
764
|
+
if (immutable) {
|
|
765
|
+
throw new Error('dataspace is immutable')
|
|
766
|
+
}
|
|
764
767
|
targetIsChanged = true
|
|
765
768
|
}
|
|
766
769
|
return (...args) => {
|
|
767
770
|
args = args.map(arg => {
|
|
768
771
|
if (JSONTag.getType(arg)==='object' && !arg[isProxy]) {
|
|
772
|
+
console.log('proxying arg')
|
|
769
773
|
arg = getNewValueProxy(arg)
|
|
770
774
|
}
|
|
771
775
|
return arg
|
|
@@ -782,6 +786,9 @@ export default function parse(input, meta, immutable=true)
|
|
|
782
786
|
}
|
|
783
787
|
},
|
|
784
788
|
set(target, prop, value) {
|
|
789
|
+
if (immutable) {
|
|
790
|
+
throw new Error('dataspace is immutable')
|
|
791
|
+
}
|
|
785
792
|
if (JSONTag.getType(value)==='object' && !value[isProxy]) {
|
|
786
793
|
value = getNewValueProxy(value)
|
|
787
794
|
}
|
|
@@ -790,12 +797,24 @@ export default function parse(input, meta, immutable=true)
|
|
|
790
797
|
return true
|
|
791
798
|
},
|
|
792
799
|
deleteProperty(target, prop) {
|
|
800
|
+
if (immutable) {
|
|
801
|
+
throw new Error('dataspace is immutable')
|
|
802
|
+
}
|
|
793
803
|
//FIXME: if target[prop] was the last reference to an object
|
|
794
804
|
//that object should be deleted so that its line will become empty
|
|
795
805
|
//when stringifying resultArray again
|
|
796
806
|
delete target[prop]
|
|
797
807
|
targetIsChanged = true
|
|
798
808
|
return true
|
|
809
|
+
},
|
|
810
|
+
ownKeys: (target) => {
|
|
811
|
+
return Reflect.ownKeys(target)
|
|
812
|
+
},
|
|
813
|
+
getOwnPropertyDescriptor: (target, prop) => {
|
|
814
|
+
return {
|
|
815
|
+
enumerable: true,
|
|
816
|
+
configurable: true
|
|
817
|
+
}
|
|
799
818
|
}
|
|
800
819
|
}
|
|
801
820
|
let handler = {
|
|
@@ -831,7 +850,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
831
850
|
if (!immutable && Array.isArray(target[prop])) {
|
|
832
851
|
return new Proxy(target[prop], arrayHandler)
|
|
833
852
|
}
|
|
834
|
-
return target[prop]
|
|
853
|
+
return target[prop]
|
|
835
854
|
break
|
|
836
855
|
}
|
|
837
856
|
},
|
|
@@ -1021,5 +1040,4 @@ export default function parse(input, meta, immutable=true)
|
|
|
1021
1040
|
}
|
|
1022
1041
|
|
|
1023
1042
|
return resultArray
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1043
|
+
}
|
package/src/server.mjs
CHANGED
|
@@ -289,12 +289,12 @@ async function main(options) {
|
|
|
289
289
|
})
|
|
290
290
|
|
|
291
291
|
function checkCommand(req, res) {
|
|
292
|
-
let error
|
|
292
|
+
let error, command, commandOK
|
|
293
293
|
let commandStr = req.body.toString() // raw body through express.raw()
|
|
294
294
|
try {
|
|
295
|
-
|
|
295
|
+
command = JSONTag.parse(commandStr)
|
|
296
296
|
|
|
297
|
-
|
|
297
|
+
commandOK = {
|
|
298
298
|
command: command?.id,
|
|
299
299
|
code: 202,
|
|
300
300
|
status: 'accepted'
|