@xata.io/client 0.0.0-next.vc2100667c1c5b74e0ea53392c05d638b47363da4 → 0.0.0-next.vc44339ec360519ae99dcb7a9bc6854c1f2dcc741

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
  }
@@ -118,132 +1926,6 @@ function promiseMap(inputValues, mapper) {
118
1926
  return inputValues.reduce(reducer, Promise.resolve([]));
119
1927
  }
120
1928
 
121
- function getEnvironment() {
122
- try {
123
- if (isDefined(process) && isDefined(process.env)) {
124
- return {
125
- apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
126
- databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
127
- branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
128
- deployPreview: process.env.XATA_PREVIEW,
129
- deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
130
- vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
131
- vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
132
- };
133
- }
134
- } catch (err) {
135
- }
136
- try {
137
- if (isObject(Deno) && isObject(Deno.env)) {
138
- return {
139
- apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
140
- databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
141
- branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
142
- deployPreview: Deno.env.get("XATA_PREVIEW"),
143
- deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
144
- vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
145
- vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
146
- };
147
- }
148
- } catch (err) {
149
- }
150
- return {
151
- apiKey: getGlobalApiKey(),
152
- databaseURL: getGlobalDatabaseURL(),
153
- branch: getGlobalBranch(),
154
- deployPreview: void 0,
155
- deployPreviewBranch: void 0,
156
- vercelGitCommitRef: void 0,
157
- vercelGitRepoOwner: void 0
158
- };
159
- }
160
- function getEnableBrowserVariable() {
161
- try {
162
- if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
163
- return process.env.XATA_ENABLE_BROWSER === "true";
164
- }
165
- } catch (err) {
166
- }
167
- try {
168
- if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
169
- return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
170
- }
171
- } catch (err) {
172
- }
173
- try {
174
- return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
175
- } catch (err) {
176
- return void 0;
177
- }
178
- }
179
- function getGlobalApiKey() {
180
- try {
181
- return XATA_API_KEY;
182
- } catch (err) {
183
- return void 0;
184
- }
185
- }
186
- function getGlobalDatabaseURL() {
187
- try {
188
- return XATA_DATABASE_URL;
189
- } catch (err) {
190
- return void 0;
191
- }
192
- }
193
- function getGlobalBranch() {
194
- try {
195
- return XATA_BRANCH;
196
- } catch (err) {
197
- return void 0;
198
- }
199
- }
200
- function getDatabaseURL() {
201
- try {
202
- const { databaseURL } = getEnvironment();
203
- return databaseURL;
204
- } catch (err) {
205
- return void 0;
206
- }
207
- }
208
- function getAPIKey() {
209
- try {
210
- const { apiKey } = getEnvironment();
211
- return apiKey;
212
- } catch (err) {
213
- return void 0;
214
- }
215
- }
216
- function getBranch() {
217
- try {
218
- const { branch } = getEnvironment();
219
- return branch;
220
- } catch (err) {
221
- return void 0;
222
- }
223
- }
224
- function buildPreviewBranchName({ org, branch }) {
225
- return `preview-${org}-${branch}`;
226
- }
227
- function getPreviewBranch() {
228
- try {
229
- const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
230
- if (deployPreviewBranch)
231
- return deployPreviewBranch;
232
- switch (deployPreview) {
233
- case "vercel": {
234
- if (!vercelGitCommitRef || !vercelGitRepoOwner) {
235
- console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
236
- return void 0;
237
- }
238
- return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
239
- }
240
- }
241
- return void 0;
242
- } catch (err) {
243
- return void 0;
244
- }
245
- }
246
-
247
1929
  var __accessCheck$6 = (obj, member, msg) => {
248
1930
  if (!member.has(obj))
249
1931
  throw TypeError("Cannot " + msg);
@@ -259,7 +1941,7 @@ var __privateAdd$6 = (obj, member, value) => {
259
1941
  };
260
1942
  var __privateSet$4 = (obj, member, value, setter) => {
261
1943
  __accessCheck$6(obj, member, "write to private field");
262
- setter ? setter.call(obj, value) : member.set(obj, value);
1944
+ member.set(obj, value);
263
1945
  return value;
264
1946
  };
265
1947
  var __privateMethod$4 = (obj, member, method) => {
@@ -528,7 +2210,7 @@ function defaultOnOpen(response) {
528
2210
  }
529
2211
  }
530
2212
 
531
- const VERSION = "0.29.2";
2213
+ const VERSION = "0.29.4";
532
2214
 
533
2215
  class ErrorWithCause extends Error {
534
2216
  constructor(message, options) {
@@ -621,15 +2303,15 @@ function parseWorkspacesUrlParts(url) {
621
2303
  if (!isString(url))
622
2304
  return null;
623
2305
  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+)/)
2306
+ production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh\/db\/([^:]+):?(.*)?/),
2307
+ staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev\/db\/([^:]+):?(.*)?/),
2308
+ dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev\/db\/([^:]+):?(.*)?/),
2309
+ local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(?:\d+)\/db\/([^:]+):?(.*)?/)
628
2310
  };
