@xata.io/client 0.0.0-next.v6c9e627772cbacc1977ba6ba82e6b403ac64c0b2 → 0.0.0-next.v75d167190643613f39533f83608bd5d30cc66dcf

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/index.cjs CHANGED
@@ -24,6 +24,1814 @@ const TraceAttributes = {
24
24
  CLOUDFLARE_RAY_ID: "cf.ray"
25
25
  };
26
26
 
27
+ const lookup = [];
28
+ const revLookup = [];
29
+ const code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
30
+ for (let i = 0, len = code.length; i < len; ++i) {
31
+ lookup[i] = code[i];
32
+ revLookup[code.charCodeAt(i)] = i;
33
+ }
34
+ revLookup["-".charCodeAt(0)] = 62;
35
+ revLookup["_".charCodeAt(0)] = 63;
36
+ function getLens(b64) {
37
+ const len = b64.length;
38
+ if (len % 4 > 0) {
39
+ throw new Error("Invalid string. Length must be a multiple of 4");
40
+ }
41
+ let validLen = b64.indexOf("=");
42
+ if (validLen === -1)
43
+ validLen = len;
44
+ const placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
45
+ return [validLen, placeHoldersLen];
46
+ }
47
+ function _byteLength(_b64, validLen, placeHoldersLen) {
48
+ return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
49
+ }
50
+ function toByteArray(b64) {
51
+ let tmp;
52
+ const lens = getLens(b64);
53
+ const validLen = lens[0];
54
+ const placeHoldersLen = lens[1];
55
+ const arr = new Uint8Array(_byteLength(b64, validLen, placeHoldersLen));
56
+ let curByte = 0;
57
+ const len = placeHoldersLen > 0 ? validLen - 4 : validLen;
58
+ let i;
59
+ for (i = 0; i < len; i += 4) {
60
+ tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
61
+ arr[curByte++] = tmp >> 16 & 255;
62
+ arr[curByte++] = tmp >> 8 & 255;
63
+ arr[curByte++] = tmp & 255;
64
+ }
65
+ if (placeHoldersLen === 2) {
66
+ tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
67
+ arr[curByte++] = tmp & 255;
68
+ }
69
+ if (placeHoldersLen === 1) {
70
+ tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
71
+ arr[curByte++] = tmp >> 8 & 255;
72
+ arr[curByte++] = tmp & 255;
73
+ }
74
+ return arr;
75
+ }
76
+ function tripletToBase64(num) {
77
+ return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
78
+ }
79
+ function encodeChunk(uint8, start, end) {
80
+ let tmp;
81
+ const output = [];
82
+ for (let i = start; i < end; i += 3) {
83
+ tmp = (uint8[i] << 16 & 16711680) + (uint8[i + 1] << 8 & 65280) + (uint8[i + 2] & 255);
84
+ output.push(tripletToBase64(tmp));
85
+ }
86
+ return output.join("");
87
+ }
88
+ function fromByteArray(uint8) {
89
+ let tmp;
90
+ const len = uint8.length;
91
+ const extraBytes = len % 3;
92
+ const parts = [];
93
+ const maxChunkLength = 16383;
94
+ for (let i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
95
+ parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
96
+ }
97
+ if (extraBytes === 1) {
98
+ tmp = uint8[len - 1];
99
+ parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
100
+ } else if (extraBytes === 2) {
101
+ tmp = (uint8[len - 2] << 8) + uint8[len - 1];
102
+ parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=");
103
+ }
104
+ return parts.join("");
105
+ }
106
+
107
+ const K_MAX_LENGTH = 2147483647;
108
+ const MAX_ARGUMENTS_LENGTH = 4096;
109
+ class Buffer extends Uint8Array {
110
+ /**
111
+ * Constructs a new `Buffer` instance.
112
+ *
113
+ * @param value
114
+ * @param encodingOrOffset
115
+ * @param length
116
+ */
117
+ constructor(value, encodingOrOffset, length) {
118
+ if (typeof value === "number") {
119
+ if (typeof encodingOrOffset === "string") {
120
+ throw new TypeError("The first argument must be of type string, received type number");
121
+ }
122
+ if (value < 0) {
123
+ throw new RangeError("The buffer size cannot be negative");
124
+ }
125
+ super(value < 0 ? 0 : Buffer._checked(value) | 0);
126
+ } else if (typeof value === "string") {
127
+ if (typeof encodingOrOffset !== "string") {
128
+ encodingOrOffset = "utf8";
129
+ }
130
+ if (!Buffer.isEncoding(encodingOrOffset)) {
131
+ throw new TypeError("Unknown encoding: " + encodingOrOffset);
132
+ }
133
+ const length2 = Buffer.byteLength(value, encodingOrOffset) | 0;
134
+ super(length2);
135
+ const written = this.write(value, 0, this.length, encodingOrOffset);
136
+ if (written !== length2) {
137
+ throw new TypeError(
138
+ "Number of bytes written did not match expected length (wrote " + written + ", expected " + length2 + ")"
139
+ );
140
+ }
141
+ } else if (ArrayBuffer.isView(value)) {
142
+ if (Buffer._isInstance(value, Uint8Array)) {
143
+ const copy = new Uint8Array(value);
144
+ const array = copy.buffer;
145
+ const byteOffset = copy.byteOffset;
146
+ const length2 = copy.byteLength;
147
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
148
+ throw new RangeError("offset is outside of buffer bounds");
149
+ }
150
+ if (array.byteLength < byteOffset + (length2 || 0)) {
151
+ throw new RangeError("length is outside of buffer bounds");
152
+ }
153
+ super(new Uint8Array(array, byteOffset, length2));
154
+ } else {
155
+ const array = value;
156
+ const length2 = array.length < 0 ? 0 : Buffer._checked(array.length) | 0;
157
+ super(new Uint8Array(length2));
158
+ for (let i = 0; i < length2; i++) {
159
+ this[i] = array[i] & 255;
160
+ }
161
+ }
162
+ } else if (value == null) {
163
+ throw new TypeError(
164
+ "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value
165
+ );
166
+ } else if (Buffer._isInstance(value, ArrayBuffer) || value && Buffer._isInstance(value.buffer, ArrayBuffer)) {
167
+ const array = value;
168
+ const byteOffset = encodingOrOffset;
169
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
170
+ throw new RangeError("offset is outside of buffer bounds");
171
+ }
172
+ if (array.byteLength < byteOffset + (length || 0)) {
173
+ throw new RangeError("length is outside of buffer bounds");
174
+ }
175
+ super(new Uint8Array(array, byteOffset, length));
176
+ } else if (Array.isArray(value)) {
177
+ const array = value;
178
+ const length2 = array.length < 0 ? 0 : Buffer._checked(array.length) | 0;
179
+ super(new Uint8Array(length2));
180
+ for (let i = 0; i < length2; i++) {
181
+ this[i] = array[i] & 255;
182
+ }
183
+ } else {
184
+ throw new TypeError("Unable to determine the correct way to allocate buffer for type " + typeof value);
185
+ }
186
+ }
187
+ /**
188
+ * Return JSON representation of the buffer.
189
+ */
190
+ toJSON() {
191
+ return {
192
+ type: "Buffer",
193
+ data: Array.prototype.slice.call(this)
194
+ };
195
+ }
196
+ /**
197
+ * Writes `string` to the buffer at `offset` according to the character encoding in `encoding`. The `length`
198
+ * parameter is the number of bytes to write. If the buffer does not contain enough space to fit the entire string,
199
+ * only part of `string` will be written. However, partially encoded characters will not be written.
200
+ *
201
+ * @param string String to write to `buf`.
202
+ * @param offset Number of bytes to skip before starting to write `string`. Default: `0`.
203
+ * @param length Maximum number of bytes to write: Default: `buf.length - offset`.
204
+ * @param encoding The character encoding of `string`. Default: `utf8`.
205
+ */
206
+ write(string, offset, length, encoding) {
207
+ if (typeof offset === "undefined") {
208
+ encoding = "utf8";
209
+ length = this.length;
210
+ offset = 0;
211
+ } else if (typeof length === "undefined" && typeof offset === "string") {
212
+ encoding = offset;
213
+ length = this.length;
214
+ offset = 0;
215
+ } else if (typeof offset === "number" && isFinite(offset)) {
216
+ offset = offset >>> 0;
217
+ if (typeof length === "number" && isFinite(length)) {
218
+ length = length >>> 0;
219
+ encoding ?? (encoding = "utf8");
220
+ } else if (typeof length === "string") {
221
+ encoding = length;
222
+ length = void 0;
223
+ }
224
+ } else {
225
+ throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");
226
+ }
227
+ const remaining = this.length - offset;
228
+ if (typeof length === "undefined" || length > remaining) {
229
+ length = remaining;
230
+ }
231
+ if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
232
+ throw new RangeError("Attempt to write outside buffer bounds");
233
+ }
234
+ encoding || (encoding = "utf8");
235
+ switch (Buffer._getEncoding(encoding)) {
236
+ case "hex":
237
+ return Buffer._hexWrite(this, string, offset, length);
238
+ case "utf8":
239
+ return Buffer._utf8Write(this, string, offset, length);
240
+ case "ascii":
241
+ case "latin1":
242
+ case "binary":
243
+ return Buffer._asciiWrite(this, string, offset, length);
244
+ case "ucs2":
245
+ case "utf16le":
246
+ return Buffer._ucs2Write(this, string, offset, length);
247
+ case "base64":
248
+ return Buffer._base64Write(this, string, offset, length);
249
+ }
250
+ }
251
+ /**
252
+ * Decodes the buffer to a string according to the specified character encoding.
253
+ * Passing `start` and `end` will decode only a subset of the buffer.
254
+ *
255
+ * Note that if the encoding is `utf8` and a byte sequence in the input is not valid UTF-8, then each invalid byte
256
+ * will be replaced with `U+FFFD`.
257
+ *
258
+ * @param encoding
259
+ * @param start
260
+ * @param end
261
+ */
262
+ toString(encoding, start, end) {
263
+ const length = this.length;
264
+ if (length === 0) {
265
+ return "";
266
+ }
267
+ if (arguments.length === 0) {
268
+ return Buffer._utf8Slice(this, 0, length);
269
+ }
270
+ if (typeof start === "undefined" || start < 0) {
271
+ start = 0;
272
+ }
273
+ if (start > this.length) {
274
+ return "";
275
+ }
276
+ if (typeof end === "undefined" || end > this.length) {
277
+ end = this.length;
278
+ }
279
+ if (end <= 0) {
280
+ return "";
281
+ }
282
+ end >>>= 0;
283
+ start >>>= 0;
284
+ if (end <= start) {
285
+ return "";
286
+ }
287
+ if (!encoding) {
288
+ encoding = "utf8";
289
+ }
290
+ switch (Buffer._getEncoding(encoding)) {
291
+ case "hex":
292
+ return Buffer._hexSlice(this, start, end);
293
+ case "utf8":
294
+ return Buffer._utf8Slice(this, start, end);
295
+ case "ascii":
296
+ return Buffer._asciiSlice(this, start, end);
297
+ case "latin1":
298
+ case "binary":
299
+ return Buffer._latin1Slice(this, start, end);
300
+ case "ucs2":
301
+ case "utf16le":
302
+ return Buffer._utf16leSlice(this, start, end);
303
+ case "base64":
304
+ return Buffer._base64Slice(this, start, end);
305
+ }
306
+ }
307
+ /**
308
+ * Returns true if this buffer's is equal to the provided buffer, meaning they share the same exact data.
309
+ *
310
+ * @param otherBuffer
311
+ */
312
+ equals(otherBuffer) {
313
+ if (!Buffer.isBuffer(otherBuffer)) {
314
+ throw new TypeError("Argument must be a Buffer");
315
+ }
316
+ if (this === otherBuffer) {
317
+ return true;
318
+ }
319
+ return Buffer.compare(this, otherBuffer) === 0;
320
+ }
321
+ /**
322
+ * Compares the buffer with `otherBuffer` and returns a number indicating whether the buffer comes before, after,
323
+ * or is the same as `otherBuffer` in sort order. Comparison is based on the actual sequence of bytes in each
324
+ * buffer.
325
+ *
326
+ * - `0` is returned if `otherBuffer` is the same as this buffer.
327
+ * - `1` is returned if `otherBuffer` should come before this buffer when sorted.
328
+ * - `-1` is returned if `otherBuffer` should come after this buffer when sorted.
329
+ *
330
+ * @param otherBuffer The buffer to compare to.
331
+ * @param targetStart The offset within `otherBuffer` at which to begin comparison.
332
+ * @param targetEnd The offset within `otherBuffer` at which to end comparison (exclusive).
333
+ * @param sourceStart The offset within this buffer at which to begin comparison.
334
+ * @param sourceEnd The offset within this buffer at which to end the comparison (exclusive).
335
+ */
336
+ compare(otherBuffer, targetStart, targetEnd, sourceStart, sourceEnd) {
337
+ if (Buffer._isInstance(otherBuffer, Uint8Array)) {
338
+ otherBuffer = Buffer.from(otherBuffer, otherBuffer.byteOffset, otherBuffer.byteLength);
339
+ }
340
+ if (!Buffer.isBuffer(otherBuffer)) {
341
+ throw new TypeError("Argument must be a Buffer or Uint8Array");
342
+ }
343
+ targetStart ?? (targetStart = 0);
344
+ targetEnd ?? (targetEnd = otherBuffer ? otherBuffer.length : 0);
345
+ sourceStart ?? (sourceStart = 0);
346
+ sourceEnd ?? (sourceEnd = this.length);
347
+ if (targetStart < 0 || targetEnd > otherBuffer.length || sourceStart < 0 || sourceEnd > this.length) {
348
+ throw new RangeError("Out of range index");
349
+ }
350
+ if (sourceStart >= sourceEnd && targetStart >= targetEnd) {
351
+ return 0;
352
+ }
353
+ if (sourceStart >= sourceEnd) {
354
+ return -1;
355
+ }
356
+ if (targetStart >= targetEnd) {
357
+ return 1;
358
+ }
359
+ targetStart >>>= 0;
360
+ targetEnd >>>= 0;
361
+ sourceStart >>>= 0;
362
+ sourceEnd >>>= 0;
363
+ if (this === otherBuffer) {
364
+ return 0;
365
+ }
366
+ let x = sourceEnd - sourceStart;
367
+ let y = targetEnd - targetStart;
368
+ const len = Math.min(x, y);
369
+ const thisCopy = this.slice(sourceStart, sourceEnd);
370
+ const targetCopy = otherBuffer.slice(targetStart, targetEnd);
371
+ for (let i = 0; i < len; ++i) {
372
+ if (thisCopy[i] !== targetCopy[i]) {
373
+ x = thisCopy[i];
374
+ y = targetCopy[i];
375
+ break;
376
+ }
377
+ }
378
+ if (x < y)
379
+ return -1;
380
+ if (y < x)
381
+ return 1;
382
+ return 0;
383
+ }
384
+ /**
385
+ * Copies data from a region of this buffer to a region in `targetBuffer`, even if the `targetBuffer` memory
386
+ * region overlaps with this buffer.
387
+ *
388
+ * @param targetBuffer The target buffer to copy into.
389
+ * @param targetStart The offset within `targetBuffer` at which to begin writing.
390
+ * @param sourceStart The offset within this buffer at which to begin copying.
391
+ * @param sourceEnd The offset within this buffer at which to end copying (exclusive).
392
+ */
393
+ copy(targetBuffer, targetStart, sourceStart, sourceEnd) {
394
+ if (!Buffer.isBuffer(targetBuffer))
395
+ throw new TypeError("argument should be a Buffer");
396
+ if (!sourceStart)
397
+ sourceStart = 0;
398
+ if (!targetStart)
399
+ targetStart = 0;
400
+ if (!sourceEnd && sourceEnd !== 0)
401
+ sourceEnd = this.length;
402
+ if (targetStart >= targetBuffer.length)
403
+ targetStart = targetBuffer.length;
404
+ if (!targetStart)
405
+ targetStart = 0;
406
+ if (sourceEnd > 0 && sourceEnd < sourceStart)
407
+ sourceEnd = sourceStart;
408
+ if (sourceEnd === sourceStart)
409
+ return 0;
410
+ if (targetBuffer.length === 0 || this.length === 0)
411
+ return 0;
412
+ if (targetStart < 0) {
413
+ throw new RangeError("targetStart out of bounds");
414
+ }
415
+ if (sourceStart < 0 || sourceStart >= this.length)
416
+ throw new RangeError("Index out of range");
417
+ if (sourceEnd < 0)
418
+ throw new RangeError("sourceEnd out of bounds");
419
+ if (sourceEnd > this.length)
420
+ sourceEnd = this.length;
421
+ if (targetBuffer.length - targetStart < sourceEnd - sourceStart) {
422
+ sourceEnd = targetBuffer.length - targetStart + sourceStart;
423
+ }
424
+ const len = sourceEnd - sourceStart;
425
+ if (this === targetBuffer && typeof Uint8Array.prototype.copyWithin === "function") {
426
+ this.copyWithin(targetStart, sourceStart, sourceEnd);
427
+ } else {
428
+ Uint8Array.prototype.set.call(targetBuffer, this.subarray(sourceStart, sourceEnd), targetStart);
429
+ }
430
+ return len;
431
+ }
432
+ /**
433
+ * Returns a new `Buffer` that references the same memory as the original, but offset and cropped by the `start`
434
+ * and `end` indices. This is the same behavior as `buf.subarray()`.
435
+ *
436
+ * This method is not compatible with the `Uint8Array.prototype.slice()`, which is a superclass of Buffer. To copy
437
+ * the slice, use `Uint8Array.prototype.slice()`.
438
+ *
439
+ * @param start
440
+ * @param end
441
+ */
442
+ slice(start, end) {
443
+ if (!start) {
444
+ start = 0;
445
+ }
446
+ const len = this.length;
447
+ start = ~~start;
448
+ end = end === void 0 ? len : ~~end;
449
+ if (start < 0) {
450
+ start += len;
451
+ if (start < 0) {
452
+ start = 0;
453
+ }
454
+ } else if (start > len) {
455
+ start = len;
456
+ }
457
+ if (end < 0) {
458
+ end += len;
459
+ if (end < 0) {
460
+ end = 0;
461
+ }
462
+ } else if (end > len) {
463
+ end = len;
464
+ }
465
+ if (end < start) {
466
+ end = start;
467
+ }
468
+ const newBuf = this.subarray(start, end);
469
+ Object.setPrototypeOf(newBuf, Buffer.prototype);
470
+ return newBuf;
471
+ }
472
+ /**
473
+ * Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as little-endian. Supports up to 48 bits
474
+ * of accuracy. Behavior is undefined when value is anything other than an unsigned integer.
475
+ *
476
+ * @param value Number to write.
477
+ * @param offset Number of bytes to skip before starting to write.
478
+ * @param byteLength Number of bytes to write, between 0 and 6.
479
+ * @param noAssert
480
+ * @returns `offset` plus the number of bytes written.
481
+ */
482
+ writeUIntLE(value, offset, byteLength, noAssert) {
483
+ value = +value;
484
+ offset = offset >>> 0;
485
+ byteLength = byteLength >>> 0;
486
+ if (!noAssert) {
487
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
488
+ Buffer._checkInt(this, value, offset, byteLength, maxBytes, 0);
489
+ }
490
+ let mul = 1;
491
+ let i = 0;
492
+ this[offset] = value & 255;
493
+ while (++i < byteLength && (mul *= 256)) {
494
+ this[offset + i] = value / mul & 255;
495
+ }
496
+ return offset + byteLength;
497
+ }
498
+ /**
499
+ * Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as big-endian. Supports up to 48 bits of
500
+ * accuracy. Behavior is undefined when `value` is anything other than an unsigned integer.
501
+ *
502
+ * @param value Number to write.
503
+ * @param offset Number of bytes to skip before starting to write.
504
+ * @param byteLength Number of bytes to write, between 0 and 6.
505
+ * @param noAssert
506
+ * @returns `offset` plus the number of bytes written.
507
+ */
508
+ writeUIntBE(value, offset, byteLength, noAssert) {
509
+ value = +value;
510
+ offset = offset >>> 0;
511
+ byteLength = byteLength >>> 0;
512
+ if (!noAssert) {
513
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
514
+ Buffer._checkInt(this, value, offset, byteLength, maxBytes, 0);
515
+ }
516
+ let i = byteLength - 1;
517
+ let mul = 1;
518
+ this[offset + i] = value & 255;
519
+ while (--i >= 0 && (mul *= 256)) {
520
+ this[offset + i] = value / mul & 255;
521
+ }
522
+ return offset + byteLength;
523
+ }
524
+ /**
525
+ * Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as little-endian. Supports up to 48 bits
526
+ * of accuracy. Behavior is undefined when `value` is anything other than a signed integer.
527
+ *
528
+ * @param value Number to write.
529
+ * @param offset Number of bytes to skip before starting to write.
530
+ * @param byteLength Number of bytes to write, between 0 and 6.
531
+ * @param noAssert
532
+ * @returns `offset` plus the number of bytes written.
533
+ */
534
+ writeIntLE(value, offset, byteLength, noAssert) {
535
+ value = +value;
536
+ offset = offset >>> 0;
537
+ if (!noAssert) {
538
+ const limit = Math.pow(2, 8 * byteLength - 1);
539
+ Buffer._checkInt(this, value, offset, byteLength, limit - 1, -limit);
540
+ }
541
+ let i = 0;
542
+ let mul = 1;
543
+ let sub = 0;
544
+ this[offset] = value & 255;
545
+ while (++i < byteLength && (mul *= 256)) {
546
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
547
+ sub = 1;
548
+ }
549
+ this[offset + i] = (value / mul >> 0) - sub & 255;
550
+ }
551
+ return offset + byteLength;
552
+ }
553
+ /**
554
+ * Writes `byteLength` bytes of `value` to `buf` at the specified `offset` as big-endian. Supports up to 48 bits
555
+ * of accuracy. Behavior is undefined when `value` is anything other than a signed integer.
556
+ *
557
+ * @param value Number to write.
558
+ * @param offset Number of bytes to skip before starting to write.
559
+ * @param byteLength Number of bytes to write, between 0 and 6.
560
+ * @param noAssert
561
+ * @returns `offset` plus the number of bytes written.
562
+ */
563
+ writeIntBE(value, offset, byteLength, noAssert) {
564
+ value = +value;
565
+ offset = offset >>> 0;
566
+ if (!noAssert) {
567
+ const limit = Math.pow(2, 8 * byteLength - 1);
568
+ Buffer._checkInt(this, value, offset, byteLength, limit - 1, -limit);
569
+ }
570
+ let i = byteLength - 1;
571
+ let mul = 1;
572
+ let sub = 0;
573
+ this[offset + i] = value & 255;
574
+ while (--i >= 0 && (mul *= 256)) {
575
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
576
+ sub = 1;
577
+ }
578
+ this[offset + i] = (value / mul >> 0) - sub & 255;
579
+ }
580
+ return offset + byteLength;
581
+ }
582
+ /**
583
+ * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an
584
+ * unsigned, little-endian integer supporting up to 48 bits of accuracy.
585
+ *
586
+ * @param offset Number of bytes to skip before starting to read.
587
+ * @param byteLength Number of bytes to read, between 0 and 6.
588
+ * @param noAssert
589
+ */
590
+ readUIntLE(offset, byteLength, noAssert) {
591
+ offset = offset >>> 0;
592
+ byteLength = byteLength >>> 0;
593
+ if (!noAssert) {
594
+ Buffer._checkOffset(offset, byteLength, this.length);
595
+ }
596
+ let val = this[offset];
597
+ let mul = 1;
598
+ let i = 0;
599
+ while (++i < byteLength && (mul *= 256)) {
600
+ val += this[offset + i] * mul;
601
+ }
602
+ return val;
603
+ }
604
+ /**
605
+ * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an
606
+ * unsigned, big-endian integer supporting up to 48 bits of accuracy.
607
+ *
608
+ * @param offset Number of bytes to skip before starting to read.
609
+ * @param byteLength Number of bytes to read, between 0 and 6.
610
+ * @param noAssert
611
+ */
612
+ readUIntBE(offset, byteLength, noAssert) {
613
+ offset = offset >>> 0;
614
+ byteLength = byteLength >>> 0;
615
+ if (!noAssert) {
616
+ Buffer._checkOffset(offset, byteLength, this.length);
617
+ }
618
+ let val = this[offset + --byteLength];
619
+ let mul = 1;
620
+ while (byteLength > 0 && (mul *= 256)) {
621
+ val += this[offset + --byteLength] * mul;
622
+ }
623
+ return val;
624
+ }
625
+ /**
626
+ * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a
627
+ * little-endian, two's complement signed value supporting up to 48 bits of accuracy.
628
+ *
629
+ * @param offset Number of bytes to skip before starting to read.
630
+ * @param byteLength Number of bytes to read, between 0 and 6.
631
+ * @param noAssert
632
+ */
633
+ readIntLE(offset, byteLength, noAssert) {
634
+ offset = offset >>> 0;
635
+ byteLength = byteLength >>> 0;
636
+ if (!noAssert) {
637
+ Buffer._checkOffset(offset, byteLength, this.length);
638
+ }
639
+ let val = this[offset];
640
+ let mul = 1;
641
+ let i = 0;
642
+ while (++i < byteLength && (mul *= 256)) {
643
+ val += this[offset + i] * mul;
644
+ }
645
+ mul *= 128;
646
+ if (val >= mul) {
647
+ val -= Math.pow(2, 8 * byteLength);
648
+ }
649
+ return val;
650
+ }
651
+ /**
652
+ * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a
653
+ * big-endian, two's complement signed value supporting up to 48 bits of accuracy.
654
+ *
655
+ * @param offset Number of bytes to skip before starting to read.
656
+ * @param byteLength Number of bytes to read, between 0 and 6.
657
+ * @param noAssert
658
+ */
659
+ readIntBE(offset, byteLength, noAssert) {
660
+ offset = offset >>> 0;
661
+ byteLength = byteLength >>> 0;
662
+ if (!noAssert) {
663
+ Buffer._checkOffset(offset, byteLength, this.length);
664
+ }
665
+ let i = byteLength;
666
+ let mul = 1;
667
+ let val = this[offset + --i];
668
+ while (i > 0 && (mul *= 256)) {
669
+ val += this[offset + --i] * mul;
670
+ }
671
+ mul *= 128;
672
+ if (val >= mul) {
673
+ val -= Math.pow(2, 8 * byteLength);
674
+ }
675
+ return val;
676
+ }
677
+ /**
678
+ * Reads an unsigned 8-bit integer from `buf` at the specified `offset`.
679
+ *
680
+ * @param offset Number of bytes to skip before starting to read.
681
+ * @param noAssert
682
+ */
683
+ readUInt8(offset, noAssert) {
684
+ offset = offset >>> 0;
685
+ if (!noAssert) {
686
+ Buffer._checkOffset(offset, 1, this.length);
687
+ }
688
+ return this[offset];
689
+ }
690
+ /**
691
+ * Reads an unsigned, little-endian 16-bit integer from `buf` at the specified `offset`.
692
+ *
693
+ * @param offset Number of bytes to skip before starting to read.
694
+ * @param noAssert
695
+ */
696
+ readUInt16LE(offset, noAssert) {
697
+ offset = offset >>> 0;
698
+ if (!noAssert) {
699
+ Buffer._checkOffset(offset, 2, this.length);
700
+ }
701
+ return this[offset] | this[offset + 1] << 8;
702
+ }
703
+ /**
704
+ * Reads an unsigned, big-endian 16-bit integer from `buf` at the specified `offset`.
705
+ *
706
+ * @param offset Number of bytes to skip before starting to read.
707
+ * @param noAssert
708
+ */
709
+ readUInt16BE(offset, noAssert) {
710
+ offset = offset >>> 0;
711
+ if (!noAssert) {
712
+ Buffer._checkOffset(offset, 2, this.length);
713
+ }
714
+ return this[offset] << 8 | this[offset + 1];
715
+ }
716
+ /**
717
+ * Reads an unsigned, little-endian 32-bit integer from `buf` at the specified `offset`.
718
+ *
719
+ * @param offset Number of bytes to skip before starting to read.
720
+ * @param noAssert
721
+ */
722
+ readUInt32LE(offset, noAssert) {
723
+ offset = offset >>> 0;
724
+ if (!noAssert) {
725
+ Buffer._checkOffset(offset, 4, this.length);
726
+ }
727
+ return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216;
728
+ }
729
+ /**
730
+ * Reads an unsigned, big-endian 32-bit integer from `buf` at the specified `offset`.
731
+ *
732
+ * @param offset Number of bytes to skip before starting to read.
733
+ * @param noAssert
734
+ */
735
+ readUInt32BE(offset, noAssert) {
736
+ offset = offset >>> 0;
737
+ if (!noAssert) {
738
+ Buffer._checkOffset(offset, 4, this.length);
739
+ }
740
+ return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
741
+ }
742
+ /**
743
+ * Reads a signed 8-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer` are interpreted
744
+ * as two's complement signed values.
745
+ *
746
+ * @param offset Number of bytes to skip before starting to read.
747
+ * @param noAssert
748
+ */
749
+ readInt8(offset, noAssert) {
750
+ offset = offset >>> 0;
751
+ if (!noAssert) {
752
+ Buffer._checkOffset(offset, 1, this.length);
753
+ }
754
+ if (!(this[offset] & 128)) {
755
+ return this[offset];
756
+ }
757
+ return (255 - this[offset] + 1) * -1;
758
+ }
759
+ /**
760
+ * Reads a signed, little-endian 16-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer`
761
+ * are interpreted as two's complement signed values.
762
+ *
763
+ * @param offset Number of bytes to skip before starting to read.
764
+ * @param noAssert
765
+ */
766
+ readInt16LE(offset, noAssert) {
767
+ offset = offset >>> 0;
768
+ if (!noAssert) {
769
+ Buffer._checkOffset(offset, 2, this.length);
770
+ }
771
+ const val = this[offset] | this[offset + 1] << 8;
772
+ return val & 32768 ? val | 4294901760 : val;
773
+ }
774
+ /**
775
+ * Reads a signed, big-endian 16-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer`
776
+ * are interpreted as two's complement signed values.
777
+ *
778
+ * @param offset Number of bytes to skip before starting to read.
779
+ * @param noAssert
780
+ */
781
+ readInt16BE(offset, noAssert) {
782
+ offset = offset >>> 0;
783
+ if (!noAssert) {
784
+ Buffer._checkOffset(offset, 2, this.length);
785
+ }
786
+ const val = this[offset + 1] | this[offset] << 8;
787
+ return val & 32768 ? val | 4294901760 : val;
788
+ }
789
+ /**
790
+ * Reads a signed, little-endian 32-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer`
791
+ * are interpreted as two's complement signed values.
792
+ *
793
+ * @param offset Number of bytes to skip before starting to read.
794
+ * @param noAssert
795
+ */
796
+ readInt32LE(offset, noAssert) {
797
+ offset = offset >>> 0;
798
+ if (!noAssert) {
799
+ Buffer._checkOffset(offset, 4, this.length);
800
+ }
801
+ return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
802
+ }
803
+ /**
804
+ * Reads a signed, big-endian 32-bit integer from `buf` at the specified `offset`. Integers read from a `Buffer`
805
+ * are interpreted as two's complement signed values.
806
+ *
807
+ * @param offset Number of bytes to skip before starting to read.
808
+ * @param noAssert
809
+ */
810
+ readInt32BE(offset, noAssert) {
811
+ offset = offset >>> 0;
812
+ if (!noAssert) {
813
+ Buffer._checkOffset(offset, 4, this.length);
814
+ }
815
+ return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
816
+ }
817
+ /**
818
+ * Interprets `buf` as an array of unsigned 16-bit integers and swaps the byte order in-place.
819
+ * Throws a `RangeError` if `buf.length` is not a multiple of 2.
820
+ */
821
+ swap16() {
822
+ const len = this.length;
823
+ if (len % 2 !== 0) {
824
+ throw new RangeError("Buffer size must be a multiple of 16-bits");
825
+ }
826
+ for (let i = 0; i < len; i += 2) {
827
+ this._swap(this, i, i + 1);
828
+ }
829
+ return this;
830
+ }
831
+ /**
832
+ * Interprets `buf` as an array of unsigned 32-bit integers and swaps the byte order in-place.
833
+ * Throws a `RangeError` if `buf.length` is not a multiple of 4.
834
+ */
835
+ swap32() {
836
+ const len = this.length;
837
+ if (len % 4 !== 0) {
838
+ throw new RangeError("Buffer size must be a multiple of 32-bits");
839
+ }
840
+ for (let i = 0; i < len; i += 4) {
841
+ this._swap(this, i, i + 3);
842
+ this._swap(this, i + 1, i + 2);
843
+ }
844
+ return this;
845
+ }
846
+ /**
847
+ * Interprets `buf` as an array of unsigned 64-bit integers and swaps the byte order in-place.
848
+ * Throws a `RangeError` if `buf.length` is not a multiple of 8.
849
+ */
850
+ swap64() {
851
+ const len = this.length;
852
+ if (len % 8 !== 0) {
853
+ throw new RangeError("Buffer size must be a multiple of 64-bits");
854
+ }
855
+ for (let i = 0; i < len; i += 8) {
856
+ this._swap(this, i, i + 7);
857
+ this._swap(this, i + 1, i + 6);
858
+ this._swap(this, i + 2, i + 5);
859
+ this._swap(this, i + 3, i + 4);
860
+ }
861
+ return this;
862
+ }
863
+ /**
864
+ * Swaps two octets.
865
+ *
866
+ * @param b
867
+ * @param n
868
+ * @param m
869
+ */
870
+ _swap(b, n, m) {
871
+ const i = b[n];
872
+ b[n] = b[m];
873
+ b[m] = i;
874
+ }
875
+ /**
876
+ * Writes `value` to `buf` at the specified `offset`. The `value` must be a valid unsigned 8-bit integer.
877
+ * Behavior is undefined when `value` is anything other than an unsigned 8-bit integer.
878
+ *
879
+ * @param value Number to write.
880
+ * @param offset Number of bytes to skip before starting to write.
881
+ * @param noAssert
882
+ * @returns `offset` plus the number of bytes written.
883
+ */
884
+ writeUInt8(value, offset, noAssert) {
885
+ value = +value;
886
+ offset = offset >>> 0;
887
+ if (!noAssert) {
888
+ Buffer._checkInt(this, value, offset, 1, 255, 0);
889
+ }
890
+ this[offset] = value & 255;
891
+ return offset + 1;
892
+ }
893
+ /**
894
+ * Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid unsigned 16-bit
895
+ * integer. Behavior is undefined when `value` is anything other than an unsigned 16-bit integer.
896
+ *
897
+ * @param value Number to write.
898
+ * @param offset Number of bytes to skip before starting to write.
899
+ * @param noAssert
900
+ * @returns `offset` plus the number of bytes written.
901
+ */
902
+ writeUInt16LE(value, offset, noAssert) {
903
+ value = +value;
904
+ offset = offset >>> 0;
905
+ if (!noAssert) {
906
+ Buffer._checkInt(this, value, offset, 2, 65535, 0);
907
+ }
908
+ this[offset] = value & 255;
909
+ this[offset + 1] = value >>> 8;
910
+ return offset + 2;
911
+ }
912
+ /**
913
+ * Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid unsigned 16-bit
914
+ * integer. Behavior is undefined when `value` is anything other than an unsigned 16-bit integer.
915
+ *
916
+ * @param value Number to write.
917
+ * @param offset Number of bytes to skip before starting to write.
918
+ * @param noAssert
919
+ * @returns `offset` plus the number of bytes written.
920
+ */
921
+ writeUInt16BE(value, offset, noAssert) {
922
+ value = +value;
923
+ offset = offset >>> 0;
924
+ if (!noAssert) {
925
+ Buffer._checkInt(this, value, offset, 2, 65535, 0);
926
+ }
927
+ this[offset] = value >>> 8;
928
+ this[offset + 1] = value & 255;
929
+ return offset + 2;
930
+ }
931
+ /**
932
+ * Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid unsigned 32-bit
933
+ * integer. Behavior is undefined when `value` is anything other than an unsigned 32-bit integer.
934
+ *
935
+ * @param value Number to write.
936
+ * @param offset Number of bytes to skip before starting to write.
937
+ * @param noAssert
938
+ * @returns `offset` plus the number of bytes written.
939
+ */
940
+ writeUInt32LE(value, offset, noAssert) {
941
+ value = +value;
942
+ offset = offset >>> 0;
943
+ if (!noAssert) {
944
+ Buffer._checkInt(this, value, offset, 4, 4294967295, 0);
945
+ }
946
+ this[offset + 3] = value >>> 24;
947
+ this[offset + 2] = value >>> 16;
948
+ this[offset + 1] = value >>> 8;
949
+ this[offset] = value & 255;
950
+ return offset + 4;
951
+ }
952
+ /**
953
+ * Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid unsigned 32-bit
954
+ * integer. Behavior is undefined when `value` is anything other than an unsigned 32-bit integer.
955
+ *
956
+ * @param value Number to write.
957
+ * @param offset Number of bytes to skip before starting to write.
958
+ * @param noAssert
959
+ * @returns `offset` plus the number of bytes written.
960
+ */
961
+ writeUInt32BE(value, offset, noAssert) {
962
+ value = +value;
963
+ offset = offset >>> 0;
964
+ if (!noAssert) {
965
+ Buffer._checkInt(this, value, offset, 4, 4294967295, 0);
966
+ }
967
+ this[offset] = value >>> 24;
968
+ this[offset + 1] = value >>> 16;
969
+ this[offset + 2] = value >>> 8;
970
+ this[offset + 3] = value & 255;
971
+ return offset + 4;
972
+ }
973
+ /**
974
+ * Writes `value` to `buf` at the specified `offset`. The `value` must be a valid signed 8-bit integer.
975
+ * Behavior is undefined when `value` is anything other than a signed 8-bit integer.
976
+ *
977
+ * @param value Number to write.
978
+ * @param offset Number of bytes to skip before starting to write.
979
+ * @param noAssert
980
+ * @returns `offset` plus the number of bytes written.
981
+ */
982
+ writeInt8(value, offset, noAssert) {
983
+ value = +value;
984
+ offset = offset >>> 0;
985
+ if (!noAssert) {
986
+ Buffer._checkInt(this, value, offset, 1, 127, -128);
987
+ }
988
+ if (value < 0) {
989
+ value = 255 + value + 1;
990
+ }
991
+ this[offset] = value & 255;
992
+ return offset + 1;
993
+ }
994
+ /**
995
+ * Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid signed 16-bit
996
+ * integer. Behavior is undefined when `value` is anything other than a signed 16-bit integer.
997
+ *
998
+ * @param value Number to write.
999
+ * @param offset Number of bytes to skip before starting to write.
1000
+ * @param noAssert
1001
+ * @returns `offset` plus the number of bytes written.
1002
+ */
1003
+ writeInt16LE(value, offset, noAssert) {
1004
+ value = +value;
1005
+ offset = offset >>> 0;
1006
+ if (!noAssert) {
1007
+ Buffer._checkInt(this, value, offset, 2, 32767, -32768);
1008
+ }
1009
+ this[offset] = value & 255;
1010
+ this[offset + 1] = value >>> 8;
1011
+ return offset + 2;
1012
+ }
1013
+ /**
1014
+ * Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid signed 16-bit
1015
+ * integer. Behavior is undefined when `value` is anything other than a signed 16-bit integer.
1016
+ *
1017
+ * @param value Number to write.
1018
+ * @param offset Number of bytes to skip before starting to write.
1019
+ * @param noAssert
1020
+ * @returns `offset` plus the number of bytes written.
1021
+ */
1022
+ writeInt16BE(value, offset, noAssert) {
1023
+ value = +value;
1024
+ offset = offset >>> 0;
1025
+ if (!noAssert) {
1026
+ Buffer._checkInt(this, value, offset, 2, 32767, -32768);
1027
+ }
1028
+ this[offset] = value >>> 8;
1029
+ this[offset + 1] = value & 255;
1030
+ return offset + 2;
1031
+ }
1032
+ /**
1033
+ * Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid signed 32-bit
1034
+ * integer. Behavior is undefined when `value` is anything other than a signed 32-bit integer.
1035
+ *
1036
+ * @param value Number to write.
1037
+ * @param offset Number of bytes to skip before starting to write.
1038
+ * @param noAssert
1039
+ * @returns `offset` plus the number of bytes written.
1040
+ */
1041
+ writeInt32LE(value, offset, noAssert) {
1042
+ value = +value;
1043
+ offset = offset >>> 0;
1044
+ if (!noAssert) {
1045
+ Buffer._checkInt(this, value, offset, 4, 2147483647, -2147483648);
1046
+ }
1047
+ this[offset] = value & 255;
1048
+ this[offset + 1] = value >>> 8;
1049
+ this[offset + 2] = value >>> 16;
1050
+ this[offset + 3] = value >>> 24;
1051
+ return offset + 4;
1052
+ }
1053
+ /**
1054
+ * Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid signed 32-bit
1055
+ * integer. Behavior is undefined when `value` is anything other than a signed 32-bit integer.
1056
+ *
1057
+ * @param value Number to write.
1058
+ * @param offset Number of bytes to skip before starting to write.
1059
+ * @param noAssert
1060
+ * @returns `offset` plus the number of bytes written.
1061
+ */
1062
+ writeInt32BE(value, offset, noAssert) {
1063
+ value = +value;
1064
+ offset = offset >>> 0;
1065
+ if (!noAssert) {
1066
+ Buffer._checkInt(this, value, offset, 4, 2147483647, -2147483648);
1067
+ }
1068
+ if (value < 0) {
1069
+ value = 4294967295 + value + 1;
1070
+ }
1071
+ this[offset] = value >>> 24;
1072
+ this[offset + 1] = value >>> 16;
1073
+ this[offset + 2] = value >>> 8;
1074
+ this[offset + 3] = value & 255;
1075
+ return offset + 4;
1076
+ }
1077
+ /**
1078
+ * Fills `buf` with the specified `value`. If the `offset` and `end` are not given, the entire `buf` will be
1079
+ * filled. The `value` is coerced to a `uint32` value if it is not a string, `Buffer`, or integer. If the resulting
1080
+ * integer is greater than `255` (decimal), then `buf` will be filled with `value & 255`.
1081
+ *
1082
+ * If the final write of a `fill()` operation falls on a multi-byte character, then only the bytes of that
1083
+ * character that fit into `buf` are written.
1084
+ *
1085
+ * If `value` contains invalid characters, it is truncated; if no valid fill data remains, an exception is thrown.
1086
+ *
1087
+ * @param value
1088
+ * @param encoding
1089
+ */
1090
+ fill(value, offset, end, encoding) {
1091
+ if (typeof value === "string") {
1092
+ if (typeof offset === "string") {
1093
+ encoding = offset;
1094
+ offset = 0;
1095
+ end = this.length;
1096
+ } else if (typeof end === "string") {
1097
+ encoding = end;
1098
+ end = this.length;
1099
+ }
1100
+ if (encoding !== void 0 && typeof encoding !== "string") {
1101
+ throw new TypeError("encoding must be a string");
1102
+ }
1103
+ if (typeof encoding === "string" && !Buffer.isEncoding(encoding)) {
1104
+ throw new TypeError("Unknown encoding: " + encoding);
1105
+ }
1106
+ if (value.length === 1) {
1107
+ const code = value.charCodeAt(0);
1108
+ if (encoding === "utf8" && code < 128) {
1109
+ value = code;
1110
+ }
1111
+ }
1112
+ } else if (typeof value === "number") {
1113
+ value = value & 255;
1114
+ } else if (typeof value === "boolean") {
1115
+ value = Number(value);
1116
+ }
1117
+ offset ?? (offset = 0);
1118
+ end ?? (end = this.length);
1119
+ if (offset < 0 || this.length < offset || this.length < end) {
1120
+ throw new RangeError("Out of range index");
1121
+ }
1122
+ if (end <= offset) {
1123
+ return this;
1124
+ }
1125
+ offset = offset >>> 0;
1126
+ end = end === void 0 ? this.length : end >>> 0;
1127
+ value || (value = 0);
1128
+ let i;
1129
+ if (typeof value === "number") {
1130
+ for (i = offset; i < end; ++i) {
1131
+ this[i] = value;
1132
+ }
1133
+ } else {
1134
+ const bytes = Buffer.isBuffer(value) ? value : Buffer.from(value, encoding);
1135
+ const len = bytes.length;
1136
+ if (len === 0) {
1137
+ throw new TypeError('The value "' + value + '" is invalid for argument "value"');
1138
+ }
1139
+ for (i = 0; i < end - offset; ++i) {
1140
+ this[i + offset] = bytes[i % len];
1141
+ }
1142
+ }
1143
+ return this;
1144
+ }
1145
+ /**
1146
+ * Returns the index of the specified value.
1147
+ *
1148
+ * If `value` is:
1149
+ * - a string, `value` is interpreted according to the character encoding in `encoding`.
1150
+ * - a `Buffer` or `Uint8Array`, `value` will be used in its entirety. To compare a partial Buffer, use `slice()`.
1151
+ * - a number, `value` will be interpreted as an unsigned 8-bit integer value between `0` and `255`.
1152
+ *
1153
+ * Any other types will throw a `TypeError`.
1154
+ *
1155
+ * @param value What to search for.
1156
+ * @param byteOffset Where to begin searching in `buf`. If negative, then calculated from the end.
1157
+ * @param encoding If `value` is a string, this is the encoding used to search.
1158
+ * @returns The index of the first occurrence of `value` in `buf`, or `-1` if not found.
1159
+ */
1160
+ indexOf(value, byteOffset, encoding) {
1161
+ return this._bidirectionalIndexOf(this, value, byteOffset, encoding, true);
1162
+ }
1163
+ /**
1164
+ * Gets the last index of the specified value.
1165
+ *
1166
+ * @see indexOf()
1167
+ * @param value
1168
+ * @param byteOffset
1169
+ * @param encoding
1170
+ */
1171
+ lastIndexOf(value, byteOffset, encoding) {
1172
+ return this._bidirectionalIndexOf(this, value, byteOffset, encoding, false);
1173
+ }
1174
+ _bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
1175
+ if (buffer.length === 0) {
1176
+ return -1;
1177
+ }
1178
+ if (typeof byteOffset === "string") {
1179
+ encoding = byteOffset;
1180
+ byteOffset = 0;
1181
+ } else if (typeof byteOffset === "undefined") {
1182
+ byteOffset = 0;
1183
+ } else if (byteOffset > 2147483647) {
1184
+ byteOffset = 2147483647;
1185
+ } else if (byteOffset < -2147483648) {
1186
+ byteOffset = -2147483648;
1187
+ }
1188
+ byteOffset = +byteOffset;
1189
+ if (byteOffset !== byteOffset) {
1190
+ byteOffset = dir ? 0 : buffer.length - 1;
1191
+ }
1192
+ if (byteOffset < 0) {
1193
+ byteOffset = buffer.length + byteOffset;
1194
+ }
1195
+ if (byteOffset >= buffer.length) {
1196
+ if (dir) {
1197
+ return -1;
1198
+ } else {
1199
+ byteOffset = buffer.length - 1;
1200
+ }
1201
+ } else if (byteOffset < 0) {
1202
+ if (dir) {
1203
+ byteOffset = 0;
1204
+ } else {
1205
+ return -1;
1206
+ }
1207
+ }
1208
+ if (typeof val === "string") {
1209
+ val = Buffer.from(val, encoding);
1210
+ }
1211
+ if (Buffer.isBuffer(val)) {
1212
+ if (val.length === 0) {
1213
+ return -1;
1214
+ }
1215
+ return Buffer._arrayIndexOf(buffer, val, byteOffset, encoding, dir);
1216
+ } else if (typeof val === "number") {
1217
+ val = val & 255;
1218
+ if (typeof Uint8Array.prototype.indexOf === "function") {
1219
+ if (dir) {
1220
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
1221
+ } else {
1222
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
1223
+ }
1224
+ }
1225
+ return Buffer._arrayIndexOf(buffer, Buffer.from([val]), byteOffset, encoding, dir);
1226
+ }
1227
+ throw new TypeError("val must be string, number or Buffer");
1228
+ }
1229
+ /**
1230
+ * Equivalent to `buf.indexOf() !== -1`.
1231
+ *
1232
+ * @param value
1233
+ * @param byteOffset
1234
+ * @param encoding
1235
+ */
1236
+ includes(value, byteOffset, encoding) {
1237
+ return this.indexOf(value, byteOffset, encoding) !== -1;
1238
+ }
1239
+ /**
1240
+ * Creates a new buffer from the given parameters.
1241
+ *
1242
+ * @param data
1243
+ * @param encoding
1244
+ */
1245
+ static from(a, b, c) {
1246
+ return new Buffer(a, b, c);
1247
+ }
1248
+ /**
1249
+ * Returns true if `obj` is a Buffer.
1250
+ *
1251
+ * @param obj
1252
+ */
1253
+ static isBuffer(obj) {
1254
+ return obj != null && obj !== Buffer.prototype && Buffer._isInstance(obj, Buffer);
1255
+ }
1256
+ /**
1257
+ * Returns true if `encoding` is a supported encoding.
1258
+ *
1259
+ * @param encoding
1260
+ */
1261
+ static isEncoding(encoding) {
1262
+ switch (encoding.toLowerCase()) {
1263
+ case "hex":
1264
+ case "utf8":
1265
+ case "ascii":
1266
+ case "binary":
1267
+ case "latin1":
1268
+ case "ucs2":
1269
+ case "utf16le":
1270
+ case "base64":
1271
+ return true;
1272
+ default:
1273
+ return false;
1274
+ }
1275
+ }
1276
+ /**
1277
+ * Gives the actual byte length of a string for an encoding. This is not the same as `string.length` since that
1278
+ * returns the number of characters in the string.
1279
+ *
1280
+ * @param string The string to test.
1281
+ * @param encoding The encoding to use for calculation. Defaults is `utf8`.
1282
+ */
1283
+ static byteLength(string, encoding) {
1284
+ if (Buffer.isBuffer(string)) {
1285
+ return string.length;
1286
+ }
1287
+ if (typeof string !== "string" && (ArrayBuffer.isView(string) || Buffer._isInstance(string, ArrayBuffer))) {
1288
+ return string.byteLength;
1289
+ }
1290
+ if (typeof string !== "string") {
1291
+ throw new TypeError(
1292
+ 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type ' + typeof string
1293
+ );
1294
+ }
1295
+ const len = string.length;
1296
+ const mustMatch = arguments.length > 2 && arguments[2] === true;
1297
+ if (!mustMatch && len === 0) {
1298
+ return 0;
1299
+ }
1300
+ switch (encoding?.toLowerCase()) {
1301
+ case "ascii":
1302
+ case "latin1":
1303
+ case "binary":
1304
+ return len;
1305
+ case "utf8":
1306
+ return Buffer._utf8ToBytes(string).length;
1307
+ case "hex":
1308
+ return len >>> 1;
1309
+ case "ucs2":
1310
+ case "utf16le":
1311
+ return len * 2;
1312
+ case "base64":
1313
+ return Buffer._base64ToBytes(string).length;
1314
+ default:
1315
+ return mustMatch ? -1 : Buffer._utf8ToBytes(string).length;
1316
+ }
1317
+ }
1318
+ /**
1319
+ * Returns a Buffer which is the result of concatenating all the buffers in the list together.
1320
+ *
1321
+ * - If the list has no items, or if the `totalLength` is 0, then it returns a zero-length buffer.
1322
+ * - If the list has exactly one item, then the first item is returned.
1323
+ * - If the list has more than one item, then a new buffer is created.
1324
+ *
1325
+ * It is faster to provide the `totalLength` if it is known. However, it will be calculated if not provided at
1326
+ * a small computational expense.
1327
+ *
1328
+ * @param list An array of Buffer objects to concatenate.
1329
+ * @param totalLength Total length of the buffers when concatenated.
1330
+ */
1331
+ static concat(list, totalLength) {
1332
+ if (!Array.isArray(list)) {
1333
+ throw new TypeError('"list" argument must be an Array of Buffers');
1334
+ }
1335
+ if (list.length === 0) {
1336
+ return Buffer.alloc(0);
1337
+ }
1338
+ let i;
1339
+ if (totalLength === void 0) {
1340
+ totalLength = 0;
1341
+ for (i = 0; i < list.length; ++i) {
1342
+ totalLength += list[i].length;
1343
+ }
1344
+ }
1345
+ const buffer = Buffer.allocUnsafe(totalLength);
1346
+ let pos = 0;
1347
+ for (i = 0; i < list.length; ++i) {
1348
+ let buf = list[i];
1349
+ if (Buffer._isInstance(buf, Uint8Array)) {
1350
+ if (pos + buf.length > buffer.length) {
1351
+ if (!Buffer.isBuffer(buf)) {
1352
+ buf = Buffer.from(buf);
1353
+ }
1354
+ buf.copy(buffer, pos);
1355
+ } else {
1356
+ Uint8Array.prototype.set.call(buffer, buf, pos);
1357
+ }
1358
+ } else if (!Buffer.isBuffer(buf)) {
1359
+ throw new TypeError('"list" argument must be an Array of Buffers');
1360
+ } else {
1361
+ buf.copy(buffer, pos);
1362
+ }
1363
+ pos += buf.length;
1364
+ }
1365
+ return buffer;
1366
+ }
1367
+ /**
1368
+ * The same as `buf1.compare(buf2)`.
1369
+ */
1370
+ static compare(buf1, buf2) {
1371
+ if (Buffer._isInstance(buf1, Uint8Array)) {
1372
+ buf1 = Buffer.from(buf1, buf1.byteOffset, buf1.byteLength);
1373
+ }
1374
+ if (Buffer._isInstance(buf2, Uint8Array)) {
1375
+ buf2 = Buffer.from(buf2, buf2.byteOffset, buf2.byteLength);
1376
+ }
1377
+ if (!Buffer.isBuffer(buf1) || !Buffer.isBuffer(buf2)) {
1378
+ throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
1379
+ }
1380
+ if (buf1 === buf2) {
1381
+ return 0;
1382
+ }
1383
+ let x = buf1.length;
1384
+ let y = buf2.length;
1385
+ for (let i = 0, len = Math.min(x, y); i < len; ++i) {
1386
+ if (buf1[i] !== buf2[i]) {
1387
+ x = buf1[i];
1388
+ y = buf2[i];
1389
+ break;
1390
+ }
1391
+ }
1392
+ if (x < y) {
1393
+ return -1;
1394
+ }
1395
+ if (y < x) {
1396
+ return 1;
1397
+ }
1398
+ return 0;
1399
+ }
1400
+ /**
1401
+ * Allocates a new buffer of `size` octets.
1402
+ *
1403
+ * @param size The number of octets to allocate.
1404
+ * @param fill If specified, the buffer will be initialized by calling `buf.fill(fill)`, or with zeroes otherwise.
1405
+ * @param encoding The encoding used for the call to `buf.fill()` while initializing.
1406
+ */
1407
+ static alloc(size, fill, encoding) {
1408
+ if (typeof size !== "number") {
1409
+ throw new TypeError('"size" argument must be of type number');
1410
+ } else if (size < 0) {
1411
+ throw new RangeError('The value "' + size + '" is invalid for option "size"');
1412
+ }
1413
+ if (size <= 0) {
1414
+ return new Buffer(size);
1415
+ }
1416
+ if (fill !== void 0) {
1417
+ return typeof encoding === "string" ? new Buffer(size).fill(fill, 0, size, encoding) : new Buffer(size).fill(fill);
1418
+ }
1419
+ return new Buffer(size);
1420
+ }
1421
+ /**
1422
+ * Allocates a new buffer of `size` octets without initializing memory. The contents of the buffer are unknown.
1423
+ *
1424
+ * @param size
1425
+ */
1426
+ static allocUnsafe(size) {
1427
+ if (typeof size !== "number") {
1428
+ throw new TypeError('"size" argument must be of type number');
1429
+ } else if (size < 0) {
1430
+ throw new RangeError('The value "' + size + '" is invalid for option "size"');
1431
+ }
1432
+ return new Buffer(size < 0 ? 0 : Buffer._checked(size) | 0);
1433
+ }
1434
+ /**
1435
+ * Returns true if the given `obj` is an instance of `type`.
1436
+ *
1437
+ * @param obj
1438
+ * @param type
1439
+ */
1440
+ static _isInstance(obj, type) {
1441
+ return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
1442
+ }
1443
+ static _checked(length) {
1444
+ if (length >= K_MAX_LENGTH) {
1445
+ throw new RangeError(
1446
+ "Attempt to allocate Buffer larger than maximum size: 0x" + K_MAX_LENGTH.toString(16) + " bytes"
1447
+ );
1448
+ }
1449
+ return length | 0;
1450
+ }
1451
+ static _blitBuffer(src, dst, offset, length) {
1452
+ let i;
1453
+ for (i = 0; i < length; ++i) {
1454
+ if (i + offset >= dst.length || i >= src.length) {
1455
+ break;
1456
+ }
1457
+ dst[i + offset] = src[i];
1458
+ }
1459
+ return i;
1460
+ }
1461
+ static _utf8Write(buf, string, offset, length) {
1462
+ return Buffer._blitBuffer(Buffer._utf8ToBytes(string, buf.length - offset), buf, offset, length);
1463
+ }
1464
+ static _asciiWrite(buf, string, offset, length) {
1465
+ return Buffer._blitBuffer(Buffer._asciiToBytes(string), buf, offset, length);
1466
+ }
1467
+ static _base64Write(buf, string, offset, length) {
1468
+ return Buffer._blitBuffer(Buffer._base64ToBytes(string), buf, offset, length);
1469
+ }
1470
+ static _ucs2Write(buf, string, offset, length) {
1471
+ return Buffer._blitBuffer(Buffer._utf16leToBytes(string, buf.length - offset), buf, offset, length);
1472
+ }
1473
+ static _hexWrite(buf, string, offset, length) {
1474
+ offset = Number(offset) || 0;
1475
+ const remaining = buf.length - offset;
1476
+ if (!length) {
1477
+ length = remaining;
1478
+ } else {
1479
+ length = Number(length);
1480
+ if (length > remaining) {
1481
+ length = remaining;
1482
+ }
1483
+ }
1484
+ const strLen = string.length;
1485
+ if (length > strLen / 2) {
1486
+ length = strLen / 2;
1487
+ }
1488
+ let i;
1489
+ for (i = 0; i < length; ++i) {
1490
+ const parsed = parseInt(string.substr(i * 2, 2), 16);
1491
+ if (parsed !== parsed) {
1492
+ return i;
1493
+ }
1494
+ buf[offset + i] = parsed;
1495
+ }
1496
+ return i;
1497
+ }
1498
+ static _utf8ToBytes(string, units) {
1499
+ units = units || Infinity;
1500
+ const length = string.length;
1501
+ const bytes = [];
1502
+ let codePoint;
1503
+ let leadSurrogate = null;
1504
+ for (let i = 0; i < length; ++i) {
1505
+ codePoint = string.charCodeAt(i);
1506
+ if (codePoint > 55295 && codePoint < 57344) {
1507
+ if (!leadSurrogate) {
1508
+ if (codePoint > 56319) {
1509
+ if ((units -= 3) > -1) {
1510
+ bytes.push(239, 191, 189);
1511
+ }
1512
+ continue;
1513
+ } else if (i + 1 === length) {
1514
+ if ((units -= 3) > -1) {
1515
+ bytes.push(239, 191, 189);
1516
+ }
1517
+ continue;
1518
+ }
1519
+ leadSurrogate = codePoint;
1520
+ continue;
1521
+ }
1522
+ if (codePoint < 56320) {
1523
+ if ((units -= 3) > -1) {
1524
+ bytes.push(239, 191, 189);
1525
+ }
1526
+ leadSurrogate = codePoint;
1527
+ continue;
1528
+ }
1529
+ codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536;
1530
+ } else if (leadSurrogate) {
1531
+ if ((units -= 3) > -1) {
1532
+ bytes.push(239, 191, 189);
1533
+ }
1534
+ }
1535
+ leadSurrogate = null;
1536
+ if (codePoint < 128) {
1537
+ if ((units -= 1) < 0) {
1538
+ break;
1539
+ }
1540
+ bytes.push(codePoint);
1541
+ } else if (codePoint < 2048) {
1542
+ if ((units -= 2) < 0) {
1543
+ break;
1544
+ }
1545
+ bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128);
1546
+ } else if (codePoint < 65536) {
1547
+ if ((units -= 3) < 0) {
1548
+ break;
1549
+ }
1550
+ bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128);
1551
+ } else if (codePoint < 1114112) {
1552
+ if ((units -= 4) < 0) {
1553
+ break;
1554
+ }
1555
+ bytes.push(
1556
+ codePoint >> 18 | 240,
1557
+ codePoint >> 12 & 63 | 128,
1558
+ codePoint >> 6 & 63 | 128,
1559
+ codePoint & 63 | 128
1560
+ );
1561
+ } else {
1562
+ throw new Error("Invalid code point");
1563
+ }
1564
+ }
1565
+ return bytes;
1566
+ }
1567
+ static _base64ToBytes(str) {
1568
+ return toByteArray(base64clean(str));
1569
+ }
1570
+ static _asciiToBytes(str) {
1571
+ const byteArray = [];
1572
+ for (let i = 0; i < str.length; ++i) {
1573
+ byteArray.push(str.charCodeAt(i) & 255);
1574
+ }
1575
+ return byteArray;
1576
+ }
1577
+ static _utf16leToBytes(str, units) {
1578
+ let c, hi, lo;
1579
+ const byteArray = [];
1580
+ for (let i = 0; i < str.length; ++i) {
1581
+ if ((units -= 2) < 0)
1582
+ break;
1583
+ c = str.charCodeAt(i);
1584
+ hi = c >> 8;
1585
+ lo = c % 256;
1586
+ byteArray.push(lo);
1587
+ byteArray.push(hi);
1588
+ }
1589
+ return byteArray;
1590
+ }
1591
+ static _hexSlice(buf, start, end) {
1592
+ const len = buf.length;
1593
+ if (!start || start < 0) {
1594
+ start = 0;
1595
+ }
1596
+ if (!end || end < 0 || end > len) {
1597
+ end = len;
1598
+ }
1599
+ let out = "";
1600
+ for (let i = start; i < end; ++i) {
1601
+ out += hexSliceLookupTable[buf[i]];
1602
+ }
1603
+ return out;
1604
+ }
1605
+ static _base64Slice(buf, start, end) {
1606
+ if (start === 0 && end === buf.length) {
1607
+ return fromByteArray(buf);
1608
+ } else {
1609
+ return fromByteArray(buf.slice(start, end));
1610
+ }
1611
+ }
1612
+ static _utf8Slice(buf, start, end) {
1613
+ end = Math.min(buf.length, end);
1614
+ const res = [];
1615
+ let i = start;
1616
+ while (i < end) {
1617
+ const firstByte = buf[i];
1618
+ let codePoint = null;
1619
+ let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1;
1620
+ if (i + bytesPerSequence <= end) {
1621
+ let secondByte, thirdByte, fourthByte, tempCodePoint;
1622
+ switch (bytesPerSequence) {
1623
+ case 1:
1624
+ if (firstByte < 128) {
1625
+ codePoint = firstByte;
1626
+ }
1627
+ break;
1628
+ case 2:
1629
+ secondByte = buf[i + 1];
1630
+ if ((secondByte & 192) === 128) {
1631
+ tempCodePoint = (firstByte & 31) << 6 | secondByte & 63;
1632
+ if (tempCodePoint > 127) {
1633
+ codePoint = tempCodePoint;
1634
+ }
1635
+ }
1636
+ break;
1637
+ case 3:
1638
+ secondByte = buf[i + 1];
1639
+ thirdByte = buf[i + 2];
1640
+ if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) {
1641
+ tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63;
1642
+ if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) {
1643
+ codePoint = tempCodePoint;
1644
+ }
1645
+ }
1646
+ break;
1647
+ case 4:
1648
+ secondByte = buf[i + 1];
1649
+ thirdByte = buf[i + 2];
1650
+ fourthByte = buf[i + 3];
1651
+ if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) {
1652
+ tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63;
1653
+ if (tempCodePoint > 65535 && tempCodePoint < 1114112) {
1654
+ codePoint = tempCodePoint;
1655
+ }
1656
+ }
1657
+ }
1658
+ }
1659
+ if (codePoint === null) {
1660
+ codePoint = 65533;
1661
+ bytesPerSequence = 1;
1662
+ } else if (codePoint > 65535) {
1663
+ codePoint -= 65536;
1664
+ res.push(codePoint >>> 10 & 1023 | 55296);
1665
+ codePoint = 56320 | codePoint & 1023;
1666
+ }
1667
+ res.push(codePoint);
1668
+ i += bytesPerSequence;
1669
+ }
1670
+ return Buffer._decodeCodePointsArray(res);
1671
+ }
1672
+ static _decodeCodePointsArray(codePoints) {
1673
+ const len = codePoints.length;
1674
+ if (len <= MAX_ARGUMENTS_LENGTH) {
1675
+ return String.fromCharCode.apply(String, codePoints);
1676
+ }
1677
+ let res = "";
1678
+ let i = 0;
1679
+ while (i < len) {
1680
+ res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
1681
+ }
1682
+ return res;
1683
+ }
1684
+ static _asciiSlice(buf, start, end) {
1685
+ let ret = "";
1686
+ end = Math.min(buf.length, end);
1687
+ for (let i = start; i < end; ++i) {
1688
+ ret += String.fromCharCode(buf[i] & 127);
1689
+ }
1690
+ return ret;
1691
+ }
1692
+ static _latin1Slice(buf, start, end) {
1693
+ let ret = "";
1694
+ end = Math.min(buf.length, end);
1695
+ for (let i = start; i < end; ++i) {
1696
+ ret += String.fromCharCode(buf[i]);
1697
+ }
1698
+ return ret;
1699
+ }
1700
+ static _utf16leSlice(buf, start, end) {
1701
+ const bytes = buf.slice(start, end);
1702
+ let res = "";
1703
+ for (let i = 0; i < bytes.length - 1; i += 2) {
1704
+ res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
1705
+ }
1706
+ return res;
1707
+ }
1708
+ static _arrayIndexOf(arr, val, byteOffset, encoding, dir) {
1709
+ let indexSize = 1;
1710
+ let arrLength = arr.length;
1711
+ let valLength = val.length;
1712
+ if (encoding !== void 0) {
1713
+ encoding = Buffer._getEncoding(encoding);
1714
+ if (encoding === "ucs2" || encoding === "utf16le") {
1715
+ if (arr.length < 2 || val.length < 2) {
1716
+ return -1;
1717
+ }
1718
+ indexSize = 2;
1719
+ arrLength /= 2;
1720
+ valLength /= 2;
1721
+ byteOffset /= 2;
1722
+ }
1723
+ }
1724
+ function read(buf, i2) {
1725
+ if (indexSize === 1) {
1726
+ return buf[i2];
1727
+ } else {
1728
+ return buf.readUInt16BE(i2 * indexSize);
1729
+ }
1730
+ }
1731
+ let i;
1732
+ if (dir) {
1733
+ let foundIndex = -1;
1734
+ for (i = byteOffset; i < arrLength; i++) {
1735
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
1736
+ if (foundIndex === -1)
1737
+ foundIndex = i;
1738
+ if (i - foundIndex + 1 === valLength)
1739
+ return foundIndex * indexSize;
1740
+ } else {
1741
+ if (foundIndex !== -1)
1742
+ i -= i - foundIndex;
1743
+ foundIndex = -1;
1744
+ }
1745
+ }
1746
+ } else {
1747
+ if (byteOffset + valLength > arrLength) {
1748
+ byteOffset = arrLength - valLength;
1749
+ }
1750
+ for (i = byteOffset; i >= 0; i--) {
1751
+ let found = true;
1752
+ for (let j = 0; j < valLength; j++) {
1753
+ if (read(arr, i + j) !== read(val, j)) {
1754
+ found = false;
1755
+ break;
1756
+ }
1757
+ }
1758
+ if (found) {
1759
+ return i;
1760
+ }
1761
+ }
1762
+ }
1763
+ return -1;
1764
+ }
1765
+ static _checkOffset(offset, ext, length) {
1766
+ if (offset % 1 !== 0 || offset < 0)
1767
+ throw new RangeError("offset is not uint");
1768
+ if (offset + ext > length)
1769
+ throw new RangeError("Trying to access beyond buffer length");
1770
+ }
1771
+ static _checkInt(buf, value, offset, ext, max, min) {
1772
+ if (!Buffer.isBuffer(buf))
1773
+ throw new TypeError('"buffer" argument must be a Buffer instance');
1774
+ if (value > max || value < min)
1775
+ throw new RangeError('"value" argument is out of bounds');
1776
+ if (offset + ext > buf.length)
1777
+ throw new RangeError("Index out of range");
1778
+ }
1779
+ static _getEncoding(encoding) {
1780
+ let toLowerCase = false;
1781
+ let originalEncoding = "";
1782
+ for (; ; ) {
1783
+ switch (encoding) {
1784
+ case "hex":
1785
+ return "hex";
1786
+ case "utf8":
1787
+ return "utf8";
1788
+ case "ascii":
1789
+ return "ascii";
1790
+ case "binary":
1791
+ return "binary";
1792
+ case "latin1":
1793
+ return "latin1";
1794
+ case "ucs2":
1795
+ return "ucs2";
1796
+ case "utf16le":
1797
+ return "utf16le";
1798
+ case "base64":
1799
+ return "base64";
1800
+ default: {
1801
+ if (toLowerCase) {
1802
+ throw new TypeError("Unknown or unsupported encoding: " + originalEncoding);
1803
+ }
1804
+ toLowerCase = true;
1805
+ originalEncoding = encoding;
1806
+ encoding = encoding.toLowerCase();
1807
+ }
1808
+ }
1809
+ }
1810
+ }
1811
+ }
1812
+ const hexSliceLookupTable = function() {
1813
+ const alphabet = "0123456789abcdef";
1814
+ const table = new Array(256);
1815
+ for (let i = 0; i < 16; ++i) {
1816
+ const i16 = i * 16;
1817
+ for (let j = 0; j < 16; ++j) {
1818
+ table[i16 + j] = alphabet[i] + alphabet[j];
1819
+ }
1820
+ }
1821
+ return table;
1822
+ }();
1823
+ const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
1824
+ function base64clean(str) {
1825
+ str = str.split("=")[0];
1826
+ str = str.trim().replace(INVALID_BASE64_RE, "");
1827
+ if (str.length < 2)
1828
+ return "";
1829
+ while (str.length % 4 !== 0) {
1830
+ str = str + "=";
1831
+ }
1832
+ return str;
1833
+ }
1834
+
27
1835
  function notEmpty(value) {
28
1836
  return value !== null && value !== void 0;
29
1837
  }
