facturas 0.12.1 → 0.12.2

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.
@@ -3108,7 +3108,8 @@ async function runOperation(wsfe, operation, input, prepare, options, context, r
3108
3108
  select ?? (() => wsfe),
3109
3109
  stored,
3110
3110
  readSettledRecord(recorded),
3111
- options
3111
+ options,
3112
+ (other) => storeCall(() => store.get(settledKey(environment, taxId, other)))
3112
3113
  );
3113
3114
  }
3114
3115
  return await settle(
@@ -3171,24 +3172,40 @@ function readSettledRecord(json) {
3171
3172
  );
3172
3173
  }
3173
3174
  }
3174
- async function settledOutcome(select, reservation, settled, options) {
3175
+ async function settledOutcome(select, reservation, settled, options, settledFor) {
3175
3176
  if (settled.kind === "conflict") {
3176
3177
  return settledConflict(settled, reservation);
3177
3178
  }
3178
3179
  const outcome = await consultReservation(select, reservation, options, true);
3179
- if (outcome.kind === "indeterminate" && outcome.lookup.kind === "not_found") {
3180
- return {
3181
- kind: "indeterminate",
3182
- attempted: {
3183
- salesPoint: reservation.salesPoint,
3184
- voucherType: reservation.voucherType,
3185
- number: settled.number
3186
- },
3187
- attempt: replayEvidence(reservation.service),
3188
- lookup: { kind: "superseded", by: settled.by }
3189
- };
3180
+ const empty = outcome.kind === "indeterminate" && outcome.lookup.kind === "not_found";
3181
+ if (!empty && (outcome.kind !== "conflict" || await successionDisputed(settled.by, settledFor))) {
3182
+ return outcome;
3190
3183
  }
3191
- return outcome;
3184
+ return {
3185
+ kind: "indeterminate",
3186
+ attempted: {
3187
+ salesPoint: reservation.salesPoint,
3188
+ voucherType: reservation.voucherType,
3189
+ number: settled.number
3190
+ },
3191
+ attempt: replayEvidence(reservation.service),
3192
+ lookup: { kind: "superseded", by: settled.by }
3193
+ };
3194
+ }
3195
+ async function successionDisputed(key, settledFor) {
3196
+ let next = key;
3197
+ for (let hop = 0; hop < 16; hop += 1) {
3198
+ const json = await settledFor(next);
3199
+ if (json === null) {
3200
+ return false;
3201
+ }
3202
+ const record = readSettledRecord(json);
3203
+ if (record.kind === "conflict") {
3204
+ return true;
3205
+ }
3206
+ next = record.by;
3207
+ }
3208
+ return true;
3192
3209
  }
3193
3210
  function settledConflict(settled, reservation) {
3194
3211
  return {
@@ -3769,7 +3786,16 @@ async function recoverOperation(select, key, inputOptions, context) {
3769
3786
  select,
3770
3787
  record,
3771
3788
  readSettledRecord(recorded),
3772
- options
3789
+ options,
3790
+ (other) => storeCall(
3791
+ () => store.get(
3792
+ settledKey(
3793
+ context.environment,
3794
+ context.taxId,
3795
+ other
3796
+ )
3797
+ )
3798
+ )
3773
3799
  );
3774
3800
  }
3775
3801
  return await recordConflict(
@@ -4246,4 +4272,4 @@ export {
4246
4272
  withLease,
4247
4273
  createFileStore
4248
4274
  };
4249
- //# sourceMappingURL=chunk-2PYF5JFG.mjs.map
4275
+ //# sourceMappingURL=chunk-BP72XNPS.mjs.map