@muze-nl/od-jsontag 0.2.3 → 0.2.5
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/parse.mjs +20 -19
- package/src/serialize.mjs +4 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muze-nl/od-jsontag",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "On Demand JSONTag: parse/serialize large datastructures on demand, useful for sharing data between threads",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Auke van Slooten <auke@muze.nl>",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "https://github.com/muze-nl/od-jsontag.git"
|
|
22
|
+
"url": "git+https://github.com/muze-nl/od-jsontag.git"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=20.0.0"
|
package/src/parse.mjs
CHANGED
|
@@ -14,15 +14,6 @@ function stringToSAB(strData) {
|
|
|
14
14
|
return uint8sab
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function JSONTagProxy(target, handler) {
|
|
18
|
-
let p = new Proxy(target, handler)
|
|
19
|
-
let a = JSONTag.getAttributes(target)
|
|
20
|
-
JSONTag.setAttributes(target, a)
|
|
21
|
-
let t = JSONTag.getType(target)
|
|
22
|
-
JSONTag.setType(target, t)
|
|
23
|
-
return p
|
|
24
|
-
}
|
|
25
|
-
|
|
26
17
|
export default function parse(input, meta, immutable=true)
|
|
27
18
|
{
|
|
28
19
|
if (!meta) {
|
|
@@ -703,7 +694,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
703
694
|
return undefined
|
|
704
695
|
}
|
|
705
696
|
if (Array.isArray(target[prop])) {
|
|
706
|
-
return
|
|
697
|
+
return new Proxy(target[prop], handlers.newArrayHandler)
|
|
707
698
|
}
|
|
708
699
|
return target[prop]
|
|
709
700
|
}
|
|
@@ -754,7 +745,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
754
745
|
return undefined
|
|
755
746
|
}
|
|
756
747
|
if (Array.isArray(target[prop])) {
|
|
757
|
-
return
|
|
748
|
+
return new Proxy(target[prop], handlers.newArrayHandler)
|
|
758
749
|
}
|
|
759
750
|
return target[prop]
|
|
760
751
|
break
|
|
@@ -798,7 +789,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
798
789
|
}
|
|
799
790
|
if (Array.isArray(target[prop])) {
|
|
800
791
|
target[prop][parent] = target[parent]
|
|
801
|
-
return
|
|
792
|
+
return new Proxy(target[prop], handlers.arrayHandler)
|
|
802
793
|
}
|
|
803
794
|
return target[prop]
|
|
804
795
|
}
|
|
@@ -834,7 +825,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
834
825
|
},
|
|
835
826
|
handler: {
|
|
836
827
|
get(target, prop, receiver) {
|
|
837
|
-
firstParse(target)
|
|
828
|
+
firstParse(target, receiver)
|
|
838
829
|
switch(prop) {
|
|
839
830
|
case resultSet:
|
|
840
831
|
return meta.resultArray
|
|
@@ -875,17 +866,17 @@ export default function parse(input, meta, immutable=true)
|
|
|
875
866
|
}
|
|
876
867
|
if (Array.isArray(target[prop])) {
|
|
877
868
|
target[prop][parent] = target
|
|
878
|
-
return
|
|
869
|
+
return new Proxy(target[prop], handlers.arrayHandler)
|
|
879
870
|
}
|
|
880
871
|
return target[prop]
|
|
881
872
|
break
|
|
882
873
|
}
|
|
883
874
|
},
|
|
884
|
-
set(target, prop, value) {
|
|
875
|
+
set(target, prop, value, receiver) {
|
|
885
876
|
if (immutable && prop!==resultSet && prop!==source) {
|
|
886
877
|
throw new Error('dataspace is immutable')
|
|
887
878
|
}
|
|
888
|
-
firstParse(target)
|
|
879
|
+
firstParse(target, receiver)
|
|
889
880
|
switch(prop) {
|
|
890
881
|
case isChanged:
|
|
891
882
|
break
|
|
@@ -955,10 +946,20 @@ export default function parse(input, meta, immutable=true)
|
|
|
955
946
|
}
|
|
956
947
|
}
|
|
957
948
|
|
|
958
|
-
const firstParse = function(target) {
|
|
949
|
+
const firstParse = function(target, receiver) {
|
|
959
950
|
if (!target[isParsed]) {
|
|
960
951
|
parseValue(target[position], target)
|
|
961
952
|
target[isParsed] = true
|
|
953
|
+
if (receiver) {
|
|
954
|
+
let tag = JSONTag.getType(target)
|
|
955
|
+
if (tag) {
|
|
956
|
+
JSONTag.setType(receiver, tag)
|
|
957
|
+
}
|
|
958
|
+
let attributes = JSONTag.getAttributes(target)
|
|
959
|
+
if (attributes) {
|
|
960
|
+
JSONTag.setAttributes(receiver, attributes)
|
|
961
|
+
}
|
|
962
|
+
}
|
|
962
963
|
}
|
|
963
964
|
}
|
|
964
965
|
|
|
@@ -973,7 +974,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
973
974
|
meta.resultArray.push('')
|
|
974
975
|
value[getIndex] = index
|
|
975
976
|
makeChildProxies(value)
|
|
976
|
-
let result =
|
|
977
|
+
let result = new Proxy(value, handlers.newValueHandler)
|
|
977
978
|
meta.resultArray[index] = result
|
|
978
979
|
return result
|
|
979
980
|
}
|
|
@@ -994,7 +995,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
994
995
|
next()
|
|
995
996
|
// newValueHandler makes sure that value[getBuffer] runs stringify
|
|
996
997
|
// arrayHandler makes sure that changes in the array set targetIsChanged to true
|
|
997
|
-
return
|
|
998
|
+
return new Proxy(cache, handlers.handler)
|
|
998
999
|
}
|
|
999
1000
|
|
|
1000
1001
|
value = function(ob={})
|
package/src/serialize.mjs
CHANGED
|
@@ -157,10 +157,7 @@ export default function serialize(value, options={}) {
|
|
|
157
157
|
let currentSource = 0
|
|
158
158
|
let currentResult = 0
|
|
159
159
|
let skipCount = 0
|
|
160
|
-
let result =
|
|
161
|
-
if (options.changes) {
|
|
162
|
-
result = []
|
|
163
|
-
}
|
|
160
|
+
let result = []
|
|
164
161
|
while(currentSource<resultArray.length) {
|
|
165
162
|
if (resultArray[currentSource][isChanged] || !resultArray[currentSource][isProxy]) {
|
|
166
163
|
if (skipCount) {
|
|
@@ -169,7 +166,7 @@ export default function serialize(value, options={}) {
|
|
|
169
166
|
currentResult++
|
|
170
167
|
}
|
|
171
168
|
result[currentResult] = encoder.encode(innerStringify(currentSource))
|
|
172
|
-
if (options.meta
|
|
169
|
+
if (options.meta) {
|
|
173
170
|
const id=odJSONTag.getAttribute(resultArray[currentSource],'id')
|
|
174
171
|
if (id) {
|
|
175
172
|
options.meta.index.id.set(id, currentSource)
|
|
@@ -177,8 +174,8 @@ export default function serialize(value, options={}) {
|
|
|
177
174
|
}
|
|
178
175
|
currentResult++
|
|
179
176
|
} else if (!options.changes) {
|
|
180
|
-
|
|
181
|
-
if (options.meta
|
|
177
|
+
result[currentResult] = resultArray[currentSource][getBuffer](currentSource)
|
|
178
|
+
if (options.meta) {
|
|
182
179
|
const id=odJSONTag.getAttribute(resultArray[currentSource],'id')
|
|
183
180
|
if (id) {
|
|
184
181
|
options.meta.index.id.set(id, currentSource)
|