rivetkit 2.0.38 → 2.0.40

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 (99) hide show
  1. package/dist/tsup/{chunk-IWXMFQDT.cjs → chunk-4KNL47JA.cjs} +274 -80
  2. package/dist/tsup/chunk-4KNL47JA.cjs.map +1 -0
  3. package/dist/tsup/{chunk-UUEZVDRL.js → chunk-4T4UWXHN.js} +8 -4
  4. package/dist/tsup/{chunk-UUEZVDRL.js.map → chunk-4T4UWXHN.js.map} +1 -1
  5. package/dist/tsup/{chunk-LULP6HM2.cjs → chunk-6NBNCWEC.cjs} +313 -289
  6. package/dist/tsup/chunk-6NBNCWEC.cjs.map +1 -0
  7. package/dist/tsup/{chunk-WIZ4JGP6.js → chunk-7Q7R3QYT.js} +2 -2
  8. package/dist/tsup/{chunk-6WLJW57U.cjs → chunk-B5BMSBR4.cjs} +230 -128
  9. package/dist/tsup/chunk-B5BMSBR4.cjs.map +1 -0
  10. package/dist/tsup/{chunk-FZQHTGQX.cjs → chunk-D2HB4PM5.cjs} +9 -9
  11. package/dist/tsup/{chunk-FZQHTGQX.cjs.map → chunk-D2HB4PM5.cjs.map} +1 -1
  12. package/dist/tsup/{chunk-IRTVRBJA.cjs → chunk-FB4TVPDQ.cjs} +50 -46
  13. package/dist/tsup/chunk-FB4TVPDQ.cjs.map +1 -0
  14. package/dist/tsup/{chunk-O433HWWG.cjs → chunk-HZOBB3KP.cjs} +2 -2
  15. package/dist/tsup/{chunk-O433HWWG.cjs.map → chunk-HZOBB3KP.cjs.map} +1 -1
  16. package/dist/tsup/{chunk-K2RNF2ZR.js → chunk-J2R742IE.js} +5 -5
  17. package/dist/tsup/{chunk-FA6FGAEC.js → chunk-J6YRLC6K.js} +143 -41
  18. package/dist/tsup/chunk-J6YRLC6K.js.map +1 -0
  19. package/dist/tsup/{chunk-MIOU6BF3.js → chunk-KVB2SG32.js} +219 -25
  20. package/dist/tsup/chunk-KVB2SG32.js.map +1 -0
  21. package/dist/tsup/{chunk-GFKZZG2A.cjs → chunk-XCDGPOZT.cjs} +3 -3
  22. package/dist/tsup/{chunk-GFKZZG2A.cjs.map → chunk-XCDGPOZT.cjs.map} +1 -1
  23. package/dist/tsup/{chunk-EEL32AJM.js → chunk-XCRJ245S.js} +74 -50
  24. package/dist/tsup/chunk-XCRJ245S.js.map +1 -0
  25. package/dist/tsup/{chunk-4U45T5KW.js → chunk-ZUMPCWKF.js} +2 -2
  26. package/dist/tsup/{chunk-4U45T5KW.js.map → chunk-ZUMPCWKF.js.map} +1 -1
  27. package/dist/tsup/client/mod.cjs +5 -5
  28. package/dist/tsup/client/mod.d.cts +3 -3
  29. package/dist/tsup/client/mod.d.ts +3 -3
  30. package/dist/tsup/client/mod.js +4 -4
  31. package/dist/tsup/common/log.cjs +2 -2
  32. package/dist/tsup/common/log.js +1 -1
  33. package/dist/tsup/common/websocket.cjs +3 -3
  34. package/dist/tsup/common/websocket.js +2 -2
  35. package/dist/tsup/{config-CbIHPGKl.d.ts → config-OR5ZtHFa.d.ts} +75 -5
  36. package/dist/tsup/{config-CwJCQyP1.d.cts → config-cizn-tcF.d.cts} +75 -5
  37. package/dist/tsup/{driver-Lw_oORox.d.cts → driver-Bg4evbcN.d.cts} +1 -1
  38. package/dist/tsup/{driver-CMN823Lc.d.ts → driver-BrAG8ioa.d.ts} +1 -1
  39. package/dist/tsup/driver-helpers/mod.cjs +3 -3
  40. package/dist/tsup/driver-helpers/mod.d.cts +2 -2
  41. package/dist/tsup/driver-helpers/mod.d.ts +2 -2
  42. package/dist/tsup/driver-helpers/mod.js +2 -2
  43. package/dist/tsup/driver-test-suite/mod.cjs +109 -35
  44. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  45. package/dist/tsup/driver-test-suite/mod.d.cts +2 -2
  46. package/dist/tsup/driver-test-suite/mod.d.ts +2 -2
  47. package/dist/tsup/driver-test-suite/mod.js +435 -361
  48. package/dist/tsup/driver-test-suite/mod.js.map +1 -1
  49. package/dist/tsup/{kv-CTM8sCvx.d.cts → keys-Chhy4ylv.d.cts} +1 -0
  50. package/dist/tsup/{kv-CTM8sCvx.d.ts → keys-Chhy4ylv.d.ts} +1 -0
  51. package/dist/tsup/mod.cjs +9 -7
  52. package/dist/tsup/mod.cjs.map +1 -1
  53. package/dist/tsup/mod.d.cts +5 -5
  54. package/dist/tsup/mod.d.ts +5 -5
  55. package/dist/tsup/mod.js +8 -6
  56. package/dist/tsup/test/mod.cjs +7 -7
  57. package/dist/tsup/test/mod.d.cts +1 -1
  58. package/dist/tsup/test/mod.d.ts +1 -1
  59. package/dist/tsup/test/mod.js +6 -6
  60. package/dist/tsup/utils.cjs +2 -2
  61. package/dist/tsup/utils.js +1 -1
  62. package/package.json +2 -2
  63. package/src/actor/config.ts +183 -34
  64. package/src/actor/contexts/base/actor.ts +12 -0
  65. package/src/actor/instance/connection-manager.ts +1 -1
  66. package/src/actor/instance/keys.ts +29 -0
  67. package/src/actor/instance/kv.ts +240 -14
  68. package/src/actor/instance/mod.ts +5 -4
  69. package/src/actor/instance/schedule-manager.ts +2 -1
  70. package/src/actor/instance/state-manager.ts +1 -1
  71. package/src/actor/mod.ts +2 -1
  72. package/src/actor/router-websocket-endpoints.test.ts +54 -0
  73. package/src/actor/router-websocket-endpoints.ts +11 -5
  74. package/src/client/actor-handle.ts +13 -3
  75. package/src/client/mod.ts +1 -1
  76. package/src/driver-helpers/utils.ts +1 -1
  77. package/src/driver-test-suite/mod.ts +3 -0
  78. package/src/driver-test-suite/test-inline-client-driver.ts +3 -0
  79. package/src/driver-test-suite/tests/actor-kv.ts +44 -0
  80. package/src/driver-test-suite/tests/raw-websocket.ts +40 -0
  81. package/src/driver-test-suite/utils.ts +4 -0
  82. package/src/drivers/engine/actor-driver.ts +3 -3
  83. package/src/drivers/file-system/manager.ts +5 -0
  84. package/src/engine-process/mod.ts +62 -7
  85. package/src/manager/driver.ts +7 -0
  86. package/src/registry/config/index.ts +6 -0
  87. package/src/registry/serve.ts +9 -5
  88. package/src/remote-manager-driver/actor-http-client.ts +5 -3
  89. package/src/remote-manager-driver/actor-websocket-client.ts +18 -7
  90. package/src/remote-manager-driver/mod.ts +10 -0
  91. package/dist/tsup/chunk-6WLJW57U.cjs.map +0 -1
  92. package/dist/tsup/chunk-EEL32AJM.js.map +0 -1
  93. package/dist/tsup/chunk-FA6FGAEC.js.map +0 -1
  94. package/dist/tsup/chunk-IRTVRBJA.cjs.map +0 -1
  95. package/dist/tsup/chunk-IWXMFQDT.cjs.map +0 -1
  96. package/dist/tsup/chunk-LULP6HM2.cjs.map +0 -1
  97. package/dist/tsup/chunk-MIOU6BF3.js.map +0 -1
  98. /package/dist/tsup/{chunk-WIZ4JGP6.js.map → chunk-7Q7R3QYT.js.map} +0 -0
  99. /package/dist/tsup/{chunk-K2RNF2ZR.js.map → chunk-J2R742IE.js.map} +0 -0
