seroval 0.12.0 → 0.12.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.
@@ -229,12 +229,13 @@ var GLOBAL_CONTEXT_PROMISE_REJECT = "Pf";
229
229
  var LOCAL_CONTEXT_STREAM_CONTROLLER = "c";
230
230
  var GLOBAL_CONTEXT_STREAM_CONSTRUCTOR = "S";
231
231
  var GLOBAL_CONTEXT_STREAM_EMIT = "Se";
232
- var GLOBAL_CONTEXT_API_SCRIPT = `self.${GLOBAL_CONTEXT_API}=self.${GLOBAL_CONTEXT_API}||{${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR}:function(s,f,p){return(p=new Promise(function(a,b){s=a,f=b})).${LOCAL_CONTEXT_PROMISE_RESOLVE}=s,p.${LOCAL_CONTEXT_PROMISE_REJECT}=f,p},uP:function(p){delete p.${LOCAL_CONTEXT_PROMISE_RESOLVE};delete p.${LOCAL_CONTEXT_PROMISE_REJECT}},${GLOBAL_CONTEXT_PROMISE_RESOLVE}:function(p,d){p.${LOCAL_CONTEXT_PROMISE_RESOLVE}(d),p.status="success",p.value=d,this.uP(p)},${GLOBAL_CONTEXT_PROMISE_REJECT}:function(p,d){p.${LOCAL_CONTEXT_PROMISE_REJECT}(d),p.status="failure",p.value=d,this.uP(p)},uS:function(s){delete s.${LOCAL_CONTEXT_STREAM_CONTROLLER}},${GLOBAL_CONTEXT_STREAM_EMIT}:function(s,t,d,c){switch(c=s.${LOCAL_CONTEXT_STREAM_CONTROLLER},t){case 0:return c.enqueue(d);case 1:return(this.uS(s),c.error(d));case 2:return(this.uS(s),c.close())}},${GLOBAL_CONTEXT_STREAM_CONSTRUCTOR}:function(s,c){return(s=new ReadableStream({start:function(x){c=x}})).${LOCAL_CONTEXT_STREAM_CONTROLLER}=c,s}}`;
232
+ var GLOBAL_CONTEXT_API_REF = `self.${GLOBAL_CONTEXT_API}`;
233
+ var GLOBAL_CONTEXT_API_SCRIPT = `${GLOBAL_CONTEXT_API_REF}=${GLOBAL_CONTEXT_API_REF}||{${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR}:function(s,f,p){return(p=new Promise(function(a,b){s=a,f=b})).${LOCAL_CONTEXT_PROMISE_RESOLVE}=s,p.${LOCAL_CONTEXT_PROMISE_REJECT}=f,p},uP:function(p){delete p.${LOCAL_CONTEXT_PROMISE_RESOLVE};delete p.${LOCAL_CONTEXT_PROMISE_REJECT}},${GLOBAL_CONTEXT_PROMISE_RESOLVE}:function(p,d){p.${LOCAL_CONTEXT_PROMISE_RESOLVE}(d),p.status="success",p.value=d,this.uP(p)},${GLOBAL_CONTEXT_PROMISE_REJECT}:function(p,d){p.${LOCAL_CONTEXT_PROMISE_REJECT}(d),p.status="failure",p.value=d,this.uP(p)},uS:function(s){delete s.${LOCAL_CONTEXT_STREAM_CONTROLLER}},${GLOBAL_CONTEXT_STREAM_EMIT}:function(s,t,d,c){switch(c=s.${LOCAL_CONTEXT_STREAM_CONTROLLER},t){case 0:return c.enqueue(d);case 1:return(this.uS(s),c.error(d));case 2:return(this.uS(s),c.close())}},${GLOBAL_CONTEXT_STREAM_CONSTRUCTOR}:function(s,c){return(s=new ReadableStream({start:function(x){c=x}})).${LOCAL_CONTEXT_STREAM_CONTROLLER}=c,s}}`;
233
234
  function getCrossReferenceHeader(id) {
234
235
  if (id == null) {
235
- return `self.${GLOBAL_CONTEXT_REFERENCES}=self.${GLOBAL_CONTEXT_REFERENCES}||[];`;
236
+ return `${GLOBAL_CONTEXT_API_REF}=${GLOBAL_CONTEXT_API_REF}||[];`;
236
237
  }
237
- return `(self.${GLOBAL_CONTEXT_REFERENCES}=self.${GLOBAL_CONTEXT_REFERENCES}||{})["${serializeString(id)}"]=[];`;
238
+ return `(${GLOBAL_CONTEXT_API_REF}=${GLOBAL_CONTEXT_API_REF}||{})["${serializeString(id)}"]=[];`;
238
239
  }
239
240
 
240
241
  // src/core/reference.ts
@@ -3762,10 +3763,13 @@ var Serializer = class {
3762
3763
  this.pending = 0;
3763
3764
  this.cleanups = [];
3764
3765
  this.refs = /* @__PURE__ */ new Map();
3766
+ this.keys = /* @__PURE__ */ new Set();
3767
+ this.ids = 0;
3765
3768
  }
3766
3769
  write(key, value) {
3767
3770
  if (this.alive && !this.flushed) {
3768
3771
  this.pending++;
3772
+ this.keys.add(key);
3769
3773
  this.cleanups.push(crossSerializeStream(value, {
3770
3774
  scopeId: this.options.scopeId,
3771
3775
  refs: this.refs,
@@ -3790,6 +3794,17 @@ var Serializer = class {
3790
3794
  }));
3791
3795
  }
3792
3796
  }
3797
+ getNextID() {
3798
+ while (this.keys.has("" + this.ids)) {
3799
+ this.ids++;
3800
+ }
3801
+ return "" + this.ids;
3802
+ }
3803
+ push(value) {
3804
+ const newID = this.getNextID();
3805
+ this.write(newID, value);
3806
+ return newID;
3807
+ }
3793
3808
  flush() {
3794
3809
  if (this.alive) {
3795
3810
  this.flushed = true;