rivetkit 2.0.7-rc.1 → 2.0.7

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.
Files changed (64) hide show
  1. package/dist/tsup/{chunk-JD54PXWP.js → chunk-2NL3KGJ7.js} +4 -4
  2. package/dist/tsup/{chunk-TZGUSEIJ.cjs → chunk-3ALZ7EGX.cjs} +11 -11
  3. package/dist/tsup/{chunk-TZGUSEIJ.cjs.map → chunk-3ALZ7EGX.cjs.map} +1 -1
  4. package/dist/tsup/{chunk-G4ABMAQY.cjs → chunk-4EXJ4ITR.cjs} +3 -3
  5. package/dist/tsup/{chunk-G4ABMAQY.cjs.map → chunk-4EXJ4ITR.cjs.map} +1 -1
  6. package/dist/tsup/{chunk-GZVBFXBI.js → chunk-54MAHBLL.js} +2 -2
  7. package/dist/tsup/{chunk-DFS77KAA.cjs → chunk-7OOBMCQI.cjs} +22 -22
  8. package/dist/tsup/{chunk-DFS77KAA.cjs.map → chunk-7OOBMCQI.cjs.map} +1 -1
  9. package/dist/tsup/{chunk-E4UVJKSV.js → chunk-B6N6VM37.js} +2 -2
  10. package/dist/tsup/{chunk-7N56ZUC7.js → chunk-DIHKN7NM.js} +3 -3
  11. package/dist/tsup/{chunk-3MBP4WNC.cjs → chunk-ETDWYT2P.cjs} +7 -7
  12. package/dist/tsup/{chunk-3MBP4WNC.cjs.map → chunk-ETDWYT2P.cjs.map} +1 -1
  13. package/dist/tsup/{chunk-3Y45CIF4.cjs → chunk-F7YL5G7Q.cjs} +172 -172
  14. package/dist/tsup/{chunk-3Y45CIF4.cjs.map → chunk-F7YL5G7Q.cjs.map} +1 -1
  15. package/dist/tsup/{chunk-6OVKCDSH.cjs → chunk-GWJTWY3G.cjs} +6 -6
  16. package/dist/tsup/{chunk-6OVKCDSH.cjs.map → chunk-GWJTWY3G.cjs.map} +1 -1
  17. package/dist/tsup/{chunk-HPT3I7UU.js → chunk-KHRZPP5T.js} +8 -8
  18. package/dist/tsup/{chunk-6EUWRXLT.cjs → chunk-LXAVET4A.cjs} +2 -2
  19. package/dist/tsup/{chunk-6EUWRXLT.cjs.map → chunk-LXAVET4A.cjs.map} +1 -1
  20. package/dist/tsup/{chunk-SAZCNSVY.cjs → chunk-NDCVQZBS.cjs} +8 -8
  21. package/dist/tsup/{chunk-SAZCNSVY.cjs.map → chunk-NDCVQZBS.cjs.map} +1 -1
  22. package/dist/tsup/{chunk-BW5DPM6Z.js → chunk-NII4KKHD.js} +7 -7
  23. package/dist/tsup/{chunk-YQ4XQYPM.js → chunk-NRELKXIX.js} +3 -3
  24. package/dist/tsup/{chunk-5ZOHIKWG.cjs → chunk-NUA6LOOJ.cjs} +196 -196
  25. package/dist/tsup/{chunk-5ZOHIKWG.cjs.map → chunk-NUA6LOOJ.cjs.map} +1 -1
  26. package/dist/tsup/{chunk-B3TLRM4Q.cjs → chunk-OSK2VSJF.cjs} +12 -12
  27. package/dist/tsup/{chunk-B3TLRM4Q.cjs.map → chunk-OSK2VSJF.cjs.map} +1 -1
  28. package/dist/tsup/{chunk-4GP7BZSR.js → chunk-PD6HCAJE.js} +2 -2
  29. package/dist/tsup/{chunk-RVP5RUSC.js → chunk-RLBM6D4L.js} +2 -2
  30. package/dist/tsup/chunk-RLBM6D4L.js.map +1 -0
  31. package/dist/tsup/{chunk-K4ENQCC4.cjs → chunk-VAF63BEI.cjs} +3 -3
  32. package/dist/tsup/{chunk-K4ENQCC4.cjs.map → chunk-VAF63BEI.cjs.map} +1 -1
  33. package/dist/tsup/{chunk-SBKRVQS2.js → chunk-WAT5AE7S.js} +5 -5
  34. package/dist/tsup/{chunk-PUSQNDJG.js → chunk-YL4VZMMT.js} +2 -2
  35. package/dist/tsup/client/mod.cjs +9 -9
  36. package/dist/tsup/client/mod.js +8 -8
  37. package/dist/tsup/common/log.cjs +3 -3
  38. package/dist/tsup/common/log.js +2 -2
  39. package/dist/tsup/common/websocket.cjs +4 -4
  40. package/dist/tsup/common/websocket.js +3 -3
  41. package/dist/tsup/driver-helpers/mod.cjs +5 -5
  42. package/dist/tsup/driver-helpers/mod.js +4 -4
  43. package/dist/tsup/driver-test-suite/mod.cjs +69 -69
  44. package/dist/tsup/driver-test-suite/mod.js +11 -11
  45. package/dist/tsup/inspector/mod.cjs +6 -6
  46. package/dist/tsup/inspector/mod.js +5 -5
  47. package/dist/tsup/mod.cjs +10 -10
  48. package/dist/tsup/mod.js +9 -9
  49. package/dist/tsup/test/mod.cjs +11 -11
  50. package/dist/tsup/test/mod.js +10 -10
  51. package/dist/tsup/utils.cjs +2 -2
  52. package/dist/tsup/utils.js +1 -1
  53. package/package.json +1 -1
  54. package/dist/tsup/chunk-RVP5RUSC.js.map +0 -1
  55. /package/dist/tsup/{chunk-JD54PXWP.js.map → chunk-2NL3KGJ7.js.map} +0 -0
  56. /package/dist/tsup/{chunk-GZVBFXBI.js.map → chunk-54MAHBLL.js.map} +0 -0
  57. /package/dist/tsup/{chunk-E4UVJKSV.js.map → chunk-B6N6VM37.js.map} +0 -0
  58. /package/dist/tsup/{chunk-7N56ZUC7.js.map → chunk-DIHKN7NM.js.map} +0 -0
  59. /package/dist/tsup/{chunk-HPT3I7UU.js.map → chunk-KHRZPP5T.js.map} +0 -0
  60. /package/dist/tsup/{chunk-BW5DPM6Z.js.map → chunk-NII4KKHD.js.map} +0 -0
  61. /package/dist/tsup/{chunk-YQ4XQYPM.js.map → chunk-NRELKXIX.js.map} +0 -0
  62. /package/dist/tsup/{chunk-4GP7BZSR.js.map → chunk-PD6HCAJE.js.map} +0 -0
  63. /package/dist/tsup/{chunk-SBKRVQS2.js.map → chunk-WAT5AE7S.js.map} +0 -0
  64. /package/dist/tsup/{chunk-PUSQNDJG.js.map → chunk-YL4VZMMT.js.map} +0 -0
@@ -1,20 +1,20 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunk5ZOHIKWGcjs = require('./chunk-5ZOHIKWG.cjs');
4
+ var _chunkNUA6LOOJcjs = require('./chunk-NUA6LOOJ.cjs');
5
5
 
6
6
 
7
- var _chunkDFS77KAAcjs = require('./chunk-DFS77KAA.cjs');
7
+ var _chunk7OOBMCQIcjs = require('./chunk-7OOBMCQI.cjs');
8
8
 
9
9
  // src/client/mod.ts