@@ -31,7 +31,7 @@ import {
31
31
  noopNext,
32
32
  promiseWithResolvers,
33
33
  stringifyError
34
- } from "./chunk-4U45T5KW.js";
34
+ } from "./chunk-ZUMPCWKF.js";
35
35
  import {
36
36
  ConnStateNotEnabled,
37
37
  Forbidden,
@@ -152,12 +152,215 @@ import * as cbor3 from "cbor-x";
152
152
  // src/actor/router-endpoints.ts
153
153
  import * as cbor2 from "cbor-x";
154
154
 
155
+ // src/actor/instance/keys.ts
156
+ var KEYS = {
157
+ PERSIST_DATA: Uint8Array.from([1]),
158
+ CONN_PREFIX: Uint8Array.from([2]),
159
+ // Prefix for connection keys
160
+ INSPECTOR_TOKEN: Uint8Array.from([3]),
161
+ // Inspector token key
162
+ KV: Uint8Array.from([4])
163
+ // Prefix for user-facing KV storage
164
+ };
165
+ function makePrefixedKey(key) {
166
+ const prefixed = new Uint8Array(KEYS.KV.length + key.length);
167
+ prefixed.set(KEYS.KV, 0);
168
+ prefixed.set(key, KEYS.KV.length);
169
+ return prefixed;
170
+ }
171
+ function removePrefixFromKey(prefixedKey) {
172
+ return prefixedKey.slice(KEYS.KV.length);
173
+ }
174
+ function makeConnKey(connId) {
175
+ const encoder = new TextEncoder();
176
+ const connIdBytes = encoder.encode(connId);
177
+ const key = new Uint8Array(KEYS.CONN_PREFIX.length + connIdBytes.length);
178
+ key.set(KEYS.CONN_PREFIX, 0);
179
+ key.set(connIdBytes, KEYS.CONN_PREFIX.length);
180
+ return key;
181
+ }
182
+
183
+ // src/actor/instance/kv.ts
184
+ var textEncoder = new TextEncoder();
185
+ var textDecoder = new TextDecoder();
186
+ function encodeKey(key, keyType) {
187
+ if (key instanceof Uint8Array) {
188
+ return key;
189
+ }
190
+ const resolvedKeyType = keyType ?? "text";
191
+ if (resolvedKeyType === "binary") {
192
+ throw new TypeError("Expected a Uint8Array when keyType is binary");
193
+ }
194
+ return textEncoder.encode(key);
195
+ }
196
+ function decodeKey(key, keyType) {
197
+ const resolvedKeyType = keyType ?? "text";
198
+ switch (resolvedKeyType) {
199
+ case "text":
200
+ return textDecoder.decode(key);
201
+ case "binary":
202
+ return key;
203
+ default:
204
+ throw new TypeError("Invalid kv key type");
205
+ }
206
+ }
207
+ function resolveValueType(value) {
208
+ if (typeof value === "string") {
209
+ return "text";
210
+ }
211
+ if (value instanceof Uint8Array) {
212
+ return "binary";
213
+ }
214
+ if (value instanceof ArrayBuffer) {
215
+ return "arrayBuffer";
216
+ }
217
+ throw new TypeError("Invalid kv value");
218
+ }
219
+ function encodeValue(value, options) {
220
+ const type = (options == null ? void 0 : options.type) ?? resolveValueType(value);
221
+ switch (type) {
222
+ case "text":
223
+ if (typeof value !== "string") {
224
+ throw new TypeError("Expected a string when type is text");
225
+ }
226
+ return textEncoder.encode(value);
227
+ case "arrayBuffer":
228
+ if (!(value instanceof ArrayBuffer)) {
229
+ throw new TypeError("Expected an ArrayBuffer when type is arrayBuffer");
230
+ }
231
+ return new Uint8Array(value);
232
+ case "binary":
233
+ if (!(value instanceof Uint8Array)) {
234
+ throw new TypeError("Expected a Uint8Array when type is binary");
235
+ }
236
+ return value;
237
+ default:
238
+ throw new TypeError("Invalid kv value type");
239
+ }
240
+ }
241
+ function decodeValue(value, options) {
242
+ const type = (options == null ? void 0 : options.type) ?? "text";
243
+ switch (type) {
244
+ case "text":
245
+ return textDecoder.decode(value);
246
+ case "arrayBuffer": {
247
+ const copy = new Uint8Array(value.byteLength);
248
+ copy.set(value);
249
+ return copy.buffer;
250
+ }
251
+ case "binary":
252
+ return value;
253
+ default:
254
+ throw new TypeError("Invalid kv value type");
255
+ }
256
+ }
257
+ var ActorKv = class {
258
+ #driver;
259
+ #actorId;
260
+ constructor(driver, actorId) {
261
+ this.#driver = driver;
262
+ this.#actorId = actorId;
263
+ }
264
+ /**
265
+ * Get a single value by key.
266
+ */
267
+ async get(key, options) {
268
+ const results = await this.#driver.kvBatchGet(this.#actorId, [
269
+ makePrefixedKey(encodeKey(key))
270
+ ]);
271
+ const result = results[0];
272
+ if (!result) {
273
+ return null;
274
+ }
275
+ return decodeValue(result, options);
276
+ }
277
+ /**
278
+ * Get multiple values by keys.
279
+ */
280
+ async getBatch(keys, options) {
281
+ const prefixedKeys = keys.map(
282
+ (key) => makePrefixedKey(encodeKey(key))
283
+ );
284
+ const results = await this.#driver.kvBatchGet(
285
+ this.#actorId,
286
+ prefixedKeys
287
+ );
288
+ return results.map(
289
+ (result) => result ? decodeValue(result, options) : null
290
+ );
291
+ }
292
+ /**
293
+ * Put a single key-value pair.
294
+ */
295
+ async put(key, value, options) {
296
+ await this.#driver.kvBatchPut(this.#actorId, [
297
+ [makePrefixedKey(encodeKey(key)), encodeValue(value, options)]
298
+ ]);
299
+ }
300
+ /**
301
+ * Put multiple key-value pairs.
302
+ */
303
+ async putBatch(entries, options) {
304
+ const prefixedEntries = entries.map(
305
+ ([key, value]) => [
306
+ makePrefixedKey(encodeKey(key)),
307
+ encodeValue(value, options)
308
+ ]
309
+ );
310
+ await this.#driver.kvBatchPut(this.#actorId, prefixedEntries);
311
+ }
312
+ /**
313
+ * Delete a single key.
314
+ */
315
+ async delete(key) {
316
+ await this.#driver.kvBatchDelete(this.#actorId, [
317
+ makePrefixedKey(encodeKey(key))
318
+ ]);
319
+ }
320
+ /**
321
+ * Delete multiple keys.
322
+ */
323
+ async deleteBatch(keys) {
324
+ const prefixedKeys = keys.map(
325
+ (key) => makePrefixedKey(encodeKey(key))
326
+ );
327
+ await this.#driver.kvBatchDelete(this.#actorId, prefixedKeys);
328
+ }
329
+ /**
330
+ * List all keys with a given prefix.
331
+ * Returns key-value pairs where keys have the user prefix removed.
332
+ */
333
+ async list(prefix, options) {
334
+ const prefixedPrefix = makePrefixedKey(
335
+ encodeKey(prefix, options == null ? void 0 : options.keyType)
336
+ );
337
+ const results = await this.#driver.kvListPrefix(
338
+ this.#actorId,
339
+ prefixedPrefix
340
+ );
341
+ return results.map(([key, value]) => [
342
+ decodeKey(removePrefixFromKey(key), options == null ? void 0 : options.keyType),
343
+ decodeValue(value, options)
344
+ ]);
345
+ }
346
+ };
347
+
155
348
  // src/actor/contexts/base/actor.ts
