rivetkit 0.0.0-sqlite-profiling-compat.87d61c0 → 0.0.0-sqlite-sync-3x-release.a00b07f
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 +1317 -765
- package/dist/browser/client.js +1457 -737
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +252 -129
- package/dist/browser/inspector/client.js +2042 -228
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +6 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +1 -1
- package/dist/tsup/actor/errors.d.ts +1 -1
- package/dist/tsup/actor/errors.js +5 -1
- package/dist/tsup/agent-os/index.cjs +3 -2367
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +1 -2277
- package/dist/tsup/agent-os/index.d.ts +1 -2277
- package/dist/tsup/agent-os/index.js +3 -2367
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-E4LNLI3W.cjs → chunk-2MOLY6AM.cjs} +444 -29
- package/dist/tsup/chunk-2MOLY6AM.cjs.map +1 -0
- package/dist/tsup/{chunk-OAUFXOG7.js → chunk-3DONDAMG.js} +2 -2
- package/dist/tsup/{chunk-XIX5DOZN.js → chunk-6FEYCVZC.js} +196 -20
- package/dist/tsup/chunk-6FEYCVZC.js.map +1 -0
- package/dist/tsup/chunk-6KXVLIXL.cjs +14 -0
- package/dist/tsup/chunk-6KXVLIXL.cjs.map +1 -0
- package/dist/tsup/chunk-73RNTXHB.cjs +243 -0
- package/dist/tsup/chunk-73RNTXHB.cjs.map +1 -0
- package/dist/tsup/{chunk-HXUEHHJF.js → chunk-A2CF6PFH.js} +19 -11
- package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
- package/dist/tsup/{chunk-EFU4JW3T.js → chunk-BRH4PQS5.js} +436 -21
- package/dist/tsup/chunk-BRH4PQS5.js.map +1 -0
- package/dist/tsup/{chunk-GM45LG7L.cjs → chunk-BTSDFFDC.cjs} +18 -11
- package/dist/tsup/chunk-BTSDFFDC.cjs.map +1 -0
- package/dist/tsup/{chunk-B3GLD4IN.js → chunk-D5WUPE47.js} +50 -3
- package/dist/tsup/chunk-D5WUPE47.js.map +1 -0
- package/dist/tsup/{chunk-O3ZUMAN7.js → chunk-DJUBJQEQ.js} +3 -3
- package/dist/tsup/chunk-DJUBJQEQ.js.map +1 -0
- package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-HDVZ6YZG.cjs} +197 -21
- package/dist/tsup/chunk-HDVZ6YZG.cjs.map +1 -0
- package/dist/tsup/{chunk-JZ7TWV65.js → chunk-JTHHCZCZ.js} +24 -1
- package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
- package/dist/tsup/{chunk-D363DMNH.cjs → chunk-JUHXV3HF.cjs} +3 -3
- package/dist/tsup/chunk-JUHXV3HF.cjs.map +1 -0
- package/dist/tsup/chunk-JUWMP5O3.js +14 -0
- package/dist/tsup/chunk-JUWMP5O3.js.map +1 -0
- package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-KVFIONKQ.cjs} +25 -2
- package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-4FC7TVS6.cjs → chunk-MGI2VVF6.cjs} +39 -7
- package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
- package/dist/tsup/{chunk-BWERJMV6.cjs → chunk-OTVJYZ2L.cjs} +1139 -470
- package/dist/tsup/chunk-OTVJYZ2L.cjs.map +1 -0
- package/dist/tsup/{chunk-VE2X4KMG.cjs → chunk-RTWH3AX3.cjs} +18 -10
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
- package/dist/tsup/{chunk-DTRDGPHU.cjs → chunk-TM76Z7XT.cjs} +7 -7
- package/dist/tsup/chunk-TM76Z7XT.cjs.map +1 -0
- package/dist/tsup/{chunk-3GVMLSND.js → chunk-TRUHDXOU.js} +1023 -354
- package/dist/tsup/chunk-TRUHDXOU.js.map +1 -0
- package/dist/tsup/{chunk-PT7AC5PC.js → chunk-TSQTI6H6.js} +16 -9
- package/dist/tsup/chunk-TSQTI6H6.js.map +1 -0
- package/dist/tsup/{chunk-FNAXD5BQ.cjs → chunk-Z7E2G3JZ.cjs} +52 -5
- package/dist/tsup/chunk-Z7E2G3JZ.cjs.map +1 -0
- package/dist/tsup/{chunk-ZZ3WBRPD.js → chunk-ZOVJDAOW.js} +38 -6
- package/dist/tsup/chunk-ZOVJDAOW.js.map +1 -0
- package/dist/tsup/chunk-ZYK4B5WV.js +243 -0
- package/dist/tsup/chunk-ZYK4B5WV.js.map +1 -0
- package/dist/tsup/client/mod.cjs +8 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +32 -6
- package/dist/tsup/client/mod.d.ts +32 -6
- package/dist/tsup/client/mod.js +7 -8
- package/dist/tsup/common/log.cjs +5 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +5 -1
- package/dist/tsup/common/log.d.ts +5 -1
- package/dist/tsup/common/log.js +6 -4
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-BR1Nn0QQ.d.ts → config-B4erdavw.d.ts} +571 -65
- package/dist/tsup/{config-B0LNDrLY.d.cts → config-BfG1qpYz.d.cts} +80 -14
- package/dist/tsup/{config-B0LNDrLY.d.ts → config-BfG1qpYz.d.ts} +80 -14
- package/dist/tsup/{config-tCvkwzyN.d.cts → config-DK144OAw.d.cts} +571 -65
- package/dist/tsup/{context-D4WDwf9m.d.cts → context-Cvnf3BRe.d.cts} +3 -2
- package/dist/tsup/{context-oc9zhA3x.d.ts → context-Oxi6YWcG.d.ts} +3 -2
- package/dist/tsup/db/drizzle.cjs +127 -67
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +8 -4
- package/dist/tsup/db/drizzle.d.ts +8 -4
- package/dist/tsup/db/drizzle.js +127 -67
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +6 -126
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +8 -4
- package/dist/tsup/db/mod.d.ts +8 -4
- package/dist/tsup/db/mod.js +5 -125
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.cjs.map +1 -1
- package/dist/tsup/dynamic/mod.d.cts +6 -4
- package/dist/tsup/dynamic/mod.d.ts +6 -4
- package/dist/tsup/dynamic/mod.js +1 -1
- package/dist/tsup/inspector/mod.cjs +47 -12
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +26 -136
- package/dist/tsup/inspector/mod.d.ts +26 -136
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector/workflow.cjs +21 -0
- package/dist/tsup/inspector/workflow.cjs.map +1 -0
- package/dist/tsup/inspector/workflow.d.cts +144 -0
- package/dist/tsup/inspector/workflow.d.ts +144 -0
- package/dist/tsup/inspector/workflow.js +21 -0
- package/dist/tsup/inspector/workflow.js.map +1 -0
- package/dist/tsup/inspector-tab/mod.cjs +2 -13
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -1
- package/dist/tsup/inspector-tab/mod.d.cts +9 -17
- package/dist/tsup/inspector-tab/mod.d.ts +9 -17
- package/dist/tsup/inspector-tab/mod.js +1 -12
- package/dist/tsup/inspector-tab/mod.js.map +1 -1
- package/dist/tsup/mod.cjs +2724 -611
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +9 -7
- package/dist/tsup/mod.d.ts +9 -7
- package/dist/tsup/mod.js +2641 -528
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +19 -17
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +6 -4
- package/dist/tsup/test/mod.d.ts +6 -4
- package/dist/tsup/test/mod.js +18 -16
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/unstable/migrations.cjs +101 -0
- package/dist/tsup/unstable/migrations.cjs.map +1 -0
- package/dist/tsup/unstable/migrations.d.cts +29 -0
- package/dist/tsup/unstable/migrations.d.ts +29 -0
- package/dist/tsup/unstable/migrations.js +101 -0
- package/dist/tsup/unstable/migrations.js.map +1 -0
- package/dist/tsup/{utils-CqDnC_PS.d.cts → utils-3rsE0JvI.d.cts} +25 -2
- package/dist/tsup/{utils-CqDnC_PS.d.ts → utils-3rsE0JvI.d.ts} +25 -2
- package/dist/tsup/utils-C1O-SklO.d.ts +162 -0
- package/dist/tsup/utils-C6b0aYUM.d.cts +162 -0
- package/dist/tsup/utils.cjs +7 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +4 -147
- package/dist/tsup/utils.d.ts +4 -147
- package/dist/tsup/utils.js +6 -2
- package/dist/tsup/workflow/mod.cjs +260 -200
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +8 -6
- package/dist/tsup/workflow/mod.d.ts +8 -6
- package/dist/tsup/workflow/mod.js +249 -189
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +34 -14
- package/src/actor/actions.ts +155 -0
- package/src/actor/config.ts +403 -43
- package/src/actor/definition.ts +26 -7
- package/src/actor/errors.ts +87 -5
- package/src/actor/keys.ts +86 -0
- package/src/actor/mod.ts +15 -1
- package/src/actor/tracing.ts +28 -0
- package/src/agent-os/index.ts +5 -65
- package/src/client/actor-common.ts +8 -15
- package/src/client/actor-conn.ts +135 -8
- package/src/client/actor-handle.ts +180 -42
- package/src/client/actor-query.ts +8 -1
- package/src/client/auth.ts +37 -0
- package/src/client/client.ts +89 -21
- package/src/client/config.ts +27 -2
- package/src/client/errors.ts +2 -1
- package/src/client/lifecycle-errors.ts +16 -1
- package/src/client/mod.ts +9 -0
- package/src/client/outbound-telemetry.ts +66 -0
- package/src/client/query.ts +2 -0
- package/src/client/queue.ts +3 -0
- package/src/client/raw-utils.ts +37 -8
- package/src/client/resolve-gateway-target.ts +2 -0
- package/src/client/retry-budget.ts +78 -0
- package/src/client/token-provider.ts +93 -0
- package/src/client/utils.ts +16 -2
- package/src/common/actor-router-consts.ts +5 -0
- package/src/common/actor-telemetry-context.ts +19 -0
- package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
- package/src/common/bare/generated/inspector/v5.ts +1016 -0
- package/src/common/bare/generated/inspector/v6.ts +1367 -0
- package/src/common/bare/transport/v1.ts +36 -0
- package/src/common/database/config.ts +108 -15
- package/src/common/database/mod.ts +247 -76
- package/src/common/database/native-database.ts +433 -23
- package/src/common/database/shared.ts +24 -0
- package/src/common/encoding.ts +31 -21
- package/src/common/fetch-like.ts +63 -0
- package/src/common/inspector-transport.ts +12 -2
- package/src/common/log.ts +14 -8
- package/src/common/otel-context.ts +99 -0
- package/src/common/router.ts +1 -1
- package/src/common/utils.ts +7 -19
- package/src/db/drizzle.ts +182 -80
- package/src/db/mod.ts +2 -0
- package/src/dynamic/isolate-runtime.ts +0 -2
- package/src/engine-api/actors.ts +3 -3
- package/src/engine-client/actor-http-client.ts +29 -20
- package/src/engine-client/actor-websocket-client.ts +6 -3
- package/src/engine-client/api-endpoints.ts +72 -14
- package/src/engine-client/driver.ts +8 -15
- package/src/engine-client/mod.ts +248 -112
- package/src/inspector/client.browser.ts +134 -16
- package/src/inspector/mod.ts +1 -1
- package/src/inspector/workflow.ts +61 -0
- package/src/inspector-tab/mod.ts +1 -15
- package/src/registry/config/envoy.ts +2 -18
- package/src/registry/config/index.ts +53 -61
- package/src/registry/index.ts +311 -21
- package/src/registry/napi-runtime.ts +583 -39
- package/src/registry/native-http.ts +225 -0
- package/src/registry/native.ts +1365 -414
- package/src/registry/run-handler-coordinator.ts +219 -0
- package/src/registry/runtime.ts +372 -7
- package/src/registry/wasm-runtime.ts +490 -21
- package/src/registry/write-through-proxy.ts +101 -0
- package/src/test/mod.ts +1 -19
- package/src/test/ready.ts +22 -0
- package/src/unstable/migrations.ts +141 -0
- package/src/utils/env-vars.ts +15 -6
- package/src/utils/node.ts +44 -28
- package/src/utils.ts +3 -0
- package/src/workflow/context.ts +9 -27
- package/src/workflow/driver.ts +253 -116
- package/src/workflow/inspector.ts +23 -24
- package/src/workflow/mod.ts +50 -72
- package/dist/tsup/chunk-3GVMLSND.js.map +0 -1
- package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
- package/dist/tsup/chunk-4FC7TVS6.cjs.map +0 -1
- package/dist/tsup/chunk-B3GLD4IN.js.map +0 -1
- package/dist/tsup/chunk-BWERJMV6.cjs.map +0 -1
- package/dist/tsup/chunk-D363DMNH.cjs.map +0 -1
- package/dist/tsup/chunk-DTRDGPHU.cjs.map +0 -1
- package/dist/tsup/chunk-E4LNLI3W.cjs.map +0 -1
- package/dist/tsup/chunk-EFU4JW3T.js.map +0 -1
- package/dist/tsup/chunk-FNAXD5BQ.cjs.map +0 -1
- package/dist/tsup/chunk-GM45LG7L.cjs.map +0 -1
- package/dist/tsup/chunk-HXUEHHJF.js.map +0 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
- package/dist/tsup/chunk-O3ZUMAN7.js.map +0 -1
- package/dist/tsup/chunk-P6F5MEWX.cjs +0 -382
- package/dist/tsup/chunk-P6F5MEWX.cjs.map +0 -1
- package/dist/tsup/chunk-PT7AC5PC.js.map +0 -1
- package/dist/tsup/chunk-UV7INX3N.js +0 -382
- package/dist/tsup/chunk-UV7INX3N.js.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/dist/tsup/chunk-ZZ3WBRPD.js.map +0 -1
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2484
- package/src/actor/keys.test.ts +0 -275
- package/src/actor/utils.test.ts +0 -48
- package/src/agent-os/actor/cron.ts +0 -84
- package/src/agent-os/actor/db.ts +0 -54
- package/src/agent-os/actor/filesystem.ts +0 -131
- package/src/agent-os/actor/index.ts +0 -285
- package/src/agent-os/actor/network.ts +0 -58
- package/src/agent-os/actor/preview.ts +0 -190
- package/src/agent-os/actor/process.ts +0 -177
- package/src/agent-os/actor/session.ts +0 -518
- package/src/agent-os/actor/shell.ts +0 -60
- package/src/agent-os/config.ts +0 -79
- package/src/agent-os/fs/database-vfs.ts +0 -624
- package/src/agent-os/types.ts +0 -148
- package/src/client/test.ts +0 -44
- package/src/common/database/mod.test.ts +0 -137
- package/src/common/database/native-database.test.ts +0 -211
- package/src/common/inline-websocket-adapter.test.ts +0 -51
- package/src/drivers/engine/actor-driver.ts +0 -2473
- package/src/registry/process-metrics.ts +0 -250
- package/src/registry/runtime.test.ts +0 -50
- package/src/utils/endpoint-parser.test.ts +0 -206
- package/src/utils.test.ts +0 -34
- /package/dist/tsup/{chunk-OAUFXOG7.js.map → chunk-3DONDAMG.js.map} +0 -0
|
@@ -1,24 +1,41 @@
|
|
|
1
|
+
import type { AsyncLocalStorage } from "node:async_hooks";
|
|
1
2
|
import type {
|
|
2
3
|
ActorContext as NativeActorContext,
|
|
3
4
|
NapiActorFactory as NativeActorFactory,
|
|
4
5
|
CancellationToken as NativeCancellationToken,
|
|
5
6
|
ConnHandle as NativeConnHandle,
|
|
6
7
|
CoreRegistry as NativeCoreRegistry,
|
|
8
|
+
HttpResponseBodyStream as NativeHttpResponseBodyStream,
|
|
7
9
|
WebSocket as NativeWebSocket,
|
|
8
10
|
} from "@rivetkit/rivetkit-napi";
|
|
11
|
+
import type { WorkflowSpan } from "@/actor/config";
|
|
12
|
+
import { encodeErrorForBridge } from "@/actor/errors";
|
|
13
|
+
import type { ActorInvocationTraceContext } from "@/common/actor-telemetry-context";
|
|
14
|
+
import {
|
|
15
|
+
readActiveTraceHeaders,
|
|
16
|
+
runWithActorInvocationSpan,
|
|
17
|
+
} from "@/common/otel-context";
|
|
18
|
+
import { logger } from "./log";
|
|
9
19
|
import type {
|
|
10
20
|
ActorContextHandle,
|
|
11
21
|
ActorFactoryHandle,
|
|
22
|
+
ActorStateTransactionHandle,
|
|
12
23
|
CancellationTokenHandle,
|
|
13
24
|
ConnHandle,
|
|
14
25
|
CoreRuntime,
|
|
15
26
|
RegistryHandle,
|
|
16
27
|
RuntimeActorConfig,
|
|
28
|
+
RuntimeApplicationFetch,
|
|
29
|
+
RuntimeApplicationListenerConfig,
|
|
17
30
|
RuntimeBytes,
|
|
31
|
+
RuntimeCronFire,
|
|
32
|
+
RuntimeCronJobInfo,
|
|
18
33
|
RuntimeHttpRequest,
|
|
34
|
+
RuntimeHttpResponseBodyStream,
|
|
19
35
|
RuntimeKvEntry,
|
|
20
36
|
RuntimeKvListOptions,
|
|
21
37
|
RuntimeListenerConfig,
|
|
38
|
+
RuntimeOutboundCall,
|
|
22
39
|
RuntimeQueueEnqueueAndWaitOptions,
|
|
23
40
|
RuntimeQueueMessage,
|
|
24
41
|
RuntimeQueueNextBatchOptions,
|
|
@@ -26,10 +43,12 @@ import type {
|
|
|
26
43
|
RuntimeQueueWaitOptions,
|
|
27
44
|
RuntimeRegistryRouteResponse,
|
|
28
45
|
RuntimeRequestSaveOpts,
|
|
46
|
+
RuntimeScheduledEventInfo,
|
|
29
47
|
RuntimeServeConfig,
|
|
30
48
|
RuntimeServerlessRequest,
|
|
31
49
|
RuntimeServerlessResponseHead,
|
|
32
50
|
RuntimeServerlessStreamCallback,
|
|
51
|
+
RuntimeSqlBatchStatement,
|
|
33
52
|
RuntimeSqlBindParam,
|
|
34
53
|
RuntimeSqlBindParams,
|
|
35
54
|
RuntimeSqlExecResult,
|
|
@@ -38,6 +57,8 @@ import type {
|
|
|
38
57
|
RuntimeSqlRunResult,
|
|
39
58
|
RuntimeStateDeltaPayload,
|
|
40
59
|
RuntimeWebSocketEvent,
|
|
60
|
+
RuntimeWorkflowKvWrite,
|
|
61
|
+
SqliteTransactionHandle,
|
|
41
62
|
WebSocketHandle,
|
|
42
63
|
} from "./runtime";
|
|
43
64
|
import { normalizeRuntimeSqlExecuteResult } from "./runtime";
|
|
@@ -45,6 +66,18 @@ import { normalizeRuntimeSqlExecuteResult } from "./runtime";
|
|
|
45
66
|
type NativeBindings = typeof import("@rivetkit/rivetkit-napi");
|
|
46
67
|
type NapiSqlDatabase = ReturnType<NativeActorContext["sql"]>;
|
|
47
68
|
type NapiSqlBindParams = Parameters<NapiSqlDatabase["execute"]>[1];
|
|
69
|
+
type NapiSqlBatchStatement = Parameters<
|
|
70
|
+
NapiSqlDatabase["executeBatch"]
|
|
71
|
+
>[0][number];
|
|
72
|
+
type NapiSqlTransaction = Awaited<
|
|
73
|
+
ReturnType<NapiSqlDatabase["beginTransaction"]>
|
|
74
|
+
>;
|
|
75
|
+
type NapiActorStateTransaction = Awaited<
|
|
76
|
+
ReturnType<NativeActorContext["beginStateTransaction"]>
|
|
77
|
+
>;
|
|
78
|
+
type NapiQueueMessage = Awaited<
|
|
79
|
+
ReturnType<ReturnType<NativeActorContext["queue"]>["send"]>
|
|
80
|
+
>;
|
|
48
81
|
|
|
49
82
|
function asNativeRegistry(handle: RegistryHandle): NativeCoreRegistry {
|
|
50
83
|
return handle as unknown as NativeCoreRegistry;
|
|
@@ -66,6 +99,17 @@ function asNativeWebSocket(handle: WebSocketHandle): NativeWebSocket {
|
|
|
66
99
|
return handle as unknown as NativeWebSocket;
|
|
67
100
|
}
|
|
68
101
|
|
|
102
|
+
function asNativeSqlTransaction(
|
|
103
|
+
handle: SqliteTransactionHandle,
|
|
104
|
+
): NapiSqlTransaction {
|
|
105
|
+
return handle as unknown as NapiSqlTransaction;
|
|
106
|
+
}
|
|
107
|
+
function asNativeActorStateTransaction(
|
|
108
|
+
handle: ActorStateTransactionHandle,
|
|
109
|
+
): NapiActorStateTransaction {
|
|
110
|
+
return handle as unknown as NapiActorStateTransaction;
|
|
111
|
+
}
|
|
112
|
+
|
|
69
113
|
function asNativeCancellationToken(
|
|
70
114
|
handle: CancellationTokenHandle,
|
|
71
115
|
): NativeCancellationToken {
|
|
@@ -104,10 +148,69 @@ function toNapiSqlBindParams(params?: RuntimeSqlBindParams): NapiSqlBindParams {
|
|
|
104
148
|
return params.map((param) => toNapiSqlBindParam(param));
|
|
105
149
|
}
|
|
106
150
|
|
|
151
|
+
function toNapiSqlBatchStatement(
|
|
152
|
+
statement: RuntimeSqlBatchStatement,
|
|
153
|
+
): NapiSqlBatchStatement {
|
|
154
|
+
return {
|
|
155
|
+
sql: statement.sql,
|
|
156
|
+
params: toNapiSqlBindParams(statement.params) ?? undefined,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
107
160
|
function toNapiBuffer(value: RuntimeBytes): Buffer {
|
|
108
161
|
return Buffer.from(value);
|
|
109
162
|
}
|
|
110
163
|
|
|
164
|
+
function toNapiApplication(application: RuntimeApplicationFetch) {
|
|
165
|
+
return async (
|
|
166
|
+
error: unknown,
|
|
167
|
+
request?: {
|
|
168
|
+
method: string;
|
|
169
|
+
url: string;
|
|
170
|
+
headers: Record<string, string>;
|
|
171
|
+
body: Buffer;
|
|
172
|
+
cancelToken?: NativeCancellationToken;
|
|
173
|
+
responseBodyStream?: RuntimeHttpResponseBodyStream;
|
|
174
|
+
},
|
|
175
|
+
) => {
|
|
176
|
+
if (error) throw error;
|
|
177
|
+
if (!request) {
|
|
178
|
+
throw new Error("application fetch callback received no request");
|
|
179
|
+
}
|
|
180
|
+
const response = await application(
|
|
181
|
+
{
|
|
182
|
+
...request,
|
|
183
|
+
body: new Uint8Array(request.body),
|
|
184
|
+
cancelToken:
|
|
185
|
+
request.cancelToken as unknown as CancellationTokenHandle,
|
|
186
|
+
},
|
|
187
|
+
request.responseBodyStream
|
|
188
|
+
? fromNapiHttpResponseBodyStream(
|
|
189
|
+
request.responseBodyStream as unknown as NativeHttpResponseBodyStream,
|
|
190
|
+
)
|
|
191
|
+
: undefined,
|
|
192
|
+
);
|
|
193
|
+
return {
|
|
194
|
+
...response,
|
|
195
|
+
body:
|
|
196
|
+
response.body === undefined
|
|
197
|
+
? undefined
|
|
198
|
+
: toNapiBuffer(response.body),
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function fromNapiHttpResponseBodyStream(
|
|
204
|
+
stream: NativeHttpResponseBodyStream,
|
|
205
|
+
): RuntimeHttpResponseBodyStream {
|
|
206
|
+
return {
|
|
207
|
+
cancelled: () => stream.cancelled(),
|
|
208
|
+
write: (chunk) => stream.write(Buffer.from(chunk)),
|
|
209
|
+
end: () => stream.end(),
|
|
210
|
+
error: (message) => stream.error(message),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
111
214
|
function toNapiHttpRequest(
|
|
112
215
|
request?: RuntimeHttpRequest | undefined | null,
|
|
113
216
|
): Parameters<NativeActorContext["connectConn"]>[1] {
|
|
@@ -143,7 +246,7 @@ function toNapiKvEntry(entry: RuntimeKvEntry): {
|
|
|
143
246
|
};
|
|
144
247
|
}
|
|
145
248
|
|
|
146
|
-
function toNapiQueueMessage(message:
|
|
249
|
+
function toNapiQueueMessage(message: NapiQueueMessage): RuntimeQueueMessage {
|
|
147
250
|
return {
|
|
148
251
|
id: () => message.id(),
|
|
149
252
|
name: () => message.name(),
|
|
@@ -164,23 +267,54 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
164
267
|
readonly kind = "napi";
|
|
165
268
|
|
|
166
269
|
#bindings: NativeBindings;
|
|
167
|
-
#
|
|
270
|
+
#sqlOpened = new WeakSet<NativeActorContext>();
|
|
271
|
+
#invocationContext: AsyncLocalStorage<NativeActorContext>;
|
|
168
272
|
|
|
169
|
-
constructor(
|
|
273
|
+
constructor(
|
|
274
|
+
bindings: NativeBindings,
|
|
275
|
+
invocationContext: AsyncLocalStorage<NativeActorContext>,
|
|
276
|
+
) {
|
|
170
277
|
this.#bindings = bindings;
|
|
278
|
+
this.#invocationContext = invocationContext;
|
|
171
279
|
}
|
|
172
280
|
|
|
173
|
-
#
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
if (!
|
|
177
|
-
|
|
178
|
-
|
|
281
|
+
#actorContextForOperation(owner: ActorContextHandle): NativeActorContext {
|
|
282
|
+
const ownerCtx = asNativeActorContext(owner);
|
|
283
|
+
const active = this.#invocationContext.getStore();
|
|
284
|
+
if (!active?.sameActorInstance(ownerCtx)) {
|
|
285
|
+
return ownerCtx;
|
|
286
|
+
}
|
|
287
|
+
const applicationSpan = readActiveTraceHeaders();
|
|
288
|
+
if (!applicationSpan) {
|
|
289
|
+
return active;
|
|
179
290
|
}
|
|
180
|
-
return
|
|
291
|
+
return active.withApplicationSpan(
|
|
292
|
+
applicationSpan.traceparent,
|
|
293
|
+
applicationSpan.tracestate ?? null,
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
#actorSql(ctx: ActorContextHandle): NapiSqlDatabase {
|
|
298
|
+
this.#sqlOpened.add(asNativeActorContext(ctx));
|
|
299
|
+
return this.#actorContextForOperation(ctx).sql();
|
|
181
300
|
}
|
|
182
301
|
|
|
183
302
|
createRegistry(): RegistryHandle {
|
|
303
|
+
this.#bindings.setTelemetryLogSink(
|
|
304
|
+
(event: {
|
|
305
|
+
name: string;
|
|
306
|
+
message: string;
|
|
307
|
+
level: "warn" | "error";
|
|
308
|
+
}) => {
|
|
309
|
+
const fields = { otelEvent: event.name };
|
|
310
|
+
const message = event.message || event.name;
|
|
311
|
+
if (event.level === "error") {
|
|
312
|
+
logger().error(fields, message);
|
|
313
|
+
} else {
|
|
314
|
+
logger().warn(fields, message);
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
);
|
|
184
318
|
return asRegistryHandle(new this.#bindings.CoreRegistry());
|
|
185
319
|
}
|
|
186
320
|
|
|
@@ -199,10 +333,18 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
199
333
|
await asNativeRegistry(registry).serve(config);
|
|
200
334
|
}
|
|
201
335
|
|
|
336
|
+
async waitRegistryReady(registry: RegistryHandle): Promise<void> {
|
|
337
|
+
await asNativeRegistry(registry).waitReady();
|
|
338
|
+
}
|
|
339
|
+
|
|
202
340
|
async shutdownRegistry(registry: RegistryHandle): Promise<void> {
|
|
203
341
|
await asNativeRegistry(registry).shutdown();
|
|
204
342
|
}
|
|
205
343
|
|
|
344
|
+
async shutdownTelemetry(): Promise<void> {
|
|
345
|
+
await this.#bindings.shutdownTelemetry();
|
|
346
|
+
}
|
|
347
|
+
|
|
206
348
|
async registryActorStopThresholdMs(
|
|
207
349
|
registry: RegistryHandle,
|
|
208
350
|
): Promise<number | undefined> {
|
|
@@ -265,6 +407,9 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
265
407
|
listener: RuntimeListenerConfig,
|
|
266
408
|
config: RuntimeServeConfig,
|
|
267
409
|
): Promise<void> {
|
|
410
|
+
const application = listener.application
|
|
411
|
+
? toNapiApplication(listener.application)
|
|
412
|
+
: undefined;
|
|
268
413
|
await asNativeRegistry(registry).serveListener(
|
|
269
414
|
{
|
|
270
415
|
port: listener.port,
|
|
@@ -272,6 +417,23 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
272
417
|
publicDir: listener.publicDir,
|
|
273
418
|
},
|
|
274
419
|
config,
|
|
420
|
+
application,
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
async serveApplicationListener(
|
|
425
|
+
registry: RegistryHandle,
|
|
426
|
+
listener: RuntimeApplicationListenerConfig,
|
|
427
|
+
config: RuntimeServeConfig,
|
|
428
|
+
): Promise<void> {
|
|
429
|
+
await asNativeRegistry(registry).serveApplicationListener(
|
|
430
|
+
{
|
|
431
|
+
port: listener.port,
|
|
432
|
+
host: listener.host,
|
|
433
|
+
publicDir: listener.publicDir,
|
|
434
|
+
},
|
|
435
|
+
toNapiApplication(listener.application),
|
|
436
|
+
config,
|
|
275
437
|
);
|
|
276
438
|
}
|
|
277
439
|
|
|
@@ -288,16 +450,24 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
288
450
|
return new this.#bindings.CancellationToken() as unknown as CancellationTokenHandle;
|
|
289
451
|
}
|
|
290
452
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
453
|
+
decodeInspectorRequest(
|
|
454
|
+
bytes: RuntimeBytes,
|
|
455
|
+
advertisedVersion: number,
|
|
456
|
+
): RuntimeBytes {
|
|
457
|
+
return this.#bindings.decodeInspectorRequest(
|
|
458
|
+
toNapiBuffer(bytes),
|
|
459
|
+
advertisedVersion,
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
encodeInspectorResponse(
|
|
464
|
+
bytes: RuntimeBytes,
|
|
465
|
+
targetVersion: number,
|
|
466
|
+
): RuntimeBytes {
|
|
467
|
+
return this.#bindings.encodeInspectorResponse(
|
|
468
|
+
toNapiBuffer(bytes),
|
|
469
|
+
targetVersion,
|
|
470
|
+
);
|
|
301
471
|
}
|
|
302
472
|
|
|
303
473
|
cancellationTokenAborted(token: CancellationTokenHandle): boolean {
|
|
@@ -311,8 +481,9 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
311
481
|
onCancellationTokenCancelled(
|
|
312
482
|
token: CancellationTokenHandle,
|
|
313
483
|
callback: (...args: unknown[]) => unknown,
|
|
314
|
-
): void {
|
|
315
|
-
asNativeCancellationToken(token).onCancelled(callback);
|
|
484
|
+
): () => void {
|
|
485
|
+
const listener = asNativeCancellationToken(token).onCancelled(callback);
|
|
486
|
+
return () => listener.release();
|
|
316
487
|
}
|
|
317
488
|
|
|
318
489
|
actorState(ctx: ActorContextHandle): Buffer {
|
|
@@ -334,6 +505,13 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
334
505
|
asNativeActorContext(ctx).setAlarm(timestampMs);
|
|
335
506
|
}
|
|
336
507
|
|
|
508
|
+
async actorSetRunWakeAt(
|
|
509
|
+
ctx: ActorContextHandle,
|
|
510
|
+
timestampMs?: number | undefined | null,
|
|
511
|
+
): Promise<void> {
|
|
512
|
+
await asNativeActorContext(ctx).setRunWakeAt(timestampMs);
|
|
513
|
+
}
|
|
514
|
+
|
|
337
515
|
actorRequestSave(
|
|
338
516
|
ctx: ActorContextHandle,
|
|
339
517
|
opts?: RuntimeRequestSaveOpts | undefined | null,
|
|
@@ -407,10 +585,90 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
407
585
|
);
|
|
408
586
|
}
|
|
409
587
|
|
|
588
|
+
async actorSaveStateAndWorkflowBatch(
|
|
589
|
+
ctx: ActorContextHandle,
|
|
590
|
+
writes: RuntimeWorkflowKvWrite[],
|
|
591
|
+
): Promise<void> {
|
|
592
|
+
await asNativeActorContext(ctx).saveStateAndWorkflowBatch(
|
|
593
|
+
writes.map((write) => ({
|
|
594
|
+
key: toNapiBuffer(write.key),
|
|
595
|
+
value: toNapiBuffer(write.value),
|
|
596
|
+
})),
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
|
|
410
600
|
actorId(ctx: ActorContextHandle): string {
|
|
411
601
|
return asNativeActorContext(ctx).actorId();
|
|
412
602
|
}
|
|
413
603
|
|
|
604
|
+
runWithActorInvocationContext<T>(ctx: ActorContextHandle, run: () => T): T {
|
|
605
|
+
return this.#runAs(asNativeActorContext(ctx), run);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
#runAs<T>(nativeCtx: NativeActorContext, run: () => T): T {
|
|
609
|
+
const span = nativeCtx.invocationTraceContext()?.span;
|
|
610
|
+
return this.#invocationContext.run(nativeCtx, () =>
|
|
611
|
+
runWithActorInvocationSpan(span, run),
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
actorInvocationTraceContext(
|
|
616
|
+
ctx: ActorContextHandle,
|
|
617
|
+
): ActorInvocationTraceContext | undefined {
|
|
618
|
+
return (
|
|
619
|
+
this.#actorContextForOperation(ctx).invocationTraceContext() ??
|
|
620
|
+
undefined
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
startCallSpan(
|
|
625
|
+
ctx: ActorContextHandle,
|
|
626
|
+
actorName: string,
|
|
627
|
+
actionName: string,
|
|
628
|
+
): RuntimeOutboundCall | undefined {
|
|
629
|
+
const call = this.#actorContextForOperation(ctx).startCallSpan(
|
|
630
|
+
actorName,
|
|
631
|
+
actionName,
|
|
632
|
+
);
|
|
633
|
+
if (!call) return undefined;
|
|
634
|
+
return {
|
|
635
|
+
span: call.spanContext() ?? undefined,
|
|
636
|
+
finish: (error?: string) => call.finish(error),
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
async startWorkflowSpan(ctx: ActorContextHandle): Promise<WorkflowSpan> {
|
|
641
|
+
const span = await asNativeActorContext(ctx).startWorkflowSpan();
|
|
642
|
+
const spanCtx = span.ctx();
|
|
643
|
+
return {
|
|
644
|
+
run: (body) => this.#runAs(spanCtx, body),
|
|
645
|
+
startStep: (name, attempt) => {
|
|
646
|
+
const step = spanCtx.startWorkflowStepSpan(name, attempt);
|
|
647
|
+
if (!step) return undefined;
|
|
648
|
+
const stepCtx = step.ctx();
|
|
649
|
+
return {
|
|
650
|
+
run: (body) => this.#runAs(stepCtx, body),
|
|
651
|
+
finish: (outcome, error) =>
|
|
652
|
+
step.finish(
|
|
653
|
+
outcome,
|
|
654
|
+
error === undefined
|
|
655
|
+
? undefined
|
|
656
|
+
: encodeErrorForBridge(error),
|
|
657
|
+
),
|
|
658
|
+
};
|
|
659
|
+
},
|
|
660
|
+
finish: (outcome) => span.finish(outcome),
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
runOutsideActorInvocationContext<T>(run: () => T): T {
|
|
665
|
+
return this.#invocationContext.exit(run);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
currentInvocationScope(): object | undefined {
|
|
669
|
+
return this.#invocationContext.getStore();
|
|
670
|
+
}
|
|
671
|
+
|
|
414
672
|
actorName(ctx: ActorContextHandle): string {
|
|
415
673
|
return asNativeActorContext(ctx).name();
|
|
416
674
|
}
|
|
@@ -459,7 +717,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
459
717
|
}
|
|
460
718
|
|
|
461
719
|
actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void {
|
|
462
|
-
|
|
720
|
+
this.#actorContextForOperation(ctx).waitUntil(promise);
|
|
463
721
|
}
|
|
464
722
|
|
|
465
723
|
async actorWaitForTrackedShutdownWork(
|
|
@@ -602,6 +860,13 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
602
860
|
return await this.#actorSql(ctx).exec(sql);
|
|
603
861
|
}
|
|
604
862
|
|
|
863
|
+
actorSqlExecSync(
|
|
864
|
+
ctx: ActorContextHandle,
|
|
865
|
+
sql: string,
|
|
866
|
+
): RuntimeSqlExecResult {
|
|
867
|
+
return this.#actorSql(ctx).execSync(sql);
|
|
868
|
+
}
|
|
869
|
+
|
|
605
870
|
async actorSqlExecute(
|
|
606
871
|
ctx: ActorContextHandle,
|
|
607
872
|
sql: string,
|
|
@@ -614,6 +879,145 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
614
879
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
615
880
|
}
|
|
616
881
|
|
|
882
|
+
actorSqlExecuteSync(
|
|
883
|
+
ctx: ActorContextHandle,
|
|
884
|
+
sql: string,
|
|
885
|
+
params?: RuntimeSqlBindParams,
|
|
886
|
+
): RuntimeSqlExecuteResult {
|
|
887
|
+
const result = this.#actorSql(ctx).executeSync(
|
|
888
|
+
sql,
|
|
889
|
+
toNapiSqlBindParams(params),
|
|
890
|
+
);
|
|
891
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
async actorSqlExecuteBatch(
|
|
895
|
+
ctx: ActorContextHandle,
|
|
896
|
+
statements: RuntimeSqlBatchStatement[],
|
|
897
|
+
): Promise<RuntimeSqlExecuteResult[]> {
|
|
898
|
+
const results = await this.#actorSql(ctx).executeBatch(
|
|
899
|
+
statements.map(toNapiSqlBatchStatement),
|
|
900
|
+
);
|
|
901
|
+
return results.map(normalizeRuntimeSqlExecuteResult);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
async actorSqlBeginTransaction(
|
|
905
|
+
ctx: ActorContextHandle,
|
|
906
|
+
timeoutMs?: number,
|
|
907
|
+
name?: string,
|
|
908
|
+
): Promise<SqliteTransactionHandle> {
|
|
909
|
+
return (await this.#actorSql(ctx).beginTransaction(
|
|
910
|
+
timeoutMs,
|
|
911
|
+
name,
|
|
912
|
+
)) as unknown as SqliteTransactionHandle;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
actorSqlBeginTransactionSync(
|
|
916
|
+
ctx: ActorContextHandle,
|
|
917
|
+
timeoutMs?: number,
|
|
918
|
+
name?: string,
|
|
919
|
+
): SqliteTransactionHandle {
|
|
920
|
+
return this.#actorSql(ctx).beginTransactionSync(
|
|
921
|
+
timeoutMs,
|
|
922
|
+
name,
|
|
923
|
+
) as unknown as SqliteTransactionHandle;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
async actorSqlTransactionExec(
|
|
927
|
+
transaction: SqliteTransactionHandle,
|
|
928
|
+
sql: string,
|
|
929
|
+
): Promise<RuntimeSqlExecResult> {
|
|
930
|
+
return await asNativeSqlTransaction(transaction).exec(sql);
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
actorSqlTransactionExecSync(
|
|
934
|
+
transaction: SqliteTransactionHandle,
|
|
935
|
+
sql: string,
|
|
936
|
+
): RuntimeSqlExecResult {
|
|
937
|
+
return asNativeSqlTransaction(transaction).execSync(sql);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
async actorSqlTransactionExecute(
|
|
941
|
+
transaction: SqliteTransactionHandle,
|
|
942
|
+
sql: string,
|
|
943
|
+
params?: RuntimeSqlBindParams,
|
|
944
|
+
): Promise<RuntimeSqlExecuteResult> {
|
|
945
|
+
const result = await asNativeSqlTransaction(transaction).execute(
|
|
946
|
+
sql,
|
|
947
|
+
toNapiSqlBindParams(params),
|
|
948
|
+
);
|
|
949
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
actorSqlTransactionExecuteSync(
|
|
953
|
+
transaction: SqliteTransactionHandle,
|
|
954
|
+
sql: string,
|
|
955
|
+
params?: RuntimeSqlBindParams,
|
|
956
|
+
): RuntimeSqlExecuteResult {
|
|
957
|
+
const result = asNativeSqlTransaction(transaction).executeSync(
|
|
958
|
+
sql,
|
|
959
|
+
toNapiSqlBindParams(params),
|
|
960
|
+
);
|
|
961
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
async actorSqlTransactionCommit(
|
|
965
|
+
transaction: SqliteTransactionHandle,
|
|
966
|
+
): Promise<void> {
|
|
967
|
+
await asNativeSqlTransaction(transaction).commit();
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
actorSqlTransactionCommitSync(transaction: SqliteTransactionHandle): void {
|
|
971
|
+
asNativeSqlTransaction(transaction).commitSync();
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
async actorSqlTransactionRollback(
|
|
975
|
+
transaction: SqliteTransactionHandle,
|
|
976
|
+
): Promise<void> {
|
|
977
|
+
await asNativeSqlTransaction(transaction).rollback();
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
actorSqlTransactionRollbackSync(
|
|
981
|
+
transaction: SqliteTransactionHandle,
|
|
982
|
+
): void {
|
|
983
|
+
asNativeSqlTransaction(transaction).rollbackSync();
|
|
984
|
+
}
|
|
985
|
+
async actorBeginStateTransaction(
|
|
986
|
+
ctx: ActorContextHandle,
|
|
987
|
+
timeoutMs?: number,
|
|
988
|
+
): Promise<ActorStateTransactionHandle> {
|
|
989
|
+
return (await this.#actorContextForOperation(ctx).beginStateTransaction(
|
|
990
|
+
timeoutMs,
|
|
991
|
+
)) as unknown as ActorStateTransactionHandle;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
async actorStateTransactionExecute(
|
|
995
|
+
transaction: ActorStateTransactionHandle,
|
|
996
|
+
sql: string,
|
|
997
|
+
params?: RuntimeSqlBindParams,
|
|
998
|
+
): Promise<RuntimeSqlExecuteResult> {
|
|
999
|
+
const result = await asNativeActorStateTransaction(transaction).execute(
|
|
1000
|
+
sql,
|
|
1001
|
+
toNapiSqlBindParams(params),
|
|
1002
|
+
);
|
|
1003
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
async actorStateTransactionCommit(
|
|
1007
|
+
transaction: ActorStateTransactionHandle,
|
|
1008
|
+
payload: RuntimeStateDeltaPayload,
|
|
1009
|
+
): Promise<void> {
|
|
1010
|
+
await asNativeActorStateTransaction(transaction).commit(
|
|
1011
|
+
toNapiStateDeltaPayload(payload),
|
|
1012
|
+
);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
async actorStateTransactionRollback(
|
|
1016
|
+
transaction: ActorStateTransactionHandle,
|
|
1017
|
+
): Promise<void> {
|
|
1018
|
+
await asNativeActorStateTransaction(transaction).rollback();
|
|
1019
|
+
}
|
|
1020
|
+
|
|
617
1021
|
async actorSqlQuery(
|
|
618
1022
|
ctx: ActorContextHandle,
|
|
619
1023
|
sql: string,
|
|
@@ -641,15 +1045,35 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
641
1045
|
return this.#actorSql(ctx).takeLastKvError?.() ?? null;
|
|
642
1046
|
}
|
|
643
1047
|
|
|
1048
|
+
async actorSqlOpen(ctx: ActorContextHandle): Promise<void> {
|
|
1049
|
+
await this.#actorSql(ctx).open();
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
actorSqlCommitTicket(ctx: ActorContextHandle): number {
|
|
1053
|
+
return this.#actorSql(ctx).commitTicket();
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
actorSqlAbortGeneration(ctx: ActorContextHandle, reason: string): void {
|
|
1057
|
+
this.#actorSql(ctx).abortGeneration(reason);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
async actorSqlWhenDurable(
|
|
1061
|
+
ctx: ActorContextHandle,
|
|
1062
|
+
ticket: number,
|
|
1063
|
+
): Promise<void> {
|
|
1064
|
+
await this.#actorSql(ctx).whenDurable(ticket);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
644
1067
|
async actorSqlClose(ctx: ActorContextHandle): Promise<void> {
|
|
645
1068
|
const nativeCtx = asNativeActorContext(ctx);
|
|
646
|
-
|
|
647
|
-
if (!database) {
|
|
1069
|
+
if (!this.#sqlOpened.delete(nativeCtx)) {
|
|
648
1070
|
return;
|
|
649
1071
|
}
|
|
1072
|
+
await nativeCtx.sql().close();
|
|
1073
|
+
}
|
|
650
1074
|
|
|
651
|
-
|
|
652
|
-
await
|
|
1075
|
+
async actorRuntimeSocketProvision(ctx: ActorContextHandle) {
|
|
1076
|
+
return await asNativeActorContext(ctx).provisionActorRuntimeSocket();
|
|
653
1077
|
}
|
|
654
1078
|
|
|
655
1079
|
async actorQueueSend(
|
|
@@ -658,7 +1082,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
658
1082
|
body: RuntimeBytes,
|
|
659
1083
|
): Promise<RuntimeQueueMessage> {
|
|
660
1084
|
return toNapiQueueMessage(
|
|
661
|
-
await
|
|
1085
|
+
await this.#actorContextForOperation(ctx)
|
|
662
1086
|
.queue()
|
|
663
1087
|
.send(name, toNapiBuffer(body)),
|
|
664
1088
|
);
|
|
@@ -669,7 +1093,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
669
1093
|
options?: RuntimeQueueNextBatchOptions | undefined | null,
|
|
670
1094
|
signal?: CancellationTokenHandle | undefined | null,
|
|
671
1095
|
): Promise<RuntimeQueueMessage[]> {
|
|
672
|
-
const messages = await
|
|
1096
|
+
const messages = await this.#actorContextForOperation(ctx)
|
|
673
1097
|
.queue()
|
|
674
1098
|
.nextBatch(
|
|
675
1099
|
options,
|
|
@@ -685,7 +1109,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
685
1109
|
signal?: CancellationTokenHandle | undefined | null,
|
|
686
1110
|
): Promise<RuntimeQueueMessage> {
|
|
687
1111
|
return toNapiQueueMessage(
|
|
688
|
-
await
|
|
1112
|
+
await this.#actorContextForOperation(ctx)
|
|
689
1113
|
.queue()
|
|
690
1114
|
.waitForNames(
|
|
691
1115
|
names,
|
|
@@ -710,6 +1134,21 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
710
1134
|
);
|
|
711
1135
|
}
|
|
712
1136
|
|
|
1137
|
+
async actorQueueCompletePersisted(
|
|
1138
|
+
ctx: ActorContextHandle,
|
|
1139
|
+
messageId: bigint,
|
|
1140
|
+
expectedName: string,
|
|
1141
|
+
response?: RuntimeBytes | undefined | null,
|
|
1142
|
+
): Promise<boolean> {
|
|
1143
|
+
return await asNativeActorContext(ctx)
|
|
1144
|
+
.queue()
|
|
1145
|
+
.completePersisted(
|
|
1146
|
+
messageId,
|
|
1147
|
+
expectedName,
|
|
1148
|
+
response == null ? response : toNapiBuffer(response),
|
|
1149
|
+
);
|
|
1150
|
+
}
|
|
1151
|
+
|
|
713
1152
|
async actorQueueEnqueueAndWait(
|
|
714
1153
|
ctx: ActorContextHandle,
|
|
715
1154
|
name: string,
|
|
@@ -717,7 +1156,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
717
1156
|
options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null,
|
|
718
1157
|
signal?: CancellationTokenHandle | undefined | null,
|
|
719
1158
|
): Promise<RuntimeBytes | null> {
|
|
720
|
-
return await
|
|
1159
|
+
return await this.#actorContextForOperation(ctx)
|
|
721
1160
|
.queue()
|
|
722
1161
|
.enqueueAndWait(
|
|
723
1162
|
name,
|
|
@@ -745,28 +1184,123 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
745
1184
|
return await asNativeActorContext(ctx).queue().inspectMessages();
|
|
746
1185
|
}
|
|
747
1186
|
|
|
748
|
-
|
|
1187
|
+
async actorQueueReset(ctx: ActorContextHandle): Promise<void> {
|
|
1188
|
+
await asNativeActorContext(ctx).queue().reset();
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
async actorScheduleAfter(
|
|
749
1192
|
ctx: ActorContextHandle,
|
|
750
1193
|
durationMs: number,
|
|
751
1194
|
actionName: string,
|
|
752
1195
|
args: RuntimeBytes,
|
|
753
|
-
):
|
|
754
|
-
|
|
1196
|
+
): Promise<string> {
|
|
1197
|
+
return await this.#actorContextForOperation(ctx)
|
|
755
1198
|
.schedule()
|
|
756
1199
|
.after(durationMs, actionName, toNapiBuffer(args));
|
|
757
1200
|
}
|
|
758
1201
|
|
|
759
|
-
actorScheduleAt(
|
|
1202
|
+
async actorScheduleAt(
|
|
760
1203
|
ctx: ActorContextHandle,
|
|
761
1204
|
timestampMs: number,
|
|
762
1205
|
actionName: string,
|
|
763
1206
|
args: RuntimeBytes,
|
|
764
|
-
):
|
|
765
|
-
|
|
1207
|
+
): Promise<string> {
|
|
1208
|
+
return await this.#actorContextForOperation(ctx)
|
|
766
1209
|
.schedule()
|
|
767
1210
|
.at(timestampMs, actionName, toNapiBuffer(args));
|
|
768
1211
|
}
|
|
769
1212
|
|
|
1213
|
+
async actorScheduleCancel(ctx: ActorContextHandle, id: string) {
|
|
1214
|
+
return await this.#actorContextForOperation(ctx).schedule().cancel(id);
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
async actorScheduleGet(
|
|
1218
|
+
ctx: ActorContextHandle,
|
|
1219
|
+
id: string,
|
|
1220
|
+
): Promise<RuntimeScheduledEventInfo | undefined> {
|
|
1221
|
+
return (
|
|
1222
|
+
(await this.#actorContextForOperation(ctx).schedule().get(id)) ??
|
|
1223
|
+
undefined
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
async actorScheduleList(ctx: ActorContextHandle) {
|
|
1228
|
+
return await this.#actorContextForOperation(ctx).schedule().list();
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
async actorCronSet(
|
|
1232
|
+
ctx: ActorContextHandle,
|
|
1233
|
+
name: string,
|
|
1234
|
+
expression: string,
|
|
1235
|
+
timezone: string | undefined,
|
|
1236
|
+
actionName: string,
|
|
1237
|
+
args: RuntimeBytes,
|
|
1238
|
+
maxHistory: number | undefined,
|
|
1239
|
+
) {
|
|
1240
|
+
await this.#actorContextForOperation(ctx)
|
|
1241
|
+
.schedule()
|
|
1242
|
+
.cronSet(
|
|
1243
|
+
name,
|
|
1244
|
+
expression,
|
|
1245
|
+
timezone,
|
|
1246
|
+
actionName,
|
|
1247
|
+
toNapiBuffer(args),
|
|
1248
|
+
maxHistory,
|
|
1249
|
+
);
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
async actorCronEvery(
|
|
1253
|
+
ctx: ActorContextHandle,
|
|
1254
|
+
name: string,
|
|
1255
|
+
intervalMs: number,
|
|
1256
|
+
actionName: string,
|
|
1257
|
+
args: RuntimeBytes,
|
|
1258
|
+
maxHistory: number | undefined,
|
|
1259
|
+
) {
|
|
1260
|
+
await this.#actorContextForOperation(ctx)
|
|
1261
|
+
.schedule()
|
|
1262
|
+
.cronEvery(
|
|
1263
|
+
name,
|
|
1264
|
+
intervalMs,
|
|
1265
|
+
actionName,
|
|
1266
|
+
toNapiBuffer(args),
|
|
1267
|
+
maxHistory,
|
|
1268
|
+
);
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
async actorCronGet(
|
|
1272
|
+
ctx: ActorContextHandle,
|
|
1273
|
+
name: string,
|
|
1274
|
+
): Promise<RuntimeCronJobInfo | undefined> {
|
|
1275
|
+
return ((await this.#actorContextForOperation(ctx)
|
|
1276
|
+
.schedule()
|
|
1277
|
+
.cronGet(name)) ?? undefined) as RuntimeCronJobInfo | undefined;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
async actorCronList(
|
|
1281
|
+
ctx: ActorContextHandle,
|
|
1282
|
+
): Promise<RuntimeCronJobInfo[]> {
|
|
1283
|
+
return (await this.#actorContextForOperation(ctx)
|
|
1284
|
+
.schedule()
|
|
1285
|
+
.cronList()) as RuntimeCronJobInfo[];
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
async actorCronDelete(ctx: ActorContextHandle, name: string) {
|
|
1289
|
+
return await this.#actorContextForOperation(ctx)
|
|
1290
|
+
.schedule()
|
|
1291
|
+
.cronDelete(name);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
async actorCronHistory(
|
|
1295
|
+
ctx: ActorContextHandle,
|
|
1296
|
+
name: string,
|
|
1297
|
+
limit: number | undefined,
|
|
1298
|
+
): Promise<RuntimeCronFire[]> {
|
|
1299
|
+
return (await this.#actorContextForOperation(ctx)
|
|
1300
|
+
.schedule()
|
|
1301
|
+
.cronHistory(name, limit)) as RuntimeCronFire[];
|
|
1302
|
+
}
|
|
1303
|
+
|
|
770
1304
|
connId(conn: ConnHandle): string {
|
|
771
1305
|
return asNativeConn(conn).id();
|
|
772
1306
|
}
|
|
@@ -828,9 +1362,19 @@ export async function loadNapiRuntime(): Promise<{
|
|
|
828
1362
|
bindings: NapiBindings;
|
|
829
1363
|
runtime: NapiCoreRuntime;
|
|
830
1364
|
}> {
|
|
831
|
-
|
|
1365
|
+
// LOAD-BEARING: the specifier is computed (`.join("/")`) on purpose. Do NOT
|
|
1366
|
+
// "simplify" it to a literal `import("@rivetkit/rivetkit-napi")`. Edge
|
|
1367
|
+
// adapters (e.g. @rivetkit/supabase) pre-bundle this module for Deno; a
|
|
1368
|
+
// literal dynamic import is statically resolvable, so Deno's eszip bundler
|
|
1369
|
+
// would snapshot the native `.node` addon into the deploy and 413. The
|
|
1370
|
+
// computed specifier keeps it opaque to static analysis so it is never
|
|
1371
|
+
// bundled. Enforced by scripts/ci/check-edge-native-closure.mjs.
|
|
1372
|
+
const [{ AsyncLocalStorage }, bindings] = await Promise.all([
|
|
1373
|
+
import("node:async_hooks"),
|
|
1374
|
+
import(["@rivetkit", "rivetkit-napi"].join("/")),
|
|
1375
|
+
]);
|
|
832
1376
|
return {
|
|
833
1377
|
bindings,
|
|
834
|
-
runtime: new NapiCoreRuntime(bindings),
|
|
1378
|
+
runtime: new NapiCoreRuntime(bindings, new AsyncLocalStorage()),
|
|
835
1379
|
};
|
|
836
1380
|
}
|