@interncom/diplomatic 0.1.0 → 0.1.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/client.d.ts +5 -4
- package/dist/entdb/entdb.d.ts +10 -4
- package/dist/entdb/idb.d.ts +1 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.mjs +1328 -1450
- package/dist/react/useClient.d.ts +14 -3
- package/dist/shared/bag.d.ts +1 -2
- package/dist/shared/endpoint.d.ts +1 -1
- package/dist/shared/http.d.ts +2 -1
- package/dist/shared/sync.d.ts +9 -0
- package/dist/shared/types.d.ts +1 -1
- package/dist/stores/idb/store.d.ts +2 -1
- package/dist/sync.d.ts +1 -8
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -34,9 +34,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
34
34
|
mod
|
|
35
35
|
));
|
|
36
36
|
|
|
37
|
-
// node_modules/file-saver/dist/FileSaver.min.js
|
|
37
|
+
// ../node_modules/.bun/file-saver@2.0.5/node_modules/file-saver/dist/FileSaver.min.js
|
|
38
38
|
var require_FileSaver_min = __commonJS({
|
|
39
|
-
"node_modules/file-saver/dist/FileSaver.min.js"(exports2, module) {
|
|
39
|
+
"../node_modules/.bun/file-saver@2.0.5/node_modules/file-saver/dist/FileSaver.min.js"(exports2, module) {
|
|
40
40
|
"use strict";
|
|
41
41
|
(function(a, b) {
|
|
42
42
|
if ("function" == typeof define && define.amd) define([], b);
|
|
@@ -112,13 +112,13 @@ var require_FileSaver_min = __commonJS({
|
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
-
// node_modules/@msgpack/msgpack/dist.
|
|
115
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/utils/utf8.mjs
|
|
116
116
|
function utf8Count(str) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
const strLength = str.length;
|
|
118
|
+
let byteLength = 0;
|
|
119
|
+
let pos = 0;
|
|
120
120
|
while (pos < strLength) {
|
|
121
|
-
|
|
121
|
+
let value = str.charCodeAt(pos++);
|
|
122
122
|
if ((value & 4294967168) === 0) {
|
|
123
123
|
byteLength++;
|
|
124
124
|
continue;
|
|
@@ -127,7 +127,7 @@ function utf8Count(str) {
|
|
|
127
127
|
} else {
|
|
128
128
|
if (value >= 55296 && value <= 56319) {
|
|
129
129
|
if (pos < strLength) {
|
|
130
|
-
|
|
130
|
+
const extra = str.charCodeAt(pos);
|
|
131
131
|
if ((extra & 64512) === 56320) {
|
|
132
132
|
++pos;
|
|
133
133
|
value = ((value & 1023) << 10) + (extra & 1023) + 65536;
|
|
@@ -144,11 +144,11 @@ function utf8Count(str) {
|
|
|
144
144
|
return byteLength;
|
|
145
145
|
}
|
|
146
146
|
function utf8EncodeJs(str, output, outputOffset) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
const strLength = str.length;
|
|
148
|
+
let offset2 = outputOffset;
|
|
149
|
+
let pos = 0;
|
|
150
150
|
while (pos < strLength) {
|
|
151
|
-
|
|
151
|
+
let value = str.charCodeAt(pos++);
|
|
152
152
|
if ((value & 4294967168) === 0) {
|
|
153
153
|
output[offset2++] = value;
|
|
154
154
|
continue;
|
|
@@ -157,7 +157,7 @@ function utf8EncodeJs(str, output, outputOffset) {
|
|
|
157
157
|
} else {
|
|
158
158
|
if (value >= 55296 && value <= 56319) {
|
|
159
159
|
if (pos < strLength) {
|
|
160
|
-
|
|
160
|
+
const extra = str.charCodeAt(pos);
|
|
161
161
|
if ((extra & 64512) === 56320) {
|
|
162
162
|
++pos;
|
|
163
163
|
value = ((value & 1023) << 10) + (extra & 1023) + 65536;
|
|
@@ -190,26 +190,26 @@ function utf8Encode(str, output, outputOffset) {
|
|
|
190
190
|
}
|
|
191
191
|
var CHUNK_SIZE = 4096;
|
|
192
192
|
function utf8DecodeJs(bytes, inputOffset, byteLength) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
193
|
+
let offset2 = inputOffset;
|
|
194
|
+
const end = offset2 + byteLength;
|
|
195
|
+
const units = [];
|
|
196
|
+
let result = "";
|
|
197
197
|
while (offset2 < end) {
|
|
198
|
-
|
|
198
|
+
const byte1 = bytes[offset2++];
|
|
199
199
|
if ((byte1 & 128) === 0) {
|
|
200
200
|
units.push(byte1);
|
|
201
201
|
} else if ((byte1 & 224) === 192) {
|
|
202
|
-
|
|
202
|
+
const byte2 = bytes[offset2++] & 63;
|
|
203
203
|
units.push((byte1 & 31) << 6 | byte2);
|
|
204
204
|
} else if ((byte1 & 240) === 224) {
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
const byte2 = bytes[offset2++] & 63;
|
|
206
|
+
const byte3 = bytes[offset2++] & 63;
|
|
207
207
|
units.push((byte1 & 31) << 12 | byte2 << 6 | byte3);
|
|
208
208
|
} else if ((byte1 & 248) === 240) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
const byte2 = bytes[offset2++] & 63;
|
|
210
|
+
const byte3 = bytes[offset2++] & 63;
|
|
211
|
+
const byte4 = bytes[offset2++] & 63;
|
|
212
|
+
let unit = (byte1 & 7) << 18 | byte2 << 12 | byte3 << 6 | byte4;
|
|
213
213
|
if (unit > 65535) {
|
|
214
214
|
unit -= 65536;
|
|
215
215
|
units.push(unit >>> 10 & 1023 | 55296);
|
|
@@ -220,19 +220,19 @@ function utf8DecodeJs(bytes, inputOffset, byteLength) {
|
|
|
220
220
|
units.push(byte1);
|
|
221
221
|
}
|
|
222
222
|
if (units.length >= CHUNK_SIZE) {
|
|
223
|
-
result += String.fromCharCode
|
|
223
|
+
result += String.fromCharCode(...units);
|
|
224
224
|
units.length = 0;
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
if (units.length > 0) {
|
|
228
|
-
result += String.fromCharCode
|
|
228
|
+
result += String.fromCharCode(...units);
|
|
229
229
|
}
|
|
230
230
|
return result;
|
|
231
231
|
}
|
|
232
232
|
var sharedTextDecoder = new TextDecoder();
|
|
233
233
|
var TEXT_DECODER_THRESHOLD = 200;
|
|
234
234
|
function utf8DecodeTD(bytes, inputOffset, byteLength) {
|
|
235
|
-
|
|
235
|
+
const stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength);
|
|
236
236
|
return sharedTextDecoder.decode(stringBytes);
|
|
237
237
|
}
|
|
238
238
|
function utf8Decode(bytes, inputOffset, byteLength) {
|
|
@@ -243,116 +243,88 @@ function utf8Decode(bytes, inputOffset, byteLength) {
|
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
-
// node_modules/@msgpack/msgpack/dist.
|
|
247
|
-
var ExtData =
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}()
|
|
256
|
-
);
|
|
246
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/ExtData.mjs
|
|
247
|
+
var ExtData = class {
|
|
248
|
+
type;
|
|
249
|
+
data;
|
|
250
|
+
constructor(type, data) {
|
|
251
|
+
this.type = type;
|
|
252
|
+
this.data = data;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
257
255
|
|
|
258
|
-
// node_modules/@msgpack/msgpack/dist.
|
|
259
|
-
var
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
extendStatics(d, b);
|
|
272
|
-
function __() {
|
|
273
|
-
this.constructor = d;
|
|
274
|
-
}
|
|
275
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
276
|
-
};
|
|
277
|
-
}();
|
|
278
|
-
var DecodeError = (
|
|
279
|
-
/** @class */
|
|
280
|
-
function(_super) {
|
|
281
|
-
__extends(DecodeError2, _super);
|
|
282
|
-
function DecodeError2(message) {
|
|
283
|
-
var _this = _super.call(this, message) || this;
|
|
284
|
-
var proto = Object.create(DecodeError2.prototype);
|
|
285
|
-
Object.setPrototypeOf(_this, proto);
|
|
286
|
-
Object.defineProperty(_this, "name", {
|
|
287
|
-
configurable: true,
|
|
288
|
-
enumerable: false,
|
|
289
|
-
value: DecodeError2.name
|
|
290
|
-
});
|
|
291
|
-
return _this;
|
|
292
|
-
}
|
|
293
|
-
return DecodeError2;
|
|
294
|
-
}(Error)
|
|
295
|
-
);
|
|
256
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/DecodeError.mjs
|
|
257
|
+
var DecodeError = class _DecodeError extends Error {
|
|
258
|
+
constructor(message) {
|
|
259
|
+
super(message);
|
|
260
|
+
const proto = Object.create(_DecodeError.prototype);
|
|
261
|
+
Object.setPrototypeOf(this, proto);
|
|
262
|
+
Object.defineProperty(this, "name", {
|
|
263
|
+
configurable: true,
|
|
264
|
+
enumerable: false,
|
|
265
|
+
value: _DecodeError.name
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
};
|
|
296
269
|
|
|
297
|
-
// node_modules/@msgpack/msgpack/dist.
|
|
270
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/utils/int.mjs
|
|
298
271
|
var UINT32_MAX = 4294967295;
|
|
299
272
|
function setUint64(view, offset2, value) {
|
|
300
|
-
|
|
301
|
-
|
|
273
|
+
const high = value / 4294967296;
|
|
274
|
+
const low = value;
|
|
302
275
|
view.setUint32(offset2, high);
|
|
303
276
|
view.setUint32(offset2 + 4, low);
|
|
304
277
|
}
|
|
305
278
|
function setInt64(view, offset2, value) {
|
|
306
|
-
|
|
307
|
-
|
|
279
|
+
const high = Math.floor(value / 4294967296);
|
|
280
|
+
const low = value;
|
|
308
281
|
view.setUint32(offset2, high);
|
|
309
282
|
view.setUint32(offset2 + 4, low);
|
|
310
283
|
}
|
|
311
284
|
function getInt64(view, offset2) {
|
|
312
|
-
|
|
313
|
-
|
|
285
|
+
const high = view.getInt32(offset2);
|
|
286
|
+
const low = view.getUint32(offset2 + 4);
|
|
314
287
|
return high * 4294967296 + low;
|
|
315
288
|
}
|
|
316
289
|
function getUint64(view, offset2) {
|
|
317
|
-
|
|
318
|
-
|
|
290
|
+
const high = view.getUint32(offset2);
|
|
291
|
+
const low = view.getUint32(offset2 + 4);
|
|
319
292
|
return high * 4294967296 + low;
|
|
320
293
|
}
|
|
321
294
|
|
|
322
|
-
// node_modules/@msgpack/msgpack/dist.
|
|
295
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/timestamp.mjs
|
|
323
296
|
var EXT_TIMESTAMP = -1;
|
|
324
297
|
var TIMESTAMP32_MAX_SEC = 4294967296 - 1;
|
|
325
298
|
var TIMESTAMP64_MAX_SEC = 17179869184 - 1;
|
|
326
|
-
function encodeTimeSpecToTimestamp(
|
|
327
|
-
var sec = _a.sec, nsec = _a.nsec;
|
|
299
|
+
function encodeTimeSpecToTimestamp({ sec, nsec }) {
|
|
328
300
|
if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) {
|
|
329
301
|
if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) {
|
|
330
|
-
|
|
331
|
-
|
|
302
|
+
const rv = new Uint8Array(4);
|
|
303
|
+
const view = new DataView(rv.buffer);
|
|
332
304
|
view.setUint32(0, sec);
|
|
333
305
|
return rv;
|
|
334
306
|
} else {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
307
|
+
const secHigh = sec / 4294967296;
|
|
308
|
+
const secLow = sec & 4294967295;
|
|
309
|
+
const rv = new Uint8Array(8);
|
|
310
|
+
const view = new DataView(rv.buffer);
|
|
339
311
|
view.setUint32(0, nsec << 2 | secHigh & 3);
|
|
340
312
|
view.setUint32(4, secLow);
|
|
341
313
|
return rv;
|
|
342
314
|
}
|
|
343
315
|
} else {
|
|
344
|
-
|
|
345
|
-
|
|
316
|
+
const rv = new Uint8Array(12);
|
|
317
|
+
const view = new DataView(rv.buffer);
|
|
346
318
|
view.setUint32(0, nsec);
|
|
347
319
|
setInt64(view, 4, sec);
|
|
348
320
|
return rv;
|
|
349
321
|
}
|
|
350
322
|
}
|
|
351
323
|
function encodeDateToTimeSpec(date) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
324
|
+
const msec = date.getTime();
|
|
325
|
+
const sec = Math.floor(msec / 1e3);
|
|
326
|
+
const nsec = (msec - sec * 1e3) * 1e6;
|
|
327
|
+
const nsecInSec = Math.floor(nsec / 1e9);
|
|
356
328
|
return {
|
|
357
329
|
sec: sec + nsecInSec,
|
|
358
330
|
nsec: nsec - nsecInSec * 1e9
|
|
@@ -360,38 +332,38 @@ function encodeDateToTimeSpec(date) {
|
|
|
360
332
|
}
|
|
361
333
|
function encodeTimestampExtension(object) {
|
|
362
334
|
if (object instanceof Date) {
|
|
363
|
-
|
|
335
|
+
const timeSpec = encodeDateToTimeSpec(object);
|
|
364
336
|
return encodeTimeSpecToTimestamp(timeSpec);
|
|
365
337
|
} else {
|
|
366
338
|
return null;
|
|
367
339
|
}
|
|
368
340
|
}
|
|
369
341
|
function decodeTimestampToTimeSpec(data) {
|
|
370
|
-
|
|
342
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
371
343
|
switch (data.byteLength) {
|
|
372
344
|
case 4: {
|
|
373
|
-
|
|
374
|
-
|
|
345
|
+
const sec = view.getUint32(0);
|
|
346
|
+
const nsec = 0;
|
|
375
347
|
return { sec, nsec };
|
|
376
348
|
}
|
|
377
349
|
case 8: {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
350
|
+
const nsec30AndSecHigh2 = view.getUint32(0);
|
|
351
|
+
const secLow32 = view.getUint32(4);
|
|
352
|
+
const sec = (nsec30AndSecHigh2 & 3) * 4294967296 + secLow32;
|
|
353
|
+
const nsec = nsec30AndSecHigh2 >>> 2;
|
|
382
354
|
return { sec, nsec };
|
|
383
355
|
}
|
|
384
356
|
case 12: {
|
|
385
|
-
|
|
386
|
-
|
|
357
|
+
const sec = getInt64(view, 4);
|
|
358
|
+
const nsec = view.getUint32(0);
|
|
387
359
|
return { sec, nsec };
|
|
388
360
|
}
|
|
389
361
|
default:
|
|
390
|
-
throw new DecodeError(
|
|
362
|
+
throw new DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${data.length}`);
|
|
391
363
|
}
|
|
392
364
|
}
|
|
393
365
|
function decodeTimestampExtension(data) {
|
|
394
|
-
|
|
366
|
+
const timeSpec = decodeTimestampToTimeSpec(data);
|
|
395
367
|
return new Date(timeSpec.sec * 1e3 + timeSpec.nsec / 1e6);
|
|
396
368
|
}
|
|
397
369
|
var timestampExtension = {
|
|
@@ -400,667 +372,629 @@ var timestampExtension = {
|
|
|
400
372
|
decode: decodeTimestampExtension
|
|
401
373
|
};
|
|
402
374
|
|
|
403
|
-
// node_modules/@msgpack/msgpack/dist.
|
|
404
|
-
var ExtensionCodec =
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
375
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/ExtensionCodec.mjs
|
|
376
|
+
var ExtensionCodec = class _ExtensionCodec {
|
|
377
|
+
static defaultCodec = new _ExtensionCodec();
|
|
378
|
+
// ensures ExtensionCodecType<X> matches ExtensionCodec<X>
|
|
379
|
+
// this will make type errors a lot more clear
|
|
380
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
381
|
+
__brand;
|
|
382
|
+
// built-in extensions
|
|
383
|
+
builtInEncoders = [];
|
|
384
|
+
builtInDecoders = [];
|
|
385
|
+
// custom extensions
|
|
386
|
+
encoders = [];
|
|
387
|
+
decoders = [];
|
|
388
|
+
constructor() {
|
|
389
|
+
this.register(timestampExtension);
|
|
390
|
+
}
|
|
391
|
+
register({ type, encode: encode2, decode: decode2 }) {
|
|
392
|
+
if (type >= 0) {
|
|
393
|
+
this.encoders[type] = encode2;
|
|
394
|
+
this.decoders[type] = decode2;
|
|
395
|
+
} else {
|
|
396
|
+
const index = -1 - type;
|
|
397
|
+
this.builtInEncoders[index] = encode2;
|
|
398
|
+
this.builtInDecoders[index] = decode2;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
tryToEncode(object, context) {
|
|
402
|
+
for (let i = 0; i < this.builtInEncoders.length; i++) {
|
|
403
|
+
const encodeExt = this.builtInEncoders[i];
|
|
404
|
+
if (encodeExt != null) {
|
|
405
|
+
const data = encodeExt(object, context);
|
|
406
|
+
if (data != null) {
|
|
407
|
+
const type = -1 - i;
|
|
408
|
+
return new ExtData(type, data);
|
|
434
409
|
}
|
|
435
410
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
411
|
+
}
|
|
412
|
+
for (let i = 0; i < this.encoders.length; i++) {
|
|
413
|
+
const encodeExt = this.encoders[i];
|
|
414
|
+
if (encodeExt != null) {
|
|
415
|
+
const data = encodeExt(object, context);
|
|
416
|
+
if (data != null) {
|
|
417
|
+
const type = i;
|
|
418
|
+
return new ExtData(type, data);
|
|
444
419
|
}
|
|
445
420
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
}()
|
|
462
|
-
);
|
|
421
|
+
}
|
|
422
|
+
if (object instanceof ExtData) {
|
|
423
|
+
return object;
|
|
424
|
+
}
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
decode(data, type, context) {
|
|
428
|
+
const decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type];
|
|
429
|
+
if (decodeExt) {
|
|
430
|
+
return decodeExt(data, type, context);
|
|
431
|
+
} else {
|
|
432
|
+
return new ExtData(type, data);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
};
|
|
463
436
|
|
|
464
|
-
// node_modules/@msgpack/msgpack/dist.
|
|
437
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/utils/typedArrays.mjs
|
|
438
|
+
function isArrayBufferLike(buffer) {
|
|
439
|
+
return buffer instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && buffer instanceof SharedArrayBuffer;
|
|
440
|
+
}
|
|
465
441
|
function ensureUint8Array(buffer) {
|
|
466
442
|
if (buffer instanceof Uint8Array) {
|
|
467
443
|
return buffer;
|
|
468
444
|
} else if (ArrayBuffer.isView(buffer)) {
|
|
469
445
|
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
470
|
-
} else if (buffer
|
|
446
|
+
} else if (isArrayBufferLike(buffer)) {
|
|
471
447
|
return new Uint8Array(buffer);
|
|
472
448
|
} else {
|
|
473
449
|
return Uint8Array.from(buffer);
|
|
474
450
|
}
|
|
475
451
|
}
|
|
476
|
-
function createDataView(buffer) {
|
|
477
|
-
if (buffer instanceof ArrayBuffer) {
|
|
478
|
-
return new DataView(buffer);
|
|
479
|
-
}
|
|
480
|
-
var bufferView = ensureUint8Array(buffer);
|
|
481
|
-
return new DataView(bufferView.buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
482
|
-
}
|
|
483
452
|
|
|
484
|
-
// node_modules/@msgpack/msgpack/dist.
|
|
453
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/Encoder.mjs
|
|
485
454
|
var DEFAULT_MAX_DEPTH = 100;
|
|
486
455
|
var DEFAULT_INITIAL_BUFFER_SIZE = 2048;
|
|
487
|
-
var Encoder =
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
456
|
+
var Encoder = class _Encoder {
|
|
457
|
+
extensionCodec;
|
|
458
|
+
context;
|
|
459
|
+
useBigInt64;
|
|
460
|
+
maxDepth;
|
|
461
|
+
initialBufferSize;
|
|
462
|
+
sortKeys;
|
|
463
|
+
forceFloat32;
|
|
464
|
+
ignoreUndefined;
|
|
465
|
+
forceIntegerToFloat;
|
|
466
|
+
pos;
|
|
467
|
+
view;
|
|
468
|
+
bytes;
|
|
469
|
+
entered = false;
|
|
470
|
+
constructor(options) {
|
|
471
|
+
this.extensionCodec = options?.extensionCodec ?? ExtensionCodec.defaultCodec;
|
|
472
|
+
this.context = options?.context;
|
|
473
|
+
this.useBigInt64 = options?.useBigInt64 ?? false;
|
|
474
|
+
this.maxDepth = options?.maxDepth ?? DEFAULT_MAX_DEPTH;
|
|
475
|
+
this.initialBufferSize = options?.initialBufferSize ?? DEFAULT_INITIAL_BUFFER_SIZE;
|
|
476
|
+
this.sortKeys = options?.sortKeys ?? false;
|
|
477
|
+
this.forceFloat32 = options?.forceFloat32 ?? false;
|
|
478
|
+
this.ignoreUndefined = options?.ignoreUndefined ?? false;
|
|
479
|
+
this.forceIntegerToFloat = options?.forceIntegerToFloat ?? false;
|
|
480
|
+
this.pos = 0;
|
|
481
|
+
this.view = new DataView(new ArrayBuffer(this.initialBufferSize));
|
|
482
|
+
this.bytes = new Uint8Array(this.view.buffer);
|
|
483
|
+
}
|
|
484
|
+
clone() {
|
|
485
|
+
return new _Encoder({
|
|
486
|
+
extensionCodec: this.extensionCodec,
|
|
487
|
+
context: this.context,
|
|
488
|
+
useBigInt64: this.useBigInt64,
|
|
489
|
+
maxDepth: this.maxDepth,
|
|
490
|
+
initialBufferSize: this.initialBufferSize,
|
|
491
|
+
sortKeys: this.sortKeys,
|
|
492
|
+
forceFloat32: this.forceFloat32,
|
|
493
|
+
ignoreUndefined: this.ignoreUndefined,
|
|
494
|
+
forceIntegerToFloat: this.forceIntegerToFloat
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
reinitializeState() {
|
|
498
|
+
this.pos = 0;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}.
|
|
502
|
+
*
|
|
503
|
+
* @returns Encodes the object and returns a shared reference the encoder's internal buffer.
|
|
504
|
+
*/
|
|
505
|
+
encodeSharedRef(object) {
|
|
506
|
+
if (this.entered) {
|
|
507
|
+
const instance = this.clone();
|
|
508
|
+
return instance.encodeSharedRef(object);
|
|
509
|
+
}
|
|
510
|
+
try {
|
|
511
|
+
this.entered = true;
|
|
509
512
|
this.reinitializeState();
|
|
510
513
|
this.doEncode(object, 1);
|
|
511
514
|
return this.bytes.subarray(0, this.pos);
|
|
512
|
-
}
|
|
513
|
-
|
|
515
|
+
} finally {
|
|
516
|
+
this.entered = false;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* @returns Encodes the object and returns a copy of the encoder's internal buffer.
|
|
521
|
+
*/
|
|
522
|
+
encode(object) {
|
|
523
|
+
if (this.entered) {
|
|
524
|
+
const instance = this.clone();
|
|
525
|
+
return instance.encode(object);
|
|
526
|
+
}
|
|
527
|
+
try {
|
|
528
|
+
this.entered = true;
|
|
514
529
|
this.reinitializeState();
|
|
515
530
|
this.doEncode(object, 1);
|
|
516
531
|
return this.bytes.slice(0, this.pos);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
532
|
+
} finally {
|
|
533
|
+
this.entered = false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
doEncode(object, depth) {
|
|
537
|
+
if (depth > this.maxDepth) {
|
|
538
|
+
throw new Error(`Too deep objects in depth ${depth}`);
|
|
539
|
+
}
|
|
540
|
+
if (object == null) {
|
|
541
|
+
this.encodeNil();
|
|
542
|
+
} else if (typeof object === "boolean") {
|
|
543
|
+
this.encodeBoolean(object);
|
|
544
|
+
} else if (typeof object === "number") {
|
|
545
|
+
if (!this.forceIntegerToFloat) {
|
|
546
|
+
this.encodeNumber(object);
|
|
547
|
+
} else {
|
|
548
|
+
this.encodeNumberAsFloat(object);
|
|
521
549
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
550
|
+
} else if (typeof object === "string") {
|
|
551
|
+
this.encodeString(object);
|
|
552
|
+
} else if (this.useBigInt64 && typeof object === "bigint") {
|
|
553
|
+
this.encodeBigInt64(object);
|
|
554
|
+
} else {
|
|
555
|
+
this.encodeObject(object, depth);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
ensureBufferSizeToWrite(sizeToWrite) {
|
|
559
|
+
const requiredSize = this.pos + sizeToWrite;
|
|
560
|
+
if (this.view.byteLength < requiredSize) {
|
|
561
|
+
this.resizeBuffer(requiredSize * 2);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
resizeBuffer(newSize) {
|
|
565
|
+
const newBuffer = new ArrayBuffer(newSize);
|
|
566
|
+
const newBytes = new Uint8Array(newBuffer);
|
|
567
|
+
const newView = new DataView(newBuffer);
|
|
568
|
+
newBytes.set(this.bytes);
|
|
569
|
+
this.view = newView;
|
|
570
|
+
this.bytes = newBytes;
|
|
571
|
+
}
|
|
572
|
+
encodeNil() {
|
|
573
|
+
this.writeU8(192);
|
|
574
|
+
}
|
|
575
|
+
encodeBoolean(object) {
|
|
576
|
+
if (object === false) {
|
|
577
|
+
this.writeU8(194);
|
|
578
|
+
} else {
|
|
579
|
+
this.writeU8(195);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
encodeNumber(object) {
|
|
583
|
+
if (!this.forceIntegerToFloat && Number.isSafeInteger(object)) {
|
|
584
|
+
if (object >= 0) {
|
|
585
|
+
if (object < 128) {
|
|
586
|
+
this.writeU8(object);
|
|
587
|
+
} else if (object < 256) {
|
|
588
|
+
this.writeU8(204);
|
|
589
|
+
this.writeU8(object);
|
|
590
|
+
} else if (object < 65536) {
|
|
591
|
+
this.writeU8(205);
|
|
592
|
+
this.writeU16(object);
|
|
593
|
+
} else if (object < 4294967296) {
|
|
594
|
+
this.writeU8(206);
|
|
595
|
+
this.writeU32(object);
|
|
596
|
+
} else if (!this.useBigInt64) {
|
|
597
|
+
this.writeU8(207);
|
|
598
|
+
this.writeU64(object);
|
|
529
599
|
} else {
|
|
530
600
|
this.encodeNumberAsFloat(object);
|
|
531
601
|
}
|
|
532
|
-
} else if (typeof object === "string") {
|
|
533
|
-
this.encodeString(object);
|
|
534
|
-
} else if (this.useBigInt64 && typeof object === "bigint") {
|
|
535
|
-
this.encodeBigInt64(object);
|
|
536
|
-
} else {
|
|
537
|
-
this.encodeObject(object, depth);
|
|
538
|
-
}
|
|
539
|
-
};
|
|
540
|
-
Encoder3.prototype.ensureBufferSizeToWrite = function(sizeToWrite) {
|
|
541
|
-
var requiredSize = this.pos + sizeToWrite;
|
|
542
|
-
if (this.view.byteLength < requiredSize) {
|
|
543
|
-
this.resizeBuffer(requiredSize * 2);
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
Encoder3.prototype.resizeBuffer = function(newSize) {
|
|
547
|
-
var newBuffer = new ArrayBuffer(newSize);
|
|
548
|
-
var newBytes = new Uint8Array(newBuffer);
|
|
549
|
-
var newView = new DataView(newBuffer);
|
|
550
|
-
newBytes.set(this.bytes);
|
|
551
|
-
this.view = newView;
|
|
552
|
-
this.bytes = newBytes;
|
|
553
|
-
};
|
|
554
|
-
Encoder3.prototype.encodeNil = function() {
|
|
555
|
-
this.writeU8(192);
|
|
556
|
-
};
|
|
557
|
-
Encoder3.prototype.encodeBoolean = function(object) {
|
|
558
|
-
if (object === false) {
|
|
559
|
-
this.writeU8(194);
|
|
560
602
|
} else {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
if (object >=
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
} else if (object < 4294967296) {
|
|
576
|
-
this.writeU8(206);
|
|
577
|
-
this.writeU32(object);
|
|
578
|
-
} else if (!this.useBigInt64) {
|
|
579
|
-
this.writeU8(207);
|
|
580
|
-
this.writeU64(object);
|
|
581
|
-
} else {
|
|
582
|
-
this.encodeNumberAsFloat(object);
|
|
583
|
-
}
|
|
603
|
+
if (object >= -32) {
|
|
604
|
+
this.writeU8(224 | object + 32);
|
|
605
|
+
} else if (object >= -128) {
|
|
606
|
+
this.writeU8(208);
|
|
607
|
+
this.writeI8(object);
|
|
608
|
+
} else if (object >= -32768) {
|
|
609
|
+
this.writeU8(209);
|
|
610
|
+
this.writeI16(object);
|
|
611
|
+
} else if (object >= -2147483648) {
|
|
612
|
+
this.writeU8(210);
|
|
613
|
+
this.writeI32(object);
|
|
614
|
+
} else if (!this.useBigInt64) {
|
|
615
|
+
this.writeU8(211);
|
|
616
|
+
this.writeI64(object);
|
|
584
617
|
} else {
|
|
585
|
-
|
|
586
|
-
this.writeU8(224 | object + 32);
|
|
587
|
-
} else if (object >= -128) {
|
|
588
|
-
this.writeU8(208);
|
|
589
|
-
this.writeI8(object);
|
|
590
|
-
} else if (object >= -32768) {
|
|
591
|
-
this.writeU8(209);
|
|
592
|
-
this.writeI16(object);
|
|
593
|
-
} else if (object >= -2147483648) {
|
|
594
|
-
this.writeU8(210);
|
|
595
|
-
this.writeI32(object);
|
|
596
|
-
} else if (!this.useBigInt64) {
|
|
597
|
-
this.writeU8(211);
|
|
598
|
-
this.writeI64(object);
|
|
599
|
-
} else {
|
|
600
|
-
this.encodeNumberAsFloat(object);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
} else {
|
|
604
|
-
this.encodeNumberAsFloat(object);
|
|
605
|
-
}
|
|
606
|
-
};
|
|
607
|
-
Encoder3.prototype.encodeNumberAsFloat = function(object) {
|
|
608
|
-
if (this.forceFloat32) {
|
|
609
|
-
this.writeU8(202);
|
|
610
|
-
this.writeF32(object);
|
|
611
|
-
} else {
|
|
612
|
-
this.writeU8(203);
|
|
613
|
-
this.writeF64(object);
|
|
614
|
-
}
|
|
615
|
-
};
|
|
616
|
-
Encoder3.prototype.encodeBigInt64 = function(object) {
|
|
617
|
-
if (object >= BigInt(0)) {
|
|
618
|
-
this.writeU8(207);
|
|
619
|
-
this.writeBigUint64(object);
|
|
620
|
-
} else {
|
|
621
|
-
this.writeU8(211);
|
|
622
|
-
this.writeBigInt64(object);
|
|
623
|
-
}
|
|
624
|
-
};
|
|
625
|
-
Encoder3.prototype.writeStringHeader = function(byteLength) {
|
|
626
|
-
if (byteLength < 32) {
|
|
627
|
-
this.writeU8(160 + byteLength);
|
|
628
|
-
} else if (byteLength < 256) {
|
|
629
|
-
this.writeU8(217);
|
|
630
|
-
this.writeU8(byteLength);
|
|
631
|
-
} else if (byteLength < 65536) {
|
|
632
|
-
this.writeU8(218);
|
|
633
|
-
this.writeU16(byteLength);
|
|
634
|
-
} else if (byteLength < 4294967296) {
|
|
635
|
-
this.writeU8(219);
|
|
636
|
-
this.writeU32(byteLength);
|
|
637
|
-
} else {
|
|
638
|
-
throw new Error("Too long string: ".concat(byteLength, " bytes in UTF-8"));
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
Encoder3.prototype.encodeString = function(object) {
|
|
642
|
-
var maxHeaderSize = 1 + 4;
|
|
643
|
-
var byteLength = utf8Count(object);
|
|
644
|
-
this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
|
|
645
|
-
this.writeStringHeader(byteLength);
|
|
646
|
-
utf8Encode(object, this.bytes, this.pos);
|
|
647
|
-
this.pos += byteLength;
|
|
648
|
-
};
|
|
649
|
-
Encoder3.prototype.encodeObject = function(object, depth) {
|
|
650
|
-
var ext = this.extensionCodec.tryToEncode(object, this.context);
|
|
651
|
-
if (ext != null) {
|
|
652
|
-
this.encodeExtension(ext);
|
|
653
|
-
} else if (Array.isArray(object)) {
|
|
654
|
-
this.encodeArray(object, depth);
|
|
655
|
-
} else if (ArrayBuffer.isView(object)) {
|
|
656
|
-
this.encodeBinary(object);
|
|
657
|
-
} else if (typeof object === "object") {
|
|
658
|
-
this.encodeMap(object, depth);
|
|
659
|
-
} else {
|
|
660
|
-
throw new Error("Unrecognized object: ".concat(Object.prototype.toString.apply(object)));
|
|
661
|
-
}
|
|
662
|
-
};
|
|
663
|
-
Encoder3.prototype.encodeBinary = function(object) {
|
|
664
|
-
var size = object.byteLength;
|
|
665
|
-
if (size < 256) {
|
|
666
|
-
this.writeU8(196);
|
|
667
|
-
this.writeU8(size);
|
|
668
|
-
} else if (size < 65536) {
|
|
669
|
-
this.writeU8(197);
|
|
670
|
-
this.writeU16(size);
|
|
671
|
-
} else if (size < 4294967296) {
|
|
672
|
-
this.writeU8(198);
|
|
673
|
-
this.writeU32(size);
|
|
674
|
-
} else {
|
|
675
|
-
throw new Error("Too large binary: ".concat(size));
|
|
676
|
-
}
|
|
677
|
-
var bytes = ensureUint8Array(object);
|
|
678
|
-
this.writeU8a(bytes);
|
|
679
|
-
};
|
|
680
|
-
Encoder3.prototype.encodeArray = function(object, depth) {
|
|
681
|
-
var size = object.length;
|
|
682
|
-
if (size < 16) {
|
|
683
|
-
this.writeU8(144 + size);
|
|
684
|
-
} else if (size < 65536) {
|
|
685
|
-
this.writeU8(220);
|
|
686
|
-
this.writeU16(size);
|
|
687
|
-
} else if (size < 4294967296) {
|
|
688
|
-
this.writeU8(221);
|
|
689
|
-
this.writeU32(size);
|
|
690
|
-
} else {
|
|
691
|
-
throw new Error("Too large array: ".concat(size));
|
|
692
|
-
}
|
|
693
|
-
for (var _i = 0, object_1 = object; _i < object_1.length; _i++) {
|
|
694
|
-
var item = object_1[_i];
|
|
695
|
-
this.doEncode(item, depth + 1);
|
|
696
|
-
}
|
|
697
|
-
};
|
|
698
|
-
Encoder3.prototype.countWithoutUndefined = function(object, keys) {
|
|
699
|
-
var count = 0;
|
|
700
|
-
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
701
|
-
var key = keys_1[_i];
|
|
702
|
-
if (object[key] !== void 0) {
|
|
703
|
-
count++;
|
|
618
|
+
this.encodeNumberAsFloat(object);
|
|
704
619
|
}
|
|
705
620
|
}
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
621
|
+
} else {
|
|
622
|
+
this.encodeNumberAsFloat(object);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
encodeNumberAsFloat(object) {
|
|
626
|
+
if (this.forceFloat32) {
|
|
627
|
+
this.writeU8(202);
|
|
628
|
+
this.writeF32(object);
|
|
629
|
+
} else {
|
|
630
|
+
this.writeU8(203);
|
|
631
|
+
this.writeF64(object);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
encodeBigInt64(object) {
|
|
635
|
+
if (object >= BigInt(0)) {
|
|
636
|
+
this.writeU8(207);
|
|
637
|
+
this.writeBigUint64(object);
|
|
638
|
+
} else {
|
|
639
|
+
this.writeU8(211);
|
|
640
|
+
this.writeBigInt64(object);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
writeStringHeader(byteLength) {
|
|
644
|
+
if (byteLength < 32) {
|
|
645
|
+
this.writeU8(160 + byteLength);
|
|
646
|
+
} else if (byteLength < 256) {
|
|
647
|
+
this.writeU8(217);
|
|
648
|
+
this.writeU8(byteLength);
|
|
649
|
+
} else if (byteLength < 65536) {
|
|
650
|
+
this.writeU8(218);
|
|
651
|
+
this.writeU16(byteLength);
|
|
652
|
+
} else if (byteLength < 4294967296) {
|
|
653
|
+
this.writeU8(219);
|
|
654
|
+
this.writeU32(byteLength);
|
|
655
|
+
} else {
|
|
656
|
+
throw new Error(`Too long string: ${byteLength} bytes in UTF-8`);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
encodeString(object) {
|
|
660
|
+
const maxHeaderSize = 1 + 4;
|
|
661
|
+
const byteLength = utf8Count(object);
|
|
662
|
+
this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
|
|
663
|
+
this.writeStringHeader(byteLength);
|
|
664
|
+
utf8Encode(object, this.bytes, this.pos);
|
|
665
|
+
this.pos += byteLength;
|
|
666
|
+
}
|
|
667
|
+
encodeObject(object, depth) {
|
|
668
|
+
const ext = this.extensionCodec.tryToEncode(object, this.context);
|
|
669
|
+
if (ext != null) {
|
|
670
|
+
this.encodeExtension(ext);
|
|
671
|
+
} else if (Array.isArray(object)) {
|
|
672
|
+
this.encodeArray(object, depth);
|
|
673
|
+
} else if (ArrayBuffer.isView(object)) {
|
|
674
|
+
this.encodeBinary(object);
|
|
675
|
+
} else if (typeof object === "object") {
|
|
676
|
+
this.encodeMap(object, depth);
|
|
677
|
+
} else {
|
|
678
|
+
throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(object)}`);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
encodeBinary(object) {
|
|
682
|
+
const size = object.byteLength;
|
|
683
|
+
if (size < 256) {
|
|
684
|
+
this.writeU8(196);
|
|
685
|
+
this.writeU8(size);
|
|
686
|
+
} else if (size < 65536) {
|
|
687
|
+
this.writeU8(197);
|
|
688
|
+
this.writeU16(size);
|
|
689
|
+
} else if (size < 4294967296) {
|
|
690
|
+
this.writeU8(198);
|
|
691
|
+
this.writeU32(size);
|
|
692
|
+
} else {
|
|
693
|
+
throw new Error(`Too large binary: ${size}`);
|
|
694
|
+
}
|
|
695
|
+
const bytes = ensureUint8Array(object);
|
|
696
|
+
this.writeU8a(bytes);
|
|
697
|
+
}
|
|
698
|
+
encodeArray(object, depth) {
|
|
699
|
+
const size = object.length;
|
|
700
|
+
if (size < 16) {
|
|
701
|
+
this.writeU8(144 + size);
|
|
702
|
+
} else if (size < 65536) {
|
|
703
|
+
this.writeU8(220);
|
|
704
|
+
this.writeU16(size);
|
|
705
|
+
} else if (size < 4294967296) {
|
|
706
|
+
this.writeU8(221);
|
|
707
|
+
this.writeU32(size);
|
|
708
|
+
} else {
|
|
709
|
+
throw new Error(`Too large array: ${size}`);
|
|
710
|
+
}
|
|
711
|
+
for (const item of object) {
|
|
712
|
+
this.doEncode(item, depth + 1);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
countWithoutUndefined(object, keys) {
|
|
716
|
+
let count = 0;
|
|
717
|
+
for (const key of keys) {
|
|
718
|
+
if (object[key] !== void 0) {
|
|
719
|
+
count++;
|
|
724
720
|
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
721
|
+
}
|
|
722
|
+
return count;
|
|
723
|
+
}
|
|
724
|
+
encodeMap(object, depth) {
|
|
725
|
+
const keys = Object.keys(object);
|
|
726
|
+
if (this.sortKeys) {
|
|
727
|
+
keys.sort();
|
|
728
|
+
}
|
|
729
|
+
const size = this.ignoreUndefined ? this.countWithoutUndefined(object, keys) : keys.length;
|
|
730
|
+
if (size < 16) {
|
|
731
|
+
this.writeU8(128 + size);
|
|
732
|
+
} else if (size < 65536) {
|
|
733
|
+
this.writeU8(222);
|
|
734
|
+
this.writeU16(size);
|
|
735
|
+
} else if (size < 4294967296) {
|
|
736
|
+
this.writeU8(223);
|
|
737
|
+
this.writeU32(size);
|
|
738
|
+
} else {
|
|
739
|
+
throw new Error(`Too large map object: ${size}`);
|
|
740
|
+
}
|
|
741
|
+
for (const key of keys) {
|
|
742
|
+
const value = object[key];
|
|
743
|
+
if (!(this.ignoreUndefined && value === void 0)) {
|
|
744
|
+
this.encodeString(key);
|
|
745
|
+
this.doEncode(value, depth + 1);
|
|
732
746
|
}
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
this.writeU8(214);
|
|
742
|
-
} else if (size === 8) {
|
|
743
|
-
this.writeU8(215);
|
|
744
|
-
} else if (size === 16) {
|
|
745
|
-
this.writeU8(216);
|
|
746
|
-
} else if (size < 256) {
|
|
747
|
-
this.writeU8(199);
|
|
748
|
-
this.writeU8(size);
|
|
749
|
-
} else if (size < 65536) {
|
|
750
|
-
this.writeU8(200);
|
|
751
|
-
this.writeU16(size);
|
|
752
|
-
} else if (size < 4294967296) {
|
|
753
|
-
this.writeU8(201);
|
|
754
|
-
this.writeU32(size);
|
|
755
|
-
} else {
|
|
756
|
-
throw new Error("Too large extension object: ".concat(size));
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
encodeExtension(ext) {
|
|
750
|
+
if (typeof ext.data === "function") {
|
|
751
|
+
const data = ext.data(this.pos + 6);
|
|
752
|
+
const size2 = data.length;
|
|
753
|
+
if (size2 >= 4294967296) {
|
|
754
|
+
throw new Error(`Too large extension object: ${size2}`);
|
|
757
755
|
}
|
|
756
|
+
this.writeU8(201);
|
|
757
|
+
this.writeU32(size2);
|
|
758
758
|
this.writeI8(ext.type);
|
|
759
|
-
this.writeU8a(
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
this.
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
this.
|
|
769
|
-
|
|
770
|
-
this.
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
this.
|
|
775
|
-
this.
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
this.
|
|
779
|
-
|
|
780
|
-
this.
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
}
|
|
829
|
-
)
|
|
759
|
+
this.writeU8a(data);
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
const size = ext.data.length;
|
|
763
|
+
if (size === 1) {
|
|
764
|
+
this.writeU8(212);
|
|
765
|
+
} else if (size === 2) {
|
|
766
|
+
this.writeU8(213);
|
|
767
|
+
} else if (size === 4) {
|
|
768
|
+
this.writeU8(214);
|
|
769
|
+
} else if (size === 8) {
|
|
770
|
+
this.writeU8(215);
|
|
771
|
+
} else if (size === 16) {
|
|
772
|
+
this.writeU8(216);
|
|
773
|
+
} else if (size < 256) {
|
|
774
|
+
this.writeU8(199);
|
|
775
|
+
this.writeU8(size);
|
|
776
|
+
} else if (size < 65536) {
|
|
777
|
+
this.writeU8(200);
|
|
778
|
+
this.writeU16(size);
|
|
779
|
+
} else if (size < 4294967296) {
|
|
780
|
+
this.writeU8(201);
|
|
781
|
+
this.writeU32(size);
|
|
782
|
+
} else {
|
|
783
|
+
throw new Error(`Too large extension object: ${size}`);
|
|
784
|
+
}
|
|
785
|
+
this.writeI8(ext.type);
|
|
786
|
+
this.writeU8a(ext.data);
|
|
787
|
+
}
|
|
788
|
+
writeU8(value) {
|
|
789
|
+
this.ensureBufferSizeToWrite(1);
|
|
790
|
+
this.view.setUint8(this.pos, value);
|
|
791
|
+
this.pos++;
|
|
792
|
+
}
|
|
793
|
+
writeU8a(values) {
|
|
794
|
+
const size = values.length;
|
|
795
|
+
this.ensureBufferSizeToWrite(size);
|
|
796
|
+
this.bytes.set(values, this.pos);
|
|
797
|
+
this.pos += size;
|
|
798
|
+
}
|
|
799
|
+
writeI8(value) {
|
|
800
|
+
this.ensureBufferSizeToWrite(1);
|
|
801
|
+
this.view.setInt8(this.pos, value);
|
|
802
|
+
this.pos++;
|
|
803
|
+
}
|
|
804
|
+
writeU16(value) {
|
|
805
|
+
this.ensureBufferSizeToWrite(2);
|
|
806
|
+
this.view.setUint16(this.pos, value);
|
|
807
|
+
this.pos += 2;
|
|
808
|
+
}
|
|
809
|
+
writeI16(value) {
|
|
810
|
+
this.ensureBufferSizeToWrite(2);
|
|
811
|
+
this.view.setInt16(this.pos, value);
|
|
812
|
+
this.pos += 2;
|
|
813
|
+
}
|
|
814
|
+
writeU32(value) {
|
|
815
|
+
this.ensureBufferSizeToWrite(4);
|
|
816
|
+
this.view.setUint32(this.pos, value);
|
|
817
|
+
this.pos += 4;
|
|
818
|
+
}
|
|
819
|
+
writeI32(value) {
|
|
820
|
+
this.ensureBufferSizeToWrite(4);
|
|
821
|
+
this.view.setInt32(this.pos, value);
|
|
822
|
+
this.pos += 4;
|
|
823
|
+
}
|
|
824
|
+
writeF32(value) {
|
|
825
|
+
this.ensureBufferSizeToWrite(4);
|
|
826
|
+
this.view.setFloat32(this.pos, value);
|
|
827
|
+
this.pos += 4;
|
|
828
|
+
}
|
|
829
|
+
writeF64(value) {
|
|
830
|
+
this.ensureBufferSizeToWrite(8);
|
|
831
|
+
this.view.setFloat64(this.pos, value);
|
|
832
|
+
this.pos += 8;
|
|
833
|
+
}
|
|
834
|
+
writeU64(value) {
|
|
835
|
+
this.ensureBufferSizeToWrite(8);
|
|
836
|
+
setUint64(this.view, this.pos, value);
|
|
837
|
+
this.pos += 8;
|
|
838
|
+
}
|
|
839
|
+
writeI64(value) {
|
|
840
|
+
this.ensureBufferSizeToWrite(8);
|
|
841
|
+
setInt64(this.view, this.pos, value);
|
|
842
|
+
this.pos += 8;
|
|
843
|
+
}
|
|
844
|
+
writeBigUint64(value) {
|
|
845
|
+
this.ensureBufferSizeToWrite(8);
|
|
846
|
+
this.view.setBigUint64(this.pos, value);
|
|
847
|
+
this.pos += 8;
|
|
848
|
+
}
|
|
849
|
+
writeBigInt64(value) {
|
|
850
|
+
this.ensureBufferSizeToWrite(8);
|
|
851
|
+
this.view.setBigInt64(this.pos, value);
|
|
852
|
+
this.pos += 8;
|
|
853
|
+
}
|
|
854
|
+
};
|
|
830
855
|
|
|
831
|
-
// node_modules/@msgpack/msgpack/dist.
|
|
856
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/encode.mjs
|
|
832
857
|
function encode(value, options) {
|
|
833
|
-
|
|
858
|
+
const encoder = new Encoder(options);
|
|
834
859
|
return encoder.encodeSharedRef(value);
|
|
835
860
|
}
|
|
836
861
|
|
|
837
|
-
// node_modules/@msgpack/msgpack/dist.
|
|
862
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/utils/prettyByte.mjs
|
|
838
863
|
function prettyByte(byte) {
|
|
839
|
-
return
|
|
864
|
+
return `${byte < 0 ? "-" : ""}0x${Math.abs(byte).toString(16).padStart(2, "0")}`;
|
|
840
865
|
}
|
|
841
866
|
|
|
842
|
-
// node_modules/@msgpack/msgpack/dist.
|
|
867
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/CachedKeyDecoder.mjs
|
|
843
868
|
var DEFAULT_MAX_KEY_LENGTH = 16;
|
|
844
869
|
var DEFAULT_MAX_LENGTH_PER_KEY = 16;
|
|
845
|
-
var CachedKeyDecoder =
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
this.
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
FIND_CHUNK: for (var _i = 0, records_1 = records; _i < records_1.length; _i++) {
|
|
870
|
-
var record = records_1[_i];
|
|
871
|
-
var recordBytes = record.bytes;
|
|
872
|
-
for (var j = 0; j < byteLength; j++) {
|
|
873
|
-
if (recordBytes[j] !== bytes[inputOffset + j]) {
|
|
874
|
-
continue FIND_CHUNK;
|
|
875
|
-
}
|
|
870
|
+
var CachedKeyDecoder = class {
|
|
871
|
+
hit = 0;
|
|
872
|
+
miss = 0;
|
|
873
|
+
caches;
|
|
874
|
+
maxKeyLength;
|
|
875
|
+
maxLengthPerKey;
|
|
876
|
+
constructor(maxKeyLength = DEFAULT_MAX_KEY_LENGTH, maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY) {
|
|
877
|
+
this.maxKeyLength = maxKeyLength;
|
|
878
|
+
this.maxLengthPerKey = maxLengthPerKey;
|
|
879
|
+
this.caches = [];
|
|
880
|
+
for (let i = 0; i < this.maxKeyLength; i++) {
|
|
881
|
+
this.caches.push([]);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
canBeCached(byteLength) {
|
|
885
|
+
return byteLength > 0 && byteLength <= this.maxKeyLength;
|
|
886
|
+
}
|
|
887
|
+
find(bytes, inputOffset, byteLength) {
|
|
888
|
+
const records = this.caches[byteLength - 1];
|
|
889
|
+
FIND_CHUNK: for (const record of records) {
|
|
890
|
+
const recordBytes = record.bytes;
|
|
891
|
+
for (let j = 0; j < byteLength; j++) {
|
|
892
|
+
if (recordBytes[j] !== bytes[inputOffset + j]) {
|
|
893
|
+
continue FIND_CHUNK;
|
|
876
894
|
}
|
|
877
|
-
return record.str;
|
|
878
|
-
}
|
|
879
|
-
return null;
|
|
880
|
-
};
|
|
881
|
-
CachedKeyDecoder2.prototype.store = function(bytes, value) {
|
|
882
|
-
var records = this.caches[bytes.length - 1];
|
|
883
|
-
var record = { bytes, str: value };
|
|
884
|
-
if (records.length >= this.maxLengthPerKey) {
|
|
885
|
-
records[Math.random() * records.length | 0] = record;
|
|
886
|
-
} else {
|
|
887
|
-
records.push(record);
|
|
888
|
-
}
|
|
889
|
-
};
|
|
890
|
-
CachedKeyDecoder2.prototype.decode = function(bytes, inputOffset, byteLength) {
|
|
891
|
-
var cachedValue = this.find(bytes, inputOffset, byteLength);
|
|
892
|
-
if (cachedValue != null) {
|
|
893
|
-
this.hit++;
|
|
894
|
-
return cachedValue;
|
|
895
|
-
}
|
|
896
|
-
this.miss++;
|
|
897
|
-
var str = utf8DecodeJs(bytes, inputOffset, byteLength);
|
|
898
|
-
var slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength);
|
|
899
|
-
this.store(slicedCopyOfBytes, str);
|
|
900
|
-
return str;
|
|
901
|
-
};
|
|
902
|
-
return CachedKeyDecoder2;
|
|
903
|
-
}()
|
|
904
|
-
);
|
|
905
|
-
|
|
906
|
-
// node_modules/@msgpack/msgpack/dist.es5+esm/Decoder.mjs
|
|
907
|
-
var __awaiter = function(thisArg, _arguments, P, generator) {
|
|
908
|
-
function adopt(value) {
|
|
909
|
-
return value instanceof P ? value : new P(function(resolve) {
|
|
910
|
-
resolve(value);
|
|
911
|
-
});
|
|
912
|
-
}
|
|
913
|
-
return new (P || (P = Promise))(function(resolve, reject) {
|
|
914
|
-
function fulfilled(value) {
|
|
915
|
-
try {
|
|
916
|
-
step(generator.next(value));
|
|
917
|
-
} catch (e) {
|
|
918
|
-
reject(e);
|
|
919
895
|
}
|
|
896
|
+
return record.str;
|
|
920
897
|
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
898
|
+
return null;
|
|
899
|
+
}
|
|
900
|
+
store(bytes, value) {
|
|
901
|
+
const records = this.caches[bytes.length - 1];
|
|
902
|
+
const record = { bytes, str: value };
|
|
903
|
+
if (records.length >= this.maxLengthPerKey) {
|
|
904
|
+
records[Math.random() * records.length | 0] = record;
|
|
905
|
+
} else {
|
|
906
|
+
records.push(record);
|
|
930
907
|
}
|
|
931
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
932
|
-
});
|
|
933
|
-
};
|
|
934
|
-
var __generator = function(thisArg, body) {
|
|
935
|
-
var _ = { label: 0, sent: function() {
|
|
936
|
-
if (t[0] & 1) throw t[1];
|
|
937
|
-
return t[1];
|
|
938
|
-
}, trys: [], ops: [] }, f, y, t, g;
|
|
939
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
940
|
-
return this;
|
|
941
|
-
}), g;
|
|
942
|
-
function verb(n) {
|
|
943
|
-
return function(v) {
|
|
944
|
-
return step([n, v]);
|
|
945
|
-
};
|
|
946
908
|
}
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
switch (op[0]) {
|
|
953
|
-
case 0:
|
|
954
|
-
case 1:
|
|
955
|
-
t = op;
|
|
956
|
-
break;
|
|
957
|
-
case 4:
|
|
958
|
-
_.label++;
|
|
959
|
-
return { value: op[1], done: false };
|
|
960
|
-
case 5:
|
|
961
|
-
_.label++;
|
|
962
|
-
y = op[1];
|
|
963
|
-
op = [0];
|
|
964
|
-
continue;
|
|
965
|
-
case 7:
|
|
966
|
-
op = _.ops.pop();
|
|
967
|
-
_.trys.pop();
|
|
968
|
-
continue;
|
|
969
|
-
default:
|
|
970
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
971
|
-
_ = 0;
|
|
972
|
-
continue;
|
|
973
|
-
}
|
|
974
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
975
|
-
_.label = op[1];
|
|
976
|
-
break;
|
|
977
|
-
}
|
|
978
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
979
|
-
_.label = t[1];
|
|
980
|
-
t = op;
|
|
981
|
-
break;
|
|
982
|
-
}
|
|
983
|
-
if (t && _.label < t[2]) {
|
|
984
|
-
_.label = t[2];
|
|
985
|
-
_.ops.push(op);
|
|
986
|
-
break;
|
|
987
|
-
}
|
|
988
|
-
if (t[2]) _.ops.pop();
|
|
989
|
-
_.trys.pop();
|
|
990
|
-
continue;
|
|
991
|
-
}
|
|
992
|
-
op = body.call(thisArg, _);
|
|
993
|
-
} catch (e) {
|
|
994
|
-
op = [6, e];
|
|
995
|
-
y = 0;
|
|
996
|
-
} finally {
|
|
997
|
-
f = t = 0;
|
|
909
|
+
decode(bytes, inputOffset, byteLength) {
|
|
910
|
+
const cachedValue = this.find(bytes, inputOffset, byteLength);
|
|
911
|
+
if (cachedValue != null) {
|
|
912
|
+
this.hit++;
|
|
913
|
+
return cachedValue;
|
|
998
914
|
}
|
|
999
|
-
|
|
1000
|
-
|
|
915
|
+
this.miss++;
|
|
916
|
+
const str = utf8DecodeJs(bytes, inputOffset, byteLength);
|
|
917
|
+
const slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength);
|
|
918
|
+
this.store(slicedCopyOfBytes, str);
|
|
919
|
+
return str;
|
|
1001
920
|
}
|
|
1002
921
|
};
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
return new Promise(function(resolve, reject) {
|
|
1012
|
-
v = o[n](v), settle(resolve, reject, v.done, v.value);
|
|
1013
|
-
});
|
|
1014
|
-
};
|
|
1015
|
-
}
|
|
1016
|
-
function settle(resolve, reject, d, v) {
|
|
1017
|
-
Promise.resolve(v).then(function(v2) {
|
|
1018
|
-
resolve({ value: v2, done: d });
|
|
1019
|
-
}, reject);
|
|
922
|
+
|
|
923
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/Decoder.mjs
|
|
924
|
+
var STATE_ARRAY = "array";
|
|
925
|
+
var STATE_MAP_KEY = "map_key";
|
|
926
|
+
var STATE_MAP_VALUE = "map_value";
|
|
927
|
+
var mapKeyConverter = (key) => {
|
|
928
|
+
if (typeof key === "string" || typeof key === "number") {
|
|
929
|
+
return key;
|
|
1020
930
|
}
|
|
931
|
+
throw new DecodeError("The type of key must be string or number but " + typeof key);
|
|
1021
932
|
};
|
|
1022
|
-
var
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
return this;
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
933
|
+
var StackPool = class {
|
|
934
|
+
stack = [];
|
|
935
|
+
stackHeadPosition = -1;
|
|
936
|
+
get length() {
|
|
937
|
+
return this.stackHeadPosition + 1;
|
|
938
|
+
}
|
|
939
|
+
top() {
|
|
940
|
+
return this.stack[this.stackHeadPosition];
|
|
941
|
+
}
|
|
942
|
+
pushArrayState(size) {
|
|
943
|
+
const state = this.getUninitializedStateFromPool();
|
|
944
|
+
state.type = STATE_ARRAY;
|
|
945
|
+
state.position = 0;
|
|
946
|
+
state.size = size;
|
|
947
|
+
state.array = new Array(size);
|
|
948
|
+
}
|
|
949
|
+
pushMapState(size) {
|
|
950
|
+
const state = this.getUninitializedStateFromPool();
|
|
951
|
+
state.type = STATE_MAP_KEY;
|
|
952
|
+
state.readCount = 0;
|
|
953
|
+
state.size = size;
|
|
954
|
+
state.map = {};
|
|
955
|
+
}
|
|
956
|
+
getUninitializedStateFromPool() {
|
|
957
|
+
this.stackHeadPosition++;
|
|
958
|
+
if (this.stackHeadPosition === this.stack.length) {
|
|
959
|
+
const partialState = {
|
|
960
|
+
type: void 0,
|
|
961
|
+
size: 0,
|
|
962
|
+
array: void 0,
|
|
963
|
+
position: 0,
|
|
964
|
+
readCount: 0,
|
|
965
|
+
map: void 0,
|
|
966
|
+
key: null
|
|
967
|
+
};
|
|
968
|
+
this.stack.push(partialState);
|
|
1043
969
|
}
|
|
970
|
+
return this.stack[this.stackHeadPosition];
|
|
1044
971
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
972
|
+
release(state) {
|
|
973
|
+
const topStackState = this.stack[this.stackHeadPosition];
|
|
974
|
+
if (topStackState !== state) {
|
|
975
|
+
throw new Error("Invalid stack state. Released state is not on top of the stack.");
|
|
976
|
+
}
|
|
977
|
+
if (state.type === STATE_ARRAY) {
|
|
978
|
+
const partialState = state;
|
|
979
|
+
partialState.size = 0;
|
|
980
|
+
partialState.array = void 0;
|
|
981
|
+
partialState.position = 0;
|
|
982
|
+
partialState.type = void 0;
|
|
983
|
+
}
|
|
984
|
+
if (state.type === STATE_MAP_KEY || state.type === STATE_MAP_VALUE) {
|
|
985
|
+
const partialState = state;
|
|
986
|
+
partialState.size = 0;
|
|
987
|
+
partialState.map = void 0;
|
|
988
|
+
partialState.readCount = 0;
|
|
989
|
+
partialState.type = void 0;
|
|
990
|
+
}
|
|
991
|
+
this.stackHeadPosition--;
|
|
1053
992
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
993
|
+
reset() {
|
|
994
|
+
this.stack.length = 0;
|
|
995
|
+
this.stackHeadPosition = -1;
|
|
1056
996
|
}
|
|
1057
997
|
};
|
|
1058
|
-
var STATE_ARRAY = "array";
|
|
1059
|
-
var STATE_MAP_KEY = "map_key";
|
|
1060
|
-
var STATE_MAP_VALUE = "map_value";
|
|
1061
|
-
var isValidMapKeyType = function(key) {
|
|
1062
|
-
return typeof key === "string" || typeof key === "number";
|
|
1063
|
-
};
|
|
1064
998
|
var HEAD_BYTE_REQUIRED = -1;
|
|
1065
999
|
var EMPTY_VIEW = new DataView(new ArrayBuffer(0));
|
|
1066
1000
|
var EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);
|
|
@@ -1071,371 +1005,215 @@ try {
|
|
|
1071
1005
|
throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
|
|
1072
1006
|
}
|
|
1073
1007
|
}
|
|
1074
|
-
var
|
|
1075
|
-
var MORE_DATA = new DataViewIndexOutOfBoundsError("Insufficient data");
|
|
1008
|
+
var MORE_DATA = new RangeError("Insufficient data");
|
|
1076
1009
|
var sharedCachedKeyDecoder = new CachedKeyDecoder();
|
|
1077
|
-
var Decoder =
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1010
|
+
var Decoder = class _Decoder {
|
|
1011
|
+
extensionCodec;
|
|
1012
|
+
context;
|
|
1013
|
+
useBigInt64;
|
|
1014
|
+
rawStrings;
|
|
1015
|
+
maxStrLength;
|
|
1016
|
+
maxBinLength;
|
|
1017
|
+
maxArrayLength;
|
|
1018
|
+
maxMapLength;
|
|
1019
|
+
maxExtLength;
|
|
1020
|
+
keyDecoder;
|
|
1021
|
+
mapKeyConverter;
|
|
1022
|
+
totalPos = 0;
|
|
1023
|
+
pos = 0;
|
|
1024
|
+
view = EMPTY_VIEW;
|
|
1025
|
+
bytes = EMPTY_BYTES;
|
|
1026
|
+
headByte = HEAD_BYTE_REQUIRED;
|
|
1027
|
+
stack = new StackPool();
|
|
1028
|
+
entered = false;
|
|
1029
|
+
constructor(options) {
|
|
1030
|
+
this.extensionCodec = options?.extensionCodec ?? ExtensionCodec.defaultCodec;
|
|
1031
|
+
this.context = options?.context;
|
|
1032
|
+
this.useBigInt64 = options?.useBigInt64 ?? false;
|
|
1033
|
+
this.rawStrings = options?.rawStrings ?? false;
|
|
1034
|
+
this.maxStrLength = options?.maxStrLength ?? UINT32_MAX;
|
|
1035
|
+
this.maxBinLength = options?.maxBinLength ?? UINT32_MAX;
|
|
1036
|
+
this.maxArrayLength = options?.maxArrayLength ?? UINT32_MAX;
|
|
1037
|
+
this.maxMapLength = options?.maxMapLength ?? UINT32_MAX;
|
|
1038
|
+
this.maxExtLength = options?.maxExtLength ?? UINT32_MAX;
|
|
1039
|
+
this.keyDecoder = options?.keyDecoder !== void 0 ? options.keyDecoder : sharedCachedKeyDecoder;
|
|
1040
|
+
this.mapKeyConverter = options?.mapKeyConverter ?? mapKeyConverter;
|
|
1041
|
+
}
|
|
1042
|
+
clone() {
|
|
1043
|
+
return new _Decoder({
|
|
1044
|
+
extensionCodec: this.extensionCodec,
|
|
1045
|
+
context: this.context,
|
|
1046
|
+
useBigInt64: this.useBigInt64,
|
|
1047
|
+
rawStrings: this.rawStrings,
|
|
1048
|
+
maxStrLength: this.maxStrLength,
|
|
1049
|
+
maxBinLength: this.maxBinLength,
|
|
1050
|
+
maxArrayLength: this.maxArrayLength,
|
|
1051
|
+
maxMapLength: this.maxMapLength,
|
|
1052
|
+
maxExtLength: this.maxExtLength,
|
|
1053
|
+
keyDecoder: this.keyDecoder
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
reinitializeState() {
|
|
1057
|
+
this.totalPos = 0;
|
|
1058
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
1059
|
+
this.stack.reset();
|
|
1060
|
+
}
|
|
1061
|
+
setBuffer(buffer) {
|
|
1062
|
+
const bytes = ensureUint8Array(buffer);
|
|
1063
|
+
this.bytes = bytes;
|
|
1064
|
+
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
1065
|
+
this.pos = 0;
|
|
1066
|
+
}
|
|
1067
|
+
appendBuffer(buffer) {
|
|
1068
|
+
if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) {
|
|
1069
|
+
this.setBuffer(buffer);
|
|
1070
|
+
} else {
|
|
1071
|
+
const remainingData = this.bytes.subarray(this.pos);
|
|
1072
|
+
const newData = ensureUint8Array(buffer);
|
|
1073
|
+
const newBuffer = new Uint8Array(remainingData.length + newData.length);
|
|
1074
|
+
newBuffer.set(remainingData);
|
|
1075
|
+
newBuffer.set(newData, remainingData.length);
|
|
1076
|
+
this.setBuffer(newBuffer);
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
hasRemaining(size) {
|
|
1080
|
+
return this.view.byteLength - this.pos >= size;
|
|
1081
|
+
}
|
|
1082
|
+
createExtraByteError(posToShow) {
|
|
1083
|
+
const { view, pos } = this;
|
|
1084
|
+
return new RangeError(`Extra ${view.byteLength - pos} of ${view.byteLength} byte(s) found at buffer[${posToShow}]`);
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* @throws {@link DecodeError}
|
|
1088
|
+
* @throws {@link RangeError}
|
|
1089
|
+
*/
|
|
1090
|
+
decode(buffer) {
|
|
1091
|
+
if (this.entered) {
|
|
1092
|
+
const instance = this.clone();
|
|
1093
|
+
return instance.decode(buffer);
|
|
1094
|
+
}
|
|
1095
|
+
try {
|
|
1096
|
+
this.entered = true;
|
|
1128
1097
|
this.reinitializeState();
|
|
1129
1098
|
this.setBuffer(buffer);
|
|
1130
|
-
|
|
1099
|
+
const object = this.doDecodeSync();
|
|
1131
1100
|
if (this.hasRemaining(1)) {
|
|
1132
1101
|
throw this.createExtraByteError(this.pos);
|
|
1133
1102
|
}
|
|
1134
1103
|
return object;
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1104
|
+
} finally {
|
|
1105
|
+
this.entered = false;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
*decodeMulti(buffer) {
|
|
1109
|
+
if (this.entered) {
|
|
1110
|
+
const instance = this.clone();
|
|
1111
|
+
yield* instance.decodeMulti(buffer);
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
try {
|
|
1115
|
+
this.entered = true;
|
|
1116
|
+
this.reinitializeState();
|
|
1117
|
+
this.setBuffer(buffer);
|
|
1118
|
+
while (this.hasRemaining(1)) {
|
|
1119
|
+
yield this.doDecodeSync();
|
|
1120
|
+
}
|
|
1121
|
+
} finally {
|
|
1122
|
+
this.entered = false;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
async decodeAsync(stream) {
|
|
1126
|
+
if (this.entered) {
|
|
1127
|
+
const instance = this.clone();
|
|
1128
|
+
return instance.decodeAsync(stream);
|
|
1129
|
+
}
|
|
1130
|
+
try {
|
|
1131
|
+
this.entered = true;
|
|
1132
|
+
let decoded = false;
|
|
1133
|
+
let object;
|
|
1134
|
+
for await (const buffer of stream) {
|
|
1135
|
+
if (decoded) {
|
|
1136
|
+
this.entered = false;
|
|
1137
|
+
throw this.createExtraByteError(this.totalPos);
|
|
1154
1138
|
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
return __generator(this, function(_f) {
|
|
1163
|
-
switch (_f.label) {
|
|
1164
|
-
case 0:
|
|
1165
|
-
decoded = false;
|
|
1166
|
-
_f.label = 1;
|
|
1167
|
-
case 1:
|
|
1168
|
-
_f.trys.push([1, 6, 7, 12]);
|
|
1169
|
-
_a = true, stream_1 = __asyncValues(stream);
|
|
1170
|
-
_f.label = 2;
|
|
1171
|
-
case 2:
|
|
1172
|
-
return [4, stream_1.next()];
|
|
1173
|
-
case 3:
|
|
1174
|
-
if (!(stream_1_1 = _f.sent(), _b = stream_1_1.done, !_b)) return [3, 5];
|
|
1175
|
-
_d = stream_1_1.value;
|
|
1176
|
-
_a = false;
|
|
1177
|
-
try {
|
|
1178
|
-
buffer = _d;
|
|
1179
|
-
if (decoded) {
|
|
1180
|
-
throw this.createExtraByteError(this.totalPos);
|
|
1181
|
-
}
|
|
1182
|
-
this.appendBuffer(buffer);
|
|
1183
|
-
try {
|
|
1184
|
-
object = this.doDecodeSync();
|
|
1185
|
-
decoded = true;
|
|
1186
|
-
} catch (e) {
|
|
1187
|
-
if (!(e instanceof DataViewIndexOutOfBoundsError)) {
|
|
1188
|
-
throw e;
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
this.totalPos += this.pos;
|
|
1192
|
-
} finally {
|
|
1193
|
-
_a = true;
|
|
1194
|
-
}
|
|
1195
|
-
_f.label = 4;
|
|
1196
|
-
case 4:
|
|
1197
|
-
return [3, 2];
|
|
1198
|
-
case 5:
|
|
1199
|
-
return [3, 12];
|
|
1200
|
-
case 6:
|
|
1201
|
-
e_1_1 = _f.sent();
|
|
1202
|
-
e_1 = { error: e_1_1 };
|
|
1203
|
-
return [3, 12];
|
|
1204
|
-
case 7:
|
|
1205
|
-
_f.trys.push([7, , 10, 11]);
|
|
1206
|
-
if (!(!_a && !_b && (_c = stream_1.return))) return [3, 9];
|
|
1207
|
-
return [4, _c.call(stream_1)];
|
|
1208
|
-
case 8:
|
|
1209
|
-
_f.sent();
|
|
1210
|
-
_f.label = 9;
|
|
1211
|
-
case 9:
|
|
1212
|
-
return [3, 11];
|
|
1213
|
-
case 10:
|
|
1214
|
-
if (e_1) throw e_1.error;
|
|
1215
|
-
return [
|
|
1216
|
-
7
|
|
1217
|
-
/*endfinally*/
|
|
1218
|
-
];
|
|
1219
|
-
case 11:
|
|
1220
|
-
return [
|
|
1221
|
-
7
|
|
1222
|
-
/*endfinally*/
|
|
1223
|
-
];
|
|
1224
|
-
case 12:
|
|
1225
|
-
if (decoded) {
|
|
1226
|
-
if (this.hasRemaining(1)) {
|
|
1227
|
-
throw this.createExtraByteError(this.totalPos);
|
|
1228
|
-
}
|
|
1229
|
-
return [2, object];
|
|
1230
|
-
}
|
|
1231
|
-
_e = this, headByte = _e.headByte, pos = _e.pos, totalPos = _e.totalPos;
|
|
1232
|
-
throw new RangeError("Insufficient data in parsing ".concat(prettyByte(headByte), " at ").concat(totalPos, " (").concat(pos, " in the current buffer)"));
|
|
1233
|
-
}
|
|
1234
|
-
});
|
|
1235
|
-
});
|
|
1236
|
-
};
|
|
1237
|
-
Decoder3.prototype.decodeArrayStream = function(stream) {
|
|
1238
|
-
return this.decodeMultiAsync(stream, true);
|
|
1239
|
-
};
|
|
1240
|
-
Decoder3.prototype.decodeStream = function(stream) {
|
|
1241
|
-
return this.decodeMultiAsync(stream, false);
|
|
1242
|
-
};
|
|
1243
|
-
Decoder3.prototype.decodeMultiAsync = function(stream, isArray) {
|
|
1244
|
-
return __asyncGenerator(this, arguments, function decodeMultiAsync_1() {
|
|
1245
|
-
var isArrayHeaderRequired, arrayItemsLeft, _a, stream_2, stream_2_1, buffer, e_2, e_3_1;
|
|
1246
|
-
var _b, e_3, _c, _d;
|
|
1247
|
-
return __generator(this, function(_e) {
|
|
1248
|
-
switch (_e.label) {
|
|
1249
|
-
case 0:
|
|
1250
|
-
isArrayHeaderRequired = isArray;
|
|
1251
|
-
arrayItemsLeft = -1;
|
|
1252
|
-
_e.label = 1;
|
|
1253
|
-
case 1:
|
|
1254
|
-
_e.trys.push([1, 15, 16, 21]);
|
|
1255
|
-
_a = true, stream_2 = __asyncValues(stream);
|
|
1256
|
-
_e.label = 2;
|
|
1257
|
-
case 2:
|
|
1258
|
-
return [4, __await(stream_2.next())];
|
|
1259
|
-
case 3:
|
|
1260
|
-
if (!(stream_2_1 = _e.sent(), _b = stream_2_1.done, !_b)) return [3, 14];
|
|
1261
|
-
_d = stream_2_1.value;
|
|
1262
|
-
_a = false;
|
|
1263
|
-
_e.label = 4;
|
|
1264
|
-
case 4:
|
|
1265
|
-
_e.trys.push([4, , 12, 13]);
|
|
1266
|
-
buffer = _d;
|
|
1267
|
-
if (isArray && arrayItemsLeft === 0) {
|
|
1268
|
-
throw this.createExtraByteError(this.totalPos);
|
|
1269
|
-
}
|
|
1270
|
-
this.appendBuffer(buffer);
|
|
1271
|
-
if (isArrayHeaderRequired) {
|
|
1272
|
-
arrayItemsLeft = this.readArraySize();
|
|
1273
|
-
isArrayHeaderRequired = false;
|
|
1274
|
-
this.complete();
|
|
1275
|
-
}
|
|
1276
|
-
_e.label = 5;
|
|
1277
|
-
case 5:
|
|
1278
|
-
_e.trys.push([5, 10, , 11]);
|
|
1279
|
-
_e.label = 6;
|
|
1280
|
-
case 6:
|
|
1281
|
-
if (false) return [3, 9];
|
|
1282
|
-
return [4, __await(this.doDecodeSync())];
|
|
1283
|
-
case 7:
|
|
1284
|
-
return [4, _e.sent()];
|
|
1285
|
-
case 8:
|
|
1286
|
-
_e.sent();
|
|
1287
|
-
if (--arrayItemsLeft === 0) {
|
|
1288
|
-
return [3, 9];
|
|
1289
|
-
}
|
|
1290
|
-
return [3, 6];
|
|
1291
|
-
case 9:
|
|
1292
|
-
return [3, 11];
|
|
1293
|
-
case 10:
|
|
1294
|
-
e_2 = _e.sent();
|
|
1295
|
-
if (!(e_2 instanceof DataViewIndexOutOfBoundsError)) {
|
|
1296
|
-
throw e_2;
|
|
1297
|
-
}
|
|
1298
|
-
return [3, 11];
|
|
1299
|
-
case 11:
|
|
1300
|
-
this.totalPos += this.pos;
|
|
1301
|
-
return [3, 13];
|
|
1302
|
-
case 12:
|
|
1303
|
-
_a = true;
|
|
1304
|
-
return [
|
|
1305
|
-
7
|
|
1306
|
-
/*endfinally*/
|
|
1307
|
-
];
|
|
1308
|
-
case 13:
|
|
1309
|
-
return [3, 2];
|
|
1310
|
-
case 14:
|
|
1311
|
-
return [3, 21];
|
|
1312
|
-
case 15:
|
|
1313
|
-
e_3_1 = _e.sent();
|
|
1314
|
-
e_3 = { error: e_3_1 };
|
|
1315
|
-
return [3, 21];
|
|
1316
|
-
case 16:
|
|
1317
|
-
_e.trys.push([16, , 19, 20]);
|
|
1318
|
-
if (!(!_a && !_b && (_c = stream_2.return))) return [3, 18];
|
|
1319
|
-
return [4, __await(_c.call(stream_2))];
|
|
1320
|
-
case 17:
|
|
1321
|
-
_e.sent();
|
|
1322
|
-
_e.label = 18;
|
|
1323
|
-
case 18:
|
|
1324
|
-
return [3, 20];
|
|
1325
|
-
case 19:
|
|
1326
|
-
if (e_3) throw e_3.error;
|
|
1327
|
-
return [
|
|
1328
|
-
7
|
|
1329
|
-
/*endfinally*/
|
|
1330
|
-
];
|
|
1331
|
-
case 20:
|
|
1332
|
-
return [
|
|
1333
|
-
7
|
|
1334
|
-
/*endfinally*/
|
|
1335
|
-
];
|
|
1336
|
-
case 21:
|
|
1337
|
-
return [
|
|
1338
|
-
2
|
|
1339
|
-
/*return*/
|
|
1340
|
-
];
|
|
1139
|
+
this.appendBuffer(buffer);
|
|
1140
|
+
try {
|
|
1141
|
+
object = this.doDecodeSync();
|
|
1142
|
+
decoded = true;
|
|
1143
|
+
} catch (e) {
|
|
1144
|
+
if (!(e instanceof RangeError)) {
|
|
1145
|
+
throw e;
|
|
1341
1146
|
}
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1147
|
+
}
|
|
1148
|
+
this.totalPos += this.pos;
|
|
1149
|
+
}
|
|
1150
|
+
if (decoded) {
|
|
1151
|
+
if (this.hasRemaining(1)) {
|
|
1152
|
+
throw this.createExtraByteError(this.totalPos);
|
|
1153
|
+
}
|
|
1154
|
+
return object;
|
|
1155
|
+
}
|
|
1156
|
+
const { headByte, pos, totalPos } = this;
|
|
1157
|
+
throw new RangeError(`Insufficient data in parsing ${prettyByte(headByte)} at ${totalPos} (${pos} in the current buffer)`);
|
|
1158
|
+
} finally {
|
|
1159
|
+
this.entered = false;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
decodeArrayStream(stream) {
|
|
1163
|
+
return this.decodeMultiAsync(stream, true);
|
|
1164
|
+
}
|
|
1165
|
+
decodeStream(stream) {
|
|
1166
|
+
return this.decodeMultiAsync(stream, false);
|
|
1167
|
+
}
|
|
1168
|
+
async *decodeMultiAsync(stream, isArray) {
|
|
1169
|
+
if (this.entered) {
|
|
1170
|
+
const instance = this.clone();
|
|
1171
|
+
yield* instance.decodeMultiAsync(stream, isArray);
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
try {
|
|
1175
|
+
this.entered = true;
|
|
1176
|
+
let isArrayHeaderRequired = isArray;
|
|
1177
|
+
let arrayItemsLeft = -1;
|
|
1178
|
+
for await (const buffer of stream) {
|
|
1179
|
+
if (isArray && arrayItemsLeft === 0) {
|
|
1180
|
+
throw this.createExtraByteError(this.totalPos);
|
|
1181
|
+
}
|
|
1182
|
+
this.appendBuffer(buffer);
|
|
1183
|
+
if (isArrayHeaderRequired) {
|
|
1184
|
+
arrayItemsLeft = this.readArraySize();
|
|
1185
|
+
isArrayHeaderRequired = false;
|
|
1186
|
+
this.complete();
|
|
1187
|
+
}
|
|
1188
|
+
try {
|
|
1189
|
+
while (true) {
|
|
1190
|
+
yield this.doDecodeSync();
|
|
1191
|
+
if (--arrayItemsLeft === 0) {
|
|
1192
|
+
break;
|
|
1371
1193
|
}
|
|
1372
|
-
} else {
|
|
1373
|
-
var byteLength = headByte - 160;
|
|
1374
|
-
object = this.decodeUtf8String(byteLength, 0);
|
|
1375
|
-
}
|
|
1376
|
-
} else if (headByte === 192) {
|
|
1377
|
-
object = null;
|
|
1378
|
-
} else if (headByte === 194) {
|
|
1379
|
-
object = false;
|
|
1380
|
-
} else if (headByte === 195) {
|
|
1381
|
-
object = true;
|
|
1382
|
-
} else if (headByte === 202) {
|
|
1383
|
-
object = this.readF32();
|
|
1384
|
-
} else if (headByte === 203) {
|
|
1385
|
-
object = this.readF64();
|
|
1386
|
-
} else if (headByte === 204) {
|
|
1387
|
-
object = this.readU8();
|
|
1388
|
-
} else if (headByte === 205) {
|
|
1389
|
-
object = this.readU16();
|
|
1390
|
-
} else if (headByte === 206) {
|
|
1391
|
-
object = this.readU32();
|
|
1392
|
-
} else if (headByte === 207) {
|
|
1393
|
-
if (this.useBigInt64) {
|
|
1394
|
-
object = this.readU64AsBigInt();
|
|
1395
|
-
} else {
|
|
1396
|
-
object = this.readU64();
|
|
1397
|
-
}
|
|
1398
|
-
} else if (headByte === 208) {
|
|
1399
|
-
object = this.readI8();
|
|
1400
|
-
} else if (headByte === 209) {
|
|
1401
|
-
object = this.readI16();
|
|
1402
|
-
} else if (headByte === 210) {
|
|
1403
|
-
object = this.readI32();
|
|
1404
|
-
} else if (headByte === 211) {
|
|
1405
|
-
if (this.useBigInt64) {
|
|
1406
|
-
object = this.readI64AsBigInt();
|
|
1407
|
-
} else {
|
|
1408
|
-
object = this.readI64();
|
|
1409
|
-
}
|
|
1410
|
-
} else if (headByte === 217) {
|
|
1411
|
-
var byteLength = this.lookU8();
|
|
1412
|
-
object = this.decodeUtf8String(byteLength, 1);
|
|
1413
|
-
} else if (headByte === 218) {
|
|
1414
|
-
var byteLength = this.lookU16();
|
|
1415
|
-
object = this.decodeUtf8String(byteLength, 2);
|
|
1416
|
-
} else if (headByte === 219) {
|
|
1417
|
-
var byteLength = this.lookU32();
|
|
1418
|
-
object = this.decodeUtf8String(byteLength, 4);
|
|
1419
|
-
} else if (headByte === 220) {
|
|
1420
|
-
var size = this.readU16();
|
|
1421
|
-
if (size !== 0) {
|
|
1422
|
-
this.pushArrayState(size);
|
|
1423
|
-
this.complete();
|
|
1424
|
-
continue DECODE;
|
|
1425
|
-
} else {
|
|
1426
|
-
object = [];
|
|
1427
1194
|
}
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
this.pushArrayState(size);
|
|
1432
|
-
this.complete();
|
|
1433
|
-
continue DECODE;
|
|
1434
|
-
} else {
|
|
1435
|
-
object = [];
|
|
1195
|
+
} catch (e) {
|
|
1196
|
+
if (!(e instanceof RangeError)) {
|
|
1197
|
+
throw e;
|
|
1436
1198
|
}
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1199
|
+
}
|
|
1200
|
+
this.totalPos += this.pos;
|
|
1201
|
+
}
|
|
1202
|
+
} finally {
|
|
1203
|
+
this.entered = false;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
doDecodeSync() {
|
|
1207
|
+
DECODE: while (true) {
|
|
1208
|
+
const headByte = this.readHeadByte();
|
|
1209
|
+
let object;
|
|
1210
|
+
if (headByte >= 224) {
|
|
1211
|
+
object = headByte - 256;
|
|
1212
|
+
} else if (headByte < 192) {
|
|
1213
|
+
if (headByte < 128) {
|
|
1214
|
+
object = headByte;
|
|
1215
|
+
} else if (headByte < 144) {
|
|
1216
|
+
const size = headByte - 128;
|
|
1439
1217
|
if (size !== 0) {
|
|
1440
1218
|
this.pushMapState(size);
|
|
1441
1219
|
this.complete();
|
|
@@ -1443,265 +1221,343 @@ var Decoder = (
|
|
|
1443
1221
|
} else {
|
|
1444
1222
|
object = {};
|
|
1445
1223
|
}
|
|
1446
|
-
} else if (headByte
|
|
1447
|
-
|
|
1224
|
+
} else if (headByte < 160) {
|
|
1225
|
+
const size = headByte - 144;
|
|
1448
1226
|
if (size !== 0) {
|
|
1449
|
-
this.
|
|
1227
|
+
this.pushArrayState(size);
|
|
1450
1228
|
this.complete();
|
|
1451
1229
|
continue DECODE;
|
|
1452
1230
|
} else {
|
|
1453
|
-
object =
|
|
1231
|
+
object = [];
|
|
1454
1232
|
}
|
|
1455
|
-
} else if (headByte === 196) {
|
|
1456
|
-
var size = this.lookU8();
|
|
1457
|
-
object = this.decodeBinary(size, 1);
|
|
1458
|
-
} else if (headByte === 197) {
|
|
1459
|
-
var size = this.lookU16();
|
|
1460
|
-
object = this.decodeBinary(size, 2);
|
|
1461
|
-
} else if (headByte === 198) {
|
|
1462
|
-
var size = this.lookU32();
|
|
1463
|
-
object = this.decodeBinary(size, 4);
|
|
1464
|
-
} else if (headByte === 212) {
|
|
1465
|
-
object = this.decodeExtension(1, 0);
|
|
1466
|
-
} else if (headByte === 213) {
|
|
1467
|
-
object = this.decodeExtension(2, 0);
|
|
1468
|
-
} else if (headByte === 214) {
|
|
1469
|
-
object = this.decodeExtension(4, 0);
|
|
1470
|
-
} else if (headByte === 215) {
|
|
1471
|
-
object = this.decodeExtension(8, 0);
|
|
1472
|
-
} else if (headByte === 216) {
|
|
1473
|
-
object = this.decodeExtension(16, 0);
|
|
1474
|
-
} else if (headByte === 199) {
|
|
1475
|
-
var size = this.lookU8();
|
|
1476
|
-
object = this.decodeExtension(size, 1);
|
|
1477
|
-
} else if (headByte === 200) {
|
|
1478
|
-
var size = this.lookU16();
|
|
1479
|
-
object = this.decodeExtension(size, 2);
|
|
1480
|
-
} else if (headByte === 201) {
|
|
1481
|
-
var size = this.lookU32();
|
|
1482
|
-
object = this.decodeExtension(size, 4);
|
|
1483
1233
|
} else {
|
|
1484
|
-
|
|
1234
|
+
const byteLength = headByte - 160;
|
|
1235
|
+
object = this.decodeString(byteLength, 0);
|
|
1485
1236
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1237
|
+
} else if (headByte === 192) {
|
|
1238
|
+
object = null;
|
|
1239
|
+
} else if (headByte === 194) {
|
|
1240
|
+
object = false;
|
|
1241
|
+
} else if (headByte === 195) {
|
|
1242
|
+
object = true;
|
|
1243
|
+
} else if (headByte === 202) {
|
|
1244
|
+
object = this.readF32();
|
|
1245
|
+
} else if (headByte === 203) {
|
|
1246
|
+
object = this.readF64();
|
|
1247
|
+
} else if (headByte === 204) {
|
|
1248
|
+
object = this.readU8();
|
|
1249
|
+
} else if (headByte === 205) {
|
|
1250
|
+
object = this.readU16();
|
|
1251
|
+
} else if (headByte === 206) {
|
|
1252
|
+
object = this.readU32();
|
|
1253
|
+
} else if (headByte === 207) {
|
|
1254
|
+
if (this.useBigInt64) {
|
|
1255
|
+
object = this.readU64AsBigInt();
|
|
1256
|
+
} else {
|
|
1257
|
+
object = this.readU64();
|
|
1258
|
+
}
|
|
1259
|
+
} else if (headByte === 208) {
|
|
1260
|
+
object = this.readI8();
|
|
1261
|
+
} else if (headByte === 209) {
|
|
1262
|
+
object = this.readI16();
|
|
1263
|
+
} else if (headByte === 210) {
|
|
1264
|
+
object = this.readI32();
|
|
1265
|
+
} else if (headByte === 211) {
|
|
1266
|
+
if (this.useBigInt64) {
|
|
1267
|
+
object = this.readI64AsBigInt();
|
|
1268
|
+
} else {
|
|
1269
|
+
object = this.readI64();
|
|
1270
|
+
}
|
|
1271
|
+
} else if (headByte === 217) {
|
|
1272
|
+
const byteLength = this.lookU8();
|
|
1273
|
+
object = this.decodeString(byteLength, 1);
|
|
1274
|
+
} else if (headByte === 218) {
|
|
1275
|
+
const byteLength = this.lookU16();
|
|
1276
|
+
object = this.decodeString(byteLength, 2);
|
|
1277
|
+
} else if (headByte === 219) {
|
|
1278
|
+
const byteLength = this.lookU32();
|
|
1279
|
+
object = this.decodeString(byteLength, 4);
|
|
1280
|
+
} else if (headByte === 220) {
|
|
1281
|
+
const size = this.readU16();
|
|
1282
|
+
if (size !== 0) {
|
|
1283
|
+
this.pushArrayState(size);
|
|
1284
|
+
this.complete();
|
|
1285
|
+
continue DECODE;
|
|
1286
|
+
} else {
|
|
1287
|
+
object = [];
|
|
1288
|
+
}
|
|
1289
|
+
} else if (headByte === 221) {
|
|
1290
|
+
const size = this.readU32();
|
|
1291
|
+
if (size !== 0) {
|
|
1292
|
+
this.pushArrayState(size);
|
|
1293
|
+
this.complete();
|
|
1294
|
+
continue DECODE;
|
|
1295
|
+
} else {
|
|
1296
|
+
object = [];
|
|
1297
|
+
}
|
|
1298
|
+
} else if (headByte === 222) {
|
|
1299
|
+
const size = this.readU16();
|
|
1300
|
+
if (size !== 0) {
|
|
1301
|
+
this.pushMapState(size);
|
|
1302
|
+
this.complete();
|
|
1303
|
+
continue DECODE;
|
|
1304
|
+
} else {
|
|
1305
|
+
object = {};
|
|
1306
|
+
}
|
|
1307
|
+
} else if (headByte === 223) {
|
|
1308
|
+
const size = this.readU32();
|
|
1309
|
+
if (size !== 0) {
|
|
1310
|
+
this.pushMapState(size);
|
|
1311
|
+
this.complete();
|
|
1312
|
+
continue DECODE;
|
|
1313
|
+
} else {
|
|
1314
|
+
object = {};
|
|
1315
|
+
}
|
|
1316
|
+
} else if (headByte === 196) {
|
|
1317
|
+
const size = this.lookU8();
|
|
1318
|
+
object = this.decodeBinary(size, 1);
|
|
1319
|
+
} else if (headByte === 197) {
|
|
1320
|
+
const size = this.lookU16();
|
|
1321
|
+
object = this.decodeBinary(size, 2);
|
|
1322
|
+
} else if (headByte === 198) {
|
|
1323
|
+
const size = this.lookU32();
|
|
1324
|
+
object = this.decodeBinary(size, 4);
|
|
1325
|
+
} else if (headByte === 212) {
|
|
1326
|
+
object = this.decodeExtension(1, 0);
|
|
1327
|
+
} else if (headByte === 213) {
|
|
1328
|
+
object = this.decodeExtension(2, 0);
|
|
1329
|
+
} else if (headByte === 214) {
|
|
1330
|
+
object = this.decodeExtension(4, 0);
|
|
1331
|
+
} else if (headByte === 215) {
|
|
1332
|
+
object = this.decodeExtension(8, 0);
|
|
1333
|
+
} else if (headByte === 216) {
|
|
1334
|
+
object = this.decodeExtension(16, 0);
|
|
1335
|
+
} else if (headByte === 199) {
|
|
1336
|
+
const size = this.lookU8();
|
|
1337
|
+
object = this.decodeExtension(size, 1);
|
|
1338
|
+
} else if (headByte === 200) {
|
|
1339
|
+
const size = this.lookU16();
|
|
1340
|
+
object = this.decodeExtension(size, 2);
|
|
1341
|
+
} else if (headByte === 201) {
|
|
1342
|
+
const size = this.lookU32();
|
|
1343
|
+
object = this.decodeExtension(size, 4);
|
|
1344
|
+
} else {
|
|
1345
|
+
throw new DecodeError(`Unrecognized type byte: ${prettyByte(headByte)}`);
|
|
1346
|
+
}
|
|
1347
|
+
this.complete();
|
|
1348
|
+
const stack = this.stack;
|
|
1349
|
+
while (stack.length > 0) {
|
|
1350
|
+
const state = stack.top();
|
|
1351
|
+
if (state.type === STATE_ARRAY) {
|
|
1352
|
+
state.array[state.position] = object;
|
|
1353
|
+
state.position++;
|
|
1354
|
+
if (state.position === state.size) {
|
|
1355
|
+
object = state.array;
|
|
1356
|
+
stack.release(state);
|
|
1509
1357
|
} else {
|
|
1510
|
-
|
|
1511
|
-
state.readCount++;
|
|
1512
|
-
if (state.readCount === state.size) {
|
|
1513
|
-
stack.pop();
|
|
1514
|
-
object = state.map;
|
|
1515
|
-
} else {
|
|
1516
|
-
state.key = null;
|
|
1517
|
-
state.type = STATE_MAP_KEY;
|
|
1518
|
-
continue DECODE;
|
|
1519
|
-
}
|
|
1358
|
+
continue DECODE;
|
|
1520
1359
|
}
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
Decoder3.prototype.readArraySize = function() {
|
|
1535
|
-
var headByte = this.readHeadByte();
|
|
1536
|
-
switch (headByte) {
|
|
1537
|
-
case 220:
|
|
1538
|
-
return this.readU16();
|
|
1539
|
-
case 221:
|
|
1540
|
-
return this.readU32();
|
|
1541
|
-
default: {
|
|
1542
|
-
if (headByte < 160) {
|
|
1543
|
-
return headByte - 144;
|
|
1360
|
+
} else if (state.type === STATE_MAP_KEY) {
|
|
1361
|
+
if (object === "__proto__") {
|
|
1362
|
+
throw new DecodeError("The key __proto__ is not allowed");
|
|
1363
|
+
}
|
|
1364
|
+
state.key = this.mapKeyConverter(object);
|
|
1365
|
+
state.type = STATE_MAP_VALUE;
|
|
1366
|
+
continue DECODE;
|
|
1367
|
+
} else {
|
|
1368
|
+
state.map[state.key] = object;
|
|
1369
|
+
state.readCount++;
|
|
1370
|
+
if (state.readCount === state.size) {
|
|
1371
|
+
object = state.map;
|
|
1372
|
+
stack.release(state);
|
|
1544
1373
|
} else {
|
|
1545
|
-
|
|
1374
|
+
state.key = null;
|
|
1375
|
+
state.type = STATE_MAP_KEY;
|
|
1376
|
+
continue DECODE;
|
|
1546
1377
|
}
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
};
|
|
1550
|
-
Decoder3.prototype.pushMapState = function(size) {
|
|
1551
|
-
if (size > this.maxMapLength) {
|
|
1552
|
-
throw new DecodeError("Max length exceeded: map length (".concat(size, ") > maxMapLengthLength (").concat(this.maxMapLength, ")"));
|
|
1553
|
-
}
|
|
1554
|
-
this.stack.push({
|
|
1555
|
-
type: STATE_MAP_KEY,
|
|
1556
|
-
size,
|
|
1557
|
-
key: null,
|
|
1558
|
-
readCount: 0,
|
|
1559
|
-
map: {}
|
|
1560
|
-
});
|
|
1561
|
-
};
|
|
1562
|
-
Decoder3.prototype.pushArrayState = function(size) {
|
|
1563
|
-
if (size > this.maxArrayLength) {
|
|
1564
|
-
throw new DecodeError("Max length exceeded: array length (".concat(size, ") > maxArrayLength (").concat(this.maxArrayLength, ")"));
|
|
1565
|
-
}
|
|
1566
|
-
this.stack.push({
|
|
1567
|
-
type: STATE_ARRAY,
|
|
1568
|
-
size,
|
|
1569
|
-
array: new Array(size),
|
|
1570
|
-
position: 0
|
|
1571
|
-
});
|
|
1572
|
-
};
|
|
1573
|
-
Decoder3.prototype.decodeUtf8String = function(byteLength, headerOffset) {
|
|
1574
|
-
var _a;
|
|
1575
|
-
if (byteLength > this.maxStrLength) {
|
|
1576
|
-
throw new DecodeError("Max length exceeded: UTF-8 byte length (".concat(byteLength, ") > maxStrLength (").concat(this.maxStrLength, ")"));
|
|
1577
|
-
}
|
|
1578
|
-
if (this.bytes.byteLength < this.pos + headerOffset + byteLength) {
|
|
1579
|
-
throw MORE_DATA;
|
|
1580
|
-
}
|
|
1581
|
-
var offset2 = this.pos + headerOffset;
|
|
1582
|
-
var object;
|
|
1583
|
-
if (this.stateIsMapKey() && ((_a = this.keyDecoder) === null || _a === void 0 ? void 0 : _a.canBeCached(byteLength))) {
|
|
1584
|
-
object = this.keyDecoder.decode(this.bytes, offset2, byteLength);
|
|
1585
|
-
} else {
|
|
1586
|
-
object = utf8Decode(this.bytes, offset2, byteLength);
|
|
1587
|
-
}
|
|
1588
|
-
this.pos += headerOffset + byteLength;
|
|
1589
|
-
return object;
|
|
1590
|
-
};
|
|
1591
|
-
Decoder3.prototype.stateIsMapKey = function() {
|
|
1592
|
-
if (this.stack.length > 0) {
|
|
1593
|
-
var state = this.stack[this.stack.length - 1];
|
|
1594
|
-
return state.type === STATE_MAP_KEY;
|
|
1595
|
-
}
|
|
1596
|
-
return false;
|
|
1597
|
-
};
|
|
1598
|
-
Decoder3.prototype.decodeBinary = function(byteLength, headOffset) {
|
|
1599
|
-
if (byteLength > this.maxBinLength) {
|
|
1600
|
-
throw new DecodeError("Max length exceeded: bin length (".concat(byteLength, ") > maxBinLength (").concat(this.maxBinLength, ")"));
|
|
1601
|
-
}
|
|
1602
|
-
if (!this.hasRemaining(byteLength + headOffset)) {
|
|
1603
|
-
throw MORE_DATA;
|
|
1378
|
+
}
|
|
1604
1379
|
}
|
|
1605
|
-
var offset2 = this.pos + headOffset;
|
|
1606
|
-
var object = this.bytes.subarray(offset2, offset2 + byteLength);
|
|
1607
|
-
this.pos += headOffset + byteLength;
|
|
1608
1380
|
return object;
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
readHeadByte() {
|
|
1384
|
+
if (this.headByte === HEAD_BYTE_REQUIRED) {
|
|
1385
|
+
this.headByte = this.readU8();
|
|
1386
|
+
}
|
|
1387
|
+
return this.headByte;
|
|
1388
|
+
}
|
|
1389
|
+
complete() {
|
|
1390
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
1391
|
+
}
|
|
1392
|
+
readArraySize() {
|
|
1393
|
+
const headByte = this.readHeadByte();
|
|
1394
|
+
switch (headByte) {
|
|
1395
|
+
case 220:
|
|
1396
|
+
return this.readU16();
|
|
1397
|
+
case 221:
|
|
1398
|
+
return this.readU32();
|
|
1399
|
+
default: {
|
|
1400
|
+
if (headByte < 160) {
|
|
1401
|
+
return headByte - 144;
|
|
1402
|
+
} else {
|
|
1403
|
+
throw new DecodeError(`Unrecognized array type byte: ${prettyByte(headByte)}`);
|
|
1404
|
+
}
|
|
1613
1405
|
}
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
}
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
this.
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
pushMapState(size) {
|
|
1409
|
+
if (size > this.maxMapLength) {
|
|
1410
|
+
throw new DecodeError(`Max length exceeded: map length (${size}) > maxMapLengthLength (${this.maxMapLength})`);
|
|
1411
|
+
}
|
|
1412
|
+
this.stack.pushMapState(size);
|
|
1413
|
+
}
|
|
1414
|
+
pushArrayState(size) {
|
|
1415
|
+
if (size > this.maxArrayLength) {
|
|
1416
|
+
throw new DecodeError(`Max length exceeded: array length (${size}) > maxArrayLength (${this.maxArrayLength})`);
|
|
1417
|
+
}
|
|
1418
|
+
this.stack.pushArrayState(size);
|
|
1419
|
+
}
|
|
1420
|
+
decodeString(byteLength, headerOffset) {
|
|
1421
|
+
if (!this.rawStrings || this.stateIsMapKey()) {
|
|
1422
|
+
return this.decodeUtf8String(byteLength, headerOffset);
|
|
1423
|
+
}
|
|
1424
|
+
return this.decodeBinary(byteLength, headerOffset);
|
|
1425
|
+
}
|
|
1426
|
+
/**
|
|
1427
|
+
* @throws {@link RangeError}
|
|
1428
|
+
*/
|
|
1429
|
+
decodeUtf8String(byteLength, headerOffset) {
|
|
1430
|
+
if (byteLength > this.maxStrLength) {
|
|
1431
|
+
throw new DecodeError(`Max length exceeded: UTF-8 byte length (${byteLength}) > maxStrLength (${this.maxStrLength})`);
|
|
1432
|
+
}
|
|
1433
|
+
if (this.bytes.byteLength < this.pos + headerOffset + byteLength) {
|
|
1434
|
+
throw MORE_DATA;
|
|
1435
|
+
}
|
|
1436
|
+
const offset2 = this.pos + headerOffset;
|
|
1437
|
+
let object;
|
|
1438
|
+
if (this.stateIsMapKey() && this.keyDecoder?.canBeCached(byteLength)) {
|
|
1439
|
+
object = this.keyDecoder.decode(this.bytes, offset2, byteLength);
|
|
1440
|
+
} else {
|
|
1441
|
+
object = utf8Decode(this.bytes, offset2, byteLength);
|
|
1442
|
+
}
|
|
1443
|
+
this.pos += headerOffset + byteLength;
|
|
1444
|
+
return object;
|
|
1445
|
+
}
|
|
1446
|
+
stateIsMapKey() {
|
|
1447
|
+
if (this.stack.length > 0) {
|
|
1448
|
+
const state = this.stack.top();
|
|
1449
|
+
return state.type === STATE_MAP_KEY;
|
|
1450
|
+
}
|
|
1451
|
+
return false;
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* @throws {@link RangeError}
|
|
1455
|
+
*/
|
|
1456
|
+
decodeBinary(byteLength, headOffset) {
|
|
1457
|
+
if (byteLength > this.maxBinLength) {
|
|
1458
|
+
throw new DecodeError(`Max length exceeded: bin length (${byteLength}) > maxBinLength (${this.maxBinLength})`);
|
|
1459
|
+
}
|
|
1460
|
+
if (!this.hasRemaining(byteLength + headOffset)) {
|
|
1461
|
+
throw MORE_DATA;
|
|
1462
|
+
}
|
|
1463
|
+
const offset2 = this.pos + headOffset;
|
|
1464
|
+
const object = this.bytes.subarray(offset2, offset2 + byteLength);
|
|
1465
|
+
this.pos += headOffset + byteLength;
|
|
1466
|
+
return object;
|
|
1467
|
+
}
|
|
1468
|
+
decodeExtension(size, headOffset) {
|
|
1469
|
+
if (size > this.maxExtLength) {
|
|
1470
|
+
throw new DecodeError(`Max length exceeded: ext length (${size}) > maxExtLength (${this.maxExtLength})`);
|
|
1471
|
+
}
|
|
1472
|
+
const extType = this.view.getInt8(this.pos + headOffset);
|
|
1473
|
+
const data = this.decodeBinary(
|
|
1474
|
+
size,
|
|
1475
|
+
headOffset + 1
|
|
1476
|
+
/* extType */
|
|
1477
|
+
);
|
|
1478
|
+
return this.extensionCodec.decode(data, extType, this.context);
|
|
1479
|
+
}
|
|
1480
|
+
lookU8() {
|
|
1481
|
+
return this.view.getUint8(this.pos);
|
|
1482
|
+
}
|
|
1483
|
+
lookU16() {
|
|
1484
|
+
return this.view.getUint16(this.pos);
|
|
1485
|
+
}
|
|
1486
|
+
lookU32() {
|
|
1487
|
+
return this.view.getUint32(this.pos);
|
|
1488
|
+
}
|
|
1489
|
+
readU8() {
|
|
1490
|
+
const value = this.view.getUint8(this.pos);
|
|
1491
|
+
this.pos++;
|
|
1492
|
+
return value;
|
|
1493
|
+
}
|
|
1494
|
+
readI8() {
|
|
1495
|
+
const value = this.view.getInt8(this.pos);
|
|
1496
|
+
this.pos++;
|
|
1497
|
+
return value;
|
|
1498
|
+
}
|
|
1499
|
+
readU16() {
|
|
1500
|
+
const value = this.view.getUint16(this.pos);
|
|
1501
|
+
this.pos += 2;
|
|
1502
|
+
return value;
|
|
1503
|
+
}
|
|
1504
|
+
readI16() {
|
|
1505
|
+
const value = this.view.getInt16(this.pos);
|
|
1506
|
+
this.pos += 2;
|
|
1507
|
+
return value;
|
|
1508
|
+
}
|
|
1509
|
+
readU32() {
|
|
1510
|
+
const value = this.view.getUint32(this.pos);
|
|
1511
|
+
this.pos += 4;
|
|
1512
|
+
return value;
|
|
1513
|
+
}
|
|
1514
|
+
readI32() {
|
|
1515
|
+
const value = this.view.getInt32(this.pos);
|
|
1516
|
+
this.pos += 4;
|
|
1517
|
+
return value;
|
|
1518
|
+
}
|
|
1519
|
+
readU64() {
|
|
1520
|
+
const value = getUint64(this.view, this.pos);
|
|
1521
|
+
this.pos += 8;
|
|
1522
|
+
return value;
|
|
1523
|
+
}
|
|
1524
|
+
readI64() {
|
|
1525
|
+
const value = getInt64(this.view, this.pos);
|
|
1526
|
+
this.pos += 8;
|
|
1527
|
+
return value;
|
|
1528
|
+
}
|
|
1529
|
+
readU64AsBigInt() {
|
|
1530
|
+
const value = this.view.getBigUint64(this.pos);
|
|
1531
|
+
this.pos += 8;
|
|
1532
|
+
return value;
|
|
1533
|
+
}
|
|
1534
|
+
readI64AsBigInt() {
|
|
1535
|
+
const value = this.view.getBigInt64(this.pos);
|
|
1536
|
+
this.pos += 8;
|
|
1537
|
+
return value;
|
|
1538
|
+
}
|
|
1539
|
+
readF32() {
|
|
1540
|
+
const value = this.view.getFloat32(this.pos);
|
|
1541
|
+
this.pos += 4;
|
|
1542
|
+
return value;
|
|
1543
|
+
}
|
|
1544
|
+
readF64() {
|
|
1545
|
+
const value = this.view.getFloat64(this.pos);
|
|
1546
|
+
this.pos += 8;
|
|
1547
|
+
return value;
|
|
1548
|
+
}
|
|
1549
|
+
};
|
|
1694
1550
|
|
|
1695
|
-
// node_modules/@msgpack/msgpack/dist.
|
|
1551
|
+
// ../node_modules/.bun/@msgpack+msgpack@3.1.3/node_modules/@msgpack/msgpack/dist.esm/decode.mjs
|
|
1696
1552
|
function decode(buffer, options) {
|
|
1697
|
-
|
|
1553
|
+
const decoder = new Decoder(options);
|
|
1698
1554
|
return decoder.decode(buffer);
|
|
1699
1555
|
}
|
|
1700
1556
|
|
|
1701
1557
|
// src/client.ts
|
|
1702
1558
|
var import_file_saver = __toESM(require_FileSaver_min(), 1);
|
|
1703
1559
|
|
|
1704
|
-
// node_modules/libsodium.js/dist/modules/libsodium-esm-wrappers.js
|
|
1560
|
+
// ../node_modules/.bun/libsodium-wrappers@git+ssh+++github.com+interncom+libsodium.js+e4e764777860213b5cbea520048847ea0a5cb6be/node_modules/libsodium-wrappers/dist/modules/libsodium-esm-wrappers.js
|
|
1705
1561
|
var libsodium_esm_wrappers_exports = {};
|
|
1706
1562
|
__export(libsodium_esm_wrappers_exports, {
|
|
1707
1563
|
AllocatedBuf: () => AllocatedBuf,
|
|
@@ -2203,7 +2059,7 @@ __export(libsodium_esm_wrappers_exports, {
|
|
|
2203
2059
|
unpad: () => unpad
|
|
2204
2060
|
});
|
|
2205
2061
|
|
|
2206
|
-
// node_modules/libsodium.js/dist/modules/libsodium.esm.js
|
|
2062
|
+
// ../node_modules/.bun/libsodium-wrappers@git+ssh+++github.com+interncom+libsodium.js+e4e764777860213b5cbea520048847ea0a5cb6be/node_modules/libsodium-wrappers/dist/modules/libsodium.esm.js
|
|
2207
2063
|
var Module = (() => {
|
|
2208
2064
|
var _scriptName = import.meta.url;
|
|
2209
2065
|
return function(moduleArg = {}) {
|
|
@@ -2854,7 +2710,7 @@ var Module = (() => {
|
|
|
2854
2710
|
})();
|
|
2855
2711
|
var libsodium_esm_default = Module;
|
|
2856
2712
|
|
|
2857
|
-
// node_modules/libsodium.js/dist/modules/libsodium-esm-wrappers.js
|
|
2713
|
+
// ../node_modules/.bun/libsodium-wrappers@git+ssh+++github.com+interncom+libsodium.js+e4e764777860213b5cbea520048847ea0a5cb6be/node_modules/libsodium-wrappers/dist/modules/libsodium-esm-wrappers.js
|
|
2858
2714
|
var output_format = "uint8array";
|
|
2859
2715
|
var libsodium = await libsodium_esm_default();
|
|
2860
2716
|
if (libsodium._sodium_init() !== 0) {
|
|
@@ -8091,13 +7947,6 @@ var Status = /* @__PURE__ */ ((Status2) => {
|
|
|
8091
7947
|
Status2[Status2["ConnectionClosed"] = 28] = "ConnectionClosed";
|
|
8092
7948
|
return Status2;
|
|
8093
7949
|
})(Status || {});
|
|
8094
|
-
var APICallName = /* @__PURE__ */ ((APICallName2) => {
|
|
8095
|
-
APICallName2[APICallName2["User"] = 0] = "User";
|
|
8096
|
-
APICallName2[APICallName2["Peek"] = 1] = "Peek";
|
|
8097
|
-
APICallName2[APICallName2["Push"] = 2] = "Push";
|
|
8098
|
-
APICallName2[APICallName2["Pull"] = 3] = "Pull";
|
|
8099
|
-
return APICallName2;
|
|
8100
|
-
})(APICallName || {});
|
|
8101
7950
|
|
|
8102
7951
|
// ../shared/valstat.ts
|
|
8103
7952
|
function ok(val) {
|
|
@@ -8939,7 +8788,7 @@ var userEnd = {
|
|
|
8939
8788
|
return 0 /* Success */;
|
|
8940
8789
|
},
|
|
8941
8790
|
decodeResp(_respDec) {
|
|
8942
|
-
return
|
|
8791
|
+
return ok(void 0);
|
|
8943
8792
|
}
|
|
8944
8793
|
};
|
|
8945
8794
|
|
|
@@ -8973,7 +8822,7 @@ var WebsocketListener = class {
|
|
|
8973
8822
|
recv(bytes);
|
|
8974
8823
|
};
|
|
8975
8824
|
this.websocket.onerror = (e) => {
|
|
8976
|
-
console.log(`ERROR: ${e}`);
|
|
8825
|
+
console.log(`ERROR: ${JSON.stringify(e)}`);
|
|
8977
8826
|
};
|
|
8978
8827
|
return Promise.resolve(0 /* Success */);
|
|
8979
8828
|
}
|
|
@@ -9035,6 +8884,9 @@ var HTTPTransport = class {
|
|
|
9035
8884
|
}
|
|
9036
8885
|
}
|
|
9037
8886
|
};
|
|
8887
|
+
var hostHTTPTransport = (host) => {
|
|
8888
|
+
return new HTTPTransport(host.handle);
|
|
8889
|
+
};
|
|
9038
8890
|
async function post(url, enc) {
|
|
9039
8891
|
const response = await fetch(url, {
|
|
9040
8892
|
method: "POST",
|
|
@@ -9097,10 +8949,6 @@ var DiplomaticClientAPI = class {
|
|
|
9097
8949
|
return err(statMeta);
|
|
9098
8950
|
}
|
|
9099
8951
|
const respVS = endpoint.decodeResp(dec);
|
|
9100
|
-
console.info(`API call: ${APICallName[name]}`, {
|
|
9101
|
-
req: items,
|
|
9102
|
-
resp: respVS
|
|
9103
|
-
});
|
|
9104
8952
|
return respVS;
|
|
9105
8953
|
}
|
|
9106
8954
|
keys = () => {
|
|
@@ -9345,7 +9193,7 @@ async function genUpsertHead({ now, eid, ctr, bod, crypto }) {
|
|
|
9345
9193
|
return ok({ eid, off, ctr, len, hsh });
|
|
9346
9194
|
}
|
|
9347
9195
|
|
|
9348
|
-
//
|
|
9196
|
+
// ../shared/sync.ts
|
|
9349
9197
|
async function decryptPeekItem(item, hostKeys2, enclave, crypto) {
|
|
9350
9198
|
const dec = new Decoder2(item.headCph);
|
|
9351
9199
|
const [peekItem, readStatus] = dec.readStruct(peekItemHeadCodec);
|
|
@@ -9370,6 +9218,8 @@ async function decryptPeekItem(item, hostKeys2, enclave, crypto) {
|
|
|
9370
9218
|
}
|
|
9371
9219
|
return ok({ kdm, headEnc });
|
|
9372
9220
|
}
|
|
9221
|
+
|
|
9222
|
+
// src/sync.ts
|
|
9373
9223
|
async function syncPeek({ conn, store, enclave, host, crypto }) {
|
|
9374
9224
|
const hostKeys2 = await conn.keys();
|
|
9375
9225
|
const dls = [];
|
|
@@ -9920,57 +9770,59 @@ var SyncClient = class {
|
|
|
9920
9770
|
return 0 /* Success */;
|
|
9921
9771
|
}
|
|
9922
9772
|
// Manage stored host connections.
|
|
9923
|
-
async link(host) {
|
|
9773
|
+
async link(host, connect = true) {
|
|
9924
9774
|
this.store.hosts.add(host);
|
|
9925
9775
|
this.clientState.emit();
|
|
9776
|
+
if (connect) {
|
|
9777
|
+
const row = await this.store.hosts.get(host.label);
|
|
9778
|
+
if (row) {
|
|
9779
|
+
this.connectToHost(row);
|
|
9780
|
+
}
|
|
9781
|
+
}
|
|
9926
9782
|
}
|
|
9927
9783
|
async unlink(label) {
|
|
9928
9784
|
await this.store.hosts.del(label);
|
|
9929
9785
|
this.clientState.emit();
|
|
9930
9786
|
}
|
|
9787
|
+
connectToHost = async (host, listen = true, sync = true) => {
|
|
9788
|
+
const { clock, connections, crypto, store, transport } = this;
|
|
9789
|
+
if (connections.has(host.label)) return;
|
|
9790
|
+
const enclave = await store.seed.load();
|
|
9791
|
+
if (!enclave) return;
|
|
9792
|
+
console.info(`Connecting to ${host.handle} (${host.label})`);
|
|
9793
|
+
const conn = new DiplomaticClientAPI(
|
|
9794
|
+
enclave,
|
|
9795
|
+
crypto_default,
|
|
9796
|
+
host,
|
|
9797
|
+
clock,
|
|
9798
|
+
transport(host),
|
|
9799
|
+
(meta) => store.hosts.set(host.label, meta)
|
|
9800
|
+
);
|
|
9801
|
+
await conn.register();
|
|
9802
|
+
if (listen) {
|
|
9803
|
+
await conn.listen(async (bytes) => {
|
|
9804
|
+
const syncParams = { conn, store, enclave, host, crypto, clock };
|
|
9805
|
+
return handleNotif(bytes, syncParams, this.apply, this.scheduleSync);
|
|
9806
|
+
});
|
|
9807
|
+
}
|
|
9808
|
+
connections.set(host.label, conn);
|
|
9809
|
+
if (sync) {
|
|
9810
|
+
this.scheduleSync();
|
|
9811
|
+
}
|
|
9812
|
+
};
|
|
9931
9813
|
// Manage active host connections.
|
|
9932
|
-
async connect(listen = true) {
|
|
9933
|
-
const {
|
|
9814
|
+
async connect(listen = true, sync = true) {
|
|
9815
|
+
const { connectToHost, scheduleSync, store } = this;
|
|
9934
9816
|
const enclave = await store.seed.load();
|
|
9935
9817
|
if (!enclave) {
|
|
9936
9818
|
return;
|
|
9937
9819
|
}
|
|
9938
9820
|
const hosts = await store.hosts.list();
|
|
9939
9821
|
for (const host of hosts) {
|
|
9940
|
-
|
|
9941
|
-
|
|
9942
|
-
|
|
9943
|
-
|
|
9944
|
-
console.info(`Connecting to ${host.handle} (${label})`);
|
|
9945
|
-
const txport = transport(host);
|
|
9946
|
-
const conn = new DiplomaticClientAPI(
|
|
9947
|
-
enclave,
|
|
9948
|
-
crypto_default,
|
|
9949
|
-
host,
|
|
9950
|
-
clock,
|
|
9951
|
-
txport,
|
|
9952
|
-
(meta) => this.store.hosts.set(label, meta)
|
|
9953
|
-
);
|
|
9954
|
-
await conn.register();
|
|
9955
|
-
if (listen) {
|
|
9956
|
-
const recv = async (bytes) => {
|
|
9957
|
-
handleNotif(
|
|
9958
|
-
bytes,
|
|
9959
|
-
{
|
|
9960
|
-
conn,
|
|
9961
|
-
store,
|
|
9962
|
-
enclave,
|
|
9963
|
-
host,
|
|
9964
|
-
crypto,
|
|
9965
|
-
clock
|
|
9966
|
-
},
|
|
9967
|
-
this.apply,
|
|
9968
|
-
this.scheduleSync
|
|
9969
|
-
);
|
|
9970
|
-
};
|
|
9971
|
-
await conn.listen(recv);
|
|
9972
|
-
}
|
|
9973
|
-
this.connections.set(host.label, conn);
|
|
9822
|
+
await connectToHost(host, listen, false);
|
|
9823
|
+
}
|
|
9824
|
+
if (sync) {
|
|
9825
|
+
scheduleSync();
|
|
9974
9826
|
}
|
|
9975
9827
|
}
|
|
9976
9828
|
disconnect = async () => {
|
|
@@ -10116,7 +9968,7 @@ function applyOp(curr, op) {
|
|
|
10116
9968
|
}
|
|
10117
9969
|
var nullEntDB = {
|
|
10118
9970
|
getEnt: async () => err(21 /* NotImplemented */),
|
|
10119
|
-
getEntities: async () => err(21 /* NotImplemented */),
|
|
9971
|
+
getEntities: async (_query) => err(21 /* NotImplemented */),
|
|
10120
9972
|
countEntities: async () => err(21 /* NotImplemented */),
|
|
10121
9973
|
apply: async (ops) => ({
|
|
10122
9974
|
stats: ops.map(() => 21 /* NotImplemented */),
|
|
@@ -10373,16 +10225,16 @@ var EntIDB = class {
|
|
|
10373
10225
|
req.onerror = () => resolve(err(18 /* DatabaseError */));
|
|
10374
10226
|
});
|
|
10375
10227
|
}
|
|
10376
|
-
async getAllEntities(
|
|
10228
|
+
async getAllEntities(query) {
|
|
10377
10229
|
if (!this.db) {
|
|
10378
10230
|
return err(16 /* DatabaseClosed */);
|
|
10379
10231
|
}
|
|
10380
|
-
if (pid
|
|
10381
|
-
const pidB64 = btob64(pid);
|
|
10232
|
+
if ("pid" in query) {
|
|
10233
|
+
const pidB64 = btob64(query.pid);
|
|
10382
10234
|
const tx = this.db.transaction(entityTableName, "readonly");
|
|
10383
10235
|
const index = tx.objectStore(entityTableName).index(typeParentIndexName);
|
|
10384
10236
|
return new Promise((resolve) => {
|
|
10385
|
-
const req = index.getAll(IDBKeyRange.only([type, pidB64]));
|
|
10237
|
+
const req = index.getAll(IDBKeyRange.only([query.type, pidB64]));
|
|
10386
10238
|
req.onsuccess = () => {
|
|
10387
10239
|
const storedEnts = req.result;
|
|
10388
10240
|
const ents = storedEnts.map(storedToEntity);
|
|
@@ -10390,16 +10242,16 @@ var EntIDB = class {
|
|
|
10390
10242
|
};
|
|
10391
10243
|
req.onerror = () => resolve(err(18 /* DatabaseError */));
|
|
10392
10244
|
});
|
|
10393
|
-
} else if (gid
|
|
10394
|
-
return await this.getGroupMembers(type, gid);
|
|
10395
|
-
} else if (updatedBetween
|
|
10245
|
+
} else if ("gid" in query) {
|
|
10246
|
+
return await this.getGroupMembers(query.type, query.gid);
|
|
10247
|
+
} else if ("updatedBetween" in query) {
|
|
10396
10248
|
return await this.getAllOfTypeUpdatedBetween(
|
|
10397
|
-
type,
|
|
10398
|
-
updatedBetween.start,
|
|
10399
|
-
updatedBetween.end
|
|
10249
|
+
query.type,
|
|
10250
|
+
query.updatedBetween.start,
|
|
10251
|
+
query.updatedBetween.end
|
|
10400
10252
|
);
|
|
10401
10253
|
}
|
|
10402
|
-
return await this.getAllOfType(type);
|
|
10254
|
+
return await this.getAllOfType(query.type);
|
|
10403
10255
|
}
|
|
10404
10256
|
async getEntities(query) {
|
|
10405
10257
|
const [ents, stat] = await this.getAllEntities(query);
|
|
@@ -10422,6 +10274,11 @@ var EntIDB = class {
|
|
|
10422
10274
|
});
|
|
10423
10275
|
}
|
|
10424
10276
|
};
|
|
10277
|
+
async function openEntIDB() {
|
|
10278
|
+
const entDB = new EntIDB();
|
|
10279
|
+
await entDB.init();
|
|
10280
|
+
return entDB;
|
|
10281
|
+
}
|
|
10425
10282
|
|
|
10426
10283
|
// src/entdb/memory.ts
|
|
10427
10284
|
var EntDBMemory = class {
|
|
@@ -10515,79 +10372,6 @@ var EntDBMemory = class {
|
|
|
10515
10372
|
|
|
10516
10373
|
// src/react/useClient.ts
|
|
10517
10374
|
import { useEffect, useState } from "react";
|
|
10518
|
-
function useClientState(client) {
|
|
10519
|
-
const [state, setState] = useState();
|
|
10520
|
-
useEffect(() => {
|
|
10521
|
-
async function updateState() {
|
|
10522
|
-
const state2 = await client.clientState.get();
|
|
10523
|
-
setState(state2);
|
|
10524
|
-
}
|
|
10525
|
-
const unsubscribe = client.clientState.listen(updateState);
|
|
10526
|
-
updateState();
|
|
10527
|
-
return () => {
|
|
10528
|
-
unsubscribe();
|
|
10529
|
-
};
|
|
10530
|
-
}, [client]);
|
|
10531
|
-
return state;
|
|
10532
|
-
}
|
|
10533
|
-
function useClientXferState(client) {
|
|
10534
|
-
const [state, setState] = useState();
|
|
10535
|
-
useEffect(() => {
|
|
10536
|
-
async function updateState() {
|
|
10537
|
-
const state2 = await client.xferState.get();
|
|
10538
|
-
setState(state2);
|
|
10539
|
-
}
|
|
10540
|
-
const unsubscribe = client.xferState.listen(updateState);
|
|
10541
|
-
updateState();
|
|
10542
|
-
return () => {
|
|
10543
|
-
unsubscribe();
|
|
10544
|
-
};
|
|
10545
|
-
}, [client]);
|
|
10546
|
-
return state;
|
|
10547
|
-
}
|
|
10548
|
-
function useSyncOnResume(client) {
|
|
10549
|
-
useEffect(() => {
|
|
10550
|
-
async function handleOnline() {
|
|
10551
|
-
await client.connect();
|
|
10552
|
-
await client.sync();
|
|
10553
|
-
}
|
|
10554
|
-
globalThis.addEventListener("online", handleOnline);
|
|
10555
|
-
return () => {
|
|
10556
|
-
globalThis.removeEventListener("online", handleOnline);
|
|
10557
|
-
};
|
|
10558
|
-
}, [client]);
|
|
10559
|
-
}
|
|
10560
|
-
|
|
10561
|
-
// src/react/useStateWatcher.ts
|
|
10562
|
-
import { use, useEffect as useEffect2, useRef, useState as useState2 } from "react";
|
|
10563
|
-
function useStateWatcher(mgr, opType, callback) {
|
|
10564
|
-
const [val, setVal] = useState2();
|
|
10565
|
-
useEffect2(() => {
|
|
10566
|
-
async function update() {
|
|
10567
|
-
const newVal = await callback();
|
|
10568
|
-
setVal(newVal);
|
|
10569
|
-
}
|
|
10570
|
-
update();
|
|
10571
|
-
mgr.on(opType, update);
|
|
10572
|
-
return () => {
|
|
10573
|
-
mgr.off(opType, update);
|
|
10574
|
-
};
|
|
10575
|
-
}, [mgr, opType, callback]);
|
|
10576
|
-
return val;
|
|
10577
|
-
}
|
|
10578
|
-
function useStateWatcherSuspense(mgr, opType, callback) {
|
|
10579
|
-
const promiseRef = useRef(callback());
|
|
10580
|
-
useEffect2(() => {
|
|
10581
|
-
async function update() {
|
|
10582
|
-
promiseRef.current = callback();
|
|
10583
|
-
}
|
|
10584
|
-
mgr.on(opType, update);
|
|
10585
|
-
return () => {
|
|
10586
|
-
mgr.off(opType, update);
|
|
10587
|
-
};
|
|
10588
|
-
}, [mgr, opType, callback]);
|
|
10589
|
-
return use(promiseRef.current);
|
|
10590
|
-
}
|
|
10591
10375
|
|
|
10592
10376
|
// src/stores/idb/dnlds.ts
|
|
10593
10377
|
var IDBDownloadQueue = class {
|
|
@@ -11086,7 +10870,7 @@ var IDBStore = class {
|
|
|
11086
10870
|
await this.messages.wipe();
|
|
11087
10871
|
}
|
|
11088
10872
|
};
|
|
11089
|
-
async function
|
|
10873
|
+
async function openIDBStoreDB() {
|
|
11090
10874
|
return new Promise((resolve, reject) => {
|
|
11091
10875
|
const req = indexedDB.open("diplomatic-store-db", 2);
|
|
11092
10876
|
req.onupgradeneeded = () => {
|
|
@@ -11115,6 +10899,104 @@ async function openIDBStore() {
|
|
|
11115
10899
|
req.onerror = () => reject(req.error);
|
|
11116
10900
|
});
|
|
11117
10901
|
}
|
|
10902
|
+
async function openIDBStore(crypto) {
|
|
10903
|
+
const db = await openIDBStoreDB();
|
|
10904
|
+
return new IDBStore(db, crypto);
|
|
10905
|
+
}
|
|
10906
|
+
|
|
10907
|
+
// src/react/useClient.ts
|
|
10908
|
+
function useClientState(client) {
|
|
10909
|
+
const [state, setState] = useState();
|
|
10910
|
+
useEffect(() => {
|
|
10911
|
+
async function updateState() {
|
|
10912
|
+
const state2 = await client.clientState.get();
|
|
10913
|
+
setState(state2);
|
|
10914
|
+
}
|
|
10915
|
+
const unsubscribe = client.clientState.listen(updateState);
|
|
10916
|
+
updateState();
|
|
10917
|
+
return () => {
|
|
10918
|
+
unsubscribe();
|
|
10919
|
+
};
|
|
10920
|
+
}, [client]);
|
|
10921
|
+
return state;
|
|
10922
|
+
}
|
|
10923
|
+
function useClientXferState(client) {
|
|
10924
|
+
const [state, setState] = useState();
|
|
10925
|
+
useEffect(() => {
|
|
10926
|
+
async function updateState() {
|
|
10927
|
+
const state2 = await client.xferState.get();
|
|
10928
|
+
setState(state2);
|
|
10929
|
+
}
|
|
10930
|
+
const unsubscribe = client.xferState.listen(updateState);
|
|
10931
|
+
updateState();
|
|
10932
|
+
return () => {
|
|
10933
|
+
unsubscribe();
|
|
10934
|
+
};
|
|
10935
|
+
}, [client]);
|
|
10936
|
+
return state;
|
|
10937
|
+
}
|
|
10938
|
+
function useSyncOnResume(client) {
|
|
10939
|
+
useEffect(() => {
|
|
10940
|
+
async function handleOnline() {
|
|
10941
|
+
await client.connect();
|
|
10942
|
+
await client.sync();
|
|
10943
|
+
}
|
|
10944
|
+
globalThis.addEventListener("online", handleOnline);
|
|
10945
|
+
return () => {
|
|
10946
|
+
globalThis.removeEventListener("online", handleOnline);
|
|
10947
|
+
};
|
|
10948
|
+
}, [client]);
|
|
10949
|
+
}
|
|
10950
|
+
function useClient({ clock = new Clock(), seed, host }) {
|
|
10951
|
+
const [diplomaticState, setDiplomaticState] = useState({ stateMgr: nullStateManager });
|
|
10952
|
+
useEffect(() => {
|
|
10953
|
+
Promise.all([openIDBStore(crypto_default), openEntIDB()]).then(
|
|
10954
|
+
async ([store, entDB]) => {
|
|
10955
|
+
const entMgr = entStateManager(entDB);
|
|
10956
|
+
const client = new SyncClient(clock, entMgr, store, hostHTTPTransport);
|
|
10957
|
+
if (seed) {
|
|
10958
|
+
await client.setSeed(seed);
|
|
10959
|
+
}
|
|
10960
|
+
if (host) {
|
|
10961
|
+
await client.link(host);
|
|
10962
|
+
}
|
|
10963
|
+
setDiplomaticState({ client, entDB, stateMgr: entMgr });
|
|
10964
|
+
}
|
|
10965
|
+
);
|
|
10966
|
+
}, [clock, seed]);
|
|
10967
|
+
return diplomaticState;
|
|
10968
|
+
}
|
|
10969
|
+
|
|
10970
|
+
// src/react/useStateWatcher.ts
|
|
10971
|
+
import { use, useEffect as useEffect2, useRef, useState as useState2 } from "react";
|
|
10972
|
+
function useStateWatcher(mgr, opType, callback) {
|
|
10973
|
+
const [val, setVal] = useState2();
|
|
10974
|
+
useEffect2(() => {
|
|
10975
|
+
async function update() {
|
|
10976
|
+
const newVal = await callback();
|
|
10977
|
+
setVal(newVal);
|
|
10978
|
+
}
|
|
10979
|
+
update();
|
|
10980
|
+
mgr.on(opType, update);
|
|
10981
|
+
return () => {
|
|
10982
|
+
mgr.off(opType, update);
|
|
10983
|
+
};
|
|
10984
|
+
}, [mgr, opType, callback]);
|
|
10985
|
+
return val;
|
|
10986
|
+
}
|
|
10987
|
+
function useStateWatcherSuspense(mgr, opType, callback) {
|
|
10988
|
+
const promiseRef = useRef(callback());
|
|
10989
|
+
useEffect2(() => {
|
|
10990
|
+
async function update() {
|
|
10991
|
+
promiseRef.current = callback();
|
|
10992
|
+
}
|
|
10993
|
+
mgr.on(opType, update);
|
|
10994
|
+
return () => {
|
|
10995
|
+
mgr.off(opType, update);
|
|
10996
|
+
};
|
|
10997
|
+
}, [mgr, opType, callback]);
|
|
10998
|
+
return use(promiseRef.current);
|
|
10999
|
+
}
|
|
11118
11000
|
|
|
11119
11001
|
// src/stores/memory/dnlds.ts
|
|
11120
11002
|
function keyFor(host, seq) {
|
|
@@ -11327,18 +11209,13 @@ var MemoryStore = class {
|
|
|
11327
11209
|
};
|
|
11328
11210
|
|
|
11329
11211
|
// src/index.ts
|
|
11330
|
-
var hostHTTPTransport = (host) => {
|
|
11331
|
-
return new HTTPTransport(host.handle);
|
|
11332
|
-
};
|
|
11333
11212
|
async function genWebClient(stateMgr, url) {
|
|
11334
|
-
const
|
|
11335
|
-
const idbStore = new IDBStore(idb, crypto_default);
|
|
11336
|
-
const transport = (host) => new HTTPTransport(host.handle);
|
|
11213
|
+
const idbStore = await openIDBStore(crypto_default);
|
|
11337
11214
|
const client = new SyncClient(
|
|
11338
11215
|
new Clock(),
|
|
11339
11216
|
stateMgr,
|
|
11340
11217
|
idbStore,
|
|
11341
|
-
|
|
11218
|
+
hostHTTPTransport
|
|
11342
11219
|
);
|
|
11343
11220
|
const setSeed = async (seedHex) => {
|
|
11344
11221
|
const seed = htob(seedHex);
|
|
@@ -11362,12 +11239,13 @@ export {
|
|
|
11362
11239
|
entStateManager,
|
|
11363
11240
|
genSingletonEID,
|
|
11364
11241
|
genWebClient,
|
|
11365
|
-
hostHTTPTransport,
|
|
11366
11242
|
htob,
|
|
11367
11243
|
crypto_default as libsodiumCrypto,
|
|
11368
11244
|
nullEntDB,
|
|
11369
11245
|
nullStateManager,
|
|
11246
|
+
openEntIDB,
|
|
11370
11247
|
openIDBStore,
|
|
11248
|
+
useClient,
|
|
11371
11249
|
useClientState,
|
|
11372
11250
|
useClientXferState,
|
|
11373
11251
|
useStateWatcher,
|