rivetkit 3.1.1 → 3.1.2-rc.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.
- package/dist/browser/client.d.ts +16 -1
- package/dist/browser/client.js +1 -1
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -1
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/{chunk-SPSBNPLC.cjs → chunk-6BGQCMIF.cjs} +3 -3
- package/dist/tsup/{chunk-SPSBNPLC.cjs.map → chunk-6BGQCMIF.cjs.map} +1 -1
- package/dist/tsup/{chunk-FBRWBUUV.js → chunk-6MJSWO33.js} +4 -4
- package/dist/tsup/{chunk-C4U5WWM6.js → chunk-6NHRZU52.js} +2 -2
- package/dist/tsup/{chunk-IROHORSE.cjs → chunk-A3N3LJC6.cjs} +10 -10
- package/dist/tsup/{chunk-IROHORSE.cjs.map → chunk-A3N3LJC6.cjs.map} +1 -1
- package/dist/tsup/{chunk-HPVDAB3Q.js → chunk-D2CCGHEJ.js} +4 -3
- package/dist/tsup/chunk-D2CCGHEJ.js.map +1 -0
- package/dist/tsup/{chunk-62DUEJF5.cjs → chunk-DDF35AIK.cjs} +2 -2
- package/dist/tsup/chunk-DDF35AIK.cjs.map +1 -0
- package/dist/tsup/{chunk-JWREVWQL.js → chunk-I6P2AHO6.js} +2 -2
- package/dist/tsup/{chunk-HXFGYYOA.js → chunk-JGMXY4GD.js} +3 -3
- package/dist/tsup/{chunk-ZZQFX3FC.cjs → chunk-L2XH4EXJ.cjs} +146 -146
- package/dist/tsup/{chunk-ZZQFX3FC.cjs.map → chunk-L2XH4EXJ.cjs.map} +1 -1
- package/dist/tsup/{chunk-O4QOORVK.cjs → chunk-LBYX466L.cjs} +3 -3
- package/dist/tsup/{chunk-O4QOORVK.cjs.map → chunk-LBYX466L.cjs.map} +1 -1
- package/dist/tsup/{chunk-RROV4JN4.js → chunk-MRWI2HTU.js} +2 -2
- package/dist/tsup/{chunk-CSYHVROJ.js → chunk-MVOIZGVC.js} +2 -2
- package/dist/tsup/chunk-MVOIZGVC.js.map +1 -0
- package/dist/tsup/{chunk-IULKFTST.js → chunk-N2SQDK2F.js} +3 -3
- package/dist/tsup/{chunk-KTZWFOBF.cjs → chunk-QJ7MIAFD.cjs} +7 -7
- package/dist/tsup/{chunk-KTZWFOBF.cjs.map → chunk-QJ7MIAFD.cjs.map} +1 -1
- package/dist/tsup/{chunk-2X7ZRXPW.cjs → chunk-TAK6KRMJ.cjs} +5 -4
- package/dist/tsup/chunk-TAK6KRMJ.cjs.map +1 -0
- package/dist/tsup/{chunk-AGFOGGFH.cjs → chunk-YAGP66QF.cjs} +4 -4
- package/dist/tsup/{chunk-AGFOGGFH.cjs.map → chunk-YAGP66QF.cjs.map} +1 -1
- package/dist/tsup/client/mod.cjs +5 -5
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- package/dist/tsup/client/mod.js +4 -4
- 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-BDdeBoxX.d.cts → config-BMGUEKMZ.d.cts} +16 -1
- package/dist/tsup/{config-Ch-SMJ-n.d.ts → config-iBpXyITj.d.ts} +16 -1
- package/dist/tsup/{context-B-wRuYrf.d.ts → context-hyVakgnU.d.ts} +1 -1
- package/dist/tsup/{context-NzsxAAoN.d.cts → context-qfvLuF0P.d.cts} +1 -1
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +3 -3
- package/dist/tsup/db/mod.js +2 -2
- package/dist/tsup/dynamic/mod.d.cts +1 -1
- package/dist/tsup/dynamic/mod.d.ts +1 -1
- package/dist/tsup/inspector/mod.cjs +5 -5
- package/dist/tsup/inspector/mod.js +4 -4
- package/dist/tsup/inspector/workflow.cjs +4 -4
- package/dist/tsup/inspector/workflow.js +3 -3
- package/dist/tsup/inspector-tab/mod.d.cts +2 -2
- package/dist/tsup/inspector-tab/mod.d.ts +2 -2
- package/dist/tsup/mod.cjs +399 -126
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +3 -3
- package/dist/tsup/mod.d.ts +3 -3
- package/dist/tsup/mod.js +319 -46
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +6 -6
- package/dist/tsup/test/mod.d.cts +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +4 -4
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +35 -27
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +3 -3
- package/dist/tsup/workflow/mod.d.ts +3 -3
- package/dist/tsup/workflow/mod.js +32 -24
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +9 -9
- package/src/common/database/config.ts +52 -0
- package/src/common/database/mod.ts +3 -0
- package/src/common/database/native-database.ts +240 -19
- package/src/registry/napi-runtime.ts +80 -0
- package/src/registry/native.ts +70 -20
- package/src/registry/runtime.ts +53 -0
- package/src/registry/wasm-runtime.ts +91 -1
- package/src/workflow/driver.ts +29 -20
- package/dist/tsup/chunk-2X7ZRXPW.cjs.map +0 -1
- package/dist/tsup/chunk-62DUEJF5.cjs.map +0 -1
- package/dist/tsup/chunk-CSYHVROJ.js.map +0 -1
- package/dist/tsup/chunk-HPVDAB3Q.js.map +0 -1
- /package/dist/tsup/{chunk-FBRWBUUV.js.map → chunk-6MJSWO33.js.map} +0 -0
- /package/dist/tsup/{chunk-C4U5WWM6.js.map → chunk-6NHRZU52.js.map} +0 -0
- /package/dist/tsup/{chunk-JWREVWQL.js.map → chunk-I6P2AHO6.js.map} +0 -0
- /package/dist/tsup/{chunk-HXFGYYOA.js.map → chunk-JGMXY4GD.js.map} +0 -0
- /package/dist/tsup/{chunk-RROV4JN4.js.map → chunk-MRWI2HTU.js.map} +0 -0
- /package/dist/tsup/{chunk-IULKFTST.js.map → chunk-N2SQDK2F.js.map} +0 -0
package/dist/tsup/mod.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeWorkflowHistoryTransport
|
|
3
|
+
} from "./chunk-I6P2AHO6.js";
|
|
1
4
|
import {
|
|
2
5
|
ACTOR_CONTEXT_INTERNAL_SYMBOL,
|
|
3
6
|
ActorConfigSchema,
|
|
@@ -15,9 +18,6 @@ import {
|
|
|
15
18
|
getRunMetadata,
|
|
16
19
|
hasRunInspectorConfig
|
|
17
20
|
} from "./chunk-IHEO5OT3.js";
|
|
18
|
-
import {
|
|
19
|
-
decodeWorkflowHistoryTransport
|
|
20
|
-
} from "./chunk-JWREVWQL.js";
|
|
21
21
|
import {
|
|
22
22
|
ALLOWED_PUBLIC_HEADERS,
|
|
23
23
|
ENGINE_HOST,
|
|
@@ -35,17 +35,17 @@ import {
|
|
|
35
35
|
runWithActorInvocationSpan,
|
|
36
36
|
tryParseEndpoint,
|
|
37
37
|
updateRunnerConfig
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-JGMXY4GD.js";
|
|
39
39
|
import {
|
|
40
40
|
makePrefixedKey,
|
|
41
41
|
removePrefixFromKey
|
|
42
42
|
} from "./chunk-A2CF6PFH.js";
|
|
43
|
-
import "./chunk-
|
|
43
|
+
import "./chunk-MRWI2HTU.js";
|
|
44
44
|
import {
|
|
45
45
|
bindNativeStateTransactionContext,
|
|
46
46
|
db,
|
|
47
47
|
registerNativeStateTransactionOpener
|
|
48
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-D2CCGHEJ.js";
|
|
49
49
|
import "./chunk-JTHHCZCZ.js";
|
|
50
50
|
import {
|
|
51
51
|
LogLevelSchema,
|
|
@@ -80,7 +80,7 @@ import {
|
|
|
80
80
|
parsePortEnv,
|
|
81
81
|
stringifyError,
|
|
82
82
|
toUint8Array
|
|
83
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-MVOIZGVC.js";
|
|
84
84
|
import {
|
|
85
85
|
INTERNAL_ERROR_CODE,
|
|
86
86
|
RivetError,
|
|
@@ -971,6 +971,11 @@ var DocRegistryConfigSchema = z3.object({
|
|
|
971
971
|
import { VirtualWebSocket as VirtualWebSocket2 } from "@rivetkit/virtual-websocket";
|
|
972
972
|
|
|
973
973
|
// src/common/database/native-database.ts
|
|
974
|
+
var EXECUTE_BATCH_TRANSACTION_NAME = "rivetkit-execute-batch";
|
|
975
|
+
function isSynchronousTransaction(transaction) {
|
|
976
|
+
const candidate = transaction;
|
|
977
|
+
return typeof candidate.commitSync === "function" && typeof candidate.rollbackSync === "function";
|
|
978
|
+
}
|
|
974
979
|
function shouldAttachNativeKvError(message) {
|
|
975
980
|
return /i\/o error|unable to open database file/i.test(message);
|
|
976
981
|
}
|
|
@@ -992,6 +997,11 @@ function toNativeBinding(arg) {
|
|
|
992
997
|
return { kind: "null" };
|
|
993
998
|
}
|
|
994
999
|
if (typeof arg === "bigint") {
|
|
1000
|
+
if (arg > BigInt(Number.MAX_SAFE_INTEGER) || arg < BigInt(Number.MIN_SAFE_INTEGER)) {
|
|
1001
|
+
throw new RangeError(
|
|
1002
|
+
"SQLite bigint bindings must be within the JavaScript safe integer range."
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
995
1005
|
return { kind: "int", intValue: Number(arg) };
|
|
996
1006
|
}
|
|
997
1007
|
if (typeof arg === "number") {
|
|
@@ -1014,9 +1024,10 @@ function toNativeBinding(arg) {
|
|
|
1014
1024
|
function extractNamedSqliteParameters(sql) {
|
|
1015
1025
|
const orderedNames = [];
|
|
1016
1026
|
const seen = /* @__PURE__ */ new Set();
|
|
1017
|
-
const pattern = /([:@$][A-Za-z_][
|
|
1027
|
+
const pattern = /'(?:''|[^'])*'|"(?:""|[^"])*"|`(?:``|[^`])*`|\[[^\]]*\]|--[^\n]*|\/\*[\s\S]*?(?:\*\/|$)|([:@$][\w$\u0080-\u{10FFFF}]+(?:::[\w$\u0080-\u{10FFFF}]+)*(?:\([^)]*\))?)|[A-Za-z_\u0080-\u{10FFFF}][\w$\u0080-\u{10FFFF}]*/gu;
|
|
1018
1028
|
for (const match of sql.matchAll(pattern)) {
|
|
1019
1029
|
const name = match[1];
|
|
1030
|
+
if (!name) continue;
|
|
1020
1031
|
if (seen.has(name)) {
|
|
1021
1032
|
continue;
|
|
1022
1033
|
}
|
|
@@ -1135,20 +1146,44 @@ function wrapJsNativeDatabase(database) {
|
|
|
1135
1146
|
let terminalPromise;
|
|
1136
1147
|
let lastInsertRowId = null;
|
|
1137
1148
|
const executeNative = async (sql, params) => {
|
|
1138
|
-
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
1139
|
-
if (lastInsertRowIdColumn) {
|
|
1140
|
-
return {
|
|
1141
|
-
columns: [lastInsertRowIdColumn],
|
|
1142
|
-
rows: [[lastInsertRowId ?? 0]],
|
|
1143
|
-
changes: 0,
|
|
1144
|
-
lastInsertRowId
|
|
1145
|
-
};
|
|
1146
|
-
}
|
|
1147
1149
|
const release = gate.enter();
|
|
1148
1150
|
try {
|
|
1151
|
+
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
1152
|
+
if (lastInsertRowIdColumn) {
|
|
1153
|
+
return {
|
|
1154
|
+
columns: [lastInsertRowIdColumn],
|
|
1155
|
+
rows: [[lastInsertRowId ?? 0]],
|
|
1156
|
+
changes: 0,
|
|
1157
|
+
lastInsertRowId
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1149
1160
|
const nativeParams = toNativeBindings(sql, params);
|
|
1150
1161
|
const result = await database.execute(sql, nativeParams);
|
|
1151
|
-
if (result.lastInsertRowId
|
|
1162
|
+
if (result.lastInsertRowId != null) {
|
|
1163
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
1164
|
+
}
|
|
1165
|
+
return result;
|
|
1166
|
+
} catch (error) {
|
|
1167
|
+
enrichNativeDatabaseError(database, error);
|
|
1168
|
+
} finally {
|
|
1169
|
+
release();
|
|
1170
|
+
}
|
|
1171
|
+
};
|
|
1172
|
+
const executeNativeSync = (sql, params) => {
|
|
1173
|
+
const release = gate.enter();
|
|
1174
|
+
try {
|
|
1175
|
+
const nativeParams = toNativeBindings(sql, params);
|
|
1176
|
+
const result = database.executeSync(sql, nativeParams);
|
|
1177
|
+
const rowIdColumn = lastInsertRowIdColumnName(sql);
|
|
1178
|
+
if (rowIdColumn) {
|
|
1179
|
+
return {
|
|
1180
|
+
columns: [rowIdColumn],
|
|
1181
|
+
rows: [[lastInsertRowId ?? 0]],
|
|
1182
|
+
changes: 0,
|
|
1183
|
+
lastInsertRowId
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
if (result.lastInsertRowId != null) {
|
|
1152
1187
|
lastInsertRowId = result.lastInsertRowId;
|
|
1153
1188
|
}
|
|
1154
1189
|
return result;
|
|
@@ -1176,16 +1211,38 @@ function wrapJsNativeDatabase(database) {
|
|
|
1176
1211
|
callback(row, result.columns);
|
|
1177
1212
|
}
|
|
1178
1213
|
},
|
|
1214
|
+
execSync(sql, callback) {
|
|
1215
|
+
const release = gate.enter();
|
|
1216
|
+
let result;
|
|
1217
|
+
try {
|
|
1218
|
+
result = database.execSync(sql);
|
|
1219
|
+
} catch (error) {
|
|
1220
|
+
enrichNativeDatabaseError(database, error);
|
|
1221
|
+
} finally {
|
|
1222
|
+
release();
|
|
1223
|
+
}
|
|
1224
|
+
if (callback) {
|
|
1225
|
+
for (const row of result.rows) {
|
|
1226
|
+
callback(row, result.columns);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
},
|
|
1179
1230
|
async execute(sql, params) {
|
|
1180
1231
|
return await executeNative(sql, params);
|
|
1181
1232
|
},
|
|
1233
|
+
executeSync(sql, params) {
|
|
1234
|
+
return executeNativeSync(sql, params);
|
|
1235
|
+
},
|
|
1182
1236
|
async executeBatch(statements) {
|
|
1183
1237
|
const nativeStatements = statements.map(toNativeBatchStatement);
|
|
1184
1238
|
const release = gate.enter();
|
|
1185
1239
|
let transaction;
|
|
1186
1240
|
try {
|
|
1187
1241
|
const results = database.executeBatch ? await database.executeBatch(nativeStatements) : await (async () => {
|
|
1188
|
-
transaction = await database.beginTransaction(
|
|
1242
|
+
transaction = await database.beginTransaction(
|
|
1243
|
+
void 0,
|
|
1244
|
+
EXECUTE_BATCH_TRANSACTION_NAME
|
|
1245
|
+
);
|
|
1189
1246
|
const transactionResults = [];
|
|
1190
1247
|
for (const statement of nativeStatements) {
|
|
1191
1248
|
transactionResults.push(
|
|
@@ -1200,7 +1257,7 @@ function wrapJsNativeDatabase(database) {
|
|
|
1200
1257
|
return transactionResults;
|
|
1201
1258
|
})();
|
|
1202
1259
|
for (const result of results) {
|
|
1203
|
-
if (result.lastInsertRowId
|
|
1260
|
+
if (result.lastInsertRowId != null) {
|
|
1204
1261
|
lastInsertRowId = result.lastInsertRowId;
|
|
1205
1262
|
}
|
|
1206
1263
|
}
|
|
@@ -1228,12 +1285,28 @@ function wrapJsNativeDatabase(database) {
|
|
|
1228
1285
|
release();
|
|
1229
1286
|
}
|
|
1230
1287
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
1231
|
-
if (result.lastInsertRowId
|
|
1288
|
+
if (result.lastInsertRowId != null) {
|
|
1289
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
1290
|
+
}
|
|
1291
|
+
});
|
|
1292
|
+
},
|
|
1293
|
+
beginTransactionSync(timeoutMs, name) {
|
|
1294
|
+
const release = gate.enter();
|
|
1295
|
+
let transaction;
|
|
1296
|
+
try {
|
|
1297
|
+
transaction = database.beginTransactionSync(timeoutMs, name);
|
|
1298
|
+
} catch (error) {
|
|
1299
|
+
enrichNativeDatabaseError(database, error);
|
|
1300
|
+
} finally {
|
|
1301
|
+
release();
|
|
1302
|
+
}
|
|
1303
|
+
return wrapTransaction(database, transaction, gate, (result) => {
|
|
1304
|
+
if (result.lastInsertRowId != null) {
|
|
1232
1305
|
lastInsertRowId = result.lastInsertRowId;
|
|
1233
1306
|
}
|
|
1234
1307
|
});
|
|
1235
1308
|
},
|
|
1236
|
-
async beginStateTransaction(timeoutMs, context) {
|
|
1309
|
+
async beginStateTransaction(timeoutMs, context, name) {
|
|
1237
1310
|
if (!database.beginStateTransaction) {
|
|
1238
1311
|
throw new Error("actor state transactions are not configured");
|
|
1239
1312
|
}
|
|
@@ -1242,7 +1315,8 @@ function wrapJsNativeDatabase(database) {
|
|
|
1242
1315
|
try {
|
|
1243
1316
|
transaction = await database.beginStateTransaction(
|
|
1244
1317
|
timeoutMs,
|
|
1245
|
-
context
|
|
1318
|
+
context,
|
|
1319
|
+
name
|
|
1246
1320
|
);
|
|
1247
1321
|
} catch (error) {
|
|
1248
1322
|
enrichNativeDatabaseError(database, error);
|
|
@@ -1250,7 +1324,7 @@ function wrapJsNativeDatabase(database) {
|
|
|
1250
1324
|
release();
|
|
1251
1325
|
}
|
|
1252
1326
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
1253
|
-
if (result.lastInsertRowId
|
|
1327
|
+
if (result.lastInsertRowId != null) {
|
|
1254
1328
|
lastInsertRowId = result.lastInsertRowId;
|
|
1255
1329
|
}
|
|
1256
1330
|
});
|
|
@@ -1266,6 +1340,25 @@ function wrapJsNativeDatabase(database) {
|
|
|
1266
1340
|
var _a;
|
|
1267
1341
|
return normalizeNativeMetrics((_a = database.metrics) == null ? void 0 : _a.call(database));
|
|
1268
1342
|
},
|
|
1343
|
+
async open() {
|
|
1344
|
+
const release = gate.enter();
|
|
1345
|
+
try {
|
|
1346
|
+
await database.open();
|
|
1347
|
+
} catch (error) {
|
|
1348
|
+
enrichNativeDatabaseError(database, error);
|
|
1349
|
+
} finally {
|
|
1350
|
+
release();
|
|
1351
|
+
}
|
|
1352
|
+
},
|
|
1353
|
+
commitTicket() {
|
|
1354
|
+
return database.commitTicket();
|
|
1355
|
+
},
|
|
1356
|
+
async whenDurable(ticket) {
|
|
1357
|
+
await database.whenDurable(ticket);
|
|
1358
|
+
},
|
|
1359
|
+
abortGeneration(reason) {
|
|
1360
|
+
database.abortGeneration(reason);
|
|
1361
|
+
},
|
|
1269
1362
|
async close() {
|
|
1270
1363
|
terminalPromise ??= gate.close(() => database.close());
|
|
1271
1364
|
await terminalPromise;
|
|
@@ -1277,7 +1370,7 @@ function wrapJsNativeDatabase(database) {
|
|
|
1277
1370
|
};
|
|
1278
1371
|
}
|
|
1279
1372
|
function wrapTransaction(database, transaction, gate, onExecute) {
|
|
1280
|
-
|
|
1373
|
+
const wrapped = {
|
|
1281
1374
|
async exec(sql, callback) {
|
|
1282
1375
|
const release = gate.enter();
|
|
1283
1376
|
let result;
|
|
@@ -1328,6 +1421,61 @@ function wrapTransaction(database, transaction, gate, onExecute) {
|
|
|
1328
1421
|
}
|
|
1329
1422
|
}
|
|
1330
1423
|
};
|
|
1424
|
+
if (isSynchronousTransaction(transaction)) {
|
|
1425
|
+
return Object.assign(wrapped, {
|
|
1426
|
+
execSync(sql, callback) {
|
|
1427
|
+
const release = gate.enter();
|
|
1428
|
+
let result;
|
|
1429
|
+
try {
|
|
1430
|
+
result = transaction.execSync(sql);
|
|
1431
|
+
} catch (error) {
|
|
1432
|
+
enrichNativeDatabaseError(database, error);
|
|
1433
|
+
} finally {
|
|
1434
|
+
release();
|
|
1435
|
+
}
|
|
1436
|
+
if (callback) {
|
|
1437
|
+
for (const row of result.rows)
|
|
1438
|
+
callback(row, result.columns);
|
|
1439
|
+
}
|
|
1440
|
+
},
|
|
1441
|
+
executeSync(sql, params) {
|
|
1442
|
+
const release = gate.enter();
|
|
1443
|
+
try {
|
|
1444
|
+
const result = transaction.executeSync(
|
|
1445
|
+
sql,
|
|
1446
|
+
toNativeBindings(sql, params)
|
|
1447
|
+
);
|
|
1448
|
+
onExecute(result);
|
|
1449
|
+
return result;
|
|
1450
|
+
} catch (error) {
|
|
1451
|
+
enrichNativeDatabaseError(database, error);
|
|
1452
|
+
} finally {
|
|
1453
|
+
release();
|
|
1454
|
+
}
|
|
1455
|
+
},
|
|
1456
|
+
commitSync() {
|
|
1457
|
+
const release = gate.enter();
|
|
1458
|
+
try {
|
|
1459
|
+
transaction.commitSync();
|
|
1460
|
+
} catch (error) {
|
|
1461
|
+
enrichNativeDatabaseError(database, error);
|
|
1462
|
+
} finally {
|
|
1463
|
+
release();
|
|
1464
|
+
}
|
|
1465
|
+
},
|
|
1466
|
+
rollbackSync() {
|
|
1467
|
+
const release = gate.enter();
|
|
1468
|
+
try {
|
|
1469
|
+
transaction.rollbackSync();
|
|
1470
|
+
} catch (error) {
|
|
1471
|
+
enrichNativeDatabaseError(database, error);
|
|
1472
|
+
} finally {
|
|
1473
|
+
release();
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
return wrapped;
|
|
1331
1479
|
}
|
|
1332
1480
|
function lastInsertRowIdColumnName(sql) {
|
|
1333
1481
|
const match = sql.match(
|
|
@@ -1927,6 +2075,9 @@ var NapiCoreRuntime = class {
|
|
|
1927
2075
|
async actorSqlExec(ctx, sql) {
|
|
1928
2076
|
return await this.#actorSql(ctx).exec(sql);
|
|
1929
2077
|
}
|
|
2078
|
+
actorSqlExecSync(ctx, sql) {
|
|
2079
|
+
return this.#actorSql(ctx).execSync(sql);
|
|
2080
|
+
}
|
|
1930
2081
|
async actorSqlExecute(ctx, sql, params) {
|
|
1931
2082
|
const result = await this.#actorSql(ctx).execute(
|
|
1932
2083
|
sql,
|
|
@@ -1934,6 +2085,13 @@ var NapiCoreRuntime = class {
|
|
|
1934
2085
|
);
|
|
1935
2086
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
1936
2087
|
}
|
|
2088
|
+
actorSqlExecuteSync(ctx, sql, params) {
|
|
2089
|
+
const result = this.#actorSql(ctx).executeSync(
|
|
2090
|
+
sql,
|
|
2091
|
+
toNapiSqlBindParams(params)
|
|
2092
|
+
);
|
|
2093
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
2094
|
+
}
|
|
1937
2095
|
async actorSqlExecuteBatch(ctx, statements) {
|
|
1938
2096
|
const results = await this.#actorSql(ctx).executeBatch(
|
|
1939
2097
|
statements.map(toNapiSqlBatchStatement)
|
|
@@ -1946,9 +2104,18 @@ var NapiCoreRuntime = class {
|
|
|
1946
2104
|
name
|
|
1947
2105
|
);
|
|
1948
2106
|
}
|
|
2107
|
+
actorSqlBeginTransactionSync(ctx, timeoutMs, name) {
|
|
2108
|
+
return this.#actorSql(ctx).beginTransactionSync(
|
|
2109
|
+
timeoutMs,
|
|
2110
|
+
name
|
|
2111
|
+
);
|
|
2112
|
+
}
|
|
1949
2113
|
async actorSqlTransactionExec(transaction, sql) {
|
|
1950
2114
|
return await asNativeSqlTransaction(transaction).exec(sql);
|
|
1951
2115
|
}
|
|
2116
|
+
actorSqlTransactionExecSync(transaction, sql) {
|
|
2117
|
+
return asNativeSqlTransaction(transaction).execSync(sql);
|
|
2118
|
+
}
|
|
1952
2119
|
async actorSqlTransactionExecute(transaction, sql, params) {
|
|
1953
2120
|
const result = await asNativeSqlTransaction(transaction).execute(
|
|
1954
2121
|
sql,
|
|
@@ -1956,15 +2123,29 @@ var NapiCoreRuntime = class {
|
|
|
1956
2123
|
);
|
|
1957
2124
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
1958
2125
|
}
|
|
2126
|
+
actorSqlTransactionExecuteSync(transaction, sql, params) {
|
|
2127
|
+
const result = asNativeSqlTransaction(transaction).executeSync(
|
|
2128
|
+
sql,
|
|
2129
|
+
toNapiSqlBindParams(params)
|
|
2130
|
+
);
|
|
2131
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
2132
|
+
}
|
|
1959
2133
|
async actorSqlTransactionCommit(transaction) {
|
|
1960
2134
|
await asNativeSqlTransaction(transaction).commit();
|
|
1961
2135
|
}
|
|
2136
|
+
actorSqlTransactionCommitSync(transaction) {
|
|
2137
|
+
asNativeSqlTransaction(transaction).commitSync();
|
|
2138
|
+
}
|
|
1962
2139
|
async actorSqlTransactionRollback(transaction) {
|
|
1963
2140
|
await asNativeSqlTransaction(transaction).rollback();
|
|
1964
2141
|
}
|
|
1965
|
-
|
|
2142
|
+
actorSqlTransactionRollbackSync(transaction) {
|
|
2143
|
+
asNativeSqlTransaction(transaction).rollbackSync();
|
|
2144
|
+
}
|
|
2145
|
+
async actorBeginStateTransaction(ctx, timeoutMs, name) {
|
|
1966
2146
|
return await this.#actorContextForOperation(ctx).beginStateTransaction(
|
|
1967
|
-
timeoutMs
|
|
2147
|
+
timeoutMs,
|
|
2148
|
+
name
|
|
1968
2149
|
);
|
|
1969
2150
|
}
|
|
1970
2151
|
async actorStateTransactionExecute(transaction, sql, params) {
|
|
@@ -1999,6 +2180,18 @@ var NapiCoreRuntime = class {
|
|
|
1999
2180
|
var _a, _b;
|
|
2000
2181
|
return ((_b = (_a = this.#actorSql(ctx)).takeLastKvError) == null ? void 0 : _b.call(_a)) ?? null;
|
|
2001
2182
|
}
|
|
2183
|
+
async actorSqlOpen(ctx) {
|
|
2184
|
+
await this.#actorSql(ctx).open();
|
|
2185
|
+
}
|
|
2186
|
+
actorSqlCommitTicket(ctx) {
|
|
2187
|
+
return this.#actorSql(ctx).commitTicket();
|
|
2188
|
+
}
|
|
2189
|
+
actorSqlAbortGeneration(ctx, reason) {
|
|
2190
|
+
this.#actorSql(ctx).abortGeneration(reason);
|
|
2191
|
+
}
|
|
2192
|
+
async actorSqlWhenDurable(ctx, ticket) {
|
|
2193
|
+
await this.#actorSql(ctx).whenDurable(ticket);
|
|
2194
|
+
}
|
|
2002
2195
|
async actorSqlClose(ctx) {
|
|
2003
2196
|
const nativeCtx = asNativeActorContext(ctx);
|
|
2004
2197
|
if (!this.#sqlOpened.delete(nativeCtx)) {
|
|
@@ -2579,6 +2772,17 @@ function optionalWasmNumber(value) {
|
|
|
2579
2772
|
function wasmNumber(value) {
|
|
2580
2773
|
return typeof value === "bigint" ? Number(value) : value;
|
|
2581
2774
|
}
|
|
2775
|
+
function synchronousSqliteUnavailable() {
|
|
2776
|
+
throw new RivetError(
|
|
2777
|
+
"sqlite",
|
|
2778
|
+
"sync_unsupported",
|
|
2779
|
+
"Synchronous SQLite is unavailable because the actor runs on the wasm runtime.",
|
|
2780
|
+
{
|
|
2781
|
+
public: true,
|
|
2782
|
+
metadata: { runtime: "wasm" }
|
|
2783
|
+
}
|
|
2784
|
+
);
|
|
2785
|
+
}
|
|
2582
2786
|
function normalizeKvEntry(entry) {
|
|
2583
2787
|
return {
|
|
2584
2788
|
key: toBytes(entry.key),
|
|
@@ -2730,6 +2934,14 @@ var WasmCoreRuntime = class {
|
|
|
2730
2934
|
);
|
|
2731
2935
|
}
|
|
2732
2936
|
createActorFactory(callbacks, config) {
|
|
2937
|
+
if (config == null ? void 0 : config.sqliteDeferredCommits) {
|
|
2938
|
+
throw new RivetError(
|
|
2939
|
+
"sqlite",
|
|
2940
|
+
"deferred_commits_unsupported",
|
|
2941
|
+
"SQLite deferred commits require local native SQLite, but the wasm runtime uses remote SQLite.",
|
|
2942
|
+
{ metadata: { runtime: "wasm" } }
|
|
2943
|
+
);
|
|
2944
|
+
}
|
|
2733
2945
|
return callWasmSync(
|
|
2734
2946
|
() => asActorFactoryHandle2(
|
|
2735
2947
|
new this.#constructors.ActorFactory(callbacks, config)
|
|
@@ -3012,12 +3224,18 @@ var WasmCoreRuntime = class {
|
|
|
3012
3224
|
async actorSqlExec(ctx, sql) {
|
|
3013
3225
|
return await callWasm(() => this.#actorSql(ctx).exec(sql));
|
|
3014
3226
|
}
|
|
3227
|
+
actorSqlExecSync(_ctx, _sql) {
|
|
3228
|
+
return synchronousSqliteUnavailable();
|
|
3229
|
+
}
|
|
3015
3230
|
async actorSqlExecute(ctx, sql, params) {
|
|
3016
3231
|
const result = await callWasm(
|
|
3017
3232
|
() => this.#actorSql(ctx).execute(sql, params)
|
|
3018
3233
|
);
|
|
3019
3234
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
3020
3235
|
}
|
|
3236
|
+
actorSqlExecuteSync(_ctx, _sql, _params) {
|
|
3237
|
+
return synchronousSqliteUnavailable();
|
|
3238
|
+
}
|
|
3021
3239
|
async actorSqlExecuteBatch(ctx, statements) {
|
|
3022
3240
|
const results = await callWasm(
|
|
3023
3241
|
() => this.#actorSql(ctx).executeBatch(statements)
|
|
@@ -3029,30 +3247,45 @@ var WasmCoreRuntime = class {
|
|
|
3029
3247
|
() => this.#actorSql(ctx).beginTransaction(timeoutMs, name)
|
|
3030
3248
|
);
|
|
3031
3249
|
}
|
|
3250
|
+
actorSqlBeginTransactionSync(_ctx, _timeoutMs, _name) {
|
|
3251
|
+
return synchronousSqliteUnavailable();
|
|
3252
|
+
}
|
|
3032
3253
|
async actorSqlTransactionExec(transaction, sql) {
|
|
3033
3254
|
return await callWasm(
|
|
3034
3255
|
() => transaction.exec(sql)
|
|
3035
3256
|
);
|
|
3036
3257
|
}
|
|
3258
|
+
actorSqlTransactionExecSync(_transaction, _sql) {
|
|
3259
|
+
return synchronousSqliteUnavailable();
|
|
3260
|
+
}
|
|
3037
3261
|
async actorSqlTransactionExecute(transaction, sql, params) {
|
|
3038
3262
|
const result = await callWasm(
|
|
3039
3263
|
() => transaction.execute(sql, params)
|
|
3040
3264
|
);
|
|
3041
3265
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
3042
3266
|
}
|
|
3267
|
+
actorSqlTransactionExecuteSync(_transaction, _sql, _params) {
|
|
3268
|
+
return synchronousSqliteUnavailable();
|
|
3269
|
+
}
|
|
3043
3270
|
async actorSqlTransactionCommit(transaction) {
|
|
3044
3271
|
await callWasm(
|
|
3045
3272
|
() => transaction.commit()
|
|
3046
3273
|
);
|
|
3047
3274
|
}
|
|
3275
|
+
actorSqlTransactionCommitSync(_transaction) {
|
|
3276
|
+
synchronousSqliteUnavailable();
|
|
3277
|
+
}
|
|
3048
3278
|
async actorSqlTransactionRollback(transaction) {
|
|
3049
3279
|
await callWasm(
|
|
3050
3280
|
() => transaction.rollback()
|
|
3051
3281
|
);
|
|
3052
3282
|
}
|
|
3053
|
-
|
|
3283
|
+
actorSqlTransactionRollbackSync(_transaction) {
|
|
3284
|
+
synchronousSqliteUnavailable();
|
|
3285
|
+
}
|
|
3286
|
+
async actorBeginStateTransaction(ctx, timeoutMs, name) {
|
|
3054
3287
|
return await callWasm(
|
|
3055
|
-
() => asWasmActorContext(ctx).beginStateTransaction(timeoutMs)
|
|
3288
|
+
() => asWasmActorContext(ctx).beginStateTransaction(timeoutMs, name)
|
|
3056
3289
|
);
|
|
3057
3290
|
}
|
|
3058
3291
|
async actorStateTransactionExecute(transaction, sql, params) {
|
|
@@ -3085,6 +3318,17 @@ var WasmCoreRuntime = class {
|
|
|
3085
3318
|
var _a, _b;
|
|
3086
3319
|
return ((_b = (_a = this.#actorSql(ctx)).takeLastKvError) == null ? void 0 : _b.call(_a)) ?? null;
|
|
3087
3320
|
}
|
|
3321
|
+
async actorSqlOpen(_ctx) {
|
|
3322
|
+
}
|
|
3323
|
+
actorSqlCommitTicket(_ctx) {
|
|
3324
|
+
return synchronousSqliteUnavailable();
|
|
3325
|
+
}
|
|
3326
|
+
actorSqlAbortGeneration(_ctx, _reason) {
|
|
3327
|
+
synchronousSqliteUnavailable();
|
|
3328
|
+
}
|
|
3329
|
+
async actorSqlWhenDurable(_ctx, _ticket) {
|
|
3330
|
+
synchronousSqliteUnavailable();
|
|
3331
|
+
}
|
|
3088
3332
|
async actorSqlClose(ctx) {
|
|
3089
3333
|
const wasmCtx = asWasmActorContext(ctx);
|
|
3090
3334
|
const database = this.#sql.get(wasmCtx);
|
|
@@ -3730,15 +3974,29 @@ async function closeNativeDatabaseClient(runtime, ctx) {
|
|
|
3730
3974
|
await entry.client.close();
|
|
3731
3975
|
}
|
|
3732
3976
|
}
|
|
3977
|
+
function createNativeSqlTransaction(runtime, transaction) {
|
|
3978
|
+
return {
|
|
3979
|
+
exec: (sql) => runtime.actorSqlTransactionExec(transaction, sql),
|
|
3980
|
+
execSync: (sql) => runtime.actorSqlTransactionExecSync(transaction, sql),
|
|
3981
|
+
execute: (sql, params) => runtime.actorSqlTransactionExecute(transaction, sql, params),
|
|
3982
|
+
executeSync: (sql, params) => runtime.actorSqlTransactionExecuteSync(transaction, sql, params),
|
|
3983
|
+
commit: () => runtime.actorSqlTransactionCommit(transaction),
|
|
3984
|
+
commitSync: () => runtime.actorSqlTransactionCommitSync(transaction),
|
|
3985
|
+
rollback: () => runtime.actorSqlTransactionRollback(transaction),
|
|
3986
|
+
rollbackSync: () => runtime.actorSqlTransactionRollbackSync(transaction)
|
|
3987
|
+
};
|
|
3988
|
+
}
|
|
3733
3989
|
function getOrCreateNativeSqlDatabase(runtime, ctx) {
|
|
3734
3990
|
const runtimeState = getNativeRuntimeState(runtime, ctx);
|
|
3735
3991
|
const cachedDatabase = runtimeState.sql;
|
|
3736
3992
|
if (cachedDatabase) {
|
|
3737
3993
|
return cachedDatabase;
|
|
3738
3994
|
}
|
|
3739
|
-
const
|
|
3995
|
+
const bindings = {
|
|
3740
3996
|
exec: (sql) => runtime.actorSqlExec(ctx, sql),
|
|
3997
|
+
execSync: (sql) => runtime.actorSqlExecSync(ctx, sql),
|
|
3741
3998
|
execute: (sql, params) => runtime.actorSqlExecute(ctx, sql, params),
|
|
3999
|
+
executeSync: (sql, params) => runtime.actorSqlExecuteSync(ctx, sql, params),
|
|
3742
4000
|
executeBatch: (statements) => runtime.actorSqlExecuteBatch(ctx, statements),
|
|
3743
4001
|
beginTransaction: async (timeoutMs, name) => {
|
|
3744
4002
|
const transaction = await runtime.actorSqlBeginTransaction(
|
|
@@ -3746,18 +4004,17 @@ function getOrCreateNativeSqlDatabase(runtime, ctx) {
|
|
|
3746
4004
|
timeoutMs,
|
|
3747
4005
|
name
|
|
3748
4006
|
);
|
|
3749
|
-
return
|
|
3750
|
-
exec: (sql) => runtime.actorSqlTransactionExec(transaction, sql),
|
|
3751
|
-
execute: (sql, params) => runtime.actorSqlTransactionExecute(
|
|
3752
|
-
transaction,
|
|
3753
|
-
sql,
|
|
3754
|
-
params
|
|
3755
|
-
),
|
|
3756
|
-
commit: () => runtime.actorSqlTransactionCommit(transaction),
|
|
3757
|
-
rollback: () => runtime.actorSqlTransactionRollback(transaction)
|
|
3758
|
-
};
|
|
4007
|
+
return createNativeSqlTransaction(runtime, transaction);
|
|
3759
4008
|
},
|
|
3760
|
-
|
|
4009
|
+
beginTransactionSync: (timeoutMs, name) => {
|
|
4010
|
+
const transaction = runtime.actorSqlBeginTransactionSync(
|
|
4011
|
+
ctx,
|
|
4012
|
+
timeoutMs,
|
|
4013
|
+
name
|
|
4014
|
+
);
|
|
4015
|
+
return createNativeSqlTransaction(runtime, transaction);
|
|
4016
|
+
},
|
|
4017
|
+
beginStateTransaction: async (timeoutMs, context, name) => {
|
|
3761
4018
|
const scope = context;
|
|
3762
4019
|
if (!scope) {
|
|
3763
4020
|
throw new Error(
|
|
@@ -3766,7 +4023,8 @@ function getOrCreateNativeSqlDatabase(runtime, ctx) {
|
|
|
3766
4023
|
}
|
|
3767
4024
|
const transaction = await runtime.actorBeginStateTransaction(
|
|
3768
4025
|
ctx,
|
|
3769
|
-
timeoutMs
|
|
4026
|
+
timeoutMs,
|
|
4027
|
+
name
|
|
3770
4028
|
);
|
|
3771
4029
|
return {
|
|
3772
4030
|
exec: async () => {
|
|
@@ -3793,8 +4051,13 @@ function getOrCreateNativeSqlDatabase(runtime, ctx) {
|
|
|
3793
4051
|
run: (sql, params) => runtime.actorSqlRun(ctx, sql, params),
|
|
3794
4052
|
metrics: () => runtime.actorSqlMetrics(ctx),
|
|
3795
4053
|
takeLastKvError: () => runtime.actorSqlTakeLastKvError(ctx),
|
|
4054
|
+
open: () => runtime.actorSqlOpen(ctx),
|
|
4055
|
+
commitTicket: () => runtime.actorSqlCommitTicket(ctx),
|
|
4056
|
+
whenDurable: (ticket) => runtime.actorSqlWhenDurable(ctx, ticket),
|
|
4057
|
+
abortGeneration: (reason) => runtime.actorSqlAbortGeneration(ctx, reason),
|
|
3796
4058
|
close: () => runtime.actorSqlClose(ctx)
|
|
3797
|
-
}
|
|
4059
|
+
};
|
|
4060
|
+
const database = wrapJsNativeDatabase(bindings);
|
|
3798
4061
|
runtimeState.sql = database;
|
|
3799
4062
|
return database;
|
|
3800
4063
|
}
|
|
@@ -5547,16 +5810,20 @@ var ActorContextHandleAdapter = class {
|
|
|
5547
5810
|
{
|
|
5548
5811
|
open: async (requestedActorId) => {
|
|
5549
5812
|
void requestedActorId;
|
|
5550
|
-
|
|
5813
|
+
const database = getOrCreateNativeSqlDatabase(
|
|
5551
5814
|
this.#runtime,
|
|
5552
5815
|
this.#ctx
|
|
5553
5816
|
);
|
|
5817
|
+
if (usesSqliteDeferredCommits(this.#databaseProvider)) {
|
|
5818
|
+
await database.open();
|
|
5819
|
+
}
|
|
5820
|
+
return database;
|
|
5554
5821
|
}
|
|
5555
5822
|
},
|
|
5556
|
-
async (timeoutMs, context) => await getOrCreateNativeSqlDatabase(
|
|
5823
|
+
async (timeoutMs, context, name) => await getOrCreateNativeSqlDatabase(
|
|
5557
5824
|
this.#runtime,
|
|
5558
5825
|
this.#ctx
|
|
5559
|
-
).beginStateTransaction(timeoutMs, context)
|
|
5826
|
+
).beginStateTransaction(timeoutMs, context, name)
|
|
5560
5827
|
)
|
|
5561
5828
|
});
|
|
5562
5829
|
runtimeState.databaseClient = {
|
|
@@ -6153,6 +6420,10 @@ function buildActorTracingConfig(actions, tracing) {
|
|
|
6153
6420
|
actions: flattenActionTraceSamplers(actions, tracing.actions)
|
|
6154
6421
|
};
|
|
6155
6422
|
}
|
|
6423
|
+
var SQLITE_DEFERRED_COMMITS = /* @__PURE__ */ Symbol.for("rivetkit.sqlite.deferredCommits");
|
|
6424
|
+
function usesSqliteDeferredCommits(databaseProvider) {
|
|
6425
|
+
return (databaseProvider == null ? void 0 : databaseProvider[SQLITE_DEFERRED_COMMITS]) === true;
|
|
6426
|
+
}
|
|
6156
6427
|
function buildActorConfig(definition, registryConfig, runtimeKind) {
|
|
6157
6428
|
var _a;
|
|
6158
6429
|
const config = definition.config;
|
|
@@ -6160,11 +6431,13 @@ function buildActorConfig(definition, registryConfig, runtimeKind) {
|
|
|
6160
6431
|
const canHibernate = options.canHibernateWebSocket;
|
|
6161
6432
|
const usesRemoteSqlite = sqliteBackendForConfig(registryConfig) === "remote";
|
|
6162
6433
|
const sqliteProfiling = (_a = config.db) == null ? void 0 : _a.sqliteProfiling;
|
|
6434
|
+
const sqliteDeferredCommits = usesSqliteDeferredCommits(config.db);
|
|
6163
6435
|
return {
|
|
6164
6436
|
name: options.name,
|
|
6165
6437
|
icon: options.icon,
|
|
6166
6438
|
hasDatabase: true,
|
|
6167
6439
|
remoteSqlite: usesRemoteSqlite,
|
|
6440
|
+
sqliteDeferredCommits: sqliteDeferredCommits || void 0,
|
|
6168
6441
|
sqliteProfiling,
|
|
6169
6442
|
tracing: buildActorTracingConfig(
|
|
6170
6443
|
definition.config.actions,
|