@muze-nl/od-jsontag 0.2.3 → 0.2.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muze-nl/od-jsontag",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
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>",
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 JSONTagProxy(target[prop], handlers.newArrayHandler)
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 JSONTagProxy(target[prop], handlers.newArrayHandler)
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 JSONTagProxy(target[prop], handlers.arrayHandler)
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 JSONTagProxy(target[prop], handlers.arrayHandler)
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 = JSONTagProxy(value, handlers.newValueHandler)
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 JSONTagProxy(cache, handlers.handler)
998
+ return new Proxy(cache, handlers.handler)
998
999
  }
999
1000
 
1000
1001
  value = function(ob={})
package/src/serialize.mjs CHANGED
@@ -169,7 +169,7 @@ export default function serialize(value, options={}) {
169
169
  currentResult++
170
170
  }
171
171
  result[currentResult] = encoder.encode(innerStringify(currentSource))
172
- if (options.meta?.index?.id) {
172
+ if (options.meta) {
173
173
  const id=odJSONTag.getAttribute(resultArray[currentSource],'id')
174
174
  if (id) {
175
175
  options.meta.index.id.set(id, currentSource)
@@ -178,7 +178,7 @@ export default function serialize(value, options={}) {
178
178
  currentResult++
179
179
  } else if (!options.changes) {
180
180
  resultArray[currentResult] = resultArray[currentSource][getBuffer](currentSource)
181
- if (options.meta?.index?.id) {
181
+ if (options.meta) {
182
182
  const id=odJSONTag.getAttribute(resultArray[currentSource],'id')
183
183
  if (id) {
184
184
  options.meta.index.id.set(id, currentSource)