629
2311
  const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
630
2312
  if (!isHostProviderAlias(host) || !match)
631
2313
  return null;
632
- return { workspace: match[1], region: match[2], host };
2314
+ return { workspace: match[1], region: match[2], database: match[3], branch: match[4], host };
633
2315
  }
634
2316
 
635
2317
  const pool = new ApiRequestPool();
@@ -849,16 +2531,42 @@ function parseUrl(url) {
849
2531
 
850
2532
  const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
851
2533
 
852
- const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/apply", method: "post", ...variables, signal });
2534
+ const applyMigration = (variables, signal) => dataPlaneFetch({
2535
+ url: "/db/{dbBranchName}/migrations/apply",
2536
+ method: "post",
2537
+ ...variables,
2538
+ signal
2539
+ });
853
2540
  const adaptTable = (variables, signal) => dataPlaneFetch({
854
2541
  url: "/db/{dbBranchName}/migrations/adapt/{tableName}",
855
2542
  method: "post",
856
2543
  ...variables,
857
2544
  signal
858
2545
  });
859
- const getBranchMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/status", method: "get", ...variables, signal });
860
- const getMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/jobs/{jobId}", method: "get", ...variables, signal });
861
- const getMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/history", method: "get", ...variables, signal });
2546
+ const adaptAllTables = (variables, signal) => dataPlaneFetch({
2547
+ url: "/db/{dbBranchName}/migrations/adapt",
2548
+ method: "post",
2549
+ ...variables,
2550
+ signal
2551
+ });
2552
+ const getBranchMigrationJobStatus = (variables, signal) => dataPlaneFetch({
2553
+ url: "/db/{dbBranchName}/migrations/status",
2554
+ method: "get",
2555
+ ...variables,
2556
+ signal
2557
+ });
2558
+ const getMigrationJobStatus = (variables, signal) => dataPlaneFetch({
2559
+ url: "/db/{dbBranchName}/migrations/jobs/{jobId}",
2560
+ method: "get",
2561
+ ...variables,
2562
+ signal
2563
+ });
2564
+ const getMigrationHistory = (variables, signal) => dataPlaneFetch({
2565
+ url: "/db/{dbBranchName}/migrations/history",
2566
+ method: "get",
2567
+ ...variables,
2568
+ signal
2569
+ });
862
2570
  const getBranchList = (variables, signal) => dataPlaneFetch({
863
2571
  url: "/dbs/{dbName}",
864
2572
  method: "get",
@@ -917,12 +2625,42 @@ const getBranchStats = (variables, signal) => dataPlaneFetch({
917
2625
  });
918
2626
  const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
919
2627
  const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
920
- const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
921
- const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
922
- const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
923
- const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
924
- const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
925
- const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
2628
+ const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({
2629
+ url: "/dbs/{dbName}/gitBranches",
2630
+ method: "delete",
2631
+ ...variables,
2632
+ signal
2633
+ });
2634
+ const resolveBranch = (variables, signal) => dataPlaneFetch({
2635
+ url: "/dbs/{dbName}/resolveBranch",
2636
+ method: "get",
2637
+ ...variables,
2638
+ signal
2639
+ });
2640
+ const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({
2641
+ url: "/db/{dbBranchName}/migrations",
2642
+ method: "get",
2643
+ ...variables,
2644
+ signal
2645
+ });
2646
+ const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({
2647
+ url: "/db/{dbBranchName}/migrations/plan",
2648
+ method: "post",
2649
+ ...variables,
2650
+ signal
2651
+ });
2652
+ const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({
2653
+ url: "/db/{dbBranchName}/migrations/execute",
2654
+ method: "post",
2655
+ ...variables,
2656
+ signal
2657
+ });
2658
+ const queryMigrationRequests = (variables, signal) => dataPlaneFetch({
2659
+ url: "/dbs/{dbName}/migrations/query",
2660
+ method: "post",
2661
+ ...variables,
2662
+ signal
2663
+ });
926
2664
  const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
927
2665
  const getMigrationRequest = (variables, signal) => dataPlaneFetch({
928
2666
  url: "/dbs/{dbName}/migrations/{mrNumber}",
@@ -930,23 +2668,78 @@ const getMigrationRequest = (variables, signal) => dataPlaneFetch({
930
2668
  ...variables,
931
2669
  signal
932
2670
  });
933
- const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
934
- const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
935
- const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
936
- const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
2671
+ const updateMigrationRequest = (variables, signal) => dataPlaneFetch({
2672
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
2673
+ method: "patch",
2674
+ ...variables,
2675
+ signal
2676
+ });
2677
+ const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({
2678
+ url: "/dbs/{dbName}/migrations/{mrNumber}/commits",
2679
+ method: "post",
2680
+ ...variables,
2681
+ signal
2682
+ });
2683
+ const compareMigrationRequest = (variables, signal) => dataPlaneFetch({
2684
+ url: "/dbs/{dbName}/migrations/{mrNumber}/compare",
2685
+ method: "post",
2686
+ ...variables,
2687
+ signal
2688
+ });
2689
+ const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({
2690
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
2691
+ method: "get",
2692
+ ...variables,
2693
+ signal
2694
+ });
937
2695
  const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
938
2696
  url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
939
2697
  method: "post",
940
2698
  ...variables,
941
2699
  signal
942
2700
  });
943
- const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
944
- const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
945
- const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
946
- const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
947
- const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
948
- const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
949
- const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
2701
+ const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({
2702
+ url: "/db/{dbBranchName}/schema/history",
2703
+ method: "post",
2704
+ ...variables,
2705
+ signal
2706
+ });
2707
+ const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({
2708
+ url: "/db/{dbBranchName}/schema/compare",
2709
+ method: "post",
2710
+ ...variables,
2711
+ signal
2712
+ });
2713
+ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({
2714
+ url: "/db/{dbBranchName}/schema/compare/{branchName}",
2715
+ method: "post",
2716
+ ...variables,
2717
+ signal
2718
+ });
2719
+ const updateBranchSchema = (variables, signal) => dataPlaneFetch({
2720
+ url: "/db/{dbBranchName}/schema/update",
2721
+ method: "post",
2722
+ ...variables,
2723
+ signal
2724
+ });
2725
+ const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({
2726
+ url: "/db/{dbBranchName}/schema/preview",
2727
+ method: "post",
2728
+ ...variables,
2729
+ signal
2730
+ });
2731
+ const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({
2732
+ url: "/db/{dbBranchName}/schema/apply",
2733
+ method: "post",
2734
+ ...variables,
2735
+ signal
2736
+ });
2737
+ const pushBranchMigrations = (variables, signal) => dataPlaneFetch({
2738
+ url: "/db/{dbBranchName}/schema/push",
2739
+ method: "post",
2740
+ ...variables,
2741
+ signal
2742
+ });
950
2743
  const createTable = (variables, signal) => dataPlaneFetch({
951
2744
  url: "/db/{dbBranchName}/tables/{tableName}",
952
2745
  method: "put",
@@ -959,14 +2752,24 @@ const deleteTable = (variables, signal) => dataPlaneFetch({
959
2752
  ...variables,
960
2753
  signal
961
2754
  });
962
- const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
2755
+ const updateTable = (variables, signal) => dataPlaneFetch({
2756
+ url: "/db/{dbBranchName}/tables/{tableName}",
2757
+ method: "patch",
2758
+ ...variables,
2759
+ signal
2760
+ });
963
2761
  const getTableSchema = (variables, signal) => dataPlaneFetch({
964
2762
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
965
2763
  method: "get",
966
2764
  ...variables,
967
2765
  signal
968
2766
  });
969
- const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
2767
+ const setTableSchema = (variables, signal) => dataPlaneFetch({
2768
+ url: "/db/{dbBranchName}/tables/{tableName}/schema",
2769
+ method: "put",
2770
+ ...variables,
2771
+ signal
2772
+ });
970
2773
  const getTableColumns = (variables, signal) => dataPlaneFetch({
971
2774
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
972
2775
  method: "get",
@@ -974,7 +2777,12 @@ const getTableColumns = (variables, signal) => dataPlaneFetch({
974
2777
  signal
975
2778
  });
976
2779
  const addTableColumn = (variables, signal) => dataPlaneFetch(
977
- { url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
2780
+ {
2781
+ url: "/db/{dbBranchName}/tables/{tableName}/columns",
2782
+ method: "post",
2783
+ ...variables,
2784
+ signal
2785
+ }
978
2786
  );
979
2787
  const getColumn = (variables, signal) => dataPlaneFetch({
980
2788
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
@@ -982,15 +2790,30 @@ const getColumn = (variables, signal) => dataPlaneFetch({
982
2790
  ...variables,
983
2791
  signal
984
2792
  });
985
- const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
2793
+ const updateColumn = (variables, signal) => dataPlaneFetch({
2794
+ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
2795
+ method: "patch",
2796
+ ...variables,
2797
+ signal
2798
+ });
986
2799
  const deleteColumn = (variables, signal) => dataPlaneFetch({
987
2800
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
988
2801
  method: "delete",
989
2802
  ...variables,
990
2803
  signal
991
2804
  });
992
- const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
993
- const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
2805
+ const branchTransaction = (variables, signal) => dataPlaneFetch({
2806
+ url: "/db/{dbBranchName}/transaction",
2807
+ method: "post",
2808
+ ...variables,
2809
+ signal
2810
+ });
2811
+ const insertRecord = (variables, signal) => dataPlaneFetch({
2812
+ url: "/db/{dbBranchName}/tables/{tableName}/data",
2813
+ method: "post",
2814
+ ...variables,
2815
+ signal
2816
+ });
994
2817
  const getFileItem = (variables, signal) => dataPlaneFetch({
995
2818
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
996
2819
  method: "get",
@@ -1033,11 +2856,36 @@ const getRecord = (variables, signal) => dataPlaneFetch({
1033
2856
  ...variables,
1034
2857
  signal
1035
2858
  });
1036
- const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
1037
- const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
1038
- const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
1039
- const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
1040
- const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
2859
+ const insertRecordWithID = (variables, signal) => dataPlaneFetch({
2860
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
2861
+ method: "put",
2862
+ ...variables,
2863
+ signal
2864
+ });
2865
+ const updateRecordWithID = (variables, signal) => dataPlaneFetch({
2866
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
2867
+ method: "patch",
2868
+ ...variables,
2869
+ signal
2870
+ });
2871
+ const upsertRecordWithID = (variables, signal) => dataPlaneFetch({
2872
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
2873
+ method: "post",
2874
+ ...variables,
2875
+ signal
2876
+ });
2877
+ const deleteRecord = (variables, signal) => dataPlaneFetch({
2878
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
2879
+ method: "delete",
2880
+ ...variables,
2881
+ signal
2882
+ });
2883
+ const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({
2884
+ url: "/db/{dbBranchName}/tables/{tableName}/bulk",
2885
+ method: "post",
2886
+ ...variables,
2887
+ signal
2888
+ });
1041
2889
  const queryTable = (variables, signal) => dataPlaneFetch({
1042
2890
  url: "/db/{dbBranchName}/tables/{tableName}/query",
1043
2891
  method: "post",
@@ -1056,16 +2904,36 @@ const searchTable = (variables, signal) => dataPlaneFetch({
1056
2904
  ...variables,
1057
2905
  signal
1058
2906
  });
1059
- const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
2907
+ const vectorSearchTable = (variables, signal) => dataPlaneFetch({
2908
+ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch",
2909
+ method: "post",
2910
+ ...variables,
2911
+ signal
2912
+ });
1060
2913
  const askTable = (variables, signal) => dataPlaneFetch({
1061
2914
  url: "/db/{dbBranchName}/tables/{tableName}/ask",
1062
2915
  method: "post",
1063
2916
  ...variables,
1064
2917
  signal
1065
2918
  });
1066
- const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
1067
- const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
1068
- const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
2919
+ const askTableSession = (variables, signal) => dataPlaneFetch({
2920
+ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
2921
+ method: "post",
2922
+ ...variables,
2923
+ signal
2924
+ });
2925
+ const summarizeTable = (variables, signal) => dataPlaneFetch({
2926
+ url: "/db/{dbBranchName}/tables/{tableName}/summarize",
2927
+ method: "post",
2928
+ ...variables,
2929
+ signal
2930
+ });
2931
+ const aggregateTable = (variables, signal) => dataPlaneFetch({
2932
+ url: "/db/{dbBranchName}/tables/{tableName}/aggregate",
2933
+ method: "post",
2934
+ ...variables,
2935
+ signal
2936
+ });
1069
2937
  const fileAccess = (variables, signal) => dataPlaneFetch({
1070
2938
  url: "/file/{fileId}",
1071
2939
  method: "get",
@@ -1088,6 +2956,7 @@ const operationsByTag$2 = {
1088
2956
  migrations: {
1089
2957
  applyMigration,
1090
2958
  adaptTable,
2959
+ adaptAllTables,
1091
2960
  getBranchMigrationJobStatus,
1092
2961
  getMigrationJobStatus,
1093
2962
  getMigrationHistory,
@@ -1150,7 +3019,16 @@ const operationsByTag$2 = {
1150
3019
  deleteRecord,
1151
3020
  bulkInsertTableRecords
1152
3021
  },
1153
- files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
3022
+ files: {
3023
+ getFileItem,
3024
+ putFileItem,
3025
+ deleteFileItem,
3026
+ getFile,
3027
+ putFile,
3028
+ deleteFile,
3029
+ fileAccess,
3030
+ fileUpload
3031
+ },
1154
3032
  searchAndFilter: {
1155
3033
  queryTable,
1156
3034
  searchBranch,
@@ -1228,7 +3106,12 @@ const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
1228
3106
  ...variables,
1229
3107
  signal
1230
3108
  });
1231
- const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
3109
+ const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({
3110
+ url: "/user/oauth/tokens/{token}",
3111
+ method: "patch",
3112
+ ...variables,
3113
+ signal
3114
+ });
1232
3115
  const getWorkspacesList = (variables, signal) => controlPlaneFetch({
1233
3116
  url: "/workspaces",
1234
3117
  method: "get",
@@ -1259,47 +3142,150 @@ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
1259
3142
  ...variables,
1260
3143
  signal
1261
3144
  });
1262
- const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
1263
- const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
3145
+ const getWorkspaceSettings = (variables, signal) => controlPlaneFetch({
3146
+ url: "/workspaces/{workspaceId}/settings",
3147
+ method: "get",
3148
+ ...variables,
3149
+ signal
3150
+ });
3151
+ const updateWorkspaceSettings = (variables, signal) => controlPlaneFetch({
3152
+ url: "/workspaces/{workspaceId}/settings",
3153
+ method: "patch",
3154
+ ...variables,
3155
+ signal
3156
+ });
3157
+ const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({
3158
+ url: "/workspaces/{workspaceId}/members",
3159
+ method: "get",
3160
+ ...variables,
3161
+ signal
3162
+ });
3163
+ const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({
3164
+ url: "/workspaces/{workspaceId}/members/{userId}",
3165
+ method: "put",
3166
+ ...variables,
3167
+ signal
3168
+ });
1264
3169
  const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
1265
3170
  url: "/workspaces/{workspaceId}/members/{userId}",
1266
3171
  method: "delete",
1267
3172
  ...variables,
1268
3173
  signal
1269
3174
  });
1270
- const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
1271
- const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
1272
- const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
1273
- const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
1274
- const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
1275
- const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
1276
- const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
3175
+ const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({
3176
+ url: "/workspaces/{workspaceId}/invites",
3177
+ method: "post",
3178
+ ...variables,
3179
+ signal
3180
+ });
3181
+ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({
3182
+ url: "/workspaces/{workspaceId}/invites/{inviteId}",
3183
+ method: "patch",
3184
+ ...variables,
3185
+ signal
3186
+ });
3187
+ const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({
3188
+ url: "/workspaces/{workspaceId}/invites/{inviteId}",
3189
+ method: "delete",
3190
+ ...variables,
3191
+ signal
3192
+ });
3193
+ const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({
3194
+ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
3195
+ method: "post",
3196
+ ...variables,
3197
+ signal
3198
+ });
3199
+ const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({
3200
+ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
3201
+ method: "post",
3202
+ ...variables,
3203
+ signal
3204
+ });
3205
+ const listClusters = (variables, signal) => controlPlaneFetch({
3206
+ url: "/workspaces/{workspaceId}/clusters",
3207
+ method: "get",
3208
+ ...variables,
3209
+ signal
3210
+ });
3211
+ const createCluster = (variables, signal) => controlPlaneFetch({
3212
+ url: "/workspaces/{workspaceId}/clusters",
3213
+ method: "post",
3214
+ ...variables,
3215
+ signal
3216
+ });
1277
3217
  const getCluster = (variables, signal) => controlPlaneFetch({
1278
3218
  url: "/workspaces/{workspaceId}/clusters/{clusterId}",
1279
3219
  method: "get",
1280
3220
  ...variables,
1281
3221
  signal
1282
3222
  });
1283
- const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
3223
+ const updateCluster = (variables, signal) => controlPlaneFetch({
3224
+ url: "/workspaces/{workspaceId}/clusters/{clusterId}",
3225
+ method: "patch",
3226
+ ...variables,
3227
+ signal
3228
+ });
3229
+ const deleteCluster = (variables, signal) => controlPlaneFetch({
3230
+ url: "/workspaces/{workspaceId}/clusters/{clusterId}",
3231
+ method: "delete",
3232
+ ...variables,
3233
+ signal
3234
+ });
1284
3235
  const getDatabaseList = (variables, signal) => controlPlaneFetch({
1285
3236
  url: "/workspaces/{workspaceId}/dbs",
1286
3237
  method: "get",
1287
3238
  ...variables,
1288
3239
  signal
1289
3240
  });
1290
- const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
3241
+ const createDatabase = (variables, signal) => controlPlaneFetch({
3242
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
3243
+ method: "put",
3244
+ ...variables,
3245
+ signal
3246
+ });
1291
3247
  const deleteDatabase = (variables, signal) => controlPlaneFetch({
1292
3248
  url: "/workspaces/{workspaceId}/dbs/{dbName}",
1293
3249
  method: "delete",
1294
3250
  ...variables,
1295
3251
  signal
1296
3252
  });
1297
- const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
1298
- const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
1299
- const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
1300
- const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
1301
- const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
1302
- const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
3253
+ const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({
3254
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
3255
+ method: "get",
3256
+ ...variables,
3257
+ signal
3258
+ });
3259
+ const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({
3260
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
3261
+ method: "patch",
3262
+ ...variables,
3263
+ signal
3264
+ });
3265
+ const renameDatabase = (variables, signal) => controlPlaneFetch({
3266
+ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename",
3267
+ method: "post",
3268
+ ...variables,
3269
+ signal
3270
+ });
3271
+ const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({
3272
+ url: "/workspaces/{workspaceId}/dbs/{dbName}/github",
3273
+ method: "get",
3274
+ ...variables,
3275
+ signal
3276
+ });
3277
+ const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({
3278
+ url: "/workspaces/{workspaceId}/dbs/{dbName}/github",
3279
+ method: "put",
3280
+ ...variables,
3281
+ signal
3282
+ });
3283
+ const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({
3284
+ url: "/workspaces/{workspaceId}/dbs/{dbName}/github",
3285
+ method: "delete",
3286
+ ...variables,
3287
+ signal
3288
+ });
1303
3289
  const listRegions = (variables, signal) => controlPlaneFetch({
1304
3290
  url: "/workspaces/{workspaceId}/regions",
1305
3291
  method: "get",
@@ -1324,6 +3310,8 @@ const operationsByTag$1 = {
1324
3310
  getWorkspace,
1325
3311
  updateWorkspace,
1326
3312
  deleteWorkspace,
3313
+ getWorkspaceSettings,
3314
+ updateWorkspaceSettings,
1327
3315
  getWorkspaceMembersList,
1328
3316
  updateWorkspaceMemberRole,
1329
3317
  removeWorkspaceMember
@@ -1335,7 +3323,13 @@ const operationsByTag$1 = {
1335
3323
  acceptWorkspaceMemberInvite,
1336
3324
  resendWorkspaceMemberInvite
1337
3325
  },
1338
- xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
3326
+ xbcontrolOther: {
3327
+ listClusters,
3328
+ createCluster,
3329
+ getCluster,
3330
+ updateCluster,
3331
+ deleteCluster
3332
+ },
1339
3333
  databases: {
1340
3334
  getDatabaseList,
1341
3335
  createDatabase,
@@ -1355,7 +3349,7 @@ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
1355
3349
  const buildApiClient = () => class {
1356
3350
  constructor(options = {}) {
1357
3351
  const provider = options.host ?? "production";
1358
- const apiKey = options.apiKey ?? getAPIKey();
3352
+ const apiKey = options.apiKey;
1359
3353
  const trace = options.trace ?? defaultTrace;
1360
3354
  const clientID = generateUUID();
1361
3355
  if (!apiKey) {
@@ -1612,7 +3606,7 @@ var __privateAdd$5 = (obj, member, value) => {
1612
3606
  };
1613
3607
  var __privateSet$3 = (obj, member, value, setter) => {
1614
3608
  __accessCheck$5(obj, member, "write to private field");
1615
- setter ? setter.call(obj, value) : member.set(obj, value);
3609
+ member.set(obj, value);
1616
3610
  return value;
1617
3611
  };
1618
3612
  var _query, _page;
@@ -1791,7 +3785,7 @@ var __privateAdd$4 = (obj, member, value) => {
1791
3785
  };
1792
3786
  var __privateSet$2 = (obj, member, value, setter) => {
1793
3787
  __accessCheck$4(obj, member, "write to private field");
1794
- setter ? setter.call(obj, value) : member.set(obj, value);
3788
+ member.set(obj, value);
1795
3789
  return value;
1796
3790
  };
1797
3791
  var __privateMethod$3 = (obj, member, method) => {
@@ -2119,7 +4113,7 @@ var __privateAdd$3 = (obj, member, value) => {
2119
4113
  };
2120
4114
  var __privateSet$1 = (obj, member, value, setter) => {
2121
4115
  __accessCheck$3(obj, member, "write to private field");
2122
- setter ? setter.call(obj, value) : member.set(obj, value);
4116
+ member.set(obj, value);
2123
4117
  return value;
2124
4118
  };
2125
4119
  var __privateMethod$2 = (obj, member, method) => {
@@ -3195,19 +5189,19 @@ function prepareParams(param1, param2) {
3195
5189
  return { statement, params: param2?.map((value) => prepareValue(value)) };
3196
5190
  }
3197
5191
  if (isObject(param1)) {
3198
- const { statement, params, consistency } = param1;
3199
- return { statement, params: params?.map((value) => prepareValue(value)), consistency };
5192
+ const { statement, params, consistency, responseType } = param1;
5193
+ return { statement, params: params?.map((value) => prepareValue(value)), consistency, responseType };
3200
5194
  }
3201
5195
  throw new Error("Invalid query");
3202
5196
  }
3203
5197
 
3204
5198
  class SQLPlugin extends XataPlugin {
3205
5199
  build(pluginOptions) {
3206
- return async (query, ...parameters) => {
5200
+ const sqlFunction = async (query, ...parameters) => {
3207
5201
  if (!isParamsObject(query) && (!isTemplateStringsArray(query) || !Array.isArray(parameters))) {
3208
5202
  throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
3209
5203
  }
3210
- const { statement, params, consistency } = prepareParams(query, parameters);
5204
+ const { statement, params, consistency, responseType } = prepareParams(query, parameters);
3211
5205
  const {
3212
5206
  records,
3213
5207
  rows,
@@ -3215,11 +5209,13 @@ class SQLPlugin extends XataPlugin {
3215
5209
  columns = []
3216
5210
  } = await sqlQuery({
3217
5211
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3218
- body: { statement, params, consistency },
5212
+ body: { statement, params, consistency, responseType },
3219
5213
  ...pluginOptions
3220
5214
  });
3221
5215
  return { records, rows, warning, columns };
3222
5216
  };
5217
+ sqlFunction.connectionString = buildConnectionString(pluginOptions);
5218
+ return sqlFunction;
3223
5219
  }
3224
5220
  }
3225
5221
  function isTemplateStringsArray(strings) {
@@ -3228,6 +5224,33 @@ function isTemplateStringsArray(strings) {
3228
5224
  function isParamsObject(params) {
3229
5225
  return isObject(params) && "statement" in params;
3230
5226
  }
5227
+ function buildDomain(host, region) {
5228
+ switch (host) {
5229
+ case "production":
5230
+ return `${region}.sql.xata.sh`;
5231
+ case "staging":
5232
+ return `${region}.sql.staging-xata.dev`;
5233
+ case "dev":
5234
+ return `${region}.sql.dev-xata.dev`;
5235
+ case "local":
5236
+ return "localhost:7654";
5237
+ default:
5238
+ throw new Error("Invalid host provider");
5239
+ }
5240
+ }
5241
+ function buildConnectionString({ apiKey, workspacesApiUrl, branch }) {
5242
+ const url = isString(workspacesApiUrl) ? workspacesApiUrl : workspacesApiUrl("", {});
5243
+ const parts = parseWorkspacesUrlParts(url);
5244
+ if (!parts)
5245
+ throw new Error("Invalid workspaces URL");
5246
+ const { workspace: workspaceSlug, region, database, host } = parts;
5247
+ const domain = buildDomain(host, region);
5248
+ const workspace = workspaceSlug.split("-").pop();
5249
+ if (!workspace || !region || !database || !apiKey || !branch) {
5250
+ throw new Error("Unable to build xata connection string");
5251
+ }
5252
+ return `postgresql://${workspace}:${apiKey}@${domain}/${database}:${branch}?sslmode=require`;
5253
+ }
3231
5254
 
3232
5255
  class TransactionPlugin extends XataPlugin {
3233
5256
  build(pluginOptions) {
@@ -3259,7 +5282,7 @@ var __privateAdd = (obj, member, value) => {
3259
5282
  };
3260
5283
  var __privateSet = (obj, member, value, setter) => {
3261
5284
  __accessCheck(obj, member, "write to private field");
3262
- setter ? setter.call(obj, value) : member.set(obj, value);
5285
+ member.set(obj, value);
3263
5286
  return value;
3264
5287
  };
3265
5288
  var __privateMethod = (obj, member, method) => {
@@ -3278,7 +5301,8 @@ const buildClient = (plugins) => {
3278
5301
  const pluginOptions = {
3279
5302
  ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3280
5303
  host: safeOptions.host,
3281
- tables
5304
+ tables,
5305
+ branch: safeOptions.branch
3282
5306
  };
3283
5307
  const db = new SchemaPlugin().build(pluginOptions);
3284
5308
  const search = new SearchPlugin(db).build(pluginOptions);
@@ -3303,7 +5327,7 @@ const buildClient = (plugins) => {
3303
5327
  return { databaseURL, branch };
3304
5328
  }
3305
5329
  }, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3306
- const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
5330
+ const enableBrowser = options?.enableBrowser ?? false;
3307
5331
  const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
3308
5332
  if (isBrowser && !enableBrowser) {
3309
5333
  throw new Error(
@@ -3311,8 +5335,9 @@ const buildClient = (plugins) => {
3311
5335
  );
3312
5336
  }
3313
5337
  const fetch = getFetchImplementation(options?.fetch);
3314
- const databaseURL = options?.databaseURL || getDatabaseURL();
3315
- const apiKey = options?.apiKey || getAPIKey();
5338
+ const databaseURL = options?.databaseURL;
5339
+ const apiKey = options?.apiKey;
5340
+ const branch = options?.branch;
3316
5341
  const trace = options?.trace ?? defaultTrace;
3317
5342
  const clientName = options?.clientName;
3318
5343
  const host = options?.host ?? "production";
@@ -3323,25 +5348,8 @@ const buildClient = (plugins) => {
3323
5348
  if (!databaseURL) {
3324
5349
  throw new Error("Option databaseURL is required");
3325
5350
  }
3326
- const envBranch = getBranch();
3327
- const previewBranch = getPreviewBranch();
3328
- const branch = options?.branch || previewBranch || envBranch || "main";
3329
- if (!!previewBranch && branch !== previewBranch) {
3330
- console.warn(
3331
- `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
3332
- );
3333
- } else if (!!envBranch && branch !== envBranch) {
3334
- console.warn(
3335
- `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3336
- );
3337
- } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
3338
- console.warn(
3339
- `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3340
- );
3341
- } else if (!previewBranch && !envBranch && options?.branch === void 0) {
3342
- console.warn(
3343
- `No branch was passed to the client constructor. Using default branch ${branch}. You can set the branch with the environment variable XATA_BRANCH or by passing the branch option to the client constructor.`
3344
- );
5351
+ if (!branch) {
5352
+ throw new Error("Option branch is required");
3345
5353
  }
3346
5354
  return {
3347
5355
  fetch,
@@ -3452,6 +5460,48 @@ const deserialize = (json) => {
3452
5460
  return defaultSerializer.fromJSON(json);
3453
5461
  };
3454
5462
 
5463
+ function parseEnvironment(environment) {
5464
+ try {
5465
+ if (typeof environment === "function") {
5466
+ return new Proxy(
5467
+ {},
5468
+ {
5469
+ get(target) {
5470
+ return environment(target);
5471
+ }
5472
+ }
5473
+ );
5474
+ }
5475
+ if (isObject(environment)) {
5476
+ return environment;
5477
+ }
5478
+ } catch (error) {
5479
+ }
5480
+ return {};
5481
+ }
5482
+ function buildPreviewBranchName({ org, branch }) {
5483
+ return `preview-${org}-${branch}`;
5484
+ }
5485
+ function getDeployPreviewBranch(environment) {
5486
+ try {
5487
+ const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = parseEnvironment(environment);
5488
+ if (deployPreviewBranch)
5489
+ return deployPreviewBranch;
5490
+ switch (deployPreview) {
5491
+ case "vercel": {
5492
+ if (!vercelGitCommitRef || !vercelGitRepoOwner) {
5493
+ console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
5494
+ return void 0;
5495
+ }
5496
+ return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
5497
+ }
5498
+ }
5499
+ return void 0;
5500
+ } catch (err) {
5501
+ return void 0;
5502
+ }
5503
+ }
5504
+
3455
5505
  class XataError extends Error {
3456
5506
  constructor(message, status) {
3457
5507
  super(message);
@@ -3460,6 +5510,7 @@ class XataError extends Error {
3460
5510
  }
3461
5511
 
3462
5512
  exports.BaseClient = BaseClient;
5513
+ exports.Buffer = Buffer;
3463
5514
  exports.FetcherError = FetcherError;
3464
5515
  exports.FilesPlugin = FilesPlugin;
3465
5516
  exports.Operations = operationsByTag;
@@ -3485,6 +5536,7 @@ exports.XataError = XataError;
3485
5536
  exports.XataFile = XataFile;
3486
5537
  exports.XataPlugin = XataPlugin;
3487
5538
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
5539
+ exports.adaptAllTables = adaptAllTables;
3488
5540
  exports.adaptTable = adaptTable;
3489
5541
  exports.addGitBranchesEntry = addGitBranchesEntry;
3490
5542
  exports.addTableColumn = addTableColumn;
@@ -3512,6 +5564,7 @@ exports.createTable = createTable;
3512
5564
  exports.createUserAPIKey = createUserAPIKey;
3513
5565
  exports.createWorkspace = createWorkspace;
3514
5566
  exports.deleteBranch = deleteBranch;
5567
+ exports.deleteCluster = deleteCluster;
3515
5568
  exports.deleteColumn = deleteColumn;
3516
5569
  exports.deleteDatabase = deleteDatabase;
3517
5570
  exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
@@ -3532,9 +5585,7 @@ exports.exists = exists;
3532
5585
  exports.fileAccess = fileAccess;
3533
5586
  exports.fileUpload = fileUpload;
3534
5587
  exports.ge = ge;
3535
- exports.getAPIKey = getAPIKey;
3536
5588
  exports.getAuthorizationCode = getAuthorizationCode;
3537
- exports.getBranch = getBranch;
3538
5589
  exports.getBranchDetails = getBranchDetails;
3539
5590
  exports.getBranchList = getBranchList;
3540
5591
  exports.getBranchMetadata = getBranchMetadata;
@@ -3549,7 +5600,7 @@ exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
3549
5600
  exports.getDatabaseList = getDatabaseList;
3550
5601
  exports.getDatabaseMetadata = getDatabaseMetadata;
3551
5602
  exports.getDatabaseSettings = getDatabaseSettings;
3552
- exports.getDatabaseURL = getDatabaseURL;
5603
+ exports.getDeployPreviewBranch = getDeployPreviewBranch;
3553
5604
  exports.getFile = getFile;
3554
5605
  exports.getFileItem = getFileItem;
3555
5606
  exports.getGitBranchesMapping = getGitBranchesMapping;
@@ -3558,7 +5609,6 @@ exports.getMigrationHistory = getMigrationHistory;
3558
5609
  exports.getMigrationJobStatus = getMigrationJobStatus;
3559
5610
  exports.getMigrationRequest = getMigrationRequest;
3560
5611
  exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
3561
- exports.getPreviewBranch = getPreviewBranch;
3562
5612
  exports.getRecord = getRecord;
3563
5613
  exports.getSchema = getSchema;
3564
5614
  exports.getTableColumns = getTableColumns;
@@ -3569,6 +5619,7 @@ exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
3569
5619
  exports.getUserOAuthClients = getUserOAuthClients;
3570
5620
  exports.getWorkspace = getWorkspace;
3571
5621
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
5622
+ exports.getWorkspaceSettings = getWorkspaceSettings;
3572
5623
  exports.getWorkspacesList = getWorkspacesList;
3573
5624
  exports.grantAuthorizationCode = grantAuthorizationCode;
3574
5625
  exports.greaterEquals = greaterEquals;
@@ -3642,6 +5693,7 @@ exports.updateUser = updateUser;
3642
5693
  exports.updateWorkspace = updateWorkspace;
3643
5694
  exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
3644
5695
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
5696
+ exports.updateWorkspaceSettings = updateWorkspaceSettings;
3645
5697
  exports.upsertRecordWithID = upsertRecordWithID;
3646
5698
  exports.vectorSearchTable = vectorSearchTable;
3647
5699
  //# sourceMappingURL=index.cjs.map