@xata.io/client 0.21.2 → 0.21.3
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/CHANGELOG.md +6 -0
- package/dist/index.cjs +29 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -7
- package/dist/index.mjs +29 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# @xata.io/client
|
2
2
|
|
3
|
+
## 0.21.3
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- [#792](https://github.com/xataio/client-ts/pull/792) [`6c96da45`](https://github.com/xataio/client-ts/commit/6c96da4533500ec236547f47310e99461d5457e8) Thanks [@SferaDev](https://github.com/SferaDev)! - Update workers return type helper
|
8
|
+
|
3
9
|
## 0.21.2
|
4
10
|
|
5
11
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
@@ -297,7 +297,14 @@ enqueue_fn = function(task) {
|
|
297
297
|
return promise;
|
298
298
|
};
|
299
299
|
|
300
|
-
|
300
|
+
function generateUUID() {
|
301
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
302
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
303
|
+
return v.toString(16);
|
304
|
+
});
|
305
|
+
}
|
306
|
+
|
307
|
+
const VERSION = "0.21.3";
|
301
308
|
|
302
309
|
class ErrorWithCause extends Error {
|
303
310
|
constructor(message, options) {
|
@@ -308,7 +315,7 @@ class FetcherError extends ErrorWithCause {
|
|
308
315
|
constructor(status, data, requestId) {
|
309
316
|
super(getMessage(data));
|
310
317
|
this.status = status;
|
311
|
-
this.errors = isBulkError(data) ? data.errors :
|
318
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
312
319
|
this.requestId = requestId;
|
313
320
|
if (data instanceof Error) {
|
314
321
|
this.stack = data.stack;
|
@@ -373,11 +380,12 @@ function hostHeader(url) {
|
|
373
380
|
const { groups } = pattern.exec(url) ?? {};
|
374
381
|
return groups?.host ? { Host: groups.host } : {};
|
375
382
|
}
|
383
|
+
const defaultClientID = generateUUID();
|
376
384
|
async function fetch$1({
|
377
385
|
url: path,
|
378
386
|
method,
|
379
387
|
body,
|
380
|
-
headers,
|
388
|
+
headers: customHeaders,
|
381
389
|
pathParams,
|
382
390
|
queryParams,
|
383
391
|
fetchImpl,
|
@@ -408,20 +416,21 @@ async function fetch$1({
|
|
408
416
|
["version", VERSION],
|
409
417
|
isDefined(clientName) ? ["service", clientName] : void 0
|
410
418
|
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
419
|
+
const headers = {
|
420
|
+
"Accept-Encoding": "identity",
|
421
|
+
"Content-Type": "application/json",
|
422
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
423
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
424
|
+
"X-Xata-Agent": xataAgent,
|
425
|
+
...customHeaders,
|
426
|
+
...hostHeader(fullUrl),
|
427
|
+
Authorization: `Bearer ${apiKey}`
|
428
|
+
};
|
411
429
|
const response = await pool.request(url, {
|
412
430
|
...fetchOptions,
|
413
431
|
method: method.toUpperCase(),
|
414
432
|
body: body ? JSON.stringify(body) : void 0,
|
415
|
-
headers
|
416
|
-
"Accept-Encoding": "identity",
|
417
|
-
"Content-Type": "application/json",
|
418
|
-
"X-Xata-Client-ID": clientID ?? "",
|
419
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
420
|
-
"X-Xata-Agent": xataAgent,
|
421
|
-
...headers,
|
422
|
-
...hostHeader(fullUrl),
|
423
|
-
Authorization: `Bearer ${apiKey}`
|
424
|
-
},
|
433
|
+
headers,
|
425
434
|
signal
|
426
435
|
});
|
427
436
|
const { host, protocol } = parseUrl(response.url);
|
@@ -848,12 +857,12 @@ function parseProviderString(provider = "production") {
|
|
848
857
|
function parseWorkspacesUrlParts(url) {
|
849
858
|
if (!isString(url))
|
850
859
|
return null;
|
851
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
852
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))
|
860
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
861
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
|
853
862
|
const match = url.match(regex) || url.match(regexStaging);
|
854
863
|
if (!match)
|
855
864
|
return null;
|
856
|
-
return { workspace: match[1], region: match[2]
|
865
|
+
return { workspace: match[1], region: match[2] };
|
857
866
|
}
|
858
867
|
|
859
868
|
var __accessCheck$7 = (obj, member, msg) => {
|
@@ -882,6 +891,7 @@ class XataApiClient {
|
|
882
891
|
const provider = options.host ?? "production";
|
883
892
|
const apiKey = options.apiKey ?? getAPIKey();
|
884
893
|
const trace = options.trace ?? defaultTrace;
|
894
|
+
const clientID = generateUUID();
|
885
895
|
if (!apiKey) {
|
886
896
|
throw new Error("Could not resolve a valid apiKey");
|
887
897
|
}
|
@@ -891,7 +901,8 @@ class XataApiClient {
|
|
891
901
|
fetchImpl: getFetchImplementation(options.fetch),
|
892
902
|
apiKey,
|
893
903
|
trace,
|
894
|
-
clientName: options.clientName
|
904
|
+
clientName: options.clientName,
|
905
|
+
clientID
|
895
906
|
});
|
896
907
|
}
|
897
908
|
get user() {
|
@@ -1896,13 +1907,6 @@ class XataApiPlugin {
|
|
1896
1907
|
class XataPlugin {
|
1897
1908
|
}
|
1898
1909
|
|
1899
|
-
function generateUUID() {
|
1900
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
1901
|
-
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
1902
|
-
return v.toString(16);
|
1903
|
-
});
|
1904
|
-
}
|
1905
|
-
|
1906
1910
|
function cleanFilter(filter) {
|
1907
1911
|
if (!filter)
|
1908
1912
|
return void 0;
|
@@ -3484,7 +3488,7 @@ const deserialize = (json) => {
|
|
3484
3488
|
};
|
3485
3489
|
|
3486
3490
|
function buildWorkerRunner(config) {
|
3487
|
-
return function xataWorker(name,
|
3491
|
+
return function xataWorker(name, worker) {
|
3488
3492
|
return async (...args) => {
|
3489
3493
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3490
3494
|
const result = await fetch(url, {
|