@muze-nl/od-jsontag 0.2.1 → 0.2.3

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.1",
3
+ "version": "0.2.3",
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
@@ -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 serialize from './serialize.mjs'
4
- import {source,isProxy,getBuffer,getIndex,isChanged,isParsed,position,parent,resultSet} from './symbols.mjs'
4
+ import {source,isProxy,proxyType,getBuffer,getIndex,isChanged,isParsed,position,parent,resultSet} from './symbols.mjs'
5
5
 
6
6
  const decoder = new TextDecoder()
7
7
  const encoder = new TextEncoder()
@@ -731,13 +731,16 @@ export default function parse(input, meta, immutable=true)
731
731
  case isProxy:
732
732
  return true
733
733
  break
734
+ case proxyType:
735
+ return 'new'
736
+ break
734
737
  case getBuffer:
735
738
  return (i) => {
736
739
  let index = target[getIndex]
737
740
  if (i != index) {
738
741
  return encoder.encode('~'+index)
739
742
  }
740
- return serialize(target, meta, true, i)
743
+ return serialize(target, {meta, skipLength:true})
741
744
  }
742
745
  break
743
746
  case getIndex:
@@ -845,6 +848,9 @@ export default function parse(input, meta, immutable=true)
845
848
  case isProxy:
846
849
  return true
847
850
  break
851
+ case proxyType:
852
+ return 'parse'
853
+ break
848
854
  case getBuffer:
849
855
  return (i) => {
850
856
  let index = target[getIndex]
@@ -852,7 +858,7 @@ export default function parse(input, meta, immutable=true)
852
858
  return encoder.encode('~'+index)
853
859
  }
854
860
  if (target[isChanged]) {
855
- return serialize(target, null, true)
861
+ return serialize(target, {skipLength: true})
856
862
  }
857
863
  return target[position].input.slice(target[position].start,target[position].end)
858
864
  }
@@ -887,6 +893,7 @@ export default function parse(input, meta, immutable=true)
887
893
  resetObject(target)
888
894
  target[position] = value[position]
889
895
  target[isParsed] = false
896
+ target[isChanged] = false
890
897
  return true
891
898
  break
892
899
  case resultSet:
@@ -1084,7 +1091,7 @@ export default function parse(input, meta, immutable=true)
1084
1091
  offsetArray.push(at)
1085
1092
  line = result[2]
1086
1093
  if (result[1]) {
1087
- if (!meta.resultArray[line]) {
1094
+ if (!meta.resultArray[line] || meta.resultArray[line][proxyType]=='new') {
1088
1095
  meta.resultArray[line] = result[1]
1089
1096
  } else {
1090
1097
  meta.resultArray[line][source] = result[1]
package/src/serialize.mjs CHANGED
@@ -19,6 +19,15 @@ export default function serialize(value, options={}) {
19
19
  let resultArray = []
20
20
  let references = new WeakMap()
21
21
 
22
+ if (options.meta) {
23
+ if (!options.meta.index) {
24
+ options.meta.index = {}
25
+ }
26
+ if (!options.meta.index.id) {
27
+ options.meta.index.id = new Map()
28
+ }
29
+ }
30
+
22
31
  function stringifyValue(value, inarray=false) {
23
32
  let prop
24
33
  let typeString = odJSONTag.getTypeString(value)
@@ -160,9 +169,21 @@ export default function serialize(value, options={}) {
160
169
  currentResult++
161
170
  }
162
171
  result[currentResult] = encoder.encode(innerStringify(currentSource))
172
+ if (options.meta?.index?.id) {
173
+ const id=odJSONTag.getAttribute(resultArray[currentSource],'id')
174
+ if (id) {
175
+ options.meta.index.id.set(id, currentSource)
176
+ }
177
+ }
163
178
  currentResult++
164
179
  } else if (!options.changes) {
165
180
  resultArray[currentResult] = resultArray[currentSource][getBuffer](currentSource)
181
+ if (options.meta?.index?.id) {
182
+ const id=odJSONTag.getAttribute(resultArray[currentSource],'id')
183
+ if (id) {
184
+ options.meta.index.id.set(id, currentSource)
185
+ }
186
+ }
166
187
  currentResult++
167
188
  } else {
168
189
  skipCount++
package/src/symbols.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  export const source = Symbol('source')
2
2
  export const isProxy = Symbol('isProxy')
3
+ export const proxyType = Symbol('proxyType')
3
4
  export const getBuffer = Symbol('getBuffer')
4
5
  export const getIndex = Symbol('getIndex')
5
6
  export const isChanged = Symbol('isChanged')