@xata.io/client 0.21.2 → 0.21.4
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 +12 -0
- package/dist/index.cjs +29 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +18 -209
- package/dist/index.mjs +30 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# @xata.io/client
|
2
2
|
|
3
|
+
## 0.21.4
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- [#816](https://github.com/xataio/client-ts/pull/816) [`a0149435`](https://github.com/xataio/client-ts/commit/a01494358ae3a8dd9d7eba3a276fe6f8b7827a33) Thanks [@SferaDev](https://github.com/SferaDev)! - Improve types for datetime fields accepting strings
|
8
|
+
|
9
|
+
## 0.21.3
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- [#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
|
14
|
+
|
3
15
|
## 0.21.2
|
4
16
|
|
5
17
|
### 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.4";
|
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);
|
@@ -463,17 +472,12 @@ function parseUrl(url) {
|
|
463
472
|
|
464
473
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
465
474
|
|
466
|
-
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
467
475
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
468
476
|
url: "/dbs/{dbName}",
|
469
477
|
method: "get",
|
470
478
|
...variables,
|
471
479
|
signal
|
472
480
|
});
|
473
|
-
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
474
|
-
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
475
|
-
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
476
|
-
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
477
481
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
478
482
|
url: "/db/{dbBranchName}",
|
479
483
|
method: "get",
|
@@ -612,13 +616,6 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
612
616
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
613
617
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
614
618
|
const operationsByTag$2 = {
|
615
|
-
database: {
|
616
|
-
dEPRECATEDgetDatabaseList,
|
617
|
-
dEPRECATEDcreateDatabase,
|
618
|
-
dEPRECATEDdeleteDatabase,
|
619
|
-
dEPRECATEDgetDatabaseMetadata,
|
620
|
-
dEPRECATEDupdateDatabaseMetadata
|
621
|
-
},
|
622
619
|
branch: {
|
623
620
|
getBranchList,
|
624
621
|
getBranchDetails,
|
@@ -848,12 +845,12 @@ function parseProviderString(provider = "production") {
|
|
848
845
|
function parseWorkspacesUrlParts(url) {
|
849
846
|
if (!isString(url))
|
850
847
|
return null;
|
851
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
852
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))
|
848
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
849
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
|
853
850
|
const match = url.match(regex) || url.match(regexStaging);
|
854
851
|
if (!match)
|
855
852
|
return null;
|
856
|
-
return { workspace: match[1], region: match[2]
|
853
|
+
return { workspace: match[1], region: match[2] };
|
857
854
|
}
|
858
855
|
|
859
856
|
var __accessCheck$7 = (obj, member, msg) => {
|
@@ -882,6 +879,7 @@ class XataApiClient {
|
|
882
879
|
const provider = options.host ?? "production";
|
883
880
|
const apiKey = options.apiKey ?? getAPIKey();
|
884
881
|
const trace = options.trace ?? defaultTrace;
|
882
|
+
const clientID = generateUUID();
|
885
883
|
if (!apiKey) {
|
886
884
|
throw new Error("Could not resolve a valid apiKey");
|
887
885
|
}
|
@@ -891,7 +889,8 @@ class XataApiClient {
|
|
891
889
|
fetchImpl: getFetchImplementation(options.fetch),
|
892
890
|
apiKey,
|
893
891
|
trace,
|
894
|
-
clientName: options.clientName
|
892
|
+
clientName: options.clientName,
|
893
|
+
clientID
|
895
894
|
});
|
896
895
|
}
|
897
896
|
get user() {
|
@@ -1896,13 +1895,6 @@ class XataApiPlugin {
|
|
1896
1895
|
class XataPlugin {
|
1897
1896
|
}
|
1898
1897
|
|
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
1898
|
function cleanFilter(filter) {
|
1907
1899
|
if (!filter)
|
1908
1900
|
return void 0;
|
@@ -3484,7 +3476,7 @@ const deserialize = (json) => {
|
|
3484
3476
|
};
|
3485
3477
|
|
3486
3478
|
function buildWorkerRunner(config) {
|
3487
|
-
return function xataWorker(name,
|
3479
|
+
return function xataWorker(name, worker) {
|
3488
3480
|
return async (...args) => {
|
3489
3481
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3490
3482
|
const result = await fetch(url, {
|
@@ -3544,11 +3536,6 @@ exports.createMigrationRequest = createMigrationRequest;
|
|
3544
3536
|
exports.createTable = createTable;
|
3545
3537
|
exports.createUserAPIKey = createUserAPIKey;
|
3546
3538
|
exports.createWorkspace = createWorkspace;
|
3547
|
-
exports.dEPRECATEDcreateDatabase = dEPRECATEDcreateDatabase;
|
3548
|
-
exports.dEPRECATEDdeleteDatabase = dEPRECATEDdeleteDatabase;
|
3549
|
-
exports.dEPRECATEDgetDatabaseList = dEPRECATEDgetDatabaseList;
|
3550
|
-
exports.dEPRECATEDgetDatabaseMetadata = dEPRECATEDgetDatabaseMetadata;
|
3551
|
-
exports.dEPRECATEDupdateDatabaseMetadata = dEPRECATEDupdateDatabaseMetadata;
|
3552
3539
|
exports.deleteBranch = deleteBranch;
|
3553
3540
|
exports.deleteColumn = deleteColumn;
|
3554
3541
|
exports.deleteDatabase = deleteDatabase;
|