@@ -259,7 +2067,7 @@ var __privateAdd$6 = (obj, member, value) => {
259
2067
  };
260
2068
  var __privateSet$4 = (obj, member, value, setter) => {
261
2069
  __accessCheck$6(obj, member, "write to private field");
262
- setter ? setter.call(obj, value) : member.set(obj, value);
2070
+ member.set(obj, value);
263
2071
  return value;
264
2072
  };
265
2073
  var __privateMethod$4 = (obj, member, method) => {
@@ -528,7 +2336,7 @@ function defaultOnOpen(response) {
528
2336
  }
529
2337
  }
530
2338
 
531
- const VERSION = "0.29.1";
2339
+ const VERSION = "0.29.4";
532
2340
 
533
2341
  class ErrorWithCause extends Error {
534
2342
  constructor(message, options) {
@@ -621,15 +2429,15 @@ function parseWorkspacesUrlParts(url) {
621
2429
  if (!isString(url))
622
2430
  return null;
623
2431
  const matches = {
624
- production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
625
- staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
626
- dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
627
- local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
2432
+ production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh\/db\/([^:]+):?(.*)?/),
2433
+ staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev\/db\/([^:]+):?(.*)?/),
2434
+ dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev\/db\/([^:]+):?(.*)?/),
2435
+ local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(?:\d+)\/db\/([^:]+):?(.*)?/)
628
2436
  };
