rivetkit 2.3.3 → 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-34P567PO.cjs → chunk-4XKED5P5.cjs} +145 -176
- package/dist/tsup/chunk-4XKED5P5.cjs.map +1 -0
- package/dist/tsup/{chunk-PYO2U53V.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-BLDO2FKO.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-CXRPENO3.js → chunk-GAV4PKFT.js} +15 -46
- package/dist/tsup/{chunk-CXRPENO3.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-YUEC5SEY.cjs → chunk-M3FCXL3Q.cjs} +3 -3
- package/dist/tsup/{chunk-YUEC5SEY.cjs.map → chunk-M3FCXL3Q.cjs.map} +1 -1
- package/dist/tsup/{chunk-KEKWJECX.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-DFA7SYSW.js → chunk-NIC3QLKL.js} +3 -3
- package/dist/tsup/{chunk-BZM4PMFS.js → chunk-P4OGQ4JL.js} +5 -7
- package/dist/tsup/{chunk-BZM4PMFS.js.map → chunk-P4OGQ4JL.js.map} +1 -1
- package/dist/tsup/{chunk-NT2NK3VT.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-TYLP3U4Y.cjs → chunk-TNIWIUNV.cjs} +9 -11
- package/dist/tsup/chunk-TNIWIUNV.cjs.map +1 -0
- package/dist/tsup/{chunk-S644FL73.cjs → chunk-TR5NLR5V.cjs} +4 -4
- package/dist/tsup/{chunk-S644FL73.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-X63ROSOG.cjs → chunk-UJ2FQY63.cjs} +7 -7
- package/dist/tsup/{chunk-X63ROSOG.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-34P567PO.cjs.map +0 -1
- package/dist/tsup/chunk-3MHDOUD7.cjs.map +0 -1
- package/dist/tsup/chunk-APW73HCH.cjs +0 -382
- package/dist/tsup/chunk-APW73HCH.cjs.map +0 -1
- package/dist/tsup/chunk-BLDO2FKO.js.map +0 -1
- package/dist/tsup/chunk-DHXWD4DF.js +0 -382
- package/dist/tsup/chunk-DHXWD4DF.js.map +0 -1
- package/dist/tsup/chunk-JZ7TWV65.js.map +0 -1
- package/dist/tsup/chunk-PYO2U53V.cjs.map +0 -1
- package/dist/tsup/chunk-TYLP3U4Y.cjs.map +0 -1
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +0 -1
- package/dist/tsup/chunk-XIX5DOZN.js.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-KEKWJECX.js.map → chunk-MGTSVSUC.js.map} +0 -0
- /package/dist/tsup/{chunk-DFA7SYSW.js.map → chunk-NIC3QLKL.js.map} +0 -0
- /package/dist/tsup/{chunk-NT2NK3VT.js.map → chunk-PAG6G46L.js.map} +0 -0
|
@@ -0,0 +1,848 @@
|
|
|
1
|
+
// @generated - post-processed by build.rs
|
|
2
|
+
import * as bare from "@rivetkit/bare-ts"
|
|
3
|
+
|
|
4
|
+
const DEFAULT_CONFIG = /* @__PURE__ */ bare.Config({})
|
|
5
|
+
|
|
6
|
+
export type f64 = number
|
|
7
|
+
export type i32 = number
|
|
8
|
+
export type i64 = bigint
|
|
9
|
+
export type u32 = number
|
|
10
|
+
export type u64 = bigint
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The schema version rides in the vbare embedded-version prefix of every
|
|
14
|
+
* frame, so ClientHello carries no version or authentication fields.
|
|
15
|
+
*/
|
|
16
|
+
export type ClientHello = null
|
|
17
|
+
|
|
18
|
+
export type HelloOk = {
|
|
19
|
+
/**
|
|
20
|
+
* Largest frame payload the server accepts and will send.
|
|
21
|
+
*/
|
|
22
|
+
readonly maxFrameBytes: u32
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function readHelloOk(bc: bare.ByteCursor): HelloOk {
|
|
26
|
+
return {
|
|
27
|
+
maxFrameBytes: bare.readU32(bc),
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function writeHelloOk(bc: bare.ByteCursor, x: HelloOk): void {
|
|
32
|
+
bare.writeU32(bc, x.maxFrameBytes)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type HelloRejectUnsupportedVersion = null
|
|
36
|
+
|
|
37
|
+
export type ServerHello =
|
|
38
|
+
| { readonly tag: "HelloOk"; readonly val: HelloOk }
|
|
39
|
+
| { readonly tag: "HelloRejectUnsupportedVersion"; readonly val: HelloRejectUnsupportedVersion }
|
|
40
|
+
|
|
41
|
+
export function readServerHello(bc: bare.ByteCursor): ServerHello {
|
|
42
|
+
const offset = bc.offset
|
|
43
|
+
const tag = bare.readU8(bc)
|
|
44
|
+
switch (tag) {
|
|
45
|
+
case 0:
|
|
46
|
+
return { tag: "HelloOk", val: readHelloOk(bc) }
|
|
47
|
+
case 1:
|
|
48
|
+
return { tag: "HelloRejectUnsupportedVersion", val: null }
|
|
49
|
+
default: {
|
|
50
|
+
bc.offset = offset
|
|
51
|
+
throw new bare.BareError(offset, "invalid tag")
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function writeServerHello(bc: bare.ByteCursor, x: ServerHello): void {
|
|
57
|
+
switch (x.tag) {
|
|
58
|
+
case "HelloOk": {
|
|
59
|
+
bare.writeU8(bc, 0)
|
|
60
|
+
writeHelloOk(bc, x.val)
|
|
61
|
+
break
|
|
62
|
+
}
|
|
63
|
+
case "HelloRejectUnsupportedVersion": {
|
|
64
|
+
bare.writeU8(bc, 1)
|
|
65
|
+
break
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function encodeServerHello(x: ServerHello, config?: Partial<bare.Config>): Uint8Array {
|
|
71
|
+
const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG
|
|
72
|
+
const bc = new bare.ByteCursor(
|
|
73
|
+
new Uint8Array(fullConfig.initialBufferLength),
|
|
74
|
+
fullConfig,
|
|
75
|
+
)
|
|
76
|
+
writeServerHello(bc, x)
|
|
77
|
+
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function decodeServerHello(bytes: Uint8Array): ServerHello {
|
|
81
|
+
const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG)
|
|
82
|
+
const result = readServerHello(bc)
|
|
83
|
+
if (bc.offset < bc.view.byteLength) {
|
|
84
|
+
throw new bare.BareError(bc.offset, "remaining bytes")
|
|
85
|
+
}
|
|
86
|
+
return result
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type SqlNull = null
|
|
90
|
+
|
|
91
|
+
export type SqlInteger = i64
|
|
92
|
+
|
|
93
|
+
export function readSqlInteger(bc: bare.ByteCursor): SqlInteger {
|
|
94
|
+
return bare.readI64(bc)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function writeSqlInteger(bc: bare.ByteCursor, x: SqlInteger): void {
|
|
98
|
+
bare.writeI64(bc, x)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export type SqlReal = f64
|
|
102
|
+
|
|
103
|
+
export function readSqlReal(bc: bare.ByteCursor): SqlReal {
|
|
104
|
+
return bare.readF64(bc)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function writeSqlReal(bc: bare.ByteCursor, x: SqlReal): void {
|
|
108
|
+
bare.writeF64(bc, x)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type SqlText = string
|
|
112
|
+
|
|
113
|
+
export function readSqlText(bc: bare.ByteCursor): SqlText {
|
|
114
|
+
return bare.readString(bc)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function writeSqlText(bc: bare.ByteCursor, x: SqlText): void {
|
|
118
|
+
bare.writeString(bc, x)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type SqlBlob = ArrayBuffer
|
|
122
|
+
|
|
123
|
+
export function readSqlBlob(bc: bare.ByteCursor): SqlBlob {
|
|
124
|
+
return bare.readData(bc)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function writeSqlBlob(bc: bare.ByteCursor, x: SqlBlob): void {
|
|
128
|
+
bare.writeData(bc, x)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export type SqlValue =
|
|
132
|
+
| { readonly tag: "SqlNull"; readonly val: SqlNull }
|
|
133
|
+
| { readonly tag: "SqlInteger"; readonly val: SqlInteger }
|
|
134
|
+
| { readonly tag: "SqlReal"; readonly val: SqlReal }
|
|
135
|
+
| { readonly tag: "SqlText"; readonly val: SqlText }
|
|
136
|
+
| { readonly tag: "SqlBlob"; readonly val: SqlBlob }
|
|
137
|
+
|
|
138
|
+
export function readSqlValue(bc: bare.ByteCursor): SqlValue {
|
|
139
|
+
const offset = bc.offset
|
|
140
|
+
const tag = bare.readU8(bc)
|
|
141
|
+
switch (tag) {
|
|
142
|
+
case 0:
|
|
143
|
+
return { tag: "SqlNull", val: null }
|
|
144
|
+
case 1:
|
|
145
|
+
return { tag: "SqlInteger", val: readSqlInteger(bc) }
|
|
146
|
+
case 2:
|
|
147
|
+
return { tag: "SqlReal", val: readSqlReal(bc) }
|
|
148
|
+
case 3:
|
|
149
|
+
return { tag: "SqlText", val: readSqlText(bc) }
|
|
150
|
+
case 4:
|
|
151
|
+
return { tag: "SqlBlob", val: readSqlBlob(bc) }
|
|
152
|
+
default: {
|
|
153
|
+
bc.offset = offset
|
|
154
|
+
throw new bare.BareError(offset, "invalid tag")
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function writeSqlValue(bc: bare.ByteCursor, x: SqlValue): void {
|
|
160
|
+
switch (x.tag) {
|
|
161
|
+
case "SqlNull": {
|
|
162
|
+
bare.writeU8(bc, 0)
|
|
163
|
+
break
|
|
164
|
+
}
|
|
165
|
+
case "SqlInteger": {
|
|
166
|
+
bare.writeU8(bc, 1)
|
|
167
|
+
writeSqlInteger(bc, x.val)
|
|
168
|
+
break
|
|
169
|
+
}
|
|
170
|
+
case "SqlReal": {
|
|
171
|
+
bare.writeU8(bc, 2)
|
|
172
|
+
writeSqlReal(bc, x.val)
|
|
173
|
+
break
|
|
174
|
+
}
|
|
175
|
+
case "SqlText": {
|
|
176
|
+
bare.writeU8(bc, 3)
|
|
177
|
+
writeSqlText(bc, x.val)
|
|
178
|
+
break
|
|
179
|
+
}
|
|
180
|
+
case "SqlBlob": {
|
|
181
|
+
bare.writeU8(bc, 4)
|
|
182
|
+
writeSqlBlob(bc, x.val)
|
|
183
|
+
break
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export type SqlRow = readonly SqlValue[]
|
|
189
|
+
|
|
190
|
+
export function readSqlRow(bc: bare.ByteCursor): SqlRow {
|
|
191
|
+
const len = bare.readUintSafe(bc)
|
|
192
|
+
if (len === 0) {
|
|
193
|
+
return []
|
|
194
|
+
}
|
|
195
|
+
const result = [readSqlValue(bc)]
|
|
196
|
+
for (let i = 1; i < len; i++) {
|
|
197
|
+
result[i] = readSqlValue(bc)
|
|
198
|
+
}
|
|
199
|
+
return result
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function writeSqlRow(bc: bare.ByteCursor, x: SqlRow): void {
|
|
203
|
+
bare.writeUintSafe(bc, x.length)
|
|
204
|
+
for (let i = 0; i < x.length; i++) {
|
|
205
|
+
writeSqlValue(bc, x[i])
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Multi-statement script, one job, no params, no result rows.
|
|
211
|
+
*/
|
|
212
|
+
export type SqliteExec = {
|
|
213
|
+
readonly script: string
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function readSqliteExec(bc: bare.ByteCursor): SqliteExec {
|
|
217
|
+
return {
|
|
218
|
+
script: bare.readString(bc),
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function writeSqliteExec(bc: bare.ByteCursor, x: SqliteExec): void {
|
|
223
|
+
bare.writeString(bc, x.script)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function read0(bc: bare.ByteCursor): readonly SqlValue[] {
|
|
227
|
+
const len = bare.readUintSafe(bc)
|
|
228
|
+
if (len === 0) {
|
|
229
|
+
return []
|
|
230
|
+
}
|
|
231
|
+
const result = [readSqlValue(bc)]
|
|
232
|
+
for (let i = 1; i < len; i++) {
|
|
233
|
+
result[i] = readSqlValue(bc)
|
|
234
|
+
}
|
|
235
|
+
return result
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function write0(bc: bare.ByteCursor, x: readonly SqlValue[]): void {
|
|
239
|
+
bare.writeUintSafe(bc, x.length)
|
|
240
|
+
for (let i = 0; i < x.length; i++) {
|
|
241
|
+
writeSqlValue(bc, x[i])
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Single statement, positional params, returns rows and change counts.
|
|
247
|
+
*/
|
|
248
|
+
export type SqliteQuery = {
|
|
249
|
+
readonly sql: string
|
|
250
|
+
readonly params: readonly SqlValue[]
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function readSqliteQuery(bc: bare.ByteCursor): SqliteQuery {
|
|
254
|
+
return {
|
|
255
|
+
sql: bare.readString(bc),
|
|
256
|
+
params: read0(bc),
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function writeSqliteQuery(bc: bare.ByteCursor, x: SqliteQuery): void {
|
|
261
|
+
bare.writeString(bc, x.sql)
|
|
262
|
+
write0(bc, x.params)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function read1(bc: bare.ByteCursor): u64 | null {
|
|
266
|
+
return bare.readBool(bc) ? bare.readU64(bc) : null
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function write1(bc: bare.ByteCursor, x: u64 | null): void {
|
|
270
|
+
bare.writeBool(bc, x != null)
|
|
271
|
+
if (x != null) {
|
|
272
|
+
bare.writeU64(bc, x)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Starts an explicit transaction owned by leaseKey. The optional timeout is
|
|
278
|
+
* milliseconds and defaults to the runtime's 60-second safety deadline.
|
|
279
|
+
*/
|
|
280
|
+
export type SqliteBegin = {
|
|
281
|
+
readonly leaseKey: string
|
|
282
|
+
readonly timeoutMs: u64 | null
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function readSqliteBegin(bc: bare.ByteCursor): SqliteBegin {
|
|
286
|
+
return {
|
|
287
|
+
leaseKey: bare.readString(bc),
|
|
288
|
+
timeoutMs: read1(bc),
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function writeSqliteBegin(bc: bare.ByteCursor, x: SqliteBegin): void {
|
|
293
|
+
bare.writeString(bc, x.leaseKey)
|
|
294
|
+
write1(bc, x.timeoutMs)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export type SqliteCommit = {
|
|
298
|
+
readonly leaseKey: string
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export function readSqliteCommit(bc: bare.ByteCursor): SqliteCommit {
|
|
302
|
+
return {
|
|
303
|
+
leaseKey: bare.readString(bc),
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function writeSqliteCommit(bc: bare.ByteCursor, x: SqliteCommit): void {
|
|
308
|
+
bare.writeString(bc, x.leaseKey)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export type SqliteRollback = {
|
|
312
|
+
readonly leaseKey: string
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export function readSqliteRollback(bc: bare.ByteCursor): SqliteRollback {
|
|
316
|
+
return {
|
|
317
|
+
leaseKey: bare.readString(bc),
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export function writeSqliteRollback(bc: bare.ByteCursor, x: SqliteRollback): void {
|
|
322
|
+
bare.writeString(bc, x.leaseKey)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export type RequestPayload =
|
|
326
|
+
| { readonly tag: "SqliteExec"; readonly val: SqliteExec }
|
|
327
|
+
| { readonly tag: "SqliteQuery"; readonly val: SqliteQuery }
|
|
328
|
+
| { readonly tag: "SqliteBegin"; readonly val: SqliteBegin }
|
|
329
|
+
| { readonly tag: "SqliteCommit"; readonly val: SqliteCommit }
|
|
330
|
+
| { readonly tag: "SqliteRollback"; readonly val: SqliteRollback }
|
|
331
|
+
|
|
332
|
+
export function readRequestPayload(bc: bare.ByteCursor): RequestPayload {
|
|
333
|
+
const offset = bc.offset
|
|
334
|
+
const tag = bare.readU8(bc)
|
|
335
|
+
switch (tag) {
|
|
336
|
+
case 0:
|
|
337
|
+
return { tag: "SqliteExec", val: readSqliteExec(bc) }
|
|
338
|
+
case 1:
|
|
339
|
+
return { tag: "SqliteQuery", val: readSqliteQuery(bc) }
|
|
340
|
+
case 2:
|
|
341
|
+
return { tag: "SqliteBegin", val: readSqliteBegin(bc) }
|
|
342
|
+
case 3:
|
|
343
|
+
return { tag: "SqliteCommit", val: readSqliteCommit(bc) }
|
|
344
|
+
case 4:
|
|
345
|
+
return { tag: "SqliteRollback", val: readSqliteRollback(bc) }
|
|
346
|
+
default: {
|
|
347
|
+
bc.offset = offset
|
|
348
|
+
throw new bare.BareError(offset, "invalid tag")
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export function writeRequestPayload(bc: bare.ByteCursor, x: RequestPayload): void {
|
|
354
|
+
switch (x.tag) {
|
|
355
|
+
case "SqliteExec": {
|
|
356
|
+
bare.writeU8(bc, 0)
|
|
357
|
+
writeSqliteExec(bc, x.val)
|
|
358
|
+
break
|
|
359
|
+
}
|
|
360
|
+
case "SqliteQuery": {
|
|
361
|
+
bare.writeU8(bc, 1)
|
|
362
|
+
writeSqliteQuery(bc, x.val)
|
|
363
|
+
break
|
|
364
|
+
}
|
|
365
|
+
case "SqliteBegin": {
|
|
366
|
+
bare.writeU8(bc, 2)
|
|
367
|
+
writeSqliteBegin(bc, x.val)
|
|
368
|
+
break
|
|
369
|
+
}
|
|
370
|
+
case "SqliteCommit": {
|
|
371
|
+
bare.writeU8(bc, 3)
|
|
372
|
+
writeSqliteCommit(bc, x.val)
|
|
373
|
+
break
|
|
374
|
+
}
|
|
375
|
+
case "SqliteRollback": {
|
|
376
|
+
bare.writeU8(bc, 4)
|
|
377
|
+
writeSqliteRollback(bc, x.val)
|
|
378
|
+
break
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function read2(bc: bare.ByteCursor): string | null {
|
|
384
|
+
return bare.readBool(bc) ? bare.readString(bc) : null
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function write2(bc: bare.ByteCursor, x: string | null): void {
|
|
388
|
+
bare.writeBool(bc, x != null)
|
|
389
|
+
if (x != null) {
|
|
390
|
+
bare.writeString(bc, x)
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export type Request = {
|
|
395
|
+
readonly requestId: u32
|
|
396
|
+
/**
|
|
397
|
+
* For Exec and Query, selects a transaction started on this connection.
|
|
398
|
+
*/
|
|
399
|
+
readonly leaseKey: string | null
|
|
400
|
+
readonly payload: RequestPayload
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export function readRequest(bc: bare.ByteCursor): Request {
|
|
404
|
+
return {
|
|
405
|
+
requestId: bare.readU32(bc),
|
|
406
|
+
leaseKey: read2(bc),
|
|
407
|
+
payload: readRequestPayload(bc),
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export function writeRequest(bc: bare.ByteCursor, x: Request): void {
|
|
412
|
+
bare.writeU32(bc, x.requestId)
|
|
413
|
+
write2(bc, x.leaseKey)
|
|
414
|
+
writeRequestPayload(bc, x.payload)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export type ClientFrame =
|
|
418
|
+
| { readonly tag: "Request"; readonly val: Request }
|
|
419
|
+
|
|
420
|
+
export function readClientFrame(bc: bare.ByteCursor): ClientFrame {
|
|
421
|
+
const offset = bc.offset
|
|
422
|
+
const tag = bare.readU8(bc)
|
|
423
|
+
switch (tag) {
|
|
424
|
+
case 0:
|
|
425
|
+
return { tag: "Request", val: readRequest(bc) }
|
|
426
|
+
default: {
|
|
427
|
+
bc.offset = offset
|
|
428
|
+
throw new bare.BareError(offset, "invalid tag")
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export function writeClientFrame(bc: bare.ByteCursor, x: ClientFrame): void {
|
|
434
|
+
switch (x.tag) {
|
|
435
|
+
case "Request": {
|
|
436
|
+
bare.writeU8(bc, 0)
|
|
437
|
+
writeRequest(bc, x.val)
|
|
438
|
+
break
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export function encodeClientFrame(x: ClientFrame, config?: Partial<bare.Config>): Uint8Array {
|
|
444
|
+
const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG
|
|
445
|
+
const bc = new bare.ByteCursor(
|
|
446
|
+
new Uint8Array(fullConfig.initialBufferLength),
|
|
447
|
+
fullConfig,
|
|
448
|
+
)
|
|
449
|
+
writeClientFrame(bc, x)
|
|
450
|
+
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export function decodeClientFrame(bytes: Uint8Array): ClientFrame {
|
|
454
|
+
const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG)
|
|
455
|
+
const result = readClientFrame(bc)
|
|
456
|
+
if (bc.offset < bc.view.byteLength) {
|
|
457
|
+
throw new bare.BareError(bc.offset, "remaining bytes")
|
|
458
|
+
}
|
|
459
|
+
return result
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export type SqliteExecOk = null
|
|
463
|
+
|
|
464
|
+
export type SqliteBeginOk = null
|
|
465
|
+
|
|
466
|
+
export type SqliteCommitOk = null
|
|
467
|
+
|
|
468
|
+
export type SqliteRollbackOk = null
|
|
469
|
+
|
|
470
|
+
function read3(bc: bare.ByteCursor): readonly string[] {
|
|
471
|
+
const len = bare.readUintSafe(bc)
|
|
472
|
+
if (len === 0) {
|
|
473
|
+
return []
|
|
474
|
+
}
|
|
475
|
+
const result = [bare.readString(bc)]
|
|
476
|
+
for (let i = 1; i < len; i++) {
|
|
477
|
+
result[i] = bare.readString(bc)
|
|
478
|
+
}
|
|
479
|
+
return result
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function write3(bc: bare.ByteCursor, x: readonly string[]): void {
|
|
483
|
+
bare.writeUintSafe(bc, x.length)
|
|
484
|
+
for (let i = 0; i < x.length; i++) {
|
|
485
|
+
bare.writeString(bc, x[i])
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function read4(bc: bare.ByteCursor): readonly SqlRow[] {
|
|
490
|
+
const len = bare.readUintSafe(bc)
|
|
491
|
+
if (len === 0) {
|
|
492
|
+
return []
|
|
493
|
+
}
|
|
494
|
+
const result = [readSqlRow(bc)]
|
|
495
|
+
for (let i = 1; i < len; i++) {
|
|
496
|
+
result[i] = readSqlRow(bc)
|
|
497
|
+
}
|
|
498
|
+
return result
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function write4(bc: bare.ByteCursor, x: readonly SqlRow[]): void {
|
|
502
|
+
bare.writeUintSafe(bc, x.length)
|
|
503
|
+
for (let i = 0; i < x.length; i++) {
|
|
504
|
+
writeSqlRow(bc, x[i])
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function read5(bc: bare.ByteCursor): i64 | null {
|
|
509
|
+
return bare.readBool(bc) ? bare.readI64(bc) : null
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function write5(bc: bare.ByteCursor, x: i64 | null): void {
|
|
513
|
+
bare.writeBool(bc, x != null)
|
|
514
|
+
if (x != null) {
|
|
515
|
+
bare.writeI64(bc, x)
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export type SqliteQueryOk = {
|
|
520
|
+
readonly columns: readonly string[]
|
|
521
|
+
readonly rows: readonly SqlRow[]
|
|
522
|
+
readonly changes: i64
|
|
523
|
+
readonly lastInsertRowId: i64 | null
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export function readSqliteQueryOk(bc: bare.ByteCursor): SqliteQueryOk {
|
|
527
|
+
return {
|
|
528
|
+
columns: read3(bc),
|
|
529
|
+
rows: read4(bc),
|
|
530
|
+
changes: bare.readI64(bc),
|
|
531
|
+
lastInsertRowId: read5(bc),
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
export function writeSqliteQueryOk(bc: bare.ByteCursor, x: SqliteQueryOk): void {
|
|
536
|
+
write3(bc, x.columns)
|
|
537
|
+
write4(bc, x.rows)
|
|
538
|
+
bare.writeI64(bc, x.changes)
|
|
539
|
+
write5(bc, x.lastInsertRowId)
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export type SqlError = {
|
|
543
|
+
readonly code: i32
|
|
544
|
+
readonly statementIndex: u32
|
|
545
|
+
readonly message: string
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
export function readSqlError(bc: bare.ByteCursor): SqlError {
|
|
549
|
+
return {
|
|
550
|
+
code: bare.readI32(bc),
|
|
551
|
+
statementIndex: bare.readU32(bc),
|
|
552
|
+
message: bare.readString(bc),
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
export function writeSqlError(bc: bare.ByteCursor, x: SqlError): void {
|
|
557
|
+
bare.writeI32(bc, x.code)
|
|
558
|
+
bare.writeU32(bc, x.statementIndex)
|
|
559
|
+
bare.writeString(bc, x.message)
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
export type EndpointClosed = null
|
|
563
|
+
|
|
564
|
+
export type QueueFull = {
|
|
565
|
+
readonly limit: string
|
|
566
|
+
readonly capacity: u32
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
export function readQueueFull(bc: bare.ByteCursor): QueueFull {
|
|
570
|
+
return {
|
|
571
|
+
limit: bare.readString(bc),
|
|
572
|
+
capacity: bare.readU32(bc),
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export function writeQueueFull(bc: bare.ByteCursor, x: QueueFull): void {
|
|
577
|
+
bare.writeString(bc, x.limit)
|
|
578
|
+
bare.writeU32(bc, x.capacity)
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* The key was missing, unknown, owned by another connection, or already
|
|
583
|
+
* committed/rolled back. The request was not executed.
|
|
584
|
+
*/
|
|
585
|
+
export type InvalidLeaseKey = {
|
|
586
|
+
readonly message: string
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
export function readInvalidLeaseKey(bc: bare.ByteCursor): InvalidLeaseKey {
|
|
590
|
+
return {
|
|
591
|
+
message: bare.readString(bc),
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
export function writeInvalidLeaseKey(bc: bare.ByteCursor, x: InvalidLeaseKey): void {
|
|
596
|
+
bare.writeString(bc, x.message)
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* The key's deadline fired (or its connection closed) and its transaction was
|
|
601
|
+
* rolled back. The request was not executed.
|
|
602
|
+
*/
|
|
603
|
+
export type LeaseExpired = {
|
|
604
|
+
readonly timeoutMs: u64
|
|
605
|
+
readonly message: string
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
export function readLeaseExpired(bc: bare.ByteCursor): LeaseExpired {
|
|
609
|
+
return {
|
|
610
|
+
timeoutMs: bare.readU64(bc),
|
|
611
|
+
message: bare.readString(bc),
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export function writeLeaseExpired(bc: bare.ByteCursor, x: LeaseExpired): void {
|
|
616
|
+
bare.writeU64(bc, x.timeoutMs)
|
|
617
|
+
bare.writeString(bc, x.message)
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* The statement executed, but its serialized response exceeded maxFrameBytes.
|
|
622
|
+
*/
|
|
623
|
+
export type ResponseTooLarge = null
|
|
624
|
+
|
|
625
|
+
export type ResponsePayload =
|
|
626
|
+
| { readonly tag: "SqliteExecOk"; readonly val: SqliteExecOk }
|
|
627
|
+
| { readonly tag: "SqliteQueryOk"; readonly val: SqliteQueryOk }
|
|
628
|
+
| { readonly tag: "SqliteBeginOk"; readonly val: SqliteBeginOk }
|
|
629
|
+
| { readonly tag: "SqliteCommitOk"; readonly val: SqliteCommitOk }
|
|
630
|
+
| { readonly tag: "SqliteRollbackOk"; readonly val: SqliteRollbackOk }
|
|
631
|
+
| { readonly tag: "SqlError"; readonly val: SqlError }
|
|
632
|
+
| { readonly tag: "EndpointClosed"; readonly val: EndpointClosed }
|
|
633
|
+
| { readonly tag: "QueueFull"; readonly val: QueueFull }
|
|
634
|
+
| { readonly tag: "InvalidLeaseKey"; readonly val: InvalidLeaseKey }
|
|
635
|
+
| { readonly tag: "LeaseExpired"; readonly val: LeaseExpired }
|
|
636
|
+
| { readonly tag: "ResponseTooLarge"; readonly val: ResponseTooLarge }
|
|
637
|
+
|
|
638
|
+
export function readResponsePayload(bc: bare.ByteCursor): ResponsePayload {
|
|
639
|
+
const offset = bc.offset
|
|
640
|
+
const tag = bare.readU8(bc)
|
|
641
|
+
switch (tag) {
|
|
642
|
+
case 0:
|
|
643
|
+
return { tag: "SqliteExecOk", val: null }
|
|
644
|
+
case 1:
|
|
645
|
+
return { tag: "SqliteQueryOk", val: readSqliteQueryOk(bc) }
|
|
646
|
+
case 2:
|
|
647
|
+
return { tag: "SqliteBeginOk", val: null }
|
|
648
|
+
case 3:
|
|
649
|
+
return { tag: "SqliteCommitOk", val: null }
|
|
650
|
+
case 4:
|
|
651
|
+
return { tag: "SqliteRollbackOk", val: null }
|
|
652
|
+
case 5:
|
|
653
|
+
return { tag: "SqlError", val: readSqlError(bc) }
|
|
654
|
+
case 6:
|
|
655
|
+
return { tag: "EndpointClosed", val: null }
|
|
656
|
+
case 7:
|
|
657
|
+
return { tag: "QueueFull", val: readQueueFull(bc) }
|
|
658
|
+
case 8:
|
|
659
|
+
return { tag: "InvalidLeaseKey", val: readInvalidLeaseKey(bc) }
|
|
660
|
+
case 9:
|
|
661
|
+
return { tag: "LeaseExpired", val: readLeaseExpired(bc) }
|
|
662
|
+
case 10:
|
|
663
|
+
return { tag: "ResponseTooLarge", val: null }
|
|
664
|
+
default: {
|
|
665
|
+
bc.offset = offset
|
|
666
|
+
throw new bare.BareError(offset, "invalid tag")
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
export function writeResponsePayload(bc: bare.ByteCursor, x: ResponsePayload): void {
|
|
672
|
+
switch (x.tag) {
|
|
673
|
+
case "SqliteExecOk": {
|
|
674
|
+
bare.writeU8(bc, 0)
|
|
675
|
+
break
|
|
676
|
+
}
|
|
677
|
+
case "SqliteQueryOk": {
|
|
678
|
+
bare.writeU8(bc, 1)
|
|
679
|
+
writeSqliteQueryOk(bc, x.val)
|
|
680
|
+
break
|
|
681
|
+
}
|
|
682
|
+
case "SqliteBeginOk": {
|
|
683
|
+
bare.writeU8(bc, 2)
|
|
684
|
+
break
|
|
685
|
+
}
|
|
686
|
+
case "SqliteCommitOk": {
|
|
687
|
+
bare.writeU8(bc, 3)
|
|
688
|
+
break
|
|
689
|
+
}
|
|
690
|
+
case "SqliteRollbackOk": {
|
|
691
|
+
bare.writeU8(bc, 4)
|
|
692
|
+
break
|
|
693
|
+
}
|
|
694
|
+
case "SqlError": {
|
|
695
|
+
bare.writeU8(bc, 5)
|
|
696
|
+
writeSqlError(bc, x.val)
|
|
697
|
+
break
|
|
698
|
+
}
|
|
699
|
+
case "EndpointClosed": {
|
|
700
|
+
bare.writeU8(bc, 6)
|
|
701
|
+
break
|
|
702
|
+
}
|
|
703
|
+
case "QueueFull": {
|
|
704
|
+
bare.writeU8(bc, 7)
|
|
705
|
+
writeQueueFull(bc, x.val)
|
|
706
|
+
break
|
|
707
|
+
}
|
|
708
|
+
case "InvalidLeaseKey": {
|
|
709
|
+
bare.writeU8(bc, 8)
|
|
710
|
+
writeInvalidLeaseKey(bc, x.val)
|
|
711
|
+
break
|
|
712
|
+
}
|
|
713
|
+
case "LeaseExpired": {
|
|
714
|
+
bare.writeU8(bc, 9)
|
|
715
|
+
writeLeaseExpired(bc, x.val)
|
|
716
|
+
break
|
|
717
|
+
}
|
|
718
|
+
case "ResponseTooLarge": {
|
|
719
|
+
bare.writeU8(bc, 10)
|
|
720
|
+
break
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
export type Response = {
|
|
726
|
+
readonly requestId: u32
|
|
727
|
+
readonly payload: ResponsePayload
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
export function readResponse(bc: bare.ByteCursor): Response {
|
|
731
|
+
return {
|
|
732
|
+
requestId: bare.readU32(bc),
|
|
733
|
+
payload: readResponsePayload(bc),
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
export function writeResponse(bc: bare.ByteCursor, x: Response): void {
|
|
738
|
+
bare.writeU32(bc, x.requestId)
|
|
739
|
+
writeResponsePayload(bc, x.payload)
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
export type FrameTooLarge = null
|
|
743
|
+
|
|
744
|
+
export type MalformedFrame = null
|
|
745
|
+
|
|
746
|
+
export type GoAwayReason =
|
|
747
|
+
| { readonly tag: "FrameTooLarge"; readonly val: FrameTooLarge }
|
|
748
|
+
| { readonly tag: "MalformedFrame"; readonly val: MalformedFrame }
|
|
749
|
+
|
|
750
|
+
export function readGoAwayReason(bc: bare.ByteCursor): GoAwayReason {
|
|
751
|
+
const offset = bc.offset
|
|
752
|
+
const tag = bare.readU8(bc)
|
|
753
|
+
switch (tag) {
|
|
754
|
+
case 0:
|
|
755
|
+
return { tag: "FrameTooLarge", val: null }
|
|
756
|
+
case 1:
|
|
757
|
+
return { tag: "MalformedFrame", val: null }
|
|
758
|
+
default: {
|
|
759
|
+
bc.offset = offset
|
|
760
|
+
throw new bare.BareError(offset, "invalid tag")
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
export function writeGoAwayReason(bc: bare.ByteCursor, x: GoAwayReason): void {
|
|
766
|
+
switch (x.tag) {
|
|
767
|
+
case "FrameTooLarge": {
|
|
768
|
+
bare.writeU8(bc, 0)
|
|
769
|
+
break
|
|
770
|
+
}
|
|
771
|
+
case "MalformedFrame": {
|
|
772
|
+
bare.writeU8(bc, 1)
|
|
773
|
+
break
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
export type GoAway = {
|
|
779
|
+
readonly reason: GoAwayReason
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
export function readGoAway(bc: bare.ByteCursor): GoAway {
|
|
783
|
+
return {
|
|
784
|
+
reason: readGoAwayReason(bc),
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
export function writeGoAway(bc: bare.ByteCursor, x: GoAway): void {
|
|
789
|
+
writeGoAwayReason(bc, x.reason)
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
export type ServerFrame =
|
|
793
|
+
| { readonly tag: "Response"; readonly val: Response }
|
|
794
|
+
| { readonly tag: "GoAway"; readonly val: GoAway }
|
|
795
|
+
|
|
796
|
+
export function readServerFrame(bc: bare.ByteCursor): ServerFrame {
|
|
797
|
+
const offset = bc.offset
|
|
798
|
+
const tag = bare.readU8(bc)
|
|
799
|
+
switch (tag) {
|
|
800
|
+
case 0:
|
|
801
|
+
return { tag: "Response", val: readResponse(bc) }
|
|
802
|
+
case 1:
|
|
803
|
+
return { tag: "GoAway", val: readGoAway(bc) }
|
|
804
|
+
default: {
|
|
805
|
+
bc.offset = offset
|
|
806
|
+
throw new bare.BareError(offset, "invalid tag")
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
export function writeServerFrame(bc: bare.ByteCursor, x: ServerFrame): void {
|
|
812
|
+
switch (x.tag) {
|
|
813
|
+
case "Response": {
|
|
814
|
+
bare.writeU8(bc, 0)
|
|
815
|
+
writeResponse(bc, x.val)
|
|
816
|
+
break
|
|
817
|
+
}
|
|
818
|
+
case "GoAway": {
|
|
819
|
+
bare.writeU8(bc, 1)
|
|
820
|
+
writeGoAway(bc, x.val)
|
|
821
|
+
break
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
export function encodeServerFrame(x: ServerFrame, config?: Partial<bare.Config>): Uint8Array {
|
|
827
|
+
const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG
|
|
828
|
+
const bc = new bare.ByteCursor(
|
|
829
|
+
new Uint8Array(fullConfig.initialBufferLength),
|
|
830
|
+
fullConfig,
|
|
831
|
+
)
|
|
832
|
+
writeServerFrame(bc, x)
|
|
833
|
+
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
export function decodeServerFrame(bytes: Uint8Array): ServerFrame {
|
|
837
|
+
const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG)
|
|
838
|
+
const result = readServerFrame(bc)
|
|
839
|
+
if (bc.offset < bc.view.byteLength) {
|
|
840
|
+
throw new bare.BareError(bc.offset, "remaining bytes")
|
|
841
|
+
}
|
|
842
|
+
return result
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
function assert(condition: boolean, message?: string): asserts condition {
|
|
847
|
+
if (!condition) throw new Error(message ?? "Assertion failed")
|
|
848
|
+
}
|