rivetkit 0.0.0-skip-ready-wait-flatten-client-options.1cae221 → 0.0.0-sqlite-uds.ea644f1
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 +561 -89
- package/dist/browser/client.js +1063 -430
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +22 -2
- package/dist/browser/inspector/client.js +1036 -232
- 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 +2232 -2082
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +556 -85
- package/dist/tsup/agent-os/index.d.ts +556 -85
- package/dist/tsup/agent-os/index.js +2234 -2084
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-7MRGNVSR.js → chunk-3GLNEWGY.js} +78 -6
- package/dist/tsup/chunk-3GLNEWGY.js.map +1 -0
- package/dist/tsup/{chunk-V3QNBJ7N.cjs → chunk-4FC7TVS6.cjs} +35 -10
- package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -0
- package/dist/tsup/{chunk-XNZR7UD2.cjs → chunk-7DDQA6KN.cjs} +90 -65
- package/dist/tsup/chunk-7DDQA6KN.cjs.map +1 -0
- package/dist/tsup/{chunk-NFC5VU36.cjs → chunk-AESHILFV.cjs} +18 -10
- package/dist/tsup/chunk-AESHILFV.cjs.map +1 -0
- package/dist/tsup/{chunk-D4TSTM6C.js → chunk-EFQCNJ23.js} +83 -58
- package/dist/tsup/chunk-EFQCNJ23.js.map +1 -0
- package/dist/tsup/{chunk-OIKOPSXQ.js → chunk-FUS4OFX5.js} +12 -4
- package/dist/tsup/chunk-FUS4OFX5.js.map +1 -0
- package/dist/tsup/{chunk-IOYKCB6Y.cjs → chunk-GUCITCR3.cjs} +44 -9
- package/dist/tsup/chunk-GUCITCR3.cjs.map +1 -0
- package/dist/tsup/{chunk-3BFYSYRU.js → chunk-HXUEHHJF.js} +3 -2
- package/dist/tsup/chunk-HXUEHHJF.js.map +1 -0
- package/dist/tsup/{chunk-PCBNKI2J.js → chunk-JZ7TWV65.js} +1 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +1 -0
- package/dist/tsup/{chunk-KSG2COSQ.js → chunk-KYBAXJRA.js} +6 -6
- package/dist/tsup/chunk-KYBAXJRA.js.map +1 -0
- package/dist/tsup/{chunk-LNMB25HW.js → chunk-LMUEIJUM.js} +780 -183
- package/dist/tsup/chunk-LMUEIJUM.js.map +1 -0
- package/dist/tsup/{chunk-RZEJJJKU.js → chunk-LTMSYD2A.js} +42 -7
- package/dist/tsup/chunk-LTMSYD2A.js.map +1 -0
- package/dist/tsup/{chunk-AK57AL7S.cjs → chunk-OAPVVVTX.cjs} +79 -7
- package/dist/tsup/chunk-OAPVVVTX.cjs.map +1 -0
- package/dist/tsup/{chunk-D2TLG75Y.cjs → chunk-TIUL6FNF.cjs} +10 -10
- package/dist/tsup/chunk-TIUL6FNF.cjs.map +1 -0
- package/dist/tsup/{chunk-POTPHU3P.cjs → chunk-UYT2CIWO.cjs} +3 -3
- package/dist/tsup/{chunk-POTPHU3P.cjs.map → chunk-UYT2CIWO.cjs.map} +1 -1
- package/dist/tsup/{chunk-TPBHXFB2.cjs → chunk-VDTC257X.cjs} +138 -24
- package/dist/tsup/chunk-VDTC257X.cjs.map +1 -0
- package/dist/tsup/{chunk-LLD2D5LO.cjs → chunk-VE2X4KMG.cjs} +3 -2
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +1 -0
- package/dist/tsup/{chunk-22XU3BVY.cjs → chunk-VWOA7DRK.cjs} +925 -328
- package/dist/tsup/chunk-VWOA7DRK.cjs.map +1 -0
- package/dist/tsup/{chunk-4ZIWB4CQ.js → chunk-VYQASICJ.js} +2 -2
- package/dist/tsup/{chunk-W54QCENI.js → chunk-X4BXYDTG.js} +134 -20
- package/dist/tsup/chunk-X4BXYDTG.js.map +1 -0
- package/dist/tsup/{chunk-2NDZ7JCR.cjs → chunk-ZA7FLHKH.cjs} +1 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -0
- package/dist/tsup/{chunk-K34B3OVG.js → chunk-ZZ3WBRPD.js} +34 -9
- package/dist/tsup/chunk-ZZ3WBRPD.js.map +1 -0
- package/dist/tsup/client/mod.cjs +9 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +8 -9
- package/dist/tsup/client/mod.d.ts +8 -9
- package/dist/tsup/client/mod.js +8 -8
- package/dist/tsup/common/log.cjs +5 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +5 -1
- package/dist/tsup/common/log.d.ts +5 -1
- package/dist/tsup/common/log.js +6 -4
- package/dist/tsup/common/websocket.cjs +4 -4
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-CRdGwwbr.d.cts → config-CxG53eQo.d.cts} +577 -36
- package/dist/tsup/{config-kxXbtrJU.d.ts → config-DLOxy81E.d.cts} +5 -5
- package/dist/tsup/{config-kxXbtrJU.d.cts → config-DLOxy81E.d.ts} +5 -5
- package/dist/tsup/{config-DIpBWm5C.d.ts → config-Ds6DCRhV.d.ts} +577 -36
- package/dist/tsup/context-8KlcOYIs.d.cts +129 -0
- package/dist/tsup/context-Cfbm4QLr.d.ts +129 -0
- package/dist/tsup/db/drizzle.cjs +164 -78
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +4 -2
- package/dist/tsup/db/drizzle.d.ts +4 -2
- package/dist/tsup/db/drizzle.js +164 -78
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +93 -24
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +2 -2
- package/dist/tsup/db/mod.d.ts +2 -2
- package/dist/tsup/db/mod.js +92 -23
- 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 +37 -0
- package/dist/tsup/dynamic/mod.d.ts +37 -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 +37 -15
- package/dist/tsup/inspector/mod.d.ts +37 -15
- package/dist/tsup/inspector/mod.js +46 -11
- package/dist/tsup/inspector/mod.js.map +1 -1
- 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 +240 -0
- package/dist/tsup/inspector-tab/mod.d.ts +240 -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 +1078 -479
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +5 -6
- package/dist/tsup/mod.d.ts +5 -6
- package/dist/tsup/mod.js +996 -397
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +21 -18
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +4 -5
- package/dist/tsup/test/mod.d.ts +4 -5
- package/dist/tsup/test/mod.js +18 -15
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils-CqDnC_PS.d.cts +104 -0
- package/dist/tsup/utils-CqDnC_PS.d.ts +104 -0
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.d.cts +1 -1
- package/dist/tsup/utils.d.ts +1 -1
- package/dist/tsup/utils.js +2 -2
- package/dist/tsup/workflow/mod.cjs +386 -322
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +8 -9
- package/dist/tsup/workflow/mod.d.ts +8 -9
- package/dist/tsup/workflow/mod.js +363 -299
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +35 -14
- package/src/actor/config.ts +188 -59
- package/src/actor/contexts/index.ts +7 -2
- package/src/actor/definition.ts +17 -19
- package/src/actor/driver.ts +3 -3
- package/src/actor/errors.ts +70 -7
- package/src/actor/instance/mod.ts +39 -56
- package/src/actor/keys.ts +2 -1
- package/src/actor/mod.ts +22 -20
- package/src/actor/schema.ts +2 -2
- package/src/agent-os/actor/index.ts +38 -18
- 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/client/actor-common.ts +88 -62
- package/src/client/actor-conn.ts +58 -63
- package/src/client/actor-handle.ts +125 -71
- package/src/client/actor-query.ts +5 -5
- package/src/client/config.ts +3 -3
- package/src/client/errors.ts +2 -1
- package/src/client/lifecycle-errors.ts +2 -4
- package/src/client/query.ts +1 -1
- package/src/client/queue.ts +8 -3
- package/src/client/raw-utils.ts +10 -10
- package/src/client/resolve-gateway-target.ts +1 -1
- package/src/client/utils.ts +34 -10
- package/src/common/actor-router-consts.ts +7 -4
- 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-uds-protocol/v1.ts +802 -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/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 +16 -5
- package/src/common/database/mod.test.ts +137 -16
- package/src/common/database/mod.ts +100 -30
- package/src/common/database/native-database.test.ts +35 -22
- package/src/common/database/native-database.ts +26 -10
- package/src/common/database/shared.ts +1 -0
- package/src/common/encoding.ts +250 -16
- package/src/common/engine.ts +28 -1
- package/src/common/eventsource.ts +1 -1
- package/src/common/inline-websocket-adapter.ts +14 -13
- package/src/common/log.ts +15 -8
- package/src/common/router.ts +49 -23
- package/src/common/utils.ts +10 -202
- package/src/common/websocket-interface.ts +1 -1
- package/src/db/drizzle.ts +194 -95
- package/src/db/mod.ts +1 -1
- package/src/devtools-loader/index.ts +4 -7
- package/src/devtools-loader/serve-devtools.ts +26 -0
- package/src/drivers/engine/actor-driver.ts +76 -73
- package/src/dynamic/instance.ts +32 -0
- package/src/dynamic/internal.ts +50 -0
- package/src/dynamic/isolate-runtime.ts +66 -0
- package/src/dynamic/mod.ts +32 -0
- package/src/engine-client/actor-http-client.ts +6 -9
- package/src/engine-client/actor-websocket-client.ts +14 -13
- package/src/engine-client/api-endpoints.ts +51 -2
- package/src/engine-client/api-utils.ts +2 -2
- package/src/engine-client/driver.ts +3 -4
- package/src/engine-client/mod.ts +17 -10
- package/src/engine-client/ws-proxy.ts +9 -4
- package/src/inspector/client.browser.ts +66 -15
- package/src/inspector/mod.ts +2 -4
- package/src/inspector-tab/mod.ts +300 -0
- package/src/registry/config/envoy.ts +1 -2
- package/src/registry/config/index.ts +46 -20
- package/src/registry/index.ts +364 -87
- package/src/registry/napi-runtime.ts +97 -8
- package/src/registry/native-validation.ts +10 -12
- package/src/registry/native.ts +592 -343
- package/src/registry/process-metrics.ts +250 -0
- package/src/registry/runtime.ts +85 -6
- package/src/registry/wasm-runtime.ts +72 -3
- package/src/registry/write-through-proxy.ts +40 -0
- package/src/serde.ts +2 -2
- package/src/serverless/configure.ts +19 -8
- package/src/test/mod.ts +11 -8
- package/src/utils/crypto.ts +14 -0
- package/src/utils/endpoint-parser.ts +1 -1
- package/src/utils/env-vars.ts +37 -0
- package/src/utils/router.ts +1 -1
- package/src/utils.ts +1 -2
- package/src/workflow/context.ts +703 -240
- package/src/workflow/driver.ts +23 -12
- package/src/workflow/inspector.ts +12 -3
- package/src/workflow/mod.ts +37 -23
- package/dist/tsup/chunk-22XU3BVY.cjs.map +0 -1
- package/dist/tsup/chunk-2NDZ7JCR.cjs.map +0 -1
- package/dist/tsup/chunk-3BFYSYRU.js.map +0 -1
- package/dist/tsup/chunk-7MRGNVSR.js.map +0 -1
- package/dist/tsup/chunk-AK57AL7S.cjs.map +0 -1
- package/dist/tsup/chunk-D2TLG75Y.cjs.map +0 -1
- package/dist/tsup/chunk-D4TSTM6C.js.map +0 -1
- package/dist/tsup/chunk-IOYKCB6Y.cjs.map +0 -1
- package/dist/tsup/chunk-K34B3OVG.js.map +0 -1
- package/dist/tsup/chunk-KSG2COSQ.js.map +0 -1
- package/dist/tsup/chunk-LLD2D5LO.cjs.map +0 -1
- package/dist/tsup/chunk-LNMB25HW.js.map +0 -1
- package/dist/tsup/chunk-NFC5VU36.cjs.map +0 -1
- package/dist/tsup/chunk-OIKOPSXQ.js.map +0 -1
- package/dist/tsup/chunk-PCBNKI2J.js.map +0 -1
- package/dist/tsup/chunk-RZEJJJKU.js.map +0 -1
- package/dist/tsup/chunk-TPBHXFB2.cjs.map +0 -1
- package/dist/tsup/chunk-V3QNBJ7N.cjs.map +0 -1
- package/dist/tsup/chunk-W54QCENI.js.map +0 -1
- package/dist/tsup/chunk-XNZR7UD2.cjs.map +0 -1
- package/dist/tsup/context-B7G6sk7x.d.ts +0 -92
- package/dist/tsup/context-DzMRHkjC.d.cts +0 -92
- package/dist/tsup/utils-fwx3o3K9.d.cts +0 -18
- package/dist/tsup/utils-fwx3o3K9.d.ts +0 -18
- package/src/utils/serve.ts +0 -217
- /package/dist/tsup/{chunk-4ZIWB4CQ.js.map → chunk-VYQASICJ.js.map} +0 -0
package/src/common/utils.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Next } from "hono";
|
|
2
2
|
import type { ContentfulStatusCode } from "hono/utils/http-status";
|
|
3
3
|
import * as errors from "@/actor/errors";
|
|
4
|
-
import { EXTRA_ERROR_LOG } from "@/utils";
|
|
5
4
|
import { getLogErrorStack } from "@/utils/env-vars";
|
|
6
|
-
import type { Logger } from "./log";
|
|
7
5
|
|
|
8
6
|
export function assertUnreachable(x: never): never {
|
|
9
7
|
throw new Error(`Unreachable case: ${x}`);
|
|
@@ -38,155 +36,6 @@ export function safeStringify(obj: unknown, maxSize: number) {
|
|
|
38
36
|
return JSON.stringify(obj, replacer);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
// TODO: Instead of doing this, use a temp var for state and attempt to write
|
|
42
|
-
// it. Roll back state if fails to serialize.
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Check if a value is CBOR serializable.
|
|
46
|
-
* Optionally pass an onInvalid callback to receive the path to invalid values.
|
|
47
|
-
*
|
|
48
|
-
* For a complete list of supported CBOR tags, see:
|
|
49
|
-
* https://github.com/kriszyp/cbor-x/blob/cc1cf9df8ba72288c7842af1dd374d73e34cdbc1/README.md#list-of-supported-tags-for-decoding
|
|
50
|
-
*/
|
|
51
|
-
export function isCborSerializable(
|
|
52
|
-
value: unknown,
|
|
53
|
-
onInvalid?: (path: string) => void,
|
|
54
|
-
currentPath = "",
|
|
55
|
-
): boolean {
|
|
56
|
-
// Handle primitive types directly
|
|
57
|
-
if (value === null || value === undefined) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (typeof value === "number") {
|
|
62
|
-
if (!Number.isFinite(value)) {
|
|
63
|
-
onInvalid?.(currentPath);
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (typeof value === "boolean" || typeof value === "string") {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Handle BigInt (CBOR tags 2 and 3)
|
|
74
|
-
if (typeof value === "bigint") {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Handle Date objects (CBOR tags 0 and 1)
|
|
79
|
-
if (value instanceof Date) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Handle typed arrays (CBOR tags 64-82)
|
|
84
|
-
if (
|
|
85
|
-
value instanceof Uint8Array ||
|
|
86
|
-
value instanceof Uint8ClampedArray ||
|
|
87
|
-
value instanceof Uint16Array ||
|
|
88
|
-
value instanceof Uint32Array ||
|
|
89
|
-
value instanceof BigUint64Array ||
|
|
90
|
-
value instanceof Int8Array ||
|
|
91
|
-
value instanceof Int16Array ||
|
|
92
|
-
value instanceof Int32Array ||
|
|
93
|
-
value instanceof BigInt64Array ||
|
|
94
|
-
value instanceof Float32Array ||
|
|
95
|
-
value instanceof Float64Array
|
|
96
|
-
) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Handle Map (CBOR tag 259)
|
|
101
|
-
if (value instanceof Map) {
|
|
102
|
-
for (const [key, val] of value.entries()) {
|
|
103
|
-
const keyPath = currentPath
|
|
104
|
-
? `${currentPath}.key(${String(key)})`
|
|
105
|
-
: `key(${String(key)})`;
|
|
106
|
-
const valPath = currentPath
|
|
107
|
-
? `${currentPath}.value(${String(key)})`
|
|
108
|
-
: `value(${String(key)})`;
|
|
109
|
-
if (
|
|
110
|
-
!isCborSerializable(key, onInvalid, keyPath) ||
|
|
111
|
-
!isCborSerializable(val, onInvalid, valPath)
|
|
112
|
-
) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Handle Set (CBOR tag 258)
|
|
120
|
-
if (value instanceof Set) {
|
|
121
|
-
let index = 0;
|
|
122
|
-
for (const item of value.values()) {
|
|
123
|
-
const itemPath = currentPath
|
|
124
|
-
? `${currentPath}.set[${index}]`
|
|
125
|
-
: `set[${index}]`;
|
|
126
|
-
if (!isCborSerializable(item, onInvalid, itemPath)) {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
index++;
|
|
130
|
-
}
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Handle RegExp (CBOR tag 27)
|
|
135
|
-
if (value instanceof RegExp) {
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Handle Error objects (CBOR tag 27)
|
|
140
|
-
if (value instanceof Error) {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Handle arrays
|
|
145
|
-
if (Array.isArray(value)) {
|
|
146
|
-
for (let i = 0; i < value.length; i++) {
|
|
147
|
-
const itemPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;
|
|
148
|
-
if (!isCborSerializable(value[i], onInvalid, itemPath)) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Handle plain objects and records (CBOR tags 105, 51, 57344-57599)
|
|
156
|
-
if (typeof value === "object") {
|
|
157
|
-
// Allow plain objects and objects with prototypes (for records and named objects)
|
|
158
|
-
const proto = Object.getPrototypeOf(value);
|
|
159
|
-
if (proto !== null && proto !== Object.prototype) {
|
|
160
|
-
// Check if it's a known serializable object type
|
|
161
|
-
const protoConstructor = value.constructor;
|
|
162
|
-
if (protoConstructor && typeof protoConstructor.name === "string") {
|
|
163
|
-
// Allow objects with named constructors (records, named objects)
|
|
164
|
-
// This includes user-defined classes and built-in objects
|
|
165
|
-
// that CBOR can serialize with tag 27 or record tags
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Check all properties recursively
|
|
170
|
-
for (const key in value) {
|
|
171
|
-
const propPath = currentPath ? `${currentPath}.${key}` : key;
|
|
172
|
-
if (
|
|
173
|
-
!isCborSerializable(
|
|
174
|
-
value[key as keyof typeof value],
|
|
175
|
-
onInvalid,
|
|
176
|
-
propPath,
|
|
177
|
-
)
|
|
178
|
-
) {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Not serializable
|
|
186
|
-
onInvalid?.(currentPath);
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
39
|
export interface DeconstructedError {
|
|
191
40
|
__type: "ActorError";
|
|
192
41
|
statusCode: ContentfulStatusCode;
|
|
@@ -195,6 +44,7 @@ export interface DeconstructedError {
|
|
|
195
44
|
code: string;
|
|
196
45
|
message: string;
|
|
197
46
|
metadata?: unknown;
|
|
47
|
+
actor?: errors.ActorSpecifier;
|
|
198
48
|
}
|
|
199
49
|
|
|
200
50
|
function isCanonicalStructuredRivetError(
|
|
@@ -221,19 +71,16 @@ function isCanonicalStructuredRivetError(
|
|
|
221
71
|
*/
|
|
222
72
|
export function deconstructError(
|
|
223
73
|
error: unknown,
|
|
224
|
-
logger: Logger,
|
|
225
|
-
extraLog: Record<string, unknown>,
|
|
226
74
|
exposeInternalError = false,
|
|
227
75
|
): DeconstructedError {
|
|
228
76
|
// Build response error information. Only return errors if flagged as public in order to prevent leaking internal behavior.
|
|
229
|
-
//
|
|
230
|
-
// We log the error here instead of after generating the code & message because we need to log the original error, not the masked internal error.
|
|
231
77
|
let statusCode: ContentfulStatusCode;
|
|
232
78
|
let public_: boolean;
|
|
233
79
|
let group: string;
|
|
234
80
|
let code: string;
|
|
235
81
|
let message: string;
|
|
236
82
|
let metadata: unknown;
|
|
83
|
+
let actor: errors.ActorSpecifier | undefined;
|
|
237
84
|
// Structured errors from core or from pre-built `RivetError` instances are canonical.
|
|
238
85
|
// Only unstructured errors go through the classifier below.
|
|
239
86
|
if (isCanonicalStructuredRivetError(error)) {
|
|
@@ -249,15 +96,7 @@ export function deconstructError(
|
|
|
249
96
|
code = error.code;
|
|
250
97
|
message = error.message;
|
|
251
98
|
metadata = error.metadata;
|
|
252
|
-
|
|
253
|
-
logger.info({
|
|
254
|
-
msg: "structured error passthrough",
|
|
255
|
-
group,
|
|
256
|
-
code,
|
|
257
|
-
message,
|
|
258
|
-
...EXTRA_ERROR_LOG,
|
|
259
|
-
...extraLog,
|
|
260
|
-
});
|
|
99
|
+
actor = error.actor;
|
|
261
100
|
} else if (errors.ActorError.isActorError(error) && error.public) {
|
|
262
101
|
// Check if error has statusCode (could be ActorError instance or DeconstructedError)
|
|
263
102
|
statusCode = (
|
|
@@ -268,15 +107,7 @@ export function deconstructError(
|
|
|
268
107
|
code = error.code;
|
|
269
108
|
message = getErrorMessage(error);
|
|
270
109
|
metadata = error.metadata;
|
|
271
|
-
|
|
272
|
-
logger.info({
|
|
273
|
-
msg: "public error",
|
|
274
|
-
group,
|
|
275
|
-
code,
|
|
276
|
-
message,
|
|
277
|
-
...EXTRA_ERROR_LOG,
|
|
278
|
-
...extraLog,
|
|
279
|
-
});
|
|
110
|
+
actor = error.actor;
|
|
280
111
|
} else if (exposeInternalError) {
|
|
281
112
|
if (errors.ActorError.isActorError(error)) {
|
|
282
113
|
statusCode = 500;
|
|
@@ -285,32 +116,13 @@ export function deconstructError(
|
|
|
285
116
|
code = error.code;
|
|
286
117
|
message = getErrorMessage(error);
|
|
287
118
|
metadata = error.metadata;
|
|
288
|
-
|
|
289
|
-
logger.info({
|
|
290
|
-
msg: "internal error",
|
|
291
|
-
group,
|
|
292
|
-
code,
|
|
293
|
-
message,
|
|
294
|
-
stack: (error as Error)?.stack,
|
|
295
|
-
...EXTRA_ERROR_LOG,
|
|
296
|
-
...extraLog,
|
|
297
|
-
});
|
|
119
|
+
actor = error.actor;
|
|
298
120
|
} else {
|
|
299
121
|
statusCode = 500;
|
|
300
122
|
public_ = false;
|
|
301
123
|
group = "rivetkit";
|
|
302
124
|
code = errors.INTERNAL_ERROR_CODE;
|
|
303
125
|
message = getErrorMessage(error);
|
|
304
|
-
|
|
305
|
-
logger.info({
|
|
306
|
-
msg: "internal error",
|
|
307
|
-
group,
|
|
308
|
-
code,
|
|
309
|
-
message,
|
|
310
|
-
stack: (error as Error)?.stack,
|
|
311
|
-
...EXTRA_ERROR_LOG,
|
|
312
|
-
...extraLog,
|
|
313
|
-
});
|
|
314
126
|
}
|
|
315
127
|
} else {
|
|
316
128
|
statusCode = 500;
|
|
@@ -318,17 +130,12 @@ export function deconstructError(
|
|
|
318
130
|
group = "rivetkit";
|
|
319
131
|
code = errors.INTERNAL_ERROR_CODE;
|
|
320
132
|
message = errors.INTERNAL_ERROR_DESCRIPTION;
|
|
133
|
+
if (errors.ActorError.isActorError(error)) {
|
|
134
|
+
actor = error.actor;
|
|
135
|
+
}
|
|
321
136
|
metadata = {
|
|
322
|
-
//url: `https://
|
|
137
|
+
//url: `https://dashboard.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
|
|
323
138
|
} satisfies errors.InternalErrorMetadata;
|
|
324
|
-
|
|
325
|
-
logger.warn({
|
|
326
|
-
msg: "internal error",
|
|
327
|
-
error: getErrorMessage(error),
|
|
328
|
-
stack: (error as Error)?.stack,
|
|
329
|
-
...EXTRA_ERROR_LOG,
|
|
330
|
-
...extraLog,
|
|
331
|
-
});
|
|
332
139
|
}
|
|
333
140
|
|
|
334
141
|
return {
|
|
@@ -339,6 +146,7 @@ export function deconstructError(
|
|
|
339
146
|
code,
|
|
340
147
|
message,
|
|
341
148
|
metadata,
|
|
149
|
+
actor,
|
|
342
150
|
};
|
|
343
151
|
}
|
|
344
152
|
|
package/src/db/drizzle.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
SqliteDatabase,
|
|
11
11
|
} from "@/common/database/config";
|
|
12
12
|
import { toSqliteBindings } from "@/common/database/shared";
|
|
13
|
-
import {
|
|
13
|
+
import { sha256Hex } from "@/utils/crypto";
|
|
14
14
|
|
|
15
15
|
export type { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
16
16
|
export {
|
|
@@ -28,8 +28,19 @@ export {
|
|
|
28
28
|
} from "drizzle-orm/sqlite-core";
|
|
29
29
|
|
|
30
30
|
type DrizzleSchema = Record<string, unknown>;
|
|
31
|
-
type DrizzleDatabase<TSchema extends DrizzleSchema> =
|
|
32
|
-
SqliteRemoteDatabase<TSchema
|
|
31
|
+
type DrizzleDatabase<TSchema extends DrizzleSchema> = Omit<
|
|
32
|
+
SqliteRemoteDatabase<TSchema>,
|
|
33
|
+
"transaction"
|
|
34
|
+
> &
|
|
35
|
+
Omit<RawAccess, "transaction"> & {
|
|
36
|
+
transaction: <T>(
|
|
37
|
+
callback: (
|
|
38
|
+
tx: DrizzleDatabase<TSchema>,
|
|
39
|
+
) => Promise<T> | T,
|
|
40
|
+
) => Promise<T>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const MIGRATION_LEASE_TIMEOUT_MS = 60_000;
|
|
33
44
|
|
|
34
45
|
interface DrizzleMigrationJournalEntry {
|
|
35
46
|
idx: number;
|
|
@@ -90,6 +101,7 @@ export function db<TSchema extends DrizzleSchema = Record<string, never>>({
|
|
|
90
101
|
|
|
91
102
|
const nativeDb = await nativeDatabaseProvider.open(ctx.actorId);
|
|
92
103
|
let closed = false;
|
|
104
|
+
let transactionActive = false;
|
|
93
105
|
const ensureOpen = () => {
|
|
94
106
|
if (closed) {
|
|
95
107
|
throw new Error(
|
|
@@ -98,108 +110,192 @@ export function db<TSchema extends DrizzleSchema = Record<string, never>>({
|
|
|
98
110
|
}
|
|
99
111
|
};
|
|
100
112
|
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
const createDrizzleClient = (lease?: {
|
|
114
|
+
key: string;
|
|
115
|
+
timeoutMs?: number;
|
|
116
|
+
}): DrizzleDatabase<TSchema> => {
|
|
117
|
+
const runSql = async (
|
|
118
|
+
query: string,
|
|
119
|
+
params: unknown[],
|
|
120
|
+
method: "run" | "all" | "values" | "get",
|
|
121
|
+
) => {
|
|
122
|
+
ensureOpen();
|
|
123
|
+
if (!lease && transactionActive) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
"Use the tx argument inside db.transaction(); the outer database client cannot run work from the transaction callback.",
|
|
126
|
+
);
|
|
127
|
+
}
|
|
107
128
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
129
|
+
const start = performance.now();
|
|
130
|
+
const kvReadsBefore = ctx.metrics?.totalKvReads ?? 0;
|
|
131
|
+
const kvWritesBefore = ctx.metrics?.totalKvWrites ?? 0;
|
|
132
|
+
try {
|
|
133
|
+
const { rows } = await nativeDb.execute(
|
|
134
|
+
query,
|
|
135
|
+
toSqliteBindings(params),
|
|
136
|
+
lease,
|
|
137
|
+
);
|
|
138
|
+
if (method === "run") {
|
|
139
|
+
return { rows: [] };
|
|
140
|
+
}
|
|
141
|
+
if (method === "get") {
|
|
142
|
+
return { rows: rows[0] };
|
|
143
|
+
}
|
|
144
|
+
return { rows };
|
|
145
|
+
} finally {
|
|
146
|
+
const durationMs = performance.now() - start;
|
|
147
|
+
ctx.metrics?.trackSql(query, durationMs);
|
|
148
|
+
if (ctx.metrics) {
|
|
149
|
+
ctx.log?.debug({
|
|
150
|
+
msg: "sql query",
|
|
151
|
+
query: query.slice(0, 120),
|
|
152
|
+
durationMs,
|
|
153
|
+
kvReads:
|
|
154
|
+
ctx.metrics.totalKvReads - kvReadsBefore,
|
|
155
|
+
kvWrites:
|
|
156
|
+
ctx.metrics.totalKvWrites - kvWritesBefore,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const callback: RemoteCallback = async (
|
|
163
|
+
query,
|
|
164
|
+
params,
|
|
165
|
+
method,
|
|
166
|
+
) => {
|
|
167
|
+
return await runSql(query, params, method);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const drizzleDb = drizzle(callback, {
|
|
171
|
+
schema,
|
|
172
|
+
}) as unknown as DrizzleDatabase<TSchema>;
|
|
173
|
+
drizzleDb.execute = async <
|
|
174
|
+
TRow extends Record<string, unknown> = Record<
|
|
175
|
+
string,
|
|
176
|
+
unknown
|
|
177
|
+
>,
|
|
178
|
+
>(
|
|
179
|
+
query: string,
|
|
180
|
+
...args: unknown[]
|
|
181
|
+
): Promise<TRow[]> => {
|
|
182
|
+
return await executeRaw<TRow>(
|
|
183
|
+
nativeDb,
|
|
184
|
+
ctx,
|
|
185
|
+
ensureOpen,
|
|
113
186
|
query,
|
|
114
|
-
|
|
187
|
+
args,
|
|
188
|
+
lease,
|
|
115
189
|
);
|
|
116
|
-
|
|
117
|
-
|
|
190
|
+
};
|
|
191
|
+
drizzleDb.transaction = async <T>(
|
|
192
|
+
transactionCallback: (
|
|
193
|
+
tx: DrizzleDatabase<TSchema>,
|
|
194
|
+
) => Promise<T> | T,
|
|
195
|
+
): Promise<T> => {
|
|
196
|
+
if (lease || transactionActive) {
|
|
197
|
+
throw new Error(
|
|
198
|
+
"Nested or concurrent db.transaction() calls are not supported.",
|
|
199
|
+
);
|
|
118
200
|
}
|
|
119
|
-
|
|
120
|
-
|
|
201
|
+
const transactionLease = { key: crypto.randomUUID() };
|
|
202
|
+
const tx = createDrizzleClient(transactionLease);
|
|
203
|
+
await nativeDb.execute(
|
|
204
|
+
"BEGIN",
|
|
205
|
+
undefined,
|
|
206
|
+
transactionLease,
|
|
207
|
+
);
|
|
208
|
+
transactionActive = true;
|
|
209
|
+
try {
|
|
210
|
+
const result = await transactionCallback(tx);
|
|
211
|
+
await nativeDb.execute(
|
|
212
|
+
"COMMIT",
|
|
213
|
+
undefined,
|
|
214
|
+
transactionLease,
|
|
215
|
+
);
|
|
216
|
+
return result;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
try {
|
|
219
|
+
await nativeDb.execute(
|
|
220
|
+
"ROLLBACK",
|
|
221
|
+
undefined,
|
|
222
|
+
transactionLease,
|
|
223
|
+
);
|
|
224
|
+
} catch {
|
|
225
|
+
// Preserve the callback or commit error after lease poisoning.
|
|
226
|
+
}
|
|
227
|
+
throw error;
|
|
228
|
+
} finally {
|
|
229
|
+
transactionActive = false;
|
|
121
230
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
231
|
+
};
|
|
232
|
+
drizzleDb.__withSqliteLease = async <T>(
|
|
233
|
+
timeoutMs: number,
|
|
234
|
+
leaseCallback: (leased: RawAccess) => Promise<T> | T,
|
|
235
|
+
): Promise<T> => {
|
|
236
|
+
const internalLease = {
|
|
237
|
+
key: crypto.randomUUID(),
|
|
238
|
+
timeoutMs,
|
|
239
|
+
};
|
|
240
|
+
return await leaseCallback(
|
|
241
|
+
createDrizzleClient(internalLease),
|
|
242
|
+
);
|
|
243
|
+
};
|
|
244
|
+
drizzleDb.close = async () => {
|
|
245
|
+
if (!closed) {
|
|
246
|
+
closed = true;
|
|
247
|
+
await nativeDb.close();
|
|
135
248
|
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
249
|
+
};
|
|
138
250
|
|
|
139
|
-
|
|
140
|
-
return await runSql(query, params, method);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const drizzleDb = drizzle(callback, {
|
|
144
|
-
schema,
|
|
145
|
-
}) as DrizzleDatabase<TSchema>;
|
|
146
|
-
drizzleDb.execute = async <
|
|
147
|
-
TRow extends Record<string, unknown> = Record<string, unknown>,
|
|
148
|
-
>(
|
|
149
|
-
query: string,
|
|
150
|
-
...args: unknown[]
|
|
151
|
-
): Promise<TRow[]> => {
|
|
152
|
-
return await executeRaw<TRow>(
|
|
153
|
-
nativeDb,
|
|
154
|
-
ctx,
|
|
155
|
-
ensureOpen,
|
|
156
|
-
query,
|
|
157
|
-
args,
|
|
158
|
-
);
|
|
251
|
+
return drizzleDb;
|
|
159
252
|
};
|
|
160
|
-
drizzleDb.close = async () => {
|
|
161
|
-
if (!closed) {
|
|
162
|
-
closed = true;
|
|
163
|
-
await nativeDb.close();
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
(
|
|
167
|
-
drizzleDb as DrizzleDatabase<TSchema> & {
|
|
168
|
-
__rivetWriteMode: <T>(
|
|
169
|
-
callback: () => Promise<T> | T,
|
|
170
|
-
) => Promise<T>;
|
|
171
|
-
}
|
|
172
|
-
).__rivetWriteMode = async (callback) =>
|
|
173
|
-
await nativeDb.writeMode(async () => await callback());
|
|
174
253
|
|
|
175
|
-
return
|
|
254
|
+
return createDrizzleClient();
|
|
176
255
|
},
|
|
177
256
|
onMigrate: async (client) => {
|
|
178
|
-
|
|
257
|
+
if (!migrations && !onMigrate) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
await withMigrationSavepoint(client, async (leased) => {
|
|
179
261
|
if (migrations) {
|
|
180
|
-
await runMigrations(
|
|
262
|
+
await runMigrations(leased, migrations);
|
|
181
263
|
}
|
|
182
264
|
if (onMigrate) {
|
|
183
|
-
await onMigrate(
|
|
265
|
+
await onMigrate(leased);
|
|
184
266
|
}
|
|
185
267
|
});
|
|
186
268
|
},
|
|
187
269
|
};
|
|
188
270
|
}
|
|
189
271
|
|
|
190
|
-
async function
|
|
191
|
-
client:
|
|
192
|
-
callback: () => Promise<T> | T,
|
|
272
|
+
async function withMigrationSavepoint<TSchema extends DrizzleSchema, T>(
|
|
273
|
+
client: DrizzleDatabase<TSchema>,
|
|
274
|
+
callback: (leased: DrizzleDatabase<TSchema>) => Promise<T> | T,
|
|
193
275
|
): Promise<T> {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
276
|
+
return await client.__withSqliteLease(
|
|
277
|
+
MIGRATION_LEASE_TIMEOUT_MS,
|
|
278
|
+
async (leasedAccess) => {
|
|
279
|
+
const leased = leasedAccess as DrizzleDatabase<TSchema>;
|
|
280
|
+
await leased.execute("SAVEPOINT __rivet_on_migrate");
|
|
281
|
+
try {
|
|
282
|
+
const result = await callback(leased);
|
|
283
|
+
await leased.execute("RELEASE SAVEPOINT __rivet_on_migrate");
|
|
284
|
+
return result;
|
|
285
|
+
} catch (error) {
|
|
286
|
+
try {
|
|
287
|
+
await leased.execute(
|
|
288
|
+
"ROLLBACK TO SAVEPOINT __rivet_on_migrate",
|
|
289
|
+
);
|
|
290
|
+
} finally {
|
|
291
|
+
await leased.execute(
|
|
292
|
+
"RELEASE SAVEPOINT __rivet_on_migrate",
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
);
|
|
203
299
|
}
|
|
204
300
|
|
|
205
301
|
async function runMigrations<TSchema extends DrizzleSchema>(
|
|
@@ -244,10 +340,7 @@ async function runMigrations<TSchema extends DrizzleSchema>(
|
|
|
244
340
|
|
|
245
341
|
await db.execute(
|
|
246
342
|
"INSERT INTO __drizzle_migrations (hash, created_at) VALUES (?, ?)",
|
|
247
|
-
|
|
248
|
-
.createHash("sha256")
|
|
249
|
-
.update(migration)
|
|
250
|
-
.digest("hex"),
|
|
343
|
+
await sha256Hex(migration),
|
|
251
344
|
entry.when,
|
|
252
345
|
);
|
|
253
346
|
}
|
|
@@ -290,6 +383,7 @@ async function executeRaw<TRow extends Record<string, unknown>>(
|
|
|
290
383
|
ensureOpen: () => void,
|
|
291
384
|
query: string,
|
|
292
385
|
args: unknown[],
|
|
386
|
+
lease?: { key: string; timeoutMs?: number },
|
|
293
387
|
): Promise<TRow[]> {
|
|
294
388
|
ensureOpen();
|
|
295
389
|
|
|
@@ -301,23 +395,28 @@ async function executeRaw<TRow extends Record<string, unknown>>(
|
|
|
301
395
|
const { rows, columns } = await db.execute(
|
|
302
396
|
query,
|
|
303
397
|
toSqliteBindings(args),
|
|
398
|
+
lease,
|
|
304
399
|
);
|
|
305
400
|
return rows.map((row) => rowToObject<TRow>(row, columns));
|
|
306
401
|
}
|
|
307
402
|
|
|
308
403
|
if (!hasMultipleStatements(query)) {
|
|
309
|
-
const { rows, columns } = await db.execute(query);
|
|
404
|
+
const { rows, columns } = await db.execute(query, undefined, lease);
|
|
310
405
|
return rows.map((row) => rowToObject<TRow>(row, columns));
|
|
311
406
|
}
|
|
312
407
|
|
|
313
408
|
const results: Record<string, unknown>[] = [];
|
|
314
409
|
let columnNames: string[] | null = null;
|
|
315
|
-
await db.exec(
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
410
|
+
await db.exec(
|
|
411
|
+
query,
|
|
412
|
+
(row, columns) => {
|
|
413
|
+
if (!columnNames) {
|
|
414
|
+
columnNames = columns;
|
|
415
|
+
}
|
|
416
|
+
results.push(rowToObject(row, columnNames));
|
|
417
|
+
},
|
|
418
|
+
lease,
|
|
419
|
+
);
|
|
321
420
|
return results as TRow[];
|
|
322
421
|
} finally {
|
|
323
422
|
const durationMs = performance.now() - start;
|
package/src/db/mod.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { db } from "@/common/database/mod";
|
|
2
1
|
export type {
|
|
3
2
|
AnyDatabaseProvider,
|
|
4
3
|
DatabaseProvider,
|
|
@@ -11,3 +10,4 @@ export type {
|
|
|
11
10
|
SqliteNativeMetrics,
|
|
12
11
|
SqliteQueryResult,
|
|
13
12
|
} from "@/common/database/config";
|
|
13
|
+
export { db } from "@/common/database/mod";
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import type { ClientConfigInput } from "@/client/client";
|
|
2
|
-
import { VERSION } from "@/utils";
|
|
3
2
|
import { logger } from "./log";
|
|
4
3
|
|
|
5
4
|
declare global {
|
|
6
5
|
// Injected via tsup config
|
|
7
|
-
// biome-ignore lint/style/noVar: required for global declaration
|
|
8
6
|
var CUSTOM_RIVETKIT_DEVTOOLS_URL: string | undefined;
|
|
9
7
|
}
|
|
10
8
|
|
|
11
|
-
const DEFAULT_DEVTOOLS_URL = (version = VERSION) =>
|
|
12
|
-
`https://releases.rivet.dev/rivet/latest/devtools/mod.js?v=${version}`;
|
|
13
|
-
|
|
14
9
|
const scriptId = "rivetkit-devtools-script";
|
|
15
10
|
|
|
16
11
|
export function injectDevtools(config: ClientConfigInput) {
|
|
@@ -20,10 +15,12 @@ export function injectDevtools(config: ClientConfigInput) {
|
|
|
20
15
|
}
|
|
21
16
|
|
|
22
17
|
if (!document.getElementById(scriptId)) {
|
|
18
|
+
const src =
|
|
19
|
+
globalThis.CUSTOM_RIVETKIT_DEVTOOLS_URL ||
|
|
20
|
+
`${config.endpoint?.replace(/\/$/, "")}/devtools/mod.js`;
|
|
23
21
|
const script = document.createElement("script");
|
|
24
22
|
script.id = scriptId;
|
|
25
|
-
script.src =
|
|
26
|
-
globalThis.CUSTOM_RIVETKIT_DEVTOOLS_URL || DEFAULT_DEVTOOLS_URL();
|
|
23
|
+
script.src = src;
|
|
27
24
|
script.async = true;
|
|
28
25
|
document.head.appendChild(script);
|
|
29
26
|
}
|