@muze-nl/od-jsontag 0.2.2 → 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.2",
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
@@ -740,7 +740,7 @@ export default function parse(input, meta, immutable=true)
740
740
  if (i != index) {
741
741
  return encoder.encode('~'+index)
742
742
  }
743
- return serialize(target, meta, true, i)
743
+ return serialize(target, {meta, skipLength:true})
744
744
  }
745
745
  break
746
746
  case getIndex:
@@ -858,7 +858,7 @@ export default function parse(input, meta, immutable=true)
858
858
  return encoder.encode('~'+index)
859
859
  }
860
860
  if (target[isChanged]) {
861
- return serialize(target, null, true)
861
+ return serialize(target, {skipLength: true})
862
862
  }
863
863
  return target[position].input.slice(target[position].start,target[position].end)
864
864
  }
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++