rivetkit 2.3.3 → 2.3.5-rc.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/browser/client.d.ts +157 -9
- package/dist/browser/client.js +518 -542
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +101 -2
- package/dist/browser/inspector/client.js +1245 -227
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/agent-os/index.cjs +103 -36
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +159 -11
- package/dist/tsup/agent-os/index.d.ts +159 -11
- package/dist/tsup/agent-os/index.js +103 -36
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-34P567PO.cjs → chunk-4XKED5P5.cjs} +145 -176
- package/dist/tsup/chunk-4XKED5P5.cjs.map +1 -0
- package/dist/tsup/{chunk-PYO2U53V.cjs → chunk-6HQCLWAW.cjs} +384 -4
- package/dist/tsup/chunk-6HQCLWAW.cjs.map +1 -0
- package/dist/tsup/{chunk-JZ7TWV65.js → chunk-7AFZMFPQ.js} +15 -1
- package/dist/tsup/chunk-7AFZMFPQ.js.map +1 -0
- package/dist/tsup/{chunk-BLDO2FKO.js → chunk-B4IZU537.js} +382 -2
- package/dist/tsup/chunk-B4IZU537.js.map +1 -0
- package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-G3CCRCTK.cjs} +14 -9
- package/dist/tsup/chunk-G3CCRCTK.cjs.map +1 -0
- package/dist/tsup/{chunk-CXRPENO3.js → chunk-GAV4PKFT.js} +15 -46
- package/dist/tsup/{chunk-CXRPENO3.js.map → chunk-GAV4PKFT.js.map} +1 -1
- package/dist/tsup/{chunk-HXUEHHJF.js → chunk-JI6GZ2C2.js} +2 -11
- package/dist/tsup/{chunk-HXUEHHJF.js.map → chunk-JI6GZ2C2.js.map} +1 -1
- package/dist/tsup/{chunk-YUEC5SEY.cjs → chunk-M3FCXL3Q.cjs} +3 -3
- package/dist/tsup/{chunk-YUEC5SEY.cjs.map → chunk-M3FCXL3Q.cjs.map} +1 -1
- package/dist/tsup/{chunk-KEKWJECX.js → chunk-MGTSVSUC.js} +2 -2
- package/dist/tsup/{chunk-VE2X4KMG.cjs → chunk-MYWZCDML.cjs} +2 -11
- package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
- package/dist/tsup/{chunk-DFA7SYSW.js → chunk-NIC3QLKL.js} +3 -3
- package/dist/tsup/{chunk-BZM4PMFS.js → chunk-P4OGQ4JL.js} +5 -7
- package/dist/tsup/{chunk-BZM4PMFS.js.map → chunk-P4OGQ4JL.js.map} +1 -1
- package/dist/tsup/{chunk-NT2NK3VT.js → chunk-PAG6G46L.js} +2 -2
- package/dist/tsup/{chunk-XIX5DOZN.js → chunk-SHBE77IT.js} +14 -9
- package/dist/tsup/chunk-SHBE77IT.js.map +1 -0
- package/dist/tsup/{chunk-TYLP3U4Y.cjs → chunk-TNIWIUNV.cjs} +9 -11
- package/dist/tsup/chunk-TNIWIUNV.cjs.map +1 -0
- package/dist/tsup/{chunk-S644FL73.cjs → chunk-TR5NLR5V.cjs} +4 -4
- package/dist/tsup/{chunk-S644FL73.cjs.map → chunk-TR5NLR5V.cjs.map} +1 -1
- package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-UEULFXUI.cjs} +16 -2
- package/dist/tsup/chunk-UEULFXUI.cjs.map +1 -0
- package/dist/tsup/{chunk-X63ROSOG.cjs → chunk-UJ2FQY63.cjs} +7 -7
- package/dist/tsup/{chunk-X63ROSOG.cjs.map → chunk-UJ2FQY63.cjs.map} +1 -1
- package/dist/tsup/client/mod.cjs +7 -8
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +5 -4
- package/dist/tsup/client/mod.d.ts +5 -4
- package/dist/tsup/client/mod.js +6 -7
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-D49x8NpL.d.cts → config-BxOimoGX.d.cts} +16 -0
- package/dist/tsup/{config-D49x8NpL.d.ts → config-BxOimoGX.d.ts} +16 -0
- package/dist/tsup/{config-ZkIsRFsN.d.ts → config-BzdqbLAP.d.ts} +164 -27
- package/dist/tsup/{config-BfBhjEbk.d.cts → config-CPPEwn_e.d.cts} +164 -27
- package/dist/tsup/{context-sZ9GlaBK.d.cts → context-DSA9gFXB.d.cts} +2 -2
- package/dist/tsup/{context-B7-84u9K.d.ts → context-wWv-K2K_.d.ts} +2 -2
- package/dist/tsup/db/drizzle.cjs +120 -68
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +8 -3
- package/dist/tsup/db/drizzle.d.ts +8 -3
- package/dist/tsup/db/drizzle.js +120 -68
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +74 -22
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +4 -3
- package/dist/tsup/db/mod.d.ts +4 -3
- package/dist/tsup/db/mod.js +74 -22
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.d.cts +3 -3
- package/dist/tsup/dynamic/mod.d.ts +3 -3
- package/dist/tsup/dynamic/mod.js +1 -1
- package/dist/tsup/inspector/mod.cjs +4 -5
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.js +3 -4
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector-tab/mod.cjs +2 -2
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -1
- package/dist/tsup/inspector-tab/mod.d.cts +5 -5
- package/dist/tsup/inspector-tab/mod.d.ts +5 -5
- package/dist/tsup/inspector-tab/mod.js +1 -1
- package/dist/tsup/inspector-tab/mod.js.map +1 -1
- package/dist/tsup/mod.cjs +605 -158
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +5 -5
- package/dist/tsup/mod.d.ts +5 -5
- package/dist/tsup/mod.js +528 -81
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +10 -11
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +3 -3
- package/dist/tsup/test/mod.d.ts +3 -3
- package/dist/tsup/test/mod.js +6 -7
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils-CV0akuDD.d.ts +162 -0
- package/dist/tsup/utils-DQDCphrl.d.cts +162 -0
- package/dist/tsup/utils.cjs +6 -2
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +3 -146
- package/dist/tsup/utils.d.ts +3 -146
- package/dist/tsup/utils.js +5 -1
- package/dist/tsup/workflow/mod.cjs +198 -151
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +5 -5
- package/dist/tsup/workflow/mod.d.ts +5 -5
- package/dist/tsup/workflow/mod.js +187 -140
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +8 -8
- package/src/actor/config.test.ts +14 -0
- package/src/actor/config.ts +104 -16
- package/src/actor/definition.ts +18 -7
- package/src/agent-os/actor/index.ts +2 -2
- package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
- package/src/common/bare/generated/inspector/v6.ts +1367 -0
- package/src/common/database/config.ts +24 -0
- package/src/common/database/mod.test.ts +148 -59
- package/src/common/database/mod.ts +93 -23
- package/src/common/database/native-database.test.ts +9 -0
- package/src/common/database/native-database.ts +151 -0
- package/src/common/database/shared.ts +15 -0
- package/src/common/encoding.ts +28 -21
- package/src/db/drizzle.test.ts +157 -0
- package/src/db/drizzle.ts +170 -79
- package/src/dynamic/isolate-runtime.ts +0 -2
- package/src/engine-client/driver.ts +0 -15
- package/src/engine-client/mod.ts +0 -41
- package/src/inspector/client.browser.ts +69 -8
- package/src/inspector-tab/mod.ts +1 -0
- package/src/registry/config/index.ts +1 -35
- package/src/registry/napi-runtime.ts +204 -16
- package/src/registry/native.ts +200 -30
- package/src/registry/runtime.ts +146 -3
- package/src/registry/wasm-runtime.ts +217 -6
- package/src/utils.ts +3 -0
- package/src/workflow/context.ts +5 -27
- package/src/workflow/driver.test.ts +62 -0
- package/src/workflow/driver.ts +231 -113
- package/src/workflow/mod.ts +3 -3
- package/dist/tsup/chunk-34P567PO.cjs.map +0 -1
- package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
- package/dist/tsup/chunk-APW73HCH.cjs +0 -382
- package/dist/tsup/chunk-APW73HCH.cjs.map +0 -1
- package/dist/tsup/chunk-BLDO2FKO.js.map +0 -1
- package/dist/tsup/chunk-DHXWD4DF.js +0 -382
- package/dist/tsup/chunk-DHXWD4DF.js.map +0 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
- package/dist/tsup/chunk-PYO2U53V.cjs.map +0 -1
- package/dist/tsup/chunk-TYLP3U4Y.cjs.map +0 -1
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +0 -1
- package/dist/tsup/chunk-XIX5DOZN.js.map +0 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +0 -1
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2484
- package/src/drivers/engine/actor-driver.ts +0 -2473
- /package/dist/tsup/{chunk-KEKWJECX.js.map → chunk-MGTSVSUC.js.map} +0 -0
- /package/dist/tsup/{chunk-DFA7SYSW.js.map → chunk-NIC3QLKL.js.map} +0 -0
- /package/dist/tsup/{chunk-NT2NK3VT.js.map → chunk-PAG6G46L.js.map} +0 -0
|
@@ -18,6 +18,7 @@ var BUILTIN_INSPECTOR_TAB_IDS = [
|
|
|
18
18
|
"database",
|
|
19
19
|
"state",
|
|
20
20
|
"queue",
|
|
21
|
+
"schedules",
|
|
21
22
|
"connections",
|
|
22
23
|
"console"
|
|
23
24
|
];
|
|
@@ -81,6 +82,8 @@ var GlobalActorOptionsBaseSchema = z.object({
|
|
|
81
82
|
name: z.string().optional(),
|
|
82
83
|
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
83
84
|
icon: z.string().optional(),
|
|
85
|
+
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
86
|
+
enableActorRuntimeSocket: z.boolean().default(false),
|
|
84
87
|
/**
|
|
85
88
|
* Can hibernate WebSockets for onWebSocket.
|
|
86
89
|
*
|
|
@@ -112,10 +115,12 @@ var InstanceActorOptionsBaseSchema = z.object({
|
|
|
112
115
|
noSleep: z.boolean().default(false),
|
|
113
116
|
sleepTimeout: z.number().positive().default(3e4),
|
|
114
117
|
maxQueueSize: z.number().positive().default(1e3),
|
|
118
|
+
/** Maximum pending one-shot and recurring schedules. */
|
|
119
|
+
maxSchedules: z.number().int().nonnegative().default(1e3),
|
|
115
120
|
maxQueueMessageSize: z.number().positive().default(64 * 1024),
|
|
116
|
-
/**
|
|
121
|
+
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
117
122
|
preloadMaxWorkflowBytes: z.number().nonnegative().optional(),
|
|
118
|
-
/**
|
|
123
|
+
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
119
124
|
preloadMaxConnectionsBytes: z.number().nonnegative().optional()
|
|
120
125
|
}).strict();
|
|
121
126
|
var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
|
|
@@ -174,6 +179,9 @@ var DocActorOptionsSchema = z.object({
|
|
|
174
179
|
icon: z.string().optional().describe(
|
|
175
180
|
"Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
|
|
176
181
|
),
|
|
182
|
+
enableActorRuntimeSocket: z.boolean().optional().describe(
|
|
183
|
+
"Enables the experimental Actor Runtime Socket for this actor. Default: false"
|
|
184
|
+
),
|
|
177
185
|
createVarsTimeout: z.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
|
|
178
186
|
createConnStateTimeout: z.number().optional().describe(
|
|
179
187
|
"Timeout in ms for createConnState handler. Default: 5000"
|
|
@@ -211,17 +219,14 @@ var DocActorOptionsSchema = z.object({
|
|
|
211
219
|
maxQueueSize: z.number().optional().describe(
|
|
212
220
|
"Maximum number of queue messages before rejecting new messages. Default: 1000"
|
|
213
221
|
),
|
|
222
|
+
maxSchedules: z.number().int().nonnegative().optional().describe(
|
|
223
|
+
"Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
|
|
224
|
+
),
|
|
214
225
|
maxQueueMessageSize: z.number().optional().describe(
|
|
215
226
|
"Maximum size of each queue message in bytes. Default: 65536"
|
|
216
227
|
),
|
|
217
228
|
canHibernateWebSocket: z.boolean().optional().describe(
|
|
218
229
|
"Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
|
|
219
|
-
),
|
|
220
|
-
preloadMaxWorkflowBytes: z.number().optional().describe(
|
|
221
|
-
"Override RivetKit's workflow preload budget for this actor. Set to 0 to disable workflow preloading."
|
|
222
|
-
),
|
|
223
|
-
preloadMaxConnectionsBytes: z.number().optional().describe(
|
|
224
|
-
"Override RivetKit's connections preload budget for this actor. Set to 0 to disable connections preloading."
|
|
225
230
|
)
|
|
226
231
|
}).describe("Actor options for timeouts and behavior configuration.");
|
|
227
232
|
var DocActorConfigSchema = z.object({
|
|
@@ -314,7 +319,7 @@ function isRivetErrorCode(error, group, code) {
|
|
|
314
319
|
// package.json
|
|
315
320
|
var package_default = {
|
|
316
321
|
name: "rivetkit",
|
|
317
|
-
version: "2.3.
|
|
322
|
+
version: "2.3.5-rc.1",
|
|
318
323
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
319
324
|
license: "Apache-2.0",
|
|
320
325
|
keywords: [
|
|
@@ -731,15 +736,21 @@ function loggerWithoutContext() {
|
|
|
731
736
|
}
|
|
732
737
|
|
|
733
738
|
// src/actor/definition.ts
|
|
734
|
-
var
|
|
735
|
-
|
|
739
|
+
var warnedDeprecatedOptionKeys = /* @__PURE__ */ new Set();
|
|
740
|
+
var DEPRECATED_OPTION_MESSAGES = {
|
|
741
|
+
onDestroyTimeout: "Configure `sleepGracePeriod` instead, which bounds the entire graceful shutdown window for both sleep and destroy.",
|
|
742
|
+
waitUntilTimeout: "Configure `sleepGracePeriod` instead, which bounds the entire graceful shutdown window for both sleep and destroy.",
|
|
743
|
+
preloadMaxWorkflowBytes: "Internal storage moved to SQLite and no longer uses KV preloading.",
|
|
744
|
+
preloadMaxConnectionsBytes: "Internal storage moved to SQLite and no longer uses KV preloading."
|
|
745
|
+
};
|
|
746
|
+
function warnDeprecatedOptionKeys(options) {
|
|
736
747
|
if (!options || typeof options !== "object") return;
|
|
737
748
|
const opts = options;
|
|
738
|
-
for (const key of
|
|
739
|
-
if (opts[key] !== void 0 && !
|
|
740
|
-
|
|
749
|
+
for (const [key, detail] of Object.entries(DEPRECATED_OPTION_MESSAGES)) {
|
|
750
|
+
if (opts[key] !== void 0 && !warnedDeprecatedOptionKeys.has(key)) {
|
|
751
|
+
warnedDeprecatedOptionKeys.add(key);
|
|
741
752
|
loggerWithoutContext().warn({
|
|
742
|
-
msg: `actor option \`${key}\` is deprecated and is now ignored.
|
|
753
|
+
msg: `actor option \`${key}\` is deprecated and is now ignored. ${detail} Will be removed in 2.2.0.`
|
|
743
754
|
});
|
|
744
755
|
}
|
|
745
756
|
}
|
|
@@ -754,7 +765,7 @@ var ActorDefinition = class {
|
|
|
754
765
|
}
|
|
755
766
|
};
|
|
756
767
|
function actor(input) {
|
|
757
|
-
|
|
768
|
+
warnDeprecatedOptionKeys(
|
|
758
769
|
input == null ? void 0 : input.options
|
|
759
770
|
);
|
|
760
771
|
const config = ActorConfigSchema.parse(input);
|
|
@@ -767,6 +778,17 @@ function event(options) {
|
|
|
767
778
|
}
|
|
768
779
|
|
|
769
780
|
// src/common/database/shared.ts
|
|
781
|
+
var MIGRATION_TRANSACTION_TIMEOUT_MS = 5 * 6e4;
|
|
782
|
+
function isManualTransactionControl(query) {
|
|
783
|
+
return /^\s*(?:BEGIN|SAVEPOINT|COMMIT|END|ROLLBACK)\b/i.test(query);
|
|
784
|
+
}
|
|
785
|
+
function validateTransactionTimeout(timeout) {
|
|
786
|
+
if (timeout !== void 0 && (!Number.isFinite(timeout) || timeout <= 0)) {
|
|
787
|
+
throw new Error(
|
|
788
|
+
"db.transaction() timeout must be a positive finite number of milliseconds"
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
770
792
|
function isSqliteBindingValue(value) {
|
|
771
793
|
if (value === null || typeof value === "number" || typeof value === "string" || typeof value === "bigint" || value instanceof Uint8Array) {
|
|
772
794
|
return true;
|
|
@@ -811,7 +833,8 @@ function hasMultipleStatements(query) {
|
|
|
811
833
|
return trimmed.includes(";");
|
|
812
834
|
}
|
|
813
835
|
function db({
|
|
814
|
-
onMigrate
|
|
836
|
+
onMigrate,
|
|
837
|
+
warnOnManualTransactions = true
|
|
815
838
|
} = {}) {
|
|
816
839
|
return {
|
|
817
840
|
createClient: async (ctx) => {
|
|
@@ -823,6 +846,7 @@ function db({
|
|
|
823
846
|
}
|
|
824
847
|
const db2 = await nativeDatabaseProvider.open(ctx.actorId);
|
|
825
848
|
let closed = false;
|
|
849
|
+
let manualTransactionWarned = false;
|
|
826
850
|
const ensureOpen = () => {
|
|
827
851
|
if (closed) {
|
|
828
852
|
throw new Error(
|
|
@@ -830,17 +854,24 @@ function db({
|
|
|
830
854
|
);
|
|
831
855
|
}
|
|
832
856
|
};
|
|
833
|
-
const
|
|
857
|
+
const createClient = (target, transactionScoped = false) => ({
|
|
834
858
|
execute: async (query, ...args) => {
|
|
835
859
|
var _a, _b, _c, _d;
|
|
836
860
|
ensureOpen();
|
|
861
|
+
if (!transactionScoped && warnOnManualTransactions && !manualTransactionWarned && !hasMultipleStatements(query) && isManualTransactionControl(query)) {
|
|
862
|
+
manualTransactionWarned = true;
|
|
863
|
+
getLogger("database").warn(
|
|
864
|
+
{ actorId: ctx.actorId },
|
|
865
|
+
"Manual cross-call SQLite transactions can interleave with other actor work. Use db.transaction() for coordinated transactions. Set warnOnManualTransactions: false in your db(...) configuration to disable this warning."
|
|
866
|
+
);
|
|
867
|
+
}
|
|
837
868
|
const kvReadsBefore = ((_a = ctx.metrics) == null ? void 0 : _a.totalKvReads) ?? 0;
|
|
838
869
|
const kvWritesBefore = ((_b = ctx.metrics) == null ? void 0 : _b.totalKvWrites) ?? 0;
|
|
839
870
|
const start = performance.now();
|
|
840
871
|
try {
|
|
841
872
|
if (args.length > 0) {
|
|
842
873
|
const bindings = args.length === 1 && isSqliteBindingObject(args[0]) ? toSqliteBindings(args[0]) : toSqliteBindings(args);
|
|
843
|
-
const { rows, columns } = await
|
|
874
|
+
const { rows, columns } = await target.execute(
|
|
844
875
|
query,
|
|
845
876
|
bindings
|
|
846
877
|
);
|
|
@@ -849,12 +880,15 @@ function db({
|
|
|
849
880
|
);
|
|
850
881
|
}
|
|
851
882
|
if (!hasMultipleStatements(query)) {
|
|
852
|
-
const { rows, columns } = await
|
|
883
|
+
const { rows, columns } = await target.execute(
|
|
884
|
+
query,
|
|
885
|
+
void 0
|
|
886
|
+
);
|
|
853
887
|
return rows.map(
|
|
854
888
|
(row) => rowToObject(row, columns)
|
|
855
889
|
);
|
|
856
890
|
}
|
|
857
|
-
return await execMultiStatement(
|
|
891
|
+
return await execMultiStatement(target, query);
|
|
858
892
|
} finally {
|
|
859
893
|
const durationMs = performance.now() - start;
|
|
860
894
|
(_c = ctx.metrics) == null ? void 0 : _c.trackSql(query, durationMs);
|
|
@@ -871,6 +905,24 @@ function db({
|
|
|
871
905
|
}
|
|
872
906
|
}
|
|
873
907
|
},
|
|
908
|
+
transaction: async (callback, options) => {
|
|
909
|
+
validateTransactionTimeout(options == null ? void 0 : options.timeout);
|
|
910
|
+
const transaction = await db2.beginTransaction(
|
|
911
|
+
options == null ? void 0 : options.timeout
|
|
912
|
+
);
|
|
913
|
+
const tx = createClient(transaction, true);
|
|
914
|
+
try {
|
|
915
|
+
const result = await callback(tx);
|
|
916
|
+
await transaction.commit();
|
|
917
|
+
return result;
|
|
918
|
+
} catch (error) {
|
|
919
|
+
try {
|
|
920
|
+
await transaction.rollback();
|
|
921
|
+
} catch {
|
|
922
|
+
}
|
|
923
|
+
throw error;
|
|
924
|
+
}
|
|
925
|
+
},
|
|
874
926
|
close: async () => {
|
|
875
927
|
if (!closed) {
|
|
876
928
|
closed = true;
|
|
@@ -881,12 +933,16 @@ function db({
|
|
|
881
933
|
var _a;
|
|
882
934
|
return ((_a = db2.nativeMetrics) == null ? void 0 : _a.call(db2)) ?? null;
|
|
883
935
|
}
|
|
884
|
-
};
|
|
936
|
+
});
|
|
937
|
+
const client = createClient(db2);
|
|
885
938
|
return client;
|
|
886
939
|
},
|
|
887
940
|
onMigrate: async (client) => {
|
|
888
941
|
if (onMigrate) {
|
|
889
|
-
await withMigrationSavepoint(
|
|
942
|
+
await withMigrationSavepoint(
|
|
943
|
+
client,
|
|
944
|
+
(leased) => onMigrate(leased)
|
|
945
|
+
);
|
|
890
946
|
}
|
|
891
947
|
}
|
|
892
948
|
};
|
|
@@ -910,19 +966,30 @@ async function execMultiStatement(db2, query) {
|
|
|
910
966
|
return results;
|
|
911
967
|
}
|
|
912
968
|
async function withMigrationSavepoint(client, callback) {
|
|
913
|
-
await client.
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
969
|
+
return await client.transaction(
|
|
970
|
+
async (transaction) => {
|
|
971
|
+
await transaction.execute("SAVEPOINT __rivet_on_migrate");
|
|
972
|
+
try {
|
|
973
|
+
const result = await callback(transaction);
|
|
974
|
+
await transaction.execute(
|
|
975
|
+
"RELEASE SAVEPOINT __rivet_on_migrate"
|
|
976
|
+
);
|
|
977
|
+
return result;
|
|
978
|
+
} catch (error) {
|
|
979
|
+
try {
|
|
980
|
+
await transaction.execute(
|
|
981
|
+
"ROLLBACK TO SAVEPOINT __rivet_on_migrate"
|
|
982
|
+
);
|
|
983
|
+
} finally {
|
|
984
|
+
await transaction.execute(
|
|
985
|
+
"RELEASE SAVEPOINT __rivet_on_migrate"
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
throw error;
|
|
989
|
+
}
|
|
990
|
+
},
|
|
991
|
+
{ timeout: MIGRATION_TRANSACTION_TIMEOUT_MS }
|
|
992
|
+
);
|
|
926
993
|
}
|
|
927
994
|
|
|
928
995
|
// src/agent-os/config.ts
|