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
|
@@ -167,17 +167,6 @@ export interface RunnerConfigsResponse {
|
|
|
167
167
|
runner_configs: Record<string, RunnerConfigDatacenters>;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
export async function getRunnerConfig(
|
|
171
|
-
config: ClientConfig,
|
|
172
|
-
name: string,
|
|
173
|
-
): Promise<RunnerConfigsResponse> {
|
|
174
|
-
return apiCall<never, RunnerConfigsResponse>(
|
|
175
|
-
config,
|
|
176
|
-
"GET",
|
|
177
|
-
`/runner-configs?runner_name=${name}`,
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
170
|
// MARK: Update runner config
|
|
182
171
|
export interface RegistryConfigRequest {
|
|
183
172
|
datacenters: Record<
|
|
@@ -212,11 +201,11 @@ export async function updateRunnerConfig(
|
|
|
212
201
|
runnerName: string,
|
|
213
202
|
request: RegistryConfigRequest,
|
|
214
203
|
): Promise<void> {
|
|
215
|
-
return apiCall<
|
|
204
|
+
return apiCall<unknown, void>(
|
|
216
205
|
config,
|
|
217
206
|
"PUT",
|
|
218
|
-
`/
|
|
219
|
-
request,
|
|
207
|
+
`/pools/${encodeURIComponent(runnerName)}`,
|
|
208
|
+
Object.values(request.datacenters)[0],
|
|
220
209
|
);
|
|
221
210
|
}
|
|
222
211
|
|
|
@@ -237,3 +226,44 @@ export async function kvGet(
|
|
|
237
226
|
`/actors/${encodeURIComponent(actorId)}/kv/keys/${encodeURIComponent(key)}`,
|
|
238
227
|
);
|
|
239
228
|
}
|
|
229
|
+
|
|
230
|
+
/** Pool changes apply when each node next connects. */
|
|
231
|
+
export interface PoolConfig {
|
|
232
|
+
drain_on_version_upgrade?: boolean;
|
|
233
|
+
actor_eviction_delay?: number;
|
|
234
|
+
actor_eviction_period?: number;
|
|
235
|
+
actor_eviction_rate?: number;
|
|
236
|
+
metadata?: unknown;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function upsertPool(
|
|
240
|
+
config: ClientConfig,
|
|
241
|
+
name: string,
|
|
242
|
+
pool: PoolConfig,
|
|
243
|
+
): Promise<{ pool: PoolConfig & { name: string } }> {
|
|
244
|
+
return apiCall(config, "PUT", `/pools/${encodeURIComponent(name)}`, pool);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function getPool(
|
|
248
|
+
config: ClientConfig,
|
|
249
|
+
name: string,
|
|
250
|
+
): Promise<{ pool: PoolConfig & { name: string } }> {
|
|
251
|
+
return apiCall(config, "GET", `/pools/${encodeURIComponent(name)}`);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function listPools(
|
|
255
|
+
config: ClientConfig,
|
|
256
|
+
page?: { limit?: number; cursor?: string },
|
|
257
|
+
): Promise<{
|
|
258
|
+
pools: Array<PoolConfig & { name: string }>;
|
|
259
|
+
pagination: { cursor: string | null };
|
|
260
|
+
}> {
|
|
261
|
+
const query = new URLSearchParams();
|
|
262
|
+
if (page?.limit !== undefined) query.set("limit", String(page.limit));
|
|
263
|
+
if (page?.cursor !== undefined) query.set("cursor", page.cursor);
|
|
264
|
+
return apiCall(config, "GET", `/pools?${query}`);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function deletePool(config: ClientConfig, name: string): Promise<void> {
|
|
268
|
+
return apiCall(config, "DELETE", `/pools/${encodeURIComponent(name)}`);
|
|
269
|
+
}
|
package/src/engine-client/mod.ts
CHANGED
|
@@ -254,7 +254,7 @@ export class RemoteEngineControlClient implements EngineControlClient {
|
|
|
254
254
|
datacenter: region,
|
|
255
255
|
name,
|
|
256
256
|
key: serializeActorKey(key),
|
|
257
|
-
|
|
257
|
+
pool: poolName ?? this.#config.poolName,
|
|
258
258
|
input: actorInput
|
|
259
259
|
? uint8ArrayToBase64(
|
|
260
260
|
encodeCborCompat(actorInput as JsonCompatValue),
|
|
@@ -325,7 +325,7 @@ export class RemoteEngineControlClient implements EngineControlClient {
|
|
|
325
325
|
createActor(config, {
|
|
326
326
|
datacenter: region,
|
|
327
327
|
name,
|
|
328
|
-
|
|
328
|
+
pool: poolName ?? this.#config.poolName,
|
|
329
329
|
key: serializeActorKey(key),
|
|
330
330
|
input: input
|
|
331
331
|
? uint8ArrayToBase64(
|
|
@@ -11,7 +11,7 @@ export const EnvoyConfigSchema = z.object({
|
|
|
11
11
|
|
|
12
12
|
// Deprecated.
|
|
13
13
|
totalSlots: z.number().default(() => getRivetTotalSlots() ?? 100000),
|
|
14
|
-
|
|
14
|
+
nodeKey: z.string().optional(),
|
|
15
15
|
});
|
|
16
16
|
export type EnvoyConfigInput = z.input<typeof EnvoyConfigSchema>;
|
|
17
17
|
export type EnvoyConfig = z.infer<typeof EnvoyConfigSchema>;
|
|
@@ -158,7 +158,7 @@ export const RegistryConfigSchema = z
|
|
|
158
158
|
// // created or must be imported async using `await import(...)`
|
|
159
159
|
// getUpgradeWebSocket: z.custom<GetUpgradeWebSocket>().optional(),
|
|
160
160
|
|
|
161
|
-
// MARK:
|
|
161
|
+
// MARK: Node Configuration
|
|
162
162
|
/**
|
|
163
163
|
* Endpoint to connect to for Rivet Engine.
|
|
164
164
|
*
|
|
@@ -251,14 +251,14 @@ export const RegistryConfigSchema = z
|
|
|
251
251
|
.default(() => getRivetRunEngineVersion() ?? VERSION),
|
|
252
252
|
/**
|
|
253
253
|
* Starts the first-party Services actor host when RivetKit manages
|
|
254
|
-
* a local engine.
|
|
255
|
-
*
|
|
254
|
+
* a local engine. Disabled by default. Set RIVET_RUN_SERVICES=1
|
|
255
|
+
* or startServices: true to enable it.
|
|
256
256
|
*/
|
|
257
257
|
startServices: z.boolean().optional(),
|
|
258
258
|
/**
|
|
259
259
|
* @experimental
|
|
260
260
|
*
|
|
261
|
-
* Automatically configure serverless
|
|
261
|
+
* Automatically configure serverless nodes in the engine.
|
|
262
262
|
*/
|
|
263
263
|
configurePool: ConfigurePoolSchema.optional(),
|
|
264
264
|
|
|
@@ -266,7 +266,7 @@ export const RegistryConfigSchema = z
|
|
|
266
266
|
serverless: ServerlessConfigSchema.optional().default(() =>
|
|
267
267
|
ServerlessConfigSchema.parse({}),
|
|
268
268
|
),
|
|
269
|
-
|
|
269
|
+
node: EnvoyConfigSchema.optional().default(() =>
|
|
270
270
|
EnvoyConfigSchema.parse({}),
|
|
271
271
|
),
|
|
272
272
|
|
|
@@ -274,9 +274,9 @@ export const RegistryConfigSchema = z
|
|
|
274
274
|
/**
|
|
275
275
|
* Graceful shutdown configuration for SIGINT/SIGTERM.
|
|
276
276
|
*
|
|
277
|
-
* When a persistent
|
|
277
|
+
* When a persistent node is running (Mode A, started via `registry.start()`),
|
|
278
278
|
* rivetkit installs Node SIGINT/SIGTERM handlers that call into core's
|
|
279
|
-
* `shutdown()` and wait up to `gracePeriodMs` for the
|
|
279
|
+
* `shutdown()` and wait up to `gracePeriodMs` for the node to drain
|
|
280
280
|
* before re-raising the signal to let Node exit via its default path.
|
|
281
281
|
*
|
|
282
282
|
* Handlers are NOT installed when `handler(request)` is used alone
|
|
@@ -289,9 +289,12 @@ export const RegistryConfigSchema = z
|
|
|
289
289
|
/**
|
|
290
290
|
* Wait this many milliseconds for the serve promise to resolve
|
|
291
291
|
* after calling `CoreRegistry::shutdown()`. Defaults to the
|
|
292
|
-
* engine-provided actor stop threshold once the
|
|
292
|
+
* engine-provided actor stop threshold once the node connects. A
|
|
293
|
+
* signal-driven shutdown of a managed local development engine waits
|
|
294
|
+
* four seconds by default so actors can acknowledge stopping before
|
|
295
|
+
* a file watcher restarts the process.
|
|
293
296
|
*
|
|
294
|
-
*
|
|
297
|
+
* Set a longer period when a complete graceful node drain is required.
|
|
295
298
|
*/
|
|
296
299
|
gracePeriodMs: z.number().int().min(1_000).optional(),
|
|
297
300
|
/**
|
|
@@ -348,12 +351,12 @@ export const RegistryConfigSchema = z
|
|
|
348
351
|
});
|
|
349
352
|
}
|
|
350
353
|
|
|
351
|
-
//
|
|
352
|
-
if (config.configurePool
|
|
354
|
+
// Serverless pool configuration is disabled for v3.
|
|
355
|
+
if (config.configurePool) {
|
|
353
356
|
ctx.addIssue({
|
|
354
357
|
code: "custom",
|
|
355
|
-
message:
|
|
356
|
-
|
|
358
|
+
message: "serverless is disabled in this version",
|
|
359
|
+
path: ["configurePool"],
|
|
357
360
|
});
|
|
358
361
|
}
|
|
359
362
|
|
|
@@ -366,13 +369,7 @@ export const RegistryConfigSchema = z
|
|
|
366
369
|
? localEngineEndpoint
|
|
367
370
|
: (parsedEndpoint?.endpoint ??
|
|
368
371
|
(isDevEnv ? localEngineEndpoint : undefined));
|
|
369
|
-
|
|
370
|
-
// follows the same local-endpoint decision that causes core to manage the
|
|
371
|
-
// Engine, while explicit config and RIVET_RUN_SERVICES take precedence.
|
|
372
|
-
const startServices =
|
|
373
|
-
config.startServices ??
|
|
374
|
-
getRivetRunServices() ??
|
|
375
|
-
Boolean(endpoint && isLocalEngineEndpoint(endpoint));
|
|
372
|
+
const startServices = config.startServices ?? getRivetRunServices();
|
|
376
373
|
const validateServerlessEndpoint = Boolean(
|
|
377
374
|
config.startEngine || parsedEndpoint,
|
|
378
375
|
);
|
|
@@ -422,6 +419,7 @@ export const RegistryConfigSchema = z
|
|
|
422
419
|
...config,
|
|
423
420
|
sqlite,
|
|
424
421
|
endpoint,
|
|
422
|
+
engineSpawn: !parsedEndpoint && Boolean(endpoint),
|
|
425
423
|
startServices,
|
|
426
424
|
namespace,
|
|
427
425
|
token,
|
|
@@ -468,10 +466,10 @@ export function buildActorNames(
|
|
|
468
466
|
|
|
469
467
|
export const DocConfigurePoolSchema = z
|
|
470
468
|
.object({
|
|
471
|
-
name: z.string().optional().describe("Name of the
|
|
469
|
+
name: z.string().optional().describe("Name of the node pool."),
|
|
472
470
|
url: z
|
|
473
471
|
.string()
|
|
474
|
-
.describe("URL of the serverless platform to configure
|
|
472
|
+
.describe("URL of the serverless platform to configure nodes."),
|
|
475
473
|
headers: z
|
|
476
474
|
.record(z.string(), z.string())
|
|
477
475
|
.optional()
|
|
@@ -504,7 +502,7 @@ export const DocConfigurePoolSchema = z
|
|
|
504
502
|
.boolean()
|
|
505
503
|
.optional()
|
|
506
504
|
.describe(
|
|
507
|
-
"Drain
|
|
505
|
+
"Drain nodes when a new version is deployed. Defaults to true.",
|
|
508
506
|
),
|
|
509
507
|
})
|
|
510
508
|
.optional();
|
|
@@ -547,17 +545,17 @@ export const DocEnvoyConfigSchema = z
|
|
|
547
545
|
poolName: z
|
|
548
546
|
.string()
|
|
549
547
|
.optional()
|
|
550
|
-
.describe("Name of this
|
|
551
|
-
|
|
548
|
+
.describe("Name of this node pool. Default: 'default'"),
|
|
549
|
+
nodeKey: z
|
|
552
550
|
.string()
|
|
553
551
|
.optional()
|
|
554
|
-
.describe("Deprecated. Authentication key for the
|
|
552
|
+
.describe("Deprecated. Authentication key for the node."),
|
|
555
553
|
version: z
|
|
556
554
|
.number()
|
|
557
555
|
.optional()
|
|
558
|
-
.describe("Version number of this
|
|
556
|
+
.describe("Version number of this node. Default: 1"),
|
|
559
557
|
})
|
|
560
|
-
.describe("Configuration for
|
|
558
|
+
.describe("Configuration for node mode.");
|
|
561
559
|
|
|
562
560
|
export const DocSqliteConfigSchema = z
|
|
563
561
|
.object({
|
|
@@ -658,12 +656,12 @@ export const DocRegistryConfigSchema = z
|
|
|
658
656
|
.boolean()
|
|
659
657
|
.optional()
|
|
660
658
|
.describe(
|
|
661
|
-
"Starts Services when RivetKit manages a local Engine.
|
|
659
|
+
"Starts Services when RivetKit manages a local Engine. Disabled by default. Set RIVET_RUN_SERVICES=1 or startServices: true to enable.",
|
|
662
660
|
),
|
|
663
661
|
configurePool: DocConfigurePoolSchema.describe(
|
|
664
|
-
"Automatically configure serverless
|
|
662
|
+
"Automatically configure serverless nodes in the engine.",
|
|
665
663
|
),
|
|
666
664
|
serverless: DocServerlessConfigSchema.optional(),
|
|
667
|
-
|
|
665
|
+
node: DocEnvoyConfigSchema.optional(),
|
|
668
666
|
})
|
|
669
667
|
.describe("RivetKit registry configuration.");
|
package/src/registry/index.ts
CHANGED
|
@@ -29,6 +29,18 @@ import type {
|
|
|
29
29
|
type ShutdownSignal = "SIGINT" | "SIGTERM";
|
|
30
30
|
|
|
31
31
|
const REGISTRY_READY_TIMEOUT_MS = 30_000;
|
|
32
|
+
// A managed Engine restart can wait for the old process to release storage and
|
|
33
|
+
// for its worker lease to expire before the replacement can register.
|
|
34
|
+
const LOCAL_ENGINE_READY_TIMEOUT_MS = 60_000;
|
|
35
|
+
// Core gives local actors three seconds to drain and acknowledge their stopped
|
|
36
|
+
// reports. Leave time to close the node connection after that, while staying
|
|
37
|
+
// below the five-second force-kill ceiling used by tsx watch.
|
|
38
|
+
const LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS = 4_000;
|
|
39
|
+
|
|
40
|
+
// Serverless is disabled for v3; keep the implementation for a later release.
|
|
41
|
+
function rejectServerless(): void {
|
|
42
|
+
throw new Error("serverless is disabled in this version");
|
|
43
|
+
}
|
|
32
44
|
|
|
33
45
|
function signalExitCode(signal: ShutdownSignal): number {
|
|
34
46
|
switch (signal) {
|
|
@@ -190,6 +202,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
190
202
|
config: RegistryConfig,
|
|
191
203
|
): Promise<void> | undefined {
|
|
192
204
|
if (!config.configurePool) return undefined;
|
|
205
|
+
rejectServerless();
|
|
193
206
|
|
|
194
207
|
if (!this.#configureServerlessPoolPromise) {
|
|
195
208
|
this.#configureServerlessPoolPromise = configureServerlessPool(
|
|
@@ -215,6 +228,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
215
228
|
* ```
|
|
216
229
|
*/
|
|
217
230
|
public async handler(request: Request): Promise<Response> {
|
|
231
|
+
rejectServerless();
|
|
218
232
|
const config = this.parseConfig();
|
|
219
233
|
this.#printWelcome(config, "serverless");
|
|
220
234
|
|
|
@@ -413,6 +427,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
413
427
|
* ```
|
|
414
428
|
*/
|
|
415
429
|
public serve(): ServerlessHandler {
|
|
430
|
+
rejectServerless();
|
|
416
431
|
return {
|
|
417
432
|
fetch: (request) => this.handler(request),
|
|
418
433
|
};
|
|
@@ -438,6 +453,9 @@ export class Registry<A extends RegistryActors> {
|
|
|
438
453
|
* ```
|
|
439
454
|
*/
|
|
440
455
|
public async listen(opts: RegistryListenOptions = {}): Promise<void> {
|
|
456
|
+
if (!opts.application) {
|
|
457
|
+
rejectServerless();
|
|
458
|
+
}
|
|
441
459
|
const port = opts.port ?? parsePortEnv(process.env.RIVET_PORT) ?? 3000;
|
|
442
460
|
const publicDir = opts.publicDir ?? getRivetkitPublicDir();
|
|
443
461
|
const config = this.parseConfig();
|
|
@@ -554,6 +572,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
554
572
|
* Returns serverless metadata suitable for mounting in a user-owned router.
|
|
555
573
|
*/
|
|
556
574
|
async #metadataRoute(): Promise<Response> {
|
|
575
|
+
rejectServerless();
|
|
557
576
|
const configured = await this.#activeConfiguredRegistry();
|
|
558
577
|
if (!configured) {
|
|
559
578
|
return new Response("registry not started\n", {
|
|
@@ -626,7 +645,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
626
645
|
*/
|
|
627
646
|
#startEnvoy(config: RegistryConfig, printWelcome: boolean) {
|
|
628
647
|
if (!this.#runtimeServePromise) {
|
|
629
|
-
const configuredEnvoyVersion = this.#config.
|
|
648
|
+
const configuredEnvoyVersion = this.#config.node?.version;
|
|
630
649
|
const envoyVersionSource =
|
|
631
650
|
configuredEnvoyVersion !== undefined
|
|
632
651
|
? "config"
|
|
@@ -637,7 +656,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
637
656
|
logger().info({
|
|
638
657
|
msg: "starting rivetkit envoy",
|
|
639
658
|
rivetkitVersion: VERSION,
|
|
640
|
-
envoyVersion: config.
|
|
659
|
+
envoyVersion: config.node.version,
|
|
641
660
|
envoyVersionSource,
|
|
642
661
|
});
|
|
643
662
|
|
|
@@ -646,8 +665,8 @@ export class Registry<A extends RegistryActors> {
|
|
|
646
665
|
getNodeEnv() === "production"
|
|
647
666
|
) {
|
|
648
667
|
logger().error({
|
|
649
|
-
msg: "
|
|
650
|
-
envoyVersion: config.
|
|
668
|
+
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",
|
|
669
|
+
envoyVersion: config.node.version,
|
|
651
670
|
envoyVersionSource,
|
|
652
671
|
});
|
|
653
672
|
}
|
|
@@ -666,7 +685,13 @@ export class Registry<A extends RegistryActors> {
|
|
|
666
685
|
// rejection unhandled. Downstream awaits (e.g. #runShutdown's
|
|
667
686
|
// Promise.race) attach their own catches and still observe
|
|
668
687
|
// resolution via the race.
|
|
669
|
-
logger().
|
|
688
|
+
logger().error({ error }, "runtime registry serve errored");
|
|
689
|
+
if (
|
|
690
|
+
typeof process !== "undefined" &&
|
|
691
|
+
typeof process.exit === "function"
|
|
692
|
+
) {
|
|
693
|
+
process.exit(1);
|
|
694
|
+
}
|
|
670
695
|
});
|
|
671
696
|
// Install signal handlers once an envoy lifecycle has begun. Only
|
|
672
697
|
// Mode A ever reaches here. Mode B (handler(request)) intentionally
|
|
@@ -714,7 +739,7 @@ export class Registry<A extends RegistryActors> {
|
|
|
714
739
|
finishShutdownSignal(signal);
|
|
715
740
|
return;
|
|
716
741
|
}
|
|
717
|
-
this.#shutdownInFlight = this.#drain(config)
|
|
742
|
+
this.#shutdownInFlight = this.#drain(config, true)
|
|
718
743
|
.catch((err) => {
|
|
719
744
|
logger().warn({ err }, "shutdown error");
|
|
720
745
|
})
|
|
@@ -757,18 +782,28 @@ export class Registry<A extends RegistryActors> {
|
|
|
757
782
|
return this.#shutdownInFlight;
|
|
758
783
|
}
|
|
759
784
|
|
|
760
|
-
async #drain(config: RegistryConfig): Promise<void> {
|
|
785
|
+
async #drain(config: RegistryConfig, signalDriven = false): Promise<void> {
|
|
761
786
|
const modeAPromise = this.#runtimeServeConfiguredPromise;
|
|
762
787
|
const modeBPromise = this.#runtimeServerlessPromise;
|
|
763
788
|
const runtimes = new Set<CoreRuntime>();
|
|
764
789
|
|
|
765
|
-
const
|
|
766
|
-
|
|
767
|
-
(
|
|
768
|
-
|
|
790
|
+
const localDevSignal =
|
|
791
|
+
signalDriven &&
|
|
792
|
+
getNodeEnv() !== "production" &&
|
|
793
|
+
config.engineSpawn &&
|
|
794
|
+
config.endpoint !== undefined &&
|
|
795
|
+
isLocalEngineEndpoint(config.endpoint);
|
|
796
|
+
let gracePeriodMs = config.shutdown?.gracePeriodMs;
|
|
797
|
+
if (gracePeriodMs === undefined) {
|
|
798
|
+
gracePeriodMs = localDevSignal
|
|
799
|
+
? LOCAL_DEV_SHUTDOWN_GRACE_PERIOD_MS
|
|
800
|
+
: ((await this.#actorStopThresholdMs(
|
|
801
|
+
modeAPromise ?? modeBPromise,
|
|
802
|
+
)) ?? 30 * 60 * 1000);
|
|
803
|
+
}
|
|
769
804
|
// Race the entire drain sequence (both modes + serve promise) against
|
|
770
|
-
// a single grace ceiling.
|
|
771
|
-
//
|
|
805
|
+
// a single grace ceiling. Local dev signal shutdowns allow the watcher
|
|
806
|
+
// to restart promptly; other shutdowns use the engine's actor stop threshold.
|
|
772
807
|
const drain = async () => {
|
|
773
808
|
// Shut down every live `CoreRegistry` we know about. Mode A
|
|
774
809
|
// (`start()`) and Mode B (`handler()`) each build a separate
|
|
@@ -887,12 +922,16 @@ export class Registry<A extends RegistryActors> {
|
|
|
887
922
|
);
|
|
888
923
|
}
|
|
889
924
|
if (this.#runtimeReadyPromise) return this.#runtimeReadyPromise;
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
925
|
+
try {
|
|
926
|
+
if (getRivetkitRuntimeMode() === "serverless") {
|
|
927
|
+
return Promise.reject(
|
|
928
|
+
new Error(
|
|
929
|
+
"registry.startAndWait() requires envoy runtime mode; serverless registries become ready per request",
|
|
930
|
+
),
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
} catch (error) {
|
|
934
|
+
return Promise.reject(error);
|
|
896
935
|
}
|
|
897
936
|
|
|
898
937
|
const config = this.parseConfig();
|
|
@@ -910,16 +949,22 @@ export class Registry<A extends RegistryActors> {
|
|
|
910
949
|
throw new Error("registry envoy startup did not initialize");
|
|
911
950
|
}
|
|
912
951
|
|
|
952
|
+
const readyTimeoutMs =
|
|
953
|
+
config.engineSpawn &&
|
|
954
|
+
config.endpoint !== undefined &&
|
|
955
|
+
isLocalEngineEndpoint(config.endpoint)
|
|
956
|
+
? LOCAL_ENGINE_READY_TIMEOUT_MS
|
|
957
|
+
: REGISTRY_READY_TIMEOUT_MS;
|
|
913
958
|
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
914
959
|
const timeoutPromise = new Promise<never>((_resolve, reject) => {
|
|
915
960
|
timeout = setTimeout(
|
|
916
961
|
() =>
|
|
917
962
|
reject(
|
|
918
963
|
new Error(
|
|
919
|
-
`RivetKit registry did not register with the Engine within ${
|
|
964
|
+
`RivetKit registry did not register with the Engine within ${readyTimeoutMs}ms`,
|
|
920
965
|
),
|
|
921
966
|
),
|
|
922
|
-
|
|
967
|
+
readyTimeoutMs,
|
|
923
968
|
);
|
|
924
969
|
timeout.unref?.();
|
|
925
970
|
});
|
|
@@ -481,8 +481,9 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
481
481
|
onCancellationTokenCancelled(
|
|
482
482
|
token: CancellationTokenHandle,
|
|
483
483
|
callback: (...args: unknown[]) => unknown,
|
|
484
|
-
): void {
|
|
485
|
-
asNativeCancellationToken(token).onCancelled(callback);
|
|
484
|
+
): () => void {
|
|
485
|
+
const listener = asNativeCancellationToken(token).onCancelled(callback);
|
|
486
|
+
return () => listener.release();
|
|
486
487
|
}
|
|
487
488
|
|
|
488
489
|
actorState(ctx: ActorContextHandle): Buffer {
|
|
@@ -859,6 +860,13 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
859
860
|
return await this.#actorSql(ctx).exec(sql);
|
|
860
861
|
}
|
|
861
862
|
|
|
863
|
+
actorSqlExecSync(
|
|
864
|
+
ctx: ActorContextHandle,
|
|
865
|
+
sql: string,
|
|
866
|
+
): RuntimeSqlExecResult {
|
|
867
|
+
return this.#actorSql(ctx).execSync(sql);
|
|
868
|
+
}
|
|
869
|
+
|
|
862
870
|
async actorSqlExecute(
|
|
863
871
|
ctx: ActorContextHandle,
|
|
864
872
|
sql: string,
|
|
@@ -871,6 +879,18 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
871
879
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
872
880
|
}
|
|
873
881
|
|
|
882
|
+
actorSqlExecuteSync(
|
|
883
|
+
ctx: ActorContextHandle,
|
|
884
|
+
sql: string,
|
|
885
|
+
params?: RuntimeSqlBindParams,
|
|
886
|
+
): RuntimeSqlExecuteResult {
|
|
887
|
+
const result = this.#actorSql(ctx).executeSync(
|
|
888
|
+
sql,
|
|
889
|
+
toNapiSqlBindParams(params),
|
|
890
|
+
);
|
|
891
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
892
|
+
}
|
|
893
|
+
|
|
874
894
|
async actorSqlExecuteBatch(
|
|
875
895
|
ctx: ActorContextHandle,
|
|
876
896
|
statements: RuntimeSqlBatchStatement[],
|
|
@@ -892,6 +912,17 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
892
912
|
)) as unknown as SqliteTransactionHandle;
|
|
893
913
|
}
|
|
894
914
|
|
|
915
|
+
actorSqlBeginTransactionSync(
|
|
916
|
+
ctx: ActorContextHandle,
|
|
917
|
+
timeoutMs?: number,
|
|
918
|
+
name?: string,
|
|
919
|
+
): SqliteTransactionHandle {
|
|
920
|
+
return this.#actorSql(ctx).beginTransactionSync(
|
|
921
|
+
timeoutMs,
|
|
922
|
+
name,
|
|
923
|
+
) as unknown as SqliteTransactionHandle;
|
|
924
|
+
}
|
|
925
|
+
|
|
895
926
|
async actorSqlTransactionExec(
|
|
896
927
|
transaction: SqliteTransactionHandle,
|
|
897
928
|
sql: string,
|
|
@@ -899,6 +930,13 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
899
930
|
return await asNativeSqlTransaction(transaction).exec(sql);
|
|
900
931
|
}
|
|
901
932
|
|
|
933
|
+
actorSqlTransactionExecSync(
|
|
934
|
+
transaction: SqliteTransactionHandle,
|
|
935
|
+
sql: string,
|
|
936
|
+
): RuntimeSqlExecResult {
|
|
937
|
+
return asNativeSqlTransaction(transaction).execSync(sql);
|
|
938
|
+
}
|
|
939
|
+
|
|
902
940
|
async actorSqlTransactionExecute(
|
|
903
941
|
transaction: SqliteTransactionHandle,
|
|
904
942
|
sql: string,
|
|
@@ -911,17 +949,39 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
911
949
|
return normalizeRuntimeSqlExecuteResult(result);
|
|
912
950
|
}
|
|
913
951
|
|
|
952
|
+
actorSqlTransactionExecuteSync(
|
|
953
|
+
transaction: SqliteTransactionHandle,
|
|
954
|
+
sql: string,
|
|
955
|
+
params?: RuntimeSqlBindParams,
|
|
956
|
+
): RuntimeSqlExecuteResult {
|
|
957
|
+
const result = asNativeSqlTransaction(transaction).executeSync(
|
|
958
|
+
sql,
|
|
959
|
+
toNapiSqlBindParams(params),
|
|
960
|
+
);
|
|
961
|
+
return normalizeRuntimeSqlExecuteResult(result);
|
|
962
|
+
}
|
|
963
|
+
|
|
914
964
|
async actorSqlTransactionCommit(
|
|
915
965
|
transaction: SqliteTransactionHandle,
|
|
916
966
|
): Promise<void> {
|
|
917
967
|
await asNativeSqlTransaction(transaction).commit();
|
|
918
968
|
}
|
|
919
969
|
|
|
970
|
+
actorSqlTransactionCommitSync(transaction: SqliteTransactionHandle): void {
|
|
971
|
+
asNativeSqlTransaction(transaction).commitSync();
|
|
972
|
+
}
|
|
973
|
+
|
|
920
974
|
async actorSqlTransactionRollback(
|
|
921
975
|
transaction: SqliteTransactionHandle,
|
|
922
976
|
): Promise<void> {
|
|
923
977
|
await asNativeSqlTransaction(transaction).rollback();
|
|
924
978
|
}
|
|
979
|
+
|
|
980
|
+
actorSqlTransactionRollbackSync(
|
|
981
|
+
transaction: SqliteTransactionHandle,
|
|
982
|
+
): void {
|
|
983
|
+
asNativeSqlTransaction(transaction).rollbackSync();
|
|
984
|
+
}
|
|
925
985
|
async actorBeginStateTransaction(
|
|
926
986
|
ctx: ActorContextHandle,
|
|
927
987
|
timeoutMs?: number,
|
|
@@ -985,6 +1045,25 @@ export class NapiCoreRuntime implements CoreRuntime {
|
|
|
985
1045
|
return this.#actorSql(ctx).takeLastKvError?.() ?? null;
|
|
986
1046
|
}
|
|
987
1047
|
|
|
1048
|
+
async actorSqlOpen(ctx: ActorContextHandle): Promise<void> {
|
|
1049
|
+
await this.#actorSql(ctx).open();
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
actorSqlCommitTicket(ctx: ActorContextHandle): number {
|
|
1053
|
+
return this.#actorSql(ctx).commitTicket();
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
actorSqlAbortGeneration(ctx: ActorContextHandle, reason: string): void {
|
|
1057
|
+
this.#actorSql(ctx).abortGeneration(reason);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
async actorSqlWhenDurable(
|
|
1061
|
+
ctx: ActorContextHandle,
|
|
1062
|
+
ticket: number,
|
|
1063
|
+
): Promise<void> {
|
|
1064
|
+
await this.#actorSql(ctx).whenDurable(ticket);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
988
1067
|
async actorSqlClose(ctx: ActorContextHandle): Promise<void> {
|
|
989
1068
|
const nativeCtx = asNativeActorContext(ctx);
|
|
990
1069
|
if (!this.#sqlOpened.delete(nativeCtx)) {
|
|
@@ -1285,7 +1364,7 @@ export async function loadNapiRuntime(): Promise<{
|
|
|
1285
1364
|
}> {
|
|
1286
1365
|
// LOAD-BEARING: the specifier is computed (`.join("/")`) on purpose. Do NOT
|
|
1287
1366
|
// "simplify" it to a literal `import("@rivetkit/rivetkit-napi")`. Edge
|
|
1288
|
-
// adapters
|
|
1367
|
+
// adapters pre-bundle this module for Deno; a
|
|
1289
1368
|
// literal dynamic import is statically resolvable, so Deno's eszip bundler
|
|
1290
1369
|
// would snapshot the native `.node` addon into the deploy and 413. The
|
|
1291
1370
|
// computed specifier keeps it opaque to static analysis so it is never
|