rivetkit 0.0.0-sqlite-query-metrics-v3.1dff84f → 0.0.0-sqlite-sync-3-0-6-final.cf8679c
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 +95 -20
- package/dist/browser/client.js +2 -2
- 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-HXJ5U2ZI.cjs → chunk-275ZGRSG.cjs} +3 -3
- package/dist/tsup/{chunk-HXJ5U2ZI.cjs.map → chunk-275ZGRSG.cjs.map} +1 -1
- package/dist/tsup/{chunk-HFGXV2CC.cjs → chunk-E54YPM4V.cjs} +10 -10
- package/dist/tsup/{chunk-HFGXV2CC.cjs.map → chunk-E54YPM4V.cjs.map} +1 -1
- package/dist/tsup/{chunk-Y4QLVCCS.cjs → chunk-I26AW6BG.cjs} +2 -2
- package/dist/tsup/{chunk-Y4QLVCCS.cjs.map → chunk-I26AW6BG.cjs.map} +1 -1
- package/dist/tsup/{chunk-CWN7N5AF.cjs → chunk-JHHUCWBC.cjs} +7 -7
- package/dist/tsup/{chunk-CWN7N5AF.cjs.map → chunk-JHHUCWBC.cjs.map} +1 -1
- package/dist/tsup/{chunk-22S5RCCJ.cjs → chunk-LYXPQB6H.cjs} +3 -3
- package/dist/tsup/{chunk-22S5RCCJ.cjs.map → chunk-LYXPQB6H.cjs.map} +1 -1
- package/dist/tsup/{chunk-NNCL4IBC.js → chunk-M72ZKQ7R.js} +2 -2
- package/dist/tsup/{chunk-NNCL4IBC.js.map → chunk-M72ZKQ7R.js.map} +1 -1
- package/dist/tsup/{chunk-QQIFRR3B.js → chunk-ME74LHJM.js} +7 -7
- package/dist/tsup/chunk-ME74LHJM.js.map +1 -0
- package/dist/tsup/{chunk-UXDASKP6.js → chunk-PBIQPYE5.js} +12 -13
- package/dist/tsup/chunk-PBIQPYE5.js.map +1 -0
- package/dist/tsup/{chunk-2CTZU7GL.js → chunk-R4QCQBB4.js} +2 -2
- package/dist/tsup/{chunk-SW33HMM5.js → chunk-RJ7WDGOJ.js} +3 -3
- package/dist/tsup/{chunk-NG5CUXMM.cjs → chunk-SJJWJU26.cjs} +145 -145
- package/dist/tsup/chunk-SJJWJU26.cjs.map +1 -0
- package/dist/tsup/{chunk-HRKFVQPS.js → chunk-SSMFNH4N.js} +4 -4
- package/dist/tsup/{chunk-Y5CFDGPA.cjs → chunk-TKCX6KNZ.cjs} +4 -4
- package/dist/tsup/{chunk-Y5CFDGPA.cjs.map → chunk-TKCX6KNZ.cjs.map} +1 -1
- package/dist/tsup/{chunk-JJUSO7GJ.cjs → chunk-TVBQQXQE.cjs} +3 -3
- package/dist/tsup/{chunk-JJUSO7GJ.cjs.map → chunk-TVBQQXQE.cjs.map} +1 -1
- package/dist/tsup/{chunk-F5PWAGS7.js → chunk-VXVJHTW6.js} +2 -2
- package/dist/tsup/{chunk-FT6VRK4C.js → chunk-XATHAIZX.js} +2 -2
- package/dist/tsup/{chunk-D7DWNYEO.js → chunk-Y5TV6V5Z.js} +2 -2
- package/dist/tsup/{chunk-SSF2XC33.cjs → chunk-YWWDUC6D.cjs} +12 -13
- package/dist/tsup/chunk-YWWDUC6D.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +5 -5
- package/dist/tsup/client/mod.d.cts +3 -3
- package/dist/tsup/client/mod.d.ts +3 -3
- 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-BnMhcPHl.d.cts → config-5K0rzjv1.d.cts} +72 -25
- package/dist/tsup/{config-CBTr4IhE.d.cts → config-Df5jOcde.d.cts} +26 -0
- package/dist/tsup/{config-CBTr4IhE.d.ts → config-Df5jOcde.d.ts} +26 -0
- package/dist/tsup/{config-BiiS5T5M.d.ts → config-DsAjIyfZ.d.ts} +72 -25
- package/dist/tsup/{context-iMxXq_Lt.d.ts → context-B19Rx5Zg.d.cts} +5 -2
- package/dist/tsup/{context-DVE8XMm1.d.cts → context-BEh8x4jn.d.ts} +5 -2
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.d.cts +1 -1
- package/dist/tsup/db/drizzle.d.ts +1 -1
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +3 -3
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +2 -2
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.d.cts +2 -2
- package/dist/tsup/dynamic/mod.d.ts +2 -2
- package/dist/tsup/dynamic/mod.js +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.cjs +2 -2
- package/dist/tsup/inspector-tab/mod.d.cts +3 -3
- package/dist/tsup/inspector-tab/mod.d.ts +3 -3
- package/dist/tsup/inspector-tab/mod.js +1 -1
- package/dist/tsup/mod.cjs +548 -169
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +6 -4
- package/dist/tsup/mod.d.ts +6 -4
- package/dist/tsup/mod.js +447 -68
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +6 -6
- package/dist/tsup/test/mod.d.cts +2 -2
- package/dist/tsup/test/mod.d.ts +2 -2
- package/dist/tsup/test/mod.js +4 -4
- package/dist/tsup/unstable/migrations.d.cts +1 -1
- package/dist/tsup/unstable/migrations.d.ts +1 -1
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +13 -10
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +4 -4
- package/dist/tsup/workflow/mod.d.ts +4 -4
- package/dist/tsup/workflow/mod.js +8 -5
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +9 -9
- package/src/actor/config.ts +41 -29
- package/src/actor/contexts/index.ts +2 -0
- package/src/actor/definition.ts +33 -1
- package/src/actor/schema.ts +4 -0
- package/src/client/actor-common.ts +4 -0
- package/src/client/actor-conn.ts +2 -0
- package/src/client/actor-handle.ts +2 -0
- package/src/client/config.ts +1 -1
- package/src/client/queue.ts +2 -0
- package/src/common/database/config.ts +39 -0
- package/src/common/database/native-database.ts +230 -21
- package/src/registry/index.ts +142 -1
- package/src/registry/napi-runtime.ts +93 -4
- package/src/registry/native.ts +61 -28
- package/src/registry/runtime.ts +58 -8
- package/src/registry/wasm-runtime.ts +88 -14
- package/src/workflow/context.ts +3 -0
- package/dist/tsup/chunk-NG5CUXMM.cjs.map +0 -1
- package/dist/tsup/chunk-QQIFRR3B.js.map +0 -1
- package/dist/tsup/chunk-SSF2XC33.cjs.map +0 -1
- package/dist/tsup/chunk-UXDASKP6.js.map +0 -1
- package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +0 -848
- /package/dist/tsup/{chunk-2CTZU7GL.js.map → chunk-R4QCQBB4.js.map} +0 -0
- /package/dist/tsup/{chunk-SW33HMM5.js.map → chunk-RJ7WDGOJ.js.map} +0 -0
- /package/dist/tsup/{chunk-HRKFVQPS.js.map → chunk-SSMFNH4N.js.map} +0 -0
- /package/dist/tsup/{chunk-F5PWAGS7.js.map → chunk-VXVJHTW6.js.map} +0 -0
- /package/dist/tsup/{chunk-FT6VRK4C.js.map → chunk-XATHAIZX.js.map} +0 -0
- /package/dist/tsup/{chunk-D7DWNYEO.js.map → chunk-Y5TV6V5Z.js.map} +0 -0
package/dist/tsup/mod.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeWorkflowHistoryTransport
|
|
3
|
+
} from "./chunk-Y5TV6V5Z.js";
|
|
1
4
|
import {
|
|
2
5
|
ACTOR_CONTEXT_INTERNAL_SYMBOL,
|
|
3
6
|
ActorConfigSchema,
|
|
@@ -14,10 +17,7 @@ import {
|
|
|
14
17
|
getRunInspectorKind,
|
|
15
18
|
getRunMetadata,
|
|
16
19
|
hasRunInspectorConfig
|
|
17
|
-
} from "./chunk-
|
|
18
|
-
import {
|
|
19
|
-
decodeWorkflowHistoryTransport
|
|
20
|
-
} from "./chunk-D7DWNYEO.js";
|
|
20
|
+
} from "./chunk-PBIQPYE5.js";
|
|
21
21
|
import {
|
|
22
22
|
ALLOWED_PUBLIC_HEADERS,
|
|
23
23
|
ENGINE_HOST,
|
|
@@ -35,18 +35,18 @@ import {
|
|
|
35
35
|
runWithActorInvocationSpan,
|
|
36
36
|
tryParseEndpoint,
|
|
37
37
|
updateRunnerConfig
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-ME74LHJM.js";
|
|
39
39
|
import {
|
|
40
40
|
makePrefixedKey,
|
|
41
41
|
removePrefixFromKey
|
|
42
42
|
} from "./chunk-A2CF6PFH.js";
|
|
43
|
-
import "./chunk-F5PWAGS7.js";
|
|
44
43
|
import {
|
|
45
44
|
bindNativeStateTransactionContext,
|
|
46
45
|
db,
|
|
47
46
|
registerNativeStateTransactionOpener
|
|
48
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-XATHAIZX.js";
|
|
49
48
|
import "./chunk-JTHHCZCZ.js";
|
|
49
|
+
import "./chunk-VXVJHTW6.js";
|
|
50
50
|
import {
|
|
51
51
|
LogLevelSchema,
|
|
52
52
|
VERSION,
|
|
@@ -80,7 +80,7 @@ import {
|
|
|
80
80
|
parsePortEnv,
|
|
81
81
|
stringifyError,
|
|
82
82
|
toUint8Array
|
|
83
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-M72ZKQ7R.js";
|
|
84
84
|
import {
|
|
85
85
|
INTERNAL_ERROR_CODE,
|
|
86
86
|
RivetError,
|
|
@@ -116,11 +116,25 @@ function warnDeprecatedOptionKeys(options) {
|
|
|
116
116
|
if (opts[key] !== void 0 && !warnedDeprecatedOptionKeys.has(key)) {
|
|
117
117
|
warnedDeprecatedOptionKeys.add(key);
|
|
118
118
|
loggerWithoutContext().warn({
|
|
119
|
-
msg: `actor option \`${key}\` is deprecated and is now ignored. ${detail} Will be removed in
|
|
119
|
+
msg: `actor option \`${key}\` is deprecated and is now ignored. ${detail} Will be removed in 3.2.0.`
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
+
var warnedDeprecatedRun = false;
|
|
125
|
+
function warnDeprecatedRun(input) {
|
|
126
|
+
if (warnedDeprecatedRun || !input || typeof input !== "object") return;
|
|
127
|
+
const run = input.run;
|
|
128
|
+
if (run === void 0) return;
|
|
129
|
+
const runFunction = typeof run === "object" && run !== null ? run.run : run;
|
|
130
|
+
if (typeof runFunction === "function" && getRunInspectorKind(runFunction) === "workflow") {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
warnedDeprecatedRun = true;
|
|
134
|
+
loggerWithoutContext().warn({
|
|
135
|
+
msg: "actor option `run` with a plain function was deprecated in 3.0 and will be removed in a future version. Start background work from `onWake` with `c.keepAwake` and track it in `c.vars`. `run: workflow(...)` is not deprecated. See https://rivet.dev/actors/docs/deprecated/run"
|
|
136
|
+
});
|
|
137
|
+
}
|
|
124
138
|
var ActorDefinition = class {
|
|
125
139
|
#config;
|
|
126
140
|
constructor(config) {
|
|
@@ -138,6 +152,7 @@ function actor(input) {
|
|
|
138
152
|
warnDeprecatedOptionKeys(
|
|
139
153
|
input == null ? void 0 : input.options
|
|
140
154
|
);
|
|
155
|
+
warnDeprecatedRun(input);
|
|
141
156
|
const config = ActorConfigSchema.parse(input);
|
|
142
157
|
flattenActionHandlers(config.actions);
|
|
143
158
|
flattenActionInputSchemas(config.actions, config.actionInputSchemas);
|
|
@@ -956,6 +971,10 @@ var DocRegistryConfigSchema = z3.object({
|
|
|
956
971
|
import { VirtualWebSocket as VirtualWebSocket2 } from "@rivetkit/virtual-websocket";
|
|
957
972
|
|
|
958
973
|
// src/common/database/native-database.ts
|
|
974
|
+
function isSynchronousTransaction(transaction) {
|
|
975
|
+
const candidate = transaction;
|
|
976
|
+
return typeof candidate.commitSync === "function" && typeof candidate.rollbackSync === "function";
|
|
977
|
+
}
|
|
959
978
|
function shouldAttachNativeKvError(message) {
|
|
960
979
|
return /i\/o error|unable to open database file/i.test(message);
|
|
961
980
|
}
|
|
@@ -976,13 +995,16 @@ function toNativeBinding(arg) {
|
|
|
976
995
|
if (arg === null || arg === void 0) {
|
|
977
996
|
return { kind: "null" };
|
|
978
997
|
}
|
|
979
|
-
if (typeof arg === "bigint") {
|
|
980
|
-
|
|
998
|
+
if (typeof arg === "bigint" || typeof arg === "number" && Number.isInteger(arg)) {
|
|
999
|
+
const value = Number(arg);
|
|
1000
|
+
if (!Number.isSafeInteger(value)) {
|
|
1001
|
+
throw new RangeError(
|
|
1002
|
+
"SQLite integer bindings must be within the JavaScript safe integer range."
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
return { kind: "int", intValue: value };
|
|
981
1006
|
}
|
|
982
1007
|
if (typeof arg === "number") {
|
|
983
|
-
if (Number.isInteger(arg)) {
|
|
984
|
-
return { kind: "int", intValue: arg };
|
|
985
|
-
}
|
|
986
1008
|
return { kind: "float", floatValue: arg };
|
|
987
1009
|
}
|
|
988
1010
|
if (typeof arg === "string") {
|
|
@@ -999,9 +1021,10 @@ function toNativeBinding(arg) {
|
|
|
999
1021
|
function extractNamedSqliteParameters(sql) {
|
|
1000
1022
|
const orderedNames = [];
|
|
1001
1023
|
const seen = /* @__PURE__ */ new Set();
|
|
1002
|
-
const pattern = /([:@$][A-Za-z_][
|
|
1024
|
+
const pattern = /'(?:''|[^'])*'|"(?:""|[^"])*"|`(?:``|[^`])*`|\[[^\]]*\]|--[^\n]*|\/\*[\s\S]*?(?:\*\/|$)|([:@$][\w$\u0080-\u{10FFFF}]+(?:::[\w$\u0080-\u{10FFFF}]+)*(?:\([^)]*\))?)|[A-Za-z_\u0080-\u{10FFFF}][\w$\u0080-\u{10FFFF}]*/gu;
|
|
1003
1025
|
for (const match of sql.matchAll(pattern)) {
|
|
1004
1026
|
const name = match[1];
|
|
1027
|
+
if (!name) continue;
|
|
1005
1028
|
if (seen.has(name)) {
|
|
1006
1029
|
continue;
|
|
1007
1030
|
}
|
|
@@ -1120,20 +1143,44 @@ function wrapJsNativeDatabase(database) {
|
|
|
1120
1143
|
let terminalPromise;
|
|
1121
1144
|
let lastInsertRowId = null;
|
|
1122
1145
|
const executeNative = async (sql, params) => {
|
|
1123
|
-
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
1124
|
-
if (lastInsertRowIdColumn) {
|
|
1125
|
-
return {
|
|
1126
|
-
columns: [lastInsertRowIdColumn],
|
|
1127
|
-
rows: [[lastInsertRowId ?? 0]],
|
|
1128
|
-
changes: 0,
|
|
1129
|
-
lastInsertRowId
|
|
1130
|
-
};
|
|
1131
|
-
}
|
|
1132
1146
|
const release = gate.enter();
|
|
1133
1147
|
try {
|
|
1148
|
+
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
1149
|
+
if (lastInsertRowIdColumn) {
|
|
1150
|
+
return {
|
|
1151
|
+
columns: [lastInsertRowIdColumn],
|
|
1152
|
+
rows: [[lastInsertRowId ?? 0]],
|
|
1153
|
+
changes: 0,
|
|
1154
|
+
lastInsertRowId
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1134
1157
|
const nativeParams = toNativeBindings(sql, params);
|
|
1135
1158
|
const result = await database.execute(sql, nativeParams);
|
|
1136
|
-
if (result.lastInsertRowId
|
|
1159
|
+
if (result.lastInsertRowId != null) {
|
|
1160
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
1161
|
+
}
|
|
1162
|
+
return result;
|
|
1163
|
+
} catch (error) {
|
|
1164
|
+
enrichNativeDatabaseError(database, error);
|
|
1165
|
+
} finally {
|
|
1166
|
+
release();
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
const executeNativeSync = (sql, params) => {
|
|
1170
|
+
const release = gate.enter();
|
|
1171
|
+
try {
|
|
1172
|
+
const nativeParams = toNativeBindings(sql, params);
|
|
1173
|
+
const result = database.executeSync(sql, nativeParams);
|
|
1174
|
+
const rowIdColumn = lastInsertRowIdColumnName(sql);
|
|
1175
|
+
if (rowIdColumn) {
|
|
1176
|
+
return {
|
|
1177
|
+
columns: [rowIdColumn],
|
|
1178
|
+
rows: [[lastInsertRowId ?? 0]],
|
|
1179
|
+
changes: 0,
|
|
1180
|
+
lastInsertRowId
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
if (result.lastInsertRowId != null) {
|
|
1137
1184
|
lastInsertRowId = result.lastInsertRowId;
|
|
1138
1185
|
}
|
|
1139
1186
|
return result;
|
|
@@ -1161,9 +1208,28 @@ function wrapJsNativeDatabase(database) {
|
|
|
1161
1208
|
callback(row, result.columns);
|
|
1162
1209
|
}
|
|
1163
1210
|
},
|
|
1211
|
+
execSync(sql, callback) {
|
|
1212
|
+
const release = gate.enter();
|
|
1213
|
+
let result;
|
|
1214
|
+
try {
|
|
1215
|
+
result = database.execSync(sql);
|
|
1216
|
+
} catch (error) {
|
|
1217
|
+
enrichNativeDatabaseError(database, error);
|
|
1218
|
+
} finally {
|
|
1219
|
+
release();
|
|
1220
|
+
}
|
|
1221
|
+
if (callback) {
|
|
1222
|
+
for (const row of result.rows) {
|
|
1223
|
+
callback(row, result.columns);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
},
|
|
1164
1227
|
async execute(sql, params) {
|
|
1165
1228
|
return await executeNative(sql, params);
|
|
1166
1229
|
},
|
|
1230
|
+
executeSync(sql, params) {
|
|
1231
|
+
return executeNativeSync(sql, params);
|
|
1232
|
+
},
|
|
1167
1233
|
async executeBatch(statements) {
|
|
1168
1234
|
const nativeStatements = statements.map(toNativeBatchStatement);
|
|
1169
1235
|
const release = gate.enter();
|
|
@@ -1185,7 +1251,7 @@ function wrapJsNativeDatabase(database) {
|
|
|
1185
1251
|
return transactionResults;
|
|
1186
1252
|
})();
|
|
1187
1253
|
for (const result of results) {
|
|
1188
|
-
if (result.lastInsertRowId
|
|
1254
|
+
if (result.lastInsertRowId != null) {
|
|
1189
1255
|
lastInsertRowId = result.lastInsertRowId;
|
|
1190
1256
|
}
|
|
1191
1257
|
}
|
|
@@ -1213,7 +1279,23 @@ function wrapJsNativeDatabase(database) {
|
|
|
1213
1279
|
release();
|
|
1214
1280
|
}
|
|
1215
1281
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
1216
|
-
if (result.lastInsertRowId
|
|
1282
|
+
if (result.lastInsertRowId != null) {
|
|
1283
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
1284
|
+
}
|
|
1285
|
+
});
|
|
1286
|
+
},
|
|
1287
|
+
beginTransactionSync(timeoutMs, name) {
|
|
1288
|
+
const release = gate.enter();
|
|
1289
|
+
let transaction;
|
|
1290
|
+
try {
|
|
1291
|
+
transaction = database.beginTransactionSync(timeoutMs, name);
|
|
1292
|
+
} catch (error) {
|
|
1293
|
+
enrichNativeDatabaseError(database, error);
|
|
1294
|
+
} finally {
|
|
1295
|
+
release();
|
|
1296
|
+
}
|
|
1297
|
+
return wrapTransaction(database, transaction, gate, (result) => {
|
|
1298
|
+
if (result.lastInsertRowId != null) {
|
|
1217
1299
|
lastInsertRowId = result.lastInsertRowId;
|
|
1218
1300
|
}
|
|
1219
1301
|
});
|
|
@@ -1235,7 +1317,7 @@ function wrapJsNativeDatabase(database) {
|
|
|
1235
1317
|
release();
|
|
1236
1318
|
}
|
|
1237
1319
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
1238
|
-
if (result.lastInsertRowId
|
|
1320
|
+
if (result.lastInsertRowId != null) {
|
|
1239
1321
|
lastInsertRowId = result.lastInsertRowId;
|
|
1240
1322
|
}
|
|
1241
1323
|
});
|
|
@@ -1251,6 +1333,25 @@ function wrapJsNativeDatabase(database) {
|
|
|
1251
1333
|
var _a;
|
|
1252
1334
|
return normalizeNativeMetrics((_a = database.metrics) == null ? void 0 : _a.call(database));
|
|
1253
1335
|
},
|
|
1336
|
+
async open() {
|
|
1337
|
+
const release = gate.enter();
|
|
1338
|
+
try {
|
|
1339
|
+
await database.open();
|
|
1340
|
+
} catch (error) {
|
|
1341
|
+
enrichNativeDatabaseError(database, error);
|
|
1342
|
+
} finally {
|
|
1343
|
+
release();
|
|
1344
|
+
}
|
|
1345
|
+
},
|
|
1346
|
+
commitTicket() {
|
|
1347
|
+
return database.commitTicket();
|
|
1348
|
+
},
|
|
1349
|
+
async whenDurable(ticket) {
|
|
1350
|
+
await database.whenDurable(ticket);
|
|
1351
|
+
},
|
|
1352
|
+
abortGeneration(reason) {
|
|
1353
|
+
database.abortGeneration(reason);
|
|
1354
|
+
},
|
|
1254
1355
|
async close() {
|
|
1255
1356
|
terminalPromise ??= gate.close(() => database.close());
|
|
1256
1357
|
await terminalPromise;
|
|
@@ -1262,7 +1363,7 @@ function wrapJsNativeDatabase(database) {
|
|
|
1262
1363
|
};
|
|
1263
1364
|
}
|
|
1264
1365
|
function wrapTransaction(database, transaction, gate, onExecute) {
|
|
1265
|
-
|
|
1366
|
+
const wrapped = {
|
|
1266
1367
|
async exec(sql, callback) {
|
|
1267
1368
|
const release = gate.enter();
|
|
1268
1369
|
let result;
|
|
@@ -1313,6 +1414,61 @@ function wrapTransaction(database, transaction, gate, onExecute) {
|
|
|
1313
1414
|
}
|
|
1314
1415
|
}
|
|
1315
1416
|
};
|
|
1417
|
+
if (isSynchronousTransaction(transaction)) {
|
|
1418
|
+
return Object.assign(wrapped, {
|
|
1419
|
+
execSync(sql, callback) {
|
|
1420
|
+
const release = gate.enter();
|
|
1421
|
+
let result;
|
|
1422
|
+
try {
|
|
1423
|
+
result = transaction.execSync(sql);
|
|
1424
|
+
} catch (error) {
|
|
1425
|
+
enrichNativeDatabaseError(database, error);
|
|
1426
|
+
} finally {
|
|
1427
|
+
release();
|
|
1428
|
+
}
|
|
1429
|
+
if (callback) {
|
|
1430
|
+
for (const row of result.rows)
|
|
1431
|
+
callback(row, result.columns);
|
|
1432
|
+
}
|
|
1433
|
+
},
|
|
1434
|
+
executeSync(sql, params) {
|
|
1435
|
+
const release = gate.enter();
|
|
1436
|
+
try {
|
|
1437
|
+
const result = transaction.executeSync(
|
|
1438
|
+
sql,
|
|
1439
|
+
toNativeBindings(sql, params)
|
|
1440
|
+
);
|
|
1441
|
+
onExecute(result);
|
|
1442
|
+
return result;
|
|
1443
|
+
} catch (error) {
|
|
1444
|
+
enrichNativeDatabaseError(database, error);
|
|
1445
|
+
} finally {
|
|
1446
|
+
release();
|
|
1447
|
+
}
|
|
1448
|
+
},
|
|
1449
|
+
commitSync() {
|
|
1450
|
+
const release = gate.enter();
|
|
1451
|
+
try {
|
|
1452
|
+
transaction.commitSync();
|
|
1453
|
+
} catch (error) {
|
|
1454
|
+
enrichNativeDatabaseError(database, error);
|
|
1455
|
+
} finally {
|
|
1456
|
+
release();
|
|
1457
|
+
}
|
|
1458
|
+
},
|
|
1459
|
+
rollbackSync() {
|
|
1460
|
+
const release = gate.enter();
|
|
1461
|
+
try {
|
|
1462
|
+
transaction.rollbackSync();
|
|
1463
|
+
} catch (error) {
|
|
1464
|
+
enrichNativeDatabaseError(database, error);
|
|
1465
|
+
} finally {
|
|
1466
|
+
release();
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
return wrapped;
|
|
1316
1472
|
}
|
|
1317
1473
|
function lastInsertRowIdColumnName(sql) {
|
|
1318
1474
|
const match = sql.match(
|
|
@@ -1599,6 +1755,15 @@ var NapiCoreRuntime = class {
|
|
|
1599
1755
|
async registryActorStopThresholdMs(registry) {
|
|
1600
1756
|
return await asNativeRegistry(registry).actorStopThresholdMs() ?? void 0;
|
|
1601
1757
|
}
|
|
1758
|
+
registryActiveActorCount(registry) {
|
|
1759
|
+
return asNativeRegistry(registry).activeActorCount();
|
|
1760
|
+
}
|
|
1761
|
+
onRegistryActiveActorCountChange(registry, callback, cancelToken) {
|
|
1762
|
+
asNativeRegistry(registry).onActiveActorCountChange(
|
|
1763
|
+
callback,
|
|
1764
|
+
asNativeCancellationToken(cancelToken)
|
|
1765
|
+
);
|
|
1766
|
+
}
|
|
1602
1767
|
async registryHealth(registry) {
|
|
1603
1768
|
const response = await asNativeRegistry(registry).health();
|
|
1604
1769
|
return {
|
|
@@ -1897,6 +2062,9 @@ var NapiCoreRuntime = class {
|
|
|
1897
2062
|
async actorSqlExec(ctx, sql) {
|
|
1898
2063
|
return await this.#actorSql(ctx).exec(sql);
|
|
1899
2064
|
}
|
|
2065
|
+
actorSqlExecSync(ctx, sql) {
|
|
2066
|
+
return this.#actorSql(ctx).execSync(sql);
|
|
2067
|
+
}
|
|
1900
2068
|
async actorSqlExecute(ctx, sql, params) {
|
|
1901
2069
|
const result = await this.#actorSql(ctx).execute(
|
|
1902
2070
|
sql,
|
|
@@ -1904,6 +2072,13 @@ var NapiCoreRuntime = class {
|
|
|
1904
2072
|
);
|
|
1905
2073
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
1906
2074
|
}
|
|
2075
|
+
actorSqlExecuteSync(ctx, sql, params) {
|
|
2076
|
+
const result = this.#actorSql(ctx).executeSync(
|
|
2077
|
+
sql,
|
|
2078
|
+
toNapiSqlBindParams(params)
|
|
2079
|
+
);
|
|
2080
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
2081
|
+
}
|
|
1907
2082
|
async actorSqlExecuteBatch(ctx, statements) {
|
|
1908
2083
|
const results = await this.#actorSql(ctx).executeBatch(
|
|
1909
2084
|
statements.map(toNapiSqlBatchStatement)
|
|
@@ -1916,9 +2091,18 @@ var NapiCoreRuntime = class {
|
|
|
1916
2091
|
name
|
|
1917
2092
|
);
|
|
1918
2093
|
}
|
|
2094
|
+
actorSqlBeginTransactionSync(ctx, timeoutMs, name) {
|
|
2095
|
+
return this.#actorSql(ctx).beginTransactionSync(
|
|
2096
|
+
timeoutMs,
|
|
2097
|
+
name
|
|
2098
|
+
);
|
|
2099
|
+
}
|
|
1919
2100
|
async actorSqlTransactionExec(transaction, sql) {
|
|
1920
2101
|
return await asNativeSqlTransaction(transaction).exec(sql);
|
|
1921
2102
|
}
|
|
2103
|
+
actorSqlTransactionExecSync(transaction, sql) {
|
|
2104
|
+
return asNativeSqlTransaction(transaction).execSync(sql);
|
|
2105
|
+
}
|
|
1922
2106
|
async actorSqlTransactionExecute(transaction, sql, params) {
|
|
1923
2107
|
const result = await asNativeSqlTransaction(transaction).execute(
|
|
1924
2108
|
sql,
|
|
@@ -1926,12 +2110,25 @@ var NapiCoreRuntime = class {
|
|
|
1926
2110
|
);
|
|
1927
2111
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
1928
2112
|
}
|
|
2113
|
+
actorSqlTransactionExecuteSync(transaction, sql, params) {
|
|
2114
|
+
const result = asNativeSqlTransaction(transaction).executeSync(
|
|
2115
|
+
sql,
|
|
2116
|
+
toNapiSqlBindParams(params)
|
|
2117
|
+
);
|
|
2118
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
2119
|
+
}
|
|
1929
2120
|
async actorSqlTransactionCommit(transaction) {
|
|
1930
2121
|
await asNativeSqlTransaction(transaction).commit();
|
|
1931
2122
|
}
|
|
2123
|
+
actorSqlTransactionCommitSync(transaction) {
|
|
2124
|
+
asNativeSqlTransaction(transaction).commitSync();
|
|
2125
|
+
}
|
|
1932
2126
|
async actorSqlTransactionRollback(transaction) {
|
|
1933
2127
|
await asNativeSqlTransaction(transaction).rollback();
|
|
1934
2128
|
}
|
|
2129
|
+
actorSqlTransactionRollbackSync(transaction) {
|
|
2130
|
+
asNativeSqlTransaction(transaction).rollbackSync();
|
|
2131
|
+
}
|
|
1935
2132
|
async actorBeginStateTransaction(ctx, timeoutMs) {
|
|
1936
2133
|
return await this.#actorContextForOperation(ctx).beginStateTransaction(
|
|
1937
2134
|
timeoutMs
|
|
@@ -1969,6 +2166,18 @@ var NapiCoreRuntime = class {
|
|
|
1969
2166
|
var _a, _b;
|
|
1970
2167
|
return ((_b = (_a = this.#actorSql(ctx)).takeLastKvError) == null ? void 0 : _b.call(_a)) ?? null;
|
|
1971
2168
|
}
|
|
2169
|
+
async actorSqlOpen(ctx) {
|
|
2170
|
+
await this.#actorSql(ctx).open();
|
|
2171
|
+
}
|
|
2172
|
+
actorSqlCommitTicket(ctx) {
|
|
2173
|
+
return this.#actorSql(ctx).commitTicket();
|
|
2174
|
+
}
|
|
2175
|
+
actorSqlAbortGeneration(ctx, reason) {
|
|
2176
|
+
this.#actorSql(ctx).abortGeneration(reason);
|
|
2177
|
+
}
|
|
2178
|
+
async actorSqlWhenDurable(ctx, ticket) {
|
|
2179
|
+
await this.#actorSql(ctx).whenDurable(ticket);
|
|
2180
|
+
}
|
|
1972
2181
|
async actorSqlClose(ctx) {
|
|
1973
2182
|
const nativeCtx = asNativeActorContext(ctx);
|
|
1974
2183
|
if (!this.#sqlOpened.delete(nativeCtx)) {
|
|
@@ -1976,9 +2185,6 @@ var NapiCoreRuntime = class {
|
|
|
1976
2185
|
}
|
|
1977
2186
|
await nativeCtx.sql().close();
|
|
1978
2187
|
}
|
|
1979
|
-
async actorRuntimeSocketProvision(ctx) {
|
|
1980
|
-
return await asNativeActorContext(ctx).provisionActorRuntimeSocket();
|
|
1981
|
-
}
|
|
1982
2188
|
async actorQueueSend(ctx, name, body) {
|
|
1983
2189
|
return toNapiQueueMessage(
|
|
1984
2190
|
await this.#actorContextForOperation(ctx).queue().send(name, toNapiBuffer(body))
|
|
@@ -2552,6 +2758,17 @@ function optionalWasmNumber(value) {
|
|
|
2552
2758
|
function wasmNumber(value) {
|
|
2553
2759
|
return typeof value === "bigint" ? Number(value) : value;
|
|
2554
2760
|
}
|
|
2761
|
+
function synchronousSqliteUnavailable() {
|
|
2762
|
+
throw new RivetError(
|
|
2763
|
+
"sqlite",
|
|
2764
|
+
"sync_unsupported",
|
|
2765
|
+
"Synchronous SQLite is unavailable because the actor runs on the wasm runtime.",
|
|
2766
|
+
{
|
|
2767
|
+
public: true,
|
|
2768
|
+
metadata: { runtime: "wasm" }
|
|
2769
|
+
}
|
|
2770
|
+
);
|
|
2771
|
+
}
|
|
2555
2772
|
function normalizeKvEntry(entry) {
|
|
2556
2773
|
return {
|
|
2557
2774
|
key: toBytes(entry.key),
|
|
@@ -2703,6 +2920,14 @@ var WasmCoreRuntime = class {
|
|
|
2703
2920
|
);
|
|
2704
2921
|
}
|
|
2705
2922
|
createActorFactory(callbacks, config) {
|
|
2923
|
+
if (config == null ? void 0 : config.sqliteDeferredCommits) {
|
|
2924
|
+
throw new RivetError(
|
|
2925
|
+
"sqlite",
|
|
2926
|
+
"deferred_commits_unsupported",
|
|
2927
|
+
"SQLite deferred commits require local native SQLite, but the wasm runtime uses remote SQLite.",
|
|
2928
|
+
{ metadata: { runtime: "wasm" } }
|
|
2929
|
+
);
|
|
2930
|
+
}
|
|
2706
2931
|
return callWasmSync(
|
|
2707
2932
|
() => asActorFactoryHandle2(
|
|
2708
2933
|
new this.#constructors.ActorFactory(callbacks, config)
|
|
@@ -2979,12 +3204,18 @@ var WasmCoreRuntime = class {
|
|
|
2979
3204
|
async actorSqlExec(ctx, sql) {
|
|
2980
3205
|
return await callWasm(() => this.#actorSql(ctx).exec(sql));
|
|
2981
3206
|
}
|
|
3207
|
+
actorSqlExecSync(_ctx, _sql) {
|
|
3208
|
+
return synchronousSqliteUnavailable();
|
|
3209
|
+
}
|
|
2982
3210
|
async actorSqlExecute(ctx, sql, params) {
|
|
2983
3211
|
const result = await callWasm(
|
|
2984
3212
|
() => this.#actorSql(ctx).execute(sql, params)
|
|
2985
3213
|
);
|
|
2986
3214
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
2987
3215
|
}
|
|
3216
|
+
actorSqlExecuteSync(_ctx, _sql, _params) {
|
|
3217
|
+
return synchronousSqliteUnavailable();
|
|
3218
|
+
}
|
|
2988
3219
|
async actorSqlExecuteBatch(ctx, statements) {
|
|
2989
3220
|
const results = await callWasm(
|
|
2990
3221
|
() => this.#actorSql(ctx).executeBatch(statements)
|
|
@@ -2996,27 +3227,42 @@ var WasmCoreRuntime = class {
|
|
|
2996
3227
|
() => this.#actorSql(ctx).beginTransaction(timeoutMs, name)
|
|
2997
3228
|
);
|
|
2998
3229
|
}
|
|
3230
|
+
actorSqlBeginTransactionSync(_ctx, _timeoutMs, _name) {
|
|
3231
|
+
return synchronousSqliteUnavailable();
|
|
3232
|
+
}
|
|
2999
3233
|
async actorSqlTransactionExec(transaction, sql) {
|
|
3000
3234
|
return await callWasm(
|
|
3001
3235
|
() => transaction.exec(sql)
|
|
3002
3236
|
);
|
|
3003
3237
|
}
|
|
3238
|
+
actorSqlTransactionExecSync(_transaction, _sql) {
|
|
3239
|
+
return synchronousSqliteUnavailable();
|
|
3240
|
+
}
|
|
3004
3241
|
async actorSqlTransactionExecute(transaction, sql, params) {
|
|
3005
3242
|
const result = await callWasm(
|
|
3006
3243
|
() => transaction.execute(sql, params)
|
|
3007
3244
|
);
|
|
3008
3245
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
3009
3246
|
}
|
|
3247
|
+
actorSqlTransactionExecuteSync(_transaction, _sql, _params) {
|
|
3248
|
+
return synchronousSqliteUnavailable();
|
|
3249
|
+
}
|
|
3010
3250
|
async actorSqlTransactionCommit(transaction) {
|
|
3011
3251
|
await callWasm(
|
|
3012
3252
|
() => transaction.commit()
|
|
3013
3253
|
);
|
|
3014
3254
|
}
|
|
3255
|
+
actorSqlTransactionCommitSync(_transaction) {
|
|
3256
|
+
synchronousSqliteUnavailable();
|
|
3257
|
+
}
|
|
3015
3258
|
async actorSqlTransactionRollback(transaction) {
|
|
3016
3259
|
await callWasm(
|
|
3017
3260
|
() => transaction.rollback()
|
|
3018
3261
|
);
|
|
3019
3262
|
}
|
|
3263
|
+
actorSqlTransactionRollbackSync(_transaction) {
|
|
3264
|
+
synchronousSqliteUnavailable();
|
|
3265
|
+
}
|
|
3020
3266
|
async actorBeginStateTransaction(ctx, timeoutMs) {
|
|
3021
3267
|
return await callWasm(
|
|
3022
3268
|
() => asWasmActorContext(ctx).beginStateTransaction(timeoutMs)
|
|
@@ -3052,6 +3298,17 @@ var WasmCoreRuntime = class {
|
|
|
3052
3298
|
var _a, _b;
|
|
3053
3299
|
return ((_b = (_a = this.#actorSql(ctx)).takeLastKvError) == null ? void 0 : _b.call(_a)) ?? null;
|
|
3054
3300
|
}
|
|
3301
|
+
async actorSqlOpen(_ctx) {
|
|
3302
|
+
}
|
|
3303
|
+
actorSqlCommitTicket(_ctx) {
|
|
3304
|
+
return synchronousSqliteUnavailable();
|
|
3305
|
+
}
|
|
3306
|
+
actorSqlAbortGeneration(_ctx, _reason) {
|
|
3307
|
+
synchronousSqliteUnavailable();
|
|
3308
|
+
}
|
|
3309
|
+
async actorSqlWhenDurable(_ctx, _ticket) {
|
|
3310
|
+
synchronousSqliteUnavailable();
|
|
3311
|
+
}
|
|
3055
3312
|
async actorSqlClose(ctx) {
|
|
3056
3313
|
const wasmCtx = asWasmActorContext(ctx);
|
|
3057
3314
|
const database = this.#sql.get(wasmCtx);
|
|
@@ -3061,17 +3318,6 @@ var WasmCoreRuntime = class {
|
|
|
3061
3318
|
this.#sql.delete(wasmCtx);
|
|
3062
3319
|
await callWasm(() => database.close());
|
|
3063
3320
|
}
|
|
3064
|
-
async actorRuntimeSocketProvision(_ctx) {
|
|
3065
|
-
throw new RivetError(
|
|
3066
|
-
"actor_runtime_socket",
|
|
3067
|
-
"unsupported",
|
|
3068
|
-
"Actor Runtime Socket is only available on Unix native runtimes.",
|
|
3069
|
-
{
|
|
3070
|
-
public: true,
|
|
3071
|
-
metadata: { runtime: "wasm" }
|
|
3072
|
-
}
|
|
3073
|
-
);
|
|
3074
|
-
}
|
|
3075
3321
|
async actorQueueSend(ctx, name, body) {
|
|
3076
3322
|
const queue2 = childHandle(asWasmActorContext(ctx), "queue");
|
|
3077
3323
|
return normalizeQueueMessage(
|
|
@@ -3708,15 +3954,29 @@ async function closeNativeDatabaseClient(runtime, ctx) {
|
|
|
3708
3954
|
await entry.client.close();
|
|
3709
3955
|
}
|
|
3710
3956
|
}
|
|
3957
|
+
function createNativeSqlTransaction(runtime, transaction) {
|
|
3958
|
+
return {
|
|
3959
|
+
exec: (sql) => runtime.actorSqlTransactionExec(transaction, sql),
|
|
3960
|
+
execSync: (sql) => runtime.actorSqlTransactionExecSync(transaction, sql),
|
|
3961
|
+
execute: (sql, params) => runtime.actorSqlTransactionExecute(transaction, sql, params),
|
|
3962
|
+
executeSync: (sql, params) => runtime.actorSqlTransactionExecuteSync(transaction, sql, params),
|
|
3963
|
+
commit: () => runtime.actorSqlTransactionCommit(transaction),
|
|
3964
|
+
commitSync: () => runtime.actorSqlTransactionCommitSync(transaction),
|
|
3965
|
+
rollback: () => runtime.actorSqlTransactionRollback(transaction),
|
|
3966
|
+
rollbackSync: () => runtime.actorSqlTransactionRollbackSync(transaction)
|
|
3967
|
+
};
|
|
3968
|
+
}
|
|
3711
3969
|
function getOrCreateNativeSqlDatabase(runtime, ctx) {
|
|
3712
3970
|
const runtimeState = getNativeRuntimeState(runtime, ctx);
|
|
3713
3971
|
const cachedDatabase = runtimeState.sql;
|
|
3714
3972
|
if (cachedDatabase) {
|
|
3715
3973
|
return cachedDatabase;
|
|
3716
3974
|
}
|
|
3717
|
-
const
|
|
3975
|
+
const bindings = {
|
|
3718
3976
|
exec: (sql) => runtime.actorSqlExec(ctx, sql),
|
|
3977
|
+
execSync: (sql) => runtime.actorSqlExecSync(ctx, sql),
|
|
3719
3978
|
execute: (sql, params) => runtime.actorSqlExecute(ctx, sql, params),
|
|
3979
|
+
executeSync: (sql, params) => runtime.actorSqlExecuteSync(ctx, sql, params),
|
|
3720
3980
|
executeBatch: (statements) => runtime.actorSqlExecuteBatch(ctx, statements),
|
|
3721
3981
|
beginTransaction: async (timeoutMs, name) => {
|
|
3722
3982
|
const transaction = await runtime.actorSqlBeginTransaction(
|
|
@@ -3724,16 +3984,15 @@ function getOrCreateNativeSqlDatabase(runtime, ctx) {
|
|
|
3724
3984
|
timeoutMs,
|
|
3725
3985
|
name
|
|
3726
3986
|
);
|
|
3727
|
-
return
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
};
|
|
3987
|
+
return createNativeSqlTransaction(runtime, transaction);
|
|
3988
|
+
},
|
|
3989
|
+
beginTransactionSync: (timeoutMs, name) => {
|
|
3990
|
+
const transaction = runtime.actorSqlBeginTransactionSync(
|
|
3991
|
+
ctx,
|
|
3992
|
+
timeoutMs,
|
|
3993
|
+
name
|
|
3994
|
+
);
|
|
3995
|
+
return createNativeSqlTransaction(runtime, transaction);
|
|
3737
3996
|
},
|
|
3738
3997
|
beginStateTransaction: async (timeoutMs, context) => {
|
|
3739
3998
|
const scope = context;
|
|
@@ -3771,8 +4030,13 @@ function getOrCreateNativeSqlDatabase(runtime, ctx) {
|
|
|
3771
4030
|
run: (sql, params) => runtime.actorSqlRun(ctx, sql, params),
|
|
3772
4031
|
metrics: () => runtime.actorSqlMetrics(ctx),
|
|
3773
4032
|
takeLastKvError: () => runtime.actorSqlTakeLastKvError(ctx),
|
|
4033
|
+
open: () => runtime.actorSqlOpen(ctx),
|
|
4034
|
+
commitTicket: () => runtime.actorSqlCommitTicket(ctx),
|
|
4035
|
+
whenDurable: (ticket) => runtime.actorSqlWhenDurable(ctx, ticket),
|
|
4036
|
+
abortGeneration: (reason) => runtime.actorSqlAbortGeneration(ctx, reason),
|
|
3774
4037
|
close: () => runtime.actorSqlClose(ctx)
|
|
3775
|
-
}
|
|
4038
|
+
};
|
|
4039
|
+
const database = wrapJsNativeDatabase(bindings);
|
|
3776
4040
|
runtimeState.sql = database;
|
|
3777
4041
|
return database;
|
|
3778
4042
|
}
|
|
@@ -5241,11 +5505,6 @@ var ActorContextHandleAdapter = class {
|
|
|
5241
5505
|
}
|
|
5242
5506
|
return this.#kv;
|
|
5243
5507
|
}
|
|
5244
|
-
async actorRuntimeSocket() {
|
|
5245
|
-
return await callNative(
|
|
5246
|
-
() => this.#runtime.actorRuntimeSocketProvision(this.#ctx)
|
|
5247
|
-
);
|
|
5248
|
-
}
|
|
5249
5508
|
get db() {
|
|
5250
5509
|
if (!this.#databaseProvider) {
|
|
5251
5510
|
throw databaseNotConfiguredError();
|
|
@@ -5518,10 +5777,12 @@ var ActorContextHandleAdapter = class {
|
|
|
5518
5777
|
{
|
|
5519
5778
|
open: async (requestedActorId) => {
|
|
5520
5779
|
void requestedActorId;
|
|
5521
|
-
|
|
5780
|
+
const database = getOrCreateNativeSqlDatabase(
|
|
5522
5781
|
this.#runtime,
|
|
5523
5782
|
this.#ctx
|
|
5524
5783
|
);
|
|
5784
|
+
await database.open();
|
|
5785
|
+
return database;
|
|
5525
5786
|
}
|
|
5526
5787
|
},
|
|
5527
5788
|
async (timeoutMs, context) => await getOrCreateNativeSqlDatabase(
|
|
@@ -5802,16 +6063,16 @@ var ActorContextHandleAdapter = class {
|
|
|
5802
6063
|
// need to keep an actor awake should use `keepAwake(promise)` or
|
|
5803
6064
|
// `waitUntil(promise)` so the native counter machinery in rivetkit-core
|
|
5804
6065
|
// owns the lifecycle.
|
|
5805
|
-
/** @deprecated Use `keepAwake(promise)` or `waitUntil(promise)
|
|
6066
|
+
/** @deprecated `setPreventSleep` was deprecated in 3.0 and will be removed in a future version. It is a no-op. Use `c.keepAwake(promise)` or `c.waitUntil(promise)`. See https://rivet.dev/actors/docs/deprecated/prevent-sleep */
|
|
5806
6067
|
setPreventSleep(_preventSleep) {
|
|
5807
6068
|
logger2().warn({
|
|
5808
|
-
msg: "setPreventSleep
|
|
6069
|
+
msg: "setPreventSleep was deprecated in 3.0 and will be removed in a future version. It is a no-op; use keepAwake(promise) or waitUntil(promise) instead. See https://rivet.dev/actors/docs/deprecated/prevent-sleep"
|
|
5809
6070
|
});
|
|
5810
6071
|
}
|
|
5811
|
-
/** @deprecated Use `keepAwake(promise)` or `waitUntil(promise)
|
|
6072
|
+
/** @deprecated `preventSleep` was deprecated in 3.0 and will be removed in a future version. It is a no-op that always returns `false`. Use `c.keepAwake(promise)` or `c.waitUntil(promise)`. See https://rivet.dev/actors/docs/deprecated/prevent-sleep */
|
|
5812
6073
|
get preventSleep() {
|
|
5813
6074
|
logger2().warn({
|
|
5814
|
-
msg: "preventSleep
|
|
6075
|
+
msg: "preventSleep was deprecated in 3.0 and will be removed in a future version. It always returns false; use keepAwake(promise) or waitUntil(promise) instead. See https://rivet.dev/actors/docs/deprecated/prevent-sleep"
|
|
5815
6076
|
});
|
|
5816
6077
|
return false;
|
|
5817
6078
|
}
|
|
@@ -6124,24 +6385,26 @@ function buildActorTracingConfig(actions, tracing) {
|
|
|
6124
6385
|
actions: flattenActionTraceSamplers(actions, tracing.actions)
|
|
6125
6386
|
};
|
|
6126
6387
|
}
|
|
6388
|
+
var SQLITE_DEFERRED_COMMITS = /* @__PURE__ */ Symbol.for("rivetkit.sqlite.deferredCommits");
|
|
6127
6389
|
function buildActorConfig(definition, registryConfig, runtimeKind) {
|
|
6128
|
-
var _a;
|
|
6390
|
+
var _a, _b;
|
|
6129
6391
|
const config = definition.config;
|
|
6130
6392
|
const options = config.options ?? {};
|
|
6131
6393
|
const canHibernate = options.canHibernateWebSocket;
|
|
6132
6394
|
const usesRemoteSqlite = sqliteBackendForConfig(registryConfig) === "remote";
|
|
6133
6395
|
const sqliteProfiling = (_a = config.db) == null ? void 0 : _a.sqliteProfiling;
|
|
6396
|
+
const sqliteDeferredCommits = ((_b = config.db) == null ? void 0 : _b[SQLITE_DEFERRED_COMMITS]) === true;
|
|
6134
6397
|
return {
|
|
6135
6398
|
name: options.name,
|
|
6136
6399
|
icon: options.icon,
|
|
6137
6400
|
hasDatabase: true,
|
|
6138
6401
|
remoteSqlite: usesRemoteSqlite,
|
|
6402
|
+
sqliteDeferredCommits: sqliteDeferredCommits || void 0,
|
|
6139
6403
|
sqliteProfiling,
|
|
6140
6404
|
tracing: buildActorTracingConfig(
|
|
6141
6405
|
definition.config.actions,
|
|
6142
6406
|
definition.config.tracing
|
|
6143
6407
|
),
|
|
6144
|
-
enableActorRuntimeSocket: options.enableActorRuntimeSocket === true,
|
|
6145
6408
|
hasState: config.state !== void 0 || typeof config.createState === "function",
|
|
6146
6409
|
canHibernateWebsocket: typeof canHibernate === "boolean" ? canHibernate : void 0,
|
|
6147
6410
|
stateSaveIntervalMs: options.stateSaveInterval,
|
|
@@ -7421,6 +7684,7 @@ async function buildConfiguredRegistry(config) {
|
|
|
7421
7684
|
var REGISTRY_READY_TIMEOUT_MS = 3e4;
|
|
7422
7685
|
var LOCAL_ENGINE_READY_TIMEOUT_MS = 6e4;
|
|
7423
7686
|
var LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS = 4e3;
|
|
7687
|
+
var DEFAULT_ACTOR_STOP_THRESHOLD_MS = 3e4;
|
|
7424
7688
|
function rejectServerless() {
|
|
7425
7689
|
throw new Error("serverless is disabled in this version");
|
|
7426
7690
|
}
|
|
@@ -7507,6 +7771,11 @@ var Registry = class {
|
|
|
7507
7771
|
#shutdownInstalled = false;
|
|
7508
7772
|
#shutdownInFlight = null;
|
|
7509
7773
|
#signalHandlers = {};
|
|
7774
|
+
#envoyConfiguredRegistry;
|
|
7775
|
+
#activeActorCountListeners = /* @__PURE__ */ new Set();
|
|
7776
|
+
#activeActorCountToken;
|
|
7777
|
+
#lastActiveActorCount;
|
|
7778
|
+
#activeActorCountSupported;
|
|
7510
7779
|
constructor(config, deps) {
|
|
7511
7780
|
var _a;
|
|
7512
7781
|
this.#config = config;
|
|
@@ -7921,6 +8190,21 @@ var Registry = class {
|
|
|
7921
8190
|
}
|
|
7922
8191
|
const configuredRegistryPromise = this.#buildConfiguredRegistry(config);
|
|
7923
8192
|
this.#runtimeServeConfiguredPromise = configuredRegistryPromise;
|
|
8193
|
+
configuredRegistryPromise.then(
|
|
8194
|
+
(configured) => {
|
|
8195
|
+
this.#envoyConfiguredRegistry = configured;
|
|
8196
|
+
try {
|
|
8197
|
+
this.#syncActiveActorCountSubscription();
|
|
8198
|
+
} catch (error) {
|
|
8199
|
+
logger2().error(
|
|
8200
|
+
{ error },
|
|
8201
|
+
"failed to subscribe to the active actor count"
|
|
8202
|
+
);
|
|
8203
|
+
}
|
|
8204
|
+
},
|
|
8205
|
+
// The serve lifecycle below reports build failures.
|
|
8206
|
+
() => void 0
|
|
8207
|
+
);
|
|
7924
8208
|
this.#runtimeServeLifecyclePromise = configuredRegistryPromise.then(
|
|
7925
8209
|
async ({ runtime, registry, serveConfig }) => {
|
|
7926
8210
|
await runtime.serveRegistry(registry, serveConfig);
|
|
@@ -8006,7 +8290,7 @@ var Registry = class {
|
|
|
8006
8290
|
if (gracePeriodMs === void 0) {
|
|
8007
8291
|
gracePeriodMs = localDevSignal ? LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS : await this.#actorStopThresholdMs(
|
|
8008
8292
|
modeAPromise ?? modeBPromise
|
|
8009
|
-
) ??
|
|
8293
|
+
) ?? DEFAULT_ACTOR_STOP_THRESHOLD_MS;
|
|
8010
8294
|
}
|
|
8011
8295
|
const drain = async () => {
|
|
8012
8296
|
const registries = [];
|
|
@@ -8200,6 +8484,101 @@ var Registry = class {
|
|
|
8200
8484
|
const config = this.parseConfig();
|
|
8201
8485
|
this.#startEnvoy(config, true);
|
|
8202
8486
|
}
|
|
8487
|
+
/**
|
|
8488
|
+
* Returns the number of actors hosted by this process's envoy, which is zero
|
|
8489
|
+
* while it is not serving. Requires the native runtime.
|
|
8490
|
+
*/
|
|
8491
|
+
activeActorCount() {
|
|
8492
|
+
this.#assertActiveActorCountSupported("activeActorCount");
|
|
8493
|
+
const configured = this.#envoyConfiguredRegistry;
|
|
8494
|
+
if (!configured) return 0;
|
|
8495
|
+
const { runtime, registry } = configured;
|
|
8496
|
+
if (!runtime.registryActiveActorCount) {
|
|
8497
|
+
throw new Error(
|
|
8498
|
+
"registry.activeActorCount() is not supported by this runtime"
|
|
8499
|
+
);
|
|
8500
|
+
}
|
|
8501
|
+
return runtime.registryActiveActorCount(registry);
|
|
8502
|
+
}
|
|
8503
|
+
/**
|
|
8504
|
+
* Calls `callback` with the number of actors hosted by this process's envoy
|
|
8505
|
+
* and again whenever it changes. Rapid changes may coalesce.
|
|
8506
|
+
* Returns a function that unsubscribes. Requires the native runtime.
|
|
8507
|
+
*
|
|
8508
|
+
* @example
|
|
8509
|
+
* ```ts
|
|
8510
|
+
* const unsubscribe = registry.onActiveActorCountChange((count) => {
|
|
8511
|
+
* setTaskProtection(count > 0);
|
|
8512
|
+
* });
|
|
8513
|
+
* ```
|
|
8514
|
+
*/
|
|
8515
|
+
onActiveActorCountChange(callback) {
|
|
8516
|
+
this.#assertActiveActorCountSupported("onActiveActorCountChange");
|
|
8517
|
+
const listener = (count) => callback(count);
|
|
8518
|
+
this.#activeActorCountListeners.add(listener);
|
|
8519
|
+
this.#syncActiveActorCountSubscription();
|
|
8520
|
+
const lastCount = this.#lastActiveActorCount;
|
|
8521
|
+
if (lastCount !== void 0) {
|
|
8522
|
+
queueMicrotask(() => {
|
|
8523
|
+
if (this.#activeActorCountListeners.has(listener)) {
|
|
8524
|
+
this.#deliverActiveActorCount(listener, lastCount);
|
|
8525
|
+
}
|
|
8526
|
+
});
|
|
8527
|
+
}
|
|
8528
|
+
return () => {
|
|
8529
|
+
this.#activeActorCountListeners.delete(listener);
|
|
8530
|
+
this.#syncActiveActorCountSubscription();
|
|
8531
|
+
};
|
|
8532
|
+
}
|
|
8533
|
+
#assertActiveActorCountSupported(method2) {
|
|
8534
|
+
this.#activeActorCountSupported ??= this.parseConfig().runtime !== "wasm";
|
|
8535
|
+
if (!this.#activeActorCountSupported) {
|
|
8536
|
+
throw new Error(
|
|
8537
|
+
`registry.${method2}() requires the native runtime; WebAssembly registries do not host an envoy`
|
|
8538
|
+
);
|
|
8539
|
+
}
|
|
8540
|
+
}
|
|
8541
|
+
/** Holds one native subscription while any listener is registered. */
|
|
8542
|
+
#syncActiveActorCountSubscription() {
|
|
8543
|
+
const configured = this.#envoyConfiguredRegistry;
|
|
8544
|
+
if (!configured) return;
|
|
8545
|
+
const { runtime, registry } = configured;
|
|
8546
|
+
const token = this.#activeActorCountToken;
|
|
8547
|
+
if (this.#activeActorCountListeners.size === 0) {
|
|
8548
|
+
if (token !== void 0) {
|
|
8549
|
+
this.#activeActorCountToken = void 0;
|
|
8550
|
+
this.#lastActiveActorCount = void 0;
|
|
8551
|
+
runtime.cancelCancellationToken(token);
|
|
8552
|
+
}
|
|
8553
|
+
return;
|
|
8554
|
+
}
|
|
8555
|
+
if (token !== void 0) return;
|
|
8556
|
+
if (!runtime.onRegistryActiveActorCountChange) {
|
|
8557
|
+
throw new Error(
|
|
8558
|
+
"active actor count subscriptions are not supported by this runtime"
|
|
8559
|
+
);
|
|
8560
|
+
}
|
|
8561
|
+
const nextToken = runtime.createCancellationToken();
|
|
8562
|
+
this.#activeActorCountToken = nextToken;
|
|
8563
|
+
runtime.onRegistryActiveActorCountChange(
|
|
8564
|
+
registry,
|
|
8565
|
+
(count) => {
|
|
8566
|
+
if (this.#activeActorCountToken !== nextToken) return;
|
|
8567
|
+
this.#lastActiveActorCount = count;
|
|
8568
|
+
for (const listener of [...this.#activeActorCountListeners]) {
|
|
8569
|
+
this.#deliverActiveActorCount(listener, count);
|
|
8570
|
+
}
|
|
8571
|
+
},
|
|
8572
|
+
nextToken
|
|
8573
|
+
);
|
|
8574
|
+
}
|
|
8575
|
+
#deliverActiveActorCount(listener, count) {
|
|
8576
|
+
try {
|
|
8577
|
+
listener(count);
|
|
8578
|
+
} catch (error) {
|
|
8579
|
+
logger2().error({ error }, "active actor count listener threw");
|
|
8580
|
+
}
|
|
8581
|
+
}
|
|
8203
8582
|
#printWelcome(config, kind, listener) {
|
|
8204
8583
|
if (config.noWelcome || this.#welcomePrinted) return;
|
|
8205
8584
|
this.#welcomePrinted = true;
|