rivetkit 0.0.0-main.41efcce → 0.0.0-main.49693dc
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 +939 -104
- package/dist/browser/client.js +1867 -900
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +252 -129
- package/dist/browser/inspector/client.js +2079 -233
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs +6 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +1 -74
- package/dist/tsup/actor/errors.d.ts +1 -74
- package/dist/tsup/actor/errors.js +5 -1
- package/dist/tsup/agent-os/index.cjs +2408 -2029
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +932 -114
- package/dist/tsup/agent-os/index.d.ts +932 -114
- package/dist/tsup/agent-os/index.js +2412 -2033
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-J27CEW6F.js → chunk-2OBVQZX6.js} +6 -6
- package/dist/tsup/chunk-2OBVQZX6.js.map +1 -0
- package/dist/tsup/chunk-3ZWHWMFJ.js +14 -0
- package/dist/tsup/chunk-3ZWHWMFJ.js.map +1 -0
- package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-4KGXFC6M.cjs} +238 -22
- package/dist/tsup/chunk-4KGXFC6M.cjs.map +1 -0
- package/dist/tsup/{chunk-CVHUXINE.js → chunk-5IU3MI7X.js} +594 -72
- package/dist/tsup/chunk-5IU3MI7X.js.map +1 -0
- package/dist/tsup/{chunk-VD7AZIBR.js → chunk-6CXQMHZR.js} +1161 -361
- package/dist/tsup/chunk-6CXQMHZR.js.map +1 -0
- package/dist/tsup/{chunk-SBEFJ4IQ.js → chunk-6W2UIH3X.js} +70 -8
- package/dist/tsup/chunk-6W2UIH3X.js.map +1 -0
- package/dist/tsup/{chunk-7MRGNVSR.js → chunk-6W5VGLFT.js} +237 -21
- package/dist/tsup/chunk-6W5VGLFT.js.map +1 -0
- package/dist/tsup/{chunk-RF3MEJV6.cjs → chunk-B73TBMMG.cjs} +18 -11
- package/dist/tsup/chunk-B73TBMMG.cjs.map +1 -0
- package/dist/tsup/chunk-D6TORRA4.js +243 -0
- package/dist/tsup/chunk-D6TORRA4.js.map +1 -0
- package/dist/tsup/{chunk-PXLJOMJD.js → chunk-FXT3HN32.js} +2 -2
- package/dist/tsup/{chunk-ZGWSH7YV.js → chunk-IXBD7BXC.js} +48 -72
- package/dist/tsup/chunk-IXBD7BXC.js.map +1 -0
- package/dist/tsup/{chunk-3BFYSYRU.js → chunk-JI6GZ2C2.js} +4 -12
- package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JTHHCZCZ.js} +24 -1
- package/dist/tsup/chunk-JTHHCZCZ.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-KVFIONKQ.cjs} +25 -2
- package/dist/tsup/chunk-KVFIONKQ.cjs.map +1 -0
- package/dist/tsup/{chunk-SPMMF6TR.cjs → chunk-LGOWPZJ5.cjs} +3 -3
- package/dist/tsup/chunk-LGOWPZJ5.cjs.map +1 -0
- package/dist/tsup/chunk-LYNWTX6R.cjs +14 -0
- package/dist/tsup/chunk-LYNWTX6R.cjs.map +1 -0
- package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-MYWZCDML.cjs} +4 -12
- package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
- package/dist/tsup/{chunk-XSC2WWXD.js → chunk-NYDZLWHZ.js} +16 -9
- package/dist/tsup/chunk-NYDZLWHZ.js.map +1 -0
- package/dist/tsup/{chunk-AV54CVAG.cjs → chunk-RB7WUDX6.cjs} +1290 -490
- package/dist/tsup/chunk-RB7WUDX6.cjs.map +1 -0
- package/dist/tsup/{chunk-JTL6Y2UN.cjs → chunk-SPJORZMM.cjs} +49 -73
- package/dist/tsup/chunk-SPJORZMM.cjs.map +1 -0
- package/dist/tsup/chunk-SSMKIYEX.cjs +243 -0
- package/dist/tsup/chunk-SSMKIYEX.cjs.map +1 -0
- package/dist/tsup/{chunk-TQSL4NJ3.cjs → chunk-TQ4HSX2U.cjs} +72 -10
- package/dist/tsup/chunk-TQ4HSX2U.cjs.map +1 -0
- package/dist/tsup/{chunk-EVADNK6Z.cjs → chunk-U6ZQELGJ.cjs} +10 -10
- package/dist/tsup/chunk-U6ZQELGJ.cjs.map +1 -0
- package/dist/tsup/chunk-XLBMKZD3.cjs +1257 -0
- package/dist/tsup/chunk-XLBMKZD3.cjs.map +1 -0
- package/dist/tsup/client/mod.cjs +8 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +18 -7
- package/dist/tsup/client/mod.d.ts +18 -7
- package/dist/tsup/client/mod.js +7 -8
- package/dist/tsup/common/log.cjs +5 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +5 -1
- package/dist/tsup/common/log.d.ts +5 -1
- package/dist/tsup/common/log.js +6 -4
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-B3RIidaJ.d.ts → config-BXSV17G7.d.cts} +987 -72
- package/dist/tsup/{config-D6WxBYjV.d.cts → config-Bi1r6gI7.d.ts} +987 -72
- package/dist/tsup/{config-B9qUIHX4.d.ts → config-ey2I2zz5.d.cts} +82 -15
- package/dist/tsup/{config-B9qUIHX4.d.cts → config-ey2I2zz5.d.ts} +82 -15
- package/dist/tsup/context-4fJemY0D.d.cts +129 -0
- package/dist/tsup/context-D4sNYboo.d.ts +129 -0
- package/dist/tsup/db/drizzle.cjs +168 -103
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +8 -4
- package/dist/tsup/db/drizzle.d.ts +8 -4
- package/dist/tsup/db/drizzle.js +170 -105
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +6 -163
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +12 -4
- package/dist/tsup/db/mod.d.ts +12 -4
- package/dist/tsup/db/mod.js +5 -162
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +24 -0
- package/dist/tsup/dynamic/mod.cjs.map +1 -0
- package/dist/tsup/dynamic/mod.d.cts +38 -0
- package/dist/tsup/dynamic/mod.d.ts +38 -0
- package/dist/tsup/dynamic/mod.js +24 -0
- package/dist/tsup/dynamic/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +47 -12
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +26 -136
- package/dist/tsup/inspector/mod.d.ts +26 -136
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector/workflow.cjs +21 -0
- package/dist/tsup/inspector/workflow.cjs.map +1 -0
- package/dist/tsup/inspector/workflow.d.cts +144 -0
- package/dist/tsup/inspector/workflow.d.ts +144 -0
- package/dist/tsup/inspector/workflow.js +21 -0
- package/dist/tsup/inspector/workflow.js.map +1 -0
- package/dist/tsup/inspector-tab/mod.cjs +162 -0
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -0
- package/dist/tsup/inspector-tab/mod.d.cts +241 -0
- package/dist/tsup/inspector-tab/mod.d.ts +241 -0
- package/dist/tsup/inspector-tab/mod.js +162 -0
- package/dist/tsup/inspector-tab/mod.js.map +1 -0
- package/dist/tsup/mod.cjs +4268 -944
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +9 -8
- package/dist/tsup/mod.d.ts +9 -8
- package/dist/tsup/mod.js +4229 -905
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +26 -21
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +7 -6
- package/dist/tsup/test/mod.d.ts +7 -6
- package/dist/tsup/test/mod.js +25 -20
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/unstable/migrations.cjs +101 -0
- package/dist/tsup/unstable/migrations.cjs.map +1 -0
- package/dist/tsup/unstable/migrations.d.cts +29 -0
- package/dist/tsup/unstable/migrations.d.ts +29 -0
- package/dist/tsup/unstable/migrations.js +101 -0
- package/dist/tsup/unstable/migrations.js.map +1 -0
- package/dist/tsup/utils-Bbz-3411.d.cts +162 -0
- package/dist/tsup/utils-BqdWVlzm.d.ts +162 -0
- package/dist/tsup/utils-vvJQyygr.d.cts +109 -0
- package/dist/tsup/utils-vvJQyygr.d.ts +109 -0
- package/dist/tsup/utils.cjs +7 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +4 -147
- package/dist/tsup/utils.d.ts +4 -147
- package/dist/tsup/utils.js +6 -2
- package/dist/tsup/workflow/mod.cjs +517 -412
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +11 -10
- package/dist/tsup/workflow/mod.d.ts +11 -10
- package/dist/tsup/workflow/mod.js +511 -406
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +62 -14
- package/src/actor/actions.ts +119 -0
- package/src/actor/config.test.ts +78 -0
- package/src/actor/config.ts +518 -96
- package/src/actor/contexts/index.ts +7 -2
- package/src/actor/definition.ts +38 -26
- package/src/actor/errors.ts +101 -89
- package/src/actor/keys.ts +2 -1
- package/src/actor/mod.ts +32 -21
- package/src/actor/schema.ts +2 -2
- package/src/agent-os/actor/cron.ts +37 -2
- package/src/agent-os/actor/index.ts +39 -19
- package/src/agent-os/actor/preview.ts +1 -2
- package/src/agent-os/actor/session.ts +2 -2
- package/src/agent-os/config.ts +1 -1
- package/src/agent-os/fs/database-vfs.ts +1 -1
- package/src/agent-os/index.ts +16 -15
- package/src/agent-os/types.ts +11 -0
- package/src/client/actor-common.ts +106 -53
- package/src/client/actor-conn.ts +94 -45
- package/src/client/actor-handle.ts +198 -79
- package/src/client/actor-query.ts +13 -6
- package/src/client/client.ts +43 -15
- package/src/client/config.ts +8 -0
- package/src/client/errors.ts +4 -2
- package/src/client/lifecycle-errors.ts +28 -4
- package/src/client/mod.ts +9 -4
- package/src/client/query.ts +3 -1
- package/src/client/queue.ts +8 -3
- package/src/client/raw-utils.ts +24 -16
- package/src/client/resolve-gateway-target.ts +3 -1
- package/src/client/utils.ts +36 -10
- package/src/common/actor-router-consts.ts +7 -0
- package/src/common/actor-websocket.ts +3 -1
- package/src/common/bare/actor-persist/v1.ts +205 -163
- package/src/common/bare/actor-persist/v2.ts +265 -213
- package/src/common/bare/actor-persist/v3.ts +176 -172
- package/src/common/bare/actor-persist/v4.ts +254 -253
- package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
- package/src/common/bare/generated/client-protocol/v4.ts +599 -0
- package/src/common/bare/generated/inspector/v5.ts +1016 -0
- package/src/common/bare/generated/inspector/v6.ts +1367 -0
- package/src/common/bare/transport/v1.ts +694 -542
- package/src/common/client-protocol-versioned.ts +176 -67
- package/src/common/client-protocol-zod.ts +7 -0
- package/src/common/client-protocol.ts +1 -1
- package/src/common/database/config.ts +103 -10
- package/src/common/database/mod.test.ts +364 -0
- package/src/common/database/mod.ts +278 -149
- package/src/common/database/native-database.test.ts +220 -0
- package/src/common/database/native-database.ts +394 -58
- package/src/common/database/shared.ts +25 -0
- package/src/common/encoding.ts +302 -38
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/fetch-like.ts +49 -0
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/inspector-transport.ts +12 -2
- package/src/common/log.ts +117 -14
- package/src/common/router.ts +49 -23
- package/src/common/utils.ts +23 -203
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/drizzle.test.ts +164 -0
- package/src/db/drizzle.ts +207 -121
- package/src/db/mod.ts +6 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +64 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-client/actor-http-client.ts +23 -4
- package/src/engine-client/actor-websocket-client.ts +32 -5
- package/src/engine-client/api-endpoints.ts +52 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +21 -17
- package/src/engine-client/mod.ts +116 -64
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/globals.d.ts +4 -0
- package/src/inspector/client.browser.ts +127 -15
- package/src/inspector/mod.ts +2 -4
- package/src/inspector/workflow.ts +61 -0
- package/src/inspector-tab/mod.ts +301 -0
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.ts +160 -53
- package/src/registry/config/serverless.ts +7 -1
- package/src/registry/index.ts +659 -96
- package/src/registry/napi-runtime.ts +1154 -0
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +2005 -955
- package/src/registry/process-metrics.ts +250 -0
- package/src/registry/run-handler-coordinator.test.ts +252 -0
- package/src/registry/run-handler-coordinator.ts +219 -0
- package/src/registry/runtime.test.ts +50 -0
- package/src/registry/runtime.ts +839 -0
- package/src/registry/wasm-runtime.ts +1283 -0
- package/src/registry/write-through-proxy.ts +141 -0
- package/src/serde.ts +8 -2
- package/src/serverless/configure.ts +102 -49
- package/src/test/mod.ts +2 -17
- package/src/test/ready.ts +22 -0
- package/src/unstable/migrations.test.ts +170 -0
- package/src/unstable/migrations.ts +141 -0
- package/src/utils/crypto.ts +14 -0
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +39 -0
- package/src/utils/node.ts +44 -28
- package/src/utils/router.ts +1 -1
- package/src/utils.ts +4 -2
- package/src/workflow/context.ts +683 -242
- package/src/workflow/driver.test.ts +62 -0
- package/src/workflow/driver.ts +246 -119
- package/src/workflow/inspector.ts +24 -24
- package/src/workflow/mod.ts +76 -84
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
- package/dist/tsup/chunk-6AVUJ52Q.cjs +0 -253
- package/dist/tsup/chunk-6AVUJ52Q.cjs.map +0 -1
- package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
- package/dist/tsup/chunk-7X7RVTFF.cjs +0 -735
- package/dist/tsup/chunk-7X7RVTFF.cjs.map +0 -1
- package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
- package/dist/tsup/chunk-AV54CVAG.cjs.map +0 -1
- package/dist/tsup/chunk-CVHUXINE.js.map +0 -1
- package/dist/tsup/chunk-EVADNK6Z.cjs.map +0 -1
- package/dist/tsup/chunk-J27CEW6F.js.map +0 -1
- package/dist/tsup/chunk-JTL6Y2UN.cjs.map +0 -1
- package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-RF3MEJV6.cjs.map +0 -1
- package/dist/tsup/chunk-SB4MXRN2.js +0 -253
- package/dist/tsup/chunk-SB4MXRN2.js.map +0 -1
- package/dist/tsup/chunk-SBEFJ4IQ.js.map +0 -1
- package/dist/tsup/chunk-SPMMF6TR.cjs.map +0 -1
- package/dist/tsup/chunk-TQSL4NJ3.cjs.map +0 -1
- package/dist/tsup/chunk-VD7AZIBR.js.map +0 -1
- package/dist/tsup/chunk-XSC2WWXD.js.map +0 -1
- package/dist/tsup/chunk-ZGWSH7YV.js.map +0 -1
- package/dist/tsup/context-BxvHh9wi.d.cts +0 -92
- package/dist/tsup/context-CNIZBIKl.d.ts +0 -92
- package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
- package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2501
- package/src/drivers/engine/actor-driver.ts +0 -2470
- package/src/utils/serve.ts +0 -217
- /package/dist/tsup/{chunk-PXLJOMJD.js.map → chunk-FXT3HN32.js.map} +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { RawAccess } from "@/common/database/config";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_MIGRATION_TABLE_NAME = "rivetkit_schema_version";
|
|
4
|
+
|
|
5
|
+
export type MigrationDatabase = Pick<RawAccess, "execute">;
|
|
6
|
+
|
|
7
|
+
export type Migration =
|
|
8
|
+
| {
|
|
9
|
+
version: number;
|
|
10
|
+
sql: string;
|
|
11
|
+
up?: never;
|
|
12
|
+
}
|
|
13
|
+
| {
|
|
14
|
+
version: number;
|
|
15
|
+
sql?: never;
|
|
16
|
+
up: (db: MigrationDatabase) => Promise<void> | void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export interface MigrationsOptions {
|
|
20
|
+
/** A table owned by this schema. Override this when multiple schemas share a database. */
|
|
21
|
+
tableName?: string;
|
|
22
|
+
/** Detect the version of a schema that predates its migration table. */
|
|
23
|
+
adopt?: (db: MigrationDatabase) => Promise<number> | number;
|
|
24
|
+
/** Contiguous migrations numbered from 1. */
|
|
25
|
+
migrations: readonly Migration[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates an `onMigrate` callback that applies each unapplied migration in order.
|
|
30
|
+
* RivetKit runs the callback inside its migration savepoint, making the complete
|
|
31
|
+
* ladder atomic when used with `db({ onMigrate })`.
|
|
32
|
+
*/
|
|
33
|
+
export function migrations({
|
|
34
|
+
tableName = DEFAULT_MIGRATION_TABLE_NAME,
|
|
35
|
+
adopt,
|
|
36
|
+
migrations: ladder,
|
|
37
|
+
}: MigrationsOptions): (db: MigrationDatabase) => Promise<void> {
|
|
38
|
+
validateTableName(tableName);
|
|
39
|
+
validateLadder(ladder);
|
|
40
|
+
|
|
41
|
+
return async (database) => {
|
|
42
|
+
const quotedTableName = `"${tableName}"`;
|
|
43
|
+
await database.execute(`
|
|
44
|
+
CREATE TABLE IF NOT EXISTS ${quotedTableName} (
|
|
45
|
+
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
46
|
+
schema_version INTEGER NOT NULL CHECK (
|
|
47
|
+
schema_version BETWEEN 0 AND ${Number.MAX_SAFE_INTEGER}
|
|
48
|
+
)
|
|
49
|
+
) STRICT
|
|
50
|
+
`);
|
|
51
|
+
|
|
52
|
+
const rows = await database.execute<{ schema_version: unknown }>(
|
|
53
|
+
`SELECT schema_version FROM ${quotedTableName} WHERE singleton = 1`,
|
|
54
|
+
);
|
|
55
|
+
if (rows.length > 1) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`invalid migration table "${tableName}": expected at most one version row, received ${rows.length}`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const rawCurrent = rows[0]?.schema_version;
|
|
62
|
+
let current = rows.length === 0 ? 0 : rawCurrent;
|
|
63
|
+
if (rows.length === 0 && adopt) {
|
|
64
|
+
current = await adopt(database);
|
|
65
|
+
}
|
|
66
|
+
if (
|
|
67
|
+
typeof current !== "number" ||
|
|
68
|
+
!Number.isSafeInteger(current) ||
|
|
69
|
+
current < 0
|
|
70
|
+
) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`invalid schema version ${String(current)} in migration table "${tableName}"`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (current > ladder.length) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
`migration version ${current} in "${tableName}" is newer than supported version ${ladder.length}`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
if (rows.length === 0 && current > 0) {
|
|
81
|
+
await writeVersion(database, quotedTableName, current);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
for (const migration of ladder.slice(current)) {
|
|
85
|
+
if (migration.sql !== undefined) {
|
|
86
|
+
await database.execute(migration.sql);
|
|
87
|
+
} else {
|
|
88
|
+
await migration.up(database);
|
|
89
|
+
}
|
|
90
|
+
await writeVersion(database, quotedTableName, migration.version);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function writeVersion(
|
|
96
|
+
database: MigrationDatabase,
|
|
97
|
+
quotedTableName: string,
|
|
98
|
+
version: number,
|
|
99
|
+
): Promise<void> {
|
|
100
|
+
await database.execute(
|
|
101
|
+
`INSERT INTO ${quotedTableName} (singleton, schema_version)
|
|
102
|
+
VALUES (1, ?)
|
|
103
|
+
ON CONFLICT(singleton) DO UPDATE SET schema_version = excluded.schema_version`,
|
|
104
|
+
version,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function validateTableName(tableName: string): void {
|
|
109
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(tableName)) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
`invalid migration table name "${tableName}": expected a SQLite identifier`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function validateLadder(ladder: readonly Migration[]): void {
|
|
117
|
+
if (ladder.length === 0) {
|
|
118
|
+
throw new Error("migration ladder must not be empty");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
for (const [index, migration] of ladder.entries()) {
|
|
122
|
+
const expectedVersion = index + 1;
|
|
123
|
+
if (migration.version !== expectedVersion) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
`invalid migration ladder: expected version ${expectedVersion}, received ${migration.version}`,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
const hasSql = typeof migration.sql === "string";
|
|
129
|
+
const hasUp = typeof migration.up === "function";
|
|
130
|
+
if (hasSql === hasUp) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`invalid migration ${migration.version}: expected exactly one of sql or up`,
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
if (hasSql && migration.sql.trim().length === 0) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`invalid migration ${migration.version}: SQL is empty`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
package/src/utils/crypto.ts
CHANGED
|
@@ -22,3 +22,17 @@ export function timingSafeEqual(
|
|
|
22
22
|
|
|
23
23
|
return result === 0;
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
export async function sha256Hex(value: string): Promise<string> {
|
|
27
|
+
if (!globalThis.crypto?.subtle) {
|
|
28
|
+
throw new Error("Web Crypto API is required to compute SHA-256 hashes");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const digest = await globalThis.crypto.subtle.digest(
|
|
32
|
+
"SHA-256",
|
|
33
|
+
new TextEncoder().encode(value),
|
|
34
|
+
);
|
|
35
|
+
return Array.from(new Uint8Array(digest), (byte) =>
|
|
36
|
+
byte.toString(16).padStart(2, "0"),
|
|
37
|
+
).join("");
|
|
38
|
+
}
|
package/src/utils/env-vars.ts
CHANGED
|
@@ -22,6 +22,12 @@ export const getRivetTotalSlots = (): number | undefined => {
|
|
|
22
22
|
};
|
|
23
23
|
export const getRivetRunEngine = (): boolean =>
|
|
24
24
|
getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
25
|
+
export const getRivetRunEngineHost = (): string | undefined =>
|
|
26
|
+
getEnvUniversal("RIVET_RUN_ENGINE_HOST");
|
|
27
|
+
export const getRivetRunEnginePort = (): number | undefined => {
|
|
28
|
+
const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
|
|
29
|
+
return value !== undefined ? parseInt(value, 10) : undefined;
|
|
30
|
+
};
|
|
25
31
|
export const getRivetRunEngineVersion = (): string | undefined =>
|
|
26
32
|
getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
27
33
|
export const getRivetEnvoyKind = (): string | undefined =>
|
|
@@ -42,6 +48,39 @@ export const getRivetkitInspectorDisable = (): boolean =>
|
|
|
42
48
|
getEnvUniversal("RIVET_INSPECTOR_DISABLE") === "1";
|
|
43
49
|
export const getRivetkitStoragePath = (): string | undefined =>
|
|
44
50
|
getEnvUniversal("RIVETKIT_STORAGE_PATH");
|
|
51
|
+
export const getRivetkitRuntime = (): string | undefined =>
|
|
52
|
+
getEnvUniversal("RIVETKIT_RUNTIME");
|
|
53
|
+
export type RuntimeMode = "envoy" | "serverless";
|
|
54
|
+
|
|
55
|
+
export const getRivetkitRuntimeMode = (): RuntimeMode => {
|
|
56
|
+
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
57
|
+
if (value === undefined) return "envoy";
|
|
58
|
+
if (value === "envoy" || value === "serverless") return value;
|
|
59
|
+
throw new Error(
|
|
60
|
+
`RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`,
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const getRivetkitPublicDir = (): string | undefined => {
|
|
65
|
+
const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
|
|
66
|
+
return value === undefined || value === "" ? undefined : value;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export function parsePortEnv(raw: string | undefined): number | undefined {
|
|
70
|
+
if (raw === undefined || raw === "") return undefined;
|
|
71
|
+
const parsed = Number.parseInt(raw, 10);
|
|
72
|
+
if (
|
|
73
|
+
!Number.isFinite(parsed) ||
|
|
74
|
+
parsed < 1 ||
|
|
75
|
+
parsed > 65535 ||
|
|
76
|
+
String(parsed) !== raw.trim()
|
|
77
|
+
) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return parsed;
|
|
83
|
+
}
|
|
45
84
|
|
|
46
85
|
// Logging configuration
|
|
47
86
|
// DEPRECATED: LOG_LEVEL will be removed in a future version
|
package/src/utils/node.ts
CHANGED
|
@@ -19,20 +19,35 @@ let nodeStream: typeof import("node:stream/promises") | undefined;
|
|
|
19
19
|
let nodeUrl: typeof import("node:url") | undefined;
|
|
20
20
|
|
|
21
21
|
let hasImportedDependencies = false;
|
|
22
|
+
type NodeBuiltin = `node:${string}`;
|
|
23
|
+
let fallbackRequire: ReturnType<typeof createRequire> | undefined;
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Loads a Node.js built-in synchronously without relying on `import.meta`,
|
|
27
|
+
* which esbuild cannot preserve in CommonJS output. Prefer Node's dedicated
|
|
28
|
+
* built-in loader and retain `createRequire` for Node 22.0-22.2 compatibility.
|
|
29
|
+
*
|
|
30
|
+
* @see https://nodejs.org/api/process.html#processgetbuiltinmoduleid
|
|
31
|
+
* @see https://github.com/evanw/esbuild/issues/1492
|
|
32
|
+
*/
|
|
33
|
+
export function loadNodeBuiltin<T>(id: NodeBuiltin): T {
|
|
34
|
+
const nodeProcess = globalThis.process;
|
|
35
|
+
const builtin = nodeProcess?.getBuiltinModule?.(id);
|
|
36
|
+
|
|
37
|
+
if (builtin !== undefined) {
|
|
38
|
+
return builtin as T;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!nodeProcess?.execPath) {
|
|
42
|
+
throw new Error("Node.js built-ins are not available");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Node 22.0-22.2 does not provide getBuiltinModule(). Avoid import.meta here:
|
|
46
|
+
// esbuild replaces it with an empty shim in CommonJS output, leaving
|
|
47
|
+
// import_meta.url undefined. This loader only resolves built-ins, so the
|
|
48
|
+
// fallback base does not affect package resolution.
|
|
49
|
+
fallbackRequire ??= createRequire(nodeProcess.execPath);
|
|
50
|
+
return fallbackRequire(id) as T;
|
|
36
51
|
}
|
|
37
52
|
|
|
38
53
|
/**
|
|
@@ -48,22 +63,23 @@ export function importNodeDependencies(): void {
|
|
|
48
63
|
if (hasImportedDependencies) return;
|
|
49
64
|
|
|
50
65
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
nodePath =
|
|
59
|
-
nodeOs =
|
|
60
|
-
nodeChildProcess =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
nodeCrypto =
|
|
67
|
+
loadNodeBuiltin<typeof import("node:crypto")>("node:crypto");
|
|
68
|
+
nodeFsSync = loadNodeBuiltin<typeof import("node:fs")>("node:fs");
|
|
69
|
+
nodeFs =
|
|
70
|
+
loadNodeBuiltin<typeof import("node:fs/promises")>(
|
|
71
|
+
"node:fs/promises",
|
|
72
|
+
);
|
|
73
|
+
nodePath = loadNodeBuiltin<typeof import("node:path")>("node:path");
|
|
74
|
+
nodeOs = loadNodeBuiltin<typeof import("node:os")>("node:os");
|
|
75
|
+
nodeChildProcess =
|
|
76
|
+
loadNodeBuiltin<typeof import("node:child_process")>(
|
|
77
|
+
"node:child_process",
|
|
78
|
+
);
|
|
79
|
+
nodeStream = loadNodeBuiltin<typeof import("node:stream/promises")>(
|
|
80
|
+
"node:stream/promises",
|
|
65
81
|
);
|
|
66
|
-
nodeUrl =
|
|
82
|
+
nodeUrl = loadNodeBuiltin<typeof import("node:url")>("node:url");
|
|
67
83
|
hasImportedDependencies = true;
|
|
68
84
|
} catch (err) {
|
|
69
85
|
console.warn(
|
package/src/utils/router.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { OpenAPIHono } from "@hono/zod-openapi";
|
|
|
2
2
|
import type { Hono } from "hono";
|
|
3
3
|
import { createMiddleware } from "hono/factory";
|
|
4
4
|
import { cors } from "@/common/cors";
|
|
5
|
+
import { getLogger } from "@/common/log";
|
|
5
6
|
import {
|
|
6
7
|
handleRouteError,
|
|
7
8
|
handleRouteNotFound,
|
|
8
9
|
loggerMiddleware,
|
|
9
10
|
} from "@/common/router";
|
|
10
|
-
import { getLogger } from "@/common/log";
|
|
11
11
|
|
|
12
12
|
export function logger() {
|
|
13
13
|
return getLogger("router");
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { stringifyError } from "@/common/utils";
|
|
2
1
|
import type { Context as HonoContext, Handler as HonoHandler } from "hono";
|
|
3
|
-
import {
|
|
2
|
+
import { stringifyError } from "@/common/utils";
|
|
4
3
|
import pkgJson from "../package.json" with { type: "json" };
|
|
5
4
|
import { getLogger } from "./common/log";
|
|
6
5
|
import { assertUnreachable } from "./common/utils";
|
|
@@ -11,6 +10,9 @@ export { stringifyError };
|
|
|
11
10
|
/** @experimental */
|
|
12
11
|
export { assertUnreachable };
|
|
13
12
|
|
|
13
|
+
/** @experimental */
|
|
14
|
+
export { jsonParseCompat, jsonStringifyCompat } from "./common/encoding";
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* Joins multiple abort signals into one.
|
|
16
18
|
*
|