rivetkit 0.0.0-sqlite-query-metrics-v2.f5d3605 → 0.0.0-sqlite-sync-3-0-1-release.95f6e2d
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 +99 -59
- package/dist/browser/client.js +228 -34
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +1 -2
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/{chunk-3URZ4UV5.js → chunk-2HWY7FZU.js} +2 -2
- package/dist/tsup/{chunk-PJ5EXY6F.js → chunk-62WFU3BQ.js} +223 -42
- package/dist/tsup/chunk-62WFU3BQ.js.map +1 -0
- package/dist/tsup/{chunk-JI6GZ2C2.js → chunk-A2CF6PFH.js} +18 -1
- package/dist/tsup/chunk-A2CF6PFH.js.map +1 -0
- package/dist/tsup/{chunk-KDT56V3Y.cjs → chunk-AQWZWR2P.cjs} +10 -11
- package/dist/tsup/chunk-AQWZWR2P.cjs.map +1 -0
- package/dist/tsup/{chunk-L3Z3W44Q.cjs → chunk-E4KDQJCR.cjs} +3 -3
- package/dist/tsup/{chunk-L3Z3W44Q.cjs.map → chunk-E4KDQJCR.cjs.map} +1 -1
- package/dist/tsup/{chunk-DHL2M2E2.cjs → chunk-E6HKVCPA.cjs} +3 -3
- package/dist/tsup/{chunk-DHL2M2E2.cjs.map → chunk-E6HKVCPA.cjs.map} +1 -1
- package/dist/tsup/{chunk-DDS7OOVF.cjs → chunk-EQBUH25O.cjs} +362 -181
- package/dist/tsup/chunk-EQBUH25O.cjs.map +1 -0
- package/dist/tsup/{chunk-USKGKQZM.js → chunk-HQHTTJW5.js} +10 -11
- package/dist/tsup/chunk-HQHTTJW5.js.map +1 -0
- package/dist/tsup/{chunk-JW2WPE6Z.cjs → chunk-M5SQGPRJ.cjs} +4 -4
- package/dist/tsup/{chunk-JW2WPE6Z.cjs.map → chunk-M5SQGPRJ.cjs.map} +1 -1
- package/dist/tsup/{chunk-FYDB45YU.cjs → chunk-MYWNJP55.cjs} +10 -10
- package/dist/tsup/{chunk-FYDB45YU.cjs.map → chunk-MYWNJP55.cjs.map} +1 -1
- package/dist/tsup/{chunk-F7IGTKGM.js → chunk-OWZ76NSH.js} +2 -2
- package/dist/tsup/{chunk-KSP3NXGY.js → chunk-QE5MTZHB.js} +3 -3
- package/dist/tsup/{chunk-D4G35VTO.js → chunk-QFZY2CK3.js} +4 -4
- package/dist/tsup/{chunk-E2CUROR3.js → chunk-QIIIRYN7.js} +2 -2
- package/dist/tsup/{chunk-MYWZCDML.cjs → chunk-RTWH3AX3.cjs} +19 -2
- package/dist/tsup/chunk-RTWH3AX3.cjs.map +1 -0
- package/dist/tsup/{chunk-HO76AEDH.cjs → chunk-UHMB5FFB.cjs} +3 -3
- package/dist/tsup/{chunk-HO76AEDH.cjs.map → chunk-UHMB5FFB.cjs.map} +1 -1
- package/dist/tsup/{chunk-QR6EAWEC.cjs → chunk-VKXEBB3Z.cjs} +7 -7
- package/dist/tsup/{chunk-QR6EAWEC.cjs.map → chunk-VKXEBB3Z.cjs.map} +1 -1
- package/dist/tsup/{chunk-EPRA2TCT.js → chunk-ZMVYZ7ZI.js} +2 -2
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.d.cts +15 -3
- package/dist/tsup/client/mod.d.ts +15 -3
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-Cw_BwH_G.d.ts → config-B4erdavw.d.ts} +58 -12
- package/dist/tsup/{config-D4clT6mq.d.ts → config-BfG1qpYz.d.cts} +34 -52
- package/dist/tsup/{config-D4clT6mq.d.cts → config-BfG1qpYz.d.ts} +34 -52
- package/dist/tsup/{config-CkmVg2fG.d.cts → config-DK144OAw.d.cts} +58 -12
- package/dist/tsup/{context-_xIcgBnE.d.cts → context-Cvnf3BRe.d.cts} +2 -2
- package/dist/tsup/{context-BYOKTQJi.d.ts → context-Oxi6YWcG.d.ts} +2 -2
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.d.cts +1 -1
- package/dist/tsup/db/drizzle.d.ts +1 -1
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +3 -3
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +2 -2
- package/dist/tsup/dynamic/mod.d.cts +2 -2
- package/dist/tsup/dynamic/mod.d.ts +2 -2
- package/dist/tsup/inspector/mod.cjs +5 -5
- package/dist/tsup/inspector/mod.js +4 -4
- package/dist/tsup/inspector/workflow.cjs +4 -4
- package/dist/tsup/inspector/workflow.js +3 -3
- package/dist/tsup/inspector-tab/mod.d.cts +3 -3
- package/dist/tsup/inspector-tab/mod.d.ts +3 -3
- package/dist/tsup/mod.cjs +553 -202
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +4 -4
- package/dist/tsup/mod.d.ts +4 -4
- package/dist/tsup/mod.js +467 -116
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +7 -7
- package/dist/tsup/test/mod.d.cts +2 -2
- package/dist/tsup/test/mod.d.ts +2 -2
- package/dist/tsup/test/mod.js +5 -5
- package/dist/tsup/unstable/migrations.d.cts +1 -1
- package/dist/tsup/unstable/migrations.d.ts +1 -1
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +22 -19
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +4 -4
- package/dist/tsup/workflow/mod.d.ts +4 -4
- package/dist/tsup/workflow/mod.js +10 -7
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +9 -10
- package/src/actor/keys.ts +86 -0
- package/src/client/actor-conn.ts +136 -24
- package/src/client/actor-handle.ts +21 -3
- package/src/client/client.ts +6 -0
- package/src/client/config.ts +12 -1
- package/src/client/lifecycle-errors.ts +35 -2
- package/src/client/retry-budget.ts +78 -0
- package/src/client/utils.ts +13 -2
- package/src/common/database/config.ts +46 -52
- package/src/common/database/native-database.ts +247 -27
- package/src/common/router.ts +1 -1
- package/src/db/mod.ts +0 -1
- package/src/engine-api/actors.ts +3 -3
- package/src/engine-client/actor-websocket-client.ts +4 -2
- package/src/engine-client/api-endpoints.ts +44 -14
- package/src/engine-client/mod.ts +2 -2
- package/src/registry/config/envoy.ts +1 -1
- package/src/registry/config/index.ts +29 -31
- package/src/registry/index.ts +66 -21
- package/src/registry/napi-runtime.ts +82 -3
- package/src/registry/native.ts +184 -52
- package/src/registry/runtime.ts +79 -10
- package/src/registry/wasm-runtime.ts +94 -3
- package/src/utils/env-vars.ts +15 -10
- package/src/workflow/driver.ts +5 -3
- package/dist/tsup/chunk-DDS7OOVF.cjs.map +0 -1
- package/dist/tsup/chunk-JI6GZ2C2.js.map +0 -1
- package/dist/tsup/chunk-KDT56V3Y.cjs.map +0 -1
- package/dist/tsup/chunk-MYWZCDML.cjs.map +0 -1
- package/dist/tsup/chunk-PJ5EXY6F.js.map +0 -1
- package/dist/tsup/chunk-USKGKQZM.js.map +0 -1
- package/src/actor/config.test.ts +0 -78
- package/src/actor/keys.test.ts +0 -275
- package/src/actor/utils.test.ts +0 -48
- package/src/client/test.ts +0 -44
- package/src/client/token-provider.test.ts +0 -86
- package/src/common/database/mod.test.ts +0 -364
- package/src/common/database/native-database.test.ts +0 -220
- package/src/common/inline-websocket-adapter.test.ts +0 -51
- package/src/db/drizzle.test.ts +0 -164
- package/src/registry/config/index.test.ts +0 -25
- package/src/registry/run-handler-coordinator.test.ts +0 -252
- package/src/registry/runtime.test.ts +0 -124
- package/src/unstable/migrations.test.ts +0 -170
- package/src/utils/endpoint-parser.test.ts +0 -206
- package/src/utils.test.ts +0 -34
- package/src/workflow/driver.test.ts +0 -62
- /package/dist/tsup/{chunk-3URZ4UV5.js.map → chunk-2HWY7FZU.js.map} +0 -0
- /package/dist/tsup/{chunk-F7IGTKGM.js.map → chunk-OWZ76NSH.js.map} +0 -0
- /package/dist/tsup/{chunk-KSP3NXGY.js.map → chunk-QE5MTZHB.js.map} +0 -0
- /package/dist/tsup/{chunk-D4G35VTO.js.map → chunk-QFZY2CK3.js.map} +0 -0
- /package/dist/tsup/{chunk-E2CUROR3.js.map → chunk-QIIIRYN7.js.map} +0 -0
- /package/dist/tsup/{chunk-EPRA2TCT.js.map → chunk-ZMVYZ7ZI.js.map} +0 -0
package/dist/tsup/mod.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
decodeWorkflowHistoryTransport
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2HWY7FZU.js";
|
|
4
4
|
import {
|
|
5
5
|
ACTOR_CONTEXT_INTERNAL_SYMBOL,
|
|
6
6
|
ActorConfigSchema,
|
|
@@ -35,18 +35,18 @@ import {
|
|
|
35
35
|
runWithActorInvocationSpan,
|
|
36
36
|
tryParseEndpoint,
|
|
37
37
|
updateRunnerConfig
|
|
38
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-62WFU3BQ.js";
|
|
39
39
|
import {
|
|
40
40
|
makePrefixedKey,
|
|
41
41
|
removePrefixFromKey
|
|
42
|
-
} from "./chunk-
|
|
43
|
-
import "./chunk-F7IGTKGM.js";
|
|
42
|
+
} from "./chunk-A2CF6PFH.js";
|
|
44
43
|
import {
|
|
45
44
|
bindNativeStateTransactionContext,
|
|
46
45
|
db,
|
|
47
46
|
registerNativeStateTransactionOpener
|
|
48
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-QIIIRYN7.js";
|
|
49
48
|
import "./chunk-JTHHCZCZ.js";
|
|
49
|
+
import "./chunk-OWZ76NSH.js";
|
|
50
50
|
import {
|
|
51
51
|
LogLevelSchema,
|
|
52
52
|
VERSION,
|
|
@@ -80,11 +80,12 @@ import {
|
|
|
80
80
|
parsePortEnv,
|
|
81
81
|
stringifyError,
|
|
82
82
|
toUint8Array
|
|
83
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-HQHTTJW5.js";
|
|
84
84
|
import {
|
|
85
85
|
INTERNAL_ERROR_CODE,
|
|
86
86
|
RivetError,
|
|
87
87
|
UserError,
|
|
88
|
+
actorStopping,
|
|
88
89
|
decodeBridgeRivetError,
|
|
89
90
|
encodeBridgeRivetError,
|
|
90
91
|
encodeErrorForBridge,
|
|
@@ -500,7 +501,7 @@ var EnvoyConfigSchema = z.object({
|
|
|
500
501
|
version: z.number().default(() => getRivetEnvoyVersion() ?? 1),
|
|
501
502
|
// Deprecated.
|
|
502
503
|
totalSlots: z.number().default(() => getRivetTotalSlots() ?? 1e5),
|
|
503
|
-
|
|
504
|
+
nodeKey: z.string().optional()
|
|
504
505
|
});
|
|
505
506
|
|
|
506
507
|
// src/registry/config/serverless.ts
|
|
@@ -644,7 +645,7 @@ var RegistryConfigSchema = z3.object({
|
|
|
644
645
|
// // (specifically Node.js) can sometimes only be specified after the router is
|
|
645
646
|
// // created or must be imported async using `await import(...)`
|
|
646
647
|
// getUpgradeWebSocket: z.custom<GetUpgradeWebSocket>().optional(),
|
|
647
|
-
// MARK:
|
|
648
|
+
// MARK: Node Configuration
|
|
648
649
|
/**
|
|
649
650
|
* Endpoint to connect to for Rivet Engine.
|
|
650
651
|
*
|
|
@@ -713,30 +714,30 @@ var RegistryConfigSchema = z3.object({
|
|
|
713
714
|
engineVersion: z3.string().optional().default(() => getRivetRunEngineVersion() ?? VERSION),
|
|
714
715
|
/**
|
|
715
716
|
* Starts the first-party Services actor host when RivetKit manages
|
|
716
|
-
* a local engine.
|
|
717
|
-
*
|
|
717
|
+
* a local engine. Disabled by default. Set RIVET_RUN_SERVICES=1
|
|
718
|
+
* or startServices: true to enable it.
|
|
718
719
|
*/
|
|
719
720
|
startServices: z3.boolean().optional(),
|
|
720
721
|
/**
|
|
721
722
|
* @experimental
|
|
722
723
|
*
|
|
723
|
-
* Automatically configure serverless
|
|
724
|
+
* Automatically configure serverless nodes in the engine.
|
|
724
725
|
*/
|
|
725
726
|
configurePool: ConfigurePoolSchema.optional(),
|
|
726
727
|
// MARK: Runtime-specific
|
|
727
728
|
serverless: ServerlessConfigSchema.optional().default(
|
|
728
729
|
() => ServerlessConfigSchema.parse({})
|
|
729
730
|
),
|
|
730
|
-
|
|
731
|
+
node: EnvoyConfigSchema.optional().default(
|
|
731
732
|
() => EnvoyConfigSchema.parse({})
|
|
732
733
|
),
|
|
733
734
|
// MARK: Shutdown
|
|
734
735
|
/**
|
|
735
736
|
* Graceful shutdown configuration for SIGINT/SIGTERM.
|
|
736
737
|
*
|
|
737
|
-
* When a persistent
|
|
738
|
+
* When a persistent node is running (Mode A, started via `registry.start()`),
|
|
738
739
|
* rivetkit installs Node SIGINT/SIGTERM handlers that call into core's
|
|
739
|
-
* `shutdown()` and wait up to `gracePeriodMs` for the
|
|
740
|
+
* `shutdown()` and wait up to `gracePeriodMs` for the node to drain
|
|
740
741
|
* before re-raising the signal to let Node exit via its default path.
|
|
741
742
|
*
|
|
742
743
|
* Handlers are NOT installed when `handler(request)` is used alone
|
|
@@ -748,9 +749,12 @@ var RegistryConfigSchema = z3.object({
|
|
|
748
749
|
/**
|
|
749
750
|
* Wait this many milliseconds for the serve promise to resolve
|
|
750
751
|
* after calling `CoreRegistry::shutdown()`. Defaults to the
|
|
751
|
-
* engine-provided actor stop threshold once the
|
|
752
|
+
* engine-provided actor stop threshold once the node connects. A
|
|
753
|
+
* signal-driven shutdown of a managed local development engine waits
|
|
754
|
+
* four seconds by default so actors can acknowledge stopping before
|
|
755
|
+
* a file watcher restarts the process.
|
|
752
756
|
*
|
|
753
|
-
*
|
|
757
|
+
* Set a longer period when a complete graceful node drain is required.
|
|
754
758
|
*/
|
|
755
759
|
gracePeriodMs: z3.number().int().min(1e3).optional(),
|
|
756
760
|
/**
|
|
@@ -786,10 +790,11 @@ var RegistryConfigSchema = z3.object({
|
|
|
786
790
|
message: "cannot specify both startEngine and endpoint"
|
|
787
791
|
});
|
|
788
792
|
}
|
|
789
|
-
if (config.configurePool
|
|
793
|
+
if (config.configurePool) {
|
|
790
794
|
ctx.addIssue({
|
|
791
795
|
code: "custom",
|
|
792
|
-
message: "
|
|
796
|
+
message: "serverless is disabled in this version",
|
|
797
|
+
path: ["configurePool"]
|
|
793
798
|
});
|
|
794
799
|
}
|
|
795
800
|
const localEngineEndpoint = buildEngineEndpoint(
|
|
@@ -797,7 +802,7 @@ var RegistryConfigSchema = z3.object({
|
|
|
797
802
|
config.enginePort
|
|
798
803
|
);
|
|
799
804
|
const endpoint = config.startEngine ? localEngineEndpoint : (parsedEndpoint == null ? void 0 : parsedEndpoint.endpoint) ?? (isDevEnv ? localEngineEndpoint : void 0);
|
|
800
|
-
const startServices = config.startServices ?? getRivetRunServices()
|
|
805
|
+
const startServices = config.startServices ?? getRivetRunServices();
|
|
801
806
|
const validateServerlessEndpoint = Boolean(
|
|
802
807
|
config.startEngine || parsedEndpoint
|
|
803
808
|
);
|
|
@@ -821,6 +826,7 @@ var RegistryConfigSchema = z3.object({
|
|
|
821
826
|
...config,
|
|
822
827
|
sqlite,
|
|
823
828
|
endpoint,
|
|
829
|
+
engineSpawn: !parsedEndpoint && Boolean(endpoint),
|
|
824
830
|
startServices,
|
|
825
831
|
namespace,
|
|
826
832
|
token,
|
|
@@ -850,8 +856,8 @@ function buildActorNames(config) {
|
|
|
850
856
|
);
|
|
851
857
|
}
|
|
852
858
|
var DocConfigurePoolSchema = z3.object({
|
|
853
|
-
name: z3.string().optional().describe("Name of the
|
|
854
|
-
url: z3.string().describe("URL of the serverless platform to configure
|
|
859
|
+
name: z3.string().optional().describe("Name of the node pool."),
|
|
860
|
+
url: z3.string().describe("URL of the serverless platform to configure nodes."),
|
|
855
861
|
headers: z3.record(z3.string(), z3.string()).optional().describe(
|
|
856
862
|
"Headers to include in requests to the serverless platform."
|
|
857
863
|
),
|
|
@@ -866,7 +872,7 @@ var DocConfigurePoolSchema = z3.object({
|
|
|
866
872
|
"Interval in milliseconds between metadata polls from the engine. Defaults to 10000 milliseconds (10 seconds)."
|
|
867
873
|
),
|
|
868
874
|
drainOnVersionUpgrade: z3.boolean().optional().describe(
|
|
869
|
-
"Drain
|
|
875
|
+
"Drain nodes when a new version is deployed. Defaults to true."
|
|
870
876
|
)
|
|
871
877
|
}).optional();
|
|
872
878
|
var DocServerlessConfigSchema = z3.object({
|
|
@@ -885,10 +891,10 @@ var DocServerlessConfigSchema = z3.object({
|
|
|
885
891
|
}).describe("Configuration for serverless deployment mode.");
|
|
886
892
|
var DocEnvoyConfigSchema = z3.object({
|
|
887
893
|
totalSlots: z3.number().optional().describe("Total number of actor slots available. Default: 100000"),
|
|
888
|
-
poolName: z3.string().optional().describe("Name of this
|
|
889
|
-
|
|
890
|
-
version: z3.number().optional().describe("Version number of this
|
|
891
|
-
}).describe("Configuration for
|
|
894
|
+
poolName: z3.string().optional().describe("Name of this node pool. Default: 'default'"),
|
|
895
|
+
nodeKey: z3.string().optional().describe("Deprecated. Authentication key for the node."),
|
|
896
|
+
version: z3.number().optional().describe("Version number of this node. Default: 1")
|
|
897
|
+
}).describe("Configuration for node mode.");
|
|
892
898
|
var DocSqliteConfigSchema = z3.object({
|
|
893
899
|
backend: SqliteBackendSchema.optional().describe(
|
|
894
900
|
"SQLite backend to use. Native defaults to local. Wasm defaults to remote and cannot use local."
|
|
@@ -936,19 +942,23 @@ var DocRegistryConfigSchema = z3.object({
|
|
|
936
942
|
"Version of the local engine package to use. Defaults to the current RivetKit version."
|
|
937
943
|
),
|
|
938
944
|
startServices: z3.boolean().optional().describe(
|
|
939
|
-
"Starts Services when RivetKit manages a local Engine.
|
|
945
|
+
"Starts Services when RivetKit manages a local Engine. Disabled by default. Set RIVET_RUN_SERVICES=1 or startServices: true to enable."
|
|
940
946
|
),
|
|
941
947
|
configurePool: DocConfigurePoolSchema.describe(
|
|
942
|
-
"Automatically configure serverless
|
|
948
|
+
"Automatically configure serverless nodes in the engine."
|
|
943
949
|
),
|
|
944
950
|
serverless: DocServerlessConfigSchema.optional(),
|
|
945
|
-
|
|
951
|
+
node: DocEnvoyConfigSchema.optional()
|
|
946
952
|
}).describe("RivetKit registry configuration.");
|
|
947
953
|
|
|
948
954
|
// src/registry/native.ts
|
|
949
955
|
import { VirtualWebSocket as VirtualWebSocket2 } from "@rivetkit/virtual-websocket";
|
|
950
956
|
|
|
951
957
|
// src/common/database/native-database.ts
|
|
958
|
+
function isSynchronousTransaction(transaction) {
|
|
959
|
+
const candidate = transaction;
|
|
960
|
+
return typeof candidate.commitSync === "function" && typeof candidate.rollbackSync === "function";
|
|
961
|
+
}
|
|
952
962
|
function shouldAttachNativeKvError(message) {
|
|
953
963
|
return /i\/o error|unable to open database file/i.test(message);
|
|
954
964
|
}
|
|
@@ -969,13 +979,16 @@ function toNativeBinding(arg) {
|
|
|
969
979
|
if (arg === null || arg === void 0) {
|
|
970
980
|
return { kind: "null" };
|
|
971
981
|
}
|
|
972
|
-
if (typeof arg === "bigint") {
|
|
973
|
-
|
|
982
|
+
if (typeof arg === "bigint" || typeof arg === "number" && Number.isInteger(arg)) {
|
|
983
|
+
const value = Number(arg);
|
|
984
|
+
if (!Number.isSafeInteger(value)) {
|
|
985
|
+
throw new RangeError(
|
|
986
|
+
"SQLite integer bindings must be within the JavaScript safe integer range."
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
return { kind: "int", intValue: value };
|
|
974
990
|
}
|
|
975
991
|
if (typeof arg === "number") {
|
|
976
|
-
if (Number.isInteger(arg)) {
|
|
977
|
-
return { kind: "int", intValue: arg };
|
|
978
|
-
}
|
|
979
992
|
return { kind: "float", floatValue: arg };
|
|
980
993
|
}
|
|
981
994
|
if (typeof arg === "string") {
|
|
@@ -992,9 +1005,10 @@ function toNativeBinding(arg) {
|
|
|
992
1005
|
function extractNamedSqliteParameters(sql) {
|
|
993
1006
|
const orderedNames = [];
|
|
994
1007
|
const seen = /* @__PURE__ */ new Set();
|
|
995
|
-
const pattern = /([:@$][A-Za-z_][
|
|
1008
|
+
const pattern = /'(?:''|[^'])*'|"(?:""|[^"])*"|`(?:``|[^`])*`|\[[^\]]*\]|--[^\n]*|\/\*[\s\S]*?(?:\*\/|$)|([:@$][\w$\u0080-\u{10FFFF}]+(?:::[\w$\u0080-\u{10FFFF}]+)*(?:\([^)]*\))?)|[A-Za-z_\u0080-\u{10FFFF}][\w$\u0080-\u{10FFFF}]*/gu;
|
|
996
1009
|
for (const match of sql.matchAll(pattern)) {
|
|
997
1010
|
const name = match[1];
|
|
1011
|
+
if (!name) continue;
|
|
998
1012
|
if (seen.has(name)) {
|
|
999
1013
|
continue;
|
|
1000
1014
|
}
|
|
@@ -1105,28 +1119,52 @@ var NativeCloseGate = class {
|
|
|
1105
1119
|
if (this.#active > 0) {
|
|
1106
1120
|
await new Promise((resolve) => this.#waiters.push(resolve));
|
|
1107
1121
|
}
|
|
1108
|
-
await callback();
|
|
1122
|
+
await (callback == null ? void 0 : callback());
|
|
1109
1123
|
}
|
|
1110
1124
|
};
|
|
1111
1125
|
function wrapJsNativeDatabase(database) {
|
|
1112
1126
|
const gate = new NativeCloseGate();
|
|
1113
|
-
let
|
|
1127
|
+
let terminalPromise;
|
|
1114
1128
|
let lastInsertRowId = null;
|
|
1115
1129
|
const executeNative = async (sql, params) => {
|
|
1116
|
-
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
1117
|
-
if (lastInsertRowIdColumn) {
|
|
1118
|
-
return {
|
|
1119
|
-
columns: [lastInsertRowIdColumn],
|
|
1120
|
-
rows: [[lastInsertRowId ?? 0]],
|
|
1121
|
-
changes: 0,
|
|
1122
|
-
lastInsertRowId
|
|
1123
|
-
};
|
|
1124
|
-
}
|
|
1125
1130
|
const release = gate.enter();
|
|
1126
1131
|
try {
|
|
1132
|
+
const lastInsertRowIdColumn = lastInsertRowIdColumnName(sql);
|
|
1133
|
+
if (lastInsertRowIdColumn) {
|
|
1134
|
+
return {
|
|
1135
|
+
columns: [lastInsertRowIdColumn],
|
|
1136
|
+
rows: [[lastInsertRowId ?? 0]],
|
|
1137
|
+
changes: 0,
|
|
1138
|
+
lastInsertRowId
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1127
1141
|
const nativeParams = toNativeBindings(sql, params);
|
|
1128
1142
|
const result = await database.execute(sql, nativeParams);
|
|
1129
|
-
if (result.lastInsertRowId
|
|
1143
|
+
if (result.lastInsertRowId != null) {
|
|
1144
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
1145
|
+
}
|
|
1146
|
+
return result;
|
|
1147
|
+
} catch (error) {
|
|
1148
|
+
enrichNativeDatabaseError(database, error);
|
|
1149
|
+
} finally {
|
|
1150
|
+
release();
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
const executeNativeSync = (sql, params) => {
|
|
1154
|
+
const release = gate.enter();
|
|
1155
|
+
try {
|
|
1156
|
+
const nativeParams = toNativeBindings(sql, params);
|
|
1157
|
+
const result = database.executeSync(sql, nativeParams);
|
|
1158
|
+
const rowIdColumn = lastInsertRowIdColumnName(sql);
|
|
1159
|
+
if (rowIdColumn) {
|
|
1160
|
+
return {
|
|
1161
|
+
columns: [rowIdColumn],
|
|
1162
|
+
rows: [[lastInsertRowId ?? 0]],
|
|
1163
|
+
changes: 0,
|
|
1164
|
+
lastInsertRowId
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
if (result.lastInsertRowId != null) {
|
|
1130
1168
|
lastInsertRowId = result.lastInsertRowId;
|
|
1131
1169
|
}
|
|
1132
1170
|
return result;
|
|
@@ -1154,9 +1192,28 @@ function wrapJsNativeDatabase(database) {
|
|
|
1154
1192
|
callback(row, result.columns);
|
|
1155
1193
|
}
|
|
1156
1194
|
},
|
|
1195
|
+
execSync(sql, callback) {
|
|
1196
|
+
const release = gate.enter();
|
|
1197
|
+
let result;
|
|
1198
|
+
try {
|
|
1199
|
+
result = database.execSync(sql);
|
|
1200
|
+
} catch (error) {
|
|
1201
|
+
enrichNativeDatabaseError(database, error);
|
|
1202
|
+
} finally {
|
|
1203
|
+
release();
|
|
1204
|
+
}
|
|
1205
|
+
if (callback) {
|
|
1206
|
+
for (const row of result.rows) {
|
|
1207
|
+
callback(row, result.columns);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
},
|
|
1157
1211
|
async execute(sql, params) {
|
|
1158
1212
|
return await executeNative(sql, params);
|
|
1159
1213
|
},
|
|
1214
|
+
executeSync(sql, params) {
|
|
1215
|
+
return executeNativeSync(sql, params);
|
|
1216
|
+
},
|
|
1160
1217
|
async executeBatch(statements) {
|
|
1161
1218
|
const nativeStatements = statements.map(toNativeBatchStatement);
|
|
1162
1219
|
const release = gate.enter();
|
|
@@ -1178,7 +1235,7 @@ function wrapJsNativeDatabase(database) {
|
|
|
1178
1235
|
return transactionResults;
|
|
1179
1236
|
})();
|
|
1180
1237
|
for (const result of results) {
|
|
1181
|
-
if (result.lastInsertRowId
|
|
1238
|
+
if (result.lastInsertRowId != null) {
|
|
1182
1239
|
lastInsertRowId = result.lastInsertRowId;
|
|
1183
1240
|
}
|
|
1184
1241
|
}
|
|
@@ -1206,7 +1263,23 @@ function wrapJsNativeDatabase(database) {
|
|
|
1206
1263
|
release();
|
|
1207
1264
|
}
|
|
1208
1265
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
1209
|
-
if (result.lastInsertRowId
|
|
1266
|
+
if (result.lastInsertRowId != null) {
|
|
1267
|
+
lastInsertRowId = result.lastInsertRowId;
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
},
|
|
1271
|
+
beginTransactionSync(timeoutMs, name) {
|
|
1272
|
+
const release = gate.enter();
|
|
1273
|
+
let transaction;
|
|
1274
|
+
try {
|
|
1275
|
+
transaction = database.beginTransactionSync(timeoutMs, name);
|
|
1276
|
+
} catch (error) {
|
|
1277
|
+
enrichNativeDatabaseError(database, error);
|
|
1278
|
+
} finally {
|
|
1279
|
+
release();
|
|
1280
|
+
}
|
|
1281
|
+
return wrapTransaction(database, transaction, gate, (result) => {
|
|
1282
|
+
if (result.lastInsertRowId != null) {
|
|
1210
1283
|
lastInsertRowId = result.lastInsertRowId;
|
|
1211
1284
|
}
|
|
1212
1285
|
});
|
|
@@ -1228,7 +1301,7 @@ function wrapJsNativeDatabase(database) {
|
|
|
1228
1301
|
release();
|
|
1229
1302
|
}
|
|
1230
1303
|
return wrapTransaction(database, transaction, gate, (result) => {
|
|
1231
|
-
if (result.lastInsertRowId
|
|
1304
|
+
if (result.lastInsertRowId != null) {
|
|
1232
1305
|
lastInsertRowId = result.lastInsertRowId;
|
|
1233
1306
|
}
|
|
1234
1307
|
});
|
|
@@ -1244,14 +1317,37 @@ function wrapJsNativeDatabase(database) {
|
|
|
1244
1317
|
var _a;
|
|
1245
1318
|
return normalizeNativeMetrics((_a = database.metrics) == null ? void 0 : _a.call(database));
|
|
1246
1319
|
},
|
|
1320
|
+
async open() {
|
|
1321
|
+
const release = gate.enter();
|
|
1322
|
+
try {
|
|
1323
|
+
await database.open();
|
|
1324
|
+
} catch (error) {
|
|
1325
|
+
enrichNativeDatabaseError(database, error);
|
|
1326
|
+
} finally {
|
|
1327
|
+
release();
|
|
1328
|
+
}
|
|
1329
|
+
},
|
|
1330
|
+
commitTicket() {
|
|
1331
|
+
return database.commitTicket();
|
|
1332
|
+
},
|
|
1333
|
+
async whenDurable(ticket) {
|
|
1334
|
+
await database.whenDurable(ticket);
|
|
1335
|
+
},
|
|
1336
|
+
abortGeneration(reason) {
|
|
1337
|
+
database.abortGeneration(reason);
|
|
1338
|
+
},
|
|
1247
1339
|
async close() {
|
|
1248
|
-
|
|
1249
|
-
await
|
|
1340
|
+
terminalPromise ??= gate.close(() => database.close());
|
|
1341
|
+
await terminalPromise;
|
|
1342
|
+
},
|
|
1343
|
+
async detachForShutdown() {
|
|
1344
|
+
terminalPromise ??= gate.close();
|
|
1345
|
+
await terminalPromise;
|
|
1250
1346
|
}
|
|
1251
1347
|
};
|
|
1252
1348
|
}
|
|
1253
1349
|
function wrapTransaction(database, transaction, gate, onExecute) {
|
|
1254
|
-
|
|
1350
|
+
const wrapped = {
|
|
1255
1351
|
async exec(sql, callback) {
|
|
1256
1352
|
const release = gate.enter();
|
|
1257
1353
|
let result;
|
|
@@ -1302,6 +1398,61 @@ function wrapTransaction(database, transaction, gate, onExecute) {
|
|
|
1302
1398
|
}
|
|
1303
1399
|
}
|
|
1304
1400
|
};
|
|
1401
|
+
if (isSynchronousTransaction(transaction)) {
|
|
1402
|
+
return Object.assign(wrapped, {
|
|
1403
|
+
execSync(sql, callback) {
|
|
1404
|
+
const release = gate.enter();
|
|
1405
|
+
let result;
|
|
1406
|
+
try {
|
|
1407
|
+
result = transaction.execSync(sql);
|
|
1408
|
+
} catch (error) {
|
|
1409
|
+
enrichNativeDatabaseError(database, error);
|
|
1410
|
+
} finally {
|
|
1411
|
+
release();
|
|
1412
|
+
}
|
|
1413
|
+
if (callback) {
|
|
1414
|
+
for (const row of result.rows)
|
|
1415
|
+
callback(row, result.columns);
|
|
1416
|
+
}
|
|
1417
|
+
},
|
|
1418
|
+
executeSync(sql, params) {
|
|
1419
|
+
const release = gate.enter();
|
|
1420
|
+
try {
|
|
1421
|
+
const result = transaction.executeSync(
|
|
1422
|
+
sql,
|
|
1423
|
+
toNativeBindings(sql, params)
|
|
1424
|
+
);
|
|
1425
|
+
onExecute(result);
|
|
1426
|
+
return result;
|
|
1427
|
+
} catch (error) {
|
|
1428
|
+
enrichNativeDatabaseError(database, error);
|
|
1429
|
+
} finally {
|
|
1430
|
+
release();
|
|
1431
|
+
}
|
|
1432
|
+
},
|
|
1433
|
+
commitSync() {
|
|
1434
|
+
const release = gate.enter();
|
|
1435
|
+
try {
|
|
1436
|
+
transaction.commitSync();
|
|
1437
|
+
} catch (error) {
|
|
1438
|
+
enrichNativeDatabaseError(database, error);
|
|
1439
|
+
} finally {
|
|
1440
|
+
release();
|
|
1441
|
+
}
|
|
1442
|
+
},
|
|
1443
|
+
rollbackSync() {
|
|
1444
|
+
const release = gate.enter();
|
|
1445
|
+
try {
|
|
1446
|
+
transaction.rollbackSync();
|
|
1447
|
+
} catch (error) {
|
|
1448
|
+
enrichNativeDatabaseError(database, error);
|
|
1449
|
+
} finally {
|
|
1450
|
+
release();
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
return wrapped;
|
|
1305
1456
|
}
|
|
1306
1457
|
function lastInsertRowIdColumnName(sql) {
|
|
1307
1458
|
const match = sql.match(
|
|
@@ -1392,6 +1543,12 @@ function getNodePath() {
|
|
|
1392
1543
|
function normalizeRuntimeSqlExecuteResult(result) {
|
|
1393
1544
|
return result;
|
|
1394
1545
|
}
|
|
1546
|
+
function servicesBinaryUnavailable(cause) {
|
|
1547
|
+
return new Error(
|
|
1548
|
+
"services.binary_unavailable: Install @rivet-dev/services yourself to run local Services, or set RIVET_SERVICES_BINARY to its executable path.",
|
|
1549
|
+
{ cause }
|
|
1550
|
+
);
|
|
1551
|
+
}
|
|
1395
1552
|
|
|
1396
1553
|
// src/registry/napi-runtime.ts
|
|
1397
1554
|
function asNativeRegistry(handle) {
|
|
@@ -1664,7 +1821,8 @@ var NapiCoreRuntime = class {
|
|
|
1664
1821
|
asNativeCancellationToken(token).cancel();
|
|
1665
1822
|
}
|
|
1666
1823
|
onCancellationTokenCancelled(token, callback) {
|
|
1667
|
-
asNativeCancellationToken(token).onCancelled(callback);
|
|
1824
|
+
const listener = asNativeCancellationToken(token).onCancelled(callback);
|
|
1825
|
+
return () => listener.release();
|
|
1668
1826
|
}
|
|
1669
1827
|
actorState(ctx) {
|
|
1670
1828
|
return asNativeActorContext(ctx).state();
|
|
@@ -1879,6 +2037,9 @@ var NapiCoreRuntime = class {
|
|
|
1879
2037
|
async actorSqlExec(ctx, sql) {
|
|
1880
2038
|
return await this.#actorSql(ctx).exec(sql);
|
|
1881
2039
|
}
|
|
2040
|
+
actorSqlExecSync(ctx, sql) {
|
|
2041
|
+
return this.#actorSql(ctx).execSync(sql);
|
|
2042
|
+
}
|
|
1882
2043
|
async actorSqlExecute(ctx, sql, params) {
|
|
1883
2044
|
const result = await this.#actorSql(ctx).execute(
|
|
1884
2045
|
sql,
|
|
@@ -1886,6 +2047,13 @@ var NapiCoreRuntime = class {
|
|
|
1886
2047
|
);
|
|
1887
2048
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
1888
2049
|
}
|
|
2050
|
+
actorSqlExecuteSync(ctx, sql, params) {
|
|
2051
|
+
const result = this.#actorSql(ctx).executeSync(
|
|
2052
|
+
sql,
|
|
2053
|
+
toNapiSqlBindParams(params)
|
|
2054
|
+
);
|
|
2055
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
2056
|
+
}
|
|
1889
2057
|
async actorSqlExecuteBatch(ctx, statements) {
|
|
1890
2058
|
const results = await this.#actorSql(ctx).executeBatch(
|
|
1891
2059
|
statements.map(toNapiSqlBatchStatement)
|
|
@@ -1898,9 +2066,18 @@ var NapiCoreRuntime = class {
|
|
|
1898
2066
|
name
|
|
1899
2067
|
);
|
|
1900
2068
|
}
|
|
2069
|
+
actorSqlBeginTransactionSync(ctx, timeoutMs, name) {
|
|
2070
|
+
return this.#actorSql(ctx).beginTransactionSync(
|
|
2071
|
+
timeoutMs,
|
|
2072
|
+
name
|
|
2073
|
+
);
|
|
2074
|
+
}
|
|
1901
2075
|
async actorSqlTransactionExec(transaction, sql) {
|
|
1902
2076
|
return await asNativeSqlTransaction(transaction).exec(sql);
|
|
1903
2077
|
}
|
|
2078
|
+
actorSqlTransactionExecSync(transaction, sql) {
|
|
2079
|
+
return asNativeSqlTransaction(transaction).execSync(sql);
|
|
2080
|
+
}
|
|
1904
2081
|
async actorSqlTransactionExecute(transaction, sql, params) {
|
|
1905
2082
|
const result = await asNativeSqlTransaction(transaction).execute(
|
|
1906
2083
|
sql,
|
|
@@ -1908,12 +2085,25 @@ var NapiCoreRuntime = class {
|
|
|
1908
2085
|
);
|
|
1909
2086
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
1910
2087
|
}
|
|
2088
|
+
actorSqlTransactionExecuteSync(transaction, sql, params) {
|
|
2089
|
+
const result = asNativeSqlTransaction(transaction).executeSync(
|
|
2090
|
+
sql,
|
|
2091
|
+
toNapiSqlBindParams(params)
|
|
2092
|
+
);
|
|
2093
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
2094
|
+
}
|
|
1911
2095
|
async actorSqlTransactionCommit(transaction) {
|
|
1912
2096
|
await asNativeSqlTransaction(transaction).commit();
|
|
1913
2097
|
}
|
|
2098
|
+
actorSqlTransactionCommitSync(transaction) {
|
|
2099
|
+
asNativeSqlTransaction(transaction).commitSync();
|
|
2100
|
+
}
|
|
1914
2101
|
async actorSqlTransactionRollback(transaction) {
|
|
1915
2102
|
await asNativeSqlTransaction(transaction).rollback();
|
|
1916
2103
|
}
|
|
2104
|
+
actorSqlTransactionRollbackSync(transaction) {
|
|
2105
|
+
asNativeSqlTransaction(transaction).rollbackSync();
|
|
2106
|
+
}
|
|
1917
2107
|
async actorBeginStateTransaction(ctx, timeoutMs) {
|
|
1918
2108
|
return await this.#actorContextForOperation(ctx).beginStateTransaction(
|
|
1919
2109
|
timeoutMs
|
|
@@ -1951,6 +2141,18 @@ var NapiCoreRuntime = class {
|
|
|
1951
2141
|
var _a, _b;
|
|
1952
2142
|
return ((_b = (_a = this.#actorSql(ctx)).takeLastKvError) == null ? void 0 : _b.call(_a)) ?? null;
|
|
1953
2143
|
}
|
|
2144
|
+
async actorSqlOpen(ctx) {
|
|
2145
|
+
await this.#actorSql(ctx).open();
|
|
2146
|
+
}
|
|
2147
|
+
actorSqlCommitTicket(ctx) {
|
|
2148
|
+
return this.#actorSql(ctx).commitTicket();
|
|
2149
|
+
}
|
|
2150
|
+
actorSqlAbortGeneration(ctx, reason) {
|
|
2151
|
+
this.#actorSql(ctx).abortGeneration(reason);
|
|
2152
|
+
}
|
|
2153
|
+
async actorSqlWhenDurable(ctx, ticket) {
|
|
2154
|
+
await this.#actorSql(ctx).whenDurable(ticket);
|
|
2155
|
+
}
|
|
1954
2156
|
async actorSqlClose(ctx) {
|
|
1955
2157
|
const nativeCtx = asNativeActorContext(ctx);
|
|
1956
2158
|
if (!this.#sqlOpened.delete(nativeCtx)) {
|
|
@@ -2534,6 +2736,17 @@ function optionalWasmNumber(value) {
|
|
|
2534
2736
|
function wasmNumber(value) {
|
|
2535
2737
|
return typeof value === "bigint" ? Number(value) : value;
|
|
2536
2738
|
}
|
|
2739
|
+
function synchronousSqliteUnavailable() {
|
|
2740
|
+
throw new RivetError(
|
|
2741
|
+
"sqlite",
|
|
2742
|
+
"sync_unsupported",
|
|
2743
|
+
"Synchronous SQLite is unavailable because the actor runs on the wasm runtime.",
|
|
2744
|
+
{
|
|
2745
|
+
public: true,
|
|
2746
|
+
metadata: { runtime: "wasm" }
|
|
2747
|
+
}
|
|
2748
|
+
);
|
|
2749
|
+
}
|
|
2537
2750
|
function normalizeKvEntry(entry) {
|
|
2538
2751
|
return {
|
|
2539
2752
|
key: toBytes(entry.key),
|
|
@@ -2685,6 +2898,14 @@ var WasmCoreRuntime = class {
|
|
|
2685
2898
|
);
|
|
2686
2899
|
}
|
|
2687
2900
|
createActorFactory(callbacks, config) {
|
|
2901
|
+
if (config == null ? void 0 : config.sqliteDeferredCommits) {
|
|
2902
|
+
throw new RivetError(
|
|
2903
|
+
"sqlite",
|
|
2904
|
+
"deferred_commits_unsupported",
|
|
2905
|
+
"SQLite deferred commits require local native SQLite, but the wasm runtime uses remote SQLite.",
|
|
2906
|
+
{ metadata: { runtime: "wasm" } }
|
|
2907
|
+
);
|
|
2908
|
+
}
|
|
2688
2909
|
return callWasmSync(
|
|
2689
2910
|
() => asActorFactoryHandle2(
|
|
2690
2911
|
new this.#constructors.ActorFactory(callbacks, config)
|
|
@@ -2703,9 +2924,10 @@ var WasmCoreRuntime = class {
|
|
|
2703
2924
|
callWasmSync(() => asWasmCancellationToken(token).cancel());
|
|
2704
2925
|
}
|
|
2705
2926
|
onCancellationTokenCancelled(token, callback) {
|
|
2706
|
-
callWasmSync(
|
|
2927
|
+
const listener = callWasmSync(
|
|
2707
2928
|
() => asWasmCancellationToken(token).onCancelled(callback)
|
|
2708
2929
|
);
|
|
2930
|
+
return () => callWasmSync(() => listener.release());
|
|
2709
2931
|
}
|
|
2710
2932
|
actorState(ctx) {
|
|
2711
2933
|
return toBytes(
|
|
@@ -2960,12 +3182,18 @@ var WasmCoreRuntime = class {
|
|
|
2960
3182
|
async actorSqlExec(ctx, sql) {
|
|
2961
3183
|
return await callWasm(() => this.#actorSql(ctx).exec(sql));
|
|
2962
3184
|
}
|
|
3185
|
+
actorSqlExecSync(_ctx, _sql) {
|
|
3186
|
+
return synchronousSqliteUnavailable();
|
|
3187
|
+
}
|
|
2963
3188
|
async actorSqlExecute(ctx, sql, params) {
|
|
2964
3189
|
const result = await callWasm(
|
|
2965
3190
|
() => this.#actorSql(ctx).execute(sql, params)
|
|
2966
3191
|
);
|
|
2967
3192
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
2968
3193
|
}
|
|
3194
|
+
actorSqlExecuteSync(_ctx, _sql, _params) {
|
|
3195
|
+
return synchronousSqliteUnavailable();
|
|
3196
|
+
}
|
|
2969
3197
|
async actorSqlExecuteBatch(ctx, statements) {
|
|
2970
3198
|
const results = await callWasm(
|
|
2971
3199
|
() => this.#actorSql(ctx).executeBatch(statements)
|
|
@@ -2977,27 +3205,42 @@ var WasmCoreRuntime = class {
|
|
|
2977
3205
|
() => this.#actorSql(ctx).beginTransaction(timeoutMs, name)
|
|
2978
3206
|
);
|
|
2979
3207
|
}
|
|
3208
|
+
actorSqlBeginTransactionSync(_ctx, _timeoutMs, _name) {
|
|
3209
|
+
return synchronousSqliteUnavailable();
|
|
3210
|
+
}
|
|
2980
3211
|
async actorSqlTransactionExec(transaction, sql) {
|
|
2981
3212
|
return await callWasm(
|
|
2982
3213
|
() => transaction.exec(sql)
|
|
2983
3214
|
);
|
|
2984
3215
|
}
|
|
3216
|
+
actorSqlTransactionExecSync(_transaction, _sql) {
|
|
3217
|
+
return synchronousSqliteUnavailable();
|
|
3218
|
+
}
|
|
2985
3219
|
async actorSqlTransactionExecute(transaction, sql, params) {
|
|
2986
3220
|
const result = await callWasm(
|
|
2987
3221
|
() => transaction.execute(sql, params)
|
|
2988
3222
|
);
|
|
2989
3223
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
2990
3224
|
}
|
|
3225
|
+
actorSqlTransactionExecuteSync(_transaction, _sql, _params) {
|
|
3226
|
+
return synchronousSqliteUnavailable();
|
|
3227
|
+
}
|
|
2991
3228
|
async actorSqlTransactionCommit(transaction) {
|
|
2992
3229
|
await callWasm(
|
|
2993
3230
|
() => transaction.commit()
|
|
2994
3231
|
);
|
|
2995
3232
|
}
|
|
3233
|
+
actorSqlTransactionCommitSync(_transaction) {
|
|
3234
|
+
synchronousSqliteUnavailable();
|
|
3235
|
+
}
|
|
2996
3236
|
async actorSqlTransactionRollback(transaction) {
|
|
2997
3237
|
await callWasm(
|
|
2998
3238
|
() => transaction.rollback()
|
|
2999
3239
|
);
|
|
3000
3240
|
}
|
|
3241
|
+
actorSqlTransactionRollbackSync(_transaction) {
|
|
3242
|
+
synchronousSqliteUnavailable();
|
|
3243
|
+
}
|
|
3001
3244
|
async actorBeginStateTransaction(ctx, timeoutMs) {
|
|
3002
3245
|
return await callWasm(
|
|
3003
3246
|
() => asWasmActorContext(ctx).beginStateTransaction(timeoutMs)
|
|
@@ -3033,6 +3276,17 @@ var WasmCoreRuntime = class {
|
|
|
3033
3276
|
var _a, _b;
|
|
3034
3277
|
return ((_b = (_a = this.#actorSql(ctx)).takeLastKvError) == null ? void 0 : _b.call(_a)) ?? null;
|
|
3035
3278
|
}
|
|
3279
|
+
async actorSqlOpen(_ctx) {
|
|
3280
|
+
}
|
|
3281
|
+
actorSqlCommitTicket(_ctx) {
|
|
3282
|
+
return synchronousSqliteUnavailable();
|
|
3283
|
+
}
|
|
3284
|
+
actorSqlAbortGeneration(_ctx, _reason) {
|
|
3285
|
+
synchronousSqliteUnavailable();
|
|
3286
|
+
}
|
|
3287
|
+
async actorSqlWhenDurable(_ctx, _ticket) {
|
|
3288
|
+
synchronousSqliteUnavailable();
|
|
3289
|
+
}
|
|
3036
3290
|
async actorSqlClose(ctx) {
|
|
3037
3291
|
const wasmCtx = asWasmActorContext(ctx);
|
|
3038
3292
|
const database = this.#sql.get(wasmCtx);
|
|
@@ -3498,9 +3752,10 @@ function normalizeRuntimeConfig(config, runtime) {
|
|
|
3498
3752
|
return normalizeRuntimeConfigForKind(config, loadedRuntimeKind(runtime));
|
|
3499
3753
|
}
|
|
3500
3754
|
function getNativeRuntimeState(runtime, ctx) {
|
|
3501
|
-
const runtimeState =
|
|
3502
|
-
|
|
3503
|
-
|
|
3755
|
+
const runtimeState = readNativeRuntimeStateBag(runtime, ctx);
|
|
3756
|
+
if (runtimeState.cleared) {
|
|
3757
|
+
throw actorStopping(callNativeSync(() => runtime.actorId(ctx)));
|
|
3758
|
+
}
|
|
3504
3759
|
if (!runtimeState.destroyGate) {
|
|
3505
3760
|
runtimeState.destroyGate = {};
|
|
3506
3761
|
}
|
|
@@ -3513,6 +3768,14 @@ function getNativeRuntimeState(runtime, ctx) {
|
|
|
3513
3768
|
}
|
|
3514
3769
|
return runtimeState;
|
|
3515
3770
|
}
|
|
3771
|
+
function readNativeRuntimeStateBag(runtime, ctx) {
|
|
3772
|
+
return callNativeSync(
|
|
3773
|
+
() => runtime.actorRuntimeState(ctx)
|
|
3774
|
+
);
|
|
3775
|
+
}
|
|
3776
|
+
function isNativeRuntimeStateCleared(runtime, ctx) {
|
|
3777
|
+
return readNativeRuntimeStateBag(runtime, ctx).cleared === true;
|
|
3778
|
+
}
|
|
3516
3779
|
function getNativePersistState(runtime, ctx) {
|
|
3517
3780
|
const persistState = getNativeRuntimeState(runtime, ctx).persistState;
|
|
3518
3781
|
if (!persistState) {
|
|
@@ -3623,13 +3886,18 @@ function resolveNativeDestroy(runtime, ctx) {
|
|
|
3623
3886
|
gate.destroyCompletion = void 0;
|
|
3624
3887
|
}
|
|
3625
3888
|
function clearNativeRuntimeState(runtime, ctx) {
|
|
3889
|
+
var _a;
|
|
3890
|
+
const pendingSaveHandle = (_a = readNativeRuntimeStateBag(runtime, ctx).persistState) == null ? void 0 : _a.pendingSaveHandle;
|
|
3891
|
+
if (pendingSaveHandle !== void 0) {
|
|
3892
|
+
clearImmediate(pendingSaveHandle);
|
|
3893
|
+
}
|
|
3626
3894
|
callNativeSync(() => runtime.actorClearRuntimeState(ctx));
|
|
3895
|
+
readNativeRuntimeStateBag(runtime, ctx).cleared = true;
|
|
3627
3896
|
}
|
|
3628
3897
|
async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrained) {
|
|
3629
3898
|
const drained = await runtime.actorWaitForTrackedShutdownWork(ctx);
|
|
3630
3899
|
if (!drained) {
|
|
3631
|
-
await
|
|
3632
|
-
await closeNativeSqlDatabase(runtime, ctx);
|
|
3900
|
+
await detachNativeDatabaseForShutdown(runtime, ctx);
|
|
3633
3901
|
void runtime.actorWaitForTrackedShutdownWorkUnbounded(ctx).then(async () => {
|
|
3634
3902
|
await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
|
|
3635
3903
|
clearNativeRuntimeState(runtime, ctx);
|
|
@@ -3642,10 +3910,19 @@ async function cleanupNativeSleepRuntimeState(runtime, ctx, afterTrackedWorkDrai
|
|
|
3642
3910
|
return;
|
|
3643
3911
|
}
|
|
3644
3912
|
await (afterTrackedWorkDrained == null ? void 0 : afterTrackedWorkDrained());
|
|
3645
|
-
await
|
|
3646
|
-
await closeNativeSqlDatabase(runtime, ctx);
|
|
3913
|
+
await detachNativeDatabaseForShutdown(runtime, ctx);
|
|
3647
3914
|
clearNativeRuntimeState(runtime, ctx);
|
|
3648
3915
|
}
|
|
3916
|
+
async function detachNativeDatabaseForShutdown(runtime, ctx) {
|
|
3917
|
+
var _a;
|
|
3918
|
+
const runtimeState = getNativeRuntimeState(runtime, ctx);
|
|
3919
|
+
await ((_a = runtimeState.sql) == null ? void 0 : _a.detachForShutdown());
|
|
3920
|
+
try {
|
|
3921
|
+
await closeNativeDatabaseClient(runtime, ctx);
|
|
3922
|
+
} finally {
|
|
3923
|
+
runtimeState.sql = void 0;
|
|
3924
|
+
}
|
|
3925
|
+
}
|
|
3649
3926
|
function closeNativeSqlDatabase(runtime, ctx) {
|
|
3650
3927
|
const runtimeState = getNativeRuntimeState(runtime, ctx);
|
|
3651
3928
|
const database = runtimeState.sql;
|
|
@@ -3666,15 +3943,29 @@ async function closeNativeDatabaseClient(runtime, ctx) {
|
|
|
3666
3943
|
await entry.client.close();
|
|
3667
3944
|
}
|
|
3668
3945
|
}
|
|
3946
|
+
function createNativeSqlTransaction(runtime, transaction) {
|
|
3947
|
+
return {
|
|
3948
|
+
exec: (sql) => runtime.actorSqlTransactionExec(transaction, sql),
|
|
3949
|
+
execSync: (sql) => runtime.actorSqlTransactionExecSync(transaction, sql),
|
|
3950
|
+
execute: (sql, params) => runtime.actorSqlTransactionExecute(transaction, sql, params),
|
|
3951
|
+
executeSync: (sql, params) => runtime.actorSqlTransactionExecuteSync(transaction, sql, params),
|
|
3952
|
+
commit: () => runtime.actorSqlTransactionCommit(transaction),
|
|
3953
|
+
commitSync: () => runtime.actorSqlTransactionCommitSync(transaction),
|
|
3954
|
+
rollback: () => runtime.actorSqlTransactionRollback(transaction),
|
|
3955
|
+
rollbackSync: () => runtime.actorSqlTransactionRollbackSync(transaction)
|
|
3956
|
+
};
|
|
3957
|
+
}
|
|
3669
3958
|
function getOrCreateNativeSqlDatabase(runtime, ctx) {
|
|
3670
3959
|
const runtimeState = getNativeRuntimeState(runtime, ctx);
|
|
3671
3960
|
const cachedDatabase = runtimeState.sql;
|
|
3672
3961
|
if (cachedDatabase) {
|
|
3673
3962
|
return cachedDatabase;
|
|
3674
3963
|
}
|
|
3675
|
-
const
|
|
3964
|
+
const bindings = {
|
|
3676
3965
|
exec: (sql) => runtime.actorSqlExec(ctx, sql),
|
|
3966
|
+
execSync: (sql) => runtime.actorSqlExecSync(ctx, sql),
|
|
3677
3967
|
execute: (sql, params) => runtime.actorSqlExecute(ctx, sql, params),
|
|
3968
|
+
executeSync: (sql, params) => runtime.actorSqlExecuteSync(ctx, sql, params),
|
|
3678
3969
|
executeBatch: (statements) => runtime.actorSqlExecuteBatch(ctx, statements),
|
|
3679
3970
|
beginTransaction: async (timeoutMs, name) => {
|
|
3680
3971
|
const transaction = await runtime.actorSqlBeginTransaction(
|
|
@@ -3682,16 +3973,15 @@ function getOrCreateNativeSqlDatabase(runtime, ctx) {
|
|
|
3682
3973
|
timeoutMs,
|
|
3683
3974
|
name
|
|
3684
3975
|
);
|
|
3685
|
-
return
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
};
|
|
3976
|
+
return createNativeSqlTransaction(runtime, transaction);
|
|
3977
|
+
},
|
|
3978
|
+
beginTransactionSync: (timeoutMs, name) => {
|
|
3979
|
+
const transaction = runtime.actorSqlBeginTransactionSync(
|
|
3980
|
+
ctx,
|
|
3981
|
+
timeoutMs,
|
|
3982
|
+
name
|
|
3983
|
+
);
|
|
3984
|
+
return createNativeSqlTransaction(runtime, transaction);
|
|
3695
3985
|
},
|
|
3696
3986
|
beginStateTransaction: async (timeoutMs, context) => {
|
|
3697
3987
|
const scope = context;
|
|
@@ -3729,8 +4019,13 @@ function getOrCreateNativeSqlDatabase(runtime, ctx) {
|
|
|
3729
4019
|
run: (sql, params) => runtime.actorSqlRun(ctx, sql, params),
|
|
3730
4020
|
metrics: () => runtime.actorSqlMetrics(ctx),
|
|
3731
4021
|
takeLastKvError: () => runtime.actorSqlTakeLastKvError(ctx),
|
|
4022
|
+
open: () => runtime.actorSqlOpen(ctx),
|
|
4023
|
+
commitTicket: () => runtime.actorSqlCommitTicket(ctx),
|
|
4024
|
+
whenDurable: (ticket) => runtime.actorSqlWhenDurable(ctx, ticket),
|
|
4025
|
+
abortGeneration: (reason) => runtime.actorSqlAbortGeneration(ctx, reason),
|
|
3732
4026
|
close: () => runtime.actorSqlClose(ctx)
|
|
3733
|
-
}
|
|
4027
|
+
};
|
|
4028
|
+
const database = wrapJsNativeDatabase(bindings);
|
|
3734
4029
|
runtimeState.sql = database;
|
|
3735
4030
|
return database;
|
|
3736
4031
|
}
|
|
@@ -5386,12 +5681,14 @@ var ActorContextHandleAdapter = class {
|
|
|
5386
5681
|
}
|
|
5387
5682
|
get abortSignal() {
|
|
5388
5683
|
if (!this.#abortSignal) {
|
|
5389
|
-
const
|
|
5684
|
+
const actorAbort = this.#actorAbort();
|
|
5685
|
+
const actorSignal = actorAbort.signal;
|
|
5390
5686
|
if (this.#dispatchCancelToken === void 0) {
|
|
5391
5687
|
this.#abortSignal = actorSignal;
|
|
5392
5688
|
} else {
|
|
5393
5689
|
const controller = new AbortController();
|
|
5394
5690
|
let cleanedUp = false;
|
|
5691
|
+
let releaseDispatchListener;
|
|
5395
5692
|
const onActorAbort = () => {
|
|
5396
5693
|
cleanup();
|
|
5397
5694
|
controller.abort();
|
|
@@ -5401,7 +5698,9 @@ var ActorContextHandleAdapter = class {
|
|
|
5401
5698
|
return;
|
|
5402
5699
|
}
|
|
5403
5700
|
cleanedUp = true;
|
|
5404
|
-
|
|
5701
|
+
actorAbort.listeners.delete(onActorAbort);
|
|
5702
|
+
releaseDispatchListener == null ? void 0 : releaseDispatchListener();
|
|
5703
|
+
releaseDispatchListener = void 0;
|
|
5405
5704
|
this.#abortSignalCleanup = void 0;
|
|
5406
5705
|
};
|
|
5407
5706
|
if (actorSignal.aborted || this.#runtime.cancellationTokenAborted(
|
|
@@ -5411,10 +5710,8 @@ var ActorContextHandleAdapter = class {
|
|
|
5411
5710
|
} else {
|
|
5412
5711
|
const dispatchCancelToken = this.#dispatchCancelToken;
|
|
5413
5712
|
this.#abortSignalCleanup = cleanup;
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
});
|
|
5417
|
-
callNativeSync(
|
|
5713
|
+
actorAbort.listeners.add(onActorAbort);
|
|
5714
|
+
releaseDispatchListener = callNativeSync(
|
|
5418
5715
|
() => this.#runtime.onCancellationTokenCancelled(
|
|
5419
5716
|
dispatchCancelToken,
|
|
5420
5717
|
() => {
|
|
@@ -5474,10 +5771,12 @@ var ActorContextHandleAdapter = class {
|
|
|
5474
5771
|
{
|
|
5475
5772
|
open: async (requestedActorId) => {
|
|
5476
5773
|
void requestedActorId;
|
|
5477
|
-
|
|
5774
|
+
const database = getOrCreateNativeSqlDatabase(
|
|
5478
5775
|
this.#runtime,
|
|
5479
5776
|
this.#ctx
|
|
5480
5777
|
);
|
|
5778
|
+
await database.open();
|
|
5779
|
+
return database;
|
|
5481
5780
|
}
|
|
5482
5781
|
},
|
|
5483
5782
|
async (timeoutMs, context) => await getOrCreateNativeSqlDatabase(
|
|
@@ -5790,22 +6089,42 @@ var ActorContextHandleAdapter = class {
|
|
|
5790
6089
|
}
|
|
5791
6090
|
async dispose() {
|
|
5792
6091
|
var _a;
|
|
5793
|
-
this.#
|
|
6092
|
+
if (!isNativeRuntimeStateCleared(this.#runtime, this.#ctx)) {
|
|
6093
|
+
this.#flushStateChange();
|
|
6094
|
+
}
|
|
5794
6095
|
(_a = this.#abortSignalCleanup) == null ? void 0 : _a.call(this);
|
|
5795
6096
|
}
|
|
5796
|
-
#
|
|
6097
|
+
#actorAbort() {
|
|
6098
|
+
const runtimeState = readNativeRuntimeStateBag(
|
|
6099
|
+
this.#runtime,
|
|
6100
|
+
this.#ctx
|
|
6101
|
+
);
|
|
6102
|
+
const cached = runtimeState.actorAbort;
|
|
6103
|
+
if (cached && !cached.signal.aborted) {
|
|
6104
|
+
return cached;
|
|
6105
|
+
}
|
|
5797
6106
|
const nativeSignal = callNativeSync(
|
|
5798
6107
|
() => this.#runtime.actorAbortSignal(this.#ctx)
|
|
5799
6108
|
);
|
|
5800
6109
|
const controller = new AbortController();
|
|
5801
|
-
|
|
6110
|
+
const actorAbort = {
|
|
6111
|
+
signal: controller.signal,
|
|
6112
|
+
listeners: /* @__PURE__ */ new Set()
|
|
6113
|
+
};
|
|
6114
|
+
const abort = () => {
|
|
5802
6115
|
controller.abort();
|
|
6116
|
+
for (const listener of actorAbort.listeners) {
|
|
6117
|
+
listener();
|
|
6118
|
+
}
|
|
6119
|
+
actorAbort.listeners.clear();
|
|
6120
|
+
};
|
|
6121
|
+
if (nativeSignal.aborted) {
|
|
6122
|
+
abort();
|
|
5803
6123
|
} else {
|
|
5804
|
-
nativeSignal.addEventListener("abort",
|
|
5805
|
-
once: true
|
|
5806
|
-
});
|
|
6124
|
+
nativeSignal.addEventListener("abort", abort, { once: true });
|
|
5807
6125
|
}
|
|
5808
|
-
|
|
6126
|
+
runtimeState.actorAbort = actorAbort;
|
|
6127
|
+
return actorAbort;
|
|
5809
6128
|
}
|
|
5810
6129
|
#readState() {
|
|
5811
6130
|
const actorState = getNativePersistState(this.#runtime, this.#ctx);
|
|
@@ -6060,18 +6379,21 @@ function buildActorTracingConfig(actions, tracing) {
|
|
|
6060
6379
|
actions: flattenActionTraceSamplers(actions, tracing.actions)
|
|
6061
6380
|
};
|
|
6062
6381
|
}
|
|
6382
|
+
var SQLITE_DEFERRED_COMMITS = /* @__PURE__ */ Symbol.for("rivetkit.sqlite.deferredCommits");
|
|
6063
6383
|
function buildActorConfig(definition, registryConfig, runtimeKind) {
|
|
6064
|
-
var _a;
|
|
6384
|
+
var _a, _b;
|
|
6065
6385
|
const config = definition.config;
|
|
6066
6386
|
const options = config.options ?? {};
|
|
6067
6387
|
const canHibernate = options.canHibernateWebSocket;
|
|
6068
6388
|
const usesRemoteSqlite = sqliteBackendForConfig(registryConfig) === "remote";
|
|
6069
6389
|
const sqliteProfiling = (_a = config.db) == null ? void 0 : _a.sqliteProfiling;
|
|
6390
|
+
const sqliteDeferredCommits = ((_b = config.db) == null ? void 0 : _b[SQLITE_DEFERRED_COMMITS]) === true;
|
|
6070
6391
|
return {
|
|
6071
6392
|
name: options.name,
|
|
6072
6393
|
icon: options.icon,
|
|
6073
6394
|
hasDatabase: true,
|
|
6074
6395
|
remoteSqlite: usesRemoteSqlite,
|
|
6396
|
+
sqliteDeferredCommits: sqliteDeferredCommits || void 0,
|
|
6075
6397
|
sqliteProfiling,
|
|
6076
6398
|
tracing: buildActorTracingConfig(
|
|
6077
6399
|
definition.config.actions,
|
|
@@ -6767,7 +7089,7 @@ function buildNativeFactory(runtime, registryConfig, definition) {
|
|
|
6767
7089
|
}
|
|
6768
7090
|
} finally {
|
|
6769
7091
|
resolveNativeDestroy(runtime, ctx);
|
|
6770
|
-
await
|
|
7092
|
+
await detachNativeDatabaseForShutdown(runtime, ctx);
|
|
6771
7093
|
clearNativeRuntimeState(runtime, ctx);
|
|
6772
7094
|
await actorCtx.dispose();
|
|
6773
7095
|
}
|
|
@@ -7271,11 +7593,12 @@ async function buildServeConfig(config, resolveServicesBinary = true) {
|
|
|
7271
7593
|
throw nativeEndpointNotConfiguredError();
|
|
7272
7594
|
}
|
|
7273
7595
|
const serveConfig = {
|
|
7274
|
-
version: config.
|
|
7596
|
+
version: config.node.version,
|
|
7275
7597
|
endpoint: config.endpoint,
|
|
7598
|
+
engineSpawn: config.engineSpawn,
|
|
7276
7599
|
token: config.token,
|
|
7277
7600
|
namespace: config.namespace,
|
|
7278
|
-
poolName: config.
|
|
7601
|
+
poolName: config.node.poolName,
|
|
7279
7602
|
startServices: resolveServicesBinary && config.startServices,
|
|
7280
7603
|
handleInspectorHttpInRuntime: true,
|
|
7281
7604
|
serverlessBasePath: config.serverless.basePath,
|
|
@@ -7296,14 +7619,16 @@ async function buildServeConfig(config, resolveServicesBinary = true) {
|
|
|
7296
7619
|
});
|
|
7297
7620
|
}
|
|
7298
7621
|
if (resolveServicesBinary && config.startServices) {
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
serveConfig.servicesBinaryPath =
|
|
7302
|
-
}
|
|
7303
|
-
|
|
7304
|
-
|
|
7305
|
-
|
|
7306
|
-
})
|
|
7622
|
+
const servicesBinary = getEnvUniversal("RIVET_SERVICES_BINARY");
|
|
7623
|
+
if (servicesBinary) {
|
|
7624
|
+
serveConfig.servicesBinaryPath = servicesBinary;
|
|
7625
|
+
} else {
|
|
7626
|
+
try {
|
|
7627
|
+
const { getServicesPath } = await loadServices();
|
|
7628
|
+
serveConfig.servicesBinaryPath = getServicesPath();
|
|
7629
|
+
} catch (error) {
|
|
7630
|
+
throw servicesBinaryUnavailable(error);
|
|
7631
|
+
}
|
|
7307
7632
|
}
|
|
7308
7633
|
}
|
|
7309
7634
|
serveConfig.engineHost = config.engineHost;
|
|
@@ -7345,6 +7670,11 @@ async function buildConfiguredRegistry(config) {
|
|
|
7345
7670
|
|
|
7346
7671
|
// src/registry/index.ts
|
|
7347
7672
|
var REGISTRY_READY_TIMEOUT_MS = 3e4;
|
|
7673
|
+
var LOCAL_ENGINE_READY_TIMEOUT_MS = 6e4;
|
|
7674
|
+
var LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS = 4e3;
|
|
7675
|
+
function rejectServerless() {
|
|
7676
|
+
throw new Error("serverless is disabled in this version");
|
|
7677
|
+
}
|
|
7348
7678
|
function signalExitCode(signal) {
|
|
7349
7679
|
switch (signal) {
|
|
7350
7680
|
case "SIGINT":
|
|
@@ -7449,6 +7779,7 @@ var Registry = class {
|
|
|
7449
7779
|
*/
|
|
7450
7780
|
#ensureServerlessPoolConfigured(config) {
|
|
7451
7781
|
if (!config.configurePool) return void 0;
|
|
7782
|
+
rejectServerless();
|
|
7452
7783
|
if (!this.#configureServerlessPoolPromise) {
|
|
7453
7784
|
this.#configureServerlessPoolPromise = configureServerlessPool(
|
|
7454
7785
|
config
|
|
@@ -7473,6 +7804,7 @@ var Registry = class {
|
|
|
7473
7804
|
*/
|
|
7474
7805
|
async handler(request) {
|
|
7475
7806
|
var _a;
|
|
7807
|
+
rejectServerless();
|
|
7476
7808
|
const config = this.parseConfig();
|
|
7477
7809
|
this.#printWelcome(config, "serverless");
|
|
7478
7810
|
if (!this.#runtimeServerlessPromise) {
|
|
@@ -7634,6 +7966,7 @@ var Registry = class {
|
|
|
7634
7966
|
* ```
|
|
7635
7967
|
*/
|
|
7636
7968
|
serve() {
|
|
7969
|
+
rejectServerless();
|
|
7637
7970
|
return {
|
|
7638
7971
|
fetch: (request) => this.handler(request)
|
|
7639
7972
|
};
|
|
@@ -7658,6 +7991,9 @@ var Registry = class {
|
|
|
7658
7991
|
* ```
|
|
7659
7992
|
*/
|
|
7660
7993
|
async listen(opts = {}) {
|
|
7994
|
+
if (!opts.application) {
|
|
7995
|
+
rejectServerless();
|
|
7996
|
+
}
|
|
7661
7997
|
const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3e3;
|
|
7662
7998
|
const publicDir = opts.publicDir ?? getRivetkitPublicDir();
|
|
7663
7999
|
const config = this.parseConfig();
|
|
@@ -7758,6 +8094,7 @@ var Registry = class {
|
|
|
7758
8094
|
* Returns serverless metadata suitable for mounting in a user-owned router.
|
|
7759
8095
|
*/
|
|
7760
8096
|
async #metadataRoute() {
|
|
8097
|
+
rejectServerless();
|
|
7761
8098
|
const configured = await this.#activeConfiguredRegistry();
|
|
7762
8099
|
if (!configured) {
|
|
7763
8100
|
return new Response("registry not started\n", {
|
|
@@ -7818,18 +8155,18 @@ var Registry = class {
|
|
|
7818
8155
|
#startEnvoy(config, printWelcome) {
|
|
7819
8156
|
var _a;
|
|
7820
8157
|
if (!this.#runtimeServePromise) {
|
|
7821
|
-
const configuredEnvoyVersion = (_a = this.#config.
|
|
8158
|
+
const configuredEnvoyVersion = (_a = this.#config.node) == null ? void 0 : _a.version;
|
|
7822
8159
|
const envoyVersionSource = configuredEnvoyVersion !== void 0 ? "config" : getRivetEnvoyVersion() !== void 0 ? "environment" : "default";
|
|
7823
8160
|
logger2().info({
|
|
7824
8161
|
msg: "starting rivetkit envoy",
|
|
7825
8162
|
rivetkitVersion: VERSION,
|
|
7826
|
-
envoyVersion: config.
|
|
8163
|
+
envoyVersion: config.node.version,
|
|
7827
8164
|
envoyVersionSource
|
|
7828
8165
|
});
|
|
7829
8166
|
if (envoyVersionSource === "default" && getNodeEnv() === "production") {
|
|
7830
8167
|
logger2().error({
|
|
7831
|
-
msg: "
|
|
7832
|
-
envoyVersion: config.
|
|
8168
|
+
msg: "node version defaulted because neither config.node.version nor RIVET_NODE_VERSION is set; actors will not drain automatically across deploys. See https://rivet.dev/docs/actors/versions",
|
|
8169
|
+
envoyVersion: config.node.version,
|
|
7833
8170
|
envoyVersionSource
|
|
7834
8171
|
});
|
|
7835
8172
|
}
|
|
@@ -7841,7 +8178,10 @@ var Registry = class {
|
|
|
7841
8178
|
}
|
|
7842
8179
|
);
|
|
7843
8180
|
this.#runtimeServePromise = this.#runtimeServeLifecyclePromise.catch((error) => {
|
|
7844
|
-
logger2().
|
|
8181
|
+
logger2().error({ error }, "runtime registry serve errored");
|
|
8182
|
+
if (typeof process !== "undefined" && typeof process.exit === "function") {
|
|
8183
|
+
process.exit(1);
|
|
8184
|
+
}
|
|
7845
8185
|
});
|
|
7846
8186
|
this.#installSignalHandlers(config);
|
|
7847
8187
|
}
|
|
@@ -7871,7 +8211,7 @@ var Registry = class {
|
|
|
7871
8211
|
finishShutdownSignal(signal);
|
|
7872
8212
|
return;
|
|
7873
8213
|
}
|
|
7874
|
-
this.#shutdownInFlight = this.#drain(config).catch((err) => {
|
|
8214
|
+
this.#shutdownInFlight = this.#drain(config, true).catch((err) => {
|
|
7875
8215
|
logger2().warn({ err }, "shutdown error");
|
|
7876
8216
|
}).then(() => {
|
|
7877
8217
|
this.#removeSignalHandlers();
|
|
@@ -7907,12 +8247,18 @@ var Registry = class {
|
|
|
7907
8247
|
});
|
|
7908
8248
|
return this.#shutdownInFlight;
|
|
7909
8249
|
}
|
|
7910
|
-
async #drain(config) {
|
|
8250
|
+
async #drain(config, signalDriven = false) {
|
|
7911
8251
|
var _a;
|
|
7912
8252
|
const modeAPromise = this.#runtimeServeConfiguredPromise;
|
|
7913
8253
|
const modeBPromise = this.#runtimeServerlessPromise;
|
|
7914
8254
|
const runtimes = /* @__PURE__ */ new Set();
|
|
7915
|
-
const
|
|
8255
|
+
const localDevSignal = signalDriven && getNodeEnv() !== "production" && config.engineSpawn && config.endpoint !== void 0 && isLocalEngineEndpoint(config.endpoint);
|
|
8256
|
+
let gracePeriodMs = (_a = config.shutdown) == null ? void 0 : _a.gracePeriodMs;
|
|
8257
|
+
if (gracePeriodMs === void 0) {
|
|
8258
|
+
gracePeriodMs = localDevSignal ? LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS : await this.#actorStopThresholdMs(
|
|
8259
|
+
modeAPromise ?? modeBPromise
|
|
8260
|
+
) ?? 30 * 60 * 1e3;
|
|
8261
|
+
}
|
|
7916
8262
|
const drain = async () => {
|
|
7917
8263
|
const registries = [];
|
|
7918
8264
|
if (modeAPromise !== void 0) {
|
|
@@ -8017,12 +8363,16 @@ var Registry = class {
|
|
|
8017
8363
|
);
|
|
8018
8364
|
}
|
|
8019
8365
|
if (this.#runtimeReadyPromise) return this.#runtimeReadyPromise;
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8366
|
+
try {
|
|
8367
|
+
if (getRivetkitRuntimeMode() === "serverless") {
|
|
8368
|
+
return Promise.reject(
|
|
8369
|
+
new Error(
|
|
8370
|
+
"registry.startAndWait() requires envoy runtime mode; serverless registries become ready per request"
|
|
8371
|
+
)
|
|
8372
|
+
);
|
|
8373
|
+
}
|
|
8374
|
+
} catch (error) {
|
|
8375
|
+
return Promise.reject(error);
|
|
8026
8376
|
}
|
|
8027
8377
|
const config = this.parseConfig();
|
|
8028
8378
|
if (config.runtime === "wasm") {
|
|
@@ -8038,16 +8388,17 @@ var Registry = class {
|
|
|
8038
8388
|
if (!configuredRegistryPromise || !serveLifecyclePromise) {
|
|
8039
8389
|
throw new Error("registry envoy startup did not initialize");
|
|
8040
8390
|
}
|
|
8391
|
+
const readyTimeoutMs = config.engineSpawn && config.endpoint !== void 0 && isLocalEngineEndpoint(config.endpoint) ? LOCAL_ENGINE_READY_TIMEOUT_MS : REGISTRY_READY_TIMEOUT_MS;
|
|
8041
8392
|
let timeout;
|
|
8042
8393
|
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
8043
8394
|
var _a;
|
|
8044
8395
|
timeout = setTimeout(
|
|
8045
8396
|
() => reject(
|
|
8046
8397
|
new Error(
|
|
8047
|
-
`RivetKit registry did not register with the Engine within ${
|
|
8398
|
+
`RivetKit registry did not register with the Engine within ${readyTimeoutMs}ms`
|
|
8048
8399
|
)
|
|
8049
8400
|
),
|
|
8050
|
-
|
|
8401
|
+
readyTimeoutMs
|
|
8051
8402
|
);
|
|
8052
8403
|
(_a = timeout.unref) == null ? void 0 : _a.call(timeout);
|
|
8053
8404
|
});
|