@rivetkit/engine-runner-protocol 25.7.1-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.
@@ -0,0 +1,345 @@
1
+ import * as bare from '@bare-ts/lib';
2
+
3
+ type i64 = bigint;
4
+ type u32 = number;
5
+ type u64 = bigint;
6
+ type Id = string;
7
+ declare function readId(bc: bare.ByteCursor): Id;
8
+ declare function writeId(bc: bare.ByteCursor, x: Id): void;
9
+ type Json = string;
10
+ declare function readJson(bc: bare.ByteCursor): Json;
11
+ declare function writeJson(bc: bare.ByteCursor, x: Json): void;
12
+ type KvKey = ArrayBuffer;
13
+ declare function readKvKey(bc: bare.ByteCursor): KvKey;
14
+ declare function writeKvKey(bc: bare.ByteCursor, x: KvKey): void;
15
+ type KvValue = ArrayBuffer;
16
+ declare function readKvValue(bc: bare.ByteCursor): KvValue;
17
+ declare function writeKvValue(bc: bare.ByteCursor, x: KvValue): void;
18
+ type KvMetadata = {
19
+ readonly version: ArrayBuffer;
20
+ readonly createTs: i64;
21
+ };
22
+ declare function readKvMetadata(bc: bare.ByteCursor): KvMetadata;
23
+ declare function writeKvMetadata(bc: bare.ByteCursor, x: KvMetadata): void;
24
+ type KvListAllQuery = null;
25
+ type KvListRangeQuery = {
26
+ readonly start: KvKey;
27
+ readonly end: KvKey;
28
+ readonly exclusive: boolean;
29
+ };
30
+ declare function readKvListRangeQuery(bc: bare.ByteCursor): KvListRangeQuery;
31
+ declare function writeKvListRangeQuery(bc: bare.ByteCursor, x: KvListRangeQuery): void;
32
+ type KvListPrefixQuery = {
33
+ readonly key: KvKey;
34
+ };
35
+ declare function readKvListPrefixQuery(bc: bare.ByteCursor): KvListPrefixQuery;
36
+ declare function writeKvListPrefixQuery(bc: bare.ByteCursor, x: KvListPrefixQuery): void;
37
+ type KvListQuery = {
38
+ readonly tag: "KvListAllQuery";
39
+ readonly val: KvListAllQuery;
40
+ } | {
41
+ readonly tag: "KvListRangeQuery";
42
+ readonly val: KvListRangeQuery;
43
+ } | {
44
+ readonly tag: "KvListPrefixQuery";
45
+ readonly val: KvListPrefixQuery;
46
+ };
47
+ declare function readKvListQuery(bc: bare.ByteCursor): KvListQuery;
48
+ declare function writeKvListQuery(bc: bare.ByteCursor, x: KvListQuery): void;
49
+ type ActorName = {
50
+ readonly metadata: Json;
51
+ };
52
+ declare function readActorName(bc: bare.ByteCursor): ActorName;
53
+ declare function writeActorName(bc: bare.ByteCursor, x: ActorName): void;
54
+ declare enum StopCode {
55
+ Ok = "Ok",
56
+ Error = "Error"
57
+ }
58
+ declare function readStopCode(bc: bare.ByteCursor): StopCode;
59
+ declare function writeStopCode(bc: bare.ByteCursor, x: StopCode): void;
60
+ type ActorIntentSleep = null;
61
+ type ActorIntentStop = null;
62
+ type ActorIntent = {
63
+ readonly tag: "ActorIntentSleep";
64
+ readonly val: ActorIntentSleep;
65
+ } | {
66
+ readonly tag: "ActorIntentStop";
67
+ readonly val: ActorIntentStop;
68
+ };
69
+ declare function readActorIntent(bc: bare.ByteCursor): ActorIntent;
70
+ declare function writeActorIntent(bc: bare.ByteCursor, x: ActorIntent): void;
71
+ type ActorStateRunning = null;
72
+ type ActorStateStopped = {
73
+ readonly code: StopCode;
74
+ readonly message: string | null;
75
+ };
76
+ declare function readActorStateStopped(bc: bare.ByteCursor): ActorStateStopped;
77
+ declare function writeActorStateStopped(bc: bare.ByteCursor, x: ActorStateStopped): void;
78
+ type ActorState = {
79
+ readonly tag: "ActorStateRunning";
80
+ readonly val: ActorStateRunning;
81
+ } | {
82
+ readonly tag: "ActorStateStopped";
83
+ readonly val: ActorStateStopped;
84
+ };
85
+ declare function readActorState(bc: bare.ByteCursor): ActorState;
86
+ declare function writeActorState(bc: bare.ByteCursor, x: ActorState): void;
87
+ type EventActorIntent = {
88
+ readonly actorId: Id;
89
+ readonly generation: u32;
90
+ readonly intent: ActorIntent;
91
+ };
92
+ declare function readEventActorIntent(bc: bare.ByteCursor): EventActorIntent;
93
+ declare function writeEventActorIntent(bc: bare.ByteCursor, x: EventActorIntent): void;
94
+ type EventActorStateUpdate = {
95
+ readonly actorId: Id;
96
+ readonly generation: u32;
97
+ readonly state: ActorState;
98
+ };
99
+ declare function readEventActorStateUpdate(bc: bare.ByteCursor): EventActorStateUpdate;
100
+ declare function writeEventActorStateUpdate(bc: bare.ByteCursor, x: EventActorStateUpdate): void;
101
+ type EventActorSetAlarm = {
102
+ readonly actorId: Id;
103
+ readonly generation: u32;
104
+ readonly alarmTs: i64 | null;
105
+ };
106
+ declare function readEventActorSetAlarm(bc: bare.ByteCursor): EventActorSetAlarm;
107
+ declare function writeEventActorSetAlarm(bc: bare.ByteCursor, x: EventActorSetAlarm): void;
108
+ type Event = {
109
+ readonly tag: "EventActorIntent";
110
+ readonly val: EventActorIntent;
111
+ } | {
112
+ readonly tag: "EventActorStateUpdate";
113
+ readonly val: EventActorStateUpdate;
114
+ } | {
115
+ readonly tag: "EventActorSetAlarm";
116
+ readonly val: EventActorSetAlarm;
117
+ };
118
+ declare function readEvent(bc: bare.ByteCursor): Event;
119
+ declare function writeEvent(bc: bare.ByteCursor, x: Event): void;
120
+ type EventWrapper = {
121
+ readonly index: i64;
122
+ readonly inner: Event;
123
+ };
124
+ declare function readEventWrapper(bc: bare.ByteCursor): EventWrapper;
125
+ declare function writeEventWrapper(bc: bare.ByteCursor, x: EventWrapper): void;
126
+ type ActorConfig = {
127
+ readonly name: string;
128
+ readonly key: string | null;
129
+ readonly createTs: i64;
130
+ readonly input: ArrayBuffer | null;
131
+ };
132
+ declare function readActorConfig(bc: bare.ByteCursor): ActorConfig;
133
+ declare function writeActorConfig(bc: bare.ByteCursor, x: ActorConfig): void;
134
+ type CommandStartActor = {
135
+ readonly actorId: Id;
136
+ readonly generation: u32;
137
+ readonly config: ActorConfig;
138
+ };
139
+ declare function readCommandStartActor(bc: bare.ByteCursor): CommandStartActor;
140
+ declare function writeCommandStartActor(bc: bare.ByteCursor, x: CommandStartActor): void;
141
+ type CommandStopActor = {
142
+ readonly actorId: Id;
143
+ readonly generation: u32;
144
+ };
145
+ declare function readCommandStopActor(bc: bare.ByteCursor): CommandStopActor;
146
+ declare function writeCommandStopActor(bc: bare.ByteCursor, x: CommandStopActor): void;
147
+ type Command = {
148
+ readonly tag: "CommandStartActor";
149
+ readonly val: CommandStartActor;
150
+ } | {
151
+ readonly tag: "CommandStopActor";
152
+ readonly val: CommandStopActor;
153
+ };
154
+ declare function readCommand(bc: bare.ByteCursor): Command;
155
+ declare function writeCommand(bc: bare.ByteCursor, x: Command): void;
156
+ type CommandWrapper = {
157
+ readonly index: i64;
158
+ readonly inner: Command;
159
+ };
160
+ declare function readCommandWrapper(bc: bare.ByteCursor): CommandWrapper;
161
+ declare function writeCommandWrapper(bc: bare.ByteCursor, x: CommandWrapper): void;
162
+ type ToServerInit = {
163
+ readonly name: string;
164
+ readonly version: u32;
165
+ readonly totalSlots: u32;
166
+ readonly lastCommandIdx: i64 | null;
167
+ readonly prepopulateActorNames: ReadonlyMap<string, ActorName> | null;
168
+ readonly metadata: Json | null;
169
+ };
170
+ declare function readToServerInit(bc: bare.ByteCursor): ToServerInit;
171
+ declare function writeToServerInit(bc: bare.ByteCursor, x: ToServerInit): void;
172
+ type ToServerEvents = readonly EventWrapper[];
173
+ declare function readToServerEvents(bc: bare.ByteCursor): ToServerEvents;
174
+ declare function writeToServerEvents(bc: bare.ByteCursor, x: ToServerEvents): void;
175
+ type ToServerAckCommands = {
176
+ readonly lastCommandIdx: i64;
177
+ };
178
+ declare function readToServerAckCommands(bc: bare.ByteCursor): ToServerAckCommands;
179
+ declare function writeToServerAckCommands(bc: bare.ByteCursor, x: ToServerAckCommands): void;
180
+ type ToServerStopping = null;
181
+ type ToServerPing = {
182
+ readonly ts: i64;
183
+ };
184
+ declare function readToServerPing(bc: bare.ByteCursor): ToServerPing;
185
+ declare function writeToServerPing(bc: bare.ByteCursor, x: ToServerPing): void;
186
+ type KvGetRequest = {
187
+ readonly keys: readonly KvKey[];
188
+ };
189
+ declare function readKvGetRequest(bc: bare.ByteCursor): KvGetRequest;
190
+ declare function writeKvGetRequest(bc: bare.ByteCursor, x: KvGetRequest): void;
191
+ type KvListRequest = {
192
+ readonly query: KvListQuery;
193
+ readonly reverse: boolean | null;
194
+ readonly limit: u64 | null;
195
+ };
196
+ declare function readKvListRequest(bc: bare.ByteCursor): KvListRequest;
197
+ declare function writeKvListRequest(bc: bare.ByteCursor, x: KvListRequest): void;
198
+ type KvPutRequest = {
199
+ readonly keys: readonly KvKey[];
200
+ readonly values: readonly KvValue[];
201
+ };
202
+ declare function readKvPutRequest(bc: bare.ByteCursor): KvPutRequest;
203
+ declare function writeKvPutRequest(bc: bare.ByteCursor, x: KvPutRequest): void;
204
+ type KvDeleteRequest = {
205
+ readonly keys: readonly KvKey[];
206
+ };
207
+ declare function readKvDeleteRequest(bc: bare.ByteCursor): KvDeleteRequest;
208
+ declare function writeKvDeleteRequest(bc: bare.ByteCursor, x: KvDeleteRequest): void;
209
+ type KvDropRequest = null;
210
+ type KvRequestData = {
211
+ readonly tag: "KvGetRequest";
212
+ readonly val: KvGetRequest;
213
+ } | {
214
+ readonly tag: "KvListRequest";
215
+ readonly val: KvListRequest;
216
+ } | {
217
+ readonly tag: "KvPutRequest";
218
+ readonly val: KvPutRequest;
219
+ } | {
220
+ readonly tag: "KvDeleteRequest";
221
+ readonly val: KvDeleteRequest;
222
+ } | {
223
+ readonly tag: "KvDropRequest";
224
+ readonly val: KvDropRequest;
225
+ };
226
+ declare function readKvRequestData(bc: bare.ByteCursor): KvRequestData;
227
+ declare function writeKvRequestData(bc: bare.ByteCursor, x: KvRequestData): void;
228
+ type ToServerKvRequest = {
229
+ readonly actorId: Id;
230
+ readonly requestId: u32;
231
+ readonly data: KvRequestData;
232
+ };
233
+ declare function readToServerKvRequest(bc: bare.ByteCursor): ToServerKvRequest;
234
+ declare function writeToServerKvRequest(bc: bare.ByteCursor, x: ToServerKvRequest): void;
235
+ type ToServer = {
236
+ readonly tag: "ToServerInit";
237
+ readonly val: ToServerInit;
238
+ } | {
239
+ readonly tag: "ToServerEvents";
240
+ readonly val: ToServerEvents;
241
+ } | {
242
+ readonly tag: "ToServerAckCommands";
243
+ readonly val: ToServerAckCommands;
244
+ } | {
245
+ readonly tag: "ToServerStopping";
246
+ readonly val: ToServerStopping;
247
+ } | {
248
+ readonly tag: "ToServerPing";
249
+ readonly val: ToServerPing;
250
+ } | {
251
+ readonly tag: "ToServerKvRequest";
252
+ readonly val: ToServerKvRequest;
253
+ };
254
+ declare function readToServer(bc: bare.ByteCursor): ToServer;
255
+ declare function writeToServer(bc: bare.ByteCursor, x: ToServer): void;
256
+ declare function encodeToServer(x: ToServer, config?: Partial<bare.Config>): Uint8Array;
257
+ declare function decodeToServer(bytes: Uint8Array): ToServer;
258
+ type ProtocolMetadata = {
259
+ readonly runnerLostThreshold: i64;
260
+ };
261
+ declare function readProtocolMetadata(bc: bare.ByteCursor): ProtocolMetadata;
262
+ declare function writeProtocolMetadata(bc: bare.ByteCursor, x: ProtocolMetadata): void;
263
+ type ToClientInit = {
264
+ readonly runnerId: Id;
265
+ readonly lastEventIdx: i64;
266
+ readonly metadata: ProtocolMetadata;
267
+ };
268
+ declare function readToClientInit(bc: bare.ByteCursor): ToClientInit;
269
+ declare function writeToClientInit(bc: bare.ByteCursor, x: ToClientInit): void;
270
+ type ToClientCommands = readonly CommandWrapper[];
271
+ declare function readToClientCommands(bc: bare.ByteCursor): ToClientCommands;
272
+ declare function writeToClientCommands(bc: bare.ByteCursor, x: ToClientCommands): void;
273
+ type ToClientAckEvents = {
274
+ readonly lastEventIdx: i64;
275
+ };
276
+ declare function readToClientAckEvents(bc: bare.ByteCursor): ToClientAckEvents;
277
+ declare function writeToClientAckEvents(bc: bare.ByteCursor, x: ToClientAckEvents): void;
278
+ type KvErrorResponse = {
279
+ readonly message: string;
280
+ };
281
+ declare function readKvErrorResponse(bc: bare.ByteCursor): KvErrorResponse;
282
+ declare function writeKvErrorResponse(bc: bare.ByteCursor, x: KvErrorResponse): void;
283
+ type KvGetResponse = {
284
+ readonly keys: readonly KvKey[];
285
+ readonly values: readonly KvValue[];
286
+ readonly metadata: readonly KvMetadata[];
287
+ };
288
+ declare function readKvGetResponse(bc: bare.ByteCursor): KvGetResponse;
289
+ declare function writeKvGetResponse(bc: bare.ByteCursor, x: KvGetResponse): void;
290
+ type KvListResponse = {
291
+ readonly keys: readonly KvKey[];
292
+ readonly values: readonly KvValue[];
293
+ readonly metadata: readonly KvMetadata[];
294
+ };
295
+ declare function readKvListResponse(bc: bare.ByteCursor): KvListResponse;
296
+ declare function writeKvListResponse(bc: bare.ByteCursor, x: KvListResponse): void;
297
+ type KvPutResponse = null;
298
+ type KvDeleteResponse = null;
299
+ type KvDropResponse = null;
300
+ type KvResponseData = {
301
+ readonly tag: "KvErrorResponse";
302
+ readonly val: KvErrorResponse;
303
+ } | {
304
+ readonly tag: "KvGetResponse";
305
+ readonly val: KvGetResponse;
306
+ } | {
307
+ readonly tag: "KvListResponse";
308
+ readonly val: KvListResponse;
309
+ } | {
310
+ readonly tag: "KvPutResponse";
311
+ readonly val: KvPutResponse;
312
+ } | {
313
+ readonly tag: "KvDeleteResponse";
314
+ readonly val: KvDeleteResponse;
315
+ } | {
316
+ readonly tag: "KvDropResponse";
317
+ readonly val: KvDropResponse;
318
+ };
319
+ declare function readKvResponseData(bc: bare.ByteCursor): KvResponseData;
320
+ declare function writeKvResponseData(bc: bare.ByteCursor, x: KvResponseData): void;
321
+ type ToClientKvResponse = {
322
+ readonly requestId: u32;
323
+ readonly data: KvResponseData;
324
+ };
325
+ declare function readToClientKvResponse(bc: bare.ByteCursor): ToClientKvResponse;
326
+ declare function writeToClientKvResponse(bc: bare.ByteCursor, x: ToClientKvResponse): void;
327
+ type ToClient = {
328
+ readonly tag: "ToClientInit";
329
+ readonly val: ToClientInit;
330
+ } | {
331
+ readonly tag: "ToClientCommands";
332
+ readonly val: ToClientCommands;
333
+ } | {
334
+ readonly tag: "ToClientAckEvents";
335
+ readonly val: ToClientAckEvents;
336
+ } | {
337
+ readonly tag: "ToClientKvResponse";
338
+ readonly val: ToClientKvResponse;
339
+ };
340
+ declare function readToClient(bc: bare.ByteCursor): ToClient;
341
+ declare function writeToClient(bc: bare.ByteCursor, x: ToClient): void;
342
+ declare function encodeToClient(x: ToClient, config?: Partial<bare.Config>): Uint8Array;
343
+ declare function decodeToClient(bytes: Uint8Array): ToClient;
344
+
345
+ export { type ActorConfig, type ActorIntent, type ActorIntentSleep, type ActorIntentStop, type ActorName, type ActorState, type ActorStateRunning, type ActorStateStopped, type Command, type CommandStartActor, type CommandStopActor, type CommandWrapper, type Event, type EventActorIntent, type EventActorSetAlarm, type EventActorStateUpdate, type EventWrapper, type Id, type Json, type KvDeleteRequest, type KvDeleteResponse, type KvDropRequest, type KvDropResponse, type KvErrorResponse, type KvGetRequest, type KvGetResponse, type KvKey, type KvListAllQuery, type KvListPrefixQuery, type KvListQuery, type KvListRangeQuery, type KvListRequest, type KvListResponse, type KvMetadata, type KvPutRequest, type KvPutResponse, type KvRequestData, type KvResponseData, type KvValue, type ProtocolMetadata, StopCode, type ToClient, type ToClientAckEvents, type ToClientCommands, type ToClientInit, type ToClientKvResponse, type ToServer, type ToServerAckCommands, type ToServerEvents, type ToServerInit, type ToServerKvRequest, type ToServerPing, type ToServerStopping, decodeToClient, decodeToServer, encodeToClient, encodeToServer, type i64, readActorConfig, readActorIntent, readActorName, readActorState, readActorStateStopped, readCommand, readCommandStartActor, readCommandStopActor, readCommandWrapper, readEvent, readEventActorIntent, readEventActorSetAlarm, readEventActorStateUpdate, readEventWrapper, readId, readJson, readKvDeleteRequest, readKvErrorResponse, readKvGetRequest, readKvGetResponse, readKvKey, readKvListPrefixQuery, readKvListQuery, readKvListRangeQuery, readKvListRequest, readKvListResponse, readKvMetadata, readKvPutRequest, readKvRequestData, readKvResponseData, readKvValue, readProtocolMetadata, readStopCode, readToClient, readToClientAckEvents, readToClientCommands, readToClientInit, readToClientKvResponse, readToServer, readToServerAckCommands, readToServerEvents, readToServerInit, readToServerKvRequest, readToServerPing, type u32, type u64, writeActorConfig, writeActorIntent, writeActorName, writeActorState, writeActorStateStopped, writeCommand, writeCommandStartActor, writeCommandStopActor, writeCommandWrapper, writeEvent, writeEventActorIntent, writeEventActorSetAlarm, writeEventActorStateUpdate, writeEventWrapper, writeId, writeJson, writeKvDeleteRequest, writeKvErrorResponse, writeKvGetRequest, writeKvGetResponse, writeKvKey, writeKvListPrefixQuery, writeKvListQuery, writeKvListRangeQuery, writeKvListRequest, writeKvListResponse, writeKvMetadata, writeKvPutRequest, writeKvRequestData, writeKvResponseData, writeKvValue, writeProtocolMetadata, writeStopCode, writeToClient, writeToClientAckEvents, writeToClientCommands, writeToClientInit, writeToClientKvResponse, writeToServer, writeToServerAckCommands, writeToServerEvents, writeToServerInit, writeToServerKvRequest, writeToServerPing };
package/dist/index.js ADDED
@@ -0,0 +1,999 @@
1
+ // src/index.ts
2
+ import * as bare from "@bare-ts/lib";
3
+ var DEFAULT_CONFIG = /* @__PURE__ */ bare.Config({});
4
+ function readId(bc) {
5
+ return bare.readString(bc);
6
+ }
7
+ function writeId(bc, x) {
8
+ bare.writeString(bc, x);
9
+ }
10
+ function readJson(bc) {
11
+ return bare.readString(bc);
12
+ }
13
+ function writeJson(bc, x) {
14
+ bare.writeString(bc, x);
15
+ }
16
+ function readKvKey(bc) {
17
+ return bare.readData(bc);
18
+ }
19
+ function writeKvKey(bc, x) {
20
+ bare.writeData(bc, x);
21
+ }
22
+ function readKvValue(bc) {
23
+ return bare.readData(bc);
24
+ }
25
+ function writeKvValue(bc, x) {
26
+ bare.writeData(bc, x);
27
+ }
28
+ function readKvMetadata(bc) {
29
+ return {
30
+ version: bare.readData(bc),
31
+ createTs: bare.readI64(bc)
32
+ };
33
+ }
34
+ function writeKvMetadata(bc, x) {
35
+ bare.writeData(bc, x.version);
36
+ bare.writeI64(bc, x.createTs);
37
+ }
38
+ function readKvListRangeQuery(bc) {
39
+ return {
40
+ start: readKvKey(bc),
41
+ end: readKvKey(bc),
42
+ exclusive: bare.readBool(bc)
43
+ };
44
+ }
45
+ function writeKvListRangeQuery(bc, x) {
46
+ writeKvKey(bc, x.start);
47
+ writeKvKey(bc, x.end);
48
+ bare.writeBool(bc, x.exclusive);
49
+ }
50
+ function readKvListPrefixQuery(bc) {
51
+ return {
52
+ key: readKvKey(bc)
53
+ };
54
+ }
55
+ function writeKvListPrefixQuery(bc, x) {
56
+ writeKvKey(bc, x.key);
57
+ }
58
+ function readKvListQuery(bc) {
59
+ const offset = bc.offset;
60
+ const tag = bare.readU8(bc);
61
+ switch (tag) {
62
+ case 0:
63
+ return { tag: "KvListAllQuery", val: null };
64
+ case 1:
65
+ return { tag: "KvListRangeQuery", val: readKvListRangeQuery(bc) };
66
+ case 2:
67
+ return { tag: "KvListPrefixQuery", val: readKvListPrefixQuery(bc) };
68
+ default: {
69
+ bc.offset = offset;
70
+ throw new bare.BareError(offset, "invalid tag");
71
+ }
72
+ }
73
+ }
74
+ function writeKvListQuery(bc, x) {
75
+ switch (x.tag) {
76
+ case "KvListAllQuery": {
77
+ bare.writeU8(bc, 0);
78
+ break;
79
+ }
80
+ case "KvListRangeQuery": {
81
+ bare.writeU8(bc, 1);
82
+ writeKvListRangeQuery(bc, x.val);
83
+ break;
84
+ }
85
+ case "KvListPrefixQuery": {
86
+ bare.writeU8(bc, 2);
87
+ writeKvListPrefixQuery(bc, x.val);
88
+ break;
89
+ }
90
+ }
91
+ }
92
+ function readActorName(bc) {
93
+ return {
94
+ metadata: readJson(bc)
95
+ };
96
+ }
97
+ function writeActorName(bc, x) {
98
+ writeJson(bc, x.metadata);
99
+ }
100
+ var StopCode = /* @__PURE__ */ ((StopCode2) => {
101
+ StopCode2["Ok"] = "Ok";
102
+ StopCode2["Error"] = "Error";
103
+ return StopCode2;
104
+ })(StopCode || {});
105
+ function readStopCode(bc) {
106
+ const offset = bc.offset;
107
+ const tag = bare.readU8(bc);
108
+ switch (tag) {
109
+ case 0:
110
+ return "Ok" /* Ok */;
111
+ case 1:
112
+ return "Error" /* Error */;
113
+ default: {
114
+ bc.offset = offset;
115
+ throw new bare.BareError(offset, "invalid tag");
116
+ }
117
+ }
118
+ }
119
+ function writeStopCode(bc, x) {
120
+ switch (x) {
121
+ case "Ok" /* Ok */: {
122
+ bare.writeU8(bc, 0);
123
+ break;
124
+ }
125
+ case "Error" /* Error */: {
126
+ bare.writeU8(bc, 1);
127
+ break;
128
+ }
129
+ }
130
+ }
131
+ function readActorIntent(bc) {
132
+ const offset = bc.offset;
133
+ const tag = bare.readU8(bc);
134
+ switch (tag) {
135
+ case 0:
136
+ return { tag: "ActorIntentSleep", val: null };
137
+ case 1:
138
+ return { tag: "ActorIntentStop", val: null };
139
+ default: {
140
+ bc.offset = offset;
141
+ throw new bare.BareError(offset, "invalid tag");
142
+ }
143
+ }
144
+ }
145
+ function writeActorIntent(bc, x) {
146
+ switch (x.tag) {
147
+ case "ActorIntentSleep": {
148
+ bare.writeU8(bc, 0);
149
+ break;
150
+ }
151
+ case "ActorIntentStop": {
152
+ bare.writeU8(bc, 1);
153
+ break;
154
+ }
155
+ }
156
+ }
157
+ function read0(bc) {
158
+ return bare.readBool(bc) ? bare.readString(bc) : null;
159
+ }
160
+ function write0(bc, x) {
161
+ bare.writeBool(bc, x != null);
162
+ if (x != null) {
163
+ bare.writeString(bc, x);
164
+ }
165
+ }
166
+ function readActorStateStopped(bc) {
167
+ return {
168
+ code: readStopCode(bc),
169
+ message: read0(bc)
170
+ };
171
+ }
172
+ function writeActorStateStopped(bc, x) {
173
+ writeStopCode(bc, x.code);
174
+ write0(bc, x.message);
175
+ }
176
+ function readActorState(bc) {
177
+ const offset = bc.offset;
178
+ const tag = bare.readU8(bc);
179
+ switch (tag) {
180
+ case 0:
181
+ return { tag: "ActorStateRunning", val: null };
182
+ case 1:
183
+ return { tag: "ActorStateStopped", val: readActorStateStopped(bc) };
184
+ default: {
185
+ bc.offset = offset;
186
+ throw new bare.BareError(offset, "invalid tag");
187
+ }
188
+ }
189
+ }
190
+ function writeActorState(bc, x) {
191
+ switch (x.tag) {
192
+ case "ActorStateRunning": {
193
+ bare.writeU8(bc, 0);
194
+ break;
195
+ }
196
+ case "ActorStateStopped": {
197
+ bare.writeU8(bc, 1);
198
+ writeActorStateStopped(bc, x.val);
199
+ break;
200
+ }
201
+ }
202
+ }
203
+ function readEventActorIntent(bc) {
204
+ return {
205
+ actorId: readId(bc),
206
+ generation: bare.readU32(bc),
207
+ intent: readActorIntent(bc)
208
+ };
209
+ }
210
+ function writeEventActorIntent(bc, x) {
211
+ writeId(bc, x.actorId);
212
+ bare.writeU32(bc, x.generation);
213
+ writeActorIntent(bc, x.intent);
214
+ }
215
+ function readEventActorStateUpdate(bc) {
216
+ return {
217
+ actorId: readId(bc),
218
+ generation: bare.readU32(bc),
219
+ state: readActorState(bc)
220
+ };
221
+ }
222
+ function writeEventActorStateUpdate(bc, x) {
223
+ writeId(bc, x.actorId);
224
+ bare.writeU32(bc, x.generation);
225
+ writeActorState(bc, x.state);
226
+ }
227
+ function read1(bc) {
228
+ return bare.readBool(bc) ? bare.readI64(bc) : null;
229
+ }
230
+ function write1(bc, x) {
231
+ bare.writeBool(bc, x != null);
232
+ if (x != null) {
233
+ bare.writeI64(bc, x);
234
+ }
235
+ }
236
+ function readEventActorSetAlarm(bc) {
237
+ return {
238
+ actorId: readId(bc),
239
+ generation: bare.readU32(bc),
240
+ alarmTs: read1(bc)
241
+ };
242
+ }
243
+ function writeEventActorSetAlarm(bc, x) {
244
+ writeId(bc, x.actorId);
245
+ bare.writeU32(bc, x.generation);
246
+ write1(bc, x.alarmTs);
247
+ }
248
+ function readEvent(bc) {
249
+ const offset = bc.offset;
250
+ const tag = bare.readU8(bc);
251
+ switch (tag) {
252
+ case 0:
253
+ return { tag: "EventActorIntent", val: readEventActorIntent(bc) };
254
+ case 1:
255
+ return { tag: "EventActorStateUpdate", val: readEventActorStateUpdate(bc) };
256
+ case 2:
257
+ return { tag: "EventActorSetAlarm", val: readEventActorSetAlarm(bc) };
258
+ default: {
259
+ bc.offset = offset;
260
+ throw new bare.BareError(offset, "invalid tag");
261
+ }
262
+ }
263
+ }
264
+ function writeEvent(bc, x) {
265
+ switch (x.tag) {
266
+ case "EventActorIntent": {
267
+ bare.writeU8(bc, 0);
268
+ writeEventActorIntent(bc, x.val);
269
+ break;
270
+ }
271
+ case "EventActorStateUpdate": {
272
+ bare.writeU8(bc, 1);
273
+ writeEventActorStateUpdate(bc, x.val);
274
+ break;
275
+ }
276
+ case "EventActorSetAlarm": {
277
+ bare.writeU8(bc, 2);
278
+ writeEventActorSetAlarm(bc, x.val);
279
+ break;
280
+ }
281
+ }
282
+ }
283
+ function readEventWrapper(bc) {
284
+ return {
285
+ index: bare.readI64(bc),
286
+ inner: readEvent(bc)
287
+ };
288
+ }
289
+ function writeEventWrapper(bc, x) {
290
+ bare.writeI64(bc, x.index);
291
+ writeEvent(bc, x.inner);
292
+ }
293
+ function read2(bc) {
294
+ return bare.readBool(bc) ? bare.readData(bc) : null;
295
+ }
296
+ function write2(bc, x) {
297
+ bare.writeBool(bc, x != null);
298
+ if (x != null) {
299
+ bare.writeData(bc, x);
300
+ }
301
+ }
302
+ function readActorConfig(bc) {
303
+ return {
304
+ name: bare.readString(bc),
305
+ key: read0(bc),
306
+ createTs: bare.readI64(bc),
307
+ input: read2(bc)
308
+ };
309
+ }
310
+ function writeActorConfig(bc, x) {
311
+ bare.writeString(bc, x.name);
312
+ write0(bc, x.key);
313
+ bare.writeI64(bc, x.createTs);
314
+ write2(bc, x.input);
315
+ }
316
+ function readCommandStartActor(bc) {
317
+ return {
318
+ actorId: readId(bc),
319
+ generation: bare.readU32(bc),
320
+ config: readActorConfig(bc)
321
+ };
322
+ }
323
+ function writeCommandStartActor(bc, x) {
324
+ writeId(bc, x.actorId);
325
+ bare.writeU32(bc, x.generation);
326
+ writeActorConfig(bc, x.config);
327
+ }
328
+ function readCommandStopActor(bc) {
329
+ return {
330
+ actorId: readId(bc),
331
+ generation: bare.readU32(bc)
332
+ };
333
+ }
334
+ function writeCommandStopActor(bc, x) {
335
+ writeId(bc, x.actorId);
336
+ bare.writeU32(bc, x.generation);
337
+ }
338
+ function readCommand(bc) {
339
+ const offset = bc.offset;
340
+ const tag = bare.readU8(bc);
341
+ switch (tag) {
342
+ case 0:
343
+ return { tag: "CommandStartActor", val: readCommandStartActor(bc) };
344
+ case 1:
345
+ return { tag: "CommandStopActor", val: readCommandStopActor(bc) };
346
+ default: {
347
+ bc.offset = offset;
348
+ throw new bare.BareError(offset, "invalid tag");
349
+ }
350
+ }
351
+ }
352
+ function writeCommand(bc, x) {
353
+ switch (x.tag) {
354
+ case "CommandStartActor": {
355
+ bare.writeU8(bc, 0);
356
+ writeCommandStartActor(bc, x.val);
357
+ break;
358
+ }
359
+ case "CommandStopActor": {
360
+ bare.writeU8(bc, 1);
361
+ writeCommandStopActor(bc, x.val);
362
+ break;
363
+ }
364
+ }
365
+ }
366
+ function readCommandWrapper(bc) {
367
+ return {
368
+ index: bare.readI64(bc),
369
+ inner: readCommand(bc)
370
+ };
371
+ }
372
+ function writeCommandWrapper(bc, x) {
373
+ bare.writeI64(bc, x.index);
374
+ writeCommand(bc, x.inner);
375
+ }
376
+ function read3(bc) {
377
+ const len = bare.readUintSafe(bc);
378
+ const result = /* @__PURE__ */ new Map();
379
+ for (let i = 0; i < len; i++) {
380
+ const offset = bc.offset;
381
+ const key = bare.readString(bc);
382
+ if (result.has(key)) {
383
+ bc.offset = offset;
384
+ throw new bare.BareError(offset, "duplicated key");
385
+ }
386
+ result.set(key, readActorName(bc));
387
+ }
388
+ return result;
389
+ }
390
+ function write3(bc, x) {
391
+ bare.writeUintSafe(bc, x.size);
392
+ for (const kv of x) {
393
+ bare.writeString(bc, kv[0]);
394
+ writeActorName(bc, kv[1]);
395
+ }
396
+ }
397
+ function read4(bc) {
398
+ return bare.readBool(bc) ? read3(bc) : null;
399
+ }
400
+ function write4(bc, x) {
401
+ bare.writeBool(bc, x != null);
402
+ if (x != null) {
403
+ write3(bc, x);
404
+ }
405
+ }
406
+ function read5(bc) {
407
+ return bare.readBool(bc) ? readJson(bc) : null;
408
+ }
409
+ function write5(bc, x) {
410
+ bare.writeBool(bc, x != null);
411
+ if (x != null) {
412
+ writeJson(bc, x);
413
+ }
414
+ }
415
+ function readToServerInit(bc) {
416
+ return {
417
+ name: bare.readString(bc),
418
+ version: bare.readU32(bc),
419
+ totalSlots: bare.readU32(bc),
420
+ lastCommandIdx: read1(bc),
421
+ prepopulateActorNames: read4(bc),
422
+ metadata: read5(bc)
423
+ };
424
+ }
425
+ function writeToServerInit(bc, x) {
426
+ bare.writeString(bc, x.name);
427
+ bare.writeU32(bc, x.version);
428
+ bare.writeU32(bc, x.totalSlots);
429
+ write1(bc, x.lastCommandIdx);
430
+ write4(bc, x.prepopulateActorNames);
431
+ write5(bc, x.metadata);
432
+ }
433
+ function readToServerEvents(bc) {
434
+ const len = bare.readUintSafe(bc);
435
+ if (len === 0) {
436
+ return [];
437
+ }
438
+ const result = [readEventWrapper(bc)];
439
+ for (let i = 1; i < len; i++) {
440
+ result[i] = readEventWrapper(bc);
441
+ }
442
+ return result;
443
+ }
444
+ function writeToServerEvents(bc, x) {
445
+ bare.writeUintSafe(bc, x.length);
446
+ for (let i = 0; i < x.length; i++) {
447
+ writeEventWrapper(bc, x[i]);
448
+ }
449
+ }
450
+ function readToServerAckCommands(bc) {
451
+ return {
452
+ lastCommandIdx: bare.readI64(bc)
453
+ };
454
+ }
455
+ function writeToServerAckCommands(bc, x) {
456
+ bare.writeI64(bc, x.lastCommandIdx);
457
+ }
458
+ function readToServerPing(bc) {
459
+ return {
460
+ ts: bare.readI64(bc)
461
+ };
462
+ }
463
+ function writeToServerPing(bc, x) {
464
+ bare.writeI64(bc, x.ts);
465
+ }
466
+ function read6(bc) {
467
+ const len = bare.readUintSafe(bc);
468
+ if (len === 0) {
469
+ return [];
470
+ }
471
+ const result = [readKvKey(bc)];
472
+ for (let i = 1; i < len; i++) {
473
+ result[i] = readKvKey(bc);
474
+ }
475
+ return result;
476
+ }
477
+ function write6(bc, x) {
478
+ bare.writeUintSafe(bc, x.length);
479
+ for (let i = 0; i < x.length; i++) {
480
+ writeKvKey(bc, x[i]);
481
+ }
482
+ }
483
+ function readKvGetRequest(bc) {
484
+ return {
485
+ keys: read6(bc)
486
+ };
487
+ }
488
+ function writeKvGetRequest(bc, x) {
489
+ write6(bc, x.keys);
490
+ }
491
+ function read7(bc) {
492
+ return bare.readBool(bc) ? bare.readBool(bc) : null;
493
+ }
494
+ function write7(bc, x) {
495
+ bare.writeBool(bc, x != null);
496
+ if (x != null) {
497
+ bare.writeBool(bc, x);
498
+ }
499
+ }
500
+ function read8(bc) {
501
+ return bare.readBool(bc) ? bare.readU64(bc) : null;
502
+ }
503
+ function write8(bc, x) {
504
+ bare.writeBool(bc, x != null);
505
+ if (x != null) {
506
+ bare.writeU64(bc, x);
507
+ }
508
+ }
509
+ function readKvListRequest(bc) {
510
+ return {
511
+ query: readKvListQuery(bc),
512
+ reverse: read7(bc),
513
+ limit: read8(bc)
514
+ };
515
+ }
516
+ function writeKvListRequest(bc, x) {
517
+ writeKvListQuery(bc, x.query);
518
+ write7(bc, x.reverse);
519
+ write8(bc, x.limit);
520
+ }
521
+ function read9(bc) {
522
+ const len = bare.readUintSafe(bc);
523
+ if (len === 0) {
524
+ return [];
525
+ }
526
+ const result = [readKvValue(bc)];
527
+ for (let i = 1; i < len; i++) {
528
+ result[i] = readKvValue(bc);
529
+ }
530
+ return result;
531
+ }
532
+ function write9(bc, x) {
533
+ bare.writeUintSafe(bc, x.length);
534
+ for (let i = 0; i < x.length; i++) {
535
+ writeKvValue(bc, x[i]);
536
+ }
537
+ }
538
+ function readKvPutRequest(bc) {
539
+ return {
540
+ keys: read6(bc),
541
+ values: read9(bc)
542
+ };
543
+ }
544
+ function writeKvPutRequest(bc, x) {
545
+ write6(bc, x.keys);
546
+ write9(bc, x.values);
547
+ }
548
+ function readKvDeleteRequest(bc) {
549
+ return {
550
+ keys: read6(bc)
551
+ };
552
+ }
553
+ function writeKvDeleteRequest(bc, x) {
554
+ write6(bc, x.keys);
555
+ }
556
+ function readKvRequestData(bc) {
557
+ const offset = bc.offset;
558
+ const tag = bare.readU8(bc);
559
+ switch (tag) {
560
+ case 0:
561
+ return { tag: "KvGetRequest", val: readKvGetRequest(bc) };
562
+ case 1:
563
+ return { tag: "KvListRequest", val: readKvListRequest(bc) };
564
+ case 2:
565
+ return { tag: "KvPutRequest", val: readKvPutRequest(bc) };
566
+ case 3:
567
+ return { tag: "KvDeleteRequest", val: readKvDeleteRequest(bc) };
568
+ case 4:
569
+ return { tag: "KvDropRequest", val: null };
570
+ default: {
571
+ bc.offset = offset;
572
+ throw new bare.BareError(offset, "invalid tag");
573
+ }
574
+ }
575
+ }
576
+ function writeKvRequestData(bc, x) {
577
+ switch (x.tag) {
578
+ case "KvGetRequest": {
579
+ bare.writeU8(bc, 0);
580
+ writeKvGetRequest(bc, x.val);
581
+ break;
582
+ }
583
+ case "KvListRequest": {
584
+ bare.writeU8(bc, 1);
585
+ writeKvListRequest(bc, x.val);
586
+ break;
587
+ }
588
+ case "KvPutRequest": {
589
+ bare.writeU8(bc, 2);
590
+ writeKvPutRequest(bc, x.val);
591
+ break;
592
+ }
593
+ case "KvDeleteRequest": {
594
+ bare.writeU8(bc, 3);
595
+ writeKvDeleteRequest(bc, x.val);
596
+ break;
597
+ }
598
+ case "KvDropRequest": {
599
+ bare.writeU8(bc, 4);
600
+ break;
601
+ }
602
+ }
603
+ }
604
+ function readToServerKvRequest(bc) {
605
+ return {
606
+ actorId: readId(bc),
607
+ requestId: bare.readU32(bc),
608
+ data: readKvRequestData(bc)
609
+ };
610
+ }
611
+ function writeToServerKvRequest(bc, x) {
612
+ writeId(bc, x.actorId);
613
+ bare.writeU32(bc, x.requestId);
614
+ writeKvRequestData(bc, x.data);
615
+ }
616
+ function readToServer(bc) {
617
+ const offset = bc.offset;
618
+ const tag = bare.readU8(bc);
619
+ switch (tag) {
620
+ case 0:
621
+ return { tag: "ToServerInit", val: readToServerInit(bc) };
622
+ case 1:
623
+ return { tag: "ToServerEvents", val: readToServerEvents(bc) };
624
+ case 2:
625
+ return { tag: "ToServerAckCommands", val: readToServerAckCommands(bc) };
626
+ case 3:
627
+ return { tag: "ToServerStopping", val: null };
628
+ case 4:
629
+ return { tag: "ToServerPing", val: readToServerPing(bc) };
630
+ case 5:
631
+ return { tag: "ToServerKvRequest", val: readToServerKvRequest(bc) };
632
+ default: {
633
+ bc.offset = offset;
634
+ throw new bare.BareError(offset, "invalid tag");
635
+ }
636
+ }
637
+ }
638
+ function writeToServer(bc, x) {
639
+ switch (x.tag) {
640
+ case "ToServerInit": {
641
+ bare.writeU8(bc, 0);
642
+ writeToServerInit(bc, x.val);
643
+ break;
644
+ }
645
+ case "ToServerEvents": {
646
+ bare.writeU8(bc, 1);
647
+ writeToServerEvents(bc, x.val);
648
+ break;
649
+ }
650
+ case "ToServerAckCommands": {
651
+ bare.writeU8(bc, 2);
652
+ writeToServerAckCommands(bc, x.val);
653
+ break;
654
+ }
655
+ case "ToServerStopping": {
656
+ bare.writeU8(bc, 3);
657
+ break;
658
+ }
659
+ case "ToServerPing": {
660
+ bare.writeU8(bc, 4);
661
+ writeToServerPing(bc, x.val);
662
+ break;
663
+ }
664
+ case "ToServerKvRequest": {
665
+ bare.writeU8(bc, 5);
666
+ writeToServerKvRequest(bc, x.val);
667
+ break;
668
+ }
669
+ }
670
+ }
671
+ function encodeToServer(x, config) {
672
+ const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG;
673
+ const bc = new bare.ByteCursor(
674
+ new Uint8Array(fullConfig.initialBufferLength),
675
+ fullConfig
676
+ );
677
+ writeToServer(bc, x);
678
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
679
+ }
680
+ function decodeToServer(bytes) {
681
+ const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG);
682
+ const result = readToServer(bc);
683
+ if (bc.offset < bc.view.byteLength) {
684
+ throw new bare.BareError(bc.offset, "remaining bytes");
685
+ }
686
+ return result;
687
+ }
688
+ function readProtocolMetadata(bc) {
689
+ return {
690
+ runnerLostThreshold: bare.readI64(bc)
691
+ };
692
+ }
693
+ function writeProtocolMetadata(bc, x) {
694
+ bare.writeI64(bc, x.runnerLostThreshold);
695
+ }
696
+ function readToClientInit(bc) {
697
+ return {
698
+ runnerId: readId(bc),
699
+ lastEventIdx: bare.readI64(bc),
700
+ metadata: readProtocolMetadata(bc)
701
+ };
702
+ }
703
+ function writeToClientInit(bc, x) {
704
+ writeId(bc, x.runnerId);
705
+ bare.writeI64(bc, x.lastEventIdx);
706
+ writeProtocolMetadata(bc, x.metadata);
707
+ }
708
+ function readToClientCommands(bc) {
709
+ const len = bare.readUintSafe(bc);
710
+ if (len === 0) {
711
+ return [];
712
+ }
713
+ const result = [readCommandWrapper(bc)];
714
+ for (let i = 1; i < len; i++) {
715
+ result[i] = readCommandWrapper(bc);
716
+ }
717
+ return result;
718
+ }
719
+ function writeToClientCommands(bc, x) {
720
+ bare.writeUintSafe(bc, x.length);
721
+ for (let i = 0; i < x.length; i++) {
722
+ writeCommandWrapper(bc, x[i]);
723
+ }
724
+ }
725
+ function readToClientAckEvents(bc) {
726
+ return {
727
+ lastEventIdx: bare.readI64(bc)
728
+ };
729
+ }
730
+ function writeToClientAckEvents(bc, x) {
731
+ bare.writeI64(bc, x.lastEventIdx);
732
+ }
733
+ function readKvErrorResponse(bc) {
734
+ return {
735
+ message: bare.readString(bc)
736
+ };
737
+ }
738
+ function writeKvErrorResponse(bc, x) {
739
+ bare.writeString(bc, x.message);
740
+ }
741
+ function read10(bc) {
742
+ const len = bare.readUintSafe(bc);
743
+ if (len === 0) {
744
+ return [];
745
+ }
746
+ const result = [readKvMetadata(bc)];
747
+ for (let i = 1; i < len; i++) {
748
+ result[i] = readKvMetadata(bc);
749
+ }
750
+ return result;
751
+ }
752
+ function write10(bc, x) {
753
+ bare.writeUintSafe(bc, x.length);
754
+ for (let i = 0; i < x.length; i++) {
755
+ writeKvMetadata(bc, x[i]);
756
+ }
757
+ }
758
+ function readKvGetResponse(bc) {
759
+ return {
760
+ keys: read6(bc),
761
+ values: read9(bc),
762
+ metadata: read10(bc)
763
+ };
764
+ }
765
+ function writeKvGetResponse(bc, x) {
766
+ write6(bc, x.keys);
767
+ write9(bc, x.values);
768
+ write10(bc, x.metadata);
769
+ }
770
+ function readKvListResponse(bc) {
771
+ return {
772
+ keys: read6(bc),
773
+ values: read9(bc),
774
+ metadata: read10(bc)
775
+ };
776
+ }
777
+ function writeKvListResponse(bc, x) {
778
+ write6(bc, x.keys);
779
+ write9(bc, x.values);
780
+ write10(bc, x.metadata);
781
+ }
782
+ function readKvResponseData(bc) {
783
+ const offset = bc.offset;
784
+ const tag = bare.readU8(bc);
785
+ switch (tag) {
786
+ case 0:
787
+ return { tag: "KvErrorResponse", val: readKvErrorResponse(bc) };
788
+ case 1:
789
+ return { tag: "KvGetResponse", val: readKvGetResponse(bc) };
790
+ case 2:
791
+ return { tag: "KvListResponse", val: readKvListResponse(bc) };
792
+ case 3:
793
+ return { tag: "KvPutResponse", val: null };
794
+ case 4:
795
+ return { tag: "KvDeleteResponse", val: null };
796
+ case 5:
797
+ return { tag: "KvDropResponse", val: null };
798
+ default: {
799
+ bc.offset = offset;
800
+ throw new bare.BareError(offset, "invalid tag");
801
+ }
802
+ }
803
+ }
804
+ function writeKvResponseData(bc, x) {
805
+ switch (x.tag) {
806
+ case "KvErrorResponse": {
807
+ bare.writeU8(bc, 0);
808
+ writeKvErrorResponse(bc, x.val);
809
+ break;
810
+ }
811
+ case "KvGetResponse": {
812
+ bare.writeU8(bc, 1);
813
+ writeKvGetResponse(bc, x.val);
814
+ break;
815
+ }
816
+ case "KvListResponse": {
817
+ bare.writeU8(bc, 2);
818
+ writeKvListResponse(bc, x.val);
819
+ break;
820
+ }
821
+ case "KvPutResponse": {
822
+ bare.writeU8(bc, 3);
823
+ break;
824
+ }
825
+ case "KvDeleteResponse": {
826
+ bare.writeU8(bc, 4);
827
+ break;
828
+ }
829
+ case "KvDropResponse": {
830
+ bare.writeU8(bc, 5);
831
+ break;
832
+ }
833
+ }
834
+ }
835
+ function readToClientKvResponse(bc) {
836
+ return {
837
+ requestId: bare.readU32(bc),
838
+ data: readKvResponseData(bc)
839
+ };
840
+ }
841
+ function writeToClientKvResponse(bc, x) {
842
+ bare.writeU32(bc, x.requestId);
843
+ writeKvResponseData(bc, x.data);
844
+ }
845
+ function readToClient(bc) {
846
+ const offset = bc.offset;
847
+ const tag = bare.readU8(bc);
848
+ switch (tag) {
849
+ case 0:
850
+ return { tag: "ToClientInit", val: readToClientInit(bc) };
851
+ case 1:
852
+ return { tag: "ToClientCommands", val: readToClientCommands(bc) };
853
+ case 2:
854
+ return { tag: "ToClientAckEvents", val: readToClientAckEvents(bc) };
855
+ case 3:
856
+ return { tag: "ToClientKvResponse", val: readToClientKvResponse(bc) };
857
+ default: {
858
+ bc.offset = offset;
859
+ throw new bare.BareError(offset, "invalid tag");
860
+ }
861
+ }
862
+ }
863
+ function writeToClient(bc, x) {
864
+ switch (x.tag) {
865
+ case "ToClientInit": {
866
+ bare.writeU8(bc, 0);
867
+ writeToClientInit(bc, x.val);
868
+ break;
869
+ }
870
+ case "ToClientCommands": {
871
+ bare.writeU8(bc, 1);
872
+ writeToClientCommands(bc, x.val);
873
+ break;
874
+ }
875
+ case "ToClientAckEvents": {
876
+ bare.writeU8(bc, 2);
877
+ writeToClientAckEvents(bc, x.val);
878
+ break;
879
+ }
880
+ case "ToClientKvResponse": {
881
+ bare.writeU8(bc, 3);
882
+ writeToClientKvResponse(bc, x.val);
883
+ break;
884
+ }
885
+ }
886
+ }
887
+ function encodeToClient(x, config) {
888
+ const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG;
889
+ const bc = new bare.ByteCursor(
890
+ new Uint8Array(fullConfig.initialBufferLength),
891
+ fullConfig
892
+ );
893
+ writeToClient(bc, x);
894
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
895
+ }
896
+ function decodeToClient(bytes) {
897
+ const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG);
898
+ const result = readToClient(bc);
899
+ if (bc.offset < bc.view.byteLength) {
900
+ throw new bare.BareError(bc.offset, "remaining bytes");
901
+ }
902
+ return result;
903
+ }
904
+ export {
905
+ StopCode,
906
+ decodeToClient,
907
+ decodeToServer,
908
+ encodeToClient,
909
+ encodeToServer,
910
+ readActorConfig,
911
+ readActorIntent,
912
+ readActorName,
913
+ readActorState,
914
+ readActorStateStopped,
915
+ readCommand,
916
+ readCommandStartActor,
917
+ readCommandStopActor,
918
+ readCommandWrapper,
919
+ readEvent,
920
+ readEventActorIntent,
921
+ readEventActorSetAlarm,
922
+ readEventActorStateUpdate,
923
+ readEventWrapper,
924
+ readId,
925
+ readJson,
926
+ readKvDeleteRequest,
927
+ readKvErrorResponse,
928
+ readKvGetRequest,
929
+ readKvGetResponse,
930
+ readKvKey,
931
+ readKvListPrefixQuery,
932
+ readKvListQuery,
933
+ readKvListRangeQuery,
934
+ readKvListRequest,
935
+ readKvListResponse,
936
+ readKvMetadata,
937
+ readKvPutRequest,
938
+ readKvRequestData,
939
+ readKvResponseData,
940
+ readKvValue,
941
+ readProtocolMetadata,
942
+ readStopCode,
943
+ readToClient,
944
+ readToClientAckEvents,
945
+ readToClientCommands,
946
+ readToClientInit,
947
+ readToClientKvResponse,
948
+ readToServer,
949
+ readToServerAckCommands,
950
+ readToServerEvents,
951
+ readToServerInit,
952
+ readToServerKvRequest,
953
+ readToServerPing,
954
+ writeActorConfig,
955
+ writeActorIntent,
956
+ writeActorName,
957
+ writeActorState,
958
+ writeActorStateStopped,
959
+ writeCommand,
960
+ writeCommandStartActor,
961
+ writeCommandStopActor,
962
+ writeCommandWrapper,
963
+ writeEvent,
964
+ writeEventActorIntent,
965
+ writeEventActorSetAlarm,
966
+ writeEventActorStateUpdate,
967
+ writeEventWrapper,
968
+ writeId,
969
+ writeJson,
970
+ writeKvDeleteRequest,
971
+ writeKvErrorResponse,
972
+ writeKvGetRequest,
973
+ writeKvGetResponse,
974
+ writeKvKey,
975
+ writeKvListPrefixQuery,
976
+ writeKvListQuery,
977
+ writeKvListRangeQuery,
978
+ writeKvListRequest,
979
+ writeKvListResponse,
980
+ writeKvMetadata,
981
+ writeKvPutRequest,
982
+ writeKvRequestData,
983
+ writeKvResponseData,
984
+ writeKvValue,
985
+ writeProtocolMetadata,
986
+ writeStopCode,
987
+ writeToClient,
988
+ writeToClientAckEvents,
989
+ writeToClientCommands,
990
+ writeToClientInit,
991
+ writeToClientKvResponse,
992
+ writeToServer,
993
+ writeToServerAckCommands,
994
+ writeToServerEvents,
995
+ writeToServerInit,
996
+ writeToServerKvRequest,
997
+ writeToServerPing
998
+ };
999
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@rivetkit/engine-runner-protocol",
3
+ "version": "25.7.1-rc.1",
4
+ "license": "Apache-2.0",
5
+ "type": "module",
6
+ "exports": {
7
+ "import": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ },
11
+ "require": {
12
+ "types": "./dist/index.d.cts",
13
+ "default": "./dist/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist/**/*.js",
18
+ "dist/**/*.d.ts"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsup src/index.ts",
22
+ "clean": "rm -rf dist",
23
+ "check-types": "tsc --noEmit"
24
+ },
25
+ "types": "dist/index.d.ts",
26
+ "dependencies": {
27
+ "@bare-ts/lib": "^0.4.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^20.0.0",
31
+ "typescript": "^5.0.0",
32
+ "tsup": "^8.4.0"
33
+ }
34
+ }