@vibeorm/adapter-bun 4.3.0 → 5.0.0
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/README.md +16 -3
- package/dist/connection-url.d.ts +24 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +545 -42
- package/dist/index.js.map +5 -5
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -102,6 +102,39 @@ function takeConnectTimeout(params) {
|
|
|
102
102
|
url.search = url.searchParams.toString().replace(/\+/g, "%20");
|
|
103
103
|
return seconds > 0 ? { url: url.toString(), seconds } : { url: url.toString() };
|
|
104
104
|
}
|
|
105
|
+
var SSLMODE_KEYS = new Set(["sslmode", "ssl-mode", "ssl_mode"]);
|
|
106
|
+
var TLS_FLAG_KEYS = new Set(["ssl", "tls"]);
|
|
107
|
+
var VERIFY_FULL = new Set(["verify-full", "verify_full", "verify-identity", "verify_identity"]);
|
|
108
|
+
function takeSystemRootCert(params) {
|
|
109
|
+
if (!URL.canParse(params.url))
|
|
110
|
+
return params.url;
|
|
111
|
+
const url = new URL(params.url);
|
|
112
|
+
const entries = [...url.searchParams.entries()];
|
|
113
|
+
const rootCert = entries.filter(([key]) => key.toLowerCase() === "sslrootcert").at(-1);
|
|
114
|
+
if (rootCert?.[1] !== "system")
|
|
115
|
+
return params.url;
|
|
116
|
+
for (const [key, value] of entries) {
|
|
117
|
+
const lower = key.toLowerCase();
|
|
118
|
+
const isFlag = TLS_FLAG_KEYS.has(lower);
|
|
119
|
+
if (!SSLMODE_KEYS.has(lower) && !isFlag)
|
|
120
|
+
continue;
|
|
121
|
+
if (isFlag && ["", "true", "1"].includes(value.toLowerCase()))
|
|
122
|
+
continue;
|
|
123
|
+
if (VERIFY_FULL.has(value.toLowerCase()))
|
|
124
|
+
continue;
|
|
125
|
+
throw new VibeError2({
|
|
126
|
+
code: "VIBE_CONFIG",
|
|
127
|
+
message: `bunAdapter \`url\` combines sslrootcert=system with ${key}=${JSON.stringify(value)}. ` + "libpq allows sslrootcert=system only with sslmode=verify-full (its default when sslmode is omitted): any certificate " + "the system trusts would otherwise vouch for a server that is not yours. Use sslmode=verify-full, or remove the setting.",
|
|
128
|
+
meta: { adapter: "bun", reason: "sslrootcert-system-weak-sslmode", parameter: key, value }
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
const kept = entries.filter(([key]) => {
|
|
132
|
+
const lower = key.toLowerCase();
|
|
133
|
+
return lower !== "sslrootcert" && !SSLMODE_KEYS.has(lower) && !TLS_FLAG_KEYS.has(lower);
|
|
134
|
+
});
|
|
135
|
+
url.search = new URLSearchParams([...kept, ["sslmode", "verify-full"]]).toString().replace(/\+/g, "%20");
|
|
136
|
+
return url.toString();
|
|
137
|
+
}
|
|
105
138
|
function applyStartupOptions(params) {
|
|
106
139
|
if (!URL.canParse(params.url)) {
|
|
107
140
|
throw new VibeError2({ code: "VIBE_VALIDATION", message: "invalid PostgreSQL connection URL" });
|
|
@@ -357,7 +390,7 @@ function scanPlaceholders(params) {
|
|
|
357
390
|
index += 1;
|
|
358
391
|
}
|
|
359
392
|
chunks.push(text.slice(chunkStart));
|
|
360
|
-
const template = Object.
|
|
393
|
+
const template = Object.defineProperty(chunks, "raw", { value: chunks, enumerable: false });
|
|
361
394
|
return { template, indices, identityOrder: indices.every((placeholder, index) => placeholder === index + 1) };
|
|
362
395
|
}
|
|
363
396
|
function templateChunks(params) {
|
|
@@ -458,6 +491,26 @@ import {
|
|
|
458
491
|
transactionOutcomeUnknownError,
|
|
459
492
|
validateTransactionDeadline as validateTransactionDeadline2
|
|
460
493
|
} from "@vibeorm/runtime/adapter-kit";
|
|
494
|
+
function commitSentRefusal() {
|
|
495
|
+
return new VibeError7({
|
|
496
|
+
code: "VIBE_TRANSACTION",
|
|
497
|
+
message: "this transaction already sent its COMMIT together with its last statement, so it accepts no further statement",
|
|
498
|
+
meta: { provider: "postgresql", reason: "commit-sent" }
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
function finalStatementMisuse() {
|
|
502
|
+
return new VibeError7({
|
|
503
|
+
code: "VIBE_INTERNAL",
|
|
504
|
+
message: "withCommit(): a view carries ONE statement, the transaction's last",
|
|
505
|
+
meta: { reason: "with-commit-second-statement" }
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
function laneGroupMisuse(params) {
|
|
509
|
+
return new VibeError7({ code: "VIBE_INTERNAL", message: `pipeline lane group: ${params.message}`, meta: { reason: "pipeline-lane-group" } });
|
|
510
|
+
}
|
|
511
|
+
function discardedRows() {
|
|
512
|
+
return Object.assign([], { count: 0 });
|
|
513
|
+
}
|
|
461
514
|
var ignore = () => {
|
|
462
515
|
return;
|
|
463
516
|
};
|
|
@@ -484,18 +537,21 @@ function orderedLaneMisuse(params) {
|
|
|
484
537
|
return new VibeError7({ code: "VIBE_INTERNAL", message: `pipeline(): ${params.message}`, meta: { reason: "pipeline-ordered-lane" } });
|
|
485
538
|
}
|
|
486
539
|
function executorFor(params) {
|
|
487
|
-
const { dispatch, effect, guard,
|
|
540
|
+
const { dispatch, effect, guard, final } = params;
|
|
541
|
+
const finalOf = final === undefined ? {} : { final: true, ...final.discardRows ? { discardRows: true } : {} };
|
|
488
542
|
return Object.assign((strings, ...values) => dispatch({
|
|
489
543
|
effect,
|
|
490
544
|
guard,
|
|
491
545
|
extended: true,
|
|
492
|
-
|
|
546
|
+
answered: () => serverAnswered({ values }),
|
|
547
|
+
...finalOf,
|
|
493
548
|
send: (connection) => connection(strings, ...values)
|
|
494
549
|
}), { unsafe: (text, values) => dispatch({
|
|
495
550
|
effect,
|
|
496
551
|
guard,
|
|
497
552
|
extended: values !== undefined && values.length > 0,
|
|
498
|
-
|
|
553
|
+
answered: () => values !== undefined && values.length > 0 && serverAnswered({ values }),
|
|
554
|
+
...finalOf,
|
|
499
555
|
send: (connection) => connection.unsafe(text, values)
|
|
500
556
|
}) });
|
|
501
557
|
}
|
|
@@ -507,8 +563,8 @@ var BUDGETS = Object.freeze({
|
|
|
507
563
|
transactionDeadline: "cancel-running-statements",
|
|
508
564
|
accessModes: Object.freeze(["readOnly"])
|
|
509
565
|
});
|
|
510
|
-
var WIRE_TEXT = Object.freeze({ dateTime: "native", json: "text", numbers: "native" });
|
|
511
|
-
var WIRE_PARSED = Object.freeze({ dateTime: "native", json: "parsed", numbers: "native" });
|
|
566
|
+
var WIRE_TEXT = Object.freeze({ dateTime: "native", json: "text", numbers: "native", bytes: "buffer" });
|
|
567
|
+
var WIRE_PARSED = Object.freeze({ dateTime: "native", json: "parsed", numbers: "native", bytes: "buffer" });
|
|
512
568
|
var ROUND_TRIPS = "network";
|
|
513
569
|
var READ_SNAPSHOT = Object.freeze({ isolationLevel: "RepeatableRead", accessMode: "readOnly" });
|
|
514
570
|
function requireUrl(params) {
|
|
@@ -521,12 +577,24 @@ function requireUrl(params) {
|
|
|
521
577
|
meta: { adapter: "bun", reason: "missing-address" }
|
|
522
578
|
});
|
|
523
579
|
}
|
|
580
|
+
var MAX_STATEMENT_TIMEOUT_MS = 2147483647;
|
|
581
|
+
function assertPoolMin(params) {
|
|
582
|
+
const { value, max } = params;
|
|
583
|
+
if (typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= max)
|
|
584
|
+
return value;
|
|
585
|
+
throw new VibeError7({
|
|
586
|
+
code: "VIBE_CONFIG",
|
|
587
|
+
message: `bunAdapter \`min\` must be an integer from 0 through \`max\` (${max}).`,
|
|
588
|
+
meta: { adapter: "bun", reason: "invalid-pool-min", option: "min", max }
|
|
589
|
+
});
|
|
590
|
+
}
|
|
524
591
|
function bunAdapter(options) {
|
|
525
592
|
refuseUnsupportedBun({ version: Bun.version });
|
|
526
593
|
const usePrepared = options?.preparedStatements ?? false;
|
|
594
|
+
const poolMin = options?.min === undefined ? 0 : assertPoolMin({ value: options.min, max: options?.max ?? 10 });
|
|
527
595
|
const pipelining = usePrepared ? "batched" : "ordered";
|
|
528
596
|
const namedUnsafe = usePrepared && namedUnsafeBinds({ version: Bun.version });
|
|
529
|
-
const address = takeConnectTimeout({ url: requireUrl({ options }) });
|
|
597
|
+
const address = takeConnectTimeout({ url: takeSystemRootCert({ url: requireUrl({ options }) }) });
|
|
530
598
|
const templates = createTemplateCache({ max: options?.stmtCacheMax ?? 1000 });
|
|
531
599
|
let activeWire = WIRE_TEXT;
|
|
532
600
|
let wireSettled = false;
|
|
@@ -536,15 +604,28 @@ function bunAdapter(options) {
|
|
|
536
604
|
function controlQuery(params) {
|
|
537
605
|
return params.connection(controlTemplates.getTemplate({ text: params.text }).template, ...params.values ?? []);
|
|
538
606
|
}
|
|
607
|
+
function controlStep(params) {
|
|
608
|
+
const { connection, step } = params;
|
|
609
|
+
if (step.values === undefined || step.values.length === 0)
|
|
610
|
+
return controlQuery({ connection, text: step.text });
|
|
611
|
+
const prepared = controlTemplates.getTemplate({ text: step.text });
|
|
612
|
+
return connection(prepared.template, ...bindTemplateValues({ text: step.text, indices: prepared.indices, values: step.values }));
|
|
613
|
+
}
|
|
539
614
|
function createReservedControl(params) {
|
|
540
615
|
const { reserved, budget, scope } = params;
|
|
541
|
-
const deferred = createDeferredControl({ opening: params.opening === null ? [] : [params.opening] });
|
|
616
|
+
const deferred = createDeferredControl({ opening: params.opening === null ? [] : [params.opening], deferReleases: true });
|
|
542
617
|
let openingFailure;
|
|
543
618
|
let openingStep = null;
|
|
544
619
|
let openingPending = null;
|
|
545
620
|
let waitTail = null;
|
|
546
621
|
let deadlineTail = Promise.resolve();
|
|
547
622
|
let lastFailure;
|
|
623
|
+
let ridden;
|
|
624
|
+
let queued = 0;
|
|
625
|
+
const inFlight = new Set;
|
|
626
|
+
const openTracks = new Set;
|
|
627
|
+
const openOrderedLanes = new Set;
|
|
628
|
+
let settingsSent = false;
|
|
548
629
|
const step = (query) => new Promise((resolve) => resolve(query())).then(undefined, (error) => {
|
|
549
630
|
const mapped = mapBunDriverError({ error });
|
|
550
631
|
if (mapped.meta.sqlstate === "25P02") {
|
|
@@ -568,25 +649,84 @@ function bunAdapter(options) {
|
|
|
568
649
|
return settled;
|
|
569
650
|
};
|
|
570
651
|
const ridesOpening = (send) => send.extended && send.effect === "read";
|
|
652
|
+
const sendStep = (deferredStep) => {
|
|
653
|
+
const settings = params.openingSettings;
|
|
654
|
+
if (settings === undefined || settingsSent || deferredStep.text !== settings.text) {
|
|
655
|
+
return step(() => controlStep({ connection: reserved, step: deferredStep }));
|
|
656
|
+
}
|
|
657
|
+
settingsSent = true;
|
|
658
|
+
return new Promise((resolve) => resolve(controlStep({ connection: reserved, step: deferredStep }))).then(undefined, (error) => {
|
|
659
|
+
const mapped = mapBunDriverError({ error });
|
|
660
|
+
if (mapped.meta.sqlstate === "25P02")
|
|
661
|
+
throw transactionAbortedError({ cause: lastFailure ?? scope.state.aborted?.cause });
|
|
662
|
+
if (typeof mapped.meta.sqlstate !== "string")
|
|
663
|
+
throw mapped;
|
|
664
|
+
const refused = settings.refused(mapped);
|
|
665
|
+
lastFailure = refused;
|
|
666
|
+
throw refused;
|
|
667
|
+
});
|
|
668
|
+
};
|
|
669
|
+
const ridesNow = (send) => {
|
|
670
|
+
if (send.final !== true || !params.commits || ridden !== undefined || openingFailure !== undefined || budget.totalMs !== null)
|
|
671
|
+
return false;
|
|
672
|
+
if (scope.state.open !== null || scope.state.aborted !== null || scope.state.poisoned !== null)
|
|
673
|
+
return false;
|
|
674
|
+
if (!send.extended || send.answered?.() !== true || queued > 0)
|
|
675
|
+
return false;
|
|
676
|
+
for (const other of inFlight)
|
|
677
|
+
if (other.answered?.() !== true)
|
|
678
|
+
return false;
|
|
679
|
+
for (const track of openTracks)
|
|
680
|
+
if (!track.final || track.group !== undefined && !track.group.sent)
|
|
681
|
+
return false;
|
|
682
|
+
for (const lane of openOrderedLanes)
|
|
683
|
+
if (!lane.final && !(lane.followed && lane.issued > 0))
|
|
684
|
+
return false;
|
|
685
|
+
return true;
|
|
686
|
+
};
|
|
687
|
+
const rideCommit = () => {
|
|
688
|
+
deferred.dropReleases();
|
|
689
|
+
const reply = step(() => controlQuery({ connection: reserved, text: "COMMIT" }));
|
|
690
|
+
const entry = { settled: Promise.resolve(), state: "in-flight" };
|
|
691
|
+
entry.settled = reply.then((result) => {
|
|
692
|
+
if (finalRows({ result }).command === "ROLLBACK") {
|
|
693
|
+
entry.state = "failed";
|
|
694
|
+
entry.error = transactionAbortedError({ cause: lastFailure ?? scope.state.aborted?.cause });
|
|
695
|
+
} else if (openingFailure !== undefined) {
|
|
696
|
+
entry.state = "failed";
|
|
697
|
+
entry.error = transactionAbortedError({ cause: openingFailure });
|
|
698
|
+
} else {
|
|
699
|
+
entry.state = "committed";
|
|
700
|
+
}
|
|
701
|
+
}, (error) => {
|
|
702
|
+
entry.state = isConnectionLoss({ error }) ? "lost" : "failed";
|
|
703
|
+
entry.error = error;
|
|
704
|
+
});
|
|
705
|
+
ridden = entry;
|
|
706
|
+
return entry;
|
|
707
|
+
};
|
|
571
708
|
const sendNow = (send) => {
|
|
572
709
|
const cleanup = send.cleanup === true;
|
|
573
710
|
if (!cleanup) {
|
|
711
|
+
if (ridden !== undefined)
|
|
712
|
+
throw commitSentRefusal();
|
|
574
713
|
if (openingFailure !== undefined)
|
|
575
714
|
throw transactionAbortedError({ cause: openingFailure });
|
|
576
715
|
budget.assertUsable({ stage: send.stage ?? "statement" });
|
|
577
716
|
send.guard?.();
|
|
578
717
|
}
|
|
579
718
|
const carriesOpening = !cleanup && !deferred.opened();
|
|
580
|
-
const control = cleanup ? [] : [...deferred.
|
|
719
|
+
const control = cleanup ? [] : [...send.carry ?? [], ...deferred.takeSteps()];
|
|
581
720
|
if (carriesOpening && !ridesOpening(send)) {
|
|
582
721
|
const [opening, ...rest] = control;
|
|
583
|
-
const confirmed = trackOpening(
|
|
584
|
-
const
|
|
585
|
-
|
|
722
|
+
const confirmed = trackOpening(sendStep(opening));
|
|
723
|
+
const bound = rest.findIndex((pending) => pending.values !== undefined);
|
|
724
|
+
const riding = (bound === -1 ? rest : rest.slice(0, bound)).map((text) => {
|
|
725
|
+
const sent = sendStep(text);
|
|
586
726
|
sent.catch(ignore);
|
|
587
727
|
return sent;
|
|
588
728
|
});
|
|
589
|
-
const next = { ...send, riding };
|
|
729
|
+
const next = { ...send, riding, carry: bound === -1 ? [] : rest.slice(bound) };
|
|
590
730
|
if (budget.totalMs !== null)
|
|
591
731
|
return confirmed.then(() => sendNow(next));
|
|
592
732
|
return enqueue(next);
|
|
@@ -595,29 +735,47 @@ function bunAdapter(options) {
|
|
|
595
735
|
const steps = [...send.riding ?? []];
|
|
596
736
|
if (!cleanup && !carriesOpening && openingStep !== null)
|
|
597
737
|
steps.push(openingStep);
|
|
598
|
-
control.forEach((
|
|
599
|
-
const sent =
|
|
738
|
+
control.forEach((pending, index) => {
|
|
739
|
+
const sent = sendStep(pending);
|
|
600
740
|
if (index === 0 && carriesOpening)
|
|
601
741
|
trackOpening(sent);
|
|
602
742
|
steps.push(sent);
|
|
603
743
|
});
|
|
604
744
|
if (ms !== null)
|
|
605
745
|
steps.push(step(() => controlQuery({ connection: reserved, text: STATEMENT_BOUND_TEXT, values: [String(ms)] })));
|
|
746
|
+
const rides = !cleanup && ridesNow(send);
|
|
606
747
|
let handed = false;
|
|
607
748
|
const statement = step(() => {
|
|
608
749
|
const query = send.send(reserved);
|
|
609
750
|
handed = true;
|
|
610
751
|
return query;
|
|
611
752
|
});
|
|
612
|
-
|
|
753
|
+
let riding;
|
|
754
|
+
if (handed) {
|
|
755
|
+
if (!cleanup) {
|
|
756
|
+
inFlight.add(send);
|
|
757
|
+
statement.then(() => inFlight.delete(send), () => inFlight.delete(send));
|
|
758
|
+
}
|
|
613
759
|
send.onSent?.();
|
|
760
|
+
if (rides)
|
|
761
|
+
riding = rideCommit();
|
|
762
|
+
}
|
|
614
763
|
steps.push(statement);
|
|
615
|
-
|
|
616
|
-
const failed = settled.find((
|
|
764
|
+
const outcome = Promise.allSettled(steps).then((settled) => {
|
|
765
|
+
const failed = settled.find((result) => result.status === "rejected");
|
|
617
766
|
if (failed !== undefined)
|
|
618
767
|
throw failed.reason;
|
|
619
768
|
return statement;
|
|
620
769
|
});
|
|
770
|
+
if (riding === undefined || send.discardRows !== true)
|
|
771
|
+
return outcome;
|
|
772
|
+
const commitReply = riding;
|
|
773
|
+
return outcome.then(undefined, async (error) => {
|
|
774
|
+
await commitReply.settled;
|
|
775
|
+
if (commitReply.state === "committed" && !(error instanceof VibeError7 && typeof error.meta.sqlstate === "string"))
|
|
776
|
+
return discardedRows();
|
|
777
|
+
throw error;
|
|
778
|
+
});
|
|
621
779
|
};
|
|
622
780
|
const enqueue = (send) => {
|
|
623
781
|
const prior = waitTail ?? openingPending ?? Promise.resolve();
|
|
@@ -626,7 +784,9 @@ function bunAdapter(options) {
|
|
|
626
784
|
markStarted = resolve;
|
|
627
785
|
});
|
|
628
786
|
waitTail = started;
|
|
787
|
+
queued += 1;
|
|
629
788
|
return prior.then(() => {
|
|
789
|
+
queued -= 1;
|
|
630
790
|
try {
|
|
631
791
|
return sendNow(send);
|
|
632
792
|
} finally {
|
|
@@ -659,12 +819,13 @@ function bunAdapter(options) {
|
|
|
659
819
|
resolveRelease = resolve;
|
|
660
820
|
});
|
|
661
821
|
let settled = false;
|
|
662
|
-
|
|
822
|
+
const lane = {
|
|
663
823
|
scope: orderedScope,
|
|
664
824
|
index,
|
|
665
825
|
open: true,
|
|
666
826
|
issued: 0,
|
|
667
827
|
followed: false,
|
|
828
|
+
final: false,
|
|
668
829
|
release,
|
|
669
830
|
settle: (outcome) => {
|
|
670
831
|
if (settled)
|
|
@@ -673,6 +834,8 @@ function bunAdapter(options) {
|
|
|
673
834
|
resolveRelease(outcome);
|
|
674
835
|
}
|
|
675
836
|
};
|
|
837
|
+
openOrderedLanes.add(lane);
|
|
838
|
+
return lane;
|
|
676
839
|
};
|
|
677
840
|
const laneDispatch = (lane, send) => {
|
|
678
841
|
if (lane.followed && lane.issued > 0) {
|
|
@@ -692,7 +855,7 @@ function bunAdapter(options) {
|
|
|
692
855
|
lane.settle({ kind: "failed", cause: failed.cause });
|
|
693
856
|
return Promise.reject(refusalBehind(failed.cause));
|
|
694
857
|
}
|
|
695
|
-
const pipelinable = first && send.
|
|
858
|
+
const pipelinable = first && send.answered?.() === true;
|
|
696
859
|
return dispatch({
|
|
697
860
|
...send,
|
|
698
861
|
onSent: () => {
|
|
@@ -737,16 +900,22 @@ function bunAdapter(options) {
|
|
|
737
900
|
if (!lane.open)
|
|
738
901
|
return;
|
|
739
902
|
lane.open = false;
|
|
903
|
+
openOrderedLanes.delete(lane);
|
|
740
904
|
if (lane.issued === 0)
|
|
741
905
|
lane.settle(LANE_CLOSED);
|
|
742
906
|
},
|
|
743
907
|
control: (lane) => {
|
|
744
|
-
const laneSend = (send) =>
|
|
908
|
+
const laneSend = (send) => {
|
|
909
|
+
if (send.cleanup === true || !lane.open)
|
|
910
|
+
return dispatch(send);
|
|
911
|
+
if (send.final === true)
|
|
912
|
+
lane.final = true;
|
|
913
|
+
return laneDispatch(lane, send);
|
|
914
|
+
};
|
|
745
915
|
return {
|
|
746
|
-
|
|
916
|
+
...base,
|
|
747
917
|
dispatch: laneSend,
|
|
748
|
-
executor: ({ effect, guard }) => executorFor({ dispatch: laneSend, effect, guard,
|
|
749
|
-
ordered,
|
|
918
|
+
executor: ({ effect, guard, final }) => executorFor({ dispatch: laneSend, effect, guard, ...final === undefined ? {} : { final } }),
|
|
750
919
|
turn: () => {
|
|
751
920
|
const before = lane.scope.lanes[lane.index - 1];
|
|
752
921
|
if (!lane.open || before === undefined)
|
|
@@ -761,12 +930,119 @@ function bunAdapter(options) {
|
|
|
761
930
|
};
|
|
762
931
|
}
|
|
763
932
|
};
|
|
764
|
-
|
|
933
|
+
const refuses = () => ridden !== undefined || openingFailure !== undefined || scope.state.poisoned !== null || scope.state.aborted !== null;
|
|
934
|
+
const groupOver = (group) => group.sealed && group.seats.every((seat) => !seat.open);
|
|
935
|
+
const sendGroup = async (group, entries) => {
|
|
936
|
+
let failure;
|
|
937
|
+
for (const [index, entry] of entries.entries()) {
|
|
938
|
+
if (failure !== undefined) {
|
|
939
|
+
entry.reject(refusalBehind(failure.cause));
|
|
940
|
+
continue;
|
|
941
|
+
}
|
|
942
|
+
const send = group.final && index === entries.length - 1 ? { ...entry.send, final: true } : entry.send;
|
|
943
|
+
const sent = dispatch(send);
|
|
944
|
+
sent.then(entry.resolve, entry.reject);
|
|
945
|
+
if (send.answered?.() !== true) {
|
|
946
|
+
const outcome = await sent.then(() => {
|
|
947
|
+
return;
|
|
948
|
+
}, (cause) => ({ cause }));
|
|
949
|
+
if (outcome !== undefined)
|
|
950
|
+
failure = outcome;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
const flushGroup = (group) => {
|
|
955
|
+
if (!group.sealed || group.sent)
|
|
956
|
+
return;
|
|
957
|
+
for (const seat of group.seats)
|
|
958
|
+
if (seat.open && !seat.done && seat.held === undefined)
|
|
959
|
+
return;
|
|
960
|
+
group.sent = true;
|
|
961
|
+
sendGroup(group, group.seats.flatMap((seat) => seat.held === undefined ? [] : [seat.held]));
|
|
962
|
+
};
|
|
963
|
+
const seatControl = (group, seat) => {
|
|
964
|
+
const hold = (send) => {
|
|
965
|
+
if (send.cleanup === true)
|
|
966
|
+
return dispatch(send);
|
|
967
|
+
if (seat.held !== undefined || seat.done || !seat.open || group.sent) {
|
|
968
|
+
return Promise.reject(laneGroupMisuse({ message: "a sub-lane issues ONE statement, before the group left" }));
|
|
969
|
+
}
|
|
970
|
+
return new Promise((resolve, reject) => {
|
|
971
|
+
seat.held = { send, resolve, reject };
|
|
972
|
+
flushGroup(group);
|
|
973
|
+
});
|
|
974
|
+
};
|
|
975
|
+
return { ...base, dispatch: hold, executor: ({ effect, guard }) => executorFor({ dispatch: hold, effect, guard }), commits: false };
|
|
976
|
+
};
|
|
977
|
+
const openLane = () => {
|
|
978
|
+
const track = { open: true, final: false };
|
|
979
|
+
openTracks.add(track);
|
|
980
|
+
const laneSend = (send) => {
|
|
981
|
+
if (send.cleanup !== true && track.open) {
|
|
982
|
+
if (track.group !== undefined && !groupOver(track.group)) {
|
|
983
|
+
return Promise.reject(laneGroupMisuse({ message: "a lane issues nothing while its group is open" }));
|
|
984
|
+
}
|
|
985
|
+
if (send.final === true)
|
|
986
|
+
track.final = true;
|
|
987
|
+
}
|
|
988
|
+
return dispatch(send);
|
|
989
|
+
};
|
|
990
|
+
const control = {
|
|
991
|
+
...base,
|
|
992
|
+
dispatch: laneSend,
|
|
993
|
+
executor: ({ effect, guard, final }) => executorFor({ dispatch: laneSend, effect, guard, ...final === undefined ? {} : { final } })
|
|
994
|
+
};
|
|
995
|
+
return {
|
|
996
|
+
control,
|
|
997
|
+
close: () => {
|
|
998
|
+
track.open = false;
|
|
999
|
+
openTracks.delete(track);
|
|
1000
|
+
},
|
|
1001
|
+
group: (final) => {
|
|
1002
|
+
if (!track.open || track.group !== undefined && !groupOver(track.group) || refuses() || !wireSettled)
|
|
1003
|
+
return;
|
|
1004
|
+
const group = { final: final && params.commits, seats: [], sealed: false, sent: false };
|
|
1005
|
+
track.group = group;
|
|
1006
|
+
if (group.final)
|
|
1007
|
+
track.final = true;
|
|
1008
|
+
return {
|
|
1009
|
+
seat: () => {
|
|
1010
|
+
if (group.sealed)
|
|
1011
|
+
throw laneGroupMisuse({ message: "a sub-lane is opened only before the group is sealed" });
|
|
1012
|
+
const seat = { open: true, used: false, done: false };
|
|
1013
|
+
group.seats.push(seat);
|
|
1014
|
+
return { seat, control: seatControl(group, seat) };
|
|
1015
|
+
},
|
|
1016
|
+
seal: () => {
|
|
1017
|
+
if (group.sealed)
|
|
1018
|
+
return;
|
|
1019
|
+
group.sealed = true;
|
|
1020
|
+
flushGroup(group);
|
|
1021
|
+
},
|
|
1022
|
+
close: (seat) => {
|
|
1023
|
+
if (!seat.open)
|
|
1024
|
+
return;
|
|
1025
|
+
seat.open = false;
|
|
1026
|
+
flushGroup(group);
|
|
1027
|
+
},
|
|
1028
|
+
drop: (seat) => {
|
|
1029
|
+
seat.done = true;
|
|
1030
|
+
flushGroup(group);
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
};
|
|
1036
|
+
const base = {
|
|
765
1037
|
deferred,
|
|
766
1038
|
dispatch,
|
|
767
|
-
executor: ({ effect, guard }) => executorFor({ dispatch, effect, guard }),
|
|
768
|
-
ordered
|
|
1039
|
+
executor: ({ effect, guard, final }) => executorFor({ dispatch, effect, guard, ...final === undefined ? {} : { final } }),
|
|
1040
|
+
ordered,
|
|
1041
|
+
commits: params.commits,
|
|
1042
|
+
ridden: () => ridden,
|
|
1043
|
+
openLane
|
|
769
1044
|
};
|
|
1045
|
+
return base;
|
|
770
1046
|
}
|
|
771
1047
|
let rawSession = null;
|
|
772
1048
|
function createSqlInstance(params) {
|
|
@@ -859,8 +1135,152 @@ function bunAdapter(options) {
|
|
|
859
1135
|
const rows = finalRows({ result });
|
|
860
1136
|
return { rows: plainRows({ rows }), affectedRows: readAffectedRows({ rows }) };
|
|
861
1137
|
}
|
|
1138
|
+
const refusedOnSubLane = (message) => () => Promise.reject(laneGroupMisuse({ message }));
|
|
1139
|
+
function subLaneAdapter(params) {
|
|
1140
|
+
let used = false;
|
|
1141
|
+
return {
|
|
1142
|
+
dialect: DIALECT,
|
|
1143
|
+
provider: PROVIDER,
|
|
1144
|
+
budgets: BUDGETS,
|
|
1145
|
+
roundTrips: ROUND_TRIPS,
|
|
1146
|
+
get wire() {
|
|
1147
|
+
return activeWire;
|
|
1148
|
+
},
|
|
1149
|
+
execute: (call) => {
|
|
1150
|
+
if (used)
|
|
1151
|
+
return Promise.reject(laneGroupMisuse({ message: "a sub-lane issues ONE statement" }));
|
|
1152
|
+
used = true;
|
|
1153
|
+
if (call.execution !== undefined) {
|
|
1154
|
+
params.drop();
|
|
1155
|
+
return Promise.reject(laneGroupMisuse({ message: "a sub-lane statement takes no read options" }));
|
|
1156
|
+
}
|
|
1157
|
+
return params.issue(call);
|
|
1158
|
+
},
|
|
1159
|
+
executeUnsafe: refusedOnSubLane("a sub-lane runs no raw statement"),
|
|
1160
|
+
transaction: refusedOnSubLane("a sub-lane opens no transaction"),
|
|
1161
|
+
connect: refusedOnSubLane("a sub-lane does not connect"),
|
|
1162
|
+
disconnect: refusedOnSubLane("a sub-lane does not disconnect"),
|
|
1163
|
+
formatArrayParam: (values) => toPgArrayLiteral(values)
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
function groupSeatAdapter(params) {
|
|
1167
|
+
const { seat, opened, inner } = params;
|
|
1168
|
+
return subLaneAdapter({
|
|
1169
|
+
drop: () => {
|
|
1170
|
+
opened.drop(seat);
|
|
1171
|
+
},
|
|
1172
|
+
issue: (call) => {
|
|
1173
|
+
const running = inner.execute(call);
|
|
1174
|
+
running.then(undefined, () => {
|
|
1175
|
+
if (seat.held === undefined)
|
|
1176
|
+
opened.drop(seat);
|
|
1177
|
+
});
|
|
1178
|
+
return running;
|
|
1179
|
+
}
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
function openPoolGroup() {
|
|
1183
|
+
const seats = [];
|
|
1184
|
+
let sealed = false;
|
|
1185
|
+
let sent = false;
|
|
1186
|
+
const flush = () => {
|
|
1187
|
+
if (!sealed || sent)
|
|
1188
|
+
return;
|
|
1189
|
+
for (const seat of seats)
|
|
1190
|
+
if (seat.open && !seat.done && seat.issued === undefined)
|
|
1191
|
+
return;
|
|
1192
|
+
sent = true;
|
|
1193
|
+
const entries = seats.flatMap((seat) => seat.issued === undefined ? [] : [seat.issued]);
|
|
1194
|
+
if (entries.length === 0)
|
|
1195
|
+
return;
|
|
1196
|
+
lifecycle.admit({ run: () => Promise.allSettled(entries.map((entry) => root.execute(entry.call))) }).then((settled) => {
|
|
1197
|
+
let failure;
|
|
1198
|
+
settled.forEach((outcome, index) => {
|
|
1199
|
+
const entry = entries[index];
|
|
1200
|
+
if (failure !== undefined)
|
|
1201
|
+
entry.reject(transactionAbortedError({ cause: failure.cause }));
|
|
1202
|
+
else if (outcome.status === "fulfilled")
|
|
1203
|
+
entry.resolve(outcome.value);
|
|
1204
|
+
else {
|
|
1205
|
+
failure = { cause: outcome.reason };
|
|
1206
|
+
entry.reject(outcome.reason);
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
}, (error) => {
|
|
1210
|
+
for (const entry of entries)
|
|
1211
|
+
entry.reject(error);
|
|
1212
|
+
});
|
|
1213
|
+
};
|
|
1214
|
+
return {
|
|
1215
|
+
lane: () => {
|
|
1216
|
+
if (sealed)
|
|
1217
|
+
throw laneGroupMisuse({ message: "a sub-lane is opened only before the group is sealed" });
|
|
1218
|
+
const seat = { open: true, done: false };
|
|
1219
|
+
seats.push(seat);
|
|
1220
|
+
return {
|
|
1221
|
+
adapter: subLaneAdapter({
|
|
1222
|
+
drop: () => {
|
|
1223
|
+
seat.done = true;
|
|
1224
|
+
flush();
|
|
1225
|
+
},
|
|
1226
|
+
issue: (call) => {
|
|
1227
|
+
if (!seat.open || sent) {
|
|
1228
|
+
seat.done = true;
|
|
1229
|
+
flush();
|
|
1230
|
+
return Promise.reject(laneGroupMisuse({ message: "a closed sub-lane issues nothing" }));
|
|
1231
|
+
}
|
|
1232
|
+
return new Promise((resolve, reject) => {
|
|
1233
|
+
seat.issued = { call, resolve, reject };
|
|
1234
|
+
flush();
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
}),
|
|
1238
|
+
close: () => {
|
|
1239
|
+
if (!seat.open)
|
|
1240
|
+
return;
|
|
1241
|
+
seat.open = false;
|
|
1242
|
+
flush();
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
},
|
|
1246
|
+
seal: () => {
|
|
1247
|
+
if (sealed)
|
|
1248
|
+
return;
|
|
1249
|
+
sealed = true;
|
|
1250
|
+
flush();
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
862
1254
|
function createAdapter(params) {
|
|
863
|
-
const { source, parentMode, scope, budget, lifetime, control } = params;
|
|
1255
|
+
const { source, parentMode, scope, budget, lifetime, control, final } = params;
|
|
1256
|
+
const finalOf = () => {
|
|
1257
|
+
if (final === undefined)
|
|
1258
|
+
return {};
|
|
1259
|
+
if (final.used)
|
|
1260
|
+
throw finalStatementMisuse();
|
|
1261
|
+
final.used = true;
|
|
1262
|
+
return { final: { discardRows: final.discardRows } };
|
|
1263
|
+
};
|
|
1264
|
+
const unorderedLane = (lane) => ({
|
|
1265
|
+
adapter: createAdapter({ source, parentMode: "tx", scope, budget, control: lane.control, ...params.commits === true ? { commits: true } : {} }),
|
|
1266
|
+
close: lane.close,
|
|
1267
|
+
group: (options) => {
|
|
1268
|
+
const opened = lane.group(options?.final === true && params.commits === true);
|
|
1269
|
+
if (opened === undefined)
|
|
1270
|
+
return;
|
|
1271
|
+
return {
|
|
1272
|
+
lane: () => {
|
|
1273
|
+
const { seat, control: seatCtl } = opened.seat();
|
|
1274
|
+
return { adapter: groupSeatAdapter({ seat, opened, inner: createAdapter({ source, parentMode: "tx", scope, budget, control: seatCtl }) }), close: () => {
|
|
1275
|
+
opened.close(seat);
|
|
1276
|
+
} };
|
|
1277
|
+
},
|
|
1278
|
+
seal: () => {
|
|
1279
|
+
opened.seal();
|
|
1280
|
+
}
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
864
1284
|
function assertHandle() {
|
|
865
1285
|
budget?.assertUsable({ stage: "statement" });
|
|
866
1286
|
if (lifetime?.active === false) {
|
|
@@ -882,7 +1302,7 @@ function bunAdapter(options) {
|
|
|
882
1302
|
assertHandle();
|
|
883
1303
|
}
|
|
884
1304
|
const savepointControl = (statement, cleanup) => {
|
|
885
|
-
if (reservedControl.deferred.routeSavepoint({ text: statement }) !== "send")
|
|
1305
|
+
if (reservedControl.deferred.routeSavepoint({ text: statement, cleanup }) !== "send")
|
|
886
1306
|
return;
|
|
887
1307
|
return reservedControl.dispatch({
|
|
888
1308
|
extended: true,
|
|
@@ -915,9 +1335,14 @@ function bunAdapter(options) {
|
|
|
915
1335
|
});
|
|
916
1336
|
const readOnly = readOnlyRequested({ options: transactionOptions, provider: PROVIDER });
|
|
917
1337
|
const openingOptions = { isolationLevel: transactionOptions?.isolationLevel, readOnly };
|
|
918
|
-
const
|
|
1338
|
+
const timeout = transactionOptions?.timeout;
|
|
1339
|
+
if (timeout !== undefined)
|
|
1340
|
+
statementTimeoutStatement({ timeout });
|
|
919
1341
|
const settings = readTransactionSettings({ settings: transactionOptions?.settings, provider: PROVIDER });
|
|
920
1342
|
const settingsStatement = settings.length === 0 ? undefined : renderTransactionSettings({ settings });
|
|
1343
|
+
const settingsDeferred = settingsStatement !== undefined && usePrepared && transactionOptions?.deferSettings === true;
|
|
1344
|
+
const eagerOpening = settingsStatement !== undefined && !settingsDeferred || timeout !== undefined && (!usePrepared || timeout > MAX_STATEMENT_TIMEOUT_MS);
|
|
1345
|
+
const eagerOpen = eagerOpening && timeout !== undefined ? openTransactionStatement({ ...openingOptions, timeout }) : null;
|
|
921
1346
|
const reserved = await runMapped(() => pool.reserve());
|
|
922
1347
|
const budget = startTransactionBudget({ options: transactionOptions, provider: PROVIDER });
|
|
923
1348
|
const txScope = createSavepointScope();
|
|
@@ -925,8 +1350,21 @@ function bunAdapter(options) {
|
|
|
925
1350
|
reserved,
|
|
926
1351
|
budget,
|
|
927
1352
|
scope: txScope,
|
|
928
|
-
opening:
|
|
1353
|
+
opening: eagerOpening ? null : beginStatement(openingOptions),
|
|
1354
|
+
commits: usePrepared && budget.totalMs === null,
|
|
1355
|
+
...settingsDeferred ? {
|
|
1356
|
+
openingSettings: {
|
|
1357
|
+
text: settingsStatement.text,
|
|
1358
|
+
refused: (cause) => transactionSettingRefusedError({ provider: PROVIDER, settings, setting: findRefusedSetting({ settings, cause }), cause, deferred: true })
|
|
1359
|
+
}
|
|
1360
|
+
} : {}
|
|
929
1361
|
});
|
|
1362
|
+
if (!eagerOpening) {
|
|
1363
|
+
if (timeout !== undefined)
|
|
1364
|
+
control.deferred.defer({ text: STATEMENT_BOUND_TEXT, values: [String(timeout)] });
|
|
1365
|
+
if (settingsDeferred)
|
|
1366
|
+
control.deferred.defer({ text: settingsStatement.text, values: settingsStatement.values });
|
|
1367
|
+
}
|
|
930
1368
|
const commit = { progress: "not-sent" };
|
|
931
1369
|
let discard = false;
|
|
932
1370
|
let openingRollback;
|
|
@@ -949,7 +1387,7 @@ function bunAdapter(options) {
|
|
|
949
1387
|
throw transactionSettingRefusedError({ provider: PROVIDER, settings, setting, cause });
|
|
950
1388
|
};
|
|
951
1389
|
try {
|
|
952
|
-
if (settingsStatement !== undefined)
|
|
1390
|
+
if (eagerOpening && settingsStatement !== undefined)
|
|
953
1391
|
await openWithSettings(settingsStatement);
|
|
954
1392
|
else if (eagerOpen !== null)
|
|
955
1393
|
await runMapped(() => reserved.unsafe(eagerOpen));
|
|
@@ -959,14 +1397,27 @@ function bunAdapter(options) {
|
|
|
959
1397
|
scope: txScope,
|
|
960
1398
|
budget,
|
|
961
1399
|
control,
|
|
962
|
-
ordered: usePrepared && budget.totalMs === null
|
|
1400
|
+
ordered: usePrepared && budget.totalMs === null,
|
|
1401
|
+
topLevel: true,
|
|
1402
|
+
...control.commits ? { commits: true } : {}
|
|
963
1403
|
});
|
|
964
1404
|
const result = await runRootScope({ scope: txScope, body: () => fn(txAdapter) });
|
|
1405
|
+
const riding = control.ridden();
|
|
1406
|
+
if (riding !== undefined) {
|
|
1407
|
+
commit.progress = "sent";
|
|
1408
|
+
await riding.settled;
|
|
1409
|
+
if (riding.state === "committed") {
|
|
1410
|
+
budget.close({ outcome: "committed" });
|
|
1411
|
+
return result;
|
|
1412
|
+
}
|
|
1413
|
+
throw riding.error;
|
|
1414
|
+
}
|
|
965
1415
|
budget.assertUsable({ stage: "commit" });
|
|
966
1416
|
if (!control.deferred.opened()) {
|
|
967
1417
|
budget.close({ outcome: "committed" });
|
|
968
1418
|
return result;
|
|
969
1419
|
}
|
|
1420
|
+
control.deferred.dropReleases();
|
|
970
1421
|
const reply = await control.dispatch({
|
|
971
1422
|
extended: true,
|
|
972
1423
|
effect: "write",
|
|
@@ -983,6 +1434,17 @@ function bunAdapter(options) {
|
|
|
983
1434
|
budget.close({ outcome: "committed" });
|
|
984
1435
|
return result;
|
|
985
1436
|
} catch (error) {
|
|
1437
|
+
const riding = control.ridden();
|
|
1438
|
+
if (riding !== undefined) {
|
|
1439
|
+
await riding.settled;
|
|
1440
|
+
if (riding.state === "committed") {
|
|
1441
|
+
budget.close({ outcome: "committed" });
|
|
1442
|
+
throw error;
|
|
1443
|
+
}
|
|
1444
|
+
commit.progress = riding.state === "lost" ? "unanswered" : "answered";
|
|
1445
|
+
if (riding.state === "lost")
|
|
1446
|
+
discard = true;
|
|
1447
|
+
}
|
|
986
1448
|
if (txScope.state.poisoned !== null)
|
|
987
1449
|
discard = true;
|
|
988
1450
|
if (commit.progress === "sent")
|
|
@@ -991,7 +1453,7 @@ function bunAdapter(options) {
|
|
|
991
1453
|
try {
|
|
992
1454
|
if (openingRollback !== undefined)
|
|
993
1455
|
rollback = openingRollback;
|
|
994
|
-
else if (control.deferred.opened()) {
|
|
1456
|
+
else if (riding === undefined && control.deferred.opened()) {
|
|
995
1457
|
await control.dispatch({ extended: false, cleanup: true, send: (connection) => connection.unsafe("ROLLBACK") });
|
|
996
1458
|
rollback = "acknowledged";
|
|
997
1459
|
}
|
|
@@ -999,7 +1461,7 @@ function bunAdapter(options) {
|
|
|
999
1461
|
discard = true;
|
|
1000
1462
|
rollback = "failed";
|
|
1001
1463
|
}
|
|
1002
|
-
const own = commit.progress === "unanswered" && txScope.state.poisoned === null ? unknownOutcome({ cause: error }) : error;
|
|
1464
|
+
const own = commit.progress === "unanswered" && txScope.state.poisoned === null ? unknownOutcome({ cause: riding?.state === "lost" ? riding.error : error }) : error;
|
|
1003
1465
|
throw settleFailedTransaction({
|
|
1004
1466
|
error: own,
|
|
1005
1467
|
provider: PROVIDER,
|
|
@@ -1032,9 +1494,9 @@ function bunAdapter(options) {
|
|
|
1032
1494
|
throw new VibeError7({ code: "VIBE_VALIDATION", message: "pipeline() needs a positive whole number of lanes", meta: { lanes: count } });
|
|
1033
1495
|
}
|
|
1034
1496
|
if (ordered !== true)
|
|
1035
|
-
return Array.from({ length: count }, () => (
|
|
1497
|
+
return Array.from({ length: count }, () => unorderedLane(control.openLane()));
|
|
1036
1498
|
const laneHandle = (lane) => ({
|
|
1037
|
-
adapter: createAdapter({ source, parentMode: "tx", scope, budget, control: control.ordered.control(lane) }),
|
|
1499
|
+
adapter: createAdapter({ source, parentMode: "tx", scope, budget, control: control.ordered.control(lane), ...params.commits === true ? { commits: true } : {} }),
|
|
1038
1500
|
close: () => {
|
|
1039
1501
|
control.ordered.close(lane);
|
|
1040
1502
|
},
|
|
@@ -1050,6 +1512,33 @@ function bunAdapter(options) {
|
|
|
1050
1512
|
assertHandle();
|
|
1051
1513
|
return readRowChanges({ scope });
|
|
1052
1514
|
} },
|
|
1515
|
+
...control === undefined || params.commits !== true || !control.commits || scope.depth !== 0 || final !== undefined ? {} : {
|
|
1516
|
+
withCommit: (options) => createAdapter({
|
|
1517
|
+
source,
|
|
1518
|
+
parentMode: "tx",
|
|
1519
|
+
scope,
|
|
1520
|
+
budget,
|
|
1521
|
+
control,
|
|
1522
|
+
commits: true,
|
|
1523
|
+
final: { used: false, discardRows: options?.rows === "discard" }
|
|
1524
|
+
})
|
|
1525
|
+
},
|
|
1526
|
+
...control === undefined || params.topLevel !== true || !usePrepared ? {} : {
|
|
1527
|
+
deferStatement: (statement) => {
|
|
1528
|
+
assertHandle();
|
|
1529
|
+
if (control.ridden() !== undefined)
|
|
1530
|
+
throw commitSentRefusal();
|
|
1531
|
+
const values = serializeParams({ values: [...statement.values], namedStatements: true });
|
|
1532
|
+
if (!serverAnswered({ values })) {
|
|
1533
|
+
throw new VibeError7({
|
|
1534
|
+
code: "VIBE_VALIDATION",
|
|
1535
|
+
message: "deferStatement(): adapter-bun defers a statement only when every value is text, null or bytes after serialization",
|
|
1536
|
+
meta: { reason: "deferred-value-not-text" }
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
control.deferred.defer({ text: statement.text, values });
|
|
1540
|
+
}
|
|
1541
|
+
},
|
|
1053
1542
|
get wire() {
|
|
1054
1543
|
return activeWire;
|
|
1055
1544
|
},
|
|
@@ -1064,7 +1553,8 @@ function bunAdapter(options) {
|
|
|
1064
1553
|
assertHandle();
|
|
1065
1554
|
assertReadExecution({ ...execParams, provider: PROVIDER, stage: "waiting-for-connection" });
|
|
1066
1555
|
};
|
|
1067
|
-
const
|
|
1556
|
+
const view = finalOf();
|
|
1557
|
+
const executor = control === undefined ? source : control.executor({ effect: execParams.effect, guard, ...wireSettled ? view : {} });
|
|
1068
1558
|
const result = runExecute({ source: executor, ...parentMode === "pool" ? {} : { scope }, ...execParams });
|
|
1069
1559
|
return parentMode === "pool" ? result : result.catch((error) => abortTransactionOnStatementFailure({ scope, error }));
|
|
1070
1560
|
} });
|
|
@@ -1075,7 +1565,8 @@ function bunAdapter(options) {
|
|
|
1075
1565
|
if (turn !== undefined)
|
|
1076
1566
|
await turn;
|
|
1077
1567
|
assertHandle();
|
|
1078
|
-
const
|
|
1568
|
+
const view = finalOf();
|
|
1569
|
+
const executor = control === undefined ? source : control.executor({ effect: execParams.effect, guard: assertHandle, ...view });
|
|
1079
1570
|
const result = runExecuteUnsafe({ source: executor, ...parentMode === "pool" ? {} : { scope }, ...execParams });
|
|
1080
1571
|
return parentMode === "pool" ? result : result.catch((error) => abortTransactionOnStatementFailure({ scope, error }));
|
|
1081
1572
|
},
|
|
@@ -1087,8 +1578,13 @@ function bunAdapter(options) {
|
|
|
1087
1578
|
assertHandle();
|
|
1088
1579
|
throw transactionLifecycleRefusal({ method: "connect" });
|
|
1089
1580
|
}
|
|
1090
|
-
const
|
|
1581
|
+
const opened = await Promise.allSettled(Array.from({ length: Math.max(1, poolMin) }, () => runMapped(() => source.reserve())));
|
|
1582
|
+
const held = opened.flatMap((outcome) => outcome.status === "fulfilled" ? [outcome.value] : []);
|
|
1091
1583
|
try {
|
|
1584
|
+
const failed = opened.find((outcome) => outcome.status === "rejected");
|
|
1585
|
+
if (failed !== undefined)
|
|
1586
|
+
throw failed.reason;
|
|
1587
|
+
const reserved = held[0];
|
|
1092
1588
|
if (!wireSettled && wireProbe === null) {
|
|
1093
1589
|
wireProbe = probeJsonWire(reserved).finally(() => {
|
|
1094
1590
|
wireProbe = null;
|
|
@@ -1096,7 +1592,8 @@ function bunAdapter(options) {
|
|
|
1096
1592
|
await wireProbe;
|
|
1097
1593
|
}
|
|
1098
1594
|
} finally {
|
|
1099
|
-
reserved
|
|
1595
|
+
for (const reserved of held)
|
|
1596
|
+
reserved.release();
|
|
1100
1597
|
}
|
|
1101
1598
|
},
|
|
1102
1599
|
async disconnect() {
|
|
@@ -1212,6 +1709,12 @@ function bunAdapter(options) {
|
|
|
1212
1709
|
pipelining,
|
|
1213
1710
|
transactionOutcome: "reported",
|
|
1214
1711
|
transactionSettings: "transaction-local",
|
|
1712
|
+
connectionGroup: () => {
|
|
1713
|
+
const closed = lifecycle.refusal();
|
|
1714
|
+
if (closed !== undefined)
|
|
1715
|
+
throw closed;
|
|
1716
|
+
return openPoolGroup();
|
|
1717
|
+
},
|
|
1215
1718
|
get wire() {
|
|
1216
1719
|
return activeWire;
|
|
1217
1720
|
},
|
|
@@ -1307,4 +1810,4 @@ export {
|
|
|
1307
1810
|
validateTransactionDeadline2 as validateTransactionDeadline
|
|
1308
1811
|
};
|
|
1309
1812
|
|
|
1310
|
-
//# debugId=
|
|
1813
|
+
//# debugId=B36822475D1CE05764756E2164756E21
|