rivetkit 0.0.0-active-actors-fix-active-count.253e406 → 0.0.0-bisect-sync-sqlite-1.910d1c7
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 +1286 -89
- package/dist/browser/client.js +1699 -704
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +252 -129
- package/dist/browser/inspector/client.js +2083 -236
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +8 -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 +7 -1
- package/dist/tsup/agent-os/index.cjs +3 -2289
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +1 -1813
- package/dist/tsup/agent-os/index.d.ts +1 -1813
- package/dist/tsup/agent-os/index.js +3 -2289
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/chunk-2JJU7IQ7.cjs +14 -0
- package/dist/tsup/chunk-2JJU7IQ7.cjs.map +1 -0
- package/dist/tsup/{chunk-DZJZLZ4R.js → chunk-2MXBZGUP.js} +2 -2
- package/dist/tsup/{chunk-L4FVS7GY.js → chunk-47IS5ZFI.js} +6 -6
- package/dist/tsup/chunk-47IS5ZFI.js.map +1 -0
- package/dist/tsup/{chunk-DXWOGCZY.js → chunk-5XWY5CBA.js} +70 -8
- package/dist/tsup/chunk-5XWY5CBA.js.map +1 -0
- package/dist/tsup/{chunk-OQEEZDIK.cjs → chunk-6XVNZKKP.cjs} +506 -31
- package/dist/tsup/chunk-6XVNZKKP.cjs.map +1 -0
- package/dist/tsup/{chunk-3YY5S6TV.js → chunk-A2CF6PFH.js} +20 -12
- package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
- package/dist/tsup/{chunk-WQ4HNA4W.cjs → chunk-AQJFKHBK.cjs} +276 -27
- package/dist/tsup/chunk-AQJFKHBK.cjs.map +1 -0
- package/dist/tsup/chunk-DPWLASMC.cjs +244 -0
- package/dist/tsup/chunk-DPWLASMC.cjs.map +1 -0
- package/dist/tsup/{chunk-VUF2YEF4.cjs → chunk-DYJOU3MF.cjs} +10 -10
- package/dist/tsup/chunk-DYJOU3MF.cjs.map +1 -0
- package/dist/tsup/{chunk-7WXCRV25.cjs → chunk-ELZ6MT3V.cjs} +18 -11
- package/dist/tsup/chunk-ELZ6MT3V.cjs.map +1 -0
- package/dist/tsup/chunk-HYIVSH5X.js +244 -0
- package/dist/tsup/chunk-HYIVSH5X.js.map +1 -0
- package/dist/tsup/{chunk-T6YVRM4K.js → chunk-IHEO5OT3.js} +275 -26
- package/dist/tsup/chunk-IHEO5OT3.js.map +1 -0
- package/dist/tsup/chunk-IWACVNN5.js +14 -0
- package/dist/tsup/chunk-IWACVNN5.js.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JTHHCZCZ.js} +24 -1
- package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
- package/dist/tsup/{chunk-V4JUWAT6.js → chunk-K3AJOPSF.js} +498 -23
- package/dist/tsup/chunk-K3AJOPSF.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-KVFIONKQ.cjs} +25 -2
- package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-QAZLM4WT.cjs → chunk-MGI2VVF6.cjs} +45 -9
- package/dist/tsup/chunk-MGI2VVF6.cjs.map +1 -0
- package/dist/tsup/{chunk-QNLGOTQP.js → chunk-NPHTIUUJ.js} +1291 -420
- package/dist/tsup/chunk-NPHTIUUJ.js.map +1 -0
- package/dist/tsup/{chunk-7GKQJFSB.cjs → chunk-POCSZXPQ.cjs} +72 -10
- package/dist/tsup/chunk-POCSZXPQ.cjs.map +1 -0
- package/dist/tsup/{chunk-LD5YASJU.cjs → chunk-RTWH3AX3.cjs} +19 -11
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
- package/dist/tsup/{chunk-ARRBQTAR.cjs → chunk-X76BM5JS.cjs} +1420 -549
- package/dist/tsup/chunk-X76BM5JS.cjs.map +1 -0
- package/dist/tsup/{chunk-AGBP757I.js → chunk-X7SYKFPM.js} +16 -9
- package/dist/tsup/chunk-X7SYKFPM.js.map +1 -0
- package/dist/tsup/{chunk-GKAMEBTZ.cjs → chunk-XLDJSZ3B.cjs} +3 -3
- package/dist/tsup/{chunk-GKAMEBTZ.cjs.map → chunk-XLDJSZ3B.cjs.map} +1 -1
- package/dist/tsup/{chunk-KIWH5H3K.js → chunk-ZOVJDAOW.js} +44 -8
- package/dist/tsup/chunk-ZOVJDAOW.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 +33 -7
- package/dist/tsup/client/mod.d.ts +33 -7
- 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.js +3 -3
- package/dist/tsup/{config-nlTlOKaE.d.cts → config-BMGUEKMZ.d.cts} +1252 -75
- package/dist/tsup/config-CBTr4IhE.d.cts +224 -0
- package/dist/tsup/config-CBTr4IhE.d.ts +224 -0
- package/dist/tsup/{config-D7ykAntK.d.ts → config-iBpXyITj.d.ts} +1252 -75
- package/dist/tsup/context-hyVakgnU.d.ts +136 -0
- package/dist/tsup/context-qfvLuF0P.d.cts +136 -0
- 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 -124
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +12 -4
- package/dist/tsup/db/mod.d.ts +12 -4
- package/dist/tsup/db/mod.js +5 -123
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +24 -0
- package/dist/tsup/dynamic/mod.cjs.map +1 -0
- package/dist/tsup/dynamic/mod.d.cts +39 -0
- package/dist/tsup/dynamic/mod.d.ts +39 -0
- package/dist/tsup/dynamic/mod.js +24 -0
- package/dist/tsup/dynamic/mod.js.map +1 -0
- 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 +162 -0
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
- package/dist/tsup/inspector-tab/mod.d.cts +242 -0
- package/dist/tsup/inspector-tab/mod.d.ts +242 -0
- package/dist/tsup/inspector-tab/mod.js +162 -0
- package/dist/tsup/inspector-tab/mod.js.map +1 -0
- package/dist/tsup/mod.cjs +3527 -753
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +11 -7
- package/dist/tsup/mod.d.ts +11 -7
- package/dist/tsup/mod.js +3468 -694
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +26 -21
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +7 -5
- package/dist/tsup/test/mod.d.ts +7 -5
- package/dist/tsup/test/mod.js +25 -20
- 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-DVekpm4I.d.ts → utils-3rsE0JvI.d.cts} +26 -2
- package/dist/tsup/{utils-DVekpm4I.d.cts → utils-3rsE0JvI.d.ts} +26 -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 +557 -410
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +11 -9
- package/dist/tsup/workflow/mod.d.ts +11 -9
- package/dist/tsup/workflow/mod.js +551 -404
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +67 -18
- package/src/actor/actions.ts +155 -0
- package/src/actor/config.ts +679 -101
- package/src/actor/contexts/index.ts +9 -2
- package/src/actor/definition.ts +75 -26
- package/src/actor/errors.ts +107 -8
- package/src/actor/keys.ts +87 -1
- package/src/actor/mod.ts +36 -20
- package/src/actor/schema.ts +6 -2
- package/src/actor/tracing.ts +28 -0
- package/src/agent-os/index.ts +5 -64
- package/src/client/actor-common.ts +84 -54
- package/src/client/actor-conn.ts +231 -68
- package/src/client/actor-handle.ts +283 -89
- package/src/client/actor-query.ts +13 -6
- package/src/client/auth.ts +37 -0
- package/src/client/client.ts +182 -21
- package/src/client/config.ts +28 -3
- package/src/client/errors.ts +15 -2
- package/src/client/lifecycle-errors.ts +63 -5
- package/src/client/mod.ts +10 -0
- package/src/client/outbound-telemetry.ts +66 -0
- package/src/client/query.ts +3 -1
- package/src/client/queue.ts +13 -3
- package/src/client/raw-utils.ts +59 -14
- package/src/client/resolve-gateway-target.ts +3 -1
- package/src/client/retry-budget.ts +81 -0
- package/src/client/token-provider.ts +93 -0
- package/src/client/utils.ts +22 -9
- package/src/common/actor-router-consts.ts +6 -0
- package/src/common/actor-telemetry-context.ts +19 -0
- package/src/common/actor-websocket.ts +3 -1
- package/src/common/bare/actor-persist/v1.ts +205 -163
- package/src/common/bare/actor-persist/v2.ts +265 -213
- package/src/common/bare/actor-persist/v3.ts +176 -172
- package/src/common/bare/actor-persist/v4.ts +254 -253
- 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 +694 -542
- package/src/common/client-protocol-versioned.ts +66 -64
- package/src/common/database/config.ts +175 -9
- package/src/common/database/mod.ts +262 -77
- package/src/common/database/native-database.ts +442 -20
- package/src/common/database/shared.ts +25 -0
- package/src/common/encoding.ts +278 -34
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/fetch-like.ts +63 -0
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/inspector-transport.ts +12 -2
- package/src/common/log.ts +15 -8
- package/src/common/otel-context.ts +99 -0
- package/src/common/router.ts +14 -18
- package/src/common/utils.ts +8 -169
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/drizzle.ts +182 -80
- package/src/db/mod.ts +5 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +64 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-api/actors.ts +15 -3
- package/src/engine-client/actor-http-client.ts +37 -22
- package/src/engine-client/actor-websocket-client.ts +37 -9
- package/src/engine-client/api-endpoints.ts +128 -5
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +21 -16
- package/src/engine-client/mod.ts +280 -111
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/inspector/client.browser.ts +127 -15
- package/src/inspector/mod.ts +2 -4
- package/src/inspector/workflow.ts +61 -0
- package/src/inspector-tab/mod.ts +301 -0
- package/src/registry/config/envoy.ts +3 -20
- package/src/registry/config/index.ts +91 -74
- package/src/registry/index.ts +702 -80
- package/src/registry/napi-runtime.ts +643 -42
- package/src/registry/native-http.ts +225 -0
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +1881 -582
- package/src/registry/run-handler-coordinator.ts +219 -0
- package/src/registry/runtime.ts +441 -7
- package/src/registry/wasm-runtime.ts +516 -23
- package/src/registry/write-through-proxy.ts +141 -0
- package/src/serde.ts +2 -2
- package/src/serverless/configure.ts +18 -7
- package/src/test/mod.ts +2 -17
- package/src/test/ready.ts +22 -0
- package/src/unstable/migrations.ts +141 -0
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +50 -2
- package/src/utils/node.ts +44 -28
- package/src/utils/router.ts +1 -1
- package/src/utils.ts +4 -2
- package/src/workflow/context.ts +703 -242
- package/src/workflow/driver.ts +284 -125
- package/src/workflow/inspector.ts +24 -24
- package/src/workflow/mod.ts +76 -84
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3YY5S6TV.js.map +0 -1
- package/dist/tsup/chunk-6NT2LIFN.cjs +0 -268
- package/dist/tsup/chunk-6NT2LIFN.cjs.map +0 -1
- package/dist/tsup/chunk-7GKQJFSB.cjs.map +0 -1
- package/dist/tsup/chunk-7WXCRV25.cjs.map +0 -1
- package/dist/tsup/chunk-AGBP757I.js.map +0 -1
- package/dist/tsup/chunk-ARRBQTAR.cjs.map +0 -1
- package/dist/tsup/chunk-DXWOGCZY.js.map +0 -1
- package/dist/tsup/chunk-JGIPV3QU.js +0 -268
- package/dist/tsup/chunk-JGIPV3QU.js.map +0 -1
- package/dist/tsup/chunk-KIWH5H3K.js.map +0 -1
- package/dist/tsup/chunk-L4FVS7GY.js.map +0 -1
- package/dist/tsup/chunk-LD5YASJU.cjs.map +0 -1
- package/dist/tsup/chunk-OQEEZDIK.cjs.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-QAZLM4WT.cjs.map +0 -1
- package/dist/tsup/chunk-QNLGOTQP.js.map +0 -1
- package/dist/tsup/chunk-T6YVRM4K.js.map +0 -1
- package/dist/tsup/chunk-V4JUWAT6.js.map +0 -1
- package/dist/tsup/chunk-VUF2YEF4.cjs.map +0 -1
- package/dist/tsup/chunk-WQ4HNA4W.cjs.map +0 -1
- package/dist/tsup/config-CxjGYf4K.d.cts +0 -121
- package/dist/tsup/config-CxjGYf4K.d.ts +0 -121
- package/dist/tsup/context-88opQsfZ.d.cts +0 -92
- package/dist/tsup/context-CVEG5zfg.d.ts +0 -92
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2492
- 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 -265
- package/src/agent-os/actor/network.ts +0 -58
- package/src/agent-os/actor/preview.ts +0 -191
- 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 -2460
- package/src/registry/runtime.test.ts +0 -50
- package/src/utils/endpoint-parser.test.ts +0 -206
- package/src/utils/serve.ts +0 -217
- package/src/utils.test.ts +0 -34
- /package/dist/tsup/{chunk-DZJZLZ4R.js.map → chunk-2MXBZGUP.js.map} +0 -0
|
@@ -1,34 +1,54 @@
|
|
|
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,
|
|
37
|
+
RuntimeListenerConfig,
|
|
38
|
+
RuntimeOutboundCall,
|
|
21
39
|
RuntimeQueueEnqueueAndWaitOptions,
|
|
22
40
|
RuntimeQueueMessage,
|
|
23
41
|
RuntimeQueueNextBatchOptions,
|
|
24
42
|
RuntimeQueueTryNextBatchOptions,
|
|
25
43
|
RuntimeQueueWaitOptions,
|
|
26
|
-
RuntimeRequestSaveOpts,
|
|
27
44
|
RuntimeRegistryRouteResponse,
|
|
45
|
+
RuntimeRequestSaveOpts,
|
|
46
|
+
RuntimeScheduledEventInfo,
|
|
28
47
|
RuntimeServeConfig,
|
|
29
48
|
RuntimeServerlessRequest,
|
|
30
49
|
RuntimeServerlessResponseHead,
|
|
31
50
|
RuntimeServerlessStreamCallback,
|
|
51
|
+
RuntimeSqlBatchStatement,
|
|
32
52
|
RuntimeSqlBindParam,
|
|
33
53
|
RuntimeSqlBindParams,
|
|
34
54
|
RuntimeSqlExecResult,
|
|
@@ -37,6 +57,8 @@ import type {
|
|
|
37
57
|
RuntimeSqlRunResult,
|
|
38
58
|
RuntimeStateDeltaPayload,
|
|
39
59
|
RuntimeWebSocketEvent,
|
|
60
|
+
RuntimeWorkflowKvWrite,
|
|
61
|
+
SqliteTransactionHandle,
|
|
40
62
|
WebSocketHandle,
|
|
41
63
|
} from "./runtime";
|
|
42
64
|
import { normalizeRuntimeSqlExecuteResult } from "./runtime";
|
|
@@ -44,6 +66,18 @@ import { normalizeRuntimeSqlExecuteResult } from "./runtime";
|
|
|
44
66
|
type NativeBindings = typeof import("@rivetkit/rivetkit-napi");
|
|
45
67
|
type NapiSqlDatabase = ReturnType<NativeActorContext["sql"]>;
|
|
46
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
|
+
>;
|
|
47
81
|
|
|
48
82
|
function asNativeRegistry(handle: RegistryHandle): NativeCoreRegistry {
|
|
49
83
|
return handle as unknown as NativeCoreRegistry;
|
|
@@ -65,6 +99,17 @@ function asNativeWebSocket(handle: WebSocketHandle): NativeWebSocket {
|
|
|
65
99
|
return handle as unknown as NativeWebSocket;
|
|
66
100
|
}
|
|
67
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
|
+
|
|
68
113
|
function asNativeCancellationToken(
|
|
69
114
|
handle: CancellationTokenHandle,
|
|
70
115
|
): NativeCancellationToken {
|
|
@@ -103,10 +148,69 @@ function toNapiSqlBindParams(params?: RuntimeSqlBindParams): NapiSqlBindParams {
|
|
|
103
148
|
return params.map((param) => toNapiSqlBindParam(param));
|
|
104
149
|
}
|
|
105
150
|
|
|
151
|
+
function toNapiSqlBatchStatement(
|
|
152
|
+
statement: RuntimeSqlBatchStatement,
|
|
153
|
+
): NapiSqlBatchStatement {
|
|
154
|
+
return {
|
|
155
|
+
sql: statement.sql,
|
|
156
|
+
params: toNapiSqlBindParams(statement.params) ?? undefined,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
106
160
|
function toNapiBuffer(value: RuntimeBytes): Buffer {
|
|
107
161
|
return Buffer.from(value);
|
|
108
162
|
}
|
|
109
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
|
+
|
|
110
214
|
function toNapiHttpRequest(
|
|
111
215
|
request?: RuntimeHttpRequest | undefined | null,
|
|
112
216
|
): Parameters<NativeActorContext["connectConn"]>[1] {
|
|
@@ -142,7 +246,7 @@ function toNapiKvEntry(entry: RuntimeKvEntry): {
|
|
|
142
246
|
};
|
|
143
247
|
}
|
|
144
248
|
|
|
145
|
-
function toNapiQueueMessage(message:
|
|
249
|
+
function toNapiQueueMessage(message: NapiQueueMessage): RuntimeQueueMessage {
|
|
146
250
|
return {
|
|
147
251
|
id: () => message.id(),
|
|
148
252
|
name: () => message.name(),
|
|
@@ -163,23 +267,54 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
163
267
|
readonly kind = "napi";
|
|
164
268
|
|
|
165
269
|
#bindings: NativeBindings;
|
|
166
|
-
#
|
|
270
|
+
#sqlOpened = new WeakSet<NativeActorContext>();
|
|
271
|
+
#invocationContext: AsyncLocalStorage<NativeActorContext>;
|
|
167
272
|
|
|
168
|
-
constructor(
|
|
273
|
+
constructor(
|
|
274
|
+
bindings: NativeBindings,
|
|
275
|
+
invocationContext: AsyncLocalStorage<NativeActorContext>,
|
|
276
|
+
) {
|
|
169
277
|
this.#bindings = bindings;
|
|
278
|
+
this.#invocationContext = invocationContext;
|
|
170
279
|
}
|
|
171
280
|
|
|
172
|
-
#
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
if (!
|
|
176
|
-
|
|
177
|
-
|
|
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;
|
|
178
290
|
}
|
|
179
|
-
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();
|
|
180
300
|
}
|
|
181
301
|
|
|
182
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
|
+
);
|
|
183
318
|
return asRegistryHandle(new this.#bindings.CoreRegistry());
|
|
184
319
|
}
|
|
185
320
|
|
|
@@ -198,10 +333,42 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
198
333
|
await asNativeRegistry(registry).serve(config);
|
|
199
334
|
}
|
|
200
335
|
|
|
336
|
+
async waitRegistryReady(registry: RegistryHandle): Promise<void> {
|
|
337
|
+
await asNativeRegistry(registry).waitReady();
|
|
338
|
+
}
|
|
339
|
+
|
|
201
340
|
async shutdownRegistry(registry: RegistryHandle): Promise<void> {
|
|
202
341
|
await asNativeRegistry(registry).shutdown();
|
|
203
342
|
}
|
|
204
343
|
|
|
344
|
+
async shutdownTelemetry(): Promise<void> {
|
|
345
|
+
await this.#bindings.shutdownTelemetry();
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async registryActorStopThresholdMs(
|
|
349
|
+
registry: RegistryHandle,
|
|
350
|
+
): Promise<number | undefined> {
|
|
351
|
+
return (
|
|
352
|
+
(await asNativeRegistry(registry).actorStopThresholdMs()) ??
|
|
353
|
+
undefined
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
registryActiveActorCount(registry: RegistryHandle): number {
|
|
358
|
+
return asNativeRegistry(registry).activeActorCount();
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
onRegistryActiveActorCountChange(
|
|
362
|
+
registry: RegistryHandle,
|
|
363
|
+
callback: (count: number) => void,
|
|
364
|
+
cancelToken: CancellationTokenHandle,
|
|
365
|
+
): void {
|
|
366
|
+
asNativeRegistry(registry).onActiveActorCountChange(
|
|
367
|
+
callback,
|
|
368
|
+
asNativeCancellationToken(cancelToken),
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
205
372
|
async registryHealth(
|
|
206
373
|
registry: RegistryHandle,
|
|
207
374
|
): Promise<RuntimeRegistryRouteResponse> {
|
|
@@ -250,6 +417,41 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
250
417
|
);
|
|
251
418
|
}
|
|
252
419
|
|
|
420
|
+
async serveListener(
|
|
421
|
+
registry: RegistryHandle,
|
|
422
|
+
listener: RuntimeListenerConfig,
|
|
423
|
+
config: RuntimeServeConfig,
|
|
424
|
+
): Promise<void> {
|
|
425
|
+
const application = listener.application
|
|
426
|
+
? toNapiApplication(listener.application)
|
|
427
|
+
: undefined;
|
|
428
|
+
await asNativeRegistry(registry).serveListener(
|
|
429
|
+
{
|
|
430
|
+
port: listener.port,
|
|
431
|
+
host: listener.host,
|
|
432
|
+
publicDir: listener.publicDir,
|
|
433
|
+
},
|
|
434
|
+
config,
|
|
435
|
+
application,
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
async serveApplicationListener(
|
|
440
|
+
registry: RegistryHandle,
|
|
441
|
+
listener: RuntimeApplicationListenerConfig,
|
|
442
|
+
config: RuntimeServeConfig,
|
|
443
|
+
): Promise<void> {
|
|
444
|
+
await asNativeRegistry(registry).serveApplicationListener(
|
|
445
|
+
{
|
|
446
|
+
port: listener.port,
|
|
447
|
+
host: listener.host,
|
|
448
|
+
publicDir: listener.publicDir,
|
|
449
|
+
},
|
|
450
|
+
toNapiApplication(listener.application),
|
|
451
|
+
config,
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
|
|
253
455
|
createActorFactory(
|
|
254
456
|
callbacks: object,
|
|
255
457
|
config?: RuntimeActorConfig | undefined | null,
|
|
@@ -263,16 +465,24 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
263
465
|
return new this.#bindings.CancellationToken() as unknown as CancellationTokenHandle;
|
|
264
466
|
}
|
|
265
467
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
468
|
+
decodeInspectorRequest(
|
|
469
|
+
bytes: RuntimeBytes,
|
|
470
|
+
advertisedVersion: number,
|
|
471
|
+
): RuntimeBytes {
|
|
472
|
+
return this.#bindings.decodeInspectorRequest(
|
|
473
|
+
toNapiBuffer(bytes),
|
|
474
|
+
advertisedVersion,
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
encodeInspectorResponse(
|
|
479
|
+
bytes: RuntimeBytes,
|
|
480
|
+
targetVersion: number,
|
|
481
|
+
): RuntimeBytes {
|
|
482
|
+
return this.#bindings.encodeInspectorResponse(
|
|
483
|
+
toNapiBuffer(bytes),
|
|
484
|
+
targetVersion,
|
|
485
|
+
);
|
|
276
486
|
}
|
|
277
487
|
|
|
278
488
|
cancellationTokenAborted(token: CancellationTokenHandle): boolean {
|
|
@@ -286,8 +496,9 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
286
496
|
onCancellationTokenCancelled(
|
|
287
497
|
token: CancellationTokenHandle,
|
|
288
498
|
callback: (...args: unknown[]) => unknown,
|
|
289
|
-
): void {
|
|
290
|
-
asNativeCancellationToken(token).onCancelled(callback);
|
|
499
|
+
): () => void {
|
|
500
|
+
const listener = asNativeCancellationToken(token).onCancelled(callback);
|
|
501
|
+
return () => listener.release();
|
|
291
502
|
}
|
|
292
503
|
|
|
293
504
|
actorState(ctx: ActorContextHandle): Buffer {
|
|
@@ -309,6 +520,13 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
309
520
|
asNativeActorContext(ctx).setAlarm(timestampMs);
|
|
310
521
|
}
|
|
311
522
|
|
|
523
|
+
async actorSetRunWakeAt(
|
|
524
|
+
ctx: ActorContextHandle,
|
|
525
|
+
timestampMs?: number | undefined | null,
|
|
526
|
+
): Promise<void> {
|
|
527
|
+
await asNativeActorContext(ctx).setRunWakeAt(timestampMs);
|
|
528
|
+
}
|
|
529
|
+
|
|
312
530
|
actorRequestSave(
|
|
313
531
|
ctx: ActorContextHandle,
|
|
314
532
|
opts?: RuntimeRequestSaveOpts | undefined | null,
|
|
@@ -382,10 +600,90 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
382
600
|
);
|
|
383
601
|
}
|
|
384
602
|
|
|
603
|
+
async actorSaveStateAndWorkflowBatch(
|
|
604
|
+
ctx: ActorContextHandle,
|
|
605
|
+
writes: RuntimeWorkflowKvWrite[],
|
|
606
|
+
): Promise<void> {
|
|
607
|
+
await asNativeActorContext(ctx).saveStateAndWorkflowBatch(
|
|
608
|
+
writes.map((write) => ({
|
|
609
|
+
key: toNapiBuffer(write.key),
|
|
610
|
+
value: toNapiBuffer(write.value),
|
|
611
|
+
})),
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
|
|
385
615
|
actorId(ctx: ActorContextHandle): string {
|
|
386
616
|
return asNativeActorContext(ctx).actorId();
|
|
387
617
|
}
|
|
388
618
|
|
|
619
|
+
runWithActorInvocationContext<T>(ctx: ActorContextHandle, run: () => T): T {
|
|
620
|
+
return this.#runAs(asNativeActorContext(ctx), run);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
#runAs<T>(nativeCtx: NativeActorContext, run: () => T): T {
|
|
624
|
+
const span = nativeCtx.invocationTraceContext()?.span;
|
|
625
|
+
return this.#invocationContext.run(nativeCtx, () =>
|
|
626
|
+
runWithActorInvocationSpan(span, run),
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
actorInvocationTraceContext(
|
|
631
|
+
ctx: ActorContextHandle,
|
|
632
|
+
): ActorInvocationTraceContext | undefined {
|
|
633
|
+
return (
|
|
634
|
+
this.#actorContextForOperation(ctx).invocationTraceContext() ??
|
|
635
|
+
undefined
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
startCallSpan(
|
|
640
|
+
ctx: ActorContextHandle,
|
|
641
|
+
actorName: string,
|
|
642
|
+
actionName: string,
|
|
643
|
+
): RuntimeOutboundCall | undefined {
|
|
644
|
+
const call = this.#actorContextForOperation(ctx).startCallSpan(
|
|
645
|
+
actorName,
|
|
646
|
+
actionName,
|
|
647
|
+
);
|
|
648
|
+
if (!call) return undefined;
|
|
649
|
+
return {
|
|
650
|
+
span: call.spanContext() ?? undefined,
|
|
651
|
+
finish: (error?: string) => call.finish(error),
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
async startWorkflowSpan(ctx: ActorContextHandle): Promise<WorkflowSpan> {
|
|
656
|
+
const span = await asNativeActorContext(ctx).startWorkflowSpan();
|
|
657
|
+
const spanCtx = span.ctx();
|
|
658
|
+
return {
|
|
659
|
+
run: (body) => this.#runAs(spanCtx, body),
|
|
660
|
+
startStep: (name, attempt) => {
|
|
661
|
+
const step = spanCtx.startWorkflowStepSpan(name, attempt);
|
|
662
|
+
if (!step) return undefined;
|
|
663
|
+
const stepCtx = step.ctx();
|
|
664
|
+
return {
|
|
665
|
+
run: (body) => this.#runAs(stepCtx, body),
|
|
666
|
+
finish: (outcome, error) =>
|
|
667
|
+
step.finish(
|
|
668
|
+
outcome,
|
|
669
|
+
error === undefined
|
|
670
|
+
? undefined
|
|
671
|
+
: encodeErrorForBridge(error),
|
|
672
|
+
),
|
|
673
|
+
};
|
|
674
|
+
},
|
|
675
|
+
finish: (outcome) => span.finish(outcome),
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
runOutsideActorInvocationContext<T>(run: () => T): T {
|
|
680
|
+
return this.#invocationContext.exit(run);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
currentInvocationScope(): object | undefined {
|
|
684
|
+
return this.#invocationContext.getStore();
|
|
685
|
+
}
|
|
686
|
+
|
|
389
687
|
actorName(ctx: ActorContextHandle): string {
|
|
390
688
|
return asNativeActorContext(ctx).name();
|
|
391
689
|
}
|
|
@@ -394,10 +692,18 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
394
692
|
return asNativeActorContext(ctx).key();
|
|
395
693
|
}
|
|
396
694
|
|
|
695
|
+
actorForkChain(ctx: ActorContextHandle) {
|
|
696
|
+
return asNativeActorContext(ctx).forkChain();
|
|
697
|
+
}
|
|
698
|
+
|
|
397
699
|
actorRegion(ctx: ActorContextHandle): string {
|
|
398
700
|
return asNativeActorContext(ctx).region();
|
|
399
701
|
}
|
|
400
702
|
|
|
703
|
+
actorNamespace(ctx: ActorContextHandle): string {
|
|
704
|
+
return asNativeActorContext(ctx).namespace();
|
|
705
|
+
}
|
|
706
|
+
|
|
401
707
|
actorSleep(ctx: ActorContextHandle): void {
|
|
402
708
|
asNativeActorContext(ctx).sleep();
|
|
403
709
|
}
|
|
@@ -434,7 +740,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
434
740
|
}
|
|
435
741
|
|
|
436
742
|
actorWaitUntil(ctx: ActorContextHandle, promise: Promise<unknown>): void {
|
|
437
|
-
|
|
743
|
+
this.#actorContextForOperation(ctx).waitUntil(promise);
|
|
438
744
|
}
|
|
439
745
|
|
|
440
746
|
async actorWaitForTrackedShutdownWork(
|
|
@@ -443,6 +749,12 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
443
749
|
return await asNativeActorContext(ctx).waitForTrackedShutdownWork();
|
|
444
750
|
}
|
|
445
751
|
|
|
752
|
+
async actorWaitForTrackedShutdownWorkUnbounded(
|
|
753
|
+
ctx: ActorContextHandle,
|
|
754
|
+
): Promise<void> {
|
|
755
|
+
await asNativeActorContext(ctx).waitForTrackedShutdownWorkUnbounded();
|
|
756
|
+
}
|
|
757
|
+
|
|
446
758
|
actorKeepAwake(ctx: ActorContextHandle, promise: Promise<unknown>): void {
|
|
447
759
|
asNativeActorContext(ctx).keepAwake(promise);
|
|
448
760
|
}
|
|
@@ -571,6 +883,13 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
571
883
|
return await this.#actorSql(ctx).exec(sql);
|
|
572
884
|
}
|
|
573
885
|
|
|
886
|
+
actorSqlExecSync(
|
|
887
|
+
ctx: ActorContextHandle,
|
|
888
|
+
sql: string,
|
|
889
|
+
): RuntimeSqlExecResult {
|
|
890
|
+
return this.#actorSql(ctx).execSync(sql);
|
|
891
|
+
}
|
|
892
|
+
|
|
574
893
|
async actorSqlExecute(
|
|
575
894
|
ctx: ActorContextHandle,
|
|
576
895
|
sql: string,
|
|
@@ -583,6 +902,147 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
583
902
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
584
903
|
}
|
|
585
904
|
|
|
905
|
+
actorSqlExecuteSync(
|
|
906
|
+
ctx: ActorContextHandle,
|
|
907
|
+
sql: string,
|
|
908
|
+
params?: RuntimeSqlBindParams,
|
|
909
|
+
): RuntimeSqlExecuteResult {
|
|
910
|
+
const result = this.#actorSql(ctx).executeSync(
|
|
911
|
+
sql,
|
|
912
|
+
toNapiSqlBindParams(params),
|
|
913
|
+
);
|
|
914
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
async actorSqlExecuteBatch(
|
|
918
|
+
ctx: ActorContextHandle,
|
|
919
|
+
statements: RuntimeSqlBatchStatement[],
|
|
920
|
+
): Promise<RuntimeSqlExecuteResult[]> {
|
|
921
|
+
const results = await this.#actorSql(ctx).executeBatch(
|
|
922
|
+
statements.map(toNapiSqlBatchStatement),
|
|
923
|
+
);
|
|
924
|
+
return results.map(normalizeRuntimeSqlExecuteResult);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
async actorSqlBeginTransaction(
|
|
928
|
+
ctx: ActorContextHandle,
|
|
929
|
+
timeoutMs?: number,
|
|
930
|
+
name?: string,
|
|
931
|
+
): Promise<SqliteTransactionHandle> {
|
|
932
|
+
return (await this.#actorSql(ctx).beginTransaction(
|
|
933
|
+
timeoutMs,
|
|
934
|
+
name,
|
|
935
|
+
)) as unknown as SqliteTransactionHandle;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
actorSqlBeginTransactionSync(
|
|
939
|
+
ctx: ActorContextHandle,
|
|
940
|
+
timeoutMs?: number,
|
|
941
|
+
name?: string,
|
|
942
|
+
): SqliteTransactionHandle {
|
|
943
|
+
return this.#actorSql(ctx).beginTransactionSync(
|
|
944
|
+
timeoutMs,
|
|
945
|
+
name,
|
|
946
|
+
) as unknown as SqliteTransactionHandle;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
async actorSqlTransactionExec(
|
|
950
|
+
transaction: SqliteTransactionHandle,
|
|
951
|
+
sql: string,
|
|
952
|
+
): Promise<RuntimeSqlExecResult> {
|
|
953
|
+
return await asNativeSqlTransaction(transaction).exec(sql);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
actorSqlTransactionExecSync(
|
|
957
|
+
transaction: SqliteTransactionHandle,
|
|
958
|
+
sql: string,
|
|
959
|
+
): RuntimeSqlExecResult {
|
|
960
|
+
return asNativeSqlTransaction(transaction).execSync(sql);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
async actorSqlTransactionExecute(
|
|
964
|
+
transaction: SqliteTransactionHandle,
|
|
965
|
+
sql: string,
|
|
966
|
+
params?: RuntimeSqlBindParams,
|
|
967
|
+
): Promise<RuntimeSqlExecuteResult> {
|
|
968
|
+
const result = await asNativeSqlTransaction(transaction).execute(
|
|
969
|
+
sql,
|
|
970
|
+
toNapiSqlBindParams(params),
|
|
971
|
+
);
|
|
972
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
actorSqlTransactionExecuteSync(
|
|
976
|
+
transaction: SqliteTransactionHandle,
|
|
977
|
+
sql: string,
|
|
978
|
+
params?: RuntimeSqlBindParams,
|
|
979
|
+
): RuntimeSqlExecuteResult {
|
|
980
|
+
const result = asNativeSqlTransaction(transaction).executeSync(
|
|
981
|
+
sql,
|
|
982
|
+
toNapiSqlBindParams(params),
|
|
983
|
+
);
|
|
984
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
async actorSqlTransactionCommit(
|
|
988
|
+
transaction: SqliteTransactionHandle,
|
|
989
|
+
): Promise<void> {
|
|
990
|
+
await asNativeSqlTransaction(transaction).commit();
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
actorSqlTransactionCommitSync(transaction: SqliteTransactionHandle): void {
|
|
994
|
+
asNativeSqlTransaction(transaction).commitSync();
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
async actorSqlTransactionRollback(
|
|
998
|
+
transaction: SqliteTransactionHandle,
|
|
999
|
+
): Promise<void> {
|
|
1000
|
+
await asNativeSqlTransaction(transaction).rollback();
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
actorSqlTransactionRollbackSync(
|
|
1004
|
+
transaction: SqliteTransactionHandle,
|
|
1005
|
+
): void {
|
|
1006
|
+
asNativeSqlTransaction(transaction).rollbackSync();
|
|
1007
|
+
}
|
|
1008
|
+
async actorBeginStateTransaction(
|
|
1009
|
+
ctx: ActorContextHandle,
|
|
1010
|
+
timeoutMs?: number,
|
|
1011
|
+
name?: string,
|
|
1012
|
+
): Promise<ActorStateTransactionHandle> {
|
|
1013
|
+
return (await this.#actorContextForOperation(ctx).beginStateTransaction(
|
|
1014
|
+
timeoutMs,
|
|
1015
|
+
name,
|
|
1016
|
+
)) as unknown as ActorStateTransactionHandle;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
async actorStateTransactionExecute(
|
|
1020
|
+
transaction: ActorStateTransactionHandle,
|
|
1021
|
+
sql: string,
|
|
1022
|
+
params?: RuntimeSqlBindParams,
|
|
1023
|
+
): Promise<RuntimeSqlExecuteResult> {
|
|
1024
|
+
const result = await asNativeActorStateTransaction(transaction).execute(
|
|
1025
|
+
sql,
|
|
1026
|
+
toNapiSqlBindParams(params),
|
|
1027
|
+
);
|
|
1028
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
async actorStateTransactionCommit(
|
|
1032
|
+
transaction: ActorStateTransactionHandle,
|
|
1033
|
+
payload: RuntimeStateDeltaPayload,
|
|
1034
|
+
): Promise<void> {
|
|
1035
|
+
await asNativeActorStateTransaction(transaction).commit(
|
|
1036
|
+
toNapiStateDeltaPayload(payload),
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
async actorStateTransactionRollback(
|
|
1041
|
+
transaction: ActorStateTransactionHandle,
|
|
1042
|
+
): Promise<void> {
|
|
1043
|
+
await asNativeActorStateTransaction(transaction).rollback();
|
|
1044
|
+
}
|
|
1045
|
+
|
|
586
1046
|
async actorSqlQuery(
|
|
587
1047
|
ctx: ActorContextHandle,
|
|
588
1048
|
sql: string,
|
|
@@ -610,15 +1070,31 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
610
1070
|
return this.#actorSql(ctx).takeLastKvError?.() ?? null;
|
|
611
1071
|
}
|
|
612
1072
|
|
|
1073
|
+
async actorSqlOpen(ctx: ActorContextHandle): Promise<void> {
|
|
1074
|
+
await this.#actorSql(ctx).open();
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
actorSqlCommitTicket(ctx: ActorContextHandle): number {
|
|
1078
|
+
return this.#actorSql(ctx).commitTicket();
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
actorSqlAbortGeneration(ctx: ActorContextHandle, reason: string): void {
|
|
1082
|
+
this.#actorSql(ctx).abortGeneration(reason);
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
async actorSqlWhenDurable(
|
|
1086
|
+
ctx: ActorContextHandle,
|
|
1087
|
+
ticket: number,
|
|
1088
|
+
): Promise<void> {
|
|
1089
|
+
await this.#actorSql(ctx).whenDurable(ticket);
|
|
1090
|
+
}
|
|
1091
|
+
|
|
613
1092
|
async actorSqlClose(ctx: ActorContextHandle): Promise<void> {
|
|
614
1093
|
const nativeCtx = asNativeActorContext(ctx);
|
|
615
|
-
|
|
616
|
-
if (!database) {
|
|
1094
|
+
if (!this.#sqlOpened.delete(nativeCtx)) {
|
|
617
1095
|
return;
|
|
618
1096
|
}
|
|
619
|
-
|
|
620
|
-
this.#sql.delete(nativeCtx);
|
|
621
|
-
await database.close();
|
|
1097
|
+
await nativeCtx.sql().close();
|
|
622
1098
|
}
|
|
623
1099
|
|
|
624
1100
|
async actorQueueSend(
|
|
@@ -627,7 +1103,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
627
1103
|
body: RuntimeBytes,
|
|
628
1104
|
): Promise<RuntimeQueueMessage> {
|
|
629
1105
|
return toNapiQueueMessage(
|
|
630
|
-
await
|
|
1106
|
+
await this.#actorContextForOperation(ctx)
|
|
631
1107
|
.queue()
|
|
632
1108
|
.send(name, toNapiBuffer(body)),
|
|
633
1109
|
);
|
|
@@ -638,7 +1114,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
638
1114
|
options?: RuntimeQueueNextBatchOptions | undefined | null,
|
|
639
1115
|
signal?: CancellationTokenHandle | undefined | null,
|
|
640
1116
|
): Promise<RuntimeQueueMessage[]> {
|
|
641
|
-
const messages = await
|
|
1117
|
+
const messages = await this.#actorContextForOperation(ctx)
|
|
642
1118
|
.queue()
|
|
643
1119
|
.nextBatch(
|
|
644
1120
|
options,
|
|
@@ -654,7 +1130,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
654
1130
|
signal?: CancellationTokenHandle | undefined | null,
|
|
655
1131
|
): Promise<RuntimeQueueMessage> {
|
|
656
1132
|
return toNapiQueueMessage(
|
|
657
|
-
await
|
|
1133
|
+
await this.#actorContextForOperation(ctx)
|
|
658
1134
|
.queue()
|
|
659
1135
|
.waitForNames(
|
|
660
1136
|
names,
|
|
@@ -668,10 +1144,30 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
668
1144
|
ctx: ActorContextHandle,
|
|
669
1145
|
names: string[],
|
|
670
1146
|
options?: RuntimeQueueWaitOptions | undefined | null,
|
|
1147
|
+
signal?: CancellationTokenHandle | undefined | null,
|
|
671
1148
|
): Promise<void> {
|
|
672
1149
|
await asNativeActorContext(ctx)
|
|
673
1150
|
.queue()
|
|
674
|
-
.waitForNamesAvailable(
|
|
1151
|
+
.waitForNamesAvailable(
|
|
1152
|
+
names,
|
|
1153
|
+
options,
|
|
1154
|
+
signal ? asNativeCancellationToken(signal) : signal,
|
|
1155
|
+
);
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
async actorQueueCompletePersisted(
|
|
1159
|
+
ctx: ActorContextHandle,
|
|
1160
|
+
messageId: bigint,
|
|
1161
|
+
expectedName: string,
|
|
1162
|
+
response?: RuntimeBytes | undefined | null,
|
|
1163
|
+
): Promise<boolean> {
|
|
1164
|
+
return await asNativeActorContext(ctx)
|
|
1165
|
+
.queue()
|
|
1166
|
+
.completePersisted(
|
|
1167
|
+
messageId,
|
|
1168
|
+
expectedName,
|
|
1169
|
+
response == null ? response : toNapiBuffer(response),
|
|
1170
|
+
);
|
|
675
1171
|
}
|
|
676
1172
|
|
|
677
1173
|
async actorQueueEnqueueAndWait(
|
|
@@ -681,7 +1177,7 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
681
1177
|
options?: RuntimeQueueEnqueueAndWaitOptions | undefined | null,
|
|
682
1178
|
signal?: CancellationTokenHandle | undefined | null,
|
|
683
1179
|
): Promise<RuntimeBytes | null> {
|
|
684
|
-
return await
|
|
1180
|
+
return await this.#actorContextForOperation(ctx)
|
|
685
1181
|
.queue()
|
|
686
1182
|
.enqueueAndWait(
|
|
687
1183
|
name,
|
|
@@ -709,28 +1205,123 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
709
1205
|
return await asNativeActorContext(ctx).queue().inspectMessages();
|
|
710
1206
|
}
|
|
711
1207
|
|
|
712
|
-
|
|
1208
|
+
async actorQueueReset(ctx: ActorContextHandle): Promise<void> {
|
|
1209
|
+
await asNativeActorContext(ctx).queue().reset();
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
async actorScheduleAfter(
|
|
713
1213
|
ctx: ActorContextHandle,
|
|
714
1214
|
durationMs: number,
|
|
715
1215
|
actionName: string,
|
|
716
1216
|
args: RuntimeBytes,
|
|
717
|
-
):
|
|
718
|
-
|
|
1217
|
+
): Promise<string> {
|
|
1218
|
+
return await this.#actorContextForOperation(ctx)
|
|
719
1219
|
.schedule()
|
|
720
1220
|
.after(durationMs, actionName, toNapiBuffer(args));
|
|
721
1221
|
}
|
|
722
1222
|
|
|
723
|
-
actorScheduleAt(
|
|
1223
|
+
async actorScheduleAt(
|
|
724
1224
|
ctx: ActorContextHandle,
|
|
725
1225
|
timestampMs: number,
|
|
726
1226
|
actionName: string,
|
|
727
1227
|
args: RuntimeBytes,
|
|
728
|
-
):
|
|
729
|
-
|
|
1228
|
+
): Promise<string> {
|
|
1229
|
+
return await this.#actorContextForOperation(ctx)
|
|
730
1230
|
.schedule()
|
|
731
1231
|
.at(timestampMs, actionName, toNapiBuffer(args));
|
|
732
1232
|
}
|
|
733
1233
|
|
|
1234
|
+
async actorScheduleCancel(ctx: ActorContextHandle, id: string) {
|
|
1235
|
+
return await this.#actorContextForOperation(ctx).schedule().cancel(id);
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
async actorScheduleGet(
|
|
1239
|
+
ctx: ActorContextHandle,
|
|
1240
|
+
id: string,
|
|
1241
|
+
): Promise<RuntimeScheduledEventInfo | undefined> {
|
|
1242
|
+
return (
|
|
1243
|
+
(await this.#actorContextForOperation(ctx).schedule().get(id)) ??
|
|
1244
|
+
undefined
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
async actorScheduleList(ctx: ActorContextHandle) {
|
|
1249
|
+
return await this.#actorContextForOperation(ctx).schedule().list();
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
async actorCronSet(
|
|
1253
|
+
ctx: ActorContextHandle,
|
|
1254
|
+
name: string,
|
|
1255
|
+
expression: string,
|
|
1256
|
+
timezone: string | undefined,
|
|
1257
|
+
actionName: string,
|
|
1258
|
+
args: RuntimeBytes,
|
|
1259
|
+
maxHistory: number | undefined,
|
|
1260
|
+
) {
|
|
1261
|
+
await this.#actorContextForOperation(ctx)
|
|
1262
|
+
.schedule()
|
|
1263
|
+
.cronSet(
|
|
1264
|
+
name,
|
|
1265
|
+
expression,
|
|
1266
|
+
timezone,
|
|
1267
|
+
actionName,
|
|
1268
|
+
toNapiBuffer(args),
|
|
1269
|
+
maxHistory,
|
|
1270
|
+
);
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
async actorCronEvery(
|
|
1274
|
+
ctx: ActorContextHandle,
|
|
1275
|
+
name: string,
|
|
1276
|
+
intervalMs: number,
|
|
1277
|
+
actionName: string,
|
|
1278
|
+
args: RuntimeBytes,
|
|
1279
|
+
maxHistory: number | undefined,
|
|
1280
|
+
) {
|
|
1281
|
+
await this.#actorContextForOperation(ctx)
|
|
1282
|
+
.schedule()
|
|
1283
|
+
.cronEvery(
|
|
1284
|
+
name,
|
|
1285
|
+
intervalMs,
|
|
1286
|
+
actionName,
|
|
1287
|
+
toNapiBuffer(args),
|
|
1288
|
+
maxHistory,
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
async actorCronGet(
|
|
1293
|
+
ctx: ActorContextHandle,
|
|
1294
|
+
name: string,
|
|
1295
|
+
): Promise<RuntimeCronJobInfo | undefined> {
|
|
1296
|
+
return ((await this.#actorContextForOperation(ctx)
|
|
1297
|
+
.schedule()
|
|
1298
|
+
.cronGet(name)) ?? undefined) as RuntimeCronJobInfo | undefined;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
async actorCronList(
|
|
1302
|
+
ctx: ActorContextHandle,
|
|
1303
|
+
): Promise<RuntimeCronJobInfo[]> {
|
|
1304
|
+
return (await this.#actorContextForOperation(ctx)
|
|
1305
|
+
.schedule()
|
|
1306
|
+
.cronList()) as RuntimeCronJobInfo[];
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
async actorCronDelete(ctx: ActorContextHandle, name: string) {
|
|
1310
|
+
return await this.#actorContextForOperation(ctx)
|
|
1311
|
+
.schedule()
|
|
1312
|
+
.cronDelete(name);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
async actorCronHistory(
|
|
1316
|
+
ctx: ActorContextHandle,
|
|
1317
|
+
name: string,
|
|
1318
|
+
limit: number | undefined,
|
|
1319
|
+
): Promise<RuntimeCronFire[]> {
|
|
1320
|
+
return (await this.#actorContextForOperation(ctx)
|
|
1321
|
+
.schedule()
|
|
1322
|
+
.cronHistory(name, limit)) as RuntimeCronFire[];
|
|
1323
|
+
}
|
|
1324
|
+
|
|
734
1325
|
connId(conn: ConnHandle): string {
|
|
735
1326
|
return asNativeConn(conn).id();
|
|
736
1327
|
}
|
|
@@ -792,9 +1383,19 @@ export async function loadNapiRuntime(): Promise<{
|
|
|
792
1383
|
bindings: NapiBindings;
|
|
793
1384
|
runtime: NapiCoreRuntime;
|
|
794
1385
|
}> {
|
|
795
|
-
|
|
1386
|
+
// LOAD-BEARING: the specifier is computed (`.join("/")`) on purpose. Do NOT
|
|
1387
|
+
// "simplify" it to a literal `import("@rivetkit/rivetkit-napi")`. Edge
|
|
1388
|
+
// adapters pre-bundle this module for Deno; a
|
|
1389
|
+
// literal dynamic import is statically resolvable, so Deno's eszip bundler
|
|
1390
|
+
// would snapshot the native `.node` addon into the deploy and 413. The
|
|
1391
|
+
// computed specifier keeps it opaque to static analysis so it is never
|
|
1392
|
+
// bundled. Enforced by scripts/ci/check-edge-native-closure.mjs.
|
|
1393
|
+
const [{ AsyncLocalStorage }, bindings] = await Promise.all([
|
|
1394
|
+
import("node:async_hooks"),
|
|
1395
|
+
import(["@rivetkit", "rivetkit-napi"].join("/")),
|
|
1396
|
+
]);
|
|
796
1397
|
return {
|
|
797
1398
|
bindings,
|
|
798
|
-
runtime: new NapiCoreRuntime(bindings),
|
|
1399
|
+
runtime: new NapiCoreRuntime(bindings, new AsyncLocalStorage()),
|
|
799
1400
|
};
|
|
800
1401
|
}
|