rivetkit 0.0.0-sqlite-uds.37f9e48 → 0.0.0-sqlite-profiling-compat.87d61c0
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 +28 -23
- package/dist/browser/client.js +6 -9
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.d.ts +2 -22
- package/dist/browser/inspector/client.js +222 -996
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/actor/errors.cjs.map +1 -1
- package/dist/tsup/agent-os/index.cjs +34 -104
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +28 -23
- package/dist/tsup/agent-os/index.d.ts +28 -23
- package/dist/tsup/agent-os/index.js +36 -106
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-2EYF7KY7.js → chunk-3GVMLSND.js} +4 -4
- package/dist/tsup/{chunk-HTREBONF.cjs → chunk-3MHDOUD7.cjs} +1 -6
- package/dist/tsup/chunk-3MHDOUD7.cjs.map +1 -0
- package/dist/tsup/chunk-4FC7TVS6.cjs.map +1 -1
- package/dist/tsup/{chunk-Q3ODMSBE.js → chunk-B3GLD4IN.js} +2 -22
- package/dist/tsup/chunk-B3GLD4IN.js.map +1 -0
- package/dist/tsup/{chunk-OSQX3QN2.cjs → chunk-BWERJMV6.cjs} +139 -139
- package/dist/tsup/chunk-BWERJMV6.cjs.map +1 -0
- package/dist/tsup/{chunk-AGWIB6VG.cjs → chunk-D363DMNH.cjs} +3 -3
- package/dist/tsup/chunk-D363DMNH.cjs.map +1 -0
- package/dist/tsup/{chunk-42H5OK5Z.cjs → chunk-DTRDGPHU.cjs} +7 -7
- package/dist/tsup/chunk-DTRDGPHU.cjs.map +1 -0
- package/dist/tsup/{chunk-MFLAOS2S.cjs → chunk-E4LNLI3W.cjs} +8 -12
- package/dist/tsup/chunk-E4LNLI3W.cjs.map +1 -0
- package/dist/tsup/{chunk-FFJXFXEW.js → chunk-EFU4JW3T.js} +7 -11
- package/dist/tsup/chunk-EFU4JW3T.js.map +1 -0
- package/dist/tsup/{chunk-UEDIZR2M.cjs → chunk-FNAXD5BQ.cjs} +4 -24
- package/dist/tsup/chunk-FNAXD5BQ.cjs.map +1 -0
- package/dist/tsup/{chunk-PVR4LVX2.cjs → chunk-GM45LG7L.cjs} +10 -18
- package/dist/tsup/chunk-GM45LG7L.cjs.map +1 -0
- package/dist/tsup/{chunk-DB45WHMU.js → chunk-O3ZUMAN7.js} +3 -3
- package/dist/tsup/{chunk-UEYBIN52.js → chunk-OAUFXOG7.js} +2 -2
- package/dist/tsup/{chunk-LIEQDMZ6.cjs → chunk-P6F5MEWX.cjs} +5 -5
- package/dist/tsup/chunk-P6F5MEWX.cjs.map +1 -0
- package/dist/tsup/{chunk-E4X3JSN7.js → chunk-PT7AC5PC.js} +4 -12
- package/dist/tsup/chunk-PT7AC5PC.js.map +1 -0
- package/dist/tsup/{chunk-D2JJWLWM.js → chunk-UV7INX3N.js} +2 -2
- package/dist/tsup/chunk-VE2X4KMG.cjs.map +1 -1
- package/dist/tsup/{chunk-ARD7UMSN.js → chunk-XIX5DOZN.js} +1 -6
- package/dist/tsup/chunk-XIX5DOZN.js.map +1 -0
- package/dist/tsup/chunk-ZA7FLHKH.cjs.map +1 -1
- package/dist/tsup/client/mod.cjs +6 -6
- package/dist/tsup/client/mod.cjs.map +1 -1
- package/dist/tsup/client/mod.d.cts +3 -3
- package/dist/tsup/client/mod.d.ts +3 -3
- package/dist/tsup/client/mod.js +5 -5
- package/dist/tsup/common/log.cjs +2 -4
- package/dist/tsup/common/log.cjs.map +1 -1
- package/dist/tsup/common/log.d.cts +1 -5
- package/dist/tsup/common/log.d.ts +1 -5
- package/dist/tsup/common/log.js +3 -5
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.cjs.map +1 -1
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/{config-DLOxy81E.d.cts → config-B0LNDrLY.d.cts} +25 -5
- package/dist/tsup/{config-DLOxy81E.d.ts → config-B0LNDrLY.d.ts} +25 -5
- package/dist/tsup/{config-BkLXikR2.d.ts → config-BR1Nn0QQ.d.ts} +5 -24
- package/dist/tsup/{config-BARPNFvr.d.cts → config-tCvkwzyN.d.cts} +5 -24
- package/dist/tsup/{context-DntnH005.d.ts → context-D4WDwf9m.d.cts} +2 -3
- package/dist/tsup/{context-A16ymKhK.d.cts → context-oc9zhA3x.d.ts} +2 -3
- package/dist/tsup/db/drizzle.cjs +72 -144
- package/dist/tsup/db/drizzle.cjs.map +1 -1
- package/dist/tsup/db/drizzle.d.cts +2 -4
- package/dist/tsup/db/drizzle.d.ts +2 -4
- package/dist/tsup/db/drizzle.js +72 -144
- package/dist/tsup/db/drizzle.js.map +1 -1
- package/dist/tsup/db/mod.cjs +28 -90
- package/dist/tsup/db/mod.cjs.map +1 -1
- package/dist/tsup/db/mod.d.cts +8 -4
- package/dist/tsup/db/mod.d.ts +8 -4
- package/dist/tsup/db/mod.js +28 -90
- package/dist/tsup/db/mod.js.map +1 -1
- package/dist/tsup/dynamic/mod.cjs +2 -2
- package/dist/tsup/dynamic/mod.cjs.map +1 -1
- package/dist/tsup/dynamic/mod.d.cts +2 -2
- package/dist/tsup/dynamic/mod.d.ts +2 -2
- package/dist/tsup/dynamic/mod.js +1 -1
- package/dist/tsup/inspector/mod.cjs +11 -46
- package/dist/tsup/inspector/mod.cjs.map +1 -1
- package/dist/tsup/inspector/mod.d.cts +15 -37
- package/dist/tsup/inspector/mod.d.ts +15 -37
- package/dist/tsup/inspector/mod.js +10 -45
- package/dist/tsup/inspector/mod.js.map +1 -1
- package/dist/tsup/inspector-tab/mod.cjs +13 -2
- package/dist/tsup/inspector-tab/mod.cjs.map +1 -1
- package/dist/tsup/inspector-tab/mod.d.cts +14 -4
- package/dist/tsup/inspector-tab/mod.d.ts +14 -4
- package/dist/tsup/inspector-tab/mod.js +12 -1
- package/dist/tsup/inspector-tab/mod.js.map +1 -1
- package/dist/tsup/mod.cjs +90 -188
- package/dist/tsup/mod.cjs.map +1 -1
- package/dist/tsup/mod.d.cts +4 -4
- package/dist/tsup/mod.d.ts +4 -4
- package/dist/tsup/mod.js +26 -124
- package/dist/tsup/mod.js.map +1 -1
- package/dist/tsup/test/mod.cjs +9 -9
- package/dist/tsup/test/mod.cjs.map +1 -1
- package/dist/tsup/test/mod.d.cts +2 -2
- package/dist/tsup/test/mod.d.ts +2 -2
- package/dist/tsup/test/mod.js +5 -5
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.cjs.map +1 -1
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +11 -14
- package/dist/tsup/workflow/mod.cjs.map +1 -1
- package/dist/tsup/workflow/mod.d.cts +4 -4
- package/dist/tsup/workflow/mod.d.ts +4 -4
- package/dist/tsup/workflow/mod.js +5 -8
- package/dist/tsup/workflow/mod.js.map +1 -1
- package/package.json +14 -9
- package/src/actor/config.ts +0 -10
- package/src/common/bare/transport/v1.ts +0 -36
- package/src/common/database/config.ts +24 -19
- package/src/common/database/mod.test.ts +2 -96
- package/src/common/database/mod.ts +38 -102
- package/src/common/database/native-database.ts +4 -19
- package/src/common/log.ts +8 -14
- package/src/db/drizzle.ts +86 -187
- package/src/db/mod.ts +1 -0
- package/src/inspector/client.browser.ts +16 -73
- package/src/inspector/mod.ts +1 -1
- package/src/inspector-tab/mod.ts +15 -0
- package/src/registry/index.ts +0 -4
- package/src/registry/napi-runtime.ts +1 -25
- package/src/registry/native.ts +13 -95
- package/src/registry/runtime.ts +6 -18
- package/src/registry/wasm-runtime.ts +0 -22
- package/src/workflow/context.ts +0 -4
- package/src/workflow/inspector.ts +0 -8
- package/dist/tsup/chunk-42H5OK5Z.cjs.map +0 -1
- package/dist/tsup/chunk-AGWIB6VG.cjs.map +0 -1
- package/dist/tsup/chunk-ARD7UMSN.js.map +0 -1
- package/dist/tsup/chunk-E4X3JSN7.js.map +0 -1
- package/dist/tsup/chunk-FFJXFXEW.js.map +0 -1
- package/dist/tsup/chunk-HTREBONF.cjs.map +0 -1
- package/dist/tsup/chunk-LIEQDMZ6.cjs.map +0 -1
- package/dist/tsup/chunk-MFLAOS2S.cjs.map +0 -1
- package/dist/tsup/chunk-OSQX3QN2.cjs.map +0 -1
- package/dist/tsup/chunk-PVR4LVX2.cjs.map +0 -1
- package/dist/tsup/chunk-Q3ODMSBE.js.map +0 -1
- package/dist/tsup/chunk-UEDIZR2M.cjs.map +0 -1
- package/src/actor/config.test.ts +0 -11
- package/src/common/bare/generated/actor-uds-protocol/v1.ts +0 -802
- package/src/common/bare/generated/inspector/v5.ts +0 -1016
- /package/dist/tsup/{chunk-2EYF7KY7.js.map → chunk-3GVMLSND.js.map} +0 -0
- /package/dist/tsup/{chunk-DB45WHMU.js.map → chunk-O3ZUMAN7.js.map} +0 -0
- /package/dist/tsup/{chunk-UEYBIN52.js.map → chunk-OAUFXOG7.js.map} +0 -0
- /package/dist/tsup/{chunk-D2JJWLWM.js.map → chunk-UV7INX3N.js.map} +0 -0
|
@@ -1,802 +0,0 @@
|
|
|
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 u16 = number
|
|
10
|
-
export type u32 = number
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The schema version rides in the vbare embedded-version prefix of every
|
|
14
|
-
* frame, so ClientHello carries no version field.
|
|
15
|
-
*/
|
|
16
|
-
export type ClientHello = {
|
|
17
|
-
readonly token: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function readClientHello(bc: bare.ByteCursor): ClientHello {
|
|
21
|
-
return {
|
|
22
|
-
token: bare.readString(bc),
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function writeClientHello(bc: bare.ByteCursor, x: ClientHello): void {
|
|
27
|
-
bare.writeString(bc, x.token)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function encodeClientHello(x: ClientHello, config?: Partial<bare.Config>): Uint8Array {
|
|
31
|
-
const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG
|
|
32
|
-
const bc = new bare.ByteCursor(
|
|
33
|
-
new Uint8Array(fullConfig.initialBufferLength),
|
|
34
|
-
fullConfig,
|
|
35
|
-
)
|
|
36
|
-
writeClientHello(bc, x)
|
|
37
|
-
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function decodeClientHello(bytes: Uint8Array): ClientHello {
|
|
41
|
-
const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG)
|
|
42
|
-
const result = readClientHello(bc)
|
|
43
|
-
if (bc.offset < bc.view.byteLength) {
|
|
44
|
-
throw new bare.BareError(bc.offset, "remaining bytes")
|
|
45
|
-
}
|
|
46
|
-
return result
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type HelloOk = {
|
|
50
|
-
/**
|
|
51
|
-
* Largest frame payload the server accepts and will send.
|
|
52
|
-
*/
|
|
53
|
-
readonly maxFrameBytes: u32
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function readHelloOk(bc: bare.ByteCursor): HelloOk {
|
|
57
|
-
return {
|
|
58
|
-
maxFrameBytes: bare.readU32(bc),
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function writeHelloOk(bc: bare.ByteCursor, x: HelloOk): void {
|
|
63
|
-
bare.writeU32(bc, x.maxFrameBytes)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export type HelloRejectUnauthorized = null
|
|
67
|
-
|
|
68
|
-
export type HelloRejectUnsupportedVersion = {
|
|
69
|
-
readonly minVersion: u16
|
|
70
|
-
readonly maxVersion: u16
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function readHelloRejectUnsupportedVersion(bc: bare.ByteCursor): HelloRejectUnsupportedVersion {
|
|
74
|
-
return {
|
|
75
|
-
minVersion: bare.readU16(bc),
|
|
76
|
-
maxVersion: bare.readU16(bc),
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function writeHelloRejectUnsupportedVersion(bc: bare.ByteCursor, x: HelloRejectUnsupportedVersion): void {
|
|
81
|
-
bare.writeU16(bc, x.minVersion)
|
|
82
|
-
bare.writeU16(bc, x.maxVersion)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export type ServerHello =
|
|
86
|
-
| { readonly tag: "HelloOk"; readonly val: HelloOk }
|
|
87
|
-
| { readonly tag: "HelloRejectUnauthorized"; readonly val: HelloRejectUnauthorized }
|
|
88
|
-
| { readonly tag: "HelloRejectUnsupportedVersion"; readonly val: HelloRejectUnsupportedVersion }
|
|
89
|
-
|
|
90
|
-
export function readServerHello(bc: bare.ByteCursor): ServerHello {
|
|
91
|
-
const offset = bc.offset
|
|
92
|
-
const tag = bare.readU8(bc)
|
|
93
|
-
switch (tag) {
|
|
94
|
-
case 0:
|
|
95
|
-
return { tag: "HelloOk", val: readHelloOk(bc) }
|
|
96
|
-
case 1:
|
|
97
|
-
return { tag: "HelloRejectUnauthorized", val: null }
|
|
98
|
-
case 2:
|
|
99
|
-
return { tag: "HelloRejectUnsupportedVersion", val: readHelloRejectUnsupportedVersion(bc) }
|
|
100
|
-
default: {
|
|
101
|
-
bc.offset = offset
|
|
102
|
-
throw new bare.BareError(offset, "invalid tag")
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function writeServerHello(bc: bare.ByteCursor, x: ServerHello): void {
|
|
108
|
-
switch (x.tag) {
|
|
109
|
-
case "HelloOk": {
|
|
110
|
-
bare.writeU8(bc, 0)
|
|
111
|
-
writeHelloOk(bc, x.val)
|
|
112
|
-
break
|
|
113
|
-
}
|
|
114
|
-
case "HelloRejectUnauthorized": {
|
|
115
|
-
bare.writeU8(bc, 1)
|
|
116
|
-
break
|
|
117
|
-
}
|
|
118
|
-
case "HelloRejectUnsupportedVersion": {
|
|
119
|
-
bare.writeU8(bc, 2)
|
|
120
|
-
writeHelloRejectUnsupportedVersion(bc, x.val)
|
|
121
|
-
break
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export function encodeServerHello(x: ServerHello, config?: Partial<bare.Config>): Uint8Array {
|
|
127
|
-
const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG
|
|
128
|
-
const bc = new bare.ByteCursor(
|
|
129
|
-
new Uint8Array(fullConfig.initialBufferLength),
|
|
130
|
-
fullConfig,
|
|
131
|
-
)
|
|
132
|
-
writeServerHello(bc, x)
|
|
133
|
-
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function decodeServerHello(bytes: Uint8Array): ServerHello {
|
|
137
|
-
const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG)
|
|
138
|
-
const result = readServerHello(bc)
|
|
139
|
-
if (bc.offset < bc.view.byteLength) {
|
|
140
|
-
throw new bare.BareError(bc.offset, "remaining bytes")
|
|
141
|
-
}
|
|
142
|
-
return result
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export type SqlNull = null
|
|
146
|
-
|
|
147
|
-
export type SqlInteger = i64
|
|
148
|
-
|
|
149
|
-
export function readSqlInteger(bc: bare.ByteCursor): SqlInteger {
|
|
150
|
-
return bare.readI64(bc)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export function writeSqlInteger(bc: bare.ByteCursor, x: SqlInteger): void {
|
|
154
|
-
bare.writeI64(bc, x)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export type SqlReal = f64
|
|
158
|
-
|
|
159
|
-
export function readSqlReal(bc: bare.ByteCursor): SqlReal {
|
|
160
|
-
return bare.readF64(bc)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function writeSqlReal(bc: bare.ByteCursor, x: SqlReal): void {
|
|
164
|
-
bare.writeF64(bc, x)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export type SqlText = string
|
|
168
|
-
|
|
169
|
-
export function readSqlText(bc: bare.ByteCursor): SqlText {
|
|
170
|
-
return bare.readString(bc)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function writeSqlText(bc: bare.ByteCursor, x: SqlText): void {
|
|
174
|
-
bare.writeString(bc, x)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export type SqlBlob = ArrayBuffer
|
|
178
|
-
|
|
179
|
-
export function readSqlBlob(bc: bare.ByteCursor): SqlBlob {
|
|
180
|
-
return bare.readData(bc)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function writeSqlBlob(bc: bare.ByteCursor, x: SqlBlob): void {
|
|
184
|
-
bare.writeData(bc, x)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export type SqlValue =
|
|
188
|
-
| { readonly tag: "SqlNull"; readonly val: SqlNull }
|
|
189
|
-
| { readonly tag: "SqlInteger"; readonly val: SqlInteger }
|
|
190
|
-
| { readonly tag: "SqlReal"; readonly val: SqlReal }
|
|
191
|
-
| { readonly tag: "SqlText"; readonly val: SqlText }
|
|
192
|
-
| { readonly tag: "SqlBlob"; readonly val: SqlBlob }
|
|
193
|
-
|
|
194
|
-
export function readSqlValue(bc: bare.ByteCursor): SqlValue {
|
|
195
|
-
const offset = bc.offset
|
|
196
|
-
const tag = bare.readU8(bc)
|
|
197
|
-
switch (tag) {
|
|
198
|
-
case 0:
|
|
199
|
-
return { tag: "SqlNull", val: null }
|
|
200
|
-
case 1:
|
|
201
|
-
return { tag: "SqlInteger", val: readSqlInteger(bc) }
|
|
202
|
-
case 2:
|
|
203
|
-
return { tag: "SqlReal", val: readSqlReal(bc) }
|
|
204
|
-
case 3:
|
|
205
|
-
return { tag: "SqlText", val: readSqlText(bc) }
|
|
206
|
-
case 4:
|
|
207
|
-
return { tag: "SqlBlob", val: readSqlBlob(bc) }
|
|
208
|
-
default: {
|
|
209
|
-
bc.offset = offset
|
|
210
|
-
throw new bare.BareError(offset, "invalid tag")
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export function writeSqlValue(bc: bare.ByteCursor, x: SqlValue): void {
|
|
216
|
-
switch (x.tag) {
|
|
217
|
-
case "SqlNull": {
|
|
218
|
-
bare.writeU8(bc, 0)
|
|
219
|
-
break
|
|
220
|
-
}
|
|
221
|
-
case "SqlInteger": {
|
|
222
|
-
bare.writeU8(bc, 1)
|
|
223
|
-
writeSqlInteger(bc, x.val)
|
|
224
|
-
break
|
|
225
|
-
}
|
|
226
|
-
case "SqlReal": {
|
|
227
|
-
bare.writeU8(bc, 2)
|
|
228
|
-
writeSqlReal(bc, x.val)
|
|
229
|
-
break
|
|
230
|
-
}
|
|
231
|
-
case "SqlText": {
|
|
232
|
-
bare.writeU8(bc, 3)
|
|
233
|
-
writeSqlText(bc, x.val)
|
|
234
|
-
break
|
|
235
|
-
}
|
|
236
|
-
case "SqlBlob": {
|
|
237
|
-
bare.writeU8(bc, 4)
|
|
238
|
-
writeSqlBlob(bc, x.val)
|
|
239
|
-
break
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export type SqlRow = readonly SqlValue[]
|
|
245
|
-
|
|
246
|
-
export function readSqlRow(bc: bare.ByteCursor): SqlRow {
|
|
247
|
-
const len = bare.readUintSafe(bc)
|
|
248
|
-
if (len === 0) {
|
|
249
|
-
return []
|
|
250
|
-
}
|
|
251
|
-
const result = [readSqlValue(bc)]
|
|
252
|
-
for (let i = 1; i < len; i++) {
|
|
253
|
-
result[i] = readSqlValue(bc)
|
|
254
|
-
}
|
|
255
|
-
return result
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export function writeSqlRow(bc: bare.ByteCursor, x: SqlRow): void {
|
|
259
|
-
bare.writeUintSafe(bc, x.length)
|
|
260
|
-
for (let i = 0; i < x.length; i++) {
|
|
261
|
-
writeSqlValue(bc, x[i])
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Multi-statement script, one job, no params, no result rows (any rows the
|
|
267
|
-
* script produces, including RETURNING output, are discarded).
|
|
268
|
-
* Intended for migrations and DDL batches.
|
|
269
|
-
*/
|
|
270
|
-
export type SqliteExec = {
|
|
271
|
-
readonly script: string
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export function readSqliteExec(bc: bare.ByteCursor): SqliteExec {
|
|
275
|
-
return {
|
|
276
|
-
script: bare.readString(bc),
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
export function writeSqliteExec(bc: bare.ByteCursor, x: SqliteExec): void {
|
|
281
|
-
bare.writeString(bc, x.script)
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
function read0(bc: bare.ByteCursor): readonly SqlValue[] {
|
|
285
|
-
const len = bare.readUintSafe(bc)
|
|
286
|
-
if (len === 0) {
|
|
287
|
-
return []
|
|
288
|
-
}
|
|
289
|
-
const result = [readSqlValue(bc)]
|
|
290
|
-
for (let i = 1; i < len; i++) {
|
|
291
|
-
result[i] = readSqlValue(bc)
|
|
292
|
-
}
|
|
293
|
-
return result
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
function write0(bc: bare.ByteCursor, x: readonly SqlValue[]): void {
|
|
297
|
-
bare.writeUintSafe(bc, x.length)
|
|
298
|
-
for (let i = 0; i < x.length; i++) {
|
|
299
|
-
writeSqlValue(bc, x[i])
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Single statement, positional params, returns rows and change counts.
|
|
305
|
-
*/
|
|
306
|
-
export type SqliteQuery = {
|
|
307
|
-
readonly sql: string
|
|
308
|
-
readonly params: readonly SqlValue[]
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
export function readSqliteQuery(bc: bare.ByteCursor): SqliteQuery {
|
|
312
|
-
return {
|
|
313
|
-
sql: bare.readString(bc),
|
|
314
|
-
params: read0(bc),
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
export function writeSqliteQuery(bc: bare.ByteCursor, x: SqliteQuery): void {
|
|
319
|
-
bare.writeString(bc, x.sql)
|
|
320
|
-
write0(bc, x.params)
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Future APIs extend this union in later schema versions.
|
|
325
|
-
*/
|
|
326
|
-
export type RequestPayload =
|
|
327
|
-
| { readonly tag: "SqliteExec"; readonly val: SqliteExec }
|
|
328
|
-
| { readonly tag: "SqliteQuery"; readonly val: SqliteQuery }
|
|
329
|
-
|
|
330
|
-
export function readRequestPayload(bc: bare.ByteCursor): RequestPayload {
|
|
331
|
-
const offset = bc.offset
|
|
332
|
-
const tag = bare.readU8(bc)
|
|
333
|
-
switch (tag) {
|
|
334
|
-
case 0:
|
|
335
|
-
return { tag: "SqliteExec", val: readSqliteExec(bc) }
|
|
336
|
-
case 1:
|
|
337
|
-
return { tag: "SqliteQuery", val: readSqliteQuery(bc) }
|
|
338
|
-
default: {
|
|
339
|
-
bc.offset = offset
|
|
340
|
-
throw new bare.BareError(offset, "invalid tag")
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
export function writeRequestPayload(bc: bare.ByteCursor, x: RequestPayload): void {
|
|
346
|
-
switch (x.tag) {
|
|
347
|
-
case "SqliteExec": {
|
|
348
|
-
bare.writeU8(bc, 0)
|
|
349
|
-
writeSqliteExec(bc, x.val)
|
|
350
|
-
break
|
|
351
|
-
}
|
|
352
|
-
case "SqliteQuery": {
|
|
353
|
-
bare.writeU8(bc, 1)
|
|
354
|
-
writeSqliteQuery(bc, x.val)
|
|
355
|
-
break
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
function read1(bc: bare.ByteCursor): string | null {
|
|
361
|
-
return bare.readBool(bc) ? bare.readString(bc) : null
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function write1(bc: bare.ByteCursor, x: string | null): void {
|
|
365
|
-
bare.writeBool(bc, x != null)
|
|
366
|
-
if (x != null) {
|
|
367
|
-
bare.writeString(bc, x)
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
export type Request = {
|
|
372
|
-
readonly requestId: u32
|
|
373
|
-
/**
|
|
374
|
-
* Transaction lease key (see sqlite-transaction-interleaving.md).
|
|
375
|
-
* Keyed jobs may hold a transaction open across requests; keyless jobs
|
|
376
|
-
* must end in autocommit. Keys are namespaced per connection.
|
|
377
|
-
*/
|
|
378
|
-
readonly leaseKey: string | null
|
|
379
|
-
readonly payload: RequestPayload
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
export function readRequest(bc: bare.ByteCursor): Request {
|
|
383
|
-
return {
|
|
384
|
-
requestId: bare.readU32(bc),
|
|
385
|
-
leaseKey: read1(bc),
|
|
386
|
-
payload: readRequestPayload(bc),
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
export function writeRequest(bc: bare.ByteCursor, x: Request): void {
|
|
391
|
-
bare.writeU32(bc, x.requestId)
|
|
392
|
-
write1(bc, x.leaseKey)
|
|
393
|
-
writeRequestPayload(bc, x.payload)
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
export type ClientFrame =
|
|
397
|
-
| { readonly tag: "Request"; readonly val: Request }
|
|
398
|
-
|
|
399
|
-
export function readClientFrame(bc: bare.ByteCursor): ClientFrame {
|
|
400
|
-
const offset = bc.offset
|
|
401
|
-
const tag = bare.readU8(bc)
|
|
402
|
-
switch (tag) {
|
|
403
|
-
case 0:
|
|
404
|
-
return { tag: "Request", val: readRequest(bc) }
|
|
405
|
-
default: {
|
|
406
|
-
bc.offset = offset
|
|
407
|
-
throw new bare.BareError(offset, "invalid tag")
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
export function writeClientFrame(bc: bare.ByteCursor, x: ClientFrame): void {
|
|
413
|
-
switch (x.tag) {
|
|
414
|
-
case "Request": {
|
|
415
|
-
bare.writeU8(bc, 0)
|
|
416
|
-
writeRequest(bc, x.val)
|
|
417
|
-
break
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
export function encodeClientFrame(x: ClientFrame, config?: Partial<bare.Config>): Uint8Array {
|
|
423
|
-
const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG
|
|
424
|
-
const bc = new bare.ByteCursor(
|
|
425
|
-
new Uint8Array(fullConfig.initialBufferLength),
|
|
426
|
-
fullConfig,
|
|
427
|
-
)
|
|
428
|
-
writeClientFrame(bc, x)
|
|
429
|
-
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
export function decodeClientFrame(bytes: Uint8Array): ClientFrame {
|
|
433
|
-
const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG)
|
|
434
|
-
const result = readClientFrame(bc)
|
|
435
|
-
if (bc.offset < bc.view.byteLength) {
|
|
436
|
-
throw new bare.BareError(bc.offset, "remaining bytes")
|
|
437
|
-
}
|
|
438
|
-
return result
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
export type SqliteExecOk = null
|
|
442
|
-
|
|
443
|
-
function read2(bc: bare.ByteCursor): readonly string[] {
|
|
444
|
-
const len = bare.readUintSafe(bc)
|
|
445
|
-
if (len === 0) {
|
|
446
|
-
return []
|
|
447
|
-
}
|
|
448
|
-
const result = [bare.readString(bc)]
|
|
449
|
-
for (let i = 1; i < len; i++) {
|
|
450
|
-
result[i] = bare.readString(bc)
|
|
451
|
-
}
|
|
452
|
-
return result
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
function write2(bc: bare.ByteCursor, x: readonly string[]): void {
|
|
456
|
-
bare.writeUintSafe(bc, x.length)
|
|
457
|
-
for (let i = 0; i < x.length; i++) {
|
|
458
|
-
bare.writeString(bc, x[i])
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
function read3(bc: bare.ByteCursor): readonly SqlRow[] {
|
|
463
|
-
const len = bare.readUintSafe(bc)
|
|
464
|
-
if (len === 0) {
|
|
465
|
-
return []
|
|
466
|
-
}
|
|
467
|
-
const result = [readSqlRow(bc)]
|
|
468
|
-
for (let i = 1; i < len; i++) {
|
|
469
|
-
result[i] = readSqlRow(bc)
|
|
470
|
-
}
|
|
471
|
-
return result
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
function write3(bc: bare.ByteCursor, x: readonly SqlRow[]): void {
|
|
475
|
-
bare.writeUintSafe(bc, x.length)
|
|
476
|
-
for (let i = 0; i < x.length; i++) {
|
|
477
|
-
writeSqlRow(bc, x[i])
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
function read4(bc: bare.ByteCursor): i64 | null {
|
|
482
|
-
return bare.readBool(bc) ? bare.readI64(bc) : null
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
function write4(bc: bare.ByteCursor, x: i64 | null): void {
|
|
486
|
-
bare.writeBool(bc, x != null)
|
|
487
|
-
if (x != null) {
|
|
488
|
-
bare.writeI64(bc, x)
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Field shapes match the existing db surface (depot-client ExecuteResult):
|
|
494
|
-
* changes is sqlite3_changes as i64; lastInsertRowId is absent when the
|
|
495
|
-
* statement changed no rows.
|
|
496
|
-
*/
|
|
497
|
-
export type SqliteQueryOk = {
|
|
498
|
-
readonly columns: readonly string[]
|
|
499
|
-
readonly rows: readonly SqlRow[]
|
|
500
|
-
readonly changes: i64
|
|
501
|
-
readonly lastInsertRowId: i64 | null
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
export function readSqliteQueryOk(bc: bare.ByteCursor): SqliteQueryOk {
|
|
505
|
-
return {
|
|
506
|
-
columns: read2(bc),
|
|
507
|
-
rows: read3(bc),
|
|
508
|
-
changes: bare.readI64(bc),
|
|
509
|
-
lastInsertRowId: read4(bc),
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
export function writeSqliteQueryOk(bc: bare.ByteCursor, x: SqliteQueryOk): void {
|
|
514
|
-
write2(bc, x.columns)
|
|
515
|
-
write3(bc, x.rows)
|
|
516
|
-
bare.writeI64(bc, x.changes)
|
|
517
|
-
write4(bc, x.lastInsertRowId)
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* Statement failure. code is the SQLite extended result code where the
|
|
522
|
-
* failure came from SQLite; server-synthesized failures (e.g. trailing
|
|
523
|
-
* content after a single statement) may use a server-generated code.
|
|
524
|
-
* statementIndex is the 0-based index of the failing statement within an
|
|
525
|
-
* Exec script; always 0 for Query.
|
|
526
|
-
*/
|
|
527
|
-
export type SqlError = {
|
|
528
|
-
readonly code: i32
|
|
529
|
-
readonly statementIndex: u32
|
|
530
|
-
readonly message: string
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
export function readSqlError(bc: bare.ByteCursor): SqlError {
|
|
534
|
-
return {
|
|
535
|
-
code: bare.readI32(bc),
|
|
536
|
-
statementIndex: bare.readU32(bc),
|
|
537
|
-
message: bare.readString(bc),
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
export function writeSqlError(bc: bare.ByteCursor, x: SqlError): void {
|
|
542
|
-
bare.writeI32(bc, x.code)
|
|
543
|
-
bare.writeU32(bc, x.statementIndex)
|
|
544
|
-
bare.writeString(bc, x.message)
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
/**
|
|
548
|
-
* Endpoint no longer serving (actor sleeping/stopping/destroyed).
|
|
549
|
-
* Terminal: the server closes the connection after answering all in-flight
|
|
550
|
-
* requests with this.
|
|
551
|
-
*/
|
|
552
|
-
export type EndpointClosed = null
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* The shared SQLite worker queue was full at admission; the request was
|
|
556
|
-
* never enqueued and had no effect.
|
|
557
|
-
*/
|
|
558
|
-
export type QueueFull = {
|
|
559
|
-
/**
|
|
560
|
-
* Names the limit that fired so the error is actionable.
|
|
561
|
-
*/
|
|
562
|
-
readonly limit: string
|
|
563
|
-
readonly capacity: u32
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
export function readQueueFull(bc: bare.ByteCursor): QueueFull {
|
|
567
|
-
return {
|
|
568
|
-
limit: bare.readString(bc),
|
|
569
|
-
capacity: bare.readU32(bc),
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
export function writeQueueFull(bc: bare.ByteCursor, x: QueueFull): void {
|
|
574
|
-
bare.writeString(bc, x.limit)
|
|
575
|
-
bare.writeU32(bc, x.capacity)
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
* A keyless job completed without a statement error but left an explicit
|
|
580
|
-
* transaction open; the server rolled it back. Hold a lease (leaseKey) to
|
|
581
|
-
* span jobs.
|
|
582
|
-
*/
|
|
583
|
-
export type TxnOpenAtEnd = null
|
|
584
|
-
|
|
585
|
-
/**
|
|
586
|
-
* The job's lease key is poisoned: its lease deadline fired (or its
|
|
587
|
-
* connection closed mid-transaction) and the transaction was rolled back.
|
|
588
|
-
* The job was not executed. Start over with a fresh key.
|
|
589
|
-
*/
|
|
590
|
-
export type LeaseExpired = null
|
|
591
|
-
|
|
592
|
-
/**
|
|
593
|
-
* The response payload would exceed maxFrameBytes. Non-terminal. The
|
|
594
|
-
* statement DID execute: for writes (e.g. INSERT ... RETURNING over a huge
|
|
595
|
-
* table) effects persist even though results were dropped.
|
|
596
|
-
*/
|
|
597
|
-
export type ResponseTooLarge = null
|
|
598
|
-
|
|
599
|
-
export type ResponsePayload =
|
|
600
|
-
| { readonly tag: "SqliteExecOk"; readonly val: SqliteExecOk }
|
|
601
|
-
| { readonly tag: "SqliteQueryOk"; readonly val: SqliteQueryOk }
|
|
602
|
-
| { readonly tag: "SqlError"; readonly val: SqlError }
|
|
603
|
-
| { readonly tag: "EndpointClosed"; readonly val: EndpointClosed }
|
|
604
|
-
| { readonly tag: "QueueFull"; readonly val: QueueFull }
|
|
605
|
-
| { readonly tag: "TxnOpenAtEnd"; readonly val: TxnOpenAtEnd }
|
|
606
|
-
| { readonly tag: "LeaseExpired"; readonly val: LeaseExpired }
|
|
607
|
-
| { readonly tag: "ResponseTooLarge"; readonly val: ResponseTooLarge }
|
|
608
|
-
|
|
609
|
-
export function readResponsePayload(bc: bare.ByteCursor): ResponsePayload {
|
|
610
|
-
const offset = bc.offset
|
|
611
|
-
const tag = bare.readU8(bc)
|
|
612
|
-
switch (tag) {
|
|
613
|
-
case 0:
|
|
614
|
-
return { tag: "SqliteExecOk", val: null }
|
|
615
|
-
case 1:
|
|
616
|
-
return { tag: "SqliteQueryOk", val: readSqliteQueryOk(bc) }
|
|
617
|
-
case 2:
|
|
618
|
-
return { tag: "SqlError", val: readSqlError(bc) }
|
|
619
|
-
case 3:
|
|
620
|
-
return { tag: "EndpointClosed", val: null }
|
|
621
|
-
case 4:
|
|
622
|
-
return { tag: "QueueFull", val: readQueueFull(bc) }
|
|
623
|
-
case 5:
|
|
624
|
-
return { tag: "TxnOpenAtEnd", val: null }
|
|
625
|
-
case 6:
|
|
626
|
-
return { tag: "LeaseExpired", val: null }
|
|
627
|
-
case 7:
|
|
628
|
-
return { tag: "ResponseTooLarge", val: null }
|
|
629
|
-
default: {
|
|
630
|
-
bc.offset = offset
|
|
631
|
-
throw new bare.BareError(offset, "invalid tag")
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
export function writeResponsePayload(bc: bare.ByteCursor, x: ResponsePayload): void {
|
|
637
|
-
switch (x.tag) {
|
|
638
|
-
case "SqliteExecOk": {
|
|
639
|
-
bare.writeU8(bc, 0)
|
|
640
|
-
break
|
|
641
|
-
}
|
|
642
|
-
case "SqliteQueryOk": {
|
|
643
|
-
bare.writeU8(bc, 1)
|
|
644
|
-
writeSqliteQueryOk(bc, x.val)
|
|
645
|
-
break
|
|
646
|
-
}
|
|
647
|
-
case "SqlError": {
|
|
648
|
-
bare.writeU8(bc, 2)
|
|
649
|
-
writeSqlError(bc, x.val)
|
|
650
|
-
break
|
|
651
|
-
}
|
|
652
|
-
case "EndpointClosed": {
|
|
653
|
-
bare.writeU8(bc, 3)
|
|
654
|
-
break
|
|
655
|
-
}
|
|
656
|
-
case "QueueFull": {
|
|
657
|
-
bare.writeU8(bc, 4)
|
|
658
|
-
writeQueueFull(bc, x.val)
|
|
659
|
-
break
|
|
660
|
-
}
|
|
661
|
-
case "TxnOpenAtEnd": {
|
|
662
|
-
bare.writeU8(bc, 5)
|
|
663
|
-
break
|
|
664
|
-
}
|
|
665
|
-
case "LeaseExpired": {
|
|
666
|
-
bare.writeU8(bc, 6)
|
|
667
|
-
break
|
|
668
|
-
}
|
|
669
|
-
case "ResponseTooLarge": {
|
|
670
|
-
bare.writeU8(bc, 7)
|
|
671
|
-
break
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
export type Response = {
|
|
677
|
-
readonly requestId: u32
|
|
678
|
-
readonly payload: ResponsePayload
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
export function readResponse(bc: bare.ByteCursor): Response {
|
|
682
|
-
return {
|
|
683
|
-
requestId: bare.readU32(bc),
|
|
684
|
-
payload: readResponsePayload(bc),
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
export function writeResponse(bc: bare.ByteCursor, x: Response): void {
|
|
689
|
-
bare.writeU32(bc, x.requestId)
|
|
690
|
-
writeResponsePayload(bc, x.payload)
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
export type FrameTooLarge = null
|
|
694
|
-
|
|
695
|
-
export type MalformedFrame = null
|
|
696
|
-
|
|
697
|
-
export type GoAwayReason =
|
|
698
|
-
| { readonly tag: "FrameTooLarge"; readonly val: FrameTooLarge }
|
|
699
|
-
| { readonly tag: "MalformedFrame"; readonly val: MalformedFrame }
|
|
700
|
-
|
|
701
|
-
export function readGoAwayReason(bc: bare.ByteCursor): GoAwayReason {
|
|
702
|
-
const offset = bc.offset
|
|
703
|
-
const tag = bare.readU8(bc)
|
|
704
|
-
switch (tag) {
|
|
705
|
-
case 0:
|
|
706
|
-
return { tag: "FrameTooLarge", val: null }
|
|
707
|
-
case 1:
|
|
708
|
-
return { tag: "MalformedFrame", val: null }
|
|
709
|
-
default: {
|
|
710
|
-
bc.offset = offset
|
|
711
|
-
throw new bare.BareError(offset, "invalid tag")
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
export function writeGoAwayReason(bc: bare.ByteCursor, x: GoAwayReason): void {
|
|
717
|
-
switch (x.tag) {
|
|
718
|
-
case "FrameTooLarge": {
|
|
719
|
-
bare.writeU8(bc, 0)
|
|
720
|
-
break
|
|
721
|
-
}
|
|
722
|
-
case "MalformedFrame": {
|
|
723
|
-
bare.writeU8(bc, 1)
|
|
724
|
-
break
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
/**
|
|
730
|
-
* Terminal: the server closes the connection after sending GoAway.
|
|
731
|
-
*/
|
|
732
|
-
export type GoAway = {
|
|
733
|
-
readonly reason: GoAwayReason
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
export function readGoAway(bc: bare.ByteCursor): GoAway {
|
|
737
|
-
return {
|
|
738
|
-
reason: readGoAwayReason(bc),
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
export function writeGoAway(bc: bare.ByteCursor, x: GoAway): void {
|
|
743
|
-
writeGoAwayReason(bc, x.reason)
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
export type ServerFrame =
|
|
747
|
-
| { readonly tag: "Response"; readonly val: Response }
|
|
748
|
-
| { readonly tag: "GoAway"; readonly val: GoAway }
|
|
749
|
-
|
|
750
|
-
export function readServerFrame(bc: bare.ByteCursor): ServerFrame {
|
|
751
|
-
const offset = bc.offset
|
|
752
|
-
const tag = bare.readU8(bc)
|
|
753
|
-
switch (tag) {
|
|
754
|
-
case 0:
|
|
755
|
-
return { tag: "Response", val: readResponse(bc) }
|
|
756
|
-
case 1:
|
|
757
|
-
return { tag: "GoAway", val: readGoAway(bc) }
|
|
758
|
-
default: {
|
|
759
|
-
bc.offset = offset
|
|
760
|
-
throw new bare.BareError(offset, "invalid tag")
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
export function writeServerFrame(bc: bare.ByteCursor, x: ServerFrame): void {
|
|
766
|
-
switch (x.tag) {
|
|
767
|
-
case "Response": {
|
|
768
|
-
bare.writeU8(bc, 0)
|
|
769
|
-
writeResponse(bc, x.val)
|
|
770
|
-
break
|
|
771
|
-
}
|
|
772
|
-
case "GoAway": {
|
|
773
|
-
bare.writeU8(bc, 1)
|
|
774
|
-
writeGoAway(bc, x.val)
|
|
775
|
-
break
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
export function encodeServerFrame(x: ServerFrame, config?: Partial<bare.Config>): Uint8Array {
|
|
781
|
-
const fullConfig = config != null ? bare.Config(config) : DEFAULT_CONFIG
|
|
782
|
-
const bc = new bare.ByteCursor(
|
|
783
|
-
new Uint8Array(fullConfig.initialBufferLength),
|
|
784
|
-
fullConfig,
|
|
785
|
-
)
|
|
786
|
-
writeServerFrame(bc, x)
|
|
787
|
-
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
export function decodeServerFrame(bytes: Uint8Array): ServerFrame {
|
|
791
|
-
const bc = new bare.ByteCursor(bytes, DEFAULT_CONFIG)
|
|
792
|
-
const result = readServerFrame(bc)
|
|
793
|
-
if (bc.offset < bc.view.byteLength) {
|
|
794
|
-
throw new bare.BareError(bc.offset, "remaining bytes")
|
|
795
|
-
}
|
|
796
|
-
return result
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
function assert(condition: boolean, message?: string): asserts condition {
|
|
801
|
-
if (!condition) throw new Error(message ?? "Assertion failed")
|
|
802
|
-
}
|