rivetkit 2.3.4 → 2.3.5-rc.1
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/browser/client.d.ts +157 -9
- package/dist/browser/client.js +518 -542
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +101 -2
- package/dist/browser/inspector/client.js +1245 -227
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/agent-os/index.cjs +103 -36
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +159 -11
- package/dist/tsup/agent-os/index.d.ts +159 -11
- package/dist/tsup/agent-os/index.js +103 -36
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-7X4M7ZRA.cjs → chunk-4XKED5P5.cjs} +146 -177
- package/dist/tsup/chunk-4XKED5P5.cjs.map +1 -0
- package/dist/tsup/{chunk-Q7NBMTF3.cjs → chunk-6HQCLWAW.cjs} +384 -4
- package/dist/tsup/chunk-6HQCLWAW.cjs.map +1 -0
- package/dist/tsup/{chunk-JZ7TWV65.js → chunk-7AFZMFPQ.js} +15 -1
- package/dist/tsup/chunk-7AFZMFPQ.js.map +1 -0
- package/dist/tsup/{chunk-M7DCRMOZ.js → chunk-B4IZU537.js} +382 -2
- package/dist/tsup/chunk-B4IZU537.js.map +1 -0
- package/dist/tsup/{chunk-3MHDOUD7.cjs → chunk-G3CCRCTK.cjs} +14 -9
- package/dist/tsup/chunk-G3CCRCTK.cjs.map +1 -0
- package/dist/tsup/{chunk-CMPFZ724.js → chunk-GAV4PKFT.js} +16 -47
- package/dist/tsup/{chunk-CMPFZ724.js.map → chunk-GAV4PKFT.js.map} +1 -1
- package/dist/tsup/{chunk-HXUEHHJF.js → chunk-JI6GZ2C2.js} +2 -11
- package/dist/tsup/{chunk-HXUEHHJF.js.map → chunk-JI6GZ2C2.js.map} +1 -1
- package/dist/tsup/{chunk-3SNFA373.cjs → chunk-M3FCXL3Q.cjs} +3 -3
- package/dist/tsup/{chunk-3SNFA373.cjs.map → chunk-M3FCXL3Q.cjs.map} +1 -1
- package/dist/tsup/{chunk-GXW3VFJQ.js → chunk-MGTSVSUC.js} +2 -2
- package/dist/tsup/{chunk-VE2X4KMG.cjs → chunk-MYWZCDML.cjs} +2 -11
- package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
- package/dist/tsup/{chunk-M5TAM4JV.js → chunk-NIC3QLKL.js} +3 -3
- package/dist/tsup/{chunk-H4XOUVGP.js → chunk-P4OGQ4JL.js} +5 -7
- package/dist/tsup/{chunk-H4XOUVGP.js.map → chunk-P4OGQ4JL.js.map} +1 -1
- package/dist/tsup/{chunk-EOSGY3DC.js → chunk-PAG6G46L.js} +2 -2
- package/dist/tsup/{chunk-XIX5DOZN.js → chunk-SHBE77IT.js} +14 -9
- package/dist/tsup/chunk-SHBE77IT.js.map +1 -0
- package/dist/tsup/{chunk-SRT2DPN3.cjs → chunk-TNIWIUNV.cjs} +9 -11
- package/dist/tsup/chunk-TNIWIUNV.cjs.map +1 -0
- package/dist/tsup/{chunk-UPOCJPEQ.cjs → chunk-TR5NLR5V.cjs} +4 -4
- package/dist/tsup/{chunk-UPOCJPEQ.cjs.map → chunk-TR5NLR5V.cjs.map} +1 -1
- package/dist/tsup/{chunk-ZA7FLHKH.cjs → chunk-UEULFXUI.cjs} +16 -2
- package/dist/tsup/chunk-UEULFXUI.cjs.map +1 -0
- package/dist/tsup/{chunk-T4MURX4P.cjs → chunk-UJ2FQY63.cjs} +7 -7
- package/dist/tsup/{chunk-T4MURX4P.cjs.map → chunk-UJ2FQY63.cjs.map} +1 -1
- package/dist/tsup/client/mod.cjs +7 -8
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +5 -4
- package/dist/tsup/client/mod.d.ts +5 -4
- package/dist/tsup/client/mod.js +6 -7
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-D49x8NpL.d.cts → config-BxOimoGX.d.cts} +16 -0
- package/dist/tsup/{config-D49x8NpL.d.ts → config-BxOimoGX.d.ts} +16 -0
- package/dist/tsup/{config-ZkIsRFsN.d.ts → config-BzdqbLAP.d.ts} +164 -27
- package/dist/tsup/{config-BfBhjEbk.d.cts → config-CPPEwn_e.d.cts} +164 -27
- package/dist/tsup/{context-sZ9GlaBK.d.cts → context-DSA9gFXB.d.cts} +2 -2
- package/dist/tsup/{context-B7-84u9K.d.ts → context-wWv-K2K_.d.ts} +2 -2
- package/dist/tsup/db/drizzle.cjs +120 -68
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +8 -3
- package/dist/tsup/db/drizzle.d.ts +8 -3
- package/dist/tsup/db/drizzle.js +120 -68
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +74 -22
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +4 -3
- package/dist/tsup/db/mod.d.ts +4 -3
- package/dist/tsup/db/mod.js +74 -22
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.d.cts +3 -3
- package/dist/tsup/dynamic/mod.d.ts +3 -3
- package/dist/tsup/dynamic/mod.js +1 -1
- package/dist/tsup/inspector/mod.cjs +4 -5
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.js +3 -4
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector-tab/mod.cjs +2 -2
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -1
- package/dist/tsup/inspector-tab/mod.d.cts +5 -5
- package/dist/tsup/inspector-tab/mod.d.ts +5 -5
- package/dist/tsup/inspector-tab/mod.js +1 -1
- package/dist/tsup/inspector-tab/mod.js.map +1 -1
- package/dist/tsup/mod.cjs +605 -158
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +5 -5
- package/dist/tsup/mod.d.ts +5 -5
- package/dist/tsup/mod.js +528 -81
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +10 -11
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +3 -3
- package/dist/tsup/test/mod.d.ts +3 -3
- package/dist/tsup/test/mod.js +6 -7
- package/dist/tsup/test/mod.js.map +1 -1
- package/dist/tsup/utils-CV0akuDD.d.ts +162 -0
- package/dist/tsup/utils-DQDCphrl.d.cts +162 -0
- package/dist/tsup/utils.cjs +6 -2
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +3 -146
- package/dist/tsup/utils.d.ts +3 -146
- package/dist/tsup/utils.js +5 -1
- package/dist/tsup/workflow/mod.cjs +198 -151
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +5 -5
- package/dist/tsup/workflow/mod.d.ts +5 -5
- package/dist/tsup/workflow/mod.js +187 -140
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +8 -8
- package/src/actor/config.test.ts +14 -0
- package/src/actor/config.ts +104 -16
- package/src/actor/definition.ts +18 -7
- package/src/agent-os/actor/index.ts +2 -2
- package/src/common/bare/generated/actor-runtime-socket-protocol/v1.ts +848 -0
- package/src/common/bare/generated/inspector/v6.ts +1367 -0
- package/src/common/database/config.ts +24 -0
- package/src/common/database/mod.test.ts +148 -59
- package/src/common/database/mod.ts +93 -23
- package/src/common/database/native-database.test.ts +9 -0
- package/src/common/database/native-database.ts +151 -0
- package/src/common/database/shared.ts +15 -0
- package/src/common/encoding.ts +28 -21
- package/src/db/drizzle.test.ts +157 -0
- package/src/db/drizzle.ts +170 -79
- package/src/dynamic/isolate-runtime.ts +0 -2
- package/src/engine-client/driver.ts +0 -15
- package/src/engine-client/mod.ts +0 -41
- package/src/inspector/client.browser.ts +69 -8
- package/src/inspector-tab/mod.ts +1 -0
- package/src/registry/config/index.ts +1 -35
- package/src/registry/napi-runtime.ts +204 -16
- package/src/registry/native.ts +200 -30
- package/src/registry/runtime.ts +146 -3
- package/src/registry/wasm-runtime.ts +217 -6
- package/src/utils.ts +3 -0
- package/src/workflow/context.ts +5 -27
- package/src/workflow/driver.test.ts +62 -0
- package/src/workflow/driver.ts +231 -113
- package/src/workflow/mod.ts +3 -3
- package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
- package/dist/tsup/chunk-7X4M7ZRA.cjs.map +0 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
- package/dist/tsup/chunk-M7DCRMOZ.js.map +0 -1
- package/dist/tsup/chunk-Q7NBMTF3.cjs.map +0 -1
- package/dist/tsup/chunk-SRT2DPN3.cjs.map +0 -1
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +0 -1
- package/dist/tsup/chunk-W6WPKZ6I.js +0 -382
- package/dist/tsup/chunk-W6WPKZ6I.js.map +0 -1
- package/dist/tsup/chunk-XIX5DOZN.js.map +0 -1
- package/dist/tsup/chunk-Z7PSQWMC.cjs +0 -382
- package/dist/tsup/chunk-Z7PSQWMC.cjs.map +0 -1
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +0 -1
- package/src/actor/driver.ts +0 -141
- package/src/actor/instance/mod.ts +0 -2484
- package/src/drivers/engine/actor-driver.ts +0 -2473
- /package/dist/tsup/{chunk-GXW3VFJQ.js.map → chunk-MGTSVSUC.js.map} +0 -0
- /package/dist/tsup/{chunk-M5TAM4JV.js.map → chunk-NIC3QLKL.js.map} +0 -0
- /package/dist/tsup/{chunk-EOSGY3DC.js.map → chunk-PAG6G46L.js.map} +0 -0
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
-
|
|
3
|
-
var _chunkQ7NBMTF3cjs = require('./chunk-Q7NBMTF3.cjs');
|
|
4
|
-
|
|
5
|
-
// src/serde.ts
|
|
6
|
-
var _cborx = require('cbor-x'); var cbor = _interopRequireWildcard(_cborx);
|
|
7
|
-
var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant);
|
|
8
|
-
|
|
9
|
-
// src/common/encoding.ts
|
|
10
|
-
var _v4 = require('zod/v4');
|
|
11
|
-
var JSON_COMPAT_BIGINT = "$BigInt";
|
|
12
|
-
var JSON_COMPAT_ARRAY_BUFFER = "$ArrayBuffer";
|
|
13
|
-
var JSON_COMPAT_UINT8_ARRAY = "$Uint8Array";
|
|
14
|
-
var JSON_COMPAT_UNDEFINED = "$Undefined";
|
|
15
|
-
var JSON_COMPAT_SET = "$Set";
|
|
16
|
-
function isTypedArray(value) {
|
|
17
|
-
return value instanceof Uint8ClampedArray || value instanceof Uint16Array || value instanceof Uint32Array || value instanceof BigUint64Array || value instanceof Int8Array || value instanceof Int16Array || value instanceof Int32Array || value instanceof BigInt64Array || value instanceof Float32Array || value instanceof Float64Array;
|
|
18
|
-
}
|
|
19
|
-
function assertJsonCompatValue(value, path = "") {
|
|
20
|
-
var _a;
|
|
21
|
-
if (value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (typeof value === "function") {
|
|
25
|
-
throw new TypeError(
|
|
26
|
-
`Value at ${path || "root"} is a function and is not CBOR serializable`
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
if (typeof value === "symbol") {
|
|
30
|
-
throw new TypeError(
|
|
31
|
-
`Value at ${path || "root"} is a symbol and is not CBOR serializable`
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
if (value instanceof Date || value instanceof RegExp || value instanceof Error || value instanceof ArrayBuffer || value instanceof Uint8Array || isTypedArray(value)) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (value instanceof WeakMap) {
|
|
38
|
-
throw new TypeError(
|
|
39
|
-
`Value at ${path || "root"} is a WeakMap and is not CBOR serializable`
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
if (value instanceof WeakSet) {
|
|
43
|
-
throw new TypeError(
|
|
44
|
-
`Value at ${path || "root"} is a WeakSet and is not CBOR serializable`
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
if (value instanceof WeakRef) {
|
|
48
|
-
throw new TypeError(
|
|
49
|
-
`Value at ${path || "root"} is a WeakRef and is not CBOR serializable`
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
if (value instanceof Promise) {
|
|
53
|
-
throw new TypeError(
|
|
54
|
-
`Value at ${path || "root"} is a Promise and is not CBOR serializable`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
if (value instanceof Map) {
|
|
58
|
-
for (const [k, v] of value.entries()) {
|
|
59
|
-
assertJsonCompatValue(k, `${path || "root"}.key(${String(k)})`);
|
|
60
|
-
assertJsonCompatValue(v, `${path || "root"}.value(${String(k)})`);
|
|
61
|
-
}
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (value instanceof Set) {
|
|
65
|
-
let index = 0;
|
|
66
|
-
for (const item of value.values()) {
|
|
67
|
-
assertJsonCompatValue(item, `${path || "root"}.set[${index}]`);
|
|
68
|
-
index++;
|
|
69
|
-
}
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (Array.isArray(value)) {
|
|
73
|
-
for (let i = 0; i < value.length; i++) {
|
|
74
|
-
assertJsonCompatValue(value[i], `${path || "root"}[${i}]`);
|
|
75
|
-
}
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (isPlainObject(value)) {
|
|
79
|
-
for (const key in value) {
|
|
80
|
-
assertJsonCompatValue(
|
|
81
|
-
value[key],
|
|
82
|
-
path ? `${path}.${key}` : key
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const typeName = typeof value === "object" && value !== null ? _nullishCoalesce(((_a = value.constructor) == null ? void 0 : _a.name), () => ( typeof value)) : typeof value;
|
|
88
|
-
throw new TypeError(
|
|
89
|
-
`Value at ${path || "root"} of type "${typeName}" is not CBOR serializable`
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
var EncodingSchema = _v4.z.enum(["json", "cbor", "bare"]);
|
|
93
|
-
async function inputDataToBuffer(data) {
|
|
94
|
-
if (typeof data === "string") {
|
|
95
|
-
return data;
|
|
96
|
-
}
|
|
97
|
-
if (data instanceof Blob) {
|
|
98
|
-
return new Uint8Array(await data.arrayBuffer());
|
|
99
|
-
}
|
|
100
|
-
if (data instanceof Uint8Array) {
|
|
101
|
-
return data;
|
|
102
|
-
}
|
|
103
|
-
if (data instanceof ArrayBuffer || data instanceof SharedArrayBuffer) {
|
|
104
|
-
return new Uint8Array(data);
|
|
105
|
-
}
|
|
106
|
-
throw new Error("Malformed message");
|
|
107
|
-
}
|
|
108
|
-
function base64EncodeUint8Array(uint8Array) {
|
|
109
|
-
let binary = "";
|
|
110
|
-
for (const value of uint8Array) {
|
|
111
|
-
binary += String.fromCharCode(value);
|
|
112
|
-
}
|
|
113
|
-
return btoa(binary);
|
|
114
|
-
}
|
|
115
|
-
function base64EncodeArrayBuffer(arrayBuffer) {
|
|
116
|
-
return base64EncodeUint8Array(new Uint8Array(arrayBuffer));
|
|
117
|
-
}
|
|
118
|
-
function isPlainObject(value) {
|
|
119
|
-
if (value === null || typeof value !== "object") {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
const proto = Object.getPrototypeOf(value);
|
|
123
|
-
return proto === Object.prototype || proto === null;
|
|
124
|
-
}
|
|
125
|
-
function encodeJsonCompatValue(input) {
|
|
126
|
-
var _a;
|
|
127
|
-
if (input === null) {
|
|
128
|
-
return input;
|
|
129
|
-
}
|
|
130
|
-
if (input === void 0) {
|
|
131
|
-
return [JSON_COMPAT_UNDEFINED, 0];
|
|
132
|
-
}
|
|
133
|
-
if (typeof input === "string" || typeof input === "number" || typeof input === "boolean") {
|
|
134
|
-
return input;
|
|
135
|
-
}
|
|
136
|
-
if (typeof input === "bigint") {
|
|
137
|
-
return [JSON_COMPAT_BIGINT, input.toString()];
|
|
138
|
-
}
|
|
139
|
-
if (input instanceof ArrayBuffer) {
|
|
140
|
-
return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(input)];
|
|
141
|
-
}
|
|
142
|
-
if (input instanceof Uint8Array) {
|
|
143
|
-
return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(input)];
|
|
144
|
-
}
|
|
145
|
-
if (isTypedArray(input)) {
|
|
146
|
-
return input;
|
|
147
|
-
}
|
|
148
|
-
if (input instanceof Date || input instanceof RegExp || input instanceof Error) {
|
|
149
|
-
return input;
|
|
150
|
-
}
|
|
151
|
-
if (input instanceof Set) {
|
|
152
|
-
const encoded = [...input.values()].map(
|
|
153
|
-
(v) => encodeJsonCompatValue(v)
|
|
154
|
-
);
|
|
155
|
-
return [JSON_COMPAT_SET, encoded];
|
|
156
|
-
}
|
|
157
|
-
if (input instanceof Map) {
|
|
158
|
-
const encoded = /* @__PURE__ */ new Map();
|
|
159
|
-
for (const [k, v] of input.entries()) {
|
|
160
|
-
encoded.set(
|
|
161
|
-
encodeJsonCompatValue(k),
|
|
162
|
-
encodeJsonCompatValue(v)
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
return encoded;
|
|
166
|
-
}
|
|
167
|
-
if (Array.isArray(input)) {
|
|
168
|
-
const encoded = input.map(
|
|
169
|
-
(value) => encodeJsonCompatValue(value)
|
|
170
|
-
);
|
|
171
|
-
if (encoded.length === 2 && typeof encoded[0] === "string" && encoded[0].startsWith("$")) {
|
|
172
|
-
return [`$${encoded[0]}`, encoded[1]];
|
|
173
|
-
}
|
|
174
|
-
return encoded;
|
|
175
|
-
}
|
|
176
|
-
if (isPlainObject(input)) {
|
|
177
|
-
const encoded = {};
|
|
178
|
-
for (const [key, value] of Object.entries(input)) {
|
|
179
|
-
encoded[key] = encodeJsonCompatValue(value);
|
|
180
|
-
}
|
|
181
|
-
return encoded;
|
|
182
|
-
}
|
|
183
|
-
const typeName = typeof input === "object" && input !== null ? _nullishCoalesce(((_a = input.constructor) == null ? void 0 : _a.name), () => ( typeof input)) : typeof input;
|
|
184
|
-
throw new TypeError(`Value of type "${typeName}" is not CBOR serializable`);
|
|
185
|
-
}
|
|
186
|
-
function reviveJsonCompatValue(input, options = {}) {
|
|
187
|
-
if (typeof input === "bigint") {
|
|
188
|
-
if (options.coerceSafeIntegerBigInts && input >= BigInt(Number.MIN_SAFE_INTEGER) && input <= BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
189
|
-
return Number(input);
|
|
190
|
-
}
|
|
191
|
-
return input;
|
|
192
|
-
}
|
|
193
|
-
if (input instanceof Map) {
|
|
194
|
-
const revived = /* @__PURE__ */ new Map();
|
|
195
|
-
for (const [k, v] of input.entries()) {
|
|
196
|
-
revived.set(
|
|
197
|
-
reviveJsonCompatValue(k, options),
|
|
198
|
-
reviveJsonCompatValue(v, options)
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
return revived;
|
|
202
|
-
}
|
|
203
|
-
if (Array.isArray(input)) {
|
|
204
|
-
if (input.length === 2 && typeof input[0] === "string" && input[0].startsWith("$")) {
|
|
205
|
-
if (input[0] === JSON_COMPAT_BIGINT) {
|
|
206
|
-
return BigInt(input[1]);
|
|
207
|
-
}
|
|
208
|
-
if (input[0] === JSON_COMPAT_ARRAY_BUFFER) {
|
|
209
|
-
return base64DecodeToArrayBuffer(input[1]);
|
|
210
|
-
}
|
|
211
|
-
if (input[0] === JSON_COMPAT_UINT8_ARRAY) {
|
|
212
|
-
return base64DecodeToUint8Array(input[1]);
|
|
213
|
-
}
|
|
214
|
-
if (input[0] === JSON_COMPAT_UNDEFINED) {
|
|
215
|
-
return void 0;
|
|
216
|
-
}
|
|
217
|
-
if (input[0] === JSON_COMPAT_SET) {
|
|
218
|
-
const items = input[1].map(
|
|
219
|
-
(v) => reviveJsonCompatValue(v, options)
|
|
220
|
-
);
|
|
221
|
-
return new Set(items);
|
|
222
|
-
}
|
|
223
|
-
if (input[0].startsWith("$$")) {
|
|
224
|
-
return [
|
|
225
|
-
input[0].substring(1),
|
|
226
|
-
reviveJsonCompatValue(input[1], options)
|
|
227
|
-
];
|
|
228
|
-
}
|
|
229
|
-
throw new Error(
|
|
230
|
-
`Unknown JSON encoding type: ${input[0]}. This may indicate corrupted data or a version mismatch.`
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
return input.map((value) => reviveJsonCompatValue(value, options));
|
|
234
|
-
}
|
|
235
|
-
if (isPlainObject(input)) {
|
|
236
|
-
const decoded = {};
|
|
237
|
-
for (const [key, value] of Object.entries(input)) {
|
|
238
|
-
decoded[key] = reviveJsonCompatValue(value, options);
|
|
239
|
-
}
|
|
240
|
-
return decoded;
|
|
241
|
-
}
|
|
242
|
-
return input;
|
|
243
|
-
}
|
|
244
|
-
function base64DecodeToUint8Array(base64) {
|
|
245
|
-
if (typeof Buffer !== "undefined") {
|
|
246
|
-
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
247
|
-
}
|
|
248
|
-
const binary = atob(base64);
|
|
249
|
-
const bytes = new Uint8Array(binary.length);
|
|
250
|
-
for (let i = 0; i < binary.length; i++) {
|
|
251
|
-
bytes[i] = binary.charCodeAt(i);
|
|
252
|
-
}
|
|
253
|
-
return bytes;
|
|
254
|
-
}
|
|
255
|
-
function base64DecodeToArrayBuffer(base64) {
|
|
256
|
-
return base64DecodeToUint8Array(base64).buffer;
|
|
257
|
-
}
|
|
258
|
-
function jsonStringifyCompat(input) {
|
|
259
|
-
return JSON.stringify(input, (_key, value) => {
|
|
260
|
-
if (typeof value === "bigint") {
|
|
261
|
-
return [JSON_COMPAT_BIGINT, value.toString()];
|
|
262
|
-
}
|
|
263
|
-
if (value instanceof ArrayBuffer) {
|
|
264
|
-
return [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(value)];
|
|
265
|
-
}
|
|
266
|
-
if (value instanceof Uint8Array) {
|
|
267
|
-
return [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(value)];
|
|
268
|
-
}
|
|
269
|
-
if (Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && value[0].startsWith("$")) {
|
|
270
|
-
return [`$${value[0]}`, value[1]];
|
|
271
|
-
}
|
|
272
|
-
return value;
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
function jsonParseCompat(input) {
|
|
276
|
-
return reviveJsonCompatValue(JSON.parse(input));
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// src/serde.ts
|
|
280
|
-
function uint8ArrayToBase64(uint8Array) {
|
|
281
|
-
if (typeof Buffer !== "undefined") {
|
|
282
|
-
return Buffer.from(uint8Array).toString("base64");
|
|
283
|
-
}
|
|
284
|
-
let binary = "";
|
|
285
|
-
const len = uint8Array.byteLength;
|
|
286
|
-
for (let i = 0; i < len; i++) {
|
|
287
|
-
binary += String.fromCharCode(uint8Array[i]);
|
|
288
|
-
}
|
|
289
|
-
return btoa(binary);
|
|
290
|
-
}
|
|
291
|
-
function contentTypeForEncoding(encoding) {
|
|
292
|
-
if (encoding === "json") {
|
|
293
|
-
return "application/json";
|
|
294
|
-
} else if (encoding === "cbor" || encoding === "bare") {
|
|
295
|
-
return "application/octet-stream";
|
|
296
|
-
} else {
|
|
297
|
-
_chunkQ7NBMTF3cjs.assertUnreachable.call(void 0, encoding);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
function encodeCborCompat(value) {
|
|
301
|
-
return cbor.encode(encodeJsonCompatValue(value));
|
|
302
|
-
}
|
|
303
|
-
function decodeCborCompat(buffer) {
|
|
304
|
-
return reviveJsonCompatValue(cbor.decode(buffer));
|
|
305
|
-
}
|
|
306
|
-
function serializeWithEncoding(encoding, value, versionedDataHandler, version, zodSchema, toJson, toBare) {
|
|
307
|
-
if (encoding === "json") {
|
|
308
|
-
const jsonValue = toJson(value);
|
|
309
|
-
const validated = zodSchema.parse(jsonValue);
|
|
310
|
-
return jsonStringifyCompat(validated);
|
|
311
|
-
} else if (encoding === "cbor") {
|
|
312
|
-
const jsonValue = toJson(value);
|
|
313
|
-
const validated = zodSchema.parse(jsonValue);
|
|
314
|
-
return cbor.encode(validated);
|
|
315
|
-
} else if (encoding === "bare") {
|
|
316
|
-
if (!versionedDataHandler) {
|
|
317
|
-
throw new Error(
|
|
318
|
-
"VersionedDataHandler is required for 'bare' encoding"
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
if (version === void 0) {
|
|
322
|
-
throw new Error("version is required for 'bare' encoding");
|
|
323
|
-
}
|
|
324
|
-
const bareValue = toBare(value);
|
|
325
|
-
return versionedDataHandler.serializeWithEmbeddedVersion(
|
|
326
|
-
bareValue,
|
|
327
|
-
version
|
|
328
|
-
);
|
|
329
|
-
} else {
|
|
330
|
-
_chunkQ7NBMTF3cjs.assertUnreachable.call(void 0, encoding);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
function deserializeWithEncoding(encoding, buffer, versionedDataHandler, zodSchema, fromJson, fromBare) {
|
|
334
|
-
if (encoding === "json") {
|
|
335
|
-
let parsed;
|
|
336
|
-
if (typeof buffer === "string") {
|
|
337
|
-
parsed = jsonParseCompat(buffer);
|
|
338
|
-
} else {
|
|
339
|
-
const decoder = new TextDecoder("utf-8");
|
|
340
|
-
const jsonString = decoder.decode(buffer);
|
|
341
|
-
parsed = jsonParseCompat(jsonString);
|
|
342
|
-
}
|
|
343
|
-
const validated = zodSchema.parse(parsed);
|
|
344
|
-
return fromJson(validated);
|
|
345
|
-
} else if (encoding === "cbor") {
|
|
346
|
-
_invariant2.default.call(void 0,
|
|
347
|
-
typeof buffer !== "string",
|
|
348
|
-
"buffer cannot be string for cbor encoding"
|
|
349
|
-
);
|
|
350
|
-
const decoded = decodeCborCompat(buffer);
|
|
351
|
-
const validated = zodSchema.parse(decoded);
|
|
352
|
-
return fromJson(validated);
|
|
353
|
-
} else if (encoding === "bare") {
|
|
354
|
-
_invariant2.default.call(void 0,
|
|
355
|
-
typeof buffer !== "string",
|
|
356
|
-
"buffer cannot be string for bare encoding"
|
|
357
|
-
);
|
|
358
|
-
if (!versionedDataHandler) {
|
|
359
|
-
throw new Error(
|
|
360
|
-
"VersionedDataHandler is required for 'bare' encoding"
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
const bareValue = versionedDataHandler.deserializeWithEmbeddedVersion(buffer);
|
|
364
|
-
return fromBare(bareValue);
|
|
365
|
-
} else {
|
|
366
|
-
_chunkQ7NBMTF3cjs.assertUnreachable.call(void 0, encoding);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
exports.uint8ArrayToBase64 = uint8ArrayToBase64; exports.contentTypeForEncoding = contentTypeForEncoding; exports.encodeCborCompat = encodeCborCompat; exports.decodeCborCompat = decodeCborCompat; exports.serializeWithEncoding = serializeWithEncoding; exports.deserializeWithEncoding = deserializeWithEncoding; exports.assertJsonCompatValue = assertJsonCompatValue; exports.EncodingSchema = EncodingSchema; exports.inputDataToBuffer = inputDataToBuffer; exports.jsonStringifyCompat = jsonStringifyCompat;
|
|
382
|
-
//# sourceMappingURL=chunk-Z7PSQWMC.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/chunk-Z7PSQWMC.cjs","../../src/serde.ts","../../src/common/encoding.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,2EAAsB;AACtB,4FAAsB;ADMtB;AACA;AEPA,4BAAkB;AAUlB,IAAM,mBAAA,EAAqB,SAAA;AAC3B,IAAM,yBAAA,EAA2B,cAAA;AACjC,IAAM,wBAAA,EAA0B,aAAA;AAChC,IAAM,sBAAA,EAAwB,YAAA;AAC9B,IAAM,gBAAA,EAAkB,MAAA;AA0CxB,SAAS,YAAA,CAAa,KAAA,EAAyB;AAC9C,EAAA,OACC,MAAA,WAAiB,kBAAA,GACjB,MAAA,WAAiB,YAAA,GACjB,MAAA,WAAiB,YAAA,GACjB,MAAA,WAAiB,eAAA,GACjB,MAAA,WAAiB,UAAA,GACjB,MAAA,WAAiB,WAAA,GACjB,MAAA,WAAiB,WAAA,GACjB,MAAA,WAAiB,cAAA,GACjB,MAAA,WAAiB,aAAA,GACjB,MAAA,WAAiB,YAAA;AAEnB;AAMO,SAAS,qBAAA,CACf,KAAA,EACA,KAAA,EAAO,EAAA,EAC4B;AA/EpC,EAAA,IAAA,EAAA;AAgFC,EAAA,GAAA,CACC,MAAA,IAAU,KAAA,GACV,MAAA,IAAU,KAAA,EAAA,GACV,OAAO,MAAA,IAAU,SAAA,GACjB,OAAO,MAAA,IAAU,SAAA,GACjB,OAAO,MAAA,IAAU,UAAA,GACjB,OAAO,MAAA,IAAU,QAAA,EAChB;AACD,IAAA,MAAA;AAAA,EACD;AAEA,EAAA,GAAA,CAAI,OAAO,MAAA,IAAU,UAAA,EAAY;AAChC,IAAA,MAAM,IAAI,SAAA;AAAA,MACT,CAAA,SAAA,EAAY,KAAA,GAAQ,MAAM,CAAA,2CAAA;AAAA,IAC3B,CAAA;AAAA,EACD;AAEA,EAAA,GAAA,CAAI,OAAO,MAAA,IAAU,QAAA,EA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A;AACpB,EAAA;AAGa,EAAA;AACU,EAAA;AACO,EAAA;AACZ,IAAA;AAClB,EAAA;AACkB,EAAA;AACnB;AAYuC;AACb,EAAA;AACjB,IAAA;AACgB,EAAA;AAChB,IAAA;AACD,EAAA;AACoB,IAAA;AAC3B,EAAA;AACD;AAEiC;AACb,EAAA;AACpB;AAEoC;AACD,EAAA;AACnC;AAqBC;AAQyB,EAAA;AACC,IAAA;AACG,IAAA;AACD,IAAA;AACJ,EAAA;AACE,IAAA;AACG,IAAA;AACA,IAAA;AACL,EAAA;AACI,IAAA;AAChB,MAAA;AACT,QAAA;AACD,MAAA;AACD,IAAA;AAC2B,IAAA;AACV,MAAA;AACjB,IAAA;AACyB,IAAA;AACG,IAAA;AAC3B,MAAA;AACA,MAAA;AACD,IAAA;AACM,EAAA;AACoB,IAAA;AAC3B,EAAA;AACD;AAEgB;AAQU,EAAA;AACpB,IAAA;AACkB,IAAA;AACI,MAAA;AACnB,IAAA;AACc,MAAA;AACD,MAAA;AACM,MAAA;AAC1B,IAAA;AAC4B,IAAA;AACH,IAAA;AACF,EAAA;AACvB,IAAA;AACmB,MAAA;AAClB,MAAA;AACD,IAAA;AAEgB,IAAA;AAEY,IAAA;AAEH,IAAA;AACF,EAAA;AACvB,IAAA;AACmB,MAAA;AAClB,MAAA;AACD,IAAA;AAC2B,IAAA;AAChB,MAAA;AACT,QAAA;AACD,MAAA;AACD,IAAA;AAEC,IAAA;AACwB,IAAA;AACnB,EAAA;AACoB,IAAA;AAC3B,EAAA;AACD;ADoNgC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/chunk-Z7PSQWMC.cjs","sourcesContent":[null,"import * as cbor from \"cbor-x\";\nimport invariant from \"invariant\";\nimport type { VersionedDataHandler } from \"vbare\";\nimport type { z } from \"zod/v4\";\nimport type { Encoding, JsonCompatValue } from \"@/common/encoding\";\nimport { assertUnreachable } from \"@/common/utils\";\nimport {\n\tencodeJsonCompatValue,\n\tjsonParseCompat,\n\tjsonStringifyCompat,\n\treviveJsonCompatValue,\n} from \"./common/encoding\";\n\nexport function uint8ArrayToBase64(uint8Array: Uint8Array): string {\n\t// Check if Buffer is available (Node.js)\n\tif (typeof Buffer !== \"undefined\") {\n\t\treturn Buffer.from(uint8Array).toString(\"base64\");\n\t}\n\n\t// Browser environment - use btoa\n\tlet binary = \"\";\n\tconst len = uint8Array.byteLength;\n\tfor (let i = 0; i < len; i++) {\n\t\tbinary += String.fromCharCode(uint8Array[i]);\n\t}\n\treturn btoa(binary);\n}\n\nexport function encodingIsBinary(encoding: Encoding): boolean {\n\tif (encoding === \"json\") {\n\t\treturn false;\n\t} else if (encoding === \"cbor\" || encoding === \"bare\") {\n\t\treturn true;\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n\nexport function contentTypeForEncoding(encoding: Encoding): string {\n\tif (encoding === \"json\") {\n\t\treturn \"application/json\";\n\t} else if (encoding === \"cbor\" || encoding === \"bare\") {\n\t\treturn \"application/octet-stream\";\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n\nexport function encodeCborCompat(value: JsonCompatValue): Uint8Array {\n\treturn cbor.encode(encodeJsonCompatValue(value));\n}\n\nexport function decodeCborCompat<T>(buffer: Uint8Array): T {\n\treturn reviveJsonCompatValue(cbor.decode(buffer)) as T;\n}\n\nexport function decodeCborJsonCompat<T>(buffer: Uint8Array): T {\n\treturn reviveJsonCompatValue(cbor.decode(buffer), {\n\t\tcoerceSafeIntegerBigInts: true,\n\t}) as T;\n}\n\nexport function wsBinaryTypeForEncoding(\n\tencoding: Encoding,\n): \"arraybuffer\" | \"blob\" {\n\tif (encoding === \"json\") {\n\t\treturn \"blob\";\n\t} else if (encoding === \"cbor\" || encoding === \"bare\") {\n\t\treturn \"arraybuffer\";\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n\nexport function serializeWithEncoding<TBare, TJson, T = TBare>(\n\tencoding: Encoding,\n\tvalue: T,\n\tversionedDataHandler: VersionedDataHandler<TBare> | undefined,\n\tversion: number | undefined,\n\tzodSchema: z.ZodType<TJson>,\n\ttoJson: (value: T) => TJson,\n\ttoBare: (value: T) => TBare,\n): Uint8Array | string {\n\tif (encoding === \"json\") {\n\t\tconst jsonValue = toJson(value);\n\t\tconst validated = zodSchema.parse(jsonValue);\n\t\treturn jsonStringifyCompat(validated);\n\t} else if (encoding === \"cbor\") {\n\t\tconst jsonValue = toJson(value);\n\t\tconst validated = zodSchema.parse(jsonValue);\n\t\treturn cbor.encode(validated);\n\t} else if (encoding === \"bare\") {\n\t\tif (!versionedDataHandler) {\n\t\t\tthrow new Error(\n\t\t\t\t\"VersionedDataHandler is required for 'bare' encoding\",\n\t\t\t);\n\t\t}\n\t\tif (version === undefined) {\n\t\t\tthrow new Error(\"version is required for 'bare' encoding\");\n\t\t}\n\t\tconst bareValue = toBare(value);\n\t\treturn versionedDataHandler.serializeWithEmbeddedVersion(\n\t\t\tbareValue,\n\t\t\tversion,\n\t\t);\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n\nexport function deserializeWithEncoding<TBare, TJson, T = TBare>(\n\tencoding: Encoding,\n\tbuffer: Uint8Array | string,\n\tversionedDataHandler: VersionedDataHandler<TBare> | undefined,\n\tzodSchema: z.ZodType<TJson>,\n\tfromJson: (value: TJson) => T,\n\tfromBare: (value: TBare) => T,\n): T {\n\tif (encoding === \"json\") {\n\t\tlet parsed: unknown;\n\t\tif (typeof buffer === \"string\") {\n\t\t\tparsed = jsonParseCompat(buffer);\n\t\t} else {\n\t\t\tconst decoder = new TextDecoder(\"utf-8\");\n\t\t\tconst jsonString = decoder.decode(buffer);\n\t\t\tparsed = jsonParseCompat(jsonString);\n\t\t}\n\t\tconst validated = zodSchema.parse(parsed);\n\t\treturn fromJson(validated);\n\t} else if (encoding === \"cbor\") {\n\t\tinvariant(\n\t\t\ttypeof buffer !== \"string\",\n\t\t\t\"buffer cannot be string for cbor encoding\",\n\t\t);\n\t\t// Decode CBOR to get JavaScript values (similar to JSON.parse)\n\t\tconst decoded = decodeCborCompat(buffer);\n\t\t// Validate with Zod schema (CBOR produces same structure as JSON)\n\t\tconst validated = zodSchema.parse(decoded);\n\t\t// CBOR decoding produces JS objects, use fromJson\n\t\treturn fromJson(validated);\n\t} else if (encoding === \"bare\") {\n\t\tinvariant(\n\t\t\ttypeof buffer !== \"string\",\n\t\t\t\"buffer cannot be string for bare encoding\",\n\t\t);\n\t\tif (!versionedDataHandler) {\n\t\t\tthrow new Error(\n\t\t\t\t\"VersionedDataHandler is required for 'bare' encoding\",\n\t\t\t);\n\t\t}\n\t\tconst bareValue =\n\t\t\tversionedDataHandler.deserializeWithEmbeddedVersion(buffer);\n\t\treturn fromBare(bareValue);\n\t} else {\n\t\tassertUnreachable(encoding);\n\t}\n}\n","import type { VersionedDataHandler } from \"vbare\";\nimport { z } from \"zod/v4\";\nimport { serializeWithEncoding } from \"@/serde\";\nimport { assertUnreachable } from \"./utils\";\n\n/** Data that can be deserialized. */\nexport type InputData = string | Buffer | Blob | ArrayBufferLike | Uint8Array;\n\n/** Data that's been serialized. */\nexport type OutputData = string | Uint8Array;\n\nconst JSON_COMPAT_BIGINT = \"$BigInt\";\nconst JSON_COMPAT_ARRAY_BUFFER = \"$ArrayBuffer\";\nconst JSON_COMPAT_UINT8_ARRAY = \"$Uint8Array\";\nconst JSON_COMPAT_UNDEFINED = \"$Undefined\";\nconst JSON_COMPAT_SET = \"$Set\";\n\n/**\n * Types that cbor-x encodes natively without any compat transforms.\n */\nexport type CborSerializable =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| undefined\n\t| bigint\n\t| Date\n\t| RegExp\n\t| Error\n\t| ArrayBuffer\n\t| Uint8Array\n\t| Uint8ClampedArray\n\t| Uint16Array\n\t| Uint32Array\n\t| BigUint64Array\n\t| Int8Array\n\t| Int16Array\n\t| Int32Array\n\t| BigInt64Array\n\t| Float32Array\n\t| Float64Array\n\t| CborSerializable[]\n\t| Map<CborSerializable, CborSerializable>\n\t| { [key: string]: CborSerializable };\n\n/**\n * User-facing serializable type. Extends CborSerializable with Set (encoded\n * as a `$Set` tagged array by the JSON compat layer).\n */\nexport type JsonCompatValue =\n\t| CborSerializable\n\t| Set<JsonCompatValue>\n\t| JsonCompatValue[]\n\t| Map<JsonCompatValue, JsonCompatValue>\n\t| { [key: string]: JsonCompatValue };\n\nfunction isTypedArray(value: unknown): boolean {\n\treturn (\n\t\tvalue instanceof Uint8ClampedArray ||\n\t\tvalue instanceof Uint16Array ||\n\t\tvalue instanceof Uint32Array ||\n\t\tvalue instanceof BigUint64Array ||\n\t\tvalue instanceof Int8Array ||\n\t\tvalue instanceof Int16Array ||\n\t\tvalue instanceof Int32Array ||\n\t\tvalue instanceof BigInt64Array ||\n\t\tvalue instanceof Float32Array ||\n\t\tvalue instanceof Float64Array\n\t);\n}\n\n/**\n * Recursively validates that a value is CBOR serializable. Throws TypeError\n * with a descriptive message for non-serializable values.\n */\nexport function assertJsonCompatValue(\n\tvalue: unknown,\n\tpath = \"\",\n): asserts value is JsonCompatValue {\n\tif (\n\t\tvalue === null ||\n\t\tvalue === undefined ||\n\t\ttypeof value === \"string\" ||\n\t\ttypeof value === \"number\" ||\n\t\ttypeof value === \"boolean\" ||\n\t\ttypeof value === \"bigint\"\n\t) {\n\t\treturn;\n\t}\n\n\tif (typeof value === \"function\") {\n\t\tthrow new TypeError(\n\t\t\t`Value at ${path || \"root\"} is a function and is not CBOR serializable`,\n\t\t);\n\t}\n\n\tif (typeof value === \"symbol\") {\n\t\tthrow new TypeError(\n\t\t\t`Value at ${path || \"root\"} is a symbol and is not CBOR serializable`,\n\t\t);\n\t}\n\n\tif (\n\t\tvalue instanceof Date ||\n\t\tvalue instanceof RegExp ||\n\t\tvalue instanceof Error ||\n\t\tvalue instanceof ArrayBuffer ||\n\t\tvalue instanceof Uint8Array ||\n\t\tisTypedArray(value)\n\t) {\n\t\treturn;\n\t}\n\n\tif (value instanceof WeakMap) {\n\t\tthrow new TypeError(\n\t\t\t`Value at ${path || \"root\"} is a WeakMap and is not CBOR serializable`,\n\t\t);\n\t}\n\n\tif (value instanceof WeakSet) {\n\t\tthrow new TypeError(\n\t\t\t`Value at ${path || \"root\"} is a WeakSet and is not CBOR serializable`,\n\t\t);\n\t}\n\n\tif (value instanceof WeakRef) {\n\t\tthrow new TypeError(\n\t\t\t`Value at ${path || \"root\"} is a WeakRef and is not CBOR serializable`,\n\t\t);\n\t}\n\n\tif (value instanceof Promise) {\n\t\tthrow new TypeError(\n\t\t\t`Value at ${path || \"root\"} is a Promise and is not CBOR serializable`,\n\t\t);\n\t}\n\n\tif (value instanceof Map) {\n\t\tfor (const [k, v] of value.entries()) {\n\t\t\tassertJsonCompatValue(k, `${path || \"root\"}.key(${String(k)})`);\n\t\t\tassertJsonCompatValue(v, `${path || \"root\"}.value(${String(k)})`);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (value instanceof Set) {\n\t\tlet index = 0;\n\t\tfor (const item of value.values()) {\n\t\t\tassertJsonCompatValue(item, `${path || \"root\"}.set[${index}]`);\n\t\t\tindex++;\n\t\t}\n\t\treturn;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tfor (let i = 0; i < value.length; i++) {\n\t\t\tassertJsonCompatValue(value[i], `${path || \"root\"}[${i}]`);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (isPlainObject(value)) {\n\t\tfor (const key in value) {\n\t\t\tassertJsonCompatValue(\n\t\t\t\tvalue[key as keyof typeof value],\n\t\t\t\tpath ? `${path}.${key}` : key,\n\t\t\t);\n\t\t}\n\t\treturn;\n\t}\n\n\tconst typeName =\n\t\ttypeof value === \"object\" && value !== null\n\t\t\t? (value.constructor?.name ?? typeof value)\n\t\t\t: typeof value;\n\tthrow new TypeError(\n\t\t`Value at ${path || \"root\"} of type \"${typeName}\" is not CBOR serializable`,\n\t);\n}\n\nexport const EncodingSchema = z.enum([\"json\", \"cbor\", \"bare\"]);\n\n/**\n * Encoding used to communicate between the client & actor.\n */\nexport type Encoding = z.infer<typeof EncodingSchema>;\n\n/**\n * Helper class that helps serialize data without re-serializing for the same encoding.\n */\nexport class CachedSerializer<TBare, TJson, T = TBare> {\n\t#data: T;\n\t#cache = new Map<Encoding, OutputData>();\n\t#versionedDataHandler: VersionedDataHandler<TBare>;\n\t#version: number;\n\t#zodSchema: z.ZodType<TJson>;\n\t#toJson: (value: T) => TJson;\n\t#toBare: (value: T) => TBare;\n\n\tconstructor(\n\t\tdata: T,\n\t\tversionedDataHandler: VersionedDataHandler<TBare>,\n\t\tversion: number,\n\t\tzodSchema: z.ZodType<TJson>,\n\t\ttoJson: (value: T) => TJson,\n\t\ttoBare: (value: T) => TBare,\n\t) {\n\t\tthis.#data = data;\n\t\tthis.#versionedDataHandler = versionedDataHandler;\n\t\tthis.#version = version;\n\t\tthis.#zodSchema = zodSchema;\n\t\tthis.#toJson = toJson;\n\t\tthis.#toBare = toBare;\n\t}\n\n\tpublic get rawData(): T {\n\t\treturn this.#data;\n\t}\n\n\tpublic serialize(encoding: Encoding): OutputData {\n\t\tconst cached = this.#cache.get(encoding);\n\t\tif (cached) {\n\t\t\treturn cached;\n\t\t}\n\n\t\tconst serialized = serializeWithEncoding(\n\t\t\tencoding,\n\t\t\tthis.#data,\n\t\t\tthis.#versionedDataHandler,\n\t\t\tthis.#version,\n\t\t\tthis.#zodSchema,\n\t\t\tthis.#toJson,\n\t\t\tthis.#toBare,\n\t\t);\n\t\tthis.#cache.set(encoding, serialized);\n\t\treturn serialized;\n\t}\n}\n\nexport async function inputDataToBuffer(\n\tdata: InputData,\n): Promise<Uint8Array | string> {\n\tif (typeof data === \"string\") {\n\t\treturn data;\n\t}\n\tif (data instanceof Blob) {\n\t\treturn new Uint8Array(await data.arrayBuffer());\n\t}\n\tif (data instanceof Uint8Array) {\n\t\treturn data;\n\t}\n\tif (data instanceof ArrayBuffer || data instanceof SharedArrayBuffer) {\n\t\treturn new Uint8Array(data);\n\t}\n\tthrow new Error(\"Malformed message\");\n}\n\nfunction base64EncodeUint8Array(uint8Array: Uint8Array): string {\n\tlet binary = \"\";\n\tfor (const value of uint8Array) {\n\t\tbinary += String.fromCharCode(value);\n\t}\n\treturn btoa(binary);\n}\n\nfunction base64EncodeArrayBuffer(arrayBuffer: ArrayBuffer): string {\n\treturn base64EncodeUint8Array(new Uint8Array(arrayBuffer));\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn false;\n\t}\n\n\tconst proto = Object.getPrototypeOf(value);\n\treturn proto === Object.prototype || proto === null;\n}\n\nexport function encodeJsonCompatValue(input: JsonCompatValue): unknown {\n\t// Primitives\n\tif (input === null) {\n\t\treturn input;\n\t}\n\tif (input === undefined) {\n\t\treturn [JSON_COMPAT_UNDEFINED, 0];\n\t}\n\tif (\n\t\ttypeof input === \"string\" ||\n\t\ttypeof input === \"number\" ||\n\t\ttypeof input === \"boolean\"\n\t) {\n\t\treturn input;\n\t}\n\tif (typeof input === \"bigint\") {\n\t\treturn [JSON_COMPAT_BIGINT, input.toString()];\n\t}\n\n\t// Binary types with custom encoding\n\tif (input instanceof ArrayBuffer) {\n\t\treturn [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(input)];\n\t}\n\tif (input instanceof Uint8Array) {\n\t\treturn [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(input)];\n\t}\n\n\t// TypedArrays pass through for cbor-x native handling\n\tif (isTypedArray(input)) {\n\t\treturn input;\n\t}\n\n\t// Date, RegExp, and Error pass through for cbor-x native handling\n\tif (\n\t\tinput instanceof Date ||\n\t\tinput instanceof RegExp ||\n\t\tinput instanceof Error\n\t) {\n\t\treturn input;\n\t}\n\n\t// Set uses custom tag encoding\n\tif (input instanceof Set) {\n\t\tconst encoded = [...input.values()].map((v) =>\n\t\t\tencodeJsonCompatValue(v as JsonCompatValue),\n\t\t);\n\t\treturn [JSON_COMPAT_SET, encoded];\n\t}\n\n\t// Map recurses into keys and values\n\tif (input instanceof Map) {\n\t\tconst encoded = new Map<unknown, unknown>();\n\t\tfor (const [k, v] of input.entries()) {\n\t\t\tencoded.set(\n\t\t\t\tencodeJsonCompatValue(k as JsonCompatValue),\n\t\t\t\tencodeJsonCompatValue(v as JsonCompatValue),\n\t\t\t);\n\t\t}\n\t\treturn encoded;\n\t}\n\n\t// Arrays\n\tif (Array.isArray(input)) {\n\t\tconst encoded = input.map((value) =>\n\t\t\tencodeJsonCompatValue(value as JsonCompatValue),\n\t\t);\n\t\tif (\n\t\t\tencoded.length === 2 &&\n\t\t\ttypeof encoded[0] === \"string\" &&\n\t\t\t(encoded[0] as string).startsWith(\"$\")\n\t\t) {\n\t\t\treturn [`$${encoded[0]}`, encoded[1]];\n\t\t}\n\t\treturn encoded;\n\t}\n\n\t// Plain objects\n\tif (isPlainObject(input)) {\n\t\tconst encoded: Record<string, unknown> = {};\n\t\tfor (const [key, value] of Object.entries(input)) {\n\t\t\tencoded[key] = encodeJsonCompatValue(value as JsonCompatValue);\n\t\t}\n\t\treturn encoded;\n\t}\n\n\t// Not serializable\n\tconst typeName =\n\t\ttypeof input === \"object\" && input !== null\n\t\t\t? ((input as object).constructor?.name ?? typeof input)\n\t\t\t: typeof input;\n\tthrow new TypeError(`Value of type \"${typeName}\" is not CBOR serializable`);\n}\n\nexport interface JsonCompatReviveOptions {\n\tcoerceSafeIntegerBigInts?: boolean;\n}\n\nexport function reviveJsonCompatValue(\n\tinput: any,\n\toptions: JsonCompatReviveOptions = {},\n): any {\n\tif (typeof input === \"bigint\") {\n\t\tif (\n\t\t\toptions.coerceSafeIntegerBigInts &&\n\t\t\tinput >= BigInt(Number.MIN_SAFE_INTEGER) &&\n\t\t\tinput <= BigInt(Number.MAX_SAFE_INTEGER)\n\t\t) {\n\t\t\treturn Number(input);\n\t\t}\n\t\treturn input;\n\t}\n\tif (input instanceof Map) {\n\t\tconst revived = new Map();\n\t\tfor (const [k, v] of input.entries()) {\n\t\t\trevived.set(\n\t\t\t\treviveJsonCompatValue(k, options),\n\t\t\t\treviveJsonCompatValue(v, options),\n\t\t\t);\n\t\t}\n\t\treturn revived;\n\t}\n\tif (Array.isArray(input)) {\n\t\tif (\n\t\t\tinput.length === 2 &&\n\t\t\ttypeof input[0] === \"string\" &&\n\t\t\tinput[0].startsWith(\"$\")\n\t\t) {\n\t\t\tif (input[0] === JSON_COMPAT_BIGINT) {\n\t\t\t\treturn BigInt(input[1]);\n\t\t\t}\n\t\t\tif (input[0] === JSON_COMPAT_ARRAY_BUFFER) {\n\t\t\t\treturn base64DecodeToArrayBuffer(input[1]);\n\t\t\t}\n\t\t\tif (input[0] === JSON_COMPAT_UINT8_ARRAY) {\n\t\t\t\treturn base64DecodeToUint8Array(input[1]);\n\t\t\t}\n\t\t\tif (input[0] === JSON_COMPAT_UNDEFINED) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (input[0] === JSON_COMPAT_SET) {\n\t\t\t\tconst items = (input[1] as unknown[]).map((v) =>\n\t\t\t\t\treviveJsonCompatValue(v, options),\n\t\t\t\t);\n\t\t\t\treturn new Set(items);\n\t\t\t}\n\t\t\tif (input[0].startsWith(\"$$\")) {\n\t\t\t\treturn [\n\t\t\t\t\tinput[0].substring(1),\n\t\t\t\t\treviveJsonCompatValue(input[1], options),\n\t\t\t\t];\n\t\t\t}\n\t\t\tthrow new Error(\n\t\t\t\t`Unknown JSON encoding type: ${input[0]}. This may indicate corrupted data or a version mismatch.`,\n\t\t\t);\n\t\t}\n\t\treturn input.map((value) => reviveJsonCompatValue(value, options));\n\t}\n\tif (isPlainObject(input)) {\n\t\tconst decoded: Record<string, unknown> = {};\n\t\tfor (const [key, value] of Object.entries(input)) {\n\t\t\tdecoded[key] = reviveJsonCompatValue(value, options);\n\t\t}\n\t\treturn decoded;\n\t}\n\treturn input;\n}\n\n/** Converts data that was encoded to a string. Some formats do not support raw binary data. */\nexport function encodeDataToString(message: OutputData): string {\n\tif (typeof message === \"string\") {\n\t\treturn message;\n\t}\n\tif (message instanceof Uint8Array) {\n\t\treturn base64EncodeUint8Array(message);\n\t}\n\tassertUnreachable(message);\n}\n\nfunction base64DecodeToUint8Array(base64: string): Uint8Array {\n\tif (typeof Buffer !== \"undefined\") {\n\t\treturn new Uint8Array(Buffer.from(base64, \"base64\"));\n\t}\n\n\tconst binary = atob(base64);\n\tconst bytes = new Uint8Array(binary.length);\n\tfor (let i = 0; i < binary.length; i++) {\n\t\tbytes[i] = binary.charCodeAt(i);\n\t}\n\treturn bytes;\n}\n\nfunction base64DecodeToArrayBuffer(base64: string): ArrayBuffer {\n\treturn base64DecodeToUint8Array(base64).buffer as ArrayBuffer;\n}\n\n/** Stringifies with compat for values that BARE & CBOR supports. */\nexport function jsonStringifyCompat(input: any): string {\n\treturn JSON.stringify(input, (_key, value) => {\n\t\tif (typeof value === \"bigint\") {\n\t\t\treturn [JSON_COMPAT_BIGINT, value.toString()];\n\t\t}\n\t\tif (value instanceof ArrayBuffer) {\n\t\t\treturn [JSON_COMPAT_ARRAY_BUFFER, base64EncodeArrayBuffer(value)];\n\t\t}\n\t\tif (value instanceof Uint8Array) {\n\t\t\treturn [JSON_COMPAT_UINT8_ARRAY, base64EncodeUint8Array(value)];\n\t\t}\n\t\tif (\n\t\t\tArray.isArray(value) &&\n\t\t\tvalue.length === 2 &&\n\t\t\ttypeof value[0] === \"string\" &&\n\t\t\tvalue[0].startsWith(\"$\")\n\t\t) {\n\t\t\treturn [`$${value[0]}`, value[1]];\n\t\t}\n\t\treturn value;\n\t});\n}\n\n/** Parses JSON with compat for values that BARE & CBOR supports. */\nexport function jsonParseCompat(input: string): any {\n\treturn reviveJsonCompatValue(JSON.parse(input));\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/chunk-ZA7FLHKH.cjs","../../src/common/database/shared.ts"],"names":[],"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AAI,KAAA;AAAA,UACT,CAAA,iCAAA,EAAoC,OAAO,KAAK,CAAA;AAAA,QAAA;AACjD,MAAA;AACD,IAAA;AAED,IAAA;AAAO,EAAA;AAGR,EAAA;AACC,IAAA;AAAO,EAAA;AAGR,EAAA;AACD;AAKO;AAAiB,EAAA;AACb,EAAA;AACkB,EAAA;AAG3B,IAAA;AACC,MAAA;AAAgE,IAAA;AAEjE,IAAA;AAAe,EAAA;AAChB,EAAA;AAGC,IAAA;AACA,IAAA;AACA,IAAA;AACC,MAAA;AAAK,IAAA;AACN,EAAA;AACD,EAAA;AAGC,IAAA;AACA,IAAA;AACC,MAAA;AAAgB,IAAA;AAEhB,MAAA;AAAa,IAAA;AACd,EAAA;AAEF;ADlCA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/rivet/rivet/rivetkit-typescript/packages/rivetkit/dist/tsup/chunk-ZA7FLHKH.cjs","sourcesContent":[null,"import type { SqliteBindings } from \"./config\";\n\ntype SqliteBindingObject = Record<string, unknown>;\n\nfunction isSqliteBindingValue(value: unknown): boolean {\n\tif (\n\t\tvalue === null ||\n\t\ttypeof value === \"number\" ||\n\t\ttypeof value === \"string\" ||\n\t\ttypeof value === \"bigint\" ||\n\t\tvalue instanceof Uint8Array\n\t) {\n\t\treturn true;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\treturn value.every((item) => typeof item === \"number\");\n\t}\n\n\treturn false;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\treturn false;\n\t}\n\treturn Object.getPrototypeOf(value) === Object.prototype;\n}\n\nexport function isSqliteBindingObject(\n\tvalue: unknown,\n): value is SqliteBindingObject {\n\tif (!isPlainObject(value)) {\n\t\treturn false;\n\t}\n\n\treturn Object.values(value).every((entry) => isSqliteBindingValue(entry));\n}\n\nexport function isSqliteBindingArray(value: unknown): value is unknown[] {\n\treturn (\n\t\tArray.isArray(value) &&\n\t\tvalue.every((entry) => isSqliteBindingValue(entry))\n\t);\n}\n\nexport function toSqliteBindings(\n\tinput: unknown[] | SqliteBindingObject,\n): SqliteBindings {\n\tif (Array.isArray(input)) {\n\t\tfor (const value of input) {\n\t\t\tif (!isSqliteBindingValue(value)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`unsupported sqlite binding type: ${typeof value}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\treturn input as SqliteBindings;\n\t}\n\n\tif (isSqliteBindingObject(input)) {\n\t\treturn input as SqliteBindings;\n\t}\n\n\tthrow new Error(\"unsupported sqlite binding collection\");\n}\n\n/**\n * Serialize async operations on a shared non-reentrant resource.\n */\nexport class AsyncMutex {\n\t#locked = false;\n\t#waiting: (() => void)[] = [];\n\n\tasync acquire(): Promise<void> {\n\t\twhile (this.#locked) {\n\t\t\tawait new Promise<void>((resolve) => this.#waiting.push(resolve));\n\t\t}\n\t\tthis.#locked = true;\n\t}\n\n\trelease(): void {\n\t\tthis.#locked = false;\n\t\tconst next = this.#waiting.shift();\n\t\tif (next) {\n\t\t\tnext();\n\t\t}\n\t}\n\n\tasync run<T>(fn: () => Promise<T>): Promise<T> {\n\t\tawait this.acquire();\n\t\ttry {\n\t\t\treturn await fn();\n\t\t} finally {\n\t\t\tthis.release();\n\t\t}\n\t}\n}\n"]}
|
package/src/actor/driver.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type { Context as HonoContext } from "hono";
|
|
2
|
-
import type { AnyClient } from "@/client/client";
|
|
3
|
-
import type {
|
|
4
|
-
DrizzleDatabaseClient,
|
|
5
|
-
NativeDatabaseProvider,
|
|
6
|
-
} from "@/common/database/config";
|
|
7
|
-
import type { EngineControlClient } from "@/engine-client/driver";
|
|
8
|
-
import type { RegistryConfig } from "@/registry/config";
|
|
9
|
-
import type { AnyActorInstance, AnyStaticActorInstance } from "./definition";
|
|
10
|
-
|
|
11
|
-
export type ActorDriverBuilder = (
|
|
12
|
-
config: RegistryConfig,
|
|
13
|
-
engineClient: EngineControlClient,
|
|
14
|
-
inlineClient: AnyClient,
|
|
15
|
-
) => ActorDriver;
|
|
16
|
-
|
|
17
|
-
export interface ActorDriver {
|
|
18
|
-
//load(): Promise<LoadOutput>;
|
|
19
|
-
|
|
20
|
-
loadActor(actorId: string): Promise<AnyActorInstance>;
|
|
21
|
-
|
|
22
|
-
getContext(actorId: string): unknown;
|
|
23
|
-
|
|
24
|
-
// Batch KV operations
|
|
25
|
-
/** Batch write multiple key-value pairs. Keys and values are Uint8Arrays. */
|
|
26
|
-
kvBatchPut(
|
|
27
|
-
actorId: string,
|
|
28
|
-
entries: [Uint8Array, Uint8Array][],
|
|
29
|
-
): Promise<void>;
|
|
30
|
-
|
|
31
|
-
/** Batch read multiple keys. Returns null for keys that don't exist. */
|
|
32
|
-
kvBatchGet(
|
|
33
|
-
actorId: string,
|
|
34
|
-
keys: Uint8Array[],
|
|
35
|
-
): Promise<(Uint8Array | null)[]>;
|
|
36
|
-
|
|
37
|
-
/** Batch delete multiple keys. */
|
|
38
|
-
kvBatchDelete(actorId: string, keys: Uint8Array[]): Promise<void>;
|
|
39
|
-
|
|
40
|
-
/** Delete all keys in the half-open range [start, end). */
|
|
41
|
-
kvDeleteRange(
|
|
42
|
-
actorId: string,
|
|
43
|
-
start: Uint8Array,
|
|
44
|
-
end: Uint8Array,
|
|
45
|
-
): Promise<void>;
|
|
46
|
-
|
|
47
|
-
/** List all keys with a given prefix. */
|
|
48
|
-
kvListPrefix(
|
|
49
|
-
actorId: string,
|
|
50
|
-
prefix: Uint8Array,
|
|
51
|
-
options?: {
|
|
52
|
-
reverse?: boolean;
|
|
53
|
-
limit?: number;
|
|
54
|
-
},
|
|
55
|
-
): Promise<[Uint8Array, Uint8Array][]>;
|
|
56
|
-
|
|
57
|
-
/** List all keys in the half-open range [start, end). */
|
|
58
|
-
kvListRange(
|
|
59
|
-
actorId: string,
|
|
60
|
-
start: Uint8Array,
|
|
61
|
-
end: Uint8Array,
|
|
62
|
-
options?: {
|
|
63
|
-
reverse?: boolean;
|
|
64
|
-
limit?: number;
|
|
65
|
-
},
|
|
66
|
-
): Promise<[Uint8Array, Uint8Array][]>;
|
|
67
|
-
|
|
68
|
-
// Schedule
|
|
69
|
-
/** ActorInstance ensure that only one instance of setAlarm is called in parallel at a time. */
|
|
70
|
-
setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void>;
|
|
71
|
-
|
|
72
|
-
/** Cancel any pending alarm timeout for the given actor. */
|
|
73
|
-
cancelAlarm?(actorId: string): void;
|
|
74
|
-
|
|
75
|
-
// Database
|
|
76
|
-
/**
|
|
77
|
-
* Override the default Drizzle database client for the actor.
|
|
78
|
-
* If not provided, rivetkit will construct a KV-backed Drizzle client.
|
|
79
|
-
* @experimental
|
|
80
|
-
*/
|
|
81
|
-
overrideDrizzleDatabaseClient?(
|
|
82
|
-
actorId: string,
|
|
83
|
-
): Promise<DrizzleDatabaseClient | undefined>;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Returns a provider for opening native databases from a live runtime handle.
|
|
87
|
-
*/
|
|
88
|
-
getNativeDatabaseProvider?(): NativeDatabaseProvider | undefined;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Requests the actor to go to sleep.
|
|
92
|
-
*
|
|
93
|
-
* This will call `ActorInstance.onStop` independently.
|
|
94
|
-
*/
|
|
95
|
-
startSleep?(actorId: string): void;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Acknowledges a persisted hibernatable websocket message index to the
|
|
99
|
-
* transport host.
|
|
100
|
-
*
|
|
101
|
-
* Actor runtime code owns the per-message hibernatable websocket bookkeeping
|
|
102
|
-
* and decides when an index is durable. Drivers only implement how to
|
|
103
|
-
* forward that durable ack to the underlying transport, such as the engine
|
|
104
|
-
* gateway.
|
|
105
|
-
*/
|
|
106
|
-
ackHibernatableWebSocketMessage?(
|
|
107
|
-
gatewayId: ArrayBuffer,
|
|
108
|
-
requestId: ArrayBuffer,
|
|
109
|
-
serverMessageIndex: number,
|
|
110
|
-
): void;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Destroys the actor and its associated data.
|
|
114
|
-
*
|
|
115
|
-
* This will call `ActorInstance.onStop` independently.
|
|
116
|
-
*/
|
|
117
|
-
startDestroy(actorId: string): void;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Test-only helper that simulates an abrupt actor crash.
|
|
121
|
-
*
|
|
122
|
-
* Unlike startSleep/startDestroy, this skips actor lifecycle hooks and the
|
|
123
|
-
* final persist flush. Drivers may still release local resources so the
|
|
124
|
-
* current test process can continue running.
|
|
125
|
-
*/
|
|
126
|
-
hardCrashActor?(actorId: string): Promise<void>;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Shuts down the actor runner.
|
|
130
|
-
*/
|
|
131
|
-
shutdownRunner?(immediate: boolean): Promise<void>;
|
|
132
|
-
|
|
133
|
-
// Serverless
|
|
134
|
-
/** This handles the serverless start request. This should manage the lifecycle of the runner tied to the request lifecycle. */
|
|
135
|
-
serverlessHandleStart?(c: HonoContext): Promise<Response>;
|
|
136
|
-
|
|
137
|
-
/** Extra properties to add to logs for each actor. */
|
|
138
|
-
getExtraActorLogParams?(): Record<string, string>;
|
|
139
|
-
|
|
140
|
-
onBeforeActorStart?(actor: AnyStaticActorInstance): Promise<void>;
|
|
141
|
-
}
|