spacetimedb 2.5.0 → 2.6.0
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/LICENSE.txt +759 -759
- package/README.md +211 -211
- package/dist/angular/index.cjs.map +1 -1
- package/dist/angular/index.mjs.map +1 -1
- package/dist/browser/angular/index.mjs.map +1 -1
- package/dist/browser/react/index.mjs +129 -57
- package/dist/browser/react/index.mjs.map +1 -1
- package/dist/browser/solid/index.mjs +120 -50
- package/dist/browser/solid/index.mjs.map +1 -1
- package/dist/browser/svelte/index.mjs.map +1 -1
- package/dist/browser/vue/index.mjs.map +1 -1
- package/dist/index.browser.mjs +10 -2
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.cjs +10 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +10 -2
- package/dist/index.mjs.map +1 -1
- package/dist/min/index.browser.mjs +1 -1
- package/dist/min/index.browser.mjs.map +1 -1
- package/dist/min/react/index.mjs +1 -1
- package/dist/min/react/index.mjs.map +1 -1
- package/dist/min/sdk/index.browser.mjs +1 -1
- package/dist/min/sdk/index.browser.mjs.map +1 -1
- package/dist/react/index.cjs +129 -57
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.mjs +129 -57
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/useTable.d.ts.map +1 -1
- package/dist/sdk/connection_manager.d.ts +8 -0
- package/dist/sdk/connection_manager.d.ts.map +1 -1
- package/dist/sdk/db_connection_impl.d.ts +7 -0
- package/dist/sdk/db_connection_impl.d.ts.map +1 -1
- package/dist/sdk/index.browser.mjs +10 -2
- package/dist/sdk/index.browser.mjs.map +1 -1
- package/dist/sdk/index.cjs +10 -2
- package/dist/sdk/index.cjs.map +1 -1
- package/dist/sdk/index.mjs +10 -2
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/sdk/websocket_test_adapter.d.ts +2 -1
- package/dist/sdk/websocket_test_adapter.d.ts.map +1 -1
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/runtime.d.ts.map +1 -1
- package/dist/solid/index.cjs +120 -50
- package/dist/solid/index.cjs.map +1 -1
- package/dist/solid/index.mjs +120 -50
- package/dist/solid/index.mjs.map +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.mjs.map +1 -1
- package/dist/tanstack/index.cjs +120 -50
- package/dist/tanstack/index.cjs.map +1 -1
- package/dist/tanstack/index.mjs +120 -50
- package/dist/tanstack/index.mjs.map +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/angular/connection_state.ts +19 -19
- package/src/angular/index.ts +3 -3
- package/src/angular/injectors/index.ts +4 -4
- package/src/angular/injectors/inject-reducer.ts +62 -62
- package/src/angular/injectors/inject-spacetimedb-connected.ts +13 -13
- package/src/angular/injectors/inject-spacetimedb.ts +10 -10
- package/src/angular/injectors/inject-table.ts +234 -234
- package/src/angular/providers/index.ts +1 -1
- package/src/angular/providers/provide-spacetimedb.ts +96 -96
- package/src/index.ts +16 -16
- package/src/lib/algebraic_type.ts +819 -819
- package/src/lib/algebraic_type_variants.ts +26 -26
- package/src/lib/algebraic_value.ts +10 -10
- package/src/lib/autogen/types.ts +746 -746
- package/src/lib/binary_reader.ts +188 -188
- package/src/lib/binary_writer.ts +213 -213
- package/src/lib/connection_id.ts +102 -102
- package/src/lib/constraints.ts +48 -48
- package/src/lib/errors.ts +26 -26
- package/src/lib/filter.ts +195 -195
- package/src/lib/identity.ts +83 -83
- package/src/lib/indexes.ts +251 -251
- package/src/lib/option.ts +34 -34
- package/src/lib/query.ts +1019 -1019
- package/src/lib/reducer_schema.ts +38 -38
- package/src/lib/reducers.ts +116 -116
- package/src/lib/result.ts +36 -36
- package/src/lib/schedule_at.ts +86 -86
- package/src/lib/schema.ts +420 -420
- package/src/lib/table.ts +548 -548
- package/src/lib/table_schema.ts +64 -64
- package/src/lib/time_duration.ts +77 -77
- package/src/lib/timestamp.ts +148 -148
- package/src/lib/type_builders.test-d.ts +128 -128
- package/src/lib/type_builders.ts +4014 -4014
- package/src/lib/type_util.ts +124 -124
- package/src/lib/util.ts +196 -196
- package/src/lib/uuid.ts +337 -337
- package/src/react/SpacetimeDBProvider.ts +84 -84
- package/src/react/connection_state.ts +6 -6
- package/src/react/index.ts +5 -5
- package/src/react/useProcedure.ts +60 -60
- package/src/react/useReducer.ts +53 -53
- package/src/react/useSpacetimeDB.ts +18 -18
- package/src/react/useTable.ts +256 -251
- package/src/sdk/client_api/index.ts +114 -114
- package/src/sdk/client_api/types/procedures.ts +8 -8
- package/src/sdk/client_api/types/reducers.ts +8 -8
- package/src/sdk/client_api/types.ts +288 -288
- package/src/sdk/client_cache.ts +129 -129
- package/src/sdk/client_table.ts +179 -179
- package/src/sdk/connection_manager.ts +352 -237
- package/src/sdk/db_connection_builder.ts +290 -290
- package/src/sdk/db_connection_impl.ts +1356 -1347
- package/src/sdk/db_context.ts +28 -28
- package/src/sdk/db_view.ts +12 -12
- package/src/sdk/decompress.ts +51 -51
- package/src/sdk/event.ts +18 -18
- package/src/sdk/event_context.ts +51 -51
- package/src/sdk/event_emitter.ts +32 -32
- package/src/sdk/index.ts +14 -14
- package/src/sdk/internal.ts +2 -2
- package/src/sdk/json_api.ts +46 -46
- package/src/sdk/logger.ts +134 -134
- package/src/sdk/message_types.ts +46 -46
- package/src/sdk/procedures.ts +83 -83
- package/src/sdk/reducer_event.ts +20 -20
- package/src/sdk/reducer_handle.ts +12 -12
- package/src/sdk/reducers.ts +159 -159
- package/src/sdk/schema.ts +45 -45
- package/src/sdk/spacetime_module.ts +28 -28
- package/src/sdk/subscription_builder_impl.ts +275 -275
- package/src/sdk/table_cache.ts +581 -581
- package/src/sdk/type_utils.ts +19 -19
- package/src/sdk/version.ts +133 -133
- package/src/sdk/websocket_decompress_adapter.ts +63 -63
- package/src/sdk/websocket_protocols.ts +25 -25
- package/src/sdk/websocket_test_adapter.ts +107 -100
- package/src/sdk/websocket_v3_frames.ts +126 -126
- package/src/sdk/ws.ts +105 -105
- package/src/server/console.ts +81 -81
- package/src/server/db_view.ts +21 -21
- package/src/server/errors.ts +138 -138
- package/src/server/http.test-d.ts +80 -80
- package/src/server/http.ts +14 -14
- package/src/server/http_handlers.ts +413 -413
- package/src/server/http_internal.ts +79 -79
- package/src/server/http_shared.ts +186 -186
- package/src/server/index.ts +37 -37
- package/src/server/polyfills.ts +4 -4
- package/src/server/procedures.ts +239 -239
- package/src/server/query.ts +1 -1
- package/src/server/range.ts +53 -53
- package/src/server/reducers.ts +113 -113
- package/src/server/rng.ts +113 -113
- package/src/server/runtime.ts +1102 -1102
- package/src/server/schema.test-d.ts +99 -99
- package/src/server/schema.ts +663 -663
- package/src/server/sys.d.ts +125 -125
- package/src/server/view.test-d.ts +194 -194
- package/src/server/views.ts +340 -340
- package/src/solid/SpacetimeDBProvider.ts +97 -97
- package/src/solid/connection_state.ts +6 -6
- package/src/solid/index.ts +5 -5
- package/src/solid/useProcedure.ts +57 -57
- package/src/solid/useReducer.ts +50 -50
- package/src/solid/useSpacetimeDB.ts +18 -18
- package/src/solid/useTable.ts +203 -203
- package/src/svelte/SpacetimeDBProvider.ts +101 -101
- package/src/svelte/connection_state.ts +16 -16
- package/src/svelte/index.ts +4 -4
- package/src/svelte/useReducer.ts +61 -61
- package/src/svelte/useSpacetimeDB.ts +22 -22
- package/src/svelte/useTable.ts +218 -218
- package/src/tanstack/SpacetimeDBQueryClient.ts +330 -330
- package/src/tanstack/hooks.ts +83 -83
- package/src/tanstack/index.ts +16 -16
- package/src/util-stub.ts +1 -1
- package/src/vue/SpacetimeDBProvider.ts +157 -157
- package/src/vue/connection_state.ts +19 -19
- package/src/vue/index.ts +5 -5
- package/src/vue/useProcedure.ts +62 -62
- package/src/vue/useReducer.ts +55 -55
- package/src/vue/useSpacetimeDB.ts +18 -18
- package/src/vue/useTable.ts +229 -229
package/src/lib/binary_writer.ts
CHANGED
|
@@ -1,213 +1,213 @@
|
|
|
1
|
-
import { fromByteArray } from 'base64-js';
|
|
2
|
-
|
|
3
|
-
const ArrayBufferPrototypeTransfer =
|
|
4
|
-
ArrayBuffer.prototype.transfer ??
|
|
5
|
-
function (this: ArrayBuffer, newByteLength) {
|
|
6
|
-
if (newByteLength === undefined) {
|
|
7
|
-
return this.slice();
|
|
8
|
-
} else if (newByteLength <= this.byteLength) {
|
|
9
|
-
return this.slice(0, newByteLength);
|
|
10
|
-
} else {
|
|
11
|
-
const copy = new Uint8Array(newByteLength);
|
|
12
|
-
copy.set(new Uint8Array(this));
|
|
13
|
-
return copy.buffer;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export class ResizableBuffer {
|
|
18
|
-
buffer: ArrayBuffer;
|
|
19
|
-
view: DataView;
|
|
20
|
-
|
|
21
|
-
constructor(init: number | ArrayBuffer) {
|
|
22
|
-
this.buffer = typeof init === 'number' ? new ArrayBuffer(init) : init;
|
|
23
|
-
this.view = new DataView(this.buffer);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get capacity(): number {
|
|
27
|
-
return this.buffer.byteLength;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
grow(newSize: number) {
|
|
31
|
-
if (newSize <= this.buffer.byteLength) return;
|
|
32
|
-
this.buffer = ArrayBufferPrototypeTransfer.call(this.buffer, newSize);
|
|
33
|
-
this.view = new DataView(this.buffer);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default class BinaryWriter {
|
|
38
|
-
buffer: ResizableBuffer;
|
|
39
|
-
offset: number = 0;
|
|
40
|
-
|
|
41
|
-
constructor(init: number | ResizableBuffer) {
|
|
42
|
-
this.buffer = typeof init === 'number' ? new ResizableBuffer(init) : init;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
clear() {
|
|
46
|
-
this.offset = 0;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
reset(buffer: ResizableBuffer) {
|
|
50
|
-
this.buffer = buffer;
|
|
51
|
-
this.offset = 0;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
expandBuffer(additionalCapacity: number): void {
|
|
55
|
-
const minCapacity = this.offset + additionalCapacity + 1;
|
|
56
|
-
if (minCapacity <= this.buffer.capacity) return;
|
|
57
|
-
let newCapacity = this.buffer.capacity * 2;
|
|
58
|
-
if (newCapacity < minCapacity) newCapacity = minCapacity;
|
|
59
|
-
this.buffer.grow(newCapacity);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
toBase64(): string {
|
|
63
|
-
return fromByteArray(this.getBuffer());
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
getBuffer(): Uint8Array<ArrayBuffer> {
|
|
67
|
-
return new Uint8Array(this.buffer.buffer, 0, this.offset);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
get view() {
|
|
71
|
-
return this.buffer.view;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
writeUInt8Array(value: Uint8Array): void {
|
|
75
|
-
const length = value.length;
|
|
76
|
-
|
|
77
|
-
this.expandBuffer(4 + length);
|
|
78
|
-
|
|
79
|
-
this.writeU32(length);
|
|
80
|
-
new Uint8Array(this.buffer.buffer, this.offset).set(value);
|
|
81
|
-
this.offset += length;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
writeBool(value: boolean): void {
|
|
85
|
-
this.expandBuffer(1);
|
|
86
|
-
this.view.setUint8(this.offset, value ? 1 : 0);
|
|
87
|
-
this.offset += 1;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
writeByte(value: number): void {
|
|
91
|
-
this.expandBuffer(1);
|
|
92
|
-
this.view.setUint8(this.offset, value);
|
|
93
|
-
this.offset += 1;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
writeBytes(value: Uint8Array): void {
|
|
97
|
-
this.expandBuffer(value.length);
|
|
98
|
-
new Uint8Array(this.buffer.buffer, this.offset, value.length).set(value);
|
|
99
|
-
this.offset += value.length;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
writeI8(value: number): void {
|
|
103
|
-
this.expandBuffer(1);
|
|
104
|
-
this.view.setInt8(this.offset, value);
|
|
105
|
-
this.offset += 1;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
writeU8(value: number): void {
|
|
109
|
-
this.expandBuffer(1);
|
|
110
|
-
this.view.setUint8(this.offset, value);
|
|
111
|
-
this.offset += 1;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
writeI16(value: number): void {
|
|
115
|
-
this.expandBuffer(2);
|
|
116
|
-
this.view.setInt16(this.offset, value, true);
|
|
117
|
-
this.offset += 2;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
writeU16(value: number): void {
|
|
121
|
-
this.expandBuffer(2);
|
|
122
|
-
this.view.setUint16(this.offset, value, true);
|
|
123
|
-
this.offset += 2;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
writeI32(value: number): void {
|
|
127
|
-
this.expandBuffer(4);
|
|
128
|
-
this.view.setInt32(this.offset, value, true);
|
|
129
|
-
this.offset += 4;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
writeU32(value: number): void {
|
|
133
|
-
this.expandBuffer(4);
|
|
134
|
-
this.view.setUint32(this.offset, value, true);
|
|
135
|
-
this.offset += 4;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
writeI64(value: bigint): void {
|
|
139
|
-
this.expandBuffer(8);
|
|
140
|
-
this.view.setBigInt64(this.offset, value, true);
|
|
141
|
-
this.offset += 8;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
writeU64(value: bigint): void {
|
|
145
|
-
this.expandBuffer(8);
|
|
146
|
-
this.view.setBigUint64(this.offset, value, true);
|
|
147
|
-
this.offset += 8;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
writeU128(value: bigint): void {
|
|
151
|
-
this.expandBuffer(16);
|
|
152
|
-
const lowerPart = value & BigInt('0xFFFFFFFFFFFFFFFF');
|
|
153
|
-
const upperPart = value >> BigInt(64);
|
|
154
|
-
this.view.setBigUint64(this.offset, lowerPart, true);
|
|
155
|
-
this.view.setBigUint64(this.offset + 8, upperPart, true);
|
|
156
|
-
this.offset += 16;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
writeI128(value: bigint): void {
|
|
160
|
-
this.expandBuffer(16);
|
|
161
|
-
const lowerPart = value & BigInt('0xFFFFFFFFFFFFFFFF');
|
|
162
|
-
const upperPart = value >> BigInt(64);
|
|
163
|
-
this.view.setBigInt64(this.offset, lowerPart, true);
|
|
164
|
-
this.view.setBigInt64(this.offset + 8, upperPart, true);
|
|
165
|
-
this.offset += 16;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
writeU256(value: bigint): void {
|
|
169
|
-
this.expandBuffer(32);
|
|
170
|
-
const low_64_mask = BigInt('0xFFFFFFFFFFFFFFFF');
|
|
171
|
-
const p0 = value & low_64_mask;
|
|
172
|
-
const p1 = (value >> BigInt(64 * 1)) & low_64_mask;
|
|
173
|
-
const p2 = (value >> BigInt(64 * 2)) & low_64_mask;
|
|
174
|
-
const p3 = value >> BigInt(64 * 3);
|
|
175
|
-
this.view.setBigUint64(this.offset + 8 * 0, p0, true);
|
|
176
|
-
this.view.setBigUint64(this.offset + 8 * 1, p1, true);
|
|
177
|
-
this.view.setBigUint64(this.offset + 8 * 2, p2, true);
|
|
178
|
-
this.view.setBigUint64(this.offset + 8 * 3, p3, true);
|
|
179
|
-
this.offset += 32;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
writeI256(value: bigint): void {
|
|
183
|
-
this.expandBuffer(32);
|
|
184
|
-
const low_64_mask = BigInt('0xFFFFFFFFFFFFFFFF');
|
|
185
|
-
const p0 = value & low_64_mask;
|
|
186
|
-
const p1 = (value >> BigInt(64 * 1)) & low_64_mask;
|
|
187
|
-
const p2 = (value >> BigInt(64 * 2)) & low_64_mask;
|
|
188
|
-
const p3 = value >> BigInt(64 * 3);
|
|
189
|
-
this.view.setBigUint64(this.offset + 8 * 0, p0, true);
|
|
190
|
-
this.view.setBigUint64(this.offset + 8 * 1, p1, true);
|
|
191
|
-
this.view.setBigUint64(this.offset + 8 * 2, p2, true);
|
|
192
|
-
this.view.setBigInt64(this.offset + 8 * 3, p3, true);
|
|
193
|
-
this.offset += 32;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
writeF32(value: number): void {
|
|
197
|
-
this.expandBuffer(4);
|
|
198
|
-
this.view.setFloat32(this.offset, value, true);
|
|
199
|
-
this.offset += 4;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
writeF64(value: number): void {
|
|
203
|
-
this.expandBuffer(8);
|
|
204
|
-
this.view.setFloat64(this.offset, value, true);
|
|
205
|
-
this.offset += 8;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
writeString(value: string): void {
|
|
209
|
-
const encoder = new TextEncoder();
|
|
210
|
-
const encodedString = encoder.encode(value);
|
|
211
|
-
this.writeUInt8Array(encodedString);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
1
|
+
import { fromByteArray } from 'base64-js';
|
|
2
|
+
|
|
3
|
+
const ArrayBufferPrototypeTransfer =
|
|
4
|
+
ArrayBuffer.prototype.transfer ??
|
|
5
|
+
function (this: ArrayBuffer, newByteLength) {
|
|
6
|
+
if (newByteLength === undefined) {
|
|
7
|
+
return this.slice();
|
|
8
|
+
} else if (newByteLength <= this.byteLength) {
|
|
9
|
+
return this.slice(0, newByteLength);
|
|
10
|
+
} else {
|
|
11
|
+
const copy = new Uint8Array(newByteLength);
|
|
12
|
+
copy.set(new Uint8Array(this));
|
|
13
|
+
return copy.buffer;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export class ResizableBuffer {
|
|
18
|
+
buffer: ArrayBuffer;
|
|
19
|
+
view: DataView;
|
|
20
|
+
|
|
21
|
+
constructor(init: number | ArrayBuffer) {
|
|
22
|
+
this.buffer = typeof init === 'number' ? new ArrayBuffer(init) : init;
|
|
23
|
+
this.view = new DataView(this.buffer);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get capacity(): number {
|
|
27
|
+
return this.buffer.byteLength;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
grow(newSize: number) {
|
|
31
|
+
if (newSize <= this.buffer.byteLength) return;
|
|
32
|
+
this.buffer = ArrayBufferPrototypeTransfer.call(this.buffer, newSize);
|
|
33
|
+
this.view = new DataView(this.buffer);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default class BinaryWriter {
|
|
38
|
+
buffer: ResizableBuffer;
|
|
39
|
+
offset: number = 0;
|
|
40
|
+
|
|
41
|
+
constructor(init: number | ResizableBuffer) {
|
|
42
|
+
this.buffer = typeof init === 'number' ? new ResizableBuffer(init) : init;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
clear() {
|
|
46
|
+
this.offset = 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
reset(buffer: ResizableBuffer) {
|
|
50
|
+
this.buffer = buffer;
|
|
51
|
+
this.offset = 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
expandBuffer(additionalCapacity: number): void {
|
|
55
|
+
const minCapacity = this.offset + additionalCapacity + 1;
|
|
56
|
+
if (minCapacity <= this.buffer.capacity) return;
|
|
57
|
+
let newCapacity = this.buffer.capacity * 2;
|
|
58
|
+
if (newCapacity < minCapacity) newCapacity = minCapacity;
|
|
59
|
+
this.buffer.grow(newCapacity);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
toBase64(): string {
|
|
63
|
+
return fromByteArray(this.getBuffer());
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getBuffer(): Uint8Array<ArrayBuffer> {
|
|
67
|
+
return new Uint8Array(this.buffer.buffer, 0, this.offset);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get view() {
|
|
71
|
+
return this.buffer.view;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
writeUInt8Array(value: Uint8Array): void {
|
|
75
|
+
const length = value.length;
|
|
76
|
+
|
|
77
|
+
this.expandBuffer(4 + length);
|
|
78
|
+
|
|
79
|
+
this.writeU32(length);
|
|
80
|
+
new Uint8Array(this.buffer.buffer, this.offset).set(value);
|
|
81
|
+
this.offset += length;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
writeBool(value: boolean): void {
|
|
85
|
+
this.expandBuffer(1);
|
|
86
|
+
this.view.setUint8(this.offset, value ? 1 : 0);
|
|
87
|
+
this.offset += 1;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
writeByte(value: number): void {
|
|
91
|
+
this.expandBuffer(1);
|
|
92
|
+
this.view.setUint8(this.offset, value);
|
|
93
|
+
this.offset += 1;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
writeBytes(value: Uint8Array): void {
|
|
97
|
+
this.expandBuffer(value.length);
|
|
98
|
+
new Uint8Array(this.buffer.buffer, this.offset, value.length).set(value);
|
|
99
|
+
this.offset += value.length;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
writeI8(value: number): void {
|
|
103
|
+
this.expandBuffer(1);
|
|
104
|
+
this.view.setInt8(this.offset, value);
|
|
105
|
+
this.offset += 1;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
writeU8(value: number): void {
|
|
109
|
+
this.expandBuffer(1);
|
|
110
|
+
this.view.setUint8(this.offset, value);
|
|
111
|
+
this.offset += 1;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
writeI16(value: number): void {
|
|
115
|
+
this.expandBuffer(2);
|
|
116
|
+
this.view.setInt16(this.offset, value, true);
|
|
117
|
+
this.offset += 2;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
writeU16(value: number): void {
|
|
121
|
+
this.expandBuffer(2);
|
|
122
|
+
this.view.setUint16(this.offset, value, true);
|
|
123
|
+
this.offset += 2;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
writeI32(value: number): void {
|
|
127
|
+
this.expandBuffer(4);
|
|
128
|
+
this.view.setInt32(this.offset, value, true);
|
|
129
|
+
this.offset += 4;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
writeU32(value: number): void {
|
|
133
|
+
this.expandBuffer(4);
|
|
134
|
+
this.view.setUint32(this.offset, value, true);
|
|
135
|
+
this.offset += 4;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
writeI64(value: bigint): void {
|
|
139
|
+
this.expandBuffer(8);
|
|
140
|
+
this.view.setBigInt64(this.offset, value, true);
|
|
141
|
+
this.offset += 8;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
writeU64(value: bigint): void {
|
|
145
|
+
this.expandBuffer(8);
|
|
146
|
+
this.view.setBigUint64(this.offset, value, true);
|
|
147
|
+
this.offset += 8;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
writeU128(value: bigint): void {
|
|
151
|
+
this.expandBuffer(16);
|
|
152
|
+
const lowerPart = value & BigInt('0xFFFFFFFFFFFFFFFF');
|
|
153
|
+
const upperPart = value >> BigInt(64);
|
|
154
|
+
this.view.setBigUint64(this.offset, lowerPart, true);
|
|
155
|
+
this.view.setBigUint64(this.offset + 8, upperPart, true);
|
|
156
|
+
this.offset += 16;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
writeI128(value: bigint): void {
|
|
160
|
+
this.expandBuffer(16);
|
|
161
|
+
const lowerPart = value & BigInt('0xFFFFFFFFFFFFFFFF');
|
|
162
|
+
const upperPart = value >> BigInt(64);
|
|
163
|
+
this.view.setBigInt64(this.offset, lowerPart, true);
|
|
164
|
+
this.view.setBigInt64(this.offset + 8, upperPart, true);
|
|
165
|
+
this.offset += 16;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
writeU256(value: bigint): void {
|
|
169
|
+
this.expandBuffer(32);
|
|
170
|
+
const low_64_mask = BigInt('0xFFFFFFFFFFFFFFFF');
|
|
171
|
+
const p0 = value & low_64_mask;
|
|
172
|
+
const p1 = (value >> BigInt(64 * 1)) & low_64_mask;
|
|
173
|
+
const p2 = (value >> BigInt(64 * 2)) & low_64_mask;
|
|
174
|
+
const p3 = value >> BigInt(64 * 3);
|
|
175
|
+
this.view.setBigUint64(this.offset + 8 * 0, p0, true);
|
|
176
|
+
this.view.setBigUint64(this.offset + 8 * 1, p1, true);
|
|
177
|
+
this.view.setBigUint64(this.offset + 8 * 2, p2, true);
|
|
178
|
+
this.view.setBigUint64(this.offset + 8 * 3, p3, true);
|
|
179
|
+
this.offset += 32;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
writeI256(value: bigint): void {
|
|
183
|
+
this.expandBuffer(32);
|
|
184
|
+
const low_64_mask = BigInt('0xFFFFFFFFFFFFFFFF');
|
|
185
|
+
const p0 = value & low_64_mask;
|
|
186
|
+
const p1 = (value >> BigInt(64 * 1)) & low_64_mask;
|
|
187
|
+
const p2 = (value >> BigInt(64 * 2)) & low_64_mask;
|
|
188
|
+
const p3 = value >> BigInt(64 * 3);
|
|
189
|
+
this.view.setBigUint64(this.offset + 8 * 0, p0, true);
|
|
190
|
+
this.view.setBigUint64(this.offset + 8 * 1, p1, true);
|
|
191
|
+
this.view.setBigUint64(this.offset + 8 * 2, p2, true);
|
|
192
|
+
this.view.setBigInt64(this.offset + 8 * 3, p3, true);
|
|
193
|
+
this.offset += 32;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
writeF32(value: number): void {
|
|
197
|
+
this.expandBuffer(4);
|
|
198
|
+
this.view.setFloat32(this.offset, value, true);
|
|
199
|
+
this.offset += 4;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
writeF64(value: number): void {
|
|
203
|
+
this.expandBuffer(8);
|
|
204
|
+
this.view.setFloat64(this.offset, value, true);
|
|
205
|
+
this.offset += 8;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
writeString(value: string): void {
|
|
209
|
+
const encoder = new TextEncoder();
|
|
210
|
+
const encodedString = encoder.encode(value);
|
|
211
|
+
this.writeUInt8Array(encodedString);
|
|
212
|
+
}
|
|
213
|
+
}
|
package/src/lib/connection_id.ts
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { AlgebraicType } from './algebraic_type';
|
|
2
|
-
import { hexStringToU128, u128ToHexString, u128ToUint8Array } from './util';
|
|
3
|
-
|
|
4
|
-
export type ConnectionIdAlgebraicType = {
|
|
5
|
-
tag: 'Product';
|
|
6
|
-
value: {
|
|
7
|
-
elements: [{ name: '__connection_id__'; algebraicType: { tag: 'U128' } }];
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* A unique identifier for a client connected to a database.
|
|
13
|
-
*/
|
|
14
|
-
export class ConnectionId {
|
|
15
|
-
__connection_id__: bigint;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Creates a new `ConnectionId`.
|
|
19
|
-
*/
|
|
20
|
-
constructor(data: bigint) {
|
|
21
|
-
this.__connection_id__ = data;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Get the algebraic type representation of the {@link ConnectionId} type.
|
|
26
|
-
* @returns The algebraic type representation of the type.
|
|
27
|
-
*/
|
|
28
|
-
static getAlgebraicType(): ConnectionIdAlgebraicType {
|
|
29
|
-
return AlgebraicType.Product({
|
|
30
|
-
elements: [
|
|
31
|
-
{ name: '__connection_id__', algebraicType: AlgebraicType.U128 },
|
|
32
|
-
],
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
isZero(): boolean {
|
|
37
|
-
return this.__connection_id__ === BigInt(0);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static nullIfZero(addr: ConnectionId): ConnectionId | null {
|
|
41
|
-
if (addr.isZero()) {
|
|
42
|
-
return null;
|
|
43
|
-
} else {
|
|
44
|
-
return addr;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
static random(): ConnectionId {
|
|
49
|
-
function randomU8(): number {
|
|
50
|
-
return Math.floor(Math.random() * 0xff);
|
|
51
|
-
}
|
|
52
|
-
let result = BigInt(0);
|
|
53
|
-
for (let i = 0; i < 16; i++) {
|
|
54
|
-
result = (result << BigInt(8)) | BigInt(randomU8());
|
|
55
|
-
}
|
|
56
|
-
return new ConnectionId(result);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Compare two connection IDs for equality.
|
|
61
|
-
*/
|
|
62
|
-
isEqual(other: ConnectionId): boolean {
|
|
63
|
-
return this.__connection_id__ == other.__connection_id__;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Check if two connection IDs are equal.
|
|
68
|
-
*/
|
|
69
|
-
equals(other: ConnectionId): boolean {
|
|
70
|
-
return this.isEqual(other);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Print the connection ID as a hexadecimal string.
|
|
75
|
-
*/
|
|
76
|
-
toHexString(): string {
|
|
77
|
-
return u128ToHexString(this.__connection_id__);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Convert the connection ID to a Uint8Array.
|
|
82
|
-
*/
|
|
83
|
-
toUint8Array(): Uint8Array {
|
|
84
|
-
return u128ToUint8Array(this.__connection_id__);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Parse a connection ID from a hexadecimal string.
|
|
89
|
-
*/
|
|
90
|
-
static fromString(str: string): ConnectionId {
|
|
91
|
-
return new ConnectionId(hexStringToU128(str));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
static fromStringOrNull(str: string): ConnectionId | null {
|
|
95
|
-
const addr = ConnectionId.fromString(str);
|
|
96
|
-
if (addr.isZero()) {
|
|
97
|
-
return null;
|
|
98
|
-
} else {
|
|
99
|
-
return addr;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
1
|
+
import { AlgebraicType } from './algebraic_type';
|
|
2
|
+
import { hexStringToU128, u128ToHexString, u128ToUint8Array } from './util';
|
|
3
|
+
|
|
4
|
+
export type ConnectionIdAlgebraicType = {
|
|
5
|
+
tag: 'Product';
|
|
6
|
+
value: {
|
|
7
|
+
elements: [{ name: '__connection_id__'; algebraicType: { tag: 'U128' } }];
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A unique identifier for a client connected to a database.
|
|
13
|
+
*/
|
|
14
|
+
export class ConnectionId {
|
|
15
|
+
__connection_id__: bigint;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new `ConnectionId`.
|
|
19
|
+
*/
|
|
20
|
+
constructor(data: bigint) {
|
|
21
|
+
this.__connection_id__ = data;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get the algebraic type representation of the {@link ConnectionId} type.
|
|
26
|
+
* @returns The algebraic type representation of the type.
|
|
27
|
+
*/
|
|
28
|
+
static getAlgebraicType(): ConnectionIdAlgebraicType {
|
|
29
|
+
return AlgebraicType.Product({
|
|
30
|
+
elements: [
|
|
31
|
+
{ name: '__connection_id__', algebraicType: AlgebraicType.U128 },
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
isZero(): boolean {
|
|
37
|
+
return this.__connection_id__ === BigInt(0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static nullIfZero(addr: ConnectionId): ConnectionId | null {
|
|
41
|
+
if (addr.isZero()) {
|
|
42
|
+
return null;
|
|
43
|
+
} else {
|
|
44
|
+
return addr;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static random(): ConnectionId {
|
|
49
|
+
function randomU8(): number {
|
|
50
|
+
return Math.floor(Math.random() * 0xff);
|
|
51
|
+
}
|
|
52
|
+
let result = BigInt(0);
|
|
53
|
+
for (let i = 0; i < 16; i++) {
|
|
54
|
+
result = (result << BigInt(8)) | BigInt(randomU8());
|
|
55
|
+
}
|
|
56
|
+
return new ConnectionId(result);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Compare two connection IDs for equality.
|
|
61
|
+
*/
|
|
62
|
+
isEqual(other: ConnectionId): boolean {
|
|
63
|
+
return this.__connection_id__ == other.__connection_id__;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Check if two connection IDs are equal.
|
|
68
|
+
*/
|
|
69
|
+
equals(other: ConnectionId): boolean {
|
|
70
|
+
return this.isEqual(other);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Print the connection ID as a hexadecimal string.
|
|
75
|
+
*/
|
|
76
|
+
toHexString(): string {
|
|
77
|
+
return u128ToHexString(this.__connection_id__);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Convert the connection ID to a Uint8Array.
|
|
82
|
+
*/
|
|
83
|
+
toUint8Array(): Uint8Array {
|
|
84
|
+
return u128ToUint8Array(this.__connection_id__);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Parse a connection ID from a hexadecimal string.
|
|
89
|
+
*/
|
|
90
|
+
static fromString(str: string): ConnectionId {
|
|
91
|
+
return new ConnectionId(hexStringToU128(str));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static fromStringOrNull(str: string): ConnectionId | null {
|
|
95
|
+
const addr = ConnectionId.fromString(str);
|
|
96
|
+
if (addr.isZero()) {
|
|
97
|
+
return null;
|
|
98
|
+
} else {
|
|
99
|
+
return addr;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|