@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/dist/index.d.ts
CHANGED
@@ -5790,9 +5790,6 @@ type RequiredBy<T, K extends keyof T> = T & {
|
|
5790
5790
|
[P in K]-?: NonNullable<T[P]>;
|
5791
5791
|
};
|
5792
5792
|
type GetArrayInnerType<T extends readonly any[]> = T[number];
|
5793
|
-
type FunctionKeys<T> = {
|
5794
|
-
[K in keyof T]: T[K] extends (...args: any) => any ? K : never;
|
5795
|
-
}[keyof T];
|
5796
5793
|
type SingleOrArray<T> = T | T[];
|
5797
5794
|
type Dictionary<T> = Record<string, T>;
|
5798
5795
|
type OmitBy<T, K extends keyof T> = T extends any ? Omit<T, K> : never;
|
@@ -7699,9 +7696,7 @@ declare class Serializer {
|
|
7699
7696
|
}
|
7700
7697
|
declare const serialize: <T>(data: T) => string;
|
7701
7698
|
declare const deserialize: <T>(json: string) => T;
|
7702
|
-
type SerializerResult<T> = T extends
|
7703
|
-
[K in keyof T]: SerializerResult<T[K]>;
|
7704
|
-
}, FunctionKeys<T>> : T;
|
7699
|
+
type SerializerResult<T> = T extends XataRecord ? EditableData<T> : T extends any[] ? SerializerResult<T[number]>[] : T;
|
7705
7700
|
|
7706
7701
|
type BranchResolutionOptions = {
|
7707
7702
|
databaseURL?: string;
|
@@ -7793,7 +7788,7 @@ type WorkerRunnerConfig = {
|
|
7793
7788
|
workspace: string;
|
7794
7789
|
worker: string;
|
7795
7790
|
};
|
7796
|
-
declare function buildWorkerRunner<XataClient>(config: WorkerRunnerConfig): <WorkerFunction extends (ctx: XataWorkerContext<XataClient>, ...args: any[]) => any>(name: string,
|
7791
|
+
declare function buildWorkerRunner<XataClient>(config: WorkerRunnerConfig): <WorkerFunction extends (ctx: XataWorkerContext<XataClient>, ...args: any[]) => any>(name: string, worker: WorkerFunction) => (...args: RemoveFirst<Parameters<WorkerFunction>>) => Promise<SerializerResult<Awaited<ReturnType<WorkerFunction>>>>;
|
7797
7792
|
|
7798
7793
|
declare class XataError extends Error {
|
7799
7794
|
readonly status: number;
|
package/dist/index.mjs
CHANGED
@@ -295,7 +295,14 @@ enqueue_fn = function(task) {
|
|
295
295
|
return promise;
|
296
296
|
};
|
297
297
|
|
298
|
-
|
298
|
+
function generateUUID() {
|
299
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
300
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
301
|
+
return v.toString(16);
|
302
|
+
});
|
303
|
+
}
|
304
|
+
|
305
|
+
const VERSION = "0.21.3";
|
299
306
|
|
300
307
|
class ErrorWithCause extends Error {
|
301
308
|
constructor(message, options) {
|
@@ -306,7 +313,7 @@ class FetcherError extends ErrorWithCause {
|
|
306
313
|
constructor(status, data, requestId) {
|
307
314
|
super(getMessage(data));
|
308
315
|
this.status = status;
|
309
|
-
this.errors = isBulkError(data) ? data.errors :
|
316
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
310
317
|
this.requestId = requestId;
|
311
318
|
if (data instanceof Error) {
|
312
319
|
this.stack = data.stack;
|
@@ -371,11 +378,12 @@ function hostHeader(url) {
|
|
371
378
|
const { groups } = pattern.exec(url) ?? {};
|
372
379
|
return groups?.host ? { Host: groups.host } : {};
|
373
380
|
}
|
381
|
+
const defaultClientID = generateUUID();
|
374
382
|
async function fetch$1({
|
375
383
|
url: path,
|
376
384
|
method,
|
377
385
|
body,
|
378
|
-
headers,
|
386
|
+
headers: customHeaders,
|
379
387
|
pathParams,
|
380
388
|
queryParams,
|
381
389
|
fetchImpl,
|
@@ -406,20 +414,21 @@ async function fetch$1({
|
|
406
414
|
["version", VERSION],
|
407
415
|
isDefined(clientName) ? ["service", clientName] : void 0
|
408
416
|
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
417
|
+
const headers = {
|
418
|
+
"Accept-Encoding": "identity",
|
419
|
+
"Content-Type": "application/json",
|
420
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
421
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
422
|
+
"X-Xata-Agent": xataAgent,
|
423
|
+
...customHeaders,
|
424
|
+
...hostHeader(fullUrl),
|
425
|
+
Authorization: `Bearer ${apiKey}`
|
426
|
+
};
|
409
427
|
const response = await pool.request(url, {
|
410
428
|
...fetchOptions,
|
411
429
|
method: method.toUpperCase(),
|
412
430
|
body: body ? JSON.stringify(body) : void 0,
|
413
|
-
headers
|
414
|
-
"Accept-Encoding": "identity",
|
415
|
-
"Content-Type": "application/json",
|
416
|
-
"X-Xata-Client-ID": clientID ?? "",
|
417
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
418
|
-
"X-Xata-Agent": xataAgent,
|
419
|
-
...headers,
|
420
|
-
...hostHeader(fullUrl),
|
421
|
-
Authorization: `Bearer ${apiKey}`
|
422
|
-
},
|
431
|
+
headers,
|
423
432
|
signal
|
424
433
|
});
|
425
434
|
const { host, protocol } = parseUrl(response.url);
|
@@ -846,12 +855,12 @@ function parseProviderString(provider = "production") {
|
|
846
855
|
function parseWorkspacesUrlParts(url) {
|
847
856
|
if (!isString(url))
|
848
857
|
return null;
|
849
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
850
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))
|
858
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
859
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
|
851
860
|
const match = url.match(regex) || url.match(regexStaging);
|
852
861
|
if (!match)
|
853
862
|
return null;
|
854
|
-
return { workspace: match[1], region: match[2]
|
863
|
+
return { workspace: match[1], region: match[2] };
|
855
864
|
}
|
856
865
|
|
857
866
|
var __accessCheck$7 = (obj, member, msg) => {
|
@@ -880,6 +889,7 @@ class XataApiClient {
|
|
880
889
|
const provider = options.host ?? "production";
|
881
890
|
const apiKey = options.apiKey ?? getAPIKey();
|
882
891
|
const trace = options.trace ?? defaultTrace;
|
892
|
+
const clientID = generateUUID();
|
883
893
|
if (!apiKey) {
|
884
894
|
throw new Error("Could not resolve a valid apiKey");
|
885
895
|
}
|
@@ -889,7 +899,8 @@ class XataApiClient {
|
|
889
899
|
fetchImpl: getFetchImplementation(options.fetch),
|
890
900
|
apiKey,
|
891
901
|
trace,
|
892
|
-
clientName: options.clientName
|
902
|
+
clientName: options.clientName,
|
903
|
+
clientID
|
893
904
|
});
|
894
905
|
}
|
895
906
|
get user() {
|
@@ -1894,13 +1905,6 @@ class XataApiPlugin {
|
|
1894
1905
|
class XataPlugin {
|
1895
1906
|
}
|
1896
1907
|
|
1897
|
-
function generateUUID() {
|
1898
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
1899
|
-
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
1900
|
-
return v.toString(16);
|
1901
|
-
});
|
1902
|
-
}
|
1903
|
-
|
1904
1908
|
function cleanFilter(filter) {
|
1905
1909
|
if (!filter)
|
1906
1910
|
return void 0;
|
@@ -3482,7 +3486,7 @@ const deserialize = (json) => {
|
|
3482
3486
|
};
|
3483
3487
|
|
3484
3488
|
function buildWorkerRunner(config) {
|
3485
|
-
return function xataWorker(name,
|
3489
|
+
return function xataWorker(name, worker) {
|
3486
3490
|
return async (...args) => {
|
3487
3491
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3488
3492
|
const result = await fetch(url, {
|