156
349
  var ActorContext = class {
157
350
  #actor;
351
+ #kv;
158
352
  constructor(actor) {
159
353
  this.#actor = actor;
160
354
  }
355
+ /**
356
+ * Gets the KV storage interface.
357
+ */
358
+ get kv() {
359
+ if (!this.#kv) {
360
+ this.#kv = new ActorKv(this.#actor.driver, this.#actor.id);
361
+ }
362
+ return this.#kv;
363
+ }
161
364
  /**
162
365
  * Get the actor state
163
366
  *
@@ -1902,6 +2105,12 @@ var RegistryConfigSchema = z7.object({
1902
2105
  * What port to run the manager on.
1903
2106
  */
1904
2107
  managerPort: z7.number().optional().default(6420),
2108
+ /**
2109
+ * @experimental
2110
+ *
2111
+ * What host to bind the manager server to.
2112
+ */
2113
+ managerHost: z7.string().optional(),
1905
2114
  /** @experimental */
1906
2115
  inspector: InspectorConfigSchema,
1907
2116
  // MARK: Runtime-specific
@@ -3132,9 +3341,10 @@ async function routeWebSocket(request, requestPath, requestHeaders, config6, act
3132
3341
  isHibernatable
3133
3342
  });
3134
3343
  const closePromiseResolvers = promiseWithResolvers();
