rivetkit 2.0.12 → 2.0.14
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/tsup/actor/errors.cjs +2 -2
- package/dist/tsup/actor/errors.d.cts +0 -8
- package/dist/tsup/actor/errors.d.ts +0 -8
- package/dist/tsup/actor/errors.js +1 -1
- package/dist/tsup/{chunk-RQGVUYBU.cjs → chunk-3HCSWRUA.cjs} +10 -10
- package/dist/tsup/{chunk-RQGVUYBU.cjs.map → chunk-3HCSWRUA.cjs.map} +1 -1
- package/dist/tsup/{chunk-LD3574QQ.js → chunk-3LGDBNZG.js} +2 -2
- package/dist/tsup/{chunk-O7SCSVV5.js → chunk-43PTNF7W.js} +3 -3
- package/dist/tsup/{chunk-DSJ7EWMA.js → chunk-5C3MRFAU.js} +2 -2
- package/dist/tsup/{chunk-2WEKN2GP.cjs → chunk-ATMZDEVA.cjs} +3 -3
- package/dist/tsup/{chunk-2WEKN2GP.cjs.map → chunk-ATMZDEVA.cjs.map} +1 -1
- package/dist/tsup/{chunk-QSWYPQ5Y.cjs → chunk-DJDDJDWR.cjs} +12 -12
- package/dist/tsup/{chunk-QSWYPQ5Y.cjs.map → chunk-DJDDJDWR.cjs.map} +1 -1
- package/dist/tsup/{chunk-TGMO7RD4.js → chunk-EY5EMNAB.js} +3 -3
- package/dist/tsup/{chunk-TGMO7RD4.js.map → chunk-EY5EMNAB.js.map} +1 -1
- package/dist/tsup/{chunk-3H2GFGYN.cjs → chunk-FNCNYJFG.cjs} +3 -3
- package/dist/tsup/{chunk-3H2GFGYN.cjs.map → chunk-FNCNYJFG.cjs.map} +1 -1
- package/dist/tsup/{chunk-DYXH4LQ3.js → chunk-FNQGHSFJ.js} +2 -2
- package/dist/tsup/{chunk-FXGRLLVS.js → chunk-G3R2O5VL.js} +67 -75
- package/dist/tsup/chunk-G3R2O5VL.js.map +1 -0
- package/dist/tsup/{chunk-YPZFLUO6.js → chunk-G64QUEDJ.js} +1 -11
- package/dist/tsup/chunk-G64QUEDJ.js.map +1 -0
- package/dist/tsup/{chunk-YLCZ3HD7.cjs → chunk-HNC6Y6JC.cjs} +321 -234
- package/dist/tsup/{chunk-X5I7MG2C.js.map → chunk-HNC6Y6JC.cjs.map} +1 -1
- package/dist/tsup/{chunk-AOWJK5JM.js → chunk-HY3MZSKX.js} +4 -4
- package/dist/tsup/{chunk-HVSEPT2G.cjs → chunk-INNBRUPH.cjs} +17 -13
- package/dist/tsup/chunk-INNBRUPH.cjs.map +1 -0
- package/dist/tsup/{chunk-5QGQK44L.cjs → chunk-KSRXX3Z4.cjs} +1 -11
- package/dist/tsup/chunk-KSRXX3Z4.cjs.map +1 -0
- package/dist/tsup/{chunk-4NPHS4GT.cjs → chunk-MF76IOZD.cjs} +7 -7
- package/dist/tsup/{chunk-4NPHS4GT.cjs.map → chunk-MF76IOZD.cjs.map} +1 -1
- package/dist/tsup/{chunk-63AELL54.cjs → chunk-OWPBIHFM.cjs} +8 -8
- package/dist/tsup/{chunk-63AELL54.cjs.map → chunk-OWPBIHFM.cjs.map} +1 -1
- package/dist/tsup/{chunk-LO6XS2NJ.js → chunk-PO352AW7.js} +2 -2
- package/dist/tsup/{chunk-FFLADW7R.cjs → chunk-Q6ESJU7P.cjs} +37 -33
- package/dist/tsup/chunk-Q6ESJU7P.cjs.map +1 -0
- package/dist/tsup/{chunk-VYQFZNPT.cjs → chunk-QZWHQAOF.cjs} +6 -6
- package/dist/tsup/{chunk-VYQFZNPT.cjs.map → chunk-QZWHQAOF.cjs.map} +1 -1
- package/dist/tsup/{chunk-XIR6UKM2.js → chunk-SQPFZW4U.js} +11 -7
- package/dist/tsup/chunk-SQPFZW4U.js.map +1 -0
- package/dist/tsup/{chunk-KQGXJTBM.cjs → chunk-SXEHZODB.cjs} +236 -244
- package/dist/tsup/chunk-SXEHZODB.cjs.map +1 -0
- package/dist/tsup/{chunk-YSIN4LW4.js → chunk-XQR2BHQP.js} +11 -7
- package/dist/tsup/chunk-XQR2BHQP.js.map +1 -0
- package/dist/tsup/{chunk-X5I7MG2C.js → chunk-ZD5CZSSF.js} +104 -17
- package/dist/tsup/chunk-ZD5CZSSF.js.map +1 -0
- package/dist/tsup/client/mod.cjs +10 -10
- package/dist/tsup/client/mod.d.cts +2 -2
- package/dist/tsup/client/mod.d.ts +2 -2
- package/dist/tsup/client/mod.js +9 -9
- package/dist/tsup/common/log.cjs +4 -4
- package/dist/tsup/common/log.js +3 -3
- package/dist/tsup/common/websocket.cjs +5 -5
- package/dist/tsup/common/websocket.js +4 -4
- package/dist/tsup/{conn-Cc9WHuN4.d.cts → conn-CxCsTz2s.d.cts} +27 -24
- package/dist/tsup/{conn-DfPG71FA.d.ts → conn-DhdZYlSX.d.ts} +27 -24
- package/dist/tsup/driver-helpers/mod.cjs +6 -6
- package/dist/tsup/driver-helpers/mod.d.cts +1 -1
- package/dist/tsup/driver-helpers/mod.d.ts +1 -1
- package/dist/tsup/driver-helpers/mod.js +5 -5
- package/dist/tsup/driver-test-suite/mod.cjs +77 -73
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +1 -1
- package/dist/tsup/driver-test-suite/mod.d.ts +1 -1
- package/dist/tsup/driver-test-suite/mod.js +17 -13
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +7 -7
- package/dist/tsup/inspector/mod.d.cts +2 -2
- package/dist/tsup/inspector/mod.d.ts +2 -2
- package/dist/tsup/inspector/mod.js +6 -6
- package/dist/tsup/mod.cjs +11 -11
- package/dist/tsup/mod.d.cts +2 -2
- package/dist/tsup/mod.d.ts +2 -2
- package/dist/tsup/mod.js +10 -10
- package/dist/tsup/test/mod.cjs +12 -12
- package/dist/tsup/test/mod.d.cts +1 -1
- package/dist/tsup/test/mod.d.ts +1 -1
- package/dist/tsup/test/mod.js +11 -11
- package/dist/tsup/utils.cjs +3 -3
- package/dist/tsup/utils.js +2 -2
- package/package.json +1 -1
- package/src/actor/errors.ts +0 -11
- package/src/client/client.ts +4 -8
- package/src/client/config.ts +3 -0
- package/src/client/utils.ts +8 -3
- package/src/common/router.ts +50 -1
- package/src/driver-test-suite/mod.ts +5 -1
- package/src/drivers/default.ts +0 -6
- package/src/drivers/engine/actor-driver.ts +16 -10
- package/src/drivers/file-system/manager.ts +5 -1
- package/src/inspector/config.ts +2 -0
- package/src/manager/router.ts +9 -15
- package/src/registry/mod.ts +30 -47
- package/src/remote-manager-driver/api-endpoints.ts +50 -0
- package/src/remote-manager-driver/mod.ts +104 -1
- package/src/test/mod.ts +5 -1
- package/dist/tsup/chunk-5QGQK44L.cjs.map +0 -1
- package/dist/tsup/chunk-FFLADW7R.cjs.map +0 -1
- package/dist/tsup/chunk-FXGRLLVS.js.map +0 -1
- package/dist/tsup/chunk-HVSEPT2G.cjs.map +0 -1
- package/dist/tsup/chunk-KQGXJTBM.cjs.map +0 -1
- package/dist/tsup/chunk-XIR6UKM2.js.map +0 -1
- package/dist/tsup/chunk-YLCZ3HD7.cjs.map +0 -1
- package/dist/tsup/chunk-YPZFLUO6.js.map +0 -1
- package/dist/tsup/chunk-YSIN4LW4.js.map +0 -1
- /package/dist/tsup/{chunk-LD3574QQ.js.map → chunk-3LGDBNZG.js.map} +0 -0
- /package/dist/tsup/{chunk-O7SCSVV5.js.map → chunk-43PTNF7W.js.map} +0 -0
- /package/dist/tsup/{chunk-DSJ7EWMA.js.map → chunk-5C3MRFAU.js.map} +0 -0
- /package/dist/tsup/{chunk-DYXH4LQ3.js.map → chunk-FNQGHSFJ.js.map} +0 -0
- /package/dist/tsup/{chunk-AOWJK5JM.js.map → chunk-HY3MZSKX.js.map} +0 -0
- /package/dist/tsup/{chunk-LO6XS2NJ.js.map → chunk-PO352AW7.js.map} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getLogger
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-PO352AW7.js";
|
|
4
4
|
import {
|
|
5
5
|
assertUnreachable
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-EY5EMNAB.js";
|
|
7
7
|
import {
|
|
8
8
|
Unreachable
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-G64QUEDJ.js";
|
|
10
10
|
|
|
11
11
|
// src/actor/log.ts
|
|
12
12
|
function loggerWithoutContext() {
|
|
@@ -310,4 +310,4 @@ export {
|
|
|
310
310
|
WS_PROTOCOL_PATH,
|
|
311
311
|
ALLOWED_PUBLIC_HEADERS
|
|
312
312
|
};
|
|
313
|
-
//# sourceMappingURL=chunk-
|
|
313
|
+
//# sourceMappingURL=chunk-HY3MZSKX.js.map
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkSXEHZODBcjs = require('./chunk-SXEHZODB.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkFNCNYJFGcjs = require('./chunk-FNCNYJFG.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkHNC6Y6JCcjs = require('./chunk-HNC6Y6JC.cjs');
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var _chunkFFLADW7Rcjs = require('./chunk-FFLADW7R.cjs');
|
|
14
13
|
|
|
14
|
+
var _chunkQ6ESJU7Pcjs = require('./chunk-Q6ESJU7P.cjs');
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
var _chunkMF76IOZDcjs = require('./chunk-MF76IOZD.cjs');
|
|
17
18
|
|
|
18
19
|
// src/test/mod.ts
|
|
19
20
|
var _net = require('net');
|
|
@@ -23,14 +24,14 @@ var _vitest = require('vitest');
|
|
|
23
24
|
|
|
24
25
|
// src/test/config.ts
|
|
25
26
|
var _zod = require('zod');
|
|
26
|
-
var ConfigSchema =
|
|
27
|
+
var ConfigSchema = _chunkQ6ESJU7Pcjs.RunnerConfigSchema.removeDefault().extend({
|
|
27
28
|
hostname: _zod.z.string().optional().default(_nullishCoalesce(process.env.HOSTNAME, () => ( "127.0.0.1"))),
|
|
28
29
|
port: _zod.z.number().optional().default(Number.parseInt(_nullishCoalesce(process.env.PORT, () => ( "8080"))))
|
|
29
30
|
}).default({});
|
|
30
31
|
|
|
31
32
|
// src/test/log.ts
|
|
32
33
|
function logger() {
|
|
33
|
-
return
|
|
34
|
+
return _chunkMF76IOZDcjs.getLogger.call(void 0, "test");
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
// src/test/mod.ts
|
|
@@ -41,12 +42,15 @@ function serve(registry, inputConfig) {
|
|
|
41
42
|
if (!config.getUpgradeWebSocket) {
|
|
42
43
|
config.getUpgradeWebSocket = () => upgradeWebSocket;
|
|
43
44
|
}
|
|
44
|
-
const runConfig =
|
|
45
|
-
const driver = _nullishCoalesce(inputConfig.driver, () => (
|
|
45
|
+
const runConfig = _chunkQ6ESJU7Pcjs.RunnerConfigSchema.parse(inputConfig);
|
|
46
|
+
const driver = _nullishCoalesce(inputConfig.driver, () => ( _chunkSXEHZODBcjs.createFileSystemOrMemoryDriver.call(void 0, false)));
|
|
46
47
|
const managerDriver = driver.manager(registry.config, config);
|
|
47
|
-
const client =
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const client = _chunkHNC6Y6JCcjs.createClientWithDriver.call(void 0,
|
|
49
|
+
managerDriver,
|
|
50
|
+
_chunkQ6ESJU7Pcjs.ClientConfigSchema.parse({})
|
|
51
|
+
);
|
|
52
|
+
_chunkFNCNYJFGcjs.configureInspectorAccessToken.call(void 0, config, managerDriver);
|
|
53
|
+
const { router } = _chunkSXEHZODBcjs.createManagerRouter.call(void 0,
|
|
50
54
|
registry.config,
|
|
51
55
|
runConfig,
|
|
52
56
|
managerDriver,
|
|
@@ -123,4 +127,4 @@ async function getPort() {
|
|
|
123
127
|
|
|
124
128
|
|
|
125
129
|
exports.setupTest = setupTest; exports.getPort = getPort;
|
|
126
|
-
//# sourceMappingURL=chunk-
|
|
130
|
+
//# sourceMappingURL=chunk-INNBRUPH.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-INNBRUPH.cjs","../../src/test/mod.ts","../../src/test/config.ts","../../src/test/log.ts"],"names":["server"],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;AClBA,0BAA6B;AAC7B,+CAAoD;AACpD,uCAAoC;AACpC,gCAAqC;ADoBrC;AACA;AExBA,0BAAkB;AAGX,IAAM,aAAA,EAAe,oCAAA,CAAmB,aAAA,CAAc,CAAA,CAC3D,MAAA,CAAO;AAAA,EACP,QAAA,EAAU,MAAA,CACR,MAAA,CAAO,CAAA,CACP,QAAA,CAAS,CAAA,CACT,OAAA,kBAAQ,OAAA,CAAQ,GAAA,CAAI,QAAA,UAAY,aAAW,CAAA;AAAA,EAC7C,IAAA,EAAM,MAAA,CACJ,MAAA,CAAO,CAAA,CACP,QAAA,CAAS,CAAA,CACT,OAAA,CAAQ,MAAA,CAAO,QAAA,kBAAS,OAAA,CAAQ,GAAA,CAAI,IAAA,UAAQ,QAAM,CAAC;AACtD,CAAC,CAAA,CACA,OAAA,CAAQ,CAAC,CAAC,CAAA;AFgBZ;AACA;AG7BO,SAAS,MAAA,CAAA,EAAS;AACxB,EAAA,OAAO,yCAAA,MAAgB,CAAA;AACxB;AH+BA;AACA;ACjBA,SAAS,KAAA,CAAM,QAAA,EAAyB,WAAA,EAAuC;AAE9E,EAAA,YAAA,IAAgB,CAAC,CAAA;AAEjB,EAAA,MA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PH.cjs","sourcesContent":[null,"import { createServer } from \"node:net\";\nimport { serve as honoServe, type ServerType } from \"@hono/node-server\";\nimport { createNodeWebSocket } from \"@hono/node-ws\";\nimport { type TestContext, vi } from \"vitest\";\nimport { ClientConfigSchema } from \"@/client/config\";\nimport { type Client, createClient } from \"@/client/mod\";\nimport { chooseDefaultDriver } from \"@/drivers/default\";\nimport { createFileSystemOrMemoryDriver } from \"@/drivers/file-system/mod\";\nimport {\n\tconfigureInspectorAccessToken,\n\tgetInspectorUrl,\n} from \"@/inspector/utils\";\nimport { createManagerRouter } from \"@/manager/router\";\nimport { createClientWithDriver } from \"@/mod\";\nimport type { Registry } from \"@/registry/mod\";\nimport { RunnerConfigSchema } from \"@/registry/run-config\";\nimport { ConfigSchema, type InputConfig } from \"./config\";\nimport { logger } from \"./log\";\n\nfunction serve(registry: Registry<any>, inputConfig?: InputConfig): ServerType {\n\t// Configure default configuration\n\tinputConfig ??= {};\n\n\tconst config = ConfigSchema.parse(inputConfig);\n\n\tlet upgradeWebSocket: any;\n\tif (!config.getUpgradeWebSocket) {\n\t\tconfig.getUpgradeWebSocket = () => upgradeWebSocket!;\n\t}\n\n\t// Create router\n\tconst runConfig = RunnerConfigSchema.parse(inputConfig);\n\tconst driver = inputConfig.driver ?? createFileSystemOrMemoryDriver(false);\n\tconst managerDriver = driver.manager(registry.config, config);\n\tconst client = createClientWithDriver(\n\t\tmanagerDriver,\n\t\tClientConfigSchema.parse({}),\n\t);\n\tconfigureInspectorAccessToken(config, managerDriver);\n\tconst { router } = createManagerRouter(\n\t\tregistry.config,\n\t\trunConfig,\n\t\tmanagerDriver,\n\t\tdriver,\n\t\tclient,\n\t);\n\n\t// Inject WebSocket\n\tconst nodeWebSocket = createNodeWebSocket({ app: router });\n\tupgradeWebSocket = nodeWebSocket.upgradeWebSocket;\n\n\tconst server = honoServe({\n\t\tfetch: router.fetch,\n\t\thostname: config.hostname,\n\t\tport: config.port,\n\t});\n\tnodeWebSocket.injectWebSocket(server);\n\n\tlogger().info({\n\t\tmsg: \"rivetkit started\",\n\t\thostname: config.hostname,\n\t\tport: config.port,\n\t\tdefinitions: Object.keys(registry.config.use).length,\n\t});\n\n\treturn server;\n}\n\nexport interface SetupTestResult<A extends Registry<any>> {\n\tclient: Client<A>;\n\tmockDriver: {\n\t\tactorDriver: {\n\t\t\tsetCreateVarsContext: (ctx: any) => void;\n\t\t};\n\t};\n}\n\n// Must use `TestContext` since global hooks do not work when running concurrently\nexport async function setupTest<A extends Registry<any>>(\n\tc: TestContext,\n\tregistry: A,\n): Promise<SetupTestResult<A>> {\n\tvi.useFakeTimers();\n\n\t// Set up mock driver for testing createVars context\n\tconst mockDriverContext: any = {};\n\tconst setDriverContextFn = (ctx: any) => {\n\t\tmockDriverContext.current = ctx;\n\t};\n\n\t// We don't need to modify the driver context anymore since we're testing with the actual context\n\n\t// Start server with a random port\n\tconst port = await getPort();\n\tconst server = serve(registry, { port });\n\tc.onTestFinished(\n\t\tasync () => await new Promise((resolve) => server.close(() => resolve())),\n\t);\n\n\tthrow \"TODO: Fix engine port\";\n\n\t// // TODO: Figure out how to make this the correct endpoint\n\t// // Create client\n\t// const client = createClient<A>(`http://127.0.0.1:${port}`);\n\t// c.onTestFinished(async () => await client.dispose());\n\t//\n\t// return {\n\t// \tclient,\n\t// \tmockDriver: {\n\t// \t\tactorDriver: {\n\t// \t\t\tsetCreateVarsContext: setDriverContextFn,\n\t// \t\t},\n\t// \t},\n\t// };\n}\n\nexport async function getPort(): Promise<number> {\n\t// Pick random port between 10000 and 65535 (avoiding well-known and registered ports)\n\tconst MIN_PORT = 10000;\n\tconst MAX_PORT = 65535;\n\tconst getRandomPort = () =>\n\t\tMath.floor(Math.random() * (MAX_PORT - MIN_PORT + 1)) + MIN_PORT;\n\n\tlet port = getRandomPort();\n\tlet maxAttempts = 10;\n\n\twhile (maxAttempts > 0) {\n\t\ttry {\n\t\t\t// Try to create a server on the port to check if it's available\n\t\t\tconst server = await new Promise<any>((resolve, reject) => {\n\t\t\t\tconst server = createServer();\n\n\t\t\t\tserver.once(\"error\", (err: Error & { code?: string }) => {\n\t\t\t\t\tif (err.code === \"EADDRINUSE\") {\n\t\t\t\t\t\treject(new Error(`Port ${port} is in use`));\n\t\t\t\t\t} else {\n\t\t\t\t\t\treject(err);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tserver.once(\"listening\", () => {\n\t\t\t\t\tresolve(server);\n\t\t\t\t});\n\n\t\t\t\tserver.listen(port);\n\t\t\t});\n\n\t\t\t// Close the server since we're just checking availability\n\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\tserver.close(() => resolve());\n\t\t\t});\n\n\t\t\treturn port;\n\t\t} catch (err) {\n\t\t\t// If port is in use, try a different one\n\t\t\tmaxAttempts--;\n\t\t\tif (maxAttempts <= 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tport = getRandomPort();\n\t\t}\n\t}\n\n\tthrow new Error(\"Could not find an available port after multiple attempts\");\n}\n","import { z } from \"zod\";\nimport { RunnerConfigSchema } from \"@/registry/run-config\";\n\nexport const ConfigSchema = RunnerConfigSchema.removeDefault()\n\t.extend({\n\t\thostname: z\n\t\t\t.string()\n\t\t\t.optional()\n\t\t\t.default(process.env.HOSTNAME ?? \"127.0.0.1\"),\n\t\tport: z\n\t\t\t.number()\n\t\t\t.optional()\n\t\t\t.default(Number.parseInt(process.env.PORT ?? \"8080\")),\n\t})\n\t.default({});\nexport type InputConfig = z.input<typeof ConfigSchema>;\n","import { getLogger } from \"@/common/log\";\n\nexport function logger() {\n\treturn getLogger(\"test\");\n}\n"]}
|
|
@@ -25,16 +25,6 @@ var ActorError = (_class = class extends Error {
|
|
|
25
25
|
toString() {
|
|
26
26
|
return this.message;
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Serialize error for HTTP response
|
|
30
|
-
*/
|
|
31
|
-
serializeForHttp() {
|
|
32
|
-
return {
|
|
33
|
-
type: this.code,
|
|
34
|
-
message: this.message,
|
|
35
|
-
metadata: this.metadata
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
28
|
}, _class);
|
|
39
29
|
var InternalError = class extends ActorError {
|
|
40
30
|
constructor(message) {
|
|
@@ -371,4 +361,4 @@ var RouteNotFound = class extends ActorError {
|
|
|
371
361
|
|
|
372
362
|
|
|
373
363
|
exports.INTERNAL_ERROR_CODE = INTERNAL_ERROR_CODE; exports.INTERNAL_ERROR_DESCRIPTION = INTERNAL_ERROR_DESCRIPTION; exports.USER_ERROR_CODE = USER_ERROR_CODE; exports.ActorError = ActorError; exports.InternalError = InternalError; exports.Unreachable = Unreachable; exports.StateNotEnabled = StateNotEnabled; exports.ConnStateNotEnabled = ConnStateNotEnabled; exports.VarsNotEnabled = VarsNotEnabled; exports.ActionTimedOut = ActionTimedOut; exports.ActionNotFound = ActionNotFound; exports.InvalidEncoding = InvalidEncoding; exports.ConnNotFound = ConnNotFound; exports.IncorrectConnToken = IncorrectConnToken; exports.MessageTooLong = MessageTooLong; exports.MalformedMessage = MalformedMessage; exports.InvalidStateType = InvalidStateType; exports.Unsupported = Unsupported; exports.UserError = UserError; exports.InvalidQueryJSON = InvalidQueryJSON; exports.InvalidRequest = InvalidRequest; exports.ActorNotFound = ActorNotFound; exports.ActorAlreadyExists = ActorAlreadyExists; exports.ProxyError = ProxyError; exports.InvalidActionRequest = InvalidActionRequest; exports.InvalidParams = InvalidParams; exports.Unauthorized = Unauthorized; exports.Forbidden = Forbidden; exports.DatabaseNotEnabled = DatabaseNotEnabled; exports.FetchHandlerNotDefined = FetchHandlerNotDefined; exports.WebSocketHandlerNotDefined = WebSocketHandlerNotDefined; exports.InvalidFetchResponse = InvalidFetchResponse; exports.MissingActorHeader = MissingActorHeader; exports.WebSocketsNotEnabled = WebSocketsNotEnabled; exports.FeatureNotImplemented = FeatureNotImplemented; exports.RouteNotFound = RouteNotFound;
|
|
374
|
-
//# sourceMappingURL=chunk-
|
|
364
|
+
//# sourceMappingURL=chunk-KSRXX3Z4.cjs.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IAAA;AACC,MAAA;AACA,MAAA;AACA,MAAA;AACD,IAAA;AACD,EAAA;AACD;AAEO;AACQ,EAAA;AACb,IAAA;AACC,MAAA;AACA,MAAA;AACA,MAAA;AACe,MAAA;AAChB,IAAA;AACkB,IAAA;AACnB,EAAA;AACD;AAEO;AACQ,EAAA;AACb,IAAA;AACC,MAAA;AACA,MAAA;AACA,MAAA;AACe,MAAA;AAChB,IAAA;AACkB,IAAA;AACnB,EAAA;AACD;AAEO;AACQ,EAAA;AACb,IAAA;AACC,MAAA;AACA,MAAA;AACA,MAAA;AACe,MAAA;AAChB,IAAA;AACkB,IAAA;AACnB,EAAA;AACD;AAGO;AACQ,EAAA;AACb,IAAA;AACC,MAAA;AACA,MAAA;AACA,MAAA;AACe,MAAA;AAChB,IAAA;AACkB,IAAA;AACnB,EAAA;AACD;AAEO;AACQ,EAAA;AACb,IAAA;AACC,MAAA;AACA,MAAA;AACA,MAAA;AACe,MAAA;AAChB,IAAA;AACkB,IAAA;AACnB,EAAA;AACD;AAEO;AACuB,EAAA;AACX,IAAA;AACR,MAAA;AACR,IAAA;AACiB,IAAA;AACnB,EAAA;AACD;AAEO;AACQ,EAAA;AACe,IAAA;AACV,IAAA;AACnB,EAAA;AACD;ADtFiC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-KSRXX3Z4.cjs","sourcesContent":[null,"import type { DeconstructedError } from \"@/common/utils\";\n\nexport const INTERNAL_ERROR_CODE = \"internal_error\";\nexport const INTERNAL_ERROR_DESCRIPTION =\n\t\"Internal error. Read the server logs for more details.\";\nexport type InternalErrorMetadata = {};\n\nexport const USER_ERROR_CODE = \"user_error\";\n\ninterface ActorErrorOptions extends ErrorOptions {\n\t/** Error data can safely be serialized in a response to the client. */\n\tpublic?: boolean;\n\t/** Metadata associated with this error. This will be sent to clients. */\n\tmetadata?: unknown;\n}\n\nexport class ActorError extends Error {\n\t__type = \"ActorError\";\n\n\tpublic public: boolean;\n\tpublic metadata?: unknown;\n\tpublic statusCode = 500;\n\tpublic readonly group: string;\n\tpublic readonly code: string;\n\n\tpublic static isActorError(\n\t\terror: unknown,\n\t): error is ActorError | DeconstructedError {\n\t\treturn (\n\t\t\ttypeof error === \"object\" &&\n\t\t\t(error as ActorError | DeconstructedError).__type === \"ActorError\"\n\t\t);\n\t}\n\n\tconstructor(\n\t\tgroup: string,\n\t\tcode: string,\n\t\tmessage: string,\n\t\topts?: ActorErrorOptions,\n\t) {\n\t\tsuper(message, { cause: opts?.cause });\n\t\tthis.group = group;\n\t\tthis.code = code;\n\t\tthis.public = opts?.public ?? false;\n\t\tthis.metadata = opts?.metadata;\n\n\t\t// Set status code based on error type\n\t\tif (opts?.public) {\n\t\t\tthis.statusCode = 400; // Bad request for public errors\n\t\t}\n\t}\n\n\ttoString() {\n\t\t// Force stringify to return the message\n\t\treturn this.message;\n\t}\n}\n\nexport class InternalError extends ActorError {\n\tconstructor(message: string) {\n\t\tsuper(\"actor\", INTERNAL_ERROR_CODE, message);\n\t}\n}\n\nexport class Unreachable extends InternalError {\n\tconstructor(x: never) {\n\t\tsuper(`Unreachable case: ${x}`);\n\t}\n}\n\nexport class StateNotEnabled extends ActorError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"actor\",\n\t\t\t\"state_not_enabled\",\n\t\t\t\"State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.dev/docs/actors/state/#initializing-state)\",\n\t\t);\n\t}\n}\n\nexport class ConnStateNotEnabled extends ActorError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"actor\",\n\t\t\t\"conn_state_not_enabled\",\n\t\t\t\"Connection state not enabled. Must implement `createConnectionState` or `connectionState` to use connection state. (https://www.rivet.dev/docs/actors/connections/#connection-state)\",\n\t\t);\n\t}\n}\n\nexport class VarsNotEnabled extends ActorError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"actor\",\n\t\t\t\"vars_not_enabled\",\n\t\t\t\"Variables not enabled. Must implement `createVars` or `vars` to use state. (https://www.rivet.dev/docs/actors/ephemeral-variables/#initializing-variables)\",\n\t\t);\n\t}\n}\n\nexport class ActionTimedOut extends ActorError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"action\",\n\t\t\t\"timed_out\",\n\t\t\t\"Action timed out. This can be increased with: `actor({ options: { action: { timeout: ... } } })`\",\n\t\t\t{ public: true },\n\t\t);\n\t}\n}\n\nexport class ActionNotFound extends ActorError {\n\tconstructor(name: string) {\n\t\tsuper(\n\t\t\t\"action\",\n\t\t\t\"not_found\",\n\t\t\t`Action '${name}' not found. Validate the action exists on your actor.`,\n\t\t\t{ public: true },\n\t\t);\n\t}\n}\n\nexport class InvalidEncoding extends ActorError {\n\tconstructor(format?: string) {\n\t\tsuper(\n\t\t\t\"encoding\",\n\t\t\t\"invalid\",\n\t\t\t`Invalid encoding \\`${format}\\`. (https://www.rivet.dev/docs/actors/clients/#actor-client)`,\n\t\t\t{\n\t\t\t\tpublic: true,\n\t\t\t},\n\t\t);\n\t}\n}\n\nexport class ConnNotFound extends ActorError {\n\tconstructor(id?: string) {\n\t\tsuper(\"connection\", \"not_found\", `Connection not found for ID: ${id}`, {\n\t\t\tpublic: true,\n\t\t});\n\t}\n}\n\nexport class IncorrectConnToken extends ActorError {\n\tconstructor() {\n\t\tsuper(\"connection\", \"incorrect_token\", \"Incorrect connection token.\", {\n\t\t\tpublic: true,\n\t\t});\n\t}\n}\n\nexport class MessageTooLong extends ActorError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"message\",\n\t\t\t\"too_long\",\n\t\t\t\"Message too long. This can be configured with: `registry.start({ maxIncomingMessageSize: ... })`\",\n\t\t\t{ public: true },\n\t\t);\n\t}\n}\n\nexport class MalformedMessage extends ActorError {\n\tconstructor(cause?: unknown) {\n\t\tsuper(\"message\", \"malformed\", `Malformed message: ${cause}`, {\n\t\t\tpublic: true,\n\t\t\tcause,\n\t\t});\n\t}\n}\n\nexport interface InvalidStateTypeOptions {\n\tpath?: unknown;\n}\n\nexport class InvalidStateType extends ActorError {\n\tconstructor(opts?: InvalidStateTypeOptions) {\n\t\tlet msg = \"\";\n\t\tif (opts?.path) {\n\t\t\tmsg += `Attempted to set invalid state at path \\`${opts.path}\\`.`;\n\t\t} else {\n\t\t\tmsg += \"Attempted to set invalid state.\";\n\t\t}\n\t\tmsg +=\n\t\t\t\" Valid types include: null, undefined, boolean, string, number, BigInt, Date, RegExp, Error, typed arrays (Uint8Array, Int8Array, Float32Array, etc.), Map, Set, Array, and plain objects. (https://www.rivet.dev/docs/actors/state/#limitations)\";\n\t\tsuper(\"state\", \"invalid_type\", msg);\n\t}\n}\n\nexport class Unsupported extends ActorError {\n\tconstructor(feature: string) {\n\t\tsuper(\"feature\", \"unsupported\", `Unsupported feature: ${feature}`);\n\t}\n}\n\n/**\n * Options for the UserError class.\n */\nexport interface UserErrorOptions extends ErrorOptions {\n\t/**\n\t * Machine readable code for this error. Useful for catching different types of errors in try-catch.\n\t */\n\tcode?: string;\n\n\t/**\n\t * Additional metadata related to the error. Useful for understanding context about the error.\n\t */\n\tmetadata?: unknown;\n}\n\n/** Error that can be safely returned to the user. */\nexport class UserError extends ActorError {\n\t/**\n\t * Constructs a new UserError instance.\n\t *\n\t * @param message - The error message to be displayed.\n\t * @param opts - Optional parameters for the error, including a machine-readable code and additional metadata.\n\t */\n\tconstructor(message: string, opts?: UserErrorOptions) {\n\t\tsuper(\"user\", opts?.code ?? USER_ERROR_CODE, message, {\n\t\t\tpublic: true,\n\t\t\tmetadata: opts?.metadata,\n\t\t});\n\t}\n}\n\nexport class InvalidQueryJSON extends ActorError {\n\tconstructor(error?: unknown) {\n\t\tsuper(\"request\", \"invalid_query_json\", `Invalid query JSON: ${error}`, {\n\t\t\tpublic: true,\n\t\t\tcause: error,\n\t\t});\n\t}\n}\n\nexport class InvalidRequest extends ActorError {\n\tconstructor(error?: unknown) {\n\t\tsuper(\"request\", \"invalid\", `Invalid request: ${error}`, {\n\t\t\tpublic: true,\n\t\t\tcause: error,\n\t\t});\n\t}\n}\n\nexport class ActorNotFound extends ActorError {\n\tconstructor(identifier?: string) {\n\t\tsuper(\n\t\t\t\"actor\",\n\t\t\t\"not_found\",\n\t\t\tidentifier\n\t\t\t\t? `Actor not found: ${identifier} (https://www.rivet.dev/docs/actors/clients/#actor-client)`\n\t\t\t\t: \"Actor not found (https://www.rivet.dev/docs/actors/clients/#actor-client)\",\n\t\t\t{ public: true },\n\t\t);\n\t}\n}\n\nexport class ActorAlreadyExists extends ActorError {\n\tconstructor(name: string, key: string[]) {\n\t\tsuper(\n\t\t\t\"actor\",\n\t\t\t\"already_exists\",\n\t\t\t`Actor already exists with name '${name}' and key '${JSON.stringify(key)}' (https://www.rivet.dev/docs/actors/clients/#actor-client)`,\n\t\t\t{ public: true },\n\t\t);\n\t}\n}\n\nexport class ProxyError extends ActorError {\n\tconstructor(operation: string, error?: unknown) {\n\t\tsuper(\n\t\t\t\"proxy\",\n\t\t\t\"error\",\n\t\t\t`Error proxying ${operation}, this is likely an internal error: ${error}`,\n\t\t\t{\n\t\t\t\tpublic: true,\n\t\t\t\tcause: error,\n\t\t\t},\n\t\t);\n\t}\n}\n\nexport class InvalidActionRequest extends ActorError {\n\tconstructor(message: string) {\n\t\tsuper(\"action\", \"invalid_request\", message, { public: true });\n\t}\n}\n\nexport class InvalidParams extends ActorError {\n\tconstructor(message: string) {\n\t\tsuper(\"params\", \"invalid\", message, { public: true });\n\t}\n}\n\nexport class Unauthorized extends ActorError {\n\tconstructor(message?: string) {\n\t\tsuper(\n\t\t\t\"auth\",\n\t\t\t\"unauthorized\",\n\t\t\tmessage ??\n\t\t\t\t\"Unauthorized. Access denied. (https://www.rivet.dev/docs/actors/authentication/)\",\n\t\t\t{\n\t\t\t\tpublic: true,\n\t\t\t},\n\t\t);\n\t\tthis.statusCode = 401;\n\t}\n}\n\nexport class Forbidden extends ActorError {\n\tconstructor(message?: string, opts?: { metadata?: unknown }) {\n\t\tsuper(\n\t\t\t\"auth\",\n\t\t\t\"forbidden\",\n\t\t\tmessage ??\n\t\t\t\t\"Forbidden. Access denied. (https://www.rivet.dev/docs/actors/authentication/)\",\n\t\t\t{\n\t\t\t\tpublic: true,\n\t\t\t\tmetadata: opts?.metadata,\n\t\t\t},\n\t\t);\n\t\tthis.statusCode = 403;\n\t}\n}\n\nexport class DatabaseNotEnabled extends ActorError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"database\",\n\t\t\t\"not_enabled\",\n\t\t\t\"Database not enabled. Must implement `database` to use database.\",\n\t\t);\n\t}\n}\n\nexport class FetchHandlerNotDefined extends ActorError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"handler\",\n\t\t\t\"fetch_not_defined\",\n\t\t\t\"Raw HTTP handler not defined. Actor must implement `onFetch` to handle raw HTTP requests. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)\",\n\t\t\t{ public: true },\n\t\t);\n\t\tthis.statusCode = 404;\n\t}\n}\n\nexport class WebSocketHandlerNotDefined extends ActorError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"handler\",\n\t\t\t\"websocket_not_defined\",\n\t\t\t\"Raw WebSocket handler not defined. Actor must implement `onWebSocket` to handle raw WebSocket connections. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)\",\n\t\t\t{ public: true },\n\t\t);\n\t\tthis.statusCode = 404;\n\t}\n}\n\nexport class InvalidFetchResponse extends ActorError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"handler\",\n\t\t\t\"invalid_fetch_response\",\n\t\t\t\"Actor's onFetch handler must return a Response object. Returning void/undefined is not allowed. (https://www.rivet.dev/docs/actors/fetch-and-websocket-handler/)\",\n\t\t\t{ public: true },\n\t\t);\n\t\tthis.statusCode = 500;\n\t}\n}\n\n// Manager-specific errors\nexport class MissingActorHeader extends ActorError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"request\",\n\t\t\t\"missing_actor_header\",\n\t\t\t\"Missing x-rivet-actor header when x-rivet-target=actor\",\n\t\t\t{ public: true },\n\t\t);\n\t\tthis.statusCode = 400;\n\t}\n}\n\nexport class WebSocketsNotEnabled extends ActorError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t\"driver\",\n\t\t\t\"websockets_not_enabled\",\n\t\t\t\"WebSockets are not enabled for this driver\",\n\t\t\t{ public: true },\n\t\t);\n\t\tthis.statusCode = 400;\n\t}\n}\n\nexport class FeatureNotImplemented extends ActorError {\n\tconstructor(feature: string) {\n\t\tsuper(\"feature\", \"not_implemented\", `${feature} is not implemented`, {\n\t\t\tpublic: true,\n\t\t});\n\t\tthis.statusCode = 501;\n\t}\n}\n\nexport class RouteNotFound extends ActorError {\n\tconstructor() {\n\t\tsuper(\"route\", \"not_found\", \"Route not found\", { public: true });\n\t\tthis.statusCode = 404;\n\t}\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkOWPBIHFMcjs = require('./chunk-OWPBIHFM.cjs');
|
|
4
4
|
|
|
5
5
|
// src/common/log.ts
|
|
6
6
|
|
|
@@ -128,7 +128,7 @@ function getPinoLevel(logLevel) {
|
|
|
128
128
|
if (configuredLogLevel) {
|
|
129
129
|
return configuredLogLevel;
|
|
130
130
|
}
|
|
131
|
-
const raw = (
|
|
131
|
+
const raw = (_chunkOWPBIHFMcjs.getEnvUniversal.call(void 0, "LOG_LEVEL") || "warn").toString().toLowerCase();
|
|
132
132
|
const parsed = LogLevelSchema.safeParse(raw);
|
|
133
133
|
if (parsed.success) {
|
|
134
134
|
return parsed.data;
|
|
@@ -136,7 +136,7 @@ function getPinoLevel(logLevel) {
|
|
|
136
136
|
return "info";
|
|
137
137
|
}
|
|
138
138
|
function getIncludeTarget() {
|
|
139
|
-
return
|
|
139
|
+
return _chunkOWPBIHFMcjs.getEnvUniversal.call(void 0, "LOG_TARGET") === "1";
|
|
140
140
|
}
|
|
141
141
|
function configureBaseLogger(logger) {
|
|
142
142
|
baseLogger = logger;
|
|
@@ -144,7 +144,7 @@ function configureBaseLogger(logger) {
|
|
|
144
144
|
}
|
|
145
145
|
function customWrite(level, o) {
|
|
146
146
|
const entries = {};
|
|
147
|
-
if (
|
|
147
|
+
if (_chunkOWPBIHFMcjs.getEnvUniversal.call(void 0, "LOG_TIMESTAMP") === "1" && o.time) {
|
|
148
148
|
const date = typeof o.time === "number" ? new Date(o.time) : /* @__PURE__ */ new Date();
|
|
149
149
|
entries.ts = formatTimestamp(date);
|
|
150
150
|
}
|
|
@@ -178,7 +178,7 @@ async function configureDefaultLogger(logLevel) {
|
|
|
178
178
|
return { level: number };
|
|
179
179
|
}
|
|
180
180
|
},
|
|
181
|
-
timestamp:
|
|
181
|
+
timestamp: _chunkOWPBIHFMcjs.getEnvUniversal.call(void 0, "LOG_TIMESTAMP") === "1" ? _pino.stdTimeFunctions.epochTime : false,
|
|
182
182
|
browser: {
|
|
183
183
|
write: {
|
|
184
184
|
fatal: customWrite.bind(null, "fatal"),
|
|
@@ -200,7 +200,7 @@ async function configureDefaultLogger(logLevel) {
|
|
|
200
200
|
60: "fatal"
|
|
201
201
|
};
|
|
202
202
|
const levelName = levelMap[level] || "info";
|
|
203
|
-
const time =
|
|
203
|
+
const time = _chunkOWPBIHFMcjs.getEnvUniversal.call(void 0, "LOG_TIMESTAMP") === "1" ? Date.now() : void 0;
|
|
204
204
|
if (inputArgs.length >= 2) {
|
|
205
205
|
const [objOrMsg, msg] = inputArgs;
|
|
206
206
|
if (typeof objOrMsg === "object" && objOrMsg !== null) {
|
|
@@ -247,4 +247,4 @@ function getLogger(name = "default") {
|
|
|
247
247
|
|
|
248
248
|
|
|
249
249
|
exports.LogLevelSchema = LogLevelSchema; exports.getPinoLevel = getPinoLevel; exports.getIncludeTarget = getIncludeTarget; exports.configureBaseLogger = configureBaseLogger; exports.configureDefaultLogger = configureDefaultLogger; exports.getBaseLogger = getBaseLogger; exports.getLogger = getLogger;
|
|
250
|
-
//# sourceMappingURL=chunk-
|
|
250
|
+
//# sourceMappingURL=chunk-MF76IOZD.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-4NPHS4GT.cjs","../../src/common/log.ts","../../src/common/log-levels.ts","../../src/common/logfmt.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA;AAGC;AACA;AAAA,4BACM;AACP,0BAAkB;ADIlB;AACA;AEHO,IAAM,UAAA,EAA0C;AAAA,EACtD,KAAA,EAAO,CAAA;AAAA,EACP,KAAA,EAAO,CAAA;AAAA,EACP,IAAA,EAAM,CAAA;AAAA,EACN,IAAA,EAAM,CAAA;AAAA,EACN,KAAA,EAAO,CAAA;AAAA,EACP,QAAA,EAAU;AACX,CAAA;AFKA;AACA;AGnBA,IAAM,iBAAA,EAA2C;AAAA,EAChD,CAAC,SAAA,CAAU,QAAQ,CAAA,EAAG,UAAA;AAAA;AAAA,EACtB,CAAC,SAAA,CAAU,KAAK,CAAA,EAAG,UAAA;AAAA;AAAA,EACnB,CAAC,SAAA,CAAU,IAAI,CAAA,EAAG,UAAA;AAAA;AAAA,EAClB,CAAC,SAAA,CAAU,IAAI,CAAA,EAAG,UAAA;AAAA;AAAA,EAClB,CAAC,SAAA,CAAU,KAAK,CAAA,EAAG,UAAA;AAAA;AAAA,EACnB,CAAC,SAAA,CAAU,KAAK,CAAA,EAAG;AAAA;AACpB,CAAA;AAEA,IAAM,YAAA,EAAc,SAAA;AAiBb,SAAS,SAAA,CAAU,IAAA,EAAW;AACpC,EAAA,IAAI,KAAA,EAAO,EAAA;AACX,EAAA,MAAM,QAAA,EAAU,M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EAAA;AACR;AAK0B;AAEV,EAAA;AACH,EAAA;AACJ,IAAA;AACR,EAAA;AAGa,EAAA;AAGC,EAAA;AAGE,EAAA;AAET,EAAA;AACR;AD0BqB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-4NPHS4GT.cjs","sourcesContent":[null,"import {\n\ttype LevelWithSilent,\n\ttype Logger,\n\tpino,\n\tstdTimeFunctions,\n} from \"pino\";\nimport { z } from \"zod\";\nimport { getEnvUniversal } from \"@/utils\";\nimport {\n\tcastToLogValue,\n\tformatTimestamp,\n\tLOGGER_CONFIG,\n\tstringify,\n} from \"./logfmt\";\n\nexport type { Logger } from \"pino\";\n\nlet baseLogger: Logger | undefined;\nlet configuredLogLevel: LogLevel | undefined;\n\n/** Cache of child loggers by logger name. */\nconst loggerCache = new Map<string, Logger>();\n\nexport const LogLevelSchema = z.enum([\n\t\"trace\",\n\t\"debug\",\n\t\"info\",\n\t\"warn\",\n\t\"error\",\n\t\"fatal\",\n\t\"silent\",\n]);\n\nexport type LogLevel = z.infer<typeof LogLevelSchema>;\n\nexport function getPinoLevel(logLevel?: LogLevel): LevelWithSilent {\n\t// Priority: provided > configured > env > default\n\tif (logLevel) {\n\t\treturn logLevel;\n\t}\n\n\tif (configuredLogLevel) {\n\t\treturn configuredLogLevel;\n\t}\n\n\tconst raw = (getEnvUniversal(\"LOG_LEVEL\") || \"warn\").toString().toLowerCase();\n\n\tconst parsed = LogLevelSchema.safeParse(raw);\n\tif (parsed.success) {\n\t\treturn parsed.data;\n\t}\n\n\t// Default to info if invalid\n\treturn \"info\";\n}\n\nexport function getIncludeTarget(): boolean {\n\treturn getEnvUniversal(\"LOG_TARGET\") === \"1\";\n}\n\n/**\n * Configure a custom base logger.\n */\nexport function configureBaseLogger(logger: Logger): void {\n\tbaseLogger = logger;\n\tloggerCache.clear();\n}\n\n// TODO: This can be simplified in logfmt.ts\nfunction customWrite(level: string, o: any) {\n\tconst entries: any = {};\n\n\t// Add timestamp if enabled\n\tif (getEnvUniversal(\"LOG_TIMESTAMP\") === \"1\" && o.time) {\n\t\tconst date = typeof o.time === \"number\" ? new Date(o.time) : new Date();\n\t\tentries.ts = formatTimestamp(date);\n\t}\n\n\t// Add level\n\tentries.level = level.toUpperCase();\n\n\t// Add target if present\n\tif (o.target) {\n\t\tentries.target = o.target;\n\t}\n\n\t// Add message\n\tif (o.msg) {\n\t\tentries.msg = o.msg;\n\t}\n\n\t// Add other properties\n\tfor (const [key, value] of Object.entries(o)) {\n\t\tif (\n\t\t\tkey !== \"time\" &&\n\t\t\tkey !== \"level\" &&\n\t\t\tkey !== \"target\" &&\n\t\t\tkey !== \"msg\" &&\n\t\t\tkey !== \"pid\" &&\n\t\t\tkey !== \"hostname\"\n\t\t) {\n\t\t\tentries[key] = castToLogValue(value);\n\t\t}\n\t}\n\n\tconst output = stringify(entries);\n\tconsole.log(output);\n}\n\n/**\n * Configure the default logger with optional log level.\n */\nexport async function configureDefaultLogger(\n\tlogLevel?: LogLevel,\n): Promise<void> {\n\t// Store the configured log level\n\tif (logLevel) {\n\t\tconfiguredLogLevel = logLevel;\n\t}\n\n\tbaseLogger = pino({\n\t\tlevel: getPinoLevel(logLevel),\n\t\tmessageKey: \"msg\",\n\t\t// Do not include pid/hostname in output\n\t\tbase: {},\n\t\t// Keep a string level in the output\n\t\tformatters: {\n\t\t\tlevel(_label: string, number: number) {\n\t\t\t\treturn { level: number };\n\t\t\t},\n\t\t},\n\t\ttimestamp:\n\t\t\tgetEnvUniversal(\"LOG_TIMESTAMP\") === \"1\"\n\t\t\t\t? stdTimeFunctions.epochTime\n\t\t\t\t: false,\n\t\tbrowser: {\n\t\t\twrite: {\n\t\t\t\tfatal: customWrite.bind(null, \"fatal\"),\n\t\t\t\terror: customWrite.bind(null, \"error\"),\n\t\t\t\twarn: customWrite.bind(null, \"warn\"),\n\t\t\t\tinfo: customWrite.bind(null, \"info\"),\n\t\t\t\tdebug: customWrite.bind(null, \"debug\"),\n\t\t\t\ttrace: customWrite.bind(null, \"trace\"),\n\t\t\t},\n\t\t},\n\t\thooks: {\n\t\t\tlogMethod(inputArgs, _method, level) {\n\t\t\t\t// TODO: This is a hack to not implement our own transport target. We can get better perf if we have our own transport target.\n\n\t\t\t\tconst levelMap: Record<number, string> = {\n\t\t\t\t\t10: \"trace\",\n\t\t\t\t\t20: \"debug\",\n\t\t\t\t\t30: \"info\",\n\t\t\t\t\t40: \"warn\",\n\t\t\t\t\t50: \"error\",\n\t\t\t\t\t60: \"fatal\",\n\t\t\t\t};\n\t\t\t\tconst levelName = levelMap[level] || \"info\";\n\t\t\t\tconst time =\n\t\t\t\t\tgetEnvUniversal(\"LOG_TIMESTAMP\") === \"1\" ? Date.now() : undefined;\n\t\t\t\t// TODO: This can be simplified in logfmt.ts\n\t\t\t\tif (inputArgs.length >= 2) {\n\t\t\t\t\tconst [objOrMsg, msg] = inputArgs;\n\t\t\t\t\tif (typeof objOrMsg === \"object\" && objOrMsg !== null) {\n\t\t\t\t\t\tcustomWrite(levelName, { ...objOrMsg, msg, time });\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcustomWrite(levelName, { msg: String(objOrMsg), time });\n\t\t\t\t\t}\n\t\t\t\t} else if (inputArgs.length === 1) {\n\t\t\t\t\tconst [objOrMsg] = inputArgs;\n\t\t\t\t\tif (typeof objOrMsg === \"object\" && objOrMsg !== null) {\n\t\t\t\t\t\tcustomWrite(levelName, { ...objOrMsg, time });\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcustomWrite(levelName, { msg: String(objOrMsg), time });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t});\n\n\tloggerCache.clear();\n}\n\n/**\n * Get or initialize the base logger.\n */\nexport function getBaseLogger(): Logger {\n\tif (!baseLogger) {\n\t\tconfigureDefaultLogger();\n\t}\n\treturn baseLogger!;\n}\n\n/**\n * Returns a child logger with `target` bound for the given name.\n */\nexport function getLogger(name = \"default\"): Logger {\n\t// Check cache first\n\tconst cached = loggerCache.get(name);\n\tif (cached) {\n\t\treturn cached;\n\t}\n\n\t// Create\n\tconst base = getBaseLogger();\n\n\t// Add target to log if enabled\n\tconst child = getIncludeTarget() ? base.child({ target: name }) : base;\n\n\t// Cache the logger\n\tloggerCache.set(name, child);\n\n\treturn child;\n}\n","export type LogLevel =\n\t| \"TRACE\"\n\t| \"DEBUG\"\n\t| \"INFO\"\n\t| \"WARN\"\n\t| \"ERROR\"\n\t| \"CRITICAL\";\n\nexport const LogLevels: Record<LogLevel, LevelIndex> = {\n\tTRACE: 0,\n\tDEBUG: 1,\n\tINFO: 2,\n\tWARN: 3,\n\tERROR: 4,\n\tCRITICAL: 5,\n} as const;\n\nexport const LevelNameMap: Record<number, LogLevel> = {\n\t0: \"TRACE\",\n\t1: \"DEBUG\",\n\t2: \"INFO\",\n\t3: \"WARN\",\n\t4: \"ERROR\",\n\t5: \"CRITICAL\",\n};\n\nexport type LevelIndex = number;\n","import { type LogLevel, LogLevels } from \"./log-levels\";\n\nconst LOG_LEVEL_COLORS: Record<number, string> = {\n\t[LogLevels.CRITICAL]: \"\\x1b[31m\", // Red\n\t[LogLevels.ERROR]: \"\\x1b[31m\", // Red\n\t[LogLevels.WARN]: \"\\x1b[33m\", // Yellow\n\t[LogLevels.INFO]: \"\\x1b[32m\", // Green\n\t[LogLevels.DEBUG]: \"\\x1b[36m\", // Cyan\n\t[LogLevels.TRACE]: \"\\x1b[36m\", // Cyan\n};\n\nconst RESET_COLOR = \"\\x1b[0m\";\n\n/**\n * Serializes logfmt line from an object.\n *\n * ## Styling Methodology\n *\n * The three things you need to know for every log line is the level, the\n * message, and who called it. These properties are highlighted in different colros\n * and sorted in th eorder that you usually read them.\n *\n * Once you've found a log line you care about, then you want to find the\n * property you need to see. The property names are bolded and the default color\n * while the rest of the data is dim. This lets you scan to find the property\n * name quickly then look closer to read the data associated with the\n * property.\n */\nexport function stringify(data: any) {\n\tlet line = \"\";\n\tconst entries = Object.entries(data);\n\n\tfor (let i = 0; i < entries.length; i++) {\n\t\tconst [key, valueRaw] = entries[i];\n\n\t\tlet isNull = false;\n\t\tlet valueString: string;\n\t\tif (valueRaw == null) {\n\t\t\tisNull = true;\n\t\t\tvalueString = \"\";\n\t\t} else {\n\t\t\tvalueString = valueRaw.toString();\n\t\t}\n\n\t\t// Clip value unless specifically the error message\n\t\tif (valueString.length > 512 && key !== \"msg\" && key !== \"error\")\n\t\t\tvalueString = `${valueString.slice(0, 512)}...`;\n\n\t\tconst needsQuoting =\n\t\t\tvalueString.indexOf(\" \") > -1 || valueString.indexOf(\"=\") > -1;\n\t\tconst needsEscaping =\n\t\t\tvalueString.indexOf('\"') > -1 || valueString.indexOf(\"\\\\\") > -1;\n\n\t\tvalueString = valueString.replace(/\\n/g, \"\\\\n\");\n\t\tif (needsEscaping) valueString = valueString.replace(/[\"\\\\]/g, \"\\\\$&\");\n\t\tif (needsQuoting || needsEscaping) valueString = `\"${valueString}\"`;\n\t\tif (valueString === \"\" && !isNull) valueString = '\"\"';\n\n\t\tif (LOGGER_CONFIG.enableColor) {\n\t\t\t// With color\n\n\t\t\t// Special message colors\n\t\t\tlet color = \"\\x1b[2m\";\n\t\t\tif (key === \"level\") {\n\t\t\t\tconst level = LogLevels[valueString as LogLevel];\n\t\t\t\tconst levelColor = LOG_LEVEL_COLORS[level];\n\t\t\t\tif (levelColor) {\n\t\t\t\t\tcolor = levelColor;\n\t\t\t\t}\n\t\t\t} else if (key === \"msg\") {\n\t\t\t\tcolor = \"\\x1b[32m\";\n\t\t\t} else if (key === \"trace\") {\n\t\t\t\tcolor = \"\\x1b[34m\";\n\t\t\t}\n\n\t\t\t// Format line\n\t\t\tline += `\\x1b[0m\\x1b[1m${key}\\x1b[0m\\x1b[2m=\\x1b[0m${color}${valueString}${RESET_COLOR}`;\n\t\t} else {\n\t\t\t// No color\n\t\t\tline += `${key}=${valueString}`;\n\t\t}\n\n\t\tif (i !== entries.length - 1) {\n\t\t\tline += \" \";\n\t\t}\n\t}\n\n\treturn line;\n}\n\nexport function formatTimestamp(date: Date): string {\n\tconst year = date.getUTCFullYear();\n\tconst month = String(date.getUTCMonth() + 1).padStart(2, \"0\");\n\tconst day = String(date.getUTCDate()).padStart(2, \"0\");\n\tconst hours = String(date.getUTCHours()).padStart(2, \"0\");\n\tconst minutes = String(date.getUTCMinutes()).padStart(2, \"0\");\n\tconst seconds = String(date.getUTCSeconds()).padStart(2, \"0\");\n\tconst milliseconds = String(date.getUTCMilliseconds()).padStart(3, \"0\");\n\n\treturn `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}Z`;\n}\n\nexport function castToLogValue(v: unknown): any {\n\tif (\n\t\ttypeof v === \"string\" ||\n\t\ttypeof v === \"number\" ||\n\t\ttypeof v === \"bigint\" ||\n\t\ttypeof v === \"boolean\" ||\n\t\tv === null ||\n\t\tv === undefined\n\t) {\n\t\treturn v;\n\t}\n\tif (v instanceof Error) {\n\t\t//args.push(...errorToLogEntries(k, v));\n\t\treturn String(v);\n\t}\n\ttry {\n\t\treturn JSON.stringify(v);\n\t} catch {\n\t\treturn \"[cannot stringify]\";\n\t}\n}\n\n// MARK: Config\ninterface GlobalLoggerConfig {\n\tenableColor: boolean;\n\tenableSpreadObject: boolean;\n\tenableErrorStack: boolean;\n}\n\nexport const LOGGER_CONFIG: GlobalLoggerConfig = {\n\tenableColor: false,\n\tenableSpreadObject: false,\n\tenableErrorStack: false,\n};\n\n// MARK: Utils\n/**\n * Converts an object in to an easier to read KV of entries.\n */\nexport function spreadObjectToLogEntries(base: string, data: unknown): any {\n\tif (\n\t\tLOGGER_CONFIG.enableSpreadObject &&\n\t\ttypeof data === \"object\" &&\n\t\t!Array.isArray(data) &&\n\t\tdata !== null &&\n\t\tObject.keys(data).length !== 0 &&\n\t\tObject.keys(data).length < 16\n\t) {\n\t\tconst logData: any = {};\n\t\tfor (const key in data) {\n\t\t\tObject.assign(\n\t\t\t\tlogData,\n\t\t\t\tspreadObjectToLogEntries(\n\t\t\t\t\t`${base}.${key}`,\n\t\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: FIXME\n\t\t\t\t\t(data as any)[key],\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\treturn logData;\n\t}\n\n\treturn { [base]: JSON.stringify(data) };\n}\n\nexport function errorToLogEntries(base: string, error: unknown): any {\n\tif (error instanceof Error) {\n\t\treturn {\n\t\t\t[`${base}.message`]: error.message,\n\t\t\t...(LOGGER_CONFIG.enableErrorStack && error.stack\n\t\t\t\t? { [`${base}.stack`]: formatStackTrace(error.stack) }\n\t\t\t\t: {}),\n\t\t\t...(error.cause ? errorToLogEntries(`${base}.cause`, error.cause) : {}),\n\t\t};\n\t}\n\treturn { [base]: `${error}` };\n}\n\n// export function errorToLogEntries(base: string, error: unknown): LogEntry[] {\n// \tif (error instanceof RuntimeError) {\n// \t\treturn [\n// \t\t\t[`${base}.code`, error.code],\n// \t\t\t[`${base}.description`, error.errorConfig?.description],\n// \t\t\t[`${base}.module`, error.moduleName],\n// \t\t\t...(error.trace ? [[`${base}.trace`, stringifyTrace(error.trace)] as LogEntry] : []),\n// \t\t\t...(LOGGER_CONFIG.enableErrorStack && error.stack\n// \t\t\t\t? [[`${base}.stack`, formatStackTrace(error.stack)] as LogEntry]\n// \t\t\t\t: []),\n// \t\t\t...(error.meta ? [[`${base}.meta`, JSON.stringify(error.meta)] as LogEntry] : []),\n// \t\t\t...(error.cause ? errorToLogEntries(`${base}.cause`, error.cause) : []),\n// \t\t];\n// \t} else if (error instanceof Error) {\n// \t\treturn [\n// \t\t\t[`${base}.name`, error.name],\n// \t\t\t[`${base}.message`, error.message],\n// \t\t\t...(LOGGER_CONFIG.enableErrorStack && error.stack\n// \t\t\t\t? [[`${base}.stack`, formatStackTrace(error.stack)] as LogEntry]\n// \t\t\t\t: []),\n// \t\t\t...(error.cause ? errorToLogEntries(`${base}.cause`, error.cause) : []),\n// \t\t];\n// \t} else {\n// \t\treturn [\n// \t\t\t[base, `${error}`],\n// \t\t];\n// \t}\n// }\n\n/**\n * Formats a JS stack trace in to a legible one-liner.\n */\nfunction formatStackTrace(stackTrace: string): string {\n\tconst regex = /at (.+?)$/gm;\n\tconst matches = [...stackTrace.matchAll(regex)];\n\t// Reverse array since the stack goes from top level -> bottom level\n\tmatches.reverse();\n\treturn matches.map((match) => match[1].trim()).join(\" > \");\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-MF76IOZD.cjs","../../src/common/log.ts","../../src/common/log-levels.ts","../../src/common/logfmt.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA;AAGC;AACA;AAAA,4BACM;AACP,0BAAkB;ADIlB;AACA;AEHO,IAAM,UAAA,EAA0C;AAAA,EACtD,KAAA,EAAO,CAAA;AAAA,EACP,KAAA,EAAO,CAAA;AAAA,EACP,IAAA,EAAM,CAAA;AAAA,EACN,IAAA,EAAM,CAAA;AAAA,EACN,KAAA,EAAO,CAAA;AAAA,EACP,QAAA,EAAU;AACX,CAAA;AFKA;AACA;AGnBA,IAAM,iBAAA,EAA2C;AAAA,EAChD,CAAC,SAAA,CAAU,QAAQ,CAAA,EAAG,UAAA;AAAA;AAAA,EACtB,CAAC,SAAA,CAAU,KAAK,CAAA,EAAG,UAAA;AAAA;AAAA,EACnB,CAAC,SAAA,CAAU,IAAI,CAAA,EAAG,UAAA;AAAA;AAAA,EAClB,CAAC,SAAA,CAAU,IAAI,CAAA,EAAG,UAAA;AAAA;AAAA,EAClB,CAAC,SAAA,CAAU,KAAK,CAAA,EAAG,UAAA;AAAA;AAAA,EACnB,CAAC,SAAA,CAAU,KAAK,CAAA,EAAG;AAAA;AACpB,CAAA;AAEA,IAAM,YAAA,EAAc,SAAA;AAiBb,SAAS,SAAA,CAAU,IAAA,EAAW;AACpC,EAAA,IAAI,KAAA,EAAO,EAAA;AACX,EAAA,MAAM,QAAA,EAAU,MAAA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A;AACR;AAK0B;AAEV,EAAA;AACH,EAAA;AACJ,IAAA;AACR,EAAA;AAGa,EAAA;AAGC,EAAA;AAGE,EAAA;AAET,EAAA;AACR;AD0BqB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-MF76IOZD.cjs","sourcesContent":[null,"import {\n\ttype LevelWithSilent,\n\ttype Logger,\n\tpino,\n\tstdTimeFunctions,\n} from \"pino\";\nimport { z } from \"zod\";\nimport { getEnvUniversal } from \"@/utils\";\nimport {\n\tcastToLogValue,\n\tformatTimestamp,\n\tLOGGER_CONFIG,\n\tstringify,\n} from \"./logfmt\";\n\nexport type { Logger } from \"pino\";\n\nlet baseLogger: Logger | undefined;\nlet configuredLogLevel: LogLevel | undefined;\n\n/** Cache of child loggers by logger name. */\nconst loggerCache = new Map<string, Logger>();\n\nexport const LogLevelSchema = z.enum([\n\t\"trace\",\n\t\"debug\",\n\t\"info\",\n\t\"warn\",\n\t\"error\",\n\t\"fatal\",\n\t\"silent\",\n]);\n\nexport type LogLevel = z.infer<typeof LogLevelSchema>;\n\nexport function getPinoLevel(logLevel?: LogLevel): LevelWithSilent {\n\t// Priority: provided > configured > env > default\n\tif (logLevel) {\n\t\treturn logLevel;\n\t}\n\n\tif (configuredLogLevel) {\n\t\treturn configuredLogLevel;\n\t}\n\n\tconst raw = (getEnvUniversal(\"LOG_LEVEL\") || \"warn\").toString().toLowerCase();\n\n\tconst parsed = LogLevelSchema.safeParse(raw);\n\tif (parsed.success) {\n\t\treturn parsed.data;\n\t}\n\n\t// Default to info if invalid\n\treturn \"info\";\n}\n\nexport function getIncludeTarget(): boolean {\n\treturn getEnvUniversal(\"LOG_TARGET\") === \"1\";\n}\n\n/**\n * Configure a custom base logger.\n */\nexport function configureBaseLogger(logger: Logger): void {\n\tbaseLogger = logger;\n\tloggerCache.clear();\n}\n\n// TODO: This can be simplified in logfmt.ts\nfunction customWrite(level: string, o: any) {\n\tconst entries: any = {};\n\n\t// Add timestamp if enabled\n\tif (getEnvUniversal(\"LOG_TIMESTAMP\") === \"1\" && o.time) {\n\t\tconst date = typeof o.time === \"number\" ? new Date(o.time) : new Date();\n\t\tentries.ts = formatTimestamp(date);\n\t}\n\n\t// Add level\n\tentries.level = level.toUpperCase();\n\n\t// Add target if present\n\tif (o.target) {\n\t\tentries.target = o.target;\n\t}\n\n\t// Add message\n\tif (o.msg) {\n\t\tentries.msg = o.msg;\n\t}\n\n\t// Add other properties\n\tfor (const [key, value] of Object.entries(o)) {\n\t\tif (\n\t\t\tkey !== \"time\" &&\n\t\t\tkey !== \"level\" &&\n\t\t\tkey !== \"target\" &&\n\t\t\tkey !== \"msg\" &&\n\t\t\tkey !== \"pid\" &&\n\t\t\tkey !== \"hostname\"\n\t\t) {\n\t\t\tentries[key] = castToLogValue(value);\n\t\t}\n\t}\n\n\tconst output = stringify(entries);\n\tconsole.log(output);\n}\n\n/**\n * Configure the default logger with optional log level.\n */\nexport async function configureDefaultLogger(\n\tlogLevel?: LogLevel,\n): Promise<void> {\n\t// Store the configured log level\n\tif (logLevel) {\n\t\tconfiguredLogLevel = logLevel;\n\t}\n\n\tbaseLogger = pino({\n\t\tlevel: getPinoLevel(logLevel),\n\t\tmessageKey: \"msg\",\n\t\t// Do not include pid/hostname in output\n\t\tbase: {},\n\t\t// Keep a string level in the output\n\t\tformatters: {\n\t\t\tlevel(_label: string, number: number) {\n\t\t\t\treturn { level: number };\n\t\t\t},\n\t\t},\n\t\ttimestamp:\n\t\t\tgetEnvUniversal(\"LOG_TIMESTAMP\") === \"1\"\n\t\t\t\t? stdTimeFunctions.epochTime\n\t\t\t\t: false,\n\t\tbrowser: {\n\t\t\twrite: {\n\t\t\t\tfatal: customWrite.bind(null, \"fatal\"),\n\t\t\t\terror: customWrite.bind(null, \"error\"),\n\t\t\t\twarn: customWrite.bind(null, \"warn\"),\n\t\t\t\tinfo: customWrite.bind(null, \"info\"),\n\t\t\t\tdebug: customWrite.bind(null, \"debug\"),\n\t\t\t\ttrace: customWrite.bind(null, \"trace\"),\n\t\t\t},\n\t\t},\n\t\thooks: {\n\t\t\tlogMethod(inputArgs, _method, level) {\n\t\t\t\t// TODO: This is a hack to not implement our own transport target. We can get better perf if we have our own transport target.\n\n\t\t\t\tconst levelMap: Record<number, string> = {\n\t\t\t\t\t10: \"trace\",\n\t\t\t\t\t20: \"debug\",\n\t\t\t\t\t30: \"info\",\n\t\t\t\t\t40: \"warn\",\n\t\t\t\t\t50: \"error\",\n\t\t\t\t\t60: \"fatal\",\n\t\t\t\t};\n\t\t\t\tconst levelName = levelMap[level] || \"info\";\n\t\t\t\tconst time =\n\t\t\t\t\tgetEnvUniversal(\"LOG_TIMESTAMP\") === \"1\" ? Date.now() : undefined;\n\t\t\t\t// TODO: This can be simplified in logfmt.ts\n\t\t\t\tif (inputArgs.length >= 2) {\n\t\t\t\t\tconst [objOrMsg, msg] = inputArgs;\n\t\t\t\t\tif (typeof objOrMsg === \"object\" && objOrMsg !== null) {\n\t\t\t\t\t\tcustomWrite(levelName, { ...objOrMsg, msg, time });\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcustomWrite(levelName, { msg: String(objOrMsg), time });\n\t\t\t\t\t}\n\t\t\t\t} else if (inputArgs.length === 1) {\n\t\t\t\t\tconst [objOrMsg] = inputArgs;\n\t\t\t\t\tif (typeof objOrMsg === \"object\" && objOrMsg !== null) {\n\t\t\t\t\t\tcustomWrite(levelName, { ...objOrMsg, time });\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcustomWrite(levelName, { msg: String(objOrMsg), time });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t});\n\n\tloggerCache.clear();\n}\n\n/**\n * Get or initialize the base logger.\n */\nexport function getBaseLogger(): Logger {\n\tif (!baseLogger) {\n\t\tconfigureDefaultLogger();\n\t}\n\treturn baseLogger!;\n}\n\n/**\n * Returns a child logger with `target` bound for the given name.\n */\nexport function getLogger(name = \"default\"): Logger {\n\t// Check cache first\n\tconst cached = loggerCache.get(name);\n\tif (cached) {\n\t\treturn cached;\n\t}\n\n\t// Create\n\tconst base = getBaseLogger();\n\n\t// Add target to log if enabled\n\tconst child = getIncludeTarget() ? base.child({ target: name }) : base;\n\n\t// Cache the logger\n\tloggerCache.set(name, child);\n\n\treturn child;\n}\n","export type LogLevel =\n\t| \"TRACE\"\n\t| \"DEBUG\"\n\t| \"INFO\"\n\t| \"WARN\"\n\t| \"ERROR\"\n\t| \"CRITICAL\";\n\nexport const LogLevels: Record<LogLevel, LevelIndex> = {\n\tTRACE: 0,\n\tDEBUG: 1,\n\tINFO: 2,\n\tWARN: 3,\n\tERROR: 4,\n\tCRITICAL: 5,\n} as const;\n\nexport const LevelNameMap: Record<number, LogLevel> = {\n\t0: \"TRACE\",\n\t1: \"DEBUG\",\n\t2: \"INFO\",\n\t3: \"WARN\",\n\t4: \"ERROR\",\n\t5: \"CRITICAL\",\n};\n\nexport type LevelIndex = number;\n","import { type LogLevel, LogLevels } from \"./log-levels\";\n\nconst LOG_LEVEL_COLORS: Record<number, string> = {\n\t[LogLevels.CRITICAL]: \"\\x1b[31m\", // Red\n\t[LogLevels.ERROR]: \"\\x1b[31m\", // Red\n\t[LogLevels.WARN]: \"\\x1b[33m\", // Yellow\n\t[LogLevels.INFO]: \"\\x1b[32m\", // Green\n\t[LogLevels.DEBUG]: \"\\x1b[36m\", // Cyan\n\t[LogLevels.TRACE]: \"\\x1b[36m\", // Cyan\n};\n\nconst RESET_COLOR = \"\\x1b[0m\";\n\n/**\n * Serializes logfmt line from an object.\n *\n * ## Styling Methodology\n *\n * The three things you need to know for every log line is the level, the\n * message, and who called it. These properties are highlighted in different colros\n * and sorted in th eorder that you usually read them.\n *\n * Once you've found a log line you care about, then you want to find the\n * property you need to see. The property names are bolded and the default color\n * while the rest of the data is dim. This lets you scan to find the property\n * name quickly then look closer to read the data associated with the\n * property.\n */\nexport function stringify(data: any) {\n\tlet line = \"\";\n\tconst entries = Object.entries(data);\n\n\tfor (let i = 0; i < entries.length; i++) {\n\t\tconst [key, valueRaw] = entries[i];\n\n\t\tlet isNull = false;\n\t\tlet valueString: string;\n\t\tif (valueRaw == null) {\n\t\t\tisNull = true;\n\t\t\tvalueString = \"\";\n\t\t} else {\n\t\t\tvalueString = valueRaw.toString();\n\t\t}\n\n\t\t// Clip value unless specifically the error message\n\t\tif (valueString.length > 512 && key !== \"msg\" && key !== \"error\")\n\t\t\tvalueString = `${valueString.slice(0, 512)}...`;\n\n\t\tconst needsQuoting =\n\t\t\tvalueString.indexOf(\" \") > -1 || valueString.indexOf(\"=\") > -1;\n\t\tconst needsEscaping =\n\t\t\tvalueString.indexOf('\"') > -1 || valueString.indexOf(\"\\\\\") > -1;\n\n\t\tvalueString = valueString.replace(/\\n/g, \"\\\\n\");\n\t\tif (needsEscaping) valueString = valueString.replace(/[\"\\\\]/g, \"\\\\$&\");\n\t\tif (needsQuoting || needsEscaping) valueString = `\"${valueString}\"`;\n\t\tif (valueString === \"\" && !isNull) valueString = '\"\"';\n\n\t\tif (LOGGER_CONFIG.enableColor) {\n\t\t\t// With color\n\n\t\t\t// Special message colors\n\t\t\tlet color = \"\\x1b[2m\";\n\t\t\tif (key === \"level\") {\n\t\t\t\tconst level = LogLevels[valueString as LogLevel];\n\t\t\t\tconst levelColor = LOG_LEVEL_COLORS[level];\n\t\t\t\tif (levelColor) {\n\t\t\t\t\tcolor = levelColor;\n\t\t\t\t}\n\t\t\t} else if (key === \"msg\") {\n\t\t\t\tcolor = \"\\x1b[32m\";\n\t\t\t} else if (key === \"trace\") {\n\t\t\t\tcolor = \"\\x1b[34m\";\n\t\t\t}\n\n\t\t\t// Format line\n\t\t\tline += `\\x1b[0m\\x1b[1m${key}\\x1b[0m\\x1b[2m=\\x1b[0m${color}${valueString}${RESET_COLOR}`;\n\t\t} else {\n\t\t\t// No color\n\t\t\tline += `${key}=${valueString}`;\n\t\t}\n\n\t\tif (i !== entries.length - 1) {\n\t\t\tline += \" \";\n\t\t}\n\t}\n\n\treturn line;\n}\n\nexport function formatTimestamp(date: Date): string {\n\tconst year = date.getUTCFullYear();\n\tconst month = String(date.getUTCMonth() + 1).padStart(2, \"0\");\n\tconst day = String(date.getUTCDate()).padStart(2, \"0\");\n\tconst hours = String(date.getUTCHours()).padStart(2, \"0\");\n\tconst minutes = String(date.getUTCMinutes()).padStart(2, \"0\");\n\tconst seconds = String(date.getUTCSeconds()).padStart(2, \"0\");\n\tconst milliseconds = String(date.getUTCMilliseconds()).padStart(3, \"0\");\n\n\treturn `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}Z`;\n}\n\nexport function castToLogValue(v: unknown): any {\n\tif (\n\t\ttypeof v === \"string\" ||\n\t\ttypeof v === \"number\" ||\n\t\ttypeof v === \"bigint\" ||\n\t\ttypeof v === \"boolean\" ||\n\t\tv === null ||\n\t\tv === undefined\n\t) {\n\t\treturn v;\n\t}\n\tif (v instanceof Error) {\n\t\t//args.push(...errorToLogEntries(k, v));\n\t\treturn String(v);\n\t}\n\ttry {\n\t\treturn JSON.stringify(v);\n\t} catch {\n\t\treturn \"[cannot stringify]\";\n\t}\n}\n\n// MARK: Config\ninterface GlobalLoggerConfig {\n\tenableColor: boolean;\n\tenableSpreadObject: boolean;\n\tenableErrorStack: boolean;\n}\n\nexport const LOGGER_CONFIG: GlobalLoggerConfig = {\n\tenableColor: false,\n\tenableSpreadObject: false,\n\tenableErrorStack: false,\n};\n\n// MARK: Utils\n/**\n * Converts an object in to an easier to read KV of entries.\n */\nexport function spreadObjectToLogEntries(base: string, data: unknown): any {\n\tif (\n\t\tLOGGER_CONFIG.enableSpreadObject &&\n\t\ttypeof data === \"object\" &&\n\t\t!Array.isArray(data) &&\n\t\tdata !== null &&\n\t\tObject.keys(data).length !== 0 &&\n\t\tObject.keys(data).length < 16\n\t) {\n\t\tconst logData: any = {};\n\t\tfor (const key in data) {\n\t\t\tObject.assign(\n\t\t\t\tlogData,\n\t\t\t\tspreadObjectToLogEntries(\n\t\t\t\t\t`${base}.${key}`,\n\t\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: FIXME\n\t\t\t\t\t(data as any)[key],\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\treturn logData;\n\t}\n\n\treturn { [base]: JSON.stringify(data) };\n}\n\nexport function errorToLogEntries(base: string, error: unknown): any {\n\tif (error instanceof Error) {\n\t\treturn {\n\t\t\t[`${base}.message`]: error.message,\n\t\t\t...(LOGGER_CONFIG.enableErrorStack && error.stack\n\t\t\t\t? { [`${base}.stack`]: formatStackTrace(error.stack) }\n\t\t\t\t: {}),\n\t\t\t...(error.cause ? errorToLogEntries(`${base}.cause`, error.cause) : {}),\n\t\t};\n\t}\n\treturn { [base]: `${error}` };\n}\n\n// export function errorToLogEntries(base: string, error: unknown): LogEntry[] {\n// \tif (error instanceof RuntimeError) {\n// \t\treturn [\n// \t\t\t[`${base}.code`, error.code],\n// \t\t\t[`${base}.description`, error.errorConfig?.description],\n// \t\t\t[`${base}.module`, error.moduleName],\n// \t\t\t...(error.trace ? [[`${base}.trace`, stringifyTrace(error.trace)] as LogEntry] : []),\n// \t\t\t...(LOGGER_CONFIG.enableErrorStack && error.stack\n// \t\t\t\t? [[`${base}.stack`, formatStackTrace(error.stack)] as LogEntry]\n// \t\t\t\t: []),\n// \t\t\t...(error.meta ? [[`${base}.meta`, JSON.stringify(error.meta)] as LogEntry] : []),\n// \t\t\t...(error.cause ? errorToLogEntries(`${base}.cause`, error.cause) : []),\n// \t\t];\n// \t} else if (error instanceof Error) {\n// \t\treturn [\n// \t\t\t[`${base}.name`, error.name],\n// \t\t\t[`${base}.message`, error.message],\n// \t\t\t...(LOGGER_CONFIG.enableErrorStack && error.stack\n// \t\t\t\t? [[`${base}.stack`, formatStackTrace(error.stack)] as LogEntry]\n// \t\t\t\t: []),\n// \t\t\t...(error.cause ? errorToLogEntries(`${base}.cause`, error.cause) : []),\n// \t\t];\n// \t} else {\n// \t\treturn [\n// \t\t\t[base, `${error}`],\n// \t\t];\n// \t}\n// }\n\n/**\n * Formats a JS stack trace in to a legible one-liner.\n */\nfunction formatStackTrace(stackTrace: string): string {\n\tconst regex = /at (.+?)$/gm;\n\tconst matches = [...stackTrace.matchAll(regex)];\n\t// Reverse array since the stack goes from top level -> bottom level\n\tmatches.reverse();\n\treturn matches.map((match) => match[1].trim()).join(\" > \");\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkKSRXX3Z4cjs = require('./chunk-KSRXX3Z4.cjs');
|
|
6
6
|
|
|
7
7
|
// src/common/utils.ts
|
|
8
8
|
function assertUnreachable(x) {
|
|
@@ -96,7 +96,7 @@ function deconstructError(error, logger, extraLog, exposeInternalError = false)
|
|
|
96
96
|
let code;
|
|
97
97
|
let message;
|
|
98
98
|
let metadata;
|
|
99
|
-
if (
|
|
99
|
+
if (_chunkKSRXX3Z4cjs.ActorError.isActorError(error) && error.public) {
|
|
100
100
|
statusCode = "statusCode" in error && error.statusCode ? error.statusCode : 400;
|
|
101
101
|
public_ = true;
|
|
102
102
|
group = error.group;
|
|
@@ -113,7 +113,7 @@ function deconstructError(error, logger, extraLog, exposeInternalError = false)
|
|
|
113
113
|
...extraLog
|
|
114
114
|
});
|
|
115
115
|
} else if (exposeInternalError) {
|
|
116
|
-
if (
|
|
116
|
+
if (_chunkKSRXX3Z4cjs.ActorError.isActorError(error)) {
|
|
117
117
|
statusCode = 500;
|
|
118
118
|
public_ = false;
|
|
119
119
|
group = error.group;
|
|
@@ -133,7 +133,7 @@ function deconstructError(error, logger, extraLog, exposeInternalError = false)
|
|
|
133
133
|
statusCode = 500;
|
|
134
134
|
public_ = false;
|
|
135
135
|
group = "internal";
|
|
136
|
-
code =
|
|
136
|
+
code = _chunkKSRXX3Z4cjs.INTERNAL_ERROR_CODE;
|
|
137
137
|
message = getErrorMessage(error);
|
|
138
138
|
logger.info({
|
|
139
139
|
msg: "internal error",
|
|
@@ -149,8 +149,8 @@ function deconstructError(error, logger, extraLog, exposeInternalError = false)
|
|
|
149
149
|
statusCode = 500;
|
|
150
150
|
public_ = false;
|
|
151
151
|
group = "internal";
|
|
152
|
-
code =
|
|
153
|
-
message =
|
|
152
|
+
code = _chunkKSRXX3Z4cjs.INTERNAL_ERROR_CODE;
|
|
153
|
+
message = _chunkKSRXX3Z4cjs.INTERNAL_ERROR_DESCRIPTION;
|
|
154
154
|
metadata = {
|
|
155
155
|
//url: `https://hub.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,
|
|
156
156
|
};
|
|
@@ -208,7 +208,7 @@ function noopNext() {
|
|
|
208
208
|
// package.json
|
|
209
209
|
var package_default = {
|
|
210
210
|
name: "rivetkit",
|
|
211
|
-
version: "2.0.
|
|
211
|
+
version: "2.0.14",
|
|
212
212
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
213
213
|
license: "Apache-2.0",
|
|
214
214
|
keywords: [
|
|
@@ -574,4 +574,4 @@ function combineUrlPath(endpoint, path, queryParams) {
|
|
|
574
574
|
|
|
575
575
|
|
|
576
576
|
exports.assertUnreachable = assertUnreachable; exports.isCborSerializable = isCborSerializable; exports.deconstructError = deconstructError; exports.stringifyError = stringifyError; exports.noopNext = noopNext; exports.package_default = package_default; exports.VERSION = VERSION; exports.httpUserAgent = httpUserAgent; exports.getEnvUniversal = getEnvUniversal; exports.dbg = dbg; exports.toUint8Array = toUint8Array; exports.promiseWithResolvers = promiseWithResolvers; exports.setLongTimeout = setLongTimeout; exports.SinglePromiseQueue = SinglePromiseQueue; exports.bufferToArrayBuffer = bufferToArrayBuffer; exports.combineUrlPath = combineUrlPath;
|
|
577
|
-
//# sourceMappingURL=chunk-
|
|
577
|
+
//# sourceMappingURL=chunk-OWPBIHFM.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-63AELL54.cjs","../../src/common/utils.ts","../../package.json","../../src/utils.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACAO,SAAS,iBAAA,CAAkB,CAAA,EAAiB;AAClD,EAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kBAAA,EAAqB,CAAC,CAAA,CAAA;AACvC;AAuCC;AAIgC,EAAA;AACxB,IAAA;AACR,EAAA;AAE+B,EAAA;AACD,IAAA;AAC5B,MAAA;AACO,MAAA;AACR,IAAA;AACO,IAAA;AACR,EAAA;AAEkC,EAAA;AAC1B,IAAA;AACR,EAAA;AAG+B,EAAA;AACvB,IAAA;AACR,EAAA;AAG2B,EAAA;AACnB,IAAA;AACR,EAAA;AAKC,EAAA;AAWO,IAAA;AACR,EAAA;AAG0B,EAAA;AACM,IAAA;AAExB,MAAA;AAGA,MAAA;AAGoB,MAAA;AAGlB,QAAA;AACR,MAAA;AACD,IAAA;AACO,IAAA;AACR,EAAA;AAG0B,EAAA;AACb,IAAA;AACuB,IAAA;AAE5B,MAAA;AAEwB,MAAA;AACtB,QAAA;AACR,MAAA;AACA,MAAA;AACD,IAAA;AACO,IAAA;AACR,EAAA;AAG6B,EAAA;AACrB,IAAA;AACR,EAAA;AAG4B,EAAA;AACpB,IAAA;AACR,EAAA;AAG0B,EAAA;AACS,IAAA;AACC,MAAA;AACA,MAAA;AAC1B,QAAA;AACR,MAAA;AACD,IAAA;AACO,IAAA;AACR,EAAA;AAG+B,EAAA;AAEM,IAAA;AACJ,IAAA;AAEA,MAAA;AACA,MAAA;AAI/B,MAAA;AACD,IAAA;AAGyB,IAAA;AACU,MAAA;AAEhC,MAAA;AAC+B,QAAA;AAC/B,QAAA;AACA,QAAA;AAEA,MAAA;AACM,QAAA;AACR,MAAA;AACD,IAAA;AACO,IAAA;AACR,EAAA;AAGY,EAAA;AACL,EAAA;AACR;AAgBC;AAMI,EAAA;AACA,EAAA;AACA,EA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;AE/MzC;AACU,EAAA;AACG,EAAA;AACI,EAAA;AACJ,EAAA;AACC,EAAA;AACV,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AACS,EAAA;AACP,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AACQ,EAAA;AACG,EAAA;AACJ,IAAA;AACO,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACY,IAAA;AACA,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACS,IAAA;AACG,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACY,IAAA;AACA,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACW,IAAA;AACC,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACoB,IAAA;AACR,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AAC8B,IAAA;AAClB,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACuB,IAAA;AACX,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AAC2B,IAAA;AACf,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAA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AC/B,QAAA;AACD,MAAA;AACD,IAAA;AACD,EAAA;AAEsC,EAAA;AACC,EAAA;AACxC;AHwTyC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-63AELL54.cjs","sourcesContent":[null,"import type { Next } from \"hono\";\nimport type { ContentfulStatusCode } from \"hono/utils/http-status\";\nimport * as errors from \"@/actor/errors\";\nimport { getEnvUniversal } from \"@/utils\";\nimport type { Logger } from \"./log\";\n\nexport function assertUnreachable(x: never): never {\n\tthrow new Error(`Unreachable case: ${x}`);\n}\n\n/**\n * Safely stringifies an object, ensuring that the stringified object is under a certain size.\n * @param obj any object to stringify\n * @param maxSize maximum size of the stringified object in bytes\n * @returns stringified object\n */\nexport function safeStringify(obj: unknown, maxSize: number) {\n\tlet size = 0;\n\n\tfunction replacer(key: string, value: unknown) {\n\t\tif (value === null || value === undefined) return value;\n\t\tconst valueSize =\n\t\t\ttypeof value === \"string\" ? value.length : JSON.stringify(value).length;\n\t\tsize += key.length + valueSize;\n\n\t\tif (size > maxSize) {\n\t\t\tthrow new Error(`JSON object exceeds size limit of ${maxSize} bytes.`);\n\t\t}\n\n\t\treturn value;\n\t}\n\n\treturn JSON.stringify(obj, replacer);\n}\n\n// TODO: Instead of doing this, use a temp var for state and attempt to write\n// it. Roll back state if fails to serialize.\n\n/**\n * Check if a value is CBOR serializable.\n * Optionally pass an onInvalid callback to receive the path to invalid values.\n *\n * For a complete list of supported CBOR tags, see:\n * https://github.com/kriszyp/cbor-x/blob/cc1cf9df8ba72288c7842af1dd374d73e34cdbc1/README.md#list-of-supported-tags-for-decoding\n */\nexport function isCborSerializable(\n\tvalue: unknown,\n\tonInvalid?: (path: string) => void,\n\tcurrentPath = \"\",\n): boolean {\n\t// Handle primitive types directly\n\tif (value === null || value === undefined) {\n\t\treturn true;\n\t}\n\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) {\n\t\t\tonInvalid?.(currentPath);\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tif (typeof value === \"boolean\" || typeof value === \"string\") {\n\t\treturn true;\n\t}\n\n\t// Handle BigInt (CBOR tags 2 and 3)\n\tif (typeof value === \"bigint\") {\n\t\treturn true;\n\t}\n\n\t// Handle Date objects (CBOR tags 0 and 1)\n\tif (value instanceof Date) {\n\t\treturn true;\n\t}\n\n\t// Handle typed arrays (CBOR tags 64-82)\n\tif (\n\t\tvalue instanceof Uint8Array ||\n\t\tvalue instanceof Uint8ClampedArray ||\n\t\tvalue instanceof Uint16Array ||\n\t\tvalue instanceof Uint32Array ||\n\t\tvalue instanceof BigUint64Array ||\n\t\tvalue instanceof Int8Array ||\n\t\tvalue instanceof Int16Array ||\n\t\tvalue instanceof Int32Array ||\n\t\tvalue instanceof BigInt64Array ||\n\t\tvalue instanceof Float32Array ||\n\t\tvalue instanceof Float64Array\n\t) {\n\t\treturn true;\n\t}\n\n\t// Handle Map (CBOR tag 259)\n\tif (value instanceof Map) {\n\t\tfor (const [key, val] of value.entries()) {\n\t\t\tconst keyPath = currentPath\n\t\t\t\t? `${currentPath}.key(${String(key)})`\n\t\t\t\t: `key(${String(key)})`;\n\t\t\tconst valPath = currentPath\n\t\t\t\t? `${currentPath}.value(${String(key)})`\n\t\t\t\t: `value(${String(key)})`;\n\t\t\tif (\n\t\t\t\t!isCborSerializable(key, onInvalid, keyPath) ||\n\t\t\t\t!isCborSerializable(val, onInvalid, valPath)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle Set (CBOR tag 258)\n\tif (value instanceof Set) {\n\t\tlet index = 0;\n\t\tfor (const item of value.values()) {\n\t\t\tconst itemPath = currentPath\n\t\t\t\t? `${currentPath}.set[${index}]`\n\t\t\t\t: `set[${index}]`;\n\t\t\tif (!isCborSerializable(item, onInvalid, itemPath)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle RegExp (CBOR tag 27)\n\tif (value instanceof RegExp) {\n\t\treturn true;\n\t}\n\n\t// Handle Error objects (CBOR tag 27)\n\tif (value instanceof Error) {\n\t\treturn true;\n\t}\n\n\t// Handle arrays\n\tif (Array.isArray(value)) {\n\t\tfor (let i = 0; i < value.length; i++) {\n\t\t\tconst itemPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;\n\t\t\tif (!isCborSerializable(value[i], onInvalid, itemPath)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle plain objects and records (CBOR tags 105, 51, 57344-57599)\n\tif (typeof value === \"object\") {\n\t\t// Allow plain objects and objects with prototypes (for records and named objects)\n\t\tconst proto = Object.getPrototypeOf(value);\n\t\tif (proto !== null && proto !== Object.prototype) {\n\t\t\t// Check if it's a known serializable object type\n\t\t\tconst protoConstructor = value.constructor;\n\t\t\tif (protoConstructor && typeof protoConstructor.name === \"string\") {\n\t\t\t\t// Allow objects with named constructors (records, named objects)\n\t\t\t\t// This includes user-defined classes and built-in objects\n\t\t\t\t// that CBOR can serialize with tag 27 or record tags\n\t\t\t}\n\t\t}\n\n\t\t// Check all properties recursively\n\t\tfor (const key in value) {\n\t\t\tconst propPath = currentPath ? `${currentPath}.${key}` : key;\n\t\t\tif (\n\t\t\t\t!isCborSerializable(\n\t\t\t\t\tvalue[key as keyof typeof value],\n\t\t\t\t\tonInvalid,\n\t\t\t\t\tpropPath,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Not serializable\n\tonInvalid?.(currentPath);\n\treturn false;\n}\n\nexport interface DeconstructedError {\n\t__type: \"ActorError\";\n\tstatusCode: ContentfulStatusCode;\n\tpublic: boolean;\n\tgroup: string;\n\tcode: string;\n\tmessage: string;\n\tmetadata?: unknown;\n}\n\n/** Deconstructs error in to components that are used to build responses. */\nexport function deconstructError(\n\terror: unknown,\n\tlogger: Logger,\n\textraLog: Record<string, unknown>,\n\texposeInternalError = false,\n): DeconstructedError {\n\t// Build response error information. Only return errors if flagged as public in order to prevent leaking internal behavior.\n\t//\n\t// 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.\n\tlet statusCode: ContentfulStatusCode;\n\tlet public_: boolean;\n\tlet group: string;\n\tlet code: string;\n\tlet message: string;\n\tlet metadata: unknown;\n\tif (errors.ActorError.isActorError(error) && error.public) {\n\t\t// Check if error has statusCode (could be ActorError instance or DeconstructedError)\n\t\tstatusCode = (\n\t\t\t\"statusCode\" in error && error.statusCode ? error.statusCode : 400\n\t\t) as ContentfulStatusCode;\n\t\tpublic_ = true;\n\t\tgroup = error.group;\n\t\tcode = error.code;\n\t\tmessage = getErrorMessage(error);\n\t\tmetadata = error.metadata;\n\n\t\tlogger.info({\n\t\t\tmsg: \"public error\",\n\t\t\tgroup,\n\t\t\tcode,\n\t\t\tmessage,\n\t\t\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\tsupport: \"https://rivet.dev/discord\",\n\t\t\t...extraLog,\n\t\t});\n\t} else if (exposeInternalError) {\n\t\tif (errors.ActorError.isActorError(error)) {\n\t\t\tstatusCode = 500;\n\t\t\tpublic_ = false;\n\t\t\tgroup = error.group;\n\t\t\tcode = error.code;\n\t\t\tmessage = getErrorMessage(error);\n\t\t\tmetadata = error.metadata;\n\n\t\t\tlogger.info({\n\t\t\t\tmsg: \"internal error\",\n\t\t\t\tgroup,\n\t\t\t\tcode,\n\t\t\t\tmessage,\n\t\t\t\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\t\tsupport: \"https://rivet.dev/discord\",\n\t\t\t\t...extraLog,\n\t\t\t});\n\t\t} else {\n\t\t\tstatusCode = 500;\n\t\t\tpublic_ = false;\n\t\t\tgroup = \"internal\";\n\t\t\tcode = errors.INTERNAL_ERROR_CODE;\n\t\t\tmessage = getErrorMessage(error);\n\n\t\t\tlogger.info({\n\t\t\t\tmsg: \"internal error\",\n\t\t\t\tgroup,\n\t\t\t\tcode,\n\t\t\t\tmessage,\n\t\t\t\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\t\tsupport: \"https://rivet.dev/discord\",\n\t\t\t\t...extraLog,\n\t\t\t});\n\t\t}\n\t} else {\n\t\tstatusCode = 500;\n\t\tpublic_ = false;\n\t\tgroup = \"internal\";\n\t\tcode = errors.INTERNAL_ERROR_CODE;\n\t\tmessage = errors.INTERNAL_ERROR_DESCRIPTION;\n\t\tmetadata = {\n\t\t\t//url: `https://hub.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,\n\t\t} satisfies errors.InternalErrorMetadata;\n\n\t\tlogger.warn({\n\t\t\tmsg: \"internal error\",\n\t\t\terror: getErrorMessage(error),\n\t\t\tstack: (error as Error)?.stack,\n\t\t\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\tsupport: \"https://rivet.dev/discord\",\n\t\t\t...extraLog,\n\t\t});\n\t}\n\n\treturn {\n\t\t__type: \"ActorError\",\n\t\tstatusCode,\n\t\tpublic: public_,\n\t\tgroup,\n\t\tcode,\n\t\tmessage,\n\t\tmetadata,\n\t};\n}\n\nexport function stringifyError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tif (\n\t\t\ttypeof process !== \"undefined\" &&\n\t\t\tgetEnvUniversal(\"_RIVETKIT_ERROR_STACK\") === \"1\"\n\t\t) {\n\t\t\treturn `${error.name}: ${error.message}${error.stack ? `\\n${error.stack}` : \"\"}`;\n\t\t} else {\n\t\t\treturn `${error.name}: ${error.message}`;\n\t\t}\n\t} else if (typeof error === \"string\") {\n\t\treturn error;\n\t} else if (typeof error === \"object\" && error !== null) {\n\t\ttry {\n\t\t\treturn `${JSON.stringify(error)}`;\n\t\t} catch {\n\t\t\treturn \"[cannot stringify error]\";\n\t\t}\n\t} else {\n\t\treturn `Unknown error: ${getErrorMessage(error)}`;\n\t}\n}\n\nfunction getErrorMessage(err: unknown): string {\n\tif (\n\t\terr &&\n\t\ttypeof err === \"object\" &&\n\t\t\"message\" in err &&\n\t\ttypeof err.message === \"string\"\n\t) {\n\t\treturn err.message;\n\t} else {\n\t\treturn String(err);\n\t}\n}\n\n/** Generates a `Next` handler to pass to middleware in order to be able to call arbitrary middleware. */\nexport function noopNext(): Next {\n\treturn async () => {};\n}\n","{\n \"name\": \"rivetkit\",\n \"version\": \"2.0.12\",\n \"description\": \"Lightweight libraries for building stateful actors on edge platforms\",\n \"license\": \"Apache-2.0\",\n \"keywords\": [\n \"rivetkit\",\n \"stateful\",\n \"serverless\",\n \"actors\",\n \"agents\",\n \"realtime\",\n \"websocket\",\n \"actors\",\n \"framework\"\n ],\n \"files\": [\n \"dist\",\n \"src\",\n \"deno.json\",\n \"bun.json\",\n \"package.json\"\n ],\n \"type\": \"module\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/tsup/mod.d.ts\",\n \"default\": \"./dist/tsup/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/mod.d.cts\",\n \"default\": \"./dist/tsup/mod.cjs\"\n }\n },\n \"./client\": {\n \"import\": {\n \"types\": \"./dist/tsup/client/mod.d.ts\",\n \"default\": \"./dist/tsup/client/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/client/mod.d.cts\",\n \"default\": \"./dist/tsup/client/mod.cjs\"\n }\n },\n \"./log\": {\n \"import\": {\n \"types\": \"./dist/tsup/common/log.d.ts\",\n \"default\": \"./dist/tsup/common/log.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/common/log.d.cts\",\n \"default\": \"./dist/tsup/common/log.cjs\"\n }\n },\n \"./errors\": {\n \"import\": {\n \"types\": \"./dist/tsup/actor/errors.d.ts\",\n \"default\": \"./dist/tsup/actor/errors.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/actor/errors.d.cts\",\n \"default\": \"./dist/tsup/actor/errors.cjs\"\n }\n },\n \"./utils\": {\n \"import\": {\n \"types\": \"./dist/tsup/utils.d.ts\",\n \"default\": \"./dist/tsup/utils.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/utils.d.cts\",\n \"default\": \"./dist/tsup/utils.cjs\"\n }\n },\n \"./driver-helpers\": {\n \"import\": {\n \"types\": \"./dist/tsup/driver-helpers/mod.d.ts\",\n \"default\": \"./dist/tsup/driver-helpers/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/driver-helpers/mod.d.cts\",\n \"default\": \"./dist/tsup/driver-helpers/mod.cjs\"\n }\n },\n \"./driver-helpers/websocket\": {\n \"import\": {\n \"types\": \"./dist/tsup/common/websocket.d.ts\",\n \"default\": \"./dist/tsup/common/websocket.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/common/websocket.d.cts\",\n \"default\": \"./dist/tsup/common/websocket.cjs\"\n }\n },\n \"./driver-test-suite\": {\n \"import\": {\n \"types\": \"./dist/tsup/driver-test-suite/mod.d.ts\",\n \"default\": \"./dist/tsup/driver-test-suite/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/driver-test-suite/mod.d.cts\",\n \"default\": \"./dist/tsup/driver-test-suite/mod.cjs\"\n }\n },\n \"./topologies/coordinate\": {\n \"import\": {\n \"types\": \"./dist/tsup/topologies/coordinate/mod.d.ts\",\n \"default\": \"./dist/tsup/topologies/coordinate/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/topologies/coordinate/mod.d.cts\",\n \"default\": \"./dist/tsup/topologies/coordinate/mod.cjs\"\n }\n },\n \"./topologies/partition\": {\n \"import\": {\n \"types\": \"./dist/tsup/topologies/partition/mod.d.ts\",\n \"default\": \"./dist/tsup/topologies/partition/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/topologies/partition/mod.d.cts\",\n \"default\": \"./dist/tsup/topologies/partition/mod.cjs\"\n }\n },\n \"./test\": {\n \"import\": {\n \"types\": \"./dist/tsup/test/mod.d.ts\",\n \"default\": \"./dist/tsup/test/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/test/mod.d.cts\",\n \"default\": \"./dist/tsup/test/mod.cjs\"\n }\n },\n \"./inspector\": {\n \"import\": {\n \"types\": \"./dist/tsup/inspector/mod.d.ts\",\n \"default\": \"./dist/tsup/inspector/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/inspector/mod.d.cts\",\n \"default\": \"./dist/tsup/inspector/mod.cjs\"\n }\n }\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"sideEffects\": [\n \"./dist/tsup/chunk-*.js\",\n \"./dist/tsup/chunk-*.cjs\"\n ],\n \"scripts\": {\n \"build\": \"tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/topologies/coordinate/mod.ts src/topologies/partition/mod.ts src/utils.ts src/driver-helpers/mod.ts src/driver-test-suite/mod.ts src/test/mod.ts src/inspector/mod.ts\",\n \"build:schema\": \"./scripts/compile-bare.ts compile schemas/client-protocol/v1.bare -o dist/schemas/client-protocol/v1.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v1.bare -o dist/schemas/file-system-driver/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v1.bare -o dist/schemas/actor-persist/v1.ts\",\n \"check-types\": \"tsc --noEmit\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"dump-openapi\": \"tsx scripts/dump-openapi.ts\"\n },\n \"dependencies\": {\n \"@bare-ts/lib\": \"~0.3.0\",\n \"@hono/standard-validator\": \"^0.1.3\",\n \"@hono/zod-openapi\": \"^0.19.10\",\n \"@rivetkit/engine-runner\": \"https://pkg.pr.new/rivet-dev/engine/@rivetkit/engine-runner@bdfca35\",\n \"@rivetkit/fast-json-patch\": \"^3.1.2\",\n \"cbor-x\": \"^1.6.0\",\n \"hono\": \"^4.7.0\",\n \"invariant\": \"^2.2.4\",\n \"nanoevents\": \"^9.1.0\",\n \"on-change\": \"^5.0.1\",\n \"p-retry\": \"^6.2.1\",\n \"pino\": \"^9.5.0\",\n \"zod\": \"^3.25.76\"\n },\n \"devDependencies\": {\n \"@bare-ts/tools\": \"^0.13.0\",\n \"@hono/node-server\": \"^1.18.2\",\n \"@hono/node-ws\": \"^1.1.1\",\n \"@types/invariant\": \"^2\",\n \"@types/node\": \"^22.13.1\",\n \"@types/ws\": \"^8\",\n \"@vitest/ui\": \"3.1.1\",\n \"bundle-require\": \"^5.1.0\",\n \"eventsource\": \"^4.0.0\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.4\",\n \"typescript\": \"^5.7.3\",\n \"vitest\": \"^3.1.1\",\n \"ws\": \"^8.18.1\"\n },\n \"peerDependencies\": {\n \"@hono/node-server\": \"^1.14.0\",\n \"@hono/node-ws\": \"^1.1.1\",\n \"eventsource\": \"^4.0.0\",\n \"ws\": \"^8.0.0\"\n },\n \"peerDependenciesMeta\": {\n \"@hono/node-server\": {\n \"optional\": true\n },\n \"@hono/node-ws\": {\n \"optional\": true\n },\n \"eventsource\": {\n \"optional\": true\n },\n \"ws\": {\n \"optional\": true\n }\n },\n \"stableVersion\": \"0.8.0\"\n}\n","export { stringifyError } from \"@/common/utils\";\nexport { assertUnreachable } from \"./common/utils\";\n\nimport type { Context as HonoContext, Handler as HonoHandler } from \"hono\";\n\nimport pkgJson from \"../package.json\" with { type: \"json\" };\n\nexport const VERSION = pkgJson.version;\n\nlet _userAgent: string | undefined;\n\nexport function httpUserAgent(): string {\n\t// Return cached value if already initialized\n\tif (_userAgent !== undefined) {\n\t\treturn _userAgent;\n\t}\n\n\t// Library\n\tlet userAgent = `RivetKit/${VERSION}`;\n\n\t// Navigator\n\tconst navigatorObj = typeof navigator !== \"undefined\" ? navigator : undefined;\n\tif (navigatorObj?.userAgent) userAgent += ` ${navigatorObj.userAgent}`;\n\n\t_userAgent = userAgent;\n\n\treturn userAgent;\n}\n\nexport type UpgradeWebSocket = (\n\tcreateEvents: (c: HonoContext) => any,\n) => HonoHandler;\n\nexport type GetUpgradeWebSocket = () => UpgradeWebSocket;\n\nexport function getEnvUniversal(key: string): string | undefined {\n\tif (typeof Deno !== \"undefined\") {\n\t\treturn Deno.env.get(key);\n\t} else if (typeof process !== \"undefined\") {\n\t\t// Do this after Deno since `process` is sometimes polyfilled\n\t\treturn process.env[key];\n\t}\n}\n\nexport function dbg<T>(x: T): T {\n\tconsole.trace(`=== DEBUG ===\\n${x}`);\n\treturn x;\n}\n\n/**\n * Converts various ArrayBuffer-like types to Uint8Array.\n * Handles ArrayBuffer, ArrayBufferView (including typed arrays), and passes through existing Uint8Array.\n *\n * @param data - The ArrayBuffer or ArrayBufferView to convert\n * @returns A Uint8Array view of the data\n */\nexport function toUint8Array(data: ArrayBuffer | ArrayBufferView): Uint8Array {\n\tif (data instanceof Uint8Array) {\n\t\treturn data;\n\t} else if (data instanceof ArrayBuffer) {\n\t\treturn new Uint8Array(data);\n\t} else if (ArrayBuffer.isView(data)) {\n\t\t// Handle other ArrayBufferView types (Int8Array, Uint16Array, DataView, etc.)\n\t\treturn new Uint8Array(\n\t\t\tdata.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength),\n\t\t);\n\t} else {\n\t\tthrow new TypeError(\"Input must be ArrayBuffer or ArrayBufferView\");\n\t}\n}\n\n// Long timeouts\n//\n// JavaScript timers use a signed 32-bit integer for delays, so values above 2^31-1 (~24.8 days)\n// are not reliable and may fire immediately or overflow.\n//\n// https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#maximum_delay_value\nconst TIMEOUT_MAX = 2147483647; // 2^31-1\n\nexport type LongTimeoutHandle = { abort: () => void };\n\n/**\n * Polyfill for Promise.withResolvers().\n *\n * This is specifically for Cloudflare Workers. Their implementation of Promise.withResolvers does not work correctly.\n */\nexport function promiseWithResolvers<T>(): {\n\tpromise: Promise<T>;\n\tresolve: (value: T | PromiseLike<T>) => void;\n\treject: (reason?: any) => void;\n} {\n\tlet resolve!: (value: T | PromiseLike<T>) => void;\n\tlet reject!: (reason?: any) => void;\n\tconst promise = new Promise<T>((res, rej) => {\n\t\tresolve = res;\n\t\treject = rej;\n\t});\n\treturn { promise, resolve, reject };\n}\n\nexport function setLongTimeout(\n\tlistener: () => void,\n\tafter: number,\n): LongTimeoutHandle {\n\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\n\tfunction start(remaining: number) {\n\t\tif (remaining <= TIMEOUT_MAX) {\n\t\t\ttimeout = setTimeout(listener, remaining);\n\t\t} else {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tstart(remaining - TIMEOUT_MAX);\n\t\t\t}, TIMEOUT_MAX);\n\t\t}\n\t}\n\n\tstart(after);\n\n\treturn {\n\t\tabort: () => {\n\t\t\tif (timeout !== undefined) clearTimeout(timeout);\n\t\t},\n\t};\n}\n\n/**\n * A tiny utility that coalesces/enqueues async operations so only the latest\n * queued task runs per cycle, while callers receive a promise that resolves\n * when the task for the cycle they joined has completed.\n */\nexport class SinglePromiseQueue {\n\t/** Next operation to execute in the queue. If attempting to enqueue another op, it will override the existing op. */\n\t#queuedOp?: () => Promise<void>;\n\n\t/** The currently running promise of #drainLoop. Do not await this, instead await `pending` to await the current cycle. */\n\trunningDrainLoop?: Promise<void>;\n\n\t/** Pending resolver fro the currently queued entry. */\n\t#pending?: ReturnType<typeof promiseWithResolvers<void>>;\n\n\t/** Queue the next operation and return a promise that resolves when it flushes. */\n\tenqueue(op: () => Promise<void>): Promise<void> {\n\t\t// Replace any previously queued operation with the latest one\n\t\tthis.#queuedOp = op;\n\n\t\t// Ensure a shared resolver exists for all callers in this cycle\n\t\tif (!this.#pending) {\n\t\t\tthis.#pending = promiseWithResolvers<void>();\n\t\t}\n\n\t\tconst waitForThisCycle = this.#pending.promise;\n\n\t\t// Start runner if not already running\n\t\tif (!this.runningDrainLoop) {\n\t\t\tthis.runningDrainLoop = this.#drainLoop();\n\t\t}\n\n\t\treturn waitForThisCycle;\n\t}\n\n\t/** Drain queued operations sequentially until there is nothing left. */\n\tasync #drainLoop(): Promise<void> {\n\t\ttry {\n\t\t\twhile (this.#queuedOp) {\n\t\t\t\t// Capture current cycle resolver then reset for the next cycle\n\t\t\t\tconst resolver = this.#pending;\n\t\t\t\tthis.#pending = undefined;\n\n\t\t\t\t// Capture and clear the currently queued operation\n\t\t\t\tconst op = this.#queuedOp;\n\t\t\t\tthis.#queuedOp = undefined;\n\n\t\t\t\ttry {\n\t\t\t\t\tawait op();\n\t\t\t\t} catch {\n\t\t\t\t\t// Swallow errors: callers only await cycle completion, not success\n\t\t\t\t}\n\n\t\t\t\t// Notify all waiters for this cycle\n\t\t\t\tresolver?.resolve();\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.runningDrainLoop = undefined;\n\t\t}\n\t}\n}\n\nexport function bufferToArrayBuffer(buf: Buffer | Uint8Array): ArrayBuffer {\n\treturn buf.buffer.slice(\n\t\tbuf.byteOffset,\n\t\tbuf.byteOffset + buf.byteLength,\n\t) as ArrayBuffer;\n}\n\n/**\n * Properly combines a base URL endpoint with a path, preserving any base path in the endpoint.\n *\n * @example\n * combineUrlPath(\"http://localhost:8787/rivet\", \"/actors/action\")\n * // Returns: \"http://localhost:8787/rivet/actors/action\"\n *\n * @example\n * combineUrlPath(\"http://localhost:8787/rivet\", \"/actors?type=foo\", { namespace: \"test\" })\n * // Returns: \"http://localhost:8787/rivet/actors?type=foo&namespace=test\"\n *\n * @param endpoint The base URL endpoint that may contain a path component\n * @param path The path to append to the endpoint (may include query parameters)\n * @param queryParams Optional additional query parameters to append\n * @returns The properly combined URL string\n */\nexport function combineUrlPath(\n\tendpoint: string,\n\tpath: string,\n\tqueryParams?: Record<string, string | undefined>,\n): string {\n\tconst baseUrl = new URL(endpoint);\n\n\t// Extract path and query from the provided path\n\tconst pathParts = path.split(\"?\");\n\tconst pathOnly = pathParts[0];\n\tconst existingQuery = pathParts[1] || \"\";\n\n\t// Remove trailing slash from base path and ensure path starts with /\n\tconst basePath = baseUrl.pathname.replace(/\\/$/, \"\");\n\tconst cleanPath = pathOnly.startsWith(\"/\") ? pathOnly : `/${pathOnly}`;\n\t// Combine paths and remove any double slashes\n\tconst fullPath = (basePath + cleanPath).replace(/\\/\\//g, \"/\");\n\n\t// Build query string\n\tconst queryParts: string[] = [];\n\tif (existingQuery) {\n\t\tqueryParts.push(existingQuery);\n\t}\n\tif (queryParams) {\n\t\tfor (const [key, value] of Object.entries(queryParams)) {\n\t\t\tif (value !== undefined) {\n\t\t\t\tqueryParts.push(\n\t\t\t\t\t`${encodeURIComponent(key)}=${encodeURIComponent(value)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst fullQuery = queryParts.length > 0 ? `?${queryParts.join(\"&\")}` : \"\";\n\treturn `${baseUrl.protocol}//${baseUrl.host}${fullPath}${fullQuery}`;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-OWPBIHFM.cjs","../../src/common/utils.ts","../../package.json","../../src/utils.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACAO,SAAS,iBAAA,CAAkB,CAAA,EAAiB;AAClD,EAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kBAAA,EAAqB,CAAC,CAAA,CAAA;AACvC;AAuCC;AAIgC,EAAA;AACxB,IAAA;AACR,EAAA;AAE+B,EAAA;AACD,IAAA;AAC5B,MAAA;AACO,MAAA;AACR,IAAA;AACO,IAAA;AACR,EAAA;AAEkC,EAAA;AAC1B,IAAA;AACR,EAAA;AAG+B,EAAA;AACvB,IAAA;AACR,EAAA;AAG2B,EAAA;AACnB,IAAA;AACR,EAAA;AAKC,EAAA;AAWO,IAAA;AACR,EAAA;AAG0B,EAAA;AACM,IAAA;AAExB,MAAA;AAGA,MAAA;AAGoB,MAAA;AAGlB,QAAA;AACR,MAAA;AACD,IAAA;AACO,IAA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AAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACW,IAAA;AACC,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACoB,IAAA;AACR,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AAC8B,IAAA;AAClB,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACuB,IAAA;AACX,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AAC2B,IAAA;AACf,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AAC0B,IAAA;AACd,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACU,IAAA;AACE,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACe,IAAA;AACH,MAAA;AACC,QAAA;AACE,QAAA;AACb,MAAA;AACW,MAAA;AACA,QAAA;AACE,QAAA;AACb,MAAA;AACF,IAAA;AACF,EAAA;AACW,EAAA;AACD,IAAA;AACV,EAAA;AACe,EAAA;AACb,IAAA;AACA,IAAA;AACF,EAAA;AACW,EAAA;AACA,IAAA;AACO,IAAA;AACD,IAAA;AACP,IAAA;AACM,IAAA;AACE,IAAA;AAClB,EAAA;AACgB,EAAA;AACE,IAAA;AACY,IAAA;AACP,IAAA;AACM,IAAA;AACE,IAAA;AACnB,IAAA;AACF,IAAA;AACK,IAAA;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AA;AAAA;AAGgD,EAAA;AAE9B,IAAA;AAGG,IAAA;AACH,MAAA;AACjB,IAAA;AAE8B,IAAA;AAGF,IAAA;AACE,MAAA;AAC9B,IAAA;AAEO,IAAA;AACR,EAAA;AAAA;AAGkC,EAAA;AAC7B,IAAA;AACoB,MAAA;AAEA,QAAA;AACN,QAAA;AAGA,QAAA;AACC,QAAA;AAEb,QAAA;AACM,UAAA;AACF,QAAA;AAER,QAAA;AAGA,QAAA;AACD,MAAA;AACC,IAAA;AACuB,MAAA;AACzB,IAAA;AACD,EAAA;AACD;AAE2E;AACxD,EAAA;AACb,IAAA;AACiB,IAAA;AACtB,EAAA;AACD;AAqBC;AAEgC,EAAA;AAGA,EAAA;AACJ,EAAA;AACU,EAAA;AAGJ,EAAA;AACI,EAAA;AAET,EAAA;AAGC,EAAA;AACX,EAAA;AACW,IAAA;AAC9B,EAAA;AACiB,EAAA;AACkB,IAAA;AACR,MAAA;AACb,QAAA;AACoB,UAAA;AAC/B,QAAA;AACD,MAAA;AACD,IAAA;AACD,EAAA;AAEsC,EAAA;AACC,EAAA;AACxC;AHwTyC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-OWPBIHFM.cjs","sourcesContent":[null,"import type { Next } from \"hono\";\nimport type { ContentfulStatusCode } from \"hono/utils/http-status\";\nimport * as errors from \"@/actor/errors\";\nimport { getEnvUniversal } from \"@/utils\";\nimport type { Logger } from \"./log\";\n\nexport function assertUnreachable(x: never): never {\n\tthrow new Error(`Unreachable case: ${x}`);\n}\n\n/**\n * Safely stringifies an object, ensuring that the stringified object is under a certain size.\n * @param obj any object to stringify\n * @param maxSize maximum size of the stringified object in bytes\n * @returns stringified object\n */\nexport function safeStringify(obj: unknown, maxSize: number) {\n\tlet size = 0;\n\n\tfunction replacer(key: string, value: unknown) {\n\t\tif (value === null || value === undefined) return value;\n\t\tconst valueSize =\n\t\t\ttypeof value === \"string\" ? value.length : JSON.stringify(value).length;\n\t\tsize += key.length + valueSize;\n\n\t\tif (size > maxSize) {\n\t\t\tthrow new Error(`JSON object exceeds size limit of ${maxSize} bytes.`);\n\t\t}\n\n\t\treturn value;\n\t}\n\n\treturn JSON.stringify(obj, replacer);\n}\n\n// TODO: Instead of doing this, use a temp var for state and attempt to write\n// it. Roll back state if fails to serialize.\n\n/**\n * Check if a value is CBOR serializable.\n * Optionally pass an onInvalid callback to receive the path to invalid values.\n *\n * For a complete list of supported CBOR tags, see:\n * https://github.com/kriszyp/cbor-x/blob/cc1cf9df8ba72288c7842af1dd374d73e34cdbc1/README.md#list-of-supported-tags-for-decoding\n */\nexport function isCborSerializable(\n\tvalue: unknown,\n\tonInvalid?: (path: string) => void,\n\tcurrentPath = \"\",\n): boolean {\n\t// Handle primitive types directly\n\tif (value === null || value === undefined) {\n\t\treturn true;\n\t}\n\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) {\n\t\t\tonInvalid?.(currentPath);\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tif (typeof value === \"boolean\" || typeof value === \"string\") {\n\t\treturn true;\n\t}\n\n\t// Handle BigInt (CBOR tags 2 and 3)\n\tif (typeof value === \"bigint\") {\n\t\treturn true;\n\t}\n\n\t// Handle Date objects (CBOR tags 0 and 1)\n\tif (value instanceof Date) {\n\t\treturn true;\n\t}\n\n\t// Handle typed arrays (CBOR tags 64-82)\n\tif (\n\t\tvalue instanceof Uint8Array ||\n\t\tvalue instanceof Uint8ClampedArray ||\n\t\tvalue instanceof Uint16Array ||\n\t\tvalue instanceof Uint32Array ||\n\t\tvalue instanceof BigUint64Array ||\n\t\tvalue instanceof Int8Array ||\n\t\tvalue instanceof Int16Array ||\n\t\tvalue instanceof Int32Array ||\n\t\tvalue instanceof BigInt64Array ||\n\t\tvalue instanceof Float32Array ||\n\t\tvalue instanceof Float64Array\n\t) {\n\t\treturn true;\n\t}\n\n\t// Handle Map (CBOR tag 259)\n\tif (value instanceof Map) {\n\t\tfor (const [key, val] of value.entries()) {\n\t\t\tconst keyPath = currentPath\n\t\t\t\t? `${currentPath}.key(${String(key)})`\n\t\t\t\t: `key(${String(key)})`;\n\t\t\tconst valPath = currentPath\n\t\t\t\t? `${currentPath}.value(${String(key)})`\n\t\t\t\t: `value(${String(key)})`;\n\t\t\tif (\n\t\t\t\t!isCborSerializable(key, onInvalid, keyPath) ||\n\t\t\t\t!isCborSerializable(val, onInvalid, valPath)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle Set (CBOR tag 258)\n\tif (value instanceof Set) {\n\t\tlet index = 0;\n\t\tfor (const item of value.values()) {\n\t\t\tconst itemPath = currentPath\n\t\t\t\t? `${currentPath}.set[${index}]`\n\t\t\t\t: `set[${index}]`;\n\t\t\tif (!isCborSerializable(item, onInvalid, itemPath)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tindex++;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle RegExp (CBOR tag 27)\n\tif (value instanceof RegExp) {\n\t\treturn true;\n\t}\n\n\t// Handle Error objects (CBOR tag 27)\n\tif (value instanceof Error) {\n\t\treturn true;\n\t}\n\n\t// Handle arrays\n\tif (Array.isArray(value)) {\n\t\tfor (let i = 0; i < value.length; i++) {\n\t\t\tconst itemPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;\n\t\t\tif (!isCborSerializable(value[i], onInvalid, itemPath)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Handle plain objects and records (CBOR tags 105, 51, 57344-57599)\n\tif (typeof value === \"object\") {\n\t\t// Allow plain objects and objects with prototypes (for records and named objects)\n\t\tconst proto = Object.getPrototypeOf(value);\n\t\tif (proto !== null && proto !== Object.prototype) {\n\t\t\t// Check if it's a known serializable object type\n\t\t\tconst protoConstructor = value.constructor;\n\t\t\tif (protoConstructor && typeof protoConstructor.name === \"string\") {\n\t\t\t\t// Allow objects with named constructors (records, named objects)\n\t\t\t\t// This includes user-defined classes and built-in objects\n\t\t\t\t// that CBOR can serialize with tag 27 or record tags\n\t\t\t}\n\t\t}\n\n\t\t// Check all properties recursively\n\t\tfor (const key in value) {\n\t\t\tconst propPath = currentPath ? `${currentPath}.${key}` : key;\n\t\t\tif (\n\t\t\t\t!isCborSerializable(\n\t\t\t\t\tvalue[key as keyof typeof value],\n\t\t\t\t\tonInvalid,\n\t\t\t\t\tpropPath,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Not serializable\n\tonInvalid?.(currentPath);\n\treturn false;\n}\n\nexport interface DeconstructedError {\n\t__type: \"ActorError\";\n\tstatusCode: ContentfulStatusCode;\n\tpublic: boolean;\n\tgroup: string;\n\tcode: string;\n\tmessage: string;\n\tmetadata?: unknown;\n}\n\n/** Deconstructs error in to components that are used to build responses. */\nexport function deconstructError(\n\terror: unknown,\n\tlogger: Logger,\n\textraLog: Record<string, unknown>,\n\texposeInternalError = false,\n): DeconstructedError {\n\t// Build response error information. Only return errors if flagged as public in order to prevent leaking internal behavior.\n\t//\n\t// 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.\n\tlet statusCode: ContentfulStatusCode;\n\tlet public_: boolean;\n\tlet group: string;\n\tlet code: string;\n\tlet message: string;\n\tlet metadata: unknown;\n\tif (errors.ActorError.isActorError(error) && error.public) {\n\t\t// Check if error has statusCode (could be ActorError instance or DeconstructedError)\n\t\tstatusCode = (\n\t\t\t\"statusCode\" in error && error.statusCode ? error.statusCode : 400\n\t\t) as ContentfulStatusCode;\n\t\tpublic_ = true;\n\t\tgroup = error.group;\n\t\tcode = error.code;\n\t\tmessage = getErrorMessage(error);\n\t\tmetadata = error.metadata;\n\n\t\tlogger.info({\n\t\t\tmsg: \"public error\",\n\t\t\tgroup,\n\t\t\tcode,\n\t\t\tmessage,\n\t\t\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\tsupport: \"https://rivet.dev/discord\",\n\t\t\t...extraLog,\n\t\t});\n\t} else if (exposeInternalError) {\n\t\tif (errors.ActorError.isActorError(error)) {\n\t\t\tstatusCode = 500;\n\t\t\tpublic_ = false;\n\t\t\tgroup = error.group;\n\t\t\tcode = error.code;\n\t\t\tmessage = getErrorMessage(error);\n\t\t\tmetadata = error.metadata;\n\n\t\t\tlogger.info({\n\t\t\t\tmsg: \"internal error\",\n\t\t\t\tgroup,\n\t\t\t\tcode,\n\t\t\t\tmessage,\n\t\t\t\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\t\tsupport: \"https://rivet.dev/discord\",\n\t\t\t\t...extraLog,\n\t\t\t});\n\t\t} else {\n\t\t\tstatusCode = 500;\n\t\t\tpublic_ = false;\n\t\t\tgroup = \"internal\";\n\t\t\tcode = errors.INTERNAL_ERROR_CODE;\n\t\t\tmessage = getErrorMessage(error);\n\n\t\t\tlogger.info({\n\t\t\t\tmsg: \"internal error\",\n\t\t\t\tgroup,\n\t\t\t\tcode,\n\t\t\t\tmessage,\n\t\t\t\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\t\tsupport: \"https://rivet.dev/discord\",\n\t\t\t\t...extraLog,\n\t\t\t});\n\t\t}\n\t} else {\n\t\tstatusCode = 500;\n\t\tpublic_ = false;\n\t\tgroup = \"internal\";\n\t\tcode = errors.INTERNAL_ERROR_CODE;\n\t\tmessage = errors.INTERNAL_ERROR_DESCRIPTION;\n\t\tmetadata = {\n\t\t\t//url: `https://hub.rivet.dev/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,\n\t\t} satisfies errors.InternalErrorMetadata;\n\n\t\tlogger.warn({\n\t\t\tmsg: \"internal error\",\n\t\t\terror: getErrorMessage(error),\n\t\t\tstack: (error as Error)?.stack,\n\t\t\tissues: \"https://github.com/rivet-dev/rivetkit/issues\",\n\t\t\tsupport: \"https://rivet.dev/discord\",\n\t\t\t...extraLog,\n\t\t});\n\t}\n\n\treturn {\n\t\t__type: \"ActorError\",\n\t\tstatusCode,\n\t\tpublic: public_,\n\t\tgroup,\n\t\tcode,\n\t\tmessage,\n\t\tmetadata,\n\t};\n}\n\nexport function stringifyError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tif (\n\t\t\ttypeof process !== \"undefined\" &&\n\t\t\tgetEnvUniversal(\"_RIVETKIT_ERROR_STACK\") === \"1\"\n\t\t) {\n\t\t\treturn `${error.name}: ${error.message}${error.stack ? `\\n${error.stack}` : \"\"}`;\n\t\t} else {\n\t\t\treturn `${error.name}: ${error.message}`;\n\t\t}\n\t} else if (typeof error === \"string\") {\n\t\treturn error;\n\t} else if (typeof error === \"object\" && error !== null) {\n\t\ttry {\n\t\t\treturn `${JSON.stringify(error)}`;\n\t\t} catch {\n\t\t\treturn \"[cannot stringify error]\";\n\t\t}\n\t} else {\n\t\treturn `Unknown error: ${getErrorMessage(error)}`;\n\t}\n}\n\nfunction getErrorMessage(err: unknown): string {\n\tif (\n\t\terr &&\n\t\ttypeof err === \"object\" &&\n\t\t\"message\" in err &&\n\t\ttypeof err.message === \"string\"\n\t) {\n\t\treturn err.message;\n\t} else {\n\t\treturn String(err);\n\t}\n}\n\n/** Generates a `Next` handler to pass to middleware in order to be able to call arbitrary middleware. */\nexport function noopNext(): Next {\n\treturn async () => {};\n}\n","{\n \"name\": \"rivetkit\",\n \"version\": \"2.0.14\",\n \"description\": \"Lightweight libraries for building stateful actors on edge platforms\",\n \"license\": \"Apache-2.0\",\n \"keywords\": [\n \"rivetkit\",\n \"stateful\",\n \"serverless\",\n \"actors\",\n \"agents\",\n \"realtime\",\n \"websocket\",\n \"actors\",\n \"framework\"\n ],\n \"files\": [\n \"dist\",\n \"src\",\n \"deno.json\",\n \"bun.json\",\n \"package.json\"\n ],\n \"type\": \"module\",\n \"exports\": {\n \".\": {\n \"import\": {\n \"types\": \"./dist/tsup/mod.d.ts\",\n \"default\": \"./dist/tsup/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/mod.d.cts\",\n \"default\": \"./dist/tsup/mod.cjs\"\n }\n },\n \"./client\": {\n \"import\": {\n \"types\": \"./dist/tsup/client/mod.d.ts\",\n \"default\": \"./dist/tsup/client/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/client/mod.d.cts\",\n \"default\": \"./dist/tsup/client/mod.cjs\"\n }\n },\n \"./log\": {\n \"import\": {\n \"types\": \"./dist/tsup/common/log.d.ts\",\n \"default\": \"./dist/tsup/common/log.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/common/log.d.cts\",\n \"default\": \"./dist/tsup/common/log.cjs\"\n }\n },\n \"./errors\": {\n \"import\": {\n \"types\": \"./dist/tsup/actor/errors.d.ts\",\n \"default\": \"./dist/tsup/actor/errors.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/actor/errors.d.cts\",\n \"default\": \"./dist/tsup/actor/errors.cjs\"\n }\n },\n \"./utils\": {\n \"import\": {\n \"types\": \"./dist/tsup/utils.d.ts\",\n \"default\": \"./dist/tsup/utils.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/utils.d.cts\",\n \"default\": \"./dist/tsup/utils.cjs\"\n }\n },\n \"./driver-helpers\": {\n \"import\": {\n \"types\": \"./dist/tsup/driver-helpers/mod.d.ts\",\n \"default\": \"./dist/tsup/driver-helpers/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/driver-helpers/mod.d.cts\",\n \"default\": \"./dist/tsup/driver-helpers/mod.cjs\"\n }\n },\n \"./driver-helpers/websocket\": {\n \"import\": {\n \"types\": \"./dist/tsup/common/websocket.d.ts\",\n \"default\": \"./dist/tsup/common/websocket.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/common/websocket.d.cts\",\n \"default\": \"./dist/tsup/common/websocket.cjs\"\n }\n },\n \"./driver-test-suite\": {\n \"import\": {\n \"types\": \"./dist/tsup/driver-test-suite/mod.d.ts\",\n \"default\": \"./dist/tsup/driver-test-suite/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/driver-test-suite/mod.d.cts\",\n \"default\": \"./dist/tsup/driver-test-suite/mod.cjs\"\n }\n },\n \"./topologies/coordinate\": {\n \"import\": {\n \"types\": \"./dist/tsup/topologies/coordinate/mod.d.ts\",\n \"default\": \"./dist/tsup/topologies/coordinate/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/topologies/coordinate/mod.d.cts\",\n \"default\": \"./dist/tsup/topologies/coordinate/mod.cjs\"\n }\n },\n \"./topologies/partition\": {\n \"import\": {\n \"types\": \"./dist/tsup/topologies/partition/mod.d.ts\",\n \"default\": \"./dist/tsup/topologies/partition/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/topologies/partition/mod.d.cts\",\n \"default\": \"./dist/tsup/topologies/partition/mod.cjs\"\n }\n },\n \"./test\": {\n \"import\": {\n \"types\": \"./dist/tsup/test/mod.d.ts\",\n \"default\": \"./dist/tsup/test/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/test/mod.d.cts\",\n \"default\": \"./dist/tsup/test/mod.cjs\"\n }\n },\n \"./inspector\": {\n \"import\": {\n \"types\": \"./dist/tsup/inspector/mod.d.ts\",\n \"default\": \"./dist/tsup/inspector/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/tsup/inspector/mod.d.cts\",\n \"default\": \"./dist/tsup/inspector/mod.cjs\"\n }\n }\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"sideEffects\": [\n \"./dist/tsup/chunk-*.js\",\n \"./dist/tsup/chunk-*.cjs\"\n ],\n \"scripts\": {\n \"build\": \"tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/topologies/coordinate/mod.ts src/topologies/partition/mod.ts src/utils.ts src/driver-helpers/mod.ts src/driver-test-suite/mod.ts src/test/mod.ts src/inspector/mod.ts\",\n \"build:schema\": \"./scripts/compile-bare.ts compile schemas/client-protocol/v1.bare -o dist/schemas/client-protocol/v1.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v1.bare -o dist/schemas/file-system-driver/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v1.bare -o dist/schemas/actor-persist/v1.ts\",\n \"check-types\": \"tsc --noEmit\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"dump-openapi\": \"tsx scripts/dump-openapi.ts\"\n },\n \"dependencies\": {\n \"@bare-ts/lib\": \"~0.3.0\",\n \"@hono/standard-validator\": \"^0.1.3\",\n \"@hono/zod-openapi\": \"^0.19.10\",\n \"@rivetkit/engine-runner\": \"https://pkg.pr.new/rivet-dev/engine/@rivetkit/engine-runner@bdfca35\",\n \"@rivetkit/fast-json-patch\": \"^3.1.2\",\n \"cbor-x\": \"^1.6.0\",\n \"hono\": \"^4.7.0\",\n \"invariant\": \"^2.2.4\",\n \"nanoevents\": \"^9.1.0\",\n \"on-change\": \"^5.0.1\",\n \"p-retry\": \"^6.2.1\",\n \"pino\": \"^9.5.0\",\n \"zod\": \"^3.25.76\"\n },\n \"devDependencies\": {\n \"@bare-ts/tools\": \"^0.13.0\",\n \"@hono/node-server\": \"^1.18.2\",\n \"@hono/node-ws\": \"^1.1.1\",\n \"@types/invariant\": \"^2\",\n \"@types/node\": \"^22.13.1\",\n \"@types/ws\": \"^8\",\n \"@vitest/ui\": \"3.1.1\",\n \"bundle-require\": \"^5.1.0\",\n \"eventsource\": \"^4.0.0\",\n \"tsup\": \"^8.4.0\",\n \"tsx\": \"^4.19.4\",\n \"typescript\": \"^5.7.3\",\n \"vitest\": \"^3.1.1\",\n \"ws\": \"^8.18.1\"\n },\n \"peerDependencies\": {\n \"@hono/node-server\": \"^1.14.0\",\n \"@hono/node-ws\": \"^1.1.1\",\n \"eventsource\": \"^4.0.0\",\n \"ws\": \"^8.0.0\"\n },\n \"peerDependenciesMeta\": {\n \"@hono/node-server\": {\n \"optional\": true\n },\n \"@hono/node-ws\": {\n \"optional\": true\n },\n \"eventsource\": {\n \"optional\": true\n },\n \"ws\": {\n \"optional\": true\n }\n },\n \"stableVersion\": \"0.8.0\"\n}\n","export { stringifyError } from \"@/common/utils\";\nexport { assertUnreachable } from \"./common/utils\";\n\nimport type { Context as HonoContext, Handler as HonoHandler } from \"hono\";\n\nimport pkgJson from \"../package.json\" with { type: \"json\" };\n\nexport const VERSION = pkgJson.version;\n\nlet _userAgent: string | undefined;\n\nexport function httpUserAgent(): string {\n\t// Return cached value if already initialized\n\tif (_userAgent !== undefined) {\n\t\treturn _userAgent;\n\t}\n\n\t// Library\n\tlet userAgent = `RivetKit/${VERSION}`;\n\n\t// Navigator\n\tconst navigatorObj = typeof navigator !== \"undefined\" ? navigator : undefined;\n\tif (navigatorObj?.userAgent) userAgent += ` ${navigatorObj.userAgent}`;\n\n\t_userAgent = userAgent;\n\n\treturn userAgent;\n}\n\nexport type UpgradeWebSocket = (\n\tcreateEvents: (c: HonoContext) => any,\n) => HonoHandler;\n\nexport type GetUpgradeWebSocket = () => UpgradeWebSocket;\n\nexport function getEnvUniversal(key: string): string | undefined {\n\tif (typeof Deno !== \"undefined\") {\n\t\treturn Deno.env.get(key);\n\t} else if (typeof process !== \"undefined\") {\n\t\t// Do this after Deno since `process` is sometimes polyfilled\n\t\treturn process.env[key];\n\t}\n}\n\nexport function dbg<T>(x: T): T {\n\tconsole.trace(`=== DEBUG ===\\n${x}`);\n\treturn x;\n}\n\n/**\n * Converts various ArrayBuffer-like types to Uint8Array.\n * Handles ArrayBuffer, ArrayBufferView (including typed arrays), and passes through existing Uint8Array.\n *\n * @param data - The ArrayBuffer or ArrayBufferView to convert\n * @returns A Uint8Array view of the data\n */\nexport function toUint8Array(data: ArrayBuffer | ArrayBufferView): Uint8Array {\n\tif (data instanceof Uint8Array) {\n\t\treturn data;\n\t} else if (data instanceof ArrayBuffer) {\n\t\treturn new Uint8Array(data);\n\t} else if (ArrayBuffer.isView(data)) {\n\t\t// Handle other ArrayBufferView types (Int8Array, Uint16Array, DataView, etc.)\n\t\treturn new Uint8Array(\n\t\t\tdata.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength),\n\t\t);\n\t} else {\n\t\tthrow new TypeError(\"Input must be ArrayBuffer or ArrayBufferView\");\n\t}\n}\n\n// Long timeouts\n//\n// JavaScript timers use a signed 32-bit integer for delays, so values above 2^31-1 (~24.8 days)\n// are not reliable and may fire immediately or overflow.\n//\n// https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#maximum_delay_value\nconst TIMEOUT_MAX = 2147483647; // 2^31-1\n\nexport type LongTimeoutHandle = { abort: () => void };\n\n/**\n * Polyfill for Promise.withResolvers().\n *\n * This is specifically for Cloudflare Workers. Their implementation of Promise.withResolvers does not work correctly.\n */\nexport function promiseWithResolvers<T>(): {\n\tpromise: Promise<T>;\n\tresolve: (value: T | PromiseLike<T>) => void;\n\treject: (reason?: any) => void;\n} {\n\tlet resolve!: (value: T | PromiseLike<T>) => void;\n\tlet reject!: (reason?: any) => void;\n\tconst promise = new Promise<T>((res, rej) => {\n\t\tresolve = res;\n\t\treject = rej;\n\t});\n\treturn { promise, resolve, reject };\n}\n\nexport function setLongTimeout(\n\tlistener: () => void,\n\tafter: number,\n): LongTimeoutHandle {\n\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\n\tfunction start(remaining: number) {\n\t\tif (remaining <= TIMEOUT_MAX) {\n\t\t\ttimeout = setTimeout(listener, remaining);\n\t\t} else {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\tstart(remaining - TIMEOUT_MAX);\n\t\t\t}, TIMEOUT_MAX);\n\t\t}\n\t}\n\n\tstart(after);\n\n\treturn {\n\t\tabort: () => {\n\t\t\tif (timeout !== undefined) clearTimeout(timeout);\n\t\t},\n\t};\n}\n\n/**\n * A tiny utility that coalesces/enqueues async operations so only the latest\n * queued task runs per cycle, while callers receive a promise that resolves\n * when the task for the cycle they joined has completed.\n */\nexport class SinglePromiseQueue {\n\t/** Next operation to execute in the queue. If attempting to enqueue another op, it will override the existing op. */\n\t#queuedOp?: () => Promise<void>;\n\n\t/** The currently running promise of #drainLoop. Do not await this, instead await `pending` to await the current cycle. */\n\trunningDrainLoop?: Promise<void>;\n\n\t/** Pending resolver fro the currently queued entry. */\n\t#pending?: ReturnType<typeof promiseWithResolvers<void>>;\n\n\t/** Queue the next operation and return a promise that resolves when it flushes. */\n\tenqueue(op: () => Promise<void>): Promise<void> {\n\t\t// Replace any previously queued operation with the latest one\n\t\tthis.#queuedOp = op;\n\n\t\t// Ensure a shared resolver exists for all callers in this cycle\n\t\tif (!this.#pending) {\n\t\t\tthis.#pending = promiseWithResolvers<void>();\n\t\t}\n\n\t\tconst waitForThisCycle = this.#pending.promise;\n\n\t\t// Start runner if not already running\n\t\tif (!this.runningDrainLoop) {\n\t\t\tthis.runningDrainLoop = this.#drainLoop();\n\t\t}\n\n\t\treturn waitForThisCycle;\n\t}\n\n\t/** Drain queued operations sequentially until there is nothing left. */\n\tasync #drainLoop(): Promise<void> {\n\t\ttry {\n\t\t\twhile (this.#queuedOp) {\n\t\t\t\t// Capture current cycle resolver then reset for the next cycle\n\t\t\t\tconst resolver = this.#pending;\n\t\t\t\tthis.#pending = undefined;\n\n\t\t\t\t// Capture and clear the currently queued operation\n\t\t\t\tconst op = this.#queuedOp;\n\t\t\t\tthis.#queuedOp = undefined;\n\n\t\t\t\ttry {\n\t\t\t\t\tawait op();\n\t\t\t\t} catch {\n\t\t\t\t\t// Swallow errors: callers only await cycle completion, not success\n\t\t\t\t}\n\n\t\t\t\t// Notify all waiters for this cycle\n\t\t\t\tresolver?.resolve();\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.runningDrainLoop = undefined;\n\t\t}\n\t}\n}\n\nexport function bufferToArrayBuffer(buf: Buffer | Uint8Array): ArrayBuffer {\n\treturn buf.buffer.slice(\n\t\tbuf.byteOffset,\n\t\tbuf.byteOffset + buf.byteLength,\n\t) as ArrayBuffer;\n}\n\n/**\n * Properly combines a base URL endpoint with a path, preserving any base path in the endpoint.\n *\n * @example\n * combineUrlPath(\"http://localhost:8787/rivet\", \"/actors/action\")\n * // Returns: \"http://localhost:8787/rivet/actors/action\"\n *\n * @example\n * combineUrlPath(\"http://localhost:8787/rivet\", \"/actors?type=foo\", { namespace: \"test\" })\n * // Returns: \"http://localhost:8787/rivet/actors?type=foo&namespace=test\"\n *\n * @param endpoint The base URL endpoint that may contain a path component\n * @param path The path to append to the endpoint (may include query parameters)\n * @param queryParams Optional additional query parameters to append\n * @returns The properly combined URL string\n */\nexport function combineUrlPath(\n\tendpoint: string,\n\tpath: string,\n\tqueryParams?: Record<string, string | undefined>,\n): string {\n\tconst baseUrl = new URL(endpoint);\n\n\t// Extract path and query from the provided path\n\tconst pathParts = path.split(\"?\");\n\tconst pathOnly = pathParts[0];\n\tconst existingQuery = pathParts[1] || \"\";\n\n\t// Remove trailing slash from base path and ensure path starts with /\n\tconst basePath = baseUrl.pathname.replace(/\\/$/, \"\");\n\tconst cleanPath = pathOnly.startsWith(\"/\") ? pathOnly : `/${pathOnly}`;\n\t// Combine paths and remove any double slashes\n\tconst fullPath = (basePath + cleanPath).replace(/\\/\\//g, \"/\");\n\n\t// Build query string\n\tconst queryParts: string[] = [];\n\tif (existingQuery) {\n\t\tqueryParts.push(existingQuery);\n\t}\n\tif (queryParams) {\n\t\tfor (const [key, value] of Object.entries(queryParams)) {\n\t\t\tif (value !== undefined) {\n\t\t\t\tqueryParts.push(\n\t\t\t\t\t`${encodeURIComponent(key)}=${encodeURIComponent(value)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst fullQuery = queryParts.length > 0 ? `?${queryParts.join(\"&\")}` : \"\";\n\treturn `${baseUrl.protocol}//${baseUrl.host}${fullPath}${fullQuery}`;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getEnvUniversal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EY5EMNAB.js";
|
|
4
4
|
|
|
5
5
|
// src/common/log.ts
|
|
6
6
|
import {
|
|
@@ -247,4 +247,4 @@ export {
|
|
|
247
247
|
getBaseLogger,
|
|
248
248
|
getLogger
|
|
249
249
|
};
|
|
250
|
-
//# sourceMappingURL=chunk-
|
|
250
|
+
//# sourceMappingURL=chunk-PO352AW7.js.map
|