10
10
  function createClient(endpointOrConfig) {
11
11
  const configInput = endpointOrConfig === void 0 ? {} : typeof endpointOrConfig === "string" ? { endpoint: endpointOrConfig } : endpointOrConfig;
12
- const config = _chunkDFS77KAAcjs.ClientConfigSchema.parse(configInput);
13
- const driver = new (0, _chunk5ZOHIKWGcjs.RemoteManagerDriver)(config);
14
- return _chunk5ZOHIKWGcjs.createClientWithDriver.call(void 0, driver, config);
12
+ const config = _chunk7OOBMCQIcjs.ClientConfigSchema.parse(configInput);
13
+ const driver = new (0, _chunkNUA6LOOJcjs.RemoteManagerDriver)(config);
14
+ return _chunkNUA6LOOJcjs.createClientWithDriver.call(void 0, driver, config);
15
15
  }
16
16
 
17
17
 
18
18
 
19
19
  exports.createClient = createClient;
20
- //# sourceMappingURL=chunk-6OVKCDSH.cjs.map
20
+ //# sourceMappingURL=chunk-GWJTWY3G.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-6OVKCDSH.cjs","../../src/client/mod.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACoCO,SAAS,YAAA,CACf,gBAAA,EACY;AAEZ,EAAA,MAAM,YAAA,EACL,iBAAA,IAAqB,KAAA,EAAA,EAClB,CAAC,EAAA,EACD,OAAO,iBAAA,IAAqB,SAAA,EAC3B,EAAE,QAAA,EAAU,iBAAiB,EAAA,EAC7B,gBAAA;AACL,EAAA,MAAM,OAAA,EAAS,oCAAA,CAAmB,KAAA,CAAM,WAAW,CAAA;AAGnD,EAAA,MAAM,OAAA,EAAS,IAAI,0CAAA,CAAoB,MAAM,CAAA;AAC7C,EAAA,OAAO,sDAAA,MAA0B,EAAQ,MAAM,CAAA;AAChD;AD5CA;AACA;AACE;AACF,oCAAC","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-6OVKCDSH.cjs","sourcesContent":[null,"import type { Registry } from \"@/registry/mod\";\nimport { RemoteManagerDriver } from \"@/remote-manager-driver/mod\";\nimport {\n\ttype Client,\n\ttype ClientConfigInput,\n\tcreateClientWithDriver,\n} from \"./client\";\nimport { ClientConfigSchema } from \"./config\";\n\nexport {\n\tActorDefinition,\n\tAnyActorDefinition,\n} from \"@/actor/definition\";\nexport type { Transport } from \"@/actor/protocol/old\";\nexport type { Encoding } from \"@/actor/protocol/serde\";\nexport {\n\tActorClientError,\n\tActorError,\n\tInternalError,\n\tMalformedResponseMessage,\n\tManagerError,\n} from \"@/client/errors\";\nexport type { CreateRequest } from \"@/manager/protocol/query\";\nexport type { ActorActionFunction } from \"./actor-common\";\nexport type { ActorConn, EventUnsubscribe } from \"./actor-conn\";\nexport { ActorConnRaw } from \"./actor-conn\";\nexport type { ActorHandle } from \"./actor-handle\";\nexport { ActorHandleRaw } from \"./actor-handle\";\nexport type {\n\tActorAccessor,\n\tClient,\n\tClientRaw,\n\tCreateOptions,\n\tExtractActorsFromRegistry,\n\tExtractRegistryFromClient,\n\tGetOptions,\n\tGetWithIdOptions,\n\tQueryOptions,\n\tRegion,\n} from \"./client\";\n\n/**\n * Creates a client with the actor accessor proxy.\n */\nexport function createClient<A extends Registry<any>>(\n\tendpointOrConfig?: string | ClientConfigInput,\n): Client<A> {\n\t// Parse config\n\tconst configInput =\n\t\tendpointOrConfig === undefined\n\t\t\t? {}\n\t\t\t: typeof endpointOrConfig === \"string\"\n\t\t\t\t? { endpoint: endpointOrConfig }\n\t\t\t\t: endpointOrConfig;\n\tconst config = ClientConfigSchema.parse(configInput);\n\n\t// Create client\n\tconst driver = new RemoteManagerDriver(config);\n\treturn createClientWithDriver<A>(driver, config);\n}\n"]}
1
+ {"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-GWJTWY3G.cjs","../../src/client/mod.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACoCO,SAAS,YAAA,CACf,gBAAA,EACY;AAEZ,EAAA,MAAM,YAAA,EACL,iBAAA,IAAqB,KAAA,EAAA,EAClB,CAAC,EAAA,EACD,OAAO,iBAAA,IAAqB,SAAA,EAC3B,EAAE,QAAA,EAAU,iBAAiB,EAAA,EAC7B,gBAAA;AACL,EAAA,MAAM,OAAA,EAAS,oCAAA,CAAmB,KAAA,CAAM,WAAW,CAAA;AAGnD,EAAA,MAAM,OAAA,EAAS,IAAI,0CAAA,CAAoB,MAAM,CAAA;AAC7C,EAAA,OAAO,sDAAA,MAA0B,EAAQ,MAAM,CAAA;AAChD;AD5CA;AACA;AACE;AACF,oCAAC","file":"/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-GWJTWY3G.cjs","sourcesContent":[null,"import type { Registry } from \"@/registry/mod\";\nimport { RemoteManagerDriver } from \"@/remote-manager-driver/mod\";\nimport {\n\ttype Client,\n\ttype ClientConfigInput,\n\tcreateClientWithDriver,\n} from \"./client\";\nimport { ClientConfigSchema } from \"./config\";\n\nexport {\n\tActorDefinition,\n\tAnyActorDefinition,\n} from \"@/actor/definition\";\nexport type { Transport } from \"@/actor/protocol/old\";\nexport type { Encoding } from \"@/actor/protocol/serde\";\nexport {\n\tActorClientError,\n\tActorError,\n\tInternalError,\n\tMalformedResponseMessage,\n\tManagerError,\n} from \"@/client/errors\";\nexport type { CreateRequest } from \"@/manager/protocol/query\";\nexport type { ActorActionFunction } from \"./actor-common\";\nexport type { ActorConn, EventUnsubscribe } from \"./actor-conn\";\nexport { ActorConnRaw } from \"./actor-conn\";\nexport type { ActorHandle } from \"./actor-handle\";\nexport { ActorHandleRaw } from \"./actor-handle\";\nexport type {\n\tActorAccessor,\n\tClient,\n\tClientRaw,\n\tCreateOptions,\n\tExtractActorsFromRegistry,\n\tExtractRegistryFromClient,\n\tGetOptions,\n\tGetWithIdOptions,\n\tQueryOptions,\n\tRegion,\n} from \"./client\";\n\n/**\n * Creates a client with the actor accessor proxy.\n */\nexport function createClient<A extends Registry<any>>(\n\tendpointOrConfig?: string | ClientConfigInput,\n): Client<A> {\n\t// Parse config\n\tconst configInput =\n\t\tendpointOrConfig === undefined\n\t\t\t? {}\n\t\t\t: typeof endpointOrConfig === \"string\"\n\t\t\t\t? { endpoint: endpointOrConfig }\n\t\t\t\t: endpointOrConfig;\n\tconst config = ClientConfigSchema.parse(configInput);\n\n\t// Create client\n\tconst driver = new RemoteManagerDriver(config);\n\treturn createClientWithDriver<A>(driver, config);\n}\n"]}
@@ -4,7 +4,7 @@ import {
4
4
  inspectorLogger,
5
5
  isInspectorEnabled,
6
6
  secureInspector
7
- } from "./chunk-4GP7BZSR.js";
7
+ } from "./chunk-PD6HCAJE.js";
8
8
  import {
9
9
  ActorDefinition,
10
10
  RemoteManagerDriver,
@@ -14,10 +14,10 @@ import {
14
14
  generateConnSocketId,
15
15
  lookupInRegistry,
16
16
  serializeActorKey
17
- } from "./chunk-BW5DPM6Z.js";
17
+ } from "./chunk-NII4KKHD.js";
18
18
  import {
19
19
  CreateActorSchema
20
- } from "./chunk-GZVBFXBI.js";
20
+ } from "./chunk-54MAHBLL.js";
21
21
  import {
22
22
  ActionContext,
23
23
  HTTP_ACTION_REQUEST_VERSIONED,
@@ -28,7 +28,7 @@ import {
28
28
  createVersionedDataHandler,
29
29
  parseMessage,
30
30
  serializeEmptyPersistData
31
- } from "./chunk-JD54PXWP.js";
31
+ } from "./chunk-2NL3KGJ7.js";
32
32
  import {
33
33
  EncodingSchema,
34
34
  HEADER_ACTOR_ID,
@@ -54,12 +54,12 @@ import {
54
54
  generateRandomString,
55
55
  loggerWithoutContext,
56
56
  serializeWithEncoding
57
- } from "./chunk-YQ4XQYPM.js";
57
+ } from "./chunk-NRELKXIX.js";
58
58
  import {
59
59
  configureBaseLogger,
60
60
  configureDefaultLogger,
61
61
  getLogger
62
- } from "./chunk-PUSQNDJG.js";
62
+ } from "./chunk-YL4VZMMT.js";
63
63
  import {
64
64
  bufferToArrayBuffer,
65
65
  deconstructError,
@@ -69,7 +69,7 @@ import {
69
69
  promiseWithResolvers,
70
70
  setLongTimeout,
71
71
  stringifyError
72
- } from "./chunk-RVP5RUSC.js";
72
+ } from "./chunk-RLBM6D4L.js";
73
73
  import {
74
74
  ActorAlreadyExists,
75
75
  ConnNotFound,
@@ -3723,4 +3723,4 @@ export {
3723
3723
  setup
3724
3724
  };
3725
3725
  //! These configs configs hold anything that's not platform-specific about running actors.
3726
- //# sourceMappingURL=chunk-HPT3I7UU.js.map
3726
+ //# sourceMappingURL=chunk-KHRZPP5T.js.map
@@ -208,7 +208,7 @@ function noopNext() {
208
208
  // package.json
209
209
  var package_default = {
210
210
  name: "rivetkit",
211
- version: "2.0.7-rc.1",
211
+ version: "2.0.7",
212
212
  description: "Lightweight libraries for building stateful actors on edge platforms",
213
213
  license: "Apache-2.0",
214
214
  keywords: [
@@ -575,4 +575,4 @@ function combineUrlPath(endpoint, path, queryParams) {
575
575
 
576
576
 
577
577
  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;
578
- //# sourceMappingURL=chunk-6EUWRXLT.cjs.map
578
+ //# sourceMappingURL=chunk-LXAVET4A.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-6EUWRXLT.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,EAAA;AACA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C;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,QAAA;AACb,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UAAA;AAC/B,QAAA;AACD,MAAA;AACD,IAAA;AACD,EAAA;AAEsC,EAAA;AACC,EAAA;AACxC;AH2TyC;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-6EUWRXLT.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.7-rc.1\",\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@3002\",\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 \"pino\": \"^9.5.0\",\n \"p-retry\": \"^6.2.1\",\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 \"bufferutil\": \"^4.0.9\"\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 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-LXAVET4A.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,EA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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;AACC,IAAA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A,EAAA;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;AH2TyC;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-LXAVET4A.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.7\",\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@3002\",\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 \"pino\": \"^9.5.0\",\n \"p-retry\": \"^6.2.1\",\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 \"bufferutil\": \"^4.0.9\"\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 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,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
2
 
3
- var _chunk3MBP4WNCcjs = require('./chunk-3MBP4WNC.cjs');
3
+ var _chunkETDWYT2Pcjs = require('./chunk-ETDWYT2P.cjs');
4
4
 
5
5
 
6
- var _chunk6EUWRXLTcjs = require('./chunk-6EUWRXLT.cjs');
6
+ var _chunkLXAVET4Acjs = require('./chunk-LXAVET4A.cjs');
7
7
 
8
8
 
9
9
  var _chunk5QGQK44Lcjs = require('./chunk-5QGQK44L.cjs');
@@ -53,7 +53,7 @@ var _zod = require('zod');
53
53
 
54
54
  // src/actor/log.ts
55
55
  function loggerWithoutContext() {
56
- return _chunk3MBP4WNCcjs.getLogger.call(void 0, "actor-runtime");
56
+ return _chunkETDWYT2Pcjs.getLogger.call(void 0, "actor-runtime");
57
57
  }
58
58
 
59
59
  // src/actor/utils.ts
@@ -163,7 +163,7 @@ function encodingIsBinary(encoding) {
163
163
  } else if (encoding === "cbor" || encoding === "bare") {
164
164
  return true;
165
165
  } else {
166
- _chunk6EUWRXLTcjs.assertUnreachable.call(void 0, encoding);
166
+ _chunkLXAVET4Acjs.assertUnreachable.call(void 0, encoding);
167
167
  }
168
168
  }
169
169
  function contentTypeForEncoding(encoding) {
@@ -172,7 +172,7 @@ function contentTypeForEncoding(encoding) {
172
172
  } else if (encoding === "cbor" || encoding === "bare") {
173
173
  return "application/octet-stream";
174
174
  } else {
175
- _chunk6EUWRXLTcjs.assertUnreachable.call(void 0, encoding);
175
+ _chunkLXAVET4Acjs.assertUnreachable.call(void 0, encoding);
176
176
  }
177
177
  }
178
178
  function serializeWithEncoding(encoding, value, versionedDataHandler) {
@@ -186,7 +186,7 @@ function serializeWithEncoding(encoding, value, versionedDataHandler) {
186
186
  }
187
187
  return versionedDataHandler.serializeWithEmbeddedVersion(value);
188
188
  } else {
189
- _chunk6EUWRXLTcjs.assertUnreachable.call(void 0, encoding);
189
+ _chunkLXAVET4Acjs.assertUnreachable.call(void 0, encoding);
190
190
  }
191
191
  }
192
192
  function deserializeWithEncoding(encoding, buffer, versionedDataHandler) {
@@ -214,7 +214,7 @@ function deserializeWithEncoding(encoding, buffer, versionedDataHandler) {
214
214
  }
215
215
  return versionedDataHandler.deserializeWithEmbeddedVersion(buffer);
216
216
  } else {
217
- _chunk6EUWRXLTcjs.assertUnreachable.call(void 0, encoding);
217
+ _chunkLXAVET4Acjs.assertUnreachable.call(void 0, encoding);
218
218
  }
219
219
  }
220
220
 
@@ -256,4 +256,4 @@ function deserializeWithEncoding(encoding, buffer, versionedDataHandler) {
256
256
 
257
257
 
258
258
  exports.encodingIsBinary = encodingIsBinary; exports.contentTypeForEncoding = contentTypeForEncoding; exports.serializeWithEncoding = serializeWithEncoding; exports.deserializeWithEncoding = deserializeWithEncoding; exports.loggerWithoutContext = loggerWithoutContext; exports.assertUnreachable = assertUnreachable2; exports.DeadlineError = DeadlineError; exports.deadline = deadline; exports.generateSecureToken = generateSecureToken; exports.generateRandomString = generateRandomString; exports.EncodingSchema = EncodingSchema; exports.CachedSerializer = CachedSerializer; exports.encodeDataToString = encodeDataToString; exports.jsonStringifyCompat = jsonStringifyCompat; exports.PATH_CONNECT_WEBSOCKET = PATH_CONNECT_WEBSOCKET; exports.PATH_RAW_WEBSOCKET_PREFIX = PATH_RAW_WEBSOCKET_PREFIX; exports.HEADER_ACTOR_QUERY = HEADER_ACTOR_QUERY; exports.HEADER_ENCODING = HEADER_ENCODING; exports.HEADER_CONN_PARAMS = HEADER_CONN_PARAMS; exports.HEADER_ACTOR_ID = HEADER_ACTOR_ID; exports.HEADER_CONN_ID = HEADER_CONN_ID; exports.HEADER_CONN_TOKEN = HEADER_CONN_TOKEN; exports.HEADER_RIVET_TOKEN = HEADER_RIVET_TOKEN; exports.HEADER_RIVET_TARGET = HEADER_RIVET_TARGET; exports.HEADER_RIVET_ACTOR = HEADER_RIVET_ACTOR; exports.WS_PROTOCOL_STANDARD = WS_PROTOCOL_STANDARD; exports.WS_PROTOCOL_TARGET = WS_PROTOCOL_TARGET; exports.WS_PROTOCOL_ACTOR = WS_PROTOCOL_ACTOR; exports.WS_PROTOCOL_ENCODING = WS_PROTOCOL_ENCODING; exports.WS_PROTOCOL_CONN_PARAMS = WS_PROTOCOL_CONN_PARAMS; exports.WS_PROTOCOL_CONN_ID = WS_PROTOCOL_CONN_ID; exports.WS_PROTOCOL_CONN_TOKEN = WS_PROTOCOL_CONN_TOKEN; exports.WS_PROTOCOL_TOKEN = WS_PROTOCOL_TOKEN; exports.WS_PROTOCOL_TRANSPORT = WS_PROTOCOL_TRANSPORT; exports.WS_PROTOCOL_PATH = WS_PROTOCOL_PATH; exports.ALLOWED_PUBLIC_HEADERS = ALLOWED_PUBLIC_HEADERS;
259
- //# sourceMappingURL=chunk-SAZCNSVY.cjs.map
259
+ //# sourceMappingURL=chunk-NDCVQZBS.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-SAZCNSVY.cjs","../../src/common/actor-router-consts.ts","../../src/serde.ts","../../src/actor/protocol/serde.ts","../../src/actor/log.ts","../../src/actor/utils.ts"],"names":["assertUnreachable"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACPO,IAAM,uBAAA,EAAyB,oBAAA;AAC/B,IAAM,0BAAA,EAA4B,iBAAA;AAGlC,IAAM,mBAAA,EAAqB,eAAA;AAE3B,IAAM,gBAAA,EAAkB,kBAAA;AAGxB,IAAM,mBAAA,EAAqB,qBAAA;AAE3B,IAAM,gBAAA,EAAkB,eAAA;AAExB,IAAM,eAAA,EAAiB,cAAA;AAEvB,IAAM,kBAAA,EAAoB,oBAAA;AAE1B,IAAM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,IAAA;AACK,IAAA;AACE,MAAA;AACP,IAAA;AACO,IAAA;AACD,EAAA;AACN,IAAA;AACD,EAAA;AACD;AFkIY;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-SAZCNSVY.cjs","sourcesContent":[null,"// NOTE: This is in a separate file from the router since it needs to be shared between the client & the server. If this was in the router file, the client would end up importing the *entire* actor router and tree shaking would not work.\n\n// MARK: Paths\nexport const PATH_CONNECT_WEBSOCKET = \"/connect/websocket\";\nexport const PATH_RAW_WEBSOCKET_PREFIX = \"/raw/websocket/\";\n\n// MARK: Headers\nexport const HEADER_ACTOR_QUERY = \"x-rivet-query\";\n\nexport const HEADER_ENCODING = \"x-rivet-encoding\";\n\n// IMPORTANT: Params must be in headers or in an E2EE part of the request (i.e. NOT the URL or query string) in order to ensure that tokens can be securely passed in params.\nexport const HEADER_CONN_PARAMS = \"x-rivet-conn-params\";\n\nexport const HEADER_ACTOR_ID = \"x-rivet-actor\";\n\nexport const HEADER_CONN_ID = \"x-rivet-conn\";\n\nexport const HEADER_CONN_TOKEN = \"x-rivet-conn-token\";\n\nexport const HEADER_RIVET_TOKEN = \"x-rivet-token\";\n\n// MARK: Manager Gateway Headers\nexport const HEADER_RIVET_TARGET = \"x-rivet-target\";\nexport const HEADER_RIVET_ACTOR = \"x-rivet-actor\";\n\n// MARK: WebSocket Protocol Prefixes\n/** Some servers (such as node-ws & Cloudflare) require explicitly match a certain WebSocket protocol. This gives us a static protocol to match against. */\nexport const WS_PROTOCOL_STANDARD = \"rivet\";\nexport const WS_PROTOCOL_TARGET = \"rivet_target.\";\nexport const WS_PROTOCOL_ACTOR = \"rivet_actor.\";\nexport const WS_PROTOCOL_ENCODING = \"rivet_encoding.\";\nexport const WS_PROTOCOL_CONN_PARAMS = \"rivet_conn_params.\";\nexport const WS_PROTOCOL_CONN_ID = \"rivet_conn.\";\nexport const WS_PROTOCOL_CONN_TOKEN = \"rivet_conn_token.\";\nexport const WS_PROTOCOL_TOKEN = \"rivet_token.\";\n\n// MARK: WebSocket Inline Test Protocol Prefixes\nexport const WS_PROTOCOL_TRANSPORT = \"test_transport.\";\nexport const WS_PROTOCOL_PATH = \"test_path.\";\n\n/**\n * Headers that publics can send from public clients.\n *\n * Used for CORS.\n **/\nexport const ALLOWED_PUBLIC_HEADERS = [\n\t\"Content-Type\",\n\t\"User-Agent\",\n\tHEADER_ACTOR_QUERY,\n\tHEADER_ENCODING,\n\tHEADER_CONN_PARAMS,\n\tHEADER_ACTOR_ID,\n\tHEADER_CONN_ID,\n\tHEADER_CONN_TOKEN,\n\tHEADER_RIVET_TARGET,\n\tHEADER_RIVET_ACTOR,\n\tHEADER_RIVET_TOKEN,\n];\n","import * as cbor from \"cbor-x\";\nimport invariant from \"invariant\";\nimport { assertUnreachable } from \"@/common/utils\";\nimport type { VersionedDataHandler } from \"@/common/versioned-data\";\nimport type { Encoding } from \"@/mod\";\nimport { jsonStringifyCompat } from \"./actor/protocol/serde\";\n\nexport function encodingIsBinary(encoding: Encoding): boolean {\n\tif (encoding === \"json\") {\n\t\treturn false;\n\t} else if (encoding === \"cbor\" || encoding === \"bare\") {\n\t\treturn true;\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n\nexport function contentTypeForEncoding(encoding: Encoding): string {\n\tif (encoding === \"json\") {\n\t\treturn \"application/json\";\n\t} else if (encoding === \"cbor\" || encoding === \"bare\") {\n\t\treturn \"application/octet-stream\";\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n\nexport function wsBinaryTypeForEncoding(\n\tencoding: Encoding,\n): \"arraybuffer\" | \"blob\" {\n\tif (encoding === \"json\") {\n\t\treturn \"blob\";\n\t} else if (encoding === \"cbor\" || encoding === \"bare\") {\n\t\treturn \"arraybuffer\";\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n\nexport function serializeWithEncoding<T>(\n\tencoding: Encoding,\n\tvalue: T,\n\tversionedDataHandler: VersionedDataHandler<T> | undefined,\n): Uint8Array | string {\n\tif (encoding === \"json\") {\n\t\treturn jsonStringifyCompat(value);\n\t} else if (encoding === \"cbor\") {\n\t\treturn cbor.encode(value);\n\t} else if (encoding === \"bare\") {\n\t\tif (!versionedDataHandler) {\n\t\t\tthrow new Error(\"VersionedDataHandler is required for 'bare' encoding\");\n\t\t}\n\t\treturn versionedDataHandler.serializeWithEmbeddedVersion(value);\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n\nexport function deserializeWithEncoding<T>(\n\tencoding: Encoding,\n\tbuffer: Uint8Array | string,\n\tversionedDataHandler: VersionedDataHandler<T> | undefined,\n): T {\n\tif (encoding === \"json\") {\n\t\tif (typeof buffer === \"string\") {\n\t\t\treturn JSON.parse(buffer);\n\t\t} else {\n\t\t\tconst decoder = new TextDecoder(\"utf-8\");\n\t\t\tconst jsonString = decoder.decode(buffer);\n\t\t\treturn JSON.parse(jsonString);\n\t\t}\n\t} else if (encoding === \"cbor\") {\n\t\tinvariant(\n\t\t\ttypeof buffer !== \"string\",\n\t\t\t\"buffer cannot be string for cbor encoding\",\n\t\t);\n\t\treturn cbor.decode(buffer);\n\t} else if (encoding === \"bare\") {\n\t\tinvariant(\n\t\t\ttypeof buffer !== \"string\",\n\t\t\t\"buffer cannot be string for bare encoding\",\n\t\t);\n\t\tif (!versionedDataHandler) {\n\t\t\tthrow new Error(\"VersionedDataHandler is required for 'bare' encoding\");\n\t\t}\n\t\treturn versionedDataHandler.deserializeWithEmbeddedVersion(buffer);\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n","import * as cbor from \"cbor-x\";\nimport { z } from \"zod\";\nimport * as errors from \"@/actor/errors\";\nimport type { VersionedDataHandler } from \"@/common/versioned-data\";\nimport { serializeWithEncoding } from \"@/serde\";\nimport { loggerWithoutContext } from \"../log\";\nimport { assertUnreachable } from \"../utils\";\n\n/** Data that can be deserialized. */\nexport type InputData = string | Buffer | Blob | ArrayBufferLike | Uint8Array;\n\n/** Data that's been serialized. */\nexport type OutputData = string | Uint8Array;\n\nexport const EncodingSchema = z.enum([\"json\", \"cbor\", \"bare\"]);\n\n/**\n * Encoding used to communicate between the client & actor.\n */\nexport type Encoding = z.infer<typeof EncodingSchema>;\n\n/**\n * Helper class that helps serialize data without re-serializing for the same encoding.\n */\nexport class CachedSerializer<T> {\n\t#data: T;\n\t#cache = new Map<Encoding, OutputData>();\n\t#versionedDataHandler: VersionedDataHandler<T>;\n\n\tconstructor(data: T, versionedDataHandler: VersionedDataHandler<T>) {\n\t\tthis.#data = data;\n\t\tthis.#versionedDataHandler = versionedDataHandler;\n\t}\n\n\tpublic get rawData(): T {\n\t\treturn this.#data;\n\t}\n\n\tpublic serialize(encoding: Encoding): OutputData {\n\t\tconst cached = this.#cache.get(encoding);\n\t\tif (cached) {\n\t\t\treturn cached;\n\t\t} else {\n\t\t\tconst serialized = serializeWithEncoding(\n\t\t\t\tencoding,\n\t\t\t\tthis.#data,\n\t\t\t\tthis.#versionedDataHandler,\n\t\t\t);\n\t\t\tthis.#cache.set(encoding, serialized);\n\t\t\treturn serialized;\n\t\t}\n\t}\n}\n\n///**\n// * Use `CachedSerializer` if serializing the same data repeatedly.\n// */\n//export function serialize<T>(value: T, encoding: Encoding): OutputData {\n//\tif (encoding === \"json\") {\n//\t\treturn JSON.stringify(value);\n//\t} else if (encoding === \"cbor\") {\n//\t\t// TODO: Remove this hack, but cbor-x can't handle anything extra in data structures\n//\t\tconst cleanValue = JSON.parse(JSON.stringify(value));\n//\t\treturn cbor.encode(cleanValue);\n//\t} else {\n//\t\tassertUnreachable(encoding);\n//\t}\n//}\n//\n//export async function deserialize(data: InputData, encoding: Encoding) {\n//\tif (encoding === \"json\") {\n//\t\tif (typeof data !== \"string\") {\n//\t\t\tlogger().warn(\"received non-string for json parse\");\n//\t\t\tthrow new errors.MalformedMessage();\n//\t\t} else {\n//\t\t\treturn JSON.parse(data);\n//\t\t}\n//\t} else if (encoding === \"cbor\") {\n//\t\tif (data instanceof Blob) {\n//\t\t\tconst arrayBuffer = await data.arrayBuffer();\n//\t\t\treturn cbor.decode(new Uint8Array(arrayBuffer));\n//\t\t} else if (data instanceof Uint8Array) {\n//\t\t\treturn cbor.decode(data);\n//\t\t} else if (\n//\t\t\tdata instanceof ArrayBuffer ||\n//\t\t\tdata instanceof SharedArrayBuffer\n//\t\t) {\n//\t\t\treturn cbor.decode(new Uint8Array(data));\n//\t\t} else {\n//\t\t\tlogger().warn(\"received non-binary type for cbor parse\");\n//\t\t\tthrow new errors.MalformedMessage();\n//\t\t}\n//\t} else {\n//\t\tassertUnreachable(encoding);\n//\t}\n//}\n\n// TODO: Encode base 128\nfunction base64EncodeUint8Array(uint8Array: Uint8Array): string {\n\tlet binary = \"\";\n\tconst len = uint8Array.byteLength;\n\tfor (let i = 0; i < len; i++) {\n\t\tbinary += String.fromCharCode(uint8Array[i]);\n\t}\n\treturn btoa(binary);\n}\n\nfunction base64EncodeArrayBuffer(arrayBuffer: ArrayBuffer): string {\n\tconst uint8Array = new Uint8Array(arrayBuffer);\n\treturn base64EncodeUint8Array(uint8Array);\n}\n\n/** Converts data that was encoded to a string. Some formats (like SSE) don't support raw binary data. */\nexport function encodeDataToString(message: OutputData): string {\n\tif (typeof message === \"string\") {\n\t\treturn message;\n\t} else if (message instanceof ArrayBuffer) {\n\t\treturn base64EncodeArrayBuffer(message);\n\t} else if (message instanceof Uint8Array) {\n\t\treturn base64EncodeUint8Array(message);\n\t} else {\n\t\tassertUnreachable(message);\n\t}\n}\n\n/** Stringifies with compat for values that BARE & CBOR supports. */\nexport function jsonStringifyCompat(input: any): string {\n\treturn JSON.stringify(input, (_key, value) =>\n\t\ttypeof value === \"bigint\" ? value.toString() : value,\n\t);\n}\n","import { getLogger } from \"@/common/log\";\n\n/** Prever to use ActorInstance.rlog child logger. This does not provide context in the log, should only be used as a last resort if you cannot pass the actor's child logger. */\nexport function loggerWithoutContext() {\n\treturn getLogger(\"actor-runtime\");\n}\n","import * as errors from \"./errors\";\nimport { loggerWithoutContext } from \"./log\";\n\nexport function assertUnreachable(x: never): never {\n\tloggerWithoutContext().error({\n\t\tmsg: \"unreachable\",\n\t\tvalue: `${x}`,\n\t\tstack: new Error().stack,\n\t});\n\tthrow new errors.Unreachable(x);\n}\n\nexport const throttle = <\n\t// biome-ignore lint/suspicious/noExplicitAny: we want to allow any function\n\tFn extends (...args: any) => any,\n>(\n\tfn: Fn,\n\tdelay: number,\n) => {\n\tlet lastRan = false;\n\tlet lastArgs: Parameters<Fn> | null = null;\n\n\treturn (...args: Parameters<Fn>) => {\n\t\tif (!lastRan) {\n\t\t\tfn.apply(this, args);\n\t\t\tlastRan = true;\n\t\t\tconst timer = () =>\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tlastRan = false;\n\t\t\t\t\tif (lastArgs) {\n\t\t\t\t\t\tfn.apply(this, lastArgs);\n\t\t\t\t\t\tlastRan = true;\n\t\t\t\t\t\tlastArgs = null;\n\t\t\t\t\t\ttimer();\n\t\t\t\t\t}\n\t\t\t\t}, delay);\n\t\t\ttimer();\n\t\t} else lastArgs = args;\n\t};\n};\n\nexport class DeadlineError extends Error {\n\tconstructor() {\n\t\tsuper(\"Promise did not complete before deadline.\");\n\t}\n}\n\nexport function deadline<T>(promise: Promise<T>, timeout: number): Promise<T> {\n\tconst controller = new AbortController();\n\tconst signal = controller.signal;\n\n\t// Set a timeout to abort the operation\n\tconst timeoutId = setTimeout(() => controller.abort(), timeout);\n\n\treturn Promise.race<T>([\n\t\tpromise,\n\t\tnew Promise<T>((_, reject) => {\n\t\t\tsignal.addEventListener(\"abort\", () => reject(new DeadlineError()));\n\t\t}),\n\t]).finally(() => {\n\t\tclearTimeout(timeoutId);\n\t});\n}\n\nexport class Lock<T> {\n\tprivate _locked = false;\n\tprivate _waiting: Array<() => void> = [];\n\n\tconstructor(private _value: T) {}\n\n\tasync lock(fn: (value: T) => Promise<void>): Promise<void> {\n\t\tif (this._locked) {\n\t\t\tawait new Promise<void>((resolve) => this._waiting.push(resolve));\n\t\t}\n\t\tthis._locked = true;\n\n\t\ttry {\n\t\t\tawait fn(this._value);\n\t\t} finally {\n\t\t\tthis._locked = false;\n\t\t\tconst next = this._waiting.shift();\n\t\t\tif (next) next();\n\t\t}\n\t}\n}\n\nexport function generateSecureToken(length = 32) {\n\tconst array = new Uint8Array(length);\n\tcrypto.getRandomValues(array);\n\t// Replace base64 chars that are not URL safe with URL-safe chars and strip padding\n\treturn btoa(String.fromCharCode(...array))\n\t\t.replace(/\\+/g, \"-\")\n\t\t.replace(/\\//g, \"_\")\n\t\t.replace(/=/g, \"\");\n}\n\nexport function generateRandomString(length = 32) {\n\tconst characters =\n\t\t\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n\tlet result = \"\";\n\tfor (let i = 0; i < length; i++) {\n\t\tconst randomIndex = Math.floor(Math.random() * characters.length);\n\t\tresult += characters[randomIndex];\n\t}\n\treturn result;\n}\n"]}
1
+ {"version":3,"sources":["/Users/nathan/rivetkit/packages/rivetkit/dist/tsup/chunk-NDCVQZBS.cjs","../../src/common/actor-router-consts.ts","../../src/serde.ts","../../src/actor/protocol/serde.ts","../../src/actor/log.ts","../../src/actor/utils.ts"],"names":["assertUnreachable"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACPO,IAAM,uBAAA,EAAyB,oBAAA;AAC/B,IAAM,0BAAA,EAA4B,iBAAA;AAGlC,IAAM,mBAAA,EAAqB,eAAA;AAE3B,IAAM,gBAAA,EAAkB,kBAAA;AAGxB,IAAM,mBAAA,EAAqB,qBAAA;AAE3B,IAAM,gBAAA,EAAkB,eAAA;AAEx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MAAA;AACD,IAAA;AACY,IAAA;AACb,EAAA;AACC,IAAA;AACC,MAAA;AACA,MAAA;AACD,IAAA;AACK,IAAA;AACE,MAAA;AACP,IAAA;AACO,IAAA;AACD,EAAA;AACN,IAAA;AACD,EAAA;AACD;AFkIY;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-NDCVQZBS.cjs","sourcesContent":[null,"// NOTE: This is in a separate file from the router since it needs to be shared between the client & the server. If this was in the router file, the client would end up importing the *entire* actor router and tree shaking would not work.\n\n// MARK: Paths\nexport const PATH_CONNECT_WEBSOCKET = \"/connect/websocket\";\nexport const PATH_RAW_WEBSOCKET_PREFIX = \"/raw/websocket/\";\n\n// MARK: Headers\nexport const HEADER_ACTOR_QUERY = \"x-rivet-query\";\n\nexport const HEADER_ENCODING = \"x-rivet-encoding\";\n\n// IMPORTANT: Params must be in headers or in an E2EE part of the request (i.e. NOT the URL or query string) in order to ensure that tokens can be securely passed in params.\nexport const HEADER_CONN_PARAMS = \"x-rivet-conn-params\";\n\nexport const HEADER_ACTOR_ID = \"x-rivet-actor\";\n\nexport const HEADER_CONN_ID = \"x-rivet-conn\";\n\nexport const HEADER_CONN_TOKEN = \"x-rivet-conn-token\";\n\nexport const HEADER_RIVET_TOKEN = \"x-rivet-token\";\n\n// MARK: Manager Gateway Headers\nexport const HEADER_RIVET_TARGET = \"x-rivet-target\";\nexport const HEADER_RIVET_ACTOR = \"x-rivet-actor\";\n\n// MARK: WebSocket Protocol Prefixes\n/** Some servers (such as node-ws & Cloudflare) require explicitly match a certain WebSocket protocol. This gives us a static protocol to match against. */\nexport const WS_PROTOCOL_STANDARD = \"rivet\";\nexport const WS_PROTOCOL_TARGET = \"rivet_target.\";\nexport const WS_PROTOCOL_ACTOR = \"rivet_actor.\";\nexport const WS_PROTOCOL_ENCODING = \"rivet_encoding.\";\nexport const WS_PROTOCOL_CONN_PARAMS = \"rivet_conn_params.\";\nexport const WS_PROTOCOL_CONN_ID = \"rivet_conn.\";\nexport const WS_PROTOCOL_CONN_TOKEN = \"rivet_conn_token.\";\nexport const WS_PROTOCOL_TOKEN = \"rivet_token.\";\n\n// MARK: WebSocket Inline Test Protocol Prefixes\nexport const WS_PROTOCOL_TRANSPORT = \"test_transport.\";\nexport const WS_PROTOCOL_PATH = \"test_path.\";\n\n/**\n * Headers that publics can send from public clients.\n *\n * Used for CORS.\n **/\nexport const ALLOWED_PUBLIC_HEADERS = [\n\t\"Content-Type\",\n\t\"User-Agent\",\n\tHEADER_ACTOR_QUERY,\n\tHEADER_ENCODING,\n\tHEADER_CONN_PARAMS,\n\tHEADER_ACTOR_ID,\n\tHEADER_CONN_ID,\n\tHEADER_CONN_TOKEN,\n\tHEADER_RIVET_TARGET,\n\tHEADER_RIVET_ACTOR,\n\tHEADER_RIVET_TOKEN,\n];\n","import * as cbor from \"cbor-x\";\nimport invariant from \"invariant\";\nimport { assertUnreachable } from \"@/common/utils\";\nimport type { VersionedDataHandler } from \"@/common/versioned-data\";\nimport type { Encoding } from \"@/mod\";\nimport { jsonStringifyCompat } from \"./actor/protocol/serde\";\n\nexport function encodingIsBinary(encoding: Encoding): boolean {\n\tif (encoding === \"json\") {\n\t\treturn false;\n\t} else if (encoding === \"cbor\" || encoding === \"bare\") {\n\t\treturn true;\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n\nexport function contentTypeForEncoding(encoding: Encoding): string {\n\tif (encoding === \"json\") {\n\t\treturn \"application/json\";\n\t} else if (encoding === \"cbor\" || encoding === \"bare\") {\n\t\treturn \"application/octet-stream\";\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n\nexport function wsBinaryTypeForEncoding(\n\tencoding: Encoding,\n): \"arraybuffer\" | \"blob\" {\n\tif (encoding === \"json\") {\n\t\treturn \"blob\";\n\t} else if (encoding === \"cbor\" || encoding === \"bare\") {\n\t\treturn \"arraybuffer\";\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n\nexport function serializeWithEncoding<T>(\n\tencoding: Encoding,\n\tvalue: T,\n\tversionedDataHandler: VersionedDataHandler<T> | undefined,\n): Uint8Array | string {\n\tif (encoding === \"json\") {\n\t\treturn jsonStringifyCompat(value);\n\t} else if (encoding === \"cbor\") {\n\t\treturn cbor.encode(value);\n\t} else if (encoding === \"bare\") {\n\t\tif (!versionedDataHandler) {\n\t\t\tthrow new Error(\"VersionedDataHandler is required for 'bare' encoding\");\n\t\t}\n\t\treturn versionedDataHandler.serializeWithEmbeddedVersion(value);\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n\nexport function deserializeWithEncoding<T>(\n\tencoding: Encoding,\n\tbuffer: Uint8Array | string,\n\tversionedDataHandler: VersionedDataHandler<T> | undefined,\n): T {\n\tif (encoding === \"json\") {\n\t\tif (typeof buffer === \"string\") {\n\t\t\treturn JSON.parse(buffer);\n\t\t} else {\n\t\t\tconst decoder = new TextDecoder(\"utf-8\");\n\t\t\tconst jsonString = decoder.decode(buffer);\n\t\t\treturn JSON.parse(jsonString);\n\t\t}\n\t} else if (encoding === \"cbor\") {\n\t\tinvariant(\n\t\t\ttypeof buffer !== \"string\",\n\t\t\t\"buffer cannot be string for cbor encoding\",\n\t\t);\n\t\treturn cbor.decode(buffer);\n\t} else if (encoding === \"bare\") {\n\t\tinvariant(\n\t\t\ttypeof buffer !== \"string\",\n\t\t\t\"buffer cannot be string for bare encoding\",\n\t\t);\n\t\tif (!versionedDataHandler) {\n\t\t\tthrow new Error(\"VersionedDataHandler is required for 'bare' encoding\");\n\t\t}\n\t\treturn versionedDataHandler.deserializeWithEmbeddedVersion(buffer);\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n","import * as cbor from \"cbor-x\";\nimport { z } from \"zod\";\nimport * as errors from \"@/actor/errors\";\nimport type { VersionedDataHandler } from \"@/common/versioned-data\";\nimport { serializeWithEncoding } from \"@/serde\";\nimport { loggerWithoutContext } from \"../log\";\nimport { assertUnreachable } from \"../utils\";\n\n/** Data that can be deserialized. */\nexport type InputData = string | Buffer | Blob | ArrayBufferLike | Uint8Array;\n\n/** Data that's been serialized. */\nexport type OutputData = string | Uint8Array;\n\nexport const EncodingSchema = z.enum([\"json\", \"cbor\", \"bare\"]);\n\n/**\n * Encoding used to communicate between the client & actor.\n */\nexport type Encoding = z.infer<typeof EncodingSchema>;\n\n/**\n * Helper class that helps serialize data without re-serializing for the same encoding.\n */\nexport class CachedSerializer<T> {\n\t#data: T;\n\t#cache = new Map<Encoding, OutputData>();\n\t#versionedDataHandler: VersionedDataHandler<T>;\n\n\tconstructor(data: T, versionedDataHandler: VersionedDataHandler<T>) {\n\t\tthis.#data = data;\n\t\tthis.#versionedDataHandler = versionedDataHandler;\n\t}\n\n\tpublic get rawData(): T {\n\t\treturn this.#data;\n\t}\n\n\tpublic serialize(encoding: Encoding): OutputData {\n\t\tconst cached = this.#cache.get(encoding);\n\t\tif (cached) {\n\t\t\treturn cached;\n\t\t} else {\n\t\t\tconst serialized = serializeWithEncoding(\n\t\t\t\tencoding,\n\t\t\t\tthis.#data,\n\t\t\t\tthis.#versionedDataHandler,\n\t\t\t);\n\t\t\tthis.#cache.set(encoding, serialized);\n\t\t\treturn serialized;\n\t\t}\n\t}\n}\n\n///**\n// * Use `CachedSerializer` if serializing the same data repeatedly.\n// */\n//export function serialize<T>(value: T, encoding: Encoding): OutputData {\n//\tif (encoding === \"json\") {\n//\t\treturn JSON.stringify(value);\n//\t} else if (encoding === \"cbor\") {\n//\t\t// TODO: Remove this hack, but cbor-x can't handle anything extra in data structures\n//\t\tconst cleanValue = JSON.parse(JSON.stringify(value));\n//\t\treturn cbor.encode(cleanValue);\n//\t} else {\n//\t\tassertUnreachable(encoding);\n//\t}\n//}\n//\n//export async function deserialize(data: InputData, encoding: Encoding) {\n//\tif (encoding === \"json\") {\n//\t\tif (typeof data !== \"string\") {\n//\t\t\tlogger().warn(\"received non-string for json parse\");\n//\t\t\tthrow new errors.MalformedMessage();\n//\t\t} else {\n//\t\t\treturn JSON.parse(data);\n//\t\t}\n//\t} else if (encoding === \"cbor\") {\n//\t\tif (data instanceof Blob) {\n//\t\t\tconst arrayBuffer = await data.arrayBuffer();\n//\t\t\treturn cbor.decode(new Uint8Array(arrayBuffer));\n//\t\t} else if (data instanceof Uint8Array) {\n//\t\t\treturn cbor.decode(data);\n//\t\t} else if (\n//\t\t\tdata instanceof ArrayBuffer ||\n//\t\t\tdata instanceof SharedArrayBuffer\n//\t\t) {\n//\t\t\treturn cbor.decode(new Uint8Array(data));\n//\t\t} else {\n//\t\t\tlogger().warn(\"received non-binary type for cbor parse\");\n//\t\t\tthrow new errors.MalformedMessage();\n//\t\t}\n//\t} else {\n//\t\tassertUnreachable(encoding);\n//\t}\n//}\n\n// TODO: Encode base 128\nfunction base64EncodeUint8Array(uint8Array: Uint8Array): string {\n\tlet binary = \"\";\n\tconst len = uint8Array.byteLength;\n\tfor (let i = 0; i < len; i++) {\n\t\tbinary += String.fromCharCode(uint8Array[i]);\n\t}\n\treturn btoa(binary);\n}\n\nfunction base64EncodeArrayBuffer(arrayBuffer: ArrayBuffer): string {\n\tconst uint8Array = new Uint8Array(arrayBuffer);\n\treturn base64EncodeUint8Array(uint8Array);\n}\n\n/** Converts data that was encoded to a string. Some formats (like SSE) don't support raw binary data. */\nexport function encodeDataToString(message: OutputData): string {\n\tif (typeof message === \"string\") {\n\t\treturn message;\n\t} else if (message instanceof ArrayBuffer) {\n\t\treturn base64EncodeArrayBuffer(message);\n\t} else if (message instanceof Uint8Array) {\n\t\treturn base64EncodeUint8Array(message);\n\t} else {\n\t\tassertUnreachable(message);\n\t}\n}\n\n/** Stringifies with compat for values that BARE & CBOR supports. */\nexport function jsonStringifyCompat(input: any): string {\n\treturn JSON.stringify(input, (_key, value) =>\n\t\ttypeof value === \"bigint\" ? value.toString() : value,\n\t);\n}\n","import { getLogger } from \"@/common/log\";\n\n/** Prever to use ActorInstance.rlog child logger. This does not provide context in the log, should only be used as a last resort if you cannot pass the actor's child logger. */\nexport function loggerWithoutContext() {\n\treturn getLogger(\"actor-runtime\");\n}\n","import * as errors from \"./errors\";\nimport { loggerWithoutContext } from \"./log\";\n\nexport function assertUnreachable(x: never): never {\n\tloggerWithoutContext().error({\n\t\tmsg: \"unreachable\",\n\t\tvalue: `${x}`,\n\t\tstack: new Error().stack,\n\t});\n\tthrow new errors.Unreachable(x);\n}\n\nexport const throttle = <\n\t// biome-ignore lint/suspicious/noExplicitAny: we want to allow any function\n\tFn extends (...args: any) => any,\n>(\n\tfn: Fn,\n\tdelay: number,\n) => {\n\tlet lastRan = false;\n\tlet lastArgs: Parameters<Fn> | null = null;\n\n\treturn (...args: Parameters<Fn>) => {\n\t\tif (!lastRan) {\n\t\t\tfn.apply(this, args);\n\t\t\tlastRan = true;\n\t\t\tconst timer = () =>\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tlastRan = false;\n\t\t\t\t\tif (lastArgs) {\n\t\t\t\t\t\tfn.apply(this, lastArgs);\n\t\t\t\t\t\tlastRan = true;\n\t\t\t\t\t\tlastArgs = null;\n\t\t\t\t\t\ttimer();\n\t\t\t\t\t}\n\t\t\t\t}, delay);\n\t\t\ttimer();\n\t\t} else lastArgs = args;\n\t};\n};\n\nexport class DeadlineError extends Error {\n\tconstructor() {\n\t\tsuper(\"Promise did not complete before deadline.\");\n\t}\n}\n\nexport function deadline<T>(promise: Promise<T>, timeout: number): Promise<T> {\n\tconst controller = new AbortController();\n\tconst signal = controller.signal;\n\n\t// Set a timeout to abort the operation\n\tconst timeoutId = setTimeout(() => controller.abort(), timeout);\n\n\treturn Promise.race<T>([\n\t\tpromise,\n\t\tnew Promise<T>((_, reject) => {\n\t\t\tsignal.addEventListener(\"abort\", () => reject(new DeadlineError()));\n\t\t}),\n\t]).finally(() => {\n\t\tclearTimeout(timeoutId);\n\t});\n}\n\nexport class Lock<T> {\n\tprivate _locked = false;\n\tprivate _waiting: Array<() => void> = [];\n\n\tconstructor(private _value: T) {}\n\n\tasync lock(fn: (value: T) => Promise<void>): Promise<void> {\n\t\tif (this._locked) {\n\t\t\tawait new Promise<void>((resolve) => this._waiting.push(resolve));\n\t\t}\n\t\tthis._locked = true;\n\n\t\ttry {\n\t\t\tawait fn(this._value);\n\t\t} finally {\n\t\t\tthis._locked = false;\n\t\t\tconst next = this._waiting.shift();\n\t\t\tif (next) next();\n\t\t}\n\t}\n}\n\nexport function generateSecureToken(length = 32) {\n\tconst array = new Uint8Array(length);\n\tcrypto.getRandomValues(array);\n\t// Replace base64 chars that are not URL safe with URL-safe chars and strip padding\n\treturn btoa(String.fromCharCode(...array))\n\t\t.replace(/\\+/g, \"-\")\n\t\t.replace(/\\//g, \"_\")\n\t\t.replace(/=/g, \"\");\n}\n\nexport function generateRandomString(length = 32) {\n\tconst characters =\n\t\t\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n\tlet result = \"\";\n\tfor (let i = 0; i < length; i++) {\n\t\tconst randomIndex = Math.floor(Math.random() * characters.length);\n\t\tresult += characters[randomIndex];\n\t}\n\treturn result;\n}\n"]}
@@ -3,11 +3,11 @@ import {
3
3
  ForeignKeysSchema,
4
4
  PatchSchema,
5
5
  TablesSchema
6
- } from "./chunk-GZVBFXBI.js";
6
+ } from "./chunk-54MAHBLL.js";
7
7
  import {
8
8
  importWebSocket,
9
9
  logger
10
- } from "./chunk-E4UVJKSV.js";
10
+ } from "./chunk-B6N6VM37.js";
11
11
  import {
12
12
  HTTP_ACTION_REQUEST_VERSIONED,
13
13
  HTTP_ACTION_RESPONSE_VERSIONED,
@@ -17,7 +17,7 @@ import {
17
17
  TO_SERVER_VERSIONED,
18
18
  inputDataToBuffer,
19
19
  processMessage
20
- } from "./chunk-JD54PXWP.js";
20
+ } from "./chunk-2NL3KGJ7.js";
21
21
  import {
22
22
  CachedSerializer,
23
23
  DeadlineError,
@@ -48,12 +48,12 @@ import {
48
48
  generateSecureToken,
49
49
  jsonStringifyCompat,
50
50
  serializeWithEncoding
51
- } from "./chunk-YQ4XQYPM.js";
51
+ } from "./chunk-NRELKXIX.js";
52
52
  import {
53
53
  getBaseLogger,
54
54
  getIncludeTarget,
55
55
  getLogger
56
- } from "./chunk-PUSQNDJG.js";
56
+ } from "./chunk-YL4VZMMT.js";
57
57
  import {
58
58
  SinglePromiseQueue,
59
59
  assertUnreachable,
@@ -66,7 +66,7 @@ import {
66
66
  noopNext,
67
67
  promiseWithResolvers,
68
68
  stringifyError
69
- } from "./chunk-RVP5RUSC.js";
69
+ } from "./chunk-RLBM6D4L.js";
70
70
  import {
71
71
  ActionNotFound,
72
72
  ActionTimedOut,
@@ -4068,4 +4068,4 @@ export {
4068
4068
  createClientWithDriver,
4069
4069
  RemoteManagerDriver
4070
4070
  };
4071
- //# sourceMappingURL=chunk-BW5DPM6Z.js.map
4071
+ //# sourceMappingURL=chunk-NII4KKHD.js.map
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  getLogger
3
- } from "./chunk-PUSQNDJG.js";
3
+ } from "./chunk-YL4VZMMT.js";
4
4
  import {
5
5
  assertUnreachable
6
- } from "./chunk-RVP5RUSC.js";
6
+ } from "./chunk-RLBM6D4L.js";
7
7
  import {
8
8
  Unreachable
9
9
  } from "./chunk-YPZFLUO6.js";
@@ -256,4 +256,4 @@ export {
256
256
  WS_PROTOCOL_PATH,
257
257
  ALLOWED_PUBLIC_HEADERS
258
258
  };
259
- //# sourceMappingURL=chunk-YQ4XQYPM.js.map
259
+ //# sourceMappingURL=chunk-NRELKXIX.js.map