3344
+ const requestPathWithoutQuery = requestPath.split("?")[0];
3135
3345
  let handler;
3136
3346
  let connDriver;
3137
- if (requestPath === PATH_CONNECT) {
3347
+ if (requestPathWithoutQuery === PATH_CONNECT) {
3138
3348
  const { driver, setWebSocket } = createWebSocketDriver(
3139
3349
  isHibernatable ? { gatewayId, requestId } : void 0,
3140
3350
  encoding,
@@ -3143,14 +3353,14 @@ async function routeWebSocket(request, requestPath, requestHeaders, config6, act
3143
3353
  );
3144
3354
  handler = handleWebSocketConnect.bind(void 0, setWebSocket);
3145
3355
  connDriver = driver;
3146
- } else if (requestPath === PATH_WEBSOCKET_BASE || requestPath.startsWith(PATH_WEBSOCKET_PREFIX)) {
3356
+ } else if (requestPathWithoutQuery === PATH_WEBSOCKET_BASE || requestPathWithoutQuery.startsWith(PATH_WEBSOCKET_PREFIX)) {
3147
3357
  const { driver, setWebSocket } = createRawWebSocketDriver(
3148
3358
  isHibernatable ? { gatewayId, requestId } : void 0,
3149
3359
  closePromiseResolvers.promise
3150
3360
  );
3151
3361
  handler = handleRawWebSocket.bind(void 0, setWebSocket);
3152
3362
  connDriver = driver;
3153
- } else if (requestPath === PATH_INSPECTOR_CONNECT) {
3363
+ } else if (requestPathWithoutQuery === PATH_INSPECTOR_CONNECT) {
3154
3364
  if (!actor.inspectorToken) {
3155
3365
  throw "WebSocket Inspector Unauthorized: actor does not provide inspector access";
3156
3366
  }
@@ -3338,7 +3548,7 @@ function parseWebSocketProtocols(protocols) {
3338
3548
  }
3339
3549
  }
3340
3550
  }
3341
- const encoding = EncodingSchema.parse(encodingRaw);
3551
+ const encoding = EncodingSchema.parse(encodingRaw ?? "json");
3342
3552
  const connParams = connParamsRaw ? JSON.parse(connParamsRaw) : void 0;
3343
3553
  return { encoding, connParams };
3344
3554
  }
