@muze-nl/simplystore 0.5.8 → 0.6.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 +2 -2
- package/src/command-worker-module.mjs +4 -3
- package/src/fastParse.mjs +82 -97
- package/src/fastStringify.mjs +0 -9
- package/src/query-worker-module.mjs +6 -6
- package/src/symbols.mjs +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muze-nl/simplystore",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"main": "src/server.mjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"homepage": "https://github.com/simplyedit/simplystore#readme",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@muze-nl/jsontag": "^0.9.1",
|
|
20
|
-
"
|
|
20
|
+
"jaqt": "^0.6.0",
|
|
21
21
|
"codemirror": "^6.0.1",
|
|
22
22
|
"express": "^4.18.1",
|
|
23
23
|
"json-pointer": "^0.6.2",
|
|
@@ -3,6 +3,7 @@ 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'
|
|
6
|
+
import {_,from,not,anyOf,allOf,asc,desc,sum,count,avg,max,min} from 'jaqt'
|
|
6
7
|
|
|
7
8
|
let commands = {}
|
|
8
9
|
let resultSet = []
|
|
@@ -86,6 +87,7 @@ export default async function runCommand(commandStr, request) {
|
|
|
86
87
|
if (commands[task.name]) {
|
|
87
88
|
let time = Date.now()
|
|
88
89
|
commands[task.name](dataspace, task, request, metaProxy)
|
|
90
|
+
//TODO: if command/task makes no changes, skip updating data.jsontag and writing it, skip response.data
|
|
89
91
|
FastJSONTag.setAttribute(dataspace, 'command', task.id)
|
|
90
92
|
|
|
91
93
|
const strData = resultSetStringify(resultSet)
|
|
@@ -96,7 +98,7 @@ export default async function runCommand(commandStr, request) {
|
|
|
96
98
|
id: meta.index.id
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
|
-
|
|
101
|
+
//TODO: write data every x commands or x minutes, in seperate thread
|
|
100
102
|
await writeFileAtomic(datafile, uint8sab)
|
|
101
103
|
let end = Date.now()
|
|
102
104
|
console.log('task time',end-time)
|
|
@@ -108,5 +110,4 @@ export default async function runCommand(commandStr, request) {
|
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
return response
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
+
}
|
package/src/fastParse.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import JSONTag from '@muze-nl/jsontag';
|
|
2
2
|
import Null from '@muze-nl/jsontag/src/lib/Null.mjs'
|
|
3
3
|
import fastStringify from './fastStringify.mjs'
|
|
4
|
-
import {source,isProxy,getBuffer,getIndex,isChanged} from './symbols.mjs'
|
|
4
|
+
import {source,isProxy,getBuffer,getIndex,isChanged,isParsed,position,parent} from './symbols.mjs'
|
|
5
5
|
|
|
6
6
|
const decoder = new TextDecoder()
|
|
7
7
|
const encoder = new TextEncoder()
|
|
@@ -36,6 +36,10 @@ export default function parse(input, meta, immutable=true)
|
|
|
36
36
|
t: "\t"
|
|
37
37
|
}
|
|
38
38
|
let offsetArray = []
|
|
39
|
+
let resultArray = []
|
|
40
|
+
|
|
41
|
+
at = 0
|
|
42
|
+
ch = " "
|
|
39
43
|
|
|
40
44
|
let error = function(m)
|
|
41
45
|
{
|
|
@@ -58,7 +62,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
58
62
|
let next = function(c)
|
|
59
63
|
{
|
|
60
64
|
if (c && c!==ch) {
|
|
61
|
-
error("Expected '"+c+"' instead of '"+ch+"'")
|
|
65
|
+
error("Expected '"+c+"' instead of '"+ch+"': "+at+':'+input)
|
|
62
66
|
}
|
|
63
67
|
ch = String.fromCharCode(input.at(at))
|
|
64
68
|
at+=1
|
|
@@ -658,10 +662,8 @@ export default function parse(input, meta, immutable=true)
|
|
|
658
662
|
})
|
|
659
663
|
}
|
|
660
664
|
|
|
661
|
-
const
|
|
662
|
-
|
|
663
|
-
resultArray.push('')
|
|
664
|
-
let arrayHandler = {
|
|
665
|
+
const handlers = {
|
|
666
|
+
newArrayHandler: {
|
|
665
667
|
get(target, prop) {
|
|
666
668
|
if (target[prop] instanceof Function) {
|
|
667
669
|
return (...args) => {
|
|
@@ -677,7 +679,8 @@ export default function parse(input, meta, immutable=true)
|
|
|
677
679
|
return true
|
|
678
680
|
} else {
|
|
679
681
|
if (Array.isArray(target[prop])) {
|
|
680
|
-
|
|
682
|
+
// console.log('proxying array with newArrayHandler')
|
|
683
|
+
return new Proxy(target[prop], handlers.newArrayHandler)
|
|
681
684
|
}
|
|
682
685
|
return target[prop]
|
|
683
686
|
}
|
|
@@ -689,8 +692,8 @@ export default function parse(input, meta, immutable=true)
|
|
|
689
692
|
target[prop] = value
|
|
690
693
|
return true
|
|
691
694
|
}
|
|
692
|
-
}
|
|
693
|
-
|
|
695
|
+
},
|
|
696
|
+
newValueHandler: {
|
|
694
697
|
get(target, prop, receiver) {
|
|
695
698
|
switch(prop) {
|
|
696
699
|
case source:
|
|
@@ -701,6 +704,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
701
704
|
break
|
|
702
705
|
case getBuffer:
|
|
703
706
|
return (i) => {
|
|
707
|
+
let index = target[getIndex]
|
|
704
708
|
if (i != index) {
|
|
705
709
|
return encoder.encode('~'+index)
|
|
706
710
|
}
|
|
@@ -709,14 +713,15 @@ export default function parse(input, meta, immutable=true)
|
|
|
709
713
|
}
|
|
710
714
|
break
|
|
711
715
|
case getIndex:
|
|
712
|
-
return
|
|
716
|
+
return target[getIndex]
|
|
713
717
|
break
|
|
714
718
|
case isChanged:
|
|
715
719
|
return true
|
|
716
720
|
break
|
|
717
721
|
default:
|
|
718
722
|
if (Array.isArray(target[prop])) {
|
|
719
|
-
|
|
723
|
+
// console.log('proxying array with newArrayHandler')
|
|
724
|
+
return new Proxy(target[prop], handlers.newArrayHandler)
|
|
720
725
|
}
|
|
721
726
|
return target[prop]
|
|
722
727
|
break
|
|
@@ -729,44 +734,18 @@ export default function parse(input, meta, immutable=true)
|
|
|
729
734
|
target[prop] = value
|
|
730
735
|
return true
|
|
731
736
|
}
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
makeChildProxies(value)
|
|
735
|
-
let result = new Proxy(value, newValueHandler)
|
|
736
|
-
resultArray[index] = result
|
|
737
|
-
return result
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
let valueProxy = function(length, index)
|
|
741
|
-
{
|
|
742
|
-
// current offset + length contains jsontag of this value
|
|
743
|
-
let position = {
|
|
744
|
-
start: at-1,
|
|
745
|
-
end: at-1+length
|
|
746
|
-
}
|
|
747
|
-
let cache = {}
|
|
748
|
-
let targetIsChanged = false
|
|
749
|
-
let parsed = false
|
|
750
|
-
at += length
|
|
751
|
-
next()
|
|
752
|
-
let firstParse = function() {
|
|
753
|
-
if (!parsed) {
|
|
754
|
-
parseValue(position, cache)
|
|
755
|
-
parsed = true
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
// newValueHandler makes sure that value[getBuffer] runs stringify
|
|
759
|
-
// arrayHandler makes sure that changes in the array set targetIsChanged to true
|
|
760
|
-
let arrayHandler = {
|
|
737
|
+
},
|
|
738
|
+
arrayHandler: {
|
|
761
739
|
get(target, prop) {
|
|
762
740
|
if (target[prop] instanceof Function) {
|
|
763
741
|
if (['copyWithin','fill','pop','push','reverse','shift','sort','splice','unshift'].indexOf(prop)!==-1) {
|
|
764
742
|
if (immutable) {
|
|
765
743
|
throw new Error('dataspace is immutable')
|
|
766
744
|
}
|
|
767
|
-
|
|
745
|
+
// console.log('getting array function '+prop)
|
|
768
746
|
}
|
|
769
747
|
return (...args) => {
|
|
748
|
+
// console.log('calling array function '+prop)
|
|
770
749
|
args = args.map(arg => {
|
|
771
750
|
if (JSONTag.getType(arg)==='object' && !arg[isProxy]) {
|
|
772
751
|
console.log('proxying arg')
|
|
@@ -774,13 +753,18 @@ export default function parse(input, meta, immutable=true)
|
|
|
774
753
|
}
|
|
775
754
|
return arg
|
|
776
755
|
})
|
|
777
|
-
|
|
756
|
+
target[parent][isChanged] = true // incorrect target for isChanged...
|
|
757
|
+
let result = target[prop].apply(target, args)
|
|
758
|
+
// console.log('target',target,result)
|
|
759
|
+
return result
|
|
778
760
|
}
|
|
779
761
|
} else if (prop===isChanged) {
|
|
780
|
-
return
|
|
762
|
+
return target[parent][isChanged]
|
|
781
763
|
} else {
|
|
782
764
|
if (!immutable && Array.isArray(target[prop])) {
|
|
783
|
-
|
|
765
|
+
// console.log('proxying array with arrayHandler')
|
|
766
|
+
target[prop][parent] = target[parent]
|
|
767
|
+
return new Proxy(target[prop], handlers.arrayHandler)
|
|
784
768
|
}
|
|
785
769
|
return target[prop]
|
|
786
770
|
}
|
|
@@ -793,7 +777,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
793
777
|
value = getNewValueProxy(value)
|
|
794
778
|
}
|
|
795
779
|
target[prop] = value
|
|
796
|
-
|
|
780
|
+
target[parent][isChanged] = true
|
|
797
781
|
return true
|
|
798
782
|
},
|
|
799
783
|
deleteProperty(target, prop) {
|
|
@@ -804,7 +788,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
804
788
|
//that object should be deleted so that its line will become empty
|
|
805
789
|
//when stringifying resultArray again
|
|
806
790
|
delete target[prop]
|
|
807
|
-
|
|
791
|
+
target[parent][isChanged] = true
|
|
808
792
|
return true
|
|
809
793
|
},
|
|
810
794
|
ownKeys: (target) => {
|
|
@@ -816,10 +800,10 @@ export default function parse(input, meta, immutable=true)
|
|
|
816
800
|
configurable: true
|
|
817
801
|
}
|
|
818
802
|
}
|
|
819
|
-
}
|
|
820
|
-
|
|
803
|
+
},
|
|
804
|
+
handler: {
|
|
821
805
|
get(target, prop, receiver) {
|
|
822
|
-
firstParse()
|
|
806
|
+
firstParse(target)
|
|
823
807
|
switch(prop) {
|
|
824
808
|
case source:
|
|
825
809
|
return target
|
|
@@ -829,26 +813,29 @@ export default function parse(input, meta, immutable=true)
|
|
|
829
813
|
break
|
|
830
814
|
case getBuffer:
|
|
831
815
|
return (i) => {
|
|
816
|
+
let index = target[getIndex]
|
|
832
817
|
if (i != index) {
|
|
833
818
|
return encoder.encode('~'+index)
|
|
834
819
|
}
|
|
835
|
-
if (
|
|
820
|
+
if (target[isChanged]) {
|
|
836
821
|
// return newly stringified contents of cache
|
|
837
822
|
let temp = fastStringify(target, null, true)
|
|
838
823
|
return encoder.encode(fastStringify(target, null, true))
|
|
839
824
|
}
|
|
840
|
-
return input.slice(position.start,position.end)
|
|
825
|
+
return input.slice(target[position].start,target[position].end)
|
|
841
826
|
}
|
|
842
827
|
break
|
|
843
828
|
case getIndex:
|
|
844
|
-
return
|
|
829
|
+
return target[getIndex]
|
|
845
830
|
break
|
|
846
831
|
case isChanged:
|
|
847
|
-
return
|
|
832
|
+
return target[isChanged]
|
|
848
833
|
break
|
|
849
834
|
default:
|
|
850
835
|
if (!immutable && Array.isArray(target[prop])) {
|
|
851
|
-
|
|
836
|
+
// console.log('proxying array with arrayHandler')
|
|
837
|
+
target[prop][parent] = target
|
|
838
|
+
return new Proxy(target[prop], handlers.arrayHandler)
|
|
852
839
|
}
|
|
853
840
|
return target[prop]
|
|
854
841
|
break
|
|
@@ -856,31 +843,66 @@ export default function parse(input, meta, immutable=true)
|
|
|
856
843
|
},
|
|
857
844
|
set(target, prop, value) {
|
|
858
845
|
if (!immutable) {
|
|
859
|
-
firstParse()
|
|
846
|
+
firstParse(target)
|
|
860
847
|
if (prop!==isChanged) {
|
|
861
848
|
if (JSONTag.getType(value)==='object' && !value[isProxy]) {
|
|
862
849
|
value = getNewValueProxy(value)
|
|
863
850
|
}
|
|
864
851
|
target[prop] = value
|
|
865
852
|
}
|
|
866
|
-
|
|
853
|
+
target[isChanged] = true
|
|
867
854
|
return true
|
|
868
855
|
}
|
|
869
856
|
},
|
|
870
857
|
deleteProperty: (target, prop) => {
|
|
871
858
|
if (!immutable) {
|
|
872
|
-
firstParse()
|
|
859
|
+
firstParse(target)
|
|
873
860
|
delete target[prop]
|
|
874
|
-
|
|
861
|
+
target[isChanged] = true
|
|
875
862
|
return true
|
|
876
863
|
}
|
|
877
864
|
},
|
|
878
865
|
'ownKeys': (target) => {
|
|
879
|
-
firstParse()
|
|
866
|
+
firstParse(target)
|
|
880
867
|
return Reflect.ownKeys(target)
|
|
881
868
|
}
|
|
882
869
|
}
|
|
883
|
-
|
|
870
|
+
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
const firstParse = function(target) {
|
|
874
|
+
if (!target[isParsed]) {
|
|
875
|
+
parseValue(target[position], target)
|
|
876
|
+
target[isParsed] = true
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
const getNewValueProxy = function(value) {
|
|
881
|
+
let index = resultArray.length
|
|
882
|
+
resultArray.push('')
|
|
883
|
+
value[getIndex] = index
|
|
884
|
+
makeChildProxies(value)
|
|
885
|
+
let result = new Proxy(value, handlers.newValueHandler)
|
|
886
|
+
resultArray[index] = result
|
|
887
|
+
return result
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
let valueProxy = function(length, index)
|
|
891
|
+
{
|
|
892
|
+
let cache = {}
|
|
893
|
+
cache[getIndex] = index
|
|
894
|
+
cache[isChanged] = false
|
|
895
|
+
cache[isParsed] = false
|
|
896
|
+
// current offset + length contains jsontag of this value
|
|
897
|
+
cache[position] = {
|
|
898
|
+
start: at-1,
|
|
899
|
+
end: at-1+length
|
|
900
|
+
}
|
|
901
|
+
at += length
|
|
902
|
+
next()
|
|
903
|
+
// newValueHandler makes sure that value[getBuffer] runs stringify
|
|
904
|
+
// arrayHandler makes sure that changes in the array set targetIsChanged to true
|
|
905
|
+
return new Proxy(cache, handlers.handler)
|
|
884
906
|
}
|
|
885
907
|
|
|
886
908
|
value = function(ob={})
|
|
@@ -960,9 +982,6 @@ export default function parse(input, meta, immutable=true)
|
|
|
960
982
|
return [l, v]
|
|
961
983
|
}
|
|
962
984
|
|
|
963
|
-
at = 0
|
|
964
|
-
ch = " "
|
|
965
|
-
let resultArray = []
|
|
966
985
|
while(ch && at<input.length) {
|
|
967
986
|
result = lengthValue(resultArray.length)
|
|
968
987
|
whitespace()
|
|
@@ -970,40 +989,6 @@ export default function parse(input, meta, immutable=true)
|
|
|
970
989
|
resultArray.push(result[1])
|
|
971
990
|
}
|
|
972
991
|
|
|
973
|
-
if (typeof reviver === 'function') {
|
|
974
|
-
function walk(holder, key)
|
|
975
|
-
{
|
|
976
|
-
var k;
|
|
977
|
-
var v;
|
|
978
|
-
var value = holder[key];
|
|
979
|
-
if (value !== null
|
|
980
|
-
&& typeof value === "object"
|
|
981
|
-
&& !(value instanceof String
|
|
982
|
-
|| value instanceof Number
|
|
983
|
-
|| value instanceof Boolean)
|
|
984
|
-
) {
|
|
985
|
-
for (k in value) {
|
|
986
|
-
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
987
|
-
v = walk(value, k);
|
|
988
|
-
if (v !== undefined
|
|
989
|
-
&& ( typeof value[k] === 'undefined' || value[k]!==v) )
|
|
990
|
-
{
|
|
991
|
-
value[k] = v;
|
|
992
|
-
if (JSONTag.getType(v)==='link') {
|
|
993
|
-
checkUnresolved(v, value, k)
|
|
994
|
-
}
|
|
995
|
-
} else if (v === undefined) {
|
|
996
|
-
delete value[k];
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
return reviver.call(holder, key, value, meta);
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
walk({"":result}, "")
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
992
|
let replaceLink = function(u,value)
|
|
1008
993
|
{
|
|
1009
994
|
if (typeof value !== 'undefined') {
|
package/src/fastStringify.mjs
CHANGED
|
@@ -100,15 +100,6 @@ export default function stringify(value, meta, skipLength=false, index=false) {
|
|
|
100
100
|
// is only ever called on object values
|
|
101
101
|
// and should always return a stringified object, not a reference (~n)
|
|
102
102
|
const innerStringify = (current) => {
|
|
103
|
-
let indent = ""
|
|
104
|
-
let gap = ""
|
|
105
|
-
|
|
106
|
-
if (typeof space === "number") {
|
|
107
|
-
indent += " ".repeat(space)
|
|
108
|
-
} else if (typeof space === "string") {
|
|
109
|
-
indent = space
|
|
110
|
-
}
|
|
111
|
-
|
|
112
103
|
let object = resultArray[current]
|
|
113
104
|
let result
|
|
114
105
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import JSONTag from '@muze-nl/jsontag'
|
|
2
2
|
import fastParse from './fastParse.mjs'
|
|
3
3
|
import {source, isProxy} from './symbols.mjs'
|
|
4
|
-
import {_,from,not,anyOf,allOf,asc,desc,sum,count,avg,max,min} from '
|
|
4
|
+
import {_,from,not,anyOf,allOf,asc,desc,sum,count,avg,max,min} from 'jaqt'
|
|
5
5
|
import pointer from 'json-pointer'
|
|
6
6
|
import {VM} from 'vm2'
|
|
7
7
|
import { memoryUsage } from 'node:process'
|
|
@@ -27,11 +27,11 @@ const metaIdProxy = {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const FastJSONTag = {
|
|
30
|
-
getType: (obj) => JSONTag.getType(obj[source]),
|
|
31
|
-
getAttribute: (obj, attr) => JSONTag.getAttribute(obj[source],attr),
|
|
32
|
-
getAttributes: (obj) => JSONTag.getAttributes(obj[source]),
|
|
33
|
-
getAttributeString: (obj) => JSONTag.getAttributesString(obj[source]),
|
|
34
|
-
getTypeString: (obj) => JSONTag.getTypeString(obj[source])
|
|
30
|
+
getType: (obj) => JSONTag.getType(obj?.[source]),
|
|
31
|
+
getAttribute: (obj, attr) => JSONTag.getAttribute(obj?.[source],attr),
|
|
32
|
+
getAttributes: (obj) => JSONTag.getAttributes(obj?.[source]),
|
|
33
|
+
getAttributeString: (obj) => JSONTag.getAttributesString(obj?.[source]),
|
|
34
|
+
getTypeString: (obj) => JSONTag.getTypeString(obj?.[source])
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const tasks = {
|
package/src/symbols.mjs
CHANGED
|
@@ -3,4 +3,7 @@ export const isProxy = Symbol('isProxy')
|
|
|
3
3
|
export const getBuffer = Symbol('getBuffer')
|
|
4
4
|
export const getIndex = Symbol('getIndex')
|
|
5
5
|
export const isChanged = Symbol('isChanged')
|
|
6
|
-
export const
|
|
6
|
+
export const isParsed = Symbol('isParsed')
|
|
7
|
+
export const getString = Symbol('getString')
|
|
8
|
+
export const position = Symbol('position')
|
|
9
|
+
export const parent = Symbol('parent')
|