@rivetkit/redis
Version:
_Lightweight Libraries for Backends_
1 lines • 46.9 kB
Source Map (JSON)
{"version":3,"sources":["/Users/nathan/rivetkit/packages/drivers/redis/dist/chunk-VQDBJLFC.cjs","../../../core/src/actor/errors.ts","../src/keys.ts","../../../core/src/common/utils.ts","../../../core/package.json","../../../core/src/utils.ts","../../../core/src/common/log-levels.ts","../../../core/src/common/logfmt.ts","../../../core/src/common/log.ts","../src/log.ts"],"names":[],"mappings":"AAAA;ACEO,IAAM,oBAAA,EAAsB,gBAAA;AAc5B,IAAM,WAAA,YAAN,MAAA,QAAyB,MAAM;ADbtC,EC6BC,WAAA,CACiB,IAAA,EAChB,OAAA,EACA,IAAA,EACC;AACD,IAAA,KAAA,CAAM,OAAA,EAAS,EAAE,KAAA,EAAO,KAAA,GAAA,KAAA,EAAA,KAAA,EAAA,EAAA,IAAA,CAAM,MAAM,CAAC,yEAAA;AAJrB,IAAA,IAAA,CAAA,KAAA,EAAA,IAAA;AAKhB,IAAA,IAAA,CAAK,OAAA,mBAAA,CAAS,KAAA,GAAA,KAAA,EAAA,KAAA,EAAA,EAAA,IAAA,CAAM,MAAA,CAAA,UAAU,OAAA;AAC9B,IAAA,IAAA,CAAK,SAAA,EAAW,KAAA,GAAA,KAAA,EAAA,KAAA,EAAA,EAAA,IAAA,CAAM,QAAA;AAGtB,IAAA,GAAA,CAAI,KAAA,GAAA,KAAA,EAAA,KAAA,EAAA,EAAA,IAAA,CAAM,MAAA,EAAQ;AACjB,MAAA,IAAA,CAAK,WAAA,EAAa,GAAA;ADjCrB,ICkCE;ADjCF,ECkCC;ADjCD,iBCKC,OAAA,EAAS,aAAA;ADJV,ECMQ;ADLR,ECMQ;ADLR,kBCMQ,WAAA,EAAa,IAAA;ADLrB,ECOC,OAAc,YAAA,CACb,KAAA,EAC2C;AAC3C,IAAA,OACC,OAAO,MAAA,IAAU,SAAA,GAChB,KAAA,CAA0C,OAAA,IAAW,YAAA;ADVzD,ECYC;ADXD,EC4BC,QAAA,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A;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;AACA,IAAA;AACY,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,QA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A;AACtB,IAAA;AAC3B,EAAA;AAEiD,EAAA;AACtB,IAAA;AAC3B,EAAA;AAEgD,EAAA;AACtB,IAAA;AAC1B,EAAA;AAEgD,EAAA;AACtB,IAAA;AAC1B,EAAA;AAEiD,EAAA;AACtB,IAAA;AAC3B,EAAA;AAEoD,EAAA;AACtB,IAAA;AAC9B,EAAA;AACD;AAEyC;AAER;AACiB,EAAA;AAChD,IAAA;AACD,EAAA;AAEkC,EAAA;AACd,EAAA;AACQ,IAAA;AAC5B,EAAA;AACmB,EAAA;AACpB;AAE2C;AAChB,EAAA;AACG,EAAA;AACH,IAAA;AACJ,IAAA;AAEI,MAAA;AAEI,QAAA;AAET,QAAA;AACnB,MAAA;AACM,IAAA;AACqB,MAAA;AAC5B,IAAA;AACD,EAAA;AAE8B,EAAA;AACZ,EAAA;AAEX,EAAA;AACc,IAAA;AACO,IAAA;AACC,IAAA;AACb,IAAA;AACZ,IAAA;AACJ,EAAA;AACD;AAE0D;AAC1B,EAAA;AAChC;ARsXiC;AACA;ASlfN;AAEF;AACI,EAAA;AAC7B;ATmfiC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/nathan/rivetkit/packages/drivers/redis/dist/chunk-VQDBJLFC.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\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\tpublic readonly code: string,\n\t\tmessage: string,\n\t\topts?: ActorErrorOptions,\n\t) {\n\t\tsuper(message, { cause: opts?.cause });\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\t/**\n\t * Serialize error for HTTP response\n\t */\n\tserializeForHttp() {\n\t\treturn {\n\t\t\ttype: this.code,\n\t\t\tmessage: this.message,\n\t\t\tmetadata: this.metadata,\n\t\t};\n\t}\n}\n\nexport class InternalError extends ActorError {\n\tconstructor(message: string) {\n\t\tsuper(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\"state_not_enabled\",\n\t\t\t\"State not enabled. Must implement `createState` or `state` to use state. (https://www.rivet.gg/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\"conn_state_not_enabled\",\n\t\t\t\"Connection state not enabled. Must implement `createConnectionState` or `connectionState` to use connection state. (https://www.rivet.gg/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\"vars_not_enabled\",\n\t\t\t\"Variables not enabled. Must implement `createVars` or `vars` to use state. (https://www.rivet.gg/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_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_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\"invalid_encoding\",\n\t\t\t`Invalid encoding \\`${format}\\`. (https://www.rivet.gg/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(\"conn_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(\"incorrect_conn_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_too_long\",\n\t\t\t\"Message too long. This can be configured with: `registry.runServer({ 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(\"malformed_message\", `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.gg/docs/actors/state/#limitations)\";\n\t\tsuper(\"invalid_state_type\", msg);\n\t}\n}\n\nexport class Unsupported extends ActorError {\n\tconstructor(feature: string) {\n\t\tsuper(\"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(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(\"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(\"invalid_request\", `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_not_found\",\n\t\t\tidentifier\n\t\t\t\t? `Actor not found: ${identifier} (https://www.rivet.gg/docs/actors/clients/#actor-client)`\n\t\t\t\t: \"Actor not found (https://www.rivet.gg/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_already_exists\",\n\t\t\t`Actor already exists with name '${name}' and key '${JSON.stringify(key)}' (https://www.rivet.gg/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_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(\"invalid_action_request\", message, { public: true });\n\t}\n}\n\nexport class InvalidParams extends ActorError {\n\tconstructor(message: string) {\n\t\tsuper(\"invalid_params\", message, { public: true });\n\t}\n}\n\nexport class Unauthorized extends ActorError {\n\tconstructor(message?: string) {\n\t\tsuper(\n\t\t\t\"unauthorized\",\n\t\t\tmessage ??\n\t\t\t\t\"Unauthorized. Access denied. (https://www.rivet.gg/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\"forbidden\",\n\t\t\tmessage ??\n\t\t\t\t\"Forbidden. Access denied. (https://www.rivet.gg/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_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\"fetch_handler_not_defined\",\n\t\t\t\"Raw HTTP handler not defined. Actor must implement `onFetch` to handle raw HTTP requests. (https://www.rivet.gg/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\"websocket_handler_not_defined\",\n\t\t\t\"Raw WebSocket handler not defined. Actor must implement `onWebSocket` to handle raw WebSocket connections. (https://www.rivet.gg/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\"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.gg/docs/actors/fetch-and-websocket-handler/)\",\n\t\t\t{ public: true },\n\t\t);\n\t\tthis.statusCode = 500;\n\t}\n}\n","export const KEYS = {\n\tACTOR: {\n\t\t// KEY\n\t\tLEASE: {\n\t\t\t// KEY (expire) = node ID\n\t\t\tnode: (prefix: string, actorId: string) =>\n\t\t\t\t`${prefix}:actor:${actorId}:lease:node`,\n\t\t},\n\t\t// KEY\n\t\tmetadata: (prefix: string, actorId: string) =>\n\t\t\t`${prefix}:actor:${actorId}:metadata`,\n\t\t// KEY\n\t\tpersistedData: (prefix: string, actorId: string) =>\n\t\t\t`${prefix}:actor:${actorId}:persisted_data`,\n\t},\n\n\t// KEY\n\tactorByKey: (prefix: string, name: string, key: string[]) => {\n\t\t// Base prefix for actor key lookups\n\t\tlet redisKey = `${prefix}:actor_by_key:${escapeRedisKey(name)}`;\n\n\t\t// Add each key component with proper escaping\n\t\tif (key.length > 0) {\n\t\t\tredisKey += `:${key.map((k) => escapeRedisKey(k)).join(\":\")}`;\n\t\t}\n\n\t\treturn redisKey;\n\t},\n};\n\nexport const PUBSUB = {\n\tnode(prefix: string, nodeId: string) {\n\t\treturn `${prefix}:node:${nodeId}:messages`;\n\t},\n};\n\n// Escape special characters in Redis keys\n// Redis keys shouldn't contain spaces or control characters\n// and we need to escape the delimiter character (:)\nfunction escapeRedisKey(part: string): string {\n\treturn part\n\t\t.replace(/\\\\/g, \"\\\\\\\\\") // Escape backslashes first\n\t\t.replace(/:/g, \"\\\\:\"); // Escape colons (our delimiter)\n}\n","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\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 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\tcode = error.code;\n\t\tmessage = getErrorMessage(error);\n\t\tmetadata = error.metadata;\n\n\t\tlogger.info(\"public error\", {\n\t\t\tcode,\n\t\t\tmessage,\n\t\t\tissues: \"https://github.com/rivet-gg/rivetkit/issues\",\n\t\t\tsupport: \"https://rivet.gg/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\tcode = error.code;\n\t\t\tmessage = getErrorMessage(error);\n\t\t\tmetadata = error.metadata;\n\n\t\t\tlogger.info(\"internal error\", {\n\t\t\t\tcode,\n\t\t\t\tmessage,\n\t\t\t\tissues: \"https://github.com/rivet-gg/rivetkit/issues\",\n\t\t\t\tsupport: \"https://rivet.gg/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\tcode = errors.INTERNAL_ERROR_CODE;\n\t\t\tmessage = getErrorMessage(error);\n\n\t\t\tlogger.info(\"internal error\", {\n\t\t\t\tcode,\n\t\t\t\tmessage,\n\t\t\t\tissues: \"https://github.com/rivet-gg/rivetkit/issues\",\n\t\t\t\tsupport: \"https://rivet.gg/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\tcode = errors.INTERNAL_ERROR_CODE;\n\t\tmessage = errors.INTERNAL_ERROR_DESCRIPTION;\n\t\tmetadata = {\n\t\t\t//url: `https://hub.rivet.gg/projects/${actorMetadata.project.slug}/environments/${actorMetadata.environment.slug}/actors?actorId=${actorMetadata.actor.id}`,\n\t\t} satisfies errors.InternalErrorMetadata;\n\n\t\tlogger.warn(\"internal error\", {\n\t\t\terror: getErrorMessage(error),\n\t\t\tstack: (error as Error)?.stack,\n\t\t\tissues: \"https://github.com/rivet-gg/rivetkit/issues\",\n\t\t\tsupport: \"https://rivet.gg/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\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/core\",\n \"version\": \"2.0.2\",\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/mod.d.ts\",\n \"default\": \"./dist/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/mod.d.cts\",\n \"default\": \"./dist/mod.cjs\"\n }\n },\n \"./client\": {\n \"import\": {\n \"types\": \"./dist/client/mod.d.ts\",\n \"default\": \"./dist/client/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/client/mod.d.cts\",\n \"default\": \"./dist/client/mod.cjs\"\n }\n },\n \"./log\": {\n \"import\": {\n \"types\": \"./dist/common/log.d.ts\",\n \"default\": \"./dist/common/log.js\"\n },\n \"require\": {\n \"types\": \"./dist/common/log.d.cts\",\n \"default\": \"./dist/common/log.cjs\"\n }\n },\n \"./errors\": {\n \"import\": {\n \"types\": \"./dist/actor/errors.d.ts\",\n \"default\": \"./dist/actor/errors.js\"\n },\n \"require\": {\n \"types\": \"./dist/actor/errors.d.cts\",\n \"default\": \"./dist/actor/errors.cjs\"\n }\n },\n \"./utils\": {\n \"import\": {\n \"types\": \"./dist/utils.d.ts\",\n \"default\": \"./dist/utils.js\"\n },\n \"require\": {\n \"types\": \"./dist/utils.d.cts\",\n \"default\": \"./dist/utils.cjs\"\n }\n },\n \"./driver-helpers\": {\n \"import\": {\n \"types\": \"./dist/driver-helpers/mod.d.ts\",\n \"default\": \"./dist/driver-helpers/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/driver-helpers/mod.d.cts\",\n \"default\": \"./dist/driver-helpers/mod.cjs\"\n }\n },\n \"./driver-helpers/websocket\": {\n \"import\": {\n \"types\": \"./dist/common/websocket.d.ts\",\n \"default\": \"./dist/common/websocket.js\"\n },\n \"require\": {\n \"types\": \"./dist/common/websocket.d.cts\",\n \"default\": \"./dist/common/websocket.cjs\"\n }\n },\n \"./driver-test-suite\": {\n \"import\": {\n \"types\": \"./dist/driver-test-suite/mod.d.ts\",\n \"default\": \"./dist/driver-test-suite/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/driver-test-suite/mod.d.cts\",\n \"default\": \"./dist/driver-test-suite/mod.cjs\"\n }\n },\n \"./topologies/coordinate\": {\n \"import\": {\n \"types\": \"./dist/topologies/coordinate/mod.d.ts\",\n \"default\": \"./dist/topologies/coordinate/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/topologies/coordinate/mod.d.cts\",\n \"default\": \"./dist/topologies/coordinate/mod.cjs\"\n }\n },\n \"./topologies/partition\": {\n \"import\": {\n \"types\": \"./dist/topologies/partition/mod.d.ts\",\n \"default\": \"./dist/topologies/partition/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/topologies/partition/mod.d.cts\",\n \"default\": \"./dist/topologies/partition/mod.cjs\"\n }\n },\n \"./test\": {\n \"import\": {\n \"types\": \"./dist/test/mod.d.ts\",\n \"default\": \"./dist/test/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/test/mod.d.cts\",\n \"default\": \"./dist/test/mod.cjs\"\n }\n },\n \"./inspector\": {\n \"import\": {\n \"types\": \"./dist/inspector/mod.d.ts\",\n \"default\": \"./dist/inspector/mod.js\"\n },\n \"require\": {\n \"types\": \"./dist/inspector/mod.d.cts\",\n \"default\": \"./dist/inspector/mod.cjs\"\n }\n }\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"sideEffects\": false,\n \"scripts\": {\n \"dev\": \"pnpm build --watch\",\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 \"check-types\": \"tsc --noEmit\",\n \"boop\": \"tsc --outDir dist/test -d\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"dump-openapi\": \"tsx scripts/dump-openapi.ts\"\n },\n \"dependencies\": {\n \"@hono/standard-validator\": \"^0.1.3\",\n \"@hono/zod-openapi\": \"^0.19.10\",\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 \"zod\": \"^3.25.76\",\n \"@rivetkit/engine-runner\": \"https://pkg.pr.new/rivet-gg/rivet/@rivetkit/engine-runner@f1c054d\"\n },\n \"devDependencies\": {\n \"@hono/node-server\": \"^1.18.2\",\n \"@hono/node-ws\": \"^1.1.1\",\n \"@rivet-gg/actor-core\": \"^25.1.0\",\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\": \"^3.0.5\",\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\": \"^3.0.5\",\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 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","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\nexport type LogEntry = [string, LogValue];\nexport type LogValue = string | number | boolean | null | undefined;\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 using orderer parameters.\n *\n * We use varargs because it's ordered & it has less overhead than 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: LogEntry[]) {\n\tlet line = \"\";\n\n\tfor (let i = 0; i < data.length; i++) {\n\t\tconst [key, valueRaw] = data[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 !== data.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): LogValue {\n\tif (\n\t\ttypeof v === \"string\" ||\n\t\ttypeof v === \"number\" ||\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(\n\tbase: string,\n\tdata: unknown,\n): LogEntry[] {\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: LogEntry[] = [];\n\t\tfor (const key in data) {\n\t\t\t// logData.push([`${base}.${key}`, JSON.stringify((data as any)[key])]);\n\n\t\t\tlogData.push(\n\t\t\t\t...spreadObjectToLogEntries(\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): LogEntry[] {\n\tif (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}\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","import { getEnvUniversal } from \"@/utils\";\nimport {\n\ttype LevelIndex,\n\tLevelNameMap,\n\ttype LogLevel,\n\tLogLevels,\n} from \"./log-levels\";\nimport {\n\tcastToLogValue,\n\tformatTimestamp,\n\ttype LogEntry,\n\tstringify,\n} from \"./logfmt\";\n\ninterface LogRecord {\n\targs: unknown[];\n\tdatetime: Date;\n\tlevel: number;\n\tlevelName: string;\n\tloggerName: string;\n\tmsg: string;\n}\n\nexport class Logger {\n\tname: string;\n\tlevel: LogLevel;\n\n\tconstructor(name: string, level: LogLevel) {\n\t\tthis.name = name;\n\t\tthis.level = level;\n\t}\n\n\tlog(level: LevelIndex, message: string, ...args: unknown[]): void {\n\t\tconst record: LogRecord = {\n\t\t\tmsg: message,\n\t\t\targs,\n\t\t\tlevel,\n\t\t\tloggerName: this.name,\n\t\t\tdatetime: new Date(),\n\t\t\tlevelName: LevelNameMap[level],\n\t\t};\n\n\t\tif (this.#shouldLog(level)) {\n\t\t\tthis.#logRecord(record);\n\t\t}\n\t}\n\n\t#shouldLog(level: LevelIndex): boolean {\n\t\treturn level >= LogLevels[this.level];\n\t}\n\n\t#logRecord(record: LogRecord): void {\n\t\tconsole.log(formatter(record));\n\t}\n\n\ttrace(message: string, ...args: unknown[]): void {\n\t\tthis.log(LogLevels.TRACE, message, ...args);\n\t}\n\n\tdebug(message: string, ...args: unknown[]): void {\n\t\tthis.log(LogLevels.DEBUG, message, ...args);\n\t}\n\n\tinfo(message: string, ...args: unknown[]): void {\n\t\tthis.log(LogLevels.INFO, message, ...args);\n\t}\n\n\twarn(message: string, ...args: unknown[]): void {\n\t\tthis.log(LogLevels.WARN, message, ...args);\n\t}\n\n\terror(message: string, ...args: unknown[]): void {\n\t\tthis.log(LogLevels.ERROR, message, ...args);\n\t}\n\n\tcritical(message: string, ...args: unknown[]): void {\n\t\tthis.log(LogLevels.CRITICAL, message, ...args);\n\t}\n}\n\nconst loggers: Record<string, Logger> = {};\n\nexport function getLogger(name = \"default\"): Logger {\n\tconst defaultLogLevelEnv: LogLevel | undefined = getEnvUniversal(\n\t\t\"_LOG_LEVEL\",\n\t) as LogLevel | undefined;\n\n\tconst defaultLogLevel: LogLevel = defaultLogLevelEnv ?? \"INFO\";\n\tif (!loggers[name]) {\n\t\tloggers[name] = new Logger(name, defaultLogLevel);\n\t}\n\treturn loggers[name];\n}\n\nfunction formatter(log: LogRecord): string {\n\tconst args: LogEntry[] = [];\n\tfor (let i = 0; i < log.args.length; i++) {\n\t\tconst logArg = log.args[i];\n\t\tif (logArg && typeof logArg === \"object\") {\n\t\t\t// Spread object\n\t\t\tfor (const k in logArg) {\n\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: Unknown type\n\t\t\t\tconst v = (logArg as any)[k];\n\n\t\t\t\tpushArg(k, v, args);\n\t\t\t}\n\t\t} else {\n\t\t\tpushArg(`arg${i}`, logArg, args);\n\t\t}\n\t}\n\n\tconst logTs = getEnvUniversal(\"_LOG_TIMESTAMP\") === \"1\";\n\tconst logTarget = getEnvUniversal(\"_LOG_TARGET\") === \"1\";\n\n\treturn stringify(\n\t\t...(logTs ? [[\"ts\", formatTimestamp(new Date())] as LogEntry] : []),\n\t\t[\"level\", LevelNameMap[log.level]],\n\t\t...(logTarget ? [[\"target\", log.loggerName] as LogEntry] : []),\n\t\t[\"msg\", log.msg],\n\t\t...args,\n\t);\n}\n\nfunction pushArg(k: string, v: unknown, args: LogEntry[]) {\n\targs.push([k, castToLogValue(v)]);\n}\n\n// function getEnv(name: string): string | undefined {\n// \tif (typeof window !== \"undefined\" && window.localStorage) {\n// \t\treturn window.localStorage.getItem(name) || undefined;\n// \t}\n// \treturn undefined;\n// \t// TODO(ACTR-9): Add back env config once node compat layer works\n// \t//return crossGetEnv(name);\n// }\n\nexport function setupLogging() {\n\t// Do nothing for now\n}\n","import { getLogger } from \"@rivetkit/core/log\";\n\nexport const LOGGER_NAME = \"driver-redis\";\n\nexport function logger() {\n\treturn getLogger(LOGGER_NAME);\n}\n"]}