@@ -4200,23 +4410,6 @@ function createApiActor(actor) {
4200
4410
  // src/driver-helpers/utils.ts
4201
4411
  import * as cbor7 from "cbor-x";
4202
4412
 
4203
- // src/actor/instance/kv.ts
4204
- var KEYS = {
4205
- PERSIST_DATA: Uint8Array.from([1]),
4206
- CONN_PREFIX: Uint8Array.from([2]),
4207
- // Prefix for connection keys
4208
- INSPECTOR_TOKEN: Uint8Array.from([3])
4209
- // Inspector token key
4210
- };
4211
- function makeConnKey(connId) {
4212
- const encoder = new TextEncoder();
4213
- const connIdBytes = encoder.encode(connId);
4214
- const key = new Uint8Array(KEYS.CONN_PREFIX.length + connIdBytes.length);
4215
- key.set(KEYS.CONN_PREFIX, 0);
4216
- key.set(connIdBytes, KEYS.CONN_PREFIX.length);
4217
- return key;
4218
- }
4219
-
4220
4413
  // src/schemas/actor-persist/versioned.ts
4221
4414
  import { createVersionedDataHandler as createVersionedDataHandler2 } from "vbare";
4222
4415
 
@@ -4936,6 +5129,9 @@ export {
4936
5129
  CONN_STATE_MANAGER_SYMBOL,
4937
5130
  CONN_SEND_MESSAGE_SYMBOL,
4938
5131
  Conn,
5132
+ KEYS,
5133
+ makeConnKey,
5134
+ ActorKv,
4939
5135
  ActorContext,
4940
5136
  ActionContext,
4941
5137
  CURRENT_VERSION2,
@@ -4951,8 +5147,6 @@ export {
4951
5147
  getValueLength,
4952
5148
  inputDataToBuffer,
4953
5149
  processMessage,
4954
- KEYS,
4955
- makeConnKey,
4956
5150
  PATH_CONNECT,
4957
5151
  PATH_WEBSOCKET_BASE,
4958
5152
  PATH_WEBSOCKET_PREFIX,
@@ -4999,4 +5193,4 @@ export {
4999
5193
  buildManagerRouter,
5000
5194
  getInitialActorKvState
5001
5195
  };
5002
- //# sourceMappingURL=chunk-MIOU6BF3.js.map
5196
+ //# sourceMappingURL=chunk-KVB2SG32.js.map