@dbsp/adapter-pgsql 3.5.0 → 3.5.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.
package/dist/index.js CHANGED
@@ -23035,8 +23035,10 @@ var PreparedStatementRegistry = class {
23035
23035
  collisionRejectedFingerprints = /* @__PURE__ */ new Set();
23036
23036
  nextGeneration = 0;
23037
23037
  /**
23038
- * Reserves a name only from the second sighting onward. Call confirm after
23039
- * successful named execution, or abort when that execution fails.
23038
+ * Reserves a name only from the second sighting onward. Call confirm to commit
23039
+ * executor-scoped admission after a successful named execution or a
23040
+ * caller-classified positionless protocol-shaped failure. Call abort for a
23041
+ * local, position-bearing, collision, or verified infrastructure failure.
23040
23042
  */
23041
23043
  admit(sql) {
23042
23044
  const fingerprint = derivePreparedStatementFingerprint(sql);
@@ -23071,7 +23073,7 @@ var PreparedStatementRegistry = class {
23071
23073
  if (this.atCapacity()) this.candidates.clear();
23072
23074
  return reservation;
23073
23075
  }
23074
- /** Confirms a reservation only after PostgreSQL accepted its named execution. */
23076
+ /** Commits executor-scoped admission after a successful named execution or a caller-classified server-reported failure. */
23075
23077
  confirm(reservation) {
23076
23078
  const pending = this.pendingByFingerprint.get(reservation.fingerprint);
23077
23079
  if (pending === void 0 || pending.name !== reservation.name || !pending.generations.has(reservation.generation))
@@ -23079,7 +23081,7 @@ var PreparedStatementRegistry = class {
23079
23081
  this.pendingByFingerprint.delete(reservation.fingerprint);
23080
23082
  this.namesByFingerprint.set(reservation.fingerprint, reservation.name);
23081
23083
  }
23082
- /** Aborts only this still-pending attempt, never a later confirmation. */
23084
+ /** Aborts only this still-pending attempt after a caller-classified failure that never reached server acceptance, never a later confirmation. */
23083
23085
  abort(reservation) {
23084
23086
  const pending = this.pendingByFingerprint.get(reservation.fingerprint);
23085
23087
  if (pending === void 0 || pending.name !== reservation.name || !pending.generations.delete(reservation.generation))
@@ -23458,25 +23460,30 @@ function isDriverLocalPreparedStatementNameCollision(error, attemptedName) {
23458
23460
  return error instanceof Error && !("code" in error) && error.message === message;
23459
23461
  }
23460
23462
  function isVerifiedPreparedStatementInfrastructureError(error) {
23463
+ if (!hasPostgresSqlStateCode(error)) return false;
23461
23464
  if (typeof error !== "object" || error === null) return false;
23462
23465
  const { code, routine } = error;
23463
23466
  return code === "0A000" && routine === "RevalidateCachedQuery" || code === "26000" && routine === "FetchPreparedStatement" || code === "42P05" && routine === "StorePreparedStatement";
23464
23467
  }
23465
- function didNamedExecutionReachExecution(error) {
23468
+ function isPositionlessProtocolShapedFailure(error) {
23469
+ return hasPostgresSqlStateCode(error) && error.position === void 0 && !isVerifiedPreparedStatementInfrastructureError(error);
23470
+ }
23471
+ function hasPostgresSqlStateCode(error) {
23466
23472
  if (typeof error !== "object" || error === null) return false;
23467
- const { code, position } = error;
23468
- return typeof code === "string" && /^[0-9A-Z]{5}$/.test(code) && position === void 0 && !isVerifiedPreparedStatementInfrastructureError(error);
23473
+ const { code, severity } = error;
23474
+ return typeof severity === "string" && typeof code === "string" && /^[0-9A-Z]{5}$/.test(code);
23469
23475
  }
23470
23476
  function shouldAbortPreparedStatementReservation(error, executor, attemptedName) {
23471
23477
  if (typeof error === "object" && error !== null && "position" in error && error.position !== void 0)
23472
23478
  return true;
23473
23479
  if (isDriverLocalPreparedStatementNameCollision(error, attemptedName))
23474
23480
  return true;
23475
- if (!isPoolClientLike(executor)) return false;
23476
- if (didNamedExecutionReachExecution(error)) return false;
23477
- return !(error instanceof Error && error.message.startsWith("Prepared statements must be unique - '"));
23481
+ if (!isPoolClientLike(executor)) return !hasPostgresSqlStateCode(error);
23482
+ if (isPositionlessProtocolShapedFailure(error)) return false;
23483
+ return true;
23478
23484
  }
23479
23485
  function isVerifiedClientWidePreparedStatementLoss(error) {
23486
+ if (!hasPostgresSqlStateCode(error)) return false;
23480
23487
  if (typeof error !== "object" || error === null) return false;
23481
23488
  const { code, routine } = error;
23482
23489
  return code === "26000" && routine === "FetchPreparedStatement";
@@ -27649,20 +27656,34 @@ var PgsqlAdapter = class {
27649
27656
  return result;
27650
27657
  } catch (error) {
27651
27658
  if (admission.reservation !== void 0) {
27652
- if (shouldAbortPreparedStatementReservation(
27659
+ try {
27660
+ if (shouldAbortPreparedStatementReservation(
27661
+ error,
27662
+ executor,
27663
+ admission.name
27664
+ )) {
27665
+ this.preparedStatementRegistry.abort(admission.reservation);
27666
+ } else
27667
+ this.preparedStatementRegistry.confirm(admission.reservation);
27668
+ } catch {
27669
+ try {
27670
+ this.preparedStatementRegistry.abort(admission.reservation);
27671
+ } catch {
27672
+ }
27673
+ }
27674
+ }
27675
+ try {
27676
+ if (isPoolClientLike(executor) && (isVerifiedPreparedStatementInfrastructureError(error) || isDriverLocalPreparedStatementNameCollision(
27653
27677
  error,
27654
- executor,
27655
27678
  admission.name
27656
- )) {
27657
- this.preparedStatementRegistry.abort(admission.reservation);
27658
- } else this.preparedStatementRegistry.confirm(admission.reservation);
27659
- }
27660
- if (isPoolClientLike(executor) && (isVerifiedPreparedStatementInfrastructureError(error) || isDriverLocalPreparedStatementNameCollision(error, admission.name))) {
27661
- quarantinePreparedStatement(
27662
- executor,
27663
- sql,
27664
- isVerifiedClientWidePreparedStatementLoss(error)
27665
- );
27679
+ ))) {
27680
+ quarantinePreparedStatement(
27681
+ executor,
27682
+ sql,
27683
+ isVerifiedClientWidePreparedStatementLoss(error)
27684
+ );
27685
+ }
27686
+ } catch {
27666
27687
  }
27667
27688
  throw error;
27668
27689
  }