rivetkit 2.0.33 → 2.0.34-rc.2
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/schemas/actor-inspector/v1.ts +784 -0
- package/dist/tsup/actor/errors.cjs +7 -2
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/actor/errors.d.cts +7 -1
- package/dist/tsup/actor/errors.d.ts +7 -1
- package/dist/tsup/actor/errors.js +5 -1
- package/dist/tsup/chunk-5QDI4DPU.cjs +1794 -0
- package/dist/tsup/chunk-5QDI4DPU.cjs.map +1 -0
- package/dist/tsup/{chunk-KGS52S7U.cjs → chunk-6EGKPHZC.cjs} +3 -3
- package/dist/tsup/{chunk-KGS52S7U.cjs.map → chunk-6EGKPHZC.cjs.map} +1 -1
- package/dist/tsup/{chunk-V35I3JSW.js → chunk-6KPMUCTX.js} +21 -2
- package/dist/tsup/{chunk-V35I3JSW.js.map → chunk-6KPMUCTX.js.map} +1 -1
- package/dist/tsup/{chunk-2RYCGQ6O.cjs → chunk-7RMEZZL3.cjs} +4040 -5735
- package/dist/tsup/chunk-7RMEZZL3.cjs.map +1 -0
- package/dist/tsup/chunk-BGADCIQL.js +1935 -0
- package/dist/tsup/chunk-BGADCIQL.js.map +1 -0
- package/dist/tsup/chunk-DWR6ZD2K.js +1794 -0
- package/dist/tsup/chunk-DWR6ZD2K.js.map +1 -0
- package/dist/tsup/chunk-E6ZE2YEA.js +664 -0
- package/dist/tsup/chunk-E6ZE2YEA.js.map +1 -0
- package/dist/tsup/{chunk-I2OKFOBV.cjs → chunk-FWT2BTVT.cjs} +21 -7
- package/dist/tsup/chunk-FWT2BTVT.cjs.map +1 -0
- package/dist/tsup/chunk-GBENOENJ.cjs +8 -0
- package/dist/tsup/chunk-GBENOENJ.cjs.map +1 -0
- package/dist/tsup/{chunk-WVHNOIV6.js → chunk-GJBHS65Y.js} +4014 -5709
- package/dist/tsup/chunk-GJBHS65Y.js.map +1 -0
- package/dist/tsup/{chunk-P27C4N62.js → chunk-JPLPHP2V.js} +2 -2
- package/dist/tsup/chunk-KDFWJKMJ.cjs +664 -0
- package/dist/tsup/chunk-KDFWJKMJ.cjs.map +1 -0
- package/dist/tsup/chunk-MPZEV7DS.cjs +5009 -0
- package/dist/tsup/chunk-MPZEV7DS.cjs.map +1 -0
- package/dist/tsup/chunk-OXWA6EGT.cjs +1938 -0
- package/dist/tsup/chunk-OXWA6EGT.cjs.map +1 -0
- package/dist/tsup/{chunk-CYTXGWMM.cjs → chunk-RKR6D55I.cjs} +73 -22
- package/dist/tsup/chunk-RKR6D55I.cjs.map +1 -0
- package/dist/tsup/chunk-UHOLGS4D.js +5009 -0
- package/dist/tsup/chunk-UHOLGS4D.js.map +1 -0
- package/dist/tsup/{chunk-DG24FYCM.js → chunk-UOAIQS7W.js} +20 -35
- package/dist/tsup/chunk-UOAIQS7W.js.map +1 -0
- package/dist/tsup/{chunk-4X2BKTR7.cjs → chunk-VFTPFCVZ.cjs} +21 -36
- package/dist/tsup/chunk-VFTPFCVZ.cjs.map +1 -0
- package/dist/tsup/{chunk-7DKU5TBR.js → chunk-Y7VZW5NS.js} +66 -15
- package/dist/tsup/chunk-Y7VZW5NS.js.map +1 -0
- package/dist/tsup/client/mod.cjs +10 -9
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +47 -7
- package/dist/tsup/client/mod.d.ts +47 -7
- package/dist/tsup/client/mod.js +11 -11
- package/dist/tsup/common/log.cjs +4 -3
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +3 -3
- package/dist/tsup/common/log.d.ts +3 -3
- package/dist/tsup/common/log.js +2 -2
- package/dist/tsup/common/websocket.cjs +5 -4
- package/dist/tsup/common/websocket.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +3 -3
- package/dist/tsup/{config-D6nMVDna.d.cts → config-D6cZz77D.d.cts} +909 -785
- package/dist/tsup/{config-DN0AurPi.d.ts → config-XMw_wSmw.d.ts} +909 -785
- package/dist/tsup/driver-CgwC-zN5.d.cts +13 -0
- package/dist/tsup/driver-NbRczJQP.d.ts +13 -0
- package/dist/tsup/driver-helpers/mod.cjs +6 -10
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -1
- package/dist/tsup/driver-helpers/mod.d.cts +15 -8
- package/dist/tsup/driver-helpers/mod.d.ts +15 -8
- package/dist/tsup/driver-helpers/mod.js +7 -12
- package/dist/tsup/driver-test-suite/mod.cjs +69 -933
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
- package/dist/tsup/driver-test-suite/mod.d.cts +6 -3
- package/dist/tsup/driver-test-suite/mod.d.ts +6 -3
- package/dist/tsup/driver-test-suite/mod.js +379 -1244
- package/dist/tsup/driver-test-suite/mod.js.map +1 -1
- package/dist/tsup/inspector/mod.cjs +82 -6
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +7 -493
- package/dist/tsup/inspector/mod.d.ts +7 -493
- package/dist/tsup/inspector/mod.js +133 -58
- package/dist/tsup/kv-CTM8sCvx.d.cts +7 -0
- package/dist/tsup/kv-CTM8sCvx.d.ts +7 -0
- package/dist/tsup/mod.cjs +21 -10
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +29 -37
- package/dist/tsup/mod.d.ts +29 -37
- package/dist/tsup/mod.js +26 -16
- package/dist/tsup/test/mod.cjs +10 -12
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +5 -3
- package/dist/tsup/test/mod.d.ts +5 -3
- package/dist/tsup/test/mod.js +8 -11
- package/dist/tsup/utils.cjs +4 -3
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.d.cts +7 -1
- package/dist/tsup/utils.d.ts +7 -1
- package/dist/tsup/utils.js +2 -2
- package/dist/tsup/v1-Gq4avTK3.d.cts +240 -0
- package/dist/tsup/v1-Gq4avTK3.d.ts +240 -0
- package/package.json +9 -6
- package/src/actor/config.ts +37 -36
- package/src/actor/conn/drivers/websocket.ts +4 -4
- package/src/actor/contexts/action.ts +17 -1
- package/src/actor/contexts/{actor.ts → base/actor.ts} +37 -11
- package/src/actor/contexts/{conn-init.ts → base/conn-init.ts} +21 -4
- package/src/actor/contexts/{conn.ts → base/conn.ts} +19 -3
- package/src/actor/contexts/before-action-response.ts +35 -0
- package/src/actor/contexts/before-connect.ts +26 -0
- package/src/actor/contexts/connect.ts +35 -0
- package/src/actor/contexts/create-conn-state.ts +15 -1
- package/src/actor/contexts/create-vars.ts +26 -0
- package/src/actor/contexts/create.ts +26 -0
- package/src/actor/contexts/destroy.ts +36 -0
- package/src/actor/contexts/disconnect.ts +37 -0
- package/src/actor/contexts/index.ts +32 -0
- package/src/actor/contexts/request.ts +16 -1
- package/src/actor/contexts/sleep.ts +36 -0
- package/src/actor/contexts/state-change.ts +36 -0
- package/src/actor/contexts/wake.ts +36 -0
- package/src/actor/contexts/websocket.ts +16 -1
- package/src/actor/definition.ts +4 -36
- package/src/actor/driver.ts +3 -5
- package/src/actor/errors.ts +19 -0
- package/src/actor/instance/connection-manager.ts +10 -8
- package/src/actor/instance/mod.ts +14 -85
- package/src/actor/mod.ts +2 -16
- package/src/actor/protocol/old.ts +8 -2
- package/src/actor/router-endpoints.ts +14 -8
- package/src/actor/router-websocket-endpoints.ts +38 -41
- package/src/actor/router.ts +48 -70
- package/src/actor/utils.ts +0 -11
- package/src/client/actor-conn.ts +102 -40
- package/src/client/client.ts +5 -5
- package/src/client/config.ts +115 -21
- package/src/client/errors.ts +70 -0
- package/src/client/mod.ts +11 -3
- package/src/client/raw-utils.ts +2 -2
- package/src/common/actor-router-consts.ts +5 -0
- package/src/common/inline-websocket-adapter.ts +92 -388
- package/src/common/log.ts +7 -17
- package/src/common/router.ts +18 -18
- package/src/common/utils.ts +3 -2
- package/src/common/websocket-interface.ts +7 -59
- package/src/devtools-loader/index.ts +33 -0
- package/src/devtools-loader/log.ts +5 -0
- package/src/driver-helpers/mod.ts +1 -5
- package/src/driver-test-suite/mod.ts +23 -29
- package/src/driver-test-suite/test-inline-client-driver.ts +25 -327
- package/src/driver-test-suite/tests/actor-inspector.ts +356 -674
- package/src/driver-test-suite/utils.ts +2 -2
- package/src/drivers/default.ts +9 -11
- package/src/drivers/engine/actor-driver.ts +42 -39
- package/src/drivers/engine/config.ts +34 -18
- package/src/drivers/engine/mod.ts +10 -9
- package/src/drivers/file-system/actor.ts +5 -9
- package/src/drivers/file-system/global-state.ts +8 -27
- package/src/drivers/file-system/manager.ts +71 -158
- package/src/drivers/file-system/mod.ts +8 -9
- package/src/engine-process/constants.ts +2 -0
- package/src/engine-process/mod.ts +13 -13
- package/src/globals.d.ts +28 -0
- package/src/inspector/actor-inspector.ts +230 -0
- package/src/inspector/config.ts +9 -14
- package/src/inspector/handler.ts +191 -0
- package/src/inspector/mod.ts +2 -3
- package/src/inspector/utils.ts +16 -50
- package/src/manager/driver.ts +12 -23
- package/src/manager/gateway.ts +126 -143
- package/src/manager/mod.ts +1 -1
- package/src/manager/router.ts +480 -606
- package/src/manager-api/actors.ts +26 -0
- package/src/mod.ts +3 -1
- package/src/registry/config/driver.ts +21 -0
- package/src/registry/config/index.ts +256 -0
- package/src/registry/{run-config.ts → config/legacy-runner.ts} +37 -20
- package/src/registry/config/runner.ts +21 -0
- package/src/registry/config/serverless.ts +61 -0
- package/src/registry/index.ts +192 -0
- package/src/registry/serve.ts +43 -12
- package/src/remote-manager-driver/actor-http-client.ts +2 -2
- package/src/remote-manager-driver/actor-websocket-client.ts +7 -1
- package/src/remote-manager-driver/api-endpoints.ts +21 -3
- package/src/remote-manager-driver/api-utils.ts +2 -1
- package/src/remote-manager-driver/metadata.ts +12 -6
- package/src/remote-manager-driver/mod.ts +52 -46
- package/src/schemas/actor-inspector/mod.ts +1 -0
- package/src/schemas/actor-inspector/versioned.ts +46 -0
- package/src/serverless/configure.ts +79 -0
- package/src/serverless/log.ts +5 -0
- package/src/serverless/router.ts +101 -0
- package/src/test/mod.ts +20 -24
- package/src/utils/crypto.ts +24 -0
- package/src/utils/endpoint-parser.test.ts +189 -0
- package/src/utils/endpoint-parser.ts +119 -0
- package/src/utils/env-vars.ts +58 -0
- package/src/utils/router.ts +83 -0
- package/src/utils.ts +8 -0
- package/dist/tsup/chunk-2RYCGQ6O.cjs.map +0 -1
- package/dist/tsup/chunk-3LZ3ARJ4.cjs +0 -99
- package/dist/tsup/chunk-3LZ3ARJ4.cjs.map +0 -1
- package/dist/tsup/chunk-4X2BKTR7.cjs.map +0 -1
- package/dist/tsup/chunk-7DKU5TBR.js.map +0 -1
- package/dist/tsup/chunk-CVASTHX7.cjs +0 -5455
- package/dist/tsup/chunk-CVASTHX7.cjs.map +0 -1
- package/dist/tsup/chunk-CYTXGWMM.cjs.map +0 -1
- package/dist/tsup/chunk-DG24FYCM.js.map +0 -1
- package/dist/tsup/chunk-EY6CIDGE.js +0 -891
- package/dist/tsup/chunk-EY6CIDGE.js.map +0 -1
- package/dist/tsup/chunk-GRBSQZ4E.js +0 -5454
- package/dist/tsup/chunk-GRBSQZ4E.js.map +0 -1
- package/dist/tsup/chunk-I2OKFOBV.cjs.map +0 -1
- package/dist/tsup/chunk-LJ5I6TXW.cjs +0 -20
- package/dist/tsup/chunk-LJ5I6TXW.cjs.map +0 -1
- package/dist/tsup/chunk-OJHMV5QA.js +0 -99
- package/dist/tsup/chunk-OJHMV5QA.js.map +0 -1
- package/dist/tsup/chunk-T7L4ZGG2.cjs +0 -330
- package/dist/tsup/chunk-T7L4ZGG2.cjs.map +0 -1
- package/dist/tsup/chunk-TAJ5PRTG.js +0 -330
- package/dist/tsup/chunk-TAJ5PRTG.js.map +0 -1
- package/dist/tsup/chunk-WVHNOIV6.js.map +0 -1
- package/dist/tsup/chunk-XEV2PLVV.cjs +0 -235
- package/dist/tsup/chunk-XEV2PLVV.cjs.map +0 -1
- package/dist/tsup/chunk-XOSCZ67Y.cjs +0 -891
- package/dist/tsup/chunk-XOSCZ67Y.cjs.map +0 -1
- package/dist/tsup/chunk-YTHFP34X.js +0 -235
- package/dist/tsup/chunk-YTHFP34X.js.map +0 -1
- package/dist/tsup/chunk-ZPWVEFBB.js +0 -20
- package/dist/tsup/chunk-ZPWVEFBB.js.map +0 -1
- package/src/actor/contexts/on-before-connect.ts +0 -13
- package/src/actor/contexts/on-connect.ts +0 -22
- package/src/inspector/actor.ts +0 -339
- package/src/inspector/manager.ts +0 -93
- package/src/inspector/protocol/actor.ts +0 -10
- package/src/inspector/protocol/common.ts +0 -196
- package/src/inspector/protocol/manager.ts +0 -10
- package/src/inspector/protocol/mod.ts +0 -2
- package/src/registry/config.ts +0 -40
- package/src/registry/mod.ts +0 -359
- package/src/test/config.ts +0 -17
- /package/dist/tsup/{chunk-P27C4N62.js.map → chunk-JPLPHP2V.js.map} +0 -0
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
// @generated - post-processed by compile-bare.ts
|
|
2
|
+
import * as bare from "@rivetkit/bare-ts"
|
|
3
|
+
|
|
4
|
+
const config = /* @__PURE__ */ bare.Config({})
|
|
5
|
+
|
|
6
|
+
export type uint = bigint
|
|
7
|
+
|
|
8
|
+
export type PatchStateRequest = {
|
|
9
|
+
readonly state: ArrayBuffer,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function readPatchStateRequest(bc: bare.ByteCursor): PatchStateRequest {
|
|
13
|
+
return {
|
|
14
|
+
state: bare.readData(bc),
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function writePatchStateRequest(bc: bare.ByteCursor, x: PatchStateRequest): void {
|
|
19
|
+
bare.writeData(bc, x.state)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type ActionRequest = {
|
|
23
|
+
readonly id: uint,
|
|
24
|
+
readonly name: string,
|
|
25
|
+
readonly args: ArrayBuffer,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function readActionRequest(bc: bare.ByteCursor): ActionRequest {
|
|
29
|
+
return {
|
|
30
|
+
id: bare.readUint(bc),
|
|
31
|
+
name: bare.readString(bc),
|
|
32
|
+
args: bare.readData(bc),
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function writeActionRequest(bc: bare.ByteCursor, x: ActionRequest): void {
|
|
37
|
+
bare.writeUint(bc, x.id)
|
|
38
|
+
bare.writeString(bc, x.name)
|
|
39
|
+
bare.writeData(bc, x.args)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type StateRequest = {
|
|
43
|
+
readonly id: uint,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function readStateRequest(bc: bare.ByteCursor): StateRequest {
|
|
47
|
+
return {
|
|
48
|
+
id: bare.readUint(bc),
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function writeStateRequest(bc: bare.ByteCursor, x: StateRequest): void {
|
|
53
|
+
bare.writeUint(bc, x.id)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type ConnectionsRequest = {
|
|
57
|
+
readonly id: uint,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function readConnectionsRequest(bc: bare.ByteCursor): ConnectionsRequest {
|
|
61
|
+
return {
|
|
62
|
+
id: bare.readUint(bc),
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function writeConnectionsRequest(bc: bare.ByteCursor, x: ConnectionsRequest): void {
|
|
67
|
+
bare.writeUint(bc, x.id)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type EventsRequest = {
|
|
71
|
+
readonly id: uint,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function readEventsRequest(bc: bare.ByteCursor): EventsRequest {
|
|
75
|
+
return {
|
|
76
|
+
id: bare.readUint(bc),
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function writeEventsRequest(bc: bare.ByteCursor, x: EventsRequest): void {
|
|
81
|
+
bare.writeUint(bc, x.id)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type ClearEventsRequest = {
|
|
85
|
+
readonly id: uint,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function readClearEventsRequest(bc: bare.ByteCursor): ClearEventsRequest {
|
|
89
|
+
return {
|
|
90
|
+
id: bare.readUint(bc),
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function writeClearEventsRequest(bc: bare.ByteCursor, x: ClearEventsRequest): void {
|
|
95
|
+
bare.writeUint(bc, x.id)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type RpcsListRequest = {
|
|
99
|
+
readonly id: uint,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function readRpcsListRequest(bc: bare.ByteCursor): RpcsListRequest {
|
|
103
|
+
return {
|
|
104
|
+
id: bare.readUint(bc),
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function writeRpcsListRequest(bc: bare.ByteCursor, x: RpcsListRequest): void {
|
|
109
|
+
bare.writeUint(bc, x.id)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type ToServerBody =
|
|
113
|
+
| { readonly tag: "PatchStateRequest", readonly val: PatchStateRequest }
|
|
114
|
+
| { readonly tag: "StateRequest", readonly val: StateRequest }
|
|
115
|
+
| { readonly tag: "ConnectionsRequest", readonly val: ConnectionsRequest }
|
|
116
|
+
| { readonly tag: "ActionRequest", readonly val: ActionRequest }
|
|
117
|
+
| { readonly tag: "EventsRequest", readonly val: EventsRequest }
|
|
118
|
+
| { readonly tag: "ClearEventsRequest", readonly val: ClearEventsRequest }
|
|
119
|
+
| { readonly tag: "RpcsListRequest", readonly val: RpcsListRequest }
|
|
120
|
+
|
|
121
|
+
export function readToServerBody(bc: bare.ByteCursor): ToServerBody {
|
|
122
|
+
const offset = bc.offset
|
|
123
|
+
const tag = bare.readU8(bc)
|
|
124
|
+
switch (tag) {
|
|
125
|
+
case 0:
|
|
126
|
+
return { tag: "PatchStateRequest", val: readPatchStateRequest(bc) }
|
|
127
|
+
case 1:
|
|
128
|
+
return { tag: "StateRequest", val: readStateRequest(bc) }
|
|
129
|
+
case 2:
|
|
130
|
+
return { tag: "ConnectionsRequest", val: readConnectionsRequest(bc) }
|
|
131
|
+
case 3:
|
|
132
|
+
return { tag: "ActionRequest", val: readActionRequest(bc) }
|
|
133
|
+
case 4:
|
|
134
|
+
return { tag: "EventsRequest", val: readEventsRequest(bc) }
|
|
135
|
+
case 5:
|
|
136
|
+
return { tag: "ClearEventsRequest", val: readClearEventsRequest(bc) }
|
|
137
|
+
case 6:
|
|
138
|
+
return { tag: "RpcsListRequest", val: readRpcsListRequest(bc) }
|
|
139
|
+
default: {
|
|
140
|
+
bc.offset = offset
|
|
141
|
+
throw new bare.BareError(offset, "invalid tag")
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function writeToServerBody(bc: bare.ByteCursor, x: ToServerBody): void {
|
|
147
|
+
switch (x.tag) {
|
|
148
|
+
case "PatchStateRequest": {
|
|
149
|
+
bare.writeU8(bc, 0)
|
|
150
|
+
writePatchStateRequest(bc, x.val)
|
|
151
|
+
break
|
|
152
|
+
}
|
|
153
|
+
case "StateRequest": {
|
|
154
|
+
bare.writeU8(bc, 1)
|
|
155
|
+
writeStateRequest(bc, x.val)
|
|
156
|
+
break
|
|
157
|
+
}
|
|
158
|
+
case "ConnectionsRequest": {
|
|
159
|
+
bare.writeU8(bc, 2)
|
|
160
|
+
writeConnectionsRequest(bc, x.val)
|
|
161
|
+
break
|
|
162
|
+
}
|
|
163
|
+
case "ActionRequest": {
|
|
164
|
+
bare.writeU8(bc, 3)
|
|
165
|
+
writeActionRequest(bc, x.val)
|
|
166
|
+
break
|
|
167
|
+
}
|
|
168
|
+
case "EventsRequest": {
|
|
169
|
+
bare.writeU8(bc, 4)
|
|
170
|
+
writeEventsRequest(bc, x.val)
|
|
171
|
+
break
|
|
172
|
+
}
|
|
173
|
+
case "ClearEventsRequest": {
|
|
174
|
+
bare.writeU8(bc, 5)
|
|
175
|
+
writeClearEventsRequest(bc, x.val)
|
|
176
|
+
break
|
|
177
|
+
}
|
|
178
|
+
case "RpcsListRequest": {
|
|
179
|
+
bare.writeU8(bc, 6)
|
|
180
|
+
writeRpcsListRequest(bc, x.val)
|
|
181
|
+
break
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export type ToServer = {
|
|
187
|
+
readonly body: ToServerBody,
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function readToServer(bc: bare.ByteCursor): ToServer {
|
|
191
|
+
return {
|
|
192
|
+
body: readToServerBody(bc),
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function writeToServer(bc: bare.ByteCursor, x: ToServer): void {
|
|
197
|
+
writeToServerBody(bc, x.body)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function encodeToServer(x: ToServer): Uint8Array {
|
|
201
|
+
const bc = new bare.ByteCursor(
|
|
202
|
+
new Uint8Array(config.initialBufferLength),
|
|
203
|
+
config
|
|
204
|
+
)
|
|
205
|
+
writeToServer(bc, x)
|
|
206
|
+
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function decodeToServer(bytes: Uint8Array): ToServer {
|
|
210
|
+
const bc = new bare.ByteCursor(bytes, config)
|
|
211
|
+
const result = readToServer(bc)
|
|
212
|
+
if (bc.offset < bc.view.byteLength) {
|
|
213
|
+
throw new bare.BareError(bc.offset, "remaining bytes")
|
|
214
|
+
}
|
|
215
|
+
return result
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export type State = ArrayBuffer
|
|
219
|
+
|
|
220
|
+
export function readState(bc: bare.ByteCursor): State {
|
|
221
|
+
return bare.readData(bc)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function writeState(bc: bare.ByteCursor, x: State): void {
|
|
225
|
+
bare.writeData(bc, x)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export type Connection = {
|
|
229
|
+
readonly id: string,
|
|
230
|
+
readonly details: ArrayBuffer,
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function readConnection(bc: bare.ByteCursor): Connection {
|
|
234
|
+
return {
|
|
235
|
+
id: bare.readString(bc),
|
|
236
|
+
details: bare.readData(bc),
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function writeConnection(bc: bare.ByteCursor, x: Connection): void {
|
|
241
|
+
bare.writeString(bc, x.id)
|
|
242
|
+
bare.writeData(bc, x.details)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export type ActionEvent = {
|
|
246
|
+
readonly name: string,
|
|
247
|
+
readonly args: ArrayBuffer,
|
|
248
|
+
readonly connId: string,
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function readActionEvent(bc: bare.ByteCursor): ActionEvent {
|
|
252
|
+
return {
|
|
253
|
+
name: bare.readString(bc),
|
|
254
|
+
args: bare.readData(bc),
|
|
255
|
+
connId: bare.readString(bc),
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export function writeActionEvent(bc: bare.ByteCursor, x: ActionEvent): void {
|
|
260
|
+
bare.writeString(bc, x.name)
|
|
261
|
+
bare.writeData(bc, x.args)
|
|
262
|
+
bare.writeString(bc, x.connId)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export type BroadcastEvent = {
|
|
266
|
+
readonly eventName: string,
|
|
267
|
+
readonly args: ArrayBuffer,
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export function readBroadcastEvent(bc: bare.ByteCursor): BroadcastEvent {
|
|
271
|
+
return {
|
|
272
|
+
eventName: bare.readString(bc),
|
|
273
|
+
args: bare.readData(bc),
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function writeBroadcastEvent(bc: bare.ByteCursor, x: BroadcastEvent): void {
|
|
278
|
+
bare.writeString(bc, x.eventName)
|
|
279
|
+
bare.writeData(bc, x.args)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export type SubscribeEvent = {
|
|
283
|
+
readonly eventName: string,
|
|
284
|
+
readonly connId: string,
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export function readSubscribeEvent(bc: bare.ByteCursor): SubscribeEvent {
|
|
288
|
+
return {
|
|
289
|
+
eventName: bare.readString(bc),
|
|
290
|
+
connId: bare.readString(bc),
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function writeSubscribeEvent(bc: bare.ByteCursor, x: SubscribeEvent): void {
|
|
295
|
+
bare.writeString(bc, x.eventName)
|
|
296
|
+
bare.writeString(bc, x.connId)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export type UnSubscribeEvent = {
|
|
300
|
+
readonly eventName: string,
|
|
301
|
+
readonly connId: string,
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export function readUnSubscribeEvent(bc: bare.ByteCursor): UnSubscribeEvent {
|
|
305
|
+
return {
|
|
306
|
+
eventName: bare.readString(bc),
|
|
307
|
+
connId: bare.readString(bc),
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export function writeUnSubscribeEvent(bc: bare.ByteCursor, x: UnSubscribeEvent): void {
|
|
312
|
+
bare.writeString(bc, x.eventName)
|
|
313
|
+
bare.writeString(bc, x.connId)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export type FiredEvent = {
|
|
317
|
+
readonly eventName: string,
|
|
318
|
+
readonly args: ArrayBuffer,
|
|
319
|
+
readonly connId: string,
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function readFiredEvent(bc: bare.ByteCursor): FiredEvent {
|
|
323
|
+
return {
|
|
324
|
+
eventName: bare.readString(bc),
|
|
325
|
+
args: bare.readData(bc),
|
|
326
|
+
connId: bare.readString(bc),
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export function writeFiredEvent(bc: bare.ByteCursor, x: FiredEvent): void {
|
|
331
|
+
bare.writeString(bc, x.eventName)
|
|
332
|
+
bare.writeData(bc, x.args)
|
|
333
|
+
bare.writeString(bc, x.connId)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export type EventBody =
|
|
337
|
+
| { readonly tag: "ActionEvent", readonly val: ActionEvent }
|
|
338
|
+
| { readonly tag: "BroadcastEvent", readonly val: BroadcastEvent }
|
|
339
|
+
| { readonly tag: "SubscribeEvent", readonly val: SubscribeEvent }
|
|
340
|
+
| { readonly tag: "UnSubscribeEvent", readonly val: UnSubscribeEvent }
|
|
341
|
+
| { readonly tag: "FiredEvent", readonly val: FiredEvent }
|
|
342
|
+
|
|
343
|
+
export function readEventBody(bc: bare.ByteCursor): EventBody {
|
|
344
|
+
const offset = bc.offset
|
|
345
|
+
const tag = bare.readU8(bc)
|
|
346
|
+
switch (tag) {
|
|
347
|
+
case 0:
|
|
348
|
+
return { tag: "ActionEvent", val: readActionEvent(bc) }
|
|
349
|
+
case 1:
|
|
350
|
+
return { tag: "BroadcastEvent", val: readBroadcastEvent(bc) }
|
|
351
|
+
case 2:
|
|
352
|
+
return { tag: "SubscribeEvent", val: readSubscribeEvent(bc) }
|
|
353
|
+
case 3:
|
|
354
|
+
return { tag: "UnSubscribeEvent", val: readUnSubscribeEvent(bc) }
|
|
355
|
+
case 4:
|
|
356
|
+
return { tag: "FiredEvent", val: readFiredEvent(bc) }
|
|
357
|
+
default: {
|
|
358
|
+
bc.offset = offset
|
|
359
|
+
throw new bare.BareError(offset, "invalid tag")
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export function writeEventBody(bc: bare.ByteCursor, x: EventBody): void {
|
|
365
|
+
switch (x.tag) {
|
|
366
|
+
case "ActionEvent": {
|
|
367
|
+
bare.writeU8(bc, 0)
|
|
368
|
+
writeActionEvent(bc, x.val)
|
|
369
|
+
break
|
|
370
|
+
}
|
|
371
|
+
case "BroadcastEvent": {
|
|
372
|
+
bare.writeU8(bc, 1)
|
|
373
|
+
writeBroadcastEvent(bc, x.val)
|
|
374
|
+
break
|
|
375
|
+
}
|
|
376
|
+
case "SubscribeEvent": {
|
|
377
|
+
bare.writeU8(bc, 2)
|
|
378
|
+
writeSubscribeEvent(bc, x.val)
|
|
379
|
+
break
|
|
380
|
+
}
|
|
381
|
+
case "UnSubscribeEvent": {
|
|
382
|
+
bare.writeU8(bc, 3)
|
|
383
|
+
writeUnSubscribeEvent(bc, x.val)
|
|
384
|
+
break
|
|
385
|
+
}
|
|
386
|
+
case "FiredEvent": {
|
|
387
|
+
bare.writeU8(bc, 4)
|
|
388
|
+
writeFiredEvent(bc, x.val)
|
|
389
|
+
break
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export type Event = {
|
|
395
|
+
readonly id: string,
|
|
396
|
+
readonly timestamp: uint,
|
|
397
|
+
readonly body: EventBody,
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export function readEvent(bc: bare.ByteCursor): Event {
|
|
401
|
+
return {
|
|
402
|
+
id: bare.readString(bc),
|
|
403
|
+
timestamp: bare.readUint(bc),
|
|
404
|
+
body: readEventBody(bc),
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export function writeEvent(bc: bare.ByteCursor, x: Event): void {
|
|
409
|
+
bare.writeString(bc, x.id)
|
|
410
|
+
bare.writeUint(bc, x.timestamp)
|
|
411
|
+
writeEventBody(bc, x.body)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function read0(bc: bare.ByteCursor): readonly Connection[] {
|
|
415
|
+
const len = bare.readUintSafe(bc)
|
|
416
|
+
if (len === 0) { return [] }
|
|
417
|
+
const result = [readConnection(bc)]
|
|
418
|
+
for (let i = 1; i < len; i++) {
|
|
419
|
+
result[i] = readConnection(bc)
|
|
420
|
+
}
|
|
421
|
+
return result
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function write0(bc: bare.ByteCursor, x: readonly Connection[]): void {
|
|
425
|
+
bare.writeUintSafe(bc, x.length)
|
|
426
|
+
for (let i = 0; i < x.length; i++) {
|
|
427
|
+
writeConnection(bc, x[i])
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function read1(bc: bare.ByteCursor): readonly Event[] {
|
|
432
|
+
const len = bare.readUintSafe(bc)
|
|
433
|
+
if (len === 0) { return [] }
|
|
434
|
+
const result = [readEvent(bc)]
|
|
435
|
+
for (let i = 1; i < len; i++) {
|
|
436
|
+
result[i] = readEvent(bc)
|
|
437
|
+
}
|
|
438
|
+
return result
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function write1(bc: bare.ByteCursor, x: readonly Event[]): void {
|
|
442
|
+
bare.writeUintSafe(bc, x.length)
|
|
443
|
+
for (let i = 0; i < x.length; i++) {
|
|
444
|
+
writeEvent(bc, x[i])
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function read2(bc: bare.ByteCursor): State | null {
|
|
449
|
+
return bare.readBool(bc)
|
|
450
|
+
? readState(bc)
|
|
451
|
+
: null
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function write2(bc: bare.ByteCursor, x: State | null): void {
|
|
455
|
+
bare.writeBool(bc, x !== null)
|
|
456
|
+
if (x !== null) {
|
|
457
|
+
writeState(bc, x)
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function read3(bc: bare.ByteCursor): readonly string[] {
|
|
462
|
+
const len = bare.readUintSafe(bc)
|
|
463
|
+
if (len === 0) { return [] }
|
|
464
|
+
const result = [bare.readString(bc)]
|
|
465
|
+
for (let i = 1; i < len; i++) {
|
|
466
|
+
result[i] = bare.readString(bc)
|
|
467
|
+
}
|
|
468
|
+
return result
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function write3(bc: bare.ByteCursor, x: readonly string[]): void {
|
|
472
|
+
bare.writeUintSafe(bc, x.length)
|
|
473
|
+
for (let i = 0; i < x.length; i++) {
|
|
474
|
+
bare.writeString(bc, x[i])
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
export type Init = {
|
|
479
|
+
readonly connections: readonly Connection[],
|
|
480
|
+
readonly events: readonly Event[],
|
|
481
|
+
readonly state: State | null,
|
|
482
|
+
readonly isStateEnabled: boolean,
|
|
483
|
+
readonly rpcs: readonly string[],
|
|
484
|
+
readonly isDatabaseEnabled: boolean,
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export function readInit(bc: bare.ByteCursor): Init {
|
|
488
|
+
return {
|
|
489
|
+
connections: read0(bc),
|
|
490
|
+
events: read1(bc),
|
|
491
|
+
state: read2(bc),
|
|
492
|
+
isStateEnabled: bare.readBool(bc),
|
|
493
|
+
rpcs: read3(bc),
|
|
494
|
+
isDatabaseEnabled: bare.readBool(bc),
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export function writeInit(bc: bare.ByteCursor, x: Init): void {
|
|
499
|
+
write0(bc, x.connections)
|
|
500
|
+
write1(bc, x.events)
|
|
501
|
+
write2(bc, x.state)
|
|
502
|
+
bare.writeBool(bc, x.isStateEnabled)
|
|
503
|
+
write3(bc, x.rpcs)
|
|
504
|
+
bare.writeBool(bc, x.isDatabaseEnabled)
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export type ConnectionsResponse = {
|
|
508
|
+
readonly rid: uint,
|
|
509
|
+
readonly connections: readonly Connection[],
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
export function readConnectionsResponse(bc: bare.ByteCursor): ConnectionsResponse {
|
|
513
|
+
return {
|
|
514
|
+
rid: bare.readUint(bc),
|
|
515
|
+
connections: read0(bc),
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export function writeConnectionsResponse(bc: bare.ByteCursor, x: ConnectionsResponse): void {
|
|
520
|
+
bare.writeUint(bc, x.rid)
|
|
521
|
+
write0(bc, x.connections)
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export type StateResponse = {
|
|
525
|
+
readonly rid: uint,
|
|
526
|
+
readonly state: State | null,
|
|
527
|
+
readonly isStateEnabled: boolean,
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export function readStateResponse(bc: bare.ByteCursor): StateResponse {
|
|
531
|
+
return {
|
|
532
|
+
rid: bare.readUint(bc),
|
|
533
|
+
state: read2(bc),
|
|
534
|
+
isStateEnabled: bare.readBool(bc),
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export function writeStateResponse(bc: bare.ByteCursor, x: StateResponse): void {
|
|
539
|
+
bare.writeUint(bc, x.rid)
|
|
540
|
+
write2(bc, x.state)
|
|
541
|
+
bare.writeBool(bc, x.isStateEnabled)
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export type EventsResponse = {
|
|
545
|
+
readonly rid: uint,
|
|
546
|
+
readonly events: readonly Event[],
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export function readEventsResponse(bc: bare.ByteCursor): EventsResponse {
|
|
550
|
+
return {
|
|
551
|
+
rid: bare.readUint(bc),
|
|
552
|
+
events: read1(bc),
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export function writeEventsResponse(bc: bare.ByteCursor, x: EventsResponse): void {
|
|
557
|
+
bare.writeUint(bc, x.rid)
|
|
558
|
+
write1(bc, x.events)
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
export type ActionResponse = {
|
|
562
|
+
readonly rid: uint,
|
|
563
|
+
readonly output: ArrayBuffer,
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
export function readActionResponse(bc: bare.ByteCursor): ActionResponse {
|
|
567
|
+
return {
|
|
568
|
+
rid: bare.readUint(bc),
|
|
569
|
+
output: bare.readData(bc),
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
export function writeActionResponse(bc: bare.ByteCursor, x: ActionResponse): void {
|
|
574
|
+
bare.writeUint(bc, x.rid)
|
|
575
|
+
bare.writeData(bc, x.output)
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
export type StateUpdated = {
|
|
579
|
+
readonly state: State,
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
export function readStateUpdated(bc: bare.ByteCursor): StateUpdated {
|
|
583
|
+
return {
|
|
584
|
+
state: readState(bc),
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export function writeStateUpdated(bc: bare.ByteCursor, x: StateUpdated): void {
|
|
589
|
+
writeState(bc, x.state)
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
export type EventsUpdated = {
|
|
593
|
+
readonly events: readonly Event[],
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export function readEventsUpdated(bc: bare.ByteCursor): EventsUpdated {
|
|
597
|
+
return {
|
|
598
|
+
events: read1(bc),
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
export function writeEventsUpdated(bc: bare.ByteCursor, x: EventsUpdated): void {
|
|
603
|
+
write1(bc, x.events)
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export type RpcsListResponse = {
|
|
607
|
+
readonly rid: uint,
|
|
608
|
+
readonly rpcs: readonly string[],
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
export function readRpcsListResponse(bc: bare.ByteCursor): RpcsListResponse {
|
|
612
|
+
return {
|
|
613
|
+
rid: bare.readUint(bc),
|
|
614
|
+
rpcs: read3(bc),
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
export function writeRpcsListResponse(bc: bare.ByteCursor, x: RpcsListResponse): void {
|
|
619
|
+
bare.writeUint(bc, x.rid)
|
|
620
|
+
write3(bc, x.rpcs)
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
export type ConnectionsUpdated = {
|
|
624
|
+
readonly connections: readonly Connection[],
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
export function readConnectionsUpdated(bc: bare.ByteCursor): ConnectionsUpdated {
|
|
628
|
+
return {
|
|
629
|
+
connections: read0(bc),
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export function writeConnectionsUpdated(bc: bare.ByteCursor, x: ConnectionsUpdated): void {
|
|
634
|
+
write0(bc, x.connections)
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
export type Error = {
|
|
638
|
+
readonly message: string,
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
export function readError(bc: bare.ByteCursor): Error {
|
|
642
|
+
return {
|
|
643
|
+
message: bare.readString(bc),
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
export function writeError(bc: bare.ByteCursor, x: Error): void {
|
|
648
|
+
bare.writeString(bc, x.message)
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
export type ToClientBody =
|
|
652
|
+
| { readonly tag: "StateResponse", readonly val: StateResponse }
|
|
653
|
+
| { readonly tag: "ConnectionsResponse", readonly val: ConnectionsResponse }
|
|
654
|
+
| { readonly tag: "EventsResponse", readonly val: EventsResponse }
|
|
655
|
+
| { readonly tag: "ActionResponse", readonly val: ActionResponse }
|
|
656
|
+
| { readonly tag: "ConnectionsUpdated", readonly val: ConnectionsUpdated }
|
|
657
|
+
| { readonly tag: "EventsUpdated", readonly val: EventsUpdated }
|
|
658
|
+
| { readonly tag: "StateUpdated", readonly val: StateUpdated }
|
|
659
|
+
| { readonly tag: "RpcsListResponse", readonly val: RpcsListResponse }
|
|
660
|
+
| { readonly tag: "Error", readonly val: Error }
|
|
661
|
+
| { readonly tag: "Init", readonly val: Init }
|
|
662
|
+
|
|
663
|
+
export function readToClientBody(bc: bare.ByteCursor): ToClientBody {
|
|
664
|
+
const offset = bc.offset
|
|
665
|
+
const tag = bare.readU8(bc)
|
|
666
|
+
switch (tag) {
|
|
667
|
+
case 0:
|
|
668
|
+
return { tag: "StateResponse", val: readStateResponse(bc) }
|
|
669
|
+
case 1:
|
|
670
|
+
return { tag: "ConnectionsResponse", val: readConnectionsResponse(bc) }
|
|
671
|
+
case 2:
|
|
672
|
+
return { tag: "EventsResponse", val: readEventsResponse(bc) }
|
|
673
|
+
case 3:
|
|
674
|
+
return { tag: "ActionResponse", val: readActionResponse(bc) }
|
|
675
|
+
case 4:
|
|
676
|
+
return { tag: "ConnectionsUpdated", val: readConnectionsUpdated(bc) }
|
|
677
|
+
case 5:
|
|
678
|
+
return { tag: "EventsUpdated", val: readEventsUpdated(bc) }
|
|
679
|
+
case 6:
|
|
680
|
+
return { tag: "StateUpdated", val: readStateUpdated(bc) }
|
|
681
|
+
case 7:
|
|
682
|
+
return { tag: "RpcsListResponse", val: readRpcsListResponse(bc) }
|
|
683
|
+
case 8:
|
|
684
|
+
return { tag: "Error", val: readError(bc) }
|
|
685
|
+
case 9:
|
|
686
|
+
return { tag: "Init", val: readInit(bc) }
|
|
687
|
+
default: {
|
|
688
|
+
bc.offset = offset
|
|
689
|
+
throw new bare.BareError(offset, "invalid tag")
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
export function writeToClientBody(bc: bare.ByteCursor, x: ToClientBody): void {
|
|
695
|
+
switch (x.tag) {
|
|
696
|
+
case "StateResponse": {
|
|
697
|
+
bare.writeU8(bc, 0)
|
|
698
|
+
writeStateResponse(bc, x.val)
|
|
699
|
+
break
|
|
700
|
+
}
|
|
701
|
+
case "ConnectionsResponse": {
|
|
702
|
+
bare.writeU8(bc, 1)
|
|
703
|
+
writeConnectionsResponse(bc, x.val)
|
|
704
|
+
break
|
|
705
|
+
}
|
|
706
|
+
case "EventsResponse": {
|
|
707
|
+
bare.writeU8(bc, 2)
|
|
708
|
+
writeEventsResponse(bc, x.val)
|
|
709
|
+
break
|
|
710
|
+
}
|
|
711
|
+
case "ActionResponse": {
|
|
712
|
+
bare.writeU8(bc, 3)
|
|
713
|
+
writeActionResponse(bc, x.val)
|
|
714
|
+
break
|
|
715
|
+
}
|
|
716
|
+
case "ConnectionsUpdated": {
|
|
717
|
+
bare.writeU8(bc, 4)
|
|
718
|
+
writeConnectionsUpdated(bc, x.val)
|
|
719
|
+
break
|
|
720
|
+
}
|
|
721
|
+
case "EventsUpdated": {
|
|
722
|
+
bare.writeU8(bc, 5)
|
|
723
|
+
writeEventsUpdated(bc, x.val)
|
|
724
|
+
break
|
|
725
|
+
}
|
|
726
|
+
case "StateUpdated": {
|
|
727
|
+
bare.writeU8(bc, 6)
|
|
728
|
+
writeStateUpdated(bc, x.val)
|
|
729
|
+
break
|
|
730
|
+
}
|
|
731
|
+
case "RpcsListResponse": {
|
|
732
|
+
bare.writeU8(bc, 7)
|
|
733
|
+
writeRpcsListResponse(bc, x.val)
|
|
734
|
+
break
|
|
735
|
+
}
|
|
736
|
+
case "Error": {
|
|
737
|
+
bare.writeU8(bc, 8)
|
|
738
|
+
writeError(bc, x.val)
|
|
739
|
+
break
|
|
740
|
+
}
|
|
741
|
+
case "Init": {
|
|
742
|
+
bare.writeU8(bc, 9)
|
|
743
|
+
writeInit(bc, x.val)
|
|
744
|
+
break
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
export type ToClient = {
|
|
750
|
+
readonly body: ToClientBody,
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
export function readToClient(bc: bare.ByteCursor): ToClient {
|
|
754
|
+
return {
|
|
755
|
+
body: readToClientBody(bc),
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
export function writeToClient(bc: bare.ByteCursor, x: ToClient): void {
|
|
760
|
+
writeToClientBody(bc, x.body)
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
export function encodeToClient(x: ToClient): Uint8Array {
|
|
764
|
+
const bc = new bare.ByteCursor(
|
|
765
|
+
new Uint8Array(config.initialBufferLength),
|
|
766
|
+
config
|
|
767
|
+
)
|
|
768
|
+
writeToClient(bc, x)
|
|
769
|
+
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
export function decodeToClient(bytes: Uint8Array): ToClient {
|
|
773
|
+
const bc = new bare.ByteCursor(bytes, config)
|
|
774
|
+
const result = readToClient(bc)
|
|
775
|
+
if (bc.offset < bc.view.byteLength) {
|
|
776
|
+
throw new bare.BareError(bc.offset, "remaining bytes")
|
|
777
|
+
}
|
|
778
|
+
return result
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
function assert(condition: boolean, message?: string): asserts condition {
|
|
783
|
+
if (!condition) throw new Error(message ?? "Assertion failed")
|
|
784
|
+
}
|