@rivetkit/supabase 2.3.11-rc.7 → 2.3.11-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mod.js +869 -769
- package/dist/mod.mjs +872 -772
- package/package.json +3 -3
package/dist/mod.mjs
CHANGED
|
@@ -297,6 +297,186 @@ var require_retry2 = __commonJS({
|
|
|
297
297
|
// src/mod.ts
|
|
298
298
|
import * as wasmBindings from "@rivetkit/rivetkit-wasm";
|
|
299
299
|
|
|
300
|
+
// ../rivetkit/dist/tsup/chunk-ZZ3WBRPD.js
|
|
301
|
+
var INTERNAL_ERROR_CODE = "internal_error";
|
|
302
|
+
var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
|
|
303
|
+
var USER_ERROR_CODE = "user_error";
|
|
304
|
+
var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
|
|
305
|
+
function looksLikeRivetErrorOptions(value) {
|
|
306
|
+
return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "statusCode" in value || "actor" in value || "cause" in value);
|
|
307
|
+
}
|
|
308
|
+
function isTypedErrorTag(value) {
|
|
309
|
+
return value === "ActorError" || value === "RivetError";
|
|
310
|
+
}
|
|
311
|
+
function errorMessage(error46, fallback = String(error46)) {
|
|
312
|
+
if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
|
|
313
|
+
return error46.message;
|
|
314
|
+
}
|
|
315
|
+
return fallback;
|
|
316
|
+
}
|
|
317
|
+
function isRivetErrorLike(error46) {
|
|
318
|
+
return typeof error46 === "object" && error46 !== null && "group" in error46 && typeof error46.group === "string" && "code" in error46 && typeof error46.code === "string" && "message" in error46 && typeof error46.message === "string" && (!("__type" in error46) || isTypedErrorTag(error46.__type));
|
|
319
|
+
}
|
|
320
|
+
function isActorAbortedError(error46) {
|
|
321
|
+
return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
|
|
322
|
+
}
|
|
323
|
+
function isActorSpecifier(value) {
|
|
324
|
+
return typeof value === "object" && value !== null && "actorId" in value && typeof value.actorId === "string" && "generation" in value && typeof value.generation === "number" && (!("key" in value) || value.key === void 0 || typeof value.key === "string");
|
|
325
|
+
}
|
|
326
|
+
var RivetError = class extends Error {
|
|
327
|
+
__type = "RivetError";
|
|
328
|
+
public;
|
|
329
|
+
metadata;
|
|
330
|
+
statusCode;
|
|
331
|
+
actor;
|
|
332
|
+
group;
|
|
333
|
+
code;
|
|
334
|
+
static isRivetError(error46) {
|
|
335
|
+
return isRivetErrorLike(error46);
|
|
336
|
+
}
|
|
337
|
+
static isActorError(error46) {
|
|
338
|
+
return isRivetErrorLike(error46);
|
|
339
|
+
}
|
|
340
|
+
constructor(group, code, message, options) {
|
|
341
|
+
const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
|
|
342
|
+
super(message, { cause: normalized.cause });
|
|
343
|
+
this.name = "RivetError";
|
|
344
|
+
this.group = group;
|
|
345
|
+
this.code = code;
|
|
346
|
+
this.public = normalized.public ?? false;
|
|
347
|
+
this.metadata = normalized.metadata;
|
|
348
|
+
this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
|
|
349
|
+
this.actor = normalized.actor;
|
|
350
|
+
}
|
|
351
|
+
toString() {
|
|
352
|
+
return this.message;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
var UserError = class extends RivetError {
|
|
356
|
+
constructor(message, options) {
|
|
357
|
+
super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
|
|
358
|
+
public: true,
|
|
359
|
+
metadata: options == null ? void 0 : options.metadata,
|
|
360
|
+
cause: options == null ? void 0 : options.cause
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
function toRivetError(error46, fallback) {
|
|
365
|
+
if (typeof error46 === "string") {
|
|
366
|
+
const bridged = decodeBridgeRivetError(error46);
|
|
367
|
+
if (bridged) {
|
|
368
|
+
return bridged;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (error46 instanceof Error) {
|
|
372
|
+
const bridged = decodeBridgeRivetError(error46.message);
|
|
373
|
+
if (bridged) {
|
|
374
|
+
return bridged;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (isRivetErrorLike(error46)) {
|
|
378
|
+
return new RivetError(error46.group, error46.code, error46.message, {
|
|
379
|
+
public: error46.public,
|
|
380
|
+
statusCode: error46.statusCode,
|
|
381
|
+
metadata: error46.metadata,
|
|
382
|
+
actor: error46.actor,
|
|
383
|
+
cause: error46 instanceof Error ? error46.cause : void 0
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
return new RivetError(
|
|
387
|
+
(fallback == null ? void 0 : fallback.group) ?? "actor",
|
|
388
|
+
(fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
|
|
389
|
+
errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
|
|
390
|
+
{
|
|
391
|
+
public: fallback == null ? void 0 : fallback.public,
|
|
392
|
+
statusCode: fallback == null ? void 0 : fallback.statusCode,
|
|
393
|
+
metadata: fallback == null ? void 0 : fallback.metadata,
|
|
394
|
+
actor: fallback == null ? void 0 : fallback.actor,
|
|
395
|
+
cause: error46 instanceof Error ? error46 : void 0
|
|
396
|
+
}
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
function encodeBridgeRivetError(error46) {
|
|
400
|
+
return `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({
|
|
401
|
+
group: error46.group,
|
|
402
|
+
code: error46.code,
|
|
403
|
+
message: error46.message,
|
|
404
|
+
metadata: error46.metadata,
|
|
405
|
+
public: error46.public,
|
|
406
|
+
statusCode: error46.statusCode,
|
|
407
|
+
actor: error46.actor
|
|
408
|
+
})}`;
|
|
409
|
+
}
|
|
410
|
+
function decodeBridgeRivetErrorPayload(value) {
|
|
411
|
+
if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
|
|
412
|
+
return void 0;
|
|
413
|
+
}
|
|
414
|
+
try {
|
|
415
|
+
const payload = JSON.parse(
|
|
416
|
+
value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
|
|
417
|
+
);
|
|
418
|
+
if (!isRivetErrorLike(payload)) {
|
|
419
|
+
return void 0;
|
|
420
|
+
}
|
|
421
|
+
if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
|
|
422
|
+
return void 0;
|
|
423
|
+
}
|
|
424
|
+
return payload;
|
|
425
|
+
} catch {
|
|
426
|
+
return void 0;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
function decodeBridgeRivetError(value) {
|
|
430
|
+
const payload = decodeBridgeRivetErrorPayload(value);
|
|
431
|
+
if (!payload) {
|
|
432
|
+
return void 0;
|
|
433
|
+
}
|
|
434
|
+
return new RivetError(payload.group, payload.code, payload.message, {
|
|
435
|
+
metadata: payload.metadata,
|
|
436
|
+
public: payload.public,
|
|
437
|
+
statusCode: payload.statusCode,
|
|
438
|
+
actor: payload.actor ?? void 0
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
function invalidRequest(error46) {
|
|
442
|
+
return new RivetError(
|
|
443
|
+
"request",
|
|
444
|
+
"invalid",
|
|
445
|
+
`Invalid request: ${errorMessage(error46, String(error46))}`,
|
|
446
|
+
{
|
|
447
|
+
public: true,
|
|
448
|
+
cause: error46 instanceof Error ? error46 : void 0
|
|
449
|
+
}
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
function actorNotFound(identifier) {
|
|
453
|
+
return new RivetError(
|
|
454
|
+
"actor",
|
|
455
|
+
"not_found",
|
|
456
|
+
identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
|
|
457
|
+
{ public: true }
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
function forbiddenError() {
|
|
461
|
+
return new RivetError("auth", "forbidden", "Forbidden", {
|
|
462
|
+
public: true,
|
|
463
|
+
statusCode: 403
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
function unsupportedFeature(feature) {
|
|
467
|
+
return new RivetError(
|
|
468
|
+
"feature",
|
|
469
|
+
"unsupported",
|
|
470
|
+
`Unsupported feature: ${feature}`
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// ../rivetkit/dist/tsup/chunk-LZ4TSBIP.js
|
|
475
|
+
import {
|
|
476
|
+
pino,
|
|
477
|
+
stdTimeFunctions
|
|
478
|
+
} from "pino";
|
|
479
|
+
|
|
300
480
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/classic/external.js
|
|
301
481
|
var external_exports = {};
|
|
302
482
|
__export(external_exports, {
|
|
@@ -12967,661 +13147,53 @@ var classic_default = external_exports;
|
|
|
12967
13147
|
// ../../../node_modules/.pnpm/zod@4.1.13/node_modules/zod/v4/index.js
|
|
12968
13148
|
var v4_default = classic_default;
|
|
12969
13149
|
|
|
12970
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
12971
|
-
|
|
12972
|
-
|
|
12973
|
-
|
|
12974
|
-
|
|
12975
|
-
|
|
12976
|
-
|
|
12977
|
-
|
|
12978
|
-
|
|
12979
|
-
|
|
12980
|
-
|
|
12981
|
-
|
|
12982
|
-
|
|
12983
|
-
|
|
12984
|
-
|
|
12985
|
-
|
|
12986
|
-
|
|
12987
|
-
|
|
12988
|
-
|
|
12989
|
-
|
|
12990
|
-
|
|
12991
|
-
|
|
12992
|
-
|
|
12993
|
-
|
|
12994
|
-
|
|
12995
|
-
|
|
13150
|
+
// ../rivetkit/dist/tsup/chunk-LZ4TSBIP.js
|
|
13151
|
+
var import_invariant = __toESM(require_invariant(), 1);
|
|
13152
|
+
import * as cbor from "cbor-x";
|
|
13153
|
+
var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
|
|
13154
|
+
var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
|
|
13155
|
+
var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
|
|
13156
|
+
var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
|
|
13157
|
+
var getRivetPool = () => getEnvUniversal("RIVET_POOL");
|
|
13158
|
+
var getRivetTotalSlots = () => {
|
|
13159
|
+
const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
|
|
13160
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13161
|
+
};
|
|
13162
|
+
var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
13163
|
+
var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
|
|
13164
|
+
var getRivetRunEnginePort = () => {
|
|
13165
|
+
const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
|
|
13166
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13167
|
+
};
|
|
13168
|
+
var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
13169
|
+
var getRivetEnvoyVersion = () => {
|
|
13170
|
+
const value = getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
13171
|
+
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13172
|
+
};
|
|
13173
|
+
var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
|
|
13174
|
+
var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
|
|
13175
|
+
var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
|
|
13176
|
+
var getRivetkitRuntimeMode = () => {
|
|
13177
|
+
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
13178
|
+
if (value === void 0) return "envoy";
|
|
13179
|
+
if (value === "envoy" || value === "serverless") return value;
|
|
13180
|
+
throw new Error(
|
|
13181
|
+
`RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
|
|
13182
|
+
);
|
|
13183
|
+
};
|
|
13184
|
+
var getRivetkitPublicDir = () => {
|
|
13185
|
+
const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
|
|
13186
|
+
return value === void 0 || value === "" ? void 0 : value;
|
|
13187
|
+
};
|
|
13188
|
+
function parsePortEnv(raw) {
|
|
13189
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
13190
|
+
const parsed = Number.parseInt(raw, 10);
|
|
13191
|
+
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
|
|
13192
|
+
throw new Error(
|
|
13193
|
+
`RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
|
|
13194
|
+
);
|
|
12996
13195
|
}
|
|
12997
|
-
return
|
|
12998
|
-
}
|
|
12999
|
-
function collectActionEntries(actions) {
|
|
13000
|
-
const entries = [];
|
|
13001
|
-
const names = /* @__PURE__ */ new Set();
|
|
13002
|
-
visitActionGroup(actions ?? {}, [], entries, names);
|
|
13003
|
-
return entries;
|
|
13004
|
-
}
|
|
13005
|
-
function visitActionGroup(value, path2, entries, names) {
|
|
13006
|
-
if (!isRecord(value)) {
|
|
13007
|
-
throw new TypeError(
|
|
13008
|
-
`${formatActionPath(path2)} must be an action handler or group`
|
|
13009
|
-
);
|
|
13010
|
-
}
|
|
13011
|
-
for (const [segment, child] of Object.entries(value)) {
|
|
13012
|
-
const childPath = [...path2, segment];
|
|
13013
|
-
if (typeof child === "function") {
|
|
13014
|
-
const name = childPath.join(".");
|
|
13015
|
-
if (names.has(name)) {
|
|
13016
|
-
throw new TypeError(
|
|
13017
|
-
`Multiple action definitions flatten to \`${name}\``
|
|
13018
|
-
);
|
|
13019
|
-
}
|
|
13020
|
-
names.add(name);
|
|
13021
|
-
entries.push({
|
|
13022
|
-
name,
|
|
13023
|
-
path: childPath,
|
|
13024
|
-
handler: child
|
|
13025
|
-
});
|
|
13026
|
-
} else {
|
|
13027
|
-
visitActionGroup(child, childPath, entries, names);
|
|
13028
|
-
}
|
|
13029
|
-
}
|
|
13030
|
-
}
|
|
13031
|
-
function lookupNestedSchema(schemas, path2) {
|
|
13032
|
-
let value = schemas;
|
|
13033
|
-
for (const segment of path2) {
|
|
13034
|
-
if (!isRecord(value) || !Object.hasOwn(value, segment)) {
|
|
13035
|
-
return void 0;
|
|
13036
|
-
}
|
|
13037
|
-
value = value[segment];
|
|
13038
|
-
}
|
|
13039
|
-
return value;
|
|
13040
|
-
}
|
|
13041
|
-
function isRecord(value) {
|
|
13042
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
13043
|
-
return false;
|
|
13044
|
-
}
|
|
13045
|
-
const prototype = Object.getPrototypeOf(value);
|
|
13046
|
-
return prototype === Object.prototype || prototype === null;
|
|
13047
|
-
}
|
|
13048
|
-
function formatActionPath(path2) {
|
|
13049
|
-
return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
|
|
13050
|
-
}
|
|
13051
|
-
var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
|
|
13052
|
-
var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
|
|
13053
|
-
"rivetkit.actor_context_internal"
|
|
13054
|
-
);
|
|
13055
|
-
var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
|
|
13056
|
-
var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
|
|
13057
|
-
var zFunction = () => external_exports.custom((val) => typeof val === "function");
|
|
13058
|
-
var zActionTree = external_exports.custom((value) => {
|
|
13059
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
13060
|
-
return false;
|
|
13061
|
-
}
|
|
13062
|
-
const prototype = Object.getPrototypeOf(value);
|
|
13063
|
-
return prototype === Object.prototype || prototype === null;
|
|
13064
|
-
}).superRefine((actions, ctx) => {
|
|
13065
|
-
try {
|
|
13066
|
-
flattenActionHandlers(actions);
|
|
13067
|
-
} catch (error46) {
|
|
13068
|
-
ctx.addIssue({
|
|
13069
|
-
code: "custom",
|
|
13070
|
-
message: error46 instanceof Error ? error46.message : "Invalid action definition"
|
|
13071
|
-
});
|
|
13072
|
-
}
|
|
13073
|
-
});
|
|
13074
|
-
var WorkflowInspectorConfigSchema = external_exports.object({
|
|
13075
|
-
getHistory: zFunction(),
|
|
13076
|
-
onHistoryUpdated: zFunction().optional(),
|
|
13077
|
-
replayFromStep: zFunction().optional()
|
|
13078
|
-
});
|
|
13079
|
-
var RunInspectorConfigSchema = external_exports.object({
|
|
13080
|
-
workflow: WorkflowInspectorConfigSchema.optional()
|
|
13081
|
-
}).optional();
|
|
13082
|
-
var BUILTIN_INSPECTOR_TAB_IDS = [
|
|
13083
|
-
"workflow",
|
|
13084
|
-
"database",
|
|
13085
|
-
"state",
|
|
13086
|
-
"queue",
|
|
13087
|
-
"schedules",
|
|
13088
|
-
"connections",
|
|
13089
|
-
"console"
|
|
13090
|
-
];
|
|
13091
|
-
var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
|
|
13092
|
-
var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
13093
|
-
var CustomInspectorTabEntrySchema = external_exports.object({
|
|
13094
|
-
id: external_exports.string().regex(
|
|
13095
|
-
CUSTOM_INSPECTOR_TAB_ID_RE,
|
|
13096
|
-
"inspector.tabs[].id must contain only letters, digits, underscore, or dash"
|
|
13097
|
-
),
|
|
13098
|
-
label: external_exports.string().min(1),
|
|
13099
|
-
source: external_exports.string().min(1),
|
|
13100
|
-
/**
|
|
13101
|
-
* Optional icon id. The dashboard maps strings to glyphs (see its
|
|
13102
|
-
* icon registry); unknown ids fall back to a generic icon.
|
|
13103
|
-
*/
|
|
13104
|
-
icon: external_exports.string().min(1).optional(),
|
|
13105
|
-
hidden: external_exports.literal(false).optional()
|
|
13106
|
-
}).strict();
|
|
13107
|
-
var HideInspectorTabEntrySchema = external_exports.object({
|
|
13108
|
-
id: BuiltinInspectorTabIdSchema,
|
|
13109
|
-
hidden: external_exports.literal(true)
|
|
13110
|
-
}).strict();
|
|
13111
|
-
var InspectorTabEntrySchema = external_exports.union([
|
|
13112
|
-
CustomInspectorTabEntrySchema,
|
|
13113
|
-
HideInspectorTabEntrySchema
|
|
13114
|
-
]);
|
|
13115
|
-
var ActorInspectorConfigSchema = external_exports.object({
|
|
13116
|
-
tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
|
|
13117
|
-
}).strict().refine(
|
|
13118
|
-
(data) => {
|
|
13119
|
-
const ids = data.tabs.map((t) => t.id);
|
|
13120
|
-
return new Set(ids).size === ids.length;
|
|
13121
|
-
},
|
|
13122
|
-
{ message: "Duplicate id in inspector.tabs", path: ["tabs"] }
|
|
13123
|
-
).refine(
|
|
13124
|
-
(data) => {
|
|
13125
|
-
const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
|
|
13126
|
-
return data.tabs.every(
|
|
13127
|
-
(t) => t.hidden === true || !builtinSet.has(t.id)
|
|
13128
|
-
);
|
|
13129
|
-
},
|
|
13130
|
-
{
|
|
13131
|
-
message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
|
|
13132
|
-
path: ["tabs"]
|
|
13133
|
-
}
|
|
13134
|
-
);
|
|
13135
|
-
var RunConfigSchema = external_exports.object({
|
|
13136
|
-
/** Display name for the actor in the Inspector UI. */
|
|
13137
|
-
name: external_exports.string().optional(),
|
|
13138
|
-
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
13139
|
-
icon: external_exports.string().optional(),
|
|
13140
|
-
/** The run handler function. */
|
|
13141
|
-
run: zFunction(),
|
|
13142
|
-
/** Inspector integration for long-running run handlers. */
|
|
13143
|
-
inspector: RunInspectorConfigSchema.optional()
|
|
13144
|
-
});
|
|
13145
|
-
var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for(
|
|
13146
|
-
"rivetkit.run_function_config"
|
|
13147
|
-
);
|
|
13148
|
-
var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
|
|
13149
|
-
function getRunFunction(run) {
|
|
13150
|
-
if (!run) return void 0;
|
|
13151
|
-
if (typeof run === "function") return run;
|
|
13152
|
-
return run.run;
|
|
13153
|
-
}
|
|
13154
|
-
function getRunMetadata(run) {
|
|
13155
|
-
if (!run) return {};
|
|
13156
|
-
if (typeof run === "function") {
|
|
13157
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13158
|
-
if (!config3) return {};
|
|
13159
|
-
return { name: config3.name, icon: config3.icon };
|
|
13160
|
-
}
|
|
13161
|
-
return { name: run.name, icon: run.icon };
|
|
13162
|
-
}
|
|
13163
|
-
function getRunInspectorConfig(run, actor2) {
|
|
13164
|
-
if (!run) return void 0;
|
|
13165
|
-
if (typeof run === "function") {
|
|
13166
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13167
|
-
return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
|
|
13168
|
-
}
|
|
13169
|
-
return run.inspector;
|
|
13170
|
-
}
|
|
13171
|
-
function disposeRunInspector(run, actorId) {
|
|
13172
|
-
var _a2;
|
|
13173
|
-
if (!run || typeof run !== "function") {
|
|
13174
|
-
return;
|
|
13175
|
-
}
|
|
13176
|
-
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
13177
|
-
(_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
|
|
13178
|
-
}
|
|
13179
|
-
var GlobalActorOptionsBaseSchema = external_exports.object({
|
|
13180
|
-
/** Display name for the actor in the Inspector UI. */
|
|
13181
|
-
name: external_exports.string().optional(),
|
|
13182
|
-
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
13183
|
-
icon: external_exports.string().optional(),
|
|
13184
|
-
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
13185
|
-
enableActorRuntimeSocket: external_exports.boolean().default(false),
|
|
13186
|
-
/**
|
|
13187
|
-
* Can hibernate WebSockets for onWebSocket.
|
|
13188
|
-
*
|
|
13189
|
-
* WebSockets using actions/events are hibernatable by default.
|
|
13190
|
-
*
|
|
13191
|
-
* @experimental
|
|
13192
|
-
**/
|
|
13193
|
-
canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
|
|
13194
|
-
}).strict();
|
|
13195
|
-
var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
|
|
13196
|
-
() => ({})
|
|
13197
|
-
);
|
|
13198
|
-
var InstanceActorOptionsBaseSchema = external_exports.object({
|
|
13199
|
-
createVarsTimeout: external_exports.number().positive().default(5e3),
|
|
13200
|
-
createConnStateTimeout: external_exports.number().positive().default(5e3),
|
|
13201
|
-
onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
|
|
13202
|
-
onConnectTimeout: external_exports.number().positive().default(5e3),
|
|
13203
|
-
onMigrateTimeout: external_exports.number().positive().default(3e4),
|
|
13204
|
-
sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
|
|
13205
|
-
/** @deprecated `onDestroyTimeout` is folded into `sleepGracePeriod`, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0. */
|
|
13206
|
-
onDestroyTimeout: external_exports.number().positive().optional(),
|
|
13207
|
-
/** @deprecated `waitUntilTimeout` is folded into `sleepGracePeriod`, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0. */
|
|
13208
|
-
waitUntilTimeout: external_exports.number().positive().optional(),
|
|
13209
|
-
stateSaveInterval: external_exports.number().positive().default(1e3),
|
|
13210
|
-
actionTimeout: external_exports.number().positive().default(6e4),
|
|
13211
|
-
connectionLivenessTimeout: external_exports.number().positive().default(2500),
|
|
13212
|
-
connectionLivenessInterval: external_exports.number().positive().default(5e3),
|
|
13213
|
-
/** @deprecated Use `c.keepAwake(promise)` to scope keep-awake to a specific operation, or keep `noSleep` for actors that must stay awake indefinitely. Will be removed in 2.2.0. */
|
|
13214
|
-
noSleep: external_exports.boolean().default(false),
|
|
13215
|
-
sleepTimeout: external_exports.number().positive().default(3e4),
|
|
13216
|
-
maxQueueSize: external_exports.number().positive().default(1e3),
|
|
13217
|
-
/** Maximum pending one-shot and recurring schedules. */
|
|
13218
|
-
maxSchedules: external_exports.number().int().nonnegative().default(1e3),
|
|
13219
|
-
maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
|
|
13220
|
-
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
13221
|
-
preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
|
|
13222
|
-
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
13223
|
-
preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
|
|
13224
|
-
}).strict();
|
|
13225
|
-
var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
|
|
13226
|
-
var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
|
|
13227
|
-
InstanceActorOptionsBaseSchema.shape
|
|
13228
|
-
).strict().prefault(() => ({}));
|
|
13229
|
-
var ActorConfigSchema = external_exports.object({
|
|
13230
|
-
onCreate: zFunction().optional(),
|
|
13231
|
-
onDestroy: zFunction().optional(),
|
|
13232
|
-
onMigrate: zFunction().optional(),
|
|
13233
|
-
onWake: zFunction().optional(),
|
|
13234
|
-
onSleep: zFunction().optional(),
|
|
13235
|
-
run: zRunHandler,
|
|
13236
|
-
onStateChange: zFunction().optional(),
|
|
13237
|
-
onBeforeConnect: zFunction().optional(),
|
|
13238
|
-
onConnect: zFunction().optional(),
|
|
13239
|
-
onDisconnect: zFunction().optional(),
|
|
13240
|
-
onBeforeActionResponse: zFunction().optional(),
|
|
13241
|
-
onRequest: zFunction().optional(),
|
|
13242
|
-
onWebSocket: zFunction().optional(),
|
|
13243
|
-
actions: zActionTree.default(() => ({})),
|
|
13244
|
-
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13245
|
-
connParamsSchema: external_exports.any().optional(),
|
|
13246
|
-
events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13247
|
-
queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
13248
|
-
state: external_exports.any().optional(),
|
|
13249
|
-
createState: zFunction().optional(),
|
|
13250
|
-
connState: external_exports.any().optional(),
|
|
13251
|
-
createConnState: zFunction().optional(),
|
|
13252
|
-
vars: external_exports.any().optional(),
|
|
13253
|
-
db: external_exports.any().optional(),
|
|
13254
|
-
createVars: zFunction().optional(),
|
|
13255
|
-
options: ActorOptionsSchema,
|
|
13256
|
-
inspector: ActorInspectorConfigSchema.optional()
|
|
13257
|
-
}).strict().refine(
|
|
13258
|
-
(data) => !(data.state !== void 0 && data.createState !== void 0),
|
|
13259
|
-
{
|
|
13260
|
-
message: "Cannot define both 'state' and 'createState'",
|
|
13261
|
-
path: ["state"]
|
|
13262
|
-
}
|
|
13263
|
-
).refine(
|
|
13264
|
-
(data) => !(data.connState !== void 0 && data.createConnState !== void 0),
|
|
13265
|
-
{
|
|
13266
|
-
message: "Cannot define both 'connState' and 'createConnState'",
|
|
13267
|
-
path: ["connState"]
|
|
13268
|
-
}
|
|
13269
|
-
).refine(
|
|
13270
|
-
(data) => !(data.vars !== void 0 && data.createVars !== void 0),
|
|
13271
|
-
{
|
|
13272
|
-
message: "Cannot define both 'vars' and 'createVars'",
|
|
13273
|
-
path: ["vars"]
|
|
13274
|
-
}
|
|
13275
|
-
);
|
|
13276
|
-
var DocActorOptionsSchema = external_exports.object({
|
|
13277
|
-
name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
|
|
13278
|
-
icon: external_exports.string().optional().describe(
|
|
13279
|
-
"Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
|
|
13280
|
-
),
|
|
13281
|
-
enableActorRuntimeSocket: external_exports.boolean().optional().describe(
|
|
13282
|
-
"Enables the experimental Actor Runtime Socket for this actor. Default: false"
|
|
13283
|
-
),
|
|
13284
|
-
createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
|
|
13285
|
-
createConnStateTimeout: external_exports.number().optional().describe(
|
|
13286
|
-
"Timeout in ms for createConnState handler. Default: 5000"
|
|
13287
|
-
),
|
|
13288
|
-
onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
|
|
13289
|
-
onBeforeConnectTimeout: external_exports.number().optional().describe(
|
|
13290
|
-
"Timeout in ms for onBeforeConnect handler. Default: 5000"
|
|
13291
|
-
),
|
|
13292
|
-
onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
|
|
13293
|
-
sleepGracePeriod: external_exports.number().optional().describe(
|
|
13294
|
-
`Max time in ms for the graceful shutdown window. Covers lifecycle hooks (onSleep, onDestroy), the run handler wait, async raw WebSocket handlers, disconnect callbacks, and final state serialization. Default: ${DEFAULT_SLEEP_GRACE_PERIOD}.`
|
|
13295
|
-
),
|
|
13296
|
-
onDestroyTimeout: external_exports.number().optional().describe(
|
|
13297
|
-
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
13298
|
-
),
|
|
13299
|
-
waitUntilTimeout: external_exports.number().optional().describe(
|
|
13300
|
-
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
13301
|
-
),
|
|
13302
|
-
stateSaveInterval: external_exports.number().optional().describe(
|
|
13303
|
-
"Interval in ms between automatic state saves. Default: 1000"
|
|
13304
|
-
),
|
|
13305
|
-
actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
|
|
13306
|
-
connectionLivenessTimeout: external_exports.number().optional().describe(
|
|
13307
|
-
"Timeout in ms for connection liveness checks. Default: 2500"
|
|
13308
|
-
),
|
|
13309
|
-
connectionLivenessInterval: external_exports.number().optional().describe(
|
|
13310
|
-
"Interval in ms between connection liveness checks. Default: 5000"
|
|
13311
|
-
),
|
|
13312
|
-
noSleep: external_exports.boolean().optional().describe(
|
|
13313
|
-
"Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
|
|
13314
|
-
),
|
|
13315
|
-
sleepTimeout: external_exports.number().optional().describe(
|
|
13316
|
-
"Time in ms of inactivity before the actor sleeps. Default: 30000"
|
|
13317
|
-
),
|
|
13318
|
-
maxQueueSize: external_exports.number().optional().describe(
|
|
13319
|
-
"Maximum number of queue messages before rejecting new messages. Default: 1000"
|
|
13320
|
-
),
|
|
13321
|
-
maxSchedules: external_exports.number().int().nonnegative().optional().describe(
|
|
13322
|
-
"Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
|
|
13323
|
-
),
|
|
13324
|
-
maxQueueMessageSize: external_exports.number().optional().describe(
|
|
13325
|
-
"Maximum size of each queue message in bytes. Default: 65536"
|
|
13326
|
-
),
|
|
13327
|
-
canHibernateWebSocket: external_exports.boolean().optional().describe(
|
|
13328
|
-
"Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
|
|
13329
|
-
)
|
|
13330
|
-
}).describe("Actor options for timeouts and behavior configuration.");
|
|
13331
|
-
var DocActorConfigSchema = external_exports.object({
|
|
13332
|
-
state: external_exports.unknown().optional().describe(
|
|
13333
|
-
"Initial state value for the actor. Cannot be used with createState."
|
|
13334
|
-
),
|
|
13335
|
-
createState: external_exports.unknown().optional().describe(
|
|
13336
|
-
"Function to create initial state. Receives context and input. Cannot be used with state."
|
|
13337
|
-
),
|
|
13338
|
-
connState: external_exports.unknown().optional().describe(
|
|
13339
|
-
"Initial connection state value. Cannot be used with createConnState."
|
|
13340
|
-
),
|
|
13341
|
-
createConnState: external_exports.unknown().optional().describe(
|
|
13342
|
-
"Function to create connection state. Receives context and connection params. The pending connection is not visible in c.conns until this succeeds. Cannot be used with connState."
|
|
13343
|
-
),
|
|
13344
|
-
vars: external_exports.unknown().optional().describe(
|
|
13345
|
-
"Initial ephemeral variables value. Cannot be used with createVars."
|
|
13346
|
-
),
|
|
13347
|
-
createVars: external_exports.unknown().optional().describe(
|
|
13348
|
-
"Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
|
|
13349
|
-
),
|
|
13350
|
-
db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
|
|
13351
|
-
onCreate: external_exports.unknown().optional().describe(
|
|
13352
|
-
"Called when the actor is first initialized. Use to initialize state."
|
|
13353
|
-
),
|
|
13354
|
-
onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
|
|
13355
|
-
onMigrate: external_exports.unknown().optional().describe(
|
|
13356
|
-
"Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
|
|
13357
|
-
),
|
|
13358
|
-
onWake: external_exports.unknown().optional().describe(
|
|
13359
|
-
"Called when the actor wakes up and is ready to receive connections and actions."
|
|
13360
|
-
),
|
|
13361
|
-
onSleep: external_exports.unknown().optional().describe(
|
|
13362
|
-
"Called when the actor is stopping or sleeping. Use to clean up resources."
|
|
13363
|
-
),
|
|
13364
|
-
run: external_exports.unknown().optional().describe(
|
|
13365
|
-
"Called after actor starts. Does not block startup. Use for background tasks like queue processing or tick loops. If it exits, the actor follows the normal idle sleep timeout once idle. If it throws, the actor logs the error and then follows the normal idle sleep timeout once idle."
|
|
13366
|
-
),
|
|
13367
|
-
onStateChange: external_exports.unknown().optional().describe(
|
|
13368
|
-
"Called when the actor's state changes. State changes within this hook won't trigger recursion."
|
|
13369
|
-
),
|
|
13370
|
-
onBeforeConnect: external_exports.unknown().optional().describe(
|
|
13371
|
-
"Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
|
|
13372
|
-
),
|
|
13373
|
-
onConnect: external_exports.unknown().optional().describe(
|
|
13374
|
-
"Called when a client successfully connects. The connection is visible in c.conns before this runs."
|
|
13375
|
-
),
|
|
13376
|
-
onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
|
|
13377
|
-
onBeforeActionResponse: external_exports.unknown().optional().describe(
|
|
13378
|
-
"Called before sending an action response. Use to transform output."
|
|
13379
|
-
),
|
|
13380
|
-
onRequest: external_exports.unknown().optional().describe(
|
|
13381
|
-
"Called for raw HTTP requests to /actors/{name}/http/* endpoints."
|
|
13382
|
-
),
|
|
13383
|
-
onWebSocket: external_exports.unknown().optional().describe(
|
|
13384
|
-
"Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
|
|
13385
|
-
),
|
|
13386
|
-
actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
13387
|
-
"Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
|
|
13388
|
-
),
|
|
13389
|
-
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
13390
|
-
"Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
|
|
13391
|
-
),
|
|
13392
|
-
connParamsSchema: external_exports.unknown().optional().describe(
|
|
13393
|
-
"Optional schema for validating connection params in native runtimes."
|
|
13394
|
-
),
|
|
13395
|
-
events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
|
|
13396
|
-
queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
|
|
13397
|
-
options: DocActorOptionsSchema.optional()
|
|
13398
|
-
}).describe("Actor configuration passed to the actor() function.");
|
|
13399
|
-
|
|
13400
|
-
// ../rivetkit/dist/tsup/chunk-ZZ3WBRPD.js
|
|
13401
|
-
var INTERNAL_ERROR_CODE = "internal_error";
|
|
13402
|
-
var INTERNAL_ERROR_DESCRIPTION = "An internal error occurred";
|
|
13403
|
-
var USER_ERROR_CODE = "user_error";
|
|
13404
|
-
var BRIDGE_RIVET_ERROR_PREFIX = "__RIVET_ERROR_JSON__:";
|
|
13405
|
-
function looksLikeRivetErrorOptions(value) {
|
|
13406
|
-
return typeof value === "object" && value !== null && ("public" in value || "metadata" in value || "statusCode" in value || "actor" in value || "cause" in value);
|
|
13407
|
-
}
|
|
13408
|
-
function isTypedErrorTag(value) {
|
|
13409
|
-
return value === "ActorError" || value === "RivetError";
|
|
13410
|
-
}
|
|
13411
|
-
function errorMessage(error46, fallback = String(error46)) {
|
|
13412
|
-
if (error46 && typeof error46 === "object" && "message" in error46 && typeof error46.message === "string") {
|
|
13413
|
-
return error46.message;
|
|
13414
|
-
}
|
|
13415
|
-
return fallback;
|
|
13416
|
-
}
|
|
13417
|
-
function isRivetErrorLike(error46) {
|
|
13418
|
-
return typeof error46 === "object" && error46 !== null && "group" in error46 && typeof error46.group === "string" && "code" in error46 && typeof error46.code === "string" && "message" in error46 && typeof error46.message === "string" && (!("__type" in error46) || isTypedErrorTag(error46.__type));
|
|
13419
|
-
}
|
|
13420
|
-
function isActorAbortedError(error46) {
|
|
13421
|
-
return isRivetErrorLike(error46) && error46.group === "actor" && error46.code === "aborted";
|
|
13422
|
-
}
|
|
13423
|
-
function isActorSpecifier(value) {
|
|
13424
|
-
return typeof value === "object" && value !== null && "actorId" in value && typeof value.actorId === "string" && "generation" in value && typeof value.generation === "number" && (!("key" in value) || value.key === void 0 || typeof value.key === "string");
|
|
13425
|
-
}
|
|
13426
|
-
var RivetError = class extends Error {
|
|
13427
|
-
__type = "RivetError";
|
|
13428
|
-
public;
|
|
13429
|
-
metadata;
|
|
13430
|
-
statusCode;
|
|
13431
|
-
actor;
|
|
13432
|
-
group;
|
|
13433
|
-
code;
|
|
13434
|
-
static isRivetError(error46) {
|
|
13435
|
-
return isRivetErrorLike(error46);
|
|
13436
|
-
}
|
|
13437
|
-
static isActorError(error46) {
|
|
13438
|
-
return isRivetErrorLike(error46);
|
|
13439
|
-
}
|
|
13440
|
-
constructor(group, code, message, options) {
|
|
13441
|
-
const normalized = looksLikeRivetErrorOptions(options) ? options : { metadata: options };
|
|
13442
|
-
super(message, { cause: normalized.cause });
|
|
13443
|
-
this.name = "RivetError";
|
|
13444
|
-
this.group = group;
|
|
13445
|
-
this.code = code;
|
|
13446
|
-
this.public = normalized.public ?? false;
|
|
13447
|
-
this.metadata = normalized.metadata;
|
|
13448
|
-
this.statusCode = normalized.statusCode ?? (this.public ? 400 : 500);
|
|
13449
|
-
this.actor = normalized.actor;
|
|
13450
|
-
}
|
|
13451
|
-
toString() {
|
|
13452
|
-
return this.message;
|
|
13453
|
-
}
|
|
13454
|
-
};
|
|
13455
|
-
var UserError = class extends RivetError {
|
|
13456
|
-
constructor(message, options) {
|
|
13457
|
-
super("user", (options == null ? void 0 : options.code) ?? USER_ERROR_CODE, message, {
|
|
13458
|
-
public: true,
|
|
13459
|
-
metadata: options == null ? void 0 : options.metadata,
|
|
13460
|
-
cause: options == null ? void 0 : options.cause
|
|
13461
|
-
});
|
|
13462
|
-
}
|
|
13463
|
-
};
|
|
13464
|
-
function toRivetError(error46, fallback) {
|
|
13465
|
-
if (typeof error46 === "string") {
|
|
13466
|
-
const bridged = decodeBridgeRivetError(error46);
|
|
13467
|
-
if (bridged) {
|
|
13468
|
-
return bridged;
|
|
13469
|
-
}
|
|
13470
|
-
}
|
|
13471
|
-
if (error46 instanceof Error) {
|
|
13472
|
-
const bridged = decodeBridgeRivetError(error46.message);
|
|
13473
|
-
if (bridged) {
|
|
13474
|
-
return bridged;
|
|
13475
|
-
}
|
|
13476
|
-
}
|
|
13477
|
-
if (isRivetErrorLike(error46)) {
|
|
13478
|
-
return new RivetError(error46.group, error46.code, error46.message, {
|
|
13479
|
-
public: error46.public,
|
|
13480
|
-
statusCode: error46.statusCode,
|
|
13481
|
-
metadata: error46.metadata,
|
|
13482
|
-
actor: error46.actor,
|
|
13483
|
-
cause: error46 instanceof Error ? error46.cause : void 0
|
|
13484
|
-
});
|
|
13485
|
-
}
|
|
13486
|
-
return new RivetError(
|
|
13487
|
-
(fallback == null ? void 0 : fallback.group) ?? "actor",
|
|
13488
|
-
(fallback == null ? void 0 : fallback.code) ?? INTERNAL_ERROR_CODE,
|
|
13489
|
-
errorMessage(error46, (fallback == null ? void 0 : fallback.message) ?? "Unknown error"),
|
|
13490
|
-
{
|
|
13491
|
-
public: fallback == null ? void 0 : fallback.public,
|
|
13492
|
-
statusCode: fallback == null ? void 0 : fallback.statusCode,
|
|
13493
|
-
metadata: fallback == null ? void 0 : fallback.metadata,
|
|
13494
|
-
actor: fallback == null ? void 0 : fallback.actor,
|
|
13495
|
-
cause: error46 instanceof Error ? error46 : void 0
|
|
13496
|
-
}
|
|
13497
|
-
);
|
|
13498
|
-
}
|
|
13499
|
-
function encodeBridgeRivetError(error46) {
|
|
13500
|
-
return `${BRIDGE_RIVET_ERROR_PREFIX}${JSON.stringify({
|
|
13501
|
-
group: error46.group,
|
|
13502
|
-
code: error46.code,
|
|
13503
|
-
message: error46.message,
|
|
13504
|
-
metadata: error46.metadata,
|
|
13505
|
-
public: error46.public,
|
|
13506
|
-
statusCode: error46.statusCode,
|
|
13507
|
-
actor: error46.actor
|
|
13508
|
-
})}`;
|
|
13509
|
-
}
|
|
13510
|
-
function decodeBridgeRivetErrorPayload(value) {
|
|
13511
|
-
if (!value.startsWith(BRIDGE_RIVET_ERROR_PREFIX)) {
|
|
13512
|
-
return void 0;
|
|
13513
|
-
}
|
|
13514
|
-
try {
|
|
13515
|
-
const payload = JSON.parse(
|
|
13516
|
-
value.slice(BRIDGE_RIVET_ERROR_PREFIX.length)
|
|
13517
|
-
);
|
|
13518
|
-
if (!isRivetErrorLike(payload)) {
|
|
13519
|
-
return void 0;
|
|
13520
|
-
}
|
|
13521
|
-
if (payload.actor !== void 0 && payload.actor !== null && !isActorSpecifier(payload.actor)) {
|
|
13522
|
-
return void 0;
|
|
13523
|
-
}
|
|
13524
|
-
return payload;
|
|
13525
|
-
} catch {
|
|
13526
|
-
return void 0;
|
|
13527
|
-
}
|
|
13528
|
-
}
|
|
13529
|
-
function decodeBridgeRivetError(value) {
|
|
13530
|
-
const payload = decodeBridgeRivetErrorPayload(value);
|
|
13531
|
-
if (!payload) {
|
|
13532
|
-
return void 0;
|
|
13533
|
-
}
|
|
13534
|
-
return new RivetError(payload.group, payload.code, payload.message, {
|
|
13535
|
-
metadata: payload.metadata,
|
|
13536
|
-
public: payload.public,
|
|
13537
|
-
statusCode: payload.statusCode,
|
|
13538
|
-
actor: payload.actor ?? void 0
|
|
13539
|
-
});
|
|
13540
|
-
}
|
|
13541
|
-
function invalidRequest(error46) {
|
|
13542
|
-
return new RivetError(
|
|
13543
|
-
"request",
|
|
13544
|
-
"invalid",
|
|
13545
|
-
`Invalid request: ${errorMessage(error46, String(error46))}`,
|
|
13546
|
-
{
|
|
13547
|
-
public: true,
|
|
13548
|
-
cause: error46 instanceof Error ? error46 : void 0
|
|
13549
|
-
}
|
|
13550
|
-
);
|
|
13551
|
-
}
|
|
13552
|
-
function actorNotFound(identifier) {
|
|
13553
|
-
return new RivetError(
|
|
13554
|
-
"actor",
|
|
13555
|
-
"not_found",
|
|
13556
|
-
identifier ? `Actor not found: ${identifier} (https://www.rivet.dev/docs/clients/javascript)` : "Actor not found (https://www.rivet.dev/docs/clients/javascript)",
|
|
13557
|
-
{ public: true }
|
|
13558
|
-
);
|
|
13559
|
-
}
|
|
13560
|
-
function forbiddenError() {
|
|
13561
|
-
return new RivetError("auth", "forbidden", "Forbidden", {
|
|
13562
|
-
public: true,
|
|
13563
|
-
statusCode: 403
|
|
13564
|
-
});
|
|
13565
|
-
}
|
|
13566
|
-
function unsupportedFeature(feature) {
|
|
13567
|
-
return new RivetError(
|
|
13568
|
-
"feature",
|
|
13569
|
-
"unsupported",
|
|
13570
|
-
`Unsupported feature: ${feature}`
|
|
13571
|
-
);
|
|
13572
|
-
}
|
|
13573
|
-
|
|
13574
|
-
// ../rivetkit/dist/tsup/chunk-XAGDGH4O.js
|
|
13575
|
-
import {
|
|
13576
|
-
pino,
|
|
13577
|
-
stdTimeFunctions
|
|
13578
|
-
} from "pino";
|
|
13579
|
-
var import_invariant = __toESM(require_invariant(), 1);
|
|
13580
|
-
import * as cbor from "cbor-x";
|
|
13581
|
-
var getRivetEngine = () => getEnvUniversal("RIVET_ENGINE");
|
|
13582
|
-
var getRivetEndpoint = () => getEnvUniversal("RIVET_ENDPOINT");
|
|
13583
|
-
var getRivetToken = () => getEnvUniversal("RIVET_TOKEN");
|
|
13584
|
-
var getRivetNamespace = () => getEnvUniversal("RIVET_NAMESPACE");
|
|
13585
|
-
var getRivetPool = () => getEnvUniversal("RIVET_POOL");
|
|
13586
|
-
var getRivetTotalSlots = () => {
|
|
13587
|
-
const value = getEnvUniversal("RIVET_TOTAL_SLOTS");
|
|
13588
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13589
|
-
};
|
|
13590
|
-
var getRivetRunEngine = () => getEnvUniversal("RIVET_RUN_ENGINE") === "1";
|
|
13591
|
-
var getRivetRunEngineHost = () => getEnvUniversal("RIVET_RUN_ENGINE_HOST");
|
|
13592
|
-
var getRivetRunEnginePort = () => {
|
|
13593
|
-
const value = getEnvUniversal("RIVET_RUN_ENGINE_PORT");
|
|
13594
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13595
|
-
};
|
|
13596
|
-
var getRivetRunEngineVersion = () => getEnvUniversal("RIVET_RUN_ENGINE_VERSION");
|
|
13597
|
-
var getRivetEnvoyVersion = () => {
|
|
13598
|
-
const value = getEnvUniversal("RIVET_ENVOY_VERSION");
|
|
13599
|
-
return value !== void 0 ? parseInt(value, 10) : void 0;
|
|
13600
|
-
};
|
|
13601
|
-
var getRivetPublicEndpoint = () => getEnvUniversal("RIVET_PUBLIC_ENDPOINT");
|
|
13602
|
-
var getRivetPublicToken = () => getEnvUniversal("RIVET_PUBLIC_TOKEN");
|
|
13603
|
-
var getRivetkitRuntime = () => getEnvUniversal("RIVETKIT_RUNTIME");
|
|
13604
|
-
var getRivetkitRuntimeMode = () => {
|
|
13605
|
-
const value = getEnvUniversal("RIVETKIT_RUNTIME_MODE");
|
|
13606
|
-
if (value === void 0) return "envoy";
|
|
13607
|
-
if (value === "envoy" || value === "serverless") return value;
|
|
13608
|
-
throw new Error(
|
|
13609
|
-
`RIVETKIT_RUNTIME_MODE env var must be "envoy" or "serverless"; got "${value}"`
|
|
13610
|
-
);
|
|
13611
|
-
};
|
|
13612
|
-
var getRivetkitPublicDir = () => {
|
|
13613
|
-
const value = getEnvUniversal("RIVETKIT_PUBLIC_DIR");
|
|
13614
|
-
return value === void 0 || value === "" ? void 0 : value;
|
|
13615
|
-
};
|
|
13616
|
-
function parsePortEnv(raw) {
|
|
13617
|
-
if (raw === void 0 || raw === "") return void 0;
|
|
13618
|
-
const parsed = Number.parseInt(raw, 10);
|
|
13619
|
-
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535 || String(parsed) !== raw.trim()) {
|
|
13620
|
-
throw new Error(
|
|
13621
|
-
`RIVET_PORT env var must be an integer between 1 and 65535; got "${raw}"`
|
|
13622
|
-
);
|
|
13623
|
-
}
|
|
13624
|
-
return parsed;
|
|
13196
|
+
return parsed;
|
|
13625
13197
|
}
|
|
13626
13198
|
var getLogLevel = () => getEnvUniversal("RIVET_LOG_LEVEL") ?? getEnvUniversal("LOG_LEVEL");
|
|
13627
13199
|
var getLogTarget = () => getEnvUniversal("RIVET_LOG_TARGET") === "1";
|
|
@@ -13740,7 +13312,7 @@ function noopNext() {
|
|
|
13740
13312
|
}
|
|
13741
13313
|
var package_default = {
|
|
13742
13314
|
name: "rivetkit",
|
|
13743
|
-
version: "2.3.11-rc.
|
|
13315
|
+
version: "2.3.11-rc.9",
|
|
13744
13316
|
description: "Lightweight libraries for building stateful actors on edge platforms",
|
|
13745
13317
|
license: "Apache-2.0",
|
|
13746
13318
|
keywords: [
|
|
@@ -15033,7 +14605,7 @@ function Config({ initialBufferLength = 1024, maxBufferLength = 1024 * 1024 * 32
|
|
|
15033
14605
|
};
|
|
15034
14606
|
}
|
|
15035
14607
|
|
|
15036
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
14608
|
+
// ../rivetkit/dist/tsup/chunk-C5TORAVP.js
|
|
15037
14609
|
var config2 = /* @__PURE__ */ Config({});
|
|
15038
14610
|
function readWorkflowCbor(bc) {
|
|
15039
14611
|
return readData(bc);
|
|
@@ -15211,125 +14783,555 @@ function readWorkflowVersionCheckEntry(bc) {
|
|
|
15211
14783
|
latest: readU32(bc)
|
|
15212
14784
|
};
|
|
15213
14785
|
}
|
|
15214
|
-
function readWorkflowEntryKind(bc) {
|
|
15215
|
-
const offset = bc.offset;
|
|
15216
|
-
const tag = readU8(bc);
|
|
15217
|
-
switch (tag) {
|
|
15218
|
-
case 0:
|
|
15219
|
-
return { tag: "WorkflowStepEntry", val: readWorkflowStepEntry(bc) };
|
|
15220
|
-
case 1:
|
|
15221
|
-
return { tag: "WorkflowLoopEntry", val: readWorkflowLoopEntry(bc) };
|
|
15222
|
-
case 2:
|
|
15223
|
-
return {
|
|
15224
|
-
tag: "WorkflowSleepEntry",
|
|
15225
|
-
val: readWorkflowSleepEntry(bc)
|
|
15226
|
-
};
|
|
15227
|
-
case 3:
|
|
15228
|
-
return {
|
|
15229
|
-
tag: "WorkflowMessageEntry",
|
|
15230
|
-
val: readWorkflowMessageEntry(bc)
|
|
15231
|
-
};
|
|
15232
|
-
case 4:
|
|
15233
|
-
return {
|
|
15234
|
-
tag: "WorkflowRollbackCheckpointEntry",
|
|
15235
|
-
val: readWorkflowRollbackCheckpointEntry(bc)
|
|
15236
|
-
};
|
|
15237
|
-
case 5:
|
|
15238
|
-
return { tag: "WorkflowJoinEntry", val: readWorkflowJoinEntry(bc) };
|
|
15239
|
-
case 6:
|
|
15240
|
-
return { tag: "WorkflowRaceEntry", val: readWorkflowRaceEntry(bc) };
|
|
15241
|
-
case 7:
|
|
15242
|
-
return {
|
|
15243
|
-
tag: "WorkflowRemovedEntry",
|
|
15244
|
-
val: readWorkflowRemovedEntry(bc)
|
|
15245
|
-
};
|
|
15246
|
-
case 8:
|
|
15247
|
-
return {
|
|
15248
|
-
tag: "WorkflowVersionCheckEntry",
|
|
15249
|
-
val: readWorkflowVersionCheckEntry(bc)
|
|
15250
|
-
};
|
|
15251
|
-
default: {
|
|
15252
|
-
bc.offset = offset;
|
|
15253
|
-
throw new BareError(offset, "invalid tag");
|
|
14786
|
+
function readWorkflowEntryKind(bc) {
|
|
14787
|
+
const offset = bc.offset;
|
|
14788
|
+
const tag = readU8(bc);
|
|
14789
|
+
switch (tag) {
|
|
14790
|
+
case 0:
|
|
14791
|
+
return { tag: "WorkflowStepEntry", val: readWorkflowStepEntry(bc) };
|
|
14792
|
+
case 1:
|
|
14793
|
+
return { tag: "WorkflowLoopEntry", val: readWorkflowLoopEntry(bc) };
|
|
14794
|
+
case 2:
|
|
14795
|
+
return {
|
|
14796
|
+
tag: "WorkflowSleepEntry",
|
|
14797
|
+
val: readWorkflowSleepEntry(bc)
|
|
14798
|
+
};
|
|
14799
|
+
case 3:
|
|
14800
|
+
return {
|
|
14801
|
+
tag: "WorkflowMessageEntry",
|
|
14802
|
+
val: readWorkflowMessageEntry(bc)
|
|
14803
|
+
};
|
|
14804
|
+
case 4:
|
|
14805
|
+
return {
|
|
14806
|
+
tag: "WorkflowRollbackCheckpointEntry",
|
|
14807
|
+
val: readWorkflowRollbackCheckpointEntry(bc)
|
|
14808
|
+
};
|
|
14809
|
+
case 5:
|
|
14810
|
+
return { tag: "WorkflowJoinEntry", val: readWorkflowJoinEntry(bc) };
|
|
14811
|
+
case 6:
|
|
14812
|
+
return { tag: "WorkflowRaceEntry", val: readWorkflowRaceEntry(bc) };
|
|
14813
|
+
case 7:
|
|
14814
|
+
return {
|
|
14815
|
+
tag: "WorkflowRemovedEntry",
|
|
14816
|
+
val: readWorkflowRemovedEntry(bc)
|
|
14817
|
+
};
|
|
14818
|
+
case 8:
|
|
14819
|
+
return {
|
|
14820
|
+
tag: "WorkflowVersionCheckEntry",
|
|
14821
|
+
val: readWorkflowVersionCheckEntry(bc)
|
|
14822
|
+
};
|
|
14823
|
+
default: {
|
|
14824
|
+
bc.offset = offset;
|
|
14825
|
+
throw new BareError(offset, "invalid tag");
|
|
14826
|
+
}
|
|
14827
|
+
}
|
|
14828
|
+
}
|
|
14829
|
+
function readWorkflowEntry(bc) {
|
|
14830
|
+
return {
|
|
14831
|
+
id: readString(bc),
|
|
14832
|
+
location: readWorkflowLocation(bc),
|
|
14833
|
+
kind: readWorkflowEntryKind(bc)
|
|
14834
|
+
};
|
|
14835
|
+
}
|
|
14836
|
+
function read3(bc) {
|
|
14837
|
+
return readBool(bc) ? readU64(bc) : null;
|
|
14838
|
+
}
|
|
14839
|
+
function readWorkflowEntryMetadata(bc) {
|
|
14840
|
+
return {
|
|
14841
|
+
status: readWorkflowEntryStatus(bc),
|
|
14842
|
+
error: read1(bc),
|
|
14843
|
+
attempts: readU32(bc),
|
|
14844
|
+
lastAttemptAt: readU64(bc),
|
|
14845
|
+
createdAt: readU64(bc),
|
|
14846
|
+
completedAt: read3(bc),
|
|
14847
|
+
rollbackCompletedAt: read3(bc),
|
|
14848
|
+
rollbackError: read1(bc)
|
|
14849
|
+
};
|
|
14850
|
+
}
|
|
14851
|
+
function read4(bc) {
|
|
14852
|
+
const len = readUintSafe(bc);
|
|
14853
|
+
if (len === 0) {
|
|
14854
|
+
return [];
|
|
14855
|
+
}
|
|
14856
|
+
const result = [readString(bc)];
|
|
14857
|
+
for (let i = 1; i < len; i++) {
|
|
14858
|
+
result[i] = readString(bc);
|
|
14859
|
+
}
|
|
14860
|
+
return result;
|
|
14861
|
+
}
|
|
14862
|
+
function read5(bc) {
|
|
14863
|
+
const len = readUintSafe(bc);
|
|
14864
|
+
if (len === 0) {
|
|
14865
|
+
return [];
|
|
14866
|
+
}
|
|
14867
|
+
const result = [readWorkflowEntry(bc)];
|
|
14868
|
+
for (let i = 1; i < len; i++) {
|
|
14869
|
+
result[i] = readWorkflowEntry(bc);
|
|
14870
|
+
}
|
|
14871
|
+
return result;
|
|
14872
|
+
}
|
|
14873
|
+
function read6(bc) {
|
|
14874
|
+
const len = readUintSafe(bc);
|
|
14875
|
+
const result = /* @__PURE__ */ new Map();
|
|
14876
|
+
for (let i = 0; i < len; i++) {
|
|
14877
|
+
const offset = bc.offset;
|
|
14878
|
+
const key = readString(bc);
|
|
14879
|
+
if (result.has(key)) {
|
|
14880
|
+
bc.offset = offset;
|
|
14881
|
+
throw new BareError(offset, "duplicated key");
|
|
14882
|
+
}
|
|
14883
|
+
result.set(key, readWorkflowEntryMetadata(bc));
|
|
14884
|
+
}
|
|
14885
|
+
return result;
|
|
14886
|
+
}
|
|
14887
|
+
function readWorkflowHistory(bc) {
|
|
14888
|
+
return {
|
|
14889
|
+
nameRegistry: read4(bc),
|
|
14890
|
+
entries: read5(bc),
|
|
14891
|
+
entryMetadata: read6(bc)
|
|
14892
|
+
};
|
|
14893
|
+
}
|
|
14894
|
+
function decodeWorkflowHistory(bytes) {
|
|
14895
|
+
const bc = new ByteCursor(bytes, config2);
|
|
14896
|
+
const result = readWorkflowHistory(bc);
|
|
14897
|
+
if (bc.offset < bc.view.byteLength) {
|
|
14898
|
+
throw new BareError(bc.offset, "remaining bytes");
|
|
14899
|
+
}
|
|
14900
|
+
return result;
|
|
14901
|
+
}
|
|
14902
|
+
function decodeWorkflowHistoryTransport(data) {
|
|
14903
|
+
return decodeWorkflowHistory(toUint8Array(data));
|
|
14904
|
+
}
|
|
14905
|
+
|
|
14906
|
+
// ../rivetkit/dist/tsup/chunk-QWLJCP3X.js
|
|
14907
|
+
function flattenActionHandlers(actions) {
|
|
14908
|
+
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14909
|
+
for (const { name, handler } of collectActionEntries(actions)) {
|
|
14910
|
+
flattened[name] = handler;
|
|
14911
|
+
}
|
|
14912
|
+
return flattened;
|
|
14913
|
+
}
|
|
14914
|
+
function flattenActionInputSchemas(actions, schemas) {
|
|
14915
|
+
if (schemas === void 0) return void 0;
|
|
14916
|
+
if (!isRecord(schemas)) {
|
|
14917
|
+
throw new TypeError("actionInputSchemas must be an object");
|
|
14918
|
+
}
|
|
14919
|
+
const flattened = /* @__PURE__ */ Object.create(null);
|
|
14920
|
+
for (const { name, path: path2 } of collectActionEntries(actions)) {
|
|
14921
|
+
const nestedSchema = lookupNestedSchema(schemas, path2);
|
|
14922
|
+
const flatSchema = schemas[name];
|
|
14923
|
+
if (nestedSchema !== void 0 && flatSchema !== void 0 && nestedSchema !== flatSchema) {
|
|
14924
|
+
throw new TypeError(
|
|
14925
|
+
`Action input schema \`${name}\` is defined by both a nested path and a dotted key`
|
|
14926
|
+
);
|
|
14927
|
+
}
|
|
14928
|
+
const schema = nestedSchema ?? flatSchema;
|
|
14929
|
+
if (schema !== void 0) {
|
|
14930
|
+
flattened[name] = schema;
|
|
14931
|
+
}
|
|
14932
|
+
}
|
|
14933
|
+
return flattened;
|
|
14934
|
+
}
|
|
14935
|
+
function collectActionEntries(actions) {
|
|
14936
|
+
const entries = [];
|
|
14937
|
+
const names = /* @__PURE__ */ new Set();
|
|
14938
|
+
visitActionGroup(actions ?? {}, [], entries, names);
|
|
14939
|
+
return entries;
|
|
14940
|
+
}
|
|
14941
|
+
function visitActionGroup(value, path2, entries, names) {
|
|
14942
|
+
if (!isRecord(value)) {
|
|
14943
|
+
throw new TypeError(
|
|
14944
|
+
`${formatActionPath(path2)} must be an action handler or group`
|
|
14945
|
+
);
|
|
14946
|
+
}
|
|
14947
|
+
for (const [segment, child] of Object.entries(value)) {
|
|
14948
|
+
const childPath = [...path2, segment];
|
|
14949
|
+
if (typeof child === "function") {
|
|
14950
|
+
const name = childPath.join(".");
|
|
14951
|
+
if (names.has(name)) {
|
|
14952
|
+
throw new TypeError(
|
|
14953
|
+
`Multiple action definitions flatten to \`${name}\``
|
|
14954
|
+
);
|
|
14955
|
+
}
|
|
14956
|
+
names.add(name);
|
|
14957
|
+
entries.push({
|
|
14958
|
+
name,
|
|
14959
|
+
path: childPath,
|
|
14960
|
+
handler: child
|
|
14961
|
+
});
|
|
14962
|
+
} else {
|
|
14963
|
+
visitActionGroup(child, childPath, entries, names);
|
|
14964
|
+
}
|
|
14965
|
+
}
|
|
14966
|
+
}
|
|
14967
|
+
function lookupNestedSchema(schemas, path2) {
|
|
14968
|
+
let value = schemas;
|
|
14969
|
+
for (const segment of path2) {
|
|
14970
|
+
if (!isRecord(value) || !Object.hasOwn(value, segment)) {
|
|
14971
|
+
return void 0;
|
|
15254
14972
|
}
|
|
14973
|
+
value = value[segment];
|
|
15255
14974
|
}
|
|
14975
|
+
return value;
|
|
15256
14976
|
}
|
|
15257
|
-
function
|
|
15258
|
-
|
|
15259
|
-
|
|
15260
|
-
|
|
15261
|
-
|
|
15262
|
-
|
|
14977
|
+
function isRecord(value) {
|
|
14978
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
14979
|
+
return false;
|
|
14980
|
+
}
|
|
14981
|
+
const prototype = Object.getPrototypeOf(value);
|
|
14982
|
+
return prototype === Object.prototype || prototype === null;
|
|
15263
14983
|
}
|
|
15264
|
-
function
|
|
15265
|
-
return
|
|
14984
|
+
function formatActionPath(path2) {
|
|
14985
|
+
return path2.length === 0 ? "actions" : `Action \`${path2.join(".")}\``;
|
|
15266
14986
|
}
|
|
15267
|
-
|
|
15268
|
-
|
|
15269
|
-
|
|
15270
|
-
|
|
15271
|
-
|
|
15272
|
-
|
|
15273
|
-
|
|
15274
|
-
|
|
15275
|
-
|
|
15276
|
-
|
|
15277
|
-
}
|
|
14987
|
+
var DEFAULT_SLEEP_GRACE_PERIOD = 15e3;
|
|
14988
|
+
var ACTOR_CONTEXT_INTERNAL_SYMBOL = /* @__PURE__ */ Symbol(
|
|
14989
|
+
"rivetkit.actor_context_internal"
|
|
14990
|
+
);
|
|
14991
|
+
var RAW_STATE_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.raw_state");
|
|
14992
|
+
var CONN_STATE_MANAGER_SYMBOL = /* @__PURE__ */ Symbol("rivetkit.conn_state_manager");
|
|
14993
|
+
var zFunction = () => external_exports.custom((val) => typeof val === "function");
|
|
14994
|
+
var zActionTree = external_exports.custom((value) => {
|
|
14995
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
14996
|
+
return false;
|
|
14997
|
+
}
|
|
14998
|
+
const prototype = Object.getPrototypeOf(value);
|
|
14999
|
+
return prototype === Object.prototype || prototype === null;
|
|
15000
|
+
}).superRefine((actions, ctx) => {
|
|
15001
|
+
try {
|
|
15002
|
+
flattenActionHandlers(actions);
|
|
15003
|
+
} catch (error46) {
|
|
15004
|
+
ctx.addIssue({
|
|
15005
|
+
code: "custom",
|
|
15006
|
+
message: error46 instanceof Error ? error46.message : "Invalid action definition"
|
|
15007
|
+
});
|
|
15008
|
+
}
|
|
15009
|
+
});
|
|
15010
|
+
var WorkflowInspectorConfigSchema = external_exports.object({
|
|
15011
|
+
getHistory: zFunction(),
|
|
15012
|
+
onHistoryUpdated: zFunction().optional(),
|
|
15013
|
+
replayFromStep: zFunction().optional()
|
|
15014
|
+
});
|
|
15015
|
+
var RunInspectorConfigSchema = external_exports.object({
|
|
15016
|
+
workflow: WorkflowInspectorConfigSchema.optional()
|
|
15017
|
+
}).optional();
|
|
15018
|
+
var BUILTIN_INSPECTOR_TAB_IDS = [
|
|
15019
|
+
"workflow",
|
|
15020
|
+
"database",
|
|
15021
|
+
"state",
|
|
15022
|
+
"queue",
|
|
15023
|
+
"schedules",
|
|
15024
|
+
"connections",
|
|
15025
|
+
"console"
|
|
15026
|
+
];
|
|
15027
|
+
var BuiltinInspectorTabIdSchema = external_exports.enum(BUILTIN_INSPECTOR_TAB_IDS);
|
|
15028
|
+
var CUSTOM_INSPECTOR_TAB_ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
15029
|
+
var CustomInspectorTabEntrySchema = external_exports.object({
|
|
15030
|
+
id: external_exports.string().regex(
|
|
15031
|
+
CUSTOM_INSPECTOR_TAB_ID_RE,
|
|
15032
|
+
"inspector.tabs[].id must contain only letters, digits, underscore, or dash"
|
|
15033
|
+
),
|
|
15034
|
+
label: external_exports.string().min(1),
|
|
15035
|
+
source: external_exports.string().min(1),
|
|
15036
|
+
/**
|
|
15037
|
+
* Optional icon id. The dashboard maps strings to glyphs (see its
|
|
15038
|
+
* icon registry); unknown ids fall back to a generic icon.
|
|
15039
|
+
*/
|
|
15040
|
+
icon: external_exports.string().min(1).optional(),
|
|
15041
|
+
hidden: external_exports.literal(false).optional()
|
|
15042
|
+
}).strict();
|
|
15043
|
+
var HideInspectorTabEntrySchema = external_exports.object({
|
|
15044
|
+
id: BuiltinInspectorTabIdSchema,
|
|
15045
|
+
hidden: external_exports.literal(true)
|
|
15046
|
+
}).strict();
|
|
15047
|
+
var InspectorTabEntrySchema = external_exports.union([
|
|
15048
|
+
CustomInspectorTabEntrySchema,
|
|
15049
|
+
HideInspectorTabEntrySchema
|
|
15050
|
+
]);
|
|
15051
|
+
var ActorInspectorConfigSchema = external_exports.object({
|
|
15052
|
+
tabs: external_exports.array(InspectorTabEntrySchema).default(() => [])
|
|
15053
|
+
}).strict().refine(
|
|
15054
|
+
(data) => {
|
|
15055
|
+
const ids = data.tabs.map((t) => t.id);
|
|
15056
|
+
return new Set(ids).size === ids.length;
|
|
15057
|
+
},
|
|
15058
|
+
{ message: "Duplicate id in inspector.tabs", path: ["tabs"] }
|
|
15059
|
+
).refine(
|
|
15060
|
+
(data) => {
|
|
15061
|
+
const builtinSet = new Set(BUILTIN_INSPECTOR_TAB_IDS);
|
|
15062
|
+
return data.tabs.every(
|
|
15063
|
+
(t) => t.hidden === true || !builtinSet.has(t.id)
|
|
15064
|
+
);
|
|
15065
|
+
},
|
|
15066
|
+
{
|
|
15067
|
+
message: "Custom inspector tab id collides with a built-in (use hidden: true to hide a built-in)",
|
|
15068
|
+
path: ["tabs"]
|
|
15069
|
+
}
|
|
15070
|
+
);
|
|
15071
|
+
var RunConfigSchema = external_exports.object({
|
|
15072
|
+
/** Display name for the actor in the Inspector UI. */
|
|
15073
|
+
name: external_exports.string().optional(),
|
|
15074
|
+
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
15075
|
+
icon: external_exports.string().optional(),
|
|
15076
|
+
/** The run handler function. */
|
|
15077
|
+
run: zFunction(),
|
|
15078
|
+
/** Inspector integration for long-running run handlers. */
|
|
15079
|
+
inspector: RunInspectorConfigSchema.optional()
|
|
15080
|
+
});
|
|
15081
|
+
var RUN_FUNCTION_CONFIG_SYMBOL = /* @__PURE__ */ Symbol.for(
|
|
15082
|
+
"rivetkit.run_function_config"
|
|
15083
|
+
);
|
|
15084
|
+
var zRunHandler = external_exports.union([zFunction(), RunConfigSchema]).optional();
|
|
15085
|
+
function getRunFunction(run) {
|
|
15086
|
+
if (!run) return void 0;
|
|
15087
|
+
if (typeof run === "function") return run;
|
|
15088
|
+
return run.run;
|
|
15278
15089
|
}
|
|
15279
|
-
function
|
|
15280
|
-
|
|
15281
|
-
if (
|
|
15282
|
-
|
|
15090
|
+
function getRunMetadata(run) {
|
|
15091
|
+
if (!run) return {};
|
|
15092
|
+
if (typeof run === "function") {
|
|
15093
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15094
|
+
if (!config3) return {};
|
|
15095
|
+
return { name: config3.name, icon: config3.icon };
|
|
15283
15096
|
}
|
|
15284
|
-
|
|
15285
|
-
|
|
15286
|
-
|
|
15097
|
+
return { name: run.name, icon: run.icon };
|
|
15098
|
+
}
|
|
15099
|
+
function getRunInspectorConfig(run, actor2) {
|
|
15100
|
+
if (!run) return void 0;
|
|
15101
|
+
if (typeof run === "function") {
|
|
15102
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15103
|
+
return (config3 == null ? void 0 : config3.inspectorFactory) ? config3.inspectorFactory(actor2) : config3 == null ? void 0 : config3.inspector;
|
|
15287
15104
|
}
|
|
15288
|
-
return
|
|
15105
|
+
return run.inspector;
|
|
15289
15106
|
}
|
|
15290
|
-
function
|
|
15291
|
-
|
|
15292
|
-
if (
|
|
15293
|
-
return
|
|
15107
|
+
function disposeRunInspector(run, actorId) {
|
|
15108
|
+
var _a2;
|
|
15109
|
+
if (!run || typeof run !== "function") {
|
|
15110
|
+
return;
|
|
15294
15111
|
}
|
|
15295
|
-
const
|
|
15296
|
-
|
|
15297
|
-
|
|
15112
|
+
const config3 = run[RUN_FUNCTION_CONFIG_SYMBOL];
|
|
15113
|
+
(_a2 = config3 == null ? void 0 : config3.disposeInspector) == null ? void 0 : _a2.call(config3, actorId);
|
|
15114
|
+
}
|
|
15115
|
+
var GlobalActorOptionsBaseSchema = external_exports.object({
|
|
15116
|
+
/** Display name for the actor in the Inspector UI. */
|
|
15117
|
+
name: external_exports.string().optional(),
|
|
15118
|
+
/** Icon for the actor in the Inspector UI. Can be an emoji or FontAwesome icon name. */
|
|
15119
|
+
icon: external_exports.string().optional(),
|
|
15120
|
+
/** Enables the experimental Actor Runtime Socket for this actor. */
|
|
15121
|
+
enableActorRuntimeSocket: external_exports.boolean().default(false),
|
|
15122
|
+
/**
|
|
15123
|
+
* Can hibernate WebSockets for onWebSocket.
|
|
15124
|
+
*
|
|
15125
|
+
* WebSockets using actions/events are hibernatable by default.
|
|
15126
|
+
*
|
|
15127
|
+
* @experimental
|
|
15128
|
+
**/
|
|
15129
|
+
canHibernateWebSocket: external_exports.union([external_exports.boolean(), zFunction()]).default(false)
|
|
15130
|
+
}).strict();
|
|
15131
|
+
var GlobalActorOptionsSchema = GlobalActorOptionsBaseSchema.prefault(
|
|
15132
|
+
() => ({})
|
|
15133
|
+
);
|
|
15134
|
+
var InstanceActorOptionsBaseSchema = external_exports.object({
|
|
15135
|
+
createVarsTimeout: external_exports.number().positive().default(5e3),
|
|
15136
|
+
createConnStateTimeout: external_exports.number().positive().default(5e3),
|
|
15137
|
+
onBeforeConnectTimeout: external_exports.number().positive().default(5e3),
|
|
15138
|
+
onConnectTimeout: external_exports.number().positive().default(5e3),
|
|
15139
|
+
onMigrateTimeout: external_exports.number().positive().default(3e4),
|
|
15140
|
+
sleepGracePeriod: external_exports.number().positive().default(DEFAULT_SLEEP_GRACE_PERIOD),
|
|
15141
|
+
/** @deprecated `onDestroyTimeout` is folded into `sleepGracePeriod`, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0. */
|
|
15142
|
+
onDestroyTimeout: external_exports.number().positive().optional(),
|
|
15143
|
+
/** @deprecated `waitUntilTimeout` is folded into `sleepGracePeriod`, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0. */
|
|
15144
|
+
waitUntilTimeout: external_exports.number().positive().optional(),
|
|
15145
|
+
stateSaveInterval: external_exports.number().positive().default(1e3),
|
|
15146
|
+
actionTimeout: external_exports.number().positive().default(6e4),
|
|
15147
|
+
connectionLivenessTimeout: external_exports.number().positive().default(2500),
|
|
15148
|
+
connectionLivenessInterval: external_exports.number().positive().default(5e3),
|
|
15149
|
+
/** @deprecated Use `c.keepAwake(promise)` to scope keep-awake to a specific operation, or keep `noSleep` for actors that must stay awake indefinitely. Will be removed in 2.2.0. */
|
|
15150
|
+
noSleep: external_exports.boolean().default(false),
|
|
15151
|
+
sleepTimeout: external_exports.number().positive().default(3e4),
|
|
15152
|
+
maxQueueSize: external_exports.number().positive().default(1e3),
|
|
15153
|
+
/** Maximum pending one-shot and recurring schedules. */
|
|
15154
|
+
maxSchedules: external_exports.number().int().nonnegative().default(1e3),
|
|
15155
|
+
maxQueueMessageSize: external_exports.number().positive().default(64 * 1024),
|
|
15156
|
+
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
15157
|
+
preloadMaxWorkflowBytes: external_exports.number().nonnegative().optional(),
|
|
15158
|
+
/** @deprecated Internal storage moved to SQLite and no longer uses KV preloading, so this option is ignored. Will be removed in 2.2.0. */
|
|
15159
|
+
preloadMaxConnectionsBytes: external_exports.number().nonnegative().optional()
|
|
15160
|
+
}).strict();
|
|
15161
|
+
var InstanceActorOptionsSchema = InstanceActorOptionsBaseSchema.prefault(() => ({}));
|
|
15162
|
+
var ActorOptionsSchema = GlobalActorOptionsBaseSchema.extend(
|
|
15163
|
+
InstanceActorOptionsBaseSchema.shape
|
|
15164
|
+
).strict().prefault(() => ({}));
|
|
15165
|
+
var ActorConfigSchema = external_exports.object({
|
|
15166
|
+
onCreate: zFunction().optional(),
|
|
15167
|
+
onDestroy: zFunction().optional(),
|
|
15168
|
+
onMigrate: zFunction().optional(),
|
|
15169
|
+
onWake: zFunction().optional(),
|
|
15170
|
+
onSleep: zFunction().optional(),
|
|
15171
|
+
run: zRunHandler,
|
|
15172
|
+
onStateChange: zFunction().optional(),
|
|
15173
|
+
onBeforeConnect: zFunction().optional(),
|
|
15174
|
+
onConnect: zFunction().optional(),
|
|
15175
|
+
onDisconnect: zFunction().optional(),
|
|
15176
|
+
onBeforeActionResponse: zFunction().optional(),
|
|
15177
|
+
onRequest: zFunction().optional(),
|
|
15178
|
+
onWebSocket: zFunction().optional(),
|
|
15179
|
+
actions: zActionTree.default(() => ({})),
|
|
15180
|
+
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15181
|
+
connParamsSchema: external_exports.any().optional(),
|
|
15182
|
+
events: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15183
|
+
queues: external_exports.record(external_exports.string(), external_exports.any()).optional(),
|
|
15184
|
+
state: external_exports.any().optional(),
|
|
15185
|
+
createState: zFunction().optional(),
|
|
15186
|
+
connState: external_exports.any().optional(),
|
|
15187
|
+
createConnState: zFunction().optional(),
|
|
15188
|
+
vars: external_exports.any().optional(),
|
|
15189
|
+
db: external_exports.any().optional(),
|
|
15190
|
+
createVars: zFunction().optional(),
|
|
15191
|
+
options: ActorOptionsSchema,
|
|
15192
|
+
inspector: ActorInspectorConfigSchema.optional()
|
|
15193
|
+
}).strict().refine(
|
|
15194
|
+
(data) => !(data.state !== void 0 && data.createState !== void 0),
|
|
15195
|
+
{
|
|
15196
|
+
message: "Cannot define both 'state' and 'createState'",
|
|
15197
|
+
path: ["state"]
|
|
15298
15198
|
}
|
|
15299
|
-
|
|
15300
|
-
|
|
15301
|
-
|
|
15302
|
-
|
|
15303
|
-
|
|
15304
|
-
for (let i = 0; i < len; i++) {
|
|
15305
|
-
const offset = bc.offset;
|
|
15306
|
-
const key = readString(bc);
|
|
15307
|
-
if (result.has(key)) {
|
|
15308
|
-
bc.offset = offset;
|
|
15309
|
-
throw new BareError(offset, "duplicated key");
|
|
15310
|
-
}
|
|
15311
|
-
result.set(key, readWorkflowEntryMetadata(bc));
|
|
15199
|
+
).refine(
|
|
15200
|
+
(data) => !(data.connState !== void 0 && data.createConnState !== void 0),
|
|
15201
|
+
{
|
|
15202
|
+
message: "Cannot define both 'connState' and 'createConnState'",
|
|
15203
|
+
path: ["connState"]
|
|
15312
15204
|
}
|
|
15313
|
-
|
|
15314
|
-
|
|
15315
|
-
|
|
15316
|
-
|
|
15317
|
-
|
|
15318
|
-
entries: read5(bc),
|
|
15319
|
-
entryMetadata: read6(bc)
|
|
15320
|
-
};
|
|
15321
|
-
}
|
|
15322
|
-
function decodeWorkflowHistory(bytes) {
|
|
15323
|
-
const bc = new ByteCursor(bytes, config2);
|
|
15324
|
-
const result = readWorkflowHistory(bc);
|
|
15325
|
-
if (bc.offset < bc.view.byteLength) {
|
|
15326
|
-
throw new BareError(bc.offset, "remaining bytes");
|
|
15205
|
+
).refine(
|
|
15206
|
+
(data) => !(data.vars !== void 0 && data.createVars !== void 0),
|
|
15207
|
+
{
|
|
15208
|
+
message: "Cannot define both 'vars' and 'createVars'",
|
|
15209
|
+
path: ["vars"]
|
|
15327
15210
|
}
|
|
15328
|
-
|
|
15329
|
-
|
|
15330
|
-
|
|
15331
|
-
|
|
15332
|
-
}
|
|
15211
|
+
);
|
|
15212
|
+
var DocActorOptionsSchema = external_exports.object({
|
|
15213
|
+
name: external_exports.string().optional().describe("Display name for the actor in the Inspector UI."),
|
|
15214
|
+
icon: external_exports.string().optional().describe(
|
|
15215
|
+
"Icon for the actor in the Inspector UI. Can be an emoji (e.g., '\u{1F680}') or FontAwesome icon name (e.g., 'rocket')."
|
|
15216
|
+
),
|
|
15217
|
+
enableActorRuntimeSocket: external_exports.boolean().optional().describe(
|
|
15218
|
+
"Enables the experimental Actor Runtime Socket for this actor. Default: false"
|
|
15219
|
+
),
|
|
15220
|
+
createVarsTimeout: external_exports.number().optional().describe("Timeout in ms for createVars handler. Default: 5000"),
|
|
15221
|
+
createConnStateTimeout: external_exports.number().optional().describe(
|
|
15222
|
+
"Timeout in ms for createConnState handler. Default: 5000"
|
|
15223
|
+
),
|
|
15224
|
+
onMigrateTimeout: external_exports.number().optional().describe("Timeout in ms for onMigrate handler. Default: 30000"),
|
|
15225
|
+
onBeforeConnectTimeout: external_exports.number().optional().describe(
|
|
15226
|
+
"Timeout in ms for onBeforeConnect handler. Default: 5000"
|
|
15227
|
+
),
|
|
15228
|
+
onConnectTimeout: external_exports.number().optional().describe("Timeout in ms for onConnect handler. Default: 5000"),
|
|
15229
|
+
sleepGracePeriod: external_exports.number().optional().describe(
|
|
15230
|
+
`Max time in ms for the graceful shutdown window. Covers lifecycle hooks (onSleep, onDestroy), the run handler wait, async raw WebSocket handlers, disconnect callbacks, and final state serialization. Default: ${DEFAULT_SLEEP_GRACE_PERIOD}.`
|
|
15231
|
+
),
|
|
15232
|
+
onDestroyTimeout: external_exports.number().optional().describe(
|
|
15233
|
+
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
15234
|
+
),
|
|
15235
|
+
waitUntilTimeout: external_exports.number().optional().describe(
|
|
15236
|
+
"Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0."
|
|
15237
|
+
),
|
|
15238
|
+
stateSaveInterval: external_exports.number().optional().describe(
|
|
15239
|
+
"Interval in ms between automatic state saves. Default: 1000"
|
|
15240
|
+
),
|
|
15241
|
+
actionTimeout: external_exports.number().optional().describe("Timeout in ms for action handlers. Default: 60000"),
|
|
15242
|
+
connectionLivenessTimeout: external_exports.number().optional().describe(
|
|
15243
|
+
"Timeout in ms for connection liveness checks. Default: 2500"
|
|
15244
|
+
),
|
|
15245
|
+
connectionLivenessInterval: external_exports.number().optional().describe(
|
|
15246
|
+
"Interval in ms between connection liveness checks. Default: 5000"
|
|
15247
|
+
),
|
|
15248
|
+
noSleep: external_exports.boolean().optional().describe(
|
|
15249
|
+
"Deprecated. If true, the actor will never sleep. Use c.keepAwake(promise) to scope keep-awake to a specific operation instead. Default: false"
|
|
15250
|
+
),
|
|
15251
|
+
sleepTimeout: external_exports.number().optional().describe(
|
|
15252
|
+
"Time in ms of inactivity before the actor sleeps. Default: 30000"
|
|
15253
|
+
),
|
|
15254
|
+
maxQueueSize: external_exports.number().optional().describe(
|
|
15255
|
+
"Maximum number of queue messages before rejecting new messages. Default: 1000"
|
|
15256
|
+
),
|
|
15257
|
+
maxSchedules: external_exports.number().int().nonnegative().optional().describe(
|
|
15258
|
+
"Maximum pending one-shot and recurring schedules before rejecting new schedules. Default: 1000"
|
|
15259
|
+
),
|
|
15260
|
+
maxQueueMessageSize: external_exports.number().optional().describe(
|
|
15261
|
+
"Maximum size of each queue message in bytes. Default: 65536"
|
|
15262
|
+
),
|
|
15263
|
+
canHibernateWebSocket: external_exports.boolean().optional().describe(
|
|
15264
|
+
"Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false"
|
|
15265
|
+
)
|
|
15266
|
+
}).describe("Actor options for timeouts and behavior configuration.");
|
|
15267
|
+
var DocActorConfigSchema = external_exports.object({
|
|
15268
|
+
state: external_exports.unknown().optional().describe(
|
|
15269
|
+
"Initial state value for the actor. Cannot be used with createState."
|
|
15270
|
+
),
|
|
15271
|
+
createState: external_exports.unknown().optional().describe(
|
|
15272
|
+
"Function to create initial state. Receives context and input. Cannot be used with state."
|
|
15273
|
+
),
|
|
15274
|
+
connState: external_exports.unknown().optional().describe(
|
|
15275
|
+
"Initial connection state value. Cannot be used with createConnState."
|
|
15276
|
+
),
|
|
15277
|
+
createConnState: external_exports.unknown().optional().describe(
|
|
15278
|
+
"Function to create connection state. Receives context and connection params. The pending connection is not visible in c.conns until this succeeds. Cannot be used with connState."
|
|
15279
|
+
),
|
|
15280
|
+
vars: external_exports.unknown().optional().describe(
|
|
15281
|
+
"Initial ephemeral variables value. Cannot be used with createVars."
|
|
15282
|
+
),
|
|
15283
|
+
createVars: external_exports.unknown().optional().describe(
|
|
15284
|
+
"Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars."
|
|
15285
|
+
),
|
|
15286
|
+
db: external_exports.unknown().optional().describe("Database provider instance for the actor."),
|
|
15287
|
+
onCreate: external_exports.unknown().optional().describe(
|
|
15288
|
+
"Called when the actor is first initialized. Use to initialize state."
|
|
15289
|
+
),
|
|
15290
|
+
onDestroy: external_exports.unknown().optional().describe("Called when the actor is destroyed."),
|
|
15291
|
+
onMigrate: external_exports.unknown().optional().describe(
|
|
15292
|
+
"Called on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations."
|
|
15293
|
+
),
|
|
15294
|
+
onWake: external_exports.unknown().optional().describe(
|
|
15295
|
+
"Called when the actor wakes up and is ready to receive connections and actions."
|
|
15296
|
+
),
|
|
15297
|
+
onSleep: external_exports.unknown().optional().describe(
|
|
15298
|
+
"Called when the actor is stopping or sleeping. Use to clean up resources."
|
|
15299
|
+
),
|
|
15300
|
+
run: external_exports.unknown().optional().describe(
|
|
15301
|
+
"Called after actor starts. Does not block startup. Use for background tasks like queue processing or tick loops. If it exits, the actor follows the normal idle sleep timeout once idle. If it throws, the actor logs the error and then follows the normal idle sleep timeout once idle."
|
|
15302
|
+
),
|
|
15303
|
+
onStateChange: external_exports.unknown().optional().describe(
|
|
15304
|
+
"Called when the actor's state changes. State changes within this hook won't trigger recursion."
|
|
15305
|
+
),
|
|
15306
|
+
onBeforeConnect: external_exports.unknown().optional().describe(
|
|
15307
|
+
"Called before a client connects. Throw an error to reject the connection. The pending connection is not visible in c.conns while this runs."
|
|
15308
|
+
),
|
|
15309
|
+
onConnect: external_exports.unknown().optional().describe(
|
|
15310
|
+
"Called when a client successfully connects. The connection is visible in c.conns before this runs."
|
|
15311
|
+
),
|
|
15312
|
+
onDisconnect: external_exports.unknown().optional().describe("Called when a client disconnects."),
|
|
15313
|
+
onBeforeActionResponse: external_exports.unknown().optional().describe(
|
|
15314
|
+
"Called before sending an action response. Use to transform output."
|
|
15315
|
+
),
|
|
15316
|
+
onRequest: external_exports.unknown().optional().describe(
|
|
15317
|
+
"Called for raw HTTP requests to /actors/{name}/http/* endpoints."
|
|
15318
|
+
),
|
|
15319
|
+
onWebSocket: external_exports.unknown().optional().describe(
|
|
15320
|
+
"Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints."
|
|
15321
|
+
),
|
|
15322
|
+
actions: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
15323
|
+
"Tree of action names or nested groups to handler functions. Nested paths use dot-separated low-level action names. Defaults to an empty object."
|
|
15324
|
+
),
|
|
15325
|
+
actionInputSchemas: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe(
|
|
15326
|
+
"Optional schemas for validating action argument tuples in native runtimes. May mirror nested action groups or use dot-separated low-level action names."
|
|
15327
|
+
),
|
|
15328
|
+
connParamsSchema: external_exports.unknown().optional().describe(
|
|
15329
|
+
"Optional schema for validating connection params in native runtimes."
|
|
15330
|
+
),
|
|
15331
|
+
events: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of event names to schemas."),
|
|
15332
|
+
queues: external_exports.record(external_exports.string(), external_exports.unknown()).optional().describe("Map of queue names to schemas."),
|
|
15333
|
+
options: DocActorOptionsSchema.optional()
|
|
15334
|
+
}).describe("Actor configuration passed to the actor() function.");
|
|
15333
15335
|
|
|
15334
15336
|
// ../rivetkit/dist/tsup/chunk-JI6GZ2C2.js
|
|
15335
15337
|
var EMPTY_KEY = "/";
|
|
@@ -15448,7 +15450,7 @@ function removePrefixFromKey(prefixedKey) {
|
|
|
15448
15450
|
return prefixedKey.slice(KEYS.KV.length);
|
|
15449
15451
|
}
|
|
15450
15452
|
|
|
15451
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15453
|
+
// ../rivetkit/dist/tsup/chunk-XOOESJY7.js
|
|
15452
15454
|
function logger() {
|
|
15453
15455
|
return getLogger("actor-client");
|
|
15454
15456
|
}
|
|
@@ -15514,7 +15516,7 @@ var AsyncMutex = class {
|
|
|
15514
15516
|
}
|
|
15515
15517
|
};
|
|
15516
15518
|
|
|
15517
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15519
|
+
// ../rivetkit/dist/tsup/chunk-HOZ3ZLZ2.js
|
|
15518
15520
|
var import_invariant2 = __toESM(require_invariant(), 1);
|
|
15519
15521
|
|
|
15520
15522
|
// ../../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
|
|
@@ -15692,7 +15694,7 @@ function createVersionedDataHandler(config3) {
|
|
|
15692
15694
|
return new VersionedDataHandler(config3);
|
|
15693
15695
|
}
|
|
15694
15696
|
|
|
15695
|
-
// ../rivetkit/dist/tsup/chunk-
|
|
15697
|
+
// ../rivetkit/dist/tsup/chunk-HOZ3ZLZ2.js
|
|
15696
15698
|
var import_invariant3 = __toESM(require_invariant(), 1);
|
|
15697
15699
|
var import_invariant4 = __toESM(require_invariant(), 1);
|
|
15698
15700
|
var PATH_CONNECT = "/connect";
|
|
@@ -25315,6 +25317,83 @@ function createWriteThroughProxy(value, commit, beforeChange) {
|
|
|
25315
25317
|
}
|
|
25316
25318
|
);
|
|
25317
25319
|
}
|
|
25320
|
+
function unwrapProxy(value) {
|
|
25321
|
+
let current = value;
|
|
25322
|
+
while (current !== null && typeof current === "object") {
|
|
25323
|
+
const target = source_default.target(current);
|
|
25324
|
+
if (target === current) {
|
|
25325
|
+
break;
|
|
25326
|
+
}
|
|
25327
|
+
current = target;
|
|
25328
|
+
}
|
|
25329
|
+
return current;
|
|
25330
|
+
}
|
|
25331
|
+
function isPlainObject3(value) {
|
|
25332
|
+
const proto = Object.getPrototypeOf(value);
|
|
25333
|
+
return proto === Object.prototype || proto === null;
|
|
25334
|
+
}
|
|
25335
|
+
function unwrapDeep(value, seen) {
|
|
25336
|
+
const unwrapped = unwrapProxy(value);
|
|
25337
|
+
if (!unwrapped || typeof unwrapped !== "object") {
|
|
25338
|
+
return unwrapped;
|
|
25339
|
+
}
|
|
25340
|
+
if (seen.has(unwrapped)) {
|
|
25341
|
+
return unwrapped;
|
|
25342
|
+
}
|
|
25343
|
+
seen.add(unwrapped);
|
|
25344
|
+
if (Array.isArray(unwrapped)) {
|
|
25345
|
+
for (let i = 0; i < unwrapped.length; i++) {
|
|
25346
|
+
const child = unwrapDeep(unwrapped[i], seen);
|
|
25347
|
+
if (child !== unwrapped[i]) {
|
|
25348
|
+
unwrapped[i] = child;
|
|
25349
|
+
}
|
|
25350
|
+
}
|
|
25351
|
+
return unwrapped;
|
|
25352
|
+
}
|
|
25353
|
+
if (unwrapped instanceof Map) {
|
|
25354
|
+
const replacements = [];
|
|
25355
|
+
for (const [key, child] of unwrapped.entries()) {
|
|
25356
|
+
const nextKey = unwrapDeep(key, seen);
|
|
25357
|
+
const nextChild = unwrapDeep(child, seen);
|
|
25358
|
+
if (nextKey !== key || nextChild !== child) {
|
|
25359
|
+
replacements.push([key, nextKey, nextChild]);
|
|
25360
|
+
}
|
|
25361
|
+
}
|
|
25362
|
+
for (const [key, nextKey, nextChild] of replacements) {
|
|
25363
|
+
if (nextKey !== key) {
|
|
25364
|
+
unwrapped.delete(key);
|
|
25365
|
+
}
|
|
25366
|
+
unwrapped.set(nextKey, nextChild);
|
|
25367
|
+
}
|
|
25368
|
+
return unwrapped;
|
|
25369
|
+
}
|
|
25370
|
+
if (unwrapped instanceof Set) {
|
|
25371
|
+
const replacements = [];
|
|
25372
|
+
for (const child of unwrapped.values()) {
|
|
25373
|
+
const next = unwrapDeep(child, seen);
|
|
25374
|
+
if (next !== child) {
|
|
25375
|
+
replacements.push([child, next]);
|
|
25376
|
+
}
|
|
25377
|
+
}
|
|
25378
|
+
for (const [child, next] of replacements) {
|
|
25379
|
+
unwrapped.delete(child);
|
|
25380
|
+
unwrapped.add(next);
|
|
25381
|
+
}
|
|
25382
|
+
return unwrapped;
|
|
25383
|
+
}
|
|
25384
|
+
if (isPlainObject3(unwrapped)) {
|
|
25385
|
+
for (const key of Object.keys(unwrapped)) {
|
|
25386
|
+
const child = unwrapDeep(unwrapped[key], seen);
|
|
25387
|
+
if (child !== unwrapped[key]) {
|
|
25388
|
+
unwrapped[key] = child;
|
|
25389
|
+
}
|
|
25390
|
+
}
|
|
25391
|
+
}
|
|
25392
|
+
return unwrapped;
|
|
25393
|
+
}
|
|
25394
|
+
function unwrapWriteThroughProxy(value) {
|
|
25395
|
+
return unwrapDeep(value, /* @__PURE__ */ new Set());
|
|
25396
|
+
}
|
|
25318
25397
|
var textEncoder = new TextEncoder();
|
|
25319
25398
|
var textDecoder = new TextDecoder();
|
|
25320
25399
|
var defaultRuntimeLoaders = {
|
|
@@ -26001,8 +26080,23 @@ var NativeConnAdapter = class {
|
|
|
26001
26080
|
}
|
|
26002
26081
|
get state() {
|
|
26003
26082
|
const nextState = this.#readState();
|
|
26083
|
+
if (!this.#ctx) {
|
|
26084
|
+
return this.#createStateProxy(nextState);
|
|
26085
|
+
}
|
|
26086
|
+
const connState = getNativeConnPersistState(
|
|
26087
|
+
this.#runtime,
|
|
26088
|
+
this.#ctx,
|
|
26089
|
+
this.#conn
|
|
26090
|
+
);
|
|
26091
|
+
if (connState.stateProxy === void 0 || connState.stateProxyTarget !== nextState) {
|
|
26092
|
+
connState.stateProxyTarget = nextState;
|
|
26093
|
+
connState.stateProxy = this.#createStateProxy(nextState);
|
|
26094
|
+
}
|
|
26095
|
+
return connState.stateProxy;
|
|
26096
|
+
}
|
|
26097
|
+
#createStateProxy(state) {
|
|
26004
26098
|
return createWriteThroughProxy(
|
|
26005
|
-
|
|
26099
|
+
state,
|
|
26006
26100
|
(nextValue) => {
|
|
26007
26101
|
this.#writeState(nextValue, { writeNative: true });
|
|
26008
26102
|
},
|
|
@@ -26012,11 +26106,14 @@ var NativeConnAdapter = class {
|
|
|
26012
26106
|
);
|
|
26013
26107
|
}
|
|
26014
26108
|
set state(value) {
|
|
26015
|
-
|
|
26016
|
-
|
|
26109
|
+
const nextValue = unwrapWriteThroughProxy(value);
|
|
26110
|
+
assertJsonCompatValue(nextValue);
|
|
26111
|
+
this.#writeState(nextValue, { writeNative: true });
|
|
26017
26112
|
}
|
|
26018
26113
|
initializeState(value) {
|
|
26019
|
-
this.#writeState(value, {
|
|
26114
|
+
this.#writeState(unwrapWriteThroughProxy(value), {
|
|
26115
|
+
writeNative: false
|
|
26116
|
+
});
|
|
26020
26117
|
}
|
|
26021
26118
|
get isHibernatable() {
|
|
26022
26119
|
return callNativeSync(
|
|
@@ -27069,14 +27166,17 @@ var ActorContextHandleAdapter = class {
|
|
|
27069
27166
|
throw stateNotEnabledError();
|
|
27070
27167
|
}
|
|
27071
27168
|
this.#assertCanMutateState();
|
|
27072
|
-
|
|
27073
|
-
|
|
27169
|
+
const nextValue = unwrapWriteThroughProxy(value);
|
|
27170
|
+
assertJsonCompatValue(nextValue);
|
|
27171
|
+
this.#writeState(nextValue, { scheduleSave: true });
|
|
27074
27172
|
}
|
|
27075
27173
|
initializeState(value) {
|
|
27076
27174
|
if (!this.#stateEnabled) {
|
|
27077
27175
|
return;
|
|
27078
27176
|
}
|
|
27079
|
-
this.#writeState(value, {
|
|
27177
|
+
this.#writeState(unwrapWriteThroughProxy(value), {
|
|
27178
|
+
scheduleSave: false
|
|
27179
|
+
});
|
|
27080
27180
|
}
|
|
27081
27181
|
get vars() {
|
|
27082
27182
|
const runtimeState = getNativeRuntimeState(this.#runtime, this.#ctx);
|