tutuca 0.9.75 → 0.9.77

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.
@@ -4247,6 +4247,9 @@ class Step {
4247
4247
  toAbstractPathStep() {
4248
4248
  return this;
4249
4249
  }
4250
+ pinKey(_v) {
4251
+ return this;
4252
+ }
4250
4253
  }
4251
4254
  function warnRawDynStep(op, step) {
4252
4255
  console.warn(`Path.${op} reached a DynStep: call toTransactionPath() first`, step);
@@ -4297,6 +4300,20 @@ class Path {
4297
4300
  }
4298
4301
  return new Path(out);
4299
4302
  }
4303
+ pinKeys(root) {
4304
+ let curVal = root;
4305
+ let out = null;
4306
+ for (let i = 0;i < this.steps.length; i++) {
4307
+ const step = this.steps[i];
4308
+ const pinned = step.pinKey(curVal);
4309
+ if (pinned !== step)
4310
+ (out ??= this.steps.slice())[i] = pinned;
4311
+ curVal = step.lookup(curVal, NONE);
4312
+ if (curVal === NONE)
4313
+ break;
4314
+ }
4315
+ return out ? new Path(out) : this;
4316
+ }
4300
4317
  lookup(v, dval = null) {
4301
4318
  let curVal = v;
4302
4319
  for (const step of this.steps) {
@@ -4582,6 +4599,10 @@ var init_path = __esm(() => {
4582
4599
  const key = root?.get(this.keyField, NONE);
4583
4600
  return seq === NONE || key === NONE ? root : root.set(this.seqField, seq.set(key, v));
4584
4601
  }
4602
+ pinKey(v) {
4603
+ const key = v?.get(this.keyField, NONE);
4604
+ return key === NONE ? this : new SeqStep(this.seqField, key);
4605
+ }
4585
4606
  };
4586
4607
  EachBindStep = class EachBindStep extends Step {
4587
4608
  constructor(seqVal, key) {
@@ -13744,12 +13765,14 @@ class Transactor {
13744
13765
  }
13745
13766
  async pushRequest(path, name, args = [], opts = {}, parent = null) {
13746
13767
  const curRoot = this.state.val;
13747
- const curLeaf = path.toTransactionPath().lookup(curRoot);
13768
+ const txnPath = path.toTransactionPath();
13769
+ const curLeaf = txnPath.lookup(curRoot);
13748
13770
  const handler = this.comps.getRequestFor(curLeaf, name) ?? mkReq404(name);
13749
13771
  const resHandlerName = opts?.onResName ?? name;
13772
+ const resPath = opts?.livePath ? null : txnPath.pinKeys(curRoot);
13750
13773
  const push = (specificName, baseName, singleArg, result, error) => {
13751
13774
  const resArgs = specificName ? [singleArg] : [result, error];
13752
- const t = new ResponseEvent(path, this, specificName ?? baseName, resArgs, parent);
13775
+ const t = new ResponseEvent(path, this, specificName ?? baseName, resArgs, parent, resPath);
13753
13776
  this.pushTransaction(t);
13754
13777
  };
13755
13778
  try {
@@ -13824,8 +13847,11 @@ class Transaction {
13824
13847
  getHandlerAndArgs(_root, _instance, _comps) {
13825
13848
  return null;
13826
13849
  }
13850
+ getTransactionPath() {
13851
+ return this.path.toTransactionPath();
13852
+ }
13827
13853
  updateRootValue(curRoot, comps) {
13828
- const txnPath = this.path.toTransactionPath();
13854
+ const txnPath = this.getTransactionPath();
13829
13855
  const curLeaf = txnPath.lookup(curRoot);
13830
13856
  const newLeaf = this.callHandler(curRoot, curLeaf, comps);
13831
13857
  this._task?.complete?.({ value: newLeaf, old: curLeaf });
@@ -13990,6 +14016,13 @@ var init_transactor = __esm(() => {
13990
14016
  };
13991
14017
  ResponseEvent = class ResponseEvent extends NameArgsTransaction {
13992
14018
  handlerProp = "response";
14019
+ constructor(path, transactor, name, args, parent, txnPath = null) {
14020
+ super(path, transactor, name, args, parent);
14021
+ this._txnPath = txnPath;
14022
+ }
14023
+ getTransactionPath() {
14024
+ return this._txnPath ?? super.getTransactionPath();
14025
+ }
13993
14026
  };
13994
14027
  SendEvent = class SendEvent extends NameArgsTransaction {
13995
14028
  handlerProp = "receive";
@@ -20,6 +20,9 @@ class Step {
20
20
  toAbstractPathStep() {
21
21
  return this;
22
22
  }
23
+ pinKey(_v) {
24
+ return this;
25
+ }
23
26
  }
24
27
 
25
28
  class BindStep extends Step {
@@ -101,6 +104,10 @@ class SeqAccessStep extends Step {
101
104
  const key = root?.get(this.keyField, NONE);
102
105
  return seq === NONE || key === NONE ? root : root.set(this.seqField, seq.set(key, v));
103
106
  }
107
+ pinKey(v) {
108
+ const key = v?.get(this.keyField, NONE);
109
+ return key === NONE ? this : new SeqStep(this.seqField, key);
110
+ }
104
111
  }
105
112
 
106
113
  class EachBindStep extends Step {
@@ -223,6 +230,20 @@ class Path {
223
230
  }
224
231
  return new Path(out);
225
232
  }
233
+ pinKeys(root) {
234
+ let curVal = root;
235
+ let out = null;
236
+ for (let i = 0;i < this.steps.length; i++) {
237
+ const step = this.steps[i];
238
+ const pinned = step.pinKey(curVal);
239
+ if (pinned !== step)
240
+ (out ??= this.steps.slice())[i] = pinned;
241
+ curVal = step.lookup(curVal, NONE);
242
+ if (curVal === NONE)
243
+ break;
244
+ }
245
+ return out ? new Path(out) : this;
246
+ }
226
247
  lookup(v, dval = null) {
227
248
  let curVal = v;
228
249
  for (const step of this.steps) {
@@ -6410,12 +6431,14 @@ class Transactor {
6410
6431
  }
6411
6432
  async pushRequest(path, name, args = [], opts = {}, parent = null) {
6412
6433
  const curRoot = this.state.val;
6413
- const curLeaf = path.toTransactionPath().lookup(curRoot);
6434
+ const txnPath = path.toTransactionPath();
6435
+ const curLeaf = txnPath.lookup(curRoot);
6414
6436
  const handler = this.comps.getRequestFor(curLeaf, name) ?? mkReq404(name);
6415
6437
  const resHandlerName = opts?.onResName ?? name;
6438
+ const resPath = opts?.livePath ? null : txnPath.pinKeys(curRoot);
6416
6439
  const push = (specificName, baseName, singleArg, result, error) => {
6417
6440
  const resArgs = specificName ? [singleArg] : [result, error];
6418
- const t = new ResponseEvent(path, this, specificName ?? baseName, resArgs, parent);
6441
+ const t = new ResponseEvent(path, this, specificName ?? baseName, resArgs, parent, resPath);
6419
6442
  this.pushTransaction(t);
6420
6443
  };
6421
6444
  try {
@@ -6490,8 +6513,11 @@ class Transaction {
6490
6513
  getHandlerAndArgs(_root, _instance, _comps) {
6491
6514
  return null;
6492
6515
  }
6516
+ getTransactionPath() {
6517
+ return this.path.toTransactionPath();
6518
+ }
6493
6519
  updateRootValue(curRoot, comps) {
6494
- const txnPath = this.path.toTransactionPath();
6520
+ const txnPath = this.getTransactionPath();
6495
6521
  const curLeaf = txnPath.lookup(curRoot);
6496
6522
  const newLeaf = this.callHandler(curRoot, curLeaf, comps);
6497
6523
  this._task?.complete?.({ value: newLeaf, old: curLeaf });
@@ -6600,6 +6626,13 @@ class NameArgsTransaction extends Transaction {
6600
6626
 
6601
6627
  class ResponseEvent extends NameArgsTransaction {
6602
6628
  handlerProp = "response";
6629
+ constructor(path, transactor, name, args, parent, txnPath = null) {
6630
+ super(path, transactor, name, args, parent);
6631
+ this._txnPath = txnPath;
6632
+ }
6633
+ getTransactionPath() {
6634
+ return this._txnPath ?? super.getTransactionPath();
6635
+ }
6603
6636
  }
6604
6637
 
6605
6638
  class SendEvent extends NameArgsTransaction {
@@ -7685,6 +7685,9 @@ class Step {
7685
7685
  toAbstractPathStep() {
7686
7686
  return this;
7687
7687
  }
7688
+ pinKey(_v) {
7689
+ return this;
7690
+ }
7688
7691
  }
7689
7692
 
7690
7693
  class BindStep extends Step {
@@ -7766,6 +7769,10 @@ class SeqAccessStep extends Step {
7766
7769
  const key = root?.get(this.keyField, NONE);
7767
7770
  return seq === NONE || key === NONE ? root : root.set(this.seqField, seq.set(key, v));
7768
7771
  }
7772
+ pinKey(v) {
7773
+ const key = v?.get(this.keyField, NONE);
7774
+ return key === NONE ? this : new SeqStep(this.seqField, key);
7775
+ }
7769
7776
  }
7770
7777
 
7771
7778
  class EachBindStep extends Step {
@@ -7888,6 +7895,20 @@ class Path {
7888
7895
  }
7889
7896
  return new Path(out);
7890
7897
  }
7898
+ pinKeys(root) {
7899
+ let curVal = root;
7900
+ let out = null;
7901
+ for (let i = 0;i < this.steps.length; i++) {
7902
+ const step = this.steps[i];
7903
+ const pinned = step.pinKey(curVal);
7904
+ if (pinned !== step)
7905
+ (out ??= this.steps.slice())[i] = pinned;
7906
+ curVal = step.lookup(curVal, NONE);
7907
+ if (curVal === NONE)
7908
+ break;
7909
+ }
7910
+ return out ? new Path(out) : this;
7911
+ }
7891
7912
  lookup(v, dval = null) {
7892
7913
  let curVal = v;
7893
7914
  for (const step of this.steps) {
@@ -14075,12 +14096,14 @@ class Transactor {
14075
14096
  }
14076
14097
  async pushRequest(path, name, args = [], opts = {}, parent = null) {
14077
14098
  const curRoot = this.state.val;
14078
- const curLeaf = path.toTransactionPath().lookup(curRoot);
14099
+ const txnPath = path.toTransactionPath();
14100
+ const curLeaf = txnPath.lookup(curRoot);
14079
14101
  const handler = this.comps.getRequestFor(curLeaf, name) ?? mkReq404(name);
14080
14102
  const resHandlerName = opts?.onResName ?? name;
14103
+ const resPath = opts?.livePath ? null : txnPath.pinKeys(curRoot);
14081
14104
  const push = (specificName, baseName, singleArg, result, error) => {
14082
14105
  const resArgs = specificName ? [singleArg] : [result, error];
14083
- const t = new ResponseEvent(path, this, specificName ?? baseName, resArgs, parent);
14106
+ const t = new ResponseEvent(path, this, specificName ?? baseName, resArgs, parent, resPath);
14084
14107
  this.pushTransaction(t);
14085
14108
  };
14086
14109
  try {
@@ -14155,8 +14178,11 @@ class Transaction {
14155
14178
  getHandlerAndArgs(_root, _instance, _comps) {
14156
14179
  return null;
14157
14180
  }
14181
+ getTransactionPath() {
14182
+ return this.path.toTransactionPath();
14183
+ }
14158
14184
  updateRootValue(curRoot, comps) {
14159
- const txnPath = this.path.toTransactionPath();
14185
+ const txnPath = this.getTransactionPath();
14160
14186
  const curLeaf = txnPath.lookup(curRoot);
14161
14187
  const newLeaf = this.callHandler(curRoot, curLeaf, comps);
14162
14188
  this._task?.complete?.({ value: newLeaf, old: curLeaf });
@@ -14265,6 +14291,13 @@ class NameArgsTransaction extends Transaction {
14265
14291
 
14266
14292
  class ResponseEvent extends NameArgsTransaction {
14267
14293
  handlerProp = "response";
14294
+ constructor(path, transactor, name, args, parent, txnPath = null) {
14295
+ super(path, transactor, name, args, parent);
14296
+ this._txnPath = txnPath;
14297
+ }
14298
+ getTransactionPath() {
14299
+ return this._txnPath ?? super.getTransactionPath();
14300
+ }
14268
14301
  }
14269
14302
 
14270
14303
  class SendEvent extends NameArgsTransaction {