629
2437
  const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
630
2438
  if (!isHostProviderAlias(host) || !match)
631
2439
  return null;
632
- return { workspace: match[1], region: match[2], host };
2440
+ return { workspace: match[1], region: match[2], database: match[3], branch: match[4], host };
633
2441
  }
634
2442
 
635
2443
  const pool = new ApiRequestPool();
@@ -740,6 +2548,8 @@ async function fetch$1({
740
2548
  "X-Xata-Client-ID": clientID ?? defaultClientID,
741
2549
  "X-Xata-Session-ID": sessionID ?? generateUUID(),
742
2550
  "X-Xata-Agent": xataAgent,
2551
+ // Force field rename to xata_ internal properties
2552
+ "X-Features": compact(["feat-internal-field-rename-api=1", customHeaders?.["X-Features"]]).join(" "),
743
2553
  ...customHeaders,
744
2554
  ...hostHeader(fullUrl),
745
2555
  Authorization: `Bearer ${apiKey}`
@@ -847,16 +2657,42 @@ function parseUrl(url) {
847
2657
 
848
2658
  const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
849
2659
 
850
- const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/apply", method: "post", ...variables, signal });
2660
+ const applyMigration = (variables, signal) => dataPlaneFetch({
2661
+ url: "/db/{dbBranchName}/migrations/apply",
2662
+ method: "post",
2663
+ ...variables,
2664
+ signal
2665
+ });
851
2666
  const adaptTable = (variables, signal) => dataPlaneFetch({
852
2667
  url: "/db/{dbBranchName}/migrations/adapt/{tableName}",
853
2668
  method: "post",
854
2669
  ...variables,
855
2670
  signal
856
2671
  });
857
- const getBranchMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/status", method: "get", ...variables, signal });
858
- const getMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/jobs/{jobId}", method: "get", ...variables, signal });
859
- const getMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/history", method: "get", ...variables, signal });
2672
+ const adaptAllTables = (variables, signal) => dataPlaneFetch({
2673
+ url: "/db/{dbBranchName}/migrations/adapt",
2674
+ method: "post",
2675
+ ...variables,
2676
+ signal
2677
+ });
2678
+ const getBranchMigrationJobStatus = (variables, signal) => dataPlaneFetch({
2679
+ url: "/db/{dbBranchName}/migrations/status",
2680
+ method: "get",
2681
+ ...variables,
2682
+ signal
2683
+ });
2684
+ const getMigrationJobStatus = (variables, signal) => dataPlaneFetch({
2685
+ url: "/db/{dbBranchName}/migrations/jobs/{jobId}",
2686
+ method: "get",
2687
+ ...variables,
2688
+ signal
2689
+ });
2690
+ const getMigrationHistory = (variables, signal) => dataPlaneFetch({
2691
+ url: "/db/{dbBranchName}/migrations/history",
2692
+ method: "get",
2693
+ ...variables,
2694
+ signal
2695
+ });
860
2696
  const getBranchList = (variables, signal) => dataPlaneFetch({
861
2697
  url: "/dbs/{dbName}",
862
2698
  method: "get",
@@ -915,12 +2751,42 @@ const getBranchStats = (variables, signal) => dataPlaneFetch({
915
2751
  });
916
2752
  const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
917
2753
  const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
918
- const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
919
- const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
920
- const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
921
- const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
922
- const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
923
- const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
2754
+ const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({
2755
+ url: "/dbs/{dbName}/gitBranches",
2756
+ method: "delete",
2757
+ ...variables,
2758
+ signal
2759
+ });
2760
+ const resolveBranch = (variables, signal) => dataPlaneFetch({
2761
+ url: "/dbs/{dbName}/resolveBranch",
2762
+ method: "get",
2763
+ ...variables,
2764
+ signal
2765
+ });
2766
+ const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({
2767
+ url: "/db/{dbBranchName}/migrations",
2768
+ method: "get",
2769
+ ...variables,
2770
+ signal
2771
+ });
2772
+ const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({
2773
+ url: "/db/{dbBranchName}/migrations/plan",
2774
+ method: "post",
2775
+ ...variables,
2776
+ signal
2777
+ });
2778
+ const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({
2779
+ url: "/db/{dbBranchName}/migrations/execute",
2780
+ method: "post",
2781
+ ...variables,
2782
+ signal
2783
+ });
2784
+ const queryMigrationRequests = (variables, signal) => dataPlaneFetch({
2785
+ url: "/dbs/{dbName}/migrations/query",
2786
+ method: "post",
2787
+ ...variables,
2788
+ signal
2789
+ });
924
2790
  const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
925
2791
  const getMigrationRequest = (variables, signal) => dataPlaneFetch({
926
2792
  url: "/dbs/{dbName}/migrations/{mrNumber}",
@@ -928,23 +2794,78 @@ const getMigrationRequest = (variables, signal) => dataPlaneFetch({
928
2794
  ...variables,
929
2795
  signal
930
2796
  });
931
- const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
932
- const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
933
- const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
934
- const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
2797
+ const updateMigrationRequest = (variables, signal) => dataPlaneFetch({
2798
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
2799
+ method: "patch",
2800
+ ...variables,
2801
+ signal
2802
+ });
2803
+ const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({
2804
+ url: "/dbs/{dbName}/migrations/{mrNumber}/commits",
2805
+ method: "post",
2806
+ ...variables,
2807
+ signal
2808
+ });
2809
+ const compareMigrationRequest = (variables, signal) => dataPlaneFetch({
2810
+ url: "/dbs/{dbName}/migrations/{mrNumber}/compare",
2811
+ method: "post",
2812
+ ...variables,
2813
+ signal
2814
+ });
2815
+ const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({
2816
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
2817
+ method: "get",
2818
+ ...variables,
2819
+ signal
2820
+ });
935
2821
  const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
936
2822
  url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
937
2823
  method: "post",
938
2824
  ...variables,
939
2825
  signal
940
2826
  });
941
- const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
942
- const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
943
- const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
944
- const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
945
- const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
946
- const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
947
- const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
2827
+ const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({
2828
+ url: "/db/{dbBranchName}/schema/history",
2829
+ method: "post",
2830
+ ...variables,
2831
+ signal
2832
+ });
2833
+ const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({
2834
+ url: "/db/{dbBranchName}/schema/compare",
2835
+ method: "post",
2836
+ ...variables,
2837
+ signal
2838
+ });
2839
+ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({
2840
+ url: "/db/{dbBranchName}/schema/compare/{branchName}",
2841
+ method: "post",
2842
+ ...variables,
2843
+ signal
2844
+ });
2845
+ const updateBranchSchema = (variables, signal) => dataPlaneFetch({
2846
+ url: "/db/{dbBranchName}/schema/update",
2847
+ method: "post",
2848
+ ...variables,
2849
+ signal
2850
+ });
2851
+ const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({
2852
+ url: "/db/{dbBranchName}/schema/preview",
2853
+ method: "post",
2854
+ ...variables,
2855
+ signal
2856
+ });
2857
+ const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({
2858
+ url: "/db/{dbBranchName}/schema/apply",
2859
+ method: "post",
2860
+ ...variables,
2861
+ signal
2862
+ });
2863
+ const pushBranchMigrations = (variables, signal) => dataPlaneFetch({
2864
+ url: "/db/{dbBranchName}/schema/push",
2865
+ method: "post",
2866
+ ...variables,
2867
+ signal
2868
+ });
948
2869
  const createTable = (variables, signal) => dataPlaneFetch({
949
2870
  url: "/db/{dbBranchName}/tables/{tableName}",
950
2871
  method: "put",
@@ -957,14 +2878,24 @@ const deleteTable = (variables, signal) => dataPlaneFetch({
957
2878
  ...variables,
958
2879
  signal
959
2880
  });
960
- const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
2881
+ const updateTable = (variables, signal) => dataPlaneFetch({
2882
+ url: "/db/{dbBranchName}/tables/{tableName}",
2883
+ method: "patch",
2884
+ ...variables,
2885
+ signal
2886
+ });
961
2887
  const getTableSchema = (variables, signal) => dataPlaneFetch({
962
2888
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
963
2889
  method: "get",
964
2890
  ...variables,
965
2891
  signal
966
2892
  });
967
- const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
2893
+ const setTableSchema = (variables, signal) => dataPlaneFetch({
2894
+ url: "/db/{dbBranchName}/tables/{tableName}/schema",
2895
+ method: "put",
2896
+ ...variables,
2897
+ signal
2898
+ });
968
2899
  const getTableColumns = (variables, signal) => dataPlaneFetch({
969
2900
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
970
2901
  method: "get",
@@ -972,7 +2903,12 @@ const getTableColumns = (variables, signal) => dataPlaneFetch({
972
2903
  signal
973
2904
  });
974
2905
  const addTableColumn = (variables, signal) => dataPlaneFetch(
975
- { url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
2906
+ {
2907
+ url: "/db/{dbBranchName}/tables/{tableName}/columns",
2908
+ method: "post",
2909
+ ...variables,
2910
+ signal
2911
+ }
976
2912
  );
977
2913
  const getColumn = (variables, signal) => dataPlaneFetch({
978
2914
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
@@ -980,15 +2916,30 @@ const getColumn = (variables, signal) => dataPlaneFetch({
980
2916
  ...variables,
981
2917
  signal
982
2918
  });
983
- const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
2919
+ const updateColumn = (variables, signal) => dataPlaneFetch({
2920
+ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
2921
+ method: "patch",
2922
+ ...variables,
2923
+ signal
2924
+ });
984
2925
  const deleteColumn = (variables, signal) => dataPlaneFetch({
985
2926
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
986
2927
  method: "delete",
987
2928
  ...variables,
988
2929
  signal
989
2930
  });
990
- const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
991
- const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
2931
+ const branchTransaction = (variables, signal) => dataPlaneFetch({
2932
+ url: "/db/{dbBranchName}/transaction",
2933
+ method: "post",
2934
+ ...variables,
2935
+ signal
2936
+ });
2937
+ const insertRecord = (variables, signal) => dataPlaneFetch({
2938
+ url: "/db/{dbBranchName}/tables/{tableName}/data",
2939
+ method: "post",
2940
+ ...variables,
2941
+ signal
2942
+ });
992
2943
  const getFileItem = (variables, signal) => dataPlaneFetch({
993
2944
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
994
2945
  method: "get",
@@ -1031,11 +2982,36 @@ const getRecord = (variables, signal) => dataPlaneFetch({
1031
2982
  ...variables,
1032
2983
  signal
1033
2984
  });
1034
- const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
1035
- const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
1036
- const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
1037
- const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
1038
- const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
2985
+ const insertRecordWithID = (variables, signal) => dataPlaneFetch({
2986
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
2987
+ method: "put",
2988
+ ...variables,
2989
+ signal
2990
+ });
2991
+ const updateRecordWithID = (variables, signal) => dataPlaneFetch({
2992
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
2993
+ method: "patch",
2994
+ ...variables,
2995
+ signal
2996
+ });
2997
+ const upsertRecordWithID = (variables, signal) => dataPlaneFetch({
2998
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
2999
+ method: "post",
3000
+ ...variables,
3001
+ signal
3002
+ });
3003
+ const deleteRecord = (variables, signal) => dataPlaneFetch({
3004
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
3005
+ method: "delete",
3006
+ ...variables,
3007
+ signal
3008
+ });
3009
+ const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({
3010
+ url: "/db/{dbBranchName}/tables/{tableName}/bulk",
3011
+ method: "post",
3012
+ ...variables,
3013
+ signal
3014
+ });
1039
3015
  const queryTable = (variables, signal) => dataPlaneFetch({
1040
3016
  url: "/db/{dbBranchName}/tables/{tableName}/query",
1041
3017
  method: "post",
@@ -1054,16 +3030,36 @@ const searchTable = (variables, signal) => dataPlaneFetch({
1054
3030
  ...variables,
1055
3031
  signal
1056
3032
  });
1057
- const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
3033
+ const vectorSearchTable = (variables, signal) => dataPlaneFetch({
3034
+ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch",
3035
+ method: "post",
3036
+ ...variables,
3037
+ signal
3038
+ });
1058
3039
  const askTable = (variables, signal) => dataPlaneFetch({
1059
3040
  url: "/db/{dbBranchName}/tables/{tableName}/ask",
1060
3041
  method: "post",
1061
3042
  ...variables,
1062
3043
  signal
1063
3044
  });
1064
- const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
1065
- const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
1066
- const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
3045
+ const askTableSession = (variables, signal) => dataPlaneFetch({
3046
+ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
3047
+ method: "post",
3048
+ ...variables,
3049
+ signal
3050
+ });
3051
+ const summarizeTable = (variables, signal) => dataPlaneFetch({
3052
+ url: "/db/{dbBranchName}/tables/{tableName}/summarize",
3053
+ method: "post",
3054
+ ...variables,
3055
+ signal
3056
+ });
3057
+ const aggregateTable = (variables, signal) => dataPlaneFetch({
3058
+ url: "/db/{dbBranchName}/tables/{tableName}/aggregate",
3059
+ method: "post",
3060
+ ...variables,
3061
+ signal
3062
+ });
1067
3063
  const fileAccess = (variables, signal) => dataPlaneFetch({
1068
3064
  url: "/file/{fileId}",
1069
3065
  method: "get",
@@ -1086,6 +3082,7 @@ const operationsByTag$2 = {
1086
3082
  migrations: {
1087
3083
  applyMigration,
1088
3084
  adaptTable,
3085
+ adaptAllTables,
1089
3086
  getBranchMigrationJobStatus,
1090
3087
  getMigrationJobStatus,
1091
3088
  getMigrationHistory,
@@ -1148,7 +3145,16 @@ const operationsByTag$2 = {
1148
3145
  deleteRecord,
1149
3146
  bulkInsertTableRecords
1150
3147
  },
1151
- files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
3148
+ files: {
3149
+ getFileItem,
3150
+ putFileItem,
3151
+ deleteFileItem,
3152
+ getFile,
3153
+ putFile,
3154
+ deleteFile,
3155
+ fileAccess,
3156
+ fileUpload
3157
+ },
1152
3158
  searchAndFilter: {
1153
3159
  queryTable,
1154
3160
  searchBranch,
@@ -1226,7 +3232,12 @@ const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
1226
3232
  ...variables,
1227
3233
  signal
1228
3234
  });
1229
- const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
3235
+ const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({
3236
+ url: "/user/oauth/tokens/{token}",
3237
+ method: "patch",
3238
+ ...variables,
3239
+ signal
3240
+ });
1230
3241
  const getWorkspacesList = (variables, signal) => controlPlaneFetch({
1231
3242
  url: "/workspaces",
1232
3243
  method: "get",
@@ -1257,47 +3268,150 @@ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
1257
3268
  ...variables,
1258
3269
  signal
1259
3270
  });
1260
- const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
1261
- const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
3271
+ const getWorkspaceSettings = (variables, signal) => controlPlaneFetch({
3272
+ url: "/workspaces/{workspaceId}/settings",
3273
+ method: "get",
3274
+ ...variables,
3275
+ signal
3276
+ });
3277
+ const updateWorkspaceSettings = (variables, signal) => controlPlaneFetch({
3278
+ url: "/workspaces/{workspaceId}/settings",
3279
+ method: "patch",
3280
+ ...variables,
3281
+ signal
3282
+ });
3283
+ const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({
3284
+ url: "/workspaces/{workspaceId}/members",
3285
+ method: "get",
3286
+ ...variables,
3287
+ signal
3288
+ });
3289
+ const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({
3290
+ url: "/workspaces/{workspaceId}/members/{userId}",
3291
+ method: "put",
3292
+ ...variables,
3293
+ signal
3294
+ });
1262
3295
  const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
1263
3296
  url: "/workspaces/{workspaceId}/members/{userId}",
1264
3297
  method: "delete",
1265
3298
  ...variables,
1266
3299
  signal
1267
3300
  });
1268
- const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
1269
- const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
1270
- const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
1271
- const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
1272
- const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
1273
- const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
1274
- const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
3301
+ const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({
3302
+ url: "/workspaces/{workspaceId}/invites",
3303
+ method: "post",
3304
+ ...variables,
3305
+ signal
3306
+ });
3307
+ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({
3308
+ url: "/workspaces/{workspaceId}/invites/{inviteId}",
3309
+ method: "patch",
3310
+ ...variables,
3311
+ signal
3312
+ });
3313
+ const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({
3314
+ url: "/workspaces/{workspaceId}/invites/{inviteId}",
3315
+ method: "delete",
3316
+ ...variables,
3317
+ signal
3318
+ });
3319
+ const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({
3320
+ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
3321
+ method: "post",
3322
+ ...variables,
3323
+ signal
3324
+ });
3325
+ const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({
3326
+ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
3327
+ method: "post",
3328
+ ...variables,
3329
+ signal
3330
+ });
3331
+ const listClusters = (variables, signal) => controlPlaneFetch({
3332
+ url: "/workspaces/{workspaceId}/clusters",
3333
+ method: "get",
3334
+ ...variables,
3335
+ signal
3336
+ });
3337
+ const createCluster = (variables, signal) => controlPlaneFetch({
3338
+ url: "/workspaces/{workspaceId}/clusters",
3339
+ method: "post",
3340
+ ...variables,
3341
+ signal
3342
+ });
1275
3343
  const getCluster = (variables, signal) => controlPlaneFetch({
1276
3344
  url: "/workspaces/{workspaceId}/clusters/{clusterId}",
1277
3345
  method: "get",
1278
3346
  ...variables,
1279
3347
  signal
1280
3348
  });
1281
- const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
3349
+ const updateCluster = (variables, signal) => controlPlaneFetch({
3350
+ url: "/workspaces/{workspaceId}/clusters/{clusterId}",
3351
+ method: "patch",
3352
+ ...variables,
3353
+ signal
3354
+ });
3355
+ const deleteCluster = (variables, signal) => controlPlaneFetch({
3356
+ url: "/workspaces/{workspaceId}/clusters/{clusterId}",
3357
+ method: "delete",
3358
+ ...variables,
3359
+ signal
3360
+ });
1282
3361
  const getDatabaseList = (variables, signal) => controlPlaneFetch({
1283
3362
  url: "/workspaces/{workspaceId}/dbs",
1284
3363
  method: "get",
1285
3364
  ...variables,
1286
3365
  signal
1287
3366
  });
1288
- const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
3367
+ const createDatabase = (variables, signal) => controlPlaneFetch({
3368
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
3369
+ method: "put",
3370
+ ...variables,
3371
+ signal
3372
+ });
1289
3373
  const deleteDatabase = (variables, signal) => controlPlaneFetch({
1290
3374
  url: "/workspaces/{workspaceId}/dbs/{dbName}",
1291
3375
  method: "delete",
1292
3376
  ...variables,
1293
3377
  signal
1294
3378
  });
1295
- const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
1296
- const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
1297
- const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
1298
- const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
1299
- const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
1300
- const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
3379
+ const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({
3380
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
3381
+ method: "get",
3382
+ ...variables,
3383
+ signal
3384
+ });
3385
+ const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({
3386
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
3387
+ method: "patch",
3388
+ ...variables,
3389
+ signal
3390
+ });
3391
+ const renameDatabase = (variables, signal) => controlPlaneFetch({
3392
+ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename",
3393
+ method: "post",
3394
+ ...variables,
3395
+ signal
3396
+ });
3397
+ const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({
3398
+ url: "/workspaces/{workspaceId}/dbs/{dbName}/github",
3399
+ method: "get",
3400
+ ...variables,
3401
+ signal
3402
+ });
3403
+ const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({
3404
+ url: "/workspaces/{workspaceId}/dbs/{dbName}/github",
3405
+ method: "put",
3406
+ ...variables,
3407
+ signal
3408
+ });
3409
+ const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({
3410
+ url: "/workspaces/{workspaceId}/dbs/{dbName}/github",
3411
+ method: "delete",
3412
+ ...variables,
3413
+ signal
3414
+ });
1301
3415
  const listRegions = (variables, signal) => controlPlaneFetch({
1302
3416
  url: "/workspaces/{workspaceId}/regions",
1303
3417
  method: "get",
@@ -1322,6 +3436,8 @@ const operationsByTag$1 = {
1322
3436
  getWorkspace,
1323
3437
  updateWorkspace,
1324
3438
  deleteWorkspace,
3439
+ getWorkspaceSettings,
3440
+ updateWorkspaceSettings,
1325
3441
  getWorkspaceMembersList,
1326
3442
  updateWorkspaceMemberRole,
1327
3443
  removeWorkspaceMember
@@ -1333,7 +3449,13 @@ const operationsByTag$1 = {
1333
3449
  acceptWorkspaceMemberInvite,
1334
3450
  resendWorkspaceMemberInvite
1335
3451
  },
1336
- xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
3452
+ xbcontrolOther: {
3453
+ listClusters,
3454
+ createCluster,
3455
+ getCluster,
3456
+ updateCluster,
3457
+ deleteCluster
3458
+ },
1337
3459
  databases: {
1338
3460
  getDatabaseList,
1339
3461
  createDatabase,
@@ -1610,7 +3732,7 @@ var __privateAdd$5 = (obj, member, value) => {
1610
3732
  };
1611
3733
  var __privateSet$3 = (obj, member, value, setter) => {
1612
3734
  __accessCheck$5(obj, member, "write to private field");
1613
- setter ? setter.call(obj, value) : member.set(obj, value);
3735
+ member.set(obj, value);
1614
3736
  return value;
1615
3737
  };
1616
3738
  var _query, _page;
@@ -1789,7 +3911,7 @@ var __privateAdd$4 = (obj, member, value) => {
1789
3911
  };
1790
3912
  var __privateSet$2 = (obj, member, value, setter) => {
1791
3913
  __accessCheck$4(obj, member, "write to private field");
1792
- setter ? setter.call(obj, value) : member.set(obj, value);
3914
+ member.set(obj, value);
1793
3915
  return value;
1794
3916
  };
1795
3917
  var __privateMethod$3 = (obj, member, method) => {
@@ -2025,8 +4147,8 @@ cleanFilterConstraint_fn = function(column, value) {
2025
4147
  if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
2026
4148
  return { $includes: value };
2027
4149
  }
2028
- if (columnType === "link" && isObject(value) && isString(value.id)) {
2029
- return value.id;
4150
+ if (columnType === "link" && isObject(value) && isString(value.xata_id)) {
4151
+ return value.xata_id;
2030
4152
  }
2031
4153
  return value;
2032
4154
  };
@@ -2054,12 +4176,7 @@ const RecordColumnTypes = [
2054
4176
  "json"
2055
4177
  ];
2056
4178
  function isIdentifiable(x) {
2057
- return isObject(x) && isString(x?.id);
2058
- }
2059
- function isXataRecord(x) {
2060
- const record = x;
2061
- const metadata = record?.getMetadata();
2062
- return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
4179
+ return isObject(x) && isString(x?.xata_id);
2063
4180
  }
2064
4181
 
2065
4182
  function isValidExpandedColumn(column) {
@@ -2122,7 +4239,7 @@ var __privateAdd$3 = (obj, member, value) => {
2122
4239
  };
2123
4240
  var __privateSet$1 = (obj, member, value, setter) => {
2124
4241
  __accessCheck$3(obj, member, "write to private field");
2125
- setter ? setter.call(obj, value) : member.set(obj, value);
4242
+ member.set(obj, value);
2126
4243
  return value;
2127
4244
  };
2128
4245
  var __privateMethod$2 = (obj, member, method) => {
@@ -2186,11 +4303,14 @@ class RestRepository extends Query {
2186
4303
  const columns = isValidSelectableColumns(c) ? c : void 0;
2187
4304
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
2188
4305
  }
2189
- if (isObject(a) && isString(a.id)) {
2190
- if (a.id === "")
4306
+ if (isObject(a) && isString(a.xata_id)) {
4307
+ if (a.xata_id === "")
2191
4308
  throw new Error("The id can't be empty");
2192
4309
  const columns = isValidSelectableColumns(b) ? b : void 0;
2193
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
4310
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
4311
+ createOnly: true,
4312
+ ifVersion
4313
+ });
2194
4314
  }
2195
4315
  if (isObject(a)) {
2196
4316
  const columns = isValidSelectableColumns(b) ? b : void 0;
@@ -2206,9 +4326,9 @@ class RestRepository extends Query {
2206
4326
  if (a.length === 0)
2207
4327
  return [];
2208
4328
  const ids = a.map((item) => extractId(item));
2209
- const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
4329
+ const finalObjects = await this.getAll({ filter: { xata_id: { $any: compact(ids) } }, columns });
2210
4330
  const dictionary = finalObjects.reduce((acc, object) => {
2211
- acc[object.id] = object;
4331
+ acc[object.xata_id] = object;
2212
4332
  return acc;
2213
4333
  }, {});
2214
4334
  return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
@@ -2270,7 +4390,7 @@ class RestRepository extends Query {
2270
4390
  if (Array.isArray(a)) {
2271
4391
  if (a.length === 0)
2272
4392
  return [];
2273
- const existing = await this.read(a, ["id"]);
4393
+ const existing = await this.read(a, ["xata_id"]);
2274
4394
  const updates = a.filter((_item, index) => existing[index] !== null);
2275
4395
  await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
2276
4396
  ifVersion,
@@ -2285,9 +4405,9 @@ class RestRepository extends Query {
2285
4405
  const columns = isValidSelectableColumns(c) ? c : void 0;
2286
4406
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2287
4407
  }
2288
- if (isObject(a) && isString(a.id)) {
4408
+ if (isObject(a) && isString(a.xata_id)) {
2289
4409
  const columns = isValidSelectableColumns(b) ? b : void 0;
2290
- return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
4410
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
2291
4411
  }
2292
4412
  } catch (error) {
2293
4413
  if (error.status === 422)
@@ -2336,16 +4456,16 @@ class RestRepository extends Query {
2336
4456
  const columns = isValidSelectableColumns(c) ? c : void 0;
2337
4457
  return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2338
4458
  }
2339
- if (isObject(a) && isString(a.id)) {
2340
- if (a.id === "")
4459
+ if (isObject(a) && isString(a.xata_id)) {
4460
+ if (a.xata_id === "")
2341
4461
  throw new Error("The id can't be empty");
2342
4462
  const columns = isValidSelectableColumns(c) ? c : void 0;
2343
- return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
4463
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
2344
4464
  }
2345
4465
  if (!isDefined(a) && isObject(b)) {
2346
4466
  return await this.create(b, c);
2347
4467
  }
2348
- if (isObject(a) && !isDefined(a.id)) {
4468
+ if (isObject(a) && !isDefined(a.xata_id)) {
2349
4469
  return await this.create(a, b);
2350
4470
  }
2351
4471
  throw new Error("Invalid arguments for createOrUpdate method");
@@ -2368,16 +4488,19 @@ class RestRepository extends Query {
2368
4488
  const columns = isValidSelectableColumns(c) ? c : void 0;
2369
4489
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2370
4490
  }
2371
- if (isObject(a) && isString(a.id)) {
2372
- if (a.id === "")
4491
+ if (isObject(a) && isString(a.xata_id)) {
4492
+ if (a.xata_id === "")
2373
4493
  throw new Error("The id can't be empty");
2374
4494
  const columns = isValidSelectableColumns(c) ? c : void 0;
2375
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
4495
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
4496
+ createOnly: false,
4497
+ ifVersion
4498
+ });
2376
4499
  }
2377
4500
  if (!isDefined(a) && isObject(b)) {
2378
4501
  return await this.create(b, c);
2379
4502
  }
2380
- if (isObject(a) && !isDefined(a.id)) {
4503
+ if (isObject(a) && !isDefined(a.xata_id)) {
2381
4504
  return await this.create(a, b);
2382
4505
  }
2383
4506
  throw new Error("Invalid arguments for createOrReplace method");
@@ -2391,8 +4514,8 @@ class RestRepository extends Query {
2391
4514
  const ids = a.map((o) => {
2392
4515
  if (isString(o))
2393
4516
  return o;
2394
- if (isString(o.id))
2395
- return o.id;
4517
+ if (isString(o.xata_id))
4518
+ return o.xata_id;
2396
4519
  throw new Error("Invalid arguments for delete method");
2397
4520
  });
2398
4521
  const columns = isValidSelectableColumns(b) ? b : ["*"];
@@ -2403,8 +4526,8 @@ class RestRepository extends Query {
2403
4526
  if (isString(a)) {
2404
4527
  return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
2405
4528
  }
2406
- if (isObject(a) && isString(a.id)) {
2407
- return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
4529
+ if (isObject(a) && isString(a.xata_id)) {
4530
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.xata_id, b);
2408
4531
  }
2409
4532
  throw new Error("Invalid arguments for delete method");
2410
4533
  });
@@ -2666,7 +4789,7 @@ _updateRecordWithID = new WeakSet();
2666
4789
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2667
4790
  if (!recordId)
2668
4791
  return null;
2669
- const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
4792
+ const { xata_id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2670
4793
  try {
2671
4794
  const response = await updateRecordWithID({
2672
4795
  pathParams: {
@@ -2691,9 +4814,9 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2691
4814
  };
2692
4815
  _updateRecords = new WeakSet();
2693
4816
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2694
- const operations = await promiseMap(objects, async ({ id, ...object }) => {
4817
+ const operations = await promiseMap(objects, async ({ xata_id, ...object }) => {
2695
4818
  const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2696
- return { update: { table: __privateGet$2(this, _table), id, ifVersion, upsert, fields } };
4819
+ return { update: { table: __privateGet$2(this, _table), id: xata_id, ifVersion, upsert, fields } };
2697
4820
  });
2698
4821
  const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
2699
4822
  const ids = [];
@@ -2798,12 +4921,12 @@ transformObjectToApi_fn = async function(object) {
2798
4921
  throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
2799
4922
  const result = {};
2800
4923
  for (const [key, value] of Object.entries(object)) {
2801
- if (key === "xata")
4924
+ if (["xata_version", "xata_createdat", "xata_updatedat"].includes(key))
2802
4925
  continue;
2803
4926
  const type = schema.columns.find((column) => column.name === key)?.type;
2804
4927
  switch (type) {
2805
4928
  case "link": {
2806
- result[key] = isIdentifiable(value) ? value.id : value;
4929
+ result[key] = isIdentifiable(value) ? value.xata_id : value;
2807
4930
  break;
2808
4931
  }
2809
4932
  case "datetime": {
@@ -2827,8 +4950,7 @@ transformObjectToApi_fn = async function(object) {
2827
4950
  };
2828
4951
  const initObject = (db, schemaTables, table, object, selectedColumns) => {
2829
4952
  const data = {};
2830
- const { xata, ...rest } = object ?? {};
2831
- Object.assign(data, rest);
4953
+ Object.assign(data, { ...object });
2832
4954
  const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
2833
4955
  if (!columns)
2834
4956
  console.error(`Table ${table} not found in schema`);
@@ -2891,28 +5013,21 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2891
5013
  }
2892
5014
  }
2893
5015
  const record = { ...data };
2894
- const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
2895
5016
  record.read = function(columns2) {
2896
- return db[table].read(record["id"], columns2);
5017
+ return db[table].read(record["xata_id"], columns2);
2897
5018
  };
2898
5019
  record.update = function(data2, b, c) {
2899
5020
  const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2900
5021
  const ifVersion = parseIfVersion(b, c);
2901
- return db[table].update(record["id"], data2, columns2, { ifVersion });
5022
+ return db[table].update(record["xata_id"], data2, columns2, { ifVersion });
2902
5023
  };
2903
5024
  record.replace = function(data2, b, c) {
2904
5025
  const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2905
5026
  const ifVersion = parseIfVersion(b, c);
2906
- return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
5027
+ return db[table].createOrReplace(record["xata_id"], data2, columns2, { ifVersion });
2907
5028
  };
2908
5029
  record.delete = function() {
2909
- return db[table].delete(record["id"]);
2910
- };
2911
- if (metadata !== void 0) {
2912
- record.xata = Object.freeze(metadata);
2913
- }
2914
- record.getMetadata = function() {
2915
- return record.xata;
5030
+ return db[table].delete(record["xata_id"]);
2916
5031
  };
2917
5032
  record.toSerializable = function() {
2918
5033
  return JSON.parse(JSON.stringify(record));
@@ -2920,7 +5035,7 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2920
5035
  record.toString = function() {
2921
5036
  return JSON.stringify(record);
2922
5037
  };
2923
- for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
5038
+ for (const prop of ["read", "update", "replace", "delete", "toSerializable", "toString"]) {
2924
5039
  Object.defineProperty(record, prop, { enumerable: false });
2925
5040
  }
2926
5041
  Object.freeze(record);
@@ -2929,8 +5044,8 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2929
5044
  function extractId(value) {
2930
5045
  if (isString(value))
2931
5046
  return value;
2932
- if (isObject(value) && isString(value.id))
2933
- return value.id;
5047
+ if (isObject(value) && isString(value.xata_id))
5048
+ return value.xata_id;
2934
5049
  return void 0;
2935
5050
  }
2936
5051
  function isValidColumn(columns, column) {
@@ -3118,7 +5233,7 @@ class SearchPlugin extends XataPlugin {
3118
5233
  return {
3119
5234
  totalCount,
3120
5235
  records: records.map((record) => {
3121
- const { table = "orphan" } = record.xata;
5236
+ const table = record.xata_table;
3122
5237
  return { table, record: initObject(this.db, pluginOptions.tables, table, record, ["*"]) };
3123
5238
  })
3124
5239
  };
@@ -3126,7 +5241,7 @@ class SearchPlugin extends XataPlugin {
3126
5241
  byTable: async (query, options = {}) => {
3127
5242
  const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3128
5243
  const records = rawRecords.reduce((acc, record) => {
3129
- const { table = "orphan" } = record.xata;
5244
+ const table = record.xata_table;
3130
5245
  const items = acc[table] ?? [];
3131
5246
  const item = initObject(this.db, pluginOptions.tables, table, record, ["*"]);
3132
5247
  return { ...acc, [table]: [...items, item] };
@@ -3200,19 +5315,19 @@ function prepareParams(param1, param2) {
3200
5315
  return { statement, params: param2?.map((value) => prepareValue(value)) };
3201
5316
  }
3202
5317
  if (isObject(param1)) {
3203
- const { statement, params, consistency } = param1;
3204
- return { statement, params: params?.map((value) => prepareValue(value)), consistency };
5318
+ const { statement, params, consistency, responseType } = param1;
5319
+ return { statement, params: params?.map((value) => prepareValue(value)), consistency, responseType };
3205
5320
  }
3206
5321
  throw new Error("Invalid query");
3207
5322
  }
3208
5323
 
3209
5324
  class SQLPlugin extends XataPlugin {
3210
5325
  build(pluginOptions) {
3211
- return async (query, ...parameters) => {
5326
+ const sqlFunction = async (query, ...parameters) => {
3212
5327
  if (!isParamsObject(query) && (!isTemplateStringsArray(query) || !Array.isArray(parameters))) {
3213
5328
  throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
3214
5329
  }
3215
- const { statement, params, consistency } = prepareParams(query, parameters);
5330
+ const { statement, params, consistency, responseType } = prepareParams(query, parameters);
3216
5331
  const {
3217
5332
  records,
3218
5333
  rows,
@@ -3220,11 +5335,13 @@ class SQLPlugin extends XataPlugin {
3220
5335
  columns = []
3221
5336
  } = await sqlQuery({
3222
5337
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3223
- body: { statement, params, consistency },
5338
+ body: { statement, params, consistency, responseType },
3224
5339
  ...pluginOptions
3225
5340
  });
3226
5341
  return { records, rows, warning, columns };
3227
5342
  };
5343
+ sqlFunction.connectionString = buildConnectionString(pluginOptions);
5344
+ return sqlFunction;
3228
5345
  }
3229
5346
  }
3230
5347
  function isTemplateStringsArray(strings) {
@@ -3233,6 +5350,33 @@ function isTemplateStringsArray(strings) {
3233
5350
  function isParamsObject(params) {
3234
5351
  return isObject(params) && "statement" in params;
3235
5352
  }
5353
+ function buildDomain(host, region) {
5354
+ switch (host) {
5355
+ case "production":
5356
+ return `${region}.sql.xata.sh`;
5357
+ case "staging":
5358
+ return `${region}.sql.staging-xata.dev`;
5359
+ case "dev":
5360
+ return `${region}.sql.dev-xata.dev`;
5361
+ case "local":
5362
+ return "localhost:7654";
5363
+ default:
5364
+ throw new Error("Invalid host provider");
5365
+ }
5366
+ }
5367
+ function buildConnectionString({ apiKey, workspacesApiUrl, branch }) {
5368
+ const url = isString(workspacesApiUrl) ? workspacesApiUrl : workspacesApiUrl("", {});
5369
+ const parts = parseWorkspacesUrlParts(url);
5370
+ if (!parts)
5371
+ throw new Error("Invalid workspaces URL");
5372
+ const { workspace: workspaceSlug, region, database, host } = parts;
5373
+ const domain = buildDomain(host, region);
5374
+ const workspace = workspaceSlug.split("-").pop();
5375
+ if (!workspace || !region || !database || !apiKey || !branch) {
5376
+ throw new Error("Unable to build xata connection string");
5377
+ }
5378
+ return `postgresql://${workspace}:${apiKey}@${domain}/${database}:${branch}?sslmode=require`;
5379
+ }
3236
5380
 
3237
5381
  class TransactionPlugin extends XataPlugin {
3238
5382
  build(pluginOptions) {
@@ -3264,7 +5408,7 @@ var __privateAdd = (obj, member, value) => {
3264
5408
  };
3265
5409
  var __privateSet = (obj, member, value, setter) => {
3266
5410
  __accessCheck(obj, member, "write to private field");
3267
- setter ? setter.call(obj, value) : member.set(obj, value);
5411
+ member.set(obj, value);
3268
5412
  return value;
3269
5413
  };
3270
5414
  var __privateMethod = (obj, member, method) => {
@@ -3283,7 +5427,8 @@ const buildClient = (plugins) => {
3283
5427
  const pluginOptions = {
3284
5428
  ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3285
5429
  host: safeOptions.host,
3286
- tables
5430
+ tables,
5431
+ branch: safeOptions.branch
3287
5432
  };
3288
5433
  const db = new SchemaPlugin().build(pluginOptions);
3289
5434
  const search = new SearchPlugin(db).build(pluginOptions);
@@ -3465,6 +5610,7 @@ class XataError extends Error {
3465
5610
  }
3466
5611
 
3467
5612
  exports.BaseClient = BaseClient;
5613
+ exports.Buffer = Buffer;
3468
5614
  exports.FetcherError = FetcherError;
3469
5615
  exports.FilesPlugin = FilesPlugin;
3470
5616
  exports.Operations = operationsByTag;
@@ -3490,6 +5636,7 @@ exports.XataError = XataError;
3490
5636
  exports.XataFile = XataFile;
3491
5637
  exports.XataPlugin = XataPlugin;
3492
5638
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
5639
+ exports.adaptAllTables = adaptAllTables;
3493
5640
  exports.adaptTable = adaptTable;
3494
5641
  exports.addGitBranchesEntry = addGitBranchesEntry;
3495
5642
  exports.addTableColumn = addTableColumn;
@@ -3517,6 +5664,7 @@ exports.createTable = createTable;
3517
5664
  exports.createUserAPIKey = createUserAPIKey;
3518
5665
  exports.createWorkspace = createWorkspace;
3519
5666
  exports.deleteBranch = deleteBranch;
5667
+ exports.deleteCluster = deleteCluster;
3520
5668
  exports.deleteColumn = deleteColumn;
3521
5669
  exports.deleteDatabase = deleteDatabase;
3522
5670
  exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
@@ -3574,6 +5722,7 @@ exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
3574
5722
  exports.getUserOAuthClients = getUserOAuthClients;
3575
5723
  exports.getWorkspace = getWorkspace;
3576
5724
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
5725
+ exports.getWorkspaceSettings = getWorkspaceSettings;
3577
5726
  exports.getWorkspacesList = getWorkspacesList;
3578
5727
  exports.grantAuthorizationCode = grantAuthorizationCode;
3579
5728
  exports.greaterEquals = greaterEquals;
@@ -3598,7 +5747,6 @@ exports.isIdentifiable = isIdentifiable;
3598
5747
  exports.isNot = isNot;
3599
5748
  exports.isValidExpandedColumn = isValidExpandedColumn;
3600
5749
  exports.isValidSelectableColumns = isValidSelectableColumns;
3601
- exports.isXataRecord = isXataRecord;
3602
5750
  exports.le = le;
3603
5751
  exports.lessEquals = lessEquals;
3604
5752
  exports.lessThan = lessThan;
@@ -3648,6 +5796,7 @@ exports.updateUser = updateUser;
3648
5796
  exports.updateWorkspace = updateWorkspace;
3649
5797
  exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
3650
5798
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
5799
+ exports.updateWorkspaceSettings = updateWorkspaceSettings;
3651
5800
  exports.upsertRecordWithID = upsertRecordWithID;
3652
5801
  exports.vectorSearchTable = vectorSearchTable;
3653
5802
  //# sourceMappingURL=